I've been trying to fix the issue where when a team only consists of zombies, it doesn't get killed off, with the added issue of a never ending loop when only zombies are left in the game. I've had mixed results, with the team consisting of only zombies getting killed
some of the time, but not consistently... If anyone could help that would be great
This is the simple logic I used:
x = amount of worms left in team
y = amount of zombies in team
if x == y; set health of all worms in team to 0 (thus killing them off)
(A different approach could be to remove the team tag from a worm, maybe that could fix the issue as well, not sure if that is at all possible...)
Code:
//Kill off team if it consists only of Zombie Worms
//Mod by raffie
void destroyTeam(int teamIndex){
for (local wormIndex = 1; wormIndex <= 8; wormIndex++){
GS->Info.SetWormHealth(teamIndex, wormIndex, 0);
}
}
override void CWorm::Message(CObject* sender,EMType Type,int MSize,CMessageData* MData)
{
super;
if(Type == M_FRAME)
//if(Type == M_TURNEND)
{
//local w = GetCurrentWorm();
//local fullWormCount = 0;
//local teamCount = 0;
//local initialWormCount = 0;
//local wormCount = 0;
//local zombieWormCount = 0;
int fullWormCount = 0;
int teamCount = 0;
int initialWormCount = 0;
int wormCount = 0;
int zombieWormCount = 0;
local wormTeamLoop;
//Get amount of Worms in Team at Start
for (local worm = 0; worm < GS->Info.Teams[1].NWorms; worm++){
initialWormCount++;
}
//Get amount of teams
for (local team = 0; team < 6; team++) {
for (local worm0 = 0; worm0 < GS->Info.Teams[team].NWorms; worm0++){
fullWormCount++;
}
}
teamCount = (fullWormCount/initialWormCount);
for (local team = 0; team < teamCount; team++) {
wormCount = 0;
zombieWormCount = 0;
wormTeamLoop = (team+1);
//Current Worm count
for (local worm = 0; worm < GS->Info.Teams[team].NWorms; worm++){
if (GS->Info.Teams[team].Worms[worm].State != 135){ // if not dead
wormCount++;
}
//if(wormTeamLoop == teamCount){ wormTeamLoop = 0; }
//if (GS->Info.Teams[wormTeamLoop].Worms[worm].State != 135){ // if not dead
local w = CWorm(Root->GetObject(2, 16 * wormTeamLoop + worm));
//if (w->Zombie){ zombieWormCount++; }
if(w != NullObj){if(w->Zombie == true)zombieWormCount = zombieWormCount + 1;}
//}
}
//GG->WriteToChat(14, StrCon(StrCon("TEAM ", displayInt(team)), ""), false);
//GG->WriteToChat(14, StrCon(StrCon("LOOP ", displayInt(wormTeamLoop)), ""), false);
if(w != NullObj){
//GG->WriteToChat(14, StrCon(StrCon(StrCon(StrCon("TEAM ", IntToC(GetTeamColor(w->WormTeam))), ": "), displayInt(wormTeamLoop)), ""), false);
//GG->WriteToChat(14, StrCon(StrCon(StrCon(StrCon("TEAM ", displayInt(wormTeamLoop)), ": "), IntToC(GetTeamColor(w->WormTeam))), ""), false);
}else{
//GG->WriteToChat(14, StrCon(StrCon("TEAM ", displayInt(wormTeamLoop)), ""), false);
}
//GG->WriteToChat(15, StrCon(StrCon("Current worm count: ", displayInt(wormCount)), ""), false);
//GG->WriteToChat(15, StrCon(StrCon("Zombie worm count: ", displayInt(zombieWormCount)), ""), false);
//GG->WriteToChat(15, StrCon(StrCon(StrCon(StrCon("Worms: ", displayInt(wormCount)), " // Zombies: "), displayInt(zombieWormCount)), ""), false);
if(zombieWormCount == wormCount)
{
//GG->WriteToChat(13, StrCon(StrCon("TEAM DEAD: ", displayInt(wormTeamLoop)), ""), false);
destroyTeam(wormTeamLoop);
}
}
}
}