Пример #1
0
def attackFlightgroup (fgname, faction, enfgname, enfaction,iscap):
    global dnewsman_
    if (iscap):
        battlename=dnewsman_.TYPE_FLEETBATTLE
        (leader,enleader)=iscap.split(",")
    else:
        battlename = dnewsman_.TYPE_BATTLE
        leader = fg_util.getFgLeaderType(fgname,faction)
        enleader = fg_util.getFgLeaderType(enfgname,enfaction)
    sys = fg_util.FGSystem (fgname,faction)
    ensys = fg_util.FGSystem (enfgname,enfaction)
    if (sys==ensys):
        if (0 and VS.systemInMemory(sys)):
            VS.pushSystem(sys)
            LaunchEqualShips (fgname,faction,enfgname,enfaction)
            VS.TargetEachOther (fgname,faction,enfgname,enfaction)
            VS.popSystem()
        #debug.debug('duke '+fgname + ' '+enfgname)
        SimulatedDukeItOut (fgname,faction,enfgname,enfaction)
    elif (sys!='nil' and ensys!='nil'):
        #pursue other flightgroup
        import universe
        adjSystemList=universe.getAdjacentSystemList(sys)
        if ensys in adjSystemList:
            fg_util.TransferFG (fgname,faction,ensys)
        else:
            return 0
    else:
        return 0 #debug.debug('nil DRAW error')
    if (fg_util.NumShipsInFG(fgname,faction)==0):
        if (fg_util.NumShipsInFG(enfgname,enfaction)==0):
            dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),battlename,dnewsman_.STAGE_END,faction,enfaction,dnewsman_.SUCCESS_DRAW,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgname,leader,enfgname,enleader])
        else:
            dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),battlename,dnewsman_.STAGE_END,faction,enfaction,dnewsman_.SUCCESS_LOSS,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgname,leader,enfgname,enleader])
        return 0
    elif (fg_util.NumShipsInFG(enfgname,enfaction)==0):
        dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),battlename,dnewsman_.STAGE_END,faction,enfaction,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgname,leader,enfgname,enleader])
        return 0
    if (vsrandom.randrange(0,4)==0):
        #FIXME  if it is advantageous to stop attacking only!!
        #FIXME add a stop attacking news report?  -- this should now be fixed, as a draw is reported (not heavilly tested)
        #CAUSES TOO MUCH NEWS#Director.pushSaveString(0,"dynamic_news",dynamic_news.makeVarList([str(Director.getSaveData(0,"stardate",0)),battlename,"end",faction,enfaction,"0",str(getImportanceOfSystem(sys)),sys,"all",fgname,leader,enfgname,enleader]))
        return 0
    if (vsrandom.randrange(0,4)==0 and enfgname!=fg_util.BaseFGInSystemName(ensys)):
        #FIXME  if it is advantageous to run away only
        #FIXME add a retreat news report?  -- this should now be fixed, as a draw is reported (not heavilly tested)
        #CAUSES TOO MUCH NEWS#Director.pushSaveString(0,"dynamic_news",dynamic_news.makeVarList([str(Director.getSaveData(0,"stardate",0)),battlename,"end",faction,enfaction,"-1",str(getImportanceOfSystem(sys)),sys,"all",fgname,leader,enfgname,enleader]))
        num=VS.GetNumAdjacentSystems(ensys)
        if (num>0):
            ensys=VS.GetAdjacentSystem(ensys,vsrandom.randrange(0,num))
            fg_util.TransferFG (fgname,faction,ensys)
    return 1
