-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmoves_action_46.php
1256 lines (1058 loc) · 52.5 KB
/
moves_action_46.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.
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/>.
*/
class moves_action_46 extends moves_common {
function _action_main() {
// #############################################################################
// Data from the attacker
/*
$sql = 'SELECT '.$this->get_combat_query_fleet_columns().', f.resource_4, f.unit_1, f.unit_2, f.unit_3, f.unit_4
FROM (ship_fleets f)
INNER JOIN user u ON u.user_id = f.user_id
INNER JOIN ships ON ships
WHERE f.fleet_id IN ('.$this->fleet_ids_str.')';
*/
$sql = 'SELECT '.$this->get_combat_query_fleet_columns().',
SUM(s.unit_1 - st.min_unit_1) AS unit_1,
SUM(s.unit_2 - st.min_unit_2) AS unit_2,
SUM(s.unit_3 - st.min_unit_3) AS unit_3,
SUM(s.unit_4 - st.min_unit_4) AS unit_4
FROM (ship_fleets f)
LEFT JOIN officers o ON o.fleet_id = f.fleet_id
INNER JOIN user u ON u.user_id = f.user_id
INNER JOIN ships s USING (fleet_id)
INNER JOIN ship_templates st ON s.template_id = st.id
WHERE f.fleet_id IN ('.$this->fleet_ids_str.')';
if(($atk_fleets = $this->db->queryrowset($sql)) === false) {
return $this->log(MV_M_DATABASE, 'Could not query attackers fleets data! SKIP');
}
$sql = 'SELECT DISTINCT ship_torso
FROM ship_templates
INNER JOIN ships ON ships.template_id = ship_templates.id
WHERE ships.fleet_id IN ('.$this->fleet_ids_str.')';
if(($atk_ships = $this->db->queryrowset($sql)) === false) {
return $this->log(MV_M_DATABASE, 'Could not query attackers fleets data! SKIP');
}
$is_tact = $is_cube = $is_sphere = false;
foreach ($atk_ships AS $atk_ship) {
if($atk_ship['ship_torso'] == 11) {$is_tact = true;}
if($atk_ship['ship_torso'] == 9) {$is_cube = true;}
if($atk_ship['ship_torso'] == 6) {$is_sphere = true;}
}
// #############################################################################
// Data from the defender
$sql = 'SELECT DISTINCT f.user_id,
u.user_alliance,
ud.ud_id, ud.accepted,
ad.ad_id, ad.type, ad.status
FROM (ship_fleets f)
INNER JOIN user u ON u.user_id = f.user_id
LEFT JOIN user_diplomacy ud ON ( ( ud.user1_id = '.$this->dest['user_id'].' AND ud.user2_id = f.user_id ) OR ( ud.user1_id = f.user_id AND ud.user2_id = '.$this->dest['user_id'].' ) )
LEFT JOIN alliance_diplomacy ad ON ( ( ad.alliance1_id = '.$this->dest['user_alliance'].' AND ad.alliance2_id = u.user_alliance) OR ( ad.alliance1_id = u.user_alliance AND ad.alliance2_id = '.$this->dest['user_alliance'].' ) )
WHERE f.planet_id = '.$this->move['dest'].' AND
f.user_id <> '.$this->dest['user_id'].' AND
f.user_id <> '.$this->move['user_id'].' AND
f.alert_phase >= '.ALERT_PHASE_YELLOW;
if(!$q_st_uid = $this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not query stationated fleets user data! SKIP');
}
$st_user = array();
while($st_uid = $this->db->fetchrow($q_st_uid)) {
$allied = false;
if($st_uid['user_alliance'] == $this->dest['user_alliance']) $allied = true;
if(!empty($st_uid['ud_id'])) {
if($st_uid['accepted'] == 1) $allied = true;
}
if(!empty($st_uid['ad_id'])) {
if( ($st_uid['type'] == ALLIANCE_DIPLOMACY_PACT) && ($st_uid['status'] == 0) ) $allied = true;
}
if($this->dest['user_id'] == INDEPENDENT_USERID) $allied = true;
if($allied) $st_user[] = $st_uid['user_id'];
}
$n_st_user = count($st_user);
if($n_st_user > 0) {
$sql = 'SELECT '.$this->get_combat_query_fleet_columns().'
FROM (ship_fleets f)
LEFT JOIN officers o ON o.fleet_id = f.fleet_id
INNER JOIN user u ON u.user_id = f.user_id
WHERE f.planet_id = '.$this->move['dest'].' AND
(
(
f.user_id = '.$this->dest['user_id'].'
)
OR
(
f.user_id IN ('.implode(',', $st_user).') AND
f.alert_phase >= '.ALERT_PHASE_YELLOW.'
)
)';
}
else {
$sql = 'SELECT '.$this->get_combat_query_fleet_columns().'
FROM (ship_fleets f)
LEFT JOIN officers o ON o.fleet_id = f.fleet_id
INNER JOIN user u ON u.user_id = f.user_id
WHERE f.planet_id = '.$this->move['dest'].' AND
f.user_id = '.$this->dest['user_id'];
}
if(($dfd_fleets = $this->db->queryrowset($sql)) === false) {
return $this->log(MV_M_DATABASE, 'Could not query defenders fleets data! SKIP');
}
$dfd_fleet_ids = array();
foreach($dfd_fleets as $i => $cur_fleet) {
$dfd_fleet_ids[] = $cur_fleet['fleet_id'];
}
$dfd_fleet_ids_str = implode(',', $dfd_fleet_ids);
if($this->do_ship_combat($this->fleet_ids_str, $dfd_fleet_ids_str, MV_COMBAT_LEVEL_PLANETARY) == MV_EXEC_ERROR) {
$this->log(MV_M_DATABASE, 'Move Action 46: Something went wrong with this fight!');
return MV_EXEC_ERROR;
}
// #############################################################################
// If the attacker has won attempt to start takeover
// #############################################################################
// 03/04/08 - AC: Retrieve player language
switch($this->dest['language'])
{
case 'GER':
$dfd_title = 'Angriff der Borg auf '.$this->dest['planet_name'];
break;
case 'ITA':
$dfd_title = 'Attacco Borg su '.$this->dest['planet_name'];
break;
default:
$dfd_title = 'Borg attack on '.$this->dest['planet_name'];
break;
}
$action_status = 0;
/* 11/07/08 - AC: Initialize here arrays atk/dfd_losses */
$atk_losses = array(0, 0, 0, 0, 0);
$dfd_losses = array(0, 0, 0, 0, 0);
if($this->cmb[MV_CMB_WINNER] == MV_CMB_ATTACKER) {
$atk_units = array(0, 0, 0, 0, 0);
// 20/06/08 - AC: Borg as no "workers"
for($i = 0; $i < count($atk_fleets); ++$i) {
$atk_units[0] += $atk_fleets[$i]['unit_1'];
$atk_units[1] += $atk_fleets[$i]['unit_2'];
$atk_units[2] += $atk_fleets[$i]['unit_3'];
$atk_units[3] += $atk_fleets[$i]['unit_4'];
}
$dfd_units = array($this->dest['unit_1'], $this->dest['unit_2'], $this->dest['unit_3'], $this->dest['unit_4'],$this->dest['resource_4']);
// Are there some defenders?
if (array_sum($dfd_units)>0)
{
$ucmb = UnitFight($atk_units, $this->move['user_race'], $dfd_units, $this->dest['user_race'], $this->mid);
$n_atk_alive = array_sum($ucmb[0]);
$atk_alive = $ucmb[0];
$dfd_alive = $ucmb[1];
}
// No ground troops presents!
else
{
$n_atk_alive=1;
$atk_alive = $atk_units;
$dfd_alive = array(0, 0, 0, 0, 0);
}
// 01/07/08 - AC: Count losses for each part
for($i = 0; $i < 5; ++$i) {
$atk_losses[$i] = $atk_units[$i] - $atk_alive[$i];
$dfd_losses[$i] = $dfd_units[$i] - $dfd_alive[$i];
}
// If there are no more attackers, the defender
// always won even if the defending had no units
if($n_atk_alive == 0) {
// In order to eliminate the troops of the aggressor, simply reset all transporters
// 21/06/08 - AC: Keep out workers from battle!
$sql = 'UPDATE ships
INNER JOIN ship_templates ON ships.template_id = ship_templates.id
SET unit_1 = ship_templates.min_unit_1,
unit_2 = ship_templates.min_unit_2,
unit_3 = ship_templates.min_unit_3,
unit_4 = ship_templates.min_unit_4
WHERE fleet_id IN ('.$this->fleet_ids_str.')';
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update ship fleets unit transport data! SKIP');
}
// Simply update the defender troops
$sql = 'UPDATE planets
SET unit_1 = '.$ucmb[1][0].',
unit_2 = '.$ucmb[1][1].',
unit_3 = '.$ucmb[1][2].',
unit_4 = '.$ucmb[1][3].',
resource_4 = '.$ucmb[1][4].'
WHERE planet_id = '.$this->move['dest'];
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update dest planet units data! SKIP');
}
$action_status = -1;
// #############################################################################
// 03/04/08 - AC: Retrieve player language
switch($this->move['language'])
{
case 'GER':
$atk_title = 'Angriff auf '.$this->dest['planet_name'].' teilweise erfolgreich';
break;
case 'ITA':
$atk_title = 'Attacco su '.$this->dest['planet_name'].' parzialmente riuscito';
break;
default:
$atk_title = 'Attack on '.$this->dest['planet_name'].' partially successful';
break;
}
}
else {
account_log($this->move['user_id'], $this->dest['user_id'], 4);
// Export a ruler switch
// We need the number of planets, which owns the colonizing
// (we want planet_owner_enum degree of certainty)
$sql = 'SELECT COUNT(planet_id) AS n_planets
FROM planets
WHERE planet_owner = '.$this->move['user_id'];
if(($pcount = $this->db->queryrow($sql)) === false) {
$this->log(MV_M_DATABASE, 'Could not query planets count data! CONTINUE AND USE INSTABLE VALUE');
$n_planets = $this->move['user_planets'];
}
else {
$n_planets = $pcount['n_planets'];
}
// We accommodate as much troops, as on the colony ship were, on the planet
$planet_units = array(0, 0, 0, 0);
// 25/06/08 - AC: Check available space on target planet
$sql = 'SELECT max_units FROM planets WHERE planet_id = '.$this->move['dest'];
if(($plspace = $this->db->queryrow($sql)) === false) {
$this->log(MV_M_DATABASE, 'Could not query planet max units data! CONTINUE AND USE INSTABLE VALUE');
$plspace['max_units'] = 1300; // Minimum size available
}
if(($atk_alive[0] * 2 + $atk_alive[1] * 3 + $atk_alive[2] * 4 + $atk_alive[3] * 4) > $plspace['max_units'])
{
$this->log(MV_M_NOTICE, 'Alive units exceed planet maximum units, we need to recall aboard the surplus');
// AC: Recall aboard the surplus troops
$i = 0;
while($n_atk_alive) {
if(($planet_units[0] * 2 + $planet_units[1] * 3 +
$planet_units[2] * 4 + $planet_units[3] * 4) >= $plspace['max_units'])
break;
if($atk_alive[$i] > 0)
{
$planet_units[$i]++;
$atk_alive[$i]--;
$n_atk_alive--;
}
else
$i++;
}
// Borg doesn't have cargo, simply use the Cube
/*
$sql = 'UPDATE ship_fleets
SET unit_1 = '.$atk_alive[0].',
unit_2 = '.$atk_alive[1].',
unit_3 = '.$atk_alive[2].',
unit_4 = '.$atk_alive[3].'
WHERE fleet_id = '.$this->fleet_ids_str;
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not update fleets units data! CONTINUE');
}
*
*/
} // alive troops doesn't exceed max planet units
else {
for($i = 0; $i <= 3; ++$i)
$planet_units[$i] += $atk_alive[$i];
/*
$sql = 'UPDATE ship_fleets
SET unit_1 = 0,
unit_2 = 0,
unit_3 = 0,
unit_4 = 0
WHERE fleet_id IN ('.$this->fleet_ids_str.')';
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update ship fleets unit transport data! SKIP');
}
*
*/
}
$sql = 'DELETE FROM scheduler_instbuild
WHERE planet_id = '.$this->move['dest'];
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not delete scheduler instbuild data! CONTINUE');
}
$sql = 'DELETE FROM scheduler_research
WHERE planet_id = '.$this->move['dest'];
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not delete scheduler research data! CONTINUE');
}
$sql = 'DELETE FROM scheduler_resourcetrade
WHERE planet = '.$this->move['dest'];
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not delete resource data! CONTINUE');
}
$sql = 'DELETE FROM scheduler_shipbuild
WHERE planet_id = '.$this->move['dest'];
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not delete shipbuild data! CONTINUE');
}
global $NUM_BUILDING, $MAX_BUILDING_LVL;
// As someone yes number == max_index sets
$n_buildings = $NUM_BUILDING + 1;
$building_levels = array();
$building_damage = 0.01 * mt_rand(40, 60);
// Set new home world
if($this->move['dest'] == $this->dest['user_capital']) {
for($i = 0; $i < $n_buildings; ++$i) {
$j = $i + 1;
$building_levels[$i] = (int) ($this->dest['building_'.$j] > $MAX_BUILDING_LVL[0][$i]) ? $MAX_BUILDING_LVL[0][$i] : round($this->dest['building_'.$j] * $building_damage, 0);
}
if($this->dest['user_planets'] == 1) {
// #############################################################################
// 03/04/08 - AC: Retrieve player language
switch($this->dest['language'])
{
case 'GER':
$msg_title = 'Verlust aller deiner Planeten';
$msg_body = 'Da du alle deine Planeten verloren hast, wurde für dich ein neuer Planet an einer zufüligen Stelle der Galaxie erstellt.';
break;
case 'ITA':
$msg_title = 'Perdita di tutti i pianeti';
$msg_body = 'Dato che hai perduto tutti i pianeti ne è stato creato uno nuovo nella galassia.';
break;
default:
$msg_title = 'Loss of all your planets';
$msg_body = 'Since you lost all your planets a new one have been created in the body of the galaxy.';
break;
}
SystemMessage($this->dest['user_id'], $msg_title, $msg_body);
}
else {
if(!$this->db->query('SET @i=0')) {
return $this->log(MV_M_DATABASE, 'Could not set sql iterator variable for planet owner enum! SKIP');
}
$sql = 'UPDATE planets
SET planet_owner_enum = (@i := (@i + 1))-1
WHERE planet_owner = '.$this->dest['user_id'].'
ORDER BY planet_owned_date ASC, planet_id ASC';
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update planet owner enum data! SKIP');
}
$sql = 'SELECT planet_id
FROM planets
WHERE planet_owner = '.$this->dest['user_id'].'
ORDER BY planet_owner_enum ASC
LIMIT 1';
if(($first_planet = $this->db->queryrow($sql)) === false) {
return $this->log(MV_M_DATABASE, 'Could not query first planet data! SKIP');
}
$sql = 'UPDATE user
SET last_active = '.time().',
last_ip = "0.0.0.0",
user_capital = '.$first_planet['planet_id'].',
pending_capital_choice = 1
WHERE user_id = '.$this->dest['user_id'];
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update user capital data! SKIP');
}
}
}
else {
for($i = 0; $i < $n_buildings; ++$i) {
$building_levels[$i] = round($this->dest['building_'.($i + 1)] * $building_damage, 0);
}
}
$sql = 'DELETE FROM resource_trade
WHERE planet = '.$this->move['dest'];
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not delete resource trade data! CONTINUE');
}
$sql = 'SELECT ship_id
FROM ship_trade
WHERE scheduler_processed = 0 AND
planet = '.$this->move['dest'];
if(!$q_shipt = $this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not query ship trade data! CONTINUE');
}
else {
$ship_ids = array();
while($_ship = $this->db->fetchrow($q_shipt)) {
$ship_ids[] = $_ship['ship_id'];
}
if(count($ship_ids) > 0) {
$sql = 'UPDATE ships
SET ship_untouchable = 0
WHERE ship_id IN ('.implode(',', $ship_ids).')';
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not update ships untouchable data! CONTINUE');
}
}
}
$sql = 'DELETE FROM ship_trade
WHERE scheduler_processed = 0 AND
planet = '.$this->move['dest'];
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not delete ship trade data! CONTINUE');
}
$sql = 'DELETE FROM scheduler_shipbuild WHERE planet_id = '.$this->move['dest'];
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not delete ship building queue! CONTINUE');
}
if($this->dest['planet_type'] == "m" || $this->dest['planet_type'] == "o" ||
$this->dest['planet_type'] == "p" || $this->dest['planet_type'] == "x" ||
$this->dest['planet_type'] == "y" || $this->dest['planet_type'] == "f" ||
$this->dest['planet_type'] == "g") {
$def_tech_lev = 9;
}
else {
$def_tech_lev = 6;
}
$sql = 'UPDATE planets
SET npc_last_action = 0,
planet_owner = '.$this->move['user_id'].',
planet_name = "Unimatrix #'.$this->move['dest'].'",
best_mood = 0,
best_mood_user = 0,
planet_available_points = 677,
planet_owned_date = '.time().',
planet_owner_enum = '.($n_planets - 1 >= 0 ? $n_planets - 1 : 0).',
resource_4 = '.$ucmb[1][4].',
planet_next_attack = 0,
planet_attack_ships = 0,
planet_attack_type = 0,
research_3 = '.$def_tech_lev.',
research_4 = '.$def_tech_lev.',
research_5 = '.$def_tech_lev.',
recompute_static = 1,
building_1 = 9,
building_2 = '.$building_levels[1].',
building_3 = '.$building_levels[2].',
building_4 = '.$building_levels[3].',
building_5 = 9,
building_6 = 9,
building_7 = '.$building_levels[6].',
building_8 = '.$building_levels[7].',
building_9 = '.$building_levels[8].',
building_10 = '.$building_levels[9].',
building_11 = '.$building_levels[10].',
building_12 = '.$building_levels[11].',
building_13 = '.$building_levels[12].',
unit_1 = '.$planet_units[0].',
unit_2 = '.$planet_units[1].',
unit_3 = '.$planet_units[2].',
unit_4 = '.$planet_units[3].',
unit_5 = 0,
unit_6 = 0,
workermine_1 = 100,
workermine_2 = 100,
workermine_3 = 100,
catresearch_1 = 0,
catresearch_2 = 0,
catresearch_3 = 0,
catresearch_4 = 0,
catresearch_5 = 0,
catresearch_6 = 0,
catresearch_7 = 0,
catresearch_8 = 0,
catresearch_9 = 0,
catresearch_10 = 0,
unittrainid_1 = 0, unittrainid_2 = 0, 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 = 0, unittrainnumber_2 = 0, 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 = 0, unittrainnumberleft_2 = 0, 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 = 0, unittrainendless_2 = 0, 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 = 0,
unittrainid_nexttime=0,
planet_surrender = 0,
planet_insurrection_time=0
WHERE planet_id = '.$this->move['dest'];
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update planets data! SKIP');
}
// DC >>>> Historycal record in planet_details, with label '29'
$sql = 'INSERT INTO planet_details (planet_id, user_id, alliance_id, source_uid, source_aid, timestamp, log_code, defeat_uid, defeat_aid)
VALUES ('.$this->move['dest'].', 0, 0, 0, 0, '.time().', 29,'.$this->dest['user_id'].', '.$this->dest['user_alliance'].')';
if(!$this->db->query($sql)) {
$this->log(MV_M_DATABASE, 'Could not update planet details data! CONTINUE');
}
// DC <<<<
// DC >>>> Update borg_target table; the $this->dest['user_id'] entry may not exists, so do not check error
$sql = 'UPDATE borg_target SET battle_lost = battle_lost + 1,
planets_back = planets_back + 1,
under_attack = under_attack - 1
WHERE user_id = '.$this->dest['user_id'];
$this->db->query($sql);
// DC <<<<
// DC >>>>
$sql = 'DELETE FROM borg_npc_target WHERE planet_id = '.$this->move['dest'];
$this->db->query($sql);
$sql = 'UPDATE scheduler_shipmovement SET action_code = 11
WHERE action_code = 46 AND move_id <> '.$this->mid.'
AND move_status = 0 AND user_id = '.BORG_USERID.' AND dest = '.$this->move['dest'];
$this->db->query($sql);
// DC <<<<
// DC >>>> Settlers management
if($this->dest['user_id'] == INDEPENDENT_USERID)
{
$sql = 'SELECT sr.user_id, u.language FROM settlers_relations sr
LEFT JOIN user u ON u.user_id = sr.user_id
WHERE planet_id = '.$this->move['dest'].' GROUP BY sr.user_id';
if($m_u_q = $this->db->queryrowset($sql))
{
foreach($m_u_q as $m_u)
{
$log_data = array($this->move['dest'],$this->dest['planet_name'], 0, '', 103);
switch($m_u['language'])
{
case 'GER':
$log_title = 'Automatic distress message from ';
break;
case 'ITA':
$log_title = 'Richiesta automatica di soccorso dalla colonia ';
break;
default:
$log_title = 'Automatic distress message from ';
break;
}
add_logbook_entry($m_u['user_id'], LOGBOOK_SETTLERS, $log_title.$this->dest['planet_name'], $log_data);
}
$sql = 'DELETE FROM settlers_relations WHERE planet_id = '.$this->move['dest'];
$this->db->query($sql);
}
}
// DC <<<< Settlers management
if(!$this->db->query('SET @i=0')) {
return $this->log(MV_M_DATABASE, 'Could not set sql iterator variable for planet owner enum (the invading player)! SKIP');
}
$sql = 'UPDATE planets
SET planet_owner_enum = (@i := (@i + 1))-1
WHERE planet_owner = '.$this->move['user_id'].'
ORDER BY planet_owned_date ASC, planet_id ASC';
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update planet owner enum data (the invading player)! SKIP');
}
$sql = 'UPDATE ships
SET user_id = '.$this->move['user_id'].'
WHERE fleet_id = -'.$this->move['dest'];
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update ships location data! SKIP');
}
$borg_bot = $this->db->queryrow('SELECT ship_template2 FROM borg_bot WHERE id = 1');
$sql = 'SELECT COUNT(*) as n_cubes FROM ships WHERE user_id = '.BORG_USERID.' AND template_id = '.$borg_bot['ship_template2'].' AND fleet_id IN ('.$this->fleet_ids_str.')';
$q_cube_count = $this->db->queryrow($sql);
if(isset($q_cube_count['n_cubes']) && $q_cube_count['n_cubes'] > 1 ) {
// Detach one Cube as local fleet
$sql = 'SELECT ship_id FROM ships WHERE user_id = '.BORG_USERID.' AND template_id = '.$borg_bot['ship_template2'].' AND fleet_id IN ('.$this->fleet_ids_str.') LIMIT 1,1';
$q_cube_id = $this->db->queryrow($sql);
$sql = 'INSERT INTO ship_fleets (fleet_name, user_id, planet_id, move_id, n_ships, alert_phase, homebase)
VALUES ("Fleet Node#'.$this->move['dest'].'", '.BORG_USERID.', '.$this->move['dest'].', 0, 1, 2, '.$this->move['dest'].')';
if(!$this->db->query($sql)) $this->log(MV_M_DATABASE, 'action_46: Could not insert new borg fleet data '.$sql);
$fleet_id = $this->db->insert_id();
$sql = 'UPDATE ships SET fleet_id = '.$fleet_id.' WHERE ship_id = '.$q_cube_id['ship_id'];
if(!$this->db->query($sql)) $this->log(MV_M_DATABASE, 'action_46: Could not update borg cube in new fleet '.$sql);
}
$action_status = 1;
// #############################################################################
// 03/04/08 - AC: Retrieve player language
switch($this->move['language'])
{
case 'GER':
$atk_title = 'Angriff auf '.$this->dest['planet_name'].' erfolgreich';
break;
case 'ITA':
$atk_title = 'Attacco su '.$this->dest['planet_name'].' riuscito';
break;
default:
$atk_title = 'Attack on '.$this->dest['planet_name'].' successful';
break;
}
}
// DC >>>>
if($this->dest['user_id'] == INDEPENDENT_USERID)
{
$sql = 'SELECT sr.user_id, u.language FROM settlers_relations sr
LEFT JOIN user u ON u.user_id = sr.user_id
WHERE planet_id = '.$this->move['dest'].' GROUP BY sr.user_id';
if($m_u_q = $this->db->queryrowset($sql))
{
foreach($m_u_q as $m_u)
{
$log_data = array($this->move['dest'],$this->dest['planet_name'], 0, '', 104);
switch($m_u['language'])
{
case 'GER':
$log_title = 'Distress call from ';
break;
case 'ITA':
$log_title = 'Richiesta di soccorso dalla colonia ';
break;
default:
$log_title = 'Distress call from ';
break;
}
add_logbook_entry($m_u['user_id'], LOGBOOK_SETTLERS, $log_title.$this->dest['planet_name'], $log_data);
}
}
}
// DC <<<<
$sql = 'UPDATE ship_fleets
SET planet_id = '.$this->move['dest'].',
move_id = 0
WHERE fleet_id IN ('.$this->fleet_ids_str.')';
if(!$this->db->query($sql)) {
// Here one could also report and then go on
return $this->log(MV_M_DATABASE, 'Could not update fleets location data! SKIP');
}
}
else {
// #############################################################################
// 03/04/08 - AC: Retrieve player language
switch($this->move['language'])
{
case 'GER':
$atk_title = 'Angriff auf '.$this->dest['planet_name'].' fehlgeschlagen';
break;
case 'ITA':
$atk_title = 'Attacco su '.$this->dest['planet_name'].' fallito';
break;
default:
$atk_title = 'Attack on '.$this->dest['planet_name'].' failed';
break;
}
// DC >>>> Begin Borg Adaption Phase!!!
if($is_tact) {
$adaption_chance_array = array (
'no_event' => 70,
'adapt_PRI' => 13,
'adapt_SEC' => 13,
'adapt_SHI' => 14,
'adapt_ARM' => 13,
'adapt_REA' => 5,
'adapt_RED' => 5,
'adapt_AGI' => 5,
'adapt_ROF' => 7,
'adapt_ROF2' => 7
);
$adaption_array = array();
foreach($adaption_chance_array as $event => $probability) {
for($i = 0; $i < $probability; ++$i) {
$adaption_array[] = $event;
}
}
$adaption_event = $adaption_array[array_rand($adaption_array)];
if($adaption_event == 'no_event') {
$this->log(MV_M_NOTICE, 'Borg Adaption Phase not occured this time.');
}
else {
$this->log(MV_M_NOTICE, 'Borg Tact Cube Adaption Phase begin NOW.');
$borg_bot = $this->db->queryrow('SELECT ship_template3 FROM borg_bot WHERE id = 1');
$borgtact_tp = $this->db->queryrow('SELECT * FROM ship_templates WHERE owner = '.BORG_USERID.' AND id = '.$borg_bot['ship_template3']);
$newvalue1 = $borgtact_tp['value_1'];
$newvalue2 = $borgtact_tp['value_2'];
$newvalue4 = $borgtact_tp['value_4'];
$newvalue5 = $borgtact_tp['value_5'];
$newvalue6 = $borgtact_tp['value_6'];
$newvalue7 = $borgtact_tp['value_7'];
$newvalue8 = $borgtact_tp['value_8'];
$newrof = $borgtact_tp['rof'];
$newrof2 = $borgtact_tp['rof2'];
switch($adaption_event) {
case 'adapt_PRI':
$newvalue1 = $newvalue1 * 1.030;
$this->log(MV_M_NOTICE, 'Borg Primary Attack Value ++.');
break;
case 'adapt_SEC':
$newvalue2 = $newvalue2 * 1.030;
$this->log(MV_M_NOTICE, 'Borg Secondary Attack Value ++.');
break;
case 'adapt_SHI':
$newvalue4 = $newvalue4 * 1.090;
$this->log(MV_M_NOTICE, 'Borg Shield Value ++.');
break;
case 'adapt_ARM':
$newvalue5 = $newvalue5 * 1.035;
$this->log(MV_M_NOTICE, 'Borg Hull Value ++.');
break;
case 'adapt_REA':
$newvalue6 = $newvalue6 + 1;
$this->log(MV_M_NOTICE, 'Borg Reaction Value ++.');
break;
case 'adapt_RED':
$newvalue7 = $newvalue7 + 1;
$this->log(MV_M_NOTICE, 'Borg Readiness Value ++.');
break;
case 'adapt_AGI':
$newvalue8 = $newvalue8 + 1;
$this->log(MV_M_NOTICE, 'Borg Agility Value ++.');
break;
case 'adapt_ROF':
$newrof = $newrof + 3;
$this->log(MV_M_NOTICE, '+++ Borg ROF Value +++.');
break;
case 'adapt_ROF2':
$newrof2 = $newrof2 + 3;
$this->log(MV_M_NOTICE, '+++ Borg ROF2 Value +++.');
break;
}
$oldversion = 0;
sscanf($borgtact_tp['name'],"Adapted Tact Cube#%u",$oldversion);
$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 ("'.$borgtact_tp['owner'].'","'.time().'","Adapted Tact Cube#'.($oldversion + 1).'","Combat ship","'.$borgtact_tp['race'].'",11,3,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"'.$newvalue1.'","'.$newvalue2.'","140","'.$newvalue4.'","'.$newvalue5.'",
"'.$newvalue6.'","'.$newvalue7.'","'.$newvalue8.'","'.($borgtact_tp['value_9'] < 200 ? $borgtact_tp['value_9'] + 1 : $borgtact_tp['value_9']).'","10",
"70","0","600","600","0",
"500000","500000","500000","50000","78","20",
"400","0","0","10",
"12400","8500","6500","500",
0, '.$newrof.', '.$newrof2.', 5000)';
$this->db->query($sql);
$newtpid = $this->db->insert_id();
$this->db->query('UPDATE borg_bot SET ship_template3 = '.$newtpid.' WHERE id = 1 ');
$this->log(MV_M_NOTICE, 'Borg Adaption Phase ends NOW.');
}
}
if($is_cube) {
$adaption_chance_array = array (
'no_event' => 90,
'adapt_PRI' => 12,
'adapt_SEC' => 12,
'adapt_SHI' => 12,
'adapt_ARM' => 5,
'adapt_REA' => 5,
'adapt_RED' => 5,
'adapt_AGI' => 2,
'adapt_ROF' => 3,
'adapt_ROF2' => 3
);
$adaption_array = array();
foreach($adaption_chance_array as $event => $probability) {
for($i = 0; $i < $probability; ++$i) {
$adaption_array[] = $event;
}
}
$adaption_event = $adaption_array[array_rand($adaption_array)];
if($adaption_event == 'no_event') {
$this->log(MV_M_NOTICE, 'Borg Adaption Phase not occured this time.');
}
else {
$this->log(MV_M_NOTICE, 'Borg CUBE Adaption Phase begin NOW.');
$borg_bot = $this->db->queryrow('SELECT ship_template2 FROM borg_bot WHERE id = 1');
$borgcube_tp = $this->db->queryrow('SELECT * FROM ship_templates WHERE owner = '.BORG_USERID.' AND id = '.$borg_bot['ship_template2']);
$newvalue1 = $borgcube_tp['value_1'];
$newvalue2 = $borgcube_tp['value_2'];
$newvalue4 = $borgcube_tp['value_4'];
$newvalue5 = $borgcube_tp['value_5'];
$newvalue6 = $borgcube_tp['value_6'];
$newvalue7 = $borgcube_tp['value_7'];
$newvalue8 = $borgcube_tp['value_8'];
$newrof = $borgcube_tp['rof'];
$newrof2 = $borgcube_tp['rof2'];
switch($adaption_event) {
case 'adapt_PRI':
$newvalue1 = $newvalue1 * 1.045;
$this->log(MV_M_NOTICE, 'Borg Primary Attack Value ++.');
break;
case 'adapt_SEC':
$newvalue2 = $newvalue2 * 1.045;
$this->log(MV_M_NOTICE, 'Borg Secondary Attack Value ++.');
break;
case 'adapt_SHI':
$newvalue4 = $newvalue4 * 1.180;
$this->log(MV_M_NOTICE, 'Borg Shield Value ++.');
break;
case 'adapt_ARM':
$newvalue5 = $newvalue5 * 1.070;
$this->log(MV_M_NOTICE, 'Borg Hull Value ++.');
break;
case 'adapt_REA':
$newvalue6 = $newvalue6 + 1;
$this->log(MV_M_NOTICE, 'Borg Reaction Value ++.');
break;
case 'adapt_RED':
$newvalue7 = $newvalue7 + 1;
$this->log(MV_M_NOTICE, 'Borg Readiness Value ++.');
break;
case 'adapt_AGI':
$newvalue8 = $newvalue8 + 1;
$this->log(MV_M_NOTICE, 'Borg Agility Value ++.');
break;
case 'adapt_ROF':
$newrof = $newrof + 2;
$this->log(MV_M_NOTICE, '+++ Borg ROF Value +++.');
break;
case 'adapt_ROF2':
$newrof2 = $newrof2 + 2;
$this->log(MV_M_NOTICE, '+++ Borg ROF2 Value +++.');
break;
}
$oldversion = 0;
sscanf($borgcube_tp['name'],"Adapted Cube#%u",$oldversion);
$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 ("'.$borgcube_tp['owner'].'","'.time().'","Adapted Cube#'.($oldversion + 1).'","Assimilation ship","'.$borgcube_tp['race'].'",9,3,
-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,
"'.$newvalue1.'","'.$newvalue2.'","140","'.$newvalue4.'","'.$newvalue5.'",
"'.$newvalue6.'","'.$newvalue7.'","'.$newvalue8.'","'.($borgcube_tp['value_9'] < 200 ? $borgcube_tp['value_9'] + 1 : $borgcube_tp['value_9']).'","10",
"50","0","300","300","0",
"500000","500000","500000","50000","39","16",
"300","0","0","6",
"300","1200","800","6",
0, '.$newrof.', '.$newrof2.', 1000)';
$this->db->query($sql);
$newtpid = $this->db->insert_id();
$this->db->query('UPDATE borg_bot SET ship_template2 = '.$newtpid.' WHERE id = 1 ');
$this->log(MV_M_NOTICE, 'Borg Adaption Phase ends NOW.');
}
}
if($is_sphere) {
$adaption_chance_array = array (
'no_event' => 90,
'adapt_PRI' => 8,
'adapt_SEC' => 8,
'adapt_SHI' => 10,
'adapt_ARM' => 5,