Home /Modules/citizen/Character.sleela

Character.sleela

lib/citizen/character/Character.sleela · 170 line(s) · sleela

<< lib/citizen/character/Character.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines Character, the central Master Class of the character
     package — a named actor in the Sleela economy who adopts exactly one
     BusinessModel and lives or dies by its monthly profit. A Character is
     classful by design: it is one class that composes any one of the many,
     many business-model classes in this package.
   
   Character is a NATURAL / LOADABLE MODULE sharing the common module contract
   (load / loaded / moduleName / describe). It holds a BusinessModel reference
   typed to the base class, so it can carry a Subscription, Freemium,
   Marketplace, Advertising, Retail, Wholesale, Franchise, Licensing, SaaS,
   Consulting, Manufacturing, or Brokerage model interchangeably and ask it, each
   month, the only question that matters. The polymorphism follows the exact
   base/subclass pattern used by lib/compiler's SLLanguageCompiler front ends.
   
   It also carries a little personality — grit and reputation — because a
   business model is only as good as the Character running it.
   
   Family: character. Settlement crosses an explicit bridge to the ledger. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class Character {
  < ---- 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 = 10300;
  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 = "Character";

  < 1 once the module is loaded >
  int loadedFlag;
  < who this Character is >
  String name;
  < their elevator pitch, mercifully short >
  String tagline;
  < 0..100 — how many bad months they can stomach >
  int grit;
  < 0..100 — grows with profit, bruises with loss >
  int reputation;
  < running cash on hand >
  int cashCents;

  < the one model they live by (any concrete subclass) >
  BusinessModel model;

  < --- loadable-module contract ------------------------------------------ >
  void load() {
    loadedFlag = 1;
    name = "Nameless Founder";
    tagline = "We're pre-revenue but post-vision.";
    grit = 50;
    reputation = 50;
    cashCents = 0;
    model = null;
  }
  boolean loaded() { return loadedFlag == 1; }
  String moduleName() { return MODULE; }

  < Introduce the Character and give them a little personality. >
  void introduce(String who, String pitch, int startingGrit, int startingCash) {
    if (who != null) { name = who; }
    if (pitch != null) { tagline = pitch; }
    grit = clamp(startingGrit);
    reputation = 50;
    if (startingCash >= 0) { cashCents = startingCash; }
  }

  < Adopt a business model. Any concrete BusinessModel subclass will do — the >
  < Character does not care which, only whether it makes money. This is the >
  < whole point of a base-typed reference holding a subclass instance. >
  void adopt(BusinessModel chosen) {
    model = chosen;
  }

  boolean hasModel() { return model != null && model.ready(); }

  < Live one month: realize the model's profit into cash and let it move the >
  < Character's reputation and grit. Returns the profit for the month. >
  int liveAMonth() {
    if (!hasModel()) { return 0; }
    int profit = model.monthlyProfit();
    cashCents = cashCents + profit;
    if (profit > 0) {
      reputation = clamp(reputation + 3);
      grit = clamp(grit + 1);
    } else {
      reputation = clamp(reputation - 2);
      < a losing month really takes it out of you >
      grit = clamp(grit - 5);
    }
    return profit;
  }

  < Run several months and report the total profit realized. >
  int runMonths(int months) {
    int total = 0;
    int i = 0;
    while (i < months) {
      total = total + liveAMonth();
      i = i + 1;
    }
    return total;
  }

  < The question every Character secretly asks at 3am. >
  boolean stillStanding() { return cashCents >= 0 && grit > 0; }
  boolean thriving() { return hasModel() && model.profitable() && reputation >= 60; }

  int cash() { return cashCents; }
  int reputationScore() { return reputation; }
  int gritScore() { return grit; }
  String characterName() { return name; }
  int modelKind() { if (!hasModel()) { return BusinessModel.KIND_NONE; } return model.modelKind(); }
  String modelName() { if (model == null) { return "none"; } return model.name(); }

  int clamp(int v) {
    if (v < 0) { return 0; }
    if (v > 100) { return 100; }
    return v;
  }

  String yn(boolean b) { if (b) { return "yes"; } return "no"; }

  String describe() {
    return MODULE + " name=" + name + " model=" + modelName()
         + " cash=" + cashCents + " reputation=" + reputation
         + " grit=" + grit + " thriving=" + yn(thriving())
         + " standing=" + yn(stillStanding());
  }
}