Planets.nu - Planetary Management Plugin v2

Planetary Management Plugin v2

当前为 2014-06-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Planets.nu - Planetary Management Plugin v2
  3. // @description Planetary Management Plugin v2
  4. // @version 2.0
  5. // @author Jim Clark
  6. // @include http://planets.nu/#/*
  7. // @include http://planets.nu/*
  8. // @include http://play.planets.nu/*
  9. // @include http://test.planets.nu/*
  10. // @history 0.2 Initial release [2013-07-28]
  11. // @history 0.5 Major Beta Add - Method Construction, Versioning
  12. // @history 1.01 Main Release
  13. // @history 1.11 Stellar Cartography Support, Filters, Global Method Applications
  14. // @history 1.20 Nu 1.16 Support - Large Saving
  15. // @history 2.0 This is a fork from dotmans original script. Fixes/Enhancmenets included are neumerous and (some) forgotten
  16. // - Removed build screen popup which cuts HUGE amounts of time from the build function
  17. // - Added new taxation methods; riot and notax
  18. // - Added more default tax and build options
  19. // - Reorginiazed managmenet window to make it harder to screwup all your settings
  20. // - More?
  21. // @namespace https://greasyfork.org/users/2874
  22. // ==/UserScript==
  23.  
  24.  
  25. function wrapper () { // wrapper for injection
  26. if (vgap.version < 3.0) {
  27. console.log("Planetary Management Plugin requires at least NU version 3.0. Plugin disabled." );
  28. return;
  29. }
  30. var plugin_version = 2.0;
  31. var debug = false;
  32. console.log("Planetary Manager plugin version: v" + plugin_version );
  33.  
  34. var plManagerPlugin = {
  35. processload: function() {
  36. if (debug) console.log("ProcessLoad: plManagerPlugin plugin called.");
  37. var plg = vgap.plugins["plManagerPlugin"];
  38. vgap.plugins["plManagerPlugin"].curplanet = 0;
  39. vgap.plugins["plManagerPlugin"].planetbuildindex = 0;
  40. vgap.plugins["plManagerPlugin"].buildstatustext = "";
  41. // Add the CSS Styling we will need later
  42. vgap.plugins["plManagerPlugin"].addCss("#PopulationTable, #InfoTable, #BldgTable, #PMResTable { \
  43. background-color: rgba(0,0,0,0.2); \
  44. padding: 5px; \
  45. box-shadow: 5px 5px 5px #777777}");
  46. // PLTable CSS
  47. vgap.plugins["plManagerPlugin"].addCss(".PLRow { \
  48. background-color: rgba(0,0,0,0.2); \
  49. padding: 10px; \
  50. box-shadow: 2px 2px 2px #777777}");
  51. vgap.plugins["plManagerPlugin"].addCss(".PLNewRow { \
  52. background-color: rgba(255,255,0,0.2); \
  53. padding: 10px; \
  54. box-shadow: 2px 2px 2px #777777}");
  55. vgap.plugins["plManagerPlugin"].addCss(".PLPlanetTable { \
  56. padding: 20px;}");
  57. vgap.plugins["plManagerPlugin"].addCss(".PLResTable { \
  58. padding: 10px;}");
  59. vgap.plugins["plManagerPlugin"].addCss(".ResAmt { \
  60. color: rgba(255,255,255,0.5); \
  61. padding-right: 20px; \
  62. font-size: 12px;}");
  63. // PL Bldg Table CSS
  64. vgap.plugins["plManagerPlugin"].addCss(".PLBldgTable { \
  65. padding: 5px;}");
  66. vgap.plugins["plManagerPlugin"].addCss(".BldgCnt { \
  67. color: #00FF00; \
  68. font-weight: bold; \
  69. text-align: right; \
  70. text-size: 16px;}");
  71. vgap.plugins["plManagerPlugin"].addCss(".BldgMax { \
  72. text-size: 12px;}");
  73. vgap.plugins["plManagerPlugin"].addCss(".BldgBlt { \
  74. color: rgba(255,255,255,0.5); \
  75. font-size: 12px;}");
  76. vgap.plugins["plManagerPlugin"].addCss(".PLPopTag { \
  77. text-align: left; \
  78. font-size: 12px;}");
  79. vgap.plugins["plManagerPlugin"].addCss(".PLPopVal { \
  80. text-align: left; \
  81. font-weight: bold; \
  82. padding-left: 30px; \
  83. font-size: 14px;}");
  84. vgap.plugins["plManagerPlugin"].addCss(".PLBuildStatus { \
  85. color: #00FF00; \
  86. font-weight: bold; \
  87. text-align: center; \
  88. text-size: 16px;}");
  89. vgap.plugins["plManagerPlugin"].addCss("#PLBldDescription { \
  90. width: 150px; \
  91. font-weight: bold; \
  92. text-align: center; \
  93. text-size: 16px;}");
  94. // PMDetail CSS
  95. vgap.plugins["plManagerPlugin"].addCss(".PMBldgCnt { \
  96. color: #00FF00; \
  97. font-weight: bold; \
  98. text-align: right; \
  99. text-size: 16px;}");
  100. vgap.plugins["plManagerPlugin"].addCss(".PredictVal { \
  101. position: relative; \
  102. color: #00FF00; \
  103. font-weight: bold; \
  104. text-size: 16px;}");
  105. vgap.plugins["plManagerPlugin"].addCss("#PredHdr { \
  106. text-size: 14px;}");
  107. vgap.plugins["plManagerPlugin"].addCss(".PMBldgMax { \
  108. text-size: 14px;}");
  109. vgap.plugins["plManagerPlugin"].addCss(".PMBldgBlt { \
  110. color: rgba(255,255,255,0.5); \
  111. font-size: 14px;}");
  112. vgap.plugins["plManagerPlugin"].addCss(".PMColTag { \
  113. text-align: left; \
  114. font-weight: bold; \
  115. font-size: 15px;}");
  116. vgap.plugins["plManagerPlugin"].addCss(".PMColVal { \
  117. color: #00FF00; \
  118. text-align: left; \
  119. font-weight: bold; \
  120. padding-left: 30px; \
  121. font-size: 15px;}");
  122. vgap.plugins["plManagerPlugin"].addCss(".PMColExtra { \
  123. color: rgba(255,255,255,0.5); \
  124. font-size: 14px;}");
  125. vgap.plugins["plManagerPlugin"].addCss(".PMResAmt { \
  126. color: rgba(255,255,255,0.5); \
  127. padding-right: 20px; \
  128. font-size: 14px;}");
  129. vgap.plugins["plManagerPlugin"].addCss(".PMResName { \
  130. font-weight: bold;\
  131. padding-right: 20px; \
  132. font-size: 15px;}");
  133. vgap.plugins["plManagerPlugin"].addCss("#BMFieldset { \
  134. width: 350px; \
  135. border: 1px solid; \
  136. border-radius: 10px; \
  137. padding: 20px;}");
  138. vgap.plugins["plManagerPlugin"].addCss("#BMWizFieldset, #TMWizMethFieldset { \
  139. width: 350px; \
  140. border: 1px solid; \
  141. border-radius: 10px; \
  142. padding: 20px;}");
  143. vgap.plugins["plManagerPlugin"].addCss("#BMLegend { \
  144. border: 1px solid #dcdcdc; \
  145. border-radius: 10px; \
  146. padding: 10px 20px; \
  147. text-transform: uppercase;}");
  148. vgap.plugins["plManagerPlugin"].addCss("input { \
  149. border-radius: 5px; \
  150. }");
  151. vgap.plugins["plManagerPlugin"].addCss("#BMMainTable { \
  152. padding: 10px;}");
  153. vgap.plugins["plManagerPlugin"].addCss("#BMDEDiv { \
  154. width: 450px; \
  155. border-radius: 10px; \
  156. background-color: rgba(0,0,0,0.2); \
  157. box-shadow: 5px 5px 5px #777777; \
  158. vertical-align: top; \
  159. padding: 20px;}");
  160. vgap.plugins["plManagerPlugin"].addCss("#BMWizDiv, #TMWiz { \
  161. box-shadow: 5px 5px 5px #777777; \
  162. width: 530px; \
  163. border-radius: 10px; \
  164. background-color: rgba(0,0,0,0.2); \
  165. vertical-align: top; \
  166. padding: 20px;}");
  167. vgap.plugins["plManagerPlugin"].addCss(".BMWizSection { \
  168. border: 1px solid; \
  169. border-radius: 10px;}");
  170. //vgap.plugins["plManagerPlugin"].addCss("#BMWizTable { \
  171. // padding: 10px;}");
  172. vgap.plugins["plManagerPlugin"].addCss("#BMWizTable td{ \
  173. padding: 10px;}");
  174. vgap.plugins["plManagerPlugin"].addCss("#DEBMStatusText { \
  175. color: #FF0000; \
  176. font-weight: bold; \
  177. text-size: 16px;}");
  178. vgap.plugins["plManagerPlugin"].addCss("#BMSelTable, #TMSelTable { \
  179. border-radius: 10px; \
  180. background-color: rgba(0,0,0,0.2); \
  181. box-shadow: 5px 5px 5px #777777}");
  182. vgap.plugins["plManagerPlugin"].addCss("#BMGSelTable, #NTMGSelTable, #CTMGSelTable, #GMATable { \
  183. border-radius: 10px; \
  184. background-color: rgba(0,0,0,0.2); \
  185. box-shadow: 5px 5px 5px #777777}");
  186. vgap.plugins["plManagerPlugin"].addCss("#warntext { \
  187. color: #00FF00;}");
  188. vgap.plugins["plManagerPlugin"].addCss("#BMSelTable td{ \
  189. padding-left: 20px;}");
  190. // End CSS
  191. // Initialize configuration arrays
  192. /*
  193. while (vgap.plugins["plManagerPlugin"].bmarray.length < 501) {
  194. vgap.plugins["plManagerPlugin"].bmarray[vgap.plugins["plManagerPlugin"].length]=1;
  195. }
  196. */
  197. bmarray = [];
  198. ntarray = [];
  199. ctarray = [];
  200. myplanetsarray = [];
  201. buildmethods = [];
  202. taxmethods = [];
  203. parray = [];
  204. // Read Notes
  205. if (debug) console.log("Preparing To Read. YOU SHOULD ALWAYS SEE THIS LINE AND IT SHOULD BE EASY TO SEE BECAUSE ITS IN CAPS AND HAS STARS IN IT!!!! *******");
  206. plg.readOrder = 1;
  207. plg.readNotes();
  208. vgap.plugins["plManagerPlugin"].buildstatustext = "Idle";
  209. plg.validateArrays();
  210. if (debug) console.log("END PROCESS LOAD");
  211. },
  212. loaddashboard: function() {
  213. //console.log("LoadDashboard: plManagerPlugin plugin called.");
  214. // Add Planetary Management Button
  215. var menu = document.getElementById("DashboardMenu").childNodes[2]; //insert in middle
  216. $("<li style=\"color:#FFF000\">Planetary Management »</li>").tclick(function () { vgap.plugins["plManagerPlugin"].displayPM(); }).appendTo(menu);
  217. },
  218. /*
  219. * showdashboard: executed when switching from starmap to dashboard
  220. */
  221. showdashboard: function() {
  222. /*
  223. console.log("ShowDashboard: plManagerPlugin plugin called.");
  224. console.log("Total Planets: " + vgap.planets.length);
  225. for (var i = 0; i < vgap.planets.length; i++) {
  226. console.log("Planet " + vgap.planets[i].id + ": " + vgap.planets[i].name + " : DD = " + vgap.planets[i].debrisdisk);
  227. }
  228. console.log("Total Debris Disks: " + vgap.debrisdisks.length);
  229. for (var i = 0; i < vgap.debrisdisks.length; i++) {
  230. console.log("Planet (DD) " + vgap.debrisdisks[i].id + ": " + vgap.debrisdisks[i].name);
  231. }
  232. console.log("Getting Planet 479:");
  233. var pln = vgap.getPlanet(479);
  234. console.log(pln);
  235. console.log("pln.id, pln.name: " + pln.id + ", "+ pln.name);
  236. */
  237. },
  238. /*
  239. * showsummary: executed when returning to the main screen of the dashboard
  240. */
  241. showsummary: function() {
  242. //console.log("ShowSummary: plManagerPlugin plugin called.");
  243. //insert Icon for Planetary Management on Home Screen
  244. var summary_list = document.getElementById("TurnSummary").childNodes[0];
  245. var planets_entry = summary_list.children[2];
  246. var node = document.createElement("li");
  247. node.setAttribute("style", "color:#FFF000");
  248. node.innerHTML = "<div class=\"iconholder\"><img src=\"http://play.planets.nu/img/icons/blacksquares/planets.png\"/></div>" +
  249. "Planetary Management";
  250. node.onclick = function() {vgap.plugins["plManagerPlugin"].displayPM();};
  251. summary_list.insertBefore(node, planets_entry);
  252. //summary_list.appendChild(node);
  253. },
  254. /*
  255. * loadmap: executed after the first turn has been loaded to create the map
  256. * as far as I can tell not executed again when using time machine
  257. */
  258. loadmap: function() {
  259. //console.log("LoadMap: plManagerPlugin plugin called.");
  260. },
  261. /*
  262. * showmap: executed when switching from dashboard to starmap
  263. */
  264. showmap: function() {
  265. //console.log("ShowMap: plManagerPlugin plugin called.");
  266. },
  267. /*
  268. * draw: executed on any click or drag on the starmap
  269. */
  270. draw: function() {
  271. //console.log("Draw: plManagerPlugin plugin called.");
  272. },
  273. /*
  274. * loadplanet: executed a planet is selected on dashboard or starmap
  275. */
  276. loadplanet: function() {
  277. //console.log("LoadPlanet: plManagerPlugin plugin called.");
  278. //vgap.plugins["plManagerPlugin"].showBldgs();
  279. $('<div id="PDBar" class="SepBar"><div id="PDBtn" class="SepButton">Planet Detail</div><div id="PDTitle" class="SepTitle">Planetary Management Plugin</div></div>').insertAfter('#MainFleetContainer');
  280. $('#PDBtn').click(function() {
  281. vgap.plugins["plManagerPlugin"].showPlanetDetailFromStarmap(vgap.planetScreen.planet.id);
  282. });
  283. },
  284. /*
  285. * loadstarbase: executed a starbase is selected on dashboard or starmap
  286. */
  287. loadstarbase: function() {
  288. //console.log("LoadStarbase: plManagerPlugin plugin called.");
  289. },
  290. /*
  291. * loadship: executed a ship is selected on dashboard or starmap
  292. */
  293. loadship: function() {
  294. //console.log("LoadShip: plManagerPlugin plugin called.");
  295. },
  296. /*
  297. * Variables
  298. */
  299. curplanet: 0,
  300. planetbuildindex: 0,
  301. savedindex: -1,
  302. buildstatustext: 0,
  303. ambuilding: false,
  304. savestarted: false,
  305. bmarray: [],
  306. ntarray: [],
  307. ctarray: [],
  308. myplanetsarray: [],
  309. buildmethods: [],
  310. taxmethods: [],
  311. notetype: -174481,
  312. bmwizcode: "",
  313. bmwiztext: "",
  314. selTaxModel: "",
  315. pplanet: "",
  316. predictarray: [],
  317. predicttimes: {},
  318. readOrder: 1,
  319. pmviewcode: 0,
  320. parray: [],
  321. qb: 0,
  322. fcrandomize: true,
  323. /* Main Display Function
  324. */
  325. displayPM: function(view) {
  326. vgap.playSound("button");
  327. vgap.closeSecond();
  328. var plg = vgap.plugins["plManagerPlugin"];
  329. vgap.dash.content.empty();
  330. var html = "";
  331. if (!view)
  332. view = 0;
  333. if (debug) console.log("Entered displayPM, buildmethods is " + plg.buildmethods);
  334. var filterMenu = $("<ul class='FilterMenu'></ul>").appendTo(vgap.dash.content);
  335. $("<li " + (view == 0 ? "class='SelectedFilter'" : "") + ">Planetary Management View</li>").tclick(function() { vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(filterMenu);
  336. $("<li " + (view == 1 ? "class='SelectedFilter'" : "") + ">Planet Detail View</li>").tclick(function() { vgap.plugins["plManagerPlugin"].displayPM(1); }).appendTo(filterMenu);
  337. $("<li " + (view == 3 ? "class='SelectedFilter'" : "") + ">Build Methods</li>").tclick(function() { vgap.plugins["plManagerPlugin"].displayPM(3); }).appendTo(filterMenu);
  338. $("<li " + (view == 4 ? "class='SelectedFilter'" : "") + ">Taxation Methods</li>").tclick(function() { vgap.plugins["plManagerPlugin"].displayPM(4); }).appendTo(filterMenu);
  339. $("<li " + (view == 2 ? "class='SelectedFilter'" : "") + ">Help</li>").tclick(function() { vgap.plugins["plManagerPlugin"].displayPM(2); }).appendTo(filterMenu);
  340. //loop through all planets and show the ones owned by this player
  341. html = "<div class='DashPane' style='height:" + ($("#DashboardContent").height() - 70) + "px;'>";
  342. if (view == 0) {
  343. var PMBreak = $("<br /><br />").appendTo(vgap.dash.content);
  344. var PMfilterMenu = $("<ul class='FilterMenu'></ul>").appendTo(vgap.dash.content);
  345. $("<li " + (plg.pmviewcode == 0 ? "class='SelectedFilter'" : "") + ">All Planets</li>").tclick(function() { plg.pmviewcode = 0; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  346. $("<li " + (plg.pmviewcode == 1 ? "class='SelectedFilter'" : "") + ">Planets with all Manual Methods</li>").tclick(function() { plg.pmviewcode = 1; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  347. $("<li " + (plg.pmviewcode == 2 ? "class='SelectedFilter'" : "") + ">Planets with Natives</li>").tclick(function() { plg.pmviewcode = 2; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  348. $("<li " + (plg.pmviewcode == 3 ? "class='SelectedFilter'" : "") + ">Planets without Natives</li>").tclick(function() { plg.pmviewcode = 3; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  349. $("<li " + (plg.pmviewcode == 4 ? "class='SelectedFilter'" : "") + ">Planets with > 1mil Colonists</li>").tclick(function() { plg.pmviewcode = 4; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  350. $("<li " + (plg.pmviewcode == 5 ? "class='SelectedFilter'" : "") + ">Planets with No Build Method</li>").tclick(function() { plg.pmviewcode = 5; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  351. $("<li " + (plg.pmviewcode == 6 ? "class='SelectedFilter'" : "") + ">Planets with No Colonist Tax Method</li>").tclick(function() { plg.pmviewcode = 6; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  352. $("<li " + (plg.pmviewcode == 7 ? "class='SelectedFilter'" : "") + ">Planets with No Native Tax Method</li>").tclick(function() { plg.pmviewcode = 7; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  353. $("<li " + (plg.pmviewcode == 8 ? "class='SelectedFilter'" : "") + ">Planets with Completed Build Methods</li>").tclick(function() { plg.pmviewcode = 8; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  354. $("<li " + (plg.pmviewcode == 9 ? "class='SelectedFilter'" : "") + ">Planets with a Starbase</li>").tclick(function() { plg.pmviewcode = 9; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  355. $("<li " + (plg.pmviewcode == 10 ? "class='SelectedFilter'" : "") + ">Planets that can Build a Starbase</li>").tclick(function() { plg.pmviewcode = 10; vgap.plugins["plManagerPlugin"].displayPM(0); }).appendTo(PMfilterMenu);
  356. //$("</div>").appendTo(vgap.dash.content);
  357. plg.parray = [];
  358. if (plg.pmviewcode == 0)
  359. plg.parray = vgap.myplanets;
  360. if (plg.pmviewcode == 1) {
  361. for (var i = 0; i < vgap.myplanets.length; i++) {
  362. var planet = vgap.myplanets[i];
  363. if (plg.bmarray[planet.id] == 'm' && plg.ctarray[planet.id] == 'm')
  364. if (planet.nativeclans > 0)
  365. if (plg.ntarray[planet.id] == 'm') {
  366. plg.parray.push(planet);
  367. }
  368. else
  369. plg.parray.push(planet);
  370. }
  371. }
  372. if (plg.pmviewcode == 2) {
  373. for (var i = 0; i < vgap.myplanets.length; i++) {
  374. var planet = vgap.myplanets[i];
  375. if (planet.nativeclans > 0)
  376. plg.parray.push(planet);
  377. }
  378. }
  379. if (plg.pmviewcode == 3) {
  380. for (var i = 0; i < vgap.myplanets.length; i++) {
  381. var planet = vgap.myplanets[i];
  382. if (planet.nativeclans == 0)
  383. plg.parray.push(planet);
  384. }
  385. }
  386. if (plg.pmviewcode == 4) {
  387. for (var i = 0; i < vgap.myplanets.length; i++) {
  388. var planet = vgap.myplanets[i];
  389. if (planet.clans >= 10000)
  390. plg.parray.push(planet);
  391. }
  392. }
  393. if (plg.pmviewcode == 5) {
  394. for (var i = 0; i < vgap.myplanets.length; i++) {
  395. var planet = vgap.myplanets[i];
  396. if (plg.bmarray[planet.id] == 'm')
  397. plg.parray.push(planet);
  398. }
  399. }
  400. if (plg.pmviewcode == 6) {
  401. for (var i = 0; i < vgap.myplanets.length; i++) {
  402. var planet = vgap.myplanets[i];
  403. if (plg.ctarray[planet.id] == 'm')
  404. plg.parray.push(planet);
  405. }
  406. }
  407. if (plg.pmviewcode == 7) {
  408. for (var i = 0; i < vgap.myplanets.length; i++) {
  409. var planet = vgap.myplanets[i];
  410. if (debug) console.log("Native view check: checking id = " + planet.id + ", method is " + plg.ntarray[planet.id] + ", nativeclans are " + planet.nativeclans);
  411. if (planet.nativeclans > 0 && plg.ntarray[planet.id] == 'm') {
  412. console.log("Pushing native planet..");
  413. plg.parray.push(planet);
  414. }
  415. }
  416. }
  417. if (plg.pmviewcode == 8) {
  418. for (var i = 0; i < vgap.myplanets.length; i++) {
  419. var planet = vgap.myplanets[i];
  420. if (plg.buildMethodCompleted(planet))
  421. plg.parray.push(planet);
  422. }
  423. }
  424. if (plg.pmviewcode == 9) {
  425. for (var i = 0; i < vgap.myplanets.length; i++) {
  426. var planet = vgap.myplanets[i];
  427. if (vgap.getStarbase(planet.id) != null)
  428. plg.parray.push(planet);
  429. }
  430. }
  431. if (plg.pmviewcode == 10) {
  432. for (var i = 0; i < vgap.myplanets.length; i++) {
  433. var planet = vgap.myplanets[i];
  434. if (planet.megacredits + planet.supplies >= 900 && planet.duranium >= 120 && planet.tritanium >= 402 && planet.molybdenum >= 340)
  435. if (vgap.getStarbase(planet.id) == null)
  436. plg.parray.push(planet);
  437. if (planet.debrisdisk > 0 && planet.megacredits + planet.supplies >= 480 && planet.duranium >= 70 && planet.tritanium >= 242 && planet.molybdenum >= 160)
  438. if (vgap.getStarbase(planet.id) == null)
  439. plg.parray.push(planet);
  440. }
  441. }
  442. // Build Method Review Table
  443. var mrevhtml = "<table id = 'BMGSelTable'><tr><td colspan=2><b>Build Methods:</b><br /></td></tr>";
  444. mrevhtml += "<tr><td rowspan = 2><select name='BMGSelect' id='BMGSelect'>";
  445. //console.log("Populating select, buildmethods is " + plg.buildmethods + ", length is " + plg.buildmethods.length);
  446. for (var i=0; i < plg.buildmethods.length; i++) {
  447. mrevhtml += "<option value='" + i + "'>" + plg.buildmethods[i][0] + "</option>";
  448. }
  449. mrevhtml += "</select></td></tr>";
  450. //mrevhtml += "<td id='BMMethText'>No Method Selected.</td></tr>";
  451. mrevhtml += "<tr><td><button id='BMGApplyBtn'>Apply to All</button></td></tr>";
  452. mrevhtml += "</table>";
  453. // Construct the colonist taxation method review pane
  454. var ctmrevhtml = "<table id = 'CTMGSelTable'><tr><td colspan=2><b>Colonist Taxation Methods:</b><br /></td></tr>";
  455. ctmrevhtml += "<tr><td rowspan = 2><select name='CTMGSelect' id='CTMGSelect'>";
  456. for (var i=0; i < plg.taxmethods.length; i++) {
  457. if (plg.taxmethods[i].taxType == 'C' || plg.taxmethods[i].taxType == 'CN')
  458. ctmrevhtml += "<option value='" + i + "'>" + plg.taxmethods[i].name + "</option>";
  459. }
  460. ctmrevhtml += "</select></td></tr>";
  461. //tmrevhtml += "<td id='TMMethText'>No Method Selected.</td></tr>";
  462. ctmrevhtml += "<tr><td><button id='CTMGApplyBtn'>Apply to All</button></td></tr>";
  463. ctmrevhtml += "</table>";
  464. // Construct the native taxation method review pane
  465. var ntmrevhtml = "<table id = 'NTMGSelTable'><tr><td colspan=2><b>Native Taxation Methods:</b><br /></td></tr>";
  466. ntmrevhtml += "<tr><td rowspan = 2><select name='NTMGSelect' id='NTMGSelect'>";
  467. for (var i=0; i < plg.taxmethods.length; i++) {
  468. if (plg.taxmethods[i].taxType == 'N' || plg.taxmethods[i].taxType == 'CN')
  469. ntmrevhtml += "<option value='" + i + "'>" + plg.taxmethods[i].name + "</option>";
  470. }
  471. ntmrevhtml += "</select></td></tr>";
  472. //tmrevhtml += "<td id='TMMethText'>No Method Selected.</td></tr>";
  473. ntmrevhtml += "<tr><td><button id='NTMGApplyBtn'>Apply to All</button></td></tr>";
  474. ntmrevhtml += "</table>";
  475. // Display build button
  476. html += "<br><table border='0' width='100%'>";
  477. html += "<tr><td rowspan = 3><h1>Planetary Management v" + plugin_version + "</h1></td>";
  478. html += "<td align=center style='width: 100px; cursor:pointer;'><img class='BuildButton' align=center width=90px height=80px src='http://play.planets.nu/img/icons/blacksquares/planets.png'/></td></tr>";
  479. html += "<tr><td class=PLBuildStatus>" + vgap.plugins["plManagerPlugin"].buildstatustext + "</td></tr>";
  480. html += "<tr><td><input type='checkbox' name='RndFCCheck' id='RandomizeFCsCheck' value ='c' checked />Randomize Friendly Codes<br /></td></tr>";
  481. html += "</table><br />";
  482. /*
  483. html += "<br><table id='GMATable' border='0' width='100%'>";
  484. html += "<tr><td colspan = 3><h3>Global Method Application</h3></td></tr>";
  485. html += "<tr><td colspan = 3 id='warntext'>Warning: Applying a method globally will overwrite any existing method assignments.</td></tr>";
  486. html += "<tr><td>" + mrevhtml + "</td>";
  487. html += "<td>" + ctmrevhtml + "</td>";
  488. html += "<td>" + ntmrevhtml + "</td></tr>";
  489. html += "</table><br />";
  490. //this.pane = $(html).appendTo(vgap.dash.content);
  491. */
  492. html += "<table id='PLPlanetTable' align='left' class='CleanTable' border='0' width='100%' style='cursor:pointer;'><thead>";
  493. //html += "<tr><th rowspan = 4></th><th rowspan = 4 align='left'>Planet</th><th rowspan = 4 title='Method' align='left'>Planetary Building Method</th><th rowspan = 4 title='Population' align='left'>Population</th><th rowspan = 4 title='Money' align='left'>Money</th><th rowspan = 4 title='Buildings' align='center' colspan=4>Buildings</th><th rowspan=4 colspan = 5 title='Mineral'>Minerals</th></tr>";
  494. //html += "<tr></tr><tr></tr><tr></tr>";
  495. //html += "</thead><tbody id='PlanetRows'></tbody></table></div>";
  496. html += "</thead><tbody id='PlanetRows'>";
  497. html += "</tbody></table></div>";
  498. this.pane = $(html).appendTo(vgap.dash.content);
  499. //for (var i = 0; i < vgap.myplanets.length; i++) {
  500. // var planet = vgap.myplanets[i];
  501. if (plg.parray.length == 0) {
  502. // There are no planets that fit this criteria
  503. html = "<tr class='PLRow'><td><h3>No Planets fit this criteria.</td></tr>";
  504. $(html).appendTo("#PlanetRows");
  505. }
  506. for (var i = 0; i < plg.parray.length; i++) {
  507. var planet = plg.parray[i];
  508. var base = vgap.getStarbase(planet.id) != null ? "X" : "";
  509. if (view == 0) {
  510. // Set up the planet information table
  511. var plpinfhtml = "";
  512. plpinfhtml += "<table class=PLInfoTable data-plid='" + planet.id + "' border='0' width='100%'>";
  513. plpinfhtml += "<thead></thead>";
  514. plpinfhtml += "<tr> \
  515. <td rowspan = 3><img class='TinyIcon' src='" + planet.img + "'/></td> \
  516. <td class='PLName' rowspan = 1 colspan = 2><b>" + planet.name + "</b></td></tr>";
  517. plpinfhtml += "<tr><td class='PLInfTag' rowspan = 1>ID#:&nbsp;</td> \
  518. <td class='PLInfVal'>" + planet.id + "</td></tr>";
  519. plpinfhtml += "<tr><td class='PLInfTag' rowspan = 1>Temp:&nbsp;</td> \
  520. <td class='PLInfVal'>" + planet.temp + "</td></tr>";
  521. plpinfhtml += "</table>";
  522. // Set up the building method table
  523. var bmhtml = "";
  524. bmhtml += "<table class=PLBMTable>";
  525. bmhtml += "<thead></thead>";
  526. bmhtml += "<tr><td>Build Method:</td> \
  527. <td><div> \
  528. <select class='BMSelect' data-plid='" + planet.id + "'> \
  529. <option value='m'>Manual</option>";
  530. for (var k=0; k < plg.buildmethods.length; k++) {
  531. bmhtml += "<option value='"+k+"'>" + plg.buildmethods[k][0] + "</option>";
  532. }
  533. bmhtml += "</select> \
  534. </div> \
  535. </td></tr>";
  536. bmhtml += "<tr><td>Colonist Tax:</td> \
  537. <td><div> \
  538. <select class='CTSelect' data-plid='" + planet.id + "'> \
  539. <option value='m'>Manual</option>";
  540. for (var k=0; k < plg.taxmethods.length; k++) {
  541. if (plg.taxmethods[k].taxType == 'C' || plg.taxmethods[k].taxType == 'CN')
  542. bmhtml += "<option value='"+k+"'>" + plg.taxmethods[k].name + "</option>";
  543. }
  544. bmhtml += "</select> \
  545. </div> \
  546. </td></tr>";
  547. if (planet.nativeclans > 0)
  548. {
  549. bmhtml += "<tr><td>Native Tax:</td> \
  550. <td><div> \
  551. <select class='NTSelect' data-plid='" + planet.id + "'> \
  552. <option value='m'>Manual</option>";
  553. for (var k=0; k < plg.taxmethods.length; k++) {
  554. if (plg.taxmethods[k].taxType == 'N' || plg.taxmethods[k].taxType == 'CN')
  555. bmhtml += "<option value='"+k+"'>" + plg.taxmethods[k].name + "</option>";
  556. }
  557. bmhtml += "</select> \
  558. </div> \
  559. </td></tr>";
  560. }
  561. bmhtml += "</table>";
  562. // Set up the population table
  563. var pophtml = "";
  564. pophtml += "<table class=PLPopTable>";
  565. pophtml += "<thead></thead>";
  566. pophtml += "<tr><td class='PLPopTag'>Colonists:</td>";
  567. if (plg.myColPopGrowth(planet,false) < 0)
  568. pophtml += "<td class='PLPopVal'><span class='BadText'>" + plg.nwc(planet.clans * 100) + "</span></td></tr>";
  569. else if (planet.clans > plg.getMaxColonists(planet,false))
  570. pophtml += "<td class='PLPopVal'><span class='WarnText'>" + plg.nwc(planet.clans * 100) + "</span></td></tr>";
  571. else
  572. pophtml += "<td class='PLPopVal'><span class='NormalText'>" + plg.nwc(planet.clans * 100) + "</span></td></tr>";
  573. if (planet.nativeclans > 0) {
  574. //console.log("Native Name: " + planet.nativeracename + " , Native Type: " + planet.nativetype);
  575. pophtml += "<tr><td class='PLPopTag'>Natives:</td>";
  576. if (plg.myNatPopGrowth(planet,false) < 0)
  577. pophtml += "<td class='PLPopVal'><span class='BadText'>" + plg.nwc(planet.nativeclans * 100) + "</span></td></tr>";
  578. else if (planet.nativeclans > plg.getMaxNatives(planet,false))
  579. pophtml += "<td class='PLPopVal'><span class='WarnText'>" + plg.nwc(planet.nativeclans * 100) + "</span></td></tr>";
  580. else
  581. pophtml += "<td class='PLPopVal'>" + plg.nwc(planet.nativeclans * 100) + "</td></tr>";
  582. pophtml += "<tr><td align='center' rowspan = 2><img width='35' height='35' src='http://play.planets.nu/img/natives/" + planet.nativetype + ".gif'/></td>";
  583. pophtml += "<td class='PLPopVal'>" + planet.nativeracename + "</td></tr>";
  584. pophtml += "<tr><td class='PLPopVal'>" + planet.nativegovernmentname + "</td></tr>";
  585. }
  586. else {
  587. pophtml += "<tr><td></td></tr>";
  588. pophtml += "<tr><td></td></tr>";
  589. pophtml += "<tr><td></td></tr>";
  590. }
  591. pophtml += "</table>";
  592. // Set up the tax table
  593. var taxhtml = "";
  594. taxhtml += "<table class=PLTaxTable>";
  595. taxhtml += "<thead></thead>";
  596. taxhtml += "<tr><td>Tax Rate:</td>";
  597. taxhtml += "<td class='BldgCnt'>" + planet.colonisttaxrate + "%</td>";
  598. taxhtml += "<td class='BldgBlt'>" + plg.colTaxAmtTxt(planet) + "</td></tr>";
  599. taxhtml += "<tr><td>Happiness:</td>";
  600. taxhtml += "<td class='BldgCnt'>" + planet.colonisthappypoints + "</td>";
  601. taxhtml += "<td class='PLHappyChg'>" + plg.happyChgTxt(vgap.colonistTaxChange(planet)) + "</td></tr>";
  602. if (planet.nativeclans > 0) {
  603. taxhtml += "<tr><td>Tax Rate:</td>";
  604. taxhtml += "<td class='BldgCnt'>" + planet.nativetaxrate + "%</td>";
  605. taxhtml += "<td class='BldgBlt'>" + plg.natTaxAmtTxt(planet) + "</td></tr>";
  606. taxhtml += "<tr><td>Happiness:</td>";
  607. taxhtml += "<td class='BldgCnt'>" + planet.nativehappypoints + "</td>";
  608. taxhtml += "<td class='PLHappyChg'>" + plg.happyChgTxt(vgap.nativeTaxChange(planet)) + "</td></tr>";
  609. }
  610. else {
  611. taxhtml += "<tr><td></td></tr>";
  612. taxhtml += "<tr><td></td></tr>";
  613. }
  614. taxhtml += "</table>";
  615. // Set up the megacredits/supply table
  616. var mcsuphtml = "";
  617. mcsuphtml += "<table class=PLMCSupTable>";
  618. mcsuphtml += "<thead></thead>";
  619. mcsuphtml += "<tr><td>Megacredits:&nbsp;</td><td><b>" + planet.megacredits + "</b></td></tr>";
  620. mcsuphtml += "<tr><td>Supplies:&nbsp;</td><td><b>" + planet.supplies + "</b></td></tr>";
  621. //mcsuphtml += "<tr><td>FC:&nbsp;</td>";
  622. mcsuphtml += "<tr><td></td><td class=FCDisp data-plid='" + planet.id + "' id='FCDisp_" + planet.id + "' align='center' width='30px' style='border: solid white 1px; color: #0000A0; background-color: " + vgap.plugins["plManagerPlugin"].getFCColor(planet.friendlycode) + ";'><b>" + planet.friendlycode + "</b></td><td></td></tr>";
  623. mcsuphtml += "</table>";
  624. /*
  625. //highlight friendly codes
  626. var fcbox_color = "transparent";
  627. fcu = planet.friendlycode.toUpperCase();
  628. if (fcu == "NUK" || fcu == "ATT") fcbox_color = "red";
  629. else if (fcu == "BUM") fcbox_color = "orchid";
  630. else if (fcu == "DMP") fcbox_color = "magenta";
  631. else if (fcu.substr(0, 2) == "PB") fcbox_color = "aqua";
  632.  
  633. return "<table width='100%'>" +
  634. "<tr><td class='head' data-topic='Buildings'>Mines:</td><td class='val'>" + planet.mines + "</td><td class='valsup'>/" + this.maxBuilding(200) + " " + mineText + "</td><td class='valsup'>" + tmText + "</td></tr>" +
  635. "<tr><td class='head' data-topic='Buildings'>Factories:</td><td class='val'>" + planet.factories + "</td><td class='valsup'>/" + this.maxBuilding(100) + " " + factoryText + "</td><td class='valsup'>" + tfText + "</td>" +
  636. "<td class='headright' data-topic='FriendlyCodes'>Friendly Code</td><td class='fc'><span style='background-color: " + fcbox_color + "' id='PlanetFC'>" + planet.friendlycode + "</span></td></tr>" +
  637. "<tr><td class='head' style='cursor:pointer' data-topic='Buildings'>Defense:</td><td class='val'>" + planet.defense + "</td><td class='valsup'>/" + this.maxBuilding(50) + " " + defText + "</td><td class='valsup'>" + tdText + "</td></tr>" +
  638. "</table>";
  639. */
  640. // Set up the buildings table
  641. var bldghtml = "";
  642. bldghtml += "<table class=PLBldgTable>";
  643. bldghtml += "<thead></thead>";
  644. // Factories
  645. bldghtml += "<tr><td>" + "<img src='http://play.planets.nu/img/icons/factory.png' height='25' width='25'></img>" + "</td>";
  646. bldghtml += "<td class='BldgCnt'>" + planet.factories + "</td>";
  647. bldghtml += "<td class='BldgMax'>/&nbsp;" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,100) + "</td>";
  648. bldghtml += "<td class='BldgBlt'>[+" + planet.builtfactories + "]</td></tr>";
  649. // Mines
  650. bldghtml += "<tr><td>" + "<img src='http://play.planets.nu/img/icons/mine.png' height='25' width='25'></img>" + "</td>";
  651. bldghtml += "<td class='BldgCnt'>" + planet.mines + "</td>";
  652. bldghtml += "<td class='BldgMax'>/&nbsp;" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,200) + "</td>";
  653. bldghtml += "<td class='BldgBlt'>[+" + planet.builtmines + "]</td></tr>";
  654. // Defense Posts
  655. bldghtml += "<tr><td>" + "<img src='http://play.planets.nu/img/icons/defense.png' height='25' width='25'></img>" + "</td>";
  656. bldghtml += "<td class='BldgCnt'>" + planet.defense + "</td>";
  657. bldghtml += "<td class='BldgMax'>/&nbsp;" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,50) + "</td>";
  658. bldghtml += "<td class='BldgBlt'>[+" + planet.builtdefense + "]</td></tr>";
  659. bldghtml += "</table>";
  660. // Set up the Resources Table
  661. var reshtml = "";
  662. reshtml += "<table class=PLResTable>";
  663. reshtml += "<thead></thead>";
  664. // Neutronium
  665. reshtml += "<tr><td class='ResName' align='right'>Neu</td>";
  666. reshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.neutronium) + ";'>" + planet.neutronium + "&nbsp;" + "</td>";
  667. reshtml += "<td class='ResGrd' align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundneutronium) + ";'><b> /&nbsp;" + planet.groundneutronium + "</b></td>";
  668. reshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densityneutronium) + ";'>" + planet.densityneutronium + "%</td>";
  669. reshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundneutronium, planet.densityneutronium) + "</td></tr>";
  670. // Duranium
  671. reshtml += "<tr><td class='ResName' align='right'>Dur</td>";
  672. reshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.duranium) + "; padding-left=0.5ex'>" + planet.duranium + "&nbsp;" + "</td>";
  673. reshtml += "<td class='ResGrd' align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundduranium) + ";'><b> /&nbsp;" + planet.groundduranium + "</b></td>";
  674. reshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densityduranium) + ";'>" + planet.densityduranium + "%</td>";
  675. reshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundduranium, planet.densityduranium) + "</td></tr>";
  676. // Tritanium
  677. reshtml += "<tr><td class='ResName' align='right'>Trit</td>";
  678. reshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.tritanium) + ";'>" + planet.tritanium + "&nbsp;" + "</td>";
  679. reshtml += "<td class='ResGrd'align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundtritanium) + ";'><b> /&nbsp;" + planet.groundtritanium + "</b></td>";
  680. reshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densitytritanium) + ";'>" + planet.densitytritanium + "%</td>";
  681. reshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundtritanium, planet.densitytritanium) + "</td></tr>";
  682. // Molybdenum
  683. reshtml += "<tr><td class='ResName' align='right'>Moly</td>";
  684. reshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.molybdenum) + ";'>" + planet.molybdenum + "&nbsp;" + "</td>";
  685. reshtml += "<td class='ResGrd'align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundmolybdenum) + ";'><b> /&nbsp;" + planet.groundmolybdenum + "</b></td>";
  686. reshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densitymolybdenum) + ";'>" + planet.densitymolybdenum + "%</td>";
  687. reshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundmolybdenum, planet.densitymolybdenum) + "</td></tr>";
  688. reshtml += "</table>";
  689. // Assemble the row : also had id='PLRow' class='RowSelect'
  690. html = "<tr class='PLRow'> \
  691. <td>" + plpinfhtml + "</td> \
  692. <td>" + bmhtml + "</td> \
  693. <td>" + pophtml + "</td> \
  694. <td>" + taxhtml + "</td> \
  695. <td>" + mcsuphtml + "</td> \
  696. <td>" + bldghtml + "</td> \
  697. <td>" + reshtml + "</td></tr>";
  698. }
  699. $(html).appendTo("#PlanetRows");
  700. }
  701. //html = "</table><br><table id='GMATable' border='0' width='100%'>";
  702. html = "<tr><td colspan = 7><h3>Global Method Application</h3></td></tr>";
  703. html += "<tr><td colspan = 7 id='warntext'>Warning: Applying a method globally will overwrite any existing method assignments.</td></tr>";
  704. html += "<tr><td colspan = 2>" + mrevhtml + "</td>";
  705. html += "<td colspan = 2>" + ctmrevhtml + "</td>";
  706. html += "<td colspan = 2>" + ntmrevhtml + "</td></tr>";
  707. $(html).appendTo("#PlanetRows");
  708. $('.PLInfoTable').click(function() {
  709. plg.showPlanetDetail(($(this).attr('data-plid')));
  710. });
  711. $('body').delegate('.FCDisp','click',function() {
  712. console.log("FCDISP CLICKED!!!");
  713. this.curplanet = ($(this).attr('data-plid'));
  714. var planet = vgap.getPlanet(this.curplanet);
  715. vgap.planetScreen.load(planet);
  716. vgap.planetScreen.randomFC();
  717. var identifier = "#FCDisp_" + planet.id;
  718. console.log("SELECTOR: " + identifier);
  719. $(identifier).replaceWith("<td class=FCDisp data-plid='" + planet.id + "' id='FCDisp_" + planet.id + "' align='center' width='30px' style='border: solid white 1px; color: #0000A0; background-color: " + vgap.plugins["plManagerPlugin"].getFCColor(planet.friendlycode) + ";'><b>" + planet.friendlycode + "</b></td>");
  720. });
  721. $('#RandomizeFCsCheck').click(function () {
  722. console.log("Randomize FCs CLICKED");
  723. if (plg.fcrandomize == true)
  724. plg.fcrandomize = false;
  725. else
  726. plg.fcrandomize = true;
  727. if (debug) console.log("FC Randomize is now: " + plg.fcrandomize);
  728. });
  729. $('.BuildButton').click(function() {
  730. plg.executePlanetUpdate();
  731. });
  732. $('.BMSelect').each(function() {
  733. $(this).val(plg.bmarray[$(this).attr('data-plid')]);
  734. });
  735. $('.BMSelect').change(function() {
  736. plg.bmarray[$(this).attr('data-plid')] = $(this).attr('value');
  737. plg.saveObjectAsNote(0, plg.notetype, [plugin_version,plg.bmarray]);
  738. });
  739. $('.CTSelect').each(function() {
  740. $(this).val(plg.ctarray[$(this).attr('data-plid')]);
  741. });
  742. $('.CTSelect').change(function() {
  743. //console.log("CT CHANGED!");
  744. plg.ctarray[$(this).attr('data-plid')] = $(this).attr('value');
  745. plg.saveObjectAsNote(2, plg.notetype, [plugin_version,plg.ctarray]);
  746. });
  747. $('.NTSelect').each(function() {
  748. $(this).val(plg.ntarray[$(this).attr('data-plid')]);
  749. });
  750. $('.NTSelect').change(function() {
  751. //console.log("NT CHANGED!");
  752. plg.ntarray[$(this).attr('data-plid')] = $(this).attr('value');
  753. plg.saveObjectAsNote(1, plg.notetype, [plugin_version,plg.ntarray]);
  754. });
  755. $('#BMGApplyBtn').click(function() {
  756. var bmind = $('#BMGSelect').val();
  757. // Apply the method
  758. for (var i = 0; i < plg.parray.length; i++) {
  759. plg.bmarray[plg.parray[i].id] = bmind;
  760. }
  761. plg.saveObjectAsNote(0, plg.notetype, [plugin_version,plg.bmarray]);
  762. plg.displayPM(0);
  763. });
  764. $('#CTMGApplyBtn').click(function() {
  765. var bmind = $('#CTMGSelect').val();
  766. // Apply the method
  767. for (var i = 0; i < plg.parray.length; i++) {
  768. plg.ctarray[plg.parray[i].id] = bmind;
  769. }
  770. plg.saveObjectAsNote(2, plg.notetype, [plugin_version,plg.ctarray]);
  771. plg.displayPM(0);
  772. });
  773. $('#NTMGApplyBtn').click(function() {
  774. var bmind = $('#NTMGSelect').val();
  775. // Apply the method
  776. for (var i = 0; i < plg.parray.length; i++) {
  777. if (plg.parray[i].nativeclans > 0)
  778. plg.ntarray[plg.parray[i].id] = bmind;
  779. }
  780. plg.saveObjectAsNote(1, plg.notetype, [plugin_version,plg.ntarray]);
  781. plg.displayPM(0);
  782. });
  783. }
  784. if (view == 1) {
  785. html += "<br /><table border='0' width='100%'>";
  786. if (this.curplanet < 1) {
  787. html += "<tr><td>No planet selected.</td>";
  788. html += "</tr></table><br /></div>";
  789. }
  790. if (this.curplanet >= 1) {
  791. //console.log("IN VIEW 1: inside of range: curplanet = " + this.curplanet);
  792. var planet = vgap.getPlanet(this.curplanet);
  793. // Set up planet info table
  794. var pinfohtml = "";
  795. pinfohtml += "<table id=InfoTable border='0' width='100%'>";
  796. pinfohtml += "<tr><td><h1><b>" + planet.name + "</b></h1></td></tr>";
  797. pinfohtml += "<tr><td><h3><b>ID#:&nbsp;" + planet.id + "</b></h3></td></tr>";
  798. pinfohtml += "<tr><td><h3><b>Temperature:&nbsp;" + planet.temp + "</b></h3></td></tr>";
  799. pinfohtml += "<tr></tr>";
  800. pinfohtml += "<tr><td><h3><b>Megacredits:&nbsp;" + planet.megacredits + "</b></h3></td></tr>";
  801. pinfohtml += "<tr><td><h3><b>Supplies:&nbsp;" + planet.supplies + "</b></h3></td></tr>";
  802. pinfohtml += "</table>";
  803. // Set up building info table
  804. var bldghtml = "";
  805. bldghtml += "<table id=BldgTable border='0' width='100%' style='font-size: 15px;'>";
  806. bldghtml += "<thead><tr><th colspan=4 align=left style='font-size: 20px;'>Buildings</th></tr></thead>";
  807. bldghtml += "<tr><td rowspan = 1 width=75 height=50>" + "<img src='http://play.planets.nu/img/icons/factory.png' height='50' width='50'></img>" + "</td>";
  808. bldghtml += "<td class=PMBldgCnt rowspan = 1 align=right>" + planet.factories + "&nbsp;</td>";
  809. bldghtml += "<td class=PMBldgMax align=left><b>&nbsp;/&nbsp;</b>" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,100) + "</td>";
  810. bldghtml += "<td class=PMBldgBlt >[+" + planet.builtfactories + "]</td></tr>";
  811. bldghtml += "<tr><td rowspan = 1 width=75 height=50>" + "<img src='http://play.planets.nu/img/icons/mine.png' height='50' width='50'></img>" + "</td>";
  812. bldghtml += "<td class=PMBldgCnt rowspan = 1 align=right>" + planet.mines + "&nbsp;</td>";
  813. bldghtml += "<td class=PMBldgMax align=left><b>&nbsp;/&nbsp;</b>" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,200) + "</td>";
  814. bldghtml += "<td class=PMBldgBlt >[+" + planet.builtmines + "]</td></tr>";
  815. bldghtml += "<tr><td rowspan = 1 width=75 height=50>" + "<img src='http://play.planets.nu/img/icons/defense.png' height='50' width='50'></img>" + "</td>";
  816. bldghtml += "<td class=PMBldgCnt rowspan = 1 align=right>" + planet.defense + "&nbsp;</td>";
  817. bldghtml += "<td class=PMBldgMax align=left><b>&nbsp;/&nbsp;</b>" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,50) + "</td>";
  818. bldghtml += "<td class=PMBldgBlt >[+" + planet.builtdefense + "]</td></tr>";
  819. bldghtml += "</table>";
  820. // Set up the population info table
  821. var pophtml = "";
  822. pophtml += "<table id=PopulationTable border='0' width='100%' style='font-size: 15px;'>";
  823. pophtml += "<thead><tr><th colspan=2 align=left style='font-size: 20px;'>Population</th></tr></thead>";
  824. if (planet.clans > 0) {
  825. pophtml += "<tr><td rowspan = 4><img width='150' height='150' src='http://play.planets.nu/img/races/1.jpg'/></td>";
  826. pophtml += "<td class=PMColTag valign='bottom' rowspan = 1 align = 'left' style='font-size: 15px;'>Colonists: </td>";
  827. if (plg.myColPopGrowth(planet,false) < 0)
  828. pophtml += "<td class='PMColVal' valign='bottom'><span class='BadText'>" + plg.nwc(planet.clans * 100) + "</span></td>";
  829. else if (planet.clans > plg.getMaxColonists(planet,false))
  830. pophtml += "<td class='PMColVal' valign='bottom'><span class='WarnText'>" + plg.nwc(planet.clans * 100) + "</span></td>";
  831. else
  832. pophtml += "<td class='PMColVal' valign='bottom'><span class='NormalText'>" + plg.nwc(planet.clans * 100) + "</span></td>";
  833. pophtml += "<td class=PMColMaxVal valign='bottom'>(" + plg.nwc(plg.getMaxColonists(planet,false)*100) + ")</td>";
  834. pophtml += "<td class=PMColExtra valign='bottom'>[+" + plg.nwc(plg.myColPopGrowth(planet,false)*100) + "]</td></tr>";
  835. pophtml += "<tr><td class=PMColTag valign='bottom'>Tax Rate:</td>";
  836. pophtml += "<td class=PMColVal valign='bottom'>" + planet.colonisttaxrate + "%</td>";
  837. pophtml += "<td class=PMColExtra valign='bottom'>" + plg.colTaxAmtTxt(planet) + "</td></tr>";
  838. pophtml += "<tr><td class=PMColTag valign='top'>Happiness:</td>";
  839. pophtml += "<td class=PMColVal valign='top'>" + planet.colonisthappypoints + "</td>";
  840. pophtml += "<td class=PMColExtra valign='top'>" + plg.happyChgTxt(vgap.colonistTaxChange(planet)) + "</td></tr>";
  841. }
  842. else
  843. pophtml += "<tr><td></td><td></td></tr>";
  844. pophtml += "<tr><td></td><td></td></tr>";
  845. pophtml += "<tr><td></td><td></td></tr>";
  846. if (planet.nativeclans > 0) {
  847. pophtml += "<tr><td rowspan = 5><img width='150' height='150' src='http://play.planets.nu/img/natives/" + planet.nativetype + ".gif'/></td>";
  848. pophtml += "<td class=PMColTag valign='bottom' rowspan = 1 align = 'left'>Natives:</td>";
  849. if (plg.myNatPopGrowth(planet,false) < 0)
  850. pophtml += "<td class='PMColVal' valign='bottom'><span class='BadText'>" + plg.nwc(planet.nativeclans * 100) + "</span></td>";
  851. else if (planet.nativeclans > plg.getMaxNatives(planet,false))
  852. pophtml += "<td class='PMColVal' valign='bottom'><span class='WarnText'>" + plg.nwc(planet.nativeclans * 100) + "</span></td>";
  853. else
  854. pophtml += "<td class='PMColVal' valign='bottom'>" + plg.nwc(planet.nativeclans * 100) + "</td>";
  855. pophtml += "<td class=PMColMaxVal valign='bottom'>(" + plg.nwc(plg.getMaxNatives(planet)*100) + ")</td>";
  856. pophtml += "<td class=PMColExtra valign='bottom'>[" + plg.nwc(plg.myNatPopGrowth(planet,false)*100) + "]</td></tr>";
  857. pophtml += "<tr><td class=PMColTag valign='top' rowspan = 1 align = 'left'>" + planet.nativeracename + "&nbsp;-&nbsp;" + planet.nativegovernmentname + "</td></tr>";
  858. pophtml += "<tr><td class=PMColTag valign='bottom'>Tax Rate:</td>";
  859. pophtml += "<td class=PMColVal valign='bottom'>" + planet.nativetaxrate + "%</td>";
  860. pophtml += "<td class=PMColExtra valign='bottom'>" + plg.natTaxAmtTxt(planet) + "</td></tr>";
  861. pophtml += "<tr><td class=PMColTag valign='top'>Happiness:</td>";
  862. pophtml += "<td class=PMColVal valign='top'>" + planet.nativehappypoints + "</td>";
  863. pophtml += "<td class=PMColExtra valign='top'>" + plg.happyChgTxt(vgap.nativeTaxChange(planet)) + "</td></tr>";
  864. }
  865. else
  866. pophtml += "<tr><td></td><td></td></tr>";
  867. pophtml += "</table>";
  868. // Set up the resources table
  869. var reshtml = "";
  870. reshtml += "<table id=PMResTable>";
  871. //reshtml += "<thead></thead>";
  872. reshtml += "<thead><tr><th colspan=5 align=left style='font-size: 20px;'>Resources</th><th width=100px>Turns to Mine Out</th>";
  873. reshtml += "<th align=left style='font-size: 20px;' rowspan = 5>What If There Were:</th><th colspan = 2>20 Mines</th><th colspan = 2>50 Mines</th><th colspan = 2>100 Mines</th><th colspan = 2>200 Mines</th></tr></thead>";
  874. // Neutronium
  875. reshtml += "<tr><td class='PMResName' align='right'>Neutronium</td>";
  876. reshtml += "<td class='PMResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.neutronium) + ";'>" + planet.neutronium + "&nbsp;" + "</td>";
  877. reshtml += "<td class='PMResGrd' align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundneutronium) + ";'><b> /&nbsp;" + planet.groundneutronium + "</b></td>";
  878. reshtml += "<td class='PMResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densityneutronium) + ";'>" + planet.densityneutronium + "%</td>";
  879. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundneutronium, planet.densityneutronium) + "</td>";
  880. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOut(planet, planet.groundneutronium, planet.densityneutronium) + "</td>";
  881. reshtml += "<td></td>";
  882. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundneutronium, planet.densityneutronium,20) + "</td>";
  883. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundneutronium, planet.densityneutronium,20) + "</td>";
  884. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundneutronium, planet.densityneutronium,50) + "</td>";
  885. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundneutronium, planet.densityneutronium,50) + "</td>";
  886. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundneutronium, planet.densityneutronium,100) + "</td>";
  887. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundneutronium, planet.densityneutronium,100) + "</td>";
  888. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundneutronium, planet.densityneutronium,200) + "</td>";
  889. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundneutronium, planet.densityneutronium,200) + "</td>";
  890. reshtml += "</tr>";
  891. // Duranium
  892. reshtml += "<tr><td class='PMResName' align='right'>Duranium</td>";
  893. reshtml += "<td class='PMResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.duranium) + "; padding-left=0.5ex'>" + planet.duranium + "&nbsp;" + "</td>";
  894. reshtml += "<td class='PMResGrd' align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundduranium) + ";'><b> /&nbsp;" + planet.groundduranium + "</b></td>";
  895. reshtml += "<td class='PMResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densityduranium) + ";'>" + planet.densityduranium + "%</td>";
  896. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundduranium, planet.densityduranium) + "</td>";
  897. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOut(planet, planet.groundduranium, planet.densityduranium) + "</td>";
  898. reshtml += "<td></td>";
  899. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundduranium, planet.densityduranium,20) + "</td>";
  900. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundduranium, planet.densityduranium,20) + "</td>";
  901. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundduranium, planet.densityduranium,50) + "</td>";
  902. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundduranium, planet.densityduranium,50) + "</td>";
  903. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundduranium, planet.densityduranium,100) + "</td>";
  904. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundduranium, planet.densityduranium,100) + "</td>";
  905. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundduranium, planet.densityduranium,200) + "</td>";
  906. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundduranium, planet.densityduranium,200) + "</td>";
  907. reshtml += "</tr>";
  908. // Tritanium
  909. reshtml += "<tr><td class='PMResName' align='right'>Tritanium</td>";
  910. reshtml += "<td class='PMResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.tritanium) + ";'>" + planet.tritanium + "&nbsp;" + "</td>";
  911. reshtml += "<td class='PMResGrd'align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundtritanium) + ";'><b> /&nbsp;" + planet.groundtritanium + "</b></td>";
  912. reshtml += "<td class='PMResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densitytritanium) + ";'>" + planet.densitytritanium + "%</td>";
  913. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundtritanium, planet.densitytritanium) + "</td>";
  914. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOut(planet, planet.groundtritanium, planet.densitytritanium) + "</td>";
  915. reshtml += "<td></td>";
  916. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundtritanium, planet.densitytritanium,20) + "</td>";
  917. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundtritanium, planet.densitytritanium,20) + "</td>";
  918. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundtritanium, planet.densitytritanium,50) + "</td>";
  919. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundtritanium, planet.densitytritanium,50) + "</td>";
  920. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundtritanium, planet.densitytritanium,100) + "</td>";
  921. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundtritanium, planet.densitytritanium,100) + "</td>";
  922. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundtritanium, planet.densitytritanium,200) + "</td>";
  923. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundtritanium, planet.densitytritanium,200) + "</td>";
  924. reshtml += "</tr>";
  925. // Molybdenum
  926. reshtml += "<tr><td class='PMResName' align='right'>Molybdenum</td>";
  927. reshtml += "<td class='PMResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.molybdenum) + ";'>" + planet.molybdenum + "&nbsp;" + "</td>";
  928. reshtml += "<td class='PMResGrd'align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundmolybdenum) + ";'><b> /&nbsp;" + planet.groundmolybdenum + "</b></td>";
  929. reshtml += "<td class='PMResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densitymolybdenum) + ";'>" + planet.densitymolybdenum + "%</td>";
  930. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundmolybdenum, planet.densitymolybdenum) + "</td>";
  931. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOut(planet, planet.groundmolybdenum, planet.densitymolybdenum) + "</td>";
  932. reshtml += "<td></td>";
  933. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,20) + "</td>";
  934. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,20) + "</td>";
  935. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,50) + "</td>";
  936. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,50) + "</td>";
  937. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,100) + "</td>";
  938. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,100) + "</td>";
  939. reshtml += "<td class='PMMineOutAmt'>" + vgap.plugins["plManagerPlugin"].turnsToMineOutTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,200) + "</td>";
  940. reshtml += "<td class='PMResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurnTheoretical(planet, planet.groundmolybdenum, planet.densitymolybdenum,200) + "</td>";
  941. reshtml += "</tr>";
  942. reshtml += "</table>";
  943. // Call the planet predictor
  944. plg.planetPredictor(planet, 0, 49);
  945. // Construct the predictor table
  946. // Set up the predictor header area
  947. var predhdrhtml = "<div id='PredHdr'><p><h2><b>Planet Predictor<b></h2></p><br />";
  948. predhdrhtml += "<p>Under the selected building and taxation plans, this planet will:<br /><ul>";
  949. if (vgap.getStarbase(planet.id) != null)
  950. predhdrhtml += "<li>This planet already has a starbase.</li>";
  951. else {
  952. if (plg.predicttimes.ttSB == -1)
  953. predhdrhtml += "<li>Not be able to build a starbase in the next 50 turns.</li>";
  954. else
  955. predhdrhtml += "<li>Be able to build a starbase in <span class='predictval'>" + plg.predicttimes.ttSB + "</span> turns.</li>";
  956. }
  957. if (plg.predicttimes.ttMaxCols == -1)
  958. predhdrhtml += "<li>Not be able to reach maximum colonists in the next 50 turns.</li>";
  959. else
  960. predhdrhtml += "<li>Reach maximum colonists in <span class='PredictVal'>" + plg.predicttimes.ttMaxCols + "</span> turns.</li>";
  961. if (planet.nativeclans > 0) {
  962. //var player = vgap.getPlayer(plg.pplanet.ownerid);
  963. //if (vgap.player.raceid == 6 && plg.pplanet.nativeclans > 0)
  964. if (vgap.player.raceid == 6)
  965. predhdrhtml += "<li>Assimilate all natives in <span class='PredictVal'>" + plg.getAssimTurns(planet) + "</span> turns.</li>";
  966. else if (plg.predicttimes.ttMaxNats == -1)
  967. predhdrhtml += "<li>Not be able to reach maximum natives in the next 50 turns.</li>";
  968. else
  969. predhdrhtml += "<li>Reach maximum natives in <span class='PredictVal'>" + plg.predicttimes.ttMaxNats + "</span> turns.</li>";
  970. }
  971. if (plg.predicttimes.ttNMO == -1)
  972. predhdrhtml += "<li>Not mine out neutronium in the next 50 turns.</li>";
  973. else
  974. predhdrhtml += "<li>Mine out neutronium in <span class='PredictVal'>" + plg.predicttimes.ttNMO + "</span> turns.</li>";
  975. if (plg.predicttimes.ttDMO == -1)
  976. predhdrhtml += "<li>Not mine out duranium in the next 50 turns.</li>";
  977. else
  978. predhdrhtml += "<li>Mine out duranium in <span class='PredictVal'>" + plg.predicttimes.ttDMO + "</span> turns.</li>";
  979. if (plg.predicttimes.ttTMO == -1)
  980. predhdrhtml += "<li>Not mine out tritanium in the next 50 turns.</li>";
  981. else
  982. predhdrhtml += "<li>Mine out tritanium in <span class='PredictVal'>" + plg.predicttimes.ttTMO + "</span> turns.</li>";
  983. if (plg.predicttimes.ttMMO == -1)
  984. predhdrhtml += "<li>Not mine out molybdenum in the next 50 turns.</li>";
  985. else
  986. predhdrhtml += "<li>Mine out molybdenum in <span class='PredictVal'>" + plg.predicttimes.ttMMO + "</span> turns.</li>";
  987. predhdrhtml += "</ul></p><br /></div>";
  988. // Set up the planet information table
  989. var predhtml = "<table id = 'predtable'>";
  990. for (var i = 0; i < plg.predictarray.length; i++) {
  991. if (i == 0)
  992. predhtml += "<tr><td colspan = 5><b>Now</td></tr>";
  993. else if (i == 1)
  994. predhtml += "<tr><td colspan = 5><b>In&nbsp;" + i + " Turn</td></tr>";
  995. else
  996. predhtml += "<tr><td colspan = 5><b>In&nbsp;" + i + " Turns</td></tr>";
  997. var planet = plg.predictarray[i];
  998. var base = vgap.getStarbase(planet.id) != null ? "X" : "";
  999. var pdppinfhtml = "";
  1000. pdppinfhtml += "<table class=PLInfoTable data-plid='" + planet.id + "' border='0' width='100%'>";
  1001. pdppinfhtml += "<thead></thead>";
  1002. pdppinfhtml += "<tr> \
  1003. <td rowspan = 3><img class='TinyIcon' src='" + planet.img + "'/></td> \
  1004. <td class='PLName' rowspan = 1 colspan = 2><b>" + planet.name + "</b></td></tr>";
  1005. pdppinfhtml += "<tr><td class='PLInfTag' rowspan = 1>ID#:&nbsp;</td> \
  1006. <td class='PLInfVal'>" + planet.id + "</td></tr>";
  1007. pdppinfhtml += "<tr><td class='PLInfTag' rowspan = 1>Temp:&nbsp;</td> \
  1008. <td class='PLInfVal'>" + planet.temp + "</td></tr>";
  1009. pdppinfhtml += "</table>";
  1010. // Set up the building method table
  1011. var pdppbmhtml = "";
  1012. pdppbmhtml += "<table class=PLBMTable>";
  1013. pdppbmhtml += "<thead></thead>";
  1014. pdppbmhtml += "<tr><td>Build Method:</td> \
  1015. <td>";
  1016. var pdppbm = plg.bmarray[plg.pplanet.id];
  1017. if (pdppbm == 'm')
  1018. pdppbmhtml += "Manual";
  1019. else
  1020. pdppbmhtml += plg.buildmethods[pdppbm][0];
  1021. pdppbmhtml += "</td></tr>";
  1022. pdppbmhtml += "<tr><td>Colonist Tax:</td> \
  1023. <td>";
  1024. var pdppcti = plg.ctarray[plg.pplanet.id];
  1025. if (pdppcti == 'm')
  1026. pdppbmhtml += "Manual";
  1027. else
  1028. pdppbmhtml += plg.taxmethods[pdppcti].name;
  1029. pdppbmhtml += "</td></tr>";
  1030. if (planet.nativeclans > 0) {
  1031. pdppbmhtml += "<tr><td>Native Tax:</td> \
  1032. <td>";
  1033. var pdppnti = plg.ntarray[plg.pplanet.id];
  1034. if (pdppnti == 'm')
  1035. pdppbmhtml += "Manual";
  1036. else
  1037. pdppbmhtml += plg.taxmethods[pdppnti].name;
  1038. pdppbmhtml += "</td></tr>";
  1039. }
  1040. pdppbmhtml += "</table>";
  1041. // Set up the population table
  1042. var pdpppophtml = "";
  1043. pdpppophtml += "<table class=PLPopTable>";
  1044. pdpppophtml += "<thead></thead>";
  1045. pdpppophtml += "<tr><td class='PLPopTag'>Colonists:</td>";
  1046. if (plg.myColPopGrowth(planet,false) < 0)
  1047. pdpppophtml += "<td class='PLPopVal'><span class='BadText'>" + plg.nwc(planet.clans * 100) + "</span></td></tr>";
  1048. else if (planet.clans > plg.getMaxColonists(planet,false))
  1049. pdpppophtml += "<td class='PLPopVal'><span class='WarnText'>" + plg.nwc(planet.clans * 100) + "</span></td></tr>";
  1050. else
  1051. pdpppophtml += "<td class='PLPopVal'><span class='NormalText'>" + plg.nwc(planet.clans * 100) + "</span></td></tr>";
  1052. if (planet.nativeclans > 0) {
  1053. //console.log("Native Name: " + planet.nativeracename + " , Native Type: " + planet.nativetype);
  1054. pdpppophtml += "<tr><td class='PLPopTag'>Natives:</td>";
  1055. if (plg.myNatPopGrowth(planet,false) < 0)
  1056. pdpppophtml += "<td class='PLPopVal'><span class='BadText'>" + plg.nwc(planet.nativeclans * 100) + "</span></td></tr>";
  1057. else if (planet.nativeclans > plg.getMaxNatives(planet,false))
  1058. pdpppophtml += "<td class='PLPopVal'><span class='WarnText'>" + plg.nwc(planet.nativeclans * 100) + "</span></td></tr>";
  1059. else
  1060. pdpppophtml += "<td class='PLPopVal'>" + plg.nwc(planet.nativeclans * 100) + "</td></tr>";
  1061. pdpppophtml += "<tr><td align='center' rowspan = 2><img width='35' height='35' src='http://play.planets.nu/img/natives/" + planet.nativetype + ".gif'/></td>";
  1062. pdpppophtml += "<td class='PLPopVal'>" + planet.nativeracename + "</td></tr>";
  1063. pdpppophtml += "<tr><td class='PLPopVal'>" + planet.nativegovernmentname + "</td></tr>";
  1064. }
  1065. else {
  1066. pdpppophtml += "<tr><td></td></tr>";
  1067. pdpppophtml += "<tr><td></td></tr>";
  1068. pdpppophtml += "<tr><td></td></tr>";
  1069. }
  1070. pdpppophtml += "</table>";
  1071. // Set up the tax table
  1072. var pdpptaxhtml = "";
  1073. pdpptaxhtml += "<table class=PLTaxTable>";
  1074. pdpptaxhtml += "<thead></thead>";
  1075. pdpptaxhtml += "<tr><td>Tax Rate:</td>";
  1076. pdpptaxhtml += "<td class='BldgCnt'>" + planet.colonisttaxrate + "%</td>";
  1077. pdpptaxhtml += "<td class='BldgBlt'>" + plg.colTaxAmtTxt(planet) + "</td></tr>";
  1078. pdpptaxhtml += "<tr><td>Happiness:</td>";
  1079. pdpptaxhtml += "<td class='BldgCnt'>" + planet.colonisthappypoints + "</td>";
  1080. pdpptaxhtml += "<td class='PLHappyChg'>" + plg.happyChgTxt(vgap.colonistTaxChange(planet)) + "</td></tr>";
  1081. if (planet.nativeclans > 0) {
  1082. pdpptaxhtml += "<tr><td>Tax Rate:</td>";
  1083. pdpptaxhtml += "<td class='BldgCnt'>" + planet.nativetaxrate + "%</td>";
  1084. pdpptaxhtml += "<td class='BldgBlt'>" + plg.natTaxAmtTxt(planet) + "</td></tr>";
  1085. pdpptaxhtml += "<tr><td>Happiness:</td>";
  1086. pdpptaxhtml += "<td class='BldgCnt'>" + planet.nativehappypoints + "</td>";
  1087. pdpptaxhtml += "<td class='PLHappyChg'>" + plg.happyChgTxt(vgap.nativeTaxChange(planet)) + "</td></tr>";
  1088. }
  1089. else {
  1090. pdpptaxhtml += "<tr><td></td></tr>";
  1091. pdpptaxhtml += "<tr><td></td></tr>";
  1092. }
  1093. pdpptaxhtml += "</table>";
  1094. // Set up the megacredits/supply table
  1095. var pdppmcsuphtml = "";
  1096. pdppmcsuphtml += "<table class=PLMCSupTable>";
  1097. pdppmcsuphtml += "<thead></thead>";
  1098. pdppmcsuphtml += "<tr><td>Megacredits:&nbsp;<b>" + planet.megacredits + "</b></td></tr>";
  1099. pdppmcsuphtml += "<tr><td>Supplies:&nbsp;<b>" + planet.supplies + "</b></td></tr>";
  1100. pdppmcsuphtml += "</table>";
  1101. // Set up the buildings table
  1102. var pdppbldghtml = "";
  1103. pdppbldghtml += "<table class=PLBldgTable>";
  1104. pdppbldghtml += "<thead></thead>";
  1105. // Factories
  1106. pdppbldghtml += "<tr><td>" + "<img src='http://play.planets.nu/img/icons/factory.png' height='25' width='25'></img>" + "</td>";
  1107. pdppbldghtml += "<td class='BldgCnt'>" + planet.factories + "</td>";
  1108. pdppbldghtml += "<td class='BldgMax'>/&nbsp;" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,100) + "</td></tr>";
  1109. //pdppbldghtml += "<td class='BldgBlt'>[+" + planet.builtfactories + "]</td></tr>";
  1110. // Mines
  1111. pdppbldghtml += "<tr><td>" + "<img src='http://play.planets.nu/img/icons/mine.png' height='25' width='25'></img>" + "</td>";
  1112. pdppbldghtml += "<td class='BldgCnt'>" + planet.mines + "</td>";
  1113. pdppbldghtml += "<td class='BldgMax'>/&nbsp;" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,200) + "</td></tr>";
  1114. //pdppbldghtml += "<td class='BldgBlt'>[+" + planet.builtmines + "]</td></tr>";
  1115. // Defense Posts
  1116. pdppbldghtml += "<tr><td>" + "<img src='http://play.planets.nu/img/icons/defense.png' height='25' width='25'></img>" + "</td>";
  1117. pdppbldghtml += "<td class='BldgCnt'>" + planet.defense + "</td>";
  1118. pdppbldghtml += "<td class='BldgMax'>/&nbsp;" + vgap.plugins["plManagerPlugin"].maxBldgs(planet,50) + "</td></tr>";
  1119. //pdppbldghtml += "<td class='BldgBlt'>[+" + planet.builtdefense + "]</td></tr>";
  1120. pdppbldghtml += "</table>";
  1121. // Set up the Resources Table
  1122. var pdppreshtml = "";
  1123. pdppreshtml += "<table class=PLResTable>";
  1124. pdppreshtml += "<thead></thead>";
  1125. // Neutronium
  1126. pdppreshtml += "<tr><td class='ResName' align='right'>Neu</td>";
  1127. pdppreshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.neutronium) + ";'>" + planet.neutronium + "&nbsp;" + "</td>";
  1128. pdppreshtml += "<td class='ResGrd' align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundneutronium) + ";'><b> /&nbsp;" + planet.groundneutronium + "</b></td>";
  1129. pdppreshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densityneutronium) + ";'>" + planet.densityneutronium + "%</td>";
  1130. pdppreshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundneutronium, planet.densityneutronium) + "</td></tr>";
  1131. // Duranium
  1132. pdppreshtml += "<tr><td class='ResName' align='right'>Dur</td>";
  1133. pdppreshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.duranium) + "; padding-left=0.5ex'>" + planet.duranium + "&nbsp;" + "</td>";
  1134. pdppreshtml += "<td class='ResGrd' align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundduranium) + ";'><b> /&nbsp;" + planet.groundduranium + "</b></td>";
  1135. pdppreshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densityduranium) + ";'>" + planet.densityduranium + "%</td>";
  1136. pdppreshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundduranium, planet.densityduranium) + "</td></tr>";
  1137. // Tritanium
  1138. pdppreshtml += "<tr><td class='ResName' align='right'>Trit</td>";
  1139. pdppreshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.tritanium) + ";'>" + planet.tritanium + "&nbsp;" + "</td>";
  1140. pdppreshtml += "<td class='ResGrd'align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundtritanium) + ";'><b> /&nbsp;" + planet.groundtritanium + "</b></td>";
  1141. pdppreshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densitytritanium) + ";'>" + planet.densitytritanium + "%</td>";
  1142. pdppreshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundtritanium, planet.densitytritanium) + "</td></tr>";
  1143. // Molybdenum
  1144. pdppreshtml += "<tr><td class='ResName' align='right'>Moly</td>";
  1145. pdppreshtml += "<td class='ResSfc' align='right' style='color: " + vgap.plugins["plManagerPlugin"].getMineralSfcColor(planet.molybdenum) + ";'>" + planet.molybdenum + "&nbsp;" + "</td>";
  1146. pdppreshtml += "<td class='ResGrd'align='left' style='color: " + vgap.plugins["plManagerPlugin"].getMineralGrdColor(planet.groundmolybdenum) + ";'><b> /&nbsp;" + planet.groundmolybdenum + "</b></td>";
  1147. pdppreshtml += "<td class='ResDen' style='color: " + vgap.plugins["plManagerPlugin"].getMineralDenColor(planet.densitymolybdenum) + ";'>" + planet.densitymolybdenum + "%</td>";
  1148. pdppreshtml += "<td class='ResAmt'>" + vgap.plugins["plManagerPlugin"].miningAmtPerTurn(planet, planet.groundmolybdenum, planet.densitymolybdenum) + "</td></tr>";
  1149. pdppreshtml += "</table>";
  1150. // Assemble the row : also had id='PLRow' class='RowSelect'
  1151. predhtml += "<tr class='PLRow'> \
  1152. <td>" + pdppinfhtml + "</td> \
  1153. <td>" + pdppbmhtml + "</td> \
  1154. <td>" + pdpppophtml + "</td> \
  1155. <td>" + pdpptaxhtml + "</td> \
  1156. <td>" + pdppmcsuphtml + "</td> \
  1157. <td>" + pdppbldghtml + "</td> \
  1158. <td>" + pdppreshtml + "</td></tr>";
  1159. }
  1160. predhtml += "</table>";
  1161. // Put it all together
  1162. html += "<table>";
  1163. html += "<tr><td id=pdimg rowspan = 2 width=350 height=350 style='cursor:pointer;'><img align=center width=300px height=300px src='" + planet.img + "'/></td>";
  1164. html += "<td align=left style='vertical-align: top;'>" + pinfohtml + "</td><td rowspan = 2 style='vertical-align: top;'>" + pophtml + "<td></td>";
  1165. html += "</tr>";
  1166. html += "<tr><td width=300>" + bldghtml + "</td><td></td></tr>";
  1167. html += "<tr><td colspan = 3>" + reshtml + "</td></tr>";
  1168. html += "<tr><td colspan = 3>" + predhdrhtml + "</td></tr>";
  1169. html += "<tr><td colspan = 3>" + predhtml + "</td></tr>";
  1170. html += "</table><br /></div>";
  1171. }
  1172. this.pane = $(html).appendTo(vgap.dash.content);
  1173. $('#pdimg').click(function() {
  1174. vgap.map.selectPlanet(planet.id);
  1175. //plg.showPlanetDetail(($(this).attr('data-plid')));
  1176. });
  1177. }
  1178. if (view == 2) {
  1179. html += "<br /><table border='0' width='100%'>";
  1180. html += "<tr><td>";
  1181. html += "<h1>Planetary Management v" + plugin_version + "</h1><br />";
  1182. html += "<h4><i><b>by dotman</b></i></h4><br/>";
  1183. html += "<h2>Introduction</h2><p>Managing your planets to their maximum potential can be a time-consuming and confusing endeavour. This plugin was created to aid \
  1184. you in this task. You may create your \
  1185. own planet build methods and taxation strategies. You can, for each planet, select a build method that determines how buildings are to be constructed, as well as \
  1186. select taxing methods for both your colonists and natives. Each turn, and again if you make any changes, you must click the planet icon to apply all of your changes. \
  1187. Finally, you can use the Planet Predictor in the planet detail view, to forecast what impact your chosen strategies will have on the planet over the next 50 turns.</p><br/>";
  1188. html += "<p><iframe width='560' height='315' src='//www.youtube.com/embed/3wlie1DMTcc' frameborder='0' allowfullscreen></iframe></iframe></p>";
  1189. html += "<p><h2>Planetary Management View</h2></p> \
  1190. <p>The planetary management view contains a list of all of the planets currently owned by you. Here you select construction methods and taxation strategies \
  1191. to apply to these planets turn after turn. Your selections are remembered from turn to turn, but you must click the small planet icon each turn to apply the \
  1192. methods. This way you can spend a little time thinking about what you want this planet to do for you when you first colonize it, and then continually apply \
  1193. that strategy turn after turn, without having to think about or calculate the nitty-gritty details each turn, leaving you more time to contemplate your enemies' \
  1194. inevitable demise. The view contains relevant info for each planet, and the method selected. New planets default to 'Manual', which means no method is assigned \
  1195. and the plug-in will take no action with these planets. You can then assign build and taxation methods, or leave it to manual if you prefer to handle this \
  1196. planet on your own. Clicking on the planet's picture will take you to the planet detail view, which contains more information about the planet, as well as the \
  1197. Planet Predictor.</p><br/>";
  1198. html += "<p>With version 1.11, features including filters and global method application were added to the plugin. You can filter planets on the planetary management screen \
  1199. by clicking on one of the available filters, and apply any method to all planets shown on the screen by selecting the method and clicking on the 'Apply to All' button.\
  1200. See the video below for an overview.</p>";
  1201. html += "<p><iframe width='560' height='315' src='//www.youtube.com/embed/rl4owPS9eGk' frameborder='0' allowfullscreen></iframe></p>";
  1202. html += "<p><h2>Planet Detail View</h2></p> \
  1203. <p>The planet detail view contains more information about your planet than can be displayed in the planetary management list view. It contains more information on \
  1204. population, including maximum possible populations for colonists and natives. The resources view tells you the resource situation on the planet right now, and how \
  1205. many more turns it will take to mine all of the given mineral out the planet based on the current number of mines. It also tells you, for reference, how long that \
  1206. would take if you had different amounts of mines on the planet.</p> \
  1207. <p>Below the Resources is the Planet Predictor, which forecasts your planet's development over the next 50 turns based on the building methods and taxation strategies you \
  1208. have selected. At the top, it computes and displays some interesting metrics, such as when the planet will be able to build a starbase, how many turns until \
  1209. populations are maxed out, and mineral mining predictions based on your build and tax strategies. Below that it shows you where the planet will be each turn, if the \
  1210. strategies are applied every turn and the planet is otherwise untouched, for the next 50 turns. You can use the predictor, then, to compare your construction \
  1211. strategies and tax strategies to one another; simply go back to the planetary management list view, change the methods you like, and go back to the detail view to see \
  1212. how your forecast has changed. Some strategies will maximize native growth, some colonist growth, and still others raw output of supplies and megacredits. By \
  1213. selecting different methods and looking at the Planet Predictor, you can see how your selected methods stack up against one another and your goals for this planet.</p><br/>";
  1214. html += "<p><h2>Planetary Construction Method Manager</h2></p> \
  1215. <p>The planetary construction method manager is where you create and remove your planetary structure building strategies. At the top is a list of the current methods \
  1216. available - these are the default methods, and any methods you have created for this game. If you click on a method, it will display text explaining how the method \
  1217. works to you. You can also remove a method here, by selecting the method you'd like to remove and clicking 'Remove Build Method'. The method will be removed \
  1218. immediately, and any planets that you had set to use that build method will revert to manual and will have to be reassigned.</p> \
  1219. <p>To create planetary structure construction methods, you can either use the wizard direct entry box. To use the wizard, you give the method a name, and select or \
  1220. deselect the check box about converting supplies to megacredits, depending on if you want this method to do so or not.</p> \
  1221. <p>Next, select one of the images corresponding to what you want to build. You can build factories, mines, defense posts, or a combination of factories and mines at a \
  1222. ratio. Then fill out the amount box with a whole number. If you select the factories+mines button, you will need to enter the amount of factories, the amount of \
  1223. mines, and select the ratio at which you'd like to build them. After you're happy with your entry, click 'Add to Method', and this piece will be added to your current \
  1224. method in the wizard. You can now select another button, type in a new amount, and add that to the method... so you build up your construction method piece by piece- \
  1225. first build 14 factories, say, then 19 mines, then 15 defense posts. When you're happy with the method, click the 'Create Method' button by the method name. If the \
  1226. method checks out, ie, you entered valid values for all of the fields, the method will be added to your available methods.</p> \
  1227. <p>You may also enter a method by directly entering a build code. The build code is what gets stored behind the scenes, and if you know how it works, you can simply \
  1228. enter one directly. A build code has the following syntax:<br /> <br />\
  1229. (y/n)-(f/m/d/rfm)-Integer-(Int)-(Int)-...<br/><br /> \
  1230. So, for instance, to build 15 factories, and allow supplies to be converted to megacredits, the code would be y-f-15 . To build 15 mines and then 20 defense posts, \
  1231. without converting supplies to megacredits, the code would be n-m-15-d-20 . The 'rfm' key has a slightly different syntax; it stands for ratio-factories-mines, and \
  1232. you have to give it a maximum factory value, a maximum mine value, and the first part of the ratio, ie, 2:1 would be 2, 5:1 would be 5. The ratio is always a ratio to \
  1233. 1, and it must be a whole number. So to build up to 400 factories and 150 mines, at a ratio of 7 factories for every mine, allowing supplies to be converted to \
  1234. megacredits, the code would be y-rfm-400-150-7.</p><br/>";
  1235. html += "<p><iframe width='560' height='315' src='//www.youtube.com/embed/5v52gSlmC6k' frameborder='0' allowfullscreen></iframe></p>";
  1236. html += "<p><h2>Taxation Method Manager</h2></p> \
  1237. <p>The taxation method manager is used to create and remove taxation strategies for both colonists and natives. At the top is a list of the current methods available - \
  1238. these are the default methods, and any methods you have created for this game. If you click on a method, it will display text explaining how the method works to you. \
  1239. You can also remove a method here, by selecting the method you'd like to remove and clicking 'Remove Taxation Method'. The method will be removed immediately, and any \
  1240. planets that you had set to use that taxation method will revert to manual and will have to be reassigned.</p>\
  1241. <p>To create a taxation method, you use the form below the methods. First, you need to give your method a unique name. Next, you select whether this method is to be \
  1242. available for use for colonists, natives, or both; your selection here will decide which methods are available in the drop-down boxes for colonists and natives when \
  1243. assigning a method to a planet.</p> \
  1244. <p>Below that, there are three sections. The first is the main method, and this is the method that will be applied normally. Next is a section for if the population is \
  1245. greater than 6,600,000 clans; this is the population at which normal growth is cut in half, and so if you want to specify a different tax method in that case, you can \
  1246. specify it here; otherwise, you select 'Same as Main Method'. Third is a section for when the population reaches its maximum; if you want to specify a different \
  1247. method in that case, you do so here; otherwise, you select 'Same as Main Method'. Note that if you select this, but the maximum population is actually greater than \
  1248. 6,600,000 clans and you've specified a different method for that portion, that is the method that will actually be applied.</p>\
  1249. <p>Currently there are two choices when defining how a tax method will work - Growth or Safe. Safe tax is designed to tax at the maximum amount possible until the \
  1250. happiness reaches a value that you set, and then continue taxing to maintain that happiness. Growth taxing is designed to tax at the maximum amount possible until the \
  1251. happiness reaches a value that you set, and then not tax for a number of turns until the happiness recovers to another value that you set. Because the growth method \
  1252. includes a number of turns where you're taxing at 0%, the population tends to grow faster under this method (hence the name), although you sacrifice a bit in immediate \
  1253. tax income.</p>\
  1254. <p>For every method, the method will only tax as much as is required to get the megacredits you can actually collect. So if, for instance, you can apply a 20% tax for \
  1255. 1500mc that will get you down to 70 happiness on the natives, but you only have enough colonists to actually collect 253mc, the method will only tax at the 4% rate or \
  1256. whatever that will get you the megacredits you can collect, without the 'wasted' happiness penalty.Hissing ships are accounted for in all methods for all races. \
  1257. Other effects such as the Avian happiness bonus, etc, are also accounted for.</p> \
  1258. <p>For the main method, if you choose 'Growth', you need to enter a minimum happiness value that you want to tax down to, and a maximum happiness value that you want to \
  1259. recover to before taxing again. If you choose 'Safe', you need only enter the minimum happiness value that you want to tax down to. In the main method, you may also \
  1260. specify a minimum number of clans that the planet must have before beginning this tax strategy. If the planet doesn't meet the minimum, the population will be taxed \
  1261. at 0% for maximum growth until the population reaches the minimum.</p> \
  1262. <p>Once you're happy with all of your settings, click the 'Create Taxation Method' button at the bottom of the form, and if you've entered proper values in the fields, \
  1263. you will see your method created in the list of methods, and you will be able to apply it to planets.</p><br/>";
  1264. html += "<p><iframe width='560' height='315' src='//www.youtube.com/embed/3JWTyGgdNSM' frameborder='0' allowfullscreen></iframe></p>";
  1265. html += "<hr /><p><h2><b>Reset All Methods</b></h2><br />Warning: Pushing this method will reset all planets to manual, and remove \
  1266. all custom build and tax methods.<br />";
  1267. html += "<button id='FullResetBtn'>Reset All Methods</button><br /></p>";
  1268. html += "<p><div id = 'FullResetDiv'></div>";
  1269. html += "</td></tr>"
  1270. html += "</table><br /></div>";
  1271. this.pane = $(html).appendTo(vgap.dash.content);
  1272. $('#FullResetBtn').click(function() {
  1273. plg.resetAllNotes();
  1274. //$('#BMWizStatusText').replaceWith("<td colspan = 2 align='center' color='red' id='BMWizStatusText'>Invalid Code Addition. Amounts must be whole numbers.</td>");
  1275. });
  1276. }
  1277. if (view == 3) {
  1278. // Build Methods View
  1279. // Disable hotkeys to allow entries
  1280. vgap.hotkeysOn = false;
  1281. // Construct PM Header
  1282. var pmheaderhtml = "<table><tr><td><h1>Planetary Construction Method Manager</h1><br /></td></tr>";
  1283. pmheaderhtml += "<tr><td>Here you may create or remove building construction methods.";
  1284. pmheaderhtml += "</td></tr></table>";
  1285. // Construct the method review pane
  1286. var mrevhtml = "<table id = 'BMSelTable'><tr><td colspan=2><b>Current Methods:</b><br /></td></tr>";
  1287. mrevhtml += "<tr><td rowspan = 2><select name='BMSelect' id='BMSelect' size='8'>";
  1288. if (debug) console.log("Populating select, buildmethods is " + plg.buildmethods + ", length is " + plg.buildmethods.length);
  1289. for (var i=0; i < plg.buildmethods.length; i++) {
  1290. mrevhtml += "<option value='" + i + "'>" + plg.buildmethods[i][0] + "</option>";
  1291. }
  1292. mrevhtml += "</select></td>";
  1293. mrevhtml += "<td id='BMMethText'>No Method Selected.</td></tr>";
  1294. mrevhtml += "<tr><td><button id='BMRemoveMethodBtn'>Remove Build Method</button></td></tr>";
  1295. mrevhtml += "</table>";
  1296. // Construct Direct Entry Method
  1297. var dehtml = "<div id='BMDEDiv'><p><h2>Create Planetary Construction Method - Direct Entry</h2></p> \
  1298. <p>You may create a build method by directly entering a valid build code. See the help for details. Here are a few examples: \
  1299. <ul><li>To build 14 factories, then 19 mines, then 20 defense posts, allowing supplies to be converted to megacredits if necessary:<br \> \
  1300. <b>y-f-14-m-19-d-20</b><br \>&nbsp;</li> \
  1301. <li>To build 30 factories, then 20 mines, then up to 100 factories and 200 mines, building factories at a 2:1 ratio (twice as fast), and not allowing supplies to be converted to megacredits:<br \> \
  1302. <b>n-f-30-m-20-rfm-100-200-2</b><br \>&nbsp;</li> \
  1303. </ul></p>";
  1304. dehtml += "<p><h4>Enter your build code here:&nbsp;&nbsp;</h4>";
  1305. dehtml += "<div id='DEBMStatusText'></div>";
  1306. dehtml += "<fieldset id='BMFieldset'><legend id='BMLegend'>Build Method Entry</legend> \
  1307. <label>Method Name:<br /> \
  1308. <input id='BMName' name='bmnamebox' maxlength='16' type='text'></label><br /><br /> \
  1309. <label>Method Build Code:<br /> \
  1310. <input id='BMCode' name='bmcodebox' type='text'></label><br /><br /> \
  1311. <button id='BMBtn' name='bmcodebtn'>Create Build Method</button></fieldset>";
  1312. dehtml += "</p></div>";
  1313. // Construct a row of the wizard entry table
  1314. var wizhtml = "<div id='BMWizDiv'><table id='BMWizTable'><tr><td colspan = 2><h2>Create Planetary Construction Method - Wizard</h2></td></tr>";
  1315. var wizmethhtml = "<fieldset id='BMWizMethFieldset'><legend>Create Method</legend> \
  1316. Method Name:<br /> \
  1317. <input id='BMWizName' name='bmnamebox' maxlength='16' type='text'></label> \
  1318. <button id='BMWizAddMethodBtn'>Create Build Method</button><br /><br /> \
  1319. <input type='checkbox' name='wizcheck' id='BMWizBurnSupCheck' value ='c' checked />Convert Supplies to MC?<br /> \
  1320. </fieldset>";
  1321. var wizbtnhtml = "<fieldset id='BMWizFieldset'><legend>Build Method Section Builder</legend> \
  1322. <input type='radio' value='f' name='wizrad' id='BMWizFRad' checked /> \
  1323. <img src='http://play.planets.nu/img/icons/factory.png' height='25' width='25'></img> \
  1324. <input type='radio' value='m' name='wizrad' id='BMWizMRad' /> \
  1325. <img src='http://play.planets.nu/img/icons/mine.png' height='25' width='25'></img> \
  1326. <input type='radio' value='d' name='wizrad' id='BMWizDRad' /> \
  1327. <img src='http://play.planets.nu/img/icons/defense.png' height='25' width='25'></img> \
  1328. <input type='radio' value='rfm' name='wizrad' id='BMWizRFMRad' /> \
  1329. <img src='http://play.planets.nu/img/icons/factory.png' height='25' width='25'></img>+ \
  1330. <img src='http://play.planets.nu/img/icons/mine.png' height='25' width='25'></img> \
  1331. <br /> \
  1332. <div id='BMWizAmt1'> \
  1333. <label>Amount: \
  1334. <input type='text' id='BMWizAmtTxt1'></label></div> \
  1335. <div id='BMWizAmt2' style='display: none;'> \
  1336. <label>2nd Amount: \
  1337. <input type='text' id='BMWizAmtTxt2'></label></div> \
  1338. <div id='BMWizRatio' style='display: none;'> \
  1339. <label>Ratio: </label>\
  1340. <input type='radio' value='2' name='wizratrad' id='BMWizRatRad2' checked/>2:1 \
  1341. <input type='radio' value='3' name='wizratrad' id='BMWizRatRad3' />3:1 \
  1342. <input type='radio' value='5' name='wizratrad' id='BMWizRatRad5' />5:1 \
  1343. <input type='radio' value='10' name='wizratrad' id='BMWizRatRad10' />10:1 \
  1344. </div><br /> \
  1345. <button id='BMWizAddBtn'>Add To Method</button></fieldset>";
  1346. wizhtml += "<tr><td colspan = 2><div id='BMWizMethStatusText'></div></td></tr>";
  1347. wizhtml += "<tr><td colspan = 2>" + wizmethhtml + "</td>";
  1348. wizhtml += "<tr><td align='center' colspan = 2 id='BMWizCode'><h3><b>" + plg.bmwizcode + "</b></h3></td></tr>";
  1349. wizhtml += "<tr><td align='center' colspan = 2 id='BMWizText'><h3><b>" + plg.bmwiztext + "</b></h3></td></tr>";
  1350. wizhtml += "<tr><td><button id='BMWizRemoveBtn'>Remove Last Piece</button></td>";
  1351. wizhtml += "<td><button id='BMWizClearBtn'>Clear</button></td></tr>";
  1352. wizhtml += "<tr><td colspan = 2 align='center' id='BMWizStatusText'></td></tr>";
  1353. wizhtml += "<tr><td colspan = 2>" + wizbtnhtml + "</td>";
  1354. wizhtml += "</table></div>";
  1355. // Put it all together
  1356. html += "<br /><table id = 'BMMainTable' border='0' width='100%'>";
  1357. html += "<tr><td colspan = 2>";
  1358. html += pmheaderhtml;
  1359. html += "</td></tr>";
  1360. html += "<tr><td colspan = 2>";
  1361. html += mrevhtml;
  1362. html += "</td></tr>";
  1363. html += "<tr><td valign='top'>" + wizhtml + "</td><td valign='top'>" + dehtml + "</td></tr>";
  1364. html += "</table><br /></div>";
  1365. html += "<br /><br /><br /><br /><br /><br /><br /><br />";
  1366. html += "<br /><br /><br /><br /><br /><br /><br /><br />";
  1367. html += "<br /><br /><br /><br /><br /><br /><br /><br />some text<hr />";
  1368. this.pane = $(html).appendTo(vgap.dash.content);
  1369. $('#BMBtn').click(function() {
  1370. var mname = $('#BMName').val();
  1371. var mcode = $('#BMCode').val();
  1372. var namesame = false;
  1373. if (plg.checkBuildCode(mcode)) {
  1374. // True is good, check to see if the name is in use
  1375. for (var i = 0; i < plg.buildmethods.length; i++) {
  1376. console.log("Comparing names, bm["+i+"]="+plg.buildmethods[i][0]+" , new name is " + mname);
  1377. if (plg.buildmethods[i][0] == mname) {
  1378. // Name in use
  1379. $('#DEBMStatusText').replaceWith("<div id='DEBMStatusText'>Method Name Already In Use, method not added.<br /></div>");
  1380. namesame = true;
  1381. }
  1382. }
  1383. // Code's good, add it
  1384. if (!namesame) {
  1385. console.log("Method good, adding...");
  1386. plg.buildmethods.push([mname,mcode]);
  1387. plg.saveObjectAsNote(4, plg.notetype, [plugin_version,plg.buildmethods]);
  1388. plg.displayPM(3);
  1389. }
  1390. }
  1391. else {
  1392. $('#DEBMStatusText').replaceWith("<div id='DEBMStatusText'>Code invalid, try again.<br /></div>");
  1393. }
  1394. });
  1395. $('#BMWizAddMethodBtn').click(function() {
  1396. var mname = $('#BMWizName').val();
  1397. var mcode = plg.bmwizcode;
  1398. var namesame = false;
  1399. if (plg.checkBuildCode(mcode)) {
  1400. // True is good, check to see if the name is in use
  1401. for (var i = 0; i < plg.buildmethods.length; i++) {
  1402. if (debug) console.log("Comparing names, bm["+i+"]="+plg.buildmethods[i][0]+" , new name is " + mname);
  1403. if (plg.buildmethods[i][0] == mname) {
  1404. // Name in use
  1405. $('#BMWizMethStatusText').replaceWith("<div id='BMWizMethStatusText'>Method Name Already In Use, method not added.<br /></div>");
  1406. namesame = true;
  1407. }
  1408. }
  1409. // Code's good, add it
  1410. if (!namesame) {
  1411. if (debug) console.log("Method good, adding...");
  1412. plg.buildmethods.push([mname,mcode]);
  1413. plg.saveObjectAsNote(4, plg.notetype, [plugin_version,plg.buildmethods]);
  1414. // Bug Fix (6): Clear bmwizcode and text on add
  1415. plg.bmwizcode = "";
  1416. plg.bmwiztext = "";
  1417. plg.displayPM(3);
  1418. }
  1419. }
  1420. else {
  1421. //<div id='DEBMStatusText'></div>
  1422. $('#BMWizMethStatusText').replaceWith("<div id='BMWizMethStatusText'>Code invalid, try again.<br /></div>");
  1423. //alert("Code bad!");
  1424. }
  1425. });
  1426. $('#BMRemoveMethodBtn').click(function() {
  1427. var bmind = $('#BMSelect').val();
  1428. // Remove the method
  1429. plg.buildmethods.splice(bmind,1);
  1430. // Adjust the bmarray as necessary
  1431. for (var i = 0; i < plg.bmarray.length; i++) {
  1432. if (plg.bmarray[i] == bmind) {
  1433. // Convert all items that were this build method to manual
  1434. plg.bmarray[i] = 'm';
  1435. }
  1436. if (plg.bmarray[i] != 'm' && plg.bmarray[i] > bmind) {
  1437. // Adjust all others higher down one so they still match
  1438. plg.bmarray[i] -= 1;
  1439. }
  1440. }
  1441. plg.saveObjectAsNote(4, plg.notetype, [plugin_version,plg.buildmethods]);
  1442. plg.displayPM(3);
  1443. });
  1444. $('#BMRadWiz').change(function () {
  1445. if (debug) console.log("wizhtml button clicked");
  1446. if ($('#BMRadWiz').attr('checked')) {
  1447. console.log("BMRADWiz is checked");
  1448. $('#BMRightPane').replaceWith("<td id='BMRightPane'>" + wizhtml + "</td>");
  1449. }
  1450. });
  1451. $('#BMRadDE').change(function () {
  1452. if (debug) console.log("dehtml button clicked");
  1453. if ($('#BMRadDE').attr('checked')) {
  1454. $('#BMRightPane').replaceWith("<td id='BMRightPane'>" + dehtml + "</td>");
  1455. console.log("BMRadDE is checked.");
  1456. }
  1457. });
  1458. $('#BMWizFRad').click(function () {
  1459. $('#BMWizAmt2').hide();
  1460. $('#BMWizRatio').hide();
  1461. });
  1462. $('#BMWizMRad').click(function () {
  1463. $('#BMWizAmt2').hide();
  1464. $('#BMWizRatio').hide();
  1465. });
  1466. $('#BMWizDRad').click(function () {
  1467. $('#BMWizAmt2').hide();
  1468. $('#BMWizRatio').hide();
  1469. });
  1470. $('#BMWizRFMRad').click(function () {
  1471. $('#BMWizAmt2').show();
  1472. $('#BMWizRatio').show();
  1473. });
  1474. $('#BMWizRemoveBtn').click(function () {
  1475. if (plg.bmwizcode != "") {
  1476. var splitarray = [];
  1477. splitarray = plg.bmwizcode.split('-');
  1478. var splitlength = splitarray.length;
  1479. if (splitlength <= 3 || (splitlength <= 5 && splitarray[1] == 'rfm'))
  1480. document.getElementById("BMWizClearBtn").click();
  1481. else {
  1482. var mcode = splitarray[0];
  1483. if (splitarray[splitlength-4] == 'rfm') {
  1484. for (var i = 1; i < splitlength - 4; i++)
  1485. mcode += "-" + splitarray[i];
  1486. }
  1487. else {
  1488. for (var i = 1; i < splitlength - 2; i++)
  1489. mcode += "-" + splitarray[i];
  1490. }
  1491. plg.bmwizcode = mcode;
  1492. $('#BMWizCode').replaceWith("<td align='center' colspan = 2 id='BMWizCode'><h3><b>" + plg.bmwizcode + "</b></h3></td>");
  1493. $('#BMWizText').replaceWith("<td align='center' colspan = 2 id='BMWizText'><h3><b>" + plg.bmwiztext + "</b></h3></td>");
  1494. $('#BMWizStatusText').replaceWith("<td colspan = 2 align='center' color='green' id='BMWizStatusText'>Last Piece Removed.</td>");
  1495. }
  1496. }
  1497. });
  1498. $('#BMWizClearBtn').click(function () {
  1499. plg.bmwizcode = "";
  1500. plg.bmwiztext = "";
  1501. $('#BMWizCode').replaceWith("<td align='center' colspan = 2 id='BMWizCode'><h3><b>" + plg.bmwizcode + "</b></h3></td>");
  1502. $('#BMWizText').replaceWith("<td align='center' colspan = 2 id='BMWizText'><h3><b>" + plg.bmwiztext + "</b></h3></td>");
  1503. $('#BMWizStatusText').replaceWith("<td colspan = 2 align='center' color='green' id='BMWizStatusText'>Method Cleared.</td>");
  1504. });
  1505. $('#BMWizBurnSupCheck').click(function () {
  1506. if (debug) console.log("BMWIZBURNSUP CLICKED");
  1507. if (plg.bmwizcode != "") {
  1508. if (plg.bmwizcode.charAt(0) == 'n')
  1509. plg.bmwizcode = 'y' + plg.bmwizcode.substring(1);
  1510. else
  1511. plg.bmwizcode = 'n' + plg.bmwizcode.substring(1);
  1512. plg.bmwiztext = plg.getBuildCodeText(plg.bmwizcode);
  1513. $('#BMWizCode').replaceWith("<td align='center' colspan = 2 id='BMWizCode'><h3><b>" + plg.bmwizcode + "</b></h3></td>");
  1514. $('#BMWizText').replaceWith("<td align='center' colspan = 2 id='BMWizText'><h3><b>" + plg.bmwiztext + "</b></h3></td>");
  1515. }
  1516. });
  1517. $('#BMWizAddBtn').click(function () {
  1518. if (plg.bmwizcode == "") {
  1519. if ($('#BMWizBurnSupCheck').attr('checked')) {
  1520. plg.bmwizcode = "y";
  1521. }
  1522. else {
  1523. plg.bmwizcode = "n";
  1524. }
  1525. }
  1526. var mcode = "";
  1527. if ($('#BMWizFRad').attr('checked')) {
  1528. mcode += "-f-" + $('#BMWizAmtTxt1').val();
  1529. }
  1530. if ($('#BMWizMRad').attr('checked')) {
  1531. mcode += "-m-" + $('#BMWizAmtTxt1').val();
  1532. }
  1533. if ($('#BMWizDRad').attr('checked')) {
  1534. mcode += "-d-" + $('#BMWizAmtTxt1').val();
  1535. }
  1536. if ($('#BMWizRFMRad').attr('checked')) {
  1537. mcode += "-rfm-" + $('#BMWizAmtTxt1').val();
  1538. mcode += "-" + $('#BMWizAmtTxt2').val();
  1539. if ($('#BMWizRatRad2').attr('checked'))
  1540. mcode += "-2";
  1541. if ($('#BMWizRatRad3').attr('checked'))
  1542. mcode += "-3";
  1543. if ($('#BMWizRatRad5').attr('checked'))
  1544. mcode += "-5";
  1545. if ($('#BMWizRatRad10').attr('checked'))
  1546. mcode += "-10";
  1547. console.log("Attempting RFM Add: mcode = " + mcode);
  1548. }
  1549. if (plg.checkBuildCode(plg.bmwizcode + mcode)) {
  1550. // The code is good
  1551. plg.bmwizcode += mcode;
  1552. plg.bmwiztext = plg.getBuildCodeText(plg.bmwizcode);
  1553. if (debug) console.log("Adding text: " + plg.bmwizcode);
  1554. $('#BMWizCode').replaceWith("<td align='center' colspan = 2 id='BMWizCode'><h3><b>" + plg.bmwizcode + "</b></h3></td>");
  1555. $('#BMWizText').replaceWith("<td align='center' colspan = 2 id='BMWizText'><h3><b>" + plg.bmwiztext + "</b></h3></td>");
  1556. $('#BMWizStatusText').replaceWith("<td colspan = 2 align='center' color='green' id='BMWizStatusText'>Section Added.</td>");
  1557. }
  1558. else {
  1559. $('#BMWizStatusText').replaceWith("<td colspan = 2 align='center' color='red' id='BMWizStatusText'>Invalid Code Addition. Amounts must be whole numbers.</td>");
  1560. }
  1561. });
  1562. $('#BMSelect').change(function () {
  1563. var bmind = $('#BMSelect').val();
  1564. var buildtext = plg.getBuildCodeText(plg.buildmethods[bmind][1]);
  1565. $('#BMMethText').replaceWith("<td id='BMMethText'><b>" + plg.buildmethods[bmind][0] + ":&nbsp;</b>" + buildtext + "</td>");
  1566. });
  1567. }
  1568. if (view == 4) {
  1569. // Taxation Methods View
  1570. // Disable hotkeys to allow entries
  1571. vgap.hotkeysOn = false;
  1572. var tmheaderhtml = "<table><tr><td><h1>Taxation Method Manager</h1><br /></td></tr>";
  1573. tmheaderhtml += "<tr><td>Here you may create or remove taxation methods.";
  1574. tmheaderhtml += "</td></tr></table>";
  1575. // Construct the taxation method review pane
  1576. var tmrevhtml = "<table id = 'TMSelTable'><tr><td colspan=2>Current Taxation Methods:<br /></td></tr>";
  1577. tmrevhtml += "<tr><td rowspan = 2><select name='TMSelect' id='TMSelect' size='8'>";
  1578. for (var i=0; i < plg.taxmethods.length; i++) {
  1579. tmrevhtml += "<option value='" + i + "'>" + plg.taxmethods[i].name + "</option>";
  1580. }
  1581. tmrevhtml += "</select></td>";
  1582. tmrevhtml += "<td id='TMMethText'>No Method Selected.</td></tr>";
  1583. tmrevhtml += "<tr><td><button id='TMRemoveMethodBtn'>Remove Taxation Method</button></td></tr>";
  1584. tmrevhtml += "</table>";
  1585. // Construct the taxation method builder wizard
  1586. var tmwizmethhtml = "<div id='TMWiz'><fieldset id='TMWizMethFieldset'><legend>Create Tax Method</legend> \
  1587. <h3><b>Method Name:</b></h3><br /> \
  1588. <input id='TMWizName' name='tmnamebox' maxlength='24' type='text'></label><br \><br /> \
  1589. Available for Natives, Colonists, or Both: <br /> \
  1590. <input type='checkbox' name='TMWizCheckC' id='TMWizCheckC' value ='C' checked />Colonists \
  1591. <input type='checkbox' name='TMWizCheckN' id='TMWizCheckN' value ='N' checked />Natives <br \> \
  1592. <div id='TMWizMethStatusText'><br /></div> \
  1593. <h3><b>Main Method:</b></h3><br /> \
  1594. Method Type: <br />\
  1595. <input type='radio' value='Growth' name='tmmethrad' id='TMMethRadG' checked /> \
  1596. Growth \
  1597. <input type='radio' value='Safe' name='tmmethrad' id='TMMethRadS' /> \
  1598. Safe <br /> \
  1599. <input type='radio' value='Riot' name='tmmethrad' id='TMMethRadR' /> \
  1600. Riot <br /> \
  1601. <input type='radio' value='No Tax' name='tmmethrad' id='TMMethRadN' /> \
  1602. No Tax <br /> \
  1603. Parameters: <br />\
  1604. <div id='TMWizMinHappy'> \
  1605. <label>Minimum Happiness: \
  1606. <input type='text' id='TMWizMinHappyTxtBox'></label></div> \
  1607. <div id='TMWizMaxHappy'> \
  1608. <label>Maximum Happiness: \
  1609. <input type='text' id='TMWizMaxHappyTxtBox'></label></div> \
  1610. <div id='TMWizMinClans'> \
  1611. <label>Minimum Clans: \
  1612. <input type='text' id='TMWizMinClansTxtBox'></label></div><br \><br \> \
  1613. \
  1614. <h3><b>If Population is Greater than 6,600,000 (growth cut in half):</b></h3><br /> \
  1615. <input type='radio' value='Growth' name='tmmidselrad' id='TMMidMethRadSame' /> \
  1616. Same as Main Method \
  1617. <input type='radio' value='Safe' name='tmmidselrad' id='TMMidMethRadDiff' checked/> \
  1618. Specify a Different Method <br /> \
  1619. <div id='TMWizMidMethod'> \
  1620. <div id='TMWizMidMethStatusText'><br /></div> \
  1621. Method Type: <br />\
  1622. <input type='radio' value='Growth' name='tmmidmethrad' id='TMMidMethRadG' checked /> \
  1623. Growth \
  1624. <input type='radio' value='Safe' name='tmmidmethrad' id='TMMidMethRadS' /> \
  1625. Safe <br /> \
  1626. <input type='radio' value='Riot' name='tmmidmethrad' id='TMMidMethRadR' /> \
  1627. Riot <br /> \
  1628. <input type='radio' value='No Tax' name='tmmidmethrad' id='TMMidMethRadN' /> \
  1629. No Tax <br /> \
  1630. Parameters: <br />\
  1631. <div id='TMWizMidMinHappy'> \
  1632. <label>Minimum Happiness: \
  1633. <input type='text' id='TMWizMidMinHappyTxtBox'></label></div> \
  1634. <div id='TMWizMidMaxHappy'> \
  1635. <label>Maximum Happiness: \
  1636. <input type='text' id='TMWizMidMaxHappyTxtBox'></label></div><br \><br \></div> \
  1637. \
  1638. <h3><b>If Population is at Maximum:</b></h3><br /> \
  1639. <input type='radio' value='Growth' name='tmmaxselrad' id='TMMaxMethRadSame' /> \
  1640. Same as Main Method \
  1641. <input type='radio' value='Safe' name='tmmaxselrad' id='TMMaxMethRadDiff' checked /> \
  1642. Specify a Different Method <br /> \
  1643. <div id='TMWizMaxMethod'> \
  1644. <div id='TMWizMaxMethStatusText'><br /></div> \
  1645. Method Type: <br />\
  1646. <input type='radio' value='Growth' name='tmmaxmethrad' id='TMMaxMethRadG' checked /> \
  1647. Growth \
  1648. <input type='radio' value='Safe' name='tmmaxmethrad' id='TMMaxMethRadS' /> \
  1649. Safe <br /> \
  1650. Parameters: <br />\
  1651. <div id='TMWizMaxMinHappy'> \
  1652. <label>Minimum Happiness: \
  1653. <input type='text' id='TMWizMaxMinHappyTxtBox'></label></div> \
  1654. <div id='TMWizMaxMaxHappy'> \
  1655. <label>Maximum Happiness: \
  1656. <input type='text' id='TMWizMaxMaxHappyTxtBox'></label></div><br \><br \><br /></div> \
  1657. <button id='TMWizAddMethodBtn'>Create Taxation Method</button><br /> \
  1658. </fieldset></div>";
  1659. html += "<br /><table border='0' width='100%'>";
  1660. html += "<tr><td colspan = 2>";
  1661. html += tmheaderhtml;
  1662. html += "</td></tr>";
  1663. html += "<tr><td colspan = 2>";
  1664. html += tmrevhtml;
  1665. html += "</td></tr>";
  1666. html += "<tr><td>" + tmwizmethhtml + "</td></tr>";
  1667. html += "</table><br /></div>";
  1668. this.pane = $(html).appendTo(vgap.dash.content);
  1669. $('#TMWizAddMethodBtn').click(function () {
  1670. var newtmodel = new Object();
  1671. newtmodel.name = $('#TMWizName').val();
  1672. newtmodel.method = "";
  1673. if ($('#TMMethRadG').attr('checked'))
  1674. newtmodel.method = "Growth";
  1675. if ($('#TMMethRadS').attr('checked'))
  1676. newtmodel.method = "Safe";
  1677. newtmodel.taxType = "";
  1678. if ($('#TMWizCheckC').attr('checked'))
  1679. newtmodel.taxType += "C";
  1680. if ($('#TMWizCheckN').attr('checked'))
  1681. newtmodel.taxType += "N";
  1682. newtmodel.minHappy = $('#TMWizMinHappyTxtBox').val();
  1683. newtmodel.maxHappy = $('#TMWizMaxHappyTxtBox').val();
  1684. newtmodel.minClans = $('#TMWizMinClansTxtBox').val().replace (/,/g, "");
  1685. if (newtmodel.minClans == "")
  1686. newtmodel.minClans = 0;
  1687. // New stuff
  1688. if ($('#TMMidMethRadSame').attr('checked')) {
  1689. newtmodel.midsame = true;
  1690. newtmodel.midmethod = "";
  1691. newtmodel.midMinHappy = "";
  1692. newtmodel.midMaxHappy = "";
  1693. }
  1694. if ($('#TMMidMethRadDiff').attr('checked')){
  1695. newtmodel.midsame = false;
  1696. if ($('#TMMidMethRadG').attr('checked'))
  1697. newtmodel.midmethod = "Growth";
  1698. if ($('#TMMidMethRadS').attr('checked'))
  1699. newtmodel.midmethod = "Safe";
  1700. if ($('#TMMidMethRadR').attr('checked'))
  1701. newtmodel.midmethod = "Riot";
  1702. if ($('#TMMidMethRadN').attr('checked'))
  1703. newtmodel.midmethod = "No Tax";
  1704. newtmodel.midMinHappy = $('#TMWizMidMinHappyTxtBox').val();
  1705. newtmodel.midMaxHappy = $('#TMWizMidMaxHappyTxtBox').val();
  1706. }
  1707. if ($('#TMMaxMethRadSame').attr('checked')) {
  1708. newtmodel.maxsame = true;
  1709. newtmodel.maxmethod = "";
  1710. newtmodel.maxMinHappy = "";
  1711. newtmodel.maxMaxHappy = "";
  1712. }
  1713. if ($('#TMMaxMethRadDiff').attr('checked')){
  1714. newtmodel.maxsame = false;
  1715. if ($('#TMMaxMethRadG').attr('checked'))
  1716. newtmodel.maxmethod = "Growth";
  1717. if ($('#TMMaxMethRadS').attr('checked'))
  1718. newtmodel.maxmethod = "Safe";
  1719. if ($('#TMMidMethRadR').attr('checked'))
  1720. newtmodel.midmethod = "Riot";
  1721. if ($('#TMMidMethRadN').attr('checked'))
  1722. newtmodel.midmethod = "No Tax";
  1723. newtmodel.maxMinHappy = $('#TMWizMaxMinHappyTxtBox').val();
  1724. newtmodel.maxMaxHappy = $('#TMWizMaxMaxHappyTxtBox').val();
  1725. }
  1726. if (debug) console.log("Checking, max max happy = " + newtmodel.maxMaxHappy);
  1727. if (debug) console.log("Checking, max method = " + newtmodel.maxmethod);
  1728. var modelgood = plg.checkTaxModel(newtmodel);
  1729. if (modelgood) {
  1730. if (newtmodel.method == "Safe")
  1731. newtmodel.maxHappy = 100;
  1732. var namesame = false;
  1733. // Check if name is in use
  1734. for (var i = 0; i < plg.taxmethods.length; i++) {
  1735. if (plg.taxmethods.name == newtmodel.name) {
  1736. // Name in use
  1737. $('#TMWizMethStatusText').replaceWith("<div id='TMWizMethStatusText'>Method Name Already In Use, method not added.<br /></div>");
  1738. namesame = true;
  1739. }
  1740. }
  1741. // Code's good, add it
  1742. if (!namesame) {
  1743. if (debug) console.log("Method good, adding...");
  1744. plg.taxmethods.push(newtmodel);
  1745. plg.saveObjectAsNote(5, plg.notetype, [plugin_version,plg.taxmethods]);
  1746. plg.displayPM(4);
  1747. }
  1748. }
  1749. else {
  1750. $('#TMWizMethStatusText').replaceWith("<div id='TMWizMethStatusText'>Method invalid, try again.<br /></div>");
  1751. }
  1752. });
  1753. $('#TMMethRadS').click(function () {
  1754. $('#TMWizMaxHappy').hide();
  1755. });
  1756. $('#TMMethRadG').click(function () {
  1757. $('#TMWizMaxHappy').show();
  1758. });
  1759. $('#TMMidMethRadSame').click(function () {
  1760. $('#TMWizMidMethod').hide();
  1761. });
  1762. $('#TMMidMethRadDiff').click(function () {
  1763. $('#TMWizMidMethod').show();
  1764. });
  1765. $('#TMMaxMethRadSame').click(function () {
  1766. $('#TMWizMaxMethod').hide();
  1767. });
  1768. $('#TMMaxMethRadDiff').click(function () {
  1769. $('#TMWizMaxMethod').show();
  1770. });
  1771. $('#TMMidMethRadS').click(function () {
  1772. $('#TMWizMidMaxHappy').hide();
  1773. });
  1774. $('#TMMidMethRadG').click(function () {
  1775. $('#TMWizMidMaxHappy').show();
  1776. });
  1777. $('#TMMaxMethRadS').click(function () {
  1778. $('#TMWizMaxMaxHappy').hide();
  1779. });
  1780. $('#TMMaxMethRadG').click(function () {
  1781. $('#TMWizMaxMaxHappy').show();
  1782. });
  1783. $('#TMRemoveMethodBtn').click(function() {
  1784. var tmind = $('#TMSelect').val();
  1785. // Remove the method
  1786. plg.taxmethods.splice(tmind,1);
  1787. // Adjust the ctarray as necessary
  1788. for (var i = 0; i < plg.ctarray.length; i++) {
  1789. if (plg.ctarray[i] == tmind) {
  1790. // Convert all items that were this tax method to manual
  1791. plg.ctarray[i] = 'm';
  1792. }
  1793. if (plg.ctarray[i] != 'm' && plg.ctarray[i] > tmind) {
  1794. // Adjust all others higher down one so they still match
  1795. plg.ctarray[i] -= 1;
  1796. }
  1797. }
  1798. // Adjust the ntarray as necessary
  1799. for (var i = 0; i < plg.ntarray.length; i++) {
  1800. if (plg.ntarray[i] == tmind) {
  1801. // Convert all items that were this tax method to manual
  1802. plg.ntarray[i] = 'm';
  1803. }
  1804. if (plg.ntarray[i] != 'm' && plg.ntarray[i] > tmind) {
  1805. // Adjust all others higher down one so they still match
  1806. plg.ntarray[i] -= 1;
  1807. }
  1808. }
  1809. plg.saveObjectAsNote(5, plg.notetype, [plugin_version,plg.taxmethods]);
  1810. plg.displayPM(4);
  1811. });
  1812. $('#TMRad1').click(function () {
  1813. plg.selTaxModel = taxModel1;
  1814. $('#TMData').replaceWith("<td id='TMData'>Method: " + plg.selTaxModel.method + "</td>");
  1815. });
  1816. $('#TMSelect').change(function () {
  1817. var tmind = $('#TMSelect').val();
  1818. var taxtext = plg.getTaxText(plg.taxmethods[tmind]);
  1819. $('#TMMethText').replaceWith("<td id='TMMethText'><b>" + plg.taxmethods[tmind].name + ":&nbsp;</b>" + taxtext + "</td>");
  1820. });
  1821. }
  1822. //this.content.fadeIn();
  1823. //$("#PlanetTable").tablesorter();
  1824. this.pane.jScrollPane();
  1825. // vgap.action added for the assistant (Alex):
  1826. vgap.CurrentView = "showPlanets";
  1827. vgap.showPlanetsViewed = 1;
  1828. },
  1829. /* Initial Read in Functions
  1830. * The following functions handle reading of the notes, and
  1831. * resetting of arrays if necessary.
  1832. */
  1833. getMaxId: function() {
  1834. var maxid = 1;
  1835. for (var i = 0; i < vgap.planets.length; i++) {
  1836. if (vgap.planets[i].id > maxid)
  1837. maxid = vgap.planets[i].id;
  1838. }
  1839. return maxid;
  1840. },
  1841. validateArrays: function() {
  1842. var plg = vgap.plugins["plManagerPlugin"];
  1843. var maxid = plg.getMaxId();
  1844. console.log("Validating Arrays...");
  1845. // Validate BMArray
  1846. console.log("Validating BMArray...");
  1847. if (plg.bmarray.length < maxid) {
  1848. if (debug) console.log("Invalid BMArray length found, correcting...");
  1849. // The array is not the correct length, make it right
  1850. for (var i = plg.bmarray.length; i <= maxid; i++) {
  1851. plg.bmarray[i] = 'm';
  1852. }
  1853. }
  1854. // Make sure there are no nulls or blanks
  1855. for (var j = 0; j < plg.bmarray.length; j++) {
  1856. if (plg.bmarray[j] == null || plg.bmarray[j] == "") {
  1857. if (debug) console.log("Invalid BMArray null/blank found, correcting...");
  1858. plg.bmarray[j] = 'm';
  1859. }
  1860. }
  1861. plg.initSaveObjectAsNote(0, plg.notetype, [plugin_version,plg.bmarray]);
  1862. if (debug) console.log("BMArray validated.");
  1863. if (debug) console.log("BMArray is: " + plg.bmarray);
  1864. // Validate NTArray
  1865. if (debug) console.log("Validating NTArray...");
  1866. if (plg.ntarray.length < maxid) {
  1867. if (debug) console.log("Invalid NTArray length found, correcting...");
  1868. // The array is not the correct length, make it right
  1869. for (var i = plg.ntarray.length; i <= maxid; i++) {
  1870. plg.ntarray[i] = 'm';
  1871. }
  1872. }
  1873. // Make sure there are no nulls or blanks
  1874. for (var j = 0; j < plg.ntarray.length; j++) {
  1875. if (plg.ntarray[j] == null || plg.ntarray[j] == "") {
  1876. if (debug) console.log("Invalid NTArray null/blank found, correcting...");
  1877. plg.ntarray[j] = 'm';
  1878. }
  1879. }
  1880. plg.initSaveObjectAsNote(1, plg.notetype, [plugin_version,plg.ntarray]);
  1881. if (debug) console.log("NTArray validated.");
  1882. if (debug) console.log("NTArray is: " + plg.ntarray);
  1883. // Validate CTArray
  1884. if (debug) console.log("Validating CTArray...");
  1885. if (plg.ctarray.length < maxid) {
  1886. if (debug) console.log("Invalid CTArray length found, correcting...");
  1887. // The array is not the correct length, make it right
  1888. for (var i = plg.ctarray.length; i <= maxid; i++) {
  1889. plg.ctarray[i] = 'm';
  1890. }
  1891. }
  1892. // Make sure there are no nulls or blanks
  1893. for (var j = 0; j < plg.ctarray.length; j++) {
  1894. //console.log("CTARRAY VALIDATION: ctarray[" + j + "] = --->" + plg.ctarray[j] + "<----");
  1895. if (plg.ctarray[j] == null || plg.ctarray[j] == "") {
  1896. if (debug) console.log("Invalid CTArray null/blank found, correcting...");
  1897. plg.ctarray[j] = 'm';
  1898. }
  1899. }
  1900. plg.initSaveObjectAsNote(2, plg.notetype, [plugin_version,plg.ctarray]);
  1901. if (debug) console.log("CTArray validated.");
  1902. if (debug) console.log("CTArray is: " + plg.ctarray);
  1903. if (debug) console.log("All Arrays Validated.");
  1904. },
  1905. resetBMArray: function() {
  1906. vgap.plugins["plManagerPlugin"].bmarray = [];
  1907. for (var i = 0; i < vgap.plugins["plManagerPlugin"].getMaxId() + 1; i++)
  1908. vgap.plugins["plManagerPlugin"].bmarray[i] = 'm';
  1909. },
  1910. resetNTArray: function() {
  1911. vgap.plugins["plManagerPlugin"].ntarray = [];
  1912. for (var i = 0; i < vgap.plugins["plManagerPlugin"].getMaxId() + 1; i++)
  1913. vgap.plugins["plManagerPlugin"].ntarray[i] = 'm';
  1914. },
  1915. resetCTArray: function() {
  1916. vgap.plugins["plManagerPlugin"].ctarray = [];
  1917. console.log("In reset ct array, getmaxid is " + vgap.plugins["plManagerPlugin"].getMaxId());
  1918. for (var i = 0; i < vgap.plugins["plManagerPlugin"].getMaxId() + 1; i++)
  1919. vgap.plugins["plManagerPlugin"].ctarray[i] = 'm';
  1920. },
  1921. resetBuildMethods: function() {
  1922. var plg = vgap.plugins["plManagerPlugin"];
  1923. plg.buildmethods = [];
  1924. plg.buildmethods[0] = ["Build 0","y-f-14-m-19-rfm-500-0-2-d-100"];
  1925. plg.buildmethods[1] = ["Build 100","y-f-14-m-19-rfm-500-100-2-d-100"];
  1926. plg.buildmethods[2] = ["Build 200","y-f-14-m-19-rfm-500-200-2-d-100"];
  1927. plg.buildmethods[3] = ["Safe Build 0","y-f-14-m-19-d-16-rfm-500-0-2-d-100"];
  1928. plg.buildmethods[4] = ["Safe Build 100","y-f-14-m-19-d-16-rfm-500-100-2-d-100"];
  1929. plg.buildmethods[5] = ["Safe Build 200","y-f-14-m-19-d-16-rfm-500-200-2-d-100"];
  1930. plg.buildmethods[6] = ["Safe Build No Burn","n-f-14-m-19-d-16-rfm-500-200-2-d-100"];
  1931. plg.buildmethods[7] = ["Build 2:1","y-rfm-500-500-2"];
  1932. plg.buildmethods[8] = ["Defence","y-d-500"];
  1933. },
  1934. resetTaxMethods: function() {
  1935. var plg = vgap.plugins["plManagerPlugin"];
  1936. plg.taxmethods = [];
  1937. var taxModel1 = new Object();
  1938. taxModel1.name = "Growth Tax 70-100";
  1939. taxModel1.method = "Growth";
  1940. taxModel1.taxType = "CN";
  1941. taxModel1.minHappy = 70;
  1942. taxModel1.maxHappy = 100;
  1943. taxModel1.minClans = 0;
  1944. taxModel1.midsame = true;
  1945. taxModel1.midmethod = "Growth";
  1946. taxModel1.midMinHappy = "";
  1947. taxModel1.midMaxHappy = "";
  1948. taxModel1.maxsame = false;
  1949. taxModel1.maxmethod = "Safe";
  1950. taxModel1.maxMinHappy = 50;
  1951. taxModel1.maxMaxHappy = "";
  1952. var taxModel2 = new Object();
  1953. taxModel2.name = "Safe Tax 100";
  1954. taxModel2.method = "Safe";
  1955. taxModel2.taxType = "CN";
  1956. taxModel2.minHappy = 100;
  1957. taxModel2.maxHappy = 100;
  1958. taxModel2.minClans = 0;
  1959. taxModel2.midsame = true;
  1960. taxModel2.midmethod = "Safe";
  1961. taxModel2.midMinHappy = "";
  1962. taxModel2.midMaxHappy = "";
  1963. taxModel2.maxsame = true;
  1964. taxModel2.maxmethod = "Safe";
  1965. taxModel2.maxMinHappy = "";
  1966. taxModel2.maxMaxHappy = "";
  1967. var taxModel3 = new Object();
  1968. taxModel3.name = "Safe Tax 70";
  1969. taxModel3.method = "Safe";
  1970. taxModel3.taxType = "CN";
  1971. taxModel3.minHappy = 70;
  1972. taxModel3.maxHappy = 100;
  1973. taxModel3.minClans = 0;
  1974. taxModel3.midsame = true;
  1975. taxModel3.midmethod = "Safe";
  1976. taxModel3.midMinHappy = "";
  1977. taxModel3.midMaxHappy = "";
  1978. taxModel3.maxsame = true;
  1979. taxModel3.maxmethod = "Safe";
  1980. taxModel3.maxMinHappy = "";
  1981. taxModel3.maxMaxHappy = "";
  1982. var taxModel4 = new Object();
  1983. taxModel4.name = "Safe Tax 50";
  1984. taxModel4.method = "Safe";
  1985. taxModel4.taxType = "CN";
  1986. taxModel4.minHappy = 50;
  1987. taxModel4.maxHappy = 100;
  1988. taxModel4.minClans = 0;
  1989. taxModel4.midsame = true;
  1990. taxModel4.midmethod = "Safe";
  1991. taxModel4.midMinHappy = "";
  1992. taxModel4.midMaxHappy = "";
  1993. taxModel4.maxsame = true;
  1994. taxModel4.maxmethod = "Safe";
  1995. taxModel4.maxMinHappy = "";
  1996. taxModel4.maxMaxHappy = "";
  1997. var taxModel5 = new Object();
  1998. taxModel5.name = "Safe Tax 40";
  1999. taxModel5.method = "Safe";
  2000. taxModel5.taxType = "CN";
  2001. taxModel5.minHappy = 40;
  2002. taxModel5.maxHappy = 100;
  2003. taxModel5.minClans = 0;
  2004. taxModel5.midsame = true;
  2005. taxModel5.midmethod = "Safe";
  2006. taxModel5.midMinHappy = "";
  2007. taxModel5.midMaxHappy = "";
  2008. taxModel5.maxsame = true;
  2009. taxModel5.maxmethod = "Safe";
  2010. taxModel5.maxMinHappy = "";
  2011. taxModel5.maxMaxHappy = "";
  2012. var taxModel6 = new Object();
  2013. taxModel6.name = "Riot Tax";
  2014. taxModel6.method = "Riot";
  2015. taxModel6.taxType = "CN";
  2016. taxModel6.minHappy = 0;
  2017. taxModel6.maxHappy = 0;
  2018. taxModel6.minClans = 0;
  2019. taxModel6.midsame = true;
  2020. taxModel6.midmethod = "Riot";
  2021. taxModel6.midMinHappy = "";
  2022. taxModel6.midMaxHappy = "";
  2023. taxModel6.maxsame = true;
  2024. taxModel6.maxmethod = "Riot";
  2025. taxModel6.maxMinHappy = "";
  2026. taxModel6.maxMaxHappy = "";
  2027. var taxModel7 = new Object();
  2028. taxModel7.name = "No Tax";
  2029. taxModel7.method = "No Tax";
  2030. taxModel7.taxType = "CN";
  2031. taxModel7.minHappy = 100;
  2032. taxModel7.maxHappy = 100;
  2033. taxModel7.minClans = 0;
  2034. taxModel7.midsame = true;
  2035. taxModel7.midmethod = "No Tax";
  2036. taxModel7.midMinHappy = "";
  2037. taxModel7.midMaxHappy = "";
  2038. taxModel7.maxsame = true;
  2039. taxModel7.maxmethod = "No Tax";
  2040. taxModel7.maxMinHappy = "";
  2041. taxModel7.maxMaxHappy = "";
  2042. vgap.plugins["plManagerPlugin"].taxmethods.push(taxModel1);
  2043. vgap.plugins["plManagerPlugin"].taxmethods.push(taxModel2);
  2044. vgap.plugins["plManagerPlugin"].taxmethods.push(taxModel3);
  2045. vgap.plugins["plManagerPlugin"].taxmethods.push(taxModel4);
  2046. vgap.plugins["plManagerPlugin"].taxmethods.push(taxModel5);
  2047. vgap.plugins["plManagerPlugin"].taxmethods.push(taxModel6);
  2048. vgap.plugins["plManagerPlugin"].taxmethods.push(taxModel7);
  2049. },
  2050. readNotes: function() {
  2051. var plg = vgap.plugins["plManagerPlugin"];
  2052. console.log("Read Notes Called: readOrder = " + plg.readOrder);
  2053. switch (plg.readOrder) {
  2054. case '1':
  2055. case 1:
  2056. // Individual Planetary Building Method Array
  2057. if (vgap.plugins["plManagerPlugin"].getObjectFromNote(0,vgap.plugins["plManagerPlugin"].notetype) == null) {
  2058. if (debug) console.log("Build Method Note is null, generating m's");
  2059. plg.resetBMArray();
  2060. plg.initSaveObjectAsNote(0, plg.notetype, [plugin_version,plg.bmarray]);
  2061. }
  2062. else {
  2063. if (debug) console.log("Build Method Note not null, reading...");
  2064. var temparray = vgap.plugins["plManagerPlugin"].getObjectFromNote(0,vgap.plugins["plManagerPlugin"].notetype);
  2065. if (temparray.length != 2) {
  2066. // An invalid array, reset
  2067. if (debug) console.log("Invalid BM Array Detected! Resetting...");
  2068. plg.resetBMArray();
  2069. plg.initSaveObjectAsNote(0, plg.notetype, [plugin_version,plg.bmarray]);
  2070. }
  2071. else {
  2072. if (debug) console.log("Valid BMArray found, reading...");
  2073. var maxid = plg.getMaxId();
  2074. plg.bmarray = temparray[1];
  2075. // Check Array
  2076. if (plg.bmarray.length < maxid) {
  2077. if (debug) console.log("Invalid BMArray length found, correcting...");
  2078. // The array is not the correct length, make it right
  2079. for (var i = plg.bmarray.length; i <= maxid; i++) {
  2080. plg.bmarray[i] = 'm';
  2081. }
  2082. }
  2083. // Make sure there are no nulls or blanks
  2084. for (var j = 0; j < plg.bmarray.length; j++) {
  2085. if (plg.bmarray[j] == null || plg.bmarray[j] == "") {
  2086. if (debug) console.log("Invalid BMArray null/blank found, correcting...");
  2087. plg.bmarray[j] = 'm';
  2088. }
  2089. }
  2090. plg.initSaveObjectAsNote(0, plg.notetype, [plugin_version,plg.bmarray]);
  2091. }
  2092. }
  2093. if (debug) console.log("Build Method Array read, bmarray = " + vgap.plugins["plManagerPlugin"].bmarray);
  2094. plg.readOrder++;
  2095. plg.readNotes();
  2096. break;
  2097. case '2':
  2098. case 2:
  2099. // All Build Methods Array
  2100. if (vgap.plugins["plManagerPlugin"].getObjectFromNote(4,vgap.plugins["plManagerPlugin"].notetype) == null) {
  2101. // There are no methods saved. Load the default methods:
  2102. if (debug) console.log("Build Methods Note is null, generating defaults");
  2103. plg.resetBuildMethods();
  2104. plg.initSaveObjectAsNote(4, plg.notetype, [plugin_version,plg.buildmethods]);
  2105. }
  2106. else {
  2107. if (debug) console.log("Build Methods Note is not null, reading....");
  2108. var temparray = vgap.plugins["plManagerPlugin"].getObjectFromNote(4,vgap.plugins["plManagerPlugin"].notetype);
  2109. if (temparray.length != 2) {
  2110. // An invalid array, reset
  2111. if (debug) console.log("Invalid Player Build Methods Array Detected! Resetting...");
  2112. plg.resetBuildMethods();
  2113. plg.initSaveObjectAsNote(4, plg.notetype, [plugin_version,plg.buildmethods]);
  2114. }
  2115. else {
  2116. if (debug) console.log("Valid Player Build Methods Array found, reading...");
  2117. var maxid = plg.getMaxId();
  2118. plg.buildmethods = temparray[1];
  2119. }
  2120. }
  2121. if (debug) console.log("Build Methods Note is read, buildmethods = " + vgap.plugins["plManagerPlugin"].buildmethods);
  2122. plg.readOrder++;
  2123. plg.readNotes();
  2124. break;
  2125. case '3':
  2126. case 3:
  2127. // Tax Methods Array
  2128. //
  2129. //
  2130. if (vgap.plugins["plManagerPlugin"].getObjectFromNote(5,vgap.plugins["plManagerPlugin"].notetype) == null) {
  2131. // There are no methods saved. Load the default methods:
  2132. if (debug) console.log("Tax Methods Note is null, generating defaults");
  2133. plg.resetTaxMethods();
  2134. plg.initSaveObjectAsNote(5, plg.notetype, [plugin_version,plg.taxmethods]);
  2135. }
  2136. else {
  2137. if (debug) console.log("Tax methods note not null");
  2138. var temparray = vgap.plugins["plManagerPlugin"].getObjectFromNote(5,vgap.plugins["plManagerPlugin"].notetype);
  2139. if (temparray.length != 2) {
  2140. // An invalid array, reset
  2141. if (debug) console.log("Invalid Player Tax Methods Array Detected! Resetting...");
  2142. plg.resetTaxMethods();
  2143. plg.initSaveObjectAsNote(5, plg.notetype, [plugin_version,plg.taxmethods]);
  2144. }
  2145. else {
  2146. if (debug) console.log("Valid Player Tax Methods Array found, reading...");
  2147. var maxid = plg.getMaxId();
  2148. plg.taxmethods = temparray[1];
  2149. }
  2150. }
  2151. if (debug) console.log("Tax methods read, tax methods is " + vgap.plugins["plManagerPlugin"].taxmethods);
  2152. plg.readOrder++;
  2153. plg.readNotes();
  2154. break;
  2155. case '4':
  2156. case 4:
  2157. // Native Tax Method Array
  2158. if (vgap.plugins["plManagerPlugin"].getObjectFromNote(1,vgap.plugins["plManagerPlugin"].notetype) == null) {
  2159. if (debug) console.log("Native Tax Note is null, generating defaults...");
  2160. plg.resetNTArray();
  2161. plg.initSaveObjectAsNote(1, plg.notetype, [plugin_version,plg.ntarray]);
  2162. }
  2163. else {
  2164. if (debug) console.log("NTArray is not null, reading....");
  2165. var temparray = vgap.plugins["plManagerPlugin"].getObjectFromNote(1,vgap.plugins["plManagerPlugin"].notetype);
  2166. if (temparray.length != 2) {
  2167. // An invalid array, reset
  2168. if (debug) console.log("Invalid NT Array Detected! Resetting...");
  2169. plg.resetNTArray();
  2170. plg.initSaveObjectAsNote(1, plg.notetype, [plugin_version,plg.ntarray]);
  2171. }
  2172. else {
  2173. if (debug) console.log("Valid NTArray found, reading...");
  2174. var maxid = plg.getMaxId();
  2175. plg.ntarray = temparray[1];
  2176. // Check Array
  2177. if (plg.ntarray.length < maxid) {
  2178. if (debug) console.log("Invalid NTArray length found, correcting...");
  2179. // The array is not the correct length, make it right
  2180. for (var i = plg.ntarray.length; i <= maxid; i++) {
  2181. plg.ntarray[i] = 'm';
  2182. }
  2183. }
  2184. // Make sure there are no nulls or blanks
  2185. for (var j = 0; j < plg.ntarray.length; j++) {
  2186. if (plg.ntarray[j] == null || plg.ntarray[j] == "") {
  2187. if (debug) console.log("Invalid NTArray null/blank found, correcting...");
  2188. plg.ntarray[j] = 'm';
  2189. }
  2190. }
  2191. plg.initSaveObjectAsNote(1, plg.notetype, [plugin_version,plg.ntarray]);
  2192. }
  2193. }
  2194. if (debug) console.log("Nat Tax Method Array read, ntarray = " + vgap.plugins["plManagerPlugin"].ntarray);
  2195. plg.readOrder++;
  2196. plg.readNotes();
  2197. break;
  2198. case '5':
  2199. case 5:
  2200. // Colonist Tax Method Array
  2201. if (vgap.plugins["plManagerPlugin"].getObjectFromNote(2,vgap.plugins["plManagerPlugin"].notetype) == null) {
  2202. if (debug) console.log("Colonist Tax Note is null, generating defaults...");
  2203. plg.resetCTArray();
  2204. plg.initSaveObjectAsNote(2, plg.notetype, [plugin_version,plg.ctarray]);
  2205. }
  2206. else {
  2207. if (debug) console.log("Colonist Tax Methods Note is not null, reading....");
  2208. var temparray = vgap.plugins["plManagerPlugin"].getObjectFromNote(2,vgap.plugins["plManagerPlugin"].notetype);
  2209. if (temparray.length != 2) {
  2210. // An invalid array, reset
  2211. if (debug) console.log("Invalid CT Array Detected! Resetting...");
  2212. plg.resetCTArray();
  2213. plg.initSaveObjectAsNote(2, plg.notetype, [plugin_version,plg.ctarray]);
  2214. }
  2215. else {
  2216. if (debug) console.log("Valid CTArray found, reading...");
  2217. var maxid = plg.getMaxId();
  2218. plg.ctarray = temparray[1];
  2219. // Check Array
  2220. if (plg.ctarray.length < maxid) {
  2221. if (debug) console.log("Invalid CTArray length found, correcting...");
  2222. // The array is not the correct length, make it right
  2223. for (var i = plg.ctarray.length; i <= maxid; i++) {
  2224. plg.ctarray[i] = 'm';
  2225. }
  2226. }
  2227. // Make sure there are no nulls or blanks
  2228. for (var j = 0; j < plg.ctarray.length; j++) {
  2229. if (plg.ctarray[j] == null || plg.ctarray[j] == "") {
  2230. if (debug) console.log("Invalid CTArray null/blank found, correcting...");
  2231. plg.ctarray[j] = 'm';
  2232. }
  2233. }
  2234. plg.initSaveObjectAsNote(2, plg.notetype, [plugin_version,plg.ctarray]);
  2235. }
  2236. }
  2237. if (debug) console.log("CT Method Array read, ctarray = " + vgap.plugins["plManagerPlugin"].ctarray);
  2238. plg.readOrder++;
  2239. plg.readNotes();
  2240. break;
  2241. case '6':
  2242. case 6:
  2243. if (debug) console.log("Read Notes is performing final checks...");
  2244. plg.printArrayToConsole(plg.ctarray,"CTARRAY");
  2245. if (debug) console.log("CT Method VIS VIS VIS, ctarray = " + vgap.plugins["plManagerPlugin"].ctarray);
  2246. // Perform checks
  2247. // Check
  2248. for (var i = 0; i < plg.ctarray.length; i++) {
  2249. if (vgap.plugins["plManagerPlugin"].ctarray[i] >= vgap.plugins["plManagerPlugin"].taxmethods.length)
  2250. vgap.plugins["plManagerPlugin"].ctarray[i] = 'm';
  2251. }
  2252. // Check to see if any are out of range
  2253. for (var i = 0; i < plg.ntarray.length; i++) {
  2254. if (vgap.plugins["plManagerPlugin"].ntarray[i] >= vgap.plugins["plManagerPlugin"].taxmethods.length)
  2255. vgap.plugins["plManagerPlugin"].ntarray[i] = 'm';
  2256. }
  2257. break;
  2258. }
  2259. },
  2260. printArrayToConsole: function(arr,str) {
  2261. console.log("Printing " + str + " array...");
  2262. console.log(arr);
  2263. },
  2264. saveInitChanges: function() {
  2265. var plg = vgap.plugins["plManagerPlugin"];
  2266. if (vgap.saveInProgress == 2) {
  2267. // We are still saving, check again in a little bit
  2268. if (debug) console.log("Save in progress, waiting 500... ReadOrder: " + plg.readOrder);
  2269. timeoutID = window.setTimeout(vgap.plugins["plManagerPlugin"].saveInitChanges, 500);
  2270. return;
  2271. }
  2272. else if (vgap.saveInProgress == 0 && vgap.plugins["plManagerPlugin"].savestarted == true) {
  2273. // We have performed a save. Read the next bit of stuff
  2274. if (debug) vgap.plugins["plManagerPlugin"].savestarted = false;
  2275. console.log("Reading done, reading next..." + (plg.readOrder + 1));
  2276. if (plg.readOrder >= 6) {
  2277. console.log("Reading complete.");
  2278. return;
  2279. }
  2280. else {
  2281. //plg.readOrder++;
  2282. //plg.readNotes();
  2283. }
  2284. }
  2285. else {
  2286. // We can save now
  2287. if (debug) vgap.plugins["plManagerPlugin"].savestarted = true;
  2288. vgap.save();
  2289. timeoutID = window.setTimeout(vgap.plugins["plManagerPlugin"].saveInitChanges, 500);
  2290. }
  2291. },
  2292. /* End Read In Functions */
  2293. /* This function takes a protoplanet, and predicts its future.
  2294. * The protoplanet is not a full fledged nu planet object.
  2295. * It is an object built here that contains only those values necessary
  2296. * to computing the planets future.
  2297. *
  2298. * This function is recursive.
  2299. */
  2300. planetPredictor: function(pl, turn, totalturns) {
  2301. var plg = vgap.plugins["plManagerPlugin"];
  2302. if (debug) console.log("Planet predictor called, turn= " + turn);
  2303. if (turn > totalturns) { // Only compute out to 50 turns
  2304. // Print out the predict array
  2305. /*
  2306. for (var i = 0; i < plg.predictarray.length; i++) {
  2307. plg.printPlanet(plg.predictarray[i], i);
  2308. }
  2309. */
  2310. return;
  2311. }
  2312. if (turn == 0) {
  2313. // First call. Set up the protoplanet
  2314. var np = new Object();
  2315. np = plg.clonePlanet(pl);
  2316. plg.pplanet = np;
  2317. //plg.planet = {};
  2318. //plg.pplanet = plg.clonePlanet(pl);
  2319. plg.predictarray = [];
  2320. plg.predicttimes = new Object();
  2321. plg.predicttimes.ttSB = -1;
  2322. plg.predicttimes.ttMaxCols = -1;
  2323. plg.predicttimes.ttMaxNats = -1;
  2324. plg.predicttimes.ttNMO = -1;
  2325. plg.predicttimes.ttDMO = -1;
  2326. plg.predicttimes.ttTMO = -1;
  2327. plg.predicttimes.ttMMO = -1;
  2328. //plg.printPlanet(turn);
  2329. plg.planetSetTaxGeneral(true);
  2330. plg.predictarray.push(plg.pplanet);
  2331. plg.checkPredictTimes(turn);
  2332. //plg.pplanet = {};
  2333. //plg.pplanet = plg.clonePlanet(plg.predictarray[plg.predictarray.length-1]);
  2334. }
  2335. if (debug) console.log("Entered turn not 0, turn= " + turn);
  2336. //plg.pplanet = null;
  2337. //plg.pplanet = new Object();
  2338. plg.pplanet = {};
  2339. plg.pplanet = plg.clonePlanet(plg.predictarray[plg.predictarray.length-1]);
  2340. if (debug) console.log("pplanet cloned, turn= " + turn);
  2341. // Bughunting: Break out if we're predicting negative clans
  2342. if (plg.pplanet.clans < 0)
  2343. return;
  2344. // Build structures
  2345. if (plg.bmarray[plg.pplanet.id] != 'm') {
  2346. var bmarrayindex = plg.pplanet.id;
  2347. var bm = plg.bmarray[bmarrayindex];
  2348. var bmstring = plg.buildmethods[bm][1];
  2349. plg.buildBldgsGeneral(bmstring, true);
  2350. }
  2351. // Structure decay
  2352. // Happiness change
  2353. // colonist taxation amounts
  2354. var colmc = plg.colTaxAmount(plg.pplanet);
  2355. /* Requires planet - factories, mines, taxrate, clans */
  2356. var colhappychange = vgap.colonistTaxChange(plg.pplanet);
  2357. plg.pplanet.colonisthappypoints = Math.min(100, plg.pplanet.colonisthappypoints += colhappychange);
  2358. // native taxation amounts
  2359. // Requires nativetaxvalue, nativetype, nativegovernment
  2360. if (plg.pplanet.nativeclans > 0) {
  2361. var natmc = plg.natTaxAmount(plg.pplanet);
  2362. var nathappychange = vgap.nativeTaxChange(plg.pplanet);
  2363. plg.pplanet.nativehappypoints = Math.min(100, plg.pplanet.nativehappypoints += nathappychange);
  2364. //plg.pplanet.nativehappypoints += nathappychange;
  2365. }
  2366. // Supplies produced
  2367. plg.pplanet.supplies += plg.pplanet.factories;
  2368. if (plg.pplanet.nativeclans > 0) {
  2369. if (plg.pplanet.nativetype == 2) {
  2370. plg.pplanet.supplies += Math.min(plg.pplanet.clans, Math.floor(plg.pplanet.nativeclans / 100));
  2371. }
  2372. }
  2373. // MC Generated
  2374. if (plg.pplanet.colonisthappypoints > 30)
  2375. plg.pplanet.megacredits += colmc;
  2376. if (plg.pplanet.nativeclans > 0) {
  2377. if (plg.pplanet.nativehappypoints > 30)
  2378. plg.pplanet.megacredits += natmc;
  2379. }
  2380. // Borg assimilation
  2381. var player = vgap.getPlayer(plg.pplanet.ownerid);
  2382. if (vgap.player.raceid == 6 && plg.pplanet.nativeclans > 0) {
  2383. if (plg.pplanet.nativetype != 5) {
  2384. if (plg.pplanet.clans > plg.pplanet.nativeclans) {
  2385. plg.pplanet.clans += plg.pplanet.nativeclans;
  2386. plg.pplanet.nativeclans = 0;
  2387. }
  2388. else {
  2389. plg.pplanet.nativeclans -= plg.pplanet.clans;
  2390. plg.pplanet.clans += plg.pplanet.clans;
  2391. }
  2392. }
  2393. }
  2394. // Apply population growth
  2395. if (debug) console.log("Applying population growth, colonist happy = " + plg.pplanet.colonisthappypoints);
  2396. if (plg.pplanet.colonisthappypoints >= 70) {
  2397. console.log("In colonisthappy if, preparing to apply, clans = " + plg.pplanet.clans + ", growth = " + plg.myColPopGrowth(plg.pplanet,true));
  2398. plg.pplanet.clans += plg.myColPopGrowth(plg.pplanet,true);
  2399. console.log("After apply, clans = " + plg.pplanet.clans + ", growth = " + plg.myColPopGrowth(plg.pplanet,true));
  2400. }
  2401. if (plg.pplanet.nativehappypoints >= 70)
  2402. plg.pplanet.nativeclans += plg.myNatPopGrowth(plg.pplanet,true);
  2403. // Overpop dies and eats supplies
  2404. // Death taken care of above, just need to eat supplies
  2405. if (plg.pplanet.clans > plg.getMaxColonists(plg.pplanet,false))
  2406. plg.pplanet.supplies = Math.max(0, plg.pplanet.supplies -= Math.floor((1 + ((plg.pplanet.clans - plg.getMaxColonists(plg.pplanet,false))/40))));
  2407. // Amorphs eat clans
  2408. // Taken care of above
  2409. // Riots
  2410. if (plg.pplanet.colonisthappypoints < 40) {
  2411. // Colonists are rioting
  2412. plg.pplanet.factories = Math.max(0,(plg.pplanet.factories - 8));
  2413. plg.pplanet.mines = Math.max(0,(plg.pplanet.mines - 10));
  2414. }
  2415. if (plg.pplanet.nativeclans > 0) {
  2416. if (plg.pplanet.nativehappypoints < 40) {
  2417. // Natives are rioting
  2418. plg.pplanet.factories = Math.max(0,(plg.pplanet.factories - 3));
  2419. plg.pplanet.mines = Math.max(0,(plg.pplanet.factories - 5));
  2420. }
  2421. }
  2422. // Civil War
  2423. if (plg.pplanet.colonisthappypoints < 0 || (plg.pplanet.nativeclans > 0 && plg.pplanet.nativehappypoints < 0)) {
  2424. // The planet is in a state of civil war
  2425. plg.pplanet.factories = Math.max(0,(plg.pplanet.factories - 8));
  2426. plg.pplanet.mines = Math.max(0,(plg.pplanet.mines - 10));
  2427. plg.pplanet.clans = Math.max(0, (Math.floor(plg.pplanet.clans * 0.7) - 100));
  2428. if (plg.pplanet.racetype != 5)
  2429. plg.pplanet.nativeclans = Math.max(0, (Math.floor(plg.pplanet.nativeclans * 0.7) - 100));
  2430. }
  2431. // Mine the minerals
  2432. // Neutronium
  2433. //console.log("NEUT DEBUG: rate is " + plg.myMiningRate(plg.pplanet, plg.pplanet.densityneutronium));
  2434. if (plg.pplanet.groundneutronium < plg.myMiningRate(plg.pplanet, plg.pplanet.densityneutronium)) {
  2435. plg.pplanet.neutronium += plg.pplanet.groundneutronium;
  2436. plg.pplanet.groundneutronium = 0;
  2437. }
  2438. else {
  2439. plg.pplanet.neutronium += plg.myMiningRate(plg.pplanet, plg.pplanet.densityneutronium);
  2440. plg.pplanet.groundneutronium -= plg.myMiningRate(plg.pplanet, plg.pplanet.densityneutronium);
  2441. }
  2442. // Duranium
  2443. if (plg.pplanet.groundduranium < plg.myMiningRate(plg.pplanet, plg.pplanet.densityduranium)) {
  2444. plg.pplanet.duranium += plg.pplanet.groundduranium;
  2445. plg.pplanet.groundduranium = 0;
  2446. }
  2447. else {
  2448. plg.pplanet.duranium += plg.myMiningRate(plg.pplanet, plg.pplanet.densityduranium);
  2449. plg.pplanet.groundduranium -= plg.myMiningRate(plg.pplanet, plg.pplanet.densityduranium);
  2450. }
  2451. // Tritanium
  2452. if (plg.pplanet.groundtritanium < plg.myMiningRate(plg.pplanet, plg.pplanet.densitytritanium)) {
  2453. plg.pplanet.tritanium += plg.pplanet.groundtritanium;
  2454. plg.pplanet.groundtritanium = 0;
  2455. }
  2456. else {
  2457. plg.pplanet.tritanium += plg.myMiningRate(plg.pplanet, plg.pplanet.densitytritanium);
  2458. plg.pplanet.groundtritanium -= plg.myMiningRate(plg.pplanet, plg.pplanet.densitytritanium);
  2459. }
  2460. // Molybdenum
  2461. if (plg.pplanet.groundmolybdenum < plg.myMiningRate(plg.pplanet, plg.pplanet.densitymolybdenum)) {
  2462. plg.pplanet.molybdenum += plg.pplanet.groundmolybdenum;
  2463. plg.pplanet.groundmolybdenum = 0;
  2464. }
  2465. else {
  2466. plg.pplanet.molybdenum += plg.myMiningRate(plg.pplanet, plg.pplanet.densitymolybdenum);
  2467. plg.pplanet.groundmolybdenum -= plg.myMiningRate(plg.pplanet, plg.pplanet.densitymolybdenum);
  2468. }
  2469. // Trans-uranium mutation
  2470. // If this is an iteration we're saving to the array, push it
  2471. // If we're not done predicting, call again
  2472. turn += 1;
  2473. // Output the planet to console
  2474. //plg.printPlanet(turn);
  2475. if (debug) console.log("Pushing turn " + turn);
  2476. plg.predictarray.push(plg.pplanet);
  2477. plg.checkPredictTimes(turn);
  2478. if (debug) console.log("Recursive call");
  2479. plg.planetSetTaxGeneral(true);
  2480. plg.planetPredictor(plg.pplanet, turn, totalturns);
  2481. },
  2482. checkPredictTimes: function(turn) {
  2483. var plg = vgap.plugins["plManagerPlugin"];
  2484. /*
  2485. * Data Structure:
  2486. plg.predicttimes.ttSB = -1;
  2487. plg.predicttimes.ttMaxCols = -1;
  2488. plg.predicttimes.ttMaxNats = -1;
  2489. plg.predicttimes.ttNMO = -1;
  2490. plg.predicttimes.ttDMO = -1;
  2491. plg.predicttimes.ttTMO = -1;
  2492. plg.predicttimes.ttMMO = -1;
  2493. */
  2494. if (plg.predicttimes.ttSB == -1 && plg.pplanet.megacredits + plg.pplanet.supplies >= 900 && plg.pplanet.duranium >= 120 && plg.pplanet.tritanium >= 402 && plg.pplanet.molybdenum >= 340)
  2495. plg.predicttimes.ttSB = turn;
  2496. //console.log("Checking predict, turn = " + turn + " cols = " + plg.pplanet.clans + ", max cols = " + plg.getMaxColonists(plg.pplanet,false));
  2497. if (plg.predicttimes.ttMaxCols == -1 && plg.pplanet.clans >= plg.getMaxColonists(plg.pplanet,false))
  2498. plg.predicttimes.ttMaxCols = turn;
  2499. if (plg.pplanet.nativeclans > 0) {
  2500. if (plg.predicttimes.ttMaxNats == -1 && plg.pplanet.nativeclans >= plg.getMaxNatives(plg.pplanet))
  2501. plg.predicttimes.ttMaxNats = turn;
  2502. }
  2503. if (plg.predicttimes.ttNMO == -1 && plg.pplanet.groundneutronium == 0)
  2504. plg.predicttimes.ttNMO = turn;
  2505. if (plg.predicttimes.ttDMO == -1 && plg.pplanet.groundduranium == 0)
  2506. plg.predicttimes.ttDMO = turn;
  2507. if (plg.predicttimes.ttTMO == -1 && plg.pplanet.groundtritanium == 0)
  2508. plg.predicttimes.ttTMO = turn;
  2509. if (plg.predicttimes.ttMMO == -1 && plg.pplanet.groundmolybdenum == 0)
  2510. plg.predicttimes.ttMMO = turn;
  2511. },
  2512. clonePlanet: function(pl) {
  2513. var newplanet = new Object();
  2514. newplanet.id = pl.id;
  2515. newplanet.x = pl.x;
  2516. newplanet.y = pl.y;
  2517. newplanet.debrisdisk = pl.debrisdisk;
  2518. newplanet.ownerid = pl.ownerid;
  2519. newplanet.img = pl.img;
  2520. newplanet.name = pl.name;
  2521. newplanet.temp = pl.temp;
  2522. newplanet.factories = pl.factories;
  2523. if (debug) console.log("Setting factories: pl.fact = " + pl.factories + " , pplan.fact = " + newplanet.factories);
  2524. newplanet.mines = pl.mines;
  2525. newplanet.defense = pl.defense;
  2526. newplanet.supplies = pl.supplies;
  2527. newplanet.megacredits = pl.megacredits;
  2528. newplanet.clans = pl.clans;
  2529. newplanet.colonisthappypoints = pl.colonisthappypoints;
  2530. newplanet.colonisttaxrate = pl.colonisttaxrate;
  2531. newplanet.nativeclans = pl.nativeclans;
  2532. newplanet.nativetype = pl.nativetype;
  2533. newplanet.nativeracename = pl.nativeracename;
  2534. newplanet.nativetaxrate = pl.nativetaxrate;
  2535. newplanet.nativetaxvalue = pl.nativetaxvalue;
  2536. newplanet.nativehappypoints = pl.nativehappypoints;
  2537. newplanet.nativegovernment = pl.nativegovernment;
  2538. newplanet.nativegovernmentname = pl.nativegovernmentname;
  2539. newplanet.neutronium = pl.neutronium;
  2540. newplanet.groundneutronium = pl.groundneutronium;
  2541. newplanet.densityneutronium = pl.densityneutronium;
  2542. newplanet.duranium = pl.duranium;
  2543. newplanet.groundduranium = pl.groundduranium;
  2544. newplanet.densityduranium = pl.densityduranium;
  2545. newplanet.tritanium = pl.tritanium;
  2546. newplanet.groundtritanium = pl.groundtritanium;
  2547. newplanet.densitytritanium = pl.densitytritanium;
  2548. newplanet.molybdenum = pl.molybdenum;
  2549. newplanet.groundmolybdenum = pl.groundmolybdenum;
  2550. newplanet.densitymolybdenum = pl.densitymolybdenum;
  2551. return newplanet;
  2552. },
  2553. printPlanet: function(p,turn) {
  2554. var plg = vgap.plugins["plManagerPlugin"];
  2555. console.log("**** Planet Predictor - Turn " + turn + " ***");
  2556. console.log("id: " + p.id);
  2557. console.log("ownerid: " + p.ownerid);
  2558. console.log("temp: " + p.temp);
  2559. console.log("factories: " + p.factories);
  2560. console.log("mines: " + p.mines);
  2561. console.log("defense: " + p.defense);
  2562. console.log("supplies: " + p.supplies);
  2563. console.log("megacredits: " + p.megacredits);
  2564. console.log("clans: " + p.clans);
  2565. console.log("colonisthappypoints: " + p.colonisthappypoints);
  2566. console.log("colonisttaxrate: " + p.colonisttaxrate);
  2567. console.log("nativeclans: " + p.nativeclans);
  2568. console.log("nativetype: " + p.nativetype);
  2569. console.log("nativeracename: " + p.nativeracename);
  2570. console.log("nativetaxrate: " + p.nativetaxrate);
  2571. console.log("nativehappypoints: " + p.nativehappypoints);
  2572. console.log("nativegovernment: " + p.nativegovernment);
  2573. console.log("neutronium: " + p.neutronium);
  2574. console.log("groundneutronium: " + p.groundneutronium);
  2575. console.log("densityneutronium: " + p.densityneutronium);
  2576. console.log("duranium: " + p.duranium);
  2577. console.log("groundduranium: " + p.groundduranium);
  2578. console.log("densityduranium: " + p.densityduranium);
  2579. console.log("tritanium: " + p.tritanium);
  2580. console.log("groundtritanium: " + p.groundtritanium);
  2581. console.log("densitytritanium: " + p.densitytritanium);
  2582. console.log("molybdenum: " + p.molybdenum);
  2583. console.log("groundmolybdenum: " + p.groundmolybdenum);
  2584. console.log("densitymolybdenum: " + p.densitymolybdenum);
  2585. console.log("**** End Planet Predictor - Turn " + turn + " ***");
  2586. },
  2587. predictChangeFactories: function(change) {
  2588. var plg = vgap.plugins["plManagerPlugin"];
  2589. var planet = plg.pplanet;
  2590. if (change > 0) {
  2591. //make sure we have enough resources for the change
  2592. if (planet.supplies < change)
  2593. change = planet.supplies;
  2594. //check the total amount we can build
  2595. if ((planet.megacredits + planet.supplies) < (change * 4))
  2596. change = Math.floor((planet.megacredits + planet.supplies) / 4);
  2597. //max factories
  2598. var max = plg.maxBldgs(plg.pplanet,100);
  2599. //we are already over the limit (nothing can be done)
  2600. if (planet.factories > max)
  2601. return;
  2602. if ((planet.factories + change) > max)
  2603. change = max - planet.factories;
  2604. //sell supplies to reach the change
  2605. if (planet.megacredits < (change * 3)) {
  2606. var diff = (change * 3) - planet.megacredits;
  2607. planet.megacredits += diff;
  2608. planet.supplies -= diff;
  2609. }
  2610. }
  2611. else {
  2612. }
  2613. planet.supplies -= change;
  2614. planet.megacredits -= change * 3;
  2615. planet.factories += change;
  2616. },
  2617. predictChangeMines: function(change) {
  2618. var plg = vgap.plugins["plManagerPlugin"];
  2619. var planet = plg.pplanet;
  2620. if (change > 0) {
  2621. //make sure we have enough resources for the change
  2622. if (planet.supplies < change)
  2623. change = planet.supplies;
  2624. //check the total amount we can build
  2625. if ((planet.megacredits + planet.supplies) < (change * 5))
  2626. change = Math.floor((planet.megacredits + planet.supplies) / 5);
  2627. //max mines
  2628. var max = plg.maxBldgs(plg.pplanet,200);
  2629. //we are already over the limit (nothing can be done)
  2630. if (planet.mines > max)
  2631. return;
  2632. if ((planet.mines + change) > max)
  2633. change = max - planet.mines;
  2634. //sell supplies to reach the change
  2635. if (planet.megacredits < (change * 4)) {
  2636. var diff = (change * 4) - planet.megacredits;
  2637. planet.megacredits += diff;
  2638. planet.supplies -= diff;
  2639. }
  2640. }
  2641. else {
  2642. }
  2643. planet.supplies -= change;
  2644. planet.megacredits -= change * 4;
  2645. planet.mines += change;
  2646. },
  2647. predictChangeDefense: function(change) {
  2648. var plg = vgap.plugins["plManagerPlugin"];
  2649. var planet = plg.pplanet;
  2650. if (change > 0) {
  2651. //make sure we have enough resources for the change
  2652. if (planet.supplies < change)
  2653. change = planet.supplies;
  2654. //check the total amount we can build
  2655. if ((planet.megacredits + planet.supplies) < (change * 11))
  2656. change = Math.floor((planet.megacredits + planet.supplies) / 11);
  2657. //max defense
  2658. var max = this.maxBldgs(plg.pplanet);
  2659. //we are already over the limit (nothing can be done)
  2660. if (planet.defense > max)
  2661. return;
  2662. if ((planet.defense + change) > max)
  2663. change = max - planet.defense;
  2664. //sell supplies to reach the change
  2665. if (planet.megacredits < (change * 10)) {
  2666. var diff = (change * 10) - planet.megacredits;
  2667. planet.megacredits += diff;
  2668. planet.supplies -= diff;
  2669. }
  2670. }
  2671. else {
  2672. }
  2673. planet.supplies -= change;
  2674. planet.megacredits -= change * 10;
  2675. planet.defense += change;
  2676. },
  2677. /* End Prediction functions */
  2678. myNatPopGrowth: function (planet, predict) {
  2679. var nativeGrowth = 0;
  2680. var nativeMax = 0;
  2681. // Hiss check
  2682. var hissships = 0;
  2683. var hapmod = 0;
  2684. var plships = vgap.shipsAt(planet.x, planet.y);
  2685. for (var i = 0; i < plships.length; i++) {
  2686. //console.log("---> " + JSON.stringify(plships[i]));
  2687. var raceid = vgap.getPlayer(plships[i].ownerid).raceid;
  2688. if (raceid == 2 && plships[i].mission == 8)
  2689. hissships += 1;
  2690. if (hissships > 0) {
  2691. hapmod = (hissships * 5)
  2692. if (planet.nativehappypoints + hapmod > 100)
  2693. hapmod = 100-planet.nativehappypoints;
  2694. }
  2695. }
  2696. //console.log("In myNatPopGrowth, before if, expr >= 70 = " + (planet.nativehappypoints + hapmod + vgap.nativeTaxChange(planet)));
  2697. //console.log("In myNatPopGrowth, before if, hapmod = " + hapmod);
  2698. //console.log("In myNatPopGrowth, before if, native tax change = " + vgap.nativeTaxChange(planet));
  2699. var compval;
  2700. if (predict)
  2701. compval = planet.nativehappypoints + hapmod;
  2702. else
  2703. compval = (planet.nativehappypoints + hapmod + vgap.nativeTaxChange(planet));
  2704. if (compval >= 70 && planet.nativeclans > 0 && planet.clans > 0) {
  2705. //console.log("In myNatPopGrowth, entered if");
  2706. if (planet.nativetype == 9) {
  2707. //siliconoid like it hot
  2708. nativeMax = planet.temp * 1000;
  2709. nativeGrowth = nativeGrowth + Math.round(((planet.temp / 100) * (planet.nativeclans / 25) * (5 / (planet.nativetaxrate + 5))));
  2710. //console.log("In myNatPopGrowth, siliconoids, native growth = " + nativeGrowth);
  2711. }
  2712. else {
  2713. nativeMax = Math.round(Math.sin(3.14 * (100 - planet.temp) / 100) * 150000);
  2714. nativeGrowth = nativeGrowth + Math.round(Math.sin(3.14 * ((100 - planet.temp) / 100)) * (planet.nativeclans / 25) * (5 / (planet.nativetaxrate + 5)));
  2715. //console.log("In myNatPopGrowth, " + planet.nativeracename + ", native growth = " + nativeGrowth);
  2716. }
  2717. //slows down over 6,600,000
  2718. if (planet.nativeclans > 66000)
  2719. nativeGrowth = Math.round(nativeGrowth / 2);
  2720. //check max
  2721. if (planet.nativeclans > nativeMax)
  2722. nativeGrowth = 0;
  2723. }
  2724. //console.log("In myNatPopGrowth, done, returning native growth = " + nativeGrowth);
  2725. return nativeGrowth;
  2726. },
  2727. myColPopGrowth: function (planet,predict) {
  2728. var player = vgap.getPlayer(planet.ownerid);
  2729. var raceId = player.raceid;
  2730. var colGrowth = 0;
  2731. // Hiss check
  2732. var hissships = 0;
  2733. var hapmod = 0;
  2734. var plships = vgap.shipsAt(planet.x, planet.y);
  2735. for (var i = 0; i < plships.length; i++) {
  2736. //console.log("---> " + JSON.stringify(plships[i]));
  2737. var raceid = vgap.getPlayer(plships[i].ownerid).raceid;
  2738. if (raceid == 2 && plships[i].mission == 8)
  2739. hissships += 1;
  2740. if (hissships > 0) {
  2741. hapmod = (hissships * 5)
  2742. if (planet.colonisthappypoints + hapmod > 100)
  2743. hapmod = 100-planet.colonisthappypoints;
  2744. }
  2745. }
  2746.  
  2747. //onsole.log("In myColPopGrowth, before if, expr >= 70 = " + (planet.colonisthappypoints + hapmod + vgap.colonistTaxChange(planet)));
  2748. //console.log("In myColPopGrowth, before if, hapmod = " + hapmod);
  2749. //console.log("In myColPopGrowth, before if, colonist tax change = " + vgap.colonistTaxChange(planet));
  2750. var compval;
  2751. if (predict)
  2752. compval = planet.colonisthappypoints + hapmod;
  2753. else
  2754. compval = (planet.colonisthappypoints + hapmod + vgap.colonistTaxChange(planet));
  2755. //if ((planet.colonisthappypoints + hapmod + vgap.colonistTaxChange(planet)) >= 70 && planet.clans > 0) {
  2756. if (compval >= 70 && planet.clans > 0) {
  2757. var colMax = Math.round(Math.sin(3.14 * (100 - planet.temp) / 100) * 100000);
  2758. //crystals like it hot
  2759. if (raceId == 7) {
  2760. colMax = 1000 * planet.temp;
  2761. colGrowth = Math.round(((planet.temp / 100) * (planet.clans / 20) * (5 / (planet.colonisttaxrate + 5))));
  2762. if (vgap.advActive(47))
  2763. colGrowth = Math.round((((planet.temp * planet.temp) / 4000) * (planet.clans / 20) * (5 / (planet.colonisttaxrate + 5))));
  2764. }
  2765. else if (planet.temp >= 15 && planet.temp <= 84)
  2766. colGrowth = Math.round(Math.sin(3.14 * ((100 - planet.temp) / 100)) * (planet.clans / 20) * (5 / (planet.colonisttaxrate + 5)));
  2767. //slows down over 6,600,000
  2768. if (planet.clans > 66000)
  2769. colGrowth = Math.round(colGrowth / 2);
  2770. //planetoids do not have an atmosphere
  2771. if (planet.debrisdisk > 0)
  2772. colGrowth = 0;
  2773. //check against max
  2774. if ((planet.clans + colGrowth) > colMax)
  2775. colGrowth = colMax - planet.clans;
  2776. //100 and 0 degree planets
  2777. if (colGrowth < 0)
  2778. colGrowth = 0;
  2779. }
  2780. if (colGrowth == 0)
  2781. colGrowth = vgap.plugins["plManagerPlugin"].getMaxColonists(planet,true);
  2782. if (planet.nativetype == 5)
  2783. colGrowth -= Math.max(5, 95 - (planet.nativehappypoints + vgap.nativeTaxChange(planet)));
  2784. return colGrowth;
  2785. },
  2786. checkTaxModel: function(tm) {
  2787. if (tm.name == "") {
  2788. if (debug) console.log("CHECK TAX MODEL FALSE: bad name");
  2789. return false;
  2790. }
  2791. if (tm.taxType == "") {
  2792. if (debug) console.log("CHECK TAX MODEL FALSE: bad type");
  2793. return false;
  2794. }
  2795. if (!(vgap.plugins["plManagerPlugin"].isInteger(tm.minHappy))) {
  2796. if (debug) console.log("CHECK TAX MODEL FALSE: bad min happy main");
  2797. return false;
  2798. }
  2799. if (!(vgap.plugins["plManagerPlugin"].isInteger(tm.minClans))) {
  2800. if (debug) console.log("CHECK TAX MODEL FALSE: bad min clans main");
  2801. return false;
  2802. }
  2803. if (tm.method == "Growth") {
  2804. if (!(vgap.plugins["plManagerPlugin"].isInteger(tm.maxHappy))) {
  2805. if (debug) console.log("CHECK TAX MODEL FALSE: bad growth max happy");
  2806. return false;
  2807. }
  2808. }
  2809. /*
  2810. var taxModel1 = new Object();
  2811. taxModel1.name = "My First Growth Tax";
  2812. taxModel1.method = "Growth";
  2813. taxModel1.taxType = "CN";
  2814. taxModel1.minHappy = 70;
  2815. taxModel1.maxHappy = 100;
  2816. taxModel1.minClans = 1000;
  2817. // New parts added
  2818. taxModel1.midsame = false;
  2819. taxModel1.midmethod = "Growth";
  2820. taxModel1.midMinHappy = 70;
  2821. taxModel1.midMaxHappy = 100;
  2822. *
  2823. taxModel1.maxsame = false;
  2824. taxModel1.maxmethod = "Growth";
  2825. taxModel1.maxMinHappy = 70;
  2826. taxModel1.maxMaxHappy = 100;
  2827. */
  2828. if (tm.midsame == false) {
  2829. if (tm.midmethod == "") {
  2830. if (debug) console.log("CHECK TAX MODEL FALSE: bad mid method");
  2831. return false;
  2832. }
  2833. if (!(vgap.plugins["plManagerPlugin"].isInteger(tm.midMinHappy))) {
  2834. if (debug) console.log("CHECK TAX MODEL FALSE: bad mid min happy");
  2835. return false;
  2836. }
  2837. if (tm.midmethod == "Growth") {
  2838. if (!(vgap.plugins["plManagerPlugin"].isInteger(tm.midMaxHappy))) {
  2839. if (debug) console.log("CHECK TAX MODEL FALSE: bad mid max happy");
  2840. return false;
  2841. }
  2842. }
  2843. }
  2844. if (tm.maxsame == false) {
  2845. if (tm.maxmethod == "") {
  2846. if (debug) console.log("CHECK TAX MODEL FALSE: bad max method");
  2847. return false;
  2848. }
  2849. if (!(vgap.plugins["plManagerPlugin"].isInteger(tm.maxMinHappy))) {
  2850. if (debug) console.log("CHECK TAX MODEL FALSE: bad max min happy");
  2851. if (debug) console.log("Max Min Happy: " + tm.maxMinHappy);
  2852. return false;
  2853. }
  2854. if (tm.maxmethod == "Growth") {
  2855. if (!(vgap.plugins["plManagerPlugin"].isInteger(tm.maxMaxHappy))) {
  2856. if (debug) console.log("CHECK TAX MODEL FALSE: bad max max happy");
  2857. return false;
  2858. }
  2859. }
  2860. }
  2861. return true;
  2862. },
  2863. getTaxText: function(taxmethod) {
  2864. /*
  2865. var taxModel1 = new Object();
  2866. taxModel1.name = "My First Growth Tax";
  2867. taxModel1.method = "Growth";
  2868. taxModel1.taxType = "CN";
  2869. taxModel1.minHappy = 70;
  2870. taxModel1.maxHappy = 100;
  2871. taxModel1.minClans = 1000;
  2872. * // New parts added
  2873. taxModel1.midsame = false;
  2874. taxModel1.midmethod = "Growth";
  2875. taxModel1.midMinHappy = 70;
  2876. taxModel1.midMaxHappy = 100;
  2877. *
  2878. taxModel1.maxsame = false;
  2879. taxModel1.maxmethod = "Growth";
  2880. taxModel1.maxMinHappy = 70;
  2881. taxModel1.maxMaxHappy = 100;
  2882. */
  2883. var taxtext = "Tax ";
  2884. if (taxmethod.taxType == 'N')
  2885. taxtext += " the natives ";
  2886. if (taxmethod.taxType == 'C')
  2887. taxtext += " the colonists ";
  2888. if (taxmethod.taxType == 'N')
  2889. taxtext += " the colonists or the natives ";
  2890. if (taxmethod.method == 'Growth') {
  2891. taxtext += "using the " + taxmethod.method + " tax method. This method will tax at the highest collectable rate ";
  2892. taxtext += "that will reduce their happiness to " + taxmethod.minHappy + ", then tax at 0 until they have recovered ";
  2893. taxtext += "to a happiness of " + taxmethod.maxHappy + " before taxing again. Only tax if there are more than ";
  2894. taxtext += taxmethod.minClans + " clans on the planet.<br /><br />";
  2895. }
  2896. if (taxmethod.method == 'Safe') {
  2897. taxtext += "using the " + taxmethod.method + " tax method. This method will tax at the highest collectable rate ";
  2898. taxtext += "that will reduce their happiness to " + taxmethod.minHappy + ", then tax at a rate to maintain this level ";
  2899. taxtext += "of happiness. Only tax if there are more than ";
  2900. taxtext += taxmethod.minClans + " clans on the planet.<br /><br />";
  2901. }
  2902. if (taxmethod.midsame == false) {
  2903. taxtext += "If the population increases above 6,600,000, tax using the ";
  2904. if (taxmethod.midmethod == 'Growth') {
  2905. taxtext += taxmethod.midmethod + " method. This method will tax at the highest collectable rate that will reduce their ";
  2906. taxtext += "happiness to " + taxmethod.midMinHappy + ", then tax at 0 until they have recovered to a happiness of ";
  2907. taxtext += taxmethod.midMaxHappy + " before taxing again.<br /><br />";
  2908. }
  2909. if (taxmethod.midmethod == 'Safe') {
  2910. taxtext += taxmethod.midmethod + " method. This method will tax at the highest collectable rate that will reduce their ";
  2911. taxtext += "happiness to " + taxmethod.midMinHappy + ", then tax at a rate to maintain this level of happiness.<br /><br />";
  2912. }
  2913. }
  2914. if (taxmethod.maxsame == false) {
  2915. taxtext += "If the population reaches its maximum, tax using the ";
  2916. if (taxmethod.maxmethod == 'Growth') {
  2917. taxtext += taxmethod.maxmethod + " method. This method will tax at the highest collectable rate that will reduce their ";
  2918. taxtext += "happiness to " + taxmethod.maxMinHappy + ", then tax at 0 until they have recovered to a happiness of ";
  2919. taxtext += taxmethod.maxMaxHappy + " before taxing again.";
  2920. }
  2921. if (taxmethod.maxmethod == 'Safe') {
  2922. taxtext += taxmethod.maxmethod + " method. This method will tax at the highest collectable rate that will reduce their ";
  2923. taxtext += "happiness to " + taxmethod.maxMinHappy + ", then tax at a rate to maintain this level of happiness.";
  2924. }
  2925. }
  2926. return taxtext;
  2927. },
  2928. getMaxNatives: function(planet) {
  2929. if (planet.nativetype == 9) {
  2930. //siliconoid like it hot
  2931. return nativeMax = planet.temp * 1000;
  2932. }
  2933. else
  2934. return nativeMax = Math.round(Math.sin(3.14 * (100 - planet.temp) / 100) * 150000);
  2935. },
  2936. getMaxColonists: function(planet,getGrowth) {
  2937. var player = vgap.getPlayer(planet.ownerid);
  2938. var raceId = player.raceid;
  2939. var climateDeathRate = 10;
  2940. var maxSupported = 0;
  2941. var colGrowth = 0;
  2942. //crystal calculation
  2943. if (raceId == 7)
  2944. maxSupported = planet.temp * 1000;
  2945. else {
  2946. //all others
  2947. maxSupported = Math.round(Math.sin(3.14 * (100 - planet.temp) / 100) * 100000);
  2948. if (planet.temp > 84)
  2949. maxSupported = Math.floor((20099.9 - (200 * planet.temp)) / climateDeathRate);
  2950. else if (planet.temp < 15)
  2951. maxSupported = Math.floor((299.9 + (200 * planet.temp)) / climateDeathRate);
  2952. }
  2953. //Fascist, Robots, Rebels, Colonies can support a small colony of 60 clans on planets over 80 degrees
  2954. if (raceId == 4 || raceId == 9 || raceId == 10 || raceId == 11) {
  2955. if (planet.temp > 80)
  2956. maxSupported = Math.max(maxSupported, 60);
  2957. }
  2958. //rebel arctic planet advantage
  2959. if (planet.temp <= 19 && raceId == 10)
  2960. maxSupported = Math.max(maxSupported, 90000);
  2961. //planetoids do not have an atmosphere
  2962. if (planet.debrisdisk > 0) {
  2963. maxSupported = 0;
  2964. if (vgap.getStarbase(planet.id) != null)
  2965. maxSupported = 500;
  2966. }
  2967. if (!getGrowth)
  2968. return maxSupported;
  2969. //determine how much we are overpopulated
  2970. var overPopulation = Math.ceil((planet.clans - maxSupported) * (climateDeathRate / 100));
  2971. if (overPopulation > 0) {
  2972. //recalculate maxsupported/overpopulation
  2973. maxSupported = maxSupported + Math.round(planet.supplies * 10 / 40);
  2974. overPopulation = Math.ceil((planet.clans - maxSupported) * (climateDeathRate / 100));
  2975. //update population
  2976. colGrowth = -1 * Math.max(0, overPopulation);
  2977. }
  2978. return colGrowth;
  2979. },
  2980. showPlanetDetailFromStarmap: function(id) {
  2981. this.curplanet = id;
  2982. if (debug) console.log("Clicked! " + id);
  2983. vgap.showDashboard();
  2984. vgap.plugins["plManagerPlugin"].displayPM(1);
  2985. },
  2986. showPlanetDetail: function(id) {
  2987. this.curplanet = id;
  2988. if (debug) console.log("Clicked! " + id);
  2989. vgap.plugins["plManagerPlugin"].displayPM(1);
  2990. },
  2991. getFCColor: function(fc) {
  2992. // Borrowed from nu.js to match the client
  2993. var fcbox_color = "lightgrey";
  2994. fcu = fc.toUpperCase();
  2995. if (fcu == "NUK" || fcu == "ATT") fcbox_color = "red";
  2996. else if (fcu == "BUM") fcbox_color = "orchid";
  2997. else if (fcu == "DMP") fcbox_color = "magenta";
  2998. else if (fcu.substr(0, 2) == "PB") fcbox_color = "aqua";
  2999. return fcbox_color;
  3000. /*
  3001. if (fc.toLowerCase() == 'att' || fc.toLowerCase() == 'nuk')
  3002. return "#F62817";
  3003. else if (fc.toLowerCase() == 'pb1' || fc.toLowerCase() == 'pb2')
  3004. return "#0000FF";
  3005. return "#FFFFFFF";
  3006. */
  3007. },
  3008. getMineralGrdColor: function(amt) {
  3009. if (amt > 800)
  3010. return "#00FF00";
  3011. if (amt > 400)
  3012. return "#FFFF00";
  3013. return "#F62817";
  3014. },
  3015. getMineralSfcColor: function(amt) {
  3016. if (amt > 500)
  3017. return "#00FF00";
  3018. if (amt > 50)
  3019. return "#FFFF00";
  3020. return "#F62817";
  3021. },
  3022. getMineralDenColor: function(amt) {
  3023. if (amt > 75)
  3024. return "#00FF00";
  3025. if (amt > 25)
  3026. return "#FFFF00";
  3027. return "#F62817";
  3028. },
  3029. miningAmtPerTurn: function (planet, amount, density) {
  3030. if (planet.mines == 0)
  3031. return "";
  3032. var amt = vgap.plugins["plManagerPlugin"].myMiningRate(planet, density);
  3033. if (amount < amt)
  3034. amt = amount;
  3035. return amt + "/turn";
  3036. },
  3037. turnsToMineOut: function (planet, amount, density) {
  3038. if (planet.mines == 0)
  3039. return "";
  3040. if (amount <= 5)
  3041. return "Mined Out";
  3042. var amt = vgap.plugins["plManagerPlugin"].myMiningRate(planet, density);
  3043. if (amount < amt)
  3044. amt = amount;
  3045. var mot = Math.ceil(amount / amt);
  3046. if (mot == 1)
  3047. return mot + " turn";
  3048. else
  3049. return mot + " turns";
  3050. },
  3051. turnsToMineOutTheoretical: function (planet, amount, density, nummines) {
  3052. if (amount <= 5)
  3053. return "Mined Out";
  3054. var amt = vgap.plugins["plManagerPlugin"].myMiningRateAtNumMines(planet, density, nummines);
  3055. if (amount < amt)
  3056. amt = amount;
  3057. var mot = Math.ceil(amount / amt);
  3058. if (mot == 1)
  3059. return mot + " turn";
  3060. else
  3061. return mot + " turns";
  3062. },
  3063. miningAmtPerTurnTheoretical: function (planet, amount, density, nummines) {
  3064. var amt = vgap.plugins["plManagerPlugin"].myMiningRateAtNumMines(planet, density, nummines);
  3065. if (amount < amt)
  3066. amt = amount;
  3067. return amt + "/turn";
  3068. },
  3069. myMiningRateAtNumMines: function (planet, density, nummines) {
  3070. var factor = 1;
  3071. if (planet.nativetype == 3)
  3072. factor *= 2;
  3073. if (planet.debrisdisk > 0 && vgap.getStarbase(planet.id) != null)
  3074. factor *= 2;
  3075. var miningrate = 1;
  3076. if (vgap.advActive(31))
  3077. miningrate = 2;
  3078. else if (vgap.advActive(4))
  3079. miningrate = 0.7;
  3080. return Math.round(density / 100 * miningrate * factor * nummines);
  3081. },
  3082. myMiningRate: function (planet, density) {
  3083. var factor = 1;
  3084. if (planet.nativetype == 3)
  3085. factor *= 2;
  3086. if (planet.debrisdisk > 0 && vgap.getStarbase(planet.id) != null)
  3087. factor *= 2;
  3088. var miningrate = 1;
  3089. if (vgap.advActive(31))
  3090. miningrate = 2;
  3091. else if (vgap.advActive(4))
  3092. miningrate = 0.7;
  3093. return Math.round(density / 100 * miningrate * factor * planet.mines);
  3094. },
  3095. getAssimTurns: function(planet) {
  3096. //return 5;
  3097. var ctemp = planet.clans;
  3098. var ntemp = planet.nativeclans;
  3099. var turns = 1;
  3100. while (ctemp < ntemp)
  3101. {
  3102. ntemp -= ctemp;
  3103. ctemp += ctemp;
  3104. turns += 1;
  3105. }
  3106. return turns;
  3107. },
  3108. nwc: function(x) {
  3109. return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  3110. },
  3111. /*
  3112. getPossFacts: function(planet) {
  3113. if (planet.supplies < 3*planet.megacredits)
  3114. return planet.supplies;
  3115. else
  3116. return Math.truncate(planet.megacredits / 3);
  3117. },
  3118. */
  3119. getPossFacts: function(mc,sup) {
  3120. if (mc == 0)
  3121. return 0;
  3122. if (sup < 3*mc)
  3123. return sup;
  3124. else
  3125. return Math.truncate(mc / 3);
  3126. },
  3127. getPossMines: function(mc,sup) {
  3128. if (mc == 0)
  3129. return 0;
  3130. if (sup < 4*mc)
  3131. return sup;
  3132. else
  3133. return Math.truncate(mc / 4);
  3134. },
  3135. getPossDef: function(mc,sup) {
  3136. if (mc == 0)
  3137. return 0;
  3138. if (sup < 10*mc)
  3139. return sup;
  3140. else
  3141. return Math.truncate(mc / 10);
  3142. },
  3143. planetSetNativeTax: function() {
  3144. //console.log("Entered set Native Tax.");
  3145. var plg = vgap.plugins["plManagerPlugin"];
  3146. var planet = vgap.myplanets[plg.planetbuildindex];
  3147. if (planet.nativeclans > 0) {
  3148. switch (plg.ntarray[vgap.myplanets[plg.planetbuildindex].id]) {
  3149. case '1':
  3150. case 1:
  3151. // No tax
  3152. planet.nativetaxrate = 0;
  3153. break;
  3154. case '2':
  3155. case 2:
  3156. // Manual Taxing. Make no changes
  3157. break;
  3158. case '3':
  3159. case 3:
  3160. // Growth Taxing
  3161. planet.nativetaxrate = plg.getNativeGrowthTaxRate(planet);
  3162. break;
  3163. case '4':
  3164. case 4:
  3165. // Chunk Taxing
  3166. planet.nativetaxrate = plg.getNativeChunkTaxRate(planet);
  3167. break;
  3168. case '5':
  3169. case 5:
  3170. // No Riot Taxing
  3171. planet.nativetaxrate = plg.getNativeBorgTaxRate(planet);
  3172. break;
  3173. }
  3174. //planet.nativetaxrate = plg.getNativeGrowthTaxRate(planet);
  3175. planet.nativehappychange = vgap.nativeTaxChange(planet);
  3176. planet.changed = 1;
  3177. }
  3178. },
  3179. planetSetTaxGeneral: function(predict) {
  3180. var plg = vgap.plugins["plManagerPlugin"];
  3181. var planet;
  3182. if (predict)
  3183. planet = plg.pplanet;
  3184. else
  3185. planet = vgap.myplanets[plg.planetbuildindex];
  3186. var ctaxindex = plg.ctarray[planet.id];
  3187. if (debug) console.log("CTAXINDEX is " + ctaxindex);
  3188. var ntaxtindex;
  3189. var ntaxmodel;
  3190. if (planet.nativeclans > 0) {
  3191. ntaxindex = plg.ntarray[planet.id];
  3192. if (debug) console.log("nTAXINDEX is " + ntaxindex);
  3193. }
  3194. // Do Colonist Tax First
  3195. if (ctaxindex != 'm') {
  3196. var rate;
  3197. //var ctaxmodel = plg.taxmethods[ctaxindex];
  3198. var ctaxsmallmodel = new Object();
  3199. ctaxsmallmodel.method = plg.taxmethods[ctaxindex].method;
  3200. ctaxsmallmodel.minHappy = plg.taxmethods[ctaxindex].minHappy;
  3201. ctaxsmallmodel.maxHappy = plg.taxmethods[ctaxindex].maxHappy;
  3202. ctaxsmallmodel.minClans = plg.taxmethods[ctaxindex].minClans;
  3203. if (planet.clans > 66000 && plg.taxmethods[ctaxindex].midsame == false) {
  3204. ctaxsmallmodel.method = plg.taxmethods[ctaxindex].midmethod;
  3205. ctaxsmallmodel.minHappy = plg.taxmethods[ctaxindex].midMinHappy;
  3206. ctaxsmallmodel.maxHappy = plg.taxmethods[ctaxindex].midMaxHappy;
  3207. if (debug) console.log("Planet " + planet.name + ": Assigning mid tax");
  3208. }
  3209. if (planet.clans >= plg.getMaxColonists(planet,false) && plg.taxmethods[ctaxindex].maxsame == false) {
  3210. ctaxsmallmodel.method = plg.taxmethods[ctaxindex].maxmethod;
  3211. ctaxsmallmodel.minHappy = plg.taxmethods[ctaxindex].maxMinHappy;
  3212. ctaxsmallmodel.maxHappy = plg.taxmethods[ctaxindex].maxMaxHappy;
  3213. if (debug) console.log("Planet " + planet.name + ": Assigning max tax");
  3214. }
  3215. if (debug) console.log("Planet " + planet.name + ": Taxing Colonists with " + ctaxsmallmodel.method + ", " + ctaxsmallmodel.minHappy + "->" + ctaxsmallmodel.maxHappy);
  3216. if (planet.clans < plg.taxmethods[ctaxindex].minClans){
  3217. if (debug) console.log("Planet " + planet.name + ": Col Tax < Min Clans, 0");
  3218. planet.colonisttaxrate = 0;
  3219. }
  3220. else {
  3221. rate = plg.getTaxCols(planet,ctaxsmallmodel);
  3222. planet.colonisttaxrate = rate;
  3223. }
  3224. /*
  3225. if (ctaxmodel.method == "Growth")
  3226. rate = plg.getTaxGrowthCols(planet,taxmodel);
  3227. if (ctaxmodel.method == "Safe")
  3228. rate = plg.getTaxSafeCols(planet,taxmodel);
  3229. rate = plg.getTaxCols(planet,ctaxmodel);
  3230. if (planet.clans > ctaxmodel.minClans)
  3231. planet.colonisttaxrate = rate;
  3232. */
  3233. }
  3234. // Then do Native Tax
  3235. if (planet.nativeclans > 0) {
  3236. if (ntaxindex != 'm') {
  3237. var rate;
  3238. var ntaxsmallmodel = new Object();
  3239. ntaxsmallmodel.method = plg.taxmethods[ntaxindex].method;
  3240. ntaxsmallmodel.minHappy = plg.taxmethods[ntaxindex].minHappy;
  3241. ntaxsmallmodel.maxHappy = plg.taxmethods[ntaxindex].maxHappy;
  3242. ntaxsmallmodel.minClans = plg.taxmethods[ntaxindex].minClans;
  3243. if (planet.nativeclans < plg.taxmethods[ntaxindex].minClans){
  3244. if (debug) console.log("Planet " + planet.name + ": Nat Tax < Min Clans, 0");
  3245. planet.nativetaxrate = 0;
  3246. }
  3247. if (planet.nativeclans > 66000 && plg.taxmethods[ntaxindex].midsame == false) {
  3248. ntaxsmallmodel.method = plg.taxmethods[ntaxindex].midmethod;
  3249. ntaxsmallmodel.minHappy = plg.taxmethods[ntaxindex].midMinHappy;
  3250. ntaxsmallmodel.maxHappy = plg.taxmethods[ntaxindex].midMaxHappy;
  3251. if (debug) console.log("Planet " + planet.name + ": Native Assigning mid tax");
  3252. }
  3253. if (planet.nativeclans >= plg.getMaxNatives(planet) && plg.taxmethods[ntaxindex].maxsame == false) {
  3254. ntaxsmallmodel.method = plg.taxmethods[ntaxindex].maxmethod;
  3255. ntaxsmallmodel.minHappy = plg.taxmethods[ntaxindex].maxMinHappy;
  3256. ntaxsmallmodel.maxHappy = plg.taxmethods[ntaxindex].maxMaxHappy;
  3257. if (debug) console.log("Planet " + planet.name + ": Native Assigning max tax");
  3258. }
  3259. if (debug) console.log("Planet " + planet.name + ": Taxing Natives with " + ntaxsmallmodel.method + ", " + ntaxsmallmodel.minHappy + "->" + ntaxsmallmodel.maxHappy);
  3260. rate = plg.getTaxNat(planet,ntaxsmallmodel);
  3261. planet.nativetaxrate = rate;
  3262. }
  3263. /*
  3264. ntaxmodel = plg.taxmethods[ntaxindex];
  3265. if (ntaxmodel.method == "Growth")
  3266. plg.getTaxGrowthNat(planet,taxmodel);
  3267. if (ntaxmodel.method == "Safe")
  3268. plg.getTaxSafeNat(planet,taxmodel);
  3269. rate = plg.getTaxNat(planet,ntaxmodel);
  3270. if (planet.nativeclans > ntaxmodel.minClans)
  3271. planet.nativetaxrate = rate;
  3272. */
  3273. }
  3274. return;
  3275. },
  3276. getTaxNat: function(planet,taxmodel) {
  3277. var rate;
  3278. // Don't tax amorphs
  3279. if (planet.nativetype == 5)
  3280. return 0;
  3281. var maxhapchng = vgap.plugins["plManagerPlugin"].ntctest(planet, 0);
  3282. var hapmod = 0;
  3283. if (debug) console.log("Entered Tax Natives: method type = " + taxmodel.method);
  3284. // Hiss check
  3285. var hissships = 0;
  3286. var plships = vgap.shipsAt(planet.x, planet.y);
  3287. for (var i = 0; i < plships.length; i++) {
  3288. //console.log("---> " + JSON.stringify(plships[i]));
  3289. var raceid = vgap.getPlayer(plships[i].ownerid).raceid;
  3290. if (raceid == 2 && plships[i].mission == 8)
  3291. hissships += 1;
  3292. if (hissships > 0) {
  3293. hapmod = (hissships * 5)
  3294. if (planet.nativehappypoints + hapmod > 100)
  3295. hapmod = 100-planet.nativehappypoints;
  3296. }
  3297. }
  3298. //console.log("nathap + maxhapchng + hapmod = " + (planet.nativehappypoints+maxhapchng+hapmod) + ", compval is " + (100-hapmod));
  3299. //console.log("---> Hissships:" + hissships);
  3300. if (taxmodel.method == "Growth") {
  3301. if (hissships > 0) {
  3302. if ((planet.nativehappypoints+hapmod) + maxhapchng < taxmodel.maxHappy-hapmod)
  3303. return 0;
  3304. }
  3305. else
  3306. if ((planet.nativehappypoints) + maxhapchng <= taxmodel.maxHappy)
  3307. return 0;
  3308. }
  3309. // First, determine the maximum amount we can collect:
  3310. var maxmc = planet.clans;
  3311. // Insectoids
  3312. if (planet.nativetype == 6)
  3313. maxmc += maxmc;
  3314. if (maxmc > 5000)
  3315. maxmc = 5000;
  3316. var nhchng = (taxmodel.minHappy-hapmod) - (planet.nativehappypoints);
  3317. rate = vgap.plugins["plManagerPlugin"].findNativeRate(planet, nhchng);
  3318. var mc = Math.round(rate * planet.nativegovernment * 20 / 100 * planet.nativeclans / 1000);
  3319. // V1.20 - Insectoids overtaxed bug fix
  3320. // We needed to double the mc here as well, not just calculate max above
  3321. if (planet.nativetype == 6)
  3322. mc += mc;
  3323. // Check to find the suggested rate if we can't collect that many megacredits
  3324. if (mc > maxmc) {
  3325. rate = Math.truncate(maxmc / (planet.nativegovernment * 20 / 100 * planet.nativeclans / 1000));
  3326. if (planet.nativetype == 6)
  3327. rate = Math.truncate((maxmc/2) / (planet.nativegovernment * 20 / 100 * planet.nativeclans / 1000));
  3328. }
  3329. if (taxmodel.method == "Riot") {
  3330. return 100;
  3331. }
  3332.  
  3333. if (taxmodel.method == "No Tax") {
  3334. return 0;
  3335. }
  3336. return rate;
  3337. },
  3338. getTaxCols: function(planet,taxmodel) {
  3339. if (debug) console.log("Entered getTaxCols: " + taxmodel.method);
  3340. var maxhapchng = vgap.plugins["plManagerPlugin"].ctctest(planet, 0);
  3341. var hapmod = 0;
  3342. // Hiss check
  3343. var hissships = 0;
  3344. var plships = vgap.shipsAt(planet.x, planet.y);
  3345. for (var i = 0; i < plships.length; i++) {
  3346. //console.log("---> " + JSON.stringify(plships[i]));
  3347. var raceid = vgap.getPlayer(plships[i].ownerid).raceid;
  3348. if (raceid == 2 && plships[i].mission == 8)
  3349. hissships += 1;
  3350. if (hissships > 0) {
  3351. hapmod = (hissships * 5)
  3352. if (planet.colonisthappypoints + hapmod > taxmodel.maxHappy)
  3353. hapmod = 100-planet.colonisthappypoints;
  3354. }
  3355. }
  3356. //console.log("nathap + maxhapchng + hapmod = " + (planet.nativehappypoints+maxhapchng+hapmod) + ", compval is " + (100-hapmod));
  3357. if (taxmodel.method == "Riot") {
  3358. return 100;
  3359. }
  3360. if (taxmodel.method == "No Tax") {
  3361. return 0;
  3362. }
  3363. if (taxmodel.method == "Growth" || taxmodel.method == "Chunk") {
  3364. if (hissships > 0) {
  3365. if ((planet.colonisthappypoints+hapmod) + maxhapchng < taxmodel.maxHappy-hapmod)
  3366. return 0;
  3367. }
  3368. else
  3369. if ((planet.colonisthappypoints) + maxhapchng <= taxmodel.maxHappy)
  3370. return 0;
  3371. }
  3372. // First, determine the maximum amount we can collect:
  3373. if (taxmodel.method == "Chunk") {
  3374. // Calculate the minimum happiness that can be recovered next turn to 70
  3375. // So we need to predict build the planet and see what will be there next turn
  3376. plg.planetPredictor(planet, 0, 1);
  3377. }
  3378. var maxmc = planet.clans;
  3379. if (maxmc > 5000)
  3380. maxmc = 5000;
  3381. if (debug) console.log("In SAFE TAX Cols: minHappy = " + taxmodel.minHappy + ", colhappy = " + planet.colonisthappypoints + ", minHap - hapmod = " + (taxmodel.minHappy - hapmod));
  3382. var nhchng = (taxmodel.minHappy-hapmod) - (planet.colonisthappypoints);
  3383. console.log("nhchng = " + nhchng);
  3384. return vgap.plugins["plManagerPlugin"].findColonistRate(planet, nhchng);
  3385. },
  3386. getTaxGrowthCols: function(planet,taxmodel) {
  3387. var maxhapchng = vgap.plugins["plManagerPlugin"].ctctest(planet, 0);
  3388. var hapmod = 0;
  3389. // Hiss check
  3390. var hissships = 0;
  3391. var plships = vgap.shipsAt(planet.x, planet.y);
  3392. for (var i = 0; i < plships.length; i++) {
  3393. //console.log("---> " + JSON.stringify(plships[i]));
  3394. var raceid = vgap.getPlayer(plships[i].ownerid).raceid;
  3395. if (raceid == 2 && plships[i].mission == 8)
  3396. hissships += 1;
  3397. if (hissships > 0) {
  3398. hapmod = (hissships * 5)
  3399. if (planet.colonisthappypoints + hapmod > taxmodel.maxHappy)
  3400. hapmod = 100-planet.colonisthappypoints;
  3401. }
  3402. }
  3403. //console.log("nathap + maxhapchng + hapmod = " + (planet.nativehappypoints+maxhapchng+hapmod) + ", compval is " + (100-hapmod));
  3404. if (hissships > 0) {
  3405. if ((planet.colonisthappypoints+hapmod) + maxhapchng < taxmodel.maxHappy-hapmod)
  3406. return 0;
  3407. }
  3408. else
  3409. if ((planet.colonisthappypoints) + maxhapchng <= taxmodel.maxHappy)
  3410. return 0;
  3411. // First, determine the maximum amount we can collect:
  3412. var maxmc = planet.clans;
  3413. if (maxmc > 5000)
  3414. maxmc = 5000;
  3415. var nhchng = (taxmodel.minHappy-hapmod) - (planet.colonisthappypoints);
  3416. return vgap.plugins["plManagerPlugin"].findColonistRate(planet, nhchng);
  3417. },
  3418. getTaxSafeCols: function(planet,taxmodel) {
  3419. var maxhapchng = vgap.plugins["plManagerPlugin"].ctctest(planet, 0);
  3420. var hapmod = 0;
  3421. // Hiss check
  3422. var hissships = 0;
  3423. var plships = vgap.shipsAt(planet.x, planet.y);
  3424. for (var i = 0; i < plships.length; i++) {
  3425. //console.log("---> " + JSON.stringify(plships[i]));
  3426. var raceid = vgap.getPlayer(plships[i].ownerid).raceid;
  3427. if (raceid == 2 && plships[i].mission == 8)
  3428. hissships += 1;
  3429. if (hissships > 0) {
  3430. hapmod = (hissships * 5)
  3431. if (planet.colonisthappypoints + hapmod > taxmodel.maxHappy)
  3432. hapmod = 100-planet.colonisthappypoints;
  3433. }
  3434. }
  3435. if (debug) console.log("nathap + maxhapchng + hapmod = " + (planet.nativehappypoints+maxhapchng+hapmod) + ", compval is " + (100-hapmod));
  3436. var rate;
  3437. // First, determine the maximum amount we can collect:
  3438. var maxmc = planet.clans;
  3439. if (maxmc > 5000)
  3440. maxmc = 5000;
  3441. var nhchng = (taxmodel.minHappy-hapmod) - (planet.colonisthappypoints);
  3442. rate = vgap.plugins["plManagerPlugin"].findColonistRate(planet, nhchng);
  3443. var mc = Math.round(rate * planet.nativegovernment * 20 / 100 * planet.nativeclans / 1000);
  3444. return rate;
  3445. },
  3446. findNativeRate: function(planet, nhchng) {
  3447. // If they're not going to get mad about 20%, do it
  3448. //if (vgap.plugins["plManagerPlugin"].ntctest(planet,20) > nhchng)
  3449. // return 20
  3450. for (var r = 1; r <= 100; r++) {
  3451. //console.log("Change for rate " + r + "%: " + vgap.plugins["plManagerPlugin"].ntctest(planet,r));
  3452. if (vgap.plugins["plManagerPlugin"].ntctest(planet,r) < nhchng)
  3453. return r-1;
  3454. }
  3455. return 0;
  3456. },
  3457. planetBuildBldgs: function() {
  3458. if (debug) console.log("Planet Build Buildings called.");
  3459. if (debug) console.log("Build Index is " + vgap.plugins["plManagerPlugin"].planetbuildindex );
  3460. if (debug) console.log("Myplanets length is " + vgap.myplanets.length);
  3461. var plg = vgap.plugins["plManagerPlugin"];
  3462. if (debug) console.log("Building planet: " + vgap.myplanets[plg.planetbuildindex].id + " Method is " + plg.bmarray[vgap.myplanets[plg.planetbuildindex].id]);
  3463. if (debug) console.log("Switching " + plg.bmarray[vgap.myplanets[plg.planetbuildindex].id]);
  3464. if (plg.bmarray[vgap.myplanets[plg.planetbuildindex].id] != 'm') {
  3465. var bmarrayindex = vgap.myplanets[plg.planetbuildindex].id;
  3466. var bm = plg.bmarray[bmarrayindex];
  3467. var bmstring = plg.buildmethods[bm][1];
  3468. //plg.buildBldgsGeneral(plg.buildmethods[plg.bmarray[vgap.myplanets[plg.planetbuildindex].id]]);
  3469. plg.buildBldgsGeneral(bmstring, false);
  3470. }
  3471. },
  3472. executePlanetUpdate: function() {
  3473. console.log("ENTERED EXPLUP");
  3474. var plg = vgap.plugins["plManagerPlugin"];
  3475. if (vgap.plugins["plManagerPlugin"].planetbuildindex >= plg.parray.length) {
  3476. // We're done
  3477. console.log("Done building.");
  3478. //vgap.closeMore();
  3479. vgap.plugins["plManagerPlugin"].buildstatustext = "All Planets Built.";
  3480. vgap.plugins["plManagerPlugin"].ambuilding = false;
  3481. vgap.plugins["plManagerPlugin"].planetbuildindex = 0;
  3482. vgap.plugins["plManagerPlugin"].displayPM(0);
  3483. //vgap.plugins["plManagerPlugin"].saveChanges();
  3484. vgap.save();
  3485. }
  3486. else {
  3487. var planet = plg.parray[vgap.plugins["plManagerPlugin"].planetbuildindex];
  3488. vgap.plugins["plManagerPlugin"].ambuilding = true;
  3489. vgap.plugins["plManagerPlugin"].buildstatustext = "Building " + (vgap.plugins["plManagerPlugin"].planetbuildindex+1) + " of " + plg.parray.length + " #" + planet.id + " - " + planet.name;
  3490. //vgap.plugins["plManagerPlugin"].displayPM(0);
  3491. //<td class=PLBuildStatus>" + vgap.plugins["plManagerPlugin"].buildstatustext + "</td>
  3492. $('.PLBuildStatus').replaceWith("<td class=PLBuildStatus>" + vgap.plugins['plManagerPlugin'].buildstatustext + "</td>");
  3493. // There are still more planets to do
  3494. // Randomize Friendly Code if that's selected
  3495. if (plg.fcrandomize == true)
  3496. {
  3497. // Randomize
  3498. var fcu = planet.friendlycode.toUpperCase();
  3499. if (!(fcu == "NUK" || fcu == "ATT" || fcu == "BUM" || fcu == "DMP" || (fcu.substr(0, 2) == "PB")))
  3500. {
  3501. planet.friendlycode = vgap.randomFC();
  3502. planet.changed = 1;
  3503. var identifier = "#FCDisp_" + planet.id;
  3504. console.log("SELECTOR: " + identifier);
  3505. $(identifier).replaceWith("<td class=FCDisp data-plid='" + planet.id + "' id='FCDisp_" + planet.id + "' align='center' width='30px' style='border: solid white 1px; color: #0000A0; background-color: " + vgap.plugins["plManagerPlugin"].getFCColor(planet.friendlycode) + ";'><b>" + planet.friendlycode + "</b></td>");
  3506. }
  3507. }
  3508. vgap.plugins["plManagerPlugin"].planetBuildBldgs();
  3509. vgap.plugins["plManagerPlugin"].planetSetTaxGeneral(false);
  3510. planet.changed = 1;
  3511. // Modification: Only save after processing every 3rd planet
  3512. // 2nd Modification V1.20: Save at the end
  3513. //plg.quickBreak();
  3514. vgap.plugins["plManagerPlugin"].planetbuildindex++;
  3515. vgap.plugins["plManagerPlugin"].executePlanetUpdate();
  3516. /*
  3517. if (vgap.plugins["plManagerPlugin"].planetbuildindex % 25 == 0 || vgap.plugins["plManagerPlugin"].planetbuildindex == plg.parray.length-1)
  3518. vgap.plugins["plManagerPlugin"].saveChanges();
  3519. else {
  3520. vgap.plugins["plManagerPlugin"].planetbuildindex++;
  3521. vgap.plugins["plManagerPlugin"].executePlanetUpdate();
  3522. }
  3523. */
  3524. }
  3525. return;
  3526. },
  3527. quickBreak: function() {
  3528. var plg = vgap.plugins["plManagerPlugin"];
  3529. if (plg.qb == 0) {
  3530. // We can take a quick break
  3531. console.log("Taking quick break...");
  3532. plg.qb = 1;
  3533. timeoutID = window.setTimeout(plg.quickBreak, 250);
  3534. }
  3535. else {
  3536. // Break time over. Back to work you scum!
  3537. plg.qb = 0;
  3538. vgap.plugins["plManagerPlugin"].planetbuildindex++;
  3539. vgap.plugins["plManagerPlugin"].executePlanetUpdate();
  3540. }
  3541. },
  3542. saveChanges: function() {
  3543. // Check to see if we're still saving
  3544. var plg = vgap.plugins["plManagerPlugin"];
  3545. if (vgap.saveInProgress == 2) {
  3546. // We are still saving, check again in a little bit
  3547. timeoutID = window.setTimeout(vgap.plugins["plManagerPlugin"].saveChanges, 500);
  3548. return;
  3549. }
  3550. // Theres a flaw here with the saved index
  3551. else if (vgap.plugins["plManagerPlugin"].ambuilding == true && vgap.saveInProgress == 0 && vgap.plugins["plManagerPlugin"].savestarted == true) {
  3552. // We have performed a save, but we're still building. Build the next planet
  3553. vgap.plugins["plManagerPlugin"].savestarted = false;
  3554. //vgap.plugins["plManagerPlugin"].savedindex = planetbuildindex;
  3555. //vgap.plugins["plManagerPlugin"].planetbuildindex++;
  3556. //vgap.plugins["plManagerPlugin"].executePlanetUpdate();
  3557. }
  3558. else {
  3559. // We can save now
  3560. vgap.plugins["plManagerPlugin"].savestarted = true;
  3561. vgap.plugins["plManagerPlugin"].ambuilding = true;
  3562. vgap.plugins["plManagerPlugin"].buildstatustext = "Building " + (vgap.plugins["plManagerPlugin"].planetbuildindex+1) + " of " + plg.parray.length;
  3563. vgap.save();
  3564. vgap.plugins["plManagerPlugin"].displayPM(0);
  3565. timeoutID = window.setTimeout(vgap.plugins["plManagerPlugin"].saveChanges, 500);
  3566. }
  3567. },
  3568. /*
  3569. * This function checks a manually entered code to see if it is valid.
  3570. */
  3571. checkBuildCode: function(mcode) {
  3572. var checkarray = mcode.split('-');
  3573. if (debug) console.log("In check build, mcode = " + mcode + " checkarray = " + checkarray);
  3574. if (!(checkarray[0] == 'y' || checkarray[0] == 'Y' || checkarray[0] == 'n' || checkarray[0] == 'N')) {
  3575. console.log("Returning false on yn check");
  3576. return false;
  3577. }
  3578. for (var i=1; i < checkarray.length; i+=2) {
  3579. if (!(checkarray[i] == 'f' || checkarray[i] == 'm' || checkarray[i] == 'd' || checkarray[i] == 'rfm')) {
  3580. if (debug) console.log("Returning false on fmd-rfm check, checkarray[i] is " + checkarray[i]);
  3581. return false;
  3582. }
  3583. if (checkarray[i] == 'rfm') {
  3584. if (!(vgap.plugins["plManagerPlugin"].isInteger(checkarray[i+1]) && vgap.plugins["plManagerPlugin"].isInteger(checkarray[i+2]) && vgap.plugins["plManagerPlugin"].isInteger(checkarray[i+3]))) {
  3585. if (debug) console.log("Returning false on rfm integer check");
  3586. return false;
  3587. }
  3588. i+=2;
  3589. }
  3590. else if (!(vgap.plugins["plManagerPlugin"].isInteger(checkarray[i+1]))) {
  3591. if (debug) console.log("Returning false on integer check");
  3592. return false;
  3593. }
  3594. }
  3595. return true;
  3596. },
  3597. /*
  3598. * This function checks a manually entered code to see if it is valid.
  3599. */
  3600. getBuildCodeText: function(mcode) {
  3601. var checkarray = mcode.split('-');
  3602. var bctext = "";
  3603. if (!(checkarray[0] == 'y' || checkarray[0] == 'Y' || checkarray[0] == 'n' || checkarray[0] == 'N')) {
  3604. console.log("Returning false on yn check");
  3605. return "Invalid Build Code";
  3606. }
  3607. else if (checkarray[0] == 'y' || checkarray[0] == 'Y')
  3608. bctext += "Convert supplies to megacredits if necessary. ";
  3609. else
  3610. bctext += "Do not convert supplies to megacredits. ";
  3611. for (var i=1; i < checkarray.length; i+=2) {
  3612. if (i==1)
  3613. bctext += "Build up to ";
  3614. else
  3615. bctext += "then build up to ";
  3616. if (checkarray[i] == 'f')
  3617. bctext += checkarray[i+1] + " factories, ";
  3618. if (checkarray[i] == 'm')
  3619. bctext += checkarray[i+1] + " mines, ";
  3620. if (checkarray[i] == 'd')
  3621. bctext += checkarray[i+1] + " defense posts, ";
  3622. if (checkarray[i] == 'rfm') {
  3623. bctext += checkarray[i+1] + " factories and up to " + checkarray[i+2] + " mines at a ratio of " + checkarray[i+3] + ":1, ";
  3624. i += 2;
  3625. }
  3626. }
  3627. bctext = bctext.substring(0, bctext.length - 2)
  3628. bctext += ".";
  3629. return bctext;
  3630. },
  3631. isInteger: function(possibleInteger) {
  3632. return Object.prototype.toString.call(possibleInteger) !== "[object Array]" && /^[\d]+$/.test(possibleInteger);
  3633. },
  3634. buildMethodCompleted: function(planet) {
  3635. var plg = vgap.plugins["plManagerPlugin"];
  3636. if (plg.bmarray[planet.id] == 'm') {
  3637. // For the purposes of this method, a build method of manual is never complete.
  3638. return false;
  3639. }
  3640. if (plg.bmarray[planet.id] != 'm') {
  3641. var bmarrayindex = planet.id;
  3642. var bm = plg.bmarray[bmarrayindex];
  3643. var buildplan = plg.buildmethods[bm][1];
  3644. var buildarray = buildplan.split('-');
  3645. var buildcount;
  3646. var buildtype;
  3647. for (var i = 1; i < buildarray.length; i+=2)
  3648. {
  3649. buildtype = buildarray[i];
  3650. buildcount = buildarray[i+1];
  3651. //console.log("ENTERED BUILD, buildtype = " + buildtype);
  3652. if (buildtype == 'f')
  3653. if (planet.factories < buildcount)
  3654. return false;
  3655. if (buildtype == 'm')
  3656. if (planet.mines < buildcount)
  3657. return false;
  3658. if (buildtype == 'd')
  3659. if (planet.defense < buildcount)
  3660. return false;
  3661. if (buildtype == 'rfm') {
  3662. var secondarybuildcount = buildarray[i+2];
  3663. i+=2;
  3664. if (planet.factories < buildcount)
  3665. return false;
  3666. if (planet.mines < secondarybuildcount)
  3667. return false;
  3668. }
  3669. }
  3670. return true;
  3671. }
  3672. },
  3673. maxBuilding: function(planet, a) {
  3674. if (planet.clans <= a) {
  3675. return planet.clans;
  3676. } else {
  3677. return Math.floor(a + Math.sqrt(planet.clans - a));
  3678. }
  3679. },
  3680. changeMines: function(planet, number) {
  3681. if (number > 0) {
  3682. if (planet.supplies < number) {
  3683. number = planet.supplies
  3684. }
  3685. if ((planet.megacredits + planet.supplies) < (number * 5)) {
  3686. number = Math.floor((planet.megacredits + planet.supplies) / 5);
  3687. }
  3688. var c = this.maxBuilding(planet, 200);
  3689. if (planet.mines > c) {
  3690. return;
  3691. }
  3692. if ((planet.mines + number) > c) {
  3693. number = c - planet.mines;
  3694. }
  3695. if (planet.megacredits < (number * 4)) {
  3696. var b = (number * 4) - planet.megacredits;
  3697. planet.megacredits += b;
  3698. planet.supplies -= b;
  3699. planet.suppliessold += b;
  3700. }
  3701. } else {
  3702. if (planet.builtmines < (-1 * number)) {
  3703. number = planet.builtmines * -1;
  3704. }
  3705. }
  3706. planet.supplies -= number;
  3707. planet.megacredits -= number * 4;
  3708. planet.builtmines += number;
  3709. planet.mines += number;
  3710. },
  3711.  
  3712. changeFactories: function(planet, number) {
  3713. if (number > 0) {
  3714. if (planet.supplies < number) {
  3715. number = planet.supplies;
  3716. }
  3717. if ((planet.megacredits + planet.supplies) < (number * 4)) {
  3718. number = Math.floor((planet.megacredits + planet.supplies) / 4);
  3719. }
  3720. var c = this.maxBuilding(planet, 100);
  3721. if (planet.factories > c) {
  3722. return;
  3723. }
  3724. if ((planet.factories + number) > c) {
  3725. number = c - planet.factories;
  3726. }
  3727. if (planet.megacredits < (number * 3)) {
  3728. var b = (number * 3) - planet.megacredits;
  3729. planet.megacredits += b;
  3730. planet.supplies -= b;
  3731. planet.suppliessold += b;
  3732. }
  3733. } else {
  3734. if (planet.builtfactories < (-1 * number)) {
  3735. number = planet.builtfactories * -1;
  3736. }
  3737. }
  3738. planet.supplies -= number;
  3739. planet.megacredits -= number * 3;
  3740. planet.builtfactories += number;
  3741. planet.factories += number;
  3742. },
  3743.  
  3744. changeDefense: function(planet, number) {
  3745. if (number > 0) {
  3746. if (planet.supplies < number) {
  3747. number = planet.supplies;
  3748. }
  3749. if ((planet.megacredits + planet.supplies) < (number * 11)) {
  3750. number = Math.floor((planet.megacredits + planet.supplies) / 11);
  3751. }
  3752. var c = this.maxBuilding(planet, 50);
  3753. if (planet.defense > c) {
  3754. return;
  3755. }
  3756. if ((planet.defense + number) > c) {
  3757. number = c - planet.defense;
  3758. }
  3759. if (planet.megacredits < (number * 10)) {
  3760. var b = (number * 10) - planet.megacredits;
  3761. planet.megacredits += b;
  3762. planet.supplies -= b;
  3763. planet.suppliessold += b;
  3764. }
  3765. } else {
  3766. if (planet.builtdefense < (-1 * number)) {
  3767. number = planet.builtdefense * -1;
  3768. }
  3769. }
  3770. planet.supplies -= number;
  3771. planet.megacredits -= number * 10;
  3772. planet.builtdefense += number;
  3773. planet.defense += number;
  3774. },
  3775. /*
  3776. * This method builds according to a buildplan
  3777. * The buildplan is a string with dashes that explains the build, ie:
  3778. * f-100-m-200-d-10
  3779. * Would build 100 factories, then 200 mines, then 10 defense posts
  3780. *
  3781. * Also, you can build in ratios, so:
  3782. *
  3783. * f-10-rfm-100-25-2-d-5
  3784. * Would build 10 factories, then 100 factories and 25 mines at a 2:1 ratio, then 5 defense posts
  3785. */
  3786. buildBldgsGeneral: function(buildplan, predict) {
  3787. var buildarray = buildplan.split('-');
  3788. var buildcount;
  3789. var buildtype;
  3790. var burnsups;
  3791. var plg = vgap.plugins["plManagerPlugin"];
  3792. if (buildarray[0] == 'y' || buildarray[0] == 'Y')
  3793. burnsups = true;
  3794. else
  3795. burnsups = false;
  3796. console.log("IN BUILD BUILDINGS: BURNSUPS = " + burnsups);
  3797. var planet;
  3798. if (predict)
  3799. planet = plg.pplanet;
  3800. else {
  3801. planet = vgap.myplanets[vgap.plugins["plManagerPlugin"].planetbuildindex];
  3802. //vgap.planetScreen.load(planet);
  3803. }
  3804. numbuildtemp = 0;
  3805. var mc = planet.megacredits;
  3806. var sup = planet.supplies;
  3807. // Prdict next turn taxes. Stop burning supplies if significant cash comming in and we don't have many factories already.
  3808. // This is mostly to stop a bit drop on a native planet from blowing all its supplies to build 10 factories and then
  3809. // Having to eak them out turn after turn there after.
  3810. /*if ((mc + colmc + natmc) > 100 && planet.factories < 20) {
  3811. console.log("Turning off burn supplies. Planet is predicted to have many MC next turn: " + (mc + colmc + natmc));
  3812. burnsups = false;
  3813. }*/
  3814. for (var i = 1; i < buildarray.length; i+=2)
  3815. {
  3816. buildtype = buildarray[i];
  3817. buildcount = buildarray[i+1];
  3818. if (debug) console.log("ENTERED BUILD, buildtype = " + buildtype);
  3819. if (buildtype == 'f') {
  3820. // Building factories
  3821. numbuildtemp = Math.max(0,buildcount - planet.factories);
  3822. if (burnsups) {
  3823. if (predict)
  3824. plg.predictChangeFactories(numbuildtemp);
  3825. else
  3826. plg.changeFactories(planet, numbuildtemp);
  3827. }
  3828. else {
  3829. var possfact = vgap.plugins["plManagerPlugin"].getPossFacts(mc,sup);
  3830. if (debug) console.log("Building Factories no burnsup, possfact = " + possfact);
  3831. if (possfact < numbuildtemp) {
  3832. // Thats all we can build
  3833. if (predict)
  3834. plg.predictChangeFactories(possfact);
  3835. else
  3836. plg.changeFactories(planet, possfact);
  3837. }
  3838. else {
  3839. if (predict)
  3840. plg.predictChangeFactories(numbuildtemp);
  3841. else
  3842. //vgap.planetScreen.changeFactories(numbuildtemp);
  3843. plg.changeFactories(planet, numbuildtemp);
  3844. }
  3845. }
  3846. }
  3847. if (buildtype == 'm') {
  3848. // Building mines
  3849. numbuildtemp = Math.max(0,buildcount - planet.mines);
  3850. if (burnsups) {
  3851. if (predict)
  3852. plg.predictChangeMines(numbuildtemp);
  3853. else
  3854. plg.changeMines(planet, numbuildtemp);
  3855. }
  3856. else {
  3857. var possmines = vgap.plugins["plManagerPlugin"].getPossMines(mc,sup);
  3858. if (debug) console.log("Building Factories no burnsup, possmines = " + possmines);
  3859. if (possmines < numbuildtemp) {
  3860. // Thats all we can build
  3861. if (predict)
  3862. plg.predictChangeMines(possmines);
  3863. else
  3864. plg.changeMines(planet, possmines);
  3865. }
  3866. else {
  3867. if (predict)
  3868. plg.predictChangeMines(numbuildtemp);
  3869. else
  3870. plg.changeMines(planet, numbuildtemp);
  3871. }
  3872. }
  3873. }
  3874. if (buildtype == 'd') {
  3875. console.log("Entered build defense");
  3876. // Building defense posts
  3877. numbuildtemp = Math.max(0,buildcount - planet.defense);
  3878. if (debug) console.log("numbuildtemp set");
  3879. if (burnsups) {
  3880. if (predict)
  3881. plg.predictChangeDefense(numbuildtemp);
  3882. else
  3883. plg.changeDefense(planet, numbuildtemp);
  3884. }
  3885. else {
  3886. if (debug) console.log("entered else");
  3887. var possdef = vgap.plugins["plManagerPlugin"].getPossDef(mc,sup);
  3888. if (debug) console.log("Building Factories no burnsup, possdef = " + possdef);
  3889. if (possdef < numbuildtemp) {
  3890. // Thats all we can build
  3891. if (predict)
  3892. plg.predictChangeDefense(possdef);
  3893. else
  3894. plg.changeDefense(planet, possdef);
  3895. }
  3896. else {
  3897. if (predict)
  3898. plg.predictChangeDefense(numbuildtemp);
  3899. else
  3900. plg.changeDefense(planet, numbuildtemp);
  3901. }
  3902. }
  3903. }
  3904. if (buildtype == 'rfm') {
  3905. // Building factories and mines according to a ratio
  3906. var secondarybuildcount = buildarray[i+2];
  3907. ratio = buildarray[i+3];
  3908. i+=2;
  3909. numbuildtemp = Math.max(0,buildcount - planet.factories);
  3910. var secnumbuildtemp = Math.max(0,secondarybuildcount - planet.mines);
  3911. var secbuildleft = secnumbuildtemp;
  3912. var res = vgap.plugins["plManagerPlugin"].calcRFMBuild(numbuildtemp,secnumbuildtemp,ratio,burnsups,mc,sup);
  3913. if (debug) console.log("**********************");
  3914. if (debug) console.log("Calculated RFM Build: Factories: " + res.facts + " Mines: " + res.mines);
  3915. if (debug) console.log("**********************");
  3916. if (predict) {
  3917. plg.predictChangeFactories(res.facts);
  3918. plg.predictChangeMines(res.mines);
  3919. secnumbuildtemp -= res.mines;
  3920. if (burnsups)
  3921. plg.predictChangeMines(secnumbuildtemp);
  3922. else {
  3923. var secpossmines = vgap.plugins["plManagerPlugin"].getPossMines(mc,sup);
  3924. //console.log("Building Secondary RFM mines no burnsup, secpossmines = " + secpossmines);
  3925. if (secpossmines < secnumbuildtemp) {
  3926. // Thats all we can build
  3927. plg.predictChangeMines(secpossmines);
  3928. }
  3929. else
  3930. plg.predictChangeMines(secnumbuildtemp);
  3931. }
  3932. }
  3933. else {
  3934. plg.changeFactories(planet, res.facts);
  3935. plg.changeMines(planet, res.mines);
  3936. secnumbuildtemp -= res.mines;
  3937. if (burnsups)
  3938. plg.changeMines(planet, secnumbuildtemp);
  3939. else {
  3940. var secpossmines = vgap.plugins["plManagerPlugin"].getPossMines(mc,sup);
  3941. if (debug) console.log("Building Secondary RFM mines no burnsup, secpossmines = " + secpossmines);
  3942. if (secpossmines < secnumbuildtemp) {
  3943. // Thats all we can build
  3944. plg.changeMines(planet, secpossmines);
  3945. }
  3946. else
  3947. plg.changeMines(planet, secnumbuildtemp);
  3948. }
  3949. }
  3950. }
  3951. }
  3952. },
  3953. calcRFMBuild: function(numf,numm,ratio,burnsups,mc,sup) {
  3954. var result = {};
  3955. result.facts = 0;
  3956. result.mines = 0;
  3957. var suptemp = sup;
  3958. var mctemp = mc;
  3959. var cnt = 0;
  3960. for (var i = 0; i < numf; i++) {
  3961. if (suptemp >=1 && mctemp >= 3) {
  3962. result.facts++;
  3963. suptemp -= 1;
  3964. mctemp -= 3;
  3965. }
  3966. else if (burnsups == true && (mctemp < 3 && suptemp >= 4-mctemp)) {
  3967. // Burn supplies to build
  3968. result.facts++;
  3969. mctemp = 0;
  3970. suptemp -= 4-mctemp;
  3971. }
  3972. if (cnt % ratio == 0 && result.mines < numm) {
  3973. if (suptemp >=1 && mctemp >= 4) {
  3974. result.mines++;
  3975. suptemp -= 1;
  3976. mctemp -= 4;
  3977. }
  3978. else if (burnsups == true && (mctemp < 4 && suptemp >= 5-mctemp)) {
  3979. // Burn supplies to build
  3980. result.mines++;
  3981. mctemp = 0;
  3982. suptemp -= 5-mctemp;
  3983. }
  3984. }
  3985. cnt++;
  3986. }
  3987. return result;
  3988. },
  3989. /*
  3990. buildBldgsSafeMinDefense: function() {
  3991. console.log("Building buildings Undetected.");
  3992. var planet = vgap.myplanets[vgap.plugins["plManagerPlugin"].planetbuildindex];
  3993. vgap.planetScreen.load(planet);
  3994. numbuildtemp = 0;
  3995. if (planet.factories < 14) {
  3996. //console.log("Factories Less than 14 on " + planet.name + ": " + planet.factories);
  3997. numbuildtemp = 14 - planet.factories;
  3998. vgap.planetScreen.changeFactories(numbuildtemp);
  3999. }
  4000. if (planet.mines < 19) {
  4001. numbuildtemp = 19 - planet.mines;
  4002. vgap.planetScreen.changeMines(numbuildtemp);
  4003. }
  4004. // Now build 15 defense posts, so we won't be detected if we build more buildings:
  4005. if (planet.defense < 15) {
  4006. numbuildtemp = 15 - planet.defense;
  4007. vgap.planetScreen.changeDefense(numbuildtemp);
  4008. }
  4009. var maxfactbld = vgap.plugins["plManagerPlugin"].maxBldgs(planet,100)-planet.factories;
  4010. vgap.planetScreen.changeFactories(maxfactbld);
  4011. var maxminebld = vgap.plugins["plManagerPlugin"].maxBldgs(planet,200)-planet.mines;
  4012. vgap.planetScreen.changeMines(maxminebld);
  4013. // Close out
  4014. vgap.closeMore();
  4015. planet.changed = 1;
  4016. return;
  4017. },
  4018. */
  4019. /*
  4020. buildBldgsUndetectedNoBurn: function() {
  4021. console.log("Building buildings Undetected No Burn.");
  4022. console.log("Entered New Build: Build index is " + vgap.plugins["plManagerPlugin"].planetbuildindex);
  4023. var planet = vgap.myplanets[vgap.plugins["plManagerPlugin"].planetbuildindex];
  4024. vgap.planetScreen.load(planet);
  4025. var mctemp = planet.megacredits;
  4026. var suptemp = planet.supplies;
  4027. var numbuildtemp;
  4028. var possfact;
  4029. var possmines;
  4030. var possdefense;
  4031. numbuildtemp = 0;
  4032. // Build 14 factories first
  4033. if (planet.factories < 14) {
  4034. console.log("Factories Less than 14 on " + planet.name + ": " + planet.factories);
  4035. numbuildtemp = 14 - planet.factories;
  4036. possfact = vgap.plugins["plManagerPlugin"].getPossFacts(planet);
  4037. if (possfact < numbuildtemp) {
  4038. // Thats all we can build
  4039. vgap.planetScreen.changeFactories(possfact);
  4040. vgap.closeMore();
  4041. planet.changed = 1;
  4042. return;
  4043. }
  4044. else {
  4045. vgap.planetScreen.changeFactories(numbuildtemp);
  4046. mctemp -= numbuildtemp*3;
  4047. suptemp -= numbuildtemp;
  4048. }
  4049. }
  4050. // Now build 19 mines
  4051. if (planet.mines < 19) {
  4052. numbuildtemp = 19 - planet.mines;
  4053. possmines = vgap.plugins["plManagerPlugin"].getPossMines(mctemp,suptemp)
  4054. if (possmines < numbuildtemp) {
  4055. // Thats all we can build
  4056. vgap.planetScreen.changeMines(possmines);
  4057. vgap.closeMore();
  4058. planet.changed = 1;
  4059. return;
  4060. }
  4061. else {
  4062. vgap.planetScreen.changeMines(numbuildtemp);
  4063. mctemp -= numbuildtemp*4;
  4064. suptemp -= numbuildtemp;
  4065. }
  4066. }
  4067. // Now build 15 defense posts, so we won't be detected if we build more buildings:
  4068. if (planet.defense < 15) {
  4069. numbuildtemp = 15 - planet.defense;
  4070. possdefense = vgap.plugins["plManagerPlugin"].getPossDef(mctemp,suptemp)
  4071. if (possdefense < numbuildtemp) {
  4072. // Thats all we can build
  4073. vgap.planetScreen.changeDefense(possdefense);
  4074. vgap.closeMore();
  4075. planet.changed = 1;
  4076. return;
  4077. }
  4078. else {
  4079. vgap.planetScreen.changeDefense(numbuildtemp);
  4080. mctemp -= numbuildtemp*10;
  4081. suptemp -= numbuildtemp;
  4082. }
  4083. }
  4084. //console.log("Maxing factories.");
  4085. // Next Max out factories:
  4086. possfact = vgap.plugins["plManagerPlugin"].getPossFactsMCSup(mctemp,suptemp);
  4087. if (possfact > (vgap.plugins["plManagerPlugin"].maxBldgs(planet,100)-planet.factories))
  4088. possfact = (vgap.plugins["plManagerPlugin"].maxBldgs(planet,100)-planet.factories);
  4089. console.log("Building max factories on " + planet.name + ": " + possfact);
  4090. vgap.planetScreen.changeFactories(possfact);
  4091. mctemp -= possfact*3;
  4092. suptemp -= possfact;
  4093. // Next build max mines:
  4094. possmines = vgap.plugins["plManagerPlugin"].getPossMines(mctemp,suptemp);
  4095. if (possmines > (vgap.plugins["plManagerPlugin"].maxBldgs(planet,200)-planet.mines))
  4096. possmines = (vgap.plugins["plManagerPlugin"].maxBldgs(planet,200)-planet.mines);
  4097. console.log("Building max mines on " + planet.name + ": " + possmines);
  4098. vgap.planetScreen.changeMines(possmines);
  4099. mctemp -= possmines*4;
  4100. suptemp -= possmines;
  4101. // Finally, max out defense posts:
  4102. possdefense = vgap.plugins["plManagerPlugin"].getPossDef(mctemp,suptemp);
  4103. console.log("Building max defense on " + planet.name + ": " + possdefense);
  4104. vgap.planetScreen.changeDefense(possdefense);
  4105. // Close out
  4106. vgap.closeMore();
  4107. planet.changed = 1;
  4108. return;
  4109. },
  4110. */
  4111. /*
  4112. buildBldgsSimple: function() {
  4113. console.log("Build Buildings Simple Called.");
  4114. for (var i = 0; i < vgap.myplanets.length; i++) {
  4115. var planet = vgap.myplanets[i];
  4116. console.log("In for loop: planet is " + planet.name);
  4117. //vgap.activePlanet.targetx = planet.x;
  4118. //vgap.activePlanet.targety = planet.y;
  4119. //vgap.activePlanet.target = planet;
  4120. vgap.planetScreen.load(planet);
  4121. console.log("In for loop: " + planet.name + "loaded.");
  4122. vgap.planetScreen.changeFactories(vgap.plugins["plManagerPlugin"].getPossFacts(planet));
  4123. console.log("In for loop: " + planet.name + "factories built.");
  4124. vgap.closeMore();
  4125. planet.changed = 1;
  4126. }
  4127. vgap.plugins["plManagerPlugin"].displayPM(3);
  4128. },
  4129. */
  4130. /*
  4131. buildBldgs: function() {
  4132. console.log("Build Buildings Called.");
  4133. for (var i = 0; i < vgap.myplanets.length; i++) {
  4134. var planet = vgap.myplanets[i];
  4135. vgap.planetScreen.load(planet);
  4136. var mctemp = planet.megacredits;
  4137. var suptemp = planet.supplies;
  4138. // Build factories first -- how many can we build?
  4139. var possfact = vgap.plugins["plManagerPlugin"].getPossFacts(planet);
  4140. // Build them
  4141. if (possfact > (vgap.plugins["plManagerPlugin"].maxBldgs(planet,100)-planet.factories))
  4142. possfact = (vgap.plugins["plManagerPlugin"].maxBldgs(planet,100)-planet.factories)
  4143. console.log("Building " + possfact + " additional factories on planet " + planet.name);
  4144. //planet.builtfactories += possfact;
  4145. //planet.changeFactories(possfact);
  4146. //vgap.planetScreen.changeFactories(possfact);
  4147. //planet.targetfactories = planet.factories + possfact;
  4148. vgap.planetScreen.changeFactories(possfact);
  4149. mctemp -= possfact*3;
  4150. suptemp -= possfact;
  4151. // Check to see if we can build any mines
  4152. var possmines = vgap.plugins["plManagerPlugin"].getPossMines(mctemp,suptemp)
  4153. // Build them
  4154. if (possmines > (vgap.plugins["plManagerPlugin"].maxBldgs(planet,200)-planet.mines))
  4155. possfact = (vgap.plugins["plManagerPlugin"].maxBldgs(planet,200)-planet.mines)
  4156. //planet.builtmines += possmines;
  4157. //planet.changeMines(possmines);
  4158. //planet.targetmines = planet.mines + possmines;
  4159. vgap.planetScreen.changeMines(possmines);
  4160. mctemp -= possmines*4;
  4161. suptemp -= possmines;
  4162. // Check to see if we can build any defense posts
  4163. var possdef = vgap.plugins["plManagerPlugin"].getPossDef(mctemp,suptemp)
  4164. // Build them
  4165. if (possdef > (vgap.plugins["plManagerPlugin"].maxBldgs(planet,50)-planet.defense))
  4166. possfact = (vgap.plugins["plManagerPlugin"].maxBldgs(planet,50)-planet.defense)
  4167. //planet.builtdefense += possdef;
  4168. //planet.changeDefense(possdef);
  4169. //planet.targetdefense = planet.defense + possdef;
  4170. vgap.planetScreen.changeDefense(possdef);
  4171. vgap.closeMore();
  4172. planet.changed = 1;
  4173. }
  4174. vgap.plugins["plManagerPlugin"].displayPM(3);
  4175. },
  4176. */
  4177. assignColTax: function() {
  4178. if (debug) console.log("Assign Colonist Tax Called.");
  4179. for (var i = 0; i < vgap.myplanets.length; i++) {
  4180. var planet = vgap.myplanets[i];
  4181. // Only tax if there's more than 1000 clans
  4182. if (planet.clans > 1000) {
  4183. planet.colonisttaxrate = vgap.plugins["plManagerPlugin"].getSuggestedColonistRate(planet);
  4184. planet.colonisthappychange = vgap.colonistTaxChange(planet);
  4185. planet.changed = 1;
  4186. }
  4187. }
  4188. vgap.plugins["plManagerPlugin"].displayPM(4);
  4189. },
  4190. assignTax: function() {
  4191. if (debug) console.log("Assign Tax Called.");
  4192. for (var i = 0; i < vgap.myplanets.length; i++) {
  4193. var planet = vgap.myplanets[i];
  4194. if (planet.nativeclans > 0) {
  4195. planet.nativetaxrate = vgap.plugins["plManagerPlugin"].getSuggestedNativeRate(planet);
  4196. planet.nativehappychange = vgap.nativeTaxChange(planet);
  4197. planet.changed = 1;
  4198. }
  4199. }
  4200. vgap.plugins["plManagerPlugin"].displayPM(2);
  4201. },
  4202. getSuggestedColonistRate: function(planet) {
  4203. // Get the suggested colonist tax rate for a borg planet.
  4204. // Plan is unclear.
  4205. var dpi = 132;
  4206. //var nhchng = 20;
  4207. var nhchng = 70 - planet.colonisthappypoints;
  4208. // Troubleshooting
  4209. if (planet.id == dpi) {
  4210. console.log("nhchng init:" + nhchng);
  4211. }
  4212. // Troubleshooting
  4213. if (planet.id == dpi) {
  4214. console.log("nhchng after riot check:" + nhchng);
  4215. }
  4216. // Find the rate iteratively instead
  4217. var rate = vgap.plugins["plManagerPlugin"].findColonistRate(planet,nhchng);
  4218. // Troubleshooting
  4219. if (planet.id == dpi) {
  4220. console.log("rate:" + rate);
  4221. }
  4222. if (planet.id == dpi) {
  4223. if (debug) console.log("rate final:" + rate);
  4224. for (var r = 1; r < 20; r++) {
  4225. if (debug) console.log("Change for rate " + r + "%: " + vgap.plugins["plManagerPlugin"].ctctest(planet,r));
  4226. }
  4227. }
  4228. return rate;
  4229. },
  4230. findColonistRate: function(planet, nhchng) {
  4231. for (var r = 1; r <= 100; r++) {
  4232. //console.log("Change for rate " + r + "%: " + vgap.plugins["plManagerPlugin"].ctctest(planet,r));
  4233. if (vgap.plugins["plManagerPlugin"].ctctest(planet,r) < nhchng)
  4234. return r-1;
  4235. }
  4236. if (vgap.plugins["plManagerPlugin"].ctctest(planet,100) > nhchng)
  4237. return 100
  4238. else
  4239. return 0;
  4240. },
  4241. ctctest: function(planet,r) {
  4242. var change = 0;
  4243. if (vgap.player.raceid == 7) //crystal
  4244. change = Math.truncate((1000 - (80 * r) - Math.sqrt(planet.clans) - ((planet.mines + planet.factories) / 3) - (3 * (100 - planet.temp))) / 100);
  4245. else
  4246. change = Math.truncate((1000 - (80 * r) - Math.sqrt(planet.clans) - ((planet.mines + planet.factories) / 3) - (3 * Math.abs(planet.temp - 50))) / 100);
  4247. return change;
  4248. },
  4249. getSuggestedNativeRate: function(planet) {
  4250. // Get the suggested native tax rate for a borg planet.
  4251. // Plan is this: tax them to rioting, but not more. They will be assimilated soon.
  4252. var dpi = 201;
  4253. if (vgap.plugins["plManagerPlugin"].getAssimTurns(planet) == 1) {
  4254. // If we're going to assimilate them all next turn anyways,
  4255. // pry every last stinkin' megacredit from their cold dead hands
  4256. // as they slowly become one with the Borg.
  4257. return 20;
  4258. }
  4259. // First, determine the maximum amount we can collect:
  4260. var maxmc = planet.clans;
  4261. // Insectoids
  4262. if (planet.nativetype == 6)
  4263. maxmc += maxmc;
  4264. if (maxmc > 5000)
  4265. maxmc = 5000;
  4266. //var nhchng = 20;
  4267. var nhchng = 40 - planet.nativehappypoints;
  4268. // Troubleshooting
  4269. if (planet.id == dpi) {
  4270. if (debug) console.log("nhchng init:" + nhchng);
  4271. }
  4272. if (planet.nativetype == 4) //avian
  4273. nhchng -= 10;
  4274. if (vgap.getNebulaIntensity(planet.x, planet.y) >= 80) //50ly visibility
  4275. nhchng -= 5;
  4276. // Make sure we're not already rioting
  4277. //if (nhchng < 0)
  4278. // nhchng = 0;
  4279. // Troubleshooting
  4280. if (planet.id == dpi) {
  4281. if (debug) console.log("nhchng after riot check:" + nhchng);
  4282. }
  4283. // Ok, got the max we can collect. Find out how to get there:
  4284. /* From InfoList:
  4285. * Natives change = trunc(5 + native_gov/2 - sqrt(# natives/1,000,000)
  4286. * - (# mine + # fact)/200 - tax_rate*.85)
  4287. *
  4288. * In Nu speak, this looks like:
  4289. *
  4290. * Natives change = trunc(5 + planet.nativegovernment/2 - sqrt(planet.nativeclans/10000)
  4291. * - (planet.mines + planet.factories)/200 - planet.nativetaxrate * 0.85
  4292. *
  4293. *
  4294. * Also from Infolist, the amount of MC recieved from natives:
  4295. * MC = planet.nativeclans * planet.nativetaxrate*planet.netivegovernment * .1
  4296. */
  4297. /* From vgap.js:
  4298. *
  4299. * var change = Math.truncate((1000 - Math.sqrt(planet.nativeclans) - (planet.nativetaxrate * 85) - Math.truncate((planet.factories + planet.mines) / 2) - (50 * (10 - planet.nativegovernment))) / 100);
  4300. * if (planet.nativetype == 4) //avian
  4301. * change += 10;
  4302. * if (vgap.getNebulaIntensity(planet.x, planet.y) >= 80) //50ly visibility
  4303. * change += 5;
  4304. *
  4305. * return change;
  4306. */
  4307. //* var change - Math.truncate((planet.factories + planet.mines) / 2) - (50 * (10 - planet.nativegovernment))) / 100) = Math.truncate((1000 - Math.sqrt(planet.nativeclans) - (planet.nativetaxrate * 85)
  4308. //var gf = 50*(10-planet.nativegovernment);
  4309. var mff = Math.truncate((planet.factories+planet.mines)/2 + 50*(10-planet.nativegovernment));
  4310. var ncf = Math.sqrt(planet.nativeclans);
  4311. // Troubleshooting
  4312. if (planet.id == dpi) {
  4313. //console.log("gf:" + gf);
  4314. if (debug) console.log("mff:" + mff);
  4315. if (debug) console.log("ncf:" + ncf);
  4316. }
  4317. //var rate = Math.truncate( ((100 * nhchng) + mff + ncf - 1000)/85)
  4318. // Find the rate iteratively instead
  4319. var rate = vgap.plugins["plManagerPlugin"].findRate(planet,nhchng);
  4320. // Troubleshooting
  4321. if (planet.id == dpi) {
  4322. if (debug) console.log("rate:" + rate);
  4323. }
  4324. //var rate = (change + (50 * (10 - planet.nativegovernment))) / 100)+ Math.truncate((planet.factories + planet.mines) / 2
  4325. var mc = Math.round(rate * planet.nativegovernment * 20 / 100 * planet.nativeclans / 1000);
  4326. // Troubleshooting
  4327. if (planet.id == dpi) {
  4328. if (debug) console.log("mc:" + mc);
  4329. }
  4330. // Check to find the suggested rate if we can't collect that many megacredits
  4331. if (mc > maxmc)
  4332. rate = Math.truncate(maxmc / (planet.nativegovernment * 20 / 100 * planet.nativeclans / 1000));
  4333. // Troubleshooting
  4334. if (planet.id == dpi) {
  4335. if (debug) console.log("rate after maxmc check:" + rate);
  4336. }
  4337. // Finally, we're Borg. We can only tax at 20%
  4338. if (rate > 20)
  4339. rate = 20
  4340. // Lastly, a rounding fix for those small colonist pop planets, but we want those early megacredits!
  4341. // If its suggesting 0%, go to 1%, as long as we have some happiness left:
  4342. if (nhchng <=0 && rate == 0)
  4343. rate = 1;
  4344. if (planet.id == dpi) {
  4345. if (debug) console.log("rate final:" + rate);
  4346. for (var r = 1; r < 20; r++) {
  4347. if (debug) console.log("Change for rate " + r + "%: " + vgap.plugins["plManagerPlugin"].ntctest(planet,r));
  4348. }
  4349. }
  4350. return rate;
  4351. },
  4352. findRate: function(planet, nhchng) {
  4353. // If they're not going to get mad about 20%, do it
  4354. if (vgap.plugins["plManagerPlugin"].ntctest(planet,20) > nhchng)
  4355. return 20;
  4356. for (var r = 1; r <= 100; r++) {
  4357. //console.log("Change for rate " + r + "%: " + vgap.plugins["plManagerPlugin"].ntctest(planet,r));
  4358. if (vgap.plugins["plManagerPlugin"].ntctest(planet,r) < nhchng)
  4359. return r-1;
  4360. }
  4361. return 0;
  4362. },
  4363. ntctest: function (planet,rate) {
  4364. var change = Math.truncate((1000 - Math.sqrt(planet.nativeclans) - (rate * 85) - Math.truncate((planet.factories + planet.mines) / 2) - (50 * (10 - planet.nativegovernment))) / 100);
  4365. if (planet.nativetype == 4) //avian
  4366. change += 10;
  4367. if (vgap.getNebulaIntensity(planet.x, planet.y) >= 80) //50ly visibility
  4368. change += 5;
  4369. return change;
  4370. },
  4371. maxBldgs: function (planet,baseAmount) {
  4372. if (planet.clans <= baseAmount)
  4373. return planet.clans;
  4374. else
  4375. return Math.floor(baseAmount + Math.sqrt(planet.clans - baseAmount));
  4376. },
  4377. addCss: function(cssString) {
  4378. var head = document.getElementsByTagName('head')[0];
  4379. if (head == null)
  4380. return
  4381. //return unless head; var newCss = document.createElement('style');
  4382. var newCss = document.createElement('style');
  4383. newCss.type = "text/css";
  4384. newCss.innerHTML = cssString;
  4385. head.appendChild(newCss);
  4386. },
  4387. /*
  4388. * Note Functions
  4389. * These functions allow us to store the configuration data as notes on the planets
  4390. *
  4391. * Based on similar functions found in Big Beefer's native tax script
  4392. */
  4393. saveObjectAsNote: function (id, type, obj) {
  4394. var note = vgap.getNote(id, type);
  4395. if (note == null)
  4396. note = vgap.addNote(id, type);
  4397. note.changed = 1;
  4398. note.body = JSON.stringify(obj);
  4399. vgap.save();
  4400. },
  4401. resetAllNotes: function() {
  4402. var plg = vgap.plugins["plManagerPlugin"];
  4403. if (debug) console.log("Resetting all notes...");
  4404. // Null the arrays
  4405. plg.bmarray = null;
  4406. plg.ntarray = null;
  4407. plg.ctarray = null;
  4408. plg.buildmethods = null;
  4409. plg.taxmethods = null;
  4410. if (debug) console.log("All methods nulled.");
  4411. plg.bmarray = [];
  4412. plg.ntarray = [];
  4413. plg.ctarray = [];
  4414. plg.buildmethods = [];
  4415. plg.taxmethods = [];
  4416. if (debug) console.log("All methods blank arrayed.");
  4417. // Save the nulls
  4418. /*
  4419. plg.initSaveObjectAsNote(0, plg.notetype, [plugin_version,plg.bmarray]);
  4420. plg.initSaveObjectAsNote(1, plg.notetype, [plugin_version,plg.ntarray]);
  4421. plg.initSaveObjectAsNote(2, plg.notetype, [plugin_version,plg.tarray]);
  4422. plg.initSaveObjectAsNote(4, plg.notetype, [plugin_version,plg.buildmethodsarray]);
  4423. plg.initSaveObjectAsNote(5, plg.notetype, [plugin_version,plg.taxmethodsarray]);
  4424. */
  4425. if (debug) console.log("Saving all notes as null.");
  4426. plg.initSaveObjectAsNote(0, plg.notetype, null);
  4427. plg.initSaveObjectAsNote(1, plg.notetype, null);
  4428. plg.initSaveObjectAsNote(2, plg.notetype, null);
  4429. plg.initSaveObjectAsNote(4, plg.notetype, null);
  4430. plg.initSaveObjectAsNote(5, plg.notetype, null);
  4431. // Read Notes
  4432. if (debug) console.log("Reading notes.");
  4433. plg.readOrder = 1;
  4434. plg.readNotes();
  4435. },
  4436. initSaveObjectAsNote: function (id, type, obj) {
  4437. var note = vgap.getNote(id, type);
  4438. if (note == null)
  4439. note = vgap.addNote(id, type);
  4440. note.changed = 1;
  4441. note.body = JSON.stringify(obj);
  4442. vgap.save();
  4443. //vgap.plugins["plManagerPlugin"].saveInitChanges();
  4444. },
  4445. getObjectFromNote: function (id, type) {
  4446. var note = vgap.getNote(id, type);
  4447. if (note != null && note.body != "")
  4448. return JSON.parse(note.body);
  4449. else
  4450. return null;
  4451. },
  4452. colTaxAmount: function (planet) {
  4453. var colTax = Math.round(planet.colonisttaxrate * planet.clans / 1000);
  4454. //player tax rate (fed bonus)
  4455. var taxbonus = 1;
  4456. if (vgap.advActive(2)) {
  4457. taxbonus = 2;
  4458. }
  4459. colTax = colTax * taxbonus;
  4460. if (colTax > 5000)
  4461. colTax = colTax;
  4462. return colTax;
  4463. },
  4464. natTaxAmount: function (planet) {
  4465. //cyborg max 20%
  4466. var nativetaxrate = planet.nativetaxrate;
  4467. var player = vgap.getPlayer(planet.ownerid);
  4468. if (player != null) {
  4469. if (player.raceid == 6 && nativetaxrate > 20)
  4470. nativetaxrate = 20;
  4471. }
  4472. var val = Math.round(nativetaxrate * planet.nativetaxvalue / 100 * planet.nativeclans / 1000);
  4473. if (val > planet.clans)
  4474. val = planet.clans;
  4475. //player tax rate (fed bonus)
  4476. var taxbonus = 1;
  4477. if (vgap.advActive(2))
  4478. taxbonus = 2;
  4479. val = val * taxbonus;
  4480. //insectoid bonus
  4481. if (planet.nativetype == 6)
  4482. val = val * 2;
  4483. if (val > 5000)
  4484. val = 5000;
  4485. return val;
  4486. },
  4487. natTaxAmtTxt: function(planet) {
  4488. var txt = "";
  4489. var amt = vgap.plugins["plManagerPlugin"].natTaxAmount(planet);
  4490. if (amt == 0)
  4491. return txt;
  4492. else
  4493. return "[+" + amt + "mc]";
  4494. },
  4495. colTaxAmtTxt: function(planet) {
  4496. var txt = "";
  4497. var amt = vgap.plugins["plManagerPlugin"].colTaxAmount(planet);
  4498. if (amt == 0)
  4499. return txt;
  4500. else
  4501. return "[+" + amt + "mc]";
  4502. },
  4503. happyChgTxt: function(chg) {
  4504. var txt = "";
  4505. if (chg == 0)
  4506. return txt;
  4507. if (chg > 0)
  4508. return "(+" + chg + ")";
  4509. else
  4510. return "(" + chg + ")";
  4511. },
  4512. showBldgs: function() {
  4513. var html = "";
  4514. var planet = vgap.planetScreen.planet;
  4515. html = "<p> Factory Manage Plugin v0.1 more<br />"
  4516. html += "<p> Planet Name: " + vgap.planetScreen.planet.name + " <br />"
  4517. // Set target factories to 200 on any viewed planet
  4518. planet.targetfactories = 87;
  4519. planet.changed = 1;
  4520. vgap.planetScreen.build();
  4521. vgap.planetScreen.screen.refresh();
  4522. $("#Buildings").append(html);
  4523. //console.log("FM: planets length is " + vgap.planets.length);
  4524. //for (var i = 0; i < vgap.planets.length; i++)
  4525. //{
  4526. // console.log("FM: i: " + i + " Planet Name: " + vgap.planets[i].name);
  4527. //}
  4528. }
  4529.  
  4530.  
  4531. };
  4532.  
  4533. // register your plugin with NU
  4534. vgap.registerPlugin(plManagerPlugin, "plManagerPlugin");
  4535.  
  4536.  
  4537.  
  4538.  
  4539. } //wrapper for injection
  4540.  
  4541. var script = document.createElement("script");
  4542. script.type = "application/javascript";
  4543. script.textContent = "(" + wrapper + ")();";
  4544.  
  4545. document.body.appendChild(script);