// FinalSun Script file
// Name: Make Infantry Recruitable
// Written By: Matthias Wagner
// Last Change: August 21, 2001
// Be careful when editing scripts, they may cause damage to maps if used improperly


AllowDelete("Necessary for changing infantry");
AllowAdd("Necessary for changing infantry");
Is("%DeleteAllowed%","=","0","%NoDelete%");
Print("Deletion must be allowed for this script to run!","%NoDelete%");
Cancel("%NoDelete%");
Is("%AddAllowed%","=","0","%NoAdd%");
Print("Adding must be allowed for this script to run!","%NoAdd%");
Cancel("%NoAdd%");

Ask("%specified%","Do you want to limit changes to a specific house?","Limit to house");

SetVariable("%House%","");
UInputGetHouse("%House%","House:","%specified%");

SetAutoUpdate("FALSE"); // no screen flickering...

Is("%InfantryCount%","=","0","%Abort%");
Cancel("%Abort%");

SetVariable("%TCounter%","%InfantryCount%");

// LOOP BEGIN
:Loop:
SetVariable("%pos%","%TCounter%");
Substract("%pos%","1");
IsInfantryDeleted("%deleted?%","%pos%");
Is("%deleted?%","=","0","%existing%");
GetInfantry("%data%","%pos%");

SetVariable("%Differ%","0");
GetParam("%param%", "%data%", "0", "%specified%");
Is("%param%","!=","%House%","%Differ%","%specified%");

Substract("%TCounter%","1", "%Differ%");
And("%cancelloop%","%Differ%", "%TCounter%");
JumpTo("Loop", "%cancelloop%");

// if we are here, and Differ is set to TRUE, TCounter must be 0, so cancel script.
Cancel("%Differ%");

DeleteInfantry("%pos%","%existing%");

// recruitable & AI recruitable
SetParam("%data%","12","1","%existing%");
SetParam("%data%","13","1","%existing%");

AddInfantry("%data%","%existing%");
Substract("%TCounter%", "1", "%TCounter%"); // only substract if >=0, else infinite loop!
JumpTo("Loop","%TCounter%");


