def __init__(self, nation): super(JuntaEvent, self).__init__(nation) self.choices['army']['actions']['training']['amount'] = utils.attrchange(nation.military.training, 25) self.choices['airforce']['actions']['planes']['amount'] = utils.attrchange(nation.military.planes, 1, upper=10) self.choices['special']['actions']['chems']['amount'] = utils.attrchange(nation.military.chems, 1, upper=10) self.choices['navy']['actions']['navy']['amount'] = utils.attrchange(nation.military.navy, 1) self.description = "%s " % nation.name + self.description
def __init__(self, nation): super(RiotsEvent, self).__init__(nation) self.choices['crush']['actions']['stability']['amount'] = utils.attrchange(nation.stability, 20) self.choices['crush']['actions']['reputation']['amount'] = utils.attrchange(nation.reputation, -20) self.choices['crush']['actions']['government']['amount'] = utils.attrchange(nation.government, -10) self.choices['promise']['actions']['approval']['amount'] = utils.attrchange(nation.approval, 5) self.description = "%s " % nation.name + self.description
def __init__(self, nation): super(RefugeeEvent, self).__init__(nation) self.choices['qol']['actions']['qol']['amount'] = utils.attrchange(nation.qol, -10) self.choices['qol']['actions']['approval']['amount'] = utils.attrchange(nation.approval, -20) self.choices['qol']['actions']['manpower']['amount'] = utils.attrchange(nation.manpower, 10) self.choices['reputation']['actions']['reputation']['amount'] = utils.attrchange(nation.reputation, -15) self.description = "%s " % nation.name + self.description
def fundopposition(nation, target, spy): img = "spy.jpg" cost = target.gdp / 30 if spy.infiltration < 10: result = "Agent do not have enough infiltration!" elif nation.budget < cost: result = "We do not have enough funds for this!" else: strength = spy.experience + spy.infiltration - target.approval spyactions = { 'actioned': { 'action': 'set', 'amount': True }, 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -10) } } if spy.specialty != 'Launderer': strength /= 2 chance = random.randint(-500, 500) if strength < chance: result = "%s was caught trying to fund the opposition. The agent has been arrested." % spy.name #no news report spyactions.update({ 'arrested': { 'action': 'set', 'amount': True }, 'discovered': { 'action': 'set', 'amount': True } }) else: result = "%s has successfully funded the opposition, decreasing government approval." % spy.name spyactions = { 'experience': { 'action': 'add', 'amount': utils.attrchange(spy.experience, 5) }, 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -10) } } nationactions = {'budget': {'action': 'subtract', 'amount': cost}} targetactions = { 'approval': { 'action': 'add', 'amount': utils.attrchange(target.approval, -10) }, } utils.atomic_transaction(Nation, target.pk, targetactions) utils.atomic_transaction(Nation, nation.pk, nationactions) commitspy(spy, spyactions) return {'result': result, 'img': img}
def __init__(self, nation): super(Newbie_event, self).__init__(nation) self.choices['military']['actions']['training']['amount'] = utils.attrchange(nation.military.training, 50) self.choices['qol']['actions']['qol']['amount'] = utils.attrchange(nation.qol, 15) self.choices['qol']['actions']['approval']['amount'] = utils.attrchange(nation.approval, 15) self.choices['qol']['actions']['literacy']['amount'] = utils.attrchange(nation.approval, 15) self.choices['stability']['actions']['stability']['amount'] = utils.attrchange(nation.stability, 40) self.description = "%s " % nation.name + self.description
def armrebels(nation, target, spy): img = '' if spy.infiltration < 10: result = "Agent do not have enough infiltration!" elif nation.military.weapons < 20: result = "We do not have the weaponry for this!" else: spyactions = { 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -10) } } strength = spy.experience + spy.infiltration - target.approval if spy.specialty != 'Gunrunner': strength /= 2 chance = random.randint(-750, 500) if strength < chance: result = "%s was caught arming the rebels. Agent %s has been arrested." % ( spy.name, spy.name) #no news report img = "spy.jpg" spyactions.update({ 'arrested': { 'action': 'set', 'amount': True }, 'discovered': { 'action': 'set', 'amount': True } }) else: img = "rebel.jpg" result = "%s has successfully armed the rebels." % spy.name spyactions = { 'experience': { 'action': 'add', 'amount': utils.attrchange(spy.experience, 5) }, } nationactions = {'weapons': {'action': 'subtract', 'amount': 5}} targetactions = { 'rebels': { 'action': 'add', 'amount': 2 }, } utils.atomic_transaction(Nation, target.pk, targetactions) utils.atomic_transaction(Military, nation.military.pk, nationactions) commitspy(spy, spyactions) return {'result': result, 'img': img}
def enact(self): fp = self.nation.econdata.foodproduction chance = random.randint(1, 100) if chance > 79: fp += utils.attrchange(fp, 100, upper=10000) self.img = "collectivization.jpg" self.result = 'The grains have never been grainer!' elif chance < 11: fp += utils.attrchange(fp, -100, upper=10000) self.result = 'Your forced collectivization is an utter disaster, reducing your agricultural output, reducing approval and quality of life.' else: self.result = "Your forced collectivization is a failure, reducing approval and quality of life." Econdata.objects.filter(nation=self.nation).update(foodproduction=fp) super(collectivization, self).enact()
def counter(nation, spy): img = '' cost = nation.gdp / 30 if spy.infiltration < 10: result = "Agent does not have enough infiltration!" elif nation.budget < cost: result = "You do not have the funding for this!" else: Nation.objects.filter(user=nation.user).update(budget=F('budget') - cost) strength = spy.experience + spy.infiltration - utils.attrchange( nation.stability, 100) spyactions = { 'actioned': { 'action': 'set', 'amount': True }, 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -10) } } if spy.specialty != "Spy Hunter": strength /= 2 chance = random.randint(-300, 300) img = 'spy.jpg' count = 0 for guy in nation.infiltrators.all().exclude(nation=nation): chance = random.randint(0, 100) nstrength = spy.infiltration + spy.experience tstrength = guy.infiltration + guy.experience if spy.specialty == "Spy Hunter": nstrength = int(1.5 * nstrength) if nstrength > tstrength: Spy.objects.filter(pk=guy.pk).update( discovered=True, discovered_timestamp=v.now()) count += 1 if count > 0: result = "We found %s infiltrators!" % count else: result = "The sweep didn't find any enemy infiltrators." return {'result': result, 'img': img}
def __init__(self, nation): super(EArtistEvent, self).__init__(nation) self.choices['labor']['actions']['approval']['amount'] = utils.attrchange(nation.approval, -20) self.choices['labor']['actions']['stability']['amount'] = utils.attrchange(nation.stability, 10) self.choices['labor']['actions']['government']['amount'] = utils.attrchange(nation.government, 20) self.choices['slap']['actions']['stability']['amount'] = utils.attrchange(nation.stability, -20) self.choices['apologize']['actions']['approval']['amount'] = utils.attrchange(nation.approval, 10) self.choices['apologize']['actions']['stability']['amount'] = utils.attrchange(nation.stability, -15) self.choices['apologize']['actions']['government']['amount'] = utils.attrchange(nation.government, 20) self.description = "%s " % nation.name + self.description
def enact(self): chance = random.randint(1, 10) progress = 0 if chance > 4: progress = utils.attrchange(self.nation.military.reactor, 1, upper=20) if progress + self.nation.military.reactor == 20: self.result = "Our scientist finish and we now have a fully operational reactor!" else: self.result = "Progress continues toward a working reactor!" elif chance < 2 and self.nation.military.reactor > 1: progress = utils.attrchange(self.nation.military.reactor, -1, upper=20) self.result = "A stealth bomber has struck your reactor in the middle of construction! Someone doesn't want you getting nuclear weapons... Progress is set back." else: self.result = "Your nuclear scientists unfortunately fail to make progress..." self.nation.military.reactor += progress self.nation.military.save(update_fields=['reactor']) super(reactor, self).enact()
def withdraw(nation, target, spy): img = '' if spy.infiltration < 10: result = "Agent do not have enough infiltration!" elif spy.arrested: result = "Agent has been arrested! We can't pull him out!" else: chance = 95 if target.spies.filter( location=target, specialty="Spy Hunter").exists() or spy.discovered: chance = 75 if spy.surveillance: chance = 10 if spy.specialty == "Intelligence": chance = 25 actions = { 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -10) } } if chance > random.randint(1, 100): spy.move_home() result = "Agent %s quietly slips through the border and returns home." % spy.name else: news.caughtspyreturning(target, nation) spyactions.update({ 'arrested': { 'action': 'set', 'amount': True }, 'discovered': { 'action': 'set', 'amount': True }, }) commitspy(spy, actions) result = "Agent %s was caught while trying to move out of %s and was placed under arrest!" % ( spy.name, target.name) return {'result': result, 'img': img}
def turnchange(): ID.objects.all().update(turn=F('turn') + 1) turn = ID.objects.get().turn for nation in Nation.objects.actives().select_related( 'alliance__initiatives').iterator(): create_snapshot(nation, turn) while True: try: approval = qol = growth = FI = mg = manpower = research = rebels = 0 #base material gain oil = oilgain(nation) reserveloss = oilbase(nation) rm = rmgain(nation) food = foodgain(nation) mg = mggain(nation, rm + nation.rm, oil + nation.oil) basedecay = mgbase(nation, rm + nation.rm, oil + nation.oil) oil -= basedecay rm -= basedecay ################## ## other stuff lol ################## research = researchgain(nation) approval = approvalchange(nation) gdpchange = nation.growth qol = qolgain(nation) FI = FIchanges(nation) manpower = manpowergain(nation) healthcare = healthcaredecay(nation) stability = stabilitygain(nation) soviet = sovietgain(nation) us = westerngain(nation) growth = growthchanges(nation) actions = { 'gdp': { 'action': 'add', 'amount': nation.growth }, 'growth': { 'action': 'add', 'amount': growth }, 'qol': { 'action': 'add', 'amount': utils.attrchange(nation.qol, qol) }, 'healthcare': { 'action': 'add', 'amount': utils.attrchange(nation.healthcare, healthcare) }, 'literacy': { 'action': 'add', 'amount': utils.attrchange(nation.literacy, literacydecay(nation)) }, 'stability': { 'action': 'add', 'amount': utils.attrchange(nation.stability, stability) }, 'approval': { 'action': 'add', 'amount': utils.attrchange(nation.approval, approval) }, 'soviet_points': { 'action': 'add', 'amount': utils.attrchange(nation.soviet_points, soviet, -100) }, 'us_points': { 'action': 'add', 'amount': utils.attrchange(nation.us_points, us, -100) }, 'reputation': { 'action': 'add', 'amount': utils.attrchange(nation.reputation, 5) }, 'rebels': { 'action': 'add', 'amount': utils.attrchange(nation.rebels, rebels) }, 'manpower': { 'action': 'add', 'amount': utils.attrchange(nation.manpower, manpower) }, 'research': { 'action': 'add', 'amount': research }, 'oilreserves': { 'action': 'subtract', 'amount': reserveloss }, 'FI': { 'action': 'add', 'amount': FI }, 'oil': { 'action': 'add', 'amount': oil }, 'rm': { 'action': 'add', 'amount': rm }, 'mg': { 'action': 'add', 'amount': mg }, 'food': { 'action': 'add', 'amount': food }, } utils.atomic_transaction(Nation, nation.pk, actions) except OperationalError: nation.refresh_from_db() continue eventhandler.trigger_events(nation) trade_balancing(nation) break return milturn()
def __init__(self, nation): super(FactoryEvent, self).__init__(nation) self.choices['FI']['actions']['FI']['amount'] = nation.FI / 2 self.choices['USpoints']['actions']['us_points']['amount'] = utils.attrchange(nation.us_points, -30)
def poison(nation, target, spy): img = '' cost = target.gdp / 15 if spy.infiltration < 50: result = "Agent do not have enough infiltration!" elif nation.budget < cost: result = "We do not have enough funds for this!" elif nation.military.weapons < 20: result = "We do not have the weapons to do this!" elif target.econdata.foodproduction == 0: result = "Their food production has already been decimated!" else: strength = spy.experience + spy.infiltration - target.approval spyactions = { 'actioned': { 'action': 'set', 'amount': True }, 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -20) } } if spy.specialty != 'Saboteur': strength /= 2 chance = random.randint(-300, 500) if strength < chance: result = "%s was caught preparing to poison the crops. He was subsequently placed under arrest." % spy.name img = "spy.jpg" spyactions.update({ 'arrested': { 'action': 'set', 'amount': True }, 'discovered': { 'action': 'set', 'amount': True } }) else: img = "spy.jpg" result = "%s successfully poisoned the target nation's crops, decreasing their food production." % spy.name spyactions = { 'experience': { 'action': 'add', 'amount': utils.attrchange(spy.experience, 5) }, } nationactions = { 'budget': { 'action': 'subtract', 'amount': cost }, } nationmilactions = { 'weapons': { 'action': 'subtract', 'amount': 2 }, } targetactions = { 'foodproduction': { 'action': 'subtract', 'amount': (1 if target.econdata.foodproduction > 0 else 0) }, } utils.atomic_transaction(Econdata, target.econdata.pk, targetactions) utils.atomic_transaction(Nation, nation.pk, nationactions) utils.atomic_transaction(Military, nation.military.pk, nationmilactions) commitspy(spy, spyactions) return {'result': result, 'img': img}
def __init__(self, nation): super(AsteroidEvent, self).__init__(nation) self.choices['gibsoviet']['actions']['soviet_points']['amount'] = utils.attrchange(nation.soviet_points, 25) self.choices['gibus']['actions']['us_points']['amount'] = utils.attrchange(nation.us_points, 25) self.description = "%s " % nation.name + self.description
def sabotagemine(nation, target, spy): img = '' cost = target.gdp / 30 if spy.infiltration < 20: result = "Agent do not have enough infiltration!" elif nation.budget < cost: result = "We do not have enough funds for this!" elif nation.military.weapons < 20: result = "We do not have the weapons to do this!" elif target.mines == 0: result = "They have no mines!" else: strength = spy.experience + spy.infiltration - target.approval spyactions = { 'actioned': { 'action': 'set', 'amount': True }, 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -20) } } if spy.specialty != 'Saboteur': strength /= 2 chance = random.randint(-300, 500) if strength < chance: result = "Agent %s was caught sabotaging a mine. He has been placed under arrest." % spy.name news.sabotagemine(target) spyactions.update({ 'arrested': { 'action': 'set', 'amount': True }, 'discovered': { 'action': 'set', 'amount': True } }) img = "spy.jpg" else: img = "spy.jpg" result = "%s has successfully sabotaged a mine, decreasing their production." % spy.name news.sabotagedmine(target) spyactions = { 'experience': { 'action': 'add', 'amount': utils.attrchange(spy.experience, 5) }, } nationactions = { 'budget': { 'action': 'subtract', 'amount': cost }, } nationmilactions = { 'weapons': { 'action': 'subtract', 'amount': 2 }, } targetactions = { 'mines': { 'action': 'subtract', 'amount': 1 }, } utils.atomic_transaction(Nation, target.pk, targetactions) utils.atomic_transaction(Nation, nation.pk, nationactions) utils.atomic_transaction(Military, nation.military.pk, nationmilactions) commitspy(spy, spyactions) return {'result': result, 'img': img}
def terroristattack(nation, target, spy): img = '' cost = target.gdp / 15 if spy.infiltration < 50: result = "Agent do not have enough infiltration!" elif nation.budget < cost: result = "We do not have enough funds for this!" elif nation.military.weapons < 20: result = "We do not have the weapons to do this!" else: strength = spy.experience + spy.infiltration - target.approval spyactions = { 'actioned': { 'action': 'set', 'amount': True }, 'infiltration': { 'action': 'add', 'amount': utils.attrchange(spy.infiltration, -50) } } if spy.specialty != 'Terrorist': strength /= 2 chance = random.randint(-300, 500) if strength < chance: result = "%s has been caught planning a terrorist attack! The agent responsible has been detained." % spy.name news.terroristattack(target) img = "spy.jpg" spyactions.update({ 'arrested': { 'action': 'set', 'amount': True }, 'discovered': { 'action': 'set', 'amount': True } }) else: img = "spy.jpg" news.terroristattacked(target) result = "%s has successfully pulled off a terrorist attack and framed it on an internal\ faction, killing countless innocent civilians and decreasing stability in the country." % spy.name spyactions = { 'experience': { 'action': 'add', 'amount': utils.attrchange(spy.experience, 5) }, } nationactions = { 'budget': { 'action': 'subtract', 'amount': cost }, } nationmilactions = { 'weapons': { 'action': 'subtract', 'amount': 10 }, } targetactions = { 'stability': { 'action': 'add', 'amount': utils.attrchange(target.approval, -15) }, } utils.atomic_transaction(Nation, target.pk, targetactions) utils.atomic_transaction(Nation, nation.pk, nationactions) utils.atomic_transaction(Military, nation.military.pk, nationmilactions) commitspy(spy, spyactions) return {'result': result, 'img': img}
def __init__(self, nation): super(RebelsEvent, self).__init__(nation) self.choices['givein']['actions']['stability']['amount'] = utils.attrchange(nation.stability, -35) self.choices['givein']['actions']['approval']['amount'] = utils.attrchange(nation.approval, 15) self.choices['dont']['actions']['rebels']['amount'] = utils.attrchange(nation.rebels, 20, 0) self.description = "%s " % nation.name + self.description
def __init__(self, nation): super(SinglePartyEvent, self).__init__(nation) self.choices['industrial']['actions']['qol']['amount'] = utils.attrchange(nation.qol, -10) self.choices['consumer']['actions']['qol']['amount'] = utils.attrchange(nation.qol, 20) self.choices['agriculture']['actions']['manpower']['amount'] = utils.attrchange(nation.manpower, 50) self.description = "%s " % nation.name + self.description
def __init__(self, nation): super(UNInterventionEvent, self).__init__(nation) self.choices['milactions']['actions']['navy']['amount'] = utils.attrchange(nation.military.navy, -4) self.description = "%s " % self.description + nation.name