Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Random Scenario/Campaign and others not working

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [Current Games From Matrix.] >> [World War II] >> Panzer Command: Ostfront >> Tech Support >> Random Scenario/Campaign and others not working Page: [1]
Login
Message << Older Topic   Newer Topic >>
Random Scenario/Campaign and others not working - 5/13/2011 3:45:46 AM   
Outis73

 

Posts: 16
Joined: 12/16/2010
Status: offline
I installed the game and left the .net 1.1 and 4.0 framework boxes checked as well as the directx 9 box.

The random scenario generator and campaign scenario shortcuts open notepad windows.
(They are lengthy)

Also, from the game menu none of the editors will open up except the map scene editor.

What is going on?? and how can I fix it??

The RANDOM BATTLE GENERATOR popups the following in a notepad window. The RANDOM CAMPAIGN GENERATOR displays a similiar notepad window.

<!--
*** DO NOT DELETE THIS SECTION ***

Panzer Command Random Battle Generator (05/03/2008)
A Microsoft HTML application (IE 6.0+ required)

*** SECTION END ***
-->

<html>
<head>

<META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes">

<HTA:APPLICATION
ID = "oPzCRBg"
APPLICATIONNAME="PzCRBg"
BORDER="thin"
BORDERSTYLE="normal"
CAPTION="yes"
ICON="game icon 16x16.bmp.ico"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SCROLL="no"
SCROLLFLAT = "yes"
SYSMENU="yes"
CONTEXTMENU="no"
SELECTION="no"
VERSION = "2.6.0.0"
WINDOWSTATE="normal" />

<script type="text/JScript.Encode">
TITLESTR = "Panzer Command: Random Battle Generator (2.6)";
INFO_TITLE = "Panzer Command: Random Battle Generator";
document.writeln("<title>"+TITLESTR+"</title>");

SWIDTH = screen.width;
SHEIGHT = screen.height;

if ((SWIDTH < 1024) || (SHEIGHT < 720)) {
alert("Can't run application: Minimium Resoultion = 1024x720");
window.close();
}

version = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (isNaN(version) || (version < 6)) {
alert("Can't run application: Requires Microsoft Intenet Explorer 6.0 or above");
window.close();
}

var myshell = new ActiveXObject( "WScript.shell" );
var bkey = false;
var PCOWSINSTALLED = false;

try {
bKey = myshell.RegRead ("HKLM\\Software\\Matrix Games\\Panzer Command Ostfront\\installed");
} catch (err) {
alert("Can't run application: Panzer Command Ostfront Not Installed!");
window.close();
}

if (bKey != "TRUE") {
alert("Can't run application: Panzer Command Ostfront Not Installed!");
window.close();
}

bkey = false;

try {
bKey = myshell.RegRead ("HKLM\\Software\\Matrix Games\\Panzer Command Operation Winter Storm\\installed");
} catch (err) { }

if (bKey == "TRUE")
PCOWSINSTALLED = true;

PCOWSINSTALLED = true;

