コード例 #1
0
    def __init__(self, millevel, *args, **kwargs):
        super(NewTradeForm, self).__init__(*args, **kwargs)

        reslist = [
            ('0', 'GEU'),
            ('1', 'Warpfuel'),
            ('2', 'Duranium'),
            ('3', 'Tritanium'),
            ('4', 'Adamantium'),
            ('11', 'Fighters'),
            ('12', 'Corvettes'),
            ('13', 'Light Cruisers'),
            ('14', 'Destroyers'),
            ('15', 'Frigates'),
            ('16', 'Heavy Cruisers'),
            ('17', 'Battlecruisers'),
            ('18', 'Battleships'),
            ('19', 'Dreadnoughts'),
        ]

        if millevel < v.millevel('cor'):
            RESOURCE_CHOICES = reslist[:7]
        elif millevel < v.millevel('lcr'):
            RESOURCE_CHOICES = reslist[:8]
        elif millevel < v.millevel('des'):
            RESOURCE_CHOICES = reslist[:9]
        elif millevel < v.millevel('fri'):
            RESOURCE_CHOICES = reslist[:10]
        elif millevel < v.millevel('hcr'):
            RESOURCE_CHOICES = reslist[:11]
        elif millevel < v.millevel('bcr'):
            RESOURCE_CHOICES = reslist[:12]
        elif millevel < v.millevel('bsh'):
            RESOURCE_CHOICES = reslist[:13]
        else:
            RESOURCE_CHOICES = reslist

        self.fields["offer"] = forms.IntegerField(widget=forms.Select(
            choices=RESOURCE_CHOICES, attrs={'id': 'offerres'}))
        self.fields["amountoff"] = forms.IntegerField(
            widget=forms.NumberInput(attrs={
                'size': '10',
                'id': 'offeramount'
            }),
            label="Amount")
        self.fields["receive"] = forms.IntegerField(widget=forms.Select(
            choices=RESOURCE_CHOICES))
        self.fields["amountrec"] = forms.IntegerField(
            widget=forms.NumberInput(attrs={'size': '10'}), label="Amount")
        self.fields["amounttrades"] = forms.IntegerField(
            widget=forms.NumberInput(attrs={
                'size': '10',
                'id': 'tradesamount',
                'value': 1
            }),
            label="No. of trades")
コード例 #2
0
ファイル: forms.py プロジェクト: Joshuaking007/WorldsAtWar
    def __init__(self, millevel, *args, **kwargs):
        super(NewTradeForm, self).__init__(*args, **kwargs)

        reslist = [('0','GEU'),
                   ('1','Warpfuel'),
                   ('2','Duranium'),
                   ('3','Tritanium'),
                   ('4','Adamantium'),
                   ('11','Fighters'),
                   ('12','Corvettes'),
                   ('13','Light Cruisers'),
                   ('14','Destroyers'),
                   ('15','Frigates'),
                   ('16','Heavy Cruisers'),
                   ('17','Battlecruisers'),
                   ('18','Battleships'),
                   ('19','Dreadnoughts'),]

        if millevel < v.millevel('cor'):
            RESOURCE_CHOICES = reslist[:7]
        elif millevel < v.millevel('lcr'):
            RESOURCE_CHOICES = reslist[:8]
        elif millevel < v.millevel('des'):
            RESOURCE_CHOICES = reslist[:9]
        elif millevel < v.millevel('fri'):
            RESOURCE_CHOICES = reslist[:10]
        elif millevel < v.millevel('hcr'):
            RESOURCE_CHOICES = reslist[:11]
        elif millevel < v.millevel('bcr'):
            RESOURCE_CHOICES = reslist[:12]
        elif millevel < v.millevel('bsh'):
            RESOURCE_CHOICES = reslist[:13]
        else:
            RESOURCE_CHOICES = reslist

        self.fields["offer"] = forms.IntegerField(widget=forms.Select(choices=RESOURCE_CHOICES, attrs={'id':'offerres'}))
        self.fields["amountoff"] = forms.IntegerField(widget=forms.NumberInput(attrs={'size':'10', 'id':'offeramount'}), label="Amount")
        self.fields["receive"] = forms.IntegerField(widget=forms.Select(choices=RESOURCE_CHOICES))
        self.fields["amountrec"] = forms.IntegerField(widget=forms.NumberInput(attrs={'size':'10'}), label="Amount")
        self.fields["amounttrades"] = forms.IntegerField(widget=forms.NumberInput(attrs={'size':'10', 'id':'tradesamount', 'value':1}),
            label="No. of trades")
コード例 #3
0
ファイル: utilities.py プロジェクト: heidi666/WorldsAtWar
def formshiplist(millevel, shiplist, freighters=False):
    'Splits shiplist for forms according to military level.'

    if millevel < v.millevel('cor'):
        choices = shiplist[:2]
    elif millevel < v.millevel('lcr'):
        choices = shiplist[:3]
    elif millevel < v.millevel('des'):
        choices = shiplist[:4]
    elif millevel < v.millevel('fri'):
        choices = shiplist[:5]
    elif millevel < v.millevel('hcr'):
        choices = shiplist[:6]
    elif millevel < v.millevel('bcr'):
        choices = shiplist[:7]
    elif millevel < v.millevel('bsh'):
        choices = shiplist[:8]
    else:
        choices = shiplist

    if freighters:
        choices.append(('0', 'Freighters'))

    return choices
コード例 #4
0
ファイル: utilities.py プロジェクト: joancefet/WorldsAtWar
def formshiplist(millevel, shiplist, freighters=False):
    'Splits shiplist for forms according to military level.'

    if millevel < v.millevel('cor'):
        choices = shiplist[:2]
    elif millevel < v.millevel('lcr'):
        choices = shiplist[:3]
    elif millevel < v.millevel('des'):
        choices = shiplist[:4]
    elif millevel < v.millevel('fri'):
        choices = shiplist[:5]
    elif millevel < v.millevel('hcr'):
        choices = shiplist[:6]
    elif millevel < v.millevel('bcr'):
        choices = shiplist[:7]
    elif millevel < v.millevel('bsh'):
        choices = shiplist[:8]
    else:
        choices = shiplist

    if freighters:
        choices.append(('0', 'Freighters'))

    return choices
