PageRenderTime 50ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/Sections/functions.php

https://github.com/RadicalLinux/faceBot
PHP | 1348 lines | 1069 code | 215 blank | 64 comment | 366 complexity | 82d1a5546cc865ca2a6129e31842100d MD5 | raw file
  1. <?php
  2. function Sections_GetUnits($flashRevision) {
  3. $vReturn = load_array('sections_unit.txt');
  4. if($vReturn['flashRevision']<>$flashRevision) {
  5. $units=Units_GetByType('seed');
  6. foreach($units as $unit) {
  7. if(strlen($unit['realname'])==0) $unit['realname']=$unit['name'];
  8. $vSeeds[$unit['name']]= $unit['realname'];
  9. }
  10. $units=Units_GetByType('animal');
  11. foreach($units as $unit) {
  12. if(strlen($unit['realname'])==0) $unit['realname']=$unit['name'];
  13. $vAnimals[$unit['name']]= $unit['realname'];
  14. if(isset($unit['buyable']) && $unit['buyable']=='true') {
  15. if(isset($unit['market'])) {
  16. $vBuyAnimals['cash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  17. } else {
  18. $vBuyAnimals['coins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  19. }
  20. } else {
  21. if(isset($unit['market'])) {
  22. $vBuyAnimals['nocash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  23. } else {
  24. $vBuyAnimals['nocoins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  25. }
  26. }
  27. $vUnit=strpos($unit['name'],'_')===false?$unit['name']:substr($unit['name'],0,strpos($unit['name'],'_'));
  28. $vAnimalUnits[$vUnit][$unit['name']]= $unit['realname'];
  29. }
  30. $units=Units_GetByType('tree');
  31. foreach($units as $unit) {
  32. $vTrees[$unit['name']] = $unit['realname'];
  33. if(isset($unit['buyable']) && $unit['buyable']=='true') {
  34. if(isset($unit['market'])) {
  35. $vBuyTrees['cash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  36. } else {
  37. $vBuyTrees['coins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  38. }
  39. } else {
  40. if(isset($unit['market'])) {
  41. $vBuyTrees['nocash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  42. } else {
  43. $vBuyTrees['nocoins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  44. }
  45. }
  46. }
  47. $units=Units_GetByType('decoration');
  48. foreach($units as $unit) {
  49. $vDecorations[$unit['name']] = $unit['realname'];
  50. if(isset($unit['buyable']) && $unit['buyable']=='true') {
  51. if(isset($unit['market'])) {
  52. $vBuyDecorations['cash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  53. } else {
  54. $vBuyDecorations['coins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  55. }
  56. } else {
  57. if(isset($unit['market'])) {
  58. $vBuyDecorations['nocash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  59. } else {
  60. $vBuyDecorations['nocoins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  61. }
  62. }
  63. }
  64. $units=Units_GetByType('building');
  65. foreach($units as $unit) {
  66. $vBuildings[$unit['name']] = $unit['realname'];
  67. if(isset($unit['buyable']) && $unit['buyable']=='true') {
  68. if(isset($unit['market'])) {
  69. $vBuyBuildings['cash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  70. } else {
  71. $vBuyBuildings['coins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  72. }
  73. } else {
  74. if(isset($unit['market'])) {
  75. $vBuyBuildings['nocash'][$unit['name']] = $unit['realname'].' ('.$unit['cash'].' cash)';
  76. } else {
  77. $vBuyBuildings['nocoins'][$unit['name']] = $unit['realname'].' ('.$unit['cost'].' coins)';
  78. }
  79. }
  80. }
  81. $units=Units_GetAll();
  82. foreach($units as $unit) {
  83. $vAll[$unit['name']] = $unit['realname'];
  84. }
  85. ksort($vSeeds);
  86. ksort($vAnimals);
  87. ksort($vTrees);
  88. ksort($vDecorations);
  89. ksort($vBuildings);
  90. ksort($vBuyAnimals['cash']);
  91. ksort($vBuyAnimals['coins']);
  92. ksort($vBuyAnimals['nocash']);
  93. ksort($vBuyAnimals['nocoins']);
  94. ksort($vBuyTrees['cash']);
  95. ksort($vBuyTrees['coins']);
  96. ksort($vBuyTrees['nocash']);
  97. ksort($vBuyTrees['nocoins']);
  98. ksort($vBuyDecorations['cash']);
  99. ksort($vBuyDecorations['coins']);
  100. ksort($vBuyDecorations['nocash']);
  101. ksort($vBuyDecorations['nocoins']);
  102. ksort($vBuyBuildings['cash']);
  103. ksort($vBuyBuildings['coins']);
  104. ksort($vBuyBuildings['nocash']);
  105. ksort($vBuyBuildings['nocoins']);
  106. ksort($vAnimalUnits);
  107. ksort($vAll);
  108. $vReturn['flashRevision']=$flashRevision;
  109. $vReturn['vSeeds']=$vSeeds;
  110. $vReturn['vAnimals']=$vAnimals;
  111. $vReturn['vTrees']=$vTrees;
  112. $vReturn['vDecorations']=$vDecorations;
  113. $vReturn['vBuildings']=$vBuildings;
  114. $vReturn['vBuyAnimals']=$vBuyAnimals;
  115. $vReturn['vBuyTrees']=$vBuyTrees;
  116. $vReturn['vBuyDecorations']=$vBuyDecorations;
  117. $vReturn['vBuyBuildings']=$vBuyBuildings;
  118. $vReturn['vAnimalUnits']=$vAnimalUnits;
  119. $vReturn['vAll']=$vAll;
  120. save_array($vReturn, 'sections_unit.txt');
  121. }
  122. return($vReturn);
  123. }
  124. function Sections_GetValue($key, $name) {
  125. return isset($key[$name]) ? $key[$name] : '';
  126. }
  127. function Sections_GetRealName($name,$realname='') {
  128. return strlen($realname)>0?$realname:$name;
  129. }
  130. #function Sections_GetGiftboxContent($units) {
  131. function Sections_GetGiftboxContent() {
  132. $ingiftbox = @unserialize(fBGetDataStore('ingiftbox'));
  133. if(is_array($ingiftbox)) {
  134. foreach ($ingiftbox as $gift => $count) {
  135. list($qcount) = explode(',', $count);
  136. # $vItem = Section_GetUnit($units,$gift);
  137. $vItem = Units_GetUnitByCode($gift);
  138. if($vItem['type']=='animal') {
  139. $vItemTyp='animal';
  140. } elseif($vItem['type']=='tree') {
  141. $vItemTyp='tree';
  142. } elseif($vItem['type']=='decoration') {
  143. $vItemTyp='decoration';
  144. } elseif($vItem['type']=='rotateabledecoration') {
  145. $vItemTyp='decoration';
  146. } elseif($vItem['type']=='lootabledecoration') {
  147. $vItemTyp='decoration';
  148. } elseif($vItem['type']=='egg') {
  149. $vItemTyp='decoration';
  150. } elseif($vItem['type']=='mysterygift') {
  151. $vItemTyp='decoration';
  152. } elseif($vItem['type']=='flowerdecoration') {
  153. $vItemTyp='decoration';
  154. } elseif($vItem['type']=='building') {
  155. $vItemTyp='building';
  156. } else {
  157. $vItemTyp='unused';
  158. }
  159. for($vI=0;$vI<$qcount;$vI++) $Return[$vItemTyp][]=$vItem;
  160. }
  161. }
  162. return $Return;
  163. }
  164. #function Section_GetUnit($Units_Array,$Code) {
  165. # foreach($Units_Array as $Item_Name => $Item_Array) {
  166. # if($Item_Array['code']==$Code) return $Item_Array;
  167. # }
  168. # return false;
  169. #}
  170. function Sections_relocate_animals() {
  171. global $need_reload;
  172. global $vAnnounceMoveArray;
  173. global $vAnnouncePlaceArray;
  174. global $vAnnounceBuyArray;
  175. global $vAnnounceWalkRotateArray;
  176. if($need_reload == true) {
  177. $res = DoInit();
  178. $need_reload=false;
  179. }
  180. #return; // uncomment to disable for debug purposes
  181. # $units = @unserialize(file_get_contents(F('units.txt')));
  182. $objects = @unserialize(fBGetDataStore('objects'));
  183. list($level, $gold, $cash, $sizeX, $sizeY, $firstname, $locale, $tileset, $wither, $xp, $energy, $flashRevision) = explode(';', fBGetDataStore('playerinfo'));
  184. $sections = array();
  185. $sections = load_array('sections.txt');
  186. if( !((is_array($sections) && count($sections))) ) {
  187. $sections = array();
  188. }
  189. // Build matrix so we can know which locations are empty
  190. $location_empty = array();
  191. for ($x = 0; $x < $sizeX; $x++) {
  192. for ($y = 0; $y < $sizeY; $y++) {
  193. $location_empty[$x][$y] = true;
  194. }
  195. }
  196. foreach($objects as $o) {
  197. # $u = $units[$o['itemName']];
  198. $u = Units_GetUnitByName($o['itemName']);
  199. if (!isset($u['sizeX'])) {
  200. $u['sizeX'] = 1;
  201. $u['sizeY'] = 1;
  202. }
  203. if ($o['state'] == 'vertical') {
  204. $t = $u['sizeX'];
  205. $u['sizeX'] = $u['sizeY'];
  206. $u['sizeY'] = $t;
  207. }
  208. for($x=0;$x < $u['sizeX']; $x++) {
  209. for($y=0;$y < $u['sizeY']; $y++) {
  210. $location_empty[ $o['position']['x'] + $x ][ $o['position']['y'] + $y ] = false;
  211. }
  212. }
  213. }
  214. $animals = GetObjects('Animal');
  215. foreach($animals as $o) {
  216. $vMoveCnt=0;
  217. $vInPositionCnt=0;
  218. # $u = $units[ $o['itemName'] ];
  219. $u = Units_GetUnitByName($o['itemName']);
  220. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  221. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  222. if ($o['state'] == 'vertical') {
  223. $t = $u['sizeX'];
  224. $u['sizeX'] = $u['sizeY'];
  225. $u['sizeY'] = $t;
  226. }
  227. foreach ($sections as $section) {
  228. if ($section['active']=='1' && (($section['type']=='anim' && in_array($o['itemName'], explode('|',$section['anim'])))||$section['type']=='dontmove')) {
  229. $npx = $o['position']['x'];
  230. $npy = $o['position']['y'];
  231. for($x=0;$x < $u['sizeX']; $x++) {
  232. for($y=0;$y < $u['sizeY']; $y++) {
  233. if( !(
  234. ($npx+$x >= $section['bot_x'] ) &&
  235. ($npx+$x <= $section['top_x']) &&
  236. ($npy+$y >= $section['bot_y']) &&
  237. ($npy+$y <= $section['top_y'])) ) {
  238. $vMoveCnt++;
  239. } else {
  240. $vInPositionCnt++;
  241. }
  242. }
  243. }
  244. }
  245. }
  246. if($vMoveCnt>0 && ($vInPositionCnt==0 || $vInPositionCnt % ($u['sizeX']*$u['sizeY']))>0) {
  247. # AddLog2("Sections: Found " . $o['itemName'] . " on " . $npx . "-" . $npy . " - wrong position.");
  248. $newpos = Sections_Find_Free_Location($sections, $u, $o, $location_empty, 'animal');
  249. if ($newpos != false) {
  250. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  251. $oldpos = $o['position'];
  252. Sections_Announce_Move($o,$newpos);
  253. for($x=0;$x < $u['sizeX']; $x++) {
  254. for($y=0;$y < $u['sizeY']; $y++) {
  255. $location_empty[ $oldpos['x'] + $x ][ $oldpos['y'] + $y ] = true;
  256. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  257. }
  258. }
  259. } else {
  260. # AddLog2("Sections: No new location found");
  261. }
  262. }
  263. }
  264. $trees = GetObjects('Tree');
  265. foreach($trees as $o) {
  266. $vMoveCnt=0;
  267. $vInPositionCnt=0;
  268. # $u = $units[ $o['itemName'] ];
  269. $u = Units_GetUnitByName($o['itemName']);
  270. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  271. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  272. if ($o['state'] == 'vertical') {
  273. $t = $u['sizeX'];
  274. $u['sizeX'] = $u['sizeY'];
  275. $u['sizeY'] = $t;
  276. }
  277. foreach ($sections as $section) {
  278. if ($section['active']=='1' && (($section['type']=='tree' && in_array($o['itemName'], explode('|',$section['tree'])))||$section['type']=='dontmove')) {
  279. $npx = $o['position']['x'];
  280. $npy = $o['position']['y'];
  281. for($x=0;$x < $u['sizeX']; $x++) {
  282. for($y=0;$y < $u['sizeY']; $y++) {
  283. if( !(
  284. ($npx+$x >= $section['bot_x'] ) &&
  285. ($npx+$x <= $section['top_x']) &&
  286. ($npy+$y >= $section['bot_y']) &&
  287. ($npy+$y <= $section['top_y'])) ) {
  288. $vMoveCnt++;
  289. } else {
  290. $vInPositionCnt++;
  291. }
  292. }
  293. }
  294. }
  295. }
  296. if($vMoveCnt>0 && ($vInPositionCnt==0 || $vInPositionCnt % ($u['sizeX']*$u['sizeY']))>0) {
  297. # AddLog2("Sections: Found " . $o['itemName'] . " on " . $npx . "-" . $npy . " - wrong position.");
  298. $newpos = Sections_Find_Free_Location($sections, $u, $o, $location_empty, 'tree');
  299. if ($newpos != false) {
  300. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  301. $oldpos = $o['position'];
  302. Sections_Announce_Move($o,$newpos);
  303. for($x=0;$x < $u['sizeX']; $x++) {
  304. for($y=0;$y < $u['sizeY']; $y++) {
  305. $location_empty[ $oldpos['x'] + $x ][ $oldpos['y'] + $y ] = true;
  306. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  307. }
  308. }
  309. } else {
  310. # AddLog2("Sections: No new location found");
  311. }
  312. }
  313. }
  314. $decorations = array_merge( GetObjects('Decoration'), GetObjects('RotateableDecoration'), GetObjects('LootableDecoration'), GetObjects('MysteryGift'), GetObjects('FlowerDecoration'), GetObjects('Building'));
  315. $vSearchEggArray[]='egg_white'; $vReplaceEggArray[]='mysteryeggwhite';
  316. $vSearchEggArray[]='egg_brown'; $vReplaceEggArray[]='mysteryeggbrown';
  317. $vSearchEggArray[]='egg_black'; $vReplaceEggArray[]='mysteryeggblack';
  318. $vSearchEggArray[]='egg_gold'; $vReplaceEggArray[]='mysteryegggold';
  319. $vSearchEggArray[]='egg_cornish'; $vReplaceEggArray[]='mysteryeggcornish';
  320. $vSearchEggArray[]='egg_rhodered'; $vReplaceEggArray[]='mysteryeggrhodered';
  321. $vSearchEggArray[]='egg_scotsgrey'; $vReplaceEggArray[]='mysteryeggscotsgrey';
  322. if (!empty($decorations)) {
  323. foreach($decorations as $o) {
  324. $vMoveCnt=0;
  325. $vInPositionCnt=0;
  326. # $u = $units[ $o['itemName'] ];
  327. $u = Units_GetUnitByName($o['itemName']);
  328. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  329. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  330. if ($o['state'] == 'vertical') {
  331. $t = $u['sizeX'];
  332. $u['sizeX'] = $u['sizeY'];
  333. $u['sizeY'] = $t;
  334. }
  335. foreach ($sections as $section) {
  336. if ($section['active']=='1' && (($section['type']=='deco' && in_array($o['itemName'], explode('|',str_replace($vSearchEggArray,$vReplaceEggArray,$section['deco']))))||$section['type']=='dontmove')) {
  337. $npx = $o['position']['x'];
  338. $npy = $o['position']['y'];
  339. for($x=0;$x < $u['sizeX']; $x++) {
  340. for($y=0;$y < $u['sizeY']; $y++) {
  341. if( !(
  342. ($npx+$x >= $section['bot_x'] ) &&
  343. ($npx+$x <= $section['top_x']) &&
  344. ($npy+$y >= $section['bot_y']) &&
  345. ($npy+$y <= $section['top_y'])) ) {
  346. $vMoveCnt++;
  347. } else {
  348. $vInPositionCnt++;
  349. }
  350. }
  351. }
  352. }
  353. }
  354. if($vMoveCnt>0 && ($vInPositionCnt==0 || $vInPositionCnt % ($u['sizeX']*$u['sizeY']))>0) {
  355. # AddLog2("Sections: Found " . $o['itemName'] . " on " . $npx . "-" . $npy . " - wrong position.");
  356. $newpos = Sections_Find_Free_Location($sections, $u, $o, $location_empty, 'decoration');
  357. if ($newpos != false) {
  358. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  359. $oldpos = $o['position'];
  360. Sections_Announce_Move($o,$newpos);
  361. for($x=0;$x < $u['sizeX']; $x++) {
  362. for($y=0;$y < $u['sizeY']; $y++) {
  363. $location_empty[ $oldpos['x'] + $x ][ $oldpos['y'] + $y ] = true;
  364. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  365. }
  366. }
  367. } else {
  368. # AddLog2("Sections: No new location found");
  369. }
  370. }
  371. }
  372. }
  373. @$buildings = array_merge( GetObjects('Building'), GetObjects('MysterySeedling'));
  374. if (!empty($buildings)) {
  375. foreach($buildings as $o) {
  376. $vMoveCnt=0;
  377. $vInPositionCnt=0;
  378. # $u = $units[ $o['itemName'] ];
  379. $u = Units_GetUnitByName($o['itemName']);
  380. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  381. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  382. if ($o['state'] == 'vertical') {
  383. $t = $u['sizeX'];
  384. $u['sizeX'] = $u['sizeY'];
  385. $u['sizeY'] = $t;
  386. }
  387. foreach ($sections as $section) {
  388. if ($section['active']=='1' && (($section['type']=='building' && in_array($o['itemName'], explode('|',$section['building'])))||$section['type']=='dontmove')) {
  389. $npx = $o['position']['x'];
  390. $npy = $o['position']['y'];
  391. for($x=0;$x < $u['sizeX']; $x++) {
  392. for($y=0;$y < $u['sizeY']; $y++) {
  393. if( !(
  394. ($npx+$x >= $section['bot_x'] ) &&
  395. ($npx+$x <= $section['top_x']) &&
  396. ($npy+$y >= $section['bot_y']) &&
  397. ($npy+$y <= $section['top_y'])) ) {
  398. $vMoveCnt++;
  399. } else {
  400. $vInPositionCnt++;
  401. }
  402. }
  403. }
  404. }
  405. }
  406. if($vMoveCnt>0 && ($vInPositionCnt==0 || $vInPositionCnt % ($u['sizeX']*$u['sizeY']))>0) {
  407. # AddLog2("Sections: Found " . $o['itemName'] . " on " . $npx . "-" . $npy . " - wrong position.");
  408. $newpos = Sections_Find_Free_Location($sections, $u, $o, $location_empty, 'building');
  409. if ($newpos != false) {
  410. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  411. $oldpos = $o['position'];
  412. Sections_Announce_Move($o,$newpos);
  413. for($x=0;$x < $u['sizeX']; $x++) {
  414. for($y=0;$y < $u['sizeY']; $y++) {
  415. $location_empty[ $oldpos['x'] + $x ][ $oldpos['y'] + $y ] = true;
  416. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  417. }
  418. }
  419. } else {
  420. # AddLog2("Sections: No new location found");
  421. }
  422. }
  423. }
  424. }
  425. $vPlaceArray=array();
  426. foreach ($sections as $section) {
  427. if ($section['active']=='1' && $section['place']=='1' && $section['type']=='anim') {
  428. $vPlaceArray=array_merge($vPlaceArray,explode('|',$section['anim']));
  429. }
  430. if ($section['active']=='1' && $section['place']=='1' && $section['type']=='tree') {
  431. $vPlaceArray=array_merge($vPlaceArray,explode('|',$section['tree']));
  432. }
  433. if ($section['active']=='1' && $section['place']=='1' && $section['type']=='deco') {
  434. $vPlaceArray=array_merge($vPlaceArray,explode('|',str_replace($vSearchEggArray,$vReplaceEggArray,$section['deco'])));
  435. }
  436. if ($section['active']=='1' && $section['place']=='1' && $section['type']=='building') {
  437. $vPlaceArray=array_merge($vPlaceArray,explode('|',$section['building']));
  438. }
  439. }
  440. # $vGiftboxContent=Sections_GetGiftboxContent($units);
  441. $vGiftboxContent=Sections_GetGiftboxContent();
  442. @$animals = $vGiftboxContent['animal'];
  443. if (!empty($animals)) {
  444. foreach($animals as $o) {
  445. if(in_array($o['name'],$vPlaceArray)) {
  446. # $u = $units[ $o['name'] ];
  447. $u = Units_GetUnitByName($o['name']);
  448. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  449. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  450. # AddLog2("Sections: Found " . $o['name'] . " (anim) in GiftBox.");
  451. $newpos = Sections_Find_Free_Location_Place($sections, $u, $o, $location_empty, 'animal');
  452. if ($newpos != false) {
  453. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  454. Sections_Announce_Place($o,$newpos);
  455. for($x=0;$x < $u['sizeX']; $x++) {
  456. for($y=0;$y < $u['sizeY']; $y++) {
  457. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  458. }
  459. }
  460. } else {
  461. # AddLog2("Sections: No new location / no section found");
  462. }
  463. }
  464. }
  465. }
  466. @$tree = $vGiftboxContent['tree'];
  467. if (!empty($tree)) {
  468. foreach($tree as $o) {
  469. if(in_array($o['name'],$vPlaceArray)) {
  470. # $u = $units[ $o['name'] ];
  471. $u = Units_GetUnitByName($o['name']);
  472. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  473. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  474. # AddLog2("Sections: Found " . $o['name'] . " (tree) in GiftBox.");
  475. $newpos = Sections_Find_Free_Location_Place($sections, $u, $o, $location_empty, 'tree');
  476. if ($newpos != false) {
  477. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  478. Sections_Announce_Place($o,$newpos);
  479. for($x=0;$x < $u['sizeX']; $x++) {
  480. for($y=0;$y < $u['sizeY']; $y++) {
  481. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  482. }
  483. }
  484. } else {
  485. # AddLog2("Sections: No new location / no section found");
  486. }
  487. }
  488. }
  489. }
  490. @$decoration = $vGiftboxContent['decoration'];
  491. if (!empty($decoration)) {
  492. foreach($decoration as $o) {
  493. if(in_array($o['name'],$vPlaceArray)) {
  494. # $u = $units[ $o['name'] ];
  495. $u = Units_GetUnitByName($o['name']);
  496. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  497. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  498. # AddLog2("Sections: Found " . $o['name'] . " (deco) in GiftBox.");
  499. $newpos = Sections_Find_Free_Location_Place($sections, $u, $o, $location_empty, 'decoration');
  500. if ($newpos != false) {
  501. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  502. Sections_Announce_Place($o,$newpos);
  503. for($x=0;$x < $u['sizeX']; $x++) {
  504. for($y=0;$y < $u['sizeY']; $y++) {
  505. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  506. }
  507. }
  508. } else {
  509. # AddLog2("Sections: No new location / no section found");
  510. }
  511. }
  512. }
  513. }
  514. @$buildings = $vGiftboxContent['building'];
  515. if (!empty($buildings)) {
  516. foreach($buildings as $o) {
  517. if(in_array($o['name'],$vPlaceArray)) {
  518. # $u = $units[ $o['name'] ];
  519. $u = Units_GetUnitByName($o['name']);
  520. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  521. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  522. # AddLog2("Sections: Found " . $o['name'] . " (deco) in GiftBox.");
  523. $newpos = Sections_Find_Free_Location_Place($sections, $u, $o, $location_empty, 'building');
  524. if ($newpos != false) {
  525. #AddLog2("Sections: Found free location on: " . $newpos['x'] . '-' . $newpos['y']);
  526. Sections_Announce_Place($o,$newpos);
  527. for($x=0;$x < $u['sizeX']; $x++) {
  528. for($y=0;$y < $u['sizeY']; $y++) {
  529. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  530. }
  531. }
  532. } else {
  533. # AddLog2("Sections: No new location / no section found");
  534. }
  535. }
  536. }
  537. }
  538. foreach ($sections as $num=>$section) {
  539. if ($section['active']=='1' && ($section['type']=='buyanim' || $section['type']=='buytree' || $section['type']=='buydeco')) {
  540. # $u = $units[$section[$section['type']]];
  541. $u = Units_GetUnitByName($section[$section['type']]);
  542. if(strlen($u['name'])>0) {
  543. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  544. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  545. while($newpos = Sections_Find_Free_Location_Buy($section, $u, $location_empty)) {
  546. Sections_Announce_Buy($u,$newpos);
  547. for($x=0;$x < $u['sizeX']; $x++) {
  548. for($y=0;$y < $u['sizeY']; $y++) {
  549. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  550. }
  551. }
  552. }
  553. }
  554. ####################################################################################################
  555. # $sections[$num]['active']='0';
  556. # save_array($sections, 'sections.txt');
  557. }
  558. }
  559. if(count($vAnnounceMoveArray)>0) {
  560. $result=Sections_Move_Speed();
  561. $need_reload = $need_reload || $result;
  562. }
  563. if(count($vAnnouncePlaceArray)>0) {
  564. $result=Sections_Buy_Place_Speed('place');
  565. $need_reload = $need_reload || $result;
  566. }
  567. if(count($vAnnounceBuyArray)>0) {
  568. $result=Sections_Buy_Place_Speed('buy');
  569. $need_reload = $need_reload || $result;
  570. }
  571. if($need_reload == true) {
  572. $res = DoInit();
  573. $need_reload = false;
  574. }
  575. $animals = GetObjects('Animal');
  576. foreach($animals as $o) {
  577. # $u = $units[ $o['itemName'] ];
  578. $u = Units_GetUnitByName($o['itemName']);
  579. if( !isset($u['sizeX']) ) $u['sizeX'] = 1;
  580. if( !isset($u['sizeY']) ) $u['sizeY'] = 1;
  581. if ($o['state'] == 'vertical') {
  582. $t = $u['sizeX'];
  583. $u['sizeX'] = $u['sizeY'];
  584. $u['sizeY'] = $t;
  585. }
  586. foreach ($sections as $vSNum=>$section) {
  587. if ($section['active']=='1' && $section['type']=='anim' && (($section['rotate']<>'' && $section['rotate']<>'nothing') || ($section['walk']<>'' && $section['walk']<>'nothing')) && in_array($o['itemName'], explode('|',$section['anim']))) {
  588. if(
  589. ($o['position']['x'] >= $section['bot_x']) &&
  590. ($o['position']['x'] <= $section['top_x']) &&
  591. ($o['position']['y'] >= $section['bot_y']) &&
  592. ($o['position']['y'] <= $section['top_y'])
  593. ) {
  594. if(($section['rotate']<>'' && $section['rotate']<>'nothing') && ($section['walk']<>'' && $section['walk']<>'nothing')) {
  595. if($o['direction']<>$section['rotate'] || ($o['canWander']=='' && $section['walk']=='walk') || ($o['canWander']==1 && $section['walk']=='stay')) {
  596. Sections_Announce_WalkRotate($o,$section['walk']=='walk'?1:0,$section['rotate']);
  597. }
  598. } elseif(($section['rotate']=='' || $section['rotate']=='nothing') && ($section['walk']<>'' && $section['walk']<>'nothing')) {
  599. if(($o['canWander']=='' && $section['walk']=='walk') || ($o['canWander']==1 && $section['walk']=='stay')) {
  600. Sections_Announce_WalkRotate($o,$section['walk']=='walk'?1:0,$o['direction']);
  601. }
  602. } elseif(($section['rotate']<>'' && $section['rotate']<>'nothing') && ($section['walk']=='' || $section['walk']=='nothing')) {
  603. if($o['direction']<>$section['rotate']) {
  604. Sections_Announce_WalkRotate($o,$o['canWander'],$section['rotate']);
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. if(count($vAnnounceWalkRotateArray)>0) {
  612. $result=Sections_WalkRotate_Speed();
  613. $need_reload = $need_reload || $result;
  614. }
  615. if($need_reload == true) {
  616. $res = DoInit();
  617. $need_reload=false;
  618. }
  619. }
  620. function Sections_Announce_Move($target,$newpos) {
  621. global $vAnnounceMoveArray;
  622. AddLog2("Sections: Announce Moving " . $target['itemName'] . " to " . $newpos['x'] . '-' . $newpos['y']);
  623. $vAnnounceMoveArray[]=array('target'=>$target,'newpos'=>$newpos);
  624. }
  625. function Sections_Announce_Place($unit,$newpos) {
  626. global $vAnnouncePlaceArray;
  627. AddLog2("Sections: Announce Place " . $unit['name'] . " on " . $newpos['x'] . '-' . $newpos['y']);
  628. $vAnnouncePlaceArray[]=array('unit'=>$unit['name'],'type'=>$unit['type'],'newpos'=>$newpos,'item'=>$unit);
  629. }
  630. function Sections_Announce_Buy($unit,$newpos) {
  631. global $vAnnounceBuyArray;
  632. AddLog2("Sections: Announce Buy " . $unit['name'] . " on " . $newpos['x'] . '-' . $newpos['y']);
  633. $vAnnounceBuyArray[]=array('unit'=>$unit['name'],'type'=>$unit['type'],'newpos'=>$newpos,'item'=>$unit);
  634. }
  635. function Sections_Announce_WalkRotate($o,$vWalk,$vRotate) {
  636. global $vAnnounceWalkRotateArray;
  637. AddLog2("Sections: Announce WalkRotate " . $o['position']['x'] . '-' . $o['position']['y']);
  638. $vAnnounceWalkRotateArray[]=array('o'=>$o,'vWalk'=>$vWalk,'vRotate'=>$vRotate,);
  639. }
  640. function Sections_Move_Speed() {
  641. global $vAnnounceMoveArray;
  642. $px_Setopts = LoadSavedSettings();
  643. if ((!@$px_Setopts['bot_speed']) || (@$px_Setopts['bot_speed'] > 50) || (@$px_Setopts['bot_speed'] < 1)) {
  644. $vSpeed = 1;
  645. } else {
  646. $vSpeed=$px_Setopts['bot_speed'];
  647. }
  648. $vCntMoves=count($vAnnounceMoveArray);
  649. $vRunMainLoop=ceil($vCntMoves/$vSpeed);
  650. for($vI=0;$vI<$vRunMainLoop;$vI++) {
  651. $need_reload = false;
  652. $res = 0;
  653. $amf = new AMFObject("");
  654. $amf->_bodys[0] = new MessageBody();
  655. $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
  656. $amf->_bodys[0]->responseURI = '/1/onStatus';
  657. $amf->_bodys[0]->responseIndex = '/1';
  658. $amf->_bodys[0]->_value[0] = GetAMFHeaders();
  659. unset($vMSG);
  660. $vNumAction=0;
  661. for($vJ=($vI*$vSpeed);(($vJ<(($vI*$vSpeed)+$vSpeed))&&($vJ<$vCntMoves));$vJ++) {
  662. $target=$vAnnounceMoveArray[$vJ]['target'];
  663. $newpos=$vAnnounceMoveArray[$vJ]['newpos'];
  664. $amf->_bodys[0]->_value[1][$vNumAction]['params'] = array();
  665. $amf->_bodys[0]->_value[1][$vNumAction]['params'][0] = 'move' ;
  666. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1] = $target;
  667. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2] = array();
  668. if(isset($target['canWander'])) $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['canWander'] = $target['canWander'];
  669. if(isset($target['state'])) $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['state'] = $target['state'];
  670. if(isset($target['direction'])) $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['direction'] = $target['direction'];
  671. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['x'] = (int)$newpos['x'];
  672. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['y'] = (int)$newpos['y'];
  673. $amf->_bodys[0]->_value[1][$vNumAction]['sequence'] = GetSequense();
  674. $amf->_bodys[0]->_value[1][$vNumAction]['functionName'] = 'WorldService.performAction';
  675. $vNumAction++;
  676. $vMSG[]=$newpos['x'].'/'.$newpos['y'];
  677. }
  678. $amf->_bodys[0]->_value[2] = 0;
  679. AddLog2("Sections: Speed_Moving to ".implode(' ',$vMSG));
  680. $res = RequestAMF($amf);
  681. AddLog2("Sections: result $res");
  682. if ($res === 'OK') {
  683. $need_reload = true;
  684. }
  685. }
  686. return ($need_reload);
  687. }
  688. function Sections_Buy_Place_Speed($vDo='buy') {
  689. if($vDo=='buy') {
  690. global $vAnnounceBuyArray;
  691. $vItemArray=$vAnnounceBuyArray;
  692. } else {
  693. global $vAnnouncePlaceArray;
  694. $vItemArray=$vAnnouncePlaceArray;
  695. }
  696. global $vCnt63000;
  697. if($vCnt63000<63000) $vCnt63000=63000;
  698. $px_Setopts = LoadSavedSettings();
  699. if ((!@$px_Setopts['bot_speed']) || (@$px_Setopts['bot_speed'] > 50) || (@$px_Setopts['bot_speed'] < 1)) {
  700. $vSpeed = 1;
  701. } else {
  702. $vSpeed=$px_Setopts['bot_speed'];
  703. }
  704. $vCntMoves=count($vItemArray);
  705. $vRunMainLoop=ceil($vCntMoves/$vSpeed);
  706. for($vI=0;$vI<$vRunMainLoop;$vI++) {
  707. $need_reload = false;
  708. $res = 0;
  709. $amf = new AMFObject("");
  710. $amf->_bodys[0] = new MessageBody();
  711. $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
  712. $amf->_bodys[0]->responseURI = '/1/onStatus';
  713. $amf->_bodys[0]->responseIndex = '/1';
  714. $amf->_bodys[0]->_value[0] = GetAMFHeaders();
  715. unset($vMSG);
  716. $vNumAction=0;
  717. for($vJ=($vI*$vSpeed);(($vJ<(($vI*$vSpeed)+$vSpeed))&&($vJ<$vCntMoves));$vJ++) {
  718. $unit=$vItemArray[$vJ]['unit'];
  719. $type=$vItemArray[$vJ]['type'];
  720. $newpos=$vItemArray[$vJ]['newpos'];
  721. if(array_key_exists('type', $vItemArray[$vJ]['item'])) {
  722. $state = 'static';
  723. if($vItemArray[$vJ]['type']['item']=='decoration') $state = 'static';
  724. if($vItemArray[$vJ]['type']['item']=='rotateableDecoration') $state = 'horizontal';
  725. if($vItemArray[$vJ]['type']['item']=='animal') $state = 'bare';
  726. } else {
  727. $state = 'static';
  728. }
  729. $amf->_bodys[0]->_value[1][$vNumAction]['params'][0] = 'place';
  730. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['itemName'] = $unit;
  731. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['direction'] = 1;
  732. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['state'] = $state;
  733. if(array_key_exists('growTime', $vItemArray[$vJ]['item'])) {
  734. list($vUSec,$vSec) = explode(" ", microtime());
  735. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['plantTime'] = (string)$vSec.substr((string)$vUSec, 2, 3);
  736. }
  737. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['deleted'] = false;
  738. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['id'] = $vCnt63000 ++;
  739. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['className'] = $type;
  740. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['tempId'] = -1;
  741. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['position']['z'] = 0;
  742. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['position']['x'] = (int)$newpos['x'];
  743. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1]['position']['y'] = (int)$newpos['y'];
  744. if($vDo=='buy') {
  745. ####################################################################################################
  746. # $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['isStorageWithdrawal'] = 0;
  747. # $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['isGift'] = false;
  748. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['isStorageWithdrawal'] = -1;
  749. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['isGift'] = false;
  750. } else {
  751. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['isStorageWithdrawal'] = -1;
  752. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['isGift'] = true;
  753. }
  754. $amf->_bodys[0]->_value[1][$vNumAction]['sequence'] = GetSequense();
  755. $amf->_bodys[0]->_value[1][$vNumAction]['functionName'] = 'WorldService.performAction';
  756. $vNumAction++;
  757. $vMSG[]=$newpos['x'].'/'.$newpos['y'];
  758. }
  759. $amf->_bodys[0]->_value[2] = 0;
  760. if($vDo=='buy') {
  761. AddLog2("Sections: Speed_Buy on ".implode(' ',$vMSG));
  762. } else {
  763. AddLog2("Sections: Speed_Place on ".implode(' ',$vMSG));
  764. }
  765. $res = RequestAMF($amf);
  766. AddLog2("Sections: result $res");
  767. if ($res === 'OK') {
  768. $need_reload = true;
  769. }
  770. }
  771. return ($need_reload);
  772. }
  773. function Sections_WalkRotate_Speed() {
  774. global $vAnnounceWalkRotateArray;
  775. $px_Setopts = LoadSavedSettings();
  776. if ((!@$px_Setopts['bot_speed']) || (@$px_Setopts['bot_speed'] > 50) || (@$px_Setopts['bot_speed'] < 1)) {
  777. $vSpeed = 1;
  778. } else {
  779. $vSpeed=$px_Setopts['bot_speed'];
  780. }
  781. $vCntMoves=count($vAnnounceWalkRotateArray);
  782. $vRunMainLoop=ceil($vCntMoves/$vSpeed);
  783. for($vI=0;$vI<$vRunMainLoop;$vI++) {
  784. $need_reload = false;
  785. $res = 0;
  786. $amf = new AMFObject("");
  787. $amf->_bodys[0] = new MessageBody();
  788. $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
  789. $amf->_bodys[0]->responseURI = '/1/onStatus';
  790. $amf->_bodys[0]->responseIndex = '/1';
  791. $amf->_bodys[0]->_value[0] = GetAMFHeaders();
  792. unset($vMSG);
  793. $vNumAction=0;
  794. for($vJ=($vI*$vSpeed);(($vJ<(($vI*$vSpeed)+$vSpeed))&&($vJ<$vCntMoves));$vJ++) {
  795. $o=$vAnnounceWalkRotateArray[$vJ]['o'];
  796. $vWalk=$vAnnounceWalkRotateArray[$vJ]['vWalk'];
  797. $vRotate=$vAnnounceWalkRotateArray[$vJ]['vRotate'];
  798. $amf->_bodys[0]->_value[1][$vNumAction]['params'] = array();
  799. $amf->_bodys[0]->_value[1][$vNumAction]['params'][0] = 'move' ;
  800. $amf->_bodys[0]->_value[1][$vNumAction]['params'][1] = $o;
  801. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2] = array();
  802. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['canWander'] = $vWalk;
  803. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['state'] = $o['state'];
  804. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['direction'] = $vRotate;
  805. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['x'] = $o['position']['x'];
  806. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['y'] = $o['position']['y'];
  807. $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['z'] = $o['position']['z'];
  808. $amf->_bodys[0]->_value[1][$vNumAction]['sequence'] = GetSequense();
  809. $amf->_bodys[0]->_value[1][$vNumAction]['functionName'] = 'WorldService.performAction';
  810. $vNumAction++;
  811. $vMSG[]=$o['position']['x'].'/'.$o['position']['y'];
  812. }
  813. $amf->_bodys[0]->_value[2] = 0;
  814. AddLog2("Sections: Speed_WalkRotate on ".implode(' ',$vMSG));
  815. $res = RequestAMF($amf);
  816. AddLog2("Sections: result $res");
  817. if ($res === 'OK') {
  818. $need_reload = true;
  819. }
  820. }
  821. return ($need_reload);
  822. }
  823. function Sections_Find_Free_Location($sections, $unit, $o, $locs, $vWhat) {
  824. $vSearchEggArray[]='egg_white'; $vReplaceEggArray[]='mysteryeggwhite';
  825. $vSearchEggArray[]='egg_brown'; $vReplaceEggArray[]='mysteryeggbrown';
  826. $vSearchEggArray[]='egg_black'; $vReplaceEggArray[]='mysteryeggblack';
  827. $vSearchEggArray[]='egg_gold'; $vReplaceEggArray[]='mysteryegggold';
  828. $vSearchEggArray[]='egg_cornish'; $vReplaceEggArray[]='mysteryeggcornish';
  829. $vSearchEggArray[]='egg_rhodered'; $vReplaceEggArray[]='mysteryeggrhodered';
  830. $vSearchEggArray[]='egg_scotsgrey'; $vReplaceEggArray[]='mysteryeggscotsgrey';
  831. for($x=0;$x < $unit['sizeX']; $x++) {
  832. for($y=0;$y < $unit['sizeY']; $y++) {
  833. $locs[ $o['position']['x'] + $x ][ $o['position']['y'] + $y ] = true;
  834. }
  835. }
  836. foreach ($sections as $section) {
  837. if (
  838. $section['active']=='1' && (
  839. ($section['type']=='anim' && $vWhat=='animal' && in_array($o['itemName'],explode('|',$section['anim'])))
  840. ||
  841. ($section['type']=='tree' && $vWhat=='tree' && in_array($o['itemName'],explode('|',$section['tree'])))
  842. ||
  843. ($section['type']=='deco' && $vWhat=='decoration' && in_array($o['itemName'],explode('|',$section['deco'])))
  844. ||
  845. ($section['type']=='deco' && $vWhat=='decoration' && in_array($o['itemName'],explode('|',str_replace($vSearchEggArray,$vReplaceEggArray,$section['deco']))))
  846. ||
  847. ($section['type']=='building' && $vWhat=='building' && in_array($o['itemName'],explode('|',$section['building'])))
  848. )
  849. ) {
  850. for($x = $section['bot_x']; $x <= ($section['top_x']-$unit['sizeX']+1);$x++) {
  851. for($y = $section['bot_y']; $y <= ($section['top_y']-$unit['sizeY']+1);$y++) {
  852. $is_available = true;
  853. for ($x2 = 0; $x2 < $unit['sizeX']; $x2++) {
  854. for ($y2 = 0; $y2 < $unit['sizeY']; $y2++) {
  855. if ($locs[$x+$x2][$y+$y2] == false) {
  856. $is_available = false;
  857. }
  858. }
  859. }
  860. if ($is_available) {
  861. return array("x"=>$x,"y"=>$y);
  862. }
  863. }
  864. }
  865. }
  866. }
  867. return false;
  868. }
  869. function Sections_Find_Free_Location_Place($sections, $unit, $o, $locs, $vWhat) {
  870. $vSearchEggArray[]='egg_white'; $vReplaceEggArray[]='mysteryeggwhite';
  871. $vSearchEggArray[]='egg_brown'; $vReplaceEggArray[]='mysteryeggbrown';
  872. $vSearchEggArray[]='egg_black'; $vReplaceEggArray[]='mysteryeggblack';
  873. $vSearchEggArray[]='egg_gold'; $vReplaceEggArray[]='mysteryegggold';
  874. $vSearchEggArray[]='egg_cornish'; $vReplaceEggArray[]='mysteryeggcornish';
  875. $vSearchEggArray[]='egg_rhodered'; $vReplaceEggArray[]='mysteryeggrhodered';
  876. $vSearchEggArray[]='egg_scotsgrey'; $vReplaceEggArray[]='mysteryeggscotsgrey';
  877. foreach ($sections as $section) {
  878. if (
  879. $section['active']=='1' && $section['place']=='1' && (
  880. ($section['type']=='anim' && $vWhat=='animal' && in_array($o['name'],explode('|',$section['anim'])))
  881. ||
  882. ($section['type']=='tree' && $vWhat=='tree' && in_array($o['name'],explode('|',$section['tree'])))
  883. ||
  884. ($section['type']=='deco' && $vWhat=='decoration' && in_array($o['name'],explode('|',$section['deco'])))
  885. ||
  886. ($section['type']=='deco' && $vWhat=='decoration' && in_array($o['name'],explode('|',str_replace($vSearchEggArray,$vReplaceEggArray,$section['deco']))))
  887. ||
  888. ($section['type']=='building' && $vWhat=='building' && in_array($o['name'],explode('|',$section['building'])))
  889. )
  890. ) {
  891. for($x = $section['bot_x']; $x <= ($section['top_x']-$unit['sizeX']+1);$x++) {
  892. for($y = $section['bot_y']; $y <= ($section['top_y']-$unit['sizeY']+1);$y++) {
  893. $is_available = true;
  894. for ($x2 = 0; $x2 < $unit['sizeX']; $x2++) {
  895. for ($y2 = 0; $y2 < $unit['sizeY']; $y2++) {
  896. if ($locs[$x+$x2][$y+$y2] == false) {
  897. $is_available = false;
  898. }
  899. }
  900. }
  901. if ($is_available) {
  902. return array("x"=>$x,"y"=>$y);
  903. }
  904. }
  905. }
  906. }
  907. }
  908. return false;
  909. }
  910. function Sections_Find_Free_Location_Buy($section, $unit, $locs) {
  911. for($x = $section['bot_x']; $x <= ($section['top_x']-$unit['sizeX']+1);$x++) {
  912. for($y = $section['bot_y']; $y <= ($section['top_y']-$unit['sizeY']+1);$y++) {
  913. $is_available = true;
  914. for ($x2 = 0; $x2 < $unit['sizeX']; $x2++) {
  915. for ($y2 = 0; $y2 < $unit['sizeY']; $y2++) {
  916. if ($locs[$x+$x2][$y+$y2] == false) {
  917. $is_available = false;
  918. }
  919. }
  920. }
  921. if ($is_available) {
  922. return array("x"=>$x,"y"=>$y);
  923. }
  924. }
  925. }
  926. return false;
  927. }
  928. function Sections_plant_sections() {
  929. global $need_reload;
  930. $enable_seed = true;
  931. echo "Sections v",sections_Version," >> plant_sections\r\n";
  932. $sections = load_array('sections.txt');
  933. if (!((is_array($sections) && count($sections)))) { return; }
  934. #return; // uncomment to disable for debug purposes
  935. if ($need_reload) {
  936. $res = DoInit(); //reload farm
  937. $need_reload=false;
  938. }
  939. # $units = @unserialize(file_get_contents(F('units.txt')));
  940. $objects = @unserialize(fBGetDataStore('objects'));
  941. list($level, $gold, $cash, $sizeX, $sizeY, $firstname, $locale, $tileset, $wither, $xp, $energy, $flashRevision) = explode(';', fBGetDataStore('playerinfo'));
  942. // Build matrix so we can know which locations are empty
  943. $location_empty = array();
  944. for ($x = 0; $x < $sizeX; $x++) {
  945. for ($y = 0; $y < $sizeY; $y++) {
  946. $location_empty[$x][$y] = true;
  947. }
  948. }
  949. foreach($objects as $o) {
  950. # $u = $units[$o['itemName']];
  951. $u = Units_GetUnitByName($o['itemName']);
  952. if (!isset($u['sizeX'])) {
  953. $u['sizeX'] = 1;
  954. $u['sizeY'] = 1;
  955. }
  956. if ($o['state'] == 'vertical') {
  957. $t = $u['sizeX'];
  958. $u['sizeX'] = $u['sizeY'];
  959. $u['sizeY'] = $t;
  960. }
  961. for($x=0;$x < $u['sizeX']; $x++) {
  962. for($y=0;$y < $u['sizeY']; $y++) {
  963. $location_empty[ $o['position']['x'] + $x ][ $o['position']['y'] + $y ] = false;
  964. }
  965. }
  966. }
  967. foreach ($sections as $section) {
  968. if ($section['active']=='1' && $section['place']=='1' && $section['type']=='seed') {
  969. $u['sizeX'] = 4;
  970. $u['sizeY'] = 4;
  971. while($newpos = Sections_Find_Free_Location_Buy($section, $u, $location_empty)) {
  972. unset($vPlot);
  973. $vPlot['itemName'] = null;
  974. $vPlot['isProduceItem'] = false;
  975. $vPlot['isBigPlot'] = false;
  976. $vPlot['direction'] = 0;
  977. $vPlot['plantTime'] = 'NaN';
  978. $vPlot['deleted'] = false;
  979. $vPlot['isJumbo'] = false;
  980. $vPlot['state'] = 'plowed';
  981. $vPlot['tempId'] = -1;
  982. $vPlot['id'] = 0;
  983. $vPlot['className'] = 'Plot';
  984. $vPlot['position']['z'] = 0;
  985. $vPlot['position']['x'] = (int)$newpos['x'];
  986. $vPlot['position']['y'] = (int)$newpos['y'];
  987. $tractor_plots[]=$vPlot;
  988. for($x=0;$x < $u['sizeX']; $x++) {
  989. for($y=0;$y < $u['sizeY']; $y++) {
  990. $location_empty[ $newpos['x'] + $x ][ $newpos['y'] + $y ] = false;
  991. }
  992. }
  993. }
  994. }
  995. }
  996. if(isset($tractor_plots) && count($tractor_plots)>0) {
  997. $result = Do_Farm_Work_Plots($tractor_plots, 'tractor');
  998. $need_reload = $need_reload || $result;
  999. }
  1000. // Below mostly copied from parser.php with adaptions
  1001. if ($need_reload) {
  1002. $res = DoInit(); //reload farm
  1003. $need_reload=false;
  1004. }
  1005. if ($enable_seed) {
  1006. $plots = GetObjects('Plot');
  1007. //Find empty plots
  1008. $plowed_plots = array();
  1009. foreach ($plots as $plowed_key => $plot) {
  1010. if ($plot['state'] == 'plowed') {
  1011. $plowed_plots[] = $plot;
  1012. }
  1013. }
  1014. $seed_plots = array();
  1015. foreach ($plowed_plots as $plot) {
  1016. $itemName = "";
  1017. $px = floor($plot['position']['x']/4);
  1018. $py = floor($plot['position']['y']/4);
  1019. $npx = $plot['position']['x'];
  1020. $npy = $plot['position']['y'];
  1021. foreach ($sections as $section) {
  1022. if(
  1023. $section['active']=='1' &&
  1024. ($section['type'] == 'seed') &&
  1025. ($section['seed'] <> 'just_plow') &&
  1026. ($section['seed'] <> '---') &&
  1027. ($npx >= $section['bot_x'] ) &&
  1028. ($npx <= $section['top_x']) &&
  1029. ($npy >= $section['bot_y']) &&
  1030. ($npy <= $section['top_y'])) {
  1031. // found the section
  1032. switch($section['pat']) {
  1033. case 'checkerboard':
  1034. $itemName = ((($px+$py)%2) == 1) ? $section['seed'] : $section['seed2'];
  1035. break;
  1036. case 'striped-row':
  1037. $itemName = ((($py)%2) == 1) ? $section['seed'] : $section['seed2'];
  1038. break;
  1039. case 'striped-col':
  1040. $itemName = ((($px)%2) == 1) ? $section['seed'] : $section['seed2'];
  1041. break;
  1042. case 'squared1':
  1043. $itemName = (((($px)%2) == 1) || ((($py)%2) == 1)) ? $section['seed'] : $section['seed2'];
  1044. break;
  1045. case 'squared2':
  1046. $itemName = (((($px)%2) == 1) || ((($py)%2) == 1)) ? $section['seed'] : $section['seed2'];
  1047. break;
  1048. case 'corner-w':
  1049. $itemName = ((((($px)%2) == 1) && ($px >= $py)) || (((($py)%2) == 1) && ($py >= $px))) ? $section['seed'] : $section['seed2'];
  1050. break;
  1051. case 'corner-e':
  1052. $itemName = ((((($px)%2) == 1) && ($px <= $py)) || (((($py)%2) == 1) && ($py <= $px))) ? $section['seed'] : $section['seed2'];
  1053. break;
  1054. case 'corner-n':
  1055. $sz_x = floor(($section['top_x'] - $section['bot_x'])/4);
  1056. $itemName = ((((($px)%2) == 1) && ($sz_x - $px <= $py)) || (((($py)%2) == 1) && ($py <= $sz_x - $px))) ? $section['seed'] : $section['seed2'];
  1057. break;
  1058. case 'corner-s':
  1059. $sz_x = floor(($section['top_x'] - $section['bot_x'])/4);
  1060. $itemName = ((((($px)%2) == 1) && ($sz_x - $px >= $py)) || (((($py)%2) == 1) && ($py <= $sz_x - $px))) ? $section['seed'] : $section['seed2'];
  1061. break;
  1062. default:
  1063. $itemName = $section['seed'];
  1064. }
  1065. }
  1066. }
  1067. if (strlen($itemName) > 0) {
  1068. $plot['itemName'] = $itemName;
  1069. $seed_plots[] = $plot;
  1070. # } else {
  1071. # echo GetPlotName($plot) . " not in a section.";
  1072. }
  1073. }
  1074. if (count($seed_plots) > 0) {
  1075. Do_Farm_Work_Plots($seed_plots, 'place'); //plant crops
  1076. }
  1077. unset($seed_plots, $plowed_plots);
  1078. }
  1079. }
  1080. function Sections_Draw_Thing($image, $x, $y, $sz_x, $sz_y, $ratio, $fc, $is_section=false) {
  1081. $s_x_horiz = $sz_x * $ratio * 2;
  1082. $s_x_vert = -1 * $sz_x * $ratio;
  1083. $s_y_horiz = $sz_y * $ratio * 2;
  1084. $s_y_vert = -1 * $sz_y * $ratio;
  1085. # $base_x = (107 * $ratio * 2) + (($x - $y) * $ratio * 2);
  1086. # $base_y = (216 * $ratio) - (($x + $y) * $ratio);
  1087. $base_x = (117 * $ratio * 2) + (($x - $y) * $ratio * 2);
  1088. $base_y = (232 * $ratio) - (($x + $y) * $ratio);
  1089. $col_poly = $is_section ? imagecolorallocate($image, 50, 50, 50) : imagecolorallocate($image, 0, 200, 0);
  1090. $col_fill = count($fc) == 3 ? imagecolorallocate($image, $fc[0], $fc[1], $fc[2]) : imagecolorallocatealpha($image, $fc[0], $fc[1], $fc[2], $fc[3]);
  1091. imagefilledpolygon($image, array(
  1092. $base_x , $base_y,
  1093. $base_x + $s_x_horiz , $base_y + $s_x_vert,
  1094. $base_x + $s_x_horiz - $s_y_horiz , $base_y + $s_x_vert + $s_y_vert,
  1095. $base_x - $s_y_horiz , $base_y + $s_y_vert
  1096. ), 4, $col_fill);
  1097. imagepolygon($image, array(
  1098. $base_x , $base_y,
  1099. $base_x + $s_x_horiz , $base_y + $s_x_vert,
  1100. $base_x + $s_x_horiz - $s_y_horiz , $base_y + $s_x_vert + $s_y_vert,
  1101. $base_x - $s_y_horiz , $base_y + $s_y_vert
  1102. ), 4, $col_poly);
  1103. }
  1104. function Sections_Write_Caption($image, $x, $y, $sz_x, $sz_y, $ratio, $text="") {
  1105. $s_x_horiz = $sz_x * $ratio * 2;
  1106. $s_x_vert = -1 * $sz_x * $ratio;
  1107. $s_y_horiz = $sz_y * $ratio * 2;
  1108. $s_y_vert = -1 * $sz_y * $ratio;
  1109. $base_x = (117 * $ratio * 2) + (($x - $y) * $ratio * 2);
  1110. $base_y = (232 * $ratio) - (($x + $y) * $ratio);
  1111. $color = imagecolorallocate($image, 0, 0, 0);
  1112. $font_size=1;
  1113. $text_width = imagefontwidth($font_size) * strlen($text);
  1114. $text_height = imagefontheight($font_size);
  1115. $xpos = $base_x - $s_y_horiz + (.5 * ($s_x_horiz + $s_y_horiz)) - (ceil($text_width/2));
  1116. $ypos = $base_y + (.5 * ($s_x_vert + $s_y_vert)) - (ceil($text_height/2));
  1117. ImageString($image, $font_size, $xpos, $ypos, $text, $color);
  1118. }
  1119. function Sections_Draw_MapThing($x, $y, $sz_x, $sz_y, $ratio, $rest="") {
  1120. $s_x_horiz = $sz_x * $ratio * 2;
  1121. $s_x_vert = -1 * $sz_x * $ratio;
  1122. $s_y_horiz = $sz_y * $ratio * 2;
  1123. $s_y_vert = -1 * $sz_y * $ratio;
  1124. $base_x = (117 * $ratio * 2) + (($x - $y) * $ratio * 2);
  1125. $base_y = (232 * $ratio) - (($x + $y) * $ratio);
  1126. echo "<AREA SHAPE='poly' COORDS='".implode(',',array(
  1127. $base_x , $base_y,
  1128. $base_x + $s_x_horiz , $base_y + $s_x_vert,
  1129. $base_x + $s_x_horiz - $s_y_horiz , $base_y + $s_x_vert + $s_y_vert,
  1130. $base_x - $s_y_horiz , $base_y + $s_y_vert)
  1131. )."' " . $rest . ">\n";
  1132. }
  1133. ?>