mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-12-20 22:06:07 +01:00
Redone the spawn procedute and destination objects
This commit is contained in:
@@ -55,6 +55,12 @@ class Entity(EnvObject, abc.ABC):
|
||||
curr_x, curr_y = self.pos
|
||||
return last_x - curr_x, last_y - curr_y
|
||||
|
||||
def destroy(self):
|
||||
valid = self._collection.remove_item(self)
|
||||
for observer in self.observers:
|
||||
observer.notify_del_entity(self)
|
||||
return valid
|
||||
|
||||
def move(self, next_tile):
|
||||
curr_tile = self.tile
|
||||
if not_same_tile := curr_tile != next_tile:
|
||||
@@ -71,7 +77,7 @@ class Entity(EnvObject, abc.ABC):
|
||||
super().__init__(**kwargs)
|
||||
self._status = None
|
||||
self._tile = tile
|
||||
tile.enter(self)
|
||||
assert tile.enter(self, spawn=True), "Positions was not valid!"
|
||||
|
||||
def summarize_state(self) -> dict:
|
||||
return dict(name=str(self.name), x=int(self.x), y=int(self.y),
|
||||
|
||||
@@ -81,8 +81,12 @@ class Floor(EnvObject):
|
||||
def is_occupied(self):
|
||||
return bool(len(self._guests))
|
||||
|
||||
def enter(self, guest):
|
||||
if (guest.name not in self._guests and not self.is_blocked) and not (guest.var_is_blocking_pos and self.is_occupied()):
|
||||
def enter(self, guest, spawn=False):
|
||||
same_pos = guest.name not in self._guests
|
||||
not_blocked = not self.is_blocked
|
||||
no_become_blocked_when_occupied = not (guest.var_is_blocking_pos and self.is_occupied())
|
||||
not_introduce_collision = not (spawn and guest.var_can_collide and any(x.var_can_collide for x in self.guests))
|
||||
if same_pos and not_blocked and no_become_blocked_when_occupied and not_introduce_collision:
|
||||
self._guests.update({guest.name: guest})
|
||||
return c.VALID
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user