function extractArgs(str) {
var matches = str.match(/((?!"([^"]+)")\b(\S+)\b|"([^"]+)")/g);

var args = new Array;
for (var i = 0; i < matches.length; i++) {
args = matches;
args = args.replace(/^"(.*)"$/, "$1");
}
return args;
}

function ReSize(x,y) {
try { window.resizeTo(x,y) }
catch(ignore) { setTimeout('ReSize('+x+','+y+')',100) }
}

function MoveTo(x,y) {
try { window.moveTo(x,y) }
catch(ignore) { setTimeout('MoveTo('+x+','+y+')',100) }
}

if (screen.deviceXDPI == 96)
ReSize(643,732);
else
ReSize(670,738);

if (extractArgs(oPzCRBg.commandLine).length > 2) MoveTo(-1000,-1000);
else if (SHEIGHT <= 768) MoveTo(0,0);
</script>

<script language="VBScript.Encode" src="Editor/comms.vbs"></script>


<style type="text/css">

p, table, th {
font-family: verdana, arial, 'sans-serif';
font-size: 9pt;
}

select.fixed {
font-family: Lucida Console;
font-size:9pt;
}

td.hilite {
font-family: verdana, arial, 'sans-serif';
font-size: 8pt;
font-weight: bold;
}

div.percent {
font-family: verdana, arial, 'sans-serif';
font-size: 10pt;
font-weight: bold;
}

td.Green {
color: rgb(0,128,0);
}

td.Veteran {
color: rgb(128,128,128);
}

td.Elite {
color: rgb(128,128,0);
}

table.armour, table.penetration, td.small, select.small, input.small, div.small {
font-family: verdana, arial, 'sans-serif';
font-size: 7pt;
}

h1 {
font-family: verdana, arial, 'sans-serif';
font-size: 26pt;
font-weight: bold;
}
</style>

<script type="text/JScript.Encode">

// *** START CONSTANTS

if (screen.deviceXDPI == 96)
MAPLEFT = 635;
else
MAPLEFT = 662;
MAPTOP = 1
MAPWIDTH = 0;
MAPHEIGHT = 0;
MAPPOSADJX = 24;
MAPPOSADJY = 62;
MAPOVERSAMP = 1000;
MAXMAPX = 1000;
MAXMAPY = 1000;

DEGTORAD = 2 * 3.1415926 / 360;

/***** NEW CODE ****/

GERM = 0;
RUSS = 1;

INF = 0;
TRA = 1;
ART = 2;
AIR = 3;
ATG = 4;
ARM = 5;

NUMUNITTYPES = 6;

PLATSIZE = new Array();
PLATSIZE[GERM] = new Array();
PLATSIZE[RUSS] = new Array();

PLATSIZE[GERM][INF] = 4; PLATSIZE[RUSS][INF] = 4;
PLATSIZE[GERM][TRA] = 4; PLATSIZE[RUSS][TRA] = 4;
PLATSIZE[GERM][ART] = 3; PLATSIZE[RUSS][ART] = 6;
PLATSIZE[GERM][AIR] = 3; PLATSIZE[RUSS][AIR] = 3;
PLATSIZE[GERM][ATG] = 3; PLATSIZE[RUSS][ATG] = 3;
PLATSIZE[GERM][ARM] = 5; PLATSIZE[RUSS][ARM] = 10;

UNITTYPENAME = new Array();
UNITTYPENAME[INF] = "Infantry";
UNITTYPENAME[TRA] = "Transport";
UNITTYPENAME[ART] = "Artillery";
UNITTYPENAME[AIR] = "Air";
UNITTYPENAME[ATG] = "Gun";
UNITTYPENAME[ARM] = "Armour";

SUBSTYPE = new Array();
SUBSTYPE[INF] = ATG;
SUBSTYPE[TRA] = ARM;
SUBSTYPE[ART] = AIR;
SUBSTYPE[AIR] = ART;
SUBSTYPE[ATG] = INF;
SUBSTYPE[ARM] = TRA;

BATTLE_PREPLANNED = "Russian";
BATTLE_ROD = "true";
BATTLE_POINTS_MULTI = 1.0;
BATTLE_PHASES = "40:40";
BATTLE_ID = "";
BATTLE_NAME = "";
BATTLE_DATE = new Array();
BATTLE_DESC = "";
BATTLE_TEMPLATE = "";

CMDLINE_DATE = new Array();

MD = 0;

YEAR = 1941;
SEASON = 0;
MONTH = 0;
DAY = 0;
DATE = "";

VPBONUSTURN = 0;
VPBONUSAMT = 0;

MEDIA = "";
NAME = "Random";
MODELS = "";
ID = "Random";
DESC = "Random Battle";
PLAINDESC = "";

FORCENAME = new Array();
FORCENAME[GERM] = "German";
FORCENAME[RUSS] = "Russian";

FORCEMIX = new Array();
FORCELOCK = new Array();

FORCEPRESETDATA = new Array();
FORCEPRESETNAME = new Array();
FORCEPRESETTITLE = new Array();
FORCEPRESETID = new Array();

NUMFORCEMIXES = new Array();

BRIEFING = new Array();

REINFORCE = new Array();
MF = new Array();
ENGAGE = new Array();
EXP = new Array();
DIR = new Array();
STR = new Array();
RND = new Array();
AI = new Array();
POINTS = new Array();

CORENUM_POINTS = new Array();
COREMAX_POINTS = new Array();

EXPNAME = new Array();
EXPNAME[0] = "Green";
EXPNAME[1] = "Veteran";
EXPNAME[2] = "Elite";

REINFORCENAME = new Array();
REINFORCENAME[0] = "no";
REINFORCENAME[1] = "yes";

DIRNAME = new Array();
DIRNAME[0] = "North";
DIRNAME[1] = "North East";
DIRNAME[2] = "East";
DIRNAME[3] = "South East";
DIRNAME[4] = "South";
DIRNAME[5] = "South West";
DIRNAME[6] = "West";
DIRNAME[7] = "North West";

EDGENAME = new Array();
EDGENAME[0] = "Southern";
EDGENAME[1] = "South Western";
EDGENAME[2] = "Western";
EDGENAME[3] = "North Western";
EDGENAME[4] = "Northern";
EDGENAME[5] = "North Eastern";
EDGENAME[6] = "Eastern";
EDGENAME[7] = "South Eastern";

STRNAME = new Array();
STRNAME[0] = "Depleted";
STRNAME[1] = "Under";
STRNAME[2] = "Operational";
STRNAME[3] = "Full";

MFNAME = new Array();
MFNAME[0] = "None";
MFNAME[1] = "Sparse";
MFNAME[2] = "Dense";

ENGAGENAME = new Array();
ENGAGENAME[0] = "Defends";
ENGAGENAME[1] = "Defends with Time Bonus";
ENGAGENAME[2] = "Assaults";

POSTURENAME = new Array();
POSTURENAME[0] = "defend";
POSTURENAME[1] = "defbonus";
POSTURENAME[2] = "attack";

MAXPOINTS = 22;
POINTSNAME = new Array();
POINTSNAME[0] = "0";
POINTSNAME[1] = "25";
POINTSNAME[2] = "50";
POINTSNAME[3] = "75";
POINTSNAME[4] = "100";
POINTSNAME[5] = "150";
POINTSNAME[6] = "200";
POINTSNAME[7] = "250";
POINTSNAME[8] = "300";
POINTSNAME[9] = "350";
POINTSNAME[10] = "400";
POINTSNAME[11] = "450";
POINTSNAME[12] = "500";
POINTSNAME[13] = "600";
POINTSNAME[14] = "700";
POINTSNAME[15] = "800";
POINTSNAME[16] = "900";
POINTSNAME[17] = "1000";
POINTSNAME[18] = "1250";
POINTSNAME[19] = "1500";
POINTSNAME[20] = "1750";
POINTSNAME[21] = "2000";

SEASONNAME = new Array();
SEASONNAME[0] = "Summer";
SEASONNAME[1] = "Autumn";
SEASONNAME[2] = "Winter";
SEASONNAME[3] = "Spring";

MONTHNAME = new Array();
MONTHNAME[1] = "January";
MONTHNAME[2] = "February";
MONTHNAME[3] = "March";
MONTHNAME[4] = "April";
MONTHNAME[5] = "May";
MONTHNAME[6] = "June";
MONTHNAME[7] = "July";
MONTHNAME[8] = "August";
MONTHNAME[9] = "September";
MONTHNAME[10] = "October";
MONTHNAME[11] = "November";
MONTHNAME[12] = "December";

SEASONMONTH = new Array();
SEASONMONTH[0] = "6,7,8";
SEASONMONTH[1] = "9,10,11";
SEASONMONTH[2] = "12,1,2";
SEASONMONTH[3] = "3,4,5";

MONTHSEASON = new Array();
MONTHSEASON[1] = 2;
MONTHSEASON[2] = 2;
MONTHSEASON[3] = 3;
MONTHSEASON[4] = 3;
MONTHSEASON[5] = 3;
MONTHSEASON[6] = 0;
MONTHSEASON[7] = 0;
MONTHSEASON[8] = 0;
MONTHSEASON[9] = 1;
MONTHSEASON[10] = 1;
MONTHSEASON[11] = 1;
MONTHSEASON[12] = 2;

MINDATE = "6/22/1941";
MAXDATE = "5/8/1945";

POINTS_SPENT = new Array();
FORCE_TOTAL = new Array();
TOTAL_POINTS = new Array();

TPlatIdx = 0;
TUnitX = new Array();
TUnitY = new Array();
TPlatType = new Array();
TPlatUnitIdx = new Array();

SelTPlatIdx = new Array();
SelTUnitX = new Array();
SelTUnitY = new Array();
SelTPlatReinf = new Array();
SelTPlatUnitIdx = new Array();

TObjIdx = 0;
TObjX = new Array();
TObjY = new Array();
TObjName = new Array();
TObjSel = new Array();

TMineIdx = 0;
TMineX = new Array();
TMineY = new Array();
TMineLX = new Array();
TMineLY = new Array();
TMineType = new Array();
TMineSel = new Array();

MINETYPE = new Array();
MINETYPE[0] = "antitank";
MINETYPE[1] = "antipersonnel";

EquipYear = new Array();
EquipID = new Array();
EquipName = new Array();
EquipPts = new Array();
Equip3D = new Array();
EquipMonth = new Array();
EquipEndYear = new Array();
EquipEndMonth = new Array();
EquipMedYear = new Array();
EquipMedMonth = new Array();
EquipMedPrev = new Array();
EquipStdDev = new Array();
EquipIdx = new Array();
EquipProb = new Array();
EquipPTot = new Array();
EquipTag = new Array();
EquipMax = new Array();

UNITSETUP = new Array();
UNITSETUP[0] = new Array();
UNITSETUP[1] = new Array();
UNITSETUP[2] = new Array();

CFPlatoonIdx = new Array();
CFPlatoonID = new Array();
CFPlatoonName = new Array();
CFPlatoonNum = new Array();
CFPlatoonMax = new Array();
CFPlatoonExp = new Array();
CFPlatoonReinT = new Array();
CFPlatoonReinC = new Array();
CFPlatoonTag = new Array();
CFPlatoonPts = new Array();
CFPlatoonX = new Array();
CFPlatoonY = new Array();
CFPlatoonHd = new Array();
CFPlatoonProb = new Array();

PlatoonIdx = 0;
PlatoonNat = new Array();
PlatoonID = new Array();
PlatoonName = new Array();
PlatoonExp = new Array();
PlatoonNum = new Array();
PlatoonMax = new Array();
PlatoonCore = new Array();
PlatoonReinT = new Array();
PlatoonReinC = new Array();
PlatoonSet = new Array();
PlatoonType = new Array();
PlatoonCost = new Array();
PlatoonProb = new Array();
PlatoonAmmo = new Array();

UnitIdx = 0;
UnitX = new Array();
UnitY = new Array();
UnitHd = new Array();
UnitPPos = new Array();
UnitPlatoon = new Array();

PreloadObjIdx = 0;
ObjIdx = 0;
ObjX = new Array();
ObjY = new Array();
ObjPts = new Array();
ObjNat = new Array();
ObjName = new Array();

MineIdx = 0;
MineX = new Array();
MineY = new Array();
MineLX = new Array();
MineLY = new Array();
MineNat = new Array();
MineType = new Array();
MineDens = new Array();

// Reinforcement Area (Inverse Area)
NRAREA = "50,50,50,950,950,950,950,50";

IntT = new Array();

MAXTPLATS = 2500;
MAXLOOPCOUNT = 20;
BUILDATTEMPTS = 0;
CANCEL_BUILD = 0;
CMDLINE = 0;
FROMGAME = 0;
WARNINGS = 1;
H_MULTI = 1;

CORE_ERROR = new Array();
CORE_ERROR[0] = "";
CORE_ERROR[1] = "";

var fso = new ActiveXObject("Scripting.FileSystemObject");
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var strComputer = ".";
var objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\"+strComputer+"\\root\\cimv2");
var xmlObj;

HEADER = new Array();
HEADER[0] = new Array(); HEADER[0][0] = new Array(); HEADER[0][1] = new Array(); HEADER[0][2] = new Array();
HEADER[1] = new Array(); HEADER[1][0] = new Array(); HEADER[1][1] = new Array(); HEADER[1][2] = new Array();
HEADER_COUNT = 2;

HEADER[0][0][0] = "Germany assaults a Russian defensive position.";
HEADER[0][0][1] = "German assault.";
HEADER[0][1][0] = "Germany defends against a Russian Assault.";
HEADER[0][1][1] = "Germany defends.";
HEADER[0][2][0] = "Germany meets a Russian attack.";
HEADER[0][2][1] = "Germany engages a Russian force.";
HEADER[1][0][0] = "Russia assaults a German defensive position.";
HEADER[1][0][1] = "Russian assault.";
HEADER[1][1][0] = "Russia defends against a German Assault.";
HEADER[1][1][1] = "Russia defends.";
HEADER[1][2][0] = "Russia meets a German attack.";
HEADER[1][2][1] = "Russia engages a German force.";

SITUATION = new Array();
SITUATION_COUNT = 4;

SITUATION[0] = "The enemy is just up ahead.";
SITUATION[1] = "The enemy forces are close by.";
SITUATION[2] = "Forward scouts have detected the enemy in the area.";
SITUATION[3] = "Enemy sighted ahead.";

ORDER = new Array();
ORDER[0] = new Array(); ORDER[1] = new Array(); ORDER[2] = new Array();
ORDER_COUNT = 3;

ORDER[0][0] = "You are ordered to rout the enemy forces from their defensive positions.";
ORDER[0][1] = "You are ordered to assault and destroy the defending enemy forces.";
ORDER[0][2] = "You are ordered to engage and defeat the enemy.";

ORDER[1][0] = "You are ordered to defend against the incoming tide of the enemy.";
ORDER[1][1] = "You are ordered to hold off the incoming enemy force.";
ORDER[1][2] = "You are ordered to delay the attacking forces, whilst inflicting significant casualties upon them.";

ORDER[2][0] = "You are ordered to engage and defeat the enemy forces in this area.";
ORDER[2][1] = "You are ordered to smash the enemy forces present in this area.";
ORDER[2][2] = "You are ordered to anihilate the enemy force.";

OBJ_ORDER = new Array();
OBJ_ORDER[0] = new Array(); OBJ_ORDER[1] = new Array(); OBJ_ORDER[2] = new Array();
OBJ_ORDER_COUNT = 3;

OBJ_ORDER[0][0] = "HQ has identified the {obj} as a vital objective of this assault.";
OBJ_ORDER[0][1] = "Securing the {obj} is of paramount importance.";
OBJ_ORDER[0][2] = "The {obj} is the most important objective.";

OBJ_ORDER[1][0] = "Defend the {obj} at all costs.";
OBJ_ORDER[1][1] = "Attempt to hold the {obj} from the enemy.";
OBJ_ORDER[1][2] = "HQ wants you to defend the {obj} as a primary objective.";

OBJ1_ORDER = new Array();
OBJ1_ORDER[0] = new Array(); OBJ1_ORDER[1] = new Array(); OBJ1_ORDER[2] = new Array();
OBJ1_ORDER_COUNT = 3;

OBJ1_ORDER[0][0] = "The {obj} should also be secured.";
OBJ1_ORDER[0][1] = "The {obj} should also be captured.";
OBJ1_ORDER[0][2] = "Also consider capturing the {obj}.";

OBJ1_ORDER[1][0] = "It is also important that the {obj} should also be defended if possible.";
OBJ1_ORDER[1][1] = "Also protect the {obj} from enemy attack.";
OBJ1_ORDER[1][2] = "Deny the {obj} from the enemy as well.";

TIME_ORDER = new Array();
TIME_ORDER[0] = new Array(); TIME_ORDER[1] = new Array();
TIME_ORDER_COUNT = 3;

TIME_ORDER[0][0] = "You must achive your objectives in a timely manner.";
TIME_ORDER[0][1] = "It is important that you control the battlefield quickly.";
TIME_ORDER[0][2] = "As is often the case in war speed is essential.";

TIME_ORDER[1][0] = "You must hold out for as long as possible.";
TIME_ORDER[1][1] = "It is important that you delay the enemy control of the battlefield for as long as possible.";
TIME_ORDER[1][2] = "Stall the enemy.";

TIME1_ORDER = new Array();
TIME1_ORDER[0] = new Array(); TIME1_ORDER[1] = new Array();
TIME1_ORDER_COUNT = 3;

TIME1_ORDER[0][0] = "The enemy will be receiving a defensive bonus on or about turn {turn}.";
TIME1_ORDER[0][1] = "Your victory will be less favourable if achieved after about turn {turn}.";
TIME1_ORDER[0][2] = "To prevent a greater operational victory by the enemy, finish them by about turn {turn}.";

TIME1_ORDER[1][0] = "You will receive a defensive bonus on or about turn {turn}.";
TIME1_ORDER[1][1] = "Your victory will be more favourable if you can hold until after about turn {turn}.";
TIME1_ORDER[1][2] = "To prevent a greater operational victory by the enemy, hold them until about turn {turn}.";

IQ_ORDER = new Array();
IQ_ORDER_COUNT = 6;

IQ_ORDER[0] = "Expect {res} enemy resistance.";
IQ_ORDER[1] = "Expect a {res} enemy resolve.";
IQ_ORDER[2] = "Expect a {res} enemy fight.";
IQ_ORDER[3] = "Expect the enemy {force} will provide {res} resistance.";
IQ_ORDER[4] = "The enemy {force} will put up a {res} fight.";
IQ_ORDER[5] = "The degree of enemy resolve is unknown.";

IQ1_ORDER = new Array();
IQ1_ORDER_COUNT = 3;

IQ1_ORDER[0] = "Our recon assets have detected enemy {units}.";
IQ1_ORDER[1] = "The enemy is known to have {units}.";
IQ1_ORDER[2] = "The enemy is likely to have {units}.";

REPORT_STR = "";

ALLOWLISTLEN = new Array();
ALLOWLISTUID = new Array();
ALLOWLISTNAME = new Array();
ALLOWLISTMAX = new Array()

SELECTEDFORCEMIX = new Array();

TemplateRIdx = 0;
TemplateRID = new Array();

PresetRIdx = new Array();
PresetRID = new Array();

UsersetupRIdx = new Array();
UsersetupRID = new Array();

StrengthRIdx = new Array();
StrengthRID = new Array();

ExpRIdx = new Array();
ExpRID = new Array();

MinefieldRIdx = new Array();
MinefieldRID = new Array();

ReinforceRIdx = new Array();
ReinforceRID = new Array();

PostureRIdx = new Array();
PostureRID = new Array();

SETUPIdx = 0;
SETUPID = new Array();
SETUPNAME = new Array();
SETUPICON = new Array();
SETUPENEMY = new Array();
SETUPFACE = new Array();
SETUPDESC = new Array();
SETUPATK = new Array();
SETUPATKZONE = new Array();
SETUPDEF = new Array();
SETUPDEFZONE = new Array();
SETUPSIM = new Array();

TID = "";

function PreErrorMsg(ErrCode, ErrText) {
var dump = "";

if (CMDLINE) {
dump = "\n\nDump:\n\n";

dump += "\nDates:\t(" + BATTLE_DATE[0] + " - " + MONTH+"/"+DAY+"/"+YEAR + " - " + BATTLE_DATE[1] + ")";
dump += "\nBattle:\t" + BATTLE_ID;
dump += "\nTemplate:\t" + TID + "\nModels:\t" + MODELS;
dump += "\n\nSIDE 0 = " + FORCENAME[0] + "\t\tSIDE 1 = " + FORCENAME[1];
dump += "\nPoints:\n SIDE 0 = " + TOTAL_POINTS[0] + "\t\tSIDE 1 = " + TOTAL_POINTS[1];
try { dump += "\nPreset:\n SIDE 0 = " + FORCEPRESETID[0][0].substring(0,10) + "\t\tSIDE 1 = " + FORCEPRESETID[1][0].substring(0,10); } catch (err) {}
try { dump += "\nPosture:\n SIDE 0 = " + ENGAGENAME[fENGAGE(0)].substring(0,10) + "\t\tSIDE 1 = " + ENGAGENAME[fENGAGE(1)].substring(0,10); } catch (err) {}
dump += "\nSetup:\n SIDE 0 = " + SETUPNAME[UsersetupRID[0][DIR[0]]] + "\t\tSIDE 1 = " + SETUPNAME[UsersetupRID[1][DIR[1]]];
try { dump += "\nStrength:\n SIDE 0 = " + STRNAME[StrengthRID[0][STR[0]]].substring(0,10) + "\t\tSIDE 1 = " + STRNAME[StrengthRID[1][STR[1]]].substring(0,10); } catch (err) {}
dump += "\nExperience:\n SIDE 0 = " + EXPNAME[ExpRID[0][EXP[0]]] + "\t\tSIDE 1 = " + EXPNAME[ExpRID[1][EXP[1]]];
dump += "\nMinefields:\n SIDE 0 = " + MFNAME[MinefieldRID[0][MF[0]]] + "\t\tSIDE 1 = " + MFNAME[MinefieldRID[1][MF[1]]];
dump += "\nReinforcements:\n SIDE 0 = " + REINFORCENAME[ReinforceRID[0][REINFORCE[0]]] + "\t\tSIDE 1 = " + REINFORCENAME[ReinforceRID[1][REINFORCE[1]]];

ErrorMsg(ErrCode,ErrText+dump);

Exit_RBG(0);
}
else {
ErrorMsg(ErrCode,ErrText);
window.close();
}
}

function loadXML(xmlFile) {
xmlDoc.async="false";
xmlDoc.onreadystatechange=verify;
xmlDoc.load(xmlFile);
xmlObj=xmlDoc.documentElement;
}

function verify() {
if (xmlDoc.readyState != 4)
return false;
}

function ParseValidXML(fname) {
var txt;

if (xmlDoc.parseError.errorCode!=0) {
txt="Illegal XML Parse\n\n";
txt=txt+"XML Error Code: " + xmlDoc.parseError.errorCode + "\n";
txt=txt+'XML File: "'+fname+'"' + '\n';
txt=txt+"Error Reason: " + xmlDoc.parseError.reason;
txt=txt+"Error Line: " + xmlDoc.parseError.line;
PreErrorMsg("004",txt);
return (false);
}
return (true);
}

function AddMenuOption(menu, value, text) {
var OptNew = document.createElement('option');
OptNew.text = text;
OptNew.value = value;
document.getElementById(menu).add(OptNew);
}

function AddTemplate(fname) {

if (fname.toLowerCase().match("\\.xml")) {
var f = "Data/Templates/"+fname.substring(0,fname.length-4)+".xml";

loadXML(f);

if (!ParseValidXML(f))
return;

var id = xmlObj.getAttribute("id");

if (id)
id = id.toLowerCase();
else
PreErrorMsg("101","Error in 'id' field of '"+f+"'");

var name = xmlObj.getAttribute("name");

if (!name)
PreErrorMsg("101","Error in 'name' field of '"+f+"'");

var m = xmlObj.getAttribute("models");

if (m)
m = m.toLowerCase();
else
PreErrorMsg("101","Error in 'models' field of '"+f+"'");

if (CMDLINE) {

var dd = (Date.parse(BATTLE_DATE[1]) - Date.parse(BATTLE_DATE[0])) / 1000 / 60 / 60 / 24;

if (dd < 185) {
var d = new Date();
d.setTime(Date.parse(BATTLE_DATE[0]));
var s0 = MONTHSEASON[d.getMonth()+1];
d.setTime(Date.parse(BATTLE_DATE[1]));
var s1 = MONTHSEASON[d.getMonth()+1];

if ((((m == "default") || (m == "winter") || (m == "autumn") || (m == "fall")) && PCOWSINSTALLED) || (m == "winterdemo")) {
if ((s0 == 1) || (s0 == 2) || (s1 == 1) || (s1 == 2))
AddMenuOption("oTemplateSelect_menu",id + "@" + f,name);
} else if ((m == "summer") || (m == "spring")) {
if ((s0 == 0) || (s0 == 3) || (s1 == 0) || (s1 == 3))
AddMenuOption("oTemplateSelect_menu",id + "@" + f,name);
}
return;
}
}

if ((((m == "default") || (m == "winter") || (m == "autumn") || (m == "fall")) && PCOWSINSTALLED) || (m == "winterdemo"))
AddMenuOption("oTemplateSelect_menu",id + "@" + f,name);
else if ((m == "summer") || (m == "spring"))
AddMenuOption("oTemplateSelect_menu",id + "@" + f,name);
}

}

function AddBattle(fname) {

if (fname.toLowerCase().match("\\.xml")) {
var f = "Data/Battles/"+fname.substring(0,fname.length-4)+".xml";

loadXML(f);

if (!ParseValidXML(f))
return;

var id = xmlObj.getAttribute("id");

if (id)
id = id.toLowerCase();
else
PreErrorMsg("101","Error in 'id' field of '"+f+"'");

var name = xmlObj.getAttribute("name");

if (!name)
PreErrorMsg("101","Error in 'name' field of '"+f+"'");

if (!CMDLINE) { var m = xmlObj.getAttribute("showinmenu"); if (m) m = m.toLowerCase(); else m = "false"; if ((m == "true") || (m == "yes")) {} else return; }

AddMenuOption("oBattleSelect_menu",id + "@" + f,name);
}
}

function AddPreset(fname) {

if (fname.toLowerCase().match("\\.xml")) {

var gs = 0, rs = 1, sim;

var f = "Data/Presets/"+fname.substring(0,fname.length-4)+".xml";

loadXML(f);

if (!ParseValidXML(f))
return;

var id = xmlObj.getAttribute("id");

if (id)
id = id.toLowerCase();
else
PreErrorMsg("101","Error in 'id' field of '"+f+"'");

var name = xmlObj.getAttribute("name");

if (!name)
PreErrorMsg("101","Error in 'name' field of '"+f+"'");

var m = xmlObj.getAttribute("showinmenu");

if (m)
m = m.toLowerCase();
else
m = "false";

if ((m == "true") || (m == "yes"))
sim = true;
else
sim = false;

if (FORCENAME[0].toLowerCase() == "german") {
gs = 0; rs = 1;
}

if (FORCENAME[0].toLowerCase() == "russian") {
rs = 0; gs = 1;
}

var side = xmlObj.getAttribute("side");

if (side)
side = side.toLowerCase();

if (side == "german") {

if ((PresetRID[gs][0].toLowerCase() != "random") || sim)
AddMenuOption("oFORCEMIX0_menu",id + "@" + f,name);
}
else if (side == "russian") {
if ((PresetRID[rs][0].toLowerCase() != "random") || sim)
AddMenuOption("oFORCEMIX1_menu",id + "@" + f,name);
}
else
PreErrorMsg("101","Error in 'side' field of '"+f+"'");
}
}

function PopulateBattles() {
var i;
var fo;
var files;

document.getElementById("oBattleSelect_menu").options.length = 0;

fo = fso.GetFolder("Data/Battles");
files = new Enumerator(fo.Files);

for (i=0; !files.atEnd(); files.moveNext())
AddBattle(files.item().name);
}

function PopulateTemplates() {
var i;
var fo;
var files;

document.getElementById("oTemplateSelect_menu").options.length = 0;

fo = fso.GetFolder("Data/Templates");
files = new Enumerator(fo.Files);

for (i=0; !files.atEnd(); files.moveNext())
AddTemplate(files.item().name);
}

function PopulatePresets() {
var i;
var fo;
var files;

document.getElementById("oFORCEMIX0_menu").options.length = 0;
document.getElementById("oFORCEMIX1_menu").options.length = 0;

fo = fso.GetFolder("Data/Presets");
files = new Enumerator(fo.Files);

for (i=0; !files.atEnd(); files.moveNext())
AddPreset(files.item().name);
}

function AddEquipment(fname) {

var i,j,k,x,y,z,sut,side,generic,tag;

if (fname.toLowerCase().match("\\.xml")) {
loadXML(fname);

if (!ParseValidXML(fname))
return;

if (xmlObj.getAttribute('side') == "German")
side = 0;
else
side = 1;

if (xmlObj.selectSingleNode("set").childNodes(0).getAttribute("compendium").match("genericvehicle"))
generic = 0;
else
generic = 1;

sut = -1;
tag = "";

for (i = 0; i < xmlObj.childNodes.length; i++) {
x = xmlObj.childNodes(i);

if ((x.tagName) && (x.tagName.toLowerCase() == "attributes")) {
if ((xmlObj.tagName) && (xmlObj.tagName.toLowerCase() == "armouredunit"))
sut = ARM;
else
sut = INF;

for (j = 0; j < x.childNodes.length; j++) {
y = x.childNodes(j);

if ((y.tagName) && (y.tagName.toLowerCase() == "attribute")) {
z = y.getAttribute("name").toLowerCase();

tag = z;

if (z == "team") { sut = INF; break; }
if (z == "truck") { sut = TRA; break; }
if (z == "indirectfire") { sut = ART; break; }
if ((z == "fighterbomber") || (z == "divebomber")) { sut = AIR; break; }
if ((z == "lightgun") || (z == "mediumgun") || (z == "heavygun") || (z == "assaultgun")) { sut = ATG; }
if ((z == "lighttank") || (z == "mediumtank") || (z == "heavytank")) { sut = ARM; break;}
if ((z == "halftrack") || (z == "scoutcar") || (z == "recon")) { sut = TRA; }
}
}
}
}

if (xmlObj.getAttribute("rbg"))
if (xmlObj.getAttribute("rbg").toLowerCase() == "false")
return;

if (sut == -1)
return;

var endservice = xmlObj.getAttribute("endservice");
var medservice = xmlObj.getAttribute("medservice");
var medprev = xmlObj.getAttribute("medprev");
var stddev = xmlObj.getAttribute("stddev");

EquipYear[side][sut][EquipIdx[side][sut]] = parseInt(xmlObj.getAttribute("year"),"10");
EquipMonth[side][sut][EquipIdx[side][sut]] = parseInt(xmlObj.getAttribute("month"),"10");

if (!endservice) {
EquipEndYear[side][sut][EquipIdx[side][sut]] = 45;
EquipEndMonth[side][sut][EquipIdx[side][sut]] = 6;
} else {
EquipEndYear[side][sut][EquipIdx[side][sut]] = parseInt(endservice.substring(endservice.search("/")+1,endservice.length),"10");
EquipEndMonth[side][sut][EquipIdx[side][sut]] = parseInt(endservice.substring(0,endservice.search("/")),"10");
}

if (!medservice) {
EquipMedYear[side][sut][EquipIdx[side][sut]] = parseInt(EquipYear[side][sut][EquipIdx[side][sut]],"10") + 1;
EquipMedMonth[side][sut][EquipIdx[side][sut]] = parseInt(EquipMonth[side][sut][EquipIdx[side][sut]],"10");

if (((EquipMedYear[side][sut][EquipIdx[side][sut]] * 12) + EquipMedMonth[side][sut][EquipIdx[side][sut]]) > ((EquipEndYear[side][sut][EquipIdx[side][sut]] * 12) + EquipEndMonth[side][sut][EquipIdx[side][sut]])) {
EquipMedYear[side][sut][EquipIdx[side][sut]] = parseInt(EquipEndYear[side][sut][EquipIdx[side][sut]],"10");
EquipMedMonth[side][sut][EquipIdx[side][sut]] = parseInt(EquipEndMonth[side][sut][EquipIdx[side][sut]],"10");
}

} else {
EquipMedYear[side][sut][EquipIdx[side][sut]] = parseInt(medservice.substring(medservice.search("/")+1,medservice.length),"10");
EquipMedMonth[side][sut][EquipIdx[side][sut]] = parseInt(medservice.substring(0,medservice.search("/")),"10");
}

if (!medprev)
EquipMedPrev[side][sut][EquipIdx[side][sut]] = 5;
else
EquipMedPrev[side][sut][EquipIdx[side][sut]] = parseInt(medprev,"10");

if (!stddev)
EquipStdDev[side][sut][EquipIdx[side][sut]] = 12;
else
EquipStdDev[side][sut][EquipIdx[side][sut]] = parseInt(stddev,"10");

EquipID[side][sut][EquipIdx[side][sut]] = xmlObj.getAttribute("type");
EquipPts[side][sut][EquipIdx[side][sut]] = xmlObj.getAttribute("points");
EquipTag[side][sut][EquipIdx[side][sut]] = tag;
EquipProb[side][sut][EquipIdx[side][sut]] = 0;
Equip3D[side][sut][EquipIdx[side][sut]] = generic;
EquipMax[side][sut][EquipIdx[side][sut]] = PLATSIZE[side][sut];

if (((EquipYear[side][sut][EquipIdx[side][sut]] * 12) + EquipMonth[side][sut][EquipIdx[side][sut]]) > ((EquipMedYear[side][sut][EquipIdx[side][sut]] * 12) + EquipMedMonth[side][sut][EquipIdx[side][sut]]))
PreErrorMsg("011","Error in equipment '"+EquipID[side][sut][EquipIdx[side][sut]]+"' Start or Median service dates");

if (((EquipMedYear[side][sut][EquipIdx[side][sut]] * 12) + EquipMedMonth[side][sut][EquipIdx[side][sut]]) > ((EquipEndYear[side][sut][EquipIdx[side][sut]] * 12) + EquipEndMonth[side][sut][EquipIdx[side][sut]]))
PreErrorMsg("011","Error in equipment '"+EquipID[side][sut][EquipIdx[side][sut]]+"' Median or End service dates");

EquipIdx[side][sut]++;
}
}

function Load_SetupZones() {
var i, j;
var fo;
var files;
var fname;

fo = fso.GetFolder("Data/Setups");
files = new Enumerator(fo.Files);

SETUPIdx = 0;

for (i=0; !files.atEnd(); files.moveNext()) {
fname = "Data/Setups/"+files.item().name;

if (fname.toLowerCase().match("\\.xml")) {
loadXML(fname);

if (!ParseValidXML(fname))
return;

SETUPID[SETUPIdx] = xmlObj.getAttribute('id');
SETUPNAME[SETUPIdx] = xmlObj.getAttribute('name');
SETUPICON[SETUPIdx] = xmlObj.getAttribute('icon');
SETUPENEMY[SETUPIdx] = xmlObj.getAttribute('enemyid');
SETUPFACE[SETUPIdx] = xmlObj.getAttribute('faceto');
SETUPDESC[SETUPIdx] = xmlObj.getAttribute('desc');
SETUPATK[SETUPIdx] = xmlObj.getAttribute('attack');
SETUPATKZONE[SETUPIdx] = xmlObj.getAttribute('attackzone');
SETUPDEF[SETUPIdx] = xmlObj.getAttribute('defend');
SETUPDEFZONE[SETUPIdx] = xmlObj.getAttribute('defendzone');
SETUPSIM[SETUPIdx] = xmlObj.getAttribute('showinmenu');

if (SETUPSIM[SETUPIdx] == null)
SETUPSIM[SETUPIdx] = "false";

SETUPIdx++;
}
}

for (i = 0; i < SETUPIdx; i++) {

for (j = 0; j < SETUPIdx; j++)
if (SETUPENEMY.toLowerCase() == SETUPID[j].toLowerCase())
break;

if (j < SETUPIdx)
SETUPENEMY = j;
else
PreErrorMsg("055","Setup Zone '"+SETUPID+"' doesn't have a valid enemyid");
}
}

function Load_Equipment() {
var i, j;
var fo;
var files;

for (i = 0; i < 2; i++)
for (j = 0; j < NUMUNITTYPES; j++) {
EquipIdx[j] = 0;
EquipPTot[j] = 0;
}

fo = fso.GetFolder("Data/ArmouredUnits");
files = new Enumerator(fo.Files);

for (i=0; !files.atEnd(); files.moveNext())
AddEquipment("Data/ArmouredUnits/"+files.item().name);

fo = fso.GetFolder("Data/Infantry");
files = new Enumerator(fo.Files);

for (i=0; !files.atEnd(); files.moveNext())
AddEquipment("Data/Infantry/"+files.item().name);
}

function Init() {
var i,j;

var o = document.getElementById("oLoading_div").style;

o.width = 632;
o.height = 702;

o.left = 0;
o.top = 0;

o.zIndex = 5;

for (i = 0; i < MAXTPLATS; i++) {
TUnitX = new Array();
TUnitY = new Array();
}

for (i = 0; i < NUMUNITTYPES; i++) {

SelTUnitX = new Array();
SelTUnitY = new Array();
SelTPlatReinf = new Array();
SelTPlatUnitIdx = new Array();

for (j = 0; j < MAXTPLATS; j++) {

SelTUnitX[j] = new Array();
SelTUnitY[j] = new Array();
}
}

for (i = 0; i < 2; i++) {
IntT = new Array();

for (j = 0; j < 10; j++)
IntT[j] = -1;

PresetRID = new Array();
UsersetupRID = new Array();
StrengthRID = new Array();
MinefieldRID = new Array();
PostureRID = new Array();
ReinforceRID = new Array();
ExpRID = new Array();
}

for (i = 0; i < 2; i++) {

ALLOWLISTLEN = new Array();
ALLOWLISTUID = new Array();
ALLOWLISTNAME = new Array();
ALLOWLISTMAX = new Array();

FORCEPRESETDATA = new Array();
FORCEPRESETNAME = new Array();
FORCEPRESETTITLE = new Array();
FORCEPRESETID = new Array();

BRIEFING = "";

EquipYear = new Array();
EquipID = new Array();
EquipName = new Array();
EquipPts = new Array();
Equip3D = new Array();
EquipMonth = new Array();
EquipEndMonth = new Array();
EquipEndYear = new Array();
EquipMedMonth = new Array();
EquipMedYear = new Array();
EquipMedPrev = new Array();
EquipStdDev = new Array();
EquipProb = new Array();
EquipIdx = new Array();
EquipPTot = new Array();
EquipTag = new Array();
EquipMax = new Array();

CFPlatoonIdx = new Array();
CFPlatoonID = new Array();
CFPlatoonName = new Array();
CFPlatoonNum = new Array();
CFPlatoonMax = new Array();
CFPlatoonExp = new Array();
CFPlatoonReinT = new Array();
CFPlatoonReinC = new Array();
CFPlatoonTag = new Array();
CFPlatoonPts = new Array();
CFPlatoonX = new Array();
CFPlatoonY = new Array();
CFPlatoonHd = new Array();
CFPlatoonProb = new Array();

FORCEMIX = new Array();
FORCELOCK = new Array();

POINTS_SPENT = new Array();

for (j = 0; j < NUMUNITTYPES; j++) {

EquipYear[j] = new Array();
EquipMonth[j] = new Array();
EquipEndYear[j] = new Array();
EquipEndMonth[j] = new Array();
EquipMedMonth[j] = new Array();
EquipMedYear[j] = new Array();
EquipMedPrev[j] = new Array();
EquipStdDev[j] = new Array();
EquipID[j] = new Array();
EquipName[j] = new Array();
EquipPts[j] = new Array();
EquipTag[j] = new Array();
Equip3D[j] = new Array();
EquipProb[j] = new Array();
EquipMax[j] = new Array();

CFPlatoonID[j] = new Array();
CFPlatoonName[j] = new Array();
CFPlatoonNum[j] = new Array();
CFPlatoonMax[j] = new Array();
CFPlatoonExp[j] = new Array();
CFPlatoonReinT[j] = new Array();
CFPlatoonReinC[j] = new Array();
CFPlatoonTag[j] = new Array();
CFPlatoonPts[j] = new Array();
CFPlatoonX[j] = new Array();
CFPlatoonY[j] = new Array();
CFPlatoonHd[j] = new Array();
CFPlatoonProb[j] = new Array();

FORCEMIX[j] = 0;
FORCELOCK[j] = 0;
}

REINFORCE = 0;
MF = 0;
ENGAGE = 0;
EXP = 0;
STR = 0;
DIR = 0;
RND = 0;
AI = 0; ToggleAI(i);
POINTS = 0;
}

document.getElementById("oBuild").src = "Editor/Build.png";
document.getElementById("oBuild").alt = "Build Battle";

Load_SetupZones();
Load_Equipment();
}

function fENGAGE(s) {
return (PostureRID[ENGAGE]);
}

function ToggleEXP(i, dir) {

if (dir)
EXP += dir;

if (EXP >= ExpRIdx)
EXP = 0;

if (EXP < 0)
EXP = ExpRIdx - 1;

var idx = ExpRID[EXP];

if (IntT[3])
document.getElementById("oEXP"+i).src = "Editor/EXP"+i+idx+"r.png";
else
document.getElementById("oEXP"+i).src = "Editor/EXP"+i+idx+".png";

document.getElementById("oEXP"+i).alt = EXPNAME[idx] + " " + FORCENAME + "s";
}

function TogglePoints(i, dir) {
POINTS += dir;

if (POINTS > (MAXPOINTS-1))
POINTS = 0;

if (POINTS < 0)
POINTS = (MAXPOINTS-1);

document.getElementById("oPoints"+i).src = "Editor/Points"+i+POINTS+".png";
document.getElementById("oPoints"+i).alt = FORCENAME + " Force has " + POINTSNAME[POINTS] + " Points to Spend\n\nLeft-click to increase, Right-click to decrease\nOr scroll through the values with the mousewheel";
}

function ToggleSTR(i,dir) {

if (dir)
STR += dir;

if (STR >= StrengthRIdx)
STR = 0;

if (STR < 0)
STR = StrengthRIdx - 1;

var idx = StrengthRID[STR];

if (IntT[4])
document.getElementById("oSTR"+i).src = "Editor/STR"+idx+"r.png";
else
document.getElementById("oSTR"+i).src = "Editor/STR"+idx+".png";

document.getElementById("oSTR"+i).alt = STRNAME[idx] + " Strength";
}

function ToggleMF(i,dir) {

if (dir)
MF += dir;

if (MF >= MinefieldRIdx)
MF = 0;

if (MF < 0)
MF = MinefieldRIdx - 1;

var idx = MinefieldRID[MF];

if (IntT[1])
document.getElementById("oMF"+i).src = "Editor/MF"+idx+"r.png";
else
document.getElementById("oMF"+i).src = "Editor/MF"+idx+".png";

document.getElementById("oMF"+i).alt = FORCENAME + " Minefields: " + MFNAME[idx];

if ((idx > 0) && (fENGAGE(i) == 2))
ToggleEngage(i,1);
}

function ToggleEngage(i,dir) {

var k;

if (dir)
ENGAGE += dir;

if (ENGAGE >= PostureRIdx)
ENGAGE = 0;

if (ENGAGE < 0)
ENGAGE = PostureRIdx - 1;

var idx = PostureRID[ENGAGE];

if (IntT[2])
document.getElementById("oENGAGE"+i).src = "Editor/Engage"+i+idx+"r.png";
else
document.getElementById("oENGAGE"+i).src = "Editor/Engage"+i+idx+".png";

document.getElementById("oENGAGE"+i).alt = FORCENAME + " " + ENGAGENAME[idx];

if (idx != 2) {
var j = Math.abs(i - 1);

if (fENGAGE(j) != 2) {
for (k = 0; k < PostureRIdx[j]; k++)
if (PostureRID[j][k] == 2) {
ENGAGE[j] = k;
break;
}
ToggleEngage(j,0);
}
}
else if (MinefieldRID[MF] > 0) {
for (k = 0; k < MinefieldRIdx; k++)
if (MinefieldRID[k] == 0) {
MF = k;
break;
}
ToggleMF(i,0);
}
}

function ToggleDIR(i,dir) {

var k;

if (dir)
DIR += dir;

if (DIR >= UsersetupRIdx)
DIR = 0;

if (DIR < 0)
DIR = UsersetupRIdx - 1;

var idx = UsersetupRID[DIR];

if (IntT[5])
document.getElementById("oDIR"+i).src = "Editor/"+SETUPICON[idx]+"r.png";
else
document.getElementById("oDIR"+i).src = "Editor/"+SETUPICON[idx]+".png";

document.getElementById("oDIR_txt"+i).innerHTML = SETUPNAME[idx];
document.getElementById("oDIR"+i).alt = FORCENAME + " player is " + SETUPDESC[idx] + ".";

var j = Math.abs(i-1);

for (k = 0; k < UsersetupRIdx[j]; k++) {
if (SETUPENEMY[idx] == UsersetupRID[j][k]) {
DIR[j] = k;
break;
}
}

idx = UsersetupRID[j][DIR[j]];

if (IntT[j][5])
document.getElementById("oDIR"+j).src = "Editor/"+SETUPICON[idx]+"r.png";
else
document.getElementById("oDIR"+j).src = "Editor/"+SETUPICON[idx]+".png";

document.getElementById("oDIR_txt"+j).innerHTML = SETUPNAME[idx];
document.getElementById("oDIR"+j).alt = FORCENAME[j] + " player is " + SETUPDESC[idx] + ".";
}

function ToggleReinf(i,dir) {

if (dir)
REINFORCE += dir;

if (REINFORCE >= ReinforceRIdx)
REINFORCE = 0;

if (REINFORCE < 0)
REINFORCE = ReinforceRIdx - 1;

var idx = ReinforceRID[REINFORCE];

if (IntT[0])
document.getElementById("oReinf"+i).src = "Editor/Reinf"+i+idx+"r.png";
else
document.getElementById("oReinf"+i).src = "Editor/Reinf"+i+idx+".png";

if (idx)
document.getElementById("oReinf"+i).alt = FORCENAME + " Reinforcements Available";
else
document.getElementById("oReinf"+i).alt = FORCENAME + " Reinforcements Not Available";
}

function RandomTemplate() {

var i, o = document.getElementById("oTemplateSelect_menu");

i = iRnd(TemplateRIdx);
o.value = Load_Template(TemplateRID);
}

function RandomPreset(i) {

var j, o = document.getElementById("oFORCEMIX"+i+"_menu");

j = iRnd(PresetRIdx);
o.value = Load_Preset(PresetRID[j], i);
}

function RandomDIR(i) {
DIR = iRnd(UsersetupRIdx);

ToggleDIR(i,0);
}

function RandomSTR(i) {

STR = iRnd(StrengthRIdx);

ToggleSTR(i,0);
}

function RandomReinf(i) {

REINFORCE = iRnd(ReinforceRIdx);

ToggleReinf(i,0);
}

function RandomMF(i) {

MF = iRnd(MinefieldRIdx);

ToggleMF(i,0);
}

function RandomEXP(i) {

EXP = iRnd(ExpRIdx);

ToggleEXP(i,0);
}

function RandomEngage(i) {

ENGAGE = iRnd(PostureRIdx);

ToggleEngage(i,0);
}

function DisplayDate() {

var post;

post = NumberPostscript(DAY);

DATE = GenerateDATE(YEAR);

document.getElementById("oDate_txt").innerHTML = "<table width='100%' cellpadding='0' cellspacing='0'><tr><td align='left' valign='bottom'><a title='Battle Date ("+BATTLE_DATE[0]+" - "+BATTLE_DATE[1]+")'>Battle Date:</a></td><td align='right' width='100' valign='bottom'><b><a title='"+MONTHNAME[MONTH]+"' onmousewheel='if (event.wheelDelta <= -5) SetDate(\"\",\"dec\",\"\",0); else if (event.wheelDelta >= 5) SetDate(\"\",\"inc\",\"\",0);' onclick='SetDate(\"\",\"inc\",\"\",0)' ondblclick='SetDate(\"\",\"inc\",\"\",0)'>" + MONTHNAME[MONTH] + "</a></b></td><td align='right' valign='bottom' width='40'><b><a title='"+DAY+post+"' onmousewheel='if (event.wheelDelta <= -5) SetDate(\"dec\",\"\",\"\",0); else if (event.wheelDelta >= 5) SetDate(\"inc\",\"\",\"\",0);' onclick='SetDate(\"inc\",\"\",\"\",0)' ondblclick='SetDate(\"inc\",\"\",\"\",0)'>" + DAY+"<sup>"+post+"</sup>" + "</a></b>,</td><td align='right' valign='bottom' width='40'><b><a title='"+YEAR+"' onmousewheel='if (event.wheelDelta <= -5) SetDate(\"\",\"\",\"dec\",0); else if (event.wheelDelta >= 5) SetDate(\"\",\"\",\"inc\",0);' onclick='SetDate(\"\",\"\",\"inc\",0)' ondblclick='SetDate(\"\",\"\",\"inc\",0)'>" + YEAR + "</a></td></tr></table>";
}

function ToggleYear(i) {

if (i == 1)
SetDate("","","inc",0);
if (i == -1)
SetDate("","","dec",0);
}

function DisplayYear() {
if ((IntT[0][7]) || (IntT[1][7]))
document.getElementById("oYear").src = "Editor/"+YEAR+"r.png";
else
document.getElementById("oYear").src = "Editor/"+YEAR+".png";

document.getElementById("oYear").alt = YEAR;
}

function DisplaySeason() {
if ((IntT[0][6]) || (IntT[1][6]))
document.getElementById("oSeason").src = "Editor/Season"+SEASON+"r.png";
else
document.getElementById("oSeason").src = "Editor/Season"+SEASON+".png";

document.getElementById("oSeason").alt = SEASONNAME[SEASON];
}

function ToggleSeason(i) {

if (SEASON == 0)
SEASON = 3;
else if (SEASON == 3)
SEASON = 0;
else if (SEASON == 1)
SEASON = 2;
else if (SEASON == 2)
SEASON = 1;

Check_Season();

if (i == 1)
SetDate("rand","rand","",0);
}

function Check_Season() {

if ((MODELS == "default") || (MODELS == "winter") || (MODELS == "autumn") || (MODELS == "fall") || (MODELS == "winterdemo")) {
if ((SEASON == 0) || (SEASON == 3)) {
SEASON = iRnd(1,2);
}

} else if ((MODELS == "summer") || (MODELS == "spring")) {
if ((SEASON == 1) || (SEASON == 2)) {
if (iRnd(2) == 1)
SEASON = 0;
else
SEASON = 3;
}
}

}

var oldd, oldm, oldy;

function SetDate(d,m,y,n) {

var dt;
var d1 = new Date();
var d2 = new Date();

if (n == 0) {
oldd = DAY;
oldm = MONTH;
oldy = YEAR;
}

d1.setTime(Date.parse(BATTLE_DATE[0]));
d2.setTime(Date.parse(BATTLE_DATE[1]));

if (y == "rand")
//YEAR = 1941 + iRnd(5);
YEAR = iRnd(d1.getFullYear(),d2.getFullYear());
else if (y == "inc")
YEAR++;
else if (y == "dec")
YEAR--;

if (m == "rand")
MONTH = StripNth(SEASONMONTH[SEASON],iRnd(3));
else if (m == "inc")
MONTH++;
else if (m == "dec")
MONTH--;

if (MONTH > 12) {
MONTH = 1;
YEAR++
}

if (MONTH < 1) {
MONTH = 12;
YEAR--;
}

if (d == "rand")
DAY = iRnd(1,31);
else if (d == "inc")
DAY++;
else if (d == "dec")
DAY--;

if ((DAY > 29) && (MONTH == 2) && (YEAR == 1944)) {
DAY = 1;
MONTH++;
} else if ((DAY > 28) && (MONTH == 2) && (YEAR != 1944) && (YEAR != 1940)) {
DAY = 1;
MONTH++;
} else if ((DAY > 30) && ((MONTH == 9) || (MONTH == 4) || (MONTH == 6) || (MONTH == 11))) {
DAY = 1;
MONTH++;
} else if (DAY > 31) {
DAY = 1;
MONTH++;
}

if (DAY < 1) {
MONTH--;

if ((MONTH == 2) && ((YEAR == 1944) || (YEAR == 1940)))
DAY = 29;
else if ((MONTH == 2) && (YEAR != 1944) && (YEAR != 1940))
DAY = 28;
else if ((MONTH == 0) || (MONTH == 1) || (MONTH == 3) || (MONTH == 5) || (MONTH == 7) || (MONTH == 8) || (MONTH == 10))
DAY = 31;
else
DAY = 30;
}

if (MONTH > 12) {
MONTH = 1;
YEAR++
}

if (MONTH < 1) {
MONTH = 12;
YEAR--;
}

if (YEAR > d2.getFullYear())
YEAR = d1.getFullYear();

if (YEAR < d1.getFullYear())
YEAR = d2.getFullYear();

dt = MONTH+"/"+DAY+"/"+YEAR;

if ((Date.parse(dt) < Date.parse(BATTLE_DATE[0])) || (Date.parse(dt) > Date.parse(BATTLE_DATE[1]))) {

if (n < 1000) {
if ((d == "rand") || (m == "rand") || (y == "rand")) {
if ((m == "rand") && ((n % 2) == 1))
ToggleSeason(0);
else if (n > 500)
m = "rand";

if ((y != "rand") && (n > 500))
y = "rand";

SetDate(d,m,y,(n+1));
return;
} else if ((y == "inc") || (y == "dec")) {
SetDate(d,m,y,(n+1));
return;
}
}

DAY = oldd; MONTH = oldm; YEAR = oldy;
}

SEASON = MONTHSEASON[MONTH];

DisplaySeason();

DisplayYear();

DisplayDate();
}

function MatchTemplateDate() {
var i, r, o = document.getElementById("oTemplateSelect_menu");

for (i = 0; i < 25; i++) {
SEASON = MONTHSEASON[MONTH];
r = Load_Template(TemplateRID[iRnd(TemplateRIdx)]);

if (r != false) {
o.value = r;
return;
}
}

for (i = 0; i < TemplateRIdx; i++) {
SEASON = MONTHSEASON[MONTH];
r = Load_Template(TemplateRID);

if (r != false) {
o.value = r;
return;
}
}

PreErrorMsg("112","Can't generate a template legal date within the date bounds supplied!");
}

function SetRCGDate(n) {

var dt;
var d1 = new Date();
var d2 = new Date();

d1.setTime(Date.parse(BATTLE_DATE[0]));
d2.setTime(Date.parse(BATTLE_DATE[1]));

YEAR = iRnd(d1.getFullYear(),d2.getFullYear());
MONTH = iRnd(1,12);
DAY = iRnd(1,31);

if ((DAY > 29) && (MONTH == 2) && (YEAR == 1944))
DAY = 1;
else if ((DAY > 28) && (MONTH == 2) && (YEAR != 1944) && (YEAR != 1940))
DAY = 1;
else if ((DAY > 30) && ((MONTH == 9) || (MONTH == 4) || (MONTH == 6) || (MONTH == 11)))
DAY = 1;
else if (DAY > 31)
DAY = 1;

dt = MONTH+"/"+DAY+"/"+YEAR;

if ((Date.parse(dt) < Date.parse(BATTLE_DATE[0])) || (Date.parse(dt) > Date.parse(BATTLE_DATE[1]))) {

if (n < 1000) {
SetRCGDate(n+1);
return;
}
else {
PreErrorMsg("111","Can't generate a legal date within the date bounds supplied!");
return;
}
}

MatchTemplateDate();
}

function SetRND(i,j,s,event) {
var dir = 1;

if (event)
if (event.wheelDelta <= -5)
dir = -1;

if ((s == 0) || (IntT[j])) {
clearInterval(IntT[j]);
IntT[j] = 0;

if (j == 0)
ToggleReinf(i,dir);

if (j == 1)
ToggleMF(i,dir);

if (j == 2)
ToggleEngage(i,dir);

if (j == 3)
ToggleEXP(i,dir);

if (j == 4)
ToggleSTR(i,dir);

if (j == 5) {
ToggleDIR(i,dir);
if (IntT[Math.abs(i-1)][j])
SetRND(Math.abs(i-1),5,0);
}

if (j == 6) {
clearInterval(IntT[Math.abs(i-1)][j]);
IntT[Math.abs(i-1)][j] = 0;
ToggleSeason(1);
}

if (j == 7) {
clearInterval(IntT[Math.abs(i-1)][j]);
IntT[Math.abs(i-1)][j] = 0;
ToggleYear(dir);
}

if (j == 8) {
document.getElementById("oDice_img").style.visibility = "hidden";
clearInterval(IntT[Math.abs(i-1)][j]);
IntT[Math.abs(i-1)][j] = 0;
}

if (j == 9)
document.getElementById("oPDice"+i+"_img").style.visibility = "hidden";

return;
}

if (IntT[j])
return;

if (j == 0)
IntT[0] = setInterval('RandomReinf('+i+')',250);

if (j == 1)
IntT[1] = setInterval('RandomMF('+i+')',250);

if (j == 2)
IntT[2] = setInterval('RandomEngage('+i+')',250);

if (j == 3)
IntT[3] = setInterval('RandomEXP('+i+')',250);

if (j == 4)
IntT[4] = setInterval('RandomSTR('+i+')',250);

if (j == 5) {
IntT[5] = setInterval('RandomDIR('+i+')',350);
if (!IntT[Math.abs(i-1)][j])
SetRND(Math.abs(i-1),5,1);
}

if (j == 6)
IntT[6] = setInterval('SEASON = iRnd(4); ToggleSeason(1)',250);

if (j == 7)
IntT[7] = setInterval('YEAR = 1941 + iRnd(5); ToggleYear(1)',250);

if (j == 8) {
document.getElementById("oDice_img").style.visibility = "visible";
IntT[8] = setInterval('RandomTemplate()',250);
}

if (j == 9) {
document.getElementById("oPDice"+i+"_img").style.visibility = "visible";
IntT[9] = setInterval('RandomPreset('+i+')',250);
}
}

function ToggleRND(i,o) {

var j;


if (isNaN(o))
RND = !RND;
else
RND = o;

if (RND) {
document.getElementById("oRND"+i).src = "Editor/Random.png";
document.getElementById("oRND"+i).alt = FORCENAME + " Setup is Randomized";

for (j = 0; j < 10; j++)
if (!IntT[j])
SetRND(i,j,1);
}
else {
document.getElementById("oRND"+i).src = "Editor/NoRandom.png";
document.getElementById("oRND"+i).alt = FORCENAME + " Setup as Selected";

for (j = 0; j < 10; j++)
if (IntT[j])
SetRND(i,j,0);
}
}

function ToggleAI(i) {
AI = !AI;


if (AI) {
document.getElementById("oAI"+i).src = "Editor/AI.png";
document.getElementById("oAI"+i).alt = FORCENAME + " Played by AI";
}
else {
document.getElementById("oAI"+i).src = "Editor/HI"+i+".png";
document.getElementById("oAI"+i).alt = FORCENAME + " Played by Human";
}

if (AI) {
var j = Math.abs(i - 1);

if (AI[j])
ToggleAI(j);
}
}

function ToggleLock(i,j) {
var o = document.getElementById("oLOCK"+i+j).style;

if (o.visibility == "hidden") {
o.visibility = "visible";
FORCELOCK[j] = 1;
} else {
o.visibility = "hidden";
FORCELOCK[j] = 0;
}
}

function MouseArrowDown(event, i, j) {
DeltaX = event.clientX;

MD = 1;
}


function MouseArrowUp() {
MD = 0;
}

function CalcP(v) {
return Math.floor((v - 88) / 1.62);
}

function CalcV(p) {
return Math.floor((p * 1.62) + 89);
}

function MouseArrowDrag(event, i, j) {

if (MD == 1) {
if (FORCELOCK[j])
return;

var b = document.getElementById("oBAR"+i+j);
var t = document.getElementById("oTEXT"+i+j);

var oldv, newv, oldp, newp, x, n, sum = 0, sucess = false;

oldv = parseInt(b.style.width);
newv = Math.min(Math.max(oldv + (event.clientX - DeltaX), 89), 250);
oldp = CalcP(oldv);
newp = CalcP(newv);

for (x = 0; x < 6; x++)
if (x == j)
sum = sum + newp;
else
sum = sum + FORCEMIX[x];

if (sum != 100)
for (x = 0; x < 6; x++) {
if (x == j)
continue;
n = FORCEMIX[x] + (100 - sum);
if ((n >= 0) && (n <= 100) && (!FORCELOCK[x])) {
FORCEMIX[x] = n;
document.getElementById("oBAR"+i+x).style.width = CalcV(n);
document.getElementById("oTEXT"+i+x).style.left = CalcV(n)+5;
document.getElementById("oTEXT"+i+x).innerHTML = n + "%";
sucess = true;
break;
}
}

if (sucess) {
b.style.width = newv;
t.style.left = newv+5;
t.innerHTML = CalcP(newv) + "%";
FORCEMIX[j] = CalcP(newv);
}

if (oldp != newp)
DeltaX = event.clientX;
}
}

function ConvertToCR(str) {
var i;
var s = "";

for (i = 0; i < str.length; i++) {
if (str.charCodeAt(i) == 13)
continue;
if (str.charCodeAt(i) == 10)
s = s + " [cr] ";
else
s = s + str.substring(i,i+1);
}

return s;
}

function ConvertFromCR(str, nl) {
var i;
var s = "";
var lss = false;

for (i = 0; i < str.length; i++)
if (str.substring(i,i+6).toLowerCase() == " [cr] ") {
s = s + nl;
i = i + 4;
lss = true;
}
else if (lss) {
lss = false;
if (str.substring(i,i+1) != " ")
s = s + str.substring(i,i+1);
}
else
s = s + str.substring(i,i+1);

return s;
}

function StripNth(str,n) {
var count = 0;
var lp = 0;
var j;

for (j = 0; j < str.length; j++)
if (str.substring(j,j+1) == ",") {
if (count == n)
return(parseInt(str.substring(lp,j),"10"));
lp = j+1;
count++;
}

return(parseInt(str.substring(lp,j+1),"10"));
}

function AddTPlat(z) {

var i, id;

id = z.getAttribute("unitid");

for (i = 0; i < NUMUNITTYPES; i++)
if (UNITTYPENAME == id) {
TPlatType[TPlatIdx] = i;
break;
}

if (i == NUMUNITTYPES) { PreErrorMsg("019","Unknown Unit Type in Template File"); return false; }

TPlatUnitIdx[TPlatIdx] = parseInt(z.getAttribute("max"),"10");

for (i = 0; i < TPlatUnitIdx[TPlatIdx]; i++) {
TUnitX[TPlatIdx] = StripNth(z.getAttribute("x"),i);
TUnitY[TPlatIdx] = StripNth(z.getAttribute("z"),i);
//UnitHd[UnitIdx] = StripNth(z.getAttribute("heading"),i);
}

TPlatIdx++;
}

function AddTCFPlat(side,z) {

var i, j, k, id, x = 0, exp = "";

try { id = z.getAttribute("unitid"); } catch (err) { PreErrorMsg("019","Unknown UnitID in Battle File"); return false; }

for (i = 0; i < NUMUNITTYPES; i++) {
for (j = 0; j < EquipIdx[side]; j++)
if (EquipID[side][j] == id) {
x = CFPlatoonIdx[side];
CFPlatoonID[side][x] = id;
//CFPlatoonType[side][x] = i;
CFPlatoonTag[side][x] = EquipTag[side][j];
CFPlatoonPts[side][x] = EquipPts[side][j];
break;
}

if (j < EquipIdx[side])
break;
}

if (i == NUMUNITTYPES) { PreErrorMsg("019","Unknown Unit Type '"+id+"' in Battle File"); return false; }

try { CFPlatoonName[side][x] = z.getAttribute("unitname"); } catch (err) { CFPlatoonName[side][x] = "?"; }
try { CFPlatoonNum[side][x] = z.getAttribute("number"); } catch (err) { CFPlatoonNum[side][x] = ""; }
try { CFPlatoonMax[side][x] = z.getAttribute("max"); } catch (err) { CFPlatoonMax[side][x] = CFPlatoonNum[side][x]; }
try { CFPlatoonReinT[side][x] = z.getAttribute("reinforcementTurn"); } catch (err) { CFPlatoonReintT[side][x] = ""; }
try { CFPlatoonReinC[side][x] = z.getAttribute("reinforcementChance"); } catch (err) { CFPlatoonReintC[side][x] = ""; }
try { CFPlatoonX[side][x] = z.getAttribute("x"); } catch (err) { CFPlatoonX[side][x] = ""; }
try { CFPlatoonY[side][x] = z.getAttribute("z"); } catch (err) { CFPlatoonY[side][x] = ""; }
try { CFPlatoonHd[side][x] = z.getAttribute("heading"); } catch (err) { CFPlatoonHd[side][x] = ""; }
try { CFPlatoonProb[side][x] = z.getAttribute("probability"); } catch (err) { CFPlatoonProb[side][x] = "1.0"; }
try {
exp = z.getAttribute("exp");

if (exp) {
exp = exp.toLowerCase();

for (k = 0; k < 3; k++)
if (EXPNAME[k].toLowerCase() == exp)
break;

if (k < 3)
CFPlatoonExp[side][x] = k;
else
{ PreErrorMsg("042","Error in 'exp' field of unit list in Battle File"); return false; }
}

}
catch (err) { CFPlatoonExp[side][x] = ""; }

CFPlatoonIdx[side]++;
}

function AddTObj(z) {

TObjName[TObjIdx] = z.getAttribute("points");
TObjX[TObjIdx] = parseInt(z.getAttribute("x"),"10");
TObjY[TObjIdx] = parseInt(z.getAttribute("z"),"10");

TObjIdx++;
}

function AddTMine(z) {

TMineType[TMineIdx] = z.getAttribute("type");
TMineX[TMineIdx] = z.getAttribute("min_x");
TMineY[TMineIdx] = z.getAttribute("min_z");
TMineLX[TMineIdx] = z.getAttribute("max_x");
TMineLY[TMineIdx] = z.getAttribute("max_z");

TMineIdx++;
}

function NumberPostscript(d) {

var p;

d = "" + d;

if (d.substring(d.length-1,d.length) == "1")
p = "st";
else if (d.substring(d.length-1,d.length) == "2")
p = "nd";
else if (d.substring(d.length-1,d.length) == "3")
p = "rd";
else
p = "th";

if ((d == "11") || (d == "12") || (d == "13"))
p = "th";

return p;
}

function GenerateDATE(year) {

var monthd, dayd;

if (MONTH < 10)
monthd = "0" + MONTH;
else
monthd = MONTH;

if (DAY < 10)
dayd = "0" + DAY;
else
dayd = DAY;

return (monthd + "/" + dayd + "/" + year);
}

function Load_Preset(pid, side) {

var tempXml;
var pfname;
var desc = "";
var o,i,j,k;
var rv = "";

if (pid.indexOf("@") != -1)
pid = pid.substring(0,pid.indexOf("@"));

if (pid)
pid = pid.toLowerCase();

o = document.getElementById("oFORCEMIX"+side+"_menu");
for (i = 0; i < o.options.length; i++)
if (((o.options.value).substring(0,(o.options.value).indexOf("@")).toLowerCase()) == pid)
break;

if (i < o.options.length) {
pfname = (o.options.value).substring((o.options.value).indexOf("@")+1,(o.options.value).length);
rv = o.options.value;
}
else
{ PreErrorMsg("015","Error can't find preset 'id' = '"+pid+"'"); return false; }

loadXML(pfname);

if (!ParseValidXML(pfname))
return false;

NUMFORCEMIXES[side] = 0;
SELECTEDFORCEMIX[side] = 0;

FORCEPRESETID[side][NUMFORCEMIXES[side]] = xmlObj.getAttribute("id");
FORCEPRESETNAME[side][NUMFORCEMIXES[side]] = xmlObj.getAttribute("name");

if (!xmlObj.getAttribute("title"))
FORCEPRESETTITLE[side][NUMFORCEMIXES[side]] = "force";
else
FORCEPRESETTITLE[side][NUMFORCEMIXES[side]] = xmlObj.getAttribute("title");

if (!xmlObj.getAttribute("desc"))
desc = "";
else
desc = ConvertFromCR(xmlObj.getAttribute("desc"),"\n");

var sum = 0;
var n;

for (k = 0; k < NUMUNITTYPES; k++) {
FORCEMIX[side][k] = 0;

n = xmlObj.getAttribute((UNITTYPENAME[k]).toLowerCase());

if (n) {
n = parseInt(n,"10");
FORCEMIX[side][k] = n;
sum += n;
document.getElementById("oBAR"+side+k).style.width = CalcV(n);
document.getElementById("oTEXT"+side+k).style.left = CalcV(n)+5;
document.getElementById("oTEXT"+side+k).innerHTML = n + "%";
}
else
{ PreErrorMsg("037","Error in preset field '"+UNITTYPENAME[k]+"' in file '"+pfname+"'"); }
}

if (sum != 100)
{ PreErrorMsg("038","Force % breakdown doesn't total 100% in file '"+pfname+"'"); }


//FORCEPRESETDATA[side][NUMFORCEMIXES[side]] = str;

ALLOWLISTLEN[side][NUMFORCEMIXES[side]] = 0;
ALLOWLISTUID[side][NUMFORCEMIXES[side]] = new Array();
ALLOWLISTNAME[side][NUMFORCEMIXES[side]] = new Array();
ALLOWLISTMAX[side][NUMFORCEMIXES[side]] = new Array();

var s = desc;

if (s)
s = s + "\n\n";

s = s + "--- Order Of Battle (potential) ---\n";

if (xmlObj.childNodes.length > 0) {

for (i = 0; i < xmlObj.childNodes.length; i++) {
x = xmlObj.childNodes(i);

if ((x.tagName) && (x.tagName.toLowerCase() == "auxillaryunits"))

for (j = 0; j < x.childNodes.length; j++) {
y = x.childNodes(j);

ALLOWLISTUID[side][NUMFORCEMIXES[side]][ALLOWLISTLEN[side][NUMFORCEMIXES[side]]] = y.getAttribute("unitid");
ALLOWLISTNAME[side][NUMFORCEMIXES[side]][ALLOWLISTLEN[side][NUMFORCEMIXES[side]]] = y.getAttribute("unitname");
ALLOWLISTMAX[side][NUMFORCEMIXES[side]][ALLOWLISTLEN[side][NUMFORCEMIXES[side]]] = y.getAttribute("max");
ALLOWLISTLEN[side][NUMFORCEMIXES[side]]++;

s = s + "\n" + y.getAttribute("unitname") + " ("+y.getAttribute("unitid")+")";
}

}
} else {

for (i = 0; i < NUMUNITTYPES; i++)
for (j = 0; j < EquipIdx[side]; j++)
s = s + "\n" + EquipID[side][j];
}

try { document.getElementById("oPreset_txt"+side).value = s; } catch (err) {}

NUMFORCEMIXES[side]++;

return rv;
}

function Load_Template(tid) {

var t;
var tempXml;
var tfname;
var o,i,j,k;
var rv = "";

if (tid.indexOf("@") != -1)
tid = tid.substring(0,tid.indexOf("@"));

if (tid)
tid = tid.toLowerCase();

o = document.getElementById("oTemplateSelect_menu");
for (i = 0; i < o.options.length; i++)
if (((o.options.value).substring(0,(o.options.value).indexOf("@")).toLowerCase()) == tid)
break;

if (i < o.options.length) {
tfname = (o.options.value).substring((o.options.value).indexOf("@")+1,(o.options.value).length);
rv = o.options.value;
}
else
{ PreErrorMsg("015","Error can't find template 'id' = '"+tid+"'"); return false; }

loadXML(tfname);

if (!ParseValidXML(tfname))
return false;

t = xmlObj.getAttribute("media");

MEDIA = t.substring(0,1).toUpperCase();
MEDIA += t.substring(1,t.length).toLowerCase();
NAME = xmlObj.getAttribute("name");
TID = xmlObj.getAttribute("id");
MODELS = xmlObj.getAttribute("models").toLowerCase();

PLAINDESC = "";

document.getElementById("oMap_img").src="Media/"+ MEDIA + "/map.bmp";
document.getElementById("oShadowMap_img").src="Media/"+ MEDIA + "/map.bmp";

var s = SEASON;

Check_Season();

if (s != SEASON)
if (CMDLINE)
return false;
else
ToggleSeason(1);

//load xml

var x;
var y;
var z;

tempXml = xmlObj;

TPlatIdx = 0;
TObjIdx = 0;
TMineIdx = 0;

for (i = 0; i < tempXml.childNodes.length; i++) {
x = tempXml.childNodes(i);

if ((x.tagName) && (x.tagName.toLowerCase() == "description")) {
PLAINDESC = ConvertFromCR(x.getAttribute("desc"),"\n");
DisplayDate();
}

else if ((x.tagName) && (x.tagName.toLowerCase() == "objectives"))
for (j = 0; j < x.childNodes.length; j++) {
y = x.childNodes(j);
if ((y.tagName) && (y.tagName.toLowerCase() == "objective"))
AddTObj(y);
}

else if ((x.tagName) && (x.tagName.toLowerCase() == "minefields"))
for (j = 0; j < x.childNodes.length; j++) {
y = x.childNodes(j);
if ((y.tagName) && (y.tagName.toLowerCase() == "minefield"))
AddTMine(y);
}


else if ((x.tagName) && (x.tagName.toLowerCase() == "units"))
for (j = 0; j < x.childNodes.length; j++) {
y = x.childNodes(j);
if ((y.tagName) && (y.tagName.toLowerCase() == "unit"))
AddTPlat(y);
}
}

document.getElementById("oMap_txt").value = PLAINDESC;

return rv;
}

function SetBattleDate() {
if (CMDLINE_DATE[0])
BATTLE_DATE[0] = CMDLINE_DATE[0];
else
BATTLE_DATE[0] = MINDATE;

if (CMDLINE_DATE[1])
BATTLE_DATE[1] = CMDLINE_DATE[1];
else
BATTLE_DATE[1] = MAXDATE;
}

function Load_Battle(bid) {

var tempXml;
var bfname;
var bid;
var d = new Date();
var BDATE, BICON;
var o,i,j,k,l;
var rv = "";

if (bid.indexOf("@") != -1)
bid = bid.substring(0,bid.indexOf("@"));

if (bid)
bid = bid.toLowerCase();

o = document.getElementById("oBattleSelect_menu");

for (i = 0; i < o.options.length; i++)
if (((o.options.value).substring(0,(o.options.value).indexOf("@")).toLowerCase()) == bid)
break;

if (i < o.options.length) {
bfname = (o.options.value).substring((o.options.value).indexOf("@")+1,(o.options.value).length);
rv = o.options.value;
}
else
{ PreErrorMsg("012","Error can't find battle 'id' = '"+bid+"'"); return false; }

loadXML(bfname);

if (!ParseValidXML(bfname))
return false;

tempXml = xmlObj;

BATTLE_ID = xmlObj.getAttribute("id");
BATTLE_NAME = xmlObj.getAttribute("name");
BATTLE_DESC = ConvertFromCR(xmlObj.getAttribute("desc"),"\n");
BDATE = xmlObj.getAttribute("date");
try { BICON = xmlObj.getAttribute("icon"); } catch(err) { BICON = "BattleBack0" }
try { BATTLE_ROD = xmlObj.getAttribute("rod"); } catch(err) { BATTLE_ROD = "true" }
try { BATTLE_POINTS_MULTI = parseFloat(xmlObj.getAttribute("pointsmulti")); } catch(err) { BATTLE_POINTS_MULTI = 1.0 }
try { BATTLE_PHASES = xmlObj.getAttribute("phases"); } catch(err) { BATTLE_PHASES = "40:40" }

if (!BATTLE_POINTS_MULTI) BATTLE_POINTS_MULTI = 1.0;
if (!BATTLE_ROD) BATTLE_ROD = "true";
if (!BATTLE_PHASES) BATTLE_PHASES = "40:40";
if (!BICON) BICON = "BattleBack0";

document.getElementById("oBattle_img").src = "Editor/"+BICON+".png";

TemplateRID.length = 0;
TemplateRID = xmlObj.getAttribute("template").split(",");
TemplateRIdx = TemplateRID.length;

//load xml

var x;
var y;
var z;
var side = -1;
var oldside = "";
var other;
var tside = "";
var player = -1;
var tplayer = "";
var points;
var tposture = "";
var posture = -1;
var reinforcements = "";
var exp = "";
var str = "";
var mf = "";
var dir = "";
var preset = "";

ObjIdx = 0;
PreloadObjIdx = 0;
UsersetupRIdx[0] = 0;
UsersetupRIdx[1] = 0;

for (i = 0; i < 2; i++)
for (j = 0; j < NUMUNITTYPES; j++)
CFPlatoonIdx[j] = 0;

for (i = 0; i < tempXml.childNodes.length; i++) {
x = tempXml.childNodes(i);

if ((x.tagName) && (x.tagName.toLowerCase() == "side")) {
tside = x.getAttribute("name");

if (tside)
tside = tside.toLowerCase();

if (tside == "german")
{ if (side == 0) { PreErrorMsg("018","Duplicated 'side' field in '"+bfname+"'"); } else side = 0;}
else if (tside == "russian")
{ if (side == 1) { PreErrorMsg("018","Duplicated 'side' field in '"+bfname+"'"); } else side = 1;}
else
{ PreErrorMsg("017","Error in 'side' field of '"+bfname+"'"); }

tplayer = x.getAttribute("player");

if (tplayer)
tplayer = tplayer.toLowerCase();

if (tplayer == "ai")
{ if (player == 1) { PreErrorMsg("018","Both sides can't be AI in '"+bfname+"'"); } else player = 1;}
else if (tplayer == "human")
{ player = 0; }
else
{ PreErrorMsg("017","Error in 'player' field of '"+bfname+"'"); }

if (AI[side] != player)
ToggleAI(side);

PresetRID[side].length = 0;
PresetRID[side] = x.getAttribute("preset").split(",");
PresetRIdx[side] = PresetRID[side].length;

if (CMDLINE) {
points = x.getAttribute("points");

if (points)
points = points.toUpperCase();

POINTS[side] = points;
}
else {
points = parseInt(x.getAttribute("points"));

for (j = 0; j < MAXPOINTS; j++)
if (POINTSNAME[j] == points)
break;

if (j < MAXPOINTS) {
POINTS[side] = j;
TogglePoints(side,0);
}
else
{ PreErrorMsg("042","Error in 'points' field of '"+bfname+"'"); }
}

PostureRID[side].length = 0;
PostureRID[side] = x.getAttribute("posture").split(",");
PostureRIdx[side] = PostureRID[side].length;

if (PostureRID[side][0] == "") {
other = Math.abs(side - 1);
if (PostureRIdx[other] == 0)
{ PreErrorMsg("027","Error in 'posture' field of '"+bfname+"', this value can not be null"); }
else
for (j = 0; j < PostureRIdx[other]; j++) {
if (PostureRID[other][j] < 2)
PostureRID[side][j] = 2;
else
PostureRID[side][j] = 0;
}
}
else
for (k = 0; k < PostureRIdx[side]; k++) {

if (PostureRID[side][k])
PostureRID[side][k] = PostureRID[side][k].toLowerCase();

if (PostureRID[side][0] == "random") {
for (j = 0; j < 3; j++)
PostureRID[side][j] = j;
break;
}
else {
for (j = 0; j < 3; j++) {
if (POSTURENAME[j].toLowerCase() == PostureRID[side][k])
break;
}

if (j < 3)
PostureRID[side][k] = j;
else
{ PreErrorMsg("028","Error in 'posture' field of '"+bfname+"'"); break; }
}
}

PostureRIdx[side] = PostureRID[side].length;

ReinforceRID[side].length = 0;
ReinforceRID[side] = x.getAttribute("reinforcements").split(",");
ReinforceRIdx[side] = ReinforceRID[side].length;

for (k = 0; k < ReinforceRIdx[side]; k++) {

if (ReinforceRID[side][k])
ReinforceRID[side][k] = ReinforceRID[side][k].toLowerCase();

if (ReinforceRID[side][0] == "random") {
for (j = 0; j < 2; j++)
ReinforceRID[side][j] = j;
break;
}
else {
for (j = 0; j < 2; j++) {
if (REINFORCENAME[j].toLowerCase() == ReinforceRID[side][k])
break;
}

if (j < 2)
ReinforceRID[side][k] = j;
else
{ PreErrorMsg("040","Error in 'reinforcements' field of '"+bfname+"'"); break; }
}
}

ReinforceRIdx[side] = ReinforceRID[side].length;

ExpRID[side].length = 0;
ExpRID[side] = x.getAttribute("exp").split(",");
ExpRIdx[side] = ExpRID[side].length;

for (k = 0; k < ExpRIdx[side]; k++) {

if (ExpRID[side][k])
ExpRID[side][k] = ExpRID[side][k].toLowerCase();

if (ExpRID[side][0] == "random") {
for (j = 0; j < 3; j++)
ExpRID[side][j] = j;
break;
}
else {
for (j = 0; j < 3; j++) {
if (EXPNAME[j].toLowerCase() == ExpRID[side][k])
break;
}

if (j < 3)
ExpRID[side][k] = j;
else
{ PreErrorMsg("042","Error in 'exp' field of '"+bfname+"'"); break; }
}
}

ExpRIdx[side] = ExpRID[side].length;

StrengthRID[side].length = 0;
StrengthRID[side] = x.getAttribute("str").split(",");
StrengthRIdx[side] = StrengthRID[side].length;

for (k = 0; k < StrengthRIdx[side]; k++) {

if (StrengthRID[side][k])
StrengthRID[side][k] = StrengthRID[side][k].toLowerCase();

if (StrengthRID[side][0] == "random") {
for (j = 0; j < 4; j++)
StrengthRID[side][j] = j;
break;
}
else {
for (j = 0; j < 4; j++)
if (STRNAME[j].toLowerCase() == StrengthRID[side][k])
break;

if (j < 4)
StrengthRID[side][k] = j;
else
{ PreErrorMsg("049","Error in 'str' field of '"+bfname+"'"); break; }
}
}

StrengthRIdx[side] = StrengthRID[side].length;

MinefieldRID[side].length = 0;
MinefieldRID[side] = x.getAttribute("minefields").split(",");
MinefieldRIdx[side] = MinefieldRID[side].length;

for (k = 0; k < MinefieldRIdx[side]; k++) {

if (MinefieldRID[side][k])
MinefieldRID[side][k] = MinefieldRID[side][k].toLowerCase();

if (MinefieldRID[side][0] == "random") {
for (j = 0; j < 3; j++)
MinefieldRID[side][j] = j;
break;
}
else {
for (j = 0; j < 3; j++) {
if (MFNAME[j].toLowerCase() == MinefieldRID[side][k])
break;
}

if (j < 3)
MinefieldRID[side][k] = j;
else
{ PreErrorMsg("037","Error in 'minefields' field of '"+bfname+"'"); break; }
}
}

MinefieldRIdx[side] = MinefieldRID[side].length;

UsersetupRID[side].length = 0;
UsersetupRID[side] = x.getAttribute("setup").split(",");
UsersetupRIdx[side] = UsersetupRID[side].length;

if (UsersetupRID[side][0] == "") {
other = Math.abs(side - 1);
if (UsersetupRIdx[other] == 0)
{ PreErrorMsg("020","Error in 'setup' field of '"+bfname+"', this value can not be null"); }
else
for (j = 0; j < UsersetupRIdx[other]; j++)
UsersetupRID[side][j] = SETUPENEMY[UsersetupRID[other][j]];
} else
for (k = 0; k < UsersetupRIdx[side]; k++) {

if (UsersetupRID[side][k])
UsersetupRID[side][k] = UsersetupRID[side][k].toLowerCase();

if (UsersetupRID[side][0] == "random") {
k = 0;
for (j = 0; j < SETUPIdx; j++) {
if ((SETUPSIM[j].toLowerCase() == "false") || (SETUPSIM[j].toLowerCase() == "no"))
continue;
UsersetupRID[side][k] = j;
k++;
}
break;
}
else {
for (j = 0; j < SETUPIdx; j++)
if (SETUPID[j].toLowerCase() == UsersetupRID[side][k])
break;

if (j < SETUPIdx)
UsersetupRID[side][k] = j;
else
{ PreErrorMsg("019","Error in 'setup' field of '"+bfname+"'"); break; }
}
}

UsersetupRIdx[side] = UsersetupRID[side].length;

BRIEFING[side] = x.getAttribute("briefing");

for (j = 0; j < x.childNodes.length; j++) {
y = x.childNodes(j);
if ((y.tagName) && (y.tagName.toLowerCase() == "coreunits"))
for (k = 0; k < y.childNodes.length; k++) {
z = y.childNodes(k);

if ((z.tagName) && (z.tagName.toLowerCase() == "unit"))
AddTCFPlat(side,z);
}
else if ((y.tagName) && (y.tagName.toLowerCase() == "objectives"))
for (k = 0; k < y.childNodes.length; k++) {
z = y.childNodes(k);

if ((z.tagName) && (z.tagName.toLowerCase() == "objective"))
AddObj(y.getAttribute("name"),FORCENAME[side],z.getAttribute("points"),z.getAttribute("x"),z.getAttribute("z"));
}
}
}

}

if (!CMDLINE) {
ToggleRND(0,0); // Turn Random Off
ToggleRND(1,0); // Turn Random Off
}

PopulateTemplates();
o = document.getElementById("oTemplateSelect_menu");
if (TemplateRID[0].toLowerCase() != "random") {

for (i = 0; i < o.options.length; i++) {
for (j = 0; j < TemplateRIdx; j++)
if (((o.options.value).substring(0,(o.options.value).indexOf("@")).toLowerCase()) == TemplateRID[j].toLowerCase())
break;
if (j == TemplateRIdx) {
o.options = null;
i--;
}
}

}
else {
TemplateRIdx = o.options.length;
for (i = 0; i < o.options.length; i++)
TemplateRID = o.options.value;
}

if (o.options.length == 0)
PreErrorMsg("008","Template Selection List is Empty");

if ((TemplateRIdx > 1) && CMDLINE)
{} // SetRND(0,8,1);
else
o.value = Load_Template(TemplateRID[0]);

PopulatePresets();

SetBattleDate();

if (BDATE.toLowerCase() == "random")
BDATE = MINDATE+"-"+MAXDATE;

if (BDATE != "") {
BATTLE_DATE= BDATE.split("-");

if (isNaN(Date.parse(BATTLE_DATE[0]))) { PreErrorMsg("010","Illegal Battle date format in '"+bfname+"'"); }

if ((Date.parse(BATTLE_DATE[0]) < Date.parse(MINDATE)) || (Date.parse(BATTLE_DATE[0]) > Date.parse(MAXDATE))) { PreErrorMsg("010","Battle date outside ("+MINDATE+" - " +MAXDATE+") in '"+bfname+"'"); }

if (CMDLINE_DATE[0])
if (Date.parse(BATTLE_DATE[0]) < Date.parse(CMDLINE_DATE[0]))
BATTLE_DATE[0] = CMDLINE_DATE[0];

if (BATTLE_DATE[1]) {
if (isNaN(Date.parse(BATTLE_DATE[1]))) { PreErrorMsg("010","Illegal Battle date format in '"+bfname+"'"); }
if ((Date.parse(BATTLE_DATE[1]) < Date.parse(MINDATE)) || (Date.parse(BATTLE_DATE[1]) > Date.parse(MAXDATE))) { PreErrorMsg("010","Battle date outside ("+MINDATE+" - " +MAXDATE+") in '"+bfname+"'"); }

if (CMDLINE_DATE[1])
if (Date.parse(BATTLE_DATE[1]) > Date.parse(CMDLINE_DATE[1]))
BATTLE_DATE[1] = CMDLINE_DATE[1];

if (CMDLINE)
SetRCGDate(0);
else
SetDate("rand","rand","rand",0);

} else {
BATTLE_DATE[1] = BATTLE_DATE[0];

d.setTime(Date.parse(BATTLE_DATE[0]));

MONTH = d.getMonth()+1;
DAY = d.getDate();
YEAR = d.getFullYear();

if (CMDLINE)
MatchTemplateDate();
else
SetDate("","","",0);
}
}

for (i = 0; i < 2; i++) {

if ((PostureRIdx > 1) && CMDLINE)
RandomEngage(i);
else {
ENGAGE = 0;
ToggleEngage(i,0);
}

if ((MinefieldRIdx > 1) && CMDLINE)
RandomMF(i);
else {
MF = 0;
ToggleMF(i,0);
}

if ((ReinforceRIdx > 1) && CMDLINE)
RandomReinf(i);
else {
REINFORCE = 0;
ToggleReinf(i,0);
}

if ((ExpRIdx > 1) && CMDLINE)
RandomEXP(i);
else {
EXP = 0;
ToggleEXP(i,0);
}

if ((StrengthRIdx > 1) && CMDLINE)
RandomSTR(i);

else {
STR = 0;
ToggleSTR(i,0);
}

o = document.getElementById("oFORCEMIX"+i+"_menu");
if (PresetRID[0].toLowerCase() != "random") {

for (k = 0; k < o.options.length; k++) {
for (j = 0; j < PresetRIdx; j++)
if (((o.options[k].value).substring(0,(o.options[k].value).indexOf("@")).toLowerCase()) == PresetRID[j].toLowerCase())
break;
if (j == PresetRIdx) {
o.options[k] = null;
k--;
}
}
}
else {
PresetRIdx = o.options.length;
for (k = 0; k < o.options.length; k++)
PresetRID[k] = o.options[k].value;

}

if ((PresetRIdx > 1) && CMDLINE)
o.value = Load_Preset(PresetRID[iRnd(PresetRIdx)],i);
else
o.value = Load_Preset(PresetRID[0],i);
}

if ((UsersetupRIdx[0] > 1) && CMDLINE)
RandomDIR(0);
else
ToggleDIR(0,0);

PreloadObjIdx = ObjIdx;

document.getElementById("oDesc_txt").value = BATTLE_DESC;

return rv;
}

function ResetAllElements() {
var o;

document.title = TITLESTR;

MAPWIDTH = Math.min(SWIDTH - MAPLEFT - MAPPOSADJX, MAXMAPX + MAPOVERSAMP);
MAPHEIGHT = Math.min(SHEIGHT - MAPPOSADJY, MAXMAPY + MAPOVERSAMP);

o = document.getElementById("oUIElements_div").style;

o.left = 1;
o.top = MAPTOP;
o.width = MAPLEFT+1;
o.height = MAPHEIGHT;
o.border = "thin solid gray";
o.backgroundColor = "rgb(235,235,235)";
}

function RAND(r0,r1) {

// return float between r0 ... r1

var t;

if (isNaN(r1))
return (Math.random()*r0);

if (r1 == r0)
return r0;

if (r1 < r0) {
t = r0;
r0 = r1;
r1 = t;
}

return (r0 + Math.random()*(Math.abs(r1-r0)));
}

function iRnd(r0,r1) {

// return random integer between (& including) r0 and r1

var t;

if (isNaN(r1))
return (Math.floor(Math.random()*r0));

if (r1 == r0)
return r0;

if (r1 < r0) {
t = r0;
r0 = r1;
r1 = t;
}

return (r0 + Math.floor(Math.random()*(Math.abs(r1-r0+1))));
}

function fRnd(r) {

// return float between 0 .. r

return (Math.random()*r);
}

function CalculateProbabilities() {

var i,j,k,l;

for (i = 0; i < 2; i++)
for (j = 0; j < NUMUNITTYPES; j++) {
EquipPTot[j] = 0;
for (k = 0; k < EquipIdx[j]; k++) {

for (l = 0; l < ALLOWLISTLEN[SELECTEDFORCEMIX]; l++)
if (EquipID[j][k] == ALLOWLISTUID[SELECTEDFORCEMIX][l])
break;

if ((l == 0) || (l < ALLOWLISTLEN[SELECTEDFORCEMIX])) {

if (ALLOWLISTLEN[SELECTEDFORCEMIX]) {
EquipName[j][k] = ALLOWLISTNAME[SELECTEDFORCEMIX][l];
if ((!isNaN(ALLOWLISTMAX[SELECTEDFORCEMIX][l])) && (parseInt(ALLOWLISTMAX[SELECTEDFORCEMIX][l]) > 0))
EquipMax[j][k] = parseInt(ALLOWLISTMAX[SELECTEDFORCEMIX][l]);
}
else
EquipName[j][k] = EquipID[j][k];

if (Equip3D[j][k])
EquipProb[j][k] = Prob(EquipYear[j][k], EquipMonth[j][k], EquipMedYear[j][k], EquipMedMonth[j][k], EquipEndYear[j][k], EquipEndMonth[j][k], (YEAR - 1900), MONTH, EquipMedPrev[j][k], EquipStdDev[j][k]);
else
EquipProb[j][k] = 0;


}
else
EquipProb[j][k] = 0;

EquipPTot[j] += EquipProb[j][k];
}
}
}

function GetArea(side) {

var idx = UsersetupRID[side][DIR[side]];

if (fENGAGE(side) == 2)
return(SETUPATK[idx]);
else
return(SETUPDEF[idx]);
}

function MakePotentialList(side) {

var i, j, type, PIdx, UIdx, reinf, area;

for (i = 0; i < NUMUNITTYPES; i++) {
SelTPlatIdx = 0;

for (j = 0; j < MAXTPLATS; j++)
SelTPlatUnitIdx[j] = 0;
}

area = GetArea(side);

for (i = 0; i < TPlatIdx; i++) {

type = TPlatType;
PIdx = SelTPlatIdx[type];
UIdx = SelTPlatUnitIdx[type][PIdx];
reinf = true;

for (j = 0; j < TPlatUnitIdx; j++)

if (PIA(area,TUnitX[j],TUnitY[j])) {
SelTUnitX[type][PIdx][UIdx] = TUnitX[j];
SelTUnitY[type][PIdx][UIdx] = TUnitY[j];

if ((reinf) && (PIA(NRAREA,TUnitX[j],TUnitY[j])))
reinf = false;
UIdx++;
}

if (UIdx > SelTPlatUnitIdx[type][PIdx]) {
SelTPlatUnitIdx[type][PIdx] = UIdx;
SelTPlatReinf[type][PIdx] = reinf;
SelTPlatIdx[type]++;
}
}
}

function GenerateMine(side,area1,area2) {

var i;

var SelMine = new Array();
var SelMineIdx = 0;
var p, s, MineD, dp;

// if pre-existing mines exist in the battle plan then exit

for (i = 0; i < MineIdx; i++)
if (MineNat == side)
return;

for (i = 0; i < TMineIdx; i++)
if (TMineSel < 0)
/*
if (area2 == "") {
if (PIA(area1,TMineX,TMineY) && PIA(area1,TMineLX,TMineLY)) {
SelMine[SelMineIdx] = i;
SelMineIdx++;
}
}
else {
*/
if (!PIA(area1,TMineX,TMineY) && !PIA(area2,TMineX,TMineY) && !PIA(area1,TMineLX,TMineLY) && !PIA(area2,TMineLX,TMineLY))
if (!PIA(area1,TMineLX,TMineY) && !PIA(area2,TMineLX,TMineY) && !PIA(area1,TMineX,TMineLY) && !PIA(area2,TMineX,TMineLY)) {
//alert(area1 + "\n\n" + area2 + "\n\nX = " + TMineX + " Y = " + TMineY + " LX = " + TMineLX + " LY = " + TMineLY);
SelMine[SelMineIdx] = i;
SelMineIdx++;
}


if (SelMineIdx == 0)
return;

dp = parseInt(POINTSNAME[POINTS[side]]) / 1000;
n = Math.max(1, (Math.round(3*dp) + iRnd(Math.floor(6*dp))) * MinefieldRID[side][MF[side]]);
n = Math.min(n,SelMineIdx);

//n = iRnd(3,Math.min(12,SelMineIdx));

while (n > 0)
for (i = 0; i < SelMineIdx; i++)
if (iRnd(10) < 1)
if (TMineSel[SelMine] < 0) {
TMineSel[SelMine] = side;
MineD = iRnd(0,2) + iRnd(0,MinefieldRID[side][MF[side]]);
MineD = Math.min(4,MineD);
MineD = Math.max(1,MineD);
AddMine(FORCENAME[side],TMineType[SelMine],MineD,TMineX[SelMine],TMineY[SelMine],TMineLX[SelMine],TMineLY[SelMine]);
n--;
break;
}


}

function GenerateSetupZones(side)
{
var zoneString;

var idx = UsersetupRID[side][DIR[side]];

if (fENGAGE(side) == 2)
zoneString = SETUPATKZONE[idx];
else
zoneString = SETUPDEFZONE[idx];

if (zoneString == null || zoneString == "")
return;

var zones = zoneString.split(";");

for (i = 0; i < zones.length; i++)
{
var zone = zones.split(",");

var x0 = parseInt(zone[0]) * MAXMAPX / 1000;
var y0 = parseInt(zone[1]) * MAXMAPY / 1000;

var x1 = parseInt(zone[2]) * MAXMAPX / 1000;
var y1 = parseInt(zone[3]) * MAXMAPY / 1000;

AddMine(FORCENAME[side],"setup",1,x0,y0,x1,y1);

}
}

function GenerateObj(side,points,area1,area2,f) {

var i;

var SelObj = new Array();
var SelObjIdx = 0;
var p, s;

// if pre-existing objectives exist in the battle plan then exit

for (i = 0; i < ObjIdx; i++)
if (ObjNat == side)
return;

for (i = 0; i < TObjIdx; i++)
if (TObjSel < 0)
if (area2 == "") {
if (PIA(area1,TObjX,TObjY)) {
SelObj[SelObjIdx] = i;
SelObjIdx++;
}
}
else {
if (!PIA(area1,TObjX,TObjY) && !PIA(area2,TObjX,TObjY)) {
SelObj[SelObjIdx] = i;
SelObjIdx++;
}
}

if (SelObjIdx == 0)
return;

if (f == 1) {
n = 1;
s = 0;
p = points;
}
else {
n = iRnd(1,Math.min(3,SelObjIdx));
p = Math.floor(points / n);
s = Math.floor(p / 10);
}

while (n > 0)
for (i = 0; i < SelObjIdx; i++)
if (iRnd(10) < 1)
if (TObjSel[SelObj] < 0) {
TObjSel[SelObj] = side;
if (area2 == "")
AddObj(TObjName[SelObj],FORCENAME[side],p + iRnd(-s,s),TObjX[SelObj],TObjY[SelObj]);
else
AddObj(TObjName[SelObj],"Contested",p + iRnd(-s,s),TObjX[SelObj],TObjY[SelObj]);
n--;
break;
}
}

function ReportProb(side,type) {

var i, em, mm, xm, d3, pt;

REPORT_STR = REPORT_STR + "\n\n\t" + UNITTYPENAME[type] + "\n\n";

for (i = 0; i < EquipIdx[side][type]; i++) {

pt = EquipPTot[side][type]; if (pt == 0) pt = 1;

if (EquipID[side][type].length > 23)
REPORT_STR = REPORT_STR + "\t\t" + EquipID[side][type] + "\t= " + (Math.round(EquipProb[side][type] / pt * 1000)) / 10;
else if (EquipID[side][type].length > 15)
REPORT_STR = REPORT_STR + "\t\t" + EquipID[side][type] + "\t\t= " + (Math.round(EquipProb[side][type] / pt * 1000)) / 10;
else if (EquipID[side][type].length > 7)
REPORT_STR = REPORT_STR + "\t\t" + EquipID[side][type] + "\t\t\t= " + (Math.round(EquipProb[side][type] / pt * 1000)) / 10;
else
REPORT_STR = REPORT_STR + "\t\t" + EquipID[side][type] + "\t\t\t\t= " + (Math.round(EquipProb[side][type] / pt * 1000)) / 10;

em = EquipMonth[side][type]; if (em < 10) em = "0" + em;
mm = EquipMedMonth[side][type]; if (mm < 10) mm = "0" + mm;
xm = EquipEndMonth[side][type]; if (xm < 10) xm = "0" + xm;
d3 = Equip3D[side][type];

REPORT_STR = REPORT_STR + "%\t\t(" + em + "/" + EquipYear[side][type] + " - " + mm + "/" + EquipMedYear[side][type] + " - " + xm + "/" + EquipEndYear[side][type] +")";

REPORT_STR = REPORT_STR + "\t\tsd = " + EquipStdDev[side][type]+ "\tmp = " + EquipMedPrev[side][type] + "\t3D = " + d3 + "\t("+EquipTag[side][type]+")\n";
}
}

function GetStr(side) {

var str = StrengthRID[side][STR[side]];

str = Math.max(0,str);

if (str == 0)
str = 40 + (side * iRnd(0,5)) + iRnd(-5,5) + iRnd(-5,5);
else if (str == 1)
str = 60 + (side * iRnd(0,10)) + iRnd(-5,5) + iRnd(-5,5);
else if (str == 2)
str = 80 + (side * iRnd(0,10)) + iRnd(-5,5) + iRnd(-5,5);
else
str = 100 + (side * iRnd(0,5)) + iRnd(-5,5) + iRnd(-5,5);

str = Math.min(1,str/100);

return str;
}

function GetNum(side, maxmax, tag) {

var num;

/*
if (tag == "team") {
num = iRnd(1,2) + iRnd(2);
num = Math.min(num, maxmax);
return num;
}
*/

num = Math.round(GetStr(side) * maxmax);
num = Math.min(num, maxmax);
num = Math.max(num, 1);

return num;
}

function GetMax(side, num, maxmax, tag) {

var max;

/*
if (tag == "team") {
max = iRnd(1,2) + iRnd(1,2);
max = Math.max(num, max);
max = Math.min(max, maxmax);
return max;
}
*/

//max = num + Math.round (((side / 2) + (iRnd(0,5) / 10)) * GetStr(side) * (maxmax - num));
max = num + Math.round (GetStr(side) * (maxmax - num));
max = Math.min(max, maxmax);
max = Math.max(max, 1);

return max;
}

function GenerateAuxForce(side,type,points_to_spend) {

var spent_points = 0;
var loop_count = 0;
var cpc, r, sum, num, max, str, exp, reint, reinc, SelTLen;
var equip, platoon, i;
var limit = SelTPlatIdx[type];

SelTLen = 0;

for (i = 0; i < SelTPlatIdx[type]; i++)
if (SelTPlatUnitIdx[type] > 0)
SelTLen++;

while ((SelTLen > 0) && (spent_points < (points_to_spend - 1)) && (loop_count < MAXLOOPCOUNT)) {

loop_count++;

if (loop_count > (MAXLOOPCOUNT/2))
limit = SelTPlatIdx[type];

r = fRnd(EquipPTot[side][type]);

sum = 0;

for (i = 0; i < EquipIdx[side][type]; i++) {
sum = sum + EquipProb[side][type];

if (sum > r)
break;
}

if (i == EquipIdx[side][type])
break;

equip = i;

r = iRnd(SelTLen);

sum = 0;

for (i = 0; i < limit; i++) {
if (SelTPlatUnitIdx[type] > 0)
sum++;
if (sum > r)
break;
}

if (i == limit)
continue;

platoon = i;

//if (EquipTag[side][type][equip] == "truck")
// if ((fENGAGE(side) == 2) || (iRnd(100) < 90))
// continue;

exp = ExpRID[side][EXP[side]];

if (exp == 0) {
r = iRnd(100);

if (r < 1)
exp = 2;
else if (r < 10)
exp = 1;
}
else if (exp == 1) {
if (iRnd(100) < 10)
exp = 0;
else if (iRnd(100) < 10)
exp = 2;
} else if (exp == 2) {
r = iRnd(100);

if (r < 1)
exp = 0;
else if (r < 10)
exp = 1;
}

num = GetNum(side, Math.min(SelTPlatUnitIdx[type][platoon],EquipMax[side][type][equip]), EquipTag[side][type][equip]);
max = GetMax(side, num, Math.min(SelTPlatUnitIdx[type][platoon],EquipMax[side][type][equip]), EquipTag[side][type][equip]);

reint = 0;
reinc = 1;

if ((SelTPlatReinf[type][platoon]) && (ReinforceRID[side][REINFORCE[side]])) {
if (iRnd(10) < 2) { // 20% chance reinforcement
reint = iRnd(1,10) + iRnd(1,10);
reinc = (iRnd(1,5) + iRnd(1,5)) / 10;
}
}

while (num > 0) {

cpc = CalcPlatoonCost(EquipPts[side][type][equip],num,exp,reint,reinc,0.5+(StrengthRID[side][STR[side]]+1)/8);

if ((spent_points+cpc) <= points_to_spend) {
spent_points += cpc;
AddPlatoon(FORCENAME[side],EquipID[side][type][equip],EquipName[side][type][equip],num,max,EXPNAME[exp],reint,reinc,side,type,platoon,"1.0",0.5+(StrengthRID[side][STR[side]]+1)/8);
loop_count = 0;

// This bit cuts the older platoon template at max, so unsued bit can be used again

if (max < SelTPlatUnitIdx[type][platoon]) {
SelTPlatUnitIdx[type][SelTPlatIdx[type]] = SelTPlatUnitIdx[type][platoon] - max;
SelTPlatReinf[type][SelTPlatIdx[type]] = SelTPlatReinf[type][platoon];
for (i = max; i < SelTPlatUnitIdx[type][platoon]; i++) {
SelTUnitX[type][SelTPlatIdx[type]][i - max] = SelTUnitX[type][platoon];
SelTUnitY[type][SelTPlatIdx[type]][i - max] = SelTUnitY[type][platoon];
}
SelTPlatIdx[type]++;

} else
SelTLen--;

SelTPlatUnitIdx[type][platoon] = 0;

// end new bit

break;
} else {

num--;
max--;
}
}
}

//alert("side = " + side + "\nType = " + type + "\nPoints to Spend = " + points_to_spend + "\nSpent Points = " + spent_points + "\nSelTLen = " + SelTLen + "\nLoop count = " + loop_count + "\nMaxloopcount = " + MAXLOOPCOUNT);

return spent_points;
}

function GenerateCoreForce(side,type) {

var spent_points = new Array;
var s_p = new Array;
var r, sum, max, SelTLen, substype;
var i, j = 0;
var p, ps, A, D;

spent_points[0] = 0;
spent_points[1] = 0;

for (i = 0; i < CFPlatoonIdx[side][type]; i++) {

p = CFPlatoonProb[side][type];

if (p)
p = p.toUpperCase();
else
p = "1.0";

ps = p;

if (isNaN(p)) {

try { eval(p); }
catch (err) { PreErrorMsg("112","Poorly formed core 'probability' (of appearing) field."); return; }

if (A > 1.0) A = 1.0; if (A < 0.0) A = 0.0;
if (D > 1.0) A = 1.0; if (D < 0.0) D = 0.0;

if (fENGAGE(side) == 2)
p = A;
else
p = D;
}
else {
p = parseFloat(p); if (p > 1.0) p = 1.0; if (p < 0.0) p = 0.0;
}

if (fRnd(1.0) > p)
continue;

if ((CFPlatoonX[side][type]) && (CFPlatoonY[side][type]) && (CFPlatoonMax[side][type])) {
s_p = AddCorePlatoon(side,type,i,-1,type,ps,0.5+(StrengthRID[side][STR[side]]+1)/8);
spent_points[0] += s_p[0];
spent_points[1] += s_p[1];
}

else {
max = 0;

if (CFPlatoonMax[side][type])
max = parseInt(CFPlatoonMax[side][type]);

SelTLen = 0;

for (j = 0; j < SelTPlatIdx[type]; j++)
if (SelTPlatUnitIdx[type][j] >= max)
SelTLen++;

substype = type;

if (SelTLen == 0) {
substype = SUBSTYPE[type];

for (j = 0; j < SelTPlatIdx[substype]; j++)
if (SelTPlatUnitIdx[substype][j] >= max)
SelTLen++;

if (SelTLen == 0) {
if (CORE_ERROR[side] == "")
CORE_ERROR[side] = CFPlatoonName[side][type];
else
CORE_ERROR[side] = CORE_ERROR[side] + ", " + CFPlatoonName[side][type];

//if (WARNINGS)
// PreErrorMsg("003","Unable to place core platoon '"+CFPlatoonName[side][type]+"' with this template!");
return spent_points;
}
}

r = iRnd(SelTLen);

sum = 0;

for (j = 0; j < SelTPlatIdx[substype]; j++) {
if (SelTPlatUnitIdx[substype][j] >= max)
sum++;

if (sum > r)
break;
}


if (j == SelTPlatIdx[substype])
break;

s_p = AddCorePlatoon(side,type,i,j,substype,ps,0.5+(StrengthRID[side][STR[side]]+1)/8);
spent_points[0] += s_p[0];
spent_points[1] += s_p[1];
SelTPlatUnitIdx[substype][j] = 0;
}

}

return spent_points;
}

function DetHdg(side,x1,y1) {

var idx = UsersetupRID[side][DIR[side]];

var s = SETUPFACE[idx];
var fp = new Array();
var hdg, dx, dy;

if (s.substring(0,1) == "!")
fp = s.substring(1,s.length).split(",");
else
fp = s.substring(0,s.length).split(",");

var x0 = parseInt(fp[0]);
var y0 = parseInt(fp[1]);

if (isNaN(x0) || isNaN(y0)) {
PreErrorMsg("047","Error in 'faceto' value.");
return 0;
}

if (s.substring(0,1) == "!") {
dx = x1 - x0;
dy = y1 - y0;
}
else {
dx = x0 - x1;
dy = y0 - y1;
}

if (dy == 0) {
if (dx == 0)
hdg = 0;
else if (dx < 0)
hdg = 90;
else
hdg = 270;
}
else {
if (dx < 0)
if (dy < 0)
hdg = Math.atan(dx/dy) / DEGTORAD;
else
hdg = 180 + (Math.atan(dx/dy) / DEGTORAD);
else
if (dy > 0)
hdg = 180 + (Math.atan(dx/dy) / DEGTORAD);
else
hdg = 360 + (Math.atan(dx/dy) / DEGTORAD);
}


hdg += iRnd(-18,18);

if (hdg >= 360)
hdg -= 360;

if (hdg < 0)
hdg += 360;

return hdg;

}

function AddCorePlatoon(side,type,idx,platoon,substype,ps,ammo) {

var i, reint = 0, reinc = 1, exp, r, num, max, str;

PlatoonNat[PlatoonIdx] = FORCENAME[side];
PlatoonID[PlatoonIdx] = CFPlatoonID[side][type][idx];
PlatoonName[PlatoonIdx] = CFPlatoonName[side][type][idx];
PlatoonType[PlatoonIdx] = type;
PlatoonCore[PlatoonIdx] = true;
PlatoonSet[PlatoonIdx] = MODELS;
PlatoonProb[PlatoonIdx] = ps;
PlatoonAmmo[PlatoonIdx] = ammo;

if (platoon != -1) {
if (CFPlatoonNum[side][type][idx])
num = parseInt(CFPlatoonNum[side][type][idx]);
else
num = GetNum(side, Math.min(SelTPlatUnitIdx[type][platoon],EquipMax[side][type][idx]), CFPlatoonTag[side][type][idx]);

if (CFPlatoonMax[side][type][idx])
max = parseInt(CFPlatoonMax[side][type][idx]);
else
max = GetMax(side, num, Math.min(SelTPlatUnitIdx[type][platoon],EquipMax[side][type][idx]), CFPlatoonTag[side][type][idx]);

PlatoonNum[PlatoonIdx] = num;
PlatoonMax[PlatoonIdx] = max;

for (i = 0; i < max; i++) {
UnitX[UnitIdx] = SelTUnitX[substype][platoon];
UnitY[UnitIdx] = SelTUnitY[substype][platoon];
UnitHd[UnitIdx] = DetHdg(side,UnitX[UnitIdx],UnitY[UnitIdx]);

UnitPPos[UnitIdx] = i;
UnitPlatoon[UnitIdx] = PlatoonIdx;
UnitIdx++;
}
}
else {
PlatoonMax[PlatoonIdx] = parseInt(CFPlatoonMax[side][type][idx]);

max = PlatoonMax[PlatoonIdx];

if (CFPlatoonNum[side][type][idx])
PlatoonNum[PlatoonIdx] = parseInt(CFPlatoonNum[side][type][idx]);
else
PlatoonNum[PlatoonIdx] = GetNum(side, max, "");

num = PlatoonNum[PlatoonIdx];

for (i = 0; i < PlatoonMax[PlatoonIdx]; i++) {
UnitX[UnitIdx] = StripNth(CFPlatoonX[side][type][idx],i);
UnitY[UnitIdx] = StripNth(CFPlatoonY[side][type][idx],i);

if (CFPlatoonHd[side][type][idx])
UnitHd[UnitIdx] = StripNth(CFPlatoonHd[side][type][idx],i);
else
UnitHd[UnitIdx] = DetHdg(side,UnitX[UnitIdx],UnitY[UnitIdx]);

UnitPPos[UnitIdx] = i;
UnitPlatoon[UnitIdx] = PlatoonIdx;
UnitIdx++;
}
}

if (CFPlatoonReinT[side][type][idx]) {
reint = parseInt(CFPlatoonReinT[side][type][idx]);
reinc = parseInt(CFPlatoonReinC[side][type][idx]);
}
else {
if ((SelTPlatReinf[type][platoon]) && (ReinforceRID[side][REINFORCE[side]])) {
if (iRnd(10) < 1) { // 10% chance reinforcement
reint = iRnd(1,10) + iRnd(1,10);
reinc = (iRnd(1,5) + iRnd(1,5)) / 10;
}
}
}

PlatoonReinT[PlatoonIdx] = reint;
PlatoonReinC[PlatoonIdx] = reinc;

if (CFPlatoonExp[side][type][idx])
exp = CFPlatoonExp[side][type][idx];
else {
exp = ExpRID[side][EXP[side]];

if (exp == 0) {
r = iRnd(100);
if (r < 1)
exp = 2;
else if (r < 10)
exp = 1;
}
else if (exp == 1) {
if (iRnd(100) < 10)
exp = 0;
else if (iRnd(100) < 10)
exp = 2;
} else if (exp == 2) {
r = iRnd(100);
if (r < 1)
exp = 0;
else if (r < 10)
exp = 1;
}
}

PlatoonExp[PlatoonIdx] = EXPNAME[exp];

PlatoonIdx++;

var r_p = new Array;

r_p[0] = CalcPlatoonCost(CFPlatoonPts[side][type][idx],num,exp,reint,reinc,ammo);
r_p[1] = CalcPlatoonCost(CFPlatoonPts[side][type][idx],max,exp,reint,reinc,ammo);

return r_p;
}

function WriteDESC() {

var i, j;
var s;
var hp, ai;
var et;

DESC = "("+fENGAGE(0)+""+fENGAGE(1)+ ") Date: " + DATE + " (" + SEASONNAME[SEASON]+")\n\n";

var s = "Art of War";
if (BATTLE_ROD == "true")
s = "Science of War";

DESC += "Turn Phases: " + BATTLE_PHASES + "\nRussian plays " + s + " rules.\n\n";

if (!AI[0])
if (!AI[1]) {
DESC += "Best played 2 Player head to head.\n";
return;
}
else
hp = 0;
else
hp = 1;

ai = Math.abs(hp - 1);

DESC += "Human: " + FORCENAME[hp] + " vs AI: " + FORCENAME[ai] + ".\n\n";

for (i = 0; i < 2; i++) {

j = Math.abs(i-1);

if (AI[j])
if (fENGAGE(i) == 2)
if (fENGAGE(j) == 2) {
et = 2;
DESC += HEADER[2][iRnd(HEADER_COUNT)];
}
else {
et = 0;
DESC += HEADER[0][iRnd(HEADER_COUNT)];
}
else {
DESC += HEADER[1][iRnd(HEADER_COUNT)];
et = 1;
}
}

if (BRIEFING[hp])
DESC += "\n\n--- Overview ---\n\n" + ConvertFromCR(BRIEFING[hp],"\n");

DESC += "\n\n--- Situation ---\n\n";

DESC += PLAINDESC + "\n\n";

DESC += "Your " + FORCEPRESETTITLE[hp][SELECTEDFORCEMIX[hp]] + " which is " +STRNAME[StrengthRID[hp][STR[hp]]].toLowerCase() + " strength with " + EXPNAME[ExpRID[hp][EXP[hp]]].toLowerCase()+" units, is "+SETUPDESC[UsersetupRID[hp][DIR[hp]]]+".\n\n";

DESC += SITUATION[iRnd(SITUATION_COUNT)];

DESC += "\n\n--- Orders ---\n\n";

DESC += ORDER[et][iRnd(ORDER_COUNT)] + " ";

var maxpts = 5;
var idx = -1;
var typ;

if (et == 0)
typ = ai;
if (et == 1)
typ = hp;

if (et != 2) {

for (i = 0; i < ObjIdx; i++)
if ((ObjNat == FORCENAME[typ]) && (ObjName != ""))
if (maxpts < ObjPts) {
maxpts = ObjPts;
idx = i;
}
}

if (idx != -1)
DESC += OBJ_ORDER[et][iRnd(OBJ_ORDER_COUNT)].replace(/{obj}/g,ObjName[idx]) + " ";

var maxpts2 = 5;
var idx2 = -1;

if (et != 2) {

for (i = 0; i < ObjIdx; i++)
if ((ObjNat == FORCENAME[typ]) && (ObjName != ""))
if (maxpts2 < ObjPts) {
if (i == idx)
continue;
maxpts2 = ObjPts;
idx2 = i;
}
}

if ((idx != -1) && (idx2 != -1))
DESC += OBJ1_ORDER[et][iRnd(OBJ1_ORDER_COUNT)].replace(/{obj}/g,ObjName[idx2]) + " ";

if ((VPBONUSTURN > 0) && (VPBONUSTURN < 60) && (fENGAGE(ai) !=2)) {
DESC += "\n\n" + TIME_ORDER[0][iRnd(TIME_ORDER_COUNT)] + " ";
DESC += TIME1_ORDER[0][iRnd(TIME1_ORDER_COUNT)].replace(/{turn}/g,VPBONUSTURN + iRnd(-3,3))
}

if ((VPBONUSTURN > 0) && (VPBONUSTURN < 60) && (fENGAGE(hp) != 2)) {
DESC += "\n\n" + TIME_ORDER[1][iRnd(TIME_ORDER_COUNT)] + " ";
DESC += TIME1_ORDER[1][iRnd(TIME1_ORDER_COUNT)].replace(/{turn}/g,VPBONUSTURN + iRnd(-3,3))
}

DESC += "\n\n--- Intelligence ---\n\n";

var pdelta = parseInt(TOTAL_POINTS[ai]) / parseInt(TOTAL_POINTS[hp]);
var res = "";

if ((pdelta > 0.9) && (pdelta < 1.1))
res = "middling";
if (pdelta >= 1.1)
res = "heavy";
if (pdelta > 1.5)
res = "very heavy";
if (pdelta > 2.0)
res = "devastating";
if (pdelta <= 0.9)
res = "light";
if (pdelta < 0.5)
res = "minimal";

DESC += (IQ_ORDER[iRnd(IQ_ORDER_COUNT)].replace(/{res}/g,res)).replace(/{force}/g,FORCEPRESETTITLE[ai][SELECTEDFORCEMIX[ai]]) + " ";

//DESC = DESC.replace(/{force}/g,FORCEPRESETTITLE[ai][SELECTEDFORCEMIX[ai]]);

var sup = new Array();
var supIdx = 0;
var supstr = "";

if ((FORCEMIX[ai][ART] > 5) && (iRnd(2) < 1))
sup[supIdx++] = "artillery";

if ((FORCEMIX[ai][AIR] > 5) && (iRnd(2) < 1))
sup[supIdx++] = "air";

if ((MinefieldRID[ai][MF[ai]] > 0) && (iRnd(2) < 1))
sup[supIdx++] = "minefield";

if (supIdx == 1)
supstr = sup[0] + " support";
if (supIdx == 2)
supstr = sup[0] + " and " + sup[1] + " support";
if (supIdx == 3)
supstr = sup[0] + ", " + sup[1] + " and " + sup[2] + " support";

if (supstr)
DESC += IQ1_ORDER[iRnd(IQ1_ORDER_COUNT)].replace(/{units}/g,supstr);

if (MinefieldRID[hp][MF[hp]] == 1)
DESC += "\n\nOur engineers have had little time to mine likely avenues of enemy attack.";

if (MinefieldRID[hp][MF[hp]] == 2)
DESC += "\n\nThankfully our engineers have had enough time to heavily mine likely avenues of enemy attack.";


if (hp == 0)
DESC += "\n\n\nGuter Glück Kommandant";
else
DESC += "\n\n\nУдачи Командир";
}

function Build() {

var i,j,k,p,r,sum,ratio,tmpp, z;
var Points_Left = new Array();
var ret_ponts = new Array();
CORE_ERROR[0] = "";
CORE_ERROR[1] = "";

// 1. Setup

if (CMDLINE)
NAME = "Campaign Random Battle " + DATE;
else
NAME = "Random Battle " + DATE;

//ID = "Random";

// 2. Calculate Probabilities

CalculateProbabilities();

// 3. Reset Old Datastructures

PlatoonIdx = 0;
UnitIdx = 0;
ObjIdx = PreloadObjIdx;
MineIdx = 0;

REPORT_STR = "RBG Z-Distribution (for debug purposes only)\nBest viewed with a monospaced font (eg. Lucida Console 10) and Word Wrap off in Notepad.\n\nBattle Date: " + DATE + "\n";

// 4. Spend % Points on units

for (z = 0; z < 2; z++) {

i = z;

if (AI[0])
i = Math.abs(z-1);

MakePotentialList(i);
FORCE_TOTAL = 0;
CORENUM_POINTS = 0;
COREMAX_POINTS = 0;
TOTAL_POINTS = 0;

REPORT_STR = REPORT_STR + "\n\n" + "--------------------------------------------------------------- " + FORCENAME + " ---------------------------------------------------------------";

for (j = 0; j < NUMUNITTYPES; j++) {
if (CANCEL_BUILD) { HideWaitBox(); return; }
ReportProb(i,j);
ret_points = GenerateCoreForce(i,j);
CORENUM_POINTS += ret_points[0];
COREMAX_POINTS += ret_points[1];
}

FORCE_TOTAL = CORENUM_POINTS;

if (CMDLINE)
try {
var enemy = Math.abs(i-1);

POINTS = POINTS.replace(/%ON/g,CORENUM_POINTS);
POINTS = POINTS.replace(/%OM/g,COREMAX_POINTS);

if ((POINTS.indexOf("%EN") != -1) && (z == 0))
{ PreErrorMsg("073","Attempted circular points calculation '%EN' variable."); return; }

POINTS = POINTS.replace(/%EN/g,CORENUM_POINTS[enemy]);

if ((POINTS.indexOf("%EM") != -1) && (z == 0))
{ PreErrorMsg("073","Attempted circular points calculation '%EM' variable."); return; }

POINTS = POINTS.replace(/%EM/g,COREMAX_POINTS[enemy]);

if ((POINTS.indexOf("%EP") != -1) && (z == 0))
{ PreErrorMsg("073","Attempted circular points calculation '%EP' variable."); return; }

POINTS = POINTS.replace(/%EP/g,TOTAL_POINTS[enemy]);

POINTS = POINTS.replace(/%RM/g,H_MULTI);

if (fENGAGE(i) < 2) {
POINTS = POINTS.replace(/%OA/g,0);
POINTS = POINTS.replace(/%OD/g,1);
}
else {
POINTS = POINTS.replace(/%OA/g,1);
POINTS = POINTS.replace(/%OD/g,0);
}

TOTAL_POINTS = Math.floor(eval(POINTS));
}
catch(err) { PreErrorMsg("073","Poorly formed "+FORCENAME+" 'points' field."); return; }
else
TOTAL_POINTS = Math.floor(parseInt(POINTSNAME[POINTS]) * BATTLE_POINTS_MULTI);

Points_Left = TOTAL_POINTS - FORCE_TOTAL;

if (Points_Left > 0)
for (j = 0; j < NUMUNITTYPES; j++) {
if (CANCEL_BUILD) { HideWaitBox(); return; }
POINTS_SPENT[j] = GenerateAuxForce(i,j,Math.round(FORCEMIX[j] * Points_Left / 100 ));
FORCE_TOTAL += POINTS_SPENT[j];
}

Points_Left = TOTAL_POINTS - FORCE_TOTAL;

for (k = 0; k < MAXLOOPCOUNT; k++) {
if (CANCEL_BUILD) { HideWaitBox(); return; }

if (Points_Left <= 0)
break;

r = iRnd(1,100);

sum = 0;

for (j = 0; j < NUMUNITTYPES; j++) {
sum = sum + FORCEMIX[j];

if (sum > r)
break;
}

if (j == NUMUNITTYPES)
break;

if ((FORCEMIX[j] == 0) || (j == AIR) || (j == ART))
continue;

p = GenerateAuxForce(i,j,Math.floor(1.0 * Points_Left));
POINTS_SPENT[j] += p;
FORCE_TOTAL += p;
Points_Left -= p;
}
}

// 5. Check that core and total points are spent

for (i = 0; i < 2; i++) {
if (CORE_ERROR != "") {
if (BUILDATTEMPTS < MAXLOOPCOUNT) {
document.getElementById("oStatus_div").style.width = Math.round(433 * (BUILDATTEMPTS/MAXLOOPCOUNT));

BUILDATTEMPTS++;

setTimeout('Build()',100);
return;
}
else {
if (CMDLINE && WARNINGS) {
PreErrorMsg("003","\nBUILDATTEMPTS = " + BUILDATTEMPTS + "\nUnable to place core platoon(s) '"+CORE_ERROR+"' with this template!");
Exit_RBG(0);
return;
} else if (!CMDLINE) {
document.getElementById("oLoading_txt").innerHTML = "<font color='white' size='5' style='height:38px'>Failed!</font>";
document.getElementById("oStatus_div").style.width = Math.round(0);
Notice(FORCENAME + " core unit defines exceed this template complexity.\n\nConsider adjusting any of the following:\n\n · Change Battle Plan\n · Change Template\n · Change Force Preset\n · Decrease Force Points\n · Change Force Direction\n · Increase Force Strength\n · Increase Force Experience\n · Set Later Date",INFO_TITLE);
HideWaitBox();
return;
}
}
Exit_RBG(0);
return;
}
}


for (i = 0; i < 2; i++) {
if (Points_Left > (TOTAL_POINTS * .05)) {
if (BUILDATTEMPTS < MAXLOOPCOUNT) {
document.getElementById("oStatus_div").style.width = Math.round(433 * (BUILDATTEMPTS/MAXLOOPCOUNT));

BUILDATTEMPTS++;

setTimeout('Build()',100);
return;
}
else {
if (CMDLINE && WARNINGS) {
PreErrorMsg("123","\nBUILDATTEMPTS = " + BUILDATTEMPTS + "\nPoints unspent SIDE " + i + " = " + Points_Left + "\nTotal Points SIDE "+ i + " = " + TOTAL_POINTS);
Exit_RBG(0);
return;
} else if (!CMDLINE) {
document.getElementById("oLoading_txt").innerHTML = "<font color='white' size='5' style='height:38px'>Failed!</font>";
document.getElementById("oStatus_div").style.width = Math.round(0);
Notice(FORCENAME + " points ("+TOTAL_POINTS+") exceeds this template complexity.\n\nConsider adjusting any of the following:\n\n · Change Battle Plan\n · Change Template\n · Change Force Preset\n · Decrease Force Points\n · Change Force Direction\n · Increase Force Strength\n · Increase Force Experience\n · Set Later Date",INFO_TITLE);
HideWaitBox();
return;
}
}
Exit_RBG(0);
return;
}
}

// 6. Randomly generate objs (objs based on total number points)

for (i = 0; i < TObjIdx; i++)
TObjSel = -1;

var Game_Points = (TOTAL_POINTS[0] + TOTAL_POINTS[1]) / BATTLE_POINTS_MULTI;

for (i = 0; i < 2; i++)
{
if ((fENGAGE(i) == 2) && (fENGAGE(Math.abs(i-1)) == 2))
GenerateObj(i, Math.floor(0.15 * Game_Points),GetArea(i),GetArea(Math.abs(i-1)),0);
if (fENGAGE(i) != 2)
GenerateObj(i, Math.floor((0.30 + (iRnd(-1,1) * fRnd(0.1))) * (TOTAL_POINTS/BATTLE_POINTS_MULTI)),GetArea(i),"",0);
}

// 7. Randomly generate minefields

for (i = 0; i < TMineIdx; i++)
TMineSel = -1;

for (i = 0; i < 2; i++)
if (MinefieldRID[MF] > 0)
GenerateMine(i,GetArea(i),GetArea(Math.abs(i-1)));

// 7a. Generate SetupZones

for (i = 0; i < 2; i++)
GenerateSetupZones(i);

// 8. Generate Defender bonuses

if ((fENGAGE(0) == 1) || (fENGAGE(1) == 1)) {

ratio = 1;

if (fENGAGE(0) == 1)
ratio = TOTAL_POINTS[1] / TOTAL_POINTS[0];
else if (fENGAGE(1) == 1)
ratio = TOTAL_POINTS[0] / TOTAL_POINTS[1];

if (ratio < 1) {
VPBONUSTURN = iRnd(25,30);
VPBONUSAMT = iRnd(Math.floor(0.005*Game_Points),Math.floor(0.01*Game_Points)); //VPBONUSAMT = function of the total points;
}
else if (ratio < 1.25) {
VPBONUSTURN = iRnd(20,25);
VPBONUSAMT = iRnd(Math.floor(0.01*Game_Points),Math.floor(0.02*Game_Points)); //VPBONUSAMT = function of the total points;
}
else if (ratio < 1.5) {
VPBONUSTURN = iRnd(15,20);
VPBONUSAMT = iRnd(Math.floor(0.015*Game_Points),Math.floor(0.03*Game_Points)); //VPBONUSAMT = function of the total points;
}
else if (ratio < 2) {
VPBONUSTURN = iRnd(10,15);
VPBONUSAMT = iRnd(Math.floor(0.02*Game_Points),Math.floor(0.04*Game_Points)); //VPBONUSAMT = function of the total points;
}
else {
VPBONUSTURN = iRnd(5,10);
VPBONUSAMT = iRnd(Math.floor(0.025*Game_Points),Math.floor(0.06*Game_Points)); //VPBONUSAMT = function of the total points;
}
}
else {
VPBONUSTURN = 60;
VPBONUSAMT = Game_Points;
}

// Determine who is the defender
if (fENGAGE(0) != 2)
DEFENDER = 0;
else if (fENGAGE(1) != 2)
DEFENDER = 1;
else {
if (AI[0])
DEFENDER = 1;
else if (AI[1])
DEFENDER = 0;
else
DEFENDER = iRnd(1);
}

// Determine who has preplanned arty
if (fENGAGE(0) == 2 && fENGAGE(1) == 2)
BATTLE_PREPLANNED = "Both";
else if (fENGAGE(0) == 2)
BATTLE_PREPLANNED = "German";
else if (fENGAGE(1) == 2)
BATTLE_PREPLANNED = "Russian";
else
BATTLE_PREPLANNED = "None";

// 9. Write Description

WriteDESC();

// 10. Save Scenario

SortPlatoons();

SaveScenario();

if (CMDLINE)
Exit_RBG(1);
else if (FROMGAME)
setTimeout("window.close()",1000);
else
window.close();
}

function Prob(ey,em,my,mm,xy,xm,dy,dm,p,sd) {

var patm = p / 100; // Probability at median date
var e = (ey * 12) + (em - 1); // entry date
var d = (dy * 12) + (dm - 1); // current date
var m = (my * 12) + (mm - 1); // median date
var x = (xy * 12) + (xm - 1); // exit date

if (d < e)
return 0;

if (d > x)
return 0;

return (patm * Math.exp(-1*(d - m)*(d - m)/(2*sd*sd)));
}

function Distance(x0,y0,x1,y1) {
return Math.sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));
}

