def cmd_THING_TYPE(game, i, type_):
- t = game.get_thing(i)
+ t = game.get_thing(i, create_unfound=True)
t.type_ = type_
cmd_THING_TYPE.argtypes = 'int:nonneg string'
def cmd_THING_POS(game, i, yx):
- t = game.get_thing(i)
+ t = game.get_thing(i,create_unfound=True)
t.position = YX(0,0), yx
cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'
@property
def player(self):
- return self.get_thing(self.player_id)
+ return self.get_thing(self.player_id, create_unfound=False)
def get_command(self, command_name):
from functools import partial
counter = 0
for id_ in self.selection:
pointer = '*' if counter == self.tui.item_pointer else ' '
- t = self.tui.game.get_thing(id_)
+ t = self.tui.game.get_thing(id_, create_unfound=False)
lines += ['%s %s' % (pointer, t.type_)]
counter += 1
line_width = self.size.x
cmd_MAP_STATS = 'yx_tuple string:thingtype int:nonneg int:nonneg'
def cmd_THING_TYPE(game, i, type_):
- t_old = game.get_thing(i)
+ t_old = game.get_thing(i, create_unfound=True)
t_new = game.thing_types[type_](game, i)
#attr_names_of_old = [name for name in dir(t_old) where name[:2] != '__']
#attr_names_of_new = [name for name in dir(t_new) where name[:2] != '__']
cmd_THING_TYPE.argtypes = 'int:nonneg string:thingtype'
def cmd_THING_POS(game, i, big_yx, small_yx):
- t = game.get_thing(i)
+ t = game.get_thing(i, create_unfound=True)
t.position = (big_yx, small_yx)
cmd_THING_POS.argtypes = 'int:nonneg yx_tuple yx_tuple:nonneg'
def cmd_THING_INVENTORY(game, id_, ids):
- carrier = game.get_thing(id_)
+ carrier = game.get_thing(id_, create_unfound=True)
carrier.inventory = ids
for id_ in ids:
- t = game.get_thing(id_)
+ t = game.get_thing(id_, create_unfound=True)
t.in_inventory = True
t.position = carrier.position
cmd_THING_INVENTORY.argtypes = 'int:nonneg seq:int:nonneg'
def cmd_THING_HEALTH(game, id_, health):
- t = game.get_thing(id_)
+ t = game.get_thing(id_, create_unfound=True)
t.health = health
cmd_THING_HEALTH.argtypes = 'int:nonneg int:nonneg'
self.turn = 0
self.things = []
- def get_thing(self, id_, create_unfound=True):
+ def get_thing(self, id_, create_unfound):
+ # No default for create_unfound because every call to get_thing
+ # should be accompanied by serious consideration whether to use it.
for thing in self.things:
if id_ == thing.id_:
return thing
else:
self.io.send('PLAYER_INVENTORY ,')
for id_ in self.player.inventory:
- thing = self.get_thing(id_)
+ thing = self.get_thing(id_, create_unfound=False)
send_thing(thing)
self.io.send('GAME_STATE_COMPLETE')
@property
def player(self):
- return self.get_thing(self.player_id)
+ return self.get_thing(self.player_id, create_unfound=False)
def new_thing_id(self):
if len(self.things) == 0:
return 0
# DANGEROUS – if anywhere we append a thing to the list of lower
# ID than the highest-value ID, this might lead to re-using an
- # already active ID. This should not happen anywhere in the
- # code, but a break here might be more visible.
+ # already active ID. This condition /should/ not be fulfilled
+ # anywhere in the code, but if it does, trouble here is one of
+ # the more obvious indicators that it does – that's why there's
+ # no safeguard here against this.
return self.things[-1].id_ + 1
def get_map(self, map_pos):
% self.args[0])
def do(self):
- to_pick_up = self.thing.game.get_thing(self.args[0])
+ to_pick_up = self.thing.game.get_thing(self.args[0],
+ create_unfound=False)
self.thing.inventory += [self.args[0]]
to_pick_up.in_inventory = True
to_pick_up.position = self.thing.position
return item
def _eliminate_from_inventory(self):
- item = self.thing.game.get_thing(self.args[0])
+ item = self.thing.game.get_thing(self.args[0], create_unfound=False)
del self.thing.inventory[self.thing.inventory.index(item.id_)]
item.in_inventory = False
return item
def _position_set(self, pos):
super()._position_set(pos)
for t_id in self.inventory:
- t = self.game.get_thing(t_id)
+ t = self.game.get_thing(t_id, create_unfound=False)
t.position = self.position
if not self.id_ == self.game.player_id:
return
def hunt_food_satisfaction(self):
for id_ in self.inventory:
- t = self.game.get_thing(id_)
+ t = self.game.get_thing(id_, create_unfound=False)
if t.type_ == 'food':
self.set_task('EAT', (id_,))
return True
for id_ in self.get_pickable_items():
- t = self.game.get_thing(id_)
+ t = self.game.get_thing(id_, create_unfound=False)
if t.type_ == 'food':
self.set_task('PICKUP', (id_,))
return True