-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathattack.php
More file actions
2699 lines (2125 loc) · 118 KB
/
attack.php
File metadata and controls
2699 lines (2125 loc) · 118 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
/********************************* *
* Fleet Attack Module.
* Version 1.2.9
* Finished: Never!!!
* Last Modified:
* Created by: Jonathan "Moriarty"
* (c) Copyright 2003 to Jonathan "Moriarty"
* This file most definitely covered by the GPL
**********************************/
/* table that shows possible attack scheme things.
$error_str .= "<table border=1><tr><th>Attacker</th><th>Defender</th></tr>";
$error_str .= "<tr><td>Send some ships to distract planet. Rest of fleet attacks enemy ships.</td><td>Random</td></tr>";
$error_str .= "<tr><td>All attack Battleships</td><td>Random</td></tr>";
$error_str .= "<tr><td>All attack PO ships</td><td>Random</td></tr>";
$error_str .= "<tr><td>All attack freighters</td><td>Random</td></tr>";
$error_str .= "<tr><td>Target planet. Remaining fleet occupies enemy fleet.</td><td>Defend selves, then defend planet.</td></tr>";
$error_str .= "<tr><td>Distract warships, and hit freighters.</td><td>Random</td></tr>";
$error_str .= "<tr><td>Distract ships, and hit planet.</td><td>Random</td></tr>";
$error_str .= "<tr><td>Distract ships, and hit planet.</td><td>Random</td></tr>";
$error_str .= "<tr><td>Destroy enemy</td><td></td></tr>";
$error_str .= "<tr><td>Destroy as many ships as possible</td><td>Random</td></tr>";
$error_str .= "<tr><td>Do most damage possible. (i.e. PO's take on planet (if is one). SO's take on ships).</td><td></td></tr>";
$error_str .= "<tr><td></td><td></td></tr>";
$error_str .= "<tr><td></td><td></td></tr>";
$error_str .= "<tr><td></td><td></td></tr>";
$error_str .= "<tr><td></td><td></td></tr>";
$error_str .= "<tr><td></td><td></td></tr>";
$error_str .= "<tr><td></td><td></td></tr>";
$error_str .= "<tr><td></td><td></td></tr>";
*/
require_once("user.inc.php");
ship_status_checker();
//seed random number generator
mt_srand((double)microtime()*1000000);
if($user['ship_id'] == 1){
print_page($st[200]);
}
//echo "<pre>";
#quark disrupter.
if(isset($quark)) {
db("select * from ${db_name}_planets where planet_id = '$planet_num'");
$planet_info = dbr();
$sv_turns = 30;
$status_bar_help = "?topic=Technical_Information";
if($user['turns'] < $sv_turns) {
print_page($cw['quark_displacer'],sprintf($st[201], $sv_turns, $user[turns]));
} elseif($user['location'] != $planet_info['location']) {
print_page($cw['quark_displacer'],sprintf($st[202], $planet_info[planet_name]));
} elseif($user['turns_run'] < $GAME_VARS['turns_before_planet_attack'] && $user['login_id'] != 1) {
print_page($cw['quark_displacer'],sprintf($st[203], $GAME_VARS[turns_before_planet_attack]));
} elseif($GAME_VARS['attack_planet_flag'] == 0) {
print_page($cw['quark_displacer'],$st[204]);
} elseif($planet_info['login_id'] == 1) {
print_page($cw['quark_displacer'],$st[205]);
} elseif(!$planet_info['fighters']) {
print_page($cw['quark_displacer'],$st[206]."<p /><a href='planet.php?planet_id=$planet_info[planet_id]'>".$cw['land']."</a>".$st[207]);
} elseif(!config_check("sv", $user_ship)) {
print_page($cw['quark_displacer'],$st[208]);
} elseif(!isset($sure)) {
get_var($cw['quark_displacer'],'attack.php',$st[209]." <b class='b1'>$planet_info[planet_name]</b>?",'sure','yes');
} else {
charge_turns($sv_turns);
$sv_damage = mt_rand(600,1400);
/*
if($sv_damage > $planet_info[fighters]) {
$sv_damage = $planet_info[fighters];
}*/
$out_str = "";
dbn("update ${db_name}_planets set fighters = fighters - '$sv_damage' where planet_id = $planet_num");
$planet_info['fighters'] -= $sv_damage;
post_news("<b class='b1'>$user[login_name]</b>".$st[210]."<b class='b1'>$planet_info[planet_name]</b>.", $st[211]);
if($planet_info['fighters'] < 1) {
send_message($planet_info['login_id'],sprintf($st[212], $user_ship[ship_name],$planet_info[planet_name],$sv_damage));
send_templated_email($planet_info['login_id'], 'attack');
dbn("update ${db_name}_planets set fighters = 0 where planet_id = $planet_num");
$f_killed = $planet_info['fighters'];
$planet_info['fighters'] = 0;
$out_str .= sprintf($st[213], $sv_damage, $planet_info[planet_name], $sv_turns, $planet_info[planet_name])."<br /> - <a href='planet.php?planet_id=$planet_info[planet_id]'>".$cw['land']."</a><br />";
} else {
send_message($planet_info['login_id'],sprintf($st[214], $user_ship[ship_name], $planet_info[planet_name], $sv_damage));
send_templated_email($planet_info['login_id'], 'attack');
$f_killed = $sv_damage;
$out_str .= sprintf($st[215], $sv_damage, $planet_info[planet_name], $sv_turns);
}
dbn("update ${db_name}_users set fighters_killed = fighters_killed + '$f_killed' where login_id = $user[login_id]");
dbn("update ${db_name}_users set fighters_lost = fighters_lost + '$f_killed' where login_id = $planet_info[login_id]");
print_page($cw['quark_disrupter'],$out_str);
}
}
#terra maelstrom
if(isset($terra)) {
db("select * from ${db_name}_planets where planet_id = '$planet_num'");
$planet_info = dbr();
$sw_turns = 50;
$base_percent = 2;
$status_bar_help = "?topic=Technical_Information";
if($user['turns'] < $sw_turns) {
print_page($cw['terra_maelstrom'],sprintf($st[216], $sw_turns, $user[turns]));
} elseif($planet_info['planet_id'] == 1) {
print_page($cw['terra_maelstrom'],$st[217]);
} elseif($user['location'] != $planet_info['location']) {
print_page($cw['terra_maelstrom'],sprintf($st[218], $planet_info[planet_name]));
} elseif($user['turns_run'] < $GAME_VARS['turns_before_planet_attack'] && $user['login_id'] != 1) {
print_page($cw['terra_maelstrom'],sprintf($st[219], $GAME_VARS[turns_before_planet_attack]));
} elseif($GAME_VARS['attack_planet_flag'] == 0) {
print_page($cw['quark_displacer'],$st[220]);
} elseif($planet_info['login_id'] == 1) {
print_page($cw['terra_maelstrom'],$st[221]);
} elseif(!$planet_info['fighters']) {
print_page($cw['terra_maelstrom'],$st[222]."<p /><a href='planet.php?planet_id=$planet_info[planet_id]'>".$cw['land']."</a>".$st[223]);
} elseif($GAME_VARS['enable_superweapons'] == 0) {
print_page($cw['terra_maelstrom'],$st[224]);
} elseif(!config_check("sw", $user_ship)) {
print_page($cw['terra_maelstrom'],$st[225]);
} else {
#base amount of damage, done for the X turns.
$sq_damage = mt_rand(4000,6000);
#if planet has more than that many fighters, use an alternate system:
if($planet_info['fighters'] > $sq_damage && $user['turns'] > $sw_turns){
#work out how many fighters may be killed in one shot (between 65 and 75 percent) as a max.
$max_fig_kills = round(($planet_info['fighters'] / 100) * mt_rand(65,75));
#work out based on the max fighters that can be killed the num of fighters killed per turn.
$killed_per_turn = round($max_fig_kills / $GAME_VARS['max_turns']);
#damage done is based on num turns used times fighters killed per turn used. simple
$damage_done = round($killed_per_turn * $user['turns']);
#random factor. allows for an increased randomness in damage done.
$damage_done += round(mt_rand(-$damage_done * .05,$damage_done * .05));
#old method of doing damage with terra maelstrom
# $t_dam_done = round(($user[turns] - $sw_turns) / 10) + $base_percent;
# $damage_done = round($planet_info[fighters] /100 * ($base_percent + $t_dam_done));
# $damage_done += round(mt_rand(-$damage_done * .15,$damage_done * .15));
}
#damage done by alternate system isn't as much as using the sure fire method (fixed damage for fixed turns)
if($sq_damage > $damage_done){
$sw_damage = $sq_damage;
$turn_cost = $sw_turns;
} else { #damage done by alternate method is greater than normal damage done.
$turn_cost = $user['turns'];
$sw_damage = $damage_done;
}
if(!isset($sure)) {
get_var($cw['terra_maelstrom'],'attack.php',sprintf($st[226], $planet_info[planet_name], $turn_cost, $damage_done),'sure', 'yes');
}
charge_turns($turn_cost);
$out_str ="";
dbn("update ${db_name}_planets set fighters = fighters - '$sw_damage' where planet_id = $planet_num");
$planet_info['fighters'] -= $sw_damage;
post_news("<b class='b1'>$user[login_name]</b>".$st[227]." <b class='b1'>$planet_info[planet_name]</b>.", $cw['planet'], $cw['attacking']);
if($planet_info['fighters'] < 1) {
send_message($planet_info['login_id'],sprintf($st[228], $user_ship[ship_name], $planet_info[planet_name], $sw_damage));
send_templated_email($planet_info['login_id'], 'attack');
dbn("update ${db_name}_planets set fighters = 0 where planet_id = $planet_num");
$f_killed = $planet_info['fighters'];
$planet_info['fighters'] = 0;
$out_str .= sprintf($st[229], $sw_damage, $planet_info[planet_name], $turn_cost, $planet_info[planet_name])."<a href='planet.php?planet_id=$planet_info[planet_id]'>".$cw['land']."</a><br />";
} else {
send_message($planet_info['login_id'],sprintf($st[230], $user_ship[ship_name], $planet_info[planet_name], $sw_damage));
send_templated_email($planet_info['login_id'], 'attack');
$f_killed = $sw_damage;
$planet_info['fighters'] -= $sw_damage;
$out_str .= sprintf($st[231], $sw_damage, $planet_info[planet_name], $turn_cost);
}
dbn("update ${db_name}_users set fighters_killed = fighters_killed + '$f_killed' where login_id = $user[login_id]");
dbn("update ${db_name}_users set fighters_lost = fighters_lost + '$f_killed' where login_id = $planet_info[login_id]");
print_page($cw['terra_maelstrom'],$out_str);
}
}
/**************************************************************************
!!!Fleet Attacking!!!
***************************************************************************/
//location of combat.
$combat_loc = $user['location'];
$status_bar_help = "?topic=Combat";
//establish if attacking a planet
if(isset($planet_attack) && $planet_attack == 1){
$planet_attack = 1;
} else {
$planet_attack = 0;
}
//establish if simulating attack
if(!isset($simulate_attack)){
$simulate_attack = 0;
} else {
$simulate_attack = 1;
}
//load the armour multiplier. save chance of forgetting about it. :)
$armour_multiplier = $GAME_VARS['armour_multiplier'];
/********
* Intial checks to see if user can attack
********/
settype($target, "integer");
if($planet_attack == 1){ //player attacking a planet - select planet details
db("select u.turns_run as turns_run, p.login_id as login_id, u.clan_id as clan_id, u.login_name as login_name, planet_engaged from ${db_name}_users u, ${db_name}_planets p where p.planet_id = '$target' && u.login_id = p.login_id");
$target_fleet_brief = dbr(1);
$sql_to_find = "(config REGEXP 'bs' && config NOT REGEXP 'so') || config REGEXP 'oo' || config REGEXP 'po'"; //allow PO ships in on planet attacks.
} else { //player attacking a ship - select ship details
db("select u.turns_run as turns_run, s.login_id as login_id, s.fleet_id as fleet_id, s.clan_fleet_id as clan_fleet_id, u.clan_id as clan_id, s.config as config from ${db_name}_users u, ${db_name}_ships s where s.ship_id = '$target' && u.login_id = s.login_id");
$target_fleet_brief = dbr(1);
$sql_to_find = "(config REGEXP 'bs' && config NOT REGEXP 'po') || config REGEXP 'oo' || config REGEXP 'so' ";
}
//count warships that user has.
db("select count(*) as warships from ${db_name}_ships where fleet_id = '$user_ship[fleet_id]' && login_id = '$user[login_id]' && location = '$combat_loc' && ship_engaged <= '".time()."' && ($sql_to_find)");
$warship_count = dbr(1);
unset($sql_to_find);
//determine if user has actually selected anything to attack
if(empty($target) || ($target < 2 && $planet_attack == 0)) {
$tech_str = $st[232];
//admin not allowed to attack.
} elseif($user['login_id'] == 1) {
$tech_str = $st[233];
//ensure target is attackable, and that it even exists properly!
} elseif(!isset($target_fleet_brief['login_id'])) {
$tech_str = $st[280];
//determine if ship attacking is actually allowed
} elseif($GAME_VARS['attack_space_flag'] == 0 && $planet_attack == 0) {
$tech_str = $st[234];
//determine if planet attacking is actually allowed
} elseif($GAME_VARS['attack_planet_flag'] == 0 && $planet_attack == 1) {
$tech_str = $st[235];
//ensure the user is not trying to attack at sol.
} elseif($GAME_VARS['attack_sol_flag'] == 0 && $combat_loc == 1 && $user['login_id'] != 1){
$tech_str = $st[236];
//ensure user has at least 1 warship in the fleet.
} elseif(empty($warship_count['warships']) || $warship_count['warships'] == 0){
if($planet_attack == 1){
$tech_str = $st[237];
} else {
$tech_str = $st[238];
}
//target planet already in combat
} elseif($planet_attack == 1 && $target_fleet_brief['planet_engaged'] > time()) {
$tech_str = $st[239];
//ensure user has run enough turns for S to S
} elseif($user['turns_run'] < $GAME_VARS['turns_before_space_attack'] && $planet_attack == 0) {
$tech_str = sprintf($st[240], $GAME_VARS[turns_before_space_attack]);
//ensure user has run enough turns for S to P
} elseif($user['turns_run'] < $GAME_VARS['turns_before_planet_attack'] && $planet_attack == 1) {
$tech_str = sprintf($st[241], $GAME_VARS[turns_before_planet_attack]);
//ensure user has enough turns to attack at least a single ship.
} elseif($user['turns'] < $GAME_VARS['attack_turn_cost_space'] && $planet_attack == 0) {
$tech_str = sprintf($st[242], $GAME_VARS[attack_turn_cost_space]);
//ensure user has enough turns to attack a planet.
} elseif($user['turns'] < $GAME_VARS['attack_turn_cost_planet'] && $planet_attack == 1) {
$tech_str = sprintf($st[243], $GAME_VARS[attack_turn_cost_planet]);
//ensure target is attackable, and that it even exists properly!
} elseif($target_fleet_brief['turns_run'] < $GAME_VARS['turns_safe']) {
$tech_str = $st[244];
//ensure the attacking ship has a scanner on it.
} elseif($planet_attack == 0 && ((!config_check("sc",$user_ship) && (config_check("ls",$target_fleet_brief) || config_check("hs",$target_fleet_brief))) && $planet_attack == 0)) {
$tech_str = $st[245];
//player trying to attack either themselves, or a clan-mate?!?!
} elseif($target_fleet_brief['login_id'] == $user['login_id'] || ($target_fleet_brief['clan_id'] == $user['clan_id'] && $user['clan_id'] > 0)) {
$tech_str = $st[246];
//wouldn't want to attack the admin would we?
} elseif($target_fleet_brief['login_id'] == 1) {
$tech_str = $st[247];
//check if attacked user is in holiday mode
} elseif ( checkHolidayMode( $target_fleet_brief['login_id'] ) ) {
$tech_str = $st[1886];
//user passed initial tests.
} else {
unset($warship_count);
/***********
* second level of checks. Ensure there is a fleet to attack and user may actually attack
***********/
//select all enemy ships that belong to that user and are in that fleet, or that are clan-mates and are in the same fleet - must also be outside turns safe.
/*$enemy_ship_counter_sql = " from ${db_name}_ships s, ${db_name}_users u, ${db_name}_planets p where
(
(((s.fleet_id = '$target_fleet_brief[fleet_id]' && s.login_id = '$target_fleet_brief[login_id]')
|| (u.clan_id > 0 && s.clan_fleet_id = '$target_fleet_brief[clan_fleet_id]' && u.clan_id = '$target_fleet_brief[clan_id]' && s.login_id != '$target_fleet_brief[login_id]')) && s.location = '$combat_loc' && s.login_id = u.login_id)
|| (((p.fleet_id = '$target_fleet_brief[fleet_id]' && p.login_id = '$target_fleet_brief[login_id]')
|| (u.clan_id > 0 && p.clan_fleet_id = '$target_fleet_brief[clan_fleet_id]' && u.clan_id = '$target_fleet_brief[clan_id]' && p.login_id != '$target_fleet_brief[login_id]')) && p.location = '$combat_loc' && p.login_id = u.login_id ))
&& u.login_id != 1 && u.turns_run > '$GAME_VARS[turns_safe]'";*/
$players_array = array();
$time_to_engage = time() + 60;
$total_planet_dam_taken = 0;
$ships_in_system = 0;
/* Enemy user details */
$foes_name_str = "";
//target is a fleet, not a planet
if($planet_attack == 0){
$enemy_ship_counter_sql = " from ${db_name}_ships s, ${db_name}_users u where ((s.fleet_id = '$target_fleet_brief[fleet_id]' && s.login_id = '$target_fleet_brief[login_id]') || ('$GAME_VARS[clan_fleet_attacking]' = 1 && u.clan_id > 0 && s.clan_fleet_id = '$target_fleet_brief[clan_fleet_id]' && u.clan_id = '$target_fleet_brief[clan_id]' && u.login_id != '$target_fleet_brief[login_id]')) && s.location = '$combat_loc' && u.login_id != 1 && s.login_id = u.login_id && u.turns_run >= '$GAME_VARS[turns_safe]' && s.ship_engaged <= '".time()."'";
//count ships and users in enemy fleets.
db("select count(distinct s.ship_id) as ship_count, count(distinct s.login_id) as user_count, sum(s.fighters) as fighter_count, sum(num_dt + num_ot + num_pc + num_ew) as upgrade_count".$enemy_ship_counter_sql);
$target_details = dbr(1);
$target_details['fighters_lost'] = 0;
//dump all the enemies names into a string.
db("select u.login_id as login_id, u.clan_id as clan_id, u.ship_id as ship_id, u.login_name as login_name, u.location as location ".$enemy_ship_counter_sql." group by u.login_id");
while($foes_logins = dbr(1)) {
add_user_to_users_array($players_array, $ships_involved_str, $foes_name_str, $foes_logins, 2);
}
unset($foes_logins);
/**************** Load Assisting Planets ****************/
$target_planets = array();
$total_planet_figs = 0;
//load all planets that can assist. will only load clan planets if player in a clan, and clan fleet attacking is enabled.
db("select p.*, p.allocated_to_fleet as fighters, p.fighters as possible_fighters, u.location as location from ${db_name}_planets p, ${db_name}_users u where (p.login_id = '$target_fleet_brief[login_id]' || (p.clan_id = '$target_fleet_brief[clan_id]' && '$GAME_VARS[clan_fleet_attacking]' = 1 && '$target_fleet_brief[clan_id]' > 0 && p.login_id != '$target_fleet_brief[login_id]')) && p.location = '$combat_loc' && p.allocated_to_fleet > 0 && u.login_id = p.login_id && u.turns_run > '$GAME_VARS[turns_safe]' && p.planet_engaged <= '".time()."'");
while($assisting_planets_db = dbr(1)) {
//simulating an attack will result in planets fig count being unknown (randomised).
if($simulate_attack == 1 || !isset($sure)){
$assisting_planets_db['fighters'] += mt_rand(round(-$assisting_planets_db['fighters'] * 0.2),round($assisting_planets_db['fighters'] * 0.2));
if($assisting_planets_db['fighters'] > $assisting_planets_db['possible_fighters']){
$assisting_planets_db['fighters'] = $assisting_planets_db['possible_fighters'];
}
}
//add planet details to assisting planet details array.
$target_planets[$assisting_planets_db['planet_id']] = $assisting_planets_db;
$total_planet_figs += $assisting_planets_db['fighters'];
//dump player details into player array.
$assisting_planets_db['ship_id'] = 0;
add_user_to_users_array($players_array, $ships_involved_str, $foes_name_str, $assisting_planets_db, 2);
$players_array[$assisting_planets_db['login_id']]['total_fighters'] += $assisting_planets_db['fighters'];
}
unset($assisting_planets_db);
if(count($target_planets) > 0){//assisting planets. So include PO
$friendly_sql_ships = "config REGEXP 'bs' || config REGEXP 'oo'";
} else {//no planets. So no po's involved.
$friendly_sql_ships = "(config REGEXP 'bs' || config REGEXP 'oo') && config NOT REGEXP 'po'";
}
//user attacking a planet. We can use the collection of info we garnered at the initial stage to initialise this entry.
//We also need to create some 'target details'.
} else {
//only select non SO ships.
$friendly_sql_ships = "(config REGEXP 'bs' || config REGEXP 'oo') && config NOT REGEXP 'so'";
$enemy_ship_counter_sql = " from ${db_name}_planets p, ${db_name}_users u where p.planet_id = '$target' && p.location = '$combat_loc' && p.login_id != 1 && u.login_id = p.login_id && u.turns_run >= '$GAME_VARS[turns_before_planet_attack]'";
db("select p.fighters - p.allocated_to_fleet as fighter_count, p.fighters as possible_fighters".$enemy_ship_counter_sql);
$target_details = dbr(1);
//planet doesn't exist for some reason
if(!is_array($target_details)){
print_page($st[248]);
//the planet has no fighters that can defend it.
} elseif(empty($target_details['fighter_count']) || $target_details['fighter_count'] < 1){
print_page($st[249]."<a href='planet.php?planet_id=$target'>".$cw['land']."</a>".$st[250]);
}
$target_details['ship_count'] = 0;
$target_details['user_count'] = 1;
$target_details['upgrade_count'] = 0;
$target_details['fighters_lost'] = 0;
$total_planet_figs = $target_details['fighter_count'];
//select the planet owners command ship, so as the owner doesn't end up in some obscure place at the end of combat.
db("select ship_id, location from ${db_name}_users where login_id = '$target_fleet_brief[login_id]'");
$temp_ship_id = dbr(1);
$target_fleet_brief['ship_id'] = $temp_ship_id['ship_id'];
$target_fleet_brief['location'] = $temp_ship_id['location'];
unset($temp_ship_id);
add_user_to_users_array($players_array, $ships_involved_str, $foes_name_str, $target_fleet_brief, 2);
/*******************************************************/
// Select Target planet Details!
/*******************************************************/
//check to see how many 'defensive ships' are in the system
//not all fighters are allocated to planet defence, some are set to assist fleets.
if($target_details['fighter_count'] != $target_details['possible_fighters']){
//Check to see if there are any ships in the system to 'defend'.
//If there are such ships, then the fighters allocated to them won't be available for planet defence.
db("select count(ship_id) as num_ships from ${db_name}_ships where location = '$combat_loc' && (login_id = '$target_fleet_brief[login_id]' || (login_id != '$target_fleet_brief[login_id]' && clan_id > 0 && '$GAME_VARS[clan_fleet_attacking] = 1' && clan_id = '$target_fleet_brief[clan_id]'))");
$ships_count_temp = dbr(1);
$ships_count_temp['num_ships'];
//there are some ships in the system, so only non-allocated fighters go to planet defence.
if($ships_count_temp['num_ships'] > 0){
$temp_var['fighters'] = $target_details['fighter_count'];
$ships_in_system = 1;
if($simulate_attack == 1){//the user won't know the exact number of figs
$temp_var['fighters'] += mt_rand(round(-$temp_var['fighters'] * 0.2),round($temp_var['fighters'] * 0.2));
if($temp_var['fighters'] > $target_details['possible_fighters']){
$temp_var['fighters'] = $target_details['possible_fighters'];
}
}
//no ships in system. All the planets fighters go into defending itself.
} else {
$temp_var['fighters'] = $target_details['possible_fighters'];
}
unset($ships_count_temp);
} else { //all fighters are allocated to planet defence.
$temp_var['fighters'] = $target_details['possible_fighters'];
}
db2("select p.* ".$enemy_ship_counter_sql);
$temp_planet = dbr2(1);
//set planet to 'combat engaged' for next 60 secs
if(isset($sure) && $simulate_attack == 0) {
dbn("update ${db_name}_planets set planet_engaged = '$time_to_engage' where planet_id = '$target'");
}
$target_planets[$target] = $temp_planet;
$target_planets[$target]['ship_destroyed'] = 0;
$total_planet_figs = $target_planets[$target]['fighters'];
$players_array[$target_fleet_brief['login_id']]['total_fighters'] += $total_planet_figs;
unset($temp_planet);
$target_details['fighter_count'] = 0; //this var contains ship fig count only
}
if(($simulate_attack == 1 || !isset($sure)) && $total_planet_figs > 0 && $ships_in_system == 1){
$report_figs = $total_planet_figs." (Guess)";
} else {
$report_figs = $total_planet_figs;
}
/* Friendly user details */
//select all own and clan ships (when clans are permitted to join combat) that are capable of attacking (not po or na), and whose users are allowed to attack.
$friendly_ship_counter_sql = " from ${db_name}_ships s, ${db_name}_users u where ((s.fleet_id = '$user_ship[fleet_id]' && s.login_id = '$user_ship[login_id]') || ('$GAME_VARS[clan_fleet_attacking]' = 1 && $user[clan_id] > 0 && s.clan_fleet_id = '$user_ship[clan_fleet_id]' && u.clan_id = '$user[clan_id]' && u.login_id != '$user[login_id]')) && s.location = '$combat_loc' && u.login_id != 1 && s.login_id = u.login_id && u.turns_run >= '$GAME_VARS[turns_before_space_attack]' && ($friendly_sql_ships) && s.config NOT REGEXP 'na'";
//count ships and users in own fleets.
db("select count(s.ship_id) as ship_count, count(distinct s.login_id) as user_count, sum(s.fighters) as fighter_count, sum(num_dt + num_ot + num_pc + num_ew) as upgrade_count".$friendly_ship_counter_sql);
$friendly_details = dbr(1);
$friendly_details['fighters_lost'] = 0;
//create a string with the names of the friend fleet owners on.
$friends_name_str = "";
db("select u.login_id as login_id, u.clan_id as clan_id, u.ship_id as ship_id, u.login_name as login_name, u.location as location".$friendly_ship_counter_sql." group by u.login_id");
while($friends_logins = dbr(1)) {
add_user_to_users_array($players_array, $ships_involved_str, $friends_name_str, $friends_logins, 1);
}
unset($friends_logins);
/*Generic Details and more checks*/
//select most experienced ship in the users fleet. Must be BS or OO.
db("select ship_name, class_name, points_killed from ${db_name}_ships where login_id = '$user[login_id]' && location = '$combat_loc' && fleet_id = '$user_ship[fleet_id]' && (config REGEXP 'bs' || config REGEXP 'oo') order by points_killed desc LIMIT 1");
$experienced_ship = dbr(1);
//work out level of the ship.
settype($exp, "integer");
$exp = resolve_level($experienced_ship['points_killed']);
//Work out turn cost to attack
if($planet_attack == 1){
$total_attack_turn_cost = $GAME_VARS['attack_turn_cost_planet'];
} else {
$total_attack_turn_cost = $GAME_VARS['attack_turn_cost_space'] * $target_details['ship_count'];
}
//work out max turns that can be used to attack (is max turn storage minus 1 hrs worth of turns).
$highest_turns = $GAME_VARS['max_turns'] - $GAME_VARS['hourly_turns'];
//if the total cost is going to be more than the user can actually store, make the number equal the max_turns minus one maints worth (so the player can get in and get out again).
if($total_attack_turn_cost > $highest_turns){
$total_attack_turn_cost = $highest_turns;
}
//check to see if the user has enough turns to progress, less than 100% turn capacity required.
if($user['turns'] < $total_attack_turn_cost && $total_attack_turn_cost < $highest_turns) {
$tech_str = sprintf($st[251], $target_details[ship_count], $GAME_VARS[attack_turn_cost_space], $total_attack_turn_cost);
//user doesn't have enough turns, and user requires high turn capacity.
} elseif($user['turns'] < $total_attack_turn_cost && $total_attack_turn_cost >= $highest_turns) {
$tech_str = sprintf($st[252], $target_details[ship_count], $highest_turns);
//ensure there are enemy ships that can be attacked.
} elseif((empty($target_details['ship_count']) || $target_details['ship_count'] == 0) && $planet_attack == 0){
$tech_str = $st[253];
//ensure user actually has some ships that can attack
} elseif(empty($friendly_details['ship_count']) || $friendly_details['ship_count'] == 0){
$tech_str = $st[254];
//ensure user actually has some damage doing ability!
} elseif($friendly_details['fighter_count'] < 1 && $friendly_details['upgrade_count'] < 1){
$tech_str = $st[255];
//list the tactics available to the user. And present absolute confirmation.
} elseif(!isset($sure)) {
//can't be telling the user the name of the target now can we? :) Not if they have high stealth at least.
if($planet_attack == 0 && config_check("hs",$target_fleet_brief)){
$temp_foes_name_str = " <b>".$cw['unknown_target']."</b>";
} else {
$temp_foes_name_str = $foes_name_str;
}
/******** Simulation Text *********/
$sim_hid_vars = "";
// if($exp == 0 || $planet_attack == 1){
$sim_hid_vars = "<input type=hidden name='gen_tactic_to_use' value=1 />";
// }
//$sim_text = "\n\n<br /><br /><br /><b>".$cw['simulation']."</b> - ".popup_help("help.php?topic=Combat&popup=1&sub_topic=Simulating_Combat", 300, 430, $st[1696])."<br />".sprintf($st[270], $simulate_attack_turn_cost)."<FORM action=attack.php method=post name=simulate_attack_form>\n<input type=hidden name='target' value='$target' /><input type=hidden name='planet_attack' value='$planet_attack' />\n<input type=hidden name='sure' value='yes' />\n <input type=hidden name='simulate_attack' value=1 />\n $sim_hid_vars \n<input type='Submit' value='".$cw['simulate']."' /></FORM>";
$attack_help_str = "<p /><a target='_blank' href='help.php?topic=Combat'>".$cw['attacking_help']."</a>";
/******** Single ship combat, Or ship against planet combat. *********/
//no need for 'tactics' if just going 1 on 1.
if($target_details['ship_count'] == 1 && $friendly_details['ship_count'] == 1 && $planet_attack == 0 && count($target_planets) < 1){
$tech_str = sprintf($st[256], $temp_foes_name_str, $total_attack_turn_cost, $attack_help_str);
$tech_str .= "\n<FORM action=attack.php method=post name=confirmation_request>\n";
$tech_str .= "\n<input type=hidden name=gen_tactic_to_use value=1 />\n<input type=hidden name='target' value='$target' />\n<input type=hidden name='sure' value='yes' />\n<input type=\"Button\" value='".$cw['flee']."' onclick=\"javascript: history.back()\" /> - <input type='Submit' value='".$cw['attack']."!!!!!' /></FORM>";
print_page($cw['ship_attack_confirmation'],$tech_str);
} elseif($planet_attack == 1){
$tech_str = $st[257]." <b class='b1'>{$target_planets[$target]['planet_name']}".sprintf($st[258], $total_attack_turn_cost)." $attack_help_str";
$tech_str .= "<p />".make_table(array("",$st[271], $cw['ships'], $cw['ship_fighters'], $cw['planet_fighters']),"WIDTH=50%");
$tech_str .= make_row(array($cw['friendly_fleet'], $friendly_details['user_count'].$friends_name_str, $friendly_details['ship_count'], $friendly_details['fighter_count']));
$tech_str .= make_row(array($cw['enemy_forces'],$target_details['user_count'].$temp_foes_name_str, "-", "-", "Up to ".$target_details['possible_fighters']));
$tech_str .= "</table>".$sim_text;
$tech_str .= "\n<FORM action=attack.php method=post name=confirmation_request>\n";
$tech_str .= "\n<input type=hidden name=gen_tactic_to_use value=1 />\n<input type=hidden name='target' value='$target' />\n<input type=hidden name='planet_attack' value='1' />\n<input type=hidden name='sure' value='yes' />\n<input type=\"Button\" value='".$cw['flee']."' onclick=\"javascript: history.back()\" /> - <input type='Submit' value=".$cw['attack']."!!!!! /></FORM>";
print_page($cw['planet_attack_confirmation'],$tech_str);
}
//start of the tactical control page.
$tech_str = $st[259].$attack_help_str;
/******** General Overview *********/
//give general stats as to what the two sides have.
$tech_str .= "\n<br /><br /><br /><b>".$cw['general_overview']."</b>";
$tech_str .= $st[260];
$tech_str .= "<p />".make_table(array("",$st[271], $cw['ships'], $cw['ship_fighters'], $cw['planets'], $cw['planet_fighters']),"WIDTH=50%");
$tech_str .= make_row(array($cw['friendly_fleet'],$friendly_details['user_count'].$friends_name_str, $friendly_details['ship_count'], $friendly_details['fighter_count']));
$tech_str .= make_row(array($cw['enemy_forces'],$target_details['user_count'].$temp_foes_name_str, $target_details['ship_count'], $target_details['fighter_count'], count($target_planets), $report_figs));
$tech_str .= sprintf($st[261], $total_attack_turn_cost);
$tech_str .= $sim_text;
/******** Listing Of Tactics *********/
$tech_str .= $st[262];
//print about experience level of the ship.
if($exp > 0){
$tech_str .= sprintf($st[263], $experienced_ship[ship_name], $experienced_ship[class_name], $exp);
} else {
$tech_str .= $st[264];
}
//quick var to make sure can't run any tactics other than the 1 that's created! :)
$no_others = 1;
$tech_str .= "\n<br /><br /><br /><b>".$cw['confirmation']."</b>";
$form_str = "<FORM action=attack.php method=post name=tactic_choice>\n";
//only tactic available to the user is simple all-out attack.
//if($exp == 0 || $planet_attack == 1){
$confirm_str = $st[265];
$hidden_vars = "<input type=hidden name=gen_tactic_to_use value=1 />";
/*} else {
$confirm_str = "\n<p />Are you <b class='b1'>Certain</b> that you want to commence a fleet attack using the tactics selected above?";
$hidden_vars = "<input type='Reset' value='Reset' /> - ";
$tech_str .= "<input type=reset value='Reset Tactics' />";
}*/
//output final form.
$tech_str .= $confirm_str."\n";
$tech_str .= $form_str.$hidden_vars."\n<p /><input type=hidden name='target' value='$target' />\n<input type=hidden name='sure' value='yes' />\n<input type=\"Button\" value='".$cw['flee']."' onclick=\"javascript: history.back()\" /> - <input type='Submit' value='".$cw['attack']."!!!!!' />";
$tech_str .= "</FORM><p />".$st[266];
print_page($cw['attack_confirmation'],$tech_str);
/***********
* Third level checks. Ensure user isn't trying to use tactics that are not available to them.
***********/
//ensure user is actually allowed to use this tactic.
} elseif($gen_tactic_to_use - 1 > $exp && $planet_attack == 0) {
$tech_str = $st[267];
//other error checking would go here if tactics were complete.
/***********
* Processing of attack begins.
***********/
} else {
//set time limit to 60 seconds. This script could take a while to process.
set_time_limit(60);
$friends_killed = 0;
$targets_killed = 0;
//these two allow for easy change of the direction that ships are ordered (when loaded).
//This in turn has a dramatic effect on which ships get damaged first in combat (fighter heavy ships (generally warships) or fighter light ships (generally freighters)).
$dir_foe_ships = "desc";
$dir_friend_ships = "desc";
/**************
* Friendly ships into array
**************/
//select all friendly ships and dump them into an array.
db2("select s.*".$friendly_ship_counter_sql." order by fighters $dir_friend_ships");
$update_ships_sql_friends = "";
//loop through friendlies and put them all into a array
while($loop_friends = dbr2(1)) {
$loop_friends['approx_damage'] = $loop_friends['shields'] + $loop_friends['fighters'] + ($loop_friends['armour'] * $armour_multiplier);
$loop_friends['ship_allocated'] = 0;
$loop_friends['friend_foe'] = 1;
if($loop_friends['approx_damage'] < 1){//ship has no damage absorb cap. So kill it outright.
$loop_friends['ship_destroyed'] = 1;
} else {
$loop_friends['ship_destroyed'] = 0;
}
$friendly_ships[$loop_friends['ship_id']] = $loop_friends;
$update_ships_sql_friends .= "ship_id = '$loop_friends[ship_id]' || ";
$players_array[$loop_friends['login_id']]['total_fighters'] += $loop_friends['fighters'];
}
if($simulate_attack == 0){
//replace only the last '|| ' from the string so it can be used as a viable sql string.
if(!empty($update_ships_sql_friends)){
$update_ships_sql_friends = preg_replace("/\|\| $/", "", $update_ships_sql_friends);
//Make sure all ships are given a time-stamp so as they can't be used during attacking.
dbn("update ${db_name}_ships set ship_engaged = '$time_to_engage' where ".$update_ships_sql_friends);
$updated_friends_1 = mysql_affected_rows();
}
//something went wrong and there were no ships to update?!?!?!
if(empty($update_ships_sql_friends) || (isset($updated_friends_1) && $updated_friends_1 < 1)){
print_page($st[268]);
}
}
/**************
* Enemy ships into array
**************/
//no need to collect foes ships if attacking a planet.
if($planet_attack == 0){
//select all Enemy ships and dump them into an array.
db2("select s.*".$enemy_ship_counter_sql." group by s.ship_id order by fighters $dir_foe_ships");
$update_ships_sql_enemies = "";
//loop through friendlies and put them all into a array
while($loop_enemies = dbr2(1)) {
$loop_enemies['approx_damage'] = $loop_enemies['shields'] + $loop_enemies['fighters'] + ($loop_enemies['armour'] * $armour_multiplier);
$loop_enemies['ship_allocated'] = 0;
$loop_enemies['friend_foe'] = 2;
if($loop_enemies['approx_damage'] < 1){//ship has no damage absorb cap. So kill it outright.
$loop_enemies['ship_destroyed'] = 1;
} else {
$loop_enemies['ship_destroyed'] = 0;
}
$target_ships[$loop_enemies['ship_id']] = $loop_enemies;
$update_ships_sql_enemies .= "ship_id = '$loop_enemies[ship_id]' || ";
$players_array[$loop_enemies['login_id']]['total_fighters'] += $loop_enemies['fighters'];
}
if($simulate_attack == 0){
//replace only the last '|| ' from the string so it can be used as a viable sql string.
if(!empty($update_ships_sql_enemies)){
$update_ships_sql_enemies = preg_replace("/\|\| $/", "", $update_ships_sql_enemies);
//Make sure all ships are given a time-stamp so as they can't be used during attacking.
dbn("update ${db_name}_ships set ship_engaged = '$time_to_engage' where ".$update_ships_sql_enemies);
$updated_enemies_1 = mysql_affected_rows();
}
//something went wrong and there were no ships to update?!?!?!
if(empty($update_ships_sql_enemies) || (isset($updated_enemies_1) && $updated_enemies_1 < 1)){
print_page($st[269]);
}
}
//let's make a replica of the starting ships, for posterities sake (and report writing necessity).
$replica_of_ships = $friendly_ships + $target_ships;
//timestamp planets so they can't be used during the combat.
if(count($target_planets) > 0 && $simulate_attack == 0){
foreach($target_planets as $planet_id){
dbn("update ${db_name}_planets set planet_engaged = '$time_to_engage' where planet_id = '$planet_id'");
}
}
//planet attacking, so let's do some stuff to the planet.
} else {
//replica of ships (only friendlies, as target doesn't have ships).
$target_ships = array();
$replica_of_ships = $friendly_ships;
}
//a nice little tidy up.
unset($enemy_ship_counter_sql, $friendly_ship_counter_sql, $update_ships_sql_enemies, $time_to_engage, $loop_enemies, $loop_friends, $updated_enemies_1, $updated_friends_1);
//make a replica of planets (for some end-of-script processing).
$replica_of_planets = $target_planets;
/************************************************************************************
* Tactical processing begins
************************************************************************************/
//ensure don't play with a tactic that won't work for planet attacking.
if($planet_attack == 1){
$gen_tactic_to_use = 1;
}
//an array that stores the number of planetary fighers alloted to this battlegroup (key the same as the battlegroup it's linked with).
$battle_group_planets_array = array();
//the array that stores all the groups for combat.
$combat_array = array();
if(!isset($gen_tactic_to_use) || $gen_tactic_to_use < 1){
$gen_tactic_to_use = 1;
}
$gen_tactic_to_use = 1;
//A switch which contains all the different tactics.
switch ($gen_tactic_to_use){
//just using random attack, as there is no experience within the fleet.
case 1;
//fills the an array with a list of friendly ship ids, and set's their values to 1
$temp_storage_array_friend = array_keys($friendly_ships);
$temp_storage_array_friend = array_flip($temp_storage_array_friend);
$temp_storage_array_friend = array_map("set_friend",$temp_storage_array_friend);
if($planet_attack == 0){
//Same as above, but for enemy ships and sets their values to 2.
$temp_storage_array_foe = array_keys($target_ships);
if(count($target_planets) > 0){
array_unshift($temp_storage_array_foe, -1);
$battle_group_planets_array[] = array('fighters' => $total_planet_figs, 'planet_destroyed' => 0, 'approx_damage' => $total_planet_figs); //note: approx_damage is same as 'fighters', to simplify damage distribution.
}
$temp_storage_array_foe = array_flip($temp_storage_array_foe);
$temp_storage_array_foe = array_map("set_foe",$temp_storage_array_foe);
//add the planet(ary group).
} else {
$temp_storage_array_foe = array('-1' => 2);
$battle_group_planets_array[] = array('fighters' => $total_planet_figs, 'planet_destroyed' => 0, 'approx_damage' => $total_planet_figs);
}
$combat_array[] = $temp_storage_array_friend + $temp_storage_array_foe;
break;
//This tactic allows PO ships to take out the planets assisting fighters, whilst the rest of the players fleet distracts the enemy fleet.
//it can also be used in the other way - distract a planets fighters with a PO ship, whilst the players fleet decimates the enemy fleet.
case 10;
//only way can have PO ships at this point is if there's an assisting enemy planet.
$po_ship_power = 0;
$po_combat_array = array();
foreach($friendly_ships as $ship_id => $ship){
//begin setting any PO ships into a anti-planet group
if(config_check("po",$ship)){
$po_combat_array[$ship_id] = 1;
$po_ship_power ++;
} else {
$temp_storage_array_friend[$ship_id] = 1;
}
}
//if po ships and assisting planets, set all po figs against the planets.
if($po_ship_power > 0){
$po_combat_array[-1] = 2;
$combat_array[] = $po_combat_array;
}
//the assisting planets have the same key as the first entry in combat_array. This means if there are no PO ships (by some strange bug thingy), then they will match the rest of the ships, and it'll be a free-for-all (as normal).
$battle_group_planets_array[] = array('fighters' => $total_planet_figs, 'planet_destroyed' => 0, 'approx_damage' => $total_planet_figs);
$temp_storage_array_foe = array_map("set_foe",array_flip(array_keys($target_ships)));
$combat_array[] = $temp_storage_array_friend + $temp_storage_array_foe;
unset($po_combat_array, $po_ship_power);
break;
default;
write_to_error_log($st[272]);
break;
}
unset($temp_storage_array_friend, $temp_storage_array_foe);
/**************************************************************************************
* End of tactical Processing
**************************************************************************************/
/**************************************************************************************
* Beginning of Damage Processing
**************************************************************************************/
//ensure we actually have something in the combat array.
if(empty($combat_array)){
write_to_error_log("$ ".$st[273],$st[274]);
}
//start of short report
if($planet_attack == 1){
$short_str = "<br /><b class='b1'>{$players_array[$user['login_id']]['login_name_link']}</b> ".$st[275]." <b class='b1'>{$target_planets[$target]['planet_name']}</b> ".$cw['in_system']." #<b>$combat_loc</b>. <p />".$cw['participants']."";
} else {
$short_str = "<br /><b class='b1'>{$players_array[$user['login_id']]['login_name_link']}</b> ".$st[276]." #<b>$combat_loc</b>. <p />".$cw['participants'];
}
//start of advanced report.
if($simulate_attack == 0){
$tech_str = sprintf($st[277], $combat_loc, $total_attack_turn_cost);
} else {
$tech_str = $st[278];
}
$temp_str = make_table(array("", $cw['attacker']."(s)", $cw['defender']."(s)"));
$temp_str .= make_row(array("<b class='b1'>".$cw['players']."</b>", "<b>$friendly_details[user_count]</b> ($friends_name_str)", "<b>$target_details[user_count]</b> ($foes_name_str)"));
$temp_str .= make_row(array("<b class='b1'>".$cw['ships']."</b>", $friendly_details['ship_count'], $target_details['ship_count']));
$temp_str .= make_row(array("<b class='b1'>".$cw['ship_fighters']."</b>", $friendly_details['fighter_count'], $target_details['fighter_count']));
$temp_str .= make_row(array("<b class='b1'>".$cw['ship_weapon_systems']."</b>", $friendly_details['upgrade_count'], $target_details['upgrade_count']));
$temp_str .= make_row(array("<b class='b1'>".$cw['planets']."</b>", 0, count($target_planets)));
$temp_str .= make_row(array("<b class='b1'>".$cw['planet_fighters']."</b>", 0, $report_figs));
$temp_str .= "</table>";
$tech_str .= $temp_str;
$short_str .= $temp_str;
unset($temp_str, $report_figs);
/*********************************
!!!!Big processing loop begins!!!!
*********************************/
//loop through the combat array, and begin processing the ships.
foreach($combat_array as $battle_group_number => $battle_group_array) {
//Declaration of all the necassary variables.
$user_group = array('ship_count' => 0, 'fighters' => 0, 'shields' => 0, 'armour' => 0, 'speed' => 0, 'size' => 0, 'exp' => 0, 'config' => "", 'fighters_ship_count' => 0, 'shields_ship_count' => 0, 'armour_ship_count' => 0, 'points_lost' => 0);
$target_group = array('ship_count' => 0, 'fighters' => 0, 'shields' => 0, 'armour' => 0, 'speed' => 0, 'size' => 0, 'exp' => 0, 'config' => "", 'fighters_ship_count' => 0, 'shields_ship_count' => 0, 'armour_ship_count' => 0, 'points_lost' => 0, 'planets' => 0);
$u_bonus = array('num_ot' => 0, 'num_dt' => 0, 'num_pc' => 0, 'num_ew' => 0, 'dt' => 0, 'ot' => 0, 'pc' => 0, 'ewa' => 0, 'ewd' => 0);
$t_bonus = array('num_ot' => 0, 'num_dt' => 0, 'num_pc' => 0, 'num_ew' => 0, 'dt' => 0, 'ot' => 0, 'pc' => 0, 'ewa' => 0, 'ewd' => 0);
$po_ship_figs_friends = 0;
$po_ship_figs_foes = 0;
$so_ship_figs_friends = 0;
$so_ship_figs_foes = 0;
//set up the groups for the array.
foreach($battle_group_array as $ship_id => $friend_foe){
//dump friend into array
if($friend_foe == 1){
$user_group['ship_count']++;
$user_group['fighters'] += $friendly_ships[$ship_id]['fighters'];
$user_group['shields'] += $friendly_ships[$ship_id]['shields'];
$user_group['armour'] += $friendly_ships[$ship_id]['armour'];
$user_group['speed'] += $friendly_ships[$ship_id]['move_turn_cost'];
$user_group['size'] += $friendly_ships[$ship_id]['size'];
$user_group['exp'] += $friendly_ships[$ship_id]['points_killed'];
$user_group['config'] .= ":".$friendly_ships[$ship_id]['config'];
//if ship has figs/shields/armour, increase count of that type by 1 (for damage distro later)
$friendly_ships[$ship_id]['fighters'] > 0 ? $user_group['fighters_ship_count'] ++ : 1;
$friendly_ships[$ship_id]['shields'] > 0 ? $user_group['shields_ship_count'] ++ : 1;
$friendly_ships[$ship_id]['armour'] > 0 ? $user_group['armour_ship_count'] ++ : 1;
$u_bonus['num_ot'] += $friendly_ships[$ship_id]['num_ot'];
$u_bonus['num_dt'] += $friendly_ships[$ship_id]['num_dt'];
$u_bonus['num_pc'] += $friendly_ships[$ship_id]['num_pc'];
$u_bonus['num_ew'] += $friendly_ships[$ship_id]['num_ew'];
if(config_check("po",$friendly_ships[$ship_id])){
$po_ship_figs_friends += $friendly_ships[$ship_id]['fighters'];
} elseif(config_check("so",$friendly_ships[$ship_id])){
$so_ship_figs_friends += $friendly_ships[$ship_id]['fighters'];
}
//dump foe into array
} elseif($friend_foe == 2) {
//playing with planet data. So had best be careful.
if($ship_id == -1){
$target_group['planets'] = 1;
$target_group['fighters'] += $battle_group_planets_array[$battle_group_number]['fighters'];
$target_group['fighters_ship_count'] ++;
continue 1;
}
$target_group['ship_count']++;
$target_group['fighters'] += $target_ships[$ship_id]['fighters'];
$target_group['shields'] += $target_ships[$ship_id]['shields'];
$target_group['armour'] += $target_ships[$ship_id]['armour'];
$target_group['speed'] += $target_ships[$ship_id]['move_turn_cost'];
$target_group['size'] += $target_ships[$ship_id]['size'];