Skip to content

Commit 03a8685

Browse files
committed
Add Limiters to Spawning of Baubles and Dragons within the Cornucopia for The Hunger Baubles
Make Dragons spawned by The Hunger Baubles game respect Spawn Manager alive_time properties.
1 parent 7571645 commit 03a8685

File tree

5 files changed

+66
-15
lines changed

5 files changed

+66
-15
lines changed

SBA_Serv/Game/TheHungerBaubles.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def __init__(self, cfgobj):
4040
self.__maxcarry = cfgobj.getint("TheHungerBaubles", "ship_cargo_size")
4141
self.__cornucopia_position = (0, 0)
4242
self.__cornucopia_radius = cfgobj.getint("TheHungerBaubles", "cornucopia_radius")
43+
self.__cornucopia_max_baubles = cfgobj.getint("TheHungerBaubles", "cornucopia_spawn_keep_max")
44+
self.__cornucopia_spawn_baubles = cfgobj.getint("TheHungerBaubles", "cornucopia_spawn_time_num")
4345
self.__spawned_num = 0
4446

4547
self.collect_radius = cfgobj.getint("TheHungerBaubles", "collect_radius")
@@ -232,7 +234,7 @@ def round_start(self):
232234
# spawn some dragons
233235
for num in xrange(self.cfg.getint("TheHungerBaubles", "cornucopia_spawn_initial_dragons")):
234236
pos = (self.__cornucopia_position[0] + random.randint(-64, 64), self.__cornucopia_position[1] + random.randint(-64, 64))
235-
Dragon.spawn(self.world, self.cfg, pos)
237+
self.spawnmanager.spawn_entity("Dragon", pos)
236238

237239
def __start_bauble_timer(self):
238240
self.__bauble_spawner = CallbackTimer(cfg_rand_min_max(self.cfg, "TheHungerBaubles", "cornucopia_spawn_time"), self.__cornucopia_bauble_spawn)
@@ -269,21 +271,46 @@ def __cornucopia_bauble_spawn(self, init=False):
269271
self.__start_bauble_timer()
270272

271273
# if we see a ship in the middle don't spawn
274+
num_baubles = 0
275+
baubles = []
276+
num_dragons = 0
277+
is_ship = False
272278
for obj in self.world.getObjectsInArea(self.__cornucopia_position, self.__cornucopia_radius):
273279
if isinstance(obj, Ship):
274-
logging.info("Ship Detected in Cornucopia #%d", obj.id)
275-
self.__spawn_fail = 3
276-
if self.cfg.getboolean("TheHungerBaubles", "cornucopia_spawn_dragon"):
277-
d = Dragon.spawn(self.world, self.cfg, self.__cornucopia_position)
278-
logging.info("Spawned Dragon #%d in Cornucopia", d.id)
279-
return
280+
is_ship = True
281+
elif isinstance(obj, Dragon):
282+
num_dragons += 1
283+
elif isinstance(obj, Bauble):
284+
baubles.append(obj)
285+
num_baubles += 1
286+
287+
if is_ship:
288+
logging.info("Ship Detected in Cornucopia #%d", obj.id)
289+
self.__spawn_fail = 3
290+
if self.cfg.getboolean("TheHungerBaubles", "cornucopia_spawn_dragon") and num_dragons < self.cfg.getint("TheHungerBaubles", "cornucopia_spawn_max_dragons"):
291+
d = self.spawnmanager.spawn_entity("Dragon", self.__cornucopia_position)
292+
logging.info("Spawned Dragon #%d in Cornucopia", d.id)
293+
else:
294+
logging.info("Not Spawning Dragon or Full of Dragons")
295+
return
296+
297+
# Only spawn Bauble if we haven't reached the max
298+
if num_baubles >= self.__cornucopia_max_baubles:
299+
logging.info("More Baubles %d in Cornucopia than configured %d, pruning", num_baubles, self.__cornucopia_max_baubles)
300+
# delete oldest baubles
301+
baubles.sort(key=lambda obj: obj.timealive, reverse = True)
302+
numdel = min(len(baubles), num_baubles - self.__cornucopia_max_baubles + self.__cornucopia_spawn_baubles)
303+
logging.info("Deleting %d Oldest Baubles", numdel)
304+
305+
for obj in baubles[:numdel]:
306+
self.world.remove(obj)
280307

281308
values = map(int, self.cfg.get("TheHungerBaubles", "cornucopia_spawn_points").split(","))
282309

283310
if init:
284311
num = self.cfg.getint("TheHungerBaubles", "cornucopia_spawn_initial_num")
285312
else:
286-
num = self.cfg.getint("TheHungerBaubles", "cornucopia_spawn_time_num")
313+
num = self.__cornucopia_spawn_baubles
287314

288315
for i in xrange(num):
289316
ang = random.randint(0, 359)

SBA_Serv/buildnum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1122
1+
1123

SBA_Serv/game_thehungerbaubles.cfg

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
[Planet]
2-
number = 4
2+
number = 3
3+
4+
[Star]
5+
number = 1
36