Пример #2
0
def LookForTrouble (faction):
    global lftiter
    key = fg_util.MakeFactionKey(faction)
    numfg=Director.getSaveStringLength(fg_util.ccp,key)
    if (lftiter>=numfg):
        lftiter=0
        if (0 and numfg):
            AddFighterTo(Director.getSaveString(fg_util.ccp,key,vsrandom.randrange(0,numfg)),faction,False)
        if faction in faction_ships.fighterProductionRate:
            AddFighterTo("Alpha",faction,True)
        return 0
    i = Director.getSaveString(fg_util.ccp,key,lftiter)
    lftiter+=1
    sys = fg_util.FGSystem (i,faction)
    citizen=VS.isCitizen(faction)
    if (sys!='nil'):
        if not citizen:
            enfac = faction_ships.get_enemy_of(faction)
            foundanyone=0
            l=fg_util.AllFGsInSystem(enfac,sys)
            j=vsrandom.randrange(0,len(l)+3)
            if (j<len(l)):
                foundanyone=1 #FIXME include some sort of measure "can I win"
                if (vsrandom.randrange(0,5)==0):
                    initiateAttack(i,faction,sys,l[j],enfac)
            elif (vsrandom.randrange(0,3)==0):
                randomMovement (i,faction)
        elif (vsrandom.randrange(0,3)==0):
            randomMovement (i,faction)
    return 1
Пример #3
0
def AddFighterTo(fgname,fac,isNew=False):
    sys = VS.getSystemFile()
    #debug.debug('add fighter')
    numsystems = generate_dyn_universe.systemcount[fac]
    if (VS.GetGalaxyFaction(sys)!=fac):
        try:
            homeworlds=faction_ships.production_centers
        except:
            homeworlds=faction_ships.homeworlds
        if fac in homeworlds:
            if type(homeworlds[fac])==type(""):
                sys=homeworlds[fac]
            else:
                sys=homeworlds[fac][vsrandom.randrange(0,len(homeworlds[fac]))]
    numfighters = int(generate_dyn_universe.XProductionRate(fac,faction_ships.fighterProductionRate)*numsystems)
    try:
        if fac in faction_ships.staticFighterProduction:
            numfighters+=faction_ships.staticFighterProduction[fac]
    except:
        pass
    if (numfighters<1):
        if (vsrandom.uniform(0,1)<numfighters):
            numfighters=1
    #debug.debug("Generating "+str(numfighters)+ " fighters for "+fac+" at "+sys)
    if isNew:
        fgk=fg_util.FGsInSystem(fac,sys)        
        if len(fgk):
            fgname=fgk[vsrandom.randrange(0,len(fgk))]
            stat=6
            if fac in faction_ships.fightersPerFG:
                stat=faction_ships.fightersPerFG[fac]
            elif "default" in faction_ships.fightersPerFG:
                stat=faction_ships.fightersPerFG["default"]
            if fg_util.NumShipsInFG(fgname,fac)+numfighters<=numfighters+stat:
                isNew=False
        if isNew:
            fgname=generate_dyn_universe.GetNewFGName(fac)
    if numfighters>=1:
        fg_util.AddShipsToFG (fgname,fac,((faction_ships.getRandomFighter(fac),int(numfighters)),),sys)
    numcapships = generate_dyn_universe.XProductionRate(fac,faction_ships.capitalProductionRate)*numsystems
    if (numcapships<1):
        if (vsrandom.uniform(0,1)>numcapships):
            return
        numcapships=1
    sys = fg_util.FGSystem(fgname,fac)
    if (1 or VS.GetGalaxyFaction(sys)!=fac):
        try:
            homeworlds=faction_ships.production_centers
        except:
            homeworlds=faction_ships.homeworlds
        if fac in homeworlds:
            if type(homeworlds[fac])==type(""):
                sys=homeworlds[fac]
            else:
                sys=homeworlds[fac][vsrandom.randrange(0,len(homeworlds[fac]))]
    cap =faction_ships.getRandomCapitol(fac)
    #debug.debug("Generating "+str(numcapships)+ " capship "+cap+" for "+fac+" at "+sys)
    fg_util.AddShipsToFG(fgname,fac,((cap,int(numcapships)),),sys)
Пример #4
0
def stopAttack (fgname,faction):
    ally=(fgname,faction)
    if ally in attacklist:
        enemy = attacklist[ally]
        sys = fg_util.FGSystem (fgname,faction)
        if (VS.systemInMemory(sys)):
            VS.pushSystem(sys)
            VS.StopTargettingEachOther(fgname,faction,enemy[0],enemy[1])
            VS.popSystem()
        del defendlist[(enemy[0],enemy[1])]
        del attacklist[ally]
