import Director
import VS
class armada(Director.Mission):
def ResetCount(self):
self.count={}
for i in self.factions:
self.count[i]=0
def __init__(self,filename,factions=("confed","kilrathi")):
Director.Mission.__init__(self)
self.filename=filename
self.factions=factions
self.enum=0
self.ResetCount();
self.ended=False
self.timer=0
self.begun=0
self.unitlist=[]
self.loser=""
def WriteFile(self):
loser=self.loser
ret={}
lret=[]
for i in self.factions:
if (i!=loser):
ret[i]=[]
for un in self.unitlist:
if un:
fac=un.getFactionName()
if (un.getName()!='Pilot' and un.GetHull()>0):
if fac in ret:
ret[fac].append(un.getName());
elif fac==loser:
lret.append(un.getName())
fret=[]
for i in ret:
fret+=[(i,ret[i])]
fret+=[(loser,lret)]
f=open(self.filename,"w")
f.write(str(fret))
f.close()
def EndMission(self,loser):
print "ENDED with Loser:"+loser
self.loser=loser
self.ended=True
self.timer=VS.GetGameTime()+10
def Execute(self):
if not self.begun:
self.begun=1
un=VS.getUnit(0)
index=0
while(un):
self.unitlist.append(un)
index+=1
un=VS.getUnit(index)
if not self.ended:
#print "exec"
for i in self.count:
self.count[i]=0
for un in self.unitlist:
if(un and un.getName()!='Pilot' and not un.isDockableUnit() ):#don't count dockable units
fac = un.getFactionName()
if fac in self.count:
self.count[fac]+=1
for i in self.count:
if self.count[i]==0:
self.EndMission(i)
elif VS.GetGameTime()>=self.timer:
self.WriteFile()
import sys
sys.exit(0)