# HG changeset patch # User Jeremy Thurgood # Date 1336767242 -7200 # Node ID f1efd252e8b09e4b15af4b2c01382ed5969cae20 # Parent dd277233538ca46f3a2db888703a167cdd59d788 Equipment power in missions. diff -r dd277233538c -r f1efd252e8b0 gamelib/missions.py --- a/gamelib/missions.py Fri May 11 21:59:33 2012 +0200 +++ b/gamelib/missions.py Fri May 11 22:14:02 2012 +0200 @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4 -from random import randint +from random import randint, random from gamelib.constants import SUCCESS, FAILURE, GAME_WIN, M_VALS from gamelib.schematics import cat @@ -153,6 +153,34 @@ def attempt_with(self, categorised, state): self.fail("You can't succceed at this mission.") + def combat_power(self, categorised, cats=None): + if cats is None: + cats = [cat.HAND_WEAPON, cat.VEHICLE, cat.COUNTERMEASURE, + cat.INTELLIGENCE] + + combat_equipment = set() + for category in cats: + combat_equipment.update(categorised.get(category, [])) + + power = 0 + for equipment in combat_equipment: + power += equipment.power() + return power + + def check_failure(self, categorised): + equipment = set() + for items in categorised.values(): + equipment.update(items) + for item in equipment: + if item.reliability() < random(): + return item.FAILURE_TEXT + return None + + def use_equipment(self, categorised, msg="Disaster strikes! %s", **loot): + failure = self.check_failure(categorised) + if failure is not None: + self.fail(msg % (failure,), **loot) + class PlaygroundBully(Mission): @@ -219,6 +247,8 @@ "'We have devised countermeasures since last time, doctor." " You cannot threaten us with that again.'") + self.use_equipment(categorised, rep=randint(-5, -2)) + self.data['prior_attempts'].add(doom.NAME) self.succeed( "Trembling at you threat of certain doom, the Chinese" @@ -238,15 +268,17 @@ MINIMUM_REPUTATION = 50 GENERIC_FAILURE = ( - "Nobody seems to quite understand what it is you're threatening them" - " with. Eventually you have to give up and go home.") + "Your invasion force was outclassed by the incumbent military, Not" + " surprising, since it turns out they've had a lot of practice in the" + " recent series of revolutions.") NO_EQUIP_FAILURE = ( "The border post may be poorly guarded, but you need to bring *some*" " kind of weaponry along. Your troops sulk on the way home.") def attempt_with(self, categorised, state): - if any(c in categorised for c in (cat.VEHICLE, cat.HAND_WEAPON)): + self.use_equipment(categorised) + if self.combat_power(categorised) > randint(60, 120): self.succeed( "The corruption and oppression continue, but at least the" " proceeds are making their way into *your* pockets. And you" @@ -265,8 +297,8 @@ MINIMUM_MILESTONE = "basement" GENERIC_FAILURE = ( - "The operation was a complete fiasco. Maybe you should try something a" - " little less eclectic next time.") + "The bank's security arrangements are rather more impressive than you" + " were led to believe. Bring more guns next time.") NO_EQUIP_FAILURE = ( "Your attempt to rob the bank barehanded is unsuccessful. Fortunately," " everyone is too stunned to impede your escape.") @@ -274,6 +306,8 @@ def attempt_with(self, categorised, state): loot = randint(500, 1500) + self.use_equipment(categorised) + if cat.VEHICLE in categorised: self.fail( "Your vehicles are impressively doom-laden, but not really" @@ -281,12 +315,6 @@ " wardens into letting you off without a fine, but by the" " time you get to the bank it's already closed.") - if cat.HAND_WEAPON in categorised: - self.succeed( - "The threat of your weapons is enough to inspire an impressive" - " level of cooperation. You make off with the loot.", - money=loot) - if cat.PATHOGEN in categorised: if randint(5, 15) < state.reputation: self.fail( @@ -299,6 +327,12 @@ " that is power.", money=loot, rep=1) + if self.combat_power(categorised) > randint(5, 20): + self.succeed( + "The threat of your weapons is enough to inspire an impressive" + " level of cooperation. You make off with the loot.", + money=loot) + class DestroyMountRushmore(Mission): @@ -346,6 +380,8 @@ def attempt_with(self, categorised, state): if cat.MIND_CONTROL in categorised: + self.use_equipment( + {cat.MIND_CONTROL: categorised[cat.MIND_CONTROL]}) self._succ("Your creative use of science has paid off nicely.", randint(5, 10)) diff -r dd277233538c -r f1efd252e8b0 gamelib/schematics.py --- a/gamelib/schematics.py Fri May 11 21:59:33 2012 +0200 +++ b/gamelib/schematics.py Fri May 11 22:14:02 2012 +0200 @@ -49,6 +49,8 @@ # FIXME: Icons for equipment. IMAGE_NAME = "physics" + FAILURE_TEXT = "Your equipment failed in an excitingly disastrous manner." + def can_spend(self, lab, spend): if self.points + spend > self.MAX_UPGRADE: return False @@ -103,9 +105,13 @@ POWER_INCREMENT = 3 PRODUCTION_RELIABILITY = 0.7 + FAILURE_TEXT = ( + "Your lightning gun dropped an insulator, leaking volts and coulombs" + " all over the place.") + class TeslaTank(Schematic): - NAME = "tesla tank" + NAME = "Tesla tank" COST = 40 * K CATEGORIES = (cat.VEHICLE,) PREREQUISITES = ( @@ -116,6 +122,10 @@ BASE_POWER = 100 POWER_INCREMENT = 10 + FAILURE_TEXT = ( + "The cheap knock-off capacitors in the primary charge module of the" + " Tesla tank knocked off, leading to much excitement.") + class PropagandaMachine(Schematic): NAME = "propaganda machine" @@ -128,6 +138,10 @@ BASE_POWER = 10 POWER_INCREMENT = 2 + FAILURE_TEXT = ( + "The propaganda machine printed reams of carefully structured" + " nonsense, which the proofreaders didn't catch until too late.") + class GiantSquid(Schematic): NAME = "giant squid"