forked from stfc2/Scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
borg.php
1511 lines (1318 loc) · 70.4 KB
/
borg.php
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 ([email protected]) and
Cristiano Delogu ([email protected]).
STFC.it is based on STFC,
Copyright 2006-2007 by Michael Krauss ([email protected]) and Tobias Gafner
STFC is based on STGC,
Copyright 2003-2007 by Florian Brede ([email protected]) 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/>.
*/
//########################################################################################
//########################################################################################
/* 23. May 2008
@Author: Carolfi - Delogu
@Action: carry on destruction to the galaxy
*/
/* ######################################################################################## */
/* ######################################################################################## */
// Startconfig of Borg
class Borg extends NPC
{
// Function to create BOT structures
public function Install($log = INSTALL_LOG_FILE_NPC)
{
// We don't use the global variable here since this function can be called also
// by the installation script.
$environment = $this->db->queryrow('SELECT * FROM config LIMIT 0 , 1');
$ACTUAL_TICK = $environment['tick_id'];
$FUTURE_SHIP = $environment['future_ship'];
$this->sdl->start_job('SevenOfNine basic system', $log);
$Bot_exe=$this->db->query('SELECT * FROM borg_bot LIMIT 0,1');
// Create BOT table if it doesn't exist
if($Bot_exe === false)
{
$sql = 'CREATE TABLE `'.$this->db->login['database'].'`.`borg_bot` (
`id` INT( 2 ) NOT NULL AUTO_INCREMENT ,
`user_id` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT \'0\',
`planet_id` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT \'0\',
`ship_template1` INT( 10 ) UNSIGNED NOT NULL DEFAULT \'0\',
`ship_template2` INT( 10 ) UNSIGNED NOT NULL DEFAULT \'0\',
`ship_template3` INT( 10 ) UNSIGNED NOT NULL DEFAULT \'0\',
`user_tick` INT( 10 ) NOT NULL ,
`attack_quadrant` TINYINT( 3 ) UNSIGNED NOT NULL DEFAULT \''.BORG_QUADRANT.'\',
`attacked_user1` MEDIUMINT( 8 ) UNSIGNED NOT NULL ,
`attacked_user2` MEDIUMINT( 8 ) UNSIGNED NOT NULL ,
`attacked_user3` MEDIUMINT( 8 ) UNSIGNED NOT NULL ,
`attacked_user4` MEDIUMINT( 8 ) UNSIGNED NOT NULL ,
`last_attacked` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT \'0\',
`wrath_size` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT \'30\',
PRIMARY KEY ( `id` )
) ENGINE = MYISAM';
if(!$this->db->query($sql))
{
$this->sdl->log('<b>Error:</b> cannot create borg_bot table - ABORTED', $log);
return;
}
}
$num_bot=$this->db->num_rows($Bot_exe);
if($num_bot < 1)
{
$sql = 'INSERT INTO borg_bot (user_id,user_tick,planet_id,ship_template1,ship_template2,ship_template3)
VALUES ("0","0","0","0","0","0")';
if(!$this->db->query($sql))
{
$this->sdl->log('<b>Error:</b> could not insert borg_bot data - ABORTED', $log);
return;
}
}
//So now we give the bot some data so that it is also Registered
$this->bot = $this->db->queryrow('SELECT * FROM borg_bot LIMIT 0,1');
//Check whether the bot already lives
if($this->bot['user_id']==0)
{
$this->sdl->log('We need to create SevenOfNine', $log);
$sql = 'INSERT INTO user (user_id, user_active, user_name, user_loginname, user_password, user_email,
user_auth_level, 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 ('.BORG_USERID.', 1, "Borg(NPC)", "BorgBot", "'.md5("borgcube").'", "[email protected]",
'.STGC_BOT.', '.BORG_RACE.', "/stfc_gfx/", "skin1/", '.time().',
"127.0.0.1", "23.05.2008", "", 16162 , "IT",
1, "<br><br><p><b>We are the Borg, resistance is futile</b></p>",
"'.BORG_SIGNATURE.'","", "", "")';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not create SevenOfNine - ABORTED', $log);
return;
}
$sql = 'UPDATE borg_bot
SET user_id="'.BORG_USERID.'",
user_tick="'.$ACTUAL_TICK.'"
WHERE id="'.$this->bot['id'].'"';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not update borg_bot table - ABORTED', $log);
return;
}
// Avoid a DB query
$this->bot['user_id'] = BORG_USERID;
} // end user bot creation
// Check whether the bot has a planet
if($this->bot['planet_id'] == 0) {
$this->sdl->log('<b>SevenOfNine needs new body</b>', $log);
while($this->bot['planet_id']==0 or $this->bot['planet_id']=='empty')
{
$this->sdl->log('Create new planet', $log);
$this->db->lock('starsystems_slots');
$this->bot['planet_id']=create_planet($this->bot['user_id'], 'quadrant', BORG_QUADRANT);
$this->db->unlock();
if($this->bot['planet_id'] == 0)
{
$this->sdl->log('<b>Error:</b> could not create SevenOfNine\'s planet - ABORTED', $log);
return;
}
$sql = 'UPDATE user
SET user_points = "400",
user_planets = "1",
last_active = "4294967295",
user_capital = "'.$this->bot['planet_id'].'",
active_planet = "'.$this->bot['planet_id'].'"
WHERE user_id = '.$this->bot['user_id'];
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not update SevenOfNine\'s attack protection info - CONTINUED', $log);
}
// That one is for resetting the Borg Targets List
$sql = 'TRUNCATE TABLE borg_target';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not reset borg_target - CONTINUED', $log);
}
//Bot gets best values for his body, he should also look good
$this->sdl->log('Give best values to the planet', $log);
$sql = 'UPDATE planets SET planet_points = 1200,building_1 = 9,building_2 = 15,building_3 = 15,
building_4 = 15,building_5 = 16,building_6 = 9,building_7 = 15,building_8 = 9,
building_9 = 9,building_10 = 35,building_11 = 9,building_12 = 15,building_13 = 35,
unit_1 = 20000,unit_2 = 10000,unit_3 = 5000,unit_4 = 5000,unit_5 = 0,unit_6 = 0,
planet_name = "Unimatrix Zero",
research_1 = 15,research_2 = 15,research_3 = 15,research_4 = 15,research_5 = 9,
workermine_1 = 1600,workermine_2 = 1600,workermine_3 = 1600,resource_4 = 4000
WHERE planet_owner = '.$this->bot['user_id'].' and planet_id='.$this->bot['planet_id'];
if(!$this->db->query($sql))
$this->sdl->log('<b>Error:</b> could not improve SevenOfNine\'s planet - CONTINUED', $log);
$sql = 'UPDATE borg_bot SET planet_id='.$this->bot['planet_id'].' WHERE user_id = '.$this->bot['user_id'];
if(!$this->db->query($sql))
$this->sdl->log('<b>Error:</b> could not update SevenOfNine ID card with planet info - CONTINUED', $log);
} // end while
} // end planet creation
// Check whether the ship already has templates
$reload=0;
if($this->bot['ship_template1']==0)
{
/**
* Brief comments of SECOND prototype of Borg Sphere:
*
* Light weapons: 600
* Heavy weapons: 600
* Planetary weapons: 50
* Hull: 700
* Shield: 700
*
* Reaction: 30
* Readiness: 30
* Agility: 30
* Experience: 20
* Warp: 10 (Borg has transwarp engines)
*
* Sensors: 20
* Camouflage: 0
* Energy available: 200
* Energy used: 200
*
* Resources needed for construction:
*
* Metal: 50000
* Minerals: 50000
* Dilithium: 50000
* Workers: 500
* Technicians: 100
* Physicians: 10
*
* Minimum crew:
*
* Drone simple: 100
* Assault drone: 25
* Elite drone: 25
* Commander drone: 5
*
* Maximum crew:
*
* Drone simple: 300
* Assault drone: 70
* Elite drone: 50
* Commander drone: 10
*/
$reload++;
$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 ("'.$this->bot['user_id'].'","'.time().'","'.BORG_SPHERE.'","Exploration ship","'.BORG_RACE.'",6,2,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"600","600","50","700","700",
"30","30","30","20","10",
"20","0","200","200","0",
"50000","50000","50000","500","100","10",
"100","25","25","5",
"300","70","50",10,
0, 1, 1, 500)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not save BOT template 1 - ABORTED', $log);
return;
}
// Update ship template id with the freshly created one
$this->bot['ship_template1'] = $this->db->insert_id();
}
if($this->bot['ship_template2']==0)
{
/**
* Brief comments of SECOND prototype of Borg Cube:
*
* Light weapons: 6000
* Heavy weapons: 6000
* Planetary weapons: 400
* Hull: 20000
* Shield: 7000
*
* Reaction: 60
* Readiness: 60
* Agility: 10
* Experience: 60
* Warp: 10 (Borg has transwarp engines)
*
* Sensors: 40
* Camouflage: 0
* Energy available: 2000
* Energy used: 2000
*
* Resources needed for construction:
*
* Metal: 500000
* Minerals: 500000
* Dilithium: 500000
* Workers: 50000
* Technicians: 10000
* Physicians: 1000
*
* Minimum crew:
*
* Drone simple: 10000
* Assault drone: 2500
* Elite drone: 2500
* Commander drone: 500
*
* Maximum crew:
*
* Drone simple: 30000
* Assault drone: 7000
* Elite drone: 5000
* Commander drone: 1000
*/
$reload++;
$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 ("'.$this->bot['user_id'].'","'.time().'","'.BORG_CUBE.'","Assimilation ship","'.BORG_RACE.'",10,3,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"6000","6000","400","20000","7000",
"60","60","10","60","10",
"40","0","2000","2000","0",
"500000","500000","500000","50000","10000","1000",
"10000","2500","2500","500",
"30000","7000","5000","1000",
0, 5, 5, 1000)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not save BOT template 2 - ABORTED', $log);
return;
}
// Update ship template id with the freshly created one
$this->bot['ship_template2'] = $this->db->insert_id();
}
if($this->bot['ship_template3']==0)
{
/**
* Brief comments of THIRD prototype of Borg Cube:
*
* Light weapons: 30000
* Heavy weapons: 30000
* Planetary weapons: 400
* Torpedoes: 800
* ROF: 16
* Hull: 100000
* Shield: 60000
*
* Reaction: 68
* Readiness: 68
* Agility: 10
* Experience: 60
* Warp: 10 (Borg has transwarp engines)
*
* Sensors: 40
* Camouflage: 0
* Energy available: 8000
* Energy used: 8000
*
* Resources needed for construction:
*
* Metal: 500000
* Minerals: 500000
* Dilithium: 500000
* Workers: 50000
* Technicians: 250
* Physicians: 250
*
* Minimum crew:
*
* Drone simple: 10000
* Assault drone: 2500
* Elite drone: 2500
* Commander drone: 500
*
* Maximum crew:
*
* Drone simple: 65000 <--- Max 65535
* Assault drone: 21000
* Elite drone: 15000
* Commander drone: 5000
*/
$reload++;
$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 ("'.$this->bot['user_id'].'","'.time().'","'.BORG_TACT.'","Combat Ship","'.BORG_RACE.'",11,3,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"30000","30000","400","100000","70000",
"68","68","10","60","10",
"40","0","8000","8000","0",
"500000","500000","500000","50000","250","250",
"10000","2500","2500","500",
"65000","21000","15000","5000",
0, 10, 10, 5000)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not save BOT template 3 - ABORTED '.$sql, $log);
return;
}
// Update ship template id with the freshly created one
$this->bot['ship_template3'] = $this->db->insert_id();
}
if($this->bot['unimatrixzero_tp']==0)
{
/**
* Brief comments of FIRST prototype of Unimatrix Zero:
*
* Light weapons: 1
* Heavy weapons: 1
* Planetary weapons: 1
* Torpedoes: 25000
* ROF: 25
* Hull: 850000
* Shield: 850000
*
* Reaction: 5
* Readiness: 80
* Agility: 5
* Experience: 100
* Warp: 10 (Borg has transwarp engines)
*
* Sensors: 80
* Camouflage: 0
* Energy available: 10000
* Energy used: 10000
*
* Resources needed for construction:
*
* Metal: 1
* Minerals: 1
* Dilithium: 1
* Workers: 1
* Technicians: 1
* Physicians: 1
*
* Minimum crew:
*
* Drone simple: 65000
* Assault drone: 25000
* Elite drone: 25000
* Commander drone: 5000
*
* Maximum crew:
*
* Drone simple: 65000 <--- Max 65535
* Assault drone: 25000
* Elite drone: 25000
* Commander drone: 5000
*/
$reload++;
$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 ('.$this->bot['user_id'].','.time().', "'.BORG_UM0.'", "Main Borg Base", '.BORG_RACE.',12,3,
-1, -1, -1, -1, -1,
-1, -1, -1, -1, -1,
1, 1, 1, 850000, 850000,
5, 80, 5, 100, 10,
80, 0, 10000, 10000, 0,
1, 1, 1, 1, 1, 1,
65000, 25000, 25000, 5000,
65000, 25000, 25000, 5000,
0, 25, 25, 25000)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not save BOT Unimatrix Zero - ABORTED '.$sql, $log);
return;
}
// Update ship template id with the freshly created one
$this->bot['unimatrixzero_tp'] = $this->db->insert_id();
}
if($reload > 0) {
$this->sdl->log('Ship templates built', $log);
$sql = 'UPDATE borg_bot
SET ship_template1 = '.$this->bot['ship_template1'].',
ship_template2 = '.$this->bot['ship_template2'].',
ship_template3 = '.$this->bot['ship_template3'].',
unimatrixzero_tp = '.$this->bot['unimatrixzero_tp'].'
WHERE user_id = '.$this->bot['user_id'];
if(!$this->db->query($sql))
$this->sdl->log('<b>Error:</b> Could not update SevenOfNine ID card with ship templates info - CONTINUED', $log);
}
$this->sdl->finish_job('SevenOfNine basic system', $log);
// ########################################################################################
// ########################################################################################
// Change the BOT password
$this->ChangePassword($log);
// Future Humans
$this->sdl->start_job('Future Humans Setup&Maintenance',$log);
if($FUTURE_SHIP == 0) {
$sql = 'SELECT count(*) AS fhship_check FROM ship_templates
WHERE template_id = '.$FUTURE_SHIP;
$result = $this->db->queryrow($sql);
if($result['fhship_check'] == 0) {
// We put the Future Humans Ship Template in the DB
$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 ("'.FUTURE_HUMANS_UID.'","'.time().'","Prometeus","Anti-Borg, Multirole, Heavy Assault Ship",12,11,3,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"5000","5000","280","21000","15000",
"36","40","48","46","9.99",
"65","0","480","480","0",
"35000","300000","300000","2900","65","15",
"150","100","85","15",
"400","200","150","25",
2000, 3, 500)';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> could not insert Future Humans Ship Template - ABORTED', $log);
return;
}
$FUTURE_SHIP = $this->db->insert_id();
if(!$this->db->query('UPDATE config SET future_ship = '.$FUTURE_SHIP))
$this->sdl->log('<b>Error:</b> could not update future ship template id - CONTINUED',$log);
$this->sdl->log('Template created with id '.$FUTURE_SHIP,$log);
}
}
$this->sdl->finish_job('Future Humans Setup&Maintenance',$log);
}
public function Execute($debug=0)
{
global $ACTUAL_TICK,$FUTURE_SHIP;
$starttime = ( microtime() + time() );
// Read debug config
if($debug_data = $this->db->queryrow('SELECT * FROM borg_debug LIMIT 0,1'))
{
if($debug_data['debug']==0 || $debug_data['debug']==1)
$debug=$debug_data['debug'];
}
$this->sdl->log('<br><b>-------------------------------------------------------------</b><br>'.
'<b>Starting Borg Bot Scheduler at '.date('d.m.y H:i:s', time()).'</b>', TICK_LOG_FILE_NPC);
$this->bot = $this->db->queryrow('SELECT * FROM borg_bot LIMIT 0,1');
if($this->bot)
$this->sdl->log("The conversation with SevenOfNine begins, oh, but I think that there is no possibility to talk with her",TICK_LOG_FILE_NPC);
else {
$this->sdl->log('<b>Error:</b> no access to the bot table - ABORTED', TICK_LOG_FILE_NPC);
return;
}
// ########################################################################################
// ########################################################################################
// Check Borg has a planet
$this->sdl->start_job('SevenOfNine integrity check', TICK_LOG_FILE_NPC);
// Check ownership of the BOT's planet
$sql = 'SELECT planet_owner FROM planets
WHERE planet_id = '.$this->bot['planet_id'];
$botplanetowner = $this->db->queryrow($sql);
// Owner are still BORG?
if($botplanetowner['planet_owner'] != $this->bot['user_id']) {
// Just reset the Borg planet_id, and call Install, the Borg Queen will get a new throne!
$sql = 'UPDATE borg_bot SET planet_id = 0';
if(!$this->db->query($sql))
$this->sdl->log('<b>Error:</b> cannot reset Borg main planet id', TICK_LOG_FILE_NPC);
else
$this->Install(TICK_LOG_FILE_NPC);
}
$this->sdl->finish_job('SevenOfNine integrity check', TICK_LOG_FILE_NPC);
// ########################################################################################
// ########################################################################################
// Messages answer
$messages=array('Resistance is futile.','Resistance is futile.','La resistenza è inutile.');
$titles=array('<b>We are Borg</b>','<b>We are Borg</b>','<b>Noi siamo i Borg</b>');
$this->ReplyToUser($titles,$messages);
// ########################################################################################
// ########################################################################################
//Sensors monitoring and user warning
$messages=array('Resistance is futile.','Resistance is futile.','La resistenza è inutile.');
$titles=array('<b>We are Borg</b>','<b>We are Borg</b>','<b>Noi siamo i Borg</b>');
//$this->CheckSensors($ACTUAL_TICK,$titles,$messages);
/**
* 13/11/08 - AC: Stop sending ONLY messages to nasty players! ^^
*/
$this->sdl->start_job('Sensors monitor', TICK_LOG_FILE_NPC);
$msgs_number=0;
$sql='SELECT user_id FROM `scheduler_shipmovement`
WHERE user_id>9 AND
move_status=0 AND
move_exec_started!=1 AND
move_finish>'.$ACTUAL_TICK.' AND
dest="'.$this->bot['planet_id'].'"';
$attackers=$this->db->query($sql);
while($attacker = $this->db->fetchrow($attackers))
{
$this->sdl->log('The User '.$attacker['user_id'].' is trying to attack bot planet', TICK_LOG_FILE_NPC);
$send_message = false;
// Choose a target
$sql='SELECT p.planet_owner,p.planet_name,p.planet_id,u.user_points FROM (planets p)
INNER JOIN (user u) ON u.user_id = p.planet_owner
WHERE p.planet_owner ='.$attacker['user_id'].' LIMIT 0 , 1';
$target=$this->db->queryrow($sql);
// Check if a fleet is already on fly
$sql = 'SELECT `fleet_id`, `move_id`, `planet_id` FROM `ship_fleets`
WHERE `user_id` = '.$this->bot['user_id'].' AND `fleet_name` = "'.$target['planet_name'].'"
LIMIT 0,1';
$fleet = $this->db->queryrow($sql);
// If the fleet does not exists
if(empty($fleet['fleet_id'])) {
// Create a new fleet
if($target['user_points'] > BORG_BIGPLAYER) {
$fleet_id = $this->CreateFleet($target['planet_name'],$this->bot['ship_template2'],1);
$sql = 'UPDATE ship_fleets SET alert_phase = '.ALERT_PHASE_RED.',
unit_1 = 1000, unit_2 = 1000, unit_3 = 4000, unit_4 = 100
WHERE fleet_id = '.$fleet_id;
if(!$this->db->query($sql))
$this->sdl->log('<b>Warning:</b> cannot update fleet alarm status to RED!', TICK_LOG_FILE_NPC);
}
else {
$fleet_id = $this->CreateFleet($target['planet_name'],$this->bot['ship_template1'],3);
$sql = 'UPDATE ship_fleets SET alert_phase = '.ALERT_PHASE_RED.',
unit_1 = (200*n_ships), unit_2 = (400*n_ships), unit_3 = (1200*n_ships), unit_4 = (40*n_ships)
WHERE fleet_id = '.$fleet_id;
if(!$this->db->query($sql))
$this->sdl->log('<b>Warning:</b> cannot update fleet alarm status to RED!', TICK_LOG_FILE_NPC);
}
// Send it to the planet
$this->SendBorgFleet($ACTUAL_TICK,$fleet_id, $target['planet_id']);
$send_message = true;
}
// If the fleet exists but it is not moving and it is not at planet
else if($fleet['planet_id'] != $target['planet_id'] && $target['move_id'] == 0) {
// Send it to the planet
$send_message = $this->SendBorgFleet($ACTUAL_TICK,$fleet['fleet_id'], $target['planet_id']);
}
if($send_message) {
$msgs_number++;
// Recover language of the sender
$sql = 'SELECT language FROM user WHERE user_id='.$attacker['user_id'];
if(!($language = $this->db->queryrow($sql)))
$this->sdl->log('<b>Error:</b> Cannot read user language!',
TICK_LOG_FILE_NPC);
switch($language['language'])
{
case 'GER':
$text=$messages[1];
$title=$titles[1];
break;
case 'ITA':
$text=$messages[2];
$title=$titles[2];
break;
default:
$text=$messages[0];
$title=$titles[0];
break;
}
$this->MessageUser($this->bot['user_id'],$attacker['user_id'],$title,
str_replace("<TARGETPLANET>",$target['planet_name'],$text));
}
}
$this->sdl->log('Number of "messages" sent:'.$msgs_number, TICK_LOG_FILE_NPC);
$this->sdl->finish_job('Sensors monitor', TICK_LOG_FILE_NPC);
// ########################################################################################
// ########################################################################################
//Ships creation
$this->sdl->start_job('Creating Unimatrix Zero Fleet', TICK_LOG_FILE_NPC);
/*
// Main Fleet Exist?
$sql = 'SELECT COUNT(*) AS cnt, fleet_id, planet_id FROM ship_fleets WHERE fleet_name = "Unimatrix Zero" AND user_id = '.$this->bot['user_id'];
$f_c = $this->db->queryrow($sql);
if($f_c['cnt'] == false)
{
$sql = 'INSERT INTO ship_fleets (fleet_name, user_id, planet_id, alert_phase, move_id, n_ships)
VALUES ("Unimatrix Zero", '.$this->bot['user_id'].', '.$this->bot['planet_id'].', '.ALERT_PHASE_RED.', 0, 1)';
if(!$this->db->query($sql))
$this->sdl->log('<b>Error:</b> Could not insert new fleet data', TICK_LOG_FILE_NPC);
$fleet_id = $this->db->insert_id();
if(!$fleet_id) $this->sdl->log('Error - '.$fleet_id.' = empty', TICK_LOG_FILE_NPC);
$sql= 'SELECT * FROM `ship_templates` WHERE `id` = '.$this->bot['ship_template3'];
if(($stpl = $this->db->queryrow($sql)) === false)
$this->sdl->log('<b>Error:</b> Could not query ship template data - '.$sql, TICK_LOG_FILE_NPC);
$sql= 'INSERT INTO ships (fleet_id, user_id, template_id, experience, hitpoints, construction_time,
rof, torp, unit_1, unit_2, unit_3, unit_4)
VALUES ('.$fleet_id.', '.$this->bot['user_id'].', '.$this->bot['ship_template3'].', '.$stpl['value_9'].',
'.$stpl['value_5'].', '.time().', '.$stpl['rof'].', '.$stpl['max_torp'].',
'.$stpl['max_unit_1'].', '.$stpl['max_unit_2'].',
'.$stpl['max_unit_3'].', '.$stpl['max_unit_4'].')';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not insert new ship data', TICK_LOG_FILE_NPC);
}
$this->sdl->log('Unimatrix Zero Fleet has been created!!!', TICK_LOG_FILE_NPC);
}
else
{
// Main Fleet is in right position?
if($f_c['planet_id'] != $this->bot['planet_id']) $this->SendBorgFleet($ACTUAL_TICK,$f_c['fleet_id'], $this->bot['planet_id'],11);
}
*/
// In questa versione, Unimatrix Zero è una flotta composta da un vascello speciale e dalla
// scorta di questo. La scorta è composta da cubi tattici, cubi e sfere. Viene generato un
// cubo tattico per ogni cinque pianeti controllati dal collettivo. Per ogni cubo tattico
// vengono generati 6 cubi. Per ogni cubo, vengono generate 4 sfere.
// ====== ATTENZIONE ======
// La flotta non viene generata in toto in questo momento! Assumerà la sua
// forma completa solo con il passare del tempo! In questa fase, la flotta
// è composta solo da Unimatrix Zero, UN cubo tattico, SEI cubi e
// VENTIQUATTRO sfere!
$sql = 'SELECT COUNT(*) AS cnt, fleet_id, planet_id FROM ship_fleets
WHERE fleet_name = "Unimatrix Zero" AND user_id = '.$this->bot['user_id'];
$f_c = $this->db->queryrow($sql);
if($f_c['cnt'] == false)
{
$sql = 'INSERT INTO ship_fleets (fleet_name, user_id, planet_id, alert_phase, move_id, n_ships)
VALUES ("Unimatrix Zero", '.$this->bot['user_id'].', '.$this->bot['planet_id'].', '.ALERT_PHASE_RED.', 0, 1)';
if(!$this->db->query($sql))
$this->sdl->log('<b>Error:</b> Could not insert new fleet data', TICK_LOG_FILE_NPC);
$fleet_id = $this->db->insert_id();
if(!$fleet_id) $this->sdl->log('Error - '.$fleet_id.' = empty', TICK_LOG_FILE_NPC);
// Creating the NEW Unimatrix Zero!
$sql = 'SELECT max_unit_1, max_unit_2, max_unit_3, max_unit_4, rof, max_torp,
value_5, value_9
FROM `ship_templates` WHERE `id` = '.$this->bot['unimatrixzero_tp'];
if(($stpl = $this->db->queryrow($sql)) === false)
$this->sdl->log('<b>Error:</b> Could not query Unimatrix Zero template data - '.$sql, TICK_LOG_FILE_NPC);
$sql= 'INSERT INTO ships (fleet_id, user_id, template_id, experience, hitpoints, construction_time,
rof, torp, unit_1, unit_2, unit_3, unit_4)
VALUES ('.$fleet_id.', '.$this->bot['user_id'].', '.$this->bot['unimatrixzero_tp'].', '.$stpl['value_9'].',
'.$stpl['value_5'].', '.time().', '.$stpl['rof'].', '.$stpl['max_torp'].',
'.$stpl['max_unit_1'].', '.$stpl['max_unit_2'].',
'.$stpl['max_unit_3'].', '.$stpl['max_unit_4'].')';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not insert new Unimatrix Zero ship data', TICK_LOG_FILE_NPC);
}
// We add the FIRST tactical cube
$sql = 'SELECT max_unit_1, max_unit_2, max_unit_3, max_unit_4, rof, max_torp,
value_5, value_9
FROM `ship_templates` WHERE `id` = '.$this->bot['ship_template3'];
if(($stpl = $this->db->queryrow($sql)) === false)
$this->sdl->log('<b>Error:</b> Could not query Borg Tactical Cube template data - '.$sql, TICK_LOG_FILE_NPC);
$sql= 'INSERT INTO ships (fleet_id, user_id, template_id, experience, hitpoints, construction_time,
rof, torp, unit_1, unit_2, unit_3, unit_4)
VALUES ('.$fleet_id.', '.$this->bot['user_id'].', '.$this->bot['ship_template3'].', '.$stpl['value_9'].',
'.$stpl['value_5'].', '.time().', '.$stpl['rof'].', '.$stpl['max_torp'].',
'.$stpl['max_unit_1'].', '.$stpl['max_unit_2'].',
'.$stpl['max_unit_3'].', '.$stpl['max_unit_4'].')';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not insert new Tactical cube data', TICK_LOG_FILE_NPC);
}
// We add SIX cubes
$sql = 'SELECT max_unit_1, max_unit_2, max_unit_3, max_unit_4, rof, max_torp,
value_5, value_9
FROM `ship_templates` WHERE `id` = '.$this->bot['ship_template2'];
if(($stpl = $this->db->queryrow($sql)) === false)
$this->sdl->log('<b>Error:</b> Could not query Borg Cube template data - '.$sql, TICK_LOG_FILE_NPC);
for ($i = 0; $i < 6; $i++) {
$sql= 'INSERT INTO ships (fleet_id, user_id, template_id, experience, hitpoints, construction_time,
rof, torp, unit_1, unit_2, unit_3, unit_4)
VALUES ('.$fleet_id.', '.$this->bot['user_id'].', '.$this->bot['ship_template2'].', '.$stpl['value_9'].',
'.$stpl['value_5'].', '.time().', '.$stpl['rof'].', '.$stpl['max_torp'].',
'.$stpl['max_unit_1'].', '.$stpl['max_unit_2'].',
'.$stpl['max_unit_3'].', '.$stpl['max_unit_4'].')';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not insert new Borg cube data', TICK_LOG_FILE_NPC);
}
}
// We add TWENTYFOUR spheres
$sql = 'SELECT max_unit_1, max_unit_2, max_unit_3, max_unit_4, rof, max_torp,
value_5, value_9
FROM `ship_templates` WHERE `id` = '.$this->bot['ship_template1'];
if(($stpl = $this->db->queryrow($sql)) === false)
$this->sdl->log('<b>Error:</b> Could not query Borg sphere template data - '.$sql, TICK_LOG_FILE_NPC);
for ($i = 0; $i < 24; $i++) {
$sql= 'INSERT INTO ships (fleet_id, user_id, template_id, experience, hitpoints, construction_time,
rof, torp, unit_1, unit_2, unit_3, unit_4)
VALUES ('.$fleet_id.', '.$this->bot['user_id'].', '.$this->bot['ship_template1'].', '.$stpl['value_9'].',
'.$stpl['value_5'].', '.time().', '.$stpl['rof'].', '.$stpl['max_torp'].',
'.$stpl['max_unit_1'].', '.$stpl['max_unit_2'].',
'.$stpl['max_unit_3'].', '.$stpl['max_unit_4'].')';
if(!$this->db->query($sql)) {
$this->sdl->log('<b>Error:</b> Could not insert new Borg sphere data', TICK_LOG_FILE_NPC);
}
}
$this->sdl->log('Unimatrix Zero Fleet has been created!!!', TICK_LOG_FILE_NPC);
}
else
{
// Main Fleet is in right position?
if($f_c['planet_id'] != $this->bot['planet_id'])
$this->SendBorgFleet($ACTUAL_TICK,$f_c['fleet_id'], $this->bot['planet_id'],11);
}
$this->sdl->finish_job('Creating Unimatrix Zero Fleet', TICK_LOG_FILE_NPC);
// ########################################################################################
// ########################################################################################
//Fleets's crew creation
// Actually put simply the troops aboard
$sql = 'UPDATE ship_fleets SET unit_1 = (1000*n_ships), unit_2 = (1000*n_ships), unit_3= (4000*n_ships), unit_4 = (100*n_ships)
WHERE fleet_name LIKE "%Fleet Node%" AND user_id = '.$this->bot['user_id'];
if(!$this->db->query($sql))
$this->sdl->log('<b>Warning:</b> cannot update Borg Nodes Fleet crew!', TICK_LOG_FILE_NPC);
// ########################################################################################
// ########################################################################################
// Create defences for BOT planets
$this->sdl->start_job('Create Borg defences on assimilated planets', TICK_LOG_FILE_NPC);
// We need many infos here, for StartBuild() function
$sql = 'SELECT planet_id, planet_type,
building_1, building_2, building_3, building_4, building_5,
building_6, building_7, building_8, building_9, building_10,
building_11, building_12, building_13,
resource_1, resource_2, resource_3,
research_3, research_4,
unittrain_actual
FROM planets
WHERE npc_last_action < '.$ACTUAL_TICK.' AND planet_owner = '.BORG_USERID.' ORDER BY npc_last_action ASC LIMIT 0, 3';
$planets = $this->db->query($sql);
// Select each planet
while($planet = $this->db->fetchrow($planets))
{
if($planet['building_6'] < 9) {
$res = $this->StartBuild($ACTUAL_TICK,5,$planet);
if($res == BUILD_ERR_ENERGY)
$res = $this->StartBuild($ACTUAL_TICK,4,$planet);
}
else
{
switch($planet['planet_type'])
{
case "e":
case "f":
case "g":
case "m":
case "o":
case "p":
case "y":
case "x":
if($planet['unittrain_actual'] == 0)
{
$sql = 'UPDATE planets SET unittrainid_1 = 3, unittrainid_2 = 2,
unittrainnumber_1 = 2, unittrainnumber_2 = 1,
unittrainnumberleft_1 = 2, unittrainnumberleft_2 = 1,
unittrainendless_1 = 1, unittrainendless_2 = 1,
unittrain_actual = 1, unittrainid_nexttime = '.($ACTUAL_TICK + 2).'
WHERE planet_id = '.$planet['planet_id'];
$this->db->query($sql);
}
break;
}
}
// Build some orbital guns
if($planet['building_10'] < (15 + $planet['research_3'])) {
$res = $this->StartBuild($ACTUAL_TICK,9,$planet);
if($res == BUILD_ERR_ENERGY)
$res = $this->StartBuild($ACTUAL_TICK,4,$planet);
}
if($planet['building_13'] < (15 + $planet['research_3'])) {
$res = $this->StartBuild($ACTUAL_TICK,12,$planet);
if($res == BUILD_ERR_ENERGY)
$res = $this->StartBuild($ACTUAL_TICK,4,$planet);
}
// Computing Fleet Strenght
if ($planet['planet_type'] == 'm' || $planet['planet_type'] == 'o' ||
$planet['planet_type'] == 'p' || $planet['planet_type'] == 'y' ||
$planet['planet_type'] == 'x' || $planet['planet_type'] == 'f' ||
$planet['planet_type'] == 'g')
$n_ships = 3;
else
$n_ships = 1;
$sql = 'SELECT `fleet_id`, `move_id`, `planet_id`, `npc_last_action` FROM `ship_fleets`
WHERE `user_id` = '.$this->bot['user_id'].' AND `fleet_name` = "Fleet Node#'.$planet['planet_id'].'"
LIMIT 0,1';
$fleet = $this->db->queryrow($sql);
// If the fleet does not exists
if(empty($fleet['fleet_id'])) {
// Create a new fleet
$fleet_id = $this->CreateFleet('Fleet Node#'.$planet['planet_id'],$this->bot['ship_template2'],$n_ships,$planet['planet_id']);
// Update alarm status & Home Planet & Embark Troops
$sql = 'UPDATE ship_fleets SET alert_phase = '.ALERT_PHASE_RED.', homebase = '.$planet['planet_id'].',
unit_1 = (1000*n_ships), unit_2 = (1000*n_ships), unit_3 = (4000*n_ships), unit_4 = (100*n_ships)
WHERE fleet_id = '.$fleet_id;
if(!$this->db->query($sql))
$this->sdl->log('<b>Warning:</b> cannot update fleet alarm status to RED!', TICK_LOG_FILE_NPC);
}
// If the fleet exists
else
{
if($fleet['move_id'] == 0)
{
// Repair&Rearm Fleet
$this->RestoreBorgFleet('Fleet Node#'.$planet['planet_id'], $n_ships);
$fleet_name = 'Fleet Node#'.$planet['planet_id'];
$this->RepairFleet($fleet_name);
// If it is not at planet, send it to the planet
if($fleet['planet_id'] != $planet['planet_id']) {
$this->SendBorgFleet($ACTUAL_TICK,$fleet['fleet_id'], $planet['planet_id'],11);
}
}
}
// Updating npc_last_action
$this->db->query('UPDATE planets SET npc_last_action = '.($ACTUAL_TICK + 240).' WHERE planet_id = '.$planet['planet_id']);
}
$this->sdl->finish_job('Create Borg defences on assimilated planets', TICK_LOG_FILE_NPC);
// ########################################################################################
// ########################################################################################
// Settlers Assimilation Program(tm)!!!
$this->sdl->start_job('Settlers Assimilation Program - BETA -', TICK_LOG_FILE_NPC);
// Settlers Target Analysis phase
$sql = 'SELECT planet_id, planet_type, bt.user_id FROM planets p
LEFT JOIN borg_npc_target bnt USING (planet_id)
LEFT JOIN borg_target bt ON best_mood_user = bt.user_id
WHERE planet_owner = '.INDEPENDENT_USERID.' AND bnt.planet_id IS NULL
ORDER BY planet_owned_date ASC LIMIT 0, 10';
$set_q1 = $this->db->query($sql);
$set_rows = $this->db->num_rows($set_q1);
if($set_rows > 0)
{
$this->sdl->log('DEBUG: Settlers Target Analysis Phase', TICK_LOG_FILE_NPC);
$data_q1 = $this->db->fetchrowset($set_q1);
foreach($data_q1 AS $item_q1)