function PIA(Area,x,y) { // Point In Area

var i, x0, x1, y0, y1, yc;
var inside = false;

var points = Area.split(",");

var p = -2;
var atEnd = false;

while (!atEnd) {

p += 2;

x0 = parseInt(points[p]) * MAXMAPX / 1000;
y0 = parseInt(points[p+1]) * MAXMAPY / 1000;

if (p == (points.length - 2)) {
x1 = parseInt(points[0]) * MAXMAPX / 1000;
y1 = parseInt(points[1]) * MAXMAPY / 1000;
atEnd = true;
}
else {
x1 = parseInt(points[p+2]) * MAXMAPX / 1000;
y1 = parseInt(points[p+3]) * MAXMAPY / 1000;

}

if ((x0 < x) && (x1 < x))
continue;

if ((x0 > x) && (x1 > x))
continue;

if ((y0 < y) && (y1 < y))
continue;

if ((y0 > y) && (y1 > y)) {
if ((Math.min(x0,x1) < x) && (Math.max(x0,x1) > x))
inside = !inside;

continue;
}

yc = y0 + (y1 - y0)/(x1 - x0)*(x - x0);

if (yc > y)
inside = !inside;
}

return inside;
}

function CalcPlatoonCost(unitcost,num,exp,reint,reinc,ammo) {

var replaceCost = 0;
var trainingModifier = 1.0;
var discount;

if (exp == 2)
trainingModifier += 0.2;
else if (exp == 0)
trainingModifier -= 0.2;

replaceCost = Math.floor(unitcost * trainingModifier * num);

if (reint > 0)
discount = (1.0 - ((((reint-1.0) * (1.0+(1.0 - reinc)))*1.5)/100.0)) * ((ammo-0.1)*0.4 + 0.64);
else
discount = ((ammo-0.1)*0.4 + 0.64);

replaceCost = Math.floor(replaceCost * discount);
if (replaceCost < 1.0)
replaceCost = 1.0;

return (replaceCost);
}

