Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rebuild3.events
- {
- import flash.utils.Dictionary;
- import rebuild3.*;
- import rebuild3.colins.*;
- import rebuild3.events.*;
- import rebuild3.events.quests.*;
- import rebuild3.factions.*;
- import rebuild3.fort.*;
- import rebuild3.game.*;
- import rebuild3.game.sound.*;
- import rebuild3.game.starling.*;
- import rebuild3.gui.*;
- import rebuild3.gui.main.*;
- import rebuild3.gui.text.*;
- import rebuild3.gui.widgets.*;
- import rebuild3.map.*;
- import rebuild3.missions.*;
- /**
- * Contains static functions for executing daily morale events.
- *
- * @author Sarah Northway
- */
- public class MoraleEvents extends EventsBase
- {
- public function MoraleEvents()
- {
- }
- /**
- * Only run in midgame and later when people are at least somewhat unhappy.
- */
- public static function frequency():Number
- {
- if (Config.ONLY_ALLOWED_EVENTS != null && Config.ONLY_ALLOWED_EVENTS != "morale") {
- return 0;
- }
- if (Context.fort.happiness >= 40) {
- return 0;
- }
- if (Context.city.day < DayManager.MORALE_START_DAY) {
- return 0;
- }
- return 1;
- }
- /**
- * Warn that survivors are unhappy.
- */
- public static function warnUnhappy():Result
- {
- var colin:Colin = ColinManager.pickUnhappyColin();
- if (colin == null) {
- return null;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_WARN);
- result.mentionedColin = colin;
- return result;
- }
- public static function suicide():Result
- {
- if (Context.fort.happiness >= 20) {
- return null;
- }
- var colin:Colin = ColinManager.pickUnhappyColin();
- if (colin == null) {
- return null;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_SUICIDE);
- result.mentionedColin = colin;
- result.killMentionedColin("death_suicide");
- return result;
- }
- /**
- * Two unhappy colins fight. One is injured or dies, you can decide how the other
- * is punished.
- */
- public static function fight():Result
- {
- if (Context.fort.happiness >= 30) {
- return null;
- }
- // peacekeeper perk often prevents fights, but MORALE_FIGHT event still flagged as happened
- var peacekeeper:Colin = ColinManager.colinWithPerk(PerkType.PEACEKEEPER);
- if (peacekeeper != null && Utils.getRandChance(2, 3)) {
- var resultAverted:Result = Text.fillEventResult(EventType.MORALE_FIGHT_AVERTED);
- resultAverted.mentionedColin = peacekeeper;
- return resultAverted;
- }
- var result:Result = new Result();
- // mentionedColin is the culprit
- var culprit:Colin = ColinManager.pickUnhappyColin(null, [result.mentionedColin]);
- if (culprit == null) {
- Utils.log("Could not find a fight killer colin.");
- return null;
- }
- result.mentionedColin = culprit;
- // mentionedColin2 is the victim
- var victim:Colin = ColinManager.pickUnhappyColin();
- if (victim == null) {
- Utils.log("Could not find a fight victim colin.");
- return null;
- }
- result.mentionedColin2 = victim;
- // jail time is same as injury
- // makes the perp unhappy and everyone else happy
- var option1:Function = function(result:Result):Result {
- Text.fillEventResult(1, result);
- result.injureMentionedColin(false, true);
- // will gain happiness from vacation mission to make up for this
- result.addHappinessColin(-25, "happy_fightJailed");
- result.addHappiness(5, "happy_fightJustice");
- return result;
- }
- // kick out of the fort (like killing), makes people happy
- var option2:Function = function(result:Result):Result {
- Text.fillEventResult(2, result);
- result.killMentionedColin("death_fightExile", false);
- result.addHappiness(10, "happy_fightExile"); // death will be -5 so net is +5
- return result;
- }
- // do nothing
- var option3:Function = function(result:Result):Result {
- Text.fillEventResult(3, result);
- return result;
- }
- // default to an injury
- Text.fillEventResult(EventType.MORALE_FIGHT, result, [option1, option2, option3]);
- // victim dies sometimes instead of just injury
- // sometimes the text will say there's no evidence, etc, but options always the same
- var chanceOfDeath:Number = (30 - Context.fort.happiness) * (100 / 30);
- if (ColinManager.injuryNotDeath(result.mentionedColin2, chanceOfDeath)) {
- ColinManager.injureColin(result.mentionedColin2, result);
- }
- if (result.injuredColins.length == 0) {
- // replace "fight" with "fightDeath" text
- result.killMentionedColin("death_fight", true, true);
- Text.replaceEventResult("fightDeath", result);
- }
- return result;
- }
- public static function deserter():Result
- {
- if (Context.fort.happiness >= 30) {
- return null;
- }
- var faction:Faction = Utils.pickRandom(Context.city.factions);
- if (faction == null) {
- return null;
- }
- var colin:Colin = ColinManager.pickUnhappyColin();
- if (colin == null) {
- return null;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_DESERTER, null,
- null, faction.type.shortName);
- result.mentionedColin = colin;
- result.killMentionedColin("death_unhappyDeserted");
- return result;
- }
- public static function riots():Result
- {
- if (Context.fort.happiness >= 20) {
- return null;
- }
- // peacekeeper perk often prevents riots, but MORALE_RIOTS event still flagged as happened
- var peacekeeper:Colin = ColinManager.colinWithPerk(PerkType.PEACEKEEPER);
- if (peacekeeper != null && Utils.getRandChance(2, 3)) {
- var resultAverted:Result = Text.fillEventResult(EventType.MORALE_RIOTS_AVERTED);
- resultAverted.mentionedColin = peacekeeper;
- return resultAverted;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_RIOTS);
- result.addEffect(City.EFFECT_RIOTING, 2);
- return result;
- }
- public static function theft():Result
- {
- if (Context.fort.numFood < 5) {
- return null;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_THEFT);
- var percentStolen:Number = Utils.getRandomNumber(0.10, 0.25);
- var numFoodStolen:int = Context.fort.numFood * percentStolen;
- numFoodStolen = Utils.minMax(numFoodStolen, 2, 100);
- result.addFood( -1 * numFoodStolen);
- return result;
- }
- /**
- *
- Someone wants to kill themselves, what do you do?
- talk them out of it (requires level 8 leader, lose the depressed trait)
- offer them time off (they go on a recovery mission, lose the depressed trait)
- do nothing (they gain the depressed trait & may kill themselves/leave/repeat later)
- */
- public static function depression():Result
- {
- var colin:Colin = ColinManager.pickUnhappyColin();
- if (colin == null) {
- return null;
- }
- // talk
- var option1:Function = function(result:Result):Result {
- Text.fillEventResult(1, result);
- result.mentionedColin = colin;
- result.addHappinessColin(20, "happy_depressionTalk");
- return result;
- }
- if (!ColinManager.fortHasSkillLevel(Colin.SKILL_LEADERSHIP, 7)) {
- option1 = Result.OPTION_DISABLED;
- }
- // time off
- var option2:Function = function(result:Result):Result {
- Text.fillEventResult(2, result);
- result.mentionedColin = colin;
- result.injureMentionedColin(false, true);
- // 20 happiness now, more for every day of the vacation
- result.addHappinessColin(20, "happy_depressionTimeOff");
- return result;
- }
- // leave him alone
- var option3:Function = function(result:Result):Result {
- Text.fillEventResult(3, result);
- result.mentionedColin = colin;
- result.addHappinessColin(-10, "happy_depressionAlone");
- return result;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_DEPRESSION,
- null, [option1, option2, option3]);
- result.mentionedColin = colin;
- return result;
- }
- /**
- * Someone wants to join another faction, do you let them?
- *
- * yes (+ faction like)
- * talk them out of it (+ happiness)
- * bribe them to stay (double rations, + happiness)
- *
- */
- public static function wantsToLeave():Result
- {
- var colin:Colin = ColinManager.pickUnhappyColin();
- if (colin == null) {
- return null;
- }
- var faction:Faction = Utils.pickRandom(Context.city.factions);
- if (faction == null) {
- return Result.RESULT_DISABLE;
- }
- var option1:Function = function(result:Result):Result {
- Text.fillEventResult(1, result);
- result.mentionedColin = colin;
- result.faction = faction;
- result.addHappinessColin(20, "happy_leaveTalk");
- return result;
- }
- if (!ColinManager.fortHasSkillLevel(Colin.SKILL_LEADERSHIP, 7)) {
- option1 = Result.OPTION_HIDDEN;
- }
- var option2:Function = function(result:Result):Result {
- Text.fillEventResult(2, result);
- result.mentionedColin = colin;
- result.faction = faction;
- result.addHappinessColin(20, "happy_leaveRations");
- colin.addPerk(PerkType.DOUBLE_RATIONS);
- return result;
- }
- var option3:Function = function(result:Result):Result {
- Text.fillEventResult(3, result);
- result.mentionedColin = colin;
- result.faction = faction;
- result.killMentionedColin("death_wantsToLeave", false,
- false, false, false, faction.type.factionName);
- faction.addRespect(5, result);
- return result;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_WANTS_TO_LEAVE,
- null, [option1, option2, option3]);
- result.mentionedColin = colin;
- result.faction = faction;
- return result;
- }
- /**
- * Bob's having some kind of breakdown.
- He's waving a gun and threatening to open the gates beside the McNoodles.
- The zed on the other side are all riled up, maybe two dozen of them ready to pile
- through the instant he raises that latch. What do you do?
- talk him down
- if you have a level 8 leader you succeed
- if not it triggers a zombie attack
- shoot him before he opens the latch
- convince him to leave the rest of the fort out of this
- he shoots himself
- */
- public static function gateBreakdown():Result
- {
- var colin:Colin = ColinManager.pickUnhappyColin();
- if (colin == null) {
- return null;
- }
- var toSquare:Square = FortUtils.getLeastDefenseSquare();
- if (toSquare == null) {
- return null;
- }
- var option1:Function = function(result:Result):Result {
- Text.fillEventResult(1, result);
- result.addHappinessColin(20, "happy_breakdownTalk");
- return result;
- }
- if (!ColinManager.fortHasSkillLevel(Colin.SKILL_LEADERSHIP, 7)) {
- option1 = Result.OPTION_HIDDEN;
- }
- var option2:Function = function(result:Result):Result {
- Text.fillEventResult(2, result);
- result.killMentionedColin("death_breakdownShot");
- return result;
- }
- var option3:Function = function(result:Result):Result {
- // bad defense leads to death and gate opening
- if (!Utils.getRandChance(Context.fort.fortDefense, 100)) {
- Text.fillEventResult("gateBreakdown_outcome3Gates", result);
- result.killMentionedColin("death_breakdownGates");
- FortUtils.loseSquare(toSquare, result);
- // better defense leads to suicide
- } else {
- Text.fillEventResult("gateBreakdown_outcome3Suicide", result);
- result.square = toSquare;
- result.mentionedColin = colin;
- result.killMentionedColin("death_breakdownSuicide");
- }
- return result;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_GATE_BREAKDOWN,
- null, [option1, option2, option3]);
- result.square = toSquare;
- result.mentionedColin = colin;
- return result;
- }
- /**
- * Someone gets angry about not having a city hall yet.
- */
- public static function needCityhall():Result
- {
- // must be ready to build a city hall for the last week but not have one yet
- if (FortSquaresManager.fortSquaresOfType(SquareType.cityHall).length > 0) {
- return null;
- }
- if (!EventsBase.minDaysSinceEvent(EventType.WIN_CAN_BUILD_CITYHALL, 7, true)) {
- return null;
- }
- var colin:Colin = ColinManager.pickUnhappyColin();
- if (colin == null) {
- return null;
- }
- var result:Result = Text.fillEventResult(EventType.MORALE_NEED_CITYHALL);
- result.mentionedColin = colin;
- result.addHappinessColin(-20, "happy_needCityHall");
- return result;
- }
- /**
- * Divide the totalAmount of happiness among random living colins in full chunks of amountPerColin.
- * If there is a remainder, it will randomly given or not a percentage of the time.
- */
- private static function divvyHappiness(totalAmount:Number, amountPerColin:Number,
- reasonTextId:String, doubleColins:Vector.<Colin> = null, noneColins:Vector.<Colin> = null):void
- {
- //lets keep this positive for now
- if ( amountPerColin < 0 ) {
- amountPerColin *= -1;
- }
- // for pretty sake set amountPerColin to multiples of 5 with a minimum of 5
- amountPerColin = Utils.minMax(5 * Math.round(amountPerColin / 5), 5);
- // 1.5 colins will become 1 half the time and 2 half the time
- var numColins:int = Utils.randomRound(Math.abs(totalAmount) / amountPerColin);
- numColins = Utils.minMax(numColins, 0, ColinManager.numLivingColins);
- if (numColins == 0) {
- return;
- }
- //now lets set amountPerColin to have the right sign
- if ( totalAmount < 0 ) {
- amountPerColin *= -1;
- }
- Utils.randomizeVector(ColinManager.livingColins);
- for (var i:int = 0; i < numColins; i++) {
- var colin:Colin = ColinManager.livingColins[i];
- if (noneColins != null) {
- if (Utils.vectorContains(noneColins, colin)) {
- continue;
- }
- }
- if (doubleColins != null) {
- if (Utils.vectorContains(doubleColins, colin)) {
- // no result since this is during daily happiness
- colin.addHappinessNoResult(amountPerColin * 2, reasonTextId, true);
- continue;
- }
- }
- // no result since this is during daily happiness
- colin.addHappinessNoResult(amountPerColin, reasonTextId, true);
- }
- }
- /**
- * Called every day, rain or shine. Increases or decreases happiness based on policies etc.
- * http://my.hrw.com/math06_07/nsmedia/tools/Graph_Calculator/graphCalc.html
- */
- public static function dailyHappiness():void
- {
- var colin:Colin;
- var i:int;
- var possibleColins:Vector.<Colin>;
- var numColins:int;
- var originalHappiness:Number = Context.fort.happiness;
- // churches and bars
- // bars and churches give one guy 2% per day no matter how many people there are
- // to balance overcrowding you need 1 bar for 10 guys but 100 bars for 100 guys
- // so you need exponentially more over time to balance overcrowding
- // with 10 colins, 1 bars give 1 guys 2% per day = (1 * 2) / (10 * 100) = fort av 0.2%
- // with 20 colins, 4 bars give 4 guys 2% per day = (4 * 2) / (20 * 100) = fort av 0.4%
- // with 50 colins, 25 bars give 25 guys 2% per day = (25 * 2) / (50 * 100) = fort av 1%
- // with 100 colins, 100 bars give 100 guys 2% per day = (100 * 2) / (50 * 100) = fort av 2%
- var pointsPerBuilding:Number = 2;
- var numBars:int = FortSquaresManager.fortSquaresOfType(SquareType.bar).length;
- var barPoints:Number = numBars * pointsPerBuilding;
- if (ColinManager.hasMainLeaderPerk(PerkType.MAIN_STUDENT)) {
- barPoints *= 1.25;
- }
- var numChurches:int = FortSquaresManager.numChurches;
- var churchPoints:Number = numChurches * pointsPerBuilding;
- // leading missions add extra points and are handled here, not in mission
- var preachers:Vector.<Colin> = new Vector.<Colin>();
- var bartenders:Vector.<Colin> = new Vector.<Colin>();
- for each (var mission:Mission in Context.fort.missions) {
- var leadMission:MissionPostLead = mission as MissionPostLead;
- if (leadMission == null || !leadMission.started || leadMission.finished) {
- continue;
- }
- if (leadMission.square.type == SquareType.bar) {
- barPoints += leadMission.happinessMultiplier * pointsPerBuilding;
- bartenders = Utils.unionVectors(bartenders, leadMission.colins);
- } else if (leadMission.square.type == SquareType.church) {
- churchPoints += leadMission.happinessMultiplier * pointsPerBuilding;
- preachers = Utils.unionVectors(preachers, leadMission.colins);
- } else {
- Utils.logError("Unexpected square for lead mission, ", mission.square);
- }
- }
- var preacher:Colin = Utils.pickRandom(preachers);
- var bartender:Colin = Utils.pickRandom(bartenders);
- if (PolicyOption.CHURCHVBAR_BAR.chosen) {
- barPoints *= 2;
- churchPoints /= 2;
- } else if (PolicyOption.CHURCHVBAR_CHURCH.chosen) {
- barPoints /= 2;
- churchPoints *= 2;
- }
- if (PolicyOption.PRIORITY_RELIGION.chosen) {
- churchPoints *= 2;
- }
- var skepticColins:Vector.<Colin> = ColinManager.colinsWithPerk(PerkType.SKEPTIC);
- var devoutColins:Vector.<Colin> = ColinManager.colinsWithPerk(PerkType.DEVOUT);
- // if there's a bartender divvy points in chunks of +15 and mention bartender instead of usual +10
- var barReasonId:String = (bartender != null) ? "happy_bartender" : "happy_bar";
- var barDivvyAmount:int = (bartender != null) ? 15 : 10;
- divvyHappiness(barPoints, barDivvyAmount, barReasonId, skepticColins, devoutColins);
- var churchReasonId:String = (preacher != null) ? "happy_preacher" : "happy_church";
- var churchDivvyAmount:int = (preacher != null) ? 15 : 10;
- divvyHappiness(churchPoints, churchDivvyAmount, churchReasonId, devoutColins, skepticColins);
- // up to 10% of living colins may comment on stuff every day
- numColins = Utils.randomRound(0.10 * ColinManager.livingColins.length);
- // lategame upset affects 10% of colins
- // based on the size of the fort so that getting by with fewer people is a legit strategy
- // http://my.hrw.com/math06_07/nsmedia/tools/Graph_Calculator/graphCalc.html
- // with 10 colins, 0.5% happy lost, 1 colin loses 5 happiness per day
- // with 15 colins, 0.75% happy lost, 1.5 colins lose 7.5 happiness per day
- // with 20 colins, 1% fort happy lost, 2 colins lose 10 happiness per day
- // with 50 colins, 2% fort happy lost, 5 colins lose 20 happiness per day
- // with 100 colins, 3% fort happy lost, 10 colins lose 30 happiness per day
- if (numColins > 0 && (DayManager.isLategame || ColinManager.numLivingColins >= 10)) {
- // can lose devout if there are no churches, with a minus to happiness
- if (numChurches == 0) {
- if (Utils.getRandChance(1, 30)) {
- var randomDevout:Colin = ColinManager.colinWithPerk(PerkType.DEVOUT);
- if ( randomDevout != null && !randomDevout.hasPerk(PerkType.MAIN_PRIEST)) {
- randomDevout.removePerk(PerkType.DEVOUT);
- randomDevout.addHappinessNoResult( -40, "happy_noChurch", true);
- }
- } else if (Utils.getRandChance(1, 30)) {
- var randomCultist:Colin = ColinManager.colinWithPerk(PerkType.CULTIST);
- if ( randomCultist != null ) {
- randomCultist.removePerk(PerkType.CULTIST);
- randomCultist.addHappinessNoResult( -40, "happy_noChurch", true);
- }
- }
- }
- // x ^ (0.5) * 0.4 * 10 - 8
- // colinsSlice should be 10 but randomRound might have made it more or less
- var colinsSlice:Number = (ColinManager.livingColins.length / numColins);
- var upsetPer:Number = Math.pow(ColinManager.numLivingColins, 0.5) * 0.4 * colinsSlice - 8;
- // later halve it and divvy it among 2x as many people
- if (upsetPer >= 10) {
- var numColinsLategameUpset:int = numColins * 2;
- upsetPer = Utils.minMax(Utils.randomRound(upsetPer / 2), 1);
- }
- // for pretty sake set upsetPer to multiples of 5 with a minimum of 5
- upsetPer = Utils.minMax(5 * Math.round(upsetPer / 5), 5);
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColinsLategameUpset; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- // for flavor and info, complain about various things
- // all of these generic complaints start with a * because we collapse them together
- // when we show them to the user and then parse the star off the front.
- var lategameReasons:Array = [];
- lategameReasons.push("happy_lategameRandom");
- if (FortSquaresManager.numSquareChunks > 10) {
- lategameReasons.push("happy_lategameBigFort");
- }
- if ( FortSquaresManager.numChurches < ColinManager.livingColins.length/10 && colin.hasPerk(PerkType.DEVOUT) ) {
- lategameReasons.push("happy_lategameChurches");
- }
- if ( FortSquaresManager.numBars < ColinManager.livingColins.length/10 && !colin.hasPerk(PerkType.DEVOUT) ) {
- lategameReasons.push("happy_lategameBars");
- }
- if ((ColinManager.colinSlotsAvail / FortSquaresManager.numHouses) < 0.10) {
- lategameReasons.push("happy_lategameHouses");
- }
- if (Context.fort.goats.length == 0) {
- lategameReasons.push("happy_lategameGoats");
- }
- if (!colin.hasPerk(PerkType.EQUIPMENT_RECREATION) && !colin.hasPerk(PerkType.MUSICIAN)
- && !colin.hasPerk(PerkType.EASYGOING)) {
- lategameReasons.push("happy_lategameRecreation");
- }
- if (!colin.hasPerk(PerkType.EQUIPMENT_PET) && !colin.hasPerk(PerkType.EQUIPMENT_GOAT)
- && RelationshipManager.getFriends(colin).length == 0) {
- lategameReasons.push("happy_lategamePet");
- }
- if (!FortSquaresManager.hasWorkingPowerPlant && !FortSquaresManager.hasWorkingWaterPlant) {
- lategameReasons.push("happy_lategameAmmenities");
- }
- // not grouped with the others (no *) so we'll see this separately, and it's more likely
- if (colin.mission.danger > 10) {
- lategameReasons.push("happy_lategameDanger");
- lategameReasons.push("happy_lategameDanger");
- lategameReasons.push("happy_lategameDanger");
- }
- var lategameReasonId:String = Utils.pickRandom(lategameReasons);
- colin.addHappinessNoResult(-1 * upsetPer, lategameReasonId, true);
- }
- }
- // policies
- // food policy makes people happy or sad
- if (PolicyOption.RATIONS_HALF.chosen || PolicyOption.RATIONS_DOUBLE.chosen) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- if (PolicyOption.RATIONS_HALF.chosen) {
- colin.addHappinessNoResult(-5, "happy_rationsReduced", true);
- } else if (PolicyOption.RATIONS_DOUBLE.chosen) {
- colin.addHappinessNoResult(5, "happy_rationsIncreased", true);
- }
- }
- }
- // non-soldiers are unhappy about forced guard duty
- if (PolicyOption.GUARD_MANDATORY.chosen) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- if (colin.getFullSkillLevel(Colin.SKILL_DEFENSE) < 1) {
- colin.addHappinessNoResult(-10, "happy_mandatoryGuard", true);
- }
- }
- }
- // devout men and women soldiers have opinions on women staying home or learning to shoot
- if (PolicyOption.WOMEN_STAYHOME.chosen || PolicyOption.WOMEN_EVEN.chosen) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- // devout men want women to stay home
- if (colin.hasPerk(PerkType.DEVOUT) && colin.isMale) {
- if (PolicyOption.WOMEN_STAYHOME.chosen) {
- colin.addHappinessNoResult(10, "happy_womenHomeHappy", true);
- } else {
- colin.addHappinessNoResult(-10, "happy_womenAwaySad", true);
- }
- // devout women non-soldiers hate guns
- } else if (colin.hasPerk(PerkType.DEVOUT) && !colin.isMale && colin.currentSkill != Colin.SKILL_DEFENSE) {
- if (PolicyOption.WOMEN_STAYHOME.chosen) {
- colin.addHappinessNoResult(10, "happy_womenHomeHappyFemale", true);
- } else {
- colin.addHappinessNoResult(-20, "happy_womenAwaySadFemale", true);
- }
- // non-devout women are gain / lose skill
- } else if (!colin.hasPerk(PerkType.DEVOUT) && !colin.isMale) {
- if (PolicyOption.WOMEN_STAYHOME.chosen) {
- colin.adjustSkill(Colin.SKILL_DEFENSE, -5);
- colin.addHappinessNoResult(-10, "happy_womenHomeSadFemale", false);
- } else {
- colin.adjustSkill(Colin.SKILL_DEFENSE, 3);
- colin.addHappinessNoResult(10, "happy_womenAwayHappyFemale", false);
- }
- }
- }
- }
- // devout like drug ban but addicts don't
- if (PolicyOption.DRUGS_BAN.chosen) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- if (colin.hasPerk(PerkType.ADDICT)) {
- // once a week on average addicts will lose their addiction
- if (Utils.getRandChance(1, 7 * numColins)) {
- colin.removePerk(PerkType.ADDICT);
- colin.addHappinessNoResult( 10, "happy_addictCured", true);
- // the rest of the time they're just unhappy
- } else {
- colin.addHappinessNoResult( -10, "happy_addictBan", true);
- }
- } else if (colin.hasPerk(PerkType.DEVOUT)) {
- colin.addHappinessNoResult(10, "happy_addictDevout", true);
- }
- }
- }
- // banning church of chosen ones upsets those guys
- if (PolicyOption.CHOSEN_BAN_YES.chosen) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- if (colin.hasPerk(PerkType.CULTIST)) {
- if (Utils.getRandChance(1, 10)) {
- colin.removePerk(PerkType.CULTIST);
- colin.addHappinessNoResult(-40, "happy_chosenBannedQuit", true);
- } else {
- colin.addHappinessNoResult(-10, "happy_chosenBanned", true);
- }
- }
- }
- }
- // whoever gets the best stuff is happy
- if (PolicyOption.WEALTH_SKILLED.chosen || PolicyOption.WEALTH_HARDWORK.chosen || PolicyOption.WEALTH_SOLDIERS.chosen) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- //have to be two skill points better than the average, or level 10
- var averageSkillLevel:Number = ColinManager.getAverageSkillLevel();
- var wealthyLevel:int = Utils.minMax(averageSkillLevel + 2, 0, 10);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- // inequality is good times for very skilled survivors, less for the unskilled
- if (PolicyOption.WEALTH_SKILLED.chosen) {
- if (colin.currentLevel >= wealthyLevel) {
- colin.addHappinessNoResult(10, "happy_wealthSkilled", true);
- } else {
- colin.addHappinessNoResult( -5, "happy_wealthSkilledNo", true);
- }
- // hard work is rewarded... anyone on non-post missions is rewarded but nobody's unhappy
- } else if (PolicyOption.WEALTH_HARDWORK.chosen) {
- if (!(colin.mission is MissionPost)) {
- colin.addHappinessNoResult(5, "happy_wealthWork", true);
- }
- } else if (PolicyOption.WEALTH_SOLDIERS.chosen) {
- if (colin.currentSkill == Colin.SKILL_DEFENSE) {
- colin.addHappinessNoResult(10, "happy_wealthSoldiers", true);
- } else {
- colin.addHappinessNoResult( -5, "happy_wealthSoldiersNo", true);
- }
- }
- }
- }
- // more vs less taxes and public property
- if (PolicyOption.PROPERTY_PUBLIC.chosen || PolicyOption.PROPERTY_PRIVATE.chosen) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- // all property is public property
- if (PolicyOption.PROPERTY_PUBLIC.chosen) {
- colin.addHappinessNoResult( -5, "happy_propertyPublic", true);
- // all property is private property, no "taxes"
- } else if (PolicyOption.PROPERTY_PRIVATE.chosen) {
- colin.addHappinessNoResult(5, "happy_propertyPublicNo", true);
- }
- }
- }
- // electricity uses fuel but gains happiness, so long as we have fuel
- if ((PolicyOption.POWER_SOMETIMES.chosen || PolicyOption.POWER_ALWAYS.chosen)
- && FortSquaresManager.hasWorkingPowerPlant) {
- var currentFuel:Number = Context.fort.getNumResource(ResourceType.FUEL);
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- // being out of fuel makes people sad
- if (currentFuel < 0.5) {
- colin.addHappinessNoResult(-1, "happy_powerFuel", true);
- // run power in the morning and evening
- } else if (PolicyOption.POWER_SOMETIMES.chosen) {
- colin.addHappinessNoResult(3, "happy_powerSometimes", true);
- // run it all the time
- } else if (PolicyOption.POWER_ALWAYS.chosen) {
- colin.addHappinessNoResult(6, "happy_powerAlways", true);
- }
- }
- // lose 1-2 fuel per week
- if (PolicyOption.POWER_SOMETIMES.chosen) {
- Context.fort.setNumResource(ResourceType.FUEL, currentFuel - (1 / 7));
- } else if (PolicyOption.POWER_ALWAYS.chosen) {
- Context.fort.setNumResource(ResourceType.FUEL, currentFuel - (2 / 7));
- }
- }
- // showers make people happy but might cause injury due to thirst in a random event
- if ((PolicyOption.SHOWER_SOMETIMES.chosen || PolicyOption.SHOWER_ALWAYS.chosen)
- && FortSquaresManager.hasWorkingWaterPlant) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- // shower once a week
- if (PolicyOption.SHOWER_SOMETIMES.chosen) {
- colin.addHappinessNoResult(2, "happy_waterSometimes", true);
- // shower all the time
- } else if (PolicyOption.SHOWER_ALWAYS.chosen) {
- colin.addHappinessNoResult(4, "happy_waterAlways", true);
- }
- }
- }
- // banshee keeps people awake at night
- if (Context.city.hasEffect(City.EFFECT_BANSHEE)) {
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- colin.addHappinessNoResult(-10, "happy_banshee", true);
- }
- }
- // check 10% of people for cats etc
- possibleColins = Utils.cloneVector(ColinManager.livingColins, true);
- for (i = 0; i < numColins; i++) {
- colin = possibleColins.pop();
- if (colin == null) {
- break;
- }
- if (colin.hasPerk(PerkType.EQUIPMENT_PET) && colin.nonweapon != null && colin.nonweapon.type.isPet) {
- if (colin.hasPerk(PerkType.ANIMAL_LOVER)) {
- colin.addHappinessNoResult(10, "happy_petLove", true,
- colin.nonweapon.type.typeName, colin.nonweapon.properName);
- } else {
- colin.addHappinessNoResult(5, "happy_pet", true,
- colin.nonweapon.type.typeName, colin.nonweapon.properName);
- }
- }
- if (colin.hasPerk(PerkType.EQUIPMENT_GOAT) && colin.nonweapon != null && colin.nonweapon.type.isGoat) {
- colin.addHappinessNoResult(10, "happy_goat", true, colin.nonweapon.properName);
- }
- }
- // change colin stats based on their new happiness
- Context.fort.calculateHappiness();
- // record whether happiness increased or decreased today for the hud
- // it involves randomness so this is only an estimate
- // average with 2x yesterday's so it doesn't change too quickly
- var happinessChange:Number = Context.fort.happiness - originalHappiness;
- var averageChange:Number = happinessChange * 1/3 + Context.fort.lastDailyHappinessChange * 2/3;
- Context.fort.lastDailyHappinessChange = averageChange;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement