Repository navigation
Adding a News Story
Please limit your stories to 50 or less character titles and 100 or less words (though fewer is always better). To add a new story to the newspaper, you will need to incorporate it in the following ways:
- What is going to trigger the story? Options here include:
- General daily story check?
OnMsg.MartianTribuneCheckStories() - Tech researched?
OnMsg.TechResearched(tech_status, city, first_time) - Colonist born?
OnMsg.ColonistBorn(colonist) - Colonist died?
OnMsg.ColonistDied(colonist, reason) - Colonist leaving Mars?
OnMsg.ColonistLeavingMars(colonist, rocket) - Colonist Earthsick, Starving, Freezing, Dehydrated, Suffocating, Homeless, Unemployed, Stressed Out?
OnMsg.ColonistStatusEffect(colonist, status_effect, bApply)- If bApply is defined, status_effect is active. If bApply is nil, status_effect just ended. Status Effect will be one of:StatusEffect_Earthsick,StatusEffect_Starving,StatusEffect_Freezing,StatusEffect_Dehydrated,StatusEffect_Suffocating(inside a dome),StatusEffect_Suffocating_Outside(outside a dome),StatusEffect_Homeless,StatusEffect_Unemployed,StatusEffect_StressedOut,StatusEffect_Irradiated(Mirror Sphere mystery). - Building Construction Complete? - Read below, do not use OnMsg.ConstructionComplete(building) as it fires before the building has been added to the UICity.labels.XXX categories, etc. You'll need to modify
<BuildingClass>.GameInit(...)instead. - Building Breakdown?
-
OnMsg.MartianTribuneBuildingMalfunction(building)for random (e.g. idiot) breakages. -
OnMsg.MartianTribuneUnmaintainedBuildingBroken(building)for breakages due to lack of maintenance.
-
- General daily story check?
- What is the story?
- What data does it need (e.g. colonist name, building name, sponsor, leader title, leader name, etc.)
- Are there any circumstances under which the story should not be published even if it had previously been added as a potential story? (e.g. a story talking about "current warmer weather" probably shouldn't be published in the middle of a Cold Wave).
Think also about things like "what if someone loads this into a pre-existing game for the first time"? Should the story become available? For example, a tech researched story is likely to need two triggers - one for when it was actually researched, and the general daily check. This means that if the story had conditions that were not met at the time when it was researched (e.g. needed colonists, but colonists hadn't landed yet), it will get added to the story lists later when the conditions for the story are met. It also means that if a player had done the research in their game before loading Martian Tribune for the first time, they can still get the story if they meet the conditions for it.
For a new story that is not related to or a prequel/sequel to an existing story, you'll need to add a new file in the Code directory. These are currently named depending on what the story is specifically about.
- About a particular building:
Stories_Building_<BuildingClass>.lua - About a colonist/spoken by a colonist/a colonist's actions or state:
Stories_Colonist_<StoryShortName>.lua - About a drone:
Stories_Drones_<StoryShortName>.lua - About life support (including food):
Stories_LifeSupport_<StoryShortName>.lua - About tech researched:
Stories_Research_<TechId>.lua - Anything else:
Stories_General_<StoryShortName>.lua
After creating the new file, add the filename to the list of code files in both metadata.lua and items.lua (there's lots of examples in those files, just copy/paste/edit with the file in amongst the other story definition files - I've been keeping those listed alphabetically). Just make sure that it is listed amongst the story files (where load order no longer matters so long as they are loaded after Code/Initialization.lua), as the initialization/save-game-update and main control code do matter when it comes to the file loading order.
NOTE: Make sure that all functions and variables other than OnMsg or GameInit functions are declared as local. That stops us leaking data into the global namespace outside of the file it is declared in, greatly reducing the likelihood of causing an incompatibility with another mod. Our most likely incompatibility will be due to having to replace GameInit for some buildings - but we can minimize the likelihood that it is our fault that things are incompatible even so.
- At the top of the file, make a list of the story keys to use.
Optionally also include Ids for items that will be reused, e.g. TechId for a researched Tech story. Having it defined in a single place means a single place needs editing if you've made a typo. ;)
local Key1 = "StoryOption1" local Key2 = "StoryOption2"
- Create a function that checks the conditions for the story, and actually generates the story if those conditions are met.
If this is a story chain, you may have multiple CheckStory functions (CheckStory1(), CheckStory2(), etc).
local function CheckStory() -- take a local copy of the global MartianTribune data for faster access. local MartianTribune = MartianTribune -- list of Sent stories, as a short-name to make the conditions easier to read. local Sent = MartianTribune.Sent -- has the first set of colonists arrived on Mars? local ColonistsHaveArrived = MartianTribune.ColonistsHaveArrived -- Check story conditions: example for not yet generated and have at least 50 colonists if not Sent[Key1] and not Sent[Key2] and ColonistsHaveArrived and #UICity.labels.Colonist >= 50 then -- Pick which story queue this should be added to, and give the function a short name -- for easy reading. If this story is to be pushed the MartianTribune repository itself, -- please use the pattern "Add<type>Story" so that stats on the number of stories of each -- type can be generated from the source code. local AddSocialStory = MartianTribuneMod.Functions.AddSocialFreeStory -- For an either/or story, pick a random number 1 or 2 local random_num = Random(1,2) if random_num == 1 then -- Collect any data needed for the story -- Note: if both versions need the data, do this once before starting "if random_num == ..." local LeaderName = MartianTribune.LeaderName AddSocialStory({ key = Key1, -- story identifying key -- Pick an unused number in Locales/English.csv for the title, and copy the English -- translation into Locales/English.csv. title = T{901XXXX, "Colonists Rejoice"}, -- Pick an unused number in Locales/English.csv for the story content, and copy the -- English translation into Locales/English.csv story = T{901XXXX, " Yay, we have passed the 50 colonists mark! <LeaderName> throws a planetary party.", LeaderName = LeaderName} }) else local Sponsor = MartianTribune.Sponsor local NumFounders = MartianTribune.Count.NumFounders AddSocialStory({ key = Key2, title = T{901XXXX, "Sponsor Praises Growing Colony"}, story = T{901XXXX, " <Sponsor> has praised the efforts of the colony on Mars that has seen it grow from the original <NumFounders> colonists to more than 50 now.", Sponsor = Sponsor, NumFounders = NumFounders} }) end end end
- Add the story trigger function(s) that call the local story check function:
function OnMsg.MartianTribuneCheckStories() CheckStory() end
By using the MartianTribuneMod.Functions.AddXXXStory functions, all other details such as recording that the story was sent, putting the story into the right table, pinning a colonist when the story is published if a colonist was defined, etc are automatically handled for you.
I'll use the MOXIE building as the example for this section. For the MOXIE, there is an existing story (MoxieMagic) that is supposed to be sent when the first MOXIE is built on the planet. The function to check whether to send the story uses the condition:
if not Sent[Key1] and UICity.labels.MOXIE ~= nil then
...
endThe problem here is that if the ConstructionComplete(building) message is used as a trigger, UICity.labels.MOXIE will not yet have been created when the ConstructionComplete message is fired for the first MOXIE built. This causes a bug where the story gets delayed until the second MOXIE gets built instead.
Delaying the treatment of the construction of the MOXIE until after its GameInit function has been run means that UICity.labels.MOXIE will exist when we check the story for the first MOXIE built.
Example replacement:
-- Take a local copy of the original function before we modify anything. Essential!
local originalGameInit = MOXIE.GameInit
-- Declare our own override of the GameInit function. This acts as a *complete
-- replacement* to the existing GameInit function for all MOXIEs.
-- Using the parameter '...' means "all parameters in a list", so we don't need to
-- know exactly how many parameters there were, etc.
function MOXIE.GameInit(...)
-- Check if there *is* an original GameInit function, as not all classes define
-- one by default. Even if the class itself didn't define one another mod may
-- have done so. By checking, we maintain compatibility with the other mod
-- (provided that they also check for the possibility of someone defining the
-- GameInit function - if not, they need to update their mod for compatibility).
if originalGameInit then
-- Call the original function with the parameters we received. Without this,
-- anything that would normally occur inside the GameInit function for a
-- MOXIE won't happen - i.e. the game would break! *THIS* is why having the
-- local copy first was essential.
originalGameInit(...)
end
-- NOW we can safely check for whether to generate our story, as the
-- UICity.labels.MOXIE list will properly contain this first MOXIE that was
-- constructed.
CheckStory()
endIf we need the actual building itself inside our CheckStory function, we'd modify the function to use the ":" syntax instead of the "." syntax, which then gives access to the building being constructed in a special variable called self. The "." syntax rolls self into the ... parameters. The ":" syntax separates self out and makes it automatically available:
local originalGameInit = MOXIE.GameInit
-- Use ":" syntax in the function declaration
function MOXIE:GameInit(...)
if originalGameInit then
-- Note the addition of "self" before the parameters here. Very Important!
originalGameInit(self, ...)
end
-- pass "self" (the actual building that was constructed) into CheckStory.
CheckStory(self)
end