PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/solar27/include/game/classes/research.php

https://bitbucket.org/sebs/mosolar
PHP | 98 lines | 59 code | 23 blank | 16 comment | 8 complexity | dd526f609d510e50008ea04271355771 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 Research
  4. {
  5. var $DB;
  6. var $TEMPLATE;
  7. var $tech_data;
  8. var $tech_done;
  9. var $game_id;
  10. ///////////////////////////////////////////////////////////////////////
  11. //
  12. ///////////////////////////////////////////////////////////////////////
  13. function Research($DB,$TEMPLATE)
  14. {
  15. $this->DB = $DB;
  16. $this->game_id = round($_SESSION["game"]);
  17. $this->TEMPLATE = $TEMPLATE;
  18. $this->tech_data = array();
  19. $this->tech_done = array();
  20. }
  21. ///////////////////////////////////////////////////////////////////////
  22. //
  23. ///////////////////////////////////////////////////////////////////////
  24. function load($empire_id)
  25. {
  26. $rs = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_research_tech");
  27. if (!$rs) trigger_error($this->DB->ErrorMsg());
  28. while(!$rs->EOF)
  29. {
  30. $this->tech_data[] = $rs->fields;
  31. $rs->MoveNext();
  32. }
  33. $rs = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_research_done WHERE empire_id='".intval($empire_id)."'");
  34. if (!$rs) trigger_error($this->DB->ErrorMsg());
  35. while(!$rs->EOF)
  36. {
  37. $this->tech_done[] = $rs->fields["tech_id"];
  38. $rs->MoveNext();
  39. }
  40. return true;
  41. }
  42. ///////////////////////////////////////////////////////////////////////
  43. //
  44. ///////////////////////////////////////////////////////////////////////
  45. function getLevel($level)
  46. {
  47. $techs = array();
  48. for ($i=0;$i<count($this->tech_data);$i++)
  49. {
  50. if ($this->tech_data[$i]["level"] == $level) $techs[] = $this->tech_data[$i];
  51. }
  52. return $techs;
  53. }
  54. ///////////////////////////////////////////////////////////////////////
  55. //
  56. ///////////////////////////////////////////////////////////////////////
  57. function getTechFromId($tech_id)
  58. {
  59. for ($i=0;$i<count($this->tech_data);$i++)
  60. {
  61. if ($this->tech_data[$i]["id"] == $tech_id) return $this->tech_data[$i];
  62. }
  63. return null;
  64. }
  65. ///////////////////////////////////////////////////////////////////////
  66. //
  67. ///////////////////////////////////////////////////////////////////////
  68. function getGrowthPoints($planets,$production)
  69. {
  70. $points = floor(($planets/100) * $production);
  71. $points *= CONF_RESEARCH_POINTS_PER_PLANET;
  72. return $points;
  73. }
  74. }
  75. ?>