public static void advImprovement(UnitList unit) { for (int i = 0; i < Form1.game.caseImps.Length; i++) { if (Form1.game.caseImps[i].pos == unit.pos) { for (int j = 0; j < Form1.game.caseImps[i].units.Length; j++) { if (Form1.game.caseImps[i].units[j] == unit) { Form1.game.caseImps[i].constructionPntLeft -= unit.moveLeft * 3 + unit.moveLeftFraction; if (Form1.game.caseImps[i].constructionPntLeft <= 0) { switch (Form1.game.caseImps[i].type) { case 0: Form1.game.grid[Form1.game.caseImps[i].pos.X, Form1.game.caseImps[i].pos.Y].roadLevel = Form1.game.caseImps[i].construction; roads.setAround(Form1.game, Form1.game.caseImps[i].pos); break; case 1: Form1.game.grid[Form1.game.caseImps[i].pos.X, Form1.game.caseImps[i].pos.Y].civicImprovement = Form1.game.caseImps[i].construction; break; case 2: Form1.game.grid[Form1.game.caseImps[i].pos.X, Form1.game.caseImps[i].pos.Y].militaryImprovement = Form1.game.caseImps[i].construction; break; } destroyCaseImps(i); } break; } } } } }
public static string getTurnLeftString(UnitList unit) { bool ok = true; int ind = 1000; for (int i = 0; i < Form1.game.caseImps.Length && ok; i++) { if (Form1.game.caseImps[i].owner == unit.player.player) { for (int j = 0; j < Form1.game.caseImps[i].units.Length; j++) { if (Form1.game.caseImps[i].units[j] == unit) { ind = i; ok = false; break; } } } } int turnsLeft = getTurnLeft(ind, false, 100, 0); string turn; if (turnsLeft > 1) { turn = " turns"; } else { turn = " turn"; } return(Convert.ToString(turnsLeft, 10) + turn); }
public static void giveCity(byte receiver, byte giver, int city) { // Form1.giveCity( receiver, giver, city ); int x = Form1.game.playerList[giver].cityList[city].X, y = Form1.game.playerList[giver].cityList[city].Y; #region move units /* if ( Form1.game.grid[ x, y ].stack.Length > 0 ) * { */ for (int u = Form1.game.grid[x, y].stack.Length - 1; u >= 0; u--) { if (Form1.game.grid[x, y].stack[u].player.player != receiver) { UnitList unitToMove = Form1.game.grid[x, y].stack[u]; System.Drawing.Point dest = unitToMove.player.capitalCity.pos; move.moveUnitFromCase(x, y, unitToMove.player.player, unitToMove.ind); move.moveUnitToCase(dest.X, dest.Y, unitToMove.player.player, unitToMove.ind); /* * System.Drawing.Point dest = Form1.game.grid[ x, y ].stack[ u ].player.capitalCity.pos; * move.moveUnitFromCase( x, y, Form1.game.grid[ x, y ].stack[ u ].player.player, Form1.game.grid[ x, y ].stack[ u ].ind ); * move.moveUnitToCase( dest.X, dest.Y, Form1.game.grid[ x, y ].stack[ u ].player.player, Form1.game.grid[ x, y ].stack[ u ].ind ); */ } } // } #endregion Form1.game.playerList[receiver].cityNumber++; if (Form1.game.playerList[receiver].cityNumber >= Form1.game.playerList[receiver].cityList.Length) { CityList[] cityListBuffer = Form1.game.playerList[receiver].cityList; Form1.game.playerList[receiver].cityList = new CityList[cityListBuffer.Length + 5]; for (int i = 0; i < cityListBuffer.Length; i++) { Form1.game.playerList[receiver].cityList[i] = cityListBuffer[i]; } } Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber] = new CityList(Form1.game.playerList[receiver], Form1.game.playerList[receiver].cityNumber); Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].buildingList = Form1.game.playerList[giver].cityList[city].buildingList; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].foodReserve = Form1.game.playerList[giver].cityList[city].foodReserve; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].laborOnField = Form1.game.playerList[giver].cityList[city].laborOnField; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].laborPos = Form1.game.playerList[giver].cityList[city].laborPos; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].name = Form1.game.playerList[giver].cityList[city].name; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].population = Form1.game.playerList[giver].cityList[city].population; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].X = Form1.game.playerList[giver].cityList[city].X; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].Y = Form1.game.playerList[giver].cityList[city].Y; Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].originalOwner = Form1.game.playerList[giver].cityList[city].originalOwner; Form1.game.playerList[giver].cityList[city].state = (byte)enums.cityState.dead; // Form1.game.grid[ x, y ].territory - 1 = receiver; Form1.game.grid[x, y].city = Form1.game.playerList[receiver].cityNumber; for (int u = Form1.game.grid[Form1.game.playerList[giver].cityList[city].X, Form1.game.playerList[giver].cityList[city].Y].stack.Length - 1; u >= 0; u--) { // to do: move unit or delete them } Form1.game.frontier.setFrontiers(); sight.setTerritorySight(receiver); // game.playerList[ owner ].cityList[ game.playerList[ owner ].cityNumber ].laborPos = new Point[ 0 ]; labor.removeAllLabor(receiver, Form1.game.playerList[receiver].cityNumber); labor.addAllLabor(receiver, Form1.game.playerList[receiver].cityNumber); Form1.game.playerList[receiver].cityList[Form1.game.playerList[receiver].cityNumber].setHasDirectAccessToRessource(); if (receiver == Form1.game.curPlayerInd) { uiWrap.choseConstruction(receiver, Form1.game.playerList[receiver].cityNumber, true); } else { ai.chooseConstruction(receiver, Form1.game.playerList[receiver].cityNumber); } }
public static string getTurnLeftString( UnitList unit ) { bool ok = true; int ind = 1000; for ( int i = 0; i < Form1.game.caseImps.Length && ok; i ++ ) if ( Form1.game.caseImps[ i ].owner == unit.player.player ) for ( int j = 0; j < Form1.game.caseImps[ i ].units.Length; j ++ ) if ( Form1.game.caseImps[ i ].units[ j ] == unit ) { ind = i; ok = false; break; } int turnsLeft = getTurnLeft( ind, false, 100, 0 ); string turn; if ( turnsLeft > 1 ) { turn = " turns"; } else { turn = " turn"; } return Convert.ToString( turnsLeft , 10 ) + turn; }
public static void advImprovement( UnitList unit ) { for ( int i = 0; i < Form1.game.caseImps.Length; i ++ ) if ( Form1.game.caseImps[ i ].pos == unit.pos ) for ( int j = 0; j < Form1.game.caseImps[ i ].units.Length; j ++ ) if ( Form1.game.caseImps[ i ].units[ j ] == unit ) { Form1.game.caseImps[ i ].constructionPntLeft -= unit.moveLeft * 3 + unit.moveLeftFraction; if ( Form1.game.caseImps[ i ].constructionPntLeft <= 0 ) { switch ( Form1.game.caseImps[ i ].type ) { case 0: Form1.game.grid[ Form1.game.caseImps[ i ].pos.X, Form1.game.caseImps[ i ].pos.Y ].roadLevel = Form1.game.caseImps[ i ].construction; roads.setAround( Form1.game, Form1.game.caseImps[ i ].pos ); break; case 1: Form1.game.grid[ Form1.game.caseImps[ i ].pos.X, Form1.game.caseImps[ i ].pos.Y ].civicImprovement = Form1.game.caseImps[ i ].construction; break; case 2: Form1.game.grid[ Form1.game.caseImps[ i ].pos.X, Form1.game.caseImps[ i ].pos.Y ].militaryImprovement = Form1.game.caseImps[ i ].construction; break; } destroyCaseImps( i ); } break; } }
public void createUnit(int x, int y, byte unitType) { if (Statistics.units[unitType].speciality != enums.speciality.builder) { int mf = count.militaryFunding(player); int un = totMilitaryUnits; //count.militaryUnits( player ); sbyte nextMFp = 0; bool mod = true; getPFT gp = new getPFT(); if (un == 0) { nextMFp = (sbyte)(3 * 100 / totalTrade + 1); } else // game.playerList[ player ].preferences.military { if (un <= mf / 3) // over yellow { nextMFp = (sbyte)(3 * 100 * (un + 1) / totalTrade + 1); } else if (un <= mf * 6 / (3 * 5)) // over red { nextMFp = (sbyte)(3 * 100 * 4 * (un + 1) / (5 * totalTrade) + 1); } else { mod = false; } } if (mod) { aiPref.setMilitary(player, nextMFp); } } unitNumber++; if (unitNumber >= unitList.Length) { UnitList[] unitListBuffer = unitList; unitList = new UnitList[unitListBuffer.Length + 10]; for (int i = 0; i < unitListBuffer.Length; i++) { unitList[i] = unitListBuffer[i]; } } unitList[unitNumber] = new UnitList(game.playerList[player], unitNumber); unitList[unitNumber].X = x; unitList[unitNumber].Y = y; unitList[unitNumber].type = unitType; unitList[unitNumber].moveLeft = (sbyte)Statistics.units[unitType].move; unitList[unitNumber].moveLeftFraction = 0; unitList[unitNumber].state = (byte)Form1.unitState.idle; unitList[unitNumber].health = 3; unitList[unitNumber].level = 1; // transport if (Statistics.units[unitType].transport > 0) { unitList[unitNumber].transport = new int[Statistics.units[unitType].transport]; unitList[unitNumber].transported = 0; } move.moveUnitToCase(x, y, player, unitNumber); sight.discoverRadius(x, y, Statistics.units[unitType].sight, player); #region special resources /* if ( game.grid[ x, y ].resources > 0 && game.grid[ x, y ].resources < 100 ) * { * if ( game.grid[ x, y ].resources == (byte)enums.speciaResources.horses ) * { * if ( !technos[ (byte)Form1.technoList.horseBreed ].researched ) * { * technos[ (byte)Form1.technoList.horseBreed ].researched = true; * * if ( Form1.game.curPlayerInd == player ) * { * DrawMap(); * MessageBox.Show( "You just discovered horses.", "Rare resources" ); * } * } * } * else if ( game.grid[ x, y ].resources == (byte)enums.speciaResources.elephant ) * { * if ( !technos[ (byte)Form1.technoList.elephantBreed ].researched ) * { * technos[ (byte)Form1.technoList.elephantBreed ].researched = true; * * if ( Form1.game.curPlayerInd == player ) * { * DrawMap(); * MessageBox.Show( "You just discovered elephants.", "Rare resources" ); * } * } * } * else if ( game.grid[ x, y ].resources == (byte)enums.speciaResources.camel ) * { * if ( !technos[ (byte)Form1.technoList.camelBreed ].researched ) * { * technos[ (byte)Form1.technoList.camelBreed ].researched = true; * * if ( Form1.game.curPlayerInd == player ) * { * DrawMap(); * MessageBox.Show( "You just discovered camels.", "Rare resources" ); * } * } * } * * game.grid[ x, y ].resources = 0; * }*/ #endregion }
public PlayerList(Game game, byte player, byte civType, string playerName, sbyte prefFood, sbyte prefProd, sbyte prefTrade, sbyte prefScience, sbyte prefHapiness, sbyte prefWealth) { #region short this.game = game; this.player = (byte)player; memory = new Memory(this, 0); curCapital = -1; for (int i = 1; i <= cityNumber; i++) { if ( cityList[i].state != (byte)enums.cityState.dead && cityList[i].isCapitale ) { curCapital = i; break; } } if (curCapital == -1) { for (int i = 1; i <= cityNumber; i++) { if (cityList[i].state != (byte)enums.cityState.dead) { capital = i; break; } } } slaves = new playerSlavery(this); govType = Statistics.governements[(byte)enums.governements.despotism]; invalidateTrade(); #endregion lastSeen = new structures.lastSeen[game.width, game.height]; this.civType = civType; this.playerName = playerName; money = 0; currentResearch = 0; unitList = new UnitList[10]; cityList = new CityList[5]; foreignRelation = new structures.sForeignRelation[game.playerList.Length]; for (int i = 0; i < game.playerList.Length; i++) { foreignRelation[i].quality = 100; foreignRelation[i].spies = new xycv_ppc.structures.sSpies[4]; for (int j = 0; j < 4; j++) { foreignRelation[i].spies[j] = new xycv_ppc.structures.sSpies(); foreignRelation[i].spies[j].nbr = 0; } } technos = new xycv_ppc.structures.technoList[Statistics.technologies.Length]; unitNumber = 0; cityNumber = 0; technos[0].pntDiscovered = 0; preferences.laborFood = prefFood; preferences.laborProd = prefProd; preferences.laborTrade = prefTrade; preferences.science = prefScience; preferences.reserve = prefWealth; discovered = new bool[game.width, game.height]; see = new bool[game.width, game.height]; // p.unitList = new UnitList[ 50 ]; // p.foreignRelation = new structures.sForeignRelation[ game.playerList.Length ]; setResourcesAccess(); // p.memory = new Memory( this, 0 ); smallWonderList = new WonderList(Statistics.smallWonders.Length); }
public void createUnit( int x, int y, byte unitType ) { if ( Statistics.units[ unitType ].speciality != enums.speciality.builder ) { int mf = count.militaryFunding( player ); int un = totMilitaryUnits; //count.militaryUnits( player ); sbyte nextMFp = 0; bool mod = true; getPFT gp = new getPFT(); if ( un == 0 ) { nextMFp = (sbyte)( 3 * 100 / totalTrade + 1 ); } else // game.playerList[ player ].preferences.military { if ( un <= mf / 3 ) // over yellow nextMFp = (sbyte)( 3 * 100 * ( un + 1 ) / totalTrade + 1 ); else if ( un <= mf * 6 / ( 3 * 5 ) ) // over red nextMFp = (sbyte)( 3 * 100 * 4 * ( un + 1 ) / ( 5 * totalTrade ) + 1 ); else mod = false; } if ( mod ) aiPref.setMilitary( player, nextMFp ); } unitNumber ++; if ( unitNumber >= unitList.Length ) { UnitList[] unitListBuffer = unitList; unitList = new UnitList[ unitListBuffer.Length + 10 ]; for ( int i = 0; i < unitListBuffer.Length; i ++ ) unitList[ i ] = unitListBuffer[ i ]; } unitList[ unitNumber ] = new UnitList( game.playerList[ player ], unitNumber ); unitList[ unitNumber ].X = x; unitList[ unitNumber ].Y = y; unitList[ unitNumber ].type = unitType; unitList[ unitNumber ].moveLeft = (sbyte)Statistics.units[ unitType].move; unitList[ unitNumber ].moveLeftFraction = 0; unitList[ unitNumber ].state = (byte)Form1.unitState.idle; unitList[ unitNumber ].health = 3; unitList[ unitNumber ].level = 1; // transport if ( Statistics.units[ unitType ].transport > 0 ) { unitList[ unitNumber ].transport = new int[ Statistics.units[ unitType ].transport ]; unitList[ unitNumber ].transported = 0; } move.moveUnitToCase( x, y, player, unitNumber ); sight.discoverRadius( x, y, Statistics.units[ unitType ].sight, player ); #region special resources /* if ( game.grid[ x, y ].resources > 0 && game.grid[ x, y ].resources < 100 ) { if ( game.grid[ x, y ].resources == (byte)enums.speciaResources.horses ) { if ( !technos[ (byte)Form1.technoList.horseBreed ].researched ) { technos[ (byte)Form1.technoList.horseBreed ].researched = true; if ( Form1.game.curPlayerInd == player ) { DrawMap(); MessageBox.Show( "You just discovered horses.", "Rare resources" ); } } } else if ( game.grid[ x, y ].resources == (byte)enums.speciaResources.elephant ) { if ( !technos[ (byte)Form1.technoList.elephantBreed ].researched ) { technos[ (byte)Form1.technoList.elephantBreed ].researched = true; if ( Form1.game.curPlayerInd == player ) { DrawMap(); MessageBox.Show( "You just discovered elephants.", "Rare resources" ); } } } else if ( game.grid[ x, y ].resources == (byte)enums.speciaResources.camel ) { if ( !technos[ (byte)Form1.technoList.camelBreed ].researched ) { technos[ (byte)Form1.technoList.camelBreed ].researched = true; if ( Form1.game.curPlayerInd == player ) { DrawMap(); MessageBox.Show( "You just discovered camels.", "Rare resources" ); } } } game.grid[ x, y ].resources = 0; }*/ #endregion }
public PlayerList( Game game, byte player, byte civType, string playerName, sbyte prefFood, sbyte prefProd, sbyte prefTrade, sbyte prefScience, sbyte prefHapiness, sbyte prefWealth ) { #region short this.game = game; this.player = (byte)player; memory = new Memory( this, 0 ); curCapital = -1; for ( int i = 1; i <= cityNumber; i ++ ) if ( cityList[ i ].state != (byte)enums.cityState.dead && cityList[ i ].isCapitale ) { curCapital = i; break; } if ( curCapital == -1 ) for ( int i = 1; i <= cityNumber; i ++ ) if ( cityList[ i ].state != (byte)enums.cityState.dead ) { capital = i; break; } slaves = new playerSlavery( this ); govType = Statistics.governements[ (byte)enums.governements.despotism ]; invalidateTrade(); #endregion lastSeen = new structures.lastSeen[ game.width, game.height ]; this.civType = civType; this.playerName = playerName; money = 0; currentResearch = 0; unitList = new UnitList[ 10 ]; cityList = new CityList[ 5 ]; foreignRelation = new structures.sForeignRelation[ game.playerList.Length ]; for ( int i = 0; i < game.playerList.Length; i ++ ) { foreignRelation[ i ].quality = 100; foreignRelation[ i ].spies = new xycv_ppc.structures.sSpies[ 4 ]; for ( int j = 0; j < 4; j ++ ) { foreignRelation[ i ].spies[ j ] = new xycv_ppc.structures.sSpies(); foreignRelation[ i ].spies[ j ].nbr = 0; } } technos = new xycv_ppc.structures.technoList[ Statistics.technologies.Length ]; unitNumber = 0; cityNumber = 0; technos[ 0 ].pntDiscovered = 0; preferences.laborFood = prefFood; preferences.laborProd = prefProd; preferences.laborTrade = prefTrade; preferences.science = prefScience; preferences.reserve = prefWealth; discovered = new bool[ game.width, game.height ]; see = new bool[ game.width, game.height ]; // p.unitList = new UnitList[ 50 ]; // p.foreignRelation = new structures.sForeignRelation[ game.playerList.Length ]; setResourcesAccess(); // p.memory = new Memory( this, 0 ); smallWonderList = new WonderList( Statistics.smallWonders.Length ); }