Пример #5
0
def KillOne (fg,fac,tn,num,enfg,enfac):
    sys = fg_util.FGSystem(fg,fac)
    numkilled= fg_util.RemoveShipFromFG(fg,fac,tn[0],num,1)
    chancetoeject=.25
    global ejectbuildup
    if (ejectbuildup>=(1-chancetoeject)**numkilled):
        global rescuelist
        rescuelist[sys]=(fac,enfg,enfac)
        #debug.debug(rescuelist[sys])
        ejectbuildup=0
    else:
        ejectbuildup+=chancetoeject
    return numkilled
Пример #6
0
def randomMovement(fg,fac):
    import universe
    import fg_util
    citizen=VS.isCitizen(fac)
    sys=fg_util.FGSystem(fg,fac)
    convoywhere=fg.find("->")
    if (convoywhere!=-1):
        endpoints=[fg[0:convoywhere],fg[convoywhere+2:]]
        
    if fg.find("Insys")!=-1:
        return#can't go about moving insys fgs away
    if (sys!='nil' and fg!=fg_util.BaseFGInSystemName(sys)):
        l = universe.getAdjacentSystemList(sys)
        nthis = fg_util.NumFactionFGsInSystem(fac,sys)
        if (len(l)):
            suggestednewsys = l[vsrandom.randrange(0,len(l))]
            sugfac=VS.GetGalaxyFaction(suggestednewsys)
            sugrel=VS.GetRelation(fac,sugfac)
            
            if convoywhere==-1 and (((fac.find(sugfac)!=-1 or sugrel>.5) and citizen) or not citizen):
                fg_util.TransferFG( fg,fac,suggestednewsys);
                #debug.debug('moving '+fg+' from '+sys+' to '+ suggestednewsys)
            else:
                for i in l:
                    ifac = VS.GetGalaxyFaction(i)
                    #if (ifac==fac and nthis > fg_util.NumFactionFGsInSystem(fac,i)):
                    #    suggestednewsys = i
                    likes=False
                    if convoywhere!=-1:
                        if endpoints[0]==i or endpoints[1]==i:
                            likes=True
                    elif VS.GetRelation(fac,ifac)>.5:
                        likes=True
                    if (likes):
                        fg_util.TransferFG(fg,fac,i)
                        return
                #debug.debug('moving '+fg+' from '+sys+' to '+ suggestednewsys)
                fg_util.TransferFG( fg,fac,suggestednewsys);
        else:
            pass #debug.debug("flightgroup "+fg+" in system "+sys + " is stuck")
Пример #7
0
def SimulateBattles():
    global deadbattles
    global cpsal
    global attacklist
    global simulateiter
    global deadbattlesiter
    if simulateiter==None:
        if (deadbattlesiter!=-2):
            if (deadbattlesiter<0):
                deadbattlesiter=-2
                return 0
            else:
                stopAttack(deadbattles[deadbattlesiter][0],deadbattles[deadbattlesiter][1])
                deadbattlesiter-=1
                return 1
        else:
            persystemattacklist=cpsal
            cpsal = {}
            simulateiter= attacklist.iteritems()

    try:
        ally = simulateiter.next()
        godoit=1
    except StopIteration:
        simulateiter = None
        deadbattlesiter = len(deadbattles)-1
        godoit=0
        import sys
        debug.debug(str(sys.exc_info()[0])+str(sys.exc_info()[1]))
    if (godoit):
        enemy = ally[1]
        ally = ally[0]
        if (not attackFlightgroup (ally[0],ally[1],enemy[0],enemy[1],enemy[2])):
            deadbattles+=[(ally[0],ally[1])]
        else:
            sys = fg_util.FGSystem(ally[0],ally[1])
            if not (sys in cpsal):
                cpsal[sys]=[]
            cpsal[sys]+=[((ally[0],ally[1]),(enemy[0],enemy[1]))]#continue the battle
    return 1