function AddMine(nat, typ, dens, x, y, lx, ly) {
var m = MineIdx;

MineNat[m] = nat;
MineType[m] = typ;
MineDens[m] = dens;

if (parseInt(x) <= parseInt(lx)) {
MineX[m] = parseInt(x);
MineLX[m] = parseInt(lx);
}
else {
MineX[m] = parseInt(lx);
MineLX[m] = parseInt(x);
}
if (parseInt(y) <= parseInt(ly)) {
MineY[m] = parseInt(y);
MineLY[m] = parseInt(ly);
}
else {
MineY[m] = parseInt(ly);
MineLY[m] = parseInt(y);
}

MineIdx++;
}

function AddObj(name, nat, points, x, y) {
var o = ObjIdx;

ObjName[o] = name;
ObjNat[o] = nat;
ObjPts[o] = points;
ObjX[o] = parseInt(x);
ObjY[o] = parseInt(y);
ObjIdx++;
}

function SortPlatoons() {
// yes a cheap bubble sort I know, but the list is short!
// sorts core, reinforceT, reinforceC, id, type, alphabetical, platoon number

var i, j;
var changed = 1;
var idx;
var fnat;
var snat;
var fuc; // :-) first unit core
var suc; // :-) second unit core
var furt;
var surt;
var furc;
var surc;
var fut;
var sut;
var fid;
var sid;
var fuid, suid;
var fname;
var sname;
var fexp;
var sexp;
var fnum;
var snum;
var fmax;
var fset;
var sset;
var fprb;
var sprb;

var sf, sc;

while (changed) {
changed = 0;
for (i = 0; i < (PlatoonIdx-1); i++) {

fnat = PlatoonNat;
snat = PlatoonNat[i+1];
fuc = PlatoonCore;
suc = PlatoonCore[i+1];
furt = PlatoonReinT;
surt = PlatoonReinT[i+1];
furc = PlatoonReinC;
surc = PlatoonReinC[i+1];
fut = PlatoonType;
sut = PlatoonType[i+1];
fuid = PlatoonID;
suid = PlatoonID[i+1];

fid = (PlatoonName).toLowerCase();
sid = (PlatoonName[i+1]).toLowerCase();

fid = fid.substring(0,fid.indexOf(" "));
sid = sid.substring(0,sid.indexOf(" "));

fname = (PlatoonName).toLowerCase();
sname = (PlatoonName[i+1]).toLowerCase();

fname = fname.substring(fname.indexOf(" "),fname.length);
sname = sname.substring(sname.indexOf(" "),sname.length);

sf = 0;
sc = 0;

if (fnat > snat)
sf += 10000000;

if (snat > fnat)
sc += 10000000;

if (!fuc)
sf += 1000000;

if (!suc)
sc += 1000000;

if (furt > surt)
sf += 100000;

if (surt > furt)
sc += 100000;

if (furc < surc)
sf += 10000;

if (surc < furc)
sc += 10000;

if (fut > sut)
sf += 1000;

if (sut > fut)
sc += 1000;

if (fuid > suid)
sf += 100;

if (suid > fuid)
sc += 100;

if (fname > sname)
sf += 10;

if (sname > fname)
sc += 10;

if (fid > sid)
sf += 1;

if (sid > fid)
sc += 1;

if (sc < sf) {
changed = 1;

fexp = PlatoonExp;
sexp = PlatoonExp[i+1];
fname = PlatoonName;
sname = PlatoonName[i+1];
fnum = PlatoonNum;
snum = PlatoonNum[i+1];
fmax = PlatoonMax;
smax = PlatoonMax[i+1];
fset = PlatoonSet;
sset = PlatoonSet[i+1];
fprb = PlatoonProb;
sprb = PlatoonProb[i+1];
famo = PlatoonAmmo;
samo = PlatoonAmmo[i+1];

PlatoonNat = snat;
PlatoonID = suid;
PlatoonType = sut;
PlatoonExp = sexp;
PlatoonCore = suc;
PlatoonNum = snum;
PlatoonMax = smax;
PlatoonReinT = surt;
PlatoonReinC = surc;
PlatoonSet = sset;
PlatoonName = sname;
PlatoonProb = sprb;
PlatoonAmmo = samo;

PlatoonNat[i+1] = fnat;
PlatoonID[i+1] = fuid;
PlatoonType[i+1] = fut;
PlatoonExp[i+1] = fexp;
PlatoonCore[i+1] = fuc;
PlatoonNum[i+1] = fnum;
PlatoonMax[i+1] = fmax;
PlatoonReinT[i+1] = furt;
PlatoonReinC[i+1] = furc;
PlatoonSet[i+1] = sset;
PlatoonName[i+1] = fname;
PlatoonProb[i+1] = fprb;
PlatoonAmmo[i+1] = famo;

for (j = 0; j < UnitIdx; j++)
if (UnitPlatoon[j] == i)
UnitPlatoon[j] = (i+1);
else if (UnitPlatoon[j] == (i+1))
UnitPlatoon[j] = i;
}
}
}
}

