PageRenderTime 48ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/solar27/include/game/classes/empire.php

https://bitbucket.org/sebs/mosolar
PHP | 674 lines | 432 code | 180 blank | 62 comment | 99 complexity | 4bb08a9f84e9146affa911306c3a31b1 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-2.0
  1. <?php
  2. // Solar Imperium is licensed under GPL2, Check LICENSE.TXT for mode details //
  3. class Empire
  4. {
  5. var $DB;
  6. var $TEMPLATE;
  7. var $data;
  8. var $data_footprint;
  9. var $gameplay_costs;
  10. var $army;
  11. var $planets;
  12. var $coalition;
  13. var $production;
  14. var $supply;
  15. var $diplomacy;
  16. var $research;
  17. var $game_id;
  18. /////////////////////////////////////////////////////////////
  19. //
  20. /////////////////////////////////////////////////////////////
  21. function Empire($DB,$TEMPLATE,$gameplay_costs)
  22. {
  23. $this->DB = $DB;
  24. $this->game_id = round($_SESSION["game"]);
  25. $this->TEMPLATE = $TEMPLATE;
  26. $this->gameplay_costs = $gameplay_costs;
  27. $this->army = new Army($DB,$TEMPLATE);
  28. $this->planets = new Planets($DB,$TEMPLATE);
  29. $this->coalition = new Coalition($DB);
  30. $this->production = new Production($DB,$TEMPLATE);
  31. $this->supply = new Supply($DB,$TEMPLATE);
  32. $this->diplomacy = new Diplomacy($DB);
  33. $this->research = new Research($DB,$TEMPLATE);
  34. }
  35. /////////////////////////////////////////////////////////////
  36. //
  37. /////////////////////////////////////////////////////////////
  38. function load($id)
  39. {
  40. $query = "SELECT * FROM game".$this->game_id."_tb_empire WHERE id='".intval($id)."'";
  41. $this->data = $this->DB->Execute($query);
  42. if (!$this->data) trigger_error($query ." = ".$this->DB->ErrorMsg());
  43. if ($this->data->EOF) return array("code"=>false,"desc"=>T_("Fatal error while loading empire object"));
  44. $this->data = $this->data->fields;
  45. $this->data_footprint = md5(serialize($this->data));
  46. if (!$this->army->load($id)) return array("code"=>false,"desc"=>T_("Fatal error while loading army object"));
  47. if (!$this->planets->load($id)) return array("code"=>false,"desc"=>T_("Fatal error while loading planets object"));
  48. if (!$this->coalition->load($id)) return array("code"=>false,"desc"=>T_("Fatal error while loading coalition object"));
  49. if (!$this->production->load($id)) return array("code"=>false,"desc"=>T_("Fatal error while loading petroleum object"));
  50. if (!$this->supply->load($id)) return array("code"=>false,"desc"=>T_("Fatal error while loading supply object"));
  51. if (!$this->diplomacy->load($id)) return array("code"=>false,"desc"=>T_("Fatal error while loading diplomacy object"));
  52. if (!$this->research->load($id)) return array("code"=>false,"desc"=>T_("Fatal error while loading research object"));
  53. return array("code"=>true,"desc"=>null);
  54. }
  55. /////////////////////////////////////////////////////////////
  56. // save, but only if data have changed !
  57. /////////////////////////////////////////////////////////////
  58. function save()
  59. {
  60. $query = "UPDATE game".$this->game_id."_tb_empire SET ";
  61. reset($this->data);
  62. while (list($key,$value) = each($this->data))
  63. {
  64. if ($key == "id") continue;
  65. if (is_numeric($key)) continue;
  66. if ((is_numeric($value)) && ($key != "logo"))
  67. $query .= "$key=$value,";
  68. else
  69. $query .= "$key='".addslashes($value)."',";
  70. }
  71. $query = substr($query,0,strlen($query)-1); // removing remaining ,
  72. $query .= " WHERE id='".$this->data["id"]."'";
  73. // $this->DB->beginTrans();
  74. if (!$this->DB->Execute($query)) trigger_error($this->DB->ErrorMsg());
  75. $this->army->save();
  76. $this->planets->save();
  77. $this->coalition->save();
  78. $this->production->save();
  79. $this->supply->save();
  80. // $this->DB->completeTrans();
  81. }
  82. /////////////////////////////////////////////////////////////
  83. //
  84. /////////////////////////////////////////////////////////////
  85. function collapse()
  86. {
  87. global $NEWS_DATA;
  88. $this->data["active"] = 2;
  89. $this->data["population"] = 0;
  90. $evt = new EventCreator($this->DB);
  91. $evt->type = CONF_EVENT_COLLAPSEDEMPIRE;
  92. $evt->from = -1;
  93. $empire_data = $this->data;
  94. $evt->params = array("empire_emperor"=>$this->data["emperor"],"empire_name"=>$this->data["name"],"gender"=>$this->data["gender"]);
  95. $evt->broadcast();
  96. // notice player
  97. $message = T_("Sorry but your empire have collapsed in game")." <b>".CONF_GAME_NAME."</b> <br/>";
  98. if (!$this->DB->Execute("INSERT INTO system_tb_messages (player_id,date,message) VALUES(".$this->data["player_id"].",".time(NULL).",'".addslashes($message)."')")) trigger_error($this->DB->ErrorMsg());
  99. $this->coalition->transferRandomOwnership(-1);
  100. // update history
  101. $military_might = $this->data["networth"]-($this->data["population"] * CONF_NETWORTH_POPULATION) - ($this->planets->getCount() * CONF_NETWORTH_PLANETS);
  102. $this->DB->Execute(
  103. "INSERT INTO system_tb_history (game_id,player_id,date,rank,empire_name,networth,military_might,planets,
  104. population,turns_played)
  105. VALUES(".$_SESSION["game"].",".$this->data["player_id"].",".time(NULL).",0,'".$this->data["name"]."',
  106. ".$this->data["networth"].",
  107. ".$military_might.",
  108. ".$this->planets->getCount().",
  109. ".$this->data["population"].",
  110. ".$this->data["turns_played"]."
  111. )");
  112. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_armyconvoy WHERE empire_from='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  113. }
  114. /////////////////////////////////////////////////////////////
  115. //
  116. /////////////////////////////////////////////////////////////
  117. function delete()
  118. {
  119. if (!$this->DB->Execute("UPDATE game".$this->game_id."_tb_empire SET active='3' WHERE id='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  120. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_army WHERE empire='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  121. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_event WHERE event_from='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  122. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_event WHERE event_to='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  123. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_loan WHERE empire='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  124. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_planets WHERE empire='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  125. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_production WHERE empire='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  126. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_stats WHERE empire='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  127. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_supply WHERE empire='".$this->data["id"]."'"))trigger_error($this->DB->ErrorMsg());
  128. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_tradeconvoy WHERE empire_from='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  129. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_tradeconvoy WHERE empire_to='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  130. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_armyconvoy WHERE empire_from='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  131. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_treaty WHERE empire_from='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  132. if (!$this->DB->Execute("DELETE FROM game".$this->game_id."_tb_treaty WHERE empire_to='".$this->data["id"]."'")) trigger_error($this->DB->ErrorMsg());
  133. // Time to give coalition to a different member, if not exist, just simply delete
  134. // and send a event.
  135. if ($this->coalition->isMember())
  136. if ($this->coalition->isOwner())
  137. $this->coalition->disband();
  138. }
  139. /////////////////////////////////////////////////////////////
  140. //
  141. /////////////////////////////////////////////////////////////
  142. function checkForEnoughFood()
  143. {
  144. global $CONF_CIVIL_STATUS;
  145. if ($this->data["active"] != 1) return "";
  146. if ($this->data["food"] >= 0) return "";
  147. $msg = "<table width=\"100%\"><tr><td><img src=\"../images/game/starving.gif\" style=\"border:0px solid yellow\"></td><td align=\"center\" width=\"100%\">&nbsp;<b style=\"color:yellow\">".T_("Your population is starving!")."</b><br/>";
  148. // First we evaluate how much food is needed
  149. $food_needed = abs($this->data["food"]);
  150. // we get the market supply
  151. $market = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_market");
  152. if (!$market) trigger_error($this->DB->ErrorMsg());
  153. $market = $market->fields;
  154. // Now we check if the food market have what we need
  155. if ($market["food"] >= $food_needed)
  156. {
  157. $food_price = round((CONF_COST_FOOD * $market["food_ratio"]));
  158. $food_total_cost = $food_needed * $food_price;
  159. // then we check for credits
  160. if ($this->data["credits"] >= $food_total_cost)
  161. {
  162. $msg_food = T_("Bought food: {food} for {credits}");
  163. $this->DB->Execute("UPDATE game".$this->game_id."_tb_market SET food='".($market["food"] - $food_needed)."',food_buy='".($market["food_buy"] + $food_needed)."'");
  164. $msg_food = str_replace("{food}",
  165. $this->TEMPLATE->formatFood($food_needed),
  166. $msg_food
  167. );
  168. $msg_food = str_replace("{credits}",
  169. $this->TEMPLATE->formatCredits($food_total_cost),
  170. $msg_food
  171. );
  172. $msg .= $msg_food;
  173. $this->data["credits"] -= $food_total_cost;
  174. $this->data["food"] = 0;
  175. $msg .= "</td></tr></table>";
  176. return $msg;
  177. }
  178. }
  179. $pop_lost = round(($this->data["population"]/100
  180. *CONF_POPULATION_STARVING));
  181. $msg_death = T_("{population} civilians starved to death!");
  182. $msg_death = str_replace("{percent}",CONF_POPULATION_STARVING,$msg_death);
  183. $msg_death = str_replace("{population}",
  184. $this->TEMPLATE->formatNumber($pop_lost),$msg_death);
  185. $msg .= $msg_death;
  186. $this->data["population"] -= $pop_lost;
  187. $soldiers_lost = round(($this->army->data["soldiers"]/100)
  188. *CONF_SOLDIERS_STARVING);
  189. $msg_death = T_("{soldiers} soldiers starved to death!");
  190. $msg_death = str_replace("{percent}",CONF_SOLDIERS_STARVING,$msg_death);
  191. $msg_death = str_replace("{soldiers}",
  192. $this->TEMPLATE->formatNumber($soldiers_lost),$msg_death);
  193. $msg .= $msg_death;
  194. $this->army->data["soldiers"] -= $soldiers_lost;
  195. $this->data["civil_status"]++;
  196. if ($this->data["civil_status"] > 7)
  197. $this->data["civil_status"] = 7;
  198. $msg .= str_replace("{civil}",
  199. $CONF_CIVIL_STATUS[$this->data["civil_status"]],
  200. T_("Population is angry! New civil status: {civil}"))."<br/>\r\n";
  201. $this->data["food"] = 0;
  202. $msg .= "</td></tr></table>";
  203. return $msg;
  204. }
  205. /////////////////////////////////////////////////////////////
  206. //
  207. /////////////////////////////////////////////////////////////
  208. function checkForEnoughCredits()
  209. {
  210. if ($this->data["active"] != 1) return "";
  211. global $CONF_CIVIL_STATUS;
  212. if ($this->data["credits"] >= 0) return "";
  213. srand(time(NULL));
  214. $msg = "<table width=\"100%\"><tr><td><img src=\"../images/game/bankrupt.gif\" style=\"border:0px solid yellow\"></td><td valign=\"top\" align=\"center\" width=\"100%\">&nbsp;<b style=\"color:yellow\">".T_("Cannot afford maintenance costs!")."<br/>\r\n";
  215. $msg .= str_replace("{percent}",CONF_BANKRUPT_PLANETS,T_("{percent}% planets released!"))."<br/>\r\n";
  216. $this->planets->data["food_planets"] -= ceil(($this->planets->data["food_planets"]/100)*CONF_BANKRUPT_PLANETS);
  217. $this->planets->data["ore_planets"] -= ceil(($this->planets->data["ore_planets"]/100)*CONF_BANKRUPT_PLANETS);
  218. $this->planets->data["tourism_planets"] -= ceil(($this->planets->data["tourism_planets"]/100)*CONF_BANKRUPT_PLANETS);
  219. $this->planets->data["supply_planets"] -= ceil(($this->planets->data["supply_planets"]/100)*CONF_BANKRUPT_PLANETS);
  220. $this->planets->data["gov_planets"] -= ceil(($this->planets->data["gov_planets"]/100)*CONF_BANKRUPT_PLANETS);
  221. $this->planets->data["edu_planets"] -= ceil(($this->planets->data["edu_planets"]/100)*CONF_BANKRUPT_PLANETS);
  222. $this->planets->data["research_planets"] -= ceil(($this->planets->data["research_planets"]/100)*CONF_BANKRUPT_PLANETS);
  223. $this->planets->data["urban_planets"] -= ceil(($this->planets->data["urban_planets"]/100)*CONF_BANKRUPT_PLANETS);
  224. $this->planets->data["petro_planets"] -= ceil(($this->planets->data["petro_planets"]/100)*CONF_BANKRUPT_PLANETS);
  225. $this->planets->data["antipollu_planets"] -= ceil(($this->planets->data["antipollu_planets"]/100)*CONF_BANKRUPT_PLANETS);
  226. $msg .= str_replace("{percent}",CONF_BANKRUPT_MILITARY,T_("{percent}% army disbanded!"))."<br/>\r\n";
  227. $this->army->data["soldiers"] -= ceil(($this->army->data["soldiers"]/100) * CONF_BANKRUPT_MILITARY);
  228. $this->army->data["fighters"] -= ceil(($this->army->data["fighters"]/100) * CONF_BANKRUPT_MILITARY);
  229. $this->army->data["stations"] -= ceil(($this->army->data["stations"]/100) * CONF_BANKRUPT_MILITARY);
  230. $this->army->data["lightcruisers"] -= ceil(($this->army->data["lightcruisers"]/100) * CONF_BANKRUPT_MILITARY);
  231. $this->army->data["heavycruisers"] -= ceil(($this->army->data["heavycruisers"]/100) * CONF_BANKRUPT_MILITARY);
  232. $this->army->data["carriers"] -= ceil(($this->army->data["carriers"]/100) * CONF_BANKRUPT_MILITARY);
  233. if (rand(0,5) == 0)
  234. {
  235. $this->army->data["effectiveness"] -= 5;
  236. if ($this->army->data["effectiveness"] < 10) $this->army->data["effectiveness"] = 10;
  237. $msg .= str_replace("{percent}",$this->army->data["effectiveness"],T_("Army effectiveness going down!"))."<br/>\r\n";
  238. }
  239. if (rand(0,5) == 0)
  240. {
  241. $this->data["civil_status"]++;
  242. if ($this->data["civil_status"] > 7) $this->data["civil_status"] = 7;
  243. $msg .= str_replace("{civil}",
  244. $CONF_CIVIL_STATUS[$this->data["civil_status"]],
  245. T_("Population is angry! New civil status: {civil}"))."<br/>\r\n";
  246. }
  247. $this->data["credits"] = 0;
  248. $msg .="</td></tr></table>";
  249. return $msg;
  250. }
  251. /////////////////////////////////////////////////////////////
  252. //
  253. /////////////////////////////////////////////////////////////
  254. function checkForEnoughOre()
  255. {
  256. if ($this->data["active"] != 1) return "";
  257. global $CONF_CIVIL_STATUS;
  258. if ($this->data["ore"] >= 0) return "";
  259. srand(time(NULL));
  260. $msg = "<table width=\"100%\"><tr><td><img src=\"../images/game/no_ore.jpg\" style=\"border:0px solid yellow\"></td><td valign=\"top\" align=\"center\" width=\"100%\">&nbsp;<b style=\"color:yellow\">".T_("No enough ore!")."<br/>\r\n";
  261. // First we evaluate how much ore is needed
  262. $ore_needed = abs($this->data["ore"]);
  263. // we get the market supply
  264. $market = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_market");
  265. if (!$market) trigger_error($this->DB->ErrorMsg());
  266. $market = $market->fields;
  267. // Now we check if the market have what we need
  268. if ($market["ore"] >= $ore_needed)
  269. {
  270. $ore_price = round((CONF_COST_ORE * $market["ore_ratio"]));
  271. $ore_total_cost = $ore_needed * $ore_price;
  272. // then we check for credits
  273. if ($this->data["credits"] >= $ore_total_cost)
  274. {
  275. $msg_ore = T_("bought ore: {ore} for {credits}");
  276. $this->DB->Execute("UPDATE game".$this->game_id."_tb_market SET ore=".($market["ore"] - $ore_needed).",ore_buy=".($market["ore_buy"] + $ore_needed));
  277. $msg_ore = str_replace("{ore}",
  278. $this->TEMPLATE->formatFood($ore_needed),
  279. $msg_ore
  280. );
  281. $msg_ore = str_replace("{credits}",
  282. $this->TEMPLATE->formatCredits($ore_total_cost),
  283. $msg_ore
  284. );
  285. $msg .= $msg_ore;
  286. $this->data["credits"] -= $ore_total_cost;
  287. $this->data["ore"] = 0;
  288. $msg .= "</td></tr></table>";
  289. return $msg;
  290. }
  291. }
  292. $msg .= str_replace("{percent}",CONF_BANKRUPT_MILITARY,T_("Army disbanded!"))."<br/>\r\n";
  293. $this->army->data["fighters"] -= ceil(($this->army->data["fighters"]/100) * CONF_BANKRUPT_MILITARY);
  294. $this->army->data["lightcruisers"] -= ceil(($this->army->data["lightcruisers"]/100) * CONF_BANKRUPT_MILITARY);
  295. $this->army->data["heavycruisers"] -= ceil(($this->army->data["heavycruisers"]/100) * CONF_BANKRUPT_MILITARY);
  296. $this->army->data["carriers"] -= ceil(($this->army->data["carriers"]/100) * CONF_BANKRUPT_MILITARY);
  297. if (rand(0,5) == 0)
  298. {
  299. $this->army->data["effectiveness"] -= 5;
  300. if ($this->army->data["effectiveness"] < 10) $this->army->data["effectiveness"] = 10;
  301. $msg .= str_replace("{percent}",$this->army->data["effectiveness"],T_("Army effectiveness going down!"))."<br/>\r\n";
  302. }
  303. if (rand(0,5) == 0)
  304. {
  305. $this->data["civil_status"]++;
  306. if ($this->data["civil_status"] > 7) $this->data["civil_status"] = 7;
  307. $msg .= str_replace("{civil}",
  308. $CONF_CIVIL_STATUS[$this->data["civil_status"]],
  309. T_("Population is angry! New civil status: {civil}"))."<br/>\r\n";
  310. }
  311. $this->data["ore"] = 0;
  312. $msg .="</td></tr></table>";
  313. return $msg;
  314. }
  315. /////////////////////////////////////////////////////////////
  316. //
  317. /////////////////////////////////////////////////////////////
  318. function checkForEnoughPetroleum()
  319. {
  320. if ($this->data["active"] != 1) return "";
  321. global $CONF_CIVIL_STATUS;
  322. if ($this->data["petroleum"] >= 0) return "";
  323. srand(time(NULL));
  324. $msg = "<table width=\"100%\"><tr><td><img src=\"../images/game/no_petro.jpg\" style=\"border:0px solid yellow\"></td><td valign=\"top\" align=\"center\" width=\"100%\">&nbsp;<b style=\"color:yellow\">".T_("No enough petroleum!")."<br/>\r\n";
  325. // First we evaluate how much petroleum is needed
  326. $petroleum_needed = abs($this->data["petroleum"]);
  327. // we get the market supply
  328. $market = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_market");
  329. if (!$market) trigger_error($this->DB->ErrorMsg());
  330. $market = $market->fields;
  331. // Now we check if the market have what we need
  332. if ($market["petroleum"] >= $petroleum_needed)
  333. {
  334. $petroleum_price = round((CONF_COST_PETROLEUM * $market["petroleum_ratio"]));
  335. $petroleum_total_cost = $petroleum_needed * $petroleum_price;
  336. // then we check for credits
  337. if ($this->data["credits"] >= $petroleum_total_cost)
  338. {
  339. $msg_petroleum = T_("Bought petroleum: {petroleum} for {credits}");
  340. $this->DB->Execute("UPDATE game".$this->game_id."_tb_market SET petroleum=".($market["petroleum"] - $petroleum_needed).",petroleum_buy=".($market["petroleum_buy"] + $petroleum_needed));
  341. $msg_petroleum = str_replace("{petroleum}",
  342. $this->TEMPLATE->formatFood($petroleum_needed),
  343. $msg_petroleum
  344. );
  345. $msg_petroleum = str_replace("{credits}",
  346. $this->TEMPLATE->formatCredits($petroleum_total_cost),
  347. $msg_petroleum
  348. );
  349. $msg .= $msg_petroleum;
  350. $this->data["credits"] -= $petroleum_total_cost;
  351. $this->data["petroleum"] = 0;
  352. $msg .= "</td></tr></table>";
  353. return $msg;
  354. }
  355. }
  356. $msg .= str_replace("{percent}",CONF_BANKRUPT_MILITARY,T_("{percent}% army disbanded!"))."<br/>\r\n";
  357. $this->army->data["fighters"] -= ceil(($this->army->data["fighters"]/100) * CONF_BANKRUPT_MILITARY);
  358. $this->army->data["stations"] -= ceil(($this->army->data["stations"]/100) * CONF_BANKRUPT_MILITARY);
  359. $this->army->data["lightcruisers"] -= ceil(($this->army->data["lightcruisers"]/100) * CONF_BANKRUPT_MILITARY);
  360. $this->army->data["heavycruisers"] -= ceil(($this->army->data["heavycruisers"]/100) * CONF_BANKRUPT_MILITARY);
  361. $this->army->data["carriers"] -= ceil(($this->army->data["carriers"]/100) * CONF_BANKRUPT_MILITARY);
  362. if (rand(0,5) == 0)
  363. {
  364. $this->army->data["effectiveness"] -= 5;
  365. if ($this->army->data["effectiveness"] < 10) $this->army->data["effectiveness"] = 10;
  366. $msg .= str_replace("{percent}",$this->army->data["effectiveness"],T_("{percent}% rmy effectiveness going down!"))."<br/>\r\n";
  367. }
  368. if (rand(0,5) == 0)
  369. {
  370. $this->data["civil_status"]++;
  371. if ($this->data["civil_status"] > 7) $this->data["civil_status"] = 7;
  372. $msg .= str_replace("{civil}",
  373. $CONF_CIVIL_STATUS[$this->data["civil_status"]],
  374. T_("Population is angry! New civil status: {civil}"))."<br/>\r\n";
  375. }
  376. $this->data["petroleum"] = 0;
  377. $msg .="</td></tr></table>";
  378. return $msg;
  379. }
  380. /////////////////////////////////////////////////////////////
  381. //
  382. /////////////////////////////////////////////////////////////
  383. function checkForEnoughPopulation()
  384. {
  385. // you are dead, jim
  386. if (($this->data["population"] < 10) || ($this->planets->getCount() == 0))
  387. return false;
  388. return true;
  389. }
  390. /////////////////////////////////////////////////////////
  391. //
  392. /////////////////////////////////////////////////////////
  393. function updateNetworth()
  394. {
  395. $networth = 0;
  396. $networth += ($this->data["population"] * CONF_NETWORTH_POPULATION);
  397. $networth += ($this->data["credits"] * CONF_NETWORTH_CREDITS);
  398. $planets = 0;
  399. $planets += $this->planets->data["food_planets"];
  400. $planets += $this->planets->data["ore_planets"];
  401. $planets += $this->planets->data["tourism_planets"];
  402. $planets += $this->planets->data["supply_planets"];
  403. $planets += $this->planets->data["gov_planets"];
  404. $planets += $this->planets->data["edu_planets"];
  405. $planets += $this->planets->data["research_planets"];
  406. $planets += $this->planets->data["urban_planets"];
  407. $planets += $this->planets->data["petro_planets"];
  408. $planets += $this->planets->data["antipollu_planets"];
  409. $networth += ($planets * CONF_NETWORTH_PLANETS);
  410. $army = 0;
  411. $army += $this->army->data["soldiers"] * CONF_NETWORTH_MILITARY_SOLDIER;
  412. $army += $this->army->data["fighters"]* CONF_NETWORTH_MILITARY_FIGHTER;
  413. $army += $this->army->data["stations"]* CONF_NETWORTH_MILITARY_STATION;
  414. $army += $this->army->data["lightcruisers"]* CONF_NETWORTH_MILITARY_LIGHTCRUISER;
  415. $army += $this->army->data["heavycruisers"]* CONF_NETWORTH_MILITARY_HEAVYCRUISER;
  416. $army += $this->army->data["carriers"]* CONF_NETWORTH_MILITARY_CARRIER;
  417. $army += $this->army->data["covertagents"]* CONF_NETWORTH_MILITARY_COVERT;
  418. $rs = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_armyconvoy WHERE empire_from=".$this->data["id"]." OR empire_to=".$this->data["id"]);
  419. if (!$rs) trigger_error($DB->ErrorMsg());
  420. while (!$rs->EOF) {
  421. $army += $rs->fields["convoy_soldiers"] * CONF_NETWORTH_MILITARY_SOLDIER;
  422. $army += $rs->fields["convoy_fighters"]* CONF_NETWORTH_MILITARY_FIGHTER;
  423. $army += $rs->fields["convoy_lightcruisers"]* CONF_NETWORTH_MILITARY_LIGHTCRUISER;
  424. $army += $rs->fields["convoy_heavycruisers"]* CONF_NETWORTH_MILITARY_HEAVYCRUISER;
  425. $army += $rs->fields["carriers"]* CONF_NETWORTH_MILITARY_CARRIER;
  426. $rs->MoveNext();
  427. }
  428. $networth += ($army);
  429. $this->data["networth"] = floor($networth);
  430. if ($this->coalition->IsMember())
  431. $this->coalition->updateNetworth($this->data["networth"]);
  432. }
  433. /////////////////////////////////////////////////////////
  434. //
  435. /////////////////////////////////////////////////////////
  436. function calcAntiPollution()
  437. {
  438. if ($this->planets->data["antipollu_planets"]!=0) {
  439. $antipollution = $this->planets->data["antipollu_planets"] * CONF_ANTIPOLLUTION;
  440. $antipollution = round(($antipollution/100)* $this->production->data["antipollu_short"]);
  441. if ($antipollution == 0) $antipollution = 1;
  442. return $antipollution;
  443. } else return 1;
  444. }
  445. /////////////////////////////////////////////////////////
  446. //
  447. /////////////////////////////////////////////////////////
  448. function calcPollution()
  449. {
  450. $pollution = floor((int) (($this->planets->data["petro_planets"]/100) * $this->production->data["petro_short"]) * CONF_PETRO_POLLUTION);
  451. $pollution += floor((int) $this->data["population"] * CONF_POP_POLLUTION);
  452. $pollution = round($pollution,2);
  453. return $pollution;
  454. }
  455. /////////////////////////////////////////////////////////
  456. //
  457. /////////////////////////////////////////////////////////
  458. function updateStats()
  459. {
  460. $pollution = $this->calcPollution();
  461. $army = 0;
  462. $army += $this->army->data["soldiers"] * CONF_NETWORTH_MILITARY_SOLDIER;
  463. $army += $this->army->data["fighters"]* CONF_NETWORTH_MILITARY_FIGHTER;
  464. $army += $this->army->data["stations"]* CONF_NETWORTH_MILITARY_STATION;
  465. $army += $this->army->data["lightcruisers"]* CONF_NETWORTH_MILITARY_LIGHTCRUISER;
  466. $army += $this->army->data["heavycruisers"]* CONF_NETWORTH_MILITARY_HEAVYCRUISER;
  467. $army += $this->army->data["carriers"]* CONF_NETWORTH_MILITARY_CARRIER;
  468. $army += $this->army->data["covertagents"]* CONF_NETWORTH_MILITARY_COVERT;
  469. $rs = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_armyconvoy WHERE empire_from=".$this->data["id"]." OR empire_to=".$this->data["id"]);
  470. if (!$rs) trigger_error($DB->ErrorMsg());
  471. while (!$rs->EOF) {
  472. $army += $rs->fields["convoy_soldiers"] * CONF_NETWORTH_MILITARY_SOLDIER;
  473. $army += $rs->fields["convoy_fighters"]* CONF_NETWORTH_MILITARY_FIGHTER;
  474. $army += $rs->fields["convoy_lightcruisers"]* CONF_NETWORTH_MILITARY_LIGHTCRUISER;
  475. $army += $rs->fields["convoy_heavycruisers"]* CONF_NETWORTH_MILITARY_HEAVYCRUISER;
  476. $army += $rs->fields["carriers"]* CONF_NETWORTH_MILITARY_CARRIER;
  477. $rs->MoveNext();
  478. }
  479. $query = "INSERT INTO game".$this->game_id."_tb_stats (empire,date,credits,food,networth,military,planets,population,pollution,turn)
  480. VALUES(".
  481. $this->data["id"].",".
  482. time(NULL).",".
  483. $this->data["credits"].",".
  484. $this->data["food"].",".
  485. $this->data["networth"].",".
  486. $army.",".
  487. $this->planets->getCount().",".
  488. $this->data["population"].",".
  489. $pollution.",".
  490. $this->data["turns_played"].");";
  491. if (!$this->DB->Execute($query)) trigger_error($this->DB->ErrorMsg());
  492. }
  493. }
  494. ?>