Oh dear Lord, don’t take me as an example.
There may be no best way to code a game like this, but the kindest that can be said for XoR’s winter segment is that it might not be the worst way.
Edit: with that possibly unhelpful gut reaction out of the way, here are some thoughts to get you rolling, which I hope better coders will correct and improve!
In XoR, I had a “freefollowers” variable that measured how many adults remained free for each weekly mission. Each mission subtracted “freefollowers” when you committed to it. Anyone killed on the mission would be deducted from “followers”. At the end of each week, I’d *set freefollowers followers.
So in your case, you could use variables like free_w (or freewarriors – do whatever’s clearest to you), free_h, and free_v which are reduced when the player commits people of that caste. Any losses in the missions come out of different variables for warriors, hunters, and villagers. Reset the “free-” variables at the end of each week to match the actual totals, e.g. *set free_w warriors
and so on.
Put the choice for the player to lead (any) mission in a gosub that only appears before the mission if me_lead is 0. Set me_lead 2 when the player chooses to lead a mission. Set me_lead 0 again at the end of the week.
You’ll want a gosub that sets how many people of each subgroup are on the current mission, which will need variables like mission_w, mission_h, and mission_v. If you want the player to have total freedom to send as many w’s, h’s and v’s as they want, that would need to be three consecutive *input_number
s for those variables. (Note that this may feel tedious to your players! It was one of the biggest problems with the winter section of XoR, leading me to reduce input_numbers, though not enough for everyone’s taste.) You would then add those three variables up to get a variable for the total, say “mission_t”. You’ll also deduct them from free_w, free_h, and free_v, so they’re not available for other missions this week.
When the player picks the rescue mission, that takes you to a rescue gosub that narrates that mission. Within that gosub, the goblins attack *if mission_t < 20
. The combat strength of your rescuers (let’s call it strength_mission) is ((mission_w*3)+(mission_h*2))+(mission_v)
. If me_lead is 2, that tells the game that you’re leading this mission; throw in a little flavor text to let the player know they’re there, then reduce me_lead to 1 (which signals that your leadership bonus for this week has been spent), and add your combat strength to strength_mission.
If strength_mission < 40
, you lose the combat and don’t get a victory variable e.g. combat_won
set true. Some arrangement of nested gosubs will be the most efficient way to handle combat results – though what I’m about to propose is almost certainly not the most efficient way of doing it! But I might put a *gosub combat_results
after every combat that takes you to:
*label combat_results
*label warrior_check
*if w_count < mission_w
*rand death 1 20
*if (death = 1) or (not(combat_won) and (death <= 2))
*set warriors -1
*set w_count +1
*goto warrior_check
*comment This should repeat the chance of losing one warrior until you've faced the risk with all "mission_w" warriors that you brought on the mission. Then it'll roll on to the same thing with the hunters and villagers...
*label hunter_check
*if h_count < mission_h
*rand death 1 20
*if (death = 1) or (not(combat_won) and (death <= 2))
*set hunters -1
*set h_count +1
*goto hunter_check
*label villager_check
*if v_count < mission_v
*rand death 1 20
*if (death = 1) or (not(combat_won) and (death <= 2))
*set villagers -1
*if (death >= 19)
*comment this is where if you won, there's a 10 percent chance to convert a villager to a warrior
*set villagers -1
*set warriors +1
*set v_count +1
*goto villager_check
*return
You’d then return from calculating combat results to the rescuer mission gosub. If combat_won is true, you set villagers +10. At the end of every gosub where there’s combat, *set combat_won false
so that the next mission doesn’t benefit from victory in the current one. Also reset mission_w, mission_h, mission_v, and mission_t to zero.
That may be enough to be starting with… 