function AddPlatoon(nat,uid,name,num,max,exp,reint,reinc,side,type,platoon,ps,ammo) {

var i, count = 1;

PlatoonNat[PlatoonIdx] = nat;
PlatoonID[PlatoonIdx] = uid;
PlatoonType[PlatoonIdx] = type;
PlatoonExp[PlatoonIdx] = exp;
PlatoonCore[PlatoonIdx] = false;
PlatoonNum[PlatoonIdx] = num;
PlatoonMax[PlatoonIdx] = max;
PlatoonReinT[PlatoonIdx] = reint;
PlatoonReinC[PlatoonIdx] = reinc;
PlatoonSet[PlatoonIdx] = MODELS;
PlatoonProb[PlatoonIdx] = ps;
PlatoonAmmo[PlatoonIdx] = ammo;

for (i = 0; i < PlatoonIdx; i++) {
if ((PlatoonNat == nat) && (PlatoonName.substring(PlatoonName.indexOf(" ")+1, PlatoonName.length) == name))
count++;
}

PlatoonName[PlatoonIdx] = count + NumberPostscript(count) + " " + name;

for (i = 0; i < max; i++) {
UnitX[UnitIdx] = SelTUnitX[type][platoon];
UnitY[UnitIdx] = SelTUnitY[type][platoon];
UnitHd[UnitIdx] = DetHdg(side,UnitX[UnitIdx],UnitY[UnitIdx]);

UnitPPos[UnitIdx] = i;
UnitPlatoon[UnitIdx] = PlatoonIdx;
UnitIdx++;
}

PlatoonIdx++;
}

