Citizen.sleela
lib/citizen/Citizen.sleela · 228 line(s) · sleela
<< lib/citizen/Citizen.sleela
SLeeLa Standard Library Definition.
Definition: Defines Citizen, the civic Master Class — one honest, taxpaying,
coffee-drinking person as modeled by the Republic of Sleela. A Citizen is
the smallest unit of a nation that still complains about the weather.
Citizen is a NATURAL / LOADABLE MODULE sharing the common module contract
(load / loaded / moduleName / describe) with the other /lib Master Classes,
so a loader can treat it uniformly. It composes three sidecar records that it
owns and keeps consistent: an Industry affiliation (what they do for a
living), a BankAccount (where the money quietly leaves from), and a
FederalReserveID (how the central bank pretends to know them personally).
A Citizen is, famously, able. It can be born, employed, paid, taxed, retired,
and — on a good day — content. It holds civic state only; the paperwork is
performed by the sidecar classes in this package. The runnable orchestration
example lives in citizen/sleela/CitizenDemo.sleela.
Family: citizen. Civic data crosses an explicit bridge to the ledger. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class Citizen {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
or catalog can read and (where appropriate) override this record.
Values are faithful to the subject's real origin where publicly known. >>
String metaVersion = "1.0.0";
int metaId = 10301;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-10-16";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-10-07";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 9;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
static final String MODULE = "Citizen";
< Life stages, because every bureaucracy loves an enum it can't spell. >
< a gleam in the census-taker's eye >
static final int STAGE_UNBORN = 0;
< all rights, none of the taxes >
static final int STAGE_MINOR = 1;
< the golden, caffeinated years >
static final int STAGE_WORKING = 2;
< emeritus citizen, senior discount >
static final int STAGE_RETIRED = 3;
< files one final, very late return >
static final int STAGE_DECEASED = 4;
< 1 once the module is loaded >
int loadedFlag;
< the name on the forms nobody reads >
String legalName;
< the name their friends actually use >
String nickname;
< in laps around a medium yellow star >
int age;
< one of STAGE_* >
int stage;
< 0 = DMV queue, 100 = Friday 5pm >
int moodOutOf100;
< what they claim at parties >
Industry industry;
< the sad truth of what they can afford >
BankAccount bank;
< how the central bank addresses the holiday card >
FederalReserveID fedId;
< --- loadable-module contract ------------------------------------------ >
void load() {
loadedFlag = 1;
legalName = "Jane Q. Public";
nickname = "Jay";
age = 0;
stage = STAGE_UNBORN;
moodOutOf100 = 50;
industry = new Industry();
industry.load();
bank = new BankAccount();
bank.load();
fedId = new FederalReserveID();
fedId.load();
}
boolean loaded() { return loadedFlag == 1; }
String moduleName() { return MODULE; }
< --- civic life cycle --------------------------------------------------- >
< A citizen is born. Congratulations, you now owe the system a resume. >
void beBorn(String name) {
if (name != null) { legalName = name; }
age = 0;
stage = STAGE_MINOR;
< newborns have no idea yet. Bless them. >
moodOutOf100 = 100;
fedId.issue(legalName);
bank.openFor(legalName);
}
< Time, that undefeated opponent, advances exactly one year. >
void haveABirthday() {
age = age + 1;
if (age >= 18 && stage == STAGE_MINOR) { stage = STAGE_WORKING; }
if (age >= 67 && stage == STAGE_WORKING) { retire(); }
< another candle, mild optimism >
moodOutOf100 = moodOutOf100 + 1;
if (moodOutOf100 > 100) { moodOutOf100 = 100; }
}
< Pick a trade. The Industry class judges you so this class doesn't have to. >
void getAJob(int sector, int wageCents) {
industry.employ(sector, wageCents);
if (stage == STAGE_MINOR && age >= 16) { stage = STAGE_WORKING; }
< the thrill wears off by Tuesday >
moodOutOf100 = moodOutOf100 + 5;
clampMood();
}
< Payday. The one unambiguously good day of the fortnight. >
int getPaid() {
if (!employed()) { return 0; }
int gross = industry.wage();
bank.deposit(gross);
moodOutOf100 = moodOutOf100 + 10;
clampMood();
return gross;
}
< Taxes. A citizen is, after all, defined by their relationship with Form 1040. >
int payTaxes(int ratePercent) {
if (ratePercent < 0) { ratePercent = 0; }
if (ratePercent > 100) { ratePercent = 100; }
int owed = (bank.balance() * ratePercent) / 100;
bank.withdraw(owed);
< the one unambiguously bad day >
moodOutOf100 = moodOutOf100 - 15;
clampMood();
return owed;
}
< Spend some money on something frivolous. Highly recommended for morale. >
boolean treatYourself(int cents) {
boolean ok = bank.withdraw(cents);
if (ok) { moodOutOf100 = moodOutOf100 + 8; }
clampMood();
return ok;
}
< Gracefully exit the workforce; keep the opinions. >
void retire() {
stage = STAGE_RETIRED;
industry.layOff();
< no more Monday meetings >
moodOutOf100 = moodOutOf100 + 20;
clampMood();
}
< The final, non-negotiable withdrawal. >
void passAway() {
stage = STAGE_DECEASED;
industry.layOff();
}
< --- queries ------------------------------------------------------------ >
boolean alive() { return stage != STAGE_UNBORN && stage != STAGE_DECEASED; }
boolean employed() { return industry.employed() && stage == STAGE_WORKING; }
boolean solvent() { return bank.balance() >= 0; }
< The whole point: a Citizen is able. This proves it. >
boolean isAble() {
return alive() && fedId.valid() && bank.open() && moodOutOf100 > 0;
}
int netWorthCents() { return bank.balance(); }
int lifeStage() { return stage; }
int happiness() { return moodOutOf100; }
String name() { return legalName; }
String fedNumber() { return fedId.number(); }
void clampMood() {
if (moodOutOf100 > 100) { moodOutOf100 = 100; }
if (moodOutOf100 < 0) { moodOutOf100 = 0; }
}
< Render a boolean as a word, so describe() concatenates only Strings/ints — >
< the exact idiom the shipped /lib describe() methods already use. >
String yn(boolean b) { if (b) { return "yes"; } return "no"; }
String describe() {
return MODULE + " name=" + legalName + " age=" + age
+ " stage=" + stage + " able=" + yn(isAble())
+ " worth=" + bank.balance() + " mood=" + moodOutOf100
+ " fed=" + fedId.number();
}
}