Commit d746ccb66420a4cc65ae884c09869a6f1ad6c80d

Authored by dg
1 parent b72b12f1

fix


git-svn-id: http://svn.net-core.org/repos/t-engine4@2639 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -40,10 +40,25 @@ end
40 40 function _M:getSpawnSpot(m)
41 41 -- Spawn near a spot
42 42 if rng.percent(self.on_spot_chance) then
  43 + -- Cycle through spots, looking for one with empty spaces
  44 + local tries = 0
43 45 local spot = rng.table(self.spots)
44   - if not spot then return end
  46 + if not spot then
  47 + print("No spots for spawning")
  48 + return
  49 + end
45 50 local _, _, gs = util.findFreeGrid(spot.x, spot.y, self.spot_radius, "block_move", {[Map.ACTOR]=true})
46   - local tries = 0
  51 + while not gs and tries < 10 do
  52 + spot = rng.table(self.spots)
  53 + _, _, gs = util.findFreeGrid(spot.x, spot.y, self.spot_radius, "block_move", {[Map.ACTOR]=true})
  54 + tries = tries + 1
  55 + end
  56 + if not gs then
  57 + print("No more free space for spawning")
  58 + return
  59 + end
  60 + -- Cycle through available spaces
  61 + tries = 0
47 62 local g = rng.table(gs)
48 63 local x, y = g[1], g[2]
49 64 while (not m:canMove(x, y) or (self.map.room_map[x][y] and self.map.room_map[x][y].special)) and tries < 100 do
... ...
... ... @@ -26,6 +26,7 @@ function _M:init(zone, map, level, spots)
26 26 Random.init(self, zone, map, level, spots)
27 27 local data = level.data.generator.actor
28 28 self.on_spot_chance = data.on_spot_chance or 70
  29 + self.spot_radius = data.spot_radius or 8
29 30 self.spot_filters = data.spot_filters or {{special=function(spot) return spot.spawned_actors and true or false end}}
30 31
31 32 -- Pick a number of spots
... ... @@ -39,17 +40,25 @@ end
39 40 function _M:getSpawnSpot(o)
40 41 -- Spawn near a spot
41 42 if rng.percent(self.on_spot_chance) then
42   - local spot = rng.table(self.spots)
43   - if not spot then return end
44   - local _, _, gs = util.findFreeGrid(spot.x, spot.y, 8, "block_move", {[Map.OBJECT]=true})
  43 + -- Cycle through spots, looking for one with empty spaces
45 44 local tries = 0
46   - local g = rng.table(gs)
47   - local x, y = g[1], g[2]
48   - while (self.map:checkEntity(x, y, Map.TERRAIN, "block_move") or self.map(x, y, Map.OBJECT) or (self.map.room_map[x][y] and self.map.room_map[x][y].special)) and tries < 100 do
49   - g = rng.table(gs)
50   - x, y = g[1], g[2]
  45 + local spot = rng.table(self.spots)
  46 + if not spot then
  47 + print("No spots for spawning")
  48 + return
  49 + end
  50 + local _, _, gs = util.findFreeGrid(spot.x, spot.y, self.spot_radius, "block_move", {[Map.OBJECT]=true})
  51 + while not gs and tries < 10 do
  52 + spot = rng.table(self.spots)
  53 + _, _, gs = util.findFreeGrid(spot.x, spot.y, self.spot_radius, "block_move", {[Map.OBJECT]=true})
51 54 tries = tries + 1
52 55 end
  56 + if not gs then
  57 + print("No more free space for spawning")
  58 + return
  59 + end
  60 + -- Cycle through available spaces
  61 + tries = 0
53 62 if tries < 100 then
54 63 print("Spawning ", o.name, " near ", spot.type, spot.subtype, " at ", x, y)
55 64 -- Count an actor there
... ...