1 | <?php |
---|
2 | /* |
---|
3 | * |
---|
4 | * Rendering-Options: |
---|
5 | nn = no npc influence (disables dn) |
---|
6 | na = no influence computation (fast, includes nn+oa, disables ds) |
---|
7 | |
---|
8 | dn = display npc influence |
---|
9 | ds = display alliance bounding box |
---|
10 | dj = display jove regions |
---|
11 | |
---|
12 | or = omit region names |
---|
13 | oa = omit alliance names |
---|
14 | oj = omit jumplines |
---|
15 | oe = omit empire |
---|
16 | */ |
---|
17 | include('evedb.php'); |
---|
18 | |
---|
19 | set_time_limit(330); |
---|
20 | error_reporting(E_ALL ^ E_NOTICE); |
---|
21 | |
---|
22 | $date1 = '2007-06-28'; |
---|
23 | $date2 = '2007-08-15'; |
---|
24 | |
---|
25 | define('JOB_UPDATE', true); |
---|
26 | $copt = false; |
---|
27 | $edb->query('select * from maprendertarget where status=1'); |
---|
28 | if ($edb->num_rows() != 0) |
---|
29 | { |
---|
30 | // job running! |
---|
31 | return; |
---|
32 | } |
---|
33 | $edb->query('select id, date1, date2, options from maprendertarget where status=0 order by prio desc, added desc'); |
---|
34 | if ($edb->num_rows() == 0) |
---|
35 | { |
---|
36 | //echo 'No Job to do'; |
---|
37 | return; |
---|
38 | } |
---|
39 | $row = $edb->fetch_array(); |
---|
40 | if (JOB_UPDATE) |
---|
41 | { |
---|
42 | $edb->query('update maprendertarget set status=1 where id='.$row['id']); |
---|
43 | } |
---|
44 | $job_id = $row['id']; |
---|
45 | if ($row['options']) |
---|
46 | { |
---|
47 | $copt = array(); |
---|
48 | $tmp = explode(',', $row['options']); |
---|
49 | foreach ($tmp as $option) |
---|
50 | { |
---|
51 | $copt[$option] = $option; |
---|
52 | } |
---|
53 | ksort($copt); |
---|
54 | } |
---|
55 | |
---|
56 | $date1 = $row['date1']; |
---|
57 | $date2 = $row['date2']; |
---|
58 | |
---|
59 | $opt['width'] = 1800; |
---|
60 | $opt['height'] = 2048; |
---|
61 | $opt['x'] = 165; // shift all systems to the right |
---|
62 | $opt['y'] = -5; // downshift |
---|
63 | |
---|
64 | $opt['font'] = 'arial.ttf'; // the used font |
---|
65 | $opt['ally_font'] = 'arial.ttf'; // the used font for alliances |
---|
66 | $opt['sov_font'] = 'refsan.ttf'; // the used font for sov changes |
---|
67 | |
---|
68 | $opt['maxrange'] = 450; // max influence range in px |
---|
69 | $opt['influence'] = 10; // influence per system |
---|
70 | $opt['inf_mod_station'] = 6; // multiplicate influence for stations |
---|
71 | $opt['inf_mod_constcap'] = 2; // multiplier for constellation capital |
---|
72 | $opt['inf_mod_constsov'] = 1.2; // 20% more influence for sov3 |
---|
73 | $opt['inf_decay'] = 0.35; // multi for decaying influence over jumps |
---|
74 | $opt['sensitivity'] = 500; |
---|
75 | $opt['validInf'] = 0.03; // 0.023 pixel needs at least that much influence to be drawn |
---|
76 | |
---|
77 | $opt['jumplineAlpha'] = 98; // adjusts the alpha of all jumplines |
---|
78 | $opt['regionAlpha'] = 0x30; |
---|
79 | $opt['regionSize'] = 10; // textsize of the region names |
---|
80 | $opt['sovSize'] = 8; // textsize of the sovchanges |
---|
81 | $opt['exludeConstID'] = "'A821-A','UUA-F4','J7HZ-F'"; // do not draw jove regions, empty string to display again |
---|
82 | |
---|
83 | if (isset($copt['dj'])) |
---|
84 | { |
---|
85 | $opt['exludeConstID'] = ""; |
---|
86 | } |
---|
87 | if (isset($copt['ne'])) |
---|
88 | { |
---|
89 | $opt['exludeConstID'] .= "'Derelik','The Forge','Great Wildlands','Curse','Venal','Lonetrek','Tash-Murkon'," |
---|
90 | ."'Stain','Molden Heath','Heimatar','Sinq Laison','The Citadel','Devoid','Everyshore'," |
---|
91 | ."'The Bleak Lands','Syndicate','Metropolis','Domain','Solitude','Placid','Khanid'," |
---|
92 | ."'Kador','Aridia','Outer Ring','Essence','Kor-Azor','Genesis','Verge Vendor'"; |
---|
93 | } |
---|
94 | if ($opt['exludeConstID'] == "") |
---|
95 | { |
---|
96 | $opt['exludeConstID'] = ''; |
---|
97 | } |
---|
98 | |
---|
99 | // internals |
---|
100 | $image = imagecreatetruecolor($opt['width'], $opt['height']); |
---|
101 | $col = imagecolorallocate($image, 0, 0, 255); |
---|
102 | $pScale = 4.8445284569785E17/(($opt['height']-20)/2.15); |
---|
103 | $alliances = array(); |
---|
104 | $systems = $systems_id = array(); |
---|
105 | $jumps = array(); |
---|
106 | define('STATION', 'outpost'); // change when fixed in db |
---|
107 | |
---|
108 | function watch ($text, $time = 0) |
---|
109 | { |
---|
110 | if ($time) |
---|
111 | { |
---|
112 | $starttime = $time; |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | global $starttime; |
---|
117 | } |
---|
118 | list($msec, $sec) = explode(" ", $starttime); |
---|
119 | $starttime = microtime(); |
---|
120 | list($msec2, $sec2) = explode(" ", $starttime); |
---|
121 | $time = round(($msec2 + $sec2 - $sec - $msec)*1000, 2); |
---|
122 | //echo "TIME: needed $time ms for '$text'\n"; |
---|
123 | //flush(); |
---|
124 | } |
---|
125 | |
---|
126 | // save startup time |
---|
127 | $starttime = microtime(); |
---|
128 | $mtime = explode(" ",microtime()); |
---|
129 | $starttimeb = $mtime[1] + $mtime[0]; |
---|
130 | watch('startup'); |
---|
131 | |
---|
132 | function getColor() |
---|
133 | { |
---|
134 | global $alliances; |
---|
135 | |
---|
136 | $done = false; |
---|
137 | $t = explode(' ', microtime()); |
---|
138 | |
---|
139 | srand($t[0]*100000000); |
---|
140 | while (!$done) |
---|
141 | { |
---|
142 | $r = rand(0, 255); |
---|
143 | $g = rand(0, 255); |
---|
144 | $b = rand(0, 255); |
---|
145 | if ($r+$g+$b > 256 && $r+$g+$b < 512) |
---|
146 | { |
---|
147 | $done = true; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | return array('r' => $r, 'g' => $g, 'b' => $b); |
---|
152 | } |
---|
153 | |
---|
154 | // load alliances |
---|
155 | $t1 = $edb->query('SELECT distinct alliances.allianceID, name, allianceColor |
---|
156 | FROM alliances |
---|
157 | inner join mapsovereignty on alliances.allianceID = mapsovereignty.allianceID |
---|
158 | left join mapalliancecolors on alliances.allianceID = mapalliancecolors.allianceID |
---|
159 | where mapsovereignty.date >= '."'$date1' and mapsovereignty.date <= '$date2'"); |
---|
160 | $i = -1; |
---|
161 | $allianceIDtoA = array(); |
---|
162 | while ($row = $edb->fetch_array($t1)) |
---|
163 | { |
---|
164 | $r = (int)base_convert(substr($row['allianceColor'], 0, 2), 16, 10); |
---|
165 | $g = (int)base_convert(substr($row['allianceColor'], 2, 2), 16, 10); |
---|
166 | $b = (int)base_convert(substr($row['allianceColor'], 4, 2), 16, 10); |
---|
167 | if ($row['allianceColor']) |
---|
168 | { |
---|
169 | $color = array('r' => $r, 'g' => $g, 'b' => $b); |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | $color = getColor(); |
---|
174 | $col = base_convert($color['r'], 10, 16).base_convert($color['g'], 10, 16).base_convert($color['b'], 10, 16); |
---|
175 | $edb->query('INSERT INTO mapalliancecolors (allianceID, allianceColor) VALUE ('.$row['allianceID'].',\''.$col.'\')'); |
---|
176 | } |
---|
177 | $alliances[++$i] = array('name' => $row['name'], 'color' => $color, 'segments' => array()); |
---|
178 | $allianceIDtoA[$row['allianceID']] = $i; |
---|
179 | } |
---|
180 | |
---|
181 | // load solar systems |
---|
182 | $query = 'SELECT a.x, a.z, a.solarSystemID, d.allianceID, a.constellationID, a.regionID, b.solarSystemID as outpost, regionName, d.factionID, d.sovereigntyLevel |
---|
183 | FROM mapsolarsystems a |
---|
184 | inner join mapsovereignty d on a.solarSystemID = d.solarSystemID and `date` = \''.$date2.'\' |
---|
185 | left join mapregions c on a.regionID = c.regionID |
---|
186 | left join mapoutposts b on a.solarSystemID = b.solarSystemID and b.added < \''.$date1.'\' |
---|
187 | where regionName not in ('.$opt['exludeConstID'].')'; |
---|
188 | $edb->query($query); |
---|
189 | while ($row = $edb->fetch_array()) |
---|
190 | { |
---|
191 | $x = intval($row['x']/$pScale + $opt['width']/2 + $opt['x']); |
---|
192 | $y = intval($row['z']/$pScale + $opt['height']/2 + $opt['y']); |
---|
193 | unset($row['z']); |
---|
194 | $row['y'] = $y; |
---|
195 | $row['x'] = $x; |
---|
196 | |
---|
197 | if ($row['factionID']) |
---|
198 | { |
---|
199 | $row['allianceID'] = 0; |
---|
200 | } |
---|
201 | |
---|
202 | $row['influence'] = array(); |
---|
203 | $systems[$y][$x] = $row; |
---|
204 | $systems_id[$row['solarSystemID']] = &$systems[$y][$x];//$row;// |
---|
205 | } |
---|
206 | |
---|
207 | // load jumps |
---|
208 | $edb->query('SELECT fromSolarSystemID, toSolarSystemID FROM mapsolarsystemjumps'); |
---|
209 | while ($row = $edb->fetch_array()) |
---|
210 | { |
---|
211 | if ($systems_id[$row['fromSolarSystemID']] && $systems_id[$row['toSolarSystemID']]) |
---|
212 | { |
---|
213 | $jumps[$row['fromSolarSystemID']][] = $row['toSolarSystemID']; |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | // calculate influence |
---|
218 | // this function iterates recursively through the jumpgates |
---|
219 | function addInfluence($id, $value, $alliance, $level, $done) |
---|
220 | { |
---|
221 | if ($level >= 4) |
---|
222 | { |
---|
223 | return; |
---|
224 | } |
---|
225 | global $systems_id, $jumps, $opt; |
---|
226 | |
---|
227 | $systems_id[$id]['influence'][$alliance] += $value; |
---|
228 | |
---|
229 | if (is_array($jumps[$id]) && $level <= 3) |
---|
230 | { |
---|
231 | foreach ($jumps[$id] as $to) |
---|
232 | { |
---|
233 | if (in_array($to, $done)) |
---|
234 | { |
---|
235 | continue; |
---|
236 | } |
---|
237 | $done[] = $to; |
---|
238 | if ($systems_id[$to]['factionID'] == 0) |
---|
239 | { |
---|
240 | addInfluence($to, $value*$opt['inf_decay'], $alliance, $level+1, $done); |
---|
241 | } |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | foreach ($systems_id as $id => $system) |
---|
247 | { |
---|
248 | $influence = $opt['influence']; |
---|
249 | $level = 2; |
---|
250 | |
---|
251 | if ($system[STATION]) |
---|
252 | { |
---|
253 | $influence *= $opt['inf_mod_station']; |
---|
254 | $level = 1; |
---|
255 | } |
---|
256 | if ($system['sovereigntyLevel'] == 4) |
---|
257 | { |
---|
258 | $influence *= $opt['inf_mod_constcap']; |
---|
259 | $level = 0; |
---|
260 | } |
---|
261 | elseif ($system['sovereigntyLevel'] == 3) |
---|
262 | { |
---|
263 | $influence *= $opt['inf_mod_constsov']; |
---|
264 | } |
---|
265 | |
---|
266 | if ($system['allianceID'] != 0) |
---|
267 | { |
---|
268 | addInfluence($id, $influence, $allianceIDtoA[$system['allianceID']], $level, array()); |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | // load npc data |
---|
273 | if (!isset($copt['nn'])) |
---|
274 | { |
---|
275 | $edb->query('SELECT solarSystemID, influence FROM mapinfluenceinject'); |
---|
276 | if (isset($copt['dn'])) |
---|
277 | { |
---|
278 | $alliances[] = array('name' => 'NPC', 'segments' => array(), 'color' => array('r' => 50, 'g' => 255, 'b' => 50)); |
---|
279 | } |
---|
280 | else |
---|
281 | { |
---|
282 | $alliances[] = array('npc' => true); |
---|
283 | } |
---|
284 | |
---|
285 | $ak = array_keys($alliances); |
---|
286 | $npc_id = array_pop($ak); |
---|
287 | while ($row = $edb->fetch_array()) |
---|
288 | { |
---|
289 | if (!isset($systems_id[$row['solarSystemID']])) |
---|
290 | { |
---|
291 | continue; |
---|
292 | } |
---|
293 | |
---|
294 | $s = &$systems_id[$row['solarSystemID']]; |
---|
295 | |
---|
296 | //imagefilledellipse($image, $s['x'], $s['y'], 5, 5, $color); |
---|
297 | addInfluence($row['solarSystemID'], $row['influence'], $npc_id, 3, array()); |
---|
298 | } |
---|
299 | } |
---|
300 | watch('loading'); |
---|
301 | |
---|
302 | // opne the textfile to the c program and dump our config |
---|
303 | $fp = fopen('evemap_systems.data', 'w'); |
---|
304 | fwrite($fp, 'c '.$opt['height'].' '.$opt['width'].' '.$opt['maxrange'].' '.$opt['sensitivity'].' '.$opt['validInf'].' '.(count($alliances)+1)."\r\n"); |
---|
305 | |
---|
306 | if ($npc_id) |
---|
307 | { |
---|
308 | $blindinfluence = array(1883 => 565, |
---|
309 | 1778 => 621, |
---|
310 | 1830 => 588, |
---|
311 | 1922 => 552, |
---|
312 | 1458 => 622, |
---|
313 | 1699 => 622, |
---|
314 | 1250 => 285, |
---|
315 | 1954 => 510); |
---|
316 | foreach ($blindinfluence as $y => $x) |
---|
317 | { |
---|
318 | $systems[$y] = array($x => array('influence' => array($npc_id => 50))); |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | // dump all systems with influence to the textfile |
---|
323 | // important: sort by y+x so the C loops can exit early |
---|
324 | foreach ($systems as $y => $arr) |
---|
325 | { |
---|
326 | ksort($systems[$y]); |
---|
327 | } |
---|
328 | ksort($systems); |
---|
329 | |
---|
330 | $systems_sov = array(); |
---|
331 | foreach ($systems as $y => $arr) |
---|
332 | { |
---|
333 | foreach ($arr as $x => $system) |
---|
334 | { |
---|
335 | if (count($system['influence'])) |
---|
336 | { |
---|
337 | $systems_sov[$y][$x] = &$systems[$y][$x]; |
---|
338 | |
---|
339 | fwrite($fp, 's '.$x.' '.$y."\r\n"); |
---|
340 | foreach ($system['influence'] as $all => $val) |
---|
341 | { |
---|
342 | fwrite($fp, 'i '.$all.' '.$val." \r\n"); |
---|
343 | } |
---|
344 | } |
---|
345 | } |
---|
346 | } |
---|
347 | fclose($fp); |
---|
348 | |
---|
349 | // remove the blind influence again |
---|
350 | if ($npc_id) |
---|
351 | { |
---|
352 | foreach ($blindinfluence as $y => $x) |
---|
353 | { |
---|
354 | unset($systems[$y][$x]); |
---|
355 | unset($systems_sov[$y][$x]); |
---|
356 | if (count($systems[$y]) == 0) |
---|
357 | { |
---|
358 | unset($systems[$y]); |
---|
359 | unset($systems_sov[$y]); |
---|
360 | } |
---|
361 | } |
---|
362 | } |
---|
363 | |
---|
364 | function paintRow($y) |
---|
365 | { |
---|
366 | global $image, $alliances, $curBorder, $curRow, $prevRow, $opt, $nameStack, $segID; |
---|
367 | |
---|
368 | $curA = -1; |
---|
369 | $segments = array(); |
---|
370 | foreach ($prevRow as $x => $last) |
---|
371 | { |
---|
372 | if ($y > 0) |
---|
373 | { |
---|
374 | if (!isset($prevRow[$x+1][0]) || !isset($prevRow[$x-1][0])) |
---|
375 | { |
---|
376 | $curA = -2; |
---|
377 | } |
---|
378 | if ($curA != $last[0]) |
---|
379 | { |
---|
380 | if ($curA != -1) |
---|
381 | { |
---|
382 | $curSegment['end'] = $lastx; |
---|
383 | $segments[] = $curSegment; |
---|
384 | } |
---|
385 | $curSegment['id'] = ++$segID; |
---|
386 | $curSegment['start'] = $x; |
---|
387 | $curSegment['x'] = 0; |
---|
388 | $curSegment['y'] = 0; |
---|
389 | $curSegment['count'] = 0; |
---|
390 | $curSegment['alliance'] = $last[0]; |
---|
391 | $curSegment['lasty'] = $y; |
---|
392 | $curSegment['Tcount'] = 0; |
---|
393 | $curA = $last[0]; |
---|
394 | } |
---|
395 | |
---|
396 | // use the influence to drag the nametag to the main source of power |
---|
397 | $curSegment['x'] += $x*$last[1]; |
---|
398 | $curSegment['y'] += $y*$last[1]; |
---|
399 | $curSegment['count'] += $last[1]; |
---|
400 | $curSegment['Tcount']++; |
---|
401 | |
---|
402 | if (!isset($alliances[$last[0]]['npc'])) |
---|
403 | { |
---|
404 | $border = ($x == 0 || $x == $opt['width']-1 || $last[0] != $curRow[$x][0] || $curBorder[$x] || $last[0] != $prevRow[$x-1][0] || $last[0] != $prevRow[$x+1][0]); |
---|
405 | |
---|
406 | $alpha = min(190, intval(log(log($prevRow[$x][1]+1)+1)*700)); |
---|
407 | |
---|
408 | if ($border) |
---|
409 | { |
---|
410 | $alpha = min(max(100, intval(log(log($prevRow[$x][1]+1)+1)*700)), 255); |
---|
411 | } |
---|
412 | $a = &$alliances[$last[0]]['color']; |
---|
413 | $alpha = intval(abs($alpha-255)/2); |
---|
414 | $color = imagecolorallocatealpha($image, $a['r'], $a['g'], $a['b'], $alpha); |
---|
415 | |
---|
416 | imagesetpixel($image, $x, $y, $color); |
---|
417 | } |
---|
418 | } |
---|
419 | $lastx = $x; |
---|
420 | $curBorder[$x] = ($y == 0 || $prevRow[$x][0] != $curRow[$x][0]); |
---|
421 | } |
---|
422 | $curSegment['end'] = $x; |
---|
423 | $segments[] = $curSegment; |
---|
424 | |
---|
425 | foreach ($segments as $curSegment) |
---|
426 | { |
---|
427 | $alliance = $curSegment['alliance']; |
---|
428 | if (isset($alliances[$alliance]['npc']) || $curSegment['alliance'] == null) |
---|
429 | { |
---|
430 | continue; |
---|
431 | } |
---|
432 | |
---|
433 | $validSegs = array(); |
---|
434 | foreach ($alliances[$alliance]['segments'] as $id => $segment) |
---|
435 | { |
---|
436 | // make sure we dont connect bubbles on the same x when they're spread apart |
---|
437 | if ($curSegment['lasty'] - $segment['lasty'] > 5) |
---|
438 | { |
---|
439 | continue; |
---|
440 | } |
---|
441 | |
---|
442 | if (($segment['lstart']-30 < $curSegment['start']) && ($segment['lend']+30 > $curSegment['end'])) |
---|
443 | { |
---|
444 | // the current segment fits into this from the alliance |
---|
445 | $validSegs[] = $id; |
---|
446 | } |
---|
447 | elseif (($segment['lstart']+30 > $curSegment['start']) && ($segment['lend']-30 < $curSegment['end'])) |
---|
448 | { |
---|
449 | // the alliance segment fits into the current one |
---|
450 | $validSegs[] = $id; |
---|
451 | } |
---|
452 | } |
---|
453 | |
---|
454 | if (count($validSegs) > 1) |
---|
455 | { |
---|
456 | $tmp = array_shift($validSegs); |
---|
457 | foreach ($validSegs as $id) |
---|
458 | { |
---|
459 | // set all ids to the same value so they are merged |
---|
460 | $alliances[$alliance]['segments'][$id]['id'] = $tmp; |
---|
461 | } |
---|
462 | $curSegment['id'] = $tmp; |
---|
463 | $alliances[$alliance]['segments'][] = $curSegment; |
---|
464 | } |
---|
465 | // we got one matching segment |
---|
466 | elseif (count($validSegs) == 1) |
---|
467 | { |
---|
468 | $curSegment['id'] = $validSegs[0]; |
---|
469 | $alliances[$alliance]['segments'][] = $curSegment; |
---|
470 | } |
---|
471 | // new segment |
---|
472 | else |
---|
473 | { |
---|
474 | $alliances[$alliance]['segments'][] = $curSegment; |
---|
475 | } |
---|
476 | } |
---|
477 | |
---|
478 | // compact all segments with the same id |
---|
479 | foreach ($segments as $curSegment) |
---|
480 | { |
---|
481 | $alliance = $curSegment['alliance']; |
---|
482 | if ($alliance == null) |
---|
483 | { |
---|
484 | continue; |
---|
485 | } |
---|
486 | if (isset($alliances[$alliance]['npc'])) |
---|
487 | { |
---|
488 | continue; |
---|
489 | } |
---|
490 | |
---|
491 | $array = array(); |
---|
492 | foreach ($alliances[$alliance]['segments'] as $segment) |
---|
493 | { |
---|
494 | $array[$segment['id']]['id'] = $segment['id']; |
---|
495 | $array[$segment['id']]['x'] += $segment['x']; |
---|
496 | $array[$segment['id']]['y'] += $segment['y']; |
---|
497 | $array[$segment['id']]['count'] += $segment['count']; |
---|
498 | $array[$segment['id']]['Tcount'] += $segment['Tcount']; |
---|
499 | $array[$segment['id']]['lstart'] = $segment['start']; |
---|
500 | $array[$segment['id']]['lend'] = $segment['end']; |
---|
501 | |
---|
502 | if (!isset($segment['firsty'])) |
---|
503 | { |
---|
504 | $segment['firsty'] = $segment['lasty']; |
---|
505 | } |
---|
506 | if (isset($array[$segment['id']]['start'])) |
---|
507 | { |
---|
508 | $array[$segment['id']]['lasty'] = max($segment['lasty'], $array[$segment['id']]['lasty']); |
---|
509 | $array[$segment['id']]['start'] = min($segment['start'], $array[$segment['id']]['start']); |
---|
510 | $array[$segment['id']]['end'] = max($segment['end'], $array[$segment['id']]['end']); |
---|
511 | $array[$segment['id']]['firsty'] = min($segment['firsty'], $array[$segment['id']]['firsty']); |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | $array[$segment['id']]['lasty'] = $segment['lasty']; |
---|
516 | $array[$segment['id']]['firsty'] = $segment['firsty']; |
---|
517 | $array[$segment['id']]['start'] = $segment['start']; |
---|
518 | $array[$segment['id']]['end'] = $segment['end']; |
---|
519 | } |
---|
520 | } |
---|
521 | $alliances[$alliance]['segments'] = $array; |
---|
522 | } |
---|
523 | } |
---|
524 | |
---|
525 | // now the fun part, execute the helper program |
---|
526 | // and read its output, it will dump every pixel in the format |
---|
527 | // 'x,y,alliID,infValue' to stdout |
---|
528 | $curRow = $prevRow = $curBorder = array(); |
---|
529 | if (!isset($copt['na'])) |
---|
530 | { |
---|
531 | if (file_exists('evemap')) |
---|
532 | { |
---|
533 | $p = popen('./evemap', 'r'); |
---|
534 | } |
---|
535 | else |
---|
536 | { |
---|
537 | $p = popen('evemap.exe', 'r'); |
---|
538 | } |
---|
539 | } |
---|
540 | if (is_resource($p)) |
---|
541 | { |
---|
542 | $lasty = 0; |
---|
543 | while ($line = fgets($p)) |
---|
544 | { |
---|
545 | $tmp = explode(',', trim($line)); |
---|
546 | |
---|
547 | // gather full rows |
---|
548 | if ($lasty != $tmp[1]) |
---|
549 | { |
---|
550 | $prevRow = $curRow; |
---|
551 | paintRow($lasty); |
---|
552 | |
---|
553 | $curRow = array(); |
---|
554 | $lasty = $tmp[1]; |
---|
555 | } |
---|
556 | $curRow[$tmp[0]] = array($tmp[2], $tmp[3]); |
---|
557 | } |
---|
558 | |
---|
559 | // process last row |
---|
560 | $prevRow = $curRow; |
---|
561 | paintRow($tmp[1]); |
---|
562 | } |
---|
563 | else |
---|
564 | { |
---|
565 | //echo 'ERROR: could not start the helper program<br>'; |
---|
566 | } |
---|
567 | |
---|
568 | watch('processing sovdata'); |
---|
569 | |
---|
570 | // draw all jumps |
---|
571 | $color = array(); |
---|
572 | $color['sys'] = imagecolorallocatealpha($image, 0, 0, 255, $opt['jumplineAlpha']); |
---|
573 | $color['con'] = imagecolorallocatealpha($image, 255, 0, 0, $opt['jumplineAlpha']); |
---|
574 | $color['reg'] = imagecolorallocatealpha($image, 255, 0, 255, $opt['jumplineAlpha']); |
---|
575 | foreach ($jumps as $from => $array) |
---|
576 | { |
---|
577 | if (isset($copt['oj'])) |
---|
578 | { |
---|
579 | break; |
---|
580 | } |
---|
581 | foreach ($array as $to) |
---|
582 | { |
---|
583 | if ($systems_id[$from]['constellationID'] == $systems_id[$to]['constellationID']) |
---|
584 | { |
---|
585 | $col = 'sys'; |
---|
586 | } |
---|
587 | elseif ($systems_id[$from]['regionID'] == $systems_id[$to]['regionID']) |
---|
588 | { |
---|
589 | $col = 'con'; |
---|
590 | } |
---|
591 | else |
---|
592 | { |
---|
593 | $col = 'reg'; |
---|
594 | } |
---|
595 | |
---|
596 | imageline($image, $systems_id[$from]['x'], $systems_id[$from]['y'], $systems_id[$to]['x'], $systems_id[$to]['y'], $color[$col]); |
---|
597 | } |
---|
598 | } |
---|
599 | |
---|
600 | // draw systems |
---|
601 | $white = imagecolorallocatealpha($image, 255, 255, 255, 20); |
---|
602 | $black_trans = imagecolorallocatealpha($image, 0, 0, 0, 35); |
---|
603 | foreach ($systems_id as $id => $system) |
---|
604 | { |
---|
605 | if ($system['allianceID']) |
---|
606 | { |
---|
607 | $a = &$alliances[$allianceIDtoA[$system['allianceID']]]['color']; |
---|
608 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
609 | } |
---|
610 | else |
---|
611 | { |
---|
612 | $color = imagecolorallocate($image, 0xB0, 0xB0, 0xFF); |
---|
613 | } |
---|
614 | |
---|
615 | if ($system[STATION] && $system['sovereigntyLevel'] == '4') |
---|
616 | { |
---|
617 | imagesetstyle($image, array($color, $color, $color, $black_trans, $black_trans)); |
---|
618 | imageellipse($image, $system['x'], $system['y']-1, 40, 40, IMG_COLOR_STYLED); |
---|
619 | } |
---|
620 | if ($system[STATION]) |
---|
621 | { |
---|
622 | imagefilledellipse($image, $system['x']-1, $system['y']-1, 2, 1, $color); |
---|
623 | imagerectangle($image, $system['x']-2, $system['y']-3, $system['x']+2, $system['y']+1, $color); |
---|
624 | } |
---|
625 | elseif ($system['allianceID']) |
---|
626 | { |
---|
627 | imagefilledellipse($image, $system['x'], $system['y'], 4, 3, $color); |
---|
628 | //imagesetpixel($image, $system['x'], $system['y'], $white); |
---|
629 | } |
---|
630 | else |
---|
631 | { |
---|
632 | imagesetpixel($image, $system['x']-1, $system['y'], $color); |
---|
633 | imagesetpixel($image, $system['x'], $system['y'], $color); |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | include('label.php'); |
---|
638 | $label = new labelmanager(); |
---|
639 | if (!isset($copt['or'])) |
---|
640 | { |
---|
641 | // draw region names |
---|
642 | $color = imagecolorallocatealpha($image, 0xff, 0xff, 0xff, $opt['regionAlpha']); |
---|
643 | $edb->query('SELECT r.x, r.z, r.regionName FROM mapsolarsystems s LEFT JOIN mapregions r ON r.regionID=s.regionID where regionName not in ('.$opt['exludeConstID'].') GROUP BY r.regionID'); |
---|
644 | while ($row = $edb->fetch_array()) |
---|
645 | { |
---|
646 | $x = $row['x']/$pScale + $opt['width']/2 + $opt['x']; |
---|
647 | $y = $row['z']/$pScale + $opt['height']/2 + $opt['y']; |
---|
648 | |
---|
649 | // x,y,text,size,font,color,type |
---|
650 | $label->add($x, $y, $row['regionName'], $opt['regionSize'], $opt['font'], $color, 'region'); |
---|
651 | } |
---|
652 | } |
---|
653 | |
---|
654 | // helper function, prints the bounding box |
---|
655 | // of each segment belonging to that alliance |
---|
656 | function printSegments($alliance) |
---|
657 | { |
---|
658 | global $image; |
---|
659 | $red = imagecolorallocate($image, 255, 0, 0); |
---|
660 | foreach ($alliance['segments'] as $segment) |
---|
661 | { |
---|
662 | $a = &$alliance['color']; |
---|
663 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
664 | $x = round($segment['x']/$segment['count']); |
---|
665 | $y = round($segment['y']/$segment['count']); |
---|
666 | imagefilledellipse($image, $x, $y, 10, 10, $color); |
---|
667 | imagefilledellipse($image, $x, $y, 4, 4, $red); |
---|
668 | imagerectangle($image, $segment['start'], $segment['firsty'], $segment['end'], $segment['lasty'], $color); |
---|
669 | } |
---|
670 | } |
---|
671 | |
---|
672 | function mapLegendHeader($x, $y) |
---|
673 | { |
---|
674 | global $image, $opt; |
---|
675 | |
---|
676 | $white = imagecolorallocate($image, 255, 255, 255); |
---|
677 | imagettftext($image, $opt['sovSize'], 0, $x+10, $y, $white, $opt['sov_font'], 'Sov. Lost'); |
---|
678 | $bbox = imagettfbbox($opt['sovSize'], 0, $opt['sov_font'], 'Sov. Lost'); |
---|
679 | $sovGstart = ceil($bbox[4]*4.1+$x+5); |
---|
680 | |
---|
681 | imagettftext($image, $opt['sovSize'], 0, $sovGstart, $y, $white, $opt['sov_font'], 'Sov. Gain'); |
---|
682 | #$bbox = imagettfbbox($opt['sovSize'], 0, $opt['sov_font'], 'Sov. Gain'); |
---|
683 | $sovSstart = ceil($bbox[4]*4+$sovGstart); |
---|
684 | |
---|
685 | imagettftext($image, $opt['sovSize'], 0, $sovSstart, $y, $white, $opt['sov_font'], 'System'); |
---|
686 | $bbox = imagettfbbox($opt['sovSize'], 0, $opt['sov_font'], 'System'); |
---|
687 | $sovRstart = ceil($bbox[4]*1.05+8+$sovSstart); |
---|
688 | |
---|
689 | imagettftext($image, $opt['sovSize'], 0, $sovRstart, $y, $white, $opt['sov_font'], 'Region'); |
---|
690 | $bbox = imagettfbbox($opt['sovSize'], 0, $opt['sov_font'], 'Region'); |
---|
691 | |
---|
692 | $opt['legendLayout']['sovGstart'] = $sovGstart; |
---|
693 | $opt['legendLayout']['sovSstart'] = $sovSstart; |
---|
694 | $opt['legendLayout']['sovRstart'] = $sovRstart; |
---|
695 | |
---|
696 | // draw the grid |
---|
697 | imageline($image, $x, $y+2, $bbox[4]+$sovRstart, $y+2, $white); |
---|
698 | imageline($image, $x+7, $y-10, $x+7, $y, $white); |
---|
699 | imageline($image, $sovGstart-3, $y-10, $sovGstart-3, $y, $white); |
---|
700 | imageline($image, $sovSstart-3, $y-10, $sovSstart-3, $y, $white); |
---|
701 | imageline($image, $sovRstart-3, $y-10, $sovRstart-3, $y, $white); |
---|
702 | } |
---|
703 | |
---|
704 | function mapLegendEntry($x, $y, $row) |
---|
705 | { |
---|
706 | global $image, $alliances, $allianceIDtoA, $opt, $systems_id; |
---|
707 | |
---|
708 | extract($opt['legendLayout']); |
---|
709 | $white = imagecolorallocate($image, 255, 255, 255); |
---|
710 | |
---|
711 | $a = &$alliances[$allianceIDtoA[$row['fromAlliance']]]['color']; |
---|
712 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
713 | imagettftext($image, $opt['sovSize'], 0, $x+10, $y, $color, $opt['sov_font'], $alliances[$allianceIDtoA[$row['fromAlliance']]]['name']); |
---|
714 | |
---|
715 | $a = &$alliances[$allianceIDtoA[$row['toAlliance']]]['color']; |
---|
716 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
717 | $toc = $color; |
---|
718 | imagettftext($image, $opt['sovSize'], 0, $sovGstart, $y, $color, $opt['sov_font'], $alliances[$allianceIDtoA[$row['toAlliance']]]['name']); |
---|
719 | |
---|
720 | $color = imagecolorallocate($image, 90, 90, 220); |
---|
721 | imagettftext($image, $opt['sovSize'], 0, $sovSstart, $y, $color, $opt['sov_font'], $row['solarSystemName']); |
---|
722 | imagettftext($image, $opt['sovSize'], 0, $sovRstart, $y, $white, $opt['sov_font'], $systems_id[$row['solarSystemID']]['regionName']); |
---|
723 | |
---|
724 | if ($row['toAlliance'] == 0) |
---|
725 | { |
---|
726 | $toc = imagecolorallocate($image, 80, 80, 80); |
---|
727 | } |
---|
728 | |
---|
729 | if ($systems_id[$row['solarSystemID']]['outpost'] == null) |
---|
730 | { |
---|
731 | $a = &$alliances[$allianceIDtoA[$row['fromAlliance']]]['color']; |
---|
732 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
733 | imageellipse($image, $systems_id[$row['solarSystemID']]['x'], $systems_id[$row['solarSystemID']]['y'], 7, 7, $color); |
---|
734 | |
---|
735 | imagefilledellipse($image, $x, $y-5, 4, 3, $toc); |
---|
736 | } |
---|
737 | else |
---|
738 | { |
---|
739 | imagefilledellipse($image, $x-1, $y-1-5, 2, 1, $toc); |
---|
740 | imagerectangle($image, $x-2, $y-3-5, $x+2, $y+1-5, $toc); |
---|
741 | |
---|
742 | $a = &$alliances[$allianceIDtoA[$row['fromAlliance']]]['color']; |
---|
743 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
744 | imageellipse($image, $systems_id[$row['solarSystemID']]['x'], $systems_id[$row['solarSystemID']]['y']-1, 9, 9, $color); |
---|
745 | } |
---|
746 | |
---|
747 | imageline($image, $x+7, $y-15, $x+7, $y, $white); |
---|
748 | imageline($image, $sovGstart-3, $y-15, $sovGstart-3, $y, $white); |
---|
749 | imageline($image, $sovSstart-3, $y-15, $sovSstart-3, $y, $white); |
---|
750 | imageline($image, $sovRstart-3, $y-15, $sovRstart-3, $y, $white); |
---|
751 | } |
---|
752 | |
---|
753 | |
---|
754 | $changeStack = array(); |
---|
755 | $query = "SELECT m1.solarSystemID, m1.solarSystemName, m1.allianceID as fromAlliance, m2.allianceID as toAlliance |
---|
756 | FROM `mapsovereignty` m1 |
---|
757 | left join `mapsovereignty` m2 using (solarSystemID) |
---|
758 | left join mapsolarsystems using (solarSystemID) |
---|
759 | WHERE m1.date='$date1' and m2.date='$date2' |
---|
760 | and (m1.allianceID != m2.allianceID) |
---|
761 | and m1.factionID = 0 order by regionID asc, m1.allianceID asc"; |
---|
762 | $edb->query($query); |
---|
763 | $i = 0; |
---|
764 | while ($row = $edb->fetch_array()) |
---|
765 | { |
---|
766 | if (isset($systems_id[$row['solarSystemID']])) |
---|
767 | { |
---|
768 | if ($systems_id[$row['solarSystemID']]['outpost'] != null) |
---|
769 | { |
---|
770 | $outposts++; |
---|
771 | } |
---|
772 | $changeStack[] = $row; |
---|
773 | } |
---|
774 | } |
---|
775 | $changes = count($changeStack); |
---|
776 | $filter = false; |
---|
777 | |
---|
778 | if ($changes > 42) |
---|
779 | { |
---|
780 | $changes = $outposts; |
---|
781 | $filter = true; |
---|
782 | } |
---|
783 | |
---|
784 | if ($changes <= 10) |
---|
785 | { |
---|
786 | $num1 = $changes; |
---|
787 | $num2 = 0; |
---|
788 | } |
---|
789 | elseif ($changes <= 30) |
---|
790 | { |
---|
791 | $num1 = 0; |
---|
792 | $num2 = $changes; |
---|
793 | } |
---|
794 | else |
---|
795 | { |
---|
796 | $num1 = 13; |
---|
797 | $num2 = 42; |
---|
798 | } |
---|
799 | |
---|
800 | if ($num1) |
---|
801 | { |
---|
802 | $y = 75; |
---|
803 | mapLegendHeader(5, $y); |
---|
804 | } |
---|
805 | |
---|
806 | |
---|
807 | $cnt = 0; |
---|
808 | $x = $prevx = 5; |
---|
809 | while ($row = array_shift($changeStack)) |
---|
810 | { |
---|
811 | |
---|
812 | // display only outpost changes when there are more than 50 entries |
---|
813 | if ($filter) |
---|
814 | { |
---|
815 | if ($systems_id[$row['solarSystemID']]['outpost'] == null) |
---|
816 | { |
---|
817 | $a = &$alliances[$allianceIDtoA[$row['fromAlliance']]]['color']; |
---|
818 | |
---|
819 | if ($a == null) |
---|
820 | { |
---|
821 | $a = array('r' => 180, 'g' => 180, 'b' => 180); |
---|
822 | } |
---|
823 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
824 | imageellipse($image, $systems_id[$row['solarSystemID']]['x'], $systems_id[$row['solarSystemID']]['y'], 7, 7, $color); |
---|
825 | $i++; |
---|
826 | continue; |
---|
827 | } |
---|
828 | } |
---|
829 | |
---|
830 | if ($cnt > $num1 || $num1 == 0) |
---|
831 | { |
---|
832 | if ($x == $prevx) |
---|
833 | { |
---|
834 | $x = 1280; |
---|
835 | $y = 15; |
---|
836 | mapLegendHeader($x, $y); |
---|
837 | } |
---|
838 | } |
---|
839 | if ($cnt > $num2 && $num2 != 0) |
---|
840 | { |
---|
841 | // dont draw more |
---|
842 | $i++; |
---|
843 | continue; |
---|
844 | } |
---|
845 | |
---|
846 | $y += 15; |
---|
847 | $cnt++; |
---|
848 | mapLegendEntry($x, $y, $row); |
---|
849 | } |
---|
850 | |
---|
851 | if ($i) |
---|
852 | { |
---|
853 | // print lala |
---|
854 | imagettftext($image, $opt['sovSize'], 0, $x+10, $y+15, $white, $opt['sov_font'], "There are $i more Sovereignity changes"); |
---|
855 | } |
---|
856 | |
---|
857 | |
---|
858 | // print alliance names |
---|
859 | $black = imagecolorallocate($image, 0, 0, 0); |
---|
860 | foreach ($alliances as $id => $alliance) |
---|
861 | { |
---|
862 | if (!isset($alliance['segments'])) |
---|
863 | { |
---|
864 | continue; |
---|
865 | } |
---|
866 | if (isset($alliance['npc'])) |
---|
867 | { |
---|
868 | continue; |
---|
869 | } |
---|
870 | |
---|
871 | if (isset($copt['ds'])) |
---|
872 | { |
---|
873 | printSegments($alliances[$id]); |
---|
874 | } |
---|
875 | |
---|
876 | if (isset($copt['oa'])) |
---|
877 | { |
---|
878 | continue; |
---|
879 | } |
---|
880 | |
---|
881 | foreach ($alliance['segments'] as $data) |
---|
882 | { |
---|
883 | $x = intval($data['x'] / $data['count']); |
---|
884 | $y = intval($data['y'] / $data['count']); |
---|
885 | |
---|
886 | //echo $x.'-'.$y.' '. $alliance['name']."\n"; |
---|
887 | $size = intval(sqrt($data['Tcount'])/30 + 8); |
---|
888 | $a = &$alliance['color']; |
---|
889 | $color = imagecolorallocate($image, $a['r'], $a['g'], $a['b']); |
---|
890 | |
---|
891 | // x,y,text,size,font,color,type |
---|
892 | $label->add($x, $y, $alliance['name'], $size, $opt['ally_font'], $color, 'alliance'); |
---|
893 | } |
---|
894 | } |
---|
895 | |
---|
896 | // draw all labels |
---|
897 | //var_export($label); |
---|
898 | $label->draw($image); |
---|
899 | |
---|
900 | // created by |
---|
901 | $color = imagecolorallocate($image, 150, 150, 150); |
---|
902 | imagettftext($image, 12, 0, 5, 22, $color, $opt['font'], 'Based on the Sovereignty Map of Paladin Vent'); |
---|
903 | imagettftext($image, 12, 0, 5, 40, $color, $opt['font'], 'brought to you by EVE-Dev'); |
---|
904 | imagettftext($image, 12, 0, 5, 58, $color, $opt['font'], 'Sovereignty data from '.$date1.' to '.$date2); |
---|
905 | |
---|
906 | $red = imagecolorallocate($image, 255, 0, 0); |
---|
907 | $mtime = explode(" ",microtime()); |
---|
908 | $endtimeb = $mtime[1] + $mtime[0]; |
---|
909 | $totaltime = round(($endtimeb - $starttimeb), 2); |
---|
910 | imagestring($image, 3, $opt['width'] - 200, $opt['height'] - 30 , "Generated in: {$totaltime}s" , $red); |
---|
911 | |
---|
912 | unset($alliances); |
---|
913 | unset($systems_id); |
---|
914 | unset($systems); |
---|
915 | unset($jumps); |
---|
916 | unset($systems_sov); |
---|
917 | unset($allianceIDtoA); |
---|
918 | |
---|
919 | if (JOB_UPDATE) |
---|
920 | { |
---|
921 | $edb->query('update maprendertarget set status=2 where id='.$job_id); |
---|
922 | } |
---|
923 | |
---|
924 | // output |
---|
925 | if ($copt) |
---|
926 | { |
---|
927 | imagepng($image, 'maps/influence_'.$date1.'_'.$date2.'_'.join('', $copt).'.png'); |
---|
928 | imageinterlace($image, 1); |
---|
929 | imagejpeg($image, 'maps/influence_'.$date1.'_'.$date2.'_'.join('', $copt).'.jpg', 95); |
---|
930 | } |
---|
931 | else |
---|
932 | { |
---|
933 | imagepng($image, 'maps/influence_'.$date1.'_'.$date2.'.png'); |
---|
934 | imageinterlace($image, 1); |
---|
935 | imagejpeg($image, 'maps/influence_'.$date1.'_'.$date2.'.jpg', 95); |
---|
936 | } |
---|
937 | |
---|
938 | watch('shutdown'); |
---|
939 | ?> |
---|