Пример #8
0
def Siege(fac):
    global siegenumber
    global siegenumtimes
    global siegeprob
    #       turns_till_siege_effective=100
    if (not fac in faction_ships.siegingfactions):
        return
    numfg= fg_util.NumAllFlightgroups(fac)
    if (numfg):
        if (siegenumber==0):
            siegeprob = float(numfg)/float(faction_ships.siegingfactions[fac]);
            siegenumtimes = int (siegeprob)
            if (siegenumtimes==0):
                siegenumtimes=1
            else:
                siegeprob =1
        if siegenumber>=siegenumtimes:
            siegenumber=0
            return 0
        else:
            if (vsrandom.uniform(0,1)<siegeprob):
                fg =fg_util.RandomFlightgroup(fac)
                sys = fg_util.FGSystem(fg,fac)
                enfac=VS.GetGalaxyFaction(sys)
                if (not sys in faction_ships.invincible_systems):
                    #fg_util.CheckAllShips(fac)
                    #fg_util.CheckAllShips(enfac)
                    if enfac == "unknown":
                        debug.debug("exploration: "+sys)
                        fgleader = fg_util.getFgLeaderType(fg,fac)
                        exploration = 1

                    else:
                        exploration = 0
                    if (VS.GetRelation(fac,enfac)<0 and neighborFaction(sys,fac)):#FIXME maybe even less than that
                        numenemyfg = fg_util.NumFactionFGsInSystem(enfac,sys)
                        numfriendfg = fg_util.NumFactionFGsInSystem(fac,sys)
                        #debug.debug('siegarol enemioes '+str(numenemyfg)+ ' friends '+str(numfriendfg))
                        global dnewsman_
                        if exploration:
                            if sys != 'nil':
                                generate_dyn_universe.TakeoverSystem(fac,sys)
                                #HACK, regenerate bases instnatly
                                dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_EXPLORATION,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fg,fgleader,"unknown","unknown"])
                                                                        #FIXME use keyword (ignore
                                                                        #keyword for now Daniel)

                        elif (numenemyfg==0 and numfriendfg==0): #If both annihalate each other completely (unlikely but possible)
                            facnum = VS.GetFactionIndex (fac)
                            debug.debug('cehcking started')
                            debug.error("DRAW error "+fg+" sys has "+sys+" has " +str(fg_util.NumFactionFGsInSystem(fac,sys))+" String is "+Director.getSaveString(0,fg_util.MakeStarSystemFGKey(sys),facnum))
                            if sys != 'nil':
                                dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_SIEGE,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fg,"unknown","unknown","unknown"])
                                                                        #FIXME use keyword (ignore
                                                                        #keyword for now Daniel)

                        elif (numenemyfg==0 and (fg_util.CapshipInFG(fg,fac) or moveSurroundingCapshipsToSiege(fac,sys))):      #If aggressor succeeded
                            debug.debug(fac + ' took over '+ sys + ' originally owned by '+enfac)
                            #ok now we have him... while the siege is going on the allies had better initiate the battle--because we're now defending the place...  so that means if the owners are gone this place is ours at this point in time
                            fgs = fg_util.FGsInSystem(fac,sys)
                            if (len(fgs)>0):
                                fgs=fgs[0]
                            else:
                                fgs = "unknown"
                            if sys != 'nil':
                                dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_SIEGE,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgs,"unknown","unknown","unknown"])
                                                                        #FIXME use keyword (ignore
                                                                        #keyword for now Daniel)

                            generate_dyn_universe.TakeoverSystem(fac,sys)
                            #HACK, regenerate bases instnatly

                        elif (numfriendfg==0):  #If aggressor lost
                            debug.error('wtf!!')
                            fgs = fg_util.FGsInSystem(enfac,sys)
                            if (len(fgs)>0):
                                fgs=fgs[0]
                            else:
                                fgs = "unknown"
                            if sys != 'nil':
                                dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_SIEGE,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_LOSS,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,"unknown","unknown",fgs,"unknown"])
                                                                        #FIXME use keyword (ignore
                                                                        #keyword for now Daniel)


                        #FIXME add if statements if there is instead a (non appocalyptic) draw (if waring factions have relations "almost neutral" you could have a cease fire, or if the two factions are evenly matched and go nowhere a withdraw of the attackers might occur)!!!
            siegenumber+=1
        return 1
    else:
        return 0