git @ Cat's Eye Technologies The-Swallows / bb64ab8
Refactor container shenanigans to hide_and_seek. Brandy! Lovely. Cat's Eye Technologies 11 years ago
1 changed file(s) with 75 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
1111
1212 # World:
1313 # more reacting to the dead body:
14 # - needing a drink (add liquor cabinet)
14 # - needing a drink
1515 # - calling the police
1616 # - trying to dispose of it
1717 # an unspeakable thing in the basement!
338338 revolver = z
339339 break
340340
341 # okay, look around you.
341342 for x in self.location.contents:
342343 if x == self:
343344 continue
414415
415416 # otherwise, fixate on some valuable object (possibly the revolver)
416417 # that you are carrying:
417 treasure = None
418 fixated_on = None
418419 for y in self.contents:
419420 if y.treasure():
420 treasure = y
421 fixated_on = y
421422 break
422 if not treasure and random.randint(0, 20) == 0:
423 if not fixated_on and random.randint(0, 20) == 0:
423424 for y in self.contents:
424425 if y.name == 'revolver':
425 treasure = y
426 fixated_on = y
426427 break
427428
428429 # check if you are alone
430431 if x.animate() and x is not self:
431432 people_about = True
432433
434 choice = random.randint(0, 25)
435 if choice < 10 and not people_about:
436 return self.hide_and_seek(fixated_on)
437 if choice < 20:
438 return self.wander()
439 if choice == 20:
440 self.emit("<1> yawned", [self])
441 if choice == 21:
442 self.emit("<1> gazed thoughtfully into the distance", [self])
443 if choice == 22:
444 self.emit("<1> thought <he-1> heard something", [self])
445 if choice == 23:
446 self.emit("<1> scratched <his-1> head", [self])
447 if choice == 24:
448 self.emit("<1> immediately had a feeling something was amiss", [self])
449 else:
450 return self.wander()
451
452 def hide_and_seek(self, fixated_on):
433453 # check for some place to hide the thing you're fixating on
454 containers = []
434455 for x in self.location.contents:
435 if x.container() and not people_about and treasure:
436 self.emit("<1> hid <2> in <3>", [self, y, x])
437 y.move_to(x)
438 self.memory[y.name] = Memory(y, x, i_hid_it_there=True)
439 return self.wander()
440 if x.container() and not people_about:
456 if x.container():
441457 # did I hide something here previously?
442 memory = None
458 memories = []
443459 for key in self.memory:
444 if self.memory[key].location == x and self.memory[key].i_hid_it_there:
445 memory = self.memory[key]
446 break
447 if memory and memory.subject.name == 'revolver':
448 y = memory.subject
449 self.emit("<1> retrieved <3> <he-1> had hidden in <2>",
450 [self, x, y])
451 if y.location != x:
452 self.emit("But <he-2> <was-2> missing", [self, y], excl=True)
460 if self.memory[key].location == x:
461 memories.append(self.memory[key])
462
463 containers.append((x, memories))
464 if not containers:
465 return self.wander()
466 # ok! we now have a list of containers, each of which has zero or more memories of things being in it.
467 if fixated_on:
468 (container, memories) = pick(containers)
469 self.emit("<1> hid <2> in <3>", [self, fixated_on, container])
470 fixated_on.move_to(container)
471 self.memory[fixated_on.name] = Memory(fixated_on, container, i_hid_it_there=True)
472 return self.wander()
473 else:
474 # we're looking for treasure!
475 (container, memories) = pick(containers)
476 if memories:
477 memory = pick(memories)
478 picking_up = random.randint(0, 5) == 0
479 if memory.subject.name == 'revolver':
480 picking_up = True
481 if picking_up:
482 if memory.i_hid_it_there:
483 self.emit("<1> retrieved <3> <he-1> had hidden in <2>",
484 [self, container, memory.subject])
485 else:
486 self.emit("<1> retrieved <3> from <2>",
487 [self, container, memory.subject])
488 # but!
489 if memory.subject.location != container:
490 self.emit("But <he-2> <was-2> missing", [self, memory.subject], excl=True)
453491 # forget ALLLLLLL about it, then. so realistic!
454 del self.memory[y.name]
492 del self.memory[memory.subject.name]
455493 else:
456494 memory.subject.move_to(self)
457 self.memory[y.name] = Memory(memory.subject, self)
458 elif memory:
459 y = memory.subject
495 self.memory[memory.subject.name] = Memory(memory.subject, self)
496 else:
460497 self.emit("<1> checked that <3> <was-3> still in <2>",
461 [self, x, memory.subject])
462 if memory.subject.location != x:
463 self.emit("But <he-2> <was-2> missing", [self, y], excl=True)
498 [self, container, memory.subject])
499 # but!
500 if memory.subject.location != container:
501 self.emit("But <he-2> <was-2> missing", [self, memory.subject], excl=True)
464502 del self.memory[memory.subject.name]
465 elif random.randint(0, 2) == 0:
466 self.emit("<1> searched <2>", [self, x])
467 for y in x.contents:
468 if y.notable() and y.takeable():
469 self.emit("<1> found <2> hidden there, and took <him-2>", [self, y])
470 y.move_to(self)
471 self.memory[y.name] = Memory(y, self)
472 if random.randint(0, 8) == 0:
473 which = random.randint(0, 5)
474 if which == 0:
475 self.emit("<1> yawned", [self])
476 if which == 1:
477 self.emit("<1> gazed thoughtfully into the distance", [self])
478 if which == 2:
479 self.emit("<1> thought <he-1> heard something", [self])
480 if which == 3:
481 self.emit("<1> scratched <his-1> head", [self])
482 if which == 4:
483 self.emit("<1> immediately had a feeling something was amiss", [self])
484 else:
485 return self.wander()
503 else: # no memories of this
504 self.emit("<1> searched <2>", [self, container])
505 for thing in container.contents:
506 if thing.notable() and thing.takeable():
507 self.emit("<1> found <2> hidden there, and took <him-2>", [self, thing])
508 thing.move_to(self)
509 self.memory[thing.name] = Memory(thing, self)
486510
487511 def converse(self, topic):
488512 self.topic = None
700724 jewels = PluralTreasure('stolen jewels', garage)
701725
702726 cupboards = Container('cupboards', kitchen)
703 cabinet = Container('cabinet', dining_room)
727 liquor_cabinet = Container('liquor cabinet', dining_room)
728 brandy = Item('bottle of brandy', liquor_cabinet)
704729 mailbox = Container('mailbox', driveway)
705730
706731 bobs_bed = Container("bed", bobs_bedroom)