58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
#include "TamaLogic.h"
|
|
|
|
void initTama(TamaState &t, uint32_t now)
|
|
{
|
|
t.hunger = 10;
|
|
t.happiness = 80;
|
|
t.hygiene = 90;
|
|
t.nextHungerTick = now + 120000UL;
|
|
t.nextHappyTick = now + 180000UL;
|
|
t.nextHygieneTick = now + 240000UL;
|
|
}
|
|
|
|
Mood updateTama(TamaState &t, const BuddyState &b, uint32_t now)
|
|
{
|
|
// Tick needs over time
|
|
if (now >= t.nextHungerTick) {
|
|
t.nextHungerTick = now + 120000UL;
|
|
if (t.hunger < 100) t.hunger++;
|
|
}
|
|
if (now >= t.nextHappyTick) {
|
|
t.nextHappyTick = now + 180000UL;
|
|
if (t.happiness > 0) t.happiness--;
|
|
}
|
|
if (now >= t.nextHygieneTick) {
|
|
t.nextHygieneTick = now + 240000UL;
|
|
if (t.hygiene > 0) t.hygiene--;
|
|
}
|
|
|
|
// Return mood override based on critical needs.
|
|
// Guard: skip when buddy has a timed mood or is in non-overridable state.
|
|
if (b.revertAt == 0 && b.mood != MOOD_SLEEPY &&
|
|
b.mood != MOOD_WINK_L && b.mood != MOOD_WINK_R)
|
|
{
|
|
if (t.hunger >= 80) return MOOD_HUNGRY;
|
|
if (t.hygiene <= 20) return MOOD_DIRTY;
|
|
if (t.happiness <= 20) return MOOD_PLAYFUL;
|
|
// Needs satisfied — signal "reset to normal" (caller handles if buddy is in need-mood)
|
|
}
|
|
return MOOD_NORMAL;
|
|
}
|
|
|
|
void tamaFeed(TamaState &t)
|
|
{
|
|
t.hunger = (t.hunger >= 30) ? t.hunger - 30 : 0;
|
|
}
|
|
|
|
void tamaPlay(TamaState &t)
|
|
{
|
|
uint16_t v = (uint16_t)t.happiness + 25;
|
|
t.happiness = (v > 100) ? 100 : (uint8_t)v;
|
|
}
|
|
|
|
void tamaClean(TamaState &t)
|
|
{
|
|
uint16_t v = (uint16_t)t.hygiene + 40;
|
|
t.hygiene = (v > 100) ? 100 : (uint8_t)v;
|
|
}
|