private void invade() { reCalcUnits(); int pID = nameTranslation("Footman"); if (this.workingUnit[pID] >= optimalArmy && invading == false) //we are ready to invade { int weakestID = findWeakestPlayer(); if (weakestID != -1) //we actually found a player { Tuple <int, int> ret = invadeLocation(weakestID); if (ret.Item1 != -1 && ret.Item2 != -1) //found target location { int firstID = findFirstUnit("Footman"); if (firstID != -1) { this.invading = true; this.leader = allUnits[playerNum][firstID]; allUnits[playerNum][firstID].patrolling = false; allUnits[playerNum][firstID].onCommand = false; allUnits[playerNum][firstID].xToGo = (int)allUnits[playerNum][firstID].x; allUnits[playerNum][firstID].yToGo = (int)allUnits[playerNum][firstID].y; allUnits[playerNum][firstID].target = gameData.target(allUnits, ret.Item1, ret.Item2, allUnits[playerNum][firstID], 0); allUnits[playerNum][firstID].findNearestOpenSpot(allUnits, ref gameData); allUnits[playerNum][firstID].onCommand = true; if (this.waitAndTryAgainI <= 0) { this.waitAndTryAgainI += this.waitTimer; } } } } } else if (this.invading == true && notDead(leader) && this.followed == false && leader.startedBattle == false) { foreach (Unit u in allUnits[playerNum]) //control all soldiers to invade { if (u.unitType == nameTranslation("Footman") && u.id != leader.id) { u.patrolling = false; u.onCommand = false; u.xToGo = leader.xToGo; u.yToGo = leader.yToGo; u.target = gameData.target(allUnits, u.xToGo, u.yToGo, u, 0); if (u.target.owner != -1) { u.findNearestOpenSpot(allUnits, ref gameData); } //u.target.reset(); //commented this out at late night u.onCommand = true; } } this.followed = true; if (this.waitAndTryAgainI <= 0) { this.waitAndTryAgainI += this.waitTimer; } } else if (this.invading == true && this.followed == true && ((notDead(leader) && ((int)leader.x == leader.xToGo && (int)leader.y == leader.yToGo)) || !notDead(leader))) //leader is dead or reached destination { this.followed = false; foreach (Unit u in allUnits[playerNum]) //control all soldiers to stop and find nearest unit (auto?) { if (u.unitType == nameTranslation("Footman") && u.id != leader.id && u.startedBattle == false) //stop all unit movements { u.patrolling = false; u.xToGo = (int)u.x; u.yToGo = (int)u.y; //u.resetAnimation(); //u.onCommand = false; u.findBattleTargetMelee(allUnits, gameData); //u.onCommand = true; } } if (this.waitAndTryAgainI <= 0) { this.waitAndTryAgainI += this.waitTimer; } } else if (this.workingUnit[pID] <= optimalArmy / 2) { this.invading = false; } else if (this.waitAndTryAgainI <= 0) { this.waitAndTryAgainI += this.waitTimer; } }