1 | <?php |
---|
2 | class MapView |
---|
3 | { |
---|
4 | function MapView($mode, $size = 200) |
---|
5 | { |
---|
6 | $this->mode_ = $mode; |
---|
7 | $this->imgwidth_ = $size; |
---|
8 | $this->imgheight_ = $size; |
---|
9 | $this->ly_ = 0.4 / 1000000000000000; |
---|
10 | $this->offset_ = 10; |
---|
11 | |
---|
12 | $this->sys_colors_[0] = array(200, 20, 48); |
---|
13 | $this->sys_colors_[1] = array(200, 20, 48); |
---|
14 | $this->sys_colors_[2] = array(200, 20, 48); |
---|
15 | $this->sys_colors_[3] = array(241, 176, 48); |
---|
16 | $this->sys_colors_[4] = array(200, 200, 48); |
---|
17 | $this->sys_colors_[5] = array(219, 241, 48); |
---|
18 | $this->sys_colors_[6] = array(103, 241, 62); |
---|
19 | $this->sys_colors_[7] = array(83, 241, 114); |
---|
20 | $this->sys_colors_[8] = array(26, 241, 183); |
---|
21 | $this->sys_colors_[9] = array(99, 241, 255); |
---|
22 | $this->sys_colors_[10] = array(99, 241, 255); |
---|
23 | |
---|
24 | $this->linecolor_ = array(75, 75, 75); |
---|
25 | $this->captioncolor_ = array(110, 110, 110); |
---|
26 | $this->bgcolor_ = array(30, 30, 30); |
---|
27 | $this->normalcolor_ = array(81, 103, 146); |
---|
28 | $this->hlcolor_ = array(200, 200, 200); |
---|
29 | } |
---|
30 | |
---|
31 | function setbgcolor($r, $g, $b) |
---|
32 | { |
---|
33 | $this->bgcolor_ = array($r, $g, $b); |
---|
34 | } |
---|
35 | |
---|
36 | function setlinecolor($r, $g, $b) |
---|
37 | { |
---|
38 | $this->linecolor_ = array($r, $g, $b); |
---|
39 | } |
---|
40 | |
---|
41 | function setcaptcolor($r, $g, $b) |
---|
42 | { |
---|
43 | $this->captioncolor_ = array($r, $g, $b); |
---|
44 | } |
---|
45 | |
---|
46 | function setnormalcolor($r, $g, $b) |
---|
47 | { |
---|
48 | $this->normalcolor_ = array($r, $g, $b); |
---|
49 | } |
---|
50 | |
---|
51 | function sethlcolor($r, $g, $b) |
---|
52 | { |
---|
53 | $this->hlcolor_ = array($r, $g, $b); |
---|
54 | } |
---|
55 | |
---|
56 | function paintSecurity($bool) |
---|
57 | { |
---|
58 | $this->psec_ = $bool; |
---|
59 | } |
---|
60 | |
---|
61 | function setOffset($offset) |
---|
62 | { |
---|
63 | $this->offset_ = $offset; |
---|
64 | } |
---|
65 | |
---|
66 | function showLines($enable) |
---|
67 | { |
---|
68 | $this->showlines_ = $enable; |
---|
69 | } |
---|
70 | |
---|
71 | function showSysNames($enable) |
---|
72 | { |
---|
73 | $this->showsysnames_ = $enable; |
---|
74 | } |
---|
75 | |
---|
76 | function colorSystems($enable) |
---|
77 | { |
---|
78 | $this->colorsystems_ = $enable; |
---|
79 | } |
---|
80 | |
---|
81 | function setRegionID($regionid) |
---|
82 | { |
---|
83 | $this->regionid_ = $regionid; |
---|
84 | } |
---|
85 | |
---|
86 | function setSystemID($systemid) |
---|
87 | { |
---|
88 | $this->systemid_ = $systemid; |
---|
89 | |
---|
90 | $sql = 'select reg.reg_id, reg.reg_name, con.con_id, con.con_name, sys.sys_name, sys.sys_sec |
---|
91 | from kb3_regions reg, kb3_constellations con, kb3_systems sys |
---|
92 | where reg.reg_id = con.con_reg_id |
---|
93 | and con.con_id = sys.sys_con_id |
---|
94 | and sys.sys_id = '.$this->systemid_; |
---|
95 | |
---|
96 | $qry = new DBQuery(); |
---|
97 | $qry->execute($sql); |
---|
98 | $row = $qry->getRow(); |
---|
99 | |
---|
100 | $this->conid_ = $row['con_id']; |
---|
101 | $this->regionid_ = $row['reg_id']; |
---|
102 | $this->conname_ = $row['con_name']; |
---|
103 | $this->regname_ = $row['reg_name']; |
---|
104 | $this->sysname_ = $row['sys_name']; |
---|
105 | $this->syssec_ = $row['sys_sec']; |
---|
106 | } |
---|
107 | |
---|
108 | function setTitle($title) |
---|
109 | { |
---|
110 | $this->title_ = $title; |
---|
111 | } |
---|
112 | |
---|
113 | function secColor($img, $security) |
---|
114 | { |
---|
115 | if ($this->psec_) |
---|
116 | { |
---|
117 | if ($security > 0.05) |
---|
118 | { |
---|
119 | $sec_status = round($security * 10); |
---|
120 | return imagecolorallocate($img, $this->sys_colors_[$sec_status][0], |
---|
121 | $this->sys_colors_[$sec_status][1], |
---|
122 | $this->sys_colors_[$sec_status][2]); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | return imagecolorallocate($img, $this->normalcolor_[0], $this->normalcolor_[1], $this->normalcolor_[2]); |
---|
127 | } |
---|
128 | |
---|
129 | function generate() |
---|
130 | { |
---|
131 | $sql = 'select sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, |
---|
132 | sys.sys_id, sys.sys_name, sys.sys_eve_id, sjp.sjp_to, con.con_id, |
---|
133 | con.con_name, reg.reg_id, reg.reg_name, |
---|
134 | reg.reg_x, reg.reg_z |
---|
135 | from kb3_systems sys, kb3_system_jumps sjp, |
---|
136 | kb3_constellations con, kb3_regions reg |
---|
137 | where con.con_id = sys.sys_con_id |
---|
138 | and reg.reg_id = con.con_reg_id |
---|
139 | and sjp.sjp_from = sys.sys_eve_id'; |
---|
140 | |
---|
141 | if ($this->mode_ == "map") |
---|
142 | { |
---|
143 | $regioncache = 'cache/map/'.KB_SITE.'_'.$this->regionid_.'_'.$this->imgwidth_.'.png'; |
---|
144 | $caption = $this->regname_; |
---|
145 | } |
---|
146 | elseif ($this->mode_ == "region") |
---|
147 | { |
---|
148 | $regioncache = 'cache/map/'.KB_SITE.'_'.$this->conid_.'_'.$this->imgwidth_.'.png'; |
---|
149 | $sql .= " and reg.reg_id = ".$this->regionid_; |
---|
150 | $caption = $this->conname_; |
---|
151 | } |
---|
152 | elseif ($this->mode_ == "cons") |
---|
153 | { |
---|
154 | $regioncache = 'cache/map/'.KB_SITE.'_'.$this->systemid_.'_'.$this->imgwidth_.'.png'; |
---|
155 | |
---|
156 | $sql .= " and con.con_id = ".$this->conid_; |
---|
157 | $caption = $this->sysname_." (".roundsec($this->syssec_).")"; |
---|
158 | } |
---|
159 | if (file_exists($regioncache)) |
---|
160 | { |
---|
161 | header("Content-type: image/png"); |
---|
162 | readfile($regioncache); |
---|
163 | return; |
---|
164 | } |
---|
165 | |
---|
166 | if (true) |
---|
167 | { |
---|
168 | $qry = new DBQuery(); |
---|
169 | $qry->execute($sql) or die($qry->getErrorMsg()); |
---|
170 | |
---|
171 | if (!$img) $img = imagecreatetruecolor($this->imgwidth_, $this->imgheight_); |
---|
172 | $white = imagecolorallocate($img, 255, 255, 255); |
---|
173 | $red = imagecolorallocate($img, 255, 0, 0); |
---|
174 | $bgcolor = imagecolorallocate($img, $this->bgcolor_[0], $this->bgcolor_[1], $this->bgcolor_[2]); |
---|
175 | imagefilledrectangle($img, 0, 0, $this->imgwidth_, $this->imgheight_, $bgcolor); |
---|
176 | |
---|
177 | $color = $white; |
---|
178 | |
---|
179 | $fov = 0; |
---|
180 | |
---|
181 | $i = 0; |
---|
182 | $minx = 0; |
---|
183 | $minz = 0; |
---|
184 | $maxx = 0; |
---|
185 | $maxz = 0; |
---|
186 | $mini = 0; |
---|
187 | $maxi = 0; |
---|
188 | $pi = 0; |
---|
189 | $sc = 0; |
---|
190 | while ($row = $qry->getRow()) |
---|
191 | { |
---|
192 | $i = $row['sys_eve_id']; |
---|
193 | if ($i < $mini || $mini == 0) |
---|
194 | $mini = $i; |
---|
195 | if ($i > $maxi || $maxi == 0) |
---|
196 | $maxi = $i; |
---|
197 | $x = $row['sys_x'] * $this->ly_; |
---|
198 | $z = $row['sys_z'] * $this->ly_; |
---|
199 | |
---|
200 | if ($x < $minx || $minx == 0) |
---|
201 | $minx = $x; |
---|
202 | if ($x > $maxx || $maxx == 0) |
---|
203 | $maxx = $x; |
---|
204 | if ($z < $minz || $minz == 0) |
---|
205 | $minz = $z; |
---|
206 | if ($z > $maxz || $maxz == 0) |
---|
207 | $maxz = $z; |
---|
208 | |
---|
209 | $sys[$i][0] = $x; |
---|
210 | $sys[$i][1] = $z; |
---|
211 | if ($i == $pi || $pi == 0) |
---|
212 | { |
---|
213 | $sys[$i][2][$sc] = $row['sjp_to']; |
---|
214 | $sys[$i][3] = $sc++; |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | $sc = 0; |
---|
219 | } |
---|
220 | $sys[$i][4] = $row['sys_id']; |
---|
221 | $sys[$i][5] = $row['sys_name']; |
---|
222 | $sys[$i][6] = $row['sys_sec']; |
---|
223 | $sys[$i][7] = $row['con_id']; |
---|
224 | $sys[$i][8] = $row['con_name']; |
---|
225 | $sys[$i][9] = $row['reg_id']; |
---|
226 | $sys[$i][10] = $row['reg_name']; |
---|
227 | $pi = $i; |
---|
228 | } |
---|
229 | $dx = abs($maxx - $minx); |
---|
230 | $dz = abs($maxz - $minz); |
---|
231 | $xscale = 1 / ($dx / ($this->imgwidth_ - ($this->offset_ * 2))); |
---|
232 | $yscale = 1 / ($dz / ($this->imgheight_ - ($this->offset_ * 2))); |
---|
233 | if ($_REQUEST['debug'] == 'admovrd') |
---|
234 | { |
---|
235 | echo "dx:".$dx." dz:".$dz."<br/> xscale:".$xscale." ".$yscale."<br/>"; |
---|
236 | echo "minx:".$minx." maxx:".$maxx."<br/>"; |
---|
237 | echo "minz:".$minz." maxz:".$maxz."<br/>".$sql."<br/>\n"; |
---|
238 | echo nl2br(print_r($this, 1)); |
---|
239 | echo nl2br(print_r($qry, 1)); |
---|
240 | } |
---|
241 | |
---|
242 | // draw lines |
---|
243 | if ($this->showlines_) |
---|
244 | { |
---|
245 | $n = $mini; |
---|
246 | while ($n <= $maxi) |
---|
247 | { |
---|
248 | $px = $this->offset_ + ($sys[$n][0] - $minx) * $xscale; |
---|
249 | $py = $this->offset_ + ($sys[$n][1] - $minz) * $yscale; |
---|
250 | |
---|
251 | $line_col = imagecolorallocate($img, $this->linecolor_[0], $this->linecolor_[1], $this->linecolor_[2]); |
---|
252 | |
---|
253 | for ($m = 0; $m <= $sys[$n][3]; $m++) |
---|
254 | { |
---|
255 | $sys_to = $sys[$n][2][$m]; |
---|
256 | |
---|
257 | if ($sys[$sys_to][4] != "") |
---|
258 | { |
---|
259 | $px_to = $this->offset_ + ($sys[$sys_to][0] - $minx) * $xscale; |
---|
260 | $py_to = $this->offset_ + ($sys[$sys_to][1] - $minz) * $yscale; |
---|
261 | |
---|
262 | imageline($img, $px, $py, $px_to, $py_to, $line_col); |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | $n++; |
---|
267 | } |
---|
268 | } |
---|
269 | // draw systems |
---|
270 | $n = $mini; |
---|
271 | while ($n <= $maxi) |
---|
272 | { |
---|
273 | $px = round($this->offset_ + ($sys[$n][0] - $minx) * $xscale); |
---|
274 | $py = round($this->offset_ + ($sys[$n][1] - $minz) * $yscale); |
---|
275 | |
---|
276 | if ($this->mode_ == "map") |
---|
277 | { |
---|
278 | if ($sys[$n][9] == $this->regionid_) |
---|
279 | $color = imagecolorallocate($img, $this->hlcolor_[0], $this->hlcolor_[1], $this->hlcolor_[2]); |
---|
280 | else |
---|
281 | $color = $this->secColor($img, $sys[$n][6]); |
---|
282 | } |
---|
283 | if ($this->mode_ == "region") |
---|
284 | { |
---|
285 | if ($sys[$n][7] == $this->conid_) |
---|
286 | $color = imagecolorallocate($img, $this->hlcolor_[0], $this->hlcolor_[1], $this->hlcolor_[2]); |
---|
287 | else |
---|
288 | $color = $this->secColor($img, $sys[$n][6]); |
---|
289 | } |
---|
290 | if ($this->mode_ == "cons") |
---|
291 | { |
---|
292 | if ($sys[$n][4] == $this->systemid_) |
---|
293 | $color = imagecolorallocate($img, $this->hlcolor_[0], $this->hlcolor_[1], $this->hlcolor_[2]); |
---|
294 | else |
---|
295 | $color = $this->secColor($img, $sys[$n][6]); |
---|
296 | } |
---|
297 | |
---|
298 | if ($this->showsysnames_) |
---|
299 | { |
---|
300 | $tlen = 5 * strlen($sys[$n][5]); |
---|
301 | if (($px + $tlen > ($this->imgwidth_ - 20))) |
---|
302 | $sx = $px - $tlen; |
---|
303 | else |
---|
304 | $sx = $px + 5; |
---|
305 | if (($py + 5 > ($this->imgheight_ - 20))) |
---|
306 | $sy = $py - 5; |
---|
307 | else |
---|
308 | $sy = $py + 5; |
---|
309 | |
---|
310 | imagestring($img, 1, $sx, $sy, $sys[$n][5], $color); |
---|
311 | // imagettftext ( $img, 6, 0, |
---|
312 | // $sx, |
---|
313 | // $sy, |
---|
314 | // $color, |
---|
315 | // "../fonts/04B_03__.TTF", |
---|
316 | // $sys[$n][5] ); |
---|
317 | } |
---|
318 | |
---|
319 | $ed = $xscale * 0.75; |
---|
320 | if ($ed > 5) |
---|
321 | { |
---|
322 | $ed = 5; |
---|
323 | } |
---|
324 | // bug compat: imagefilledellipse doesnt draw ellipses with 1px size |
---|
325 | // on some installations |
---|
326 | if ($ed < 1) |
---|
327 | { |
---|
328 | imagesetpixel($img, $px, $py, $color); |
---|
329 | } |
---|
330 | elseif ($ed < 3) |
---|
331 | { |
---|
332 | imagesetpixel($img, $px, $py, $color); |
---|
333 | imagesetpixel($img, $px+1, $py, $color); |
---|
334 | imagesetpixel($img, $px-1, $py, $color); |
---|
335 | imagesetpixel($img, $px, $py-1, $color); |
---|
336 | imagesetpixel($img, $px, $py+1, $color); |
---|
337 | } |
---|
338 | else |
---|
339 | { |
---|
340 | imagefilledellipse($img, $px, $py, $ed, $ed, $color); |
---|
341 | } |
---|
342 | |
---|
343 | $n++; |
---|
344 | } |
---|
345 | } |
---|
346 | |
---|
347 | $captioncolor = imagecolorallocate($img, $this->captioncolor_[0], $this->captioncolor_[1], $this->captioncolor_[2]); |
---|
348 | if (strlen($this->title_) > 0) |
---|
349 | { |
---|
350 | $title = $this->title_." ".$caption; |
---|
351 | } |
---|
352 | else |
---|
353 | { |
---|
354 | $title = $caption; |
---|
355 | } |
---|
356 | |
---|
357 | imagestring($img, 1, 2, 2, $title, $captioncolor); |
---|
358 | if ($this->mode_ == "map") |
---|
359 | { |
---|
360 | imagepng($img, $regioncache); |
---|
361 | } |
---|
362 | // optionally cache constellation maps |
---|
363 | elseif ($this->mode_ == 'region' && config::get('map_region_cache')) |
---|
364 | { |
---|
365 | imagepng($img, $regioncache); |
---|
366 | } |
---|
367 | // cache everything if we are reinforced |
---|
368 | elseif (config::get('is_reinforced')) |
---|
369 | { |
---|
370 | imagepng($img, $regioncache); |
---|
371 | } |
---|
372 | header("Content-type: image/png"); |
---|
373 | imagepng($img); |
---|
374 | } |
---|
375 | } |
---|
376 | ?> |
---|