function enc(s) {
var i;
var rs ="";

//return(s);

for (i = 0; i < s.length; i++) {
if (s.substring(i,i+2) == "&#") {
rs += "&#";
for (i = i+2; i < s.length; i++) {
rs += s.substring(i,i+1);
if (s.substring(i,i+1) == ";")
break;
}
}
else {

if (s.charCodeAt(i) > 0)
rs += "&#"+s.charCodeAt(i)+";";
else
rs += s.substring(i,i+1);
}
}

return rs;
}

function ReturnUnitXML(pi) {
var s2 = "";
var s3 = "";
var s4 = "";
var s5 = "";

var sp;

var j;

if ((PlatoonProb[pi] == "1.0") && PlatoonCore[pi])
sp = "true";
else
sp = "false";

s2 = s2 + '<unit unitid="'+enc(PlatoonID[pi])+'" unitname="'+enc(PlatoonName[pi])+'" exp="'+enc(PlatoonExp[pi])+'" number="'+PlatoonNum[pi]+'" max="'+PlatoonMax[pi]+'" model="'+enc(PlatoonSet[pi])+'" reinforcementTurn="'+PlatoonReinT[pi]+'" reinforcementChance="'+PlatoonReinC[pi]+'" ammo="'+PlatoonAmmo[pi]+'" keyunit="'+enc(sp)+'"';


for (j = 0; j < UnitIdx; j++) {
if (UnitPlatoon[j] == pi) {
if (s3) {
s3 = s3 + ',' + Math.round(UnitX[j]);
s4 = s4 + ',' + Math.round(UnitY[j]);
s5 = s5 + ',' + Math.round(UnitHd[j]);
}
else {
s3 = s3 + ' x="'+ Math.round(UnitX[j]);
s4 = s4 + ' z="'+ Math.round(UnitY[j]);
s5 = s5 + ' heading="'+ Math.round(UnitHd[j]);
}
}
}

s3 = s3 + '"';
s4 = s4 + '"';
s5 = s5 + '"';

s2 = s2 + s3 + s4 + s5 + "></unit>\n";

return(s2);
}

