ELASTIC WORDS (ELW) DocumentationHour 2: C++ Orchestrator & The Golden Rule Task 2.1 & 2.4: PointPool, FamilyMember, and Family ClassesDefine the C++ wrappers in src/family.h. This demonstrates RAII over the C structs and utilizes std::vector for FamilyMember. #ifndef FAMILY_H
#define FAMILY_H
#include <string>
#include <vector>
extern "C" {
#include "substrate.h"
}
enum Quirk { CHARISMATIC, FRUGAL, FIERCE, PASSIONATE, PEACEMAKER, RUTHLESS, FERTILE, MIDAS_TOUCH };
enum Fault { ABRASIVE, WASTEFUL, COWARDLY, FRIGID, TRAITOROUS, RECKLESS, LUSTFUL, SLOTHFUL };
enum Era { GOLDEN, DARK, NEUTRAL };
class PointPool {
private:
PPData data;
public:
PointPool();
~PointPool();
void applyModifier(int aggroMod, int commMod, int amorMod, int prizeMod);
int calculateAP() const;
int getAggro() const { return data.aggro; }
int getComm() const { return data.comm; }
int getAmor() const { return data.amor; }
int getPrize() const { return data.prize; }
};
class FamilyMember {
public:
std::string name;
Quirk quirk;
Fault fault;
FamilyMember(std::string n, Quirk q, Fault f);
~FamilyMember();
};
class Family {
public:
std::vector<FamilyMember> members;
PointPool pool;
Era activeEra;
int growthRate;
Family();
~Family();
};
#endif
Task 2.2: Implement the Action Point (AP) CalculatorImplement the methods in src/family.cpp. #include "family.h"
PointPool::PointPool() {
data.aggro = 7;
data.comm = 7;
data.amor = 7;
data.prize = 7;
}
PointPool::~PointPool() {
}
void PointPool::applyModifier(int aggroMod, int commMod, int amorMod, int prizeMod) {
data.aggro += aggroMod;
data.comm += commMod;
data.amor += amorMod;
data.prize += prizeMod;
ppClamp(&data);
}
int PointPool::calculateAP() const {
int ap = 5 + (data.comm / 3) - (data.aggro / 5);
return (ap > 0) ? ap : 1;
}
FamilyMember::FamilyMember(std::string n, Quirk q, Fault f) : name(n), quirk(q), fault(f) {
}
FamilyMember::~FamilyMember() {
}
Family::Family() : activeEra(NEUTRAL), growthRate(0) {
}
Family::~Family() {
members.clear();
}
Task 2.3: TEST - Pass dummy states to AP calculatorCreate src/main.cpp to test the AP yields and the C clamping logic integration. #include <iostream>
#include "family.h"
int main() {
PointPool pp;
std::cout << "Initial AP: " << pp.calculateAP() << std::endl;
pp.applyModifier(10, -5, 0, 0);
std::cout << "New AP Yield: " << pp.calculateAP() << std::endl;
return 0;
}
Build & RunSave files using C-x C-s in Emacs 22.3, then run the build process.
Optimized for 800x600 resolution. |