47
[BlackHole]
58
number = 1
69

10+
[Nebula]
11+
number = 2
12+
713
[WormHole]
814
number = 3
915

@@ -14,6 +20,15 @@ spawn_time_num = 1
1420
spawn_time_min = 20
1521
spawn_time_max = 30
1622

23+
[Dragon]
24+
number = 2
25+
spawn_keep_max = 4
26+
spawn_time_num = 1
27+
spawn_time_min = 10
28+
spawn_time_max = 20
29+
spawn_alive_time_min = 20
30+
spawn_alive_time_max = 40
31+
1732
[Bauble]
1833
number = 10
1934
buffer_object = 80
@@ -49,12 +64,14 @@ cornucopia_buffer_object = 250
4964
collect_radius = 48
5065
limit_weapons = true
5166
cornucopia_spawn_initial_num = 3
67+
cornucopia_spawn_keep_max = 5
5268
cornucopia_spawn_time_num = 1
5369
cornucopia_spawn_time_min = 10
5470
cornucopia_spawn_time_max = 20
5571
cornucopia_spawn_points = 3, 5, 7
5672
cornucopia_spawn_dragon = true
5773
cornucopia_spawn_initial_dragons = 1
74+
cornucopia_spawn_max_dragons = 2
5875
asteroid_bauble_percent = 0.5
5976
asteroid_bauble_points = 1, 2, 3
6077
dragon_bauble_percent = 1.0

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ v1.2 : Planned - May 2016 [Season 5] - The Hunger Baubles
4343
* Hungry Hungry Baubles and Bauble Hunt now share new *[BaubleGame]* point/percentage spawning parameters.
4444
* **Bauble Hunt** now respects weight not number carried for *ship_cargo_size*. Default weights are set to 1 though to behave in same manner as previously.
4545
* *BaubleHuntGameInfo* has *getBaublesCarriedWeight* method now.
46+
* One Time Commands (AllStop, FireTorpedo) have been modified with cooldown times (i.e. **AllStopCommand** now waits for 5 seconds after stopping before returning).
4647
* RotateCommand/Orientation Related Client code now uses **int** vs. **double**.
4748
* Client code now does some validation of command arguments, can **throw IllegalArgumentException**.
4849
* **Removed SelfDestructCommand**

doc/games/thehungerbaubles.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ The maximum number of baubles each ship can carry.
6969
Should a new bauble be spawned every time one is collected?
7070

7171
###cornucopia_radius = int
72-
How big should the cornucopia area be. If your ship's position is within this radius distance from the cornucopia position, the cornucopia won't spawn baubles.
72+
How big should the cornucopia area be. If your ship's position is within this radius distance from the cornucopia position, the cornucopia won't spawn baubles. (Note the visual ring on screen is slightly smaller so it looks like the edge of your ship needs to cross - though it is calculated like everything else by midpoints.)
7373

7474
###cornucopia_buffer_edge = int
75-
How far should the cornucopia be from the edge of the world.
75+
What's the closest the cornucopia should be from the edge of the world.
7676

7777
###cornucopia_buffer_object = int
78-
How far should the cornucopia be from the edge of other objects.
78+
What's the closest the cornucopia should be from the edge of other objects.
7979

8080
###collect_radius = int
8181
How far can a bauble be away from the ship for the Collect Command to pick it up.
@@ -86,8 +86,11 @@ Should each player be limited to having one torpedo and one space mine in the wo
8686
###cornucopia_spawn_initial_num = int
8787
How many baubles should be spawned in the Cornucopia at the start of each round.
8888

89+
###cornucopia_spawn_keep_max = int
90+
How many baubles should remain in the Cornucopia. Baubles over this number which have remained in the Cornucopia the longest will be removed when the timer goes off (see below).
91+
8992
###cornucopia_spawn_time_num = int
90-
How many baubles should spawn when the timer (see below) expires and there are no ships in the Cornucopia.
93+
How many baubles should spawn when the timer expires and there are no ships in the Cornucopia.
9194

9295
###cornucopia_spawn_time_min = int
9396
What's the minimum random time to elapse before trying to spawn baubles in the Cornucopia.
@@ -102,7 +105,10 @@ What value of baubles should spawn in the Cornucopia? These values must exist i
102105
Should the Cornucopia spawn a dragon at the Cornucopia position if a ship is detected instead when it tries to spawn a Bauble?
103106

104107
###cornucopia_spawn_initial_dragons = int
105-
How many Dragons should initial spawn in the Cornucopia?
108+
How many Dragons should initially spawn in the Cornucopia?
109+
110+
###cornucopia_spawn_max_dragons = int
111+
How many Dragons should be allowed in the Cornucopia? A new Dragon won't be spawned for ships if this number is reached and the Dragons remain within the Cornucopia.
106112

107113
###asteroid_bauble_percent = float
108114
Percent Chance [0.0-1.0] that a Bauble is dropped when a player torpedos an Asteroid.

0 commit comments

Comments
 (0)