include "Math.xs"; //include math library
//define global variables
vector result = cInvalidVector;
vector point1 = cInvalidVector;
vector point2 = cInvalidVector;
/* Because we all love maths! Equation of a circle.
* @param x: requested point on circle
* @param r: radius
* @param x0: x-coordiante centerpoint
* @param y0: y-coordinate centerpoint
* @returns:
* vector( X ) = x
* vector( Y ) = 1st result
* vector( Z ) = 2nd result
*/
vector circlePoint(float x=0.0, float r=20.0, float x0=61.0, float y0=61.0) {
return(xsVectorSet(x,
(y0+Math_sqrt(Math_pow(r,2) - Math_pow(x,2) + 2.0*x0*x - Math_pow(x0,2))),
(y0-Math_sqrt(Math_pow(r,2) - Math_pow(x,2) + 2.0*x0*x - Math_pow(x0,2)))
));
}
void generateUnits(int proto1ID=-1, int proto2ID=-1, int proto3ID=-1) {
if(proto1ID == -1 || proto2ID == -1)
return; //bad params
if(proto3ID == -1) proto3ID = proto1ID;
for(i=4; < 17) {
//outer circle has x in [20, 180] range
//generate units in [40, 160] range
int x = 10*i; //with steps of 10
result = circlePoint(x, 62, 100, 100);
point1 = xsVectorSet(x, 0 , xsVectorGetY(result));
point2 = xsVectorSet(x, 0 , xsVectorGetZ(result));
aiEcho("Circle1("+i+") = "+point1+" & "+point2);
aiUnitCreateCheat(1, proto1ID, point1);
aiUnitCreateCheat(1, proto1ID, point2);
result = circlePoint(x, 78, 100, 100);
point1 = xsVectorSet(x, 0 , xsVectorGetY(result));
point2 = xsVectorSet(x, 0 , xsVectorGetZ(result));
aiEcho("Circle2("+i+") = "+point1+" & "+point2);
aiUnitCreateCheat(2, proto2ID, point1);
aiUnitCreateCheat(2, proto2ID, point2);
result = circlePoint(x, 80, 100, 100);
point1 = xsVectorSet(x, 0 , xsVectorGetY(result));
point2 = xsVectorSet(x, 0 , xsVectorGetZ(result));
aiEcho("Circle3("+i+") = "+point1+" & "+point2);
aiUnitCreateCheat(1, proto3ID, point1);
aiUnitCreateCheat(1, proto3ID, point2);
}
}
void generateMiddle(int proto1ID=-1, int proto2ID=-1) {
if(proto1ID == -1 || proto2ID == -1)
return; //bad params
aiUnitCreateCheat(2, proto2ID, vector(100,0,100));
for(i=90; <= 110) {
result = circlePoint(i, 9, 100, 100);
point1 = xsVectorSet(i, 0 , xsVectorGetY(result));
point2 = xsVectorSet(i, 0 , xsVectorGetZ(result));
aiEcho("MiddleCircle("+i+") = "+point1+" & "+point2);
aiUnitCreateCheat(1, proto1ID, point1);
aiUnitCreateCheat(1, proto1ID, point2);
}
}
void generateTrees(int proto1ID=-1, int proto2ID=-1) { //nested for loops!
if(proto1ID == -1 || proto2ID == -1)
return; //bad params
for(i=1; <= 10) /* no curly brackets, so the tiniest piece of code that must be executed as a whole will be repeated,
* in this case that's the nested for loop, and it's whole body.
*/
for(j=1; <= 10) { //take a good look at the (i,j) coordinates in the output
if(j==10) continue; //we don't like z == 100, not sure why though
vector pos = xsVectorSet(20*i,0,20*j);
aiEcho("Generating tree on "+pos);
if((i+j)%2 == 0) //modulo! this generates a nice pattern
aiUnitCreateCheat(0, proto1ID, pos);
else
aiUnitCreateCheat(0, proto2ID, pos);
}
}
void lameExampleToUseWhile(int proto1ID=-1) { //and it's a bad function name too
if(proto1ID == -1)
return; //bad params
int counter = 0;
while(counter <= 22) {
aiUnitCreateCheat(1,proto1ID, xsVectorSet(190, 0, 10*counter)); //weird positions for a 200x200 map... :-/
aiUnitCreateCheat(1,proto1ID, xsVectorSet(50, 0, 10*counter));
aiUnitCreateCheat(1,proto1ID, xsVectorSet(10*counter, 0, 40));
aiUnitCreateCheat(1,proto1ID, xsVectorSet(10*counter, 0, 200));
counter++;
}
}
void printRandomStuff() {
aiEcho("------------------------------------------------------------ --------------------------");
for(i=0; <100) { //repeat 100 times
int random = aiRandInt(4); //get a random number
switch(random) { //switch - case - break
case 0: {aiEcho("A"); break;}
case 1: {aiEcho("B"); break;}
case 2: {aiEcho("C"); break;}
case 3: {aiEcho("D"); break;}
case 4: {aiEcho("E"); break;}
default: {aiEcho("Z");} //this shouldn't be reachable...
}
}
}
//main, this is executed first
void main() {
aiSetDefaultStance(cUnitStancePassive); //that doesn't work very well...
aiRandSetSeed(); //this has to be called if we work with random numbers
generateUnits(cUnitTypeHeroGreekPolyphemus, cUnitTypeValkyrie);
generateMiddle(cUnitTypeCentaur, cUnitTypeMountainGiant);
generateTrees(cUnitTypePine, cUnitTypePineBurning);
lameExampleToUseWhile(cUnitTypeGoldMine);
printRandomStuff();
}