Exemplo n.º 1
0
def doTechnologyResearchOrder(entry):
    mbo = TechnologyResearchOrder.objects.get(got=entry)
    tech = mbo.mother.owner.technology
    
    tech.setTechnologyLevelById(mbo.what, tech.getTechnologyLevelById(mbo.what) + 1)
    tech.save()
    
    if (mbo.what == 2) or (mbo.what == 3):
        from bellum.common.fixtures.resources import recalc
        recalc(mbo.mother.owner)
        
    mbo.delete()
Exemplo n.º 2
0
def doMotherConstructOrder(entry):
    mbo = MotherConstructionOrder.objects.get(got=entry)
    mum = mbo.mother
    
    mum.setConstructionLevelById(mbo.what, mum.getConstructionLevelById(mbo.what) + 1)
    mum.save()

    if mbo.what in (1,2):           # enlarged Dust Collector or Quarters
        from bellum.common.fixtures.resources import recalc
        recalc(mum.owner)
        
    mbo.delete()
Exemplo n.º 3
0
def doProvinceBuildOrder(entry):
    pp = ProvinceBuildOrder.objects.get(got=entry)

    otype, olvl = pp.ppresence.getPair(pp.slot)
    if otype != 0:
        pp.ppresence.setPair(pp.slot, pp.what, olvl+1)
    else:
        pp.ppresence.setPair(pp.slot, pp.what, 1)

    pp.ppresence.save()
    
    if pp.what in (1,2,3):
        recalc(pp.ppresence.owner)

    pp.delete()  
Exemplo n.º 4
0
def doLandarmyPlanetaryStrikeOrder(entry):
    '''
        If order was to reinforce, signal Exception
    '''
    lpso = LandarmyPlanetaryStrikeOrder.objects.get(got=entry)

    wtd = whatToDo(lpso.mother.owner, lpso.province, lpso.designation)

    if wtd == 'REINFORCE':
        if lpso.mother.owner == lpso.province.presence.owner:      # Reinforce own province
            lpso.province.presence.garrison += lpso.garrison
            lpso.province.presence.garrison.save()
            lpso.garrison.delete()
            lpso.delete()
            return
                                                             # Reinforce somebody's else province
        try:
            reinforcement = lpso.province.presence.reinforcement_set.get(owner=lpso.mother.owner)
        except:                          # I have no reinforcements in this province
            Reinforcement(None, lpso.mother.owner.id, lpso.province.presence.id, lpso.garrison.id, lpso.orders).save()
            lpso.delete()
            return
        else:                            # I do have reinforcements on this province
            reinforcement.garrison += lpso.garrison
            reinforcement.garrison.save()
            lpso.garrison.delete()
            lpso.delete()
            return
    elif wtd == 'FALLBACK':
        lmpo = LandarmyMotherPickupOrder(None, lpso.got.id, lpso.mother.id, lpso.province.id, lpso.garrison.id)
        lmpo.save()
        lpso.got.ordertype = 8
        lpso.got.to_be_completed += timedelta(0, int(pmmovelen(lpso.province, lpso.mother, lpso.garrison)))
        lpso.got.save()
        lpso.delete()
        raise DontRemoveGOT
    elif wtd == 'ASSAULT':
        try:
            lpso.province.presence          # If uninhabited?
        except:
            pres = ProvintionalPresence(id=None,
                                        garrison=lpso.garrison,
                                        owner=lpso.mother.owner,
                                        province=lpso.province,
                                        garrison_orders=lpso.orders)
            pres.save()
            lpso.delete()
            return

        report = WarfareReport()
        report.initializeEnvironment(lpso.mother, lpso.province, datetime.now())
        report.initializeParties(lpso.mother.owner, lpso.province.presence.owner)
        attacker_army, defender_army = prepare(lpso)
        attacker_won = perform(attacker_army, defender_army, report, is_drop=True)
        cleanup(attacker_army, defender_army, report, attacker_won)

        rep = makeReport(report, u'Raport wojenny z '+lpso.province.name)
        sendTo(rep, lpso.mother.owner, False)
        sendTo(rep, lpso.province.presence.owner, False)
        for reinf in lpso.province.presence.reinforcement_set.all():
            sendTo(rep, reinf.owner, False)

        note(None, LX_DROP_COMBAT_LAND, attacker_id=lpso.mother.owner,
                                        defender_id=lpso.province.presence.owner,
                                        province_id=lpso.province,
                                        attacker_won=attacker_won)

        if attacker_won:
            defender = lpso.province.presence.owner
                    # Elliminate all reinforcements
            reinfs = Reinforcement.objects.filter(presence=lpso.province.presence)
            for reinf in reinfs:
                reinf.garrison.delete()
                reinf.delete()

            lpso.province.presence.unsettle_dueToAssault()

            lpso.province.presence.garrison.clone(lpso.garrison)# Copy to presence's garrison info about garrison
            lpso.province.presence.garrison.save()

            lpso.province.presence.owner = lpso.mother.owner  # Change owner
            lpso.province.presence.save()

            lpso.garrison.delete()

            from bellum.common.fixtures.resources import recalc
            recalc(defender)
            recalc(lpso.mother.owner)
        if attacker_won in (False, None):       # save garrisons
            # Save all reinforcement garrisons, delete if necessary
            for reinf in lpso.province.presence.reinforcement_set.all():
                if reinf.garrison.isZero():
                    reinf.garrison.delete()
                    reinf.delete()
                else:
                    reinf.garrison.save()

            lpso.province.presence.garrison.save()
            if attacker_won == False: lpso.garrison.delete()
        if attacker_won == None:
            lpso.garrison.save()
            lpso.fallback()
            raise DontRemoveGOT

        lpso.delete()    
