source: lost-haven/main/SpawnPoint.java@ 8edd04e

Last change on this file since 8edd04e was 8edd04e, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Make the decompiled game code compile successfully

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[8edd04e]1package main;
2
3import java.util.Iterator;
4import java.util.Random;
5
6public class SpawnPoint {
7
8 static int numSpawnPoints = 0;
9
10 Point loc;
11 long lastSpawned;
12 long interval;
13 Creature creature;
14 int numSpawns;
15 int maxSpawns;
16 int idNum;
17
18 public SpawnPoint(Creature creature, Point loc, long interval, int maxSpawns) {
19 this.creature = creature;
20 this.loc = loc;
21 this.interval = interval;
22 this.maxSpawns = maxSpawns;
23 this.lastSpawned = 0L;
24 this.idNum = ++numSpawnPoints;
25 }
26
27 public Creature spawn() {
28 if (System.currentTimeMillis() - this.lastSpawned >= this.interval && this.numSpawns < this.maxSpawns) {
29 this.lastSpawned = System.currentTimeMillis();
30 Creature cr = this.creature.copy();
31 Point newLoc = null;
32 Random gen = new Random();
33 boolean goodLoc = false, occupied = false;
34 while (!goodLoc) {
35 newLoc = new Point(this.loc.getX() - 400 + gen.nextInt(800), this.loc.getY() - 400 + gen.nextInt(800));
36 if (newLoc.getX() >= 0 && newLoc.getY() >= 0 && LostHavenRPG.map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100).isPassable() && Point.dist(newLoc, this.loc) <= 400.0D) {
37 occupied = false;
38 int xLow = newLoc.getX() / 100 - 2;
39 int xHigh = xLow + 5;
40 int yLow = newLoc.getY() / 100 - 2;
41 int yHigh = yLow + 5;
42 if (xLow < 0) {
43 xLow = 0;
44 }
45 if (xHigh > LostHavenRPG.map.getLength()) {
46 xHigh = LostHavenRPG.map.getLength();
47 }
48 if (yLow < 0) {
49 yLow = 0;
50 }
51 if (yHigh > LostHavenRPG.map.getHeight()) {
52 yHigh = LostHavenRPG.map.getHeight();
53 }
54 for (int x = xLow; x < xHigh; x++) {
55 for (int y = yLow; y < yHigh; y++) {
56 Iterator<Creature> iter = LostHavenRPG.map.getLoc(x, y).getCreatures().iterator();
57 while (iter.hasNext() && !occupied) {
58 Creature cur = iter.next();
59 if (Point.dist(cur.getLoc(), newLoc) < 100.0D) {
60 occupied = true;
61 }
62 }
63 }
64 }
65 if (!occupied) {
66 goodLoc = true;
67 }
68 }
69 }
70 cr.setLoc(newLoc);
71 cr.setSpawnPoint(this);
72 this.numSpawns++;
73 return cr;
74 }
75
76 return null;
77 }
78
79 public CreatureType getType() {
80 return this.creature.getType();
81 }
82
83 public Point getLoc() {
84 return this.loc;
85 }
86
87 public void removeCreature() {
88 this.numSpawns--;
89 }
90
91 public void clear() {
92 this.numSpawns = 0;
93 this.lastSpawned = 0L;
94 }
95}
Note: See TracBrowser for help on using the repository browser.