def make_relations(city): """ Try to make relations between citizens of current city """ #we get all possible variants here, to see if we can make connection suspicion_of_connection = combinations(filter(lambda x: not x.dead, city.denizens), 2) for pair in suspicion_of_connection: #if they're still not acquainted - make them friends or enemies a, b = pair if a.dead or b.dead: continue if not a.know(b) and util.onechancein(3): a.ack(b, city) elif a.know(b): a.meet(b, city) for denizen in city.denizens: denizen.free_action(city) for deity in city.deities: deity.free_action(city) if isinstance(world.king, KingNPC): world.king.free_action(city) if city.plague_src : #if there is a plague in the city if util.onechancein(15) and city==world.capital and len(world.royalties): #infect royalty victim = choice(world.royalties) victim.plague = True elif util.onechancein(7) and len(city.denizens): victim = choice(city.denizens) victim.plague = True
def make_relations(city): """ Try to make relations between citizens of current city """ #we get all possible variants here, to see if we can make connection suspicion_of_connection = combinations( filter(lambda x: not x.dead, city.denizens), 2) for pair in suspicion_of_connection: #if they're still not acquainted - make them friends or enemies a, b = pair if a.dead or b.dead: continue if not a.know(b) and util.onechancein(3): a.ack(b, city) elif a.know(b): a.meet(b, city) for denizen in city.denizens: denizen.free_action(city) for deity in city.deities: deity.free_action(city) if isinstance(world.king, KingNPC): world.king.free_action(city) if city.plague_src: #if there is a plague in the city if util.onechancein(15) and city == world.capital and len( world.royalties): #infect royalty victim = choice(world.royalties) victim.plague = True elif util.onechancein(7) and len(city.denizens): victim = choice(city.denizens) victim.plague = True
def _add_enchants(wep, cost, single_digit=False): max_wait = 20 while cost > 0 and wep.enchantment < wep.max_enchantment and max_wait > 0: max_wait -= 1 if single_digit: if util.onechancein(3) and wep.enchantment < wep.max_enchantment and cost > 0: wep.enchantment += 1 cost -= ONE_PIECE_ENCHANTMENT else: for x in (0, 1): if util.onechancein(3) and wep.enchantment[x] < wep.max_enchantment[x] and cost > 0: wep.enchantment[x] += 1 cost -= ONE_PIECE_ENCHANTMENT
def acquire_armor(npc, unique=None, base_type=None, artefact=False): cost = TOP_COST_ARMOR + random.randrange(-1 * TOP_COST_ARMOR_RANGE, TOP_COST_ARMOR_RANGE) if base_type is None: base_type = random.choice(items.weapon) cost -= base_type.base_cost arm = base_type() if util.onechancein(6): cost -= _make_resist(arm) elif util.onechancein(7) or artefact: cost += FIXED_ART_UP cost -= _make_randart(arm, unique) cost -= _add_misc(arm, cost) _add_enchants(arm, cost, True) return arm
def fulfil(self, hero, chance=15): if util.onechancein(chance): #yeah, rescuing princesses is that simple world.global_quests.remove(self) hero.history.append('In year %d %s rescued %s' % (world.year, hero.name, self.who.name)) self.who.rescued_by(hero) self.issuer.award_for_quest(hero, self)
def fulfil(self, hero, chance=15): if util.onechancein(chance): thief = 'unknown man' if self.thief: thief = self.thief.name world.global_quests.remove(self) hero.history.append('In year %d %s retrieved %s from %s' % (world.year, hero.name, self.what.unique_name, thief)) hero.retrieved_stolen_from(self.thief, self.what, self.issuer, stolen=False)
def generate_artefacts(artefacts_count, check=None): """Generates as many artefacts as specified by artefacts_count argument.""" result = [] arts = artefacts[:] shuffle(arts) while artefacts_count > 0: artefacts_count -= 1 if util.onechancein(3) and len(arts) > 0: result.append(arts.pop()) else: result.append(acquire(unique=check, artefact=True)) return result
def acquire_weapon(npc, unique=None): cost = TOP_COST_WEP + random.randrange(-1 * TOP_COST_WEP_RANGE, TOP_COST_WEP_RANGE) base_type = random.choice(items.weapons) cost -= base_type.base_cost wep = base_type() if util.coinflip(): cost -= _make_brand(wep) if util.onechancein(5): cost += FIXED_ART_UP cost -= _make_randart(wep, unique) cost -= _add_misc(wep, cost) _add_enchants(wep, cost) return wep
def _add_misc(wep, cost): old_cost = cost accumulated_chance = 2 accumulated_cost = 100 feats = items.multilevel_features[:]*3 + items.innate_features[:] random.shuffle(feats) for feat in feats: if cost <= 0 : break if util.onechancein(accumulated_chance): wep.resists.append(feat) cost -= accumulated_cost accumulated_cost *= 3 accumulated_chance *= 2 return old_cost - cost
assign_random_name_from_list((WereNPC, BadNPC), world.demon_npc_names, demon=True) assign_random_name_from_list(DeityNPC, world.deity_npc_names) #all that left without names gets brand new name for npc in world.mNPC: if npc.name is None: name = util.gen_name(check_unique=world.npc_names) if debug_names: name += ' ' + str(npc.__class__) npc.name = name #now we handle WereNPC, so that each get his own proxy and target weres = filter(lambda x: isinstance(x, WereNPC), world.mNPC) wered_npc = {} for were in weres: while True: #first find target if util.onechancein(20): #mimic royalty if util.coinflip(): if wered_npc.has_key(world.king): continue were.target = world.king wered_npc[world.king] = were logger.debug('King will be WereNPC '+ were.name) else: royalty = choice(world.royalties) if wered_npc.has_key(royalty): continue were.target = royalty wered_npc[royalty] = were logger.debug('%s %s will be WereNPC %s' % (royalty.type, royalty.name, were.name)) break else: target = choice(world.mNPC) if isinstance(target, WereNPC): continue
def fulfil(self, hero, chance=15): if util.onechancein(chance): hero.retrieve_lost(self.issuer, self.what) world.global_quests.remove(self)
def _make_resist(arm): """ This is used for items with single resistance alowed - like armor """ if util.onechancein(5): arm.resist = "fire" return 400
demon=True) assign_random_name_from_list(DeityNPC, world.deity_npc_names) #all that left without names gets brand new name for npc in world.mNPC: if npc.name is None: name = util.gen_name(check_unique=world.npc_names) if debug_names: name += ' ' + str(npc.__class__) npc.name = name #now we handle WereNPC, so that each get his own proxy and target weres = filter(lambda x: isinstance(x, WereNPC), world.mNPC) wered_npc = {} for were in weres: while True: #first find target if util.onechancein(20): #mimic royalty if util.coinflip(): if wered_npc.has_key(world.king): continue were.target = world.king wered_npc[world.king] = were logger.debug('King will be WereNPC ' + were.name) else: royalty = choice(world.royalties) if wered_npc.has_key(royalty): continue were.target = royalty wered_npc[royalty] = were logger.debug('%s %s will be WereNPC %s' % (royalty.type, royalty.name, were.name)) break else: target = choice(world.mNPC)