Exemplo n.º 5
0
def doLandarmyProvintionalStrikeOrder(entry, lpso=None):
    '''
        If order was to reinforce, signal Exception
    '''

    if lpso == None: lpso = LandarmyProvintionalStrikeOrder.objects.get(got=entry)

    wtd = whatToDo(lpso.attacker, lpso.dstprovince, lpso.designation)

    if wtd == 'REINFORCE':
        if lpso.attacker == lpso.dstprovince.presence.owner:      # Reinforce own province
            lpso.dstprovince.presence.garrison  # make sure it's ready
            lpso.dstprovince.presence.garrison += lpso.garrison
            lpso.garrison.delete()
            lpso.dstprovince.presence.garrison.save()
            lpso.delete()
            return
        try:
            reinforcement = lpso.dstprovince.presence.reinforcement_set.get(owner=lpso.attacker)
        except: # Was not previously reinforced, need to make new classes
            Reinforcement(None, lpso.attacker.id, lpso.dstprovince.presence.id, lpso.garrison.id, lpso.orders).save()
            lpso.delete()
            return
        else:   # Reinforce already reinforced troops
            reinforcement.garrison += lpso.garrison
            reinforcement.garrison.save()
            lpso.garrison.delete()
            lpso.delete()
            return
    elif wtd == 'FALLBACK':
        lpso.directiveFallback(0)
        raise DontRemoveGOT
    elif wtd == 'ASSAULT':
        try:
            lpso.dstprovince.presence             # If uninhabited?
        except:
            pres = ProvintionalPresence(id=None,
                                        garrison=lpso.garrison,
                                        owner=lpso.attacker,
                                        province=lpso.dstprovince,
                                        garrison_orders=0)
            pres.save()
            lpso.delete()
            return

        # War!
        # lpso.attacker WITH HIS lpso.garrison IS ATTACKING lpso.dstprovince

        report = WarfareReport()
        report.initializeEnvironment(lpso.srcprovince, lpso.dstprovince, datetime.now())
        report.initializeParties(lpso.attacker, lpso.dstprovince.presence.owner)
        attacker_army, defender_army = prepare(lpso)
        attacker_won = perform(attacker_army, defender_army, report)
        cleanup(attacker_army, defender_army, report, attacker_won)

        rep = makeReport(report, u'Raport wojenny z '+lpso.dstprovince.name)
        sendTo(rep, lpso.attacker, False)
        sendTo(rep, lpso.dstprovince.presence.owner, False)
        for reinf in lpso.dstprovince.presence.reinforcement_set.all():
            sendTo(rep, reinf.owner, False)


        note(None, LX_PROVINCE_COMBAT_LAND, attacker_id=lpso.attacker.id,
                                                defender_id=lpso.dstprovince.presence.owner.id,
                                                source_pid=lpso.srcprovince.id,
                                                target_pid=lpso.dstprovince.id,
                                                attacker_won=attacker_won)

        if attacker_won == True:
            defender = lpso.dstprovince.presence.owner

            lpso.dstprovince.presence.unsettle_dueToAssault()

            lpso.dstprovince.presence.garrison.clone(lpso.garrison)
            lpso.dstprovince.presence.garrison.save()
            lpso.dstprovince.presence.owner = lpso.attacker
            lpso.dstprovince.presence.save()
            lpso.garrison.delete()

            # Slay all reinforcement garrisons
            for reinf in lpso.dstprovince.presence.reinforcement_set.all():
                reinf.garrison.delete()
                reinf.delete()                            
                
            from bellum.common.fixtures.resources import recalc
            recalc(defender)
            recalc(lpso.attacker)
        else: # if (attacker_won == False) or (attacker_won == None):
            # Save all reinforcement garrisons, delete if necessary
            for reinf in lpso.dstprovince.presence.reinforcement_set.all():
                if reinf.garrison.isZero():
                    reinf.garrison.delete()
                    reinf.delete()
                else:
                    reinf.garrison.save()

            lpso.dstprovince.presence.garrison.save()
            if attacker_won == False: lpso.garrison.delete()
        if attacker_won == None:  # stalemate
            # pack attackers bags and send him home
            lpso.garrison.save()
            lpso.directiveFallback()
            raise DontRemoveGOT
    
        lpso.delete()