@civ-clone/base-government-change
v0.1.2
Published
How a player changes government: a revolution kept as a pending effect, the interim government while it lasts, how long it lasts, choosing the new one, which governments are available, and what a change sets off, for a ruleset to wrap in its own rules.
Readme
base-government-change
How a player changes government, for a ruleset to wrap in its own Added, Action, AnarchyDuration, Availability,
Changed, RevolutionTerms, MayRechoose, GovernmentAvailable and research Complete rules with its own ids,
governments and numbers:
Rules/AnarchyDuration: the rule asked how many turns of the interim government a revolution causes, for aRevolutionCause('chosen'or'civil-disorder'). The shortest answer wins.Rules/RevolutionTerms: the rule that names the ruleset's revolution, its handlerkeyandInterimgovernment, so code outside the ruleset (a computer player) can start and finish its revolutions throughlib/revolution.lib/termshasterms(key, Interim), the rule's effect, andrevolutionTerms(ruleRegistry), which reads it (nullwith no rule). A game has one ruleset's terms: if two are registered, the first answer wins.lib/revolution: a revolution kept as aPendingEffecton thePlayerGovernmentunder the ruleset's own handlerkey(a save names it).revolution(key, Interim, …)starts one,turnsUntilChoiceandpendingRevolutionread it,chooseGovernmentfinishes it (given the game's rules as its last argument, it also records the choice forMayRechoose), andregisterRevolutionHandlerlets one loaded from a save finish.RevolutionErroris what they throw.Rules/MayRechoose: whether a player may choose its government again, with no interim, in the turn it chose one. With no rule that says so, it may not.lib/rechoicekeeps the turn of the choice as aPendingEffecton thePlayerGovernmentunder<key>:rechoice(never discharged; the next choice replaces it;registerRevolutionHandlerregisters a handler for it that does nothing), written only whenchooseGovernmentis given the game's rules and aMayRechooserule says yes. In that turn, a revolution the player chooses ('chosen') starts no interim and makes the choice due at once, whateverAnarchyDurationsays.mayRechoose,chosenThisTurnandrechoiceOpenread it.Rules/GovernmentAvailableandlib/offer: offering a revolution when an advance makes a government available.offerGovernments(key, entries, …)is a researchCompleterule's effect: for each government that one ofentries(the ruleset's "government requires advances" entries) requires the discovered advance for, that the player may now choose (governmentsOpenedBy) and doesn't already have, unless a revolution underkeyis under way, it asks theGovernmentAvailable(player, government)rules, and when any says yes the engine emitsplayer:government:availablewith the player and the government. With noGovernmentAvailablerules, nothing is offered.lib/actions: the playerActioncriteria and effects:notInInterim,noRevolutionPendingandofferRevolution(Revolution), thenchoiceDueandofferGovernmentChoice(ChooseGovernment).lib/playerGovernment:addPlayerGovernment(player, Initial, …), for anAddedrule.lib/anarchyDuration:forCause(cause)andrandomDuration(min, max, rng), forAnarchyDurationrules.lib/availability:availabilityRulesFor(entry, …)andderiveAvailabilityRules(…), theAvailabilityrule a requirement entry ("government requires advances") is played by.lib/changed:emitGovernmentChanged,hasPlayerWorldandclearYieldCaches, forChangedrules.lib/governedBy:governedBy(player, governments, …), whether a player has one ofgovernments(no, when the player has none), for rules that depend on the government.
A library: it registers no rules. See civ1-government for Civilization's governments, durations and ids.