コード例 #5
0
ファイル: news.py プロジェクト: joancefet/WorldsAtWar
def world_news(request):
    world = request.user.world
    anlist = ActionNewsItem.objects.filter(target=world)
    message = None
    notask = 'No such news item!'

    if request.method == 'POST':
        form = request.POST
        if "delete" in form:  # deletes news by checkbox
            listitems = request.POST.getlist('newsitem')
            for i in listitems:
                try:
                    item = NewsItem.objects.get(pk=i)
                except ObjectDoesNotExist:
                    message = notask
                else:
                    if item.target == world:
                        item.delete()

        if "deleteall" in form:  # deletes all news
            NewsItem.objects.filter(target=world).delete()

        ##############
        ### ACTIONNEWS
        ##############

        ##
        ## TYPE 1
        ##
        if (("acceptpeace" in form) or
            ("declinepeace" in form)) and (anlist.filter(
                actiontype=1).exists()):  # type 1
            taskid = request.POST.get('taskid')
            war = None
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except ObjectDoesNotExist:
                message = notask
            else:
                try:
                    war = actionnewsitem.peacebyatk.all()[0]
                except IndexError:
                    try:
                        war = actionnewsitem.peacebydef.all()[0]
                    except IndexError:
                        message = 'You are not at war with this world!'
            if war != None:
                if "acceptpeace" in form:
                    htmldata = news.peaceaccept(world)
                    if world == war.attacker and war.peaceofferbydef != None:
                        NewsItem.objects.create(target=war.defender,
                                                content=htmldata)
                    elif world == war.defender and war.peaceofferbyatk != None:
                        NewsItem.objects.create(target=war.attacker,
                                                content=htmldata)

                    war.delete()
                    message = 'You are now at peace.'

                if "declinepeace" in form:
                    htmldata = news.peacedecline(world)
                    if world == war.attacker and war.peaceofferbydef != None:
                        NewsItem.objects.create(target=war.defender,
                                                content=htmldata)
                    elif world == war.defender and war.peaceofferbyatk != None:
                        NewsItem.objects.create(target=war.attacker,
                                                content=htmldata)

                    actionnewsitem.delete()
                    message = 'The peace offer has been declined.'

        ##
        ## TYPE 2
        ##
        if ("noobmoney" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.budget = F('budget') + D(600)
                    world.save(update_fields=['budget'])
                    message = 'Money! Money falling from the skies!'

        if ("noobqol" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    contentment = utilities.attrchange(world.contentment, 40)
                    contaction = ('set' if contentment == 100 else 'add')
                    qol = utilities.attrchange(world.qol, 40)
                    qolaction = ('set' if qol == 100 else 'add')
                    actions = {
                        'contentment': {
                            'action': contaction,
                            'amount': contentment
                        },
                        'qol': {
                            'action': qolaction,
                            'amount': qol
                        },
                    }
                    utilities.atomic_world(world.pk, actions)
                    message = 'Well, aren\'t you a humanitarian?'

        if ("noobsecurity" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    stab = utilities.attrchange(world.stability, 60)
                    stabaction = ('set' if stab == 100 else 'add')
                    actions = {
                        'stability': {
                            'action': stabaction,
                            'amount': stab
                        }
                    }
                    utilities.atomic_world(world.pk, actions)
                    message = 'Your people are used to absolute obedience to your rule.'

        if ("noobmilitary" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    f = fleet.objects.filter(world=world,
                                             controller=world,
                                             sector=world.sector)[0]
                    f.fighters += v.eventfighters
                    f.train()
                    f.save(update_fields=['fighters', 'training'])
                    world.warpfuelprod = F('warpfuelprod') + 10
                    world.save(update_fields=['warpfuelprod'])
                    message = 'Your warmongering world starts out with extra fighters!'

        ##
        ## TYPE 3
        ##
        if ("fleetresearch"
                in form) and (anlist.filter(actiontype=3).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.millevel = F('millevel') + 1500
                    world.save(update_fields=['millevel'])
                    message = 'You pour intensive effort into bettering your ship technology.'

        if ("fleetshipyard"
                in form) and (anlist.filter(actiontype=3).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.shipyards = F('shipyards') + 1
                    world.save(update_fields=['shipyards'])
                    message = 'You must build ships faster! You construct a shipyard as fast as possible.'

        if ("fleettraining"
                in form) and (anlist.filter(actiontype=3).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    maximum = utilities.trainingfromlist(
                        utilities.regionshiplist(world, world.region))
                    utilities.trainingchange(world, world.region, maximum / 10)
                    message = 'You order a series of war and battle simulations and training improves a great deal.'

        ##
        ## TYPE 4
        ##
        if ("asteroidduranium"
                in form) and (anlist.filter(actiontype=4).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.duraniumprod = F('duraniumprod') + 3
                    world.save(update_fields=['duraniumprod'])
                    message = 'You set up a duranium mine on the asteroid.'

        if ("asteroidtritanium"
                in form) and (anlist.filter(actiontype=4).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.millevel < v.millevel('lcr'):
                        message = 'Your military level is not high enough to refine this material!'
                    else:
                        actionnewsitem.delete()
                        world.tritaniumprod = F('tritaniumprod') + 2
                        world.save(update_fields=['tritaniumprod'])
                        message = 'You set up a tritanium mine on the asteroid.'

        if ("asteroidadamantium"
                in form) and (anlist.filter(actiontype=4).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.millevel < v.millevel('hcr'):
                        message = 'Your military level is not high enough to refine this material!'
                    else:
                        actionnewsitem.delete()
                        world.adamantiumprod = F('adamantiumprod') + 1
                        world.save(update_fields=['adamantiumprod'])
                        message = 'You set up an adamantium mine on the asteroid.'

        ##
        ## TYPE 5
        ##
        if ("dasteroiddeflect"
                in form) and (anlist.filter(actiontype=5).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.warpfuel < 50:
                        message = 'You do not have enough warpfuel for this event!'
                    else:
                        actionnewsitem.delete()
                        world.warpfuel = F('warpfuel') - 50
                        world.save(update_fields=['warpfuel'])
                        message = 'You deflect the asteroid harmlessly into space.'

        if ("dasteroidsubcontract"
                in form) and (anlist.filter(actiontype=5).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.budget < 500:
                        message = 'You do not have enough money for this event!'
                    else:
                        actionnewsitem.delete()
                        world.budget = F('budget') - D(500)
                        world.save(update_fields=['budget'])
                        message = 'You pay a civilian group to deflect the asteroid for you.'

        if ("dasteroidredirect"
                in form) and (anlist.filter(actiontype=5).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.warpfuel < 20:
                        message = 'You do not have enough warpfuel for this event!'
                    else:
                        actionnewsitem.delete()
                        world.warpfuel = F('warpfuel') - 20
                        utilities.rebelschange(world, -20)
                        utilities.contentmentchange(world, -40)
                        world.save(update_fields=['warpfuel'])
                        message = 'You redirect the asteroid onto an area of the planet you know<br>rebels like to hide in. \
                            Any rebels you may have suffer<br>heavy losses, but the population is horrified at you.'

        ##
        ## TYPE 6
        ##
        if ("radmiralignore"
                in form) and (anlist.filter(actiontype=6).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if random.randint(1, 3) == 1:
                        utilities.rebelschange(world, 5)
                        utilities.stabilitychange(world, -20)
                        message = 'It seems you were wrong! Stability drops as <br> the admiral musters rebels to your rule.'
                    else:
                        world.budget = F('budget') + D(500)
                        world.save(update_fields=['budget'])
                        message = 'You were right. The people take your side and you eventually <br> \
                            confiscate the admiral\'s property, sending him off-world.'

                    actionnewsitem.delete()

        if ("radmiralbribe"
                in form) and (anlist.filter(actiontype=6).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.budget < 250:
                        message = 'You do not have enough money for this event!'
                    elif random.randint(1, 10) == 1:
                        stab = utilities.attrchange(world.stability, 10)
                        actions = {
                            'stability': {
                                'action': 'add',
                                'amount': stab
                            },
                            'budget': {
                                'action': 'subtract',
                                'amount': 250
                            },
                        }
                        utilities.atomic_world(world.pk, actions)
                        message = 'The admiral accepts your payoffs and retires, extolling your <br> \
                            virtues in his retirement speech broadcast around the world.'

                    else:
                        rebels = utilities.attrchange(world.rebels,
                                                      5,
                                                      zero=True)
                        stab = utilities.attrchange(world.stability, -20)
                        actions = {
                            'rebels': {
                                'action': 'add',
                                'amount': rebels
                            },
                            'stability': {
                                'action': 'add',
                                'amount': stab
                            },
                            'budget': {
                                'action': 'subtract',
                                'amount': 250
                            },
                        }
                        utilities.atomic_world(world.pk, actions)
                        message = 'The admiral takes your money and uses it to raise rebels against your rule!'

                    actionnewsitem.delete()

        if ("radmiralspy" in form) and (anlist.filter(actiontype=6).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if not Spy.objects.filter(owner=world,
                                              location=world).exists():
                        message = 'You do not have a spy at home!'
                    elif random.randint(1, 4) == 1:
                        rebels = utilities.attrchange(world.rebels,
                                                      10,
                                                      zero=True)
                        stab = utilities.attrchange(world.stability, -10)
                        actions = {
                            'rebels': {
                                'action': 'add',
                                'amount': rebels
                            },
                            'stability': {
                                'action': 'add',
                                'amount': stab
                            },
                        }
                        utilities.atomic_world(world.pk, actions)
                        message = 'The admiral survives his \'accident\' and the people, <br> \
                            shocked at your methods, rise up against you.'

                    else:
                        actions = {'budget': {'action': 'add', 'amount': 500}}
                        utilities.atomic_world(world.pk, actions)
                        message = 'Your spy succeeds in his mission, and the people soon forget what <br> \
                            all the fuss was about. You confiscate the dead admiral\'s property.'

                    actionnewsitem.delete()

        ##
        ## TYPE 7
        ##
        if ("traidersattack"
                in form) and (anlist.filter(actiontype=7).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    #rebelpower = 50
                    #worldpower = utilities.militarypower(world, world.region)
                    #totworldpower = utilities.powerallmodifiers(world, world.region)
                    #worldlist = utilities.regionshiplist(world, world.region)
                    #deflosses = [0, 0, 0, 0, 0, 0, 0, 0, 0]
                    #deflosses = utilities.war_result(rebelpower, totworldpower, worldpower, worldlist)
                    #utilities.warloss_byregion(world, world.region, deflosses)
                    #losses = news.losses(deflosses)
                    message = 'You defeated the raiders - the fleet lost nothing in the engagement.'
                    actionnewsitem.delete()

        if ("traidersbribe"
                in form) and (anlist.filter(actiontype=7).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.budget < 500:
                        message = 'You do not have enough money for this event!'
                    elif random.randint(1, 10) == 1:
                        rebels = utilities.attrchange(world.rebels,
                                                      5,
                                                      zero=True)
                        actions = {
                            'budget': {
                                'action': 'subtract',
                                'amount': 500
                            },
                            'rebels': {
                                'action': 'add',
                                'amount': rebels
                            }
                        }
                        utilities.atomic_world(world.pk, actions)
                        message = 'The raiders take your money and use it to better equip their <br> \
                            ships and mount more organised attacks in your system!'

                        actionnewsitem.delete()
                    else:
                        actions = {
                            'budget': {
                                'action': 'subtract',
                                'amount': 500
                            },
                        }
                        utilities.atomic_world(world.pk, actions)
                        message = 'The raiders use the payoff to leave for another system.'
                        actionnewsitem.delete()

        if ("traidersignore"
                in form) and (anlist.filter(actiontype=7).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    rebels = utilities.attrchange(world.rebels, 10, zero=True)
                    actions = {'rebels': {'action': 'add', 'amount': rebels}}
                    utilities.atomic_world(world.pk, actions)
                    message = 'The raiders use the lack of response to organise themselves <br> \
                        and recruit more scum for a greater presence in your system.'

                    actionnewsitem.delete()

        ##
        ## TYPE 8
        ##
        if ("durasteroidmine"
                in form) and (anlist.filter(actiontype=8).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    duranium = random.randint(70, 100)
                    qol = utilities.attrchange(world.qol, -10)
                    actions = {
                        'duranium': {
                            'action': 'add',
                            'amount': duranium
                        },
                        'qol': {
                            'action': 'add',
                            'amount': qol
                        },
                    }
                    utilities.atomic_world(world.pk, actions)
                    message = 'You managed to extract %s duranium from the asteroid.' % duranium
                    actionnewsitem.delete()

        ##
        ## TYPE 9
        ##
        if ("fuelexplodeaccept"
                in form) and (anlist.filter(actiontype=9).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    message = 'You send form letters of commiseration to the worker\'s families.'
                    actionnewsitem.delete()

        ##
        ## TYPE 10
        ##
        if ("xenuaccept" in form) and (anlist.filter(actiontype=10).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    qol = utilities.attrchange(world.qol, -10)
                    actions = {
                        'qol': {
                            'action': 'add',
                            'amount': qol
                        },
                        'gdp': {
                            'action': 'add',
                            'amount': 100
                        }
                    }
                    utilities.atomic_world(world.pk, actions)
                    message = 'Quality of life goes down somewhat from the tortured spirits hassling <br> your population, \
                        but you gain 100 GDP from all the businesses <br> that have popped up to rid them through \'auditing sessions\'.'

                    actionnewsitem.delete()

        if ("xenurefuse" in form) and (anlist.filter(actiontype=10).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    message = 'The angry despot attempts to detonate a primitive Old Earth bomb <br> on your capital city \
                        but you effortlessly warp it out of existence.<br> Humiliated, he leaves.'

                    actionnewsitem.delete()

    newslist = list(
        NewsItem.objects.filter(
            target=world).order_by('-datetime'))  # reverse chrono order
    actionnewslist = list(
        ActionNewsItem.objects.filter(target=world).order_by('-datetime'))

    if len(newslist) == 0:  # Displays 'no news'
        newslist = None
    if len(actionnewslist) == 0:
        actionnewslist = None

    world = World.objects.get(pk=world.pk)
    world.save()

    NewsItem.objects.filter(target=world).update(seen=True)
    ActionNewsItem.objects.filter(target=world).update(seen=True)

    return render(request, 'world_news.html', {
        'news': newslist,
        'actionnews': actionnewslist,
        'message': message
    })
コード例 #6
0
ファイル: news.py プロジェクト: Joshuaking007/WorldsAtWar
def world_news(request, world):

    anlist = ActionNewsItem.objects.filter(target=world)
    message = None
    notask = 'No such news item!'

    if request.method == 'POST':
        form = request.POST
        if "delete" in form:      # deletes news by checkbox
            listitems = request.POST.getlist('newsitem')
            for i in listitems:
                try:
                    item = NewsItem.objects.get(pk=i)
                except ObjectDoesNotExist:
                    message = notask
                else:
                    if item.target == world:
                        item.delete()

        if "deleteall" in form:   # deletes all news
            NewsItem.objects.filter(target=world).delete()

        ##############
        ### ACTIONNEWS
        ##############

        ##
        ## TYPE 1
        ##
        if (("acceptpeace" in form) or ("declinepeace" in form)) and (anlist.filter(actiontype=1).exists()): # type 1
            taskid = request.POST.get('taskid')
            war = None
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except ObjectDoesNotExist:
                message = notask
            else:
                try:
                    war = actionnewsitem.peacebyatk.all()[0]
                except IndexError:
                    try:
                        war = actionnewsitem.peacebydef.all()[0]
                    except IndexError:
                        message = 'You are not at war with this world!'
            if war != None:
                if "acceptpeace" in form:
                    htmldata = news.peaceaccept(world)
                    if world == war.attacker and war.peaceofferbydef != None:
                        NewsItem.objects.create(target=war.defender, content=htmldata)
                    elif world == war.defender and war.peaceofferbyatk != None:
                        NewsItem.objects.create(target=war.attacker, content=htmldata)

                    war.delete()
                    message = 'You are now at peace.'

                if "declinepeace" in form:
                    htmldata = news.peacedecline(world)
                    if world == war.attacker and war.peaceofferbydef != None:
                        NewsItem.objects.create(target=war.defender, content=htmldata)
                    elif world == war.defender and war.peaceofferbyatk != None:
                        NewsItem.objects.create(target=war.attacker, content=htmldata)

                    actionnewsitem.delete()
                    message = 'The peace offer has been declined.'

        ##
        ## TYPE 2
        ##
        if ("noobmoney" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.budget = F('budget') + D(600)
                    world.save(update_fields=['budget'])
                    message = 'Money! Money falling from the skies!'

        if ("noobqol" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    utilities.qolchange(world, 40)
                    utilities.contentmentchange(world, 40)
                    message = 'Well, aren\'t you a humanitarian?'

        if ("noobsecurity" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    utilities.stabilitychange(world, 60)
                    message = 'Your people are used to absolute obedience to your rule.'

        if ("noobmilitary" in form) and (anlist.filter(actiontype=2).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    utilities.movecomplete(world, 1, 10, world.region, 40)
                    world.warpfuelprod = F('warpfuelprod') + 10
                    world.save(update_fields=['warpfuelprod'])
                    message = 'Your warmongering world starts out with extra fighters!'

        ##
        ## TYPE 3
        ##
        if ("fleetresearch" in form) and (anlist.filter(actiontype=3).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.millevel = F('millevel') + 1500
                    world.save(update_fields=['millevel'])
                    message = 'You pour intensive effort into bettering your ship technology.'

        if ("fleetshipyard" in form) and (anlist.filter(actiontype=3).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.shipyards = F('shipyards') + 1
                    world.save(update_fields=['shipyards'])
                    message = 'You must build ships faster! You construct a shipyard as fast as possible.'

        if ("fleettraining" in form) and (anlist.filter(actiontype=3).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    maximum = utilities.trainingfromlist(utilities.regionshiplist(world, world.region))
                    utilities.trainingchange(world, world.region, maximum/10)
                    message = 'You order a series of war and battle simulations and training improves a great deal.'

        ##
        ## TYPE 4
        ##
        if ("asteroidduranium" in form) and (anlist.filter(actiontype=4).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    actionnewsitem.delete()
                    world.duraniumprod = F('duraniumprod') + 3
                    world.save(update_fields=['duraniumprod'])
                    message = 'You set up a duranium mine on the asteroid.'

        if ("asteroidtritanium" in form) and (anlist.filter(actiontype=4).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.millevel < v.millevel('lcr'):
                        message = 'Your military level is not high enough to refine this material!'
                    else:
                        actionnewsitem.delete()
                        world.tritaniumprod = F('tritaniumprod') + 2
                        world.save(update_fields=['tritaniumprod'])
                        message = 'You set up a tritanium mine on the asteroid.'

        if ("asteroidadamantium" in form) and (anlist.filter(actiontype=4).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.millevel < v.millevel('hcr'):
                        message = 'Your military level is not high enough to refine this material!'
                    else:
                        actionnewsitem.delete()
                        world.adamantiumprod = F('adamantiumprod') + 1
                        world.save(update_fields=['adamantiumprod'])
                        message = 'You set up an adamantium mine on the asteroid.'

        ##
        ## TYPE 5
        ##
        if ("dasteroiddeflect" in form) and (anlist.filter(actiontype=5).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.warpfuel < 50:
                        message = 'You do not have enough warpfuel for this event!'
                    else:
                        actionnewsitem.delete()
                        world.warpfuel = F('warpfuel') - 50
                        world.save(update_fields=['warpfuel'])
                        message = 'You deflect the asteroid harmlessly into space.'

        if ("dasteroidsubcontract" in form) and (anlist.filter(actiontype=5).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.budget < 500:
                        message = 'You do not have enough money for this event!'
                    else:
                        actionnewsitem.delete()
                        world.budget = F('budget') - D(500)
                        world.save(update_fields=['budget'])
                        message = 'You pay a civilian group to deflect the asteroid for you.'

        if ("dasteroidredirect" in form) and (anlist.filter(actiontype=5).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.warpfuel < 20:
                        message = 'You do not have enough warpfuel for this event!'
                    else:
                        actionnewsitem.delete()
                        world.warpfuel = F('warpfuel') - 20
                        utilities.rebelschange(world, -20)
                        utilities.contentmentchange(world, -40)
                        world.save(update_fields=['warpfuel'])
                        message = 'You redirect the asteroid onto an area of the planet you know<br>rebels like to hide in. \
                            Any rebels you may have suffer<br>heavy losses, but the population is horrified at you.'

        ##
        ## TYPE 6
        ##
        if ("radmiralignore" in form) and (anlist.filter(actiontype=6).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if random.randint(1,3) == 1:
                        utilities.rebelschange(world, 5)
                        utilities.stabilitychange(world, -20)
                        message = 'It seems you were wrong! Stability drops as <br> the admiral musters rebels to your rule.'
                    else:
                        world.budget = F('budget') + D(500)
                        world.save(update_fields=['budget'])
                        message = 'You were right. The people take your side and you eventually <br> \
                            confiscate the admiral\'s property, sending him off-world.'

                    actionnewsitem.delete()

        if ("radmiralbribe" in form) and (anlist.filter(actiontype=6).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.budget < 250:
                        message = 'You do not have enough money for this event!'
                    elif random.randint(1,10) == 1:
                        world.budget = F('budget') - D(250)
                        utilities.stabilitychange(world, 10)
                        world.save(update_fields=['budget'])
                        message = 'The admiral accepts your payoffs and retires, extolling your <br> \
                            virtues in his retirement speech broadcast around the world.'
                    else:
                        world.budget = F('budget') - D(250)
                        utilities.rebelschange(world, 5)
                        utilities.stabilitychange(world, -20)
                        world.save(update_fields=['budget'])
                        message = 'The admiral takes your money and uses it to raise rebels against your rule!'

                    actionnewsitem.delete()

        if ("radmiralspy" in form) and (anlist.filter(actiontype=6).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if not Spy.objects.filter(owner=world, location=world).exists():
                        message = 'You do not have a spy at home!'
                    elif random.randint(1,4) == 1:
                        utilities.rebelschange(world, 10)
                        utilities.stabilitychange(world, -10)
                        message = 'The admiral survives his \'accident\' and the people, <br> \
                            shocked at your methods, rise up against you.'
                    else:
                        world.budget = F('budget') + D(500)
                        world.save(update_fields=['budget'])
                        message = 'Your spy succeeds in his mission, and the people soon forget what <br> \
                            all the fuss was about. You confiscate the dead admiral\'s property.'

                    actionnewsitem.delete()

        ##
        ## TYPE 7
        ##
        if ("traidersattack" in form) and (anlist.filter(actiontype=7).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    rebelpower = 50
                    worldpower = utilities.militarypower(world, world.region)
                    totworldpower = utilities.powerallmodifiers(world, world.region)
                    worldlist = utilities.regionshiplist(world, world.region)
                    deflosses = [0, 0, 0, 0, 0, 0, 0, 0, 0]
                    deflosses = utilities.war_result(rebelpower, totworldpower, worldpower, worldlist)
                    utilities.warloss_byregion(world, world.region, deflosses)
                    losses = news.losses(deflosses)
                    message = 'You defeated the raiders - the fleet lost %s in the engagement.' % losses
                    actionnewsitem.delete()

        if ("traidersbribe" in form) and (anlist.filter(actiontype=7).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    if world.budget < 500:
                        message = 'You do not have enough money for this event!'
                    elif random.randint(1,10) == 1:
                        world.budget = F('budget') - D(500)
                        utilities.rebelschange(world, 5)
                        world.save(update_fields=['budget'])
                        message = 'The raiders take your money and use it to better equip their <br> \
                            ships and mount more organised attacks in your system!'
                        actionnewsitem.delete()
                    else:
                        world.budget = F('budget') - D(500)
                        world.save(update_fields=['budget'])
                        message = 'The raiders use the payoff to leave for another system.'
                        actionnewsitem.delete()

        if ("traidersignore" in form) and (anlist.filter(actiontype=7).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    utilities.rebelschange(world, 10)
                    message = 'The raiders use the lack of response to organise themselves <br> \
                        and recruit more scum for a greater presence in your system.'
                    actionnewsitem.delete()

        ##
        ## TYPE 8
        ##
        if ("durasteroidmine" in form) and (anlist.filter(actiontype=8).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    duranium = random.randint(70,100)
                    utilities.qolchange(world, -10)
                    world.duranium = F('duranium') + duranium
                    world.save(update_fields=['duranium'])
                    message = 'You managed to extract %s duranium from the asteroid.' % duranium
                    actionnewsitem.delete()

        ##
        ## TYPE 9
        ##
        if ("fuelexplodeaccept" in form) and (anlist.filter(actiontype=9).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    message = 'You send form letters of commiseration to the worker\'s families.'
                    actionnewsitem.delete()

        ##
        ## TYPE 10
        ##
        if ("xenuaccept" in form) and (anlist.filter(actiontype=10).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    utilities.qolchange(world, -10)
                    world.gdp = F('gdp') + 100
                    world.save(update_fields=['gdp'])
                    message = 'Quality of life goes down somewhat from the tortured spirits hassling <br> your population, \
                        but you gain 100 GDP from all the businesses <br> that have popped up to rid them through \'auditing sessions\'.'
                    actionnewsitem.delete()

        if ("xenurefuse" in form) and (anlist.filter(actiontype=10).exists()):
            taskid = request.POST.get('taskid')
            try:
                actionnewsitem = ActionNewsItem.objects.get(pk=taskid)
            except:
                message = 'No such task!'
            else:
                if actionnewsitem.target == world:
                    message = 'The angry despot attempts to detonate a primitive Old Earth bomb <br> on your capital city \
                        but you effortlessly warp it out of existence.<br> Humiliated, he leaves.'
                    actionnewsitem.delete()

    newslist = list(NewsItem.objects.filter(target=world).order_by('-datetime')) # reverse chrono order
    actionnewslist = list(ActionNewsItem.objects.filter(target=world).order_by('-datetime'))

    if len(newslist) == 0:   # Displays 'no news'
        newslist = None
    if len(actionnewslist) == 0:
        actionnewslist = None

    world = World.objects.get(pk=world.pk)
    world.save()

    NewsItem.objects.filter(target=world).update(seen=True)
    ActionNewsItem.objects.filter(target=world).update(seen=True)

    return render(request, 'world_news.html', {'news': newslist, 'actionnews': actionnewslist, 'message':message})
コード例 #7
0
ファイル: policies.py プロジェクト: joancefet/WorldsAtWar
def policies_diplomacy(request):

    # variable setup
    world = request.user.world
    result = None
    if Spy.objects.filter(owner=world, location=world).count() == 0:
        spyform = None
    else:
        spyform = SelectSpyForm(world)

    if request.method == 'POST':
        form = request.POST
        actions = False
        if "createfederation" in form:
            if world.alliance != None:
                result = outcomes.createfederation('AlreadyAllied')
            elif world.alliancepaid:
                return redirect('new_alliance')
            else:
                if world.budget < 200:
                    result = outcomes.nomoney()
                else:
                    actions = {
                        'budget': {
                            'action': 'subtract',
                            'amount': 200
                        },
                        'alliancepaid': {
                            'action': 'set',
                            'amount': True
                        }
                    }
                    utilities.atomic_world(world.pk, actions)
                    return redirect('new_alliance')

        if "trainspy" in form:
            name = form['spyname']
            if world.budget < 500:
                result = outcomes.nomoney()
            elif Spy.objects.filter(owner=world).count() >= 5:
                result = outcomes.trainspy('TooMany')
            elif len(name) > 10:
                result = outcomes.trainspy('TooLong')
            else:
                actions = {'budget': {'action': 'subtract', 'amount': 500}}
                spy = Spy.objects.create(owner=world,
                                         location=world,
                                         name=name)
                if world.sector == 'draco':
                    if world.millevel >= v.millevel('dre'):
                        spy.infiltration = spy.propaganda = spy.gunrunning = spy.intelligence = spy.sabotage = spy.counterint = 4
                    else:
                        spy.infiltration = spy.propaganda = spy.gunrunning = spy.intelligence = spy.sabotage = spy.counterint = 2
                spy.nextaction = v.now() + time.timedelta(hours=4)
                spy.save()
                result = outcomes.trainspy('Success')

        if "counterintel" in form:
            form = SelectSpyForm(world, request.POST)
            if form.is_valid():
                data = form.cleaned_data
                spyid = data['spyselect']
                try:
                    spy = Spy.objects.get(pk=spyid)
                except ObjectDoesNotExist:
                    result = "There is no such spy!"
                else:
                    if world.budget < 100:
                        result = outcomes.nomoney()
                    elif spy.owner != world:
                        result = "This spy does not belong to your intelligence services!"
                    elif spy.location != world:
                        result = "This spy is not at your home world!"
                    elif spy.nextaction > v.now():
                        result = "This spy is currently recovering and unavailable for missions."
                    else:
                        actions = {
                            'budget': {
                                'action': 'subtract',
                                'amount': 100
                            }
                        }
                        killed = 0
                        listkilled = []
                        enemyspies = list(
                            Spy.objects.filter(location=world).exclude(
                                owner=world))
                        for enspy in enemyspies:
                            chance = random.randint(1, 100)
                            if 20 + spy.counterint - enspy.timespent >= chance:
                                killed += 1
                                listkilled.append(enspy)
                                reveal, x = utilities.reveal(enspy)

                                htmldata = news.counterintkilled(enspy, world)
                                NewsItem.objects.create(target=enspy.owner,
                                                        content=htmldata)

                                enspy.delete()

                        spy.nextaction = v.now() + time.timedelta(hours=8)
                        if killed > 0:
                            spy.counterint += 1
                        spy.save()

                        result = outcomes.counterintel(listkilled)
            else:
                result = "You have no spies available!"
        if actions:
            utilities.atomic_world(world.pk, actions)
            world.refresh_from_db()
    money = world.budget
    return render(request, 'policies_diplomacy.html', {
        'result': result,
        'money': money,
        'spyform': spyform
    })
コード例 #8
0
ファイル: policies.py プロジェクト: joancefet/WorldsAtWar
def policies_econ(request):

    # variable setup
    world = request.user.world
    result = rumsodmsg = None
    salvagecost = 2 * (world.salvdur + world.salvtrit + world.salvadam)
    salvagecost = (100 if salvagecost < 100 else salvagecost)
    shownoob = (True if world.gdp <= 115 else None)
    showtrit = (True if world.millevel >= v.millevel('lcr') else False)
    showadam = (True if world.millevel >= v.millevel('hcr') else False)
    rescosts = {
        'warpfuelprod':
        (v.production['warpfuelprod']['cost'] if world.sector != 'cleon' else
         v.production['warpfuelprod']['cost'] * v.bonuses['cleon']),
        'duraniumprod':
        (v.production['duraniumprod']['cost'] if world.sector != 'cleon' else
         v.production['duraniumprod']['cost'] * v.bonuses['cleon']),
        'tritaniumprod':
        (v.production['tritaniumprod']['cost'] if world.sector != 'cleon' else
         v.production['tritaniumprod']['cost'] * v.bonuses['cleon']),
        'adamantiumprod':
        (v.production['adamantiumprod']['cost'] if world.sector != 'cleon' else
         v.production['adamantiumprod']['cost'] * v.bonuses['cleon']),
    }

    if request.method == 'POST':
        form = request.POST
        actions = False
        if "noobgrowthpolicy" in form:
            if world.budget < 70:
                result = outcomes.nomoney()
            elif not shownoob:
                result = outcomes.noobgrowth('TooRich')
            elif world.growth >= 100:
                result = outcomes.toomuchgrowth()
            else:
                actions = {
                    'growth': {
                        'action': 'add',
                        'amount': 2
                    },
                    'budget': {
                        'action': 'subtract',
                        'amount': 70
                    },
                }
                result = outcomes.noobgrowth('Success')

        if "forcedlabour" in form:
            if world.polsystem > -60:
                result = outcomes.forcedlabour('NotDictatorship')
            elif world.stability < -80:
                result = outcomes.forcedlabour('StabilityTooLow')
            else:
                outcome = random.randint(1, 100)
                content = utilities.attrchange(world.contentment, -10)
                stability = utilities.attrchange(world.stability, -5)
                actions = {
                    'contentment': {
                        'action': 'add',
                        'amount': content
                    },
                    'stability': {
                        'action': 'add',
                        'amount': stability
                    },
                }
                if 15 < outcome <= 100:
                    actions.update({'growth': {'action': 'add', 'amount': 5}})
                if 1 <= outcome <= 5:
                    actions.update({'rebels': {'action': 'add', 'amount': 10}})
                result = outcomes.forcedlabour(outcome)

        if "nationalise" in form:
            if world.econsystem == -1:
                result = outcomes.nationalise('NotFreeOrMixed')
            elif world.econchanged:
                result = outcomes.nationalise('Already')
            else:
                stab = utilities.attrchange(world.stability, -20)
                actions = {
                    'econchanged': {
                        'action': 'set',
                        'amount': True
                    },
                    'stability': {
                        'action': 'add',
                        'amount': stab
                    },
                    'econsystem': {
                        'action': 'subtract',
                        'amount': 1
                    },
                }
                result = outcomes.nationalise('Success')

        if "privatise" in form:
            if world.econsystem == 1:
                result = outcomes.privatise('NotCPorMixed')
            elif world.econchanged:
                result = outcomes.nationalise('Already')
            else:
                stab = utilities.attrchange(world.stability, -20)
                actions = {
                    'econchanged': {
                        'action': 'set',
                        'amount': True
                    },
                    'stability': {
                        'action': 'add',
                        'amount': stab
                    },
                    'econsystem': {
                        'action': 'subtract',
                        'amount': 1
                    },
                }
                result = outcomes.privatise('Success')

        if 'build' in form:
            if form['build'] in v.production:
                build = form['build']
                if build == 'warpfuelprod' or build == 'duraniumprod':
                    canbuild = True
                elif build == 'tritaniumprod' and showtrit:
                    canbuild = True
                elif build == 'adamantiumprod' and showadam:
                    canbuild = True
                else:
                    canbuild = False
                if canbuild:
                    if world.budget < v.production[build]['cost']:
                        result = outcomes.nomoney()
                    else:
                        actions = {
                            'budget': {
                                'action': 'subtract',
                                'amount': D(rescosts[build])
                            }
                        }
                        modifier = v.production[build]['chance']
                        if modifier > 10:
                            modifier = (modifier - 30 if world.sector
                                        == "cleon" else modifier)
                        else:
                            modifier = (modifier - 3 if world.sector == "cleon"
                                        else modifier)

                        if modifier < random.randint(1, 100) <= 100:
                            actions.update({
                                build: {
                                    'action': 'add',
                                    'amount': v.production[build]['production']
                                }
                            })
                            result = outcomes.prospecting[build]('Success')
                        else:
                            result = outcomes.prospecting[build]('Failure')
                result = "You've been a naughty boy"

        if 'close' in form:
            form = mineshutdownform(world, request.POST)
            if form.is_valid():
                prodtype = form.cleaned_data['mine']
                actions = {
                    prodtype: {
                        'action': 'subtract',
                        'amount': v.production[prodtype]['production']
                    },
                    'inactive_%s' % prodtype: {
                        'action': 'add',
                        'amount': 1
                    }
                }
                result = outcomes.shutdown(prodtype[:-4])
            else:
                result = outcomes.nomines(prodtype[:-4])

        if 'reopen' in form:
            form = reopenmineform(world, request.POST)
            if form.is_valid():
                prodtype = form.cleaned_data['mine']
                actions = {
                    'inactive_%s' % prodtype: {
                        'action': 'subtract',
                        'amount': 1
                    },
                    'resuming_%s' % prodtype: {
                        'action': 'add',
                        'amount': 1
                    },
                }
                result = outcomes.reopen(prodtype[:-4])
            else:
                result = "Inspect element is naughty (and won't work)"

        if "salvagemission" in form:
            if world.budget < salvagecost:
                result = outcomes.nomoney()
            elif world.turnsalvaged:
                result = outcomes.salvagemission('AlreadySalvaged')
            elif world.salvdur + world.salvtrit + world.salvadam == 0:
                result = outcomes.salvagemission('NoSalvage')
            else:
                salvmin = (70 if world.sector == 'C' else 60)
                salvmax = (80 if world.sector == 'C' else 70)
                dur = int(
                    round(world.salvdur * random.randint(salvmin, salvmax) /
                          100.0))
                trit = int(
                    round(world.salvtrit * random.randint(salvmin, salvmax) /
                          100.0))
                adam = int(
                    round(world.salvadam * random.randint(salvmin, salvmax) /
                          100.0))
                actions = {
                    'budget': {
                        'action': 'subtract',
                        'amount': D(salvagecost)
                    },
                    'salvdur': {
                        'action': 'subtract',
                        'amount': dur
                    },
                    'duranium': {
                        'action': 'add',
                        'amount': dur
                    },
                    'salvtrit': {
                        'action': 'subtract',
                        'amount': trit
                    },
                    'tritanium': {
                        'action': 'add',
                        'amount': trit
                    },
                    'salvadam': {
                        'action': 'subtract',
                        'amount': adam
                    },
                    'adamantium': {
                        'action': 'add',
                        'amount': adam
                    },
                    'turnsalvaged': {
                        'action': 'set',
                        'amount': True
                    },
                }
                result = outcomes.salvagemission([dur, trit, adam])

        if "rumsodecon" in form:  #make more powerful, is way useless
            if world.rumsoddium != 4:
                result = 'You do not have enough rumsoddium for the ritual!'
            else:
                actions = {
                    'gdp': {
                        'action': 'add',
                        'amount': world.gdp
                    },
                    'budget': {
                        'action': 'add',
                        'amount': D(world.gdp * 6)
                    },
                    'warpfuel': {
                        'action': 'add',
                        'amount': world.warpfuel
                    },
                    'duranium': {
                        'action': 'add',
                        'amount': world.duranium
                    },
                    'tritanium': {
                        'action': 'add',
                        'amount': world.tritanium
                    },
                    'adamantium': {
                        'action': 'add',
                        'amount': world.adamantium
                    },
                    'rumsoddium': {
                        'action': 'set',
                        'amount': 0
                    }
                }
                rumsodmsg = v.rumsodeconomy
                utilities.rumsoddiumhandout()
        if actions:  #easier than putting the line in every policy conditional
            utilities.atomic_world(world.pk, actions)
            world.refresh_from_db()

    salvagecost = 2 * (world.salvdur + world.salvtrit + world.salvadam)
    salvagecost = (100 if salvagecost < 100 else salvagecost)
    salvagetext = news.salvagetext(world.salvdur, world.salvtrit,
                                   world.salvadam)
    rumpolicy = (True if world.rumsoddium == 4 else None)

    return render(
        request, 'policies_econ.html', {
            'result': result,
            'rescosts': rescosts,
            'world': world,
            'shownoob': shownoob,
            'pvalues': v.production,
            'shutterform': mineshutdownform(world),
            'showtrit': showtrit,
            'showadam': showadam,
            'rumpolicy': rumpolicy,
            'rumsodmsg': rumsodmsg,
            'salvagecost': salvagecost,
            'salvagetext': salvagetext
        })
コード例 #9
0
ファイル: utilities.py プロジェクト: heidi666/WorldsAtWar
def levellist():
    'Returns a list of millevels.'
    return v.millevel('cor'), v.millevel('lcr'), v.millevel('des'), v.millevel('fri'), \
     v.millevel('hcr'), v.millevel('bcr'), v.millevel('bsh'), v.millevel('dre')
コード例 #10
0
ファイル: utilities.py プロジェクト: joancefet/WorldsAtWar
def levellist():
    'Returns a list of millevels.'
    return v.millevel('cor'), v.millevel('lcr'), v.millevel('des'), v.millevel('fri'), \
     v.millevel('hcr'), v.millevel('bcr'), v.millevel('bsh'), v.millevel('dre')