function ReturnXMLStr(typ,side,points,core) {
var s1 = "";
var i;

core = Math.floor(core / BATTLE_POINTS_MULTI);
points = Math.floor(points / BATTLE_POINTS_MULTI);

s1 = s1 + '<'+typ+' side="'+enc(side)+'">\n';
s1 = s1 + '<coreunits pointsavailable="'+core+'">\n';

for (i = 0; i < PlatoonIdx; i++)
if ((PlatoonNat == side) && (PlatoonCore))
s1 = s1 + ReturnUnitXML(i);

s1 = s1 + '</coreunits>\n';
s1 = s1 + '<auxillaryunits pointsavailable="'+points+'">\n';

for (i = 0; i < PlatoonIdx; i++)
if ((PlatoonNat == side) && (!PlatoonCore))
s1 = s1 + ReturnUnitXML(i);

s1 = s1 + '</auxillaryunits>\n';
s1 = s1 + '</'+typ+'>\n';

return(s1);
}

function SaveScenario() {
var str = "";
var s = "";
var OE = 0;
var i;
var fo;
var fi;
var multi;

// * Validation Section *

// start with scenario tag

var dt, yr = YEAR;

dt = GenerateDATE(yr);

var showinmenu = "true";

if (CMDLINE)
showinmenu = "false";

str = str + '<scenario id="'+enc(ID)+'" media="'+enc(MEDIA)+'" name="'+enc(NAME)+'" date="'+dt+'" year="'+yr+'" victory="1000" models="'+enc(MODELS)+'" vpbonusturn="'+VPBONUSTURN+'" vpbonusamt="'+VPBONUSAMT+'" turnlimit="100" showinmenu="'+showinmenu+'" phases="'+BATTLE_PHASES+'" rod="'+BATTLE_ROD+'" preplanned="'+BATTLE_PREPLANNED+'" >\n';

// now add description which is not strictly in Koios xml def, but allows exporting of scenarios

var td;

td = ConvertToCR(DESC);

str = str + '<description desc="'+enc(td)+'"></description>\n';

//str = str + '<description desc="'+ConvertToCR(DESC)+'"></description>\n';

// then objectives tag

str = str + '<objectives>\n';
for (i = 0; i < ObjIdx; i++)
if (ObjNat != -1)
str = str + '<objective owner="'+enc(ObjNat)+'" points="'+ObjPts+'" x="'+ Math.round(ObjX) +'" z="'+ Math.round(ObjY) +'"></objective>\n';
str = str + '</objectives>\n';

// then minfields and setup zones

str = str + '<minefields>\n';
for (i = 0; i < MineIdx; i++)
if (MineNat != -1 && MineType != "setup")
str = str + '<minefield owner="'+enc(MineNat)+'" type="'+enc(MineType)+'" density="'+MineDens+'" min_x="'+ Math.round(MineX)+'" max_x="'+ Math.round(MineLX)+'" min_z="'+ Math.round(MineY)+'" max_z="'+ Math.round(MineLY)+'"></minefield>\n';
str = str + '</minefields>\n';

str = str + '<setups>\n';
for (i = 0; i < MineIdx; i++)
if (MineNat != -1 && MineType == "setup")
str = str + '<setup owner="'+enc(MineNat)+'" min_x="'+ Math.round(MineX)+'" max_x="'+ Math.round(MineLX)+'" min_z="'+ Math.round(MineY)+'" max_z="'+ Math.round(MineLY)+'"></setup>\n';
str = str + '</setups>\n';


// defender tag


str = str + ReturnXMLStr("defender",FORCENAME[DEFENDER], TOTAL_POINTS[DEFENDER], CORENUM_POINTS[DEFENDER]);

// attacker tag

str = str + ReturnXMLStr("attacker",FORCENAME[Math.abs(DEFENDER-1)], TOTAL_POINTS[Math.abs(DEFENDER-1)], CORENUM_POINTS[Math.abs(DEFENDER-1)]);

str = str + '</scenario>\n';

// write file

try {
if (CMDLINE)
fo = fso.CreateTextFile("Data/Scenarios/Random.xml", true);
else
fo = fso.CreateTextFile("Data/Scenarios/"+ID+".xml", true);
}
catch (err) {
PreErrorMsg("023",'File System Error\n\nUnable to Create File Name');
return;
}

// this code because "\n" not recognised as newline by fo.WriteLine!

for (i = 0; i < str.length; i++)
if (str.substring(i,i+1) == "\n")
fo.WriteLine();
//continue;
else
fo.Write(str.substring(i,i+1));

fo.close();

try {
fo = fso.CreateTextFile("Log\\RBG_ZD.txt", true);
}
catch (err) {
PreErrorMsg("023",'File System Error\n\nUnable to Create File Name');
return;
}

// this code because "\n" not recognised as newline by fo.WriteLine!

for (i = 0; i < REPORT_STR.length; i++)
if (REPORT_STR.substring(i,i+1) == "\n")
fo.WriteLine();
else
fo.Write(REPORT_STR.substring(i,i+1));

fo.close();

if (!CMDLINE) {
//HideWaitBox();
document.getElementById("oLoading_txt").innerHTML = "<font color='white' size='5' style='height:38px'>Success!</font>";
document.getElementById("oStatus_div").style.width = Math.round(433);
if (!FROMGAME)
Notice('Battle "'+ID+'" Successfully Generated.\n\nAttempts: '+(BUILDATTEMPTS+1)+'\n\nBattle Date: '+DATE,INFO_TITLE);
}
}

MOTID = 0;
MOCLR = "";
MOOBJ = "";

function RotateBorder() {

if (MOCLR == "black")
MOCLR = "white";
else
MOCLR = "black";

MOOBJ.style.border = "1px " + MOCLR + " solid";
}

function MouseOver(o) {

MOCLR = "white";
//MOCLR = "black";
MOOBJ = o;
MOTID = setInterval("RotateBorder()",333);

MOOBJ.style.border = "1px " + MOCLR + " solid";
}

function MouseOut(o) {

o.style.border = "1px #000 solid";
//o.style.border = "1px #EBEBEB solid";
clearInterval(MOTID);
}

function HideWaitBox() {
document.getElementById("oLoading_div").style.visibility = "hidden";
document.getElementById("oFORCEMIX0_menu").style.visibility = "visible";
document.getElementById("oFORCEMIX1_menu").style.visibility = "visible";
document.getElementById("oBattleSelect_menu").style.visibility = "visible";
document.getElementById("oTemplateSelect_menu").style.visibility = "visible";
CMDLINE = 0;
}

function ShowWaitBox() {
BUILDATTEMPTS = 0;
CANCEL_BUILD = 0;
//document.getElementById("oLoading_txt").innerHTML = "<font color='white' size='5' style='height:38px'>   Building </font><font color='white' size='10' weight='bold' face='Wingdings'>&#"+194+";</font>";
document.getElementById("oLoading_txt").innerHTML = "<font color='white' size='5' style='height:38px'>Building Battle ...</font>";
document.getElementById("oStatus_div").style.width = Math.round(0);
document.getElementById("oLoading_div").style.visibility = "visible";
document.getElementById("oFORCEMIX0_menu").style.visibility = "hidden";
document.getElementById("oFORCEMIX1_menu").style.visibility = "hidden";
document.getElementById("oBattleSelect_menu").style.visibility = "hidden";
document.getElementById("oTemplateSelect_menu").style.visibility = "hidden";
}

function Exit_RBG(code) {

var fo;

if (fso.FileExists("Last_RBG_"+Math.abs(code-1)))
fso.DeleteFile("Last_RBG_"+Math.abs(code-1));

try {
fo = fso.CreateTextFile("Last_RBG_"+code, true);
}
catch (err) {
PreErrorMsg("023",'File System Error\n\nUnable to Create File Name');
return;
}

fo.close();

KillProc("PzCRBg");
}

function KillProc(p) {
var colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'mshta.exe'");
var procs = new Enumerator(colProcessList);

for (; !procs.atEnd(); procs.moveNext())
try {
if (procs.item().CommandLine.match(p)) {
procs.item().Terminate();
return;
}
} catch (err) {
return;
}
}

function Cancel() {
if (Question('Do you wish to cancel the build?',INFO_TITLE) == 6)
if (CMDLINE)
Exit_RBG(0);
else
CANCEL_BUILD = 1;
}

function CmdLineBattle() {

var cmd = extractArgs(oPzCRBg.commandLine);
var i, a = "", b = "";
var o = document.getElementById("oBattleSelect_menu");
var d = new Date();

CMDLINE = 0;
FROMGAME = 0;
ID = "R" + d.getTime();

for (i = 0; i < cmd.length; i++) {
if (cmd.toLowerCase() == "b")
a = cmd[i+1];
else if (cmd.toLowerCase() == "i")
ID = cmd[i+1];
else if (cmd.toLowerCase() == "w")
WARNINGS = 0;
else if (cmd.toLowerCase() == "d1")
CMDLINE_DATE[0] = cmd[i+1];
else if (cmd.toLowerCase() == "d2")
CMDLINE_DATE[1] = cmd[i+1];
else if (cmd.toLowerCase() == "m")
H_MULTI = parseFloat(cmd[i+1]);
else if (cmd.toLowerCase() == "g")
FROMGAME = 1;
}

if (isNaN(H_MULTI))
H_MULTI = 1.0;

if (a) {
CMDLINE = 1;

PopulateBattles();

b = Load_Battle(a);

if (!b)
return false;

document.getElementById("oBattleSelect_menu").value = b;

//ID = a;

//ShowWaitBox();

//setTimeout("Build()",999);

Build();
}
else {
PopulateBattles();

if (document.getElementById("oBattleSelect_menu").length != 0)
Load_Battle(document.getElementById("oBattleSelect_menu").value);
else
PreErrorMsg("001","There are no defined Battle Plans!");

return false;
}
}

function main() {

Init();

ResetAllElements();

CmdLineBattle();
}

function ToggleText(side) {

var i, s;

if (document.getElementById("oPreset_txt"+side).style.visibility == "hidden") {
document.getElementById("oPreset_txt"+side).style.visibility = "visible";
s = "hidden";
}
else {
document.getElementById("oPreset_txt"+side).style.visibility = "hidden";
s = "visible";
}

for (i = 0; i < 6; i++) {
document.getElementById("oICON"+side+""+i).style.visibility = s;
document.getElementById("oBAR"+side+""+i).style.visibility = s;
document.getElementById("oTEXT"+side+""+i).style.visibility = s;
if ( (s == "hidden") || ((s == "visible") && (FORCELOCK[side])) )
document.getElementById("oLOCK"+side+""+i).style.visibility = s;
}
}

function ToggleMapText() {

if (document.getElementById("oMap_txt").style.visibility == "hidden") {
document.getElementById("oMap_txt").style.visibility = "visible";
document.getElementById("oMap_img").style.visibility = "hidden";
}
else {
document.getElementById("oMap_txt").style.visibility = "hidden";
document.getElementById("oMap_img").style.visibility = "visible";
}
}

function ToggleBattleText() {

if (document.getElementById("oDesc_txt").style.visibility == "hidden") {
document.getElementById("oDesc_txt").style.visibility = "visible";
document.getElementById("oBattle_img").style.visibility = "hidden";
}
else {
document.getElementById("oDesc_txt").style.visibility = "hidden";
document.getElementById("oBattle_img").style.visibility = "visible";
}
}

function ZoomPreset(event,side) {

var o = document.getElementById("oFORCEMIX"+side+"_menu");

if (event.wheelDelta >= 5) {
o.selectedIndex++;

if (o.selectedIndex < 0)
o.selectedIndex = 0;

} else if (event.wheelDelta <= -5) {
o.selectedIndex--;

if (o.selectedIndex < 0)
o.selectedIndex = o.length - 1;
}

Load_Preset(o.options[o.selectedIndex].value,side);
}

function ScrollPreset(event,side) {

var o = document.getElementById("oPreset_txt"+side);

if (event.wheelDelta >= 5)
o.scrollTop -= 30;
else if (event.wheelDelta <= -5)
o.scrollTop += 30;
}

function ZoomMap(event) {

var o = document.getElementById("oTemplateSelect_menu");

if (event.wheelDelta >= 5) {
o.selectedIndex++;

if (o.selectedIndex < 0)
o.selectedIndex = 0;

} else if (event.wheelDelta <= -5) {
o.selectedIndex--;

if (o.selectedIndex < 0)
o.selectedIndex = o.length - 1;
}

Load_Template(o.options[o.selectedIndex].value);
}

function ZoomBattle(event) {

var o = document.getElementById("oBattleSelect_menu");

if (event.wheelDelta >= 5) {
o.selectedIndex++;

if (o.selectedIndex < 0)
o.selectedIndex = 0;

} else if (event.wheelDelta <= -5) {
o.selectedIndex--;

if (o.selectedIndex < 0)
o.selectedIndex = o.length - 1;
}

Load_Battle(o.options[o.selectedIndex].value);
}

</script>
</head>
<body> <!-- onkeyup="KeyUp(event)"> -->

<!-- *** UI Element and master table *** -->
<img name="ShadowMAPimg" id="oShadowMap_img" src="Media/Level1/map.bmp" style="position:absolute; z-index:-10; top:-10000; left:-10000; border: thin dashed black; " />

<div name="LOADINGdiv" id="oLoading_div" onclick="Cancel()" style="position:absolute; left:0; top:0; z:index:10; width:632; height:702; overflow:hidden; visibility:hidden; background-image:url('Editor/build_back.png');">
<div name="LOADINGTXTdiv" id="oLoadingtxt_div" style="position:absolute; left:90; top:305; z:index:12; width:450; height:50; overflow:hidden;"><table width="100%" height="100%"><tr align="center"><td valign="center" align="center" id="oLoading_txt"></td></tr></table></div>
<div name="STATUSdiv" id="oStatus_div" style="position:absolute; left:101; top:390; z:index:12; width:433; height:35; overflow:hidden; background-image:url('Editor/gen_back.png')"></div>
</div>

<!--
<div name="LOADINGdiv" id="oLoading_div" onclick="Cancel()" style="position:absolute; left:0; top:0; z:index:10; overflow:hidden; visibility:hidden; background-image:url('Editor/build_back.png');">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="center"><td align="center" id="oLoading_txt"></td></tr></table>
</div>
-->

<div style="position:absolute; left:224; top:128; width:90; height:20; z-index:5"><table width="100%"><tr><td align="right" class="small" id="oDIR_txt0" ondblclick="SetRND(0,5,0);" onclick="SetRND(0,5,0);" onmousedown="if (event.button == 2) SetRND(0,5,1)" ></td></tr></table></div>
<div style="position:absolute; left:328; top:128; width:90; height:20; z-index:5"><table width="100%"><tr><td align="right" class="small" id="oDIR_txt1" ondblclick="SetRND(1,5,0);" onclick="SetRND(1,5,0);" onmousedown="if (event.button == 2) SetRND(1,5,1)" ></td></tr></table></div>

<!-- Main UI Elements Div-->
<div id="oUIElements_div" style="position:absolute; overflow:hidden; z:index:0">
<table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top">
<table width="100%"><tr><td>

<table width="100%">

<tr><td>

<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><img id="oRND0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="ToggleRND(0)" ondblclick="ToggleRND(0,0)" onclick="ToggleRND(0,0)" onmousedown="if (event.button == 2) ToggleRND(0)" style="border:1px #000 solid" /></td>
<td align="center"><img id="oPoints0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="if (event.wheelDelta >= 5) TogglePoints(0,1); else if (event.wheelDelta <= -5) TogglePoints(0,-1);" ondblclick="TogglePoints(0,1)" onclick="TogglePoints(0,1)" onmousedown="if (event.button == 2) TogglePoints(0,-1)" style="border:1px #000 solid"/></td>
<td align="right"><img id="oAI0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="ToggleAI(0)" ondblclick="ToggleAI(0)" onclick="ToggleAI(0)" style="border:1px #000 solid"/></td>
</tr>
</table>
</td></tr>

<tr><td>

<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><img id="oReinf0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,0,0,event)" ondblclick="SetRND(0,0,0);" onclick="SetRND(0,0,0);" onmousedown="if (event.button == 2) SetRND(0,0,1)" style="border:1px #000 solid" /></td>
<td align="center"><img id="oMF0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,1,0,event)" ondblclick="SetRND(0,1,0);" onclick="SetRND(0,1,0);" onmousedown="if (event.button == 2) SetRND(0,1,1)" style="border:1px #000 solid"/></td>
<td align="right"><img id="oEngage0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,2,0,event)" ondblclick="SetRND(0,2,0);" onclick="SetRND(0,2,0);" onmousedown="if (event.button == 2) SetRND(0,2,1)" style="border:1px #000 solid"/></td>
</tr>
</table>
</td></tr>

<tr><td>

<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><img id="oEXP0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,3,0,event)" ondblclick="SetRND(0,3,0);" onclick="SetRND(0,3,0);" onmousedown="if (event.button == 2) SetRND(0,3,1)" style="border:1px #000 solid" /></td>
<td align="center"><img id="oSTR0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,4,0,event)" ondblclick="SetRND(0,4,0);" onclick="SetRND(0,4,0);" onmousedown="if (event.button == 2) SetRND(0,4,1)" style="border:1px #000 solid"/></td>
<td align="right"><img id="oDIR0" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,5,0,event)" ondblclick="SetRND(0,5,0)" onclick="SetRND(0,5,0)" onmousedown="if (event.button == 2) { SetRND(0,5,1) }" style="border:1px #000 solid"/></td>
</tr>
</table>
</td></tr>

<tr><td style="color:darkslategray">
<a title="Click to Toggle Preset Display" style="cursor:hand" onclick="ToggleText(0)" ondblclick="ToggleText(0)"><u>Preset</u>:</a> <select title="Select Force Preset" class="small" id="oFORCEMIX0_menu" onclick="SetRND(0,9,0)" onchange="Load_Preset(this.value,0)" style="width:254; color:darkslategray"></select>
</td></tr>


<tr><td>

<div id="oGermanForce" ondblclick="ToggleText(0)" onmousewheel='if (document.getElementById("oPreset_txt0").style.visibility == "hidden") {SetRND(0,9,0);ZoomPreset(event,0);} else ScrollPreset(event,0);' onmousedown="if (event.button == 2) SetRND(0,9,1)" style="position:relative; top:0px; left:0px; width:304px; height:304px; border: 1px #000 solid;">
<img id="oBACK0" alt="" src="Editor/GBack.png" style="position:absolute; top:1px; left:1px; z-index:-3"/>
<!-- <img name="oPDice0" id="oPDice0_img" alt="" src="Editor/dice.png" style="position:absolute; top:282px; left:270px; z-index:5; visibility:hidden;" /> -->
<div name="oPDice0" id="oPDice0_img" title="" style="position:absolute; top:282px; width:32px; height:20px; left:270px; z-index:5; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Dice.png', sizingMethod='scale', enabled='true')"></div>

