/src/game/include/scienceDetail.html.php

https://github.com/extraaa/Game · PHP · 193 lines · 145 code · 35 blank · 13 comment · 38 complexity · b082be1f070b056db371af7bd28da0f2 MD5 · raw file

  1. <?php
  2. /*
  3. * science_detail.html.php -
  4. * Copyright (c) 2004 OGP-Team
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. */
  11. /** ensure this file is being included by a parent file */
  12. defined('_VALID_UA') or die('Direct Access to this location is not allowed.');
  13. function science_getScienceDetails($scienceID, $caveData, $method) {
  14. global $template;
  15. global $buildingTypeList, $defenseSystemTypeList, $resourceTypeList, $scienceTypeList, $unitTypeList;
  16. $no_resource_flag = 1;
  17. // first check whether that science should be displayed...
  18. $science = $scienceTypeList[$scienceID];
  19. $maxLevel = round(eval('return '.formula_parseToPHP("{$science->maxLevel};", '$caveData')));
  20. if (!$science || ($science->nodocumentation &&
  21. !$caveData[$science->dbFieldName] &&
  22. rules_checkDependencies($science, $caveData) !== TRUE)) {
  23. $science = current($scienceTypeList);
  24. }
  25. if ($method == 'ajax') {
  26. $template->setFile('scienceDetailAjax.tmpl');
  27. $shortVersion = 1;
  28. }
  29. else {
  30. $template->setFile('scienceDetail.tmpl');
  31. $template->setShowRresource(false);
  32. $shortVersion = 0;
  33. }
  34. $currentlevel = $caveData[$science->dbFieldName];
  35. $levels = array();
  36. for ($level = $caveData[$science->dbFieldName], $count = 0;
  37. $level < $maxLevel && $count < ($shortVersion ? 3 : 10);
  38. ++$count, ++$level, ++$caveData[$science->dbFieldName]){
  39. $duration = time_formatDuration(
  40. eval('return ' .
  41. formula_parseToPHP($scienceTypeList[$scienceID]->productionTimeFunction.";",'$caveData'))
  42. * BUILDING_TIME_BASE_FACTOR);
  43. // iterate ressourcecosts
  44. $resourcecost = array();
  45. foreach ($science->resourceProductionCost as $resourceID => $function){
  46. $cost = ceil(eval('return '. formula_parseToPHP($function . ';', '$caveData')));
  47. if ($cost)
  48. array_push($resourcecost,
  49. array(
  50. 'name' => $resourceTypeList[$resourceID]->name,
  51. 'dbFieldName' => $resourceTypeList[$resourceID]->dbFieldName,
  52. 'value' => $cost));
  53. }
  54. // iterate unitcosts
  55. $unitcost = array();
  56. foreach ($science->unitProductionCost as $unitID => $function){
  57. $cost = ceil(eval('return '. formula_parseToPHP($function . ';', '$caveData')));
  58. if ($cost)
  59. array_push($unitcost,
  60. array(
  61. 'name' => $unitTypeList[$unitID]->name,
  62. 'dbFieldName' => $unitTypeList[$unitID]->dbFieldName,
  63. 'value' => $cost));
  64. }
  65. $buildingCost = array();
  66. foreach ($science->buildingProductionCost as $key => $value)
  67. if ($value != "" && $value != 0)
  68. array_push($buildingCost, array('dbFieldName' => $buildingTypeList[$key]->dbFieldName,
  69. 'name' => $buildingTypeList[$key]->name,
  70. 'value' => ceil(eval('return '.formula_parseToPHP($science->buildingProductionCost[$key] . ';', '$details')))));
  71. $defenseCost = array();
  72. foreach ($science->defenseProductionCost as $key => $value)
  73. if ($value != "" && $value != 0)
  74. array_push($defenseCost, array('dbFieldName' => $defenseSystemTypeList[$key]->dbFieldName,
  75. 'name' => $defenseSystemTypeList[$key]->name,
  76. 'value' => ceil(eval('return '.formula_parseToPHP($science->defenseProductionCost[$key] . ';', '$details')))));
  77. $levels[$count] = array('level' => $level + 1,
  78. 'time' => $duration,
  79. 'BUILDINGCOST' => $buildingCost,
  80. 'DEFENSECOST' => $defenseCost,
  81. 'RESOURCECOST' => $resourcecost,
  82. 'UNITCOST' => $unitcost);
  83. }
  84. if (sizeof($levels))
  85. $levels = array('population' => $caveData['population'], 'LEVEL' => $levels);
  86. $dependencies = array();
  87. $buildingdep = array();
  88. $defensesystemdep = array();
  89. $resourcedep = array();
  90. $sciencedep = array();
  91. $unitdep = array();
  92. foreach ($science->buildingDepList as $key => $level)
  93. if ($level)
  94. array_push($buildingdep, array('name' => $buildingTypeList[$key]->name,
  95. 'level' => "&gt;= " . $level));
  96. foreach ($science->defenseSystemDepList as $key => $level)
  97. if ($level)
  98. array_push($defensesystemdep, array('name' => $defenseSystemTypeList[$key]->name,
  99. 'level' => "&gt;= " . $level));
  100. foreach ($science->resourceDepList as $key => $level)
  101. if ($level)
  102. array_push($resourcedep, array('name' => $resourceTypeList[$key]->name,
  103. 'level' => "&gt;= " . $level));
  104. foreach ($science->scienceDepList as $key => $level)
  105. if ($level)
  106. array_push($sciencedep, array('name' => $scienceTypeList[$key]->name,
  107. 'level' => "&gt;= " . $level));
  108. foreach ($science->unitDepList as $key => $level)
  109. if ($level)
  110. array_push($unitdep, array('name' => $unitTypeList[$key]->name,
  111. 'level' => "&gt;= " . $level));
  112. foreach ($science->maxBuildingDepList as $key => $level)
  113. if ($level != -1)
  114. array_push($buildingdep, array('name' => $buildingTypeList[$key]->name,
  115. 'level' => "&lt;= " . $level));
  116. foreach ($science->maxDefenseSystemDepList as $key => $level)
  117. if ($level != -1)
  118. array_push($defensesystemdep, array('name' => $defenseSystemTypeList[$key]->name,
  119. 'level' => "&lt;= " . $level));
  120. foreach ($science->maxResourceDepList as $key => $level)
  121. if ($level != -1)
  122. array_push($resourcedep, array('name' => $resourceTypeList[$key]->name,
  123. 'level' => "&lt;= " . $level));
  124. foreach ($science->maxScienceDepList as $key => $level)
  125. if ($level != -1)
  126. array_push($sciencedep, array('name' => $scienceTypeList[$key]->name,
  127. 'level' => "&lt;= " . $level));
  128. foreach ($science->maxUnitDepList as $key => $level)
  129. if ($level != -1)
  130. array_push($unitdep, array('name' => $unitTypeList[$key]->name,
  131. 'level' => "&lt;= " . $level));
  132. if (sizeof($buildingdep))
  133. array_push($dependencies, array('name' => _('Erweiterungen'),
  134. 'DEP' => $buildingdep));
  135. if (sizeof($defensesystemdep))
  136. array_push($dependencies, array('name' => _('Verteidigungsanlagen'),
  137. 'DEP' => $defensesystemdep));
  138. if (sizeof($resourcedep))
  139. array_push($dependencies, array('name' => _('Rohstoffe'),
  140. 'DEP' => $resourcedep));
  141. if (sizeof($sciencedep))
  142. array_push($dependencies, array('name' => _('Forschungen'),
  143. 'DEP' => $sciencedep));
  144. if (sizeof($unitdep))
  145. array_push($dependencies, array('name' => _('Einheiten'),
  146. 'DEP' => $unitdep));
  147. $template->addVars(array(
  148. 'name' => $science->name,
  149. 'dbFieldName' => $science->dbFieldName,
  150. 'description' => $science->description,
  151. 'maxlevel' => $maxLevel,
  152. 'currentlevel' => $currentlevel,
  153. 'LEVELS' => $levels,
  154. 'DEPGROUP' => $dependencies,
  155. 'rules_path' => RULES_PATH
  156. ));
  157. }
  158. ?>