feat: pogoda, poprawki w wyświetlaniu. Clean Architecture
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "BuddyTypes.h"
|
||||
|
||||
struct TamaState {
|
||||
uint8_t hunger; // 0=full → 100=starving
|
||||
uint8_t happiness; // 100=happy → 0=bored
|
||||
uint8_t hygiene; // 100=clean → 0=dirty
|
||||
uint32_t nextHungerTick;
|
||||
uint32_t nextHappyTick;
|
||||
uint32_t nextHygieneTick;
|
||||
};
|
||||
|
||||
void initTama(TamaState &t, uint32_t now);
|
||||
|
||||
// Updates ticks and returns the mood override for buddy.
|
||||
// Returns MOOD_HUNGRY / MOOD_DIRTY / MOOD_PLAYFUL when a need is critical.
|
||||
// Returns MOOD_NORMAL when needs are satisfied or guard blocks (revertAt != 0, sleepy, wink).
|
||||
Mood updateTama(TamaState &t, const BuddyState &b, uint32_t now);
|
||||
|
||||
void tamaFeed(TamaState &t); // hunger -= 30 (floor 0)
|
||||
void tamaPlay(TamaState &t); // happy += 25 (cap 100)
|
||||
void tamaClean(TamaState &t); // hygiene += 40 (cap 100)
|
||||
@@ -0,0 +1 @@
|
||||
{ "name": "TamaLogic", "version": "1.0.0", "frameworks": "*", "platforms": "*" }
|
||||
Reference in New Issue
Block a user