<textarea id="oPreset_txt0" UNSELECTABLE="on" readonly style="position:absolute; visibility:hidden; top:2px; left:2px; width:299px; height:299px; color:darkslategray; background-color:transparent; border-width:0; font-family: verdana, arial, 'sans-serif'; font-size: 8pt; font-weight: bold; cursor: default; z-index:1"></textarea>

<img id="oICON00" ondblclick="ToggleLock(0,0)" onclick="ToggleLock(0,0)" alt="Infantry Slider Unlocked" src="Editor/GInf.png" style="position:absolute; top:0px; left:0px; z-index:1"/>
<img id="oICON01" ondblclick="ToggleLock(0,1)" onclick="ToggleLock(0,1)" alt="Light Vehicle Slider Unlocked" src="Editor/GTra.png" style="position:absolute; top:50px; left:0px; z-index:1"/>
<img id="oICON02" ondblclick="ToggleLock(0,2)" onclick="ToggleLock(0,2)" alt="Artillery Slider Unlocked" src="Editor/GArt.png" style="position:absolute; top:100px; left:0px; z-index:1"/>
<img id="oICON03" ondblclick="ToggleLock(0,3)" onclick="ToggleLock(0,3)" alt="Tactical Air Slider Unlocked" src="Editor/GAir.png" style="position:absolute; top:150px; left:0px; z-index:1"/>
<img id="oICON04" ondblclick="ToggleLock(0,4)" onclick="ToggleLock(0,4)" alt="Field/Assault Gun Slider Unlocked" src="Editor/GATG.png" style="position:absolute; top:200px; left:0px; z-index:1"/>
<img id="oICON05" ondblclick="ToggleLock(0,5)" onclick="ToggleLock(0,5)" alt="Armour Slider Unlocked" src="Editor/GArm.png" style="position:absolute; top:250px; left:0px; z-index:1"/>

<div id="oBAR00" onMouseDown="setCapture();MouseArrowDown(event,0,0)" title="Infantry Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,0)" style="position:absolute; top:2px; left:0px; width:95px; height:48px; background-color: #a0a0a0; border: 1px #000 solid; z-index: -1; background-image:url('Editor/GBarBack.png'); cursor:hand"></div>
<div id="oBAR01" onMouseDown="setCapture();MouseArrowDown(event,0,1)" title="Light Vehicle Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,1)" style="position:absolute; top:52px; left:0px; width:125px; height:48px; background-color: #a0a0a0; border: 1px #000 solid; z-index: -1; background-image:url('Editor/GBarBack.png'); cursor:hand"></div>
<div id="oBAR02" onMouseDown="setCapture();MouseArrowDown(event,0,2)" title="Artillery Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,2)" style="position:absolute; top:102px; left:0px; width:195px; height:48px; background-color: #a0a0a0; border: 1px #000 solid; z-index: -1; background-image:url('Editor/GBarBack.png'); cursor:hand"></div>
<div id="oBAR03" onMouseDown="setCapture();MouseArrowDown(event,0,3)" title="Tactical Air Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,3)" style="position:absolute; top:152px; left:0px; width:95px; height:48px; background-color: #a0a0a0; border: 1px #000 solid; z-index: -1; background-image:url('Editor/GBarBack.png'); cursor:hand"></div>
<div id="oBAR04" onMouseDown="setCapture();MouseArrowDown(event,0,4)" title="Field/Assault Gun Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,4)" style="position:absolute; top:202px; left:0px; width:125px; height:48px; background-color: #a0a0a0; border: 1px #000 solid; z-index: -1; background-image:url('Editor/GBarBack.png'); cursor:hand"></div>
<div id="oBAR05" onMouseDown="setCapture();MouseArrowDown(event,0,5)" title="Armour Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,5)" style="position:absolute; top:252px; left:0px; width:195px; height:48px; background-color: #a0a0a0; border: 1px #000 solid; z-index: -1; background-image:url('Editor/GBarBack.png'); cursor:hand"></div>

<div id="oTEXT00" class="percent" onMouseDown="setCapture();MouseArrowDown(event,0,0)" title="Infantry Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,0)" style="position:absolute; top:18px; left:110px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT01" class="percent" onMouseDown="setCapture();MouseArrowDown(event,0,1)" title="Light Vehicle Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,1)" style="position:absolute; top:68px; left:140px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT02" class="percent" onMouseDown="setCapture();MouseArrowDown(event,0,2)" title="Artillery Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,2)" style="position:absolute; top:118px; left:210px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT03" class="percent" onMouseDown="setCapture();MouseArrowDown(event,0,3)" title="Tactical Air Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,3)" style="position:absolute; top:168px; left:110px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT04" class="percent" onMouseDown="setCapture();MouseArrowDown(event,0,4)" title="Field/Assault Gun Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,4)" style="position:absolute; top:218px; left:140px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT05" class="percent" onMouseDown="setCapture();MouseArrowDown(event,0,5)" title="Armour Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,0,5)" style="position:absolute; top:268px; left:210px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>

<div id="oLOCK00" ondblclick="ToggleLock(0,0)" onclick="ToggleLock(0,0)" title="Infantry Slider Locked" style="position:absolute; top:0px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK01" ondblclick="ToggleLock(0,1)" onclick="ToggleLock(0,1)" title="Light Vehicle Slider Locked" style="position:absolute; top:50px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK02" ondblclick="ToggleLock(0,2)" onclick="ToggleLock(0,2)" title="Artillery Slider Locked" style="position:absolute; top:100px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK03" ondblclick="ToggleLock(0,3)" onclick="ToggleLock(0,3)" title="Tactical Air Slider Locked" style="position:absolute; top:150px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK04" ondblclick="ToggleLock(0,4)" onclick="ToggleLock(0,4)" title="Field/Assault Gun Slider Locked" style="position:absolute; top:200px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK05" ondblclick="ToggleLock(0,5)" onclick="ToggleLock(0,5)" title="Armour Slider Locked" style="position:absolute; top:250px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
</div>

</td></tr>

<tr><td>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><a title="Select Battle" style="cursor:hand" onclick="ToggleBattleText()" ondblclick="ToggleBattleText()"><u>Battle</u>:</a> <select class="small" title="Select Battle" id="oBattleSelect_menu" onchange="Load_Battle(this.value)" style="width:256"></select></td>
</tr>
<tr>
<td align="left"><a title="Click to Toggle Template Display" style="cursor:hand" onclick="ToggleMapText()" ondblclick="ToggleMapText()" ><u>Template</u>:</a> <select class="small" title="Select Template" id="oTemplateSelect_menu" onclick="SetRND(0,8,0)" onchange="Load_Template(this.value)" style="width:235"></select></td>
</tr>
<tr>
<td align="left" id="oDate_txt"></td>
</tr>
<tr>
<td align="left"><div ondblclick="ToggleBattleText()" onmousewheel='if (document.getElementById("oDesc_txt").style.visibility == "hidden") {ZoomBattle(event);}' style="position:relative; top:0px; left:0px; width:302px; height:108px; border: 1px #000 solid">
<img name="oBattleBack" id="oBattle_img" alt="Battle" src="Editor/BattleBack0.png" style="position:absolute; top:1px; left:1px; width:300px; height:108px; z-index:0;" />
<textarea id="oDesc_txt" UNSELECTABLE="on" readonly style="position:relative; visibility:hidden; top:0px; left:0px; width:302px; height:108px; background-color:#F5F5F5; border-width:0; font-family: verdana, arial, 'sans-serif'; font-size: 8pt; cursor: default"></textarea>
</div>
</td>
</tr>
</table>

</td></tr>

</table>


</td>
<td valign="top"><table width="100%"><tr><td>

<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><img id="oAI1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="ToggleAI(1)" ondblclick="ToggleAI(1)" onclick="ToggleAI(1)" style="border:1px #000 solid"/></td>
<td align="center"><img id="oPoints1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="if (event.wheelDelta >= 5) TogglePoints(1,1); else if (event.wheelDelta <= -5) TogglePoints(1,-1);" ondblclick="TogglePoints(1,1)" onclick="TogglePoints(1,1)" onmousedown="if (event.button == 2) TogglePoints(1,-1)" style="border:1px #000 solid"/></td>
<td align="right"><img id="oRND1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="ToggleRND(1)" ondblclick="ToggleRND(1,0)" onclick="ToggleRND(1,0)" onmousedown="if (event.button == 2) ToggleRND(1)" style="border:1px #000 solid" /></td>
</tr>
</table>
</td></tr>

<tr><td>

<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><img id="oEngage1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(1,2,0,event)" ondblclick="SetRND(1,2,0);" onclick="SetRND(1,2,0);" onmousedown="if (event.button == 2) SetRND(1,2,1)" style="border:1px #000 solid"/></td>
<td align="center"><img id="oMF1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(1,1,0,event)" ondblclick="SetRND(1,1,0);" onclick="SetRND(1,1,0);" onmousedown="if (event.button == 2) SetRND(1,1,1)" style="border:1px #000 solid"/></td>
<td align="right"><img id="oReinf1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(1,0,0,event)" ondblclick="SetRND(1,0,0);" onclick="SetRND(1,0,0);" onmousedown="if (event.button == 2) SetRND(1,0,1)" style="border:1px #000 solid" /></td>
</tr>
</table>
</td></tr>

<tr><td>

<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><img id="oDIR1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(1,5,0,event)" ondblclick="SetRND(1,5,0)" onclick="SetRND(1,5,0)" onmousedown="if (event.button == 2) { SetRND(1,5,1) }" style="border:1px #000 solid"/></td>
<td align="center"><img id="oSTR1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(1,4,0,event)" ondblclick="SetRND(1,4,0);" onclick="SetRND(1,4,0);" onmousedown="if (event.button == 2) SetRND(1,4,1)" style="border:1px #000 solid"/></td>
<td align="right"><img id="oEXP1" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(1,3,0,event)" ondblclick="SetRND(1,3,0);" onclick="SetRND(1,3,0);" onmousedown="if (event.button == 2) SetRND(1,3,1)" style="border:1px #000 solid" /></td>
</tr>
</table>
</td></tr>

<tr><td style="color:darkred">
<a title="Click to Toggle Preset Display" style="cursor:hand" onclick="ToggleText(1)" ondblclick="ToggleText(1)"><u>Preset</u>:</a> <select title="Select Force Preset" class="small" id="oFORCEMIX1_menu" onclick="SetRND(1,9,0)" onchange="Load_Preset(this.value,1)" style="width:254; color:darkred"></select>
</td></tr>

<tr><td>

<div id="oRussianForce" ondblclick="ToggleText(1)" onmousewheel='if (document.getElementById("oPreset_txt1").style.visibility == "hidden") {SetRND(1,9,0);ZoomPreset(event,1);} else ScrollPreset(event,1);' onmousedown="if (event.button == 2) SetRND(1,9,1)" style="position:relative; top:0px; left:0px; width:304px; height:304px; border: 1px #000 solid;">
<img id="oBACK1" src="Editor/RBack.png" alt="" style="position:absolute; top:1px; left:1px; z-index:-3"/>
<div name="oPDice1" id="oPDice1_img" title="" style="position:absolute; top:282px; width:32px; height:20px; left:270px; z-index:5; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Dice.png', sizingMethod='scale', enabled='true')"></div>

<textarea id="oPreset_txt1" UNSELECTABLE="on" readonly style="position:absolute; visibility:hidden; top:2px; left:2px; width:299px; height:299px; color:darkred; background-color:transparent; border-width:0; font-family: verdana, arial, 'sans-serif'; font-size: 8pt; font-weight:bold; cursor: default; z-index:1"></textarea>

<img id="oICON10" ondblclick="ToggleLock(1,0)" onclick="ToggleLock(1,0)" alt="Infantry Slider Unlocked" src="Editor/RInf.png" style="position:absolute; top:0px; left:0px; z-index:1"/>
<img id="oICON11" ondblclick="ToggleLock(1,1)" onclick="ToggleLock(1,1)" alt="Light Vehicle Slider Unlocked" src="Editor/RTra.png" style="position:absolute; top:50px; left:0px; z-index:1"/>
<img id="oICON12" ondblclick="ToggleLock(1,2)" onclick="ToggleLock(1,2)" alt="Artillery Slider Unlocked" src="Editor/RArt.png" style="position:absolute; top:100px; left:0px; z-index:1"/>
<img id="oICON13" ondblclick="ToggleLock(1,3)" onclick="ToggleLock(1,3)" alt="Tactical Air Slider Unlocked" src="Editor/RAir.png" style="position:absolute; top:150px; left:0px; z-index:1"/>
<img id="oICON14" ondblclick="ToggleLock(1,4)" onclick="ToggleLock(1,4)" alt="Field/Assault Gun Slider Unlocked" src="Editor/RATG.png" style="position:absolute; top:200px; left:0px; z-index:1"/>
<img id="oICON15" ondblclick="ToggleLock(1,5)" onclick="ToggleLock(1,5)" alt="Armour Slider Unlocked" src="Editor/RArm.png" style="position:absolute; top:250px; left:0px; z-index:1"/>

<div id="oBAR10" onMouseDown="setCapture();MouseArrowDown(event,1,0)" title="Infantry Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,0)" style="position:absolute; top:2px; left:0px; width:95px; height:48px; background-color: #a00000; border: 1px #000 solid; z-index: -1; background-image:url('Editor/RBarBack.png'); cursor:hand"></div>
<div id="oBAR11" onMouseDown="setCapture();MouseArrowDown(event,1,1)" title="Light Vehicle Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,1)" style="position:absolute; top:52px; left:0px; width:125px; height:48px; background-color: #a00000; border: 1px #000 solid; z-index: -1; background-image:url('Editor/RBarBack.png'); cursor:hand"></div>
<div id="oBAR12" onMouseDown="setCapture();MouseArrowDown(event,1,2)" title="Artillery Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,2)" style="position:absolute; top:102px; left:0px; width:195px; height:48px; background-color: #a00000; border: 1px #000 solid; z-index: -1; background-image:url('Editor/RBarBack.png'); cursor:hand"></div>
<div id="oBAR13" onMouseDown="setCapture();MouseArrowDown(event,1,3)" title="Tactical Air Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,3)" style="position:absolute; top:152px; left:0px; width:95px; height:48px; background-color: #a00000; border: 1px #000 solid; z-index: -1; background-image:url('Editor/RBarBack.png'); cursor:hand"></div>
<div id="oBAR14" onMouseDown="setCapture();MouseArrowDown(event,1,4)" title="Field/Assault Gun Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,4)" style="position:absolute; top:202px; left:0px; width:125px; height:48px; background-color: #a00000; border: 1px #000 solid; z-index: -1; background-image:url('Editor/RBarBack.png'); cursor:hand"></div>
<div id="oBAR15" onMouseDown="setCapture();MouseArrowDown(event,1,5)" title="Armour Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,5)" style="position:absolute; top:252px; left:0px; width:195px; height:48px; background-color: #a00000; border: 1px #000 solid; z-index: -1; background-image:url('Editor/RBarBack.png'); cursor:hand"></div>

<div id="oTEXT10" class="percent" onMouseDown="setCapture();MouseArrowDown(event,1,0)" title="Infantry Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,0)" style="position:absolute; top:18px; left:110px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT11" class="percent" onMouseDown="setCapture();MouseArrowDown(event,1,1)" title="Light Vehicle Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,1)" style="position:absolute; top:68px; left:140px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT12" class="percent" onMouseDown="setCapture();MouseArrowDown(event,1,2)" title="Artillery Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,2)" style="position:absolute; top:118px; left:210px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT13" class="percent" onMouseDown="setCapture();MouseArrowDown(event,1,3)" title="Tactical Air Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,3)" style="position:absolute; top:168px; left:110px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT14" class="percent" onMouseDown="setCapture();MouseArrowDown(event,1,4)" title="Field/Assault Gun Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,4)" style="position:absolute; top:218px; left:140px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>
<div id="oTEXT15" class="percent" onMouseDown="setCapture();MouseArrowDown(event,1,5)" title="Armour Force Mix" onMouseUp="releaseCapture();MouseArrowUp()" onMouseMove="MouseArrowDrag(event,1,5)" style="position:absolute; top:268px; left:210px; width:25px; height:48px; z-index: -1; color: #000; cursor:hand"></div>

<div id="oLOCK10" ondblclick="ToggleLock(1,0)" onclick="ToggleLock(1,0)" title="Infantry Slider Locked" style="position:absolute; top:0px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK11" ondblclick="ToggleLock(1,1)" onclick="ToggleLock(1,1)" title="Light Vehicle Slider Locked" style="position:absolute; top:50px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK12" ondblclick="ToggleLock(1,2)" onclick="ToggleLock(1,2)" title="Artillery Slider Locked" style="position:absolute; top:100px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK13" ondblclick="ToggleLock(1,3)" onclick="ToggleLock(1,3)" title="Tactical Air Slider Locked" style="position:absolute; top:150px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK14" ondblclick="ToggleLock(1,4)" onclick="ToggleLock(1,4)" title="Field/Assault Gun Slider Locked" style="position:absolute; top:200px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
<div id="oLOCK15" ondblclick="ToggleLock(1,5)" onclick="ToggleLock(1,5)" title="Armour Slider Locked" style="position:absolute; top:250px; left:0px; visibility:hidden; z-index:3; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Locked.png', sizingMethod='scale', enabled='true'); width:88; height:50;" ></div>
</div>

</td></tr>

<tr><td>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td align="left"><div ondblclick="ToggleMapText()" onmousedown="if (event.button == 2) SetRND(0,8,1)" onmousewheel='if (document.getElementById("oMap_txt").style.visibility == "hidden") {SetRND(0,8,0);ZoomMap(event);}' style="position:relative; top:0px; left:0px; width:200px; height:174px;">
<img name="oMap" id="oMap_img" alt="Template" src="" style="position:absolute; top:0px; left:0px; width:170px; height:170px; z-index:0; border: thin dashed black" />
<div name="oDice" id="oDice_img" title="" style="position:absolute; top:152px; width:32px; height:20px; left:140px; z-index:2; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Editor/Dice.png', sizingMethod='scale', enabled='true')"></div>

<textarea id="oMap_txt" UNSELECTABLE="on" readonly style="position:absolute; visibility:hidden; top:0px; left:0px; width:198px; height:174px; color:black; background-color:#F5F5F5; border: 1px #000 solid font-family: verdana, arial, 'sans-serif'; font-size: 8pt; cursor: default; z-index:1"></textarea>
</div></td>
<td align="right">
<table width="100%" cellpadding="3" cellspacing="0">
<tr valign="top" align="right"><td><img id="oSeason" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,6,0,event)" ondblclick="SetRND(0,6,0);" onclick="SetRND(0,6,0);" onmousedown="if (event.button == 2) SetRND(0,6,1)" style="border:1px #000 solid"/></td></tr>
<tr valign="center" align="right"><td><img id="oYear" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousewheel="SetRND(0,7,0,event)" ondblclick="SetRND(0,7,0);" onclick="SetRND(0,7,0);" onmousedown="if (event.button == 2) SetRND(0,7,1)" style="border:1px #000 solid"/></td></tr>
<tr valign="bottom" align="right"><td><img id="oBuild" onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" ondblclick="ShowWaitBox();setTimeout('Build()',100)" onclick="ShowWaitBox();setTimeout('Build()',100)" style="border:1px #000 solid"/></td></tr>
</table>
</td>
</tr>
</table>

</td></tr>

</table>

</td></tr></table>

</td>
</tr>

</table>
</div>

<script type="text/JScript.Encode">
main();

var mimg = document.images.ShadowMAPimg;
mimg.onload = function (evt)
{
if (this.width != MAXMAPX)
{
MAXMAPX = this.width;
MAXMAPY = this.height;
}
}
</script>

</body>
</html>
Post #: 1
RE: Random Scenario/Campaign and others not working - 5/13/2011 3:48:28 AM   
junk2drive


Posts: 12907
Joined: 6/27/2002
From: Arizona West Coast
Status: offline
I didn't go through the post to look for problems but do you have any version of IE installed? The tools require IE6 or higher to work.

_____________________________

Conflict of Heroes "Most games are like checkers or chess and some have dice and cards involved too. This game plays like checkers but you think like chess and the dice and cards can change everything in real time."

(in reply to Outis73)
Post #: 2
RE: Random Scenario/Campaign and others not working - 5/13/2011 3:53:06 AM   
Outis73

 

Posts: 16
Joined: 12/16/2010
Status: offline
Yes, I have  IE9 installed

windows 7, 64 bit

(in reply to junk2drive)
Post #: 3
RE: Random Scenario/Campaign and others not working - 5/13/2011 3:56:23 AM   
DasTactic

 

Posts: 996
Joined: 10/10/2005
Status: offline

quote:

ORIGINAL: junk2drive

...The tools require IE6 or higher to work.


So we've gone with the stable compliant option then. Sorry - couldn't resist.

(in reply to junk2drive)
Post #: 4
RE: Random Scenario/Campaign and others not working - 5/13/2011 5:49:49 AM   
rickier65

 

Posts: 14231
Joined: 4/20/2000
Status: offline
quote:


ORIGINAL: jmcd30

I installed the game and left the .net 1.1 and 4.0 framework boxes checked as well as the directx 9 box.

The random scenario generator and campaign scenario shortcuts open notepad windows.
(They are lengthy)

Also, from the game menu none of the editors will open up except the map scene editor.

What is going on?? and how can I fix it??

.......


There is a file in the Folder you installed the game to named PzCRBg.hta. Note the .hta extension

if you can, locate the file and right click on nit. you will see the properties of the file.

towards the top of the properties box is should say: Open With: and it should show: Microsoft HTML Application Host

If it doesnt, then that's your problem. While you could probably change it there, this might indicate some other problems as I'm pretty sure that by default Windows sets the .hta extension to be opened by the HTML Application Host and I'm not sure what would have changed that.

NOTE: I do not have IE 9 installed, so I don't know what it sets this to.

Thanks
rick


< Message edited by Rick -- 5/13/2011 5:50:43 AM >

(in reply to Outis73)
Post #: 5
RE: Random Scenario/Campaign and others not working - 5/13/2011 1:50:48 PM   
Outis73

 

Posts: 16
Joined: 12/16/2010
Status: offline
THANKS!

For some reason those files were associated with notepad, so I just re-associated them with mshta and everything seems to work now.

(in reply to Outis73)
Post #: 6
RE: Random Scenario/Campaign and others not working - 5/13/2011 1:53:29 PM   
junk2drive


Posts: 12907
Joined: 6/27/2002
From: Arizona West Coast
Status: offline
Thank goodness it was a simple solution! Enjoy.

_____________________________

Conflict of Heroes "Most games are like checkers or chess and some have dice and cards involved too. This game plays like checkers but you think like chess and the dice and cards can change everything in real time."

(in reply to Outis73)
Post #: 7
RE: Random Scenario/Campaign and others not working - 5/13/2011 5:58:02 PM   
rickier65

 

Posts: 14231
Joined: 4/20/2000
Status: offline

quote:

ORIGINAL: jmcd30

THANKS!

For some reason those files were associated with notepad, so I just re-associated them with mshta and everything seems to work now.



Great! Glad that did it.

thanks
rick

(in reply to Outis73)
Post #: 8
Page:   [1]
All Forums >> [Current Games From Matrix.] >> [World War II] >> Panzer Command: Ostfront >> Tech Support >> Random Scenario/Campaign and others not working Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.688