-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsettlers.php
More file actions
1783 lines (1631 loc) · 113 KB
/
settlers.php
File metadata and controls
1783 lines (1631 loc) · 113 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
This file is part of STFC.it
Copyright 2008-2013 by Andrea Carolfi (carolfi@stfc.it) and
Cristiano Delogu (delogu@stfc.it).
STFC.it is based on STFC,
Copyright 2006-2007 by Michael Krauss (info@stfc2.de) and Tobias Gafner
STFC is based on STGC,
Copyright 2003-2007 by Florian Brede (florian_brede@hotmail.com) and Philipp Schmidt
STFC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
STFC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//########################################################################################
//########################################################################################
/* 25. June 2008
@Author: Delogu - Carolfi
@Action: Thanks to Delogu they're definitely more active now! ^^
*/
// ########################################################################################
// ########################################################################################
// Startconfig of Settlers
class Settlers extends NPC
{
function refresh_planet_to_serve(&$planet)
{
$planet = $this->db->queryrow('SELECT * FROM planets WHERE planet_id = '.$planet['planet_id']);
}
function delay_activity($planet,$actual)
{
$sql = 'UPDATE planets SET npc_last_action = '.($actual + 20).' WHERE planet_id = '.$planet['planet_id'];
$this->sdl->log('SQL E '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
}
function besty_capital($user_id){
$sql = 'SELECT user_capital from user WHERE user_id = '.$user_id;
$res = $this->db->queryrow($sql);
return $res['user_capital'];
}
function raise_defense($planet,$mood,$actual)
{
global $TECH_DATA, $RACE_DATA;
if($planet['research_3'] >= 9) {
$this->sdl->log('SETL - RAISE_DEFENSE: Defences are already at top!',TICK_LOG_FILE_NPC);
return;
}
if($mood < 4) {
$this->sdl->log('SETL - RAISE_DEFENSE: mood '.$mood.' is too low for raising defences!',TICK_LOG_FILE_NPC);
return;
}
$tech_data = 2;
$sql = 'SELECT COUNT(*) as counter
FROM scheduler_research WHERE planet_id = '.$planet['planet_id'].'
AND research_id = '.$tech_data;
$queue_check=$this->db->queryrow($sql);
if(isset($queue_check['counter']) && $queue_check['counter'] > 0) {
$this->sdl->log('SETL - RAISE_DEFENSE: Defences are already being raised by someone else!',TICK_LOG_FILE_NPC);
return;
}
$tech_reward = array(5,7,7,7,10,10,10,12,12);
$time=0;
$time=$TECH_DATA[$tech_data][3]+ pow($planet['research_'.($tech_data+1)],$TECH_DATA[$tech_data][4]);
$time*=$RACE_DATA[13][4]; // Settlers Race is 13
$time/=100;
$time*=(100-2*($planet['research_4']*$RACE_DATA[13][20])); // Settlers Race is 13
if ($time<1) $time=1;
$time=round($time,0);
$sql = 'INSERT INTO scheduler_research (research_id,planet_id,player_id,research_finish,research_start)
VALUES ("'.$tech_data.'","'.$planet['planet_id'].'","'.INDEPENDENT_USERID.'","'.($actual+$time).'","'.$actual.'")';
if(!$this->db->query($sql)) {
$this->sdl->log('SETL - RAISE_DEFENSE: Could not write research record for settlers research!'.$sql,TICK_LOG_FILE_NPC);
return;
}
$tech_value = $tech_reward[$planet['research_'.($tech_data+1)]];
$sql='INSERT INTO settlers_relations SET planet_id = '.$planet['planet_id'].', user_id = '.INDEPENDENT_USERID.',timestamp = '.time().',log_code = '.LC_SUP_DFNS.', mood_modifier = '.$tech_value;
if(!$this->db->query($sql)) {
$this->sdl->log('SETL - RAISE_DEFENSE: Could not write relation record for settlers research!'.$sql,TICK_LOG_FILE_NPC);
}
}
function ferengi_presidio($planet_id, $user_id=0) {
if($user_id === 0) {return false;}
$sql = 'SELECT timestamp FROM settlers_events WHERE event_code = 124 AND event_status = 0 AND user_id = '.$user_id.' AND planet_id = '.$planet_id;
$res = $this->db->queryrow($sql);
if($this->db->num_rows() > 0) {return true;}
return false;
}
function ferengi_delegatio($planet_id,$user_id=0) {
$sql = 'SELECT user_id FROM settlers_events WHERE event_code = 124 AND event_status = 0 AND user_id = '.$user_id.' AND planet_id = '.$planet_id;
$res = $this->db->queryrow($sql);
if($this->db->num_rows() > 0) {return true;}
return -1;
}
function orbital_rebalance($planet_id, $num) {
$sql = 'SELECT user_id, mood_modifier FROM settlers_relations WHERE planet_id = '.$planet_id.' AND log_code = '.LC_MIL_ORBITAL;
$res = $this->db->queryrowset($sql);
foreach ($res AS $res_item) {
$defender_list[$res_item['user_id']] = array('mood_modifier' => $res_item['mood_modifier'], 'hits' => 0);
$this->sdl->log('SETL - ORBITAL REBALANCE - User '.$res_item['user_id'].' has '.$res_item['mood_modifier'].' orbitals', TICK_LOG_FILE_NPC);
}
if($this->db->num_rows() > 0) {
foreach($defender_list as $defender_id => $defender_item) {
$this->sdl->log('SETL - ORBITAL REBALANCE - User '.$defender_id.' has a mood modifier of '.$defender_item['mood_modifier'].' and # of hits of '.$defender_item['hits'], TICK_LOG_FILE_NPC);
for($i = 0; $i < $defender_item['mood_modifier']; $i++) {
$hits_array[] = array($defender_id, 0);
}
}
$i = 0;
while($i < $num) {
shuffle($hits_array);
if($hits_array[$i][1] == 0) {
$hits_array[$i][1] = 1;
$defender_list[$hits_array[$i][0]]['hits']++;
$i++;
}
}
foreach ($defender_list as $defender_id => $defender_item) {
if($defender_item['hits'] == 0) continue;
$sql = 'UPDATE settlers_relations SET mood_modifier = '.($defender_item['mood_modifier'] - $defender_item['hits']).' WHERE planet_id = '.$planet_id.' AND user_id = '.$defender_id.' AND log_code = '.LC_MIL_ORBITAL;
$this->db->query($sql);
$this->sdl->log('SETL - ORBITAL REBALANCE - User '.$defender_id.' has a new value of '.($defender_item['mood_modifier'] - $defender_item['hits']).' orbitals', TICK_LOG_FILE_NPC);
}
}
else {
$sql = 'UPDATE settlers_relations SET mood_modifier = '.($res[0]['mood_modifier'] - $num).' WHERE planet_id = '.$planet_id.' AND user_id = '.$res[0]['user_id'].' AND log_code = '.LC_MIL_ORBITAL;
$this->db->query($sql);
$this->sdl->log('SETL - ORBITAL REBALANCE - User '.$res[0]['user_id'].' has a new value of '.($res[0]['mood_modifier'] - $num).' orbitals', TICK_LOG_FILE_NPC);
}
return;
}
public function Install($log = INSTALL_LOG_FILE_NPC)
{
$this->sdl->start_job('Mayflower basic system', $log);
// We give the bot some data so that it is also Registered
$this->bot = $this->db->queryrow('SELECT * FROM user WHERE user_id = '.INDEPENDENT_USERID);
//Check whether the bot already lives
if(empty($this->bot['user_id'])) {
$this->sdl->log('We need to create TheSettlers!', $log);
$sql = 'INSERT INTO user (user_id, user_auth_level, user_name, user_loginname, user_password,
user_email, user_active, user_race, user_gfxpath, user_skinpath,
user_registration_time, user_registration_ip,
user_birthday, user_gender, plz, country, user_enable_sig,
user_message_sig, user_signature, user_notepad, user_options, message_basement)
VALUES ('.INDEPENDENT_USERID.', '.STGC_BOT.', "Coloni(NPC)", "SettlersBot", "'.md5("settlers").'",
"settlers@stfc.it", 1, 13, "'.DEFAULT_GFX_PATH.'", "skin1/", '.time().', "127.0.0.1",
"25.06.2008", "", 16162 , "IT", 1,
"", "", "", "", "")';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not create TheSettlers - ABORTED', $log);
}
}
//Check for Settlers cargo ship definition
$settler_ship_id = $this->db->queryrow('SELECT settler_tmp_1 FROM config WHERE config_set_id = 0');
if(empty($settler_ship_id['settler_tmp_1'])) {
$this->sdl->log('Writing Settler Cargo Ship!', $log);
$sql = 'INSERT INTO ship_templates (owner, timestamp, name, description, race, ship_torso, ship_class,
component_1, component_2, component_3, component_4, component_5,
component_6, component_7, component_8, component_9, component_10,
value_1, value_2, value_3, value_4, value_5,
value_6, value_7, value_8, value_9, value_10,
value_11, value_12, value_13, value_14, value_15,
resource_1, resource_2, resource_3, resource_4, unit_5, unit_6,
min_unit_1, min_unit_2, min_unit_3, min_unit_4,
max_unit_1, max_unit_2, max_unit_3, max_unit_4,
buildtime, rof, rof2, max_torp)
VALUES ("'.INDEPENDENT_USERID.'","'.time().'","Transporter","Settlers Cargo",13,1,0,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"15","0","0","5","20",
"2","1","5","5","3.4",
"5","0","10","4","0",
"4250","5800","4640","105","2","1",
"56","0","0","1",
"56","0","0","1",
720, 1, 0, 0)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not create TheSettlers - ABORTED', $log);
}
$template_id = $this->db->insert_id();
$sql = 'UPDATE config SET settler_tmp_1 = '.$template_id.' WHERE config_set_id = 0';
$this->db->query($sql);
}
//Check for Settlers cruiser ship definition
$settler_ship_id = (int)$this->db->queryrow('SELECT settler_tmp_2 FROM config WHERE config_set_id = 0');
if(empty($settler_ship_id['settler_tmp_2'])) {
$this->sdl->log('Writing Settler Cruiser Ship!', $log);
$sql = 'INSERT INTO ship_templates (owner, timestamp, name, description, race, ship_torso, ship_class,
component_1, component_2, component_3, component_4, component_5,
component_6, component_7, component_8, component_9, component_10,
value_1, value_2, value_3, value_4, value_5,
value_6, value_7, value_8, value_9, value_10,
value_11, value_12, value_13, value_14, value_15,
resource_1, resource_2, resource_3, resource_4, unit_5, unit_6,
min_unit_1, min_unit_2, min_unit_3, min_unit_4,
max_unit_1, max_unit_2, max_unit_3, max_unit_4,
buildtime, rof, rof2, max_torp)
VALUES ("'.INDEPENDENT_USERID.'","'.time().'","Centaur","Settlers Cruiser",13,7,2,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"100","200","16","476","665",
"6","12","26","1","6.5",
"34","0","160","140","0",
"54929","54929","43719","1121","15","4",
"100","0","0","2",
"120","20","20","4",
1121, 6, 4, 85)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not create TheSettlers - ABORTED', $log);
}
$template_id = $this->db->insert_id();
$sql = 'UPDATE config SET settler_tmp_2 = '.$template_id.' WHERE config_set_id = 0';
$this->db->query($sql);
}
//Check for Settlers battleship ship definition
$settler_ship_id = (int)$this->db->queryrow('SELECT settler_tmp_3 FROM config WHERE config_set_id = 0');
if(empty($settler_ship_id['settler_tmp_3'])) {
$this->sdl->log('Writing Settler Heavy Cruiser!', $log);
$sql = 'INSERT INTO ship_templates (owner, timestamp, name, description, race, ship_torso, ship_class,
component_1, component_2, component_3, component_4, component_5,
component_6, component_7, component_8, component_9, component_10,
value_1, value_2, value_3, value_4, value_5,
value_6, value_7, value_8, value_9, value_10,
value_11, value_12, value_13, value_14, value_15,
resource_1, resource_2, resource_3, resource_4, unit_5, unit_6,
min_unit_1, min_unit_2, min_unit_3, min_unit_4,
max_unit_1, max_unit_2, max_unit_3, max_unit_4,
buildtime, rof, rof2, max_torp)
VALUES ("'.INDEPENDENT_USERID.'","'.time().'","Achilles","Settlers Battleship",13,9,3,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"100","210","100","1535","1720",
"6","14","16","1","6.5",
"30","0","180","160","0",
"123872","123872","98592","2528","20","8",
"150","0","0","3",
"170","15","20","5",
2528, 15, 8, 250)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not create TheSettlers - ABORTED', $log);
}
$template_id = $this->db->insert_id();
$sql = 'UPDATE config SET settler_tmp_3 = '.$template_id.' WHERE config_set_id = 0';
$this->db->query($sql);
}
//Check for Settlers Orbital Cannon definition
$settler_ship_id = (int)$this->db->queryrow('SELECT settler_tmp_4 FROM config WHERE config_set_id = 0');
if(empty($settler_ship_id['settler_tmp_4'])) {
$this->sdl->log('Writing Settler Orbital!', $log);
$sql = 'INSERT INTO ship_templates (owner, timestamp, name, description, race, ship_torso, ship_class,
component_1, component_2, component_3, component_4, component_5,
component_6, component_7, component_8, component_9, component_10,
value_1, value_2, value_3, value_4, value_5,
value_6, value_7, value_8, value_9, value_10,
value_11, value_12, value_13, value_14, value_15,
resource_1, resource_2, resource_3, resource_4, unit_5, unit_6,
min_unit_1, min_unit_2, min_unit_3, min_unit_4,
max_unit_1, max_unit_2, max_unit_3, max_unit_4,
buildtime, rof, max_torp)
VALUES ("'.INDEPENDENT_USERID.'","'.time().'","Orbitaler","Settlers PlanetaryShield",13,12,3,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"750","750","0","1000","100",
"35","25","0","0","0",
"35","0","33","33","0",
"50400","50400","40320","500","0","0",
"0","0","0","0",
"0","0","0","0",
480, 3, 400)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not create TheSettlers - ABORTED', $log);
}
$template_id = $this->db->insert_id();
$sql = 'UPDATE config SET settler_tmp_4 = '.$template_id.' WHERE config_set_id = 0';
$this->db->query($sql);
}
$this->sdl->finish_job('Mayflower basic system', $log);
}
public function Execute($debug=0)
{
global $ACTUAL_TICK,$cfg_data,$RACE_DATA, $ACADEMY_MAJOR_LIST, $ACADEMY_MINOR_LIST, $MINE_MAJOR_LIST, $MINE_MINOR_LIST;
$starttime = ( microtime() + time() );
$this->sdl->log('<br><b>-------------------------------------------------------------</b><br>'.
'<b>Starting Settlers Bot Scheduler at '.date('d.m.y H:i:s', time()).'</b>', TICK_LOG_FILE_NPC);
// Update BOT user ID
$this->bot['user_id'] = INDEPENDENT_USERID;
// ########################################################################################
// ########################################################################################
// Messages answer
$messages=array('Bot system.','Bot system.','Se desiderate avere contatti con noi, dovrete scendere direttamente su uno dei nostri pianeti.<br><br>A presto.');
$titles=array('--','--','Grazie per averci contattato.');
$this->ReplyToUser($titles,$messages);
// ########################################################################################
// ########################################################################################
// Read Logbook
$this->ReadLogbook();
// ########################################################################################
// ########################################################################################
// Ok, only three (3) Settlers' planets per run are going to wake up. More planets means more overhead.
$this->sdl->start_job('Mayflower Parliament Session', TICK_LOG_FILE_NPC);
$sql = 'SELECT user_id, COUNT(planet_id) AS planets_taken FROM settlers_relations WHERE log_code = 34 GROUP BY user_id';
if($res = $this->db->queryrowset($sql)) {
foreach($res AS $criminal){
if($criminal['planets_taken'] > 4) {
$sql = 'SELECT uf_id FROM user_felony WHERE user1_id = '.INDEPENDENT_USERID.' AND user2_id = '.$criminal['user_id'];
$ud_exists = $this->db->queryrow($sql);
if(!isset($ud_exists['uf_id']) || empty($ud_exists['uf_id'])) {
$sql = 'INSERT INTO user_felony SET user1_id = '.INDEPENDENT_USERID.', user2_id = '.$criminal['user_id'].', date = '.time();
$this->sdl->log('SQL P.1 '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
}
}
}
}
$this->sdl->finish_job('Mayflower Parliament Session', TICK_LOG_FILE_NPC);
$this->sdl->start_job('Mayflower Planets Building Control', TICK_LOG_FILE_NPC);
$sql='SELECT * FROM planets WHERE planet_owner = '.INDEPENDENT_USERID.' AND npc_last_action < '.$ACTUAL_TICK.' ORDER BY npc_last_action ASC LIMIT 0, 3';
if(($setpoint = $this->db->query($sql)) === false)
{
$this->sdl->log('<b>Error:</b> Bot: Could not read planets DB', TICK_LOG_FILE_NPC);
}
else
{
$_already_done = false;
while($planet_to_serve = $this->db->fetchrow($setpoint))
{
$future_lvl = [0,0,0,0,0,0,0,0,0,0,0,0,0];
$sched_build = $this->db->queryrowset('SELECT installation_type FROM scheduler_instbuild WHERE planet_id = '.$planet_to_serve['planet_id']);
foreach ($sched_build AS $sched_item) {
$future_lvl[$sched_item['installation_type']]++;
}
if(($planet_to_serve['building_1'] + $future_lvl[0]) < 9)
{
/*
$sql = 'UPDATE planets SET building_1 = 9, npc_last_action = '.$ACTUAL_TICK.' WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 1.1 '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*
*/
$res = $this->StartBuild($ACTUAL_TICK,0,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
}
/*
if($planet_to_serve['building_5'] < 6)
{
---
$sql = 'UPDATE planets SET building_5 = 6, npc_last_action = '.$ACTUAL_TICK.' WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 1'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
---
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {continue;}
}
*
*/
if(($planet_to_serve['building_2'] + $future_lvl[1]) < 9)
{
/*
$sql = 'UPDATE planets SET building_2 = 9, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 1.2'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*
*/
$res = $this->StartBuild($ACTUAL_TICK,1,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
}
if(($planet_to_serve['building_3'] + $future_lvl[2]) < 9)
{
/*
$sql = 'UPDATE planets SET building_3 = 9, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 1.3'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*
*/
$res = $this->StartBuild($ACTUAL_TICK,2,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
}
if(($planet_to_serve['building_4'] + $future_lvl[3]) < 9)
{
/*
$sql = 'UPDATE planets SET building_4 = 9, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 1.4'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*
*/
$res = $this->StartBuild($ACTUAL_TICK,3,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
}
if(($planet_to_serve['building_12'] + $future_lvl[11]) < 9)
{
/*
$sql = 'UPDATE planets SET building_12 = 9, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 1.12'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*
*/
$res = $this->StartBuild($ACTUAL_TICK,11,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
}
// At this point, having rebuilt HQ and mines, Settlers automatically gains level 9 Academy.
if(($planet_to_serve['building_6'] + $future_lvl[5]) < 9)
{
/*
$sql = 'UPDATE planets SET building_6 = 9, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 2'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*
*/
$res = $this->StartBuild($ACTUAL_TICK,5,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
}
// Now the Spacedock
if(($planet_to_serve['building_7'] + $future_lvl[6]) < 3)
{
$res = $this->StartBuild($ACTUAL_TICK,6,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
/*
$sql = 'UPDATE planets SET building_7 = 3, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 3'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
*
*/
}
// Now the Spaceyard
if(($planet_to_serve['building_8'] + $future_lvl[7]) < 1)
{
$res = $this->StartBuild($ACTUAL_TICK,7,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
continue;
}
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
/*
$sql = 'UPDATE planets SET building_8 = 1, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 4'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
*
*/
}
// Light orbital defense
if((($planet_to_serve['building_10'] + $future_lvl[9] + $planet_to_serve['research_3']) < (14 + $planet_to_serve['research_3'])) && $planet_to_serve['npc_next_delivery'] > $ACTUAL_TICK)
{
$res = $this->StartBuild($ACTUAL_TICK,9,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
$this->refresh_planet_to_serve($planet_to_serve);
}
/*
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
*
*/
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
/*
$sql = 'UPDATE planets SET building_10 = '.(14 + $planet_to_serve['research_3']).', npc_last_action = '.($ACTUAL_TICK + 10).', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 5'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*/
}
// Heavy orbital defense
if((($planet_to_serve['building_13'] + $future_lvl[12] + $planet_to_serve['research_3']) < (14 + $planet_to_serve['research_3'])) && $planet_to_serve['npc_next_delivery'] > $ACTUAL_TICK)
{
$res = $this->StartBuild($ACTUAL_TICK,12,$planet_to_serve);
if($res == BUILD_ERR_ENERGY) {
$res = $this->StartBuild($ACTUAL_TICK,4,$planet_to_serve);
$this->refresh_planet_to_serve($planet_to_serve);
}
/*
elseif($res == BUILD_ERR_QUEUE || $res == BUILD_ERR_RESOURCES) {
$this->delay_activity($planet_to_serve,$ACTUAL_TICK);
continue;
}
*
*/
elseif($res == BUILD_SUCCESS) {
$this->refresh_planet_to_serve($planet_to_serve);
}
/*
$sql = 'UPDATE planets SET building_13 = '.(14 + $planet_to_serve['research_3']).', npc_last_action = '.($ACTUAL_TICK + 30).', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 6'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
*/
}
// orbital_fleet_id = id from ship_fleets of orbital gun fleets defending planet; -1 = no fleet
// orbital_num = number of orbital gun in the fleet
// orbital_by_player = number of existing guns made by players
$sql='SELECT fleet_id FROM ship_fleets WHERE fleet_name LIKE "Orbital'.$planet_to_serve['planet_id'].'"';
$od_q = $this->db->queryrow($sql);
if(isset($od_q['fleet_id']) && !empty($od_q['fleet_id'])) {
$planet_to_serve['orbital_fleet_id'] = $od_q['fleet_id'];
$sql='SELECT COUNT(*) AS counter FROM ships WHERE fleet_id = '.$planet_to_serve['orbital_fleet_id'];
$res=$this->db->queryrow($sql);
$planet_to_serve['orbital_num'] = $res['counter'];
$sql='SELECT SUM(mood_modifier) AS counter FROM settlers_relations WHERE planet_id = '.$planet_to_serve['planet_id'].' AND log_code = '.LC_MIL_ORBITAL;
$res=$this->db->queryrow($sql);
$planet_to_serve['orbital_by_player'] = $res['counter'];
if($planet_to_serve['orbital_by_player'] > $planet_to_serve['orbital_num']) {
$this->sdl->log('orbital fleet id = '.$planet_to_serve['orbital_fleet_id'].', orbital num = '.$planet_to_serve['orbital_num'].', orbital_by_player = '.$planet_to_serve['orbital_by_player'],TICK_LOG_FILE_NPC);
$this->sdl->log('Call orbital_rebalance for planet '.$planet_to_serve['planet_id'].' with a num of '.($planet_to_serve['orbital_by_player'] - $planet_to_serve['orbital_num']),TICK_LOG_FILE_NPC);
$this->orbital_rebalance($planet_to_serve['planet_id'], ($planet_to_serve['orbital_by_player'] - $planet_to_serve['orbital_num']));
$this->sdl->log('Back from orbital_rebalance for planet '.$planet_to_serve['planet_id'],TICK_LOG_FILE_NPC);
}
}
else {
$planet_to_serve['orbital_fleet_id'] = 0;
$planet_to_serve['orbital_num'] = 0;
$planet_to_serve['orbital_by_player'] = 0;
}
// Are there enough workers in the mines?
if($planet_to_serve['workermine_1'] < 1000 || $planet_to_serve['workermine_2'] < 1000 || $planet_to_serve['workermine_3'] < 1000)
{
$sql = 'UPDATE planets SET workermine_1 = 1000, workermine_2 = 1000, workermine_3 = 1000, npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 7'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
}
// Are there enough security troops?
$troops_check = ($planet_to_serve['unit_1']*2) + ($planet_to_serve['unit_2']*3) + ($planet_to_serve['unit_3']*4) + ($planet_to_serve['unit_4']*4);
$troops_to_train = $planet_to_serve['min_security_troops'] - $troops_check;
$modulo = $troops_to_train % 4;
$unit3_to_train = $unit2_to_remove = $unit1_to_remove= 0;
if($modulo == 0) {
$unit3_to_train = $troops_to_train / 4;
$unit2_to_remove = 0;
$unit1_to_remove = 0;
}
elseif ($planet_to_serve['unit_2'] > 0 && (($planet_to_serve['unit_2']*3) % 4) != 0) {
$unit3_to_train = round($troops_to_train / 4) + 1;
$unit2_to_remove = 1;
$unit1_to_remove = 0;
}
elseif ($planet_to_serve['unit_1'] > 0 && (($planet_to_serve['unit_1']*2) % 4) != 0) {
$unit3_to_train = round($troops_to_train / 4) + 1;
$unit2_to_remove = 0;
$unit1_to_remove = 1;
}
else {
$unit3_to_train = round($troops_to_train / 4);
}
if($troops_to_train > 0)
{
$sql = 'UPDATE planets SET unit_1 = unit_1 - '.$unit1_to_remove.', unit_2 = unit_2 - '.$unit2_to_remove.', unit_3 = unit_3 + '.$unit3_to_train.', npc_last_action = '.$ACTUAL_TICK.', recompute_static = 1 WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL 7.1'.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
}
// Settlers looking for their own autonomy!!!
if($planet_to_serve['best_mood_user'] != INDEPENDENT_USERID) {
$sql = 'SELECT log_code, SUM(mood_modifier) as mood_value FROM settlers_relations WHERE planet_id = '.$planet_to_serve['planet_id'].' AND user_id = '.INDEPENDENT_USERID.' GROUP BY log_code';
$q_s_m = $this->db->queryrowset($sql);
$autonomy_basevalue = $autonomy_terror = $autonomy_dissent = $autonomy_crime = $autonomy_survival = $autonomy_welfare = $autonomy_egemony = $autonomy_tecnology = $autonomy_autharchy = 0;
foreach ($q_s_m AS $q_s_item) {
switch ($q_s_item['log_code']) {
case 28:
$autonomy_terror = $q_s_item['mood_value'];
break;
case 29:
$autonomy_dissent = $q_s_item['mood_value'];
break;
case 35:
$autonomy_crime = $q_s_item['mood_value'];
break;
case 100:
$autonomy_basevalue = $q_s_item['mood_value'];
break;
case 101:
$autonomy_survival = $q_s_item['mood_value'];
break;
case 102:
$autonomy_welfare = $q_s_item['mood_value'];
break;
case 103:
$autonomy_egemony = $q_s_item['mood_value'];
break;
case 104:
$autonomy_tecnology = $q_s_item['mood_value'];
break;
case 105:
$autonomy_autharchy = $q_s_item['mood_value'];
break;
}
}
$autonomy_modifier = 1 + ($autonomy_basevalue - $autonomy_terror) +
(4 * $planet_to_serve['research_1'] - $autonomy_crime) +
(4 * $planet_to_serve['research_2'] - $autonomy_crime) +
(4 * $planet_to_serve['research_3'] - ($autonomy_crime/4)) +
(4 * $planet_to_serve['research_4'] - ($autonomy_crime/2) - $autonomy_dissent) +
(4 * $planet_to_serve['research_5'] - $autonomy_crime);
$this->sdl->log('Autonomy modifier planet '.$planet_to_serve['planet_id'].' = '.$autonomy_modifier, TICK_LOG_FILE_NPC);
$autonomy_check = rand(1,720) + $autonomy_modifier;
if ($autonomy_check >= 720) {
$this->sdl->log('Autonomy strike!!! value = '.$autonomy_check, TICK_LOG_FILE_NPC);
$settlers_autonomy_chance_array = array (
'autonomy' => 20,
'survival' => ($autonomy_survival == 64 ? 0 : 15 + (5 + $planet_to_serve['research_1'])),
'welfare' => ($autonomy_welfare == 64 ? 0 : 15 + (5 + $planet_to_serve['research_2'])),
'egemony' => 20,
'tecnology' => ($autonomy_tecnology == 64 ? 0 : 15 + (5 + $planet_to_serve['research_4'])),
'autharchy' => ($autonomy_autharchy == 64 ? 0 : 15 + (5 + $planet_to_serve['research_5']))
);
$mood_bonus = array(0,0,0,0,0,0,1,2,4);
$autonomy_array = array();
foreach($settlers_autonomy_chance_array as $event => $probability) {
for($i = 0; $i < $probability; ++$i) {
$autonomy_array[] = $event;
}
}
$autonomy_event = $autonomy_array[array_rand($autonomy_array)];
switch ($autonomy_event) {
case 'autonomy':
$log_code = 100;
$mood_actual = $autonomy_basevalue;
$this->raise_defense($planet_to_serve,($mood_actual+1),$ACTUAL_TICK);
break;
case 'survival':
$log_code = 101;
$mood_actual = $autonomy_survival;
$mood_modifier = $mood_bonus[$planet_to_serve['research_1']];
break;
case 'welfare':
$log_code = 102;
$mood_actual = $autonomy_welfare;
$mood_modifier = $mood_bonus[$planet_to_serve['research_2']];
break;
case 'egemony':
$log_code = 103;
$mood_actual = $autonomy_egemony;
$mood_modifier = $mood_bonus[$planet_to_serve['research_3']];
break;
case 'tecnology':
$log_code = 104;
$mood_actual = $autonomy_tecnology;
$mood_modifier = $mood_bonus[$planet_to_serve['research_4']];
break;
case 'autharchy':
$log_code = 105;
$mood_actual = $autonomy_autharchy;
$mood_modifier = $mood_bonus[$planet_to_serve['research_5']];
break;
default :
$this->sdl->log('Autonomy event anomaly = '.$autonomy_event, TICK_LOG_FILE_NPC);
break;
}
if($mood_actual == 0) {
$sql='INSERT INTO settlers_relations SET planet_id = '.$planet_to_serve['planet_id'].', user_id = '.INDEPENDENT_USERID.',timestamp = '.time().',log_code = '.$log_code.', mood_modifier = 1';
}
else {
$new_mood = min(($log_code == 100 ? 80 : 64), (1 + $mood_actual + $mood_modifier));
$sql='UPDATE settlers_relations SET mood_modifier = '.$new_mood.', timestamp = '.time().'
WHERE planet_id = '.$planet_to_serve['planet_id'].' AND user_id = '.INDEPENDENT_USERID.' AND log_code = '.$log_code;
}
$this->sdl->log('SQL 8 '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
}
}
else
{
$this->sdl->log('DEBUG: planet '.$planet_to_serve['planet_id'].' skip independency phase.', TICK_LOG_FILE_NPC);
}
// Check for best mood user felony
$sql = 'SELECT date FROM user_felony WHERE user1_id = '.INDEPENDENT_USERID.' AND user2_id = '.$planet_to_serve['best_mood_user'];
$res = $this->db->queryrow($sql);
if(isset($res['date'])) {
$sql = 'DELETE FROM settlers_relations WHERE planet_id = '.$planet_to_serve['planet_id'].' AND user_id = '.$planet_to_serve['best_mood_user'];
$this->db->query($sql);
}
// Check for best mood!!!
$sql = 'SELECT user_id, SUM(mood_modifier) AS mood FROM settlers_relations
WHERE planet_id = '.$planet_to_serve['planet_id'].' GROUP BY user_id ORDER BY timestamp ASC';
$q_p_m = $this->db->queryrowset($sql);
// $this->sdl->log('DEBUG CHECK MOOD A'.$planet_to_serve['best_mood'].' '.$planet_to_serve['best_mood_user'], TICK_LOG_FILE_NPC);
$best = -1000;
$best_id = 0;
$newbest = false;
foreach($q_p_m as $q_m) {
if($q_m['mood'] > 0 && $q_m['mood'] > $best) {
$newbest = true;
$best = $q_m['mood'];
$best_id = $q_m['user_id'];
}
}
if($newbest) {
$sql = 'UPDATE planets SET best_mood = '.$best.', best_mood_user = '.$best_id.' WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->db->query($sql);
}
// $this->sdl->log('DEBUG CHECK MOOD B '.$best.' '.$best_id, TICK_LOG_FILE_NPC);
if($best_id != $planet_to_serve['best_mood_user'])
{
if($planet_to_serve['best_mood_alert']) {
$log_data = array($planet_to_serve['planet_id'],$planet_to_serve['planet_name'], 0, '', 100);
add_logbook_entry($planet_to_serve['best_mood_user'], LOGBOOK_SETTLERS, 'Comunicazione prioritaria dalla colonia '.$planet_to_serve['planet_name'], $log_data);
}
$planet_to_serve['best_mood'] = $best;
$planet_to_serve['best_mood_user'] = $best_id;
$planet_to_serve['best_mood_alert'] = false;
$this->db->query('UPDATE planets SET best_mood_alert = FALSE, best_mood_planet = NULL WHERE planet_id = '.$planet_to_serve['planet_id']);
}
// Let's activate the Academy! Sadly, we have to set ALL the fields for clearing them
if($planet_to_serve['unittrain_actual'] == 0 && in_array($planet_to_serve['planet_type'], $ACADEMY_MAJOR_LIST))
{
if($troops_to_train < 1) $troops_to_train = 0;
$sql = 'UPDATE planets SET unittrainid_1 = 5, unittrainid_2 = 6,
unittrainid_3 = 0, unittrainid_4 = 0,
unittrainid_5 = 0, unittrainid_6 = 0,
unittrainid_7 = 0, unittrainid_8 = 0,
unittrainid_9 = 0, unittrainid_10 = 0,
unittrainnumber_1 = 3, unittrainnumber_2 = 1,
unittrainnumber_3 = 0, unittrainnumber_4 = 0,
unittrainnumber_5 = 0, unittrainnumber_6 = 0,
unittrainnumber_7 = 0, unittrainnumber_8 = 0,
unittrainnumber_9 = 0, unittrainnumber_10 = 0,
unittrainnumberleft_1 = 3, unittrainnumberleft_2 = 1,
unittrainnumberleft_3 = 0, unittrainnumberleft_4 = 0,
unittrainnumberleft_5 = 0, unittrainnumberleft_6 = 0,
unittrainnumberleft_7 = 0, unittrainnumberleft_8 = 0,
unittrainnumberleft_9 = 0, unittrainnumberleft_10 = 0,
unittrainendless_1 = 1, unittrainendless_2 = 1,
unittrainendless_3 = 0, unittrainendless_4 = 0,
unittrainendless_5 = 0, unittrainendless_6 = 0,
unittrainendless_7 = 0, unittrainendless_8 = 0,
unittrainendless_9 = 0, unittrainendless_10 = 0,
unittrain_actual = 1, unittrainid_nexttime = '.($ACTUAL_TICK + 2).',
npc_last_action = '.$ACTUAL_TICK.'
WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL A - 1A '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
}
if($planet_to_serve['unittrain_actual'] == 0 && in_array($planet_to_serve['planet_type'], $ACADEMY_MINOR_LIST))
{
if($troops_to_train < 1) $troops_to_train = 0;
$sql = 'UPDATE planets SET unittrainid_1 = 1, unittrainid_2 = 2,
unittrainid_3 = 0, unittrainid_4 = 0,
unittrainid_5 = 0, unittrainid_6 = 0,
unittrainid_7 = 0, unittrainid_8 = 0,
unittrainid_9 = 0, unittrainid_10 = 0,
unittrainnumber_1 = 2, unittrainnumber_2 = 1,
unittrainnumber_3 = 0, unittrainnumber_4 = 0,
unittrainnumber_5 = 0, unittrainnumber_6 = 0,
unittrainnumber_7 = 0, unittrainnumber_8 = 0,
unittrainnumber_9 = 0, unittrainnumber_10 = 0,
unittrainnumberleft_1 = 2, unittrainnumberleft_2 = 1,
unittrainnumberleft_3 = 0, unittrainnumberleft_4 = 0,
unittrainnumberleft_5 = 0, unittrainnumberleft_6 = 0,
unittrainnumberleft_7 = 0, unittrainnumberleft_8 = 0,
unittrainnumberleft_9 = 0, unittrainnumberleft_10 = 0,
unittrainendless_1 = 1, unittrainendless_2 = 1,
unittrainendless_3 = 0, unittrainendless_4 = 0,
unittrainendless_5 = 0, unittrainendless_6 = 0,
unittrainendless_7 = 0, unittrainendless_8 = 0,
unittrainendless_9 = 0, unittrainendless_10 = 0,
unittrain_actual = 1, unittrainid_nexttime = '.($ACTUAL_TICK + 2).',
npc_last_action = '.$ACTUAL_TICK.'
WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL A - 1B '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
}
// A - 6
// Settlers get back a ship from unsuccesful auction.
$sql='SELECT ship_id FROM FHB_warteschlange WHERE user_id = '.INDEPENDENT_USERID.' LIMIT 0,1';
$notpayed=$this->db->queryrow($sql);
if(isset($notpayed['ship_id']) && !empty($notpayed['ship_id']))
{
$sql='DELETE FROM FHB_warteschlange WHERE ship_id = '.$notpayed['ship_id'];
$this->sdl->log('SQL A - 6A '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
$sql='UPDATE ships SET user_id = '.INDEPENDENT_USERID.', fleet_id = -'.$planet_to_serve['planet_id'].' WHERE ship_id = '.$notpayed['ship_id'];
$this->sdl->log('SQL A - 6B '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
$sql = 'UPDATE planets SET npc_last_action = '.($ACTUAL_TICK + 20).' WHERE planet_id = '.$planet_to_serve['planet_id'];
$this->sdl->log('SQL A - 6C '.$sql, TICK_LOG_FILE_NPC);
$this->db->query($sql);
continue;
}
if($planet_to_serve['best_mood_user'] == INDEPENDENT_USERID) {
$this->sdl->log('DEBUG: planet '.$planet_to_serve['planet_id'].' is truly independent!', TICK_LOG_FILE_NPC);
$sql = 'SELECT event_status
FROM (settlers_relations sr)
LEFT JOIN (settlers_events se) ON (sr.planet_id = se.planet_id AND sr.user_id = se.user_id)
WHERE sr.planet_id = '.$planet_to_serve['planet_id'].' AND
sr.log_code = 1 AND
sr.user_id = '.ORION_USERID;
$res = $this->db->queryrow($sql);
if($res['event_status'] == 1){
$sql = 'SELECT log_code, SUM(mood_modifier) as mood_value FROM settlers_relations WHERE planet_id = '.$planet_to_serve['planet_id'].' AND user_id = '.ORION_USERID.' GROUP BY log_code';
$q_s_m = $this->db->queryrowset($sql);
$orion_basevalue = $orion_terror = $orion_survival = $orion_support = $orion_tactics = $orion_intel = $orion_resources = 0;
foreach ($q_s_m AS $q_s_item) {
switch ($q_s_item['log_code']) {
case 28:
$orion_terror = $q_s_item['mood_value'];
break;
case 106: