1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Asylamba\Modules\Gaia\Helper; |
4
|
|
|
|
5
|
|
|
use Asylamba\Classes\Database\DatabaseAdmin; |
6
|
|
|
use Asylamba\Classes\Library\Utils; |
7
|
|
|
|
8
|
|
|
use Asylamba\Modules\Gaia\Galaxy\GalaxyConfiguration; |
9
|
|
|
|
10
|
|
|
use Asylamba\Modules\Gaia\Model\PointLocation; |
11
|
|
|
use Asylamba\Modules\Gaia\Model\Place; |
12
|
|
|
use Asylamba\Classes\Library\Format; |
13
|
|
|
|
14
|
|
|
class GalaxyGenerator { |
15
|
|
|
const MAX_QUERY = 5000; |
16
|
|
|
|
17
|
|
|
# stats |
18
|
|
|
public $nbSystem = 0; |
19
|
|
|
public $listSystem = array(); |
20
|
|
|
|
21
|
|
|
public $nbPlace = 0; |
22
|
|
|
public $popTotal = 0; |
23
|
|
|
public $listPlace = array(); |
24
|
|
|
|
25
|
|
|
public $nbSector = 0; |
26
|
|
|
public $systemDeleted = 0; |
27
|
|
|
public $listSector = array(); |
28
|
|
|
|
29
|
|
|
/** @var string **/ |
30
|
|
|
protected $output; |
31
|
|
|
/** @var DatabaseAdmin **/ |
32
|
|
|
protected $databaseAdmin; |
33
|
|
|
/** @var GalaxyConfiguration **/ |
34
|
|
|
protected $galaxyConfiguration; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param DatabaseAdmin $databaseAdmin |
38
|
|
|
* @param GalaxyConfiguration $galaxyConfiguration |
39
|
|
|
*/ |
40
|
|
|
public function __construct(DatabaseAdmin $databaseAdmin, GalaxyConfiguration $galaxyConfiguration) |
41
|
|
|
{ |
42
|
|
|
$this->databaseAdmin = $databaseAdmin; |
43
|
|
|
$this->galaxyConfiguration = $galaxyConfiguration; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function generate() { |
47
|
|
|
$this->clear(); |
48
|
|
|
|
49
|
|
|
# generation |
50
|
|
|
$this->generateSector(); |
51
|
|
|
$this->generateSystem(); |
52
|
|
|
$this->associateSystemToSector(); |
53
|
|
|
$this->generatePlace(); |
54
|
|
|
|
55
|
|
|
$this->save(); |
56
|
|
|
|
57
|
|
|
$this->getStatisticsSector(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function clear() { |
61
|
|
|
$this->databaseAdmin->query('SET FOREIGN_KEY_CHECKS = 0;'); |
62
|
|
|
|
63
|
|
|
$this->databaseAdmin->query('TRUNCATE place'); |
64
|
|
|
$this->log('table `place` vidées'); |
65
|
|
|
|
66
|
|
|
$this->databaseAdmin->query('TRUNCATE system'); |
67
|
|
|
$this->log('table `system` vidées'); |
68
|
|
|
|
69
|
|
|
$this->databaseAdmin->query('TRUNCATE sector'); |
70
|
|
|
$this->log('table `sector` vidées'); |
71
|
|
|
|
72
|
|
|
$this->databaseAdmin->query('SET FOREIGN_KEY_CHECKS = 1;'); |
73
|
|
|
$this->log('_ _ _ _'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function save() { |
77
|
|
|
# clean up database |
78
|
|
|
$this->clear(); |
79
|
|
|
|
80
|
|
|
$this->log('sauvegarde des secteurs'); |
81
|
|
|
for ($i = 0; $i < ceil(count($this->listSector) / self::MAX_QUERY); $i++) { |
82
|
|
|
$qr = 'INSERT INTO sector(id, rColor, xPosition, yPosition, xBarycentric, yBarycentric, tax, population, lifePlanet, name, prime, points) VALUES '; |
83
|
|
|
|
84
|
|
|
for ($j = $i * self::MAX_QUERY; $j < (($i + 1) * self::MAX_QUERY) - 1; $j++) { |
85
|
|
|
if (isset($this->listSector[$j])) { |
86
|
|
|
$qr .= '(\'' . implode('\', \'', $this->listSector[$j]) . '\'), '; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$qr = substr($qr, 0, -2); |
91
|
|
|
$this->databaseAdmin->query($qr); |
92
|
|
|
} |
93
|
|
|
$this->log(ceil(count($this->listSector) / self::MAX_QUERY) . ' requêtes `INSERT`'); |
94
|
|
|
|
95
|
|
|
$this->log('sauvegarde des systèmes'); |
96
|
|
|
for ($i = 0; $i < ceil(count($this->listSystem) / self::MAX_QUERY); $i++) { |
97
|
|
|
$qr = 'INSERT INTO system(id, rSector, rColor, xPosition, yPosition, typeOfSystem) VALUES '; |
98
|
|
|
|
99
|
|
|
for ($j = $i * self::MAX_QUERY; $j < (($i + 1) * self::MAX_QUERY) - 1; $j++) { |
100
|
|
|
if (isset($this->listSystem[$j])) { |
101
|
|
|
$qr .= '(' . implode(', ', $this->listSystem[$j]) . '), '; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$qr = substr($qr, 0, -2); |
106
|
|
|
$this->databaseAdmin->query($qr); |
107
|
|
|
} |
108
|
|
|
$this->log(ceil(count($this->listSystem) / self::MAX_QUERY) . ' requêtes `INSERT`'); |
109
|
|
|
|
110
|
|
|
$this->log('sauvegarde des places'); |
111
|
|
|
for ($i = 0; $i < ceil(count($this->listPlace) / self::MAX_QUERY); $i++) { |
112
|
|
|
$qr = 'INSERT INTO place(id, rSystem, typeOfPlace, position, population, coefResources, coefHistory, resources, danger, maxDanger, uPlace) VALUES '; |
113
|
|
|
|
114
|
|
|
for ($j = $i * self::MAX_QUERY; $j < (($i + 1) * self::MAX_QUERY) - 1; $j++) { |
115
|
|
|
if (isset($this->listPlace[$j])) { |
116
|
|
|
$qr .= '(' . implode(', ', $this->listPlace[$j]) . ', "' . Utils::addSecondsToDate(Utils::now(), -259200) . '"), '; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$qr = substr($qr, 0, -2); |
121
|
|
|
$this->databaseAdmin->query($qr); |
122
|
|
|
} |
123
|
|
|
$this->log(ceil(count($this->listPlace) / self::MAX_QUERY) . ' requêtes `INSERT`'); |
124
|
|
|
|
125
|
|
|
$this->log('_ _ _ _'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getLog() { |
129
|
|
|
$rt = '<pre style="font-family: consolas;">'; |
130
|
|
|
$rt .= $this->output; |
131
|
|
|
$rt .= '</pre>'; |
132
|
|
|
|
133
|
|
|
return $rt; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
private function log($text) { |
137
|
|
|
$this->output .= ">_ $text <br />"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
private function generateSystem() { |
141
|
|
|
$this->log('génération des systèmes'); |
142
|
|
|
|
143
|
|
|
# id |
144
|
|
|
$k = 1; |
145
|
|
|
|
146
|
|
|
# GENERATION DES LINES |
147
|
|
|
for ($w = 0; $w < count($this->galaxyConfiguration->galaxy['lineSystemPosition']); $w++) { |
|
|
|
|
148
|
|
|
# line point |
149
|
|
|
$xA = $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][0][0]; |
150
|
|
|
$yA = $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][0][1]; |
151
|
|
|
|
152
|
|
|
$xB = $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][1][0]; |
153
|
|
|
$yB = $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][1][1]; |
154
|
|
|
|
155
|
|
|
$l = sqrt(pow($xB - $xA, 2) + pow($yB - $yA, 2)); |
|
|
|
|
156
|
|
|
|
157
|
|
|
for ($i = 1; $i <= $this->galaxyConfiguration->galaxy['size']; $i++) { |
158
|
|
|
for ($j = 1; $j <= $this->galaxyConfiguration->galaxy['size']; $j++) { |
159
|
|
|
# current cursor position |
160
|
|
|
$xC = $j; |
161
|
|
|
$yC = $i; |
162
|
|
|
|
163
|
|
|
$d = $this->distToSegment($xC, $yC, $xA, $yA, $xB, $yB); |
164
|
|
|
|
165
|
|
|
$thickness = $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][2]; |
166
|
|
|
$intensity = $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][3]; |
167
|
|
|
|
168
|
|
|
if ($d < $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][2]) { |
169
|
|
|
#$prob = rand(0, $this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][3]); |
170
|
|
|
$prob = rand(0, 100); |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
#if ($this->galaxyConfiguration->galaxy['lineSystemPosition'][$w][2] - $d > $prob) { |
174
|
|
|
if (round($intensity - ($d * $intensity / $thickness)) >= $prob) { |
|
|
|
|
175
|
|
|
|
176
|
|
|
|
177
|
|
|
$type = $this->getSystem(); |
178
|
|
|
|
179
|
|
|
$this->nbSystem++; |
180
|
|
|
$this->listSystem[] = array($k, 0, 0, $xC, $yC, $type); |
181
|
|
|
|
182
|
|
|
$k++; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
# GENERATION DES ANNEAUX (circleSystemPosition) |
190
|
|
|
for ($w = 0; $w < count($this->galaxyConfiguration->galaxy['circleSystemPosition']); $w++) { |
|
|
|
|
191
|
|
|
# line point |
192
|
|
|
$xC = $this->galaxyConfiguration->galaxy['circleSystemPosition'][$w][0][0]; |
193
|
|
|
$yC = $this->galaxyConfiguration->galaxy['circleSystemPosition'][$w][0][1]; |
194
|
|
|
|
195
|
|
|
$radius = $this->galaxyConfiguration->galaxy['circleSystemPosition'][$w][1]; |
196
|
|
|
$thickness = $this->galaxyConfiguration->galaxy['circleSystemPosition'][$w][2]; |
197
|
|
|
$intensity = $this->galaxyConfiguration->galaxy['circleSystemPosition'][$w][3]; |
198
|
|
|
|
199
|
|
|
for ($i = 1; $i <= $this->galaxyConfiguration->galaxy['size']; $i++) { |
200
|
|
|
for ($j = 1; $j <= $this->galaxyConfiguration->galaxy['size']; $j++) { |
201
|
|
|
# current cursor position |
202
|
|
|
$xPosition = $j; |
203
|
|
|
$yPosition = $i; |
204
|
|
|
|
205
|
|
|
# calcul de la distance entre la case et le centre |
206
|
|
|
$d = sqrt( |
207
|
|
|
pow(abs($xC - $xPosition), 2) + |
208
|
|
|
pow(abs($yC - $yPosition), 2) |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
if ($d >= ($radius - $thickness) && $d <= ($radius + $thickness)) { |
212
|
|
|
$dtoseg = abs($d - $radius); |
213
|
|
|
$prob = rand(0, 100); |
214
|
|
|
|
215
|
|
|
if (round($intensity - ($dtoseg * $intensity / $thickness)) >= $prob) { |
216
|
|
|
$type = $this->getSystem(); |
217
|
|
|
|
218
|
|
|
$this->nbSystem++; |
219
|
|
|
$this->listSystem[] = array($k, 0, 0, $xPosition, $yPosition, $type); |
220
|
|
|
|
221
|
|
|
$k++; |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
# GENERATION PAR VAGUES |
229
|
|
|
if ($this->galaxyConfiguration->galaxy['systemPosition'] !== NULL) { |
230
|
|
|
for ($i = 1; $i <= $this->galaxyConfiguration->galaxy['size']; $i++) { |
231
|
|
|
for ($j = 1; $j <= $this->galaxyConfiguration->galaxy['size']; $j++) { |
232
|
|
|
# current cursor position |
233
|
|
|
$xPosition = $j; |
234
|
|
|
$yPosition = $i; |
235
|
|
|
|
236
|
|
|
# calcul de la distance entre la case et le centre |
237
|
|
|
$d2o = sqrt( |
238
|
|
|
pow(abs(($this->galaxyConfiguration->galaxy['size'] / 2) - $xPosition), 2) + |
239
|
|
|
pow(abs(($this->galaxyConfiguration->galaxy['size'] / 2) - $yPosition), 2) |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
if ($this->isPointInMap($d2o)) { |
243
|
|
|
$type = $this->getSystem(); |
244
|
|
|
|
245
|
|
|
$this->nbSystem++; |
246
|
|
|
$this->listSystem[] = array($k, 0, 0, $xPosition, $yPosition, $type); |
247
|
|
|
|
248
|
|
|
$k++; |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
$this->log($this->nbSystem . ' systèmes générés'); |
255
|
|
|
$this->log('_ _ _ _'); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function generatePlace() { |
259
|
|
|
$this->log('génération des places'); |
260
|
|
|
$k = 1; |
261
|
|
|
|
262
|
|
|
foreach ($this->listSystem AS $system) { |
|
|
|
|
263
|
|
|
$sectorDanger = 0; |
264
|
|
|
foreach ($this->galaxyConfiguration->sectors as $sector) { |
|
|
|
|
265
|
|
|
if ($system[1] == $sector['id']) { |
266
|
|
|
$sectorDanger = $sector['danger']; |
267
|
|
|
break; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
$place = $this->getNbOfPlace($system[5]); |
272
|
|
|
|
273
|
|
|
for ($i = 0; $i < $place; $i++) { |
274
|
|
|
$type = $this->getTypeOfPlace($system[5]); |
275
|
|
|
|
276
|
|
|
if ($type == 1) { |
277
|
|
|
$pointsRep = rand(1, 10); |
278
|
|
|
$abilities = [ |
279
|
|
|
'population' => 0, |
280
|
|
|
'history' => 0, |
281
|
|
|
'resources' => 0 |
282
|
|
|
]; |
283
|
|
|
|
284
|
|
|
# nombre de point a distribuer |
285
|
|
|
if ($pointsRep < 2) { |
286
|
|
|
$pointsTot = rand(90, 100); |
287
|
|
|
} elseif ($pointsRep < 10) { |
288
|
|
|
$pointsTot = 100; |
289
|
|
|
} else { |
290
|
|
|
$pointsTot = rand(100, 120); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
# brassage du tableau |
294
|
|
|
Utils::shuffle($abilities); |
295
|
|
|
|
296
|
|
|
# répartition |
297
|
|
|
$z = 1; |
298
|
|
|
foreach ($abilities as $l => $v) { |
299
|
|
|
if ($z < 3) { |
300
|
|
|
$max = $pointsTot - ($z * 10); |
301
|
|
|
$max = $max < 10 ? 10 : $max; |
302
|
|
|
|
303
|
|
|
$points = rand(10, $max); |
304
|
|
|
$abilities[$l] = $points; |
305
|
|
|
$pointsTot -= $points; |
306
|
|
|
} else { |
307
|
|
|
$abilities[$l] = $pointsTot < 5 ? 5 : $pointsTot; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
$z++; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
$population = $abilities['population'] * 250 / 100; |
314
|
|
|
$history = $abilities['history']; |
315
|
|
|
$resources = $abilities['resources']; |
316
|
|
|
$stRES = 0; |
317
|
|
|
} elseif ($type == 6) { |
318
|
|
|
$population = 0; |
319
|
|
|
$history = 0; |
320
|
|
|
$resources = 0; |
321
|
|
|
$stRES = 0; |
322
|
|
|
} else { |
323
|
|
|
$population = $this->galaxyConfiguration->places[$type - 1]['credits']; |
|
|
|
|
324
|
|
|
$resources = $this->galaxyConfiguration->places[$type - 1]['resources']; |
325
|
|
|
$history = $this->galaxyConfiguration->places[$type - 1]['history']; |
326
|
|
|
$stRES = rand(2000000, 20000000); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
# TODO DANGER |
330
|
|
|
switch ($sectorDanger) { |
331
|
|
|
case GalaxyConfiguration::DNG_CASUAL: |
332
|
|
|
$danger = rand(0, Place::DNG_CASUAL); |
|
|
|
|
333
|
|
|
break; |
334
|
|
|
case GalaxyConfiguration::DNG_EASY: |
335
|
|
|
$danger = rand(3, Place::DNG_EASY); |
|
|
|
|
336
|
|
|
break; |
337
|
|
|
case GalaxyConfiguration::DNG_MEDIUM: |
338
|
|
|
$danger = rand(6, Place::DNG_MEDIUM); |
339
|
|
|
break; |
340
|
|
|
case GalaxyConfiguration::DNG_HARD: |
341
|
|
|
$danger = rand(9, Place::DNG_HARD); |
342
|
|
|
break; |
343
|
|
|
case GalaxyConfiguration::DNG_VERY_HARD: |
344
|
|
|
$danger = rand(12, Place::DNG_VERY_HARD); |
345
|
|
|
break; |
346
|
|
|
default: $danger = 0; break; |
|
|
|
|
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
$this->nbPlace++; |
350
|
|
|
$this->popTotal += $population; |
351
|
|
|
$this->listPlace[] = array($k, $system[0], $type, ($i + 1), $population, $resources, $history, $stRES, $danger, $danger); |
352
|
|
|
$k++; |
353
|
|
|
} |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
$this->log($this->nbPlace . ' places générées'); |
357
|
|
|
$this->log(Format::numberFormat($this->popTotal * 1000000) . ' de population'); |
358
|
|
|
$this->log('_ _ _ _'); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
public function generateSector() { |
362
|
|
|
$this->log('génération des secteurs'); |
363
|
|
|
$k = 1; |
364
|
|
|
|
365
|
|
|
foreach ($this->galaxyConfiguration->sectors as $sector) { |
|
|
|
|
366
|
|
|
$this->nbSector++; |
367
|
|
|
|
368
|
|
|
$prime = ($sector['beginColor'] != 0) |
369
|
|
|
? 1 |
370
|
|
|
: 0; |
371
|
|
|
|
372
|
|
|
$this->listSector[] = array( |
373
|
|
|
$k, |
374
|
|
|
$sector['beginColor'], |
375
|
|
|
$sector['display'][0], |
376
|
|
|
$sector['display'][1], |
377
|
|
|
$sector['barycentre'][0], |
378
|
|
|
$sector['barycentre'][1], |
379
|
|
|
5, |
380
|
|
|
0, |
381
|
|
|
0, |
382
|
|
|
$sector['name'], |
383
|
|
|
$prime, |
384
|
|
|
$sector['points'] |
385
|
|
|
); |
386
|
|
|
|
387
|
|
|
$k++; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
$this->log($this->nbSector . ' secteurs générés'); |
391
|
|
|
$this->log('_ _ _ _'); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
public function associateSystemToSector() { |
395
|
|
|
$pl = new PointLocation(); |
396
|
|
|
$systemToDelete = array(); |
397
|
|
|
$k = 0; |
398
|
|
|
|
399
|
|
|
foreach ($this->listSystem as $v) { |
400
|
|
|
foreach ($this->galaxyConfiguration->sectors as $w) { |
|
|
|
|
401
|
|
|
$place = $pl->pointInPolygon($v[3] . ', ' . $v[4], $w['vertices']); |
402
|
|
|
|
403
|
|
|
if ($place == 1 OR $place == 2) { |
|
|
|
|
404
|
|
|
$systemToDelete[] = $v[0]; |
405
|
|
|
break; |
406
|
|
|
} elseif ($place == 3) { |
407
|
|
|
$this->listSystem[$k][1] = $w['id']; |
408
|
|
|
break; |
409
|
|
|
} |
410
|
|
|
} |
411
|
|
|
$k++; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
foreach ($this->listSystem as $v) { |
415
|
|
|
if ($v[1] == 0) { |
416
|
|
|
$systemToDelete[] = $v[0]; |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
# suppression des systemes sur des lignes ou des angles |
421
|
|
|
for ($i = count($this->listSystem) - 1; $i >= 0; $i--) { |
422
|
|
|
if (in_array($this->listSystem[$i][0], $systemToDelete)) { |
423
|
|
|
unset($this->listSystem[$i]); |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
$this->systemDeleted = count($systemToDelete); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
protected function getStatisticsSector() { |
431
|
|
|
foreach ($this->listSector as $sector) { |
432
|
|
|
$id = $sector[0]; |
433
|
|
|
|
434
|
|
|
$qr = $this->databaseAdmin->prepare('SELECT |
435
|
|
|
COUNT(pl.id) AS planet, |
436
|
|
|
SUM(pl.population) AS population |
437
|
|
|
FROM sector AS se |
438
|
|
|
LEFT JOIN system AS sy |
439
|
|
|
ON se.id = sy.rSector |
440
|
|
|
LEFT JOIN place AS pl |
441
|
|
|
ON sy.id = pl.rSystem |
442
|
|
|
WHERE pl.typeOfPlace = 1 |
443
|
|
|
AND se.id = ?'); |
444
|
|
|
$qr->execute(array($id)); |
445
|
|
|
$aw = $qr->fetch(); |
446
|
|
|
|
447
|
|
|
$nbrPlanet = $aw['planet']; |
448
|
|
|
$population = ceil($aw['population']); |
449
|
|
|
|
450
|
|
|
$qr->closeCursor(); |
451
|
|
|
|
452
|
|
|
$qr = $this->databaseAdmin->prepare('UPDATE sector SET lifePlanet = ?, population = ? WHERE id = ?'); |
453
|
|
|
$qr->execute(array($nbrPlanet, $population, $id)); |
454
|
|
|
|
455
|
|
|
$qr->closeCursor(); |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
protected function isPointInMap($d2o) { |
460
|
|
|
$mask = rand(1, $this->galaxyConfiguration->galaxy['mask']); |
|
|
|
|
461
|
|
|
|
462
|
|
|
if ($mask < 3) { |
463
|
|
|
$realPosition = $this->galaxyConfiguration->galaxy['diag'] - $d2o; |
464
|
|
|
$step = $this->galaxyConfiguration->galaxy['diag'] / count($this->galaxyConfiguration->galaxy['systemPosition']); |
465
|
|
|
$currentStep = floor($realPosition / $step); |
466
|
|
|
|
467
|
|
|
$random = rand(0, 100); |
468
|
|
|
|
469
|
|
|
if ($this->galaxyConfiguration->galaxy['systemPosition'][$currentStep] > $random) { |
470
|
|
|
return TRUE; |
471
|
|
|
} else { |
472
|
|
|
return FALSE; |
473
|
|
|
} |
474
|
|
|
} else { |
475
|
|
|
return FALSE; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
protected function l2p($x1, $x2, $y1, $y2) { |
481
|
|
|
return (pow($x1 - $y1, 2) + pow($x2 - $y2, 2)); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
protected function distToSegment($p1, $p2, $v1, $v2, $w1, $w2) { |
485
|
|
|
$l2 = $this->l2p($v1, $v2, $w1, $w2); |
486
|
|
|
|
487
|
|
|
if ($l2 == 0) { |
488
|
|
|
return sqrt($this->l2p($p1, $p2, $v1, $v2)); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
$t = (($p1 - $v1) * ($w1 - $v1) + ($p2 - $v2) * ($w2 - $v2)) / $l2; |
492
|
|
|
|
493
|
|
|
if ($t < 0) { |
494
|
|
|
return sqrt($this->l2p($p1, $p2, $v1, $v2)); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
if ($t > 1) { |
498
|
|
|
return sqrt($this->l2p($p1, $p2, $w1, $w2)); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
$tx = $v1 + $t * ($w1 - $v1); |
502
|
|
|
$ty = $v2 + $t * ($w2 - $v2); |
503
|
|
|
|
504
|
|
|
return sqrt($this->l2p($p1, $p2, $tx, $ty)); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
protected function getProportion($params, $value) { |
508
|
|
|
$cursor = 0; |
509
|
|
|
$type = 0; |
510
|
|
|
$min = 0; |
511
|
|
|
$max = 0; |
|
|
|
|
512
|
|
|
|
513
|
|
|
for ($i = 0; $i < count($params); $i++) { |
|
|
|
|
514
|
|
|
if ($i == 0) { |
515
|
|
|
$max = $params[$i]; |
516
|
|
|
} elseif ($i < count($params) - 1) { |
517
|
|
|
$min = $cursor; |
518
|
|
|
$max = $cursor + $params[$i]; |
519
|
|
|
} else { |
520
|
|
|
$min = $cursor; |
521
|
|
|
$max = 100; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
$cursor = $max; |
525
|
|
|
$type += 1; |
526
|
|
|
|
527
|
|
|
|
528
|
|
|
if ($value > $min && $value <= $max) { |
529
|
|
|
return $type; |
530
|
|
|
} |
531
|
|
|
} |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
protected function getSystem() { |
535
|
|
|
return $this->getProportion($this->galaxyConfiguration->galaxy['systemProportion'], rand(1, 100)); |
|
|
|
|
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
protected function getNbOfPlace($systemType) { |
539
|
|
|
return rand( |
540
|
|
|
$this->galaxyConfiguration->systems[$systemType - 1]['nbrPlaces'][0], |
|
|
|
|
541
|
|
|
$this->galaxyConfiguration->systems[$systemType - 1]['nbrPlaces'][1] |
542
|
|
|
); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
protected function getTypeOfPlace($systemType) { |
546
|
|
|
return $this->getProportion($this->galaxyConfiguration->systems[$systemType - 1]['placesPropotion'], rand(1, 100)); |
|
|
|
|
547
|
|
|
} |
548
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.