Skip to content

Commit

Permalink
Add Limiters to Spawning of Baubles and Dragons within the Cornucopia…
Browse files Browse the repository at this point in the history
… for The Hunger Baubles

Make Dragons spawned by The Hunger Baubles game respect Spawn Manager alive_time properties.
  • Loading branch information
hawkerm committed Jun 3, 2016
1 parent 7571645 commit 03a8685
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
43 changes: 35 additions & 8 deletions SBA_Serv/Game/TheHungerBaubles.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(self, cfgobj):
self.__maxcarry = cfgobj.getint("TheHungerBaubles", "ship_cargo_size")
self.__cornucopia_position = (0, 0)
self.__cornucopia_radius = cfgobj.getint("TheHungerBaubles", "cornucopia_radius")
self.__cornucopia_max_baubles = cfgobj.getint("TheHungerBaubles", "cornucopia_spawn_keep_max")
self.__cornucopia_spawn_baubles = cfgobj.getint("TheHungerBaubles", "cornucopia_spawn_time_num")
self.__spawned_num = 0

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

def __start_bauble_timer(self):
self.__bauble_spawner = CallbackTimer(cfg_rand_min_max(self.cfg, "TheHungerBaubles", "cornucopia_spawn_time"), self.__cornucopia_bauble_spawn)
Expand Down Expand Up @@ -269,21 +271,46 @@ def __cornucopia_bauble_spawn(self, init=False):
self.__start_bauble_timer()

# if we see a ship in the middle don't spawn
num_baubles = 0
baubles = []
num_dragons = 0
is_ship = False
for obj in self.world.getObjectsInArea(self.__cornucopia_position, self.__cornucopia_radius):
if isinstance(obj, Ship):
logging.info("Ship Detected in Cornucopia #%d", obj.id)
self.__spawn_fail = 3
if self.cfg.getboolean("TheHungerBaubles", "cornucopia_spawn_dragon"):
d = Dragon.spawn(self.world, self.cfg, self.__cornucopia_position)
logging.info("Spawned Dragon #%d in Cornucopia", d.id)
return
is_ship = True
elif isinstance(obj, Dragon):
num_dragons += 1
elif isinstance(obj, Bauble):
baubles.append(obj)
num_baubles += 1

if is_ship:
logging.info("Ship Detected in Cornucopia #%d", obj.id)
self.__spawn_fail = 3
if self.cfg.getboolean("TheHungerBaubles", "cornucopia_spawn_dragon") and num_dragons < self.cfg.getint("TheHungerBaubles", "cornucopia_spawn_max_dragons"):
d = self.spawnmanager.spawn_entity("Dragon", self.__cornucopia_position)
logging.info("Spawned Dragon #%d in Cornucopia", d.id)
else:
logging.info("Not Spawning Dragon or Full of Dragons")
return

# Only spawn Bauble if we haven't reached the max
if num_baubles >= self.__cornucopia_max_baubles:
logging.info("More Baubles %d in Cornucopia than configured %d, pruning", num_baubles, self.__cornucopia_max_baubles)
# delete oldest baubles
baubles.sort(key=lambda obj: obj.timealive, reverse = True)
numdel = min(len(baubles), num_baubles - self.__cornucopia_max_baubles + self.__cornucopia_spawn_baubles)
logging.info("Deleting %d Oldest Baubles", numdel)

for obj in baubles[:numdel]:
self.world.remove(obj)

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

if init:
num = self.cfg.getint("TheHungerBaubles", "cornucopia_spawn_initial_num")
else:
num = self.cfg.getint("TheHungerBaubles", "cornucopia_spawn_time_num")
num = self.__cornucopia_spawn_baubles

for i in xrange(num):
ang = random.randint(0, 359)
Expand Down
2 changes: 1 addition & 1 deletion SBA_Serv/buildnum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1122
1123
19 changes: 18 additions & 1 deletion SBA_Serv/game_thehungerbaubles.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
[Planet]
number = 4
number = 3

[Star]
number = 1

[BlackHole]
number = 1

[Nebula]
number = 2

[WormHole]
number = 3

Expand All @@ -14,6 +20,15 @@ spawn_time_num = 1
spawn_time_min = 20
spawn_time_max = 30

[Dragon]
number = 2
spawn_keep_max = 4
spawn_time_num = 1
spawn_time_min = 10
spawn_time_max = 20
spawn_alive_time_min = 20
spawn_alive_time_max = 40

[Bauble]
number = 10
buffer_object = 80
Expand Down Expand Up @@ -49,12 +64,14 @@ cornucopia_buffer_object = 250
collect_radius = 48
limit_weapons = true
cornucopia_spawn_initial_num = 3
cornucopia_spawn_keep_max = 5
cornucopia_spawn_time_num = 1
cornucopia_spawn_time_min = 10
cornucopia_spawn_time_max = 20
cornucopia_spawn_points = 3, 5, 7
cornucopia_spawn_dragon = true
cornucopia_spawn_initial_dragons = 1
cornucopia_spawn_max_dragons = 2
asteroid_bauble_percent = 0.5
asteroid_bauble_points = 1, 2, 3
dragon_bauble_percent = 1.0
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ v1.2 : Planned - May 2016 [Season 5] - The Hunger Baubles
* Hungry Hungry Baubles and Bauble Hunt now share new *[BaubleGame]* point/percentage spawning parameters.
* **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.
* *BaubleHuntGameInfo* has *getBaublesCarriedWeight* method now.
* One Time Commands (AllStop, FireTorpedo) have been modified with cooldown times (i.e. **AllStopCommand** now waits for 5 seconds after stopping before returning).
* RotateCommand/Orientation Related Client code now uses **int** vs. **double**.
* Client code now does some validation of command arguments, can **throw IllegalArgumentException**.
* **Removed SelfDestructCommand**
Expand Down
16 changes: 11 additions & 5 deletions doc/games/thehungerbaubles.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ The maximum number of baubles each ship can carry.
Should a new bauble be spawned every time one is collected?

###cornucopia_radius = int
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.
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.)

###cornucopia_buffer_edge = int
How far should the cornucopia be from the edge of the world.
What's the closest the cornucopia should be from the edge of the world.

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

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

###cornucopia_spawn_keep_max = int
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).

###cornucopia_spawn_time_num = int
How many baubles should spawn when the timer (see below) expires and there are no ships in the Cornucopia.
How many baubles should spawn when the timer expires and there are no ships in the Cornucopia.

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

###cornucopia_spawn_initial_dragons = int
How many Dragons should initial spawn in the Cornucopia?
How many Dragons should initially spawn in the Cornucopia?

###cornucopia_spawn_max_dragons = int
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.

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

0 comments on commit 03a8685

Please sign in to comment.