forked from stfc2/Scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoves_action_42.php
More file actions
279 lines (225 loc) · 10.4 KB
/
moves_action_42.php
File metadata and controls
279 lines (225 loc) · 10.4 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
<?php
/*
This file is part of STFC.
Copyright 2006-2007 by Michael Krauss (info@stfc2.de) and Tobias Gafner
STFC is based on STGC,
Copyright 2003-2007 by Florian Brede (florian_brede@hotmail.com) and Philipp Schmidt
STFC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
STFC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class moves_action_42 extends moves_common {
function _action_main() {
// #############################################################################
// Data of the attacker
$sql = 'SELECT fleet_id
FROM ship_fleets
WHERE planet_id = '.$this->move['dest'].' AND
user_id = '.$this->move['user_id'].' AND
alert_phase >= '.ALERT_PHASE_YELLOW;
if(!$q_atk_st_fleets = $this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not query stationated attacker fleet data! SKIP');
}
$atk_fleet_ids_str = $this->fleet_ids_str;
while($_fleet = $this->db->fetchrow($q_atk_st_fleets)) {
$atk_fleet_ids_str .= ','.$_fleet['fleet_id'];
}
$sql = 'SELECT '.$this->get_combat_query_fleet_columns().'
FROM (ship_fleets f)
INNER JOIN user u ON u.user_id = f.user_id
WHERE f.fleet_id IN ('.$atk_fleet_ids_str.')';
if(($atk_fleets = $this->db->queryrowset($sql)) === false) {
return $this->log(MV_M_DATABASE, 'Could not query attackers fleets data! SKIP');}
// #############################################################################
// Data of 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($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)
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)
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'];
}
if($this->do_ship_combat($atk_fleet_ids_str, implode(',', $dfd_fleet_ids), MV_COMBAT_LEVEL_ORBITAL) == MV_EXEC_ERROR) {
$this->log(MV_M_DATABASE, 'Move Action 42: Something went wrong with this fight!');
return MV_EXEC_ERROR;
}
// #############################################################################
// Possibly return the remaining ships again to the attacker
if($this->cmb[MV_CMB_WINNER] == MV_CMB_ATTACKER) {
$sql = 'SELECT COUNT(ship_id) AS n_ships
FROM ships
WHERE fleet_id IN ('.$this->fleet_ids_str.')';
if(($ships_alive = $this->db->queryrow($sql)) === false) {
return $this->log(MV_M_DATABASE, 'Could not query ships count! SKIP');
}
$sql = 'INSERT INTO scheduler_shipmovement (user_id, move_status, move_exec_started, start, dest, total_distance, remaining_distance, tick_speed, move_begin, move_finish, n_ships, action_code, action_data)
VALUES ('.$this->move['user_id'].', 0, 0, '.$this->move['dest'].', '.$this->move['start'].', '.$this->move['total_distance'].', '.$this->move['total_distance'].', '.$this->move['tick_speed'].', '.$this->CURRENT_TICK.', '.($this->CURRENT_TICK + ($this->move['move_finish'] - $this->move['move_begin'])).', '.$ships_alive['n_ships'].', 12, "'.serialize(42).'")';
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not create new movement for return! SKIP');
}
$new_move_id = $this->db->insert_id();
if(!$new_move_id) {
return $this->log(MV_M_ERROR, 'Could not get new move id! SKIP');
}
$sql = 'UPDATE ship_fleets
SET move_id = '.$new_move_id.'
WHERE fleet_id IN ('.$this->fleet_ids_str.')';
if(!$this->db->query($sql)) {
return $this->log(MV_M_DATABASE, 'Could not update fleets movement data! SKIP');
}
// #############################################################################
// 02/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;
}
switch($this->dest['language'])
{
case 'GER':
$dfd_title = 'Schwerer Angriff auf '.$this->dest['planet_name'];
break;
case 'ITA':
$dfd_title = 'Attacco fatale su '.$this->dest['planet_name'];
break;
default:
$dfd_title = 'Fatal attack on '.$this->dest['planet_name'];
break;
}
}
else {
// #############################################################################
// 02/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;
}
switch($this->dest['language'])
{
case 'GER':
$dfd_title = 'Verteidigung von '.$this->dest['planet_name'].' erfolgreich';
break;
case 'ITA':
$dfd_title = 'Difesa di '.$this->dest['planet_name'].' riuscita';
break;
default:
$dfd_title = 'Defence of '.$this->dest['planet_name'].' successful';
break;
}
}
// #############################################################################
// Write logbook
$log1_data = array(41, $this->move['user_id'], $this->move['start'], $this->start['planet_name'], $this->start['user_id'], $this->move['dest'], $this->dest['planet_name'], $this->dest['user_id'], MV_CMB_ATTACKER, ( ($this->cmb[MV_CMB_WINNER] == MV_CMB_ATTACKER) ? 1 : 0 ), 0,0, $atk_fleets, $dfd_fleets);
$log2_data = array(41, $this->move['user_id'], $this->move['start'], $this->start['planet_name'], $this->start['user_id'], $this->move['dest'], $this->dest['planet_name'], $this->dest['user_id'], MV_CMB_DEFENDER, ( ($this->cmb[MV_CMB_WINNER] == MV_CMB_DEFENDER) ? 1 : 0 ), 0,0, $atk_fleets, $dfd_fleets, $this->cmb[MV_CMB_KILLS_PLANETARY]);
$log1_data[10] = $this->cmb[MV_CMB_KILLS_EXT];
$log2_data[10] = $this->cmb[MV_CMB_KILLS_EXT];
add_logbook_entry($this->move['user_id'], LOGBOOK_TACTICAL_2, $atk_title, $log1_data);
add_logbook_entry($this->dest['user_id'], LOGBOOK_TACTICAL_2, $dfd_title, $log2_data);
if($n_st_user > 0) {
$log2_data[2] = $this->move['dest'];
$log2_data[3] = $this->dest['planet_name'];
$log2_data[4] = $this->dest['user_id'];
$log2_data[5] = 0;
$log2_data[6] = 0;
$log2_data[7] = 0;
$log2_data[16] = 1;
for($i = 0; $i < $n_st_user; ++$i) {
// #############################################################################
// 02/04/08 - AC: Retrieve player language
$log_title = 'One of your allies defended '.$this->dest['planet_name'];
$sql = 'SELECT language FROM user WHERE user_id = '.$st_user[$i];
if(!($lang = $this->db->queryrow($sql))) {
$this->log(MV_M_DATABASE, 'Could not retrieve player language');
}
else
{
switch($lang['language'])
{
case 'GER':
$log_title = 'Verbündeten bei '.$this->dest['planet_name'].' verteidigt';
break;
case 'ITA':
$log_title = 'Difesa alleata presso '.$this->dest['planet_name'];
break;
}
}
add_logbook_entry($st_user[$i], LOGBOOK_TACTICAL_2, $log_title, $log2_data);
}
}
return MV_EXEC_OK;
}
}
?>