1 | <?php |
---|
2 | require_once('common/includes/class.corp.php'); |
---|
3 | require_once('common/includes/class.alliance.php'); |
---|
4 | require_once('common/includes/class.killlist.php'); |
---|
5 | require_once('common/includes/class.killlisttable.php'); |
---|
6 | require_once('common/includes/class.killsummarytable.php'); |
---|
7 | |
---|
8 | if (!$kll_id = intval($_GET['kll_id'])) |
---|
9 | { |
---|
10 | echo 'No valid kill id specified'; |
---|
11 | exit; |
---|
12 | } |
---|
13 | |
---|
14 | $page = new Page('Related kills & losses'); |
---|
15 | |
---|
16 | // this is a fast query to get the system and timestamp |
---|
17 | $rqry = new DBQuery(); |
---|
18 | $rsql = 'SELECT kll_timestamp, kll_system_id from kb3_kills where kll_id = '.$kll_id; |
---|
19 | $rqry->execute($rsql); |
---|
20 | $rrow = $rqry->getRow(); |
---|
21 | $system = new SolarSystem($rrow['kll_system_id']); |
---|
22 | |
---|
23 | // now we get all kills in that system for +-12 hours |
---|
24 | $query = 'SELECT kll.kll_timestamp AS ts FROM kb3_kills kll WHERE kll.kll_system_id='.$rrow['kll_system_id'].' |
---|
25 | AND kll.kll_timestamp <= date_add( \''.$rrow['kll_timestamp'].'\', INTERVAL \'12\' HOUR ) |
---|
26 | AND kll.kll_timestamp >= date_sub( \''.$rrow['kll_timestamp'].'\', INTERVAL \'12\' HOUR ) |
---|
27 | ORDER BY kll.kll_timestamp ASC'; |
---|
28 | $qry = new DBQuery(); |
---|
29 | $qry->execute($query); |
---|
30 | $ts = array(); |
---|
31 | while ($row = $qry->getRow()) |
---|
32 | { |
---|
33 | $time = strtotime($row['ts']); |
---|
34 | $ts[intval(date('H', $time))][] = $row['ts']; |
---|
35 | } |
---|
36 | |
---|
37 | // this tricky thing looks for gaps of more than 1 hour and creates an intersection |
---|
38 | $baseh = date('H', strtotime($rrow['kll_timestamp'])); |
---|
39 | $maxc = count($ts); |
---|
40 | $times = array(); |
---|
41 | for ($i = 0; $i < $maxc; $i++) |
---|
42 | { |
---|
43 | $h = ($baseh+$i) % 24; |
---|
44 | if (!isset($ts[$h])) |
---|
45 | { |
---|
46 | break; |
---|
47 | } |
---|
48 | foreach ($ts[$h] as $timestamp) |
---|
49 | { |
---|
50 | $times[] = $timestamp; |
---|
51 | } |
---|
52 | } |
---|
53 | for ($i = 0; $i < $maxc; $i++) |
---|
54 | { |
---|
55 | $h = ($baseh-$i) % 24; |
---|
56 | if ($h < 0) |
---|
57 | { |
---|
58 | $h += 24; |
---|
59 | } |
---|
60 | if (!isset($ts[$h])) |
---|
61 | { |
---|
62 | break; |
---|
63 | } |
---|
64 | foreach ($ts[$h] as $timestamp) |
---|
65 | { |
---|
66 | $times[] = $timestamp; |
---|
67 | } |
---|
68 | } |
---|
69 | unset($ts); |
---|
70 | asort($times); |
---|
71 | |
---|
72 | // we got 2 resulting timestamps |
---|
73 | $firstts = array_shift($times); |
---|
74 | $lastts = array_pop($times); |
---|
75 | |
---|
76 | $kslist = new KillList(); |
---|
77 | $kslist->setOrdered(true); |
---|
78 | $kslist->addSystem($system); |
---|
79 | $kslist->setStartDate($firstts); |
---|
80 | $kslist->setEndDate($lastts); |
---|
81 | involved::load($kslist,'kill'); |
---|
82 | |
---|
83 | $lslist = new KillList(); |
---|
84 | $lslist->setOrdered(true); |
---|
85 | $lslist->addSystem($system); |
---|
86 | $lslist->setStartDate($firstts); |
---|
87 | $lslist->setEndDate($lastts); |
---|
88 | involved::load($lslist,'loss'); |
---|
89 | |
---|
90 | $summarytable = new KillSummaryTable($kslist, $lslist); |
---|
91 | $summarytable->setBreak(config::get('summarytable_rowcount')); |
---|
92 | $html .= $summarytable->generate(); |
---|
93 | |
---|
94 | $klist = new KillList(); |
---|
95 | $klist->setOrdered(true); |
---|
96 | $klist->addSystem($system); |
---|
97 | $klist->setStartDate($firstts); |
---|
98 | $klist->setEndDate($lastts); |
---|
99 | involved::load($klist,'kill'); |
---|
100 | |
---|
101 | $llist = new KillList(); |
---|
102 | $llist->setOrdered(true); |
---|
103 | $llist->addSystem($system); |
---|
104 | $llist->setStartDate($firstts); |
---|
105 | $llist->setEndDate($lastts); |
---|
106 | involved::load($llist,'loss'); |
---|
107 | |
---|
108 | if ($_GET['scl_id']) |
---|
109 | { |
---|
110 | $klist->addVictimShipClass(new ShipClass($_GET['scl_id'])); |
---|
111 | $llist->addVictimShipClass(new ShipClass($_GET['scl_id'])); |
---|
112 | } |
---|
113 | |
---|
114 | function handle_involved($kill, $side) |
---|
115 | { |
---|
116 | global $pilots; |
---|
117 | |
---|
118 | // we need to get all involved pilots, killlists dont supply them |
---|
119 | $qry = new DBQuery(); |
---|
120 | $sql = "select ind_plt_id, ind_crp_id, ind_all_id, ind_sec_status, ind_shp_id, ind_wep_id, |
---|
121 | typeName, plt_name, crp_name, all_name, shp_name, scl_points, scl_id, shp_externalid |
---|
122 | from kb3_inv_detail |
---|
123 | left join kb3_invtypes on ind_wep_id=typeID |
---|
124 | left join kb3_pilots on ind_plt_id=plt_id |
---|
125 | left join kb3_corps on ind_crp_id=crp_id |
---|
126 | left join kb3_alliances on ind_all_id=all_id |
---|
127 | left join kb3_ships on ind_shp_id=shp_id |
---|
128 | left join kb3_ship_classes on shp_class=scl_id |
---|
129 | where ind_kll_id = ".$kill->getID()." |
---|
130 | order by ind_order"; |
---|
131 | |
---|
132 | $qry->execute($sql); |
---|
133 | while ($row = $qry->getRow()) |
---|
134 | { |
---|
135 | //$ship = new Ship($row['ind_shp_id']); |
---|
136 | //$shipc = $ship->getClass(); |
---|
137 | |
---|
138 | // check for npc names (copied from pilot class) |
---|
139 | $pos = strpos($row['plt_name'], "#"); |
---|
140 | if ($pos !== false) |
---|
141 | { |
---|
142 | $name = explode("#", $row['plt_name']); |
---|
143 | $item = new Item($name[2]); |
---|
144 | $row['plt_name'] = $item->getName(); |
---|
145 | } |
---|
146 | |
---|
147 | // dont set pods as ships for pilots we already have |
---|
148 | if (isset($pilots[$side][$row['ind_plt_id']])) |
---|
149 | { |
---|
150 | if ($row['scl_id'] == 18 || $row['scl_id'] == 2) |
---|
151 | { |
---|
152 | continue; |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | // search for ships with the same id |
---|
157 | if (isset($pilots[$side][$row['ind_plt_id']])) |
---|
158 | { |
---|
159 | foreach ($pilots[$side][$row['ind_plt_id']] as $id => $_ship) |
---|
160 | { |
---|
161 | if ($row['ind_shp_id'] == $_ship['sid']) |
---|
162 | { |
---|
163 | // we already got that pilot in this ship, continue |
---|
164 | continue 2; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | $shipimage = IMG_URL.'/ships/32_32/'.$row['shp_externalid'].'.png'; |
---|
170 | $pilots[$side][$row['ind_plt_id']][] = array('name' => $row['plt_name'], 'sid' => $row['ind_shp_id'], |
---|
171 | 'spic' => $shipimage, 'aid' => $row['ind_all_id'], 'ts' => strtotime($kill->getTimeStamp()), |
---|
172 | 'corp' =>$row['crp_name'], 'alliance' => $row['all_name'], 'scl' => $row['scl_points'], |
---|
173 | 'ship' => $row['shp_name'], 'weapon' => $row['itm_name'], 'cid' => $row['ind_crp_id']); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | function handle_destroyed($kill, $side) |
---|
178 | { |
---|
179 | global $destroyed, $pilots; |
---|
180 | |
---|
181 | $destroyed[$kill->getID()] = $kill->getVictimID(); |
---|
182 | |
---|
183 | $ship = new Ship(); |
---|
184 | $ship->lookup($kill->getVictimShipName()); |
---|
185 | $shipc = $ship->getClass(); |
---|
186 | |
---|
187 | $ts = strtotime($kill->getTimeStamp()); |
---|
188 | |
---|
189 | // mark the pilot as podded |
---|
190 | if ($shipc->getID() == 18 || $shipc->getID() == 2) |
---|
191 | { |
---|
192 | // increase the timestamp of a podkill by 1 so its after the shipkill |
---|
193 | $ts++; |
---|
194 | global $pods; |
---|
195 | $pods[$kill->getID()] = $kill->getVictimID(); |
---|
196 | |
---|
197 | // return when we've added him already |
---|
198 | if (isset($pilots[$side][$kill->getVictimId()])) |
---|
199 | { |
---|
200 | #return; |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | // search for ships with the same id |
---|
205 | if (isset($pilots[$side][$kill->getVictimId()])) |
---|
206 | { |
---|
207 | foreach ($pilots[$side][$kill->getVictimId()] as $id => $_ship) |
---|
208 | { |
---|
209 | if ($ship->getID() == $_ship['sid']) |
---|
210 | { |
---|
211 | $pilots[$side][$kill->getVictimId()][$id]['destroyed'] = true; |
---|
212 | |
---|
213 | if (!isset($pilots[$side][$kill->getVictimId()][$id]['kll_id'])) |
---|
214 | { |
---|
215 | $pilots[$side][$kill->getVictimId()][$id]['kll_id'] = $kill->getID(); |
---|
216 | } |
---|
217 | return; |
---|
218 | } |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | $pilots[$side][$kill->getVictimId()][] = array('name' => $kill->getVictimName(), 'kll_id' => $kill->getID(), |
---|
223 | 'spic' => $ship->getImage(32), 'scl' => $shipc->getPoints(), 'destroyed' => true, |
---|
224 | 'corp' => $kill->getVictimCorpName(), 'alliance' => $kill->getVictimAllianceName(), 'aid' => $kill->getVictimAllianceID(), |
---|
225 | 'ship' => $kill->getVictimShipname(), 'sid' => $ship->getID(), 'cid' => $kill->getVictimCorpID(), 'ts' => $ts); |
---|
226 | } |
---|
227 | |
---|
228 | $destroyed = $pods = array(); |
---|
229 | $pilots = array('a' => array(), 'e' => array()); |
---|
230 | $kslist->rewind(); |
---|
231 | $classified = false; |
---|
232 | while ($kill = $kslist->getKill()) |
---|
233 | { |
---|
234 | handle_involved($kill, 'a'); |
---|
235 | handle_destroyed($kill, 'e'); |
---|
236 | if ($kill->isClassified()) |
---|
237 | { |
---|
238 | $classified = true; |
---|
239 | } |
---|
240 | } |
---|
241 | $lslist->rewind(); |
---|
242 | while ($kill = $lslist->getKill()) |
---|
243 | { |
---|
244 | handle_involved($kill, 'e'); |
---|
245 | handle_destroyed($kill, 'a'); |
---|
246 | if ($kill->isClassified()) |
---|
247 | { |
---|
248 | $classified = true; |
---|
249 | } |
---|
250 | } |
---|
251 | function cmp_func($a, $b) |
---|
252 | { |
---|
253 | // select the biggest fish of that pilot |
---|
254 | $t_scl = 0; |
---|
255 | foreach ($a as $i => $ai) |
---|
256 | { |
---|
257 | if ($ai['scl'] > $t_scl) |
---|
258 | { |
---|
259 | $t_scl = $ai['scl']; |
---|
260 | $cur_i = $i; |
---|
261 | } |
---|
262 | } |
---|
263 | $a = $a[$cur_i]; |
---|
264 | |
---|
265 | $t_scl = 0; |
---|
266 | foreach ($b as $i => $bi) |
---|
267 | { |
---|
268 | if ($bi['scl'] > $t_scl) |
---|
269 | { |
---|
270 | $t_scl = $bi['scl']; |
---|
271 | $cur_i = $i; |
---|
272 | } |
---|
273 | } |
---|
274 | $b = $b[$cur_i]; |
---|
275 | |
---|
276 | if ($a['scl'] > $b['scl']) |
---|
277 | { |
---|
278 | return -1; |
---|
279 | } |
---|
280 | // sort after points, shipname, pilotname |
---|
281 | elseif ($a['scl'] == $b['scl']) |
---|
282 | { |
---|
283 | if ($a['ship'] == $b['ship']) |
---|
284 | { |
---|
285 | if ($a['name'] > $b['name']) |
---|
286 | { |
---|
287 | return 1; |
---|
288 | } |
---|
289 | return -1; |
---|
290 | } |
---|
291 | elseif ($a['ship'] > $b['ship']) |
---|
292 | { |
---|
293 | return 1; |
---|
294 | } |
---|
295 | return -1; |
---|
296 | } |
---|
297 | return 1; |
---|
298 | } |
---|
299 | |
---|
300 | function is_destroyed($pilot) |
---|
301 | { |
---|
302 | global $destroyed; |
---|
303 | |
---|
304 | if ($result = array_search((string)$pilot, $destroyed)) |
---|
305 | { |
---|
306 | global $smarty; |
---|
307 | |
---|
308 | $smarty->assign('kll_id', $result); |
---|
309 | return true; |
---|
310 | } |
---|
311 | return false; |
---|
312 | } |
---|
313 | |
---|
314 | function podded($pilot) |
---|
315 | { |
---|
316 | global $pods; |
---|
317 | |
---|
318 | if ($result = array_search((string)$pilot, $pods)) |
---|
319 | { |
---|
320 | global $smarty; |
---|
321 | |
---|
322 | $smarty->assign('pod_kll_id', $result); |
---|
323 | return true; |
---|
324 | } |
---|
325 | return false; |
---|
326 | } |
---|
327 | |
---|
328 | function cmp_ts_func($a, $b) |
---|
329 | { |
---|
330 | if ($a['ts'] < $b['ts']) |
---|
331 | { |
---|
332 | return -1; |
---|
333 | } |
---|
334 | return 1; |
---|
335 | } |
---|
336 | |
---|
337 | // sort pilot ships, order pods after ships |
---|
338 | foreach ($pilots as $side => $pilot) |
---|
339 | { |
---|
340 | foreach ($pilot as $id => $kll) |
---|
341 | { |
---|
342 | usort($pilots[$side][$id], 'cmp_ts_func'); |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | // sort arrays, ships with high points first |
---|
347 | uasort($pilots['a'], 'cmp_func'); |
---|
348 | uasort($pilots['e'], 'cmp_func'); |
---|
349 | |
---|
350 | // now get the pods out and mark the ships the've flown as podded |
---|
351 | foreach ($pilots as $side => $pilot) |
---|
352 | { |
---|
353 | foreach ($pilot as $id => $kll) |
---|
354 | { |
---|
355 | $max = count($kll); |
---|
356 | for ($i = 0; $i < $max; $i++) |
---|
357 | { |
---|
358 | if ($kll[$i]['ship'] == 'Capsule') |
---|
359 | { |
---|
360 | if (isset($kll[$i-1]['sid']) && isset($kll[$i]['destroyed'])) |
---|
361 | { |
---|
362 | $pilots[$side][$id][$i-1]['podded'] = true; |
---|
363 | $pilots[$side][$id][$i-1]['podid'] = $kll[$i]['kll_id']; |
---|
364 | unset($pilots[$side][$id][$i]); |
---|
365 | } |
---|
366 | else |
---|
367 | { |
---|
368 | // now sort out all pods from pilots who previously flown a real ship |
---|
369 | $valid_ship = false; |
---|
370 | foreach ($kll as $ship) |
---|
371 | { |
---|
372 | if ($ship['ship'] != 'Capsule') |
---|
373 | { |
---|
374 | $valid_ship = true; |
---|
375 | break; |
---|
376 | } |
---|
377 | } |
---|
378 | if ($valid_ship) |
---|
379 | { |
---|
380 | unset($pilots[$side][$id][$i]); |
---|
381 | } |
---|
382 | } |
---|
383 | } |
---|
384 | } |
---|
385 | } |
---|
386 | } |
---|
387 | |
---|
388 | $smarty->assign_by_ref('pilots_a', $pilots['a']); |
---|
389 | $smarty->assign_by_ref('pilots_e', $pilots['e']); |
---|
390 | |
---|
391 | $pod = new Ship(6); |
---|
392 | $smarty->assign('podpic', $pod->getImage(32)); |
---|
393 | $smarty->assign('friendlycnt', count($pilots['a'])); |
---|
394 | $smarty->assign('hostilecnt', count($pilots['e'])); |
---|
395 | if ($classified) |
---|
396 | { |
---|
397 | $smarty->assign('system', 'Classified System'); |
---|
398 | } |
---|
399 | else |
---|
400 | { |
---|
401 | $smarty->assign('system', $system->getName()); |
---|
402 | } |
---|
403 | $smarty->assign('firstts', $firstts); |
---|
404 | $smarty->assign('lastts', $lastts); |
---|
405 | |
---|
406 | $html .= $smarty->fetch(get_tpl('battle_overview')); |
---|
407 | |
---|
408 | $html .= '<div class="kb-kills-header">Battle Statistics</div>'; |
---|
409 | $html .= "<table class=kb-table width=\"100%\" border=\"0\" cellspacing=1><tr class=kb-table-row-even>"; |
---|
410 | |
---|
411 | $kill_summary = new KillSummaryTable($klist, $llist); |
---|
412 | $summary_html = $kill_summary->generate(); |
---|
413 | |
---|
414 | $html .= "<td class=kb-table-cell width=180><b>Kills:</b></td><td class=kl-kill>".$kill_summary->getTotalKills()."</td></tr>"; |
---|
415 | $html .= "<tr class=kb-table-row-even><td class=kb-table-cell><b>Losses:</b></td><td class=kl-loss>".$kill_summary->getTotalLosses()."</td></tr>"; |
---|
416 | $html .= "<tr class=kb-table-row-even><td class=kb-table-cell><b>Damage done (ISK):</b></td><td class=kl-kill>".round($kill_summary->getTotalKillISK()/1000000, 2)."M</td></tr>"; |
---|
417 | $html .= "<tr class=kb-table-row-even><td class=kb-table-cell><b>Damage received (ISK):</b></td><td class=kl-loss>".round($kill_summary->getTotalLossISK()/1000000, 2)."M</td></tr>"; |
---|
418 | if ($kill_summary->getTotalKillISK()) |
---|
419 | { |
---|
420 | $efficiency = round($kill_summary->getTotalKillISK() / ($kill_summary->getTotalKillISK() + $kill_summary->getTotalLossISK()) * 100, 2); |
---|
421 | } |
---|
422 | else |
---|
423 | { |
---|
424 | $efficiency = 0; |
---|
425 | } |
---|
426 | |
---|
427 | $html .= "<tr class=kb-table-row-even><td class=kb-table-cell><b>Efficiency:</b></td><td class=kb-table-cell><b>" . $efficiency . "%</b></td></tr>"; |
---|
428 | |
---|
429 | $html .= "</table>"; |
---|
430 | $html .= "<br/>"; |
---|
431 | |
---|
432 | |
---|
433 | $html .= "<div class=\"kb-kills-header\">Related kills</div>"; |
---|
434 | |
---|
435 | $ktable = new KillListTable($klist); |
---|
436 | $html .= $ktable->generate(); |
---|
437 | |
---|
438 | $html .= "<div class=\"kb-losses-header\">Related losses</div>"; |
---|
439 | |
---|
440 | $ltable = new KillListTable($llist); |
---|
441 | $html .= $ltable->generate(); |
---|
442 | |
---|
443 | $menubox = new Box("Menu"); |
---|
444 | $menubox->setIcon("menu-item.gif"); |
---|
445 | $menubox->addOption("caption", "View"); |
---|
446 | $menubox->addOption("link", "Back to Killmail", "?a=kill_detail&kll_id=".$_GET['kll_id']); |
---|
447 | $menubox->addOption("link", "Kills & losses", "?a=kill_related&kll_id=".$_GET['kll_id']); |
---|
448 | |
---|
449 | if($page->isAdmin()){ |
---|
450 | $menubox->addOption("caption","Admin"); |
---|
451 | $menubox->addOption("link", "Forum Summary", "javascript:sndReq('index.php?a=forum_post&kll_id=".$_GET['kll_id']."');ReverseContentDisplay('popup')"); |
---|
452 | } |
---|
453 | $page->addContext($menubox->generate()); |
---|
454 | |
---|
455 | $page->setContent($html); |
---|
456 | $page->generate(); |
---|
457 | ?> |
---|