def check_fleets(): for player in world.players.itervalues(): fleets = player.check_fleets() for _, fl in fleets: player.add_msg("Impossible de garder le controle de la flotte %s" % fl.name) return True
def set_priority(player, tech, spe, cesp): if player.set_priority(tech, spe, cesp): player.add_msg('Priorité de budget réglée') return True else: player.add_msg('Impossible de regler votre budget, il dépasse la limite') return False
def decolonize(player, race, asset, pla): if race not in pla.pops: player.add_msg('La décolonisation de la planete a échoué : race absente') return false pla.decolonize(race) player.add_msg('La décolonisation de la planete a réussie') return True
def scheme_add(player, scheme, compo, num): try: scheme.add_compo(compo, num) return True except: player.add_msg("Impossible d'ajouter %d %s sur le plan %s" % (num, compo.name, scheme.name)) return False
def scheme_mask(player, scheme): if scheme.owner != player: del player.schemes[scheme.id] player.add_msg("Vous venez de masquer le vaisseau %s" % scheme.name) return True else: player.add_msg("Vous ne pouvez pas masquer %s : vous êtes son créateur" % scheme.name) return False
def add_ships(player, fl, ship, num, race): try: _, dom = fl.mother.remove_ships((ship, race), num) fl.add_ships(ship, race, num, dom) except: player.add_msg("Impossible de transferer %d %s de la flotte %s vers %s" % num, ship.name, fl.mother.name, fl.name) return False return True
def construct_fleet(player, fleet, ship): if ship.get_carac(I('colo')) > 0 or ship.get_carac(I('SCM')) > 0: player.add_msg("Impossible de construire des %s depuis %s: %s" % (ship.name, fleet.name, "vaisseau interdit")) return False fleet.caracs[I('build_order')] = ship player.add_msg("La flotte %s a maintenant un ordre de construction de %s" % (fleet.name, ship.name)) return True
def terraformer_p(player, asset, planet): try: planet.terraform() except Exception as e: player.add_msg('Impossible de terraformer la planète %d sur %s: %s.' % (planet.position + 1, asset.name, str(e))) return False player.add_msg('Terraformation de la planète %d sur %s.' % (planet.position + 1, asset.name)) return True
def scheme_invalid(player, scheme): if scheme.owner == player: scheme.valid = False player.state[I('lim_scheme')] -= 1 assert(player.state[I('lim_scheme')] >= 0) player.add_msg("Vous venez d'invalider le vaisseau %s", scheme.name) return True else: player.add_msg("Vous ne pouvez pas invalider %s : vous n'êtes pas son" % (scheme.name, "créateur")) return False
def scheme_create(player, name, brand, domain, alliance, cut, sid): if sid in player.tmpschemes: raise Exception("Duplicate SID") if cut < 0 or cut > 100: player.add_msg("Impossible de creer le plan %s, les royaltises %s" % (name, "sont hors limites")) return False sch = scheme(player, name, brand, domain, cut) player.tmpschemes[sid] = sch world.tmpscheme[(player.id, sid)] = sch
def move(player, fleet, x, y, guideline, target_hum, target_pla): fleet.move = (x, y) fleet.caracs[I('behaviour')] = guideline if guideline == I('pla_conquest'): fleet.caracs[I('target')] = target_pla elif guideline == I('player_attack'): fleet.caracs[I('target')] = target_hum else: fleet.caracs[I('target')] = None player.add_msg('Votre flotte %s a pour nouvelle destination (%d, %d) en %s' % (fleet.name, x, y, S(guideline))) return True
def destroy_p(player, asset, pla, building, num): if building not in pla.constructions: player.add_msg('Impossible de détruire %d %s sur la planète %d de %s%s' % (num, building.name, pla.position + 1, asset.name, ': pas de construction de ce type')) return False num = pla.destroy(building, num) asset.add_ore(building.caracs[I('cost_ore')] * num / 2) player.set_budget(I('budget_destr'), building.caracs[I('cost_prod')]*num/3) player.add_msg('Destruction de %d %s sur la planète %d de %s' % (num, building.name, pla.position + 1, asset.name)) return True
def affect_tech(player, tech, point): if point < 0: player.add_msg("Impossible d'allouer moins de 0 points sur %s" % tech.name) return False if tech in player.research: player.research[tech] += point else: player.research[tech] = point # FIXME tech should be 1. player.bank[2] -= point player.add_msg("Vous avez alloué %d point sur %s" % (point, tech.name)) return True
def divide(player, fl, name, guideline, target_hum, target_pla, fid): if guideline == I('pla_conquest'): nfleet = fleet(player, name, fl.position, guideline, target_pla) elif guideline == I('player_attack'): nfleet = fleet(player, name, fl.position, guideline, target_hum) else: nfleet = fleet(player, name, fl.position, guideline) if fid in player.tmpfleets: raise Exception("duplicate FID") nfleet.mother = fl player.add_tmpfleet(fid, nfleet) player.add_msg("Division de la flotte %s, formation de %s" % (fl.name, nfleet.name)) return True
def absorb(player, fld_exist, fld_tmp, fls_exist, fls_tmp): def fusion(fl1, fl2): for sh_ra, nu_do in fl2.compos.iteritems(): fl1.add_ships(sh_ra[0], sh_ra[1], nu_do[0], nu_do[1]) fldst, flsrc = fld_exist, fls_exist if flsrc is None: flsrc = fls_tmp if fldst is None: fldst = fld_tmp if flsrc is None or fldst is None: raise Exception("Impossible de réalisation l'absorbtion relative à %s " % ("[%s %s %s %s]" % (str(fld_exist), str(fld_tmp), str(fls_exist), str(fls_tmp)))) fusion(fldst, flsrc) player.remove_fleet(flsrc) player.add_msg("Fusion entre %s et %s réussie" %(fldst.name, flsrc.name)) return True
def destroy(player, asset, building, num): already = 0 for p in asset.planets: if building in p.constructions: already += p.destroy(building, num - already) assert(already > num) if already == num: break if already == 0: player.add_msg('Impossible de détruire %d %s sur %s: pas de const%s' % (num, building.name, asset.name, 'ruction de ce type')) return False else: asset.add_ore(building.caracs[I('cost_ore')] * already / 2) player.set_budget(I('budget_destr'), building.caracs[I('cost_prod')] * already / 3) player.add_msg('Destruction de %d %s sur %s' % (num, building.name, asset.name)) return True
def colonize(player, fleet, race, asset, pla): if race in pla.pops: player.add_msg('La colonisation de la planete a échoué : pop dja la') return false if not pla.colonizable(race): player.add_msg('La colonisation de la planete a échoué : incolonizable') return false found = False for v, r in fleet.compos: if r != race or I('colo') not in v.caracs: continue fleet.remove_ships((v, r), 1) found = True break if found: pla.colonize(race) player.add_msg('La colonisation de la planete a réussie') return True else: player.add_msg('La colonisation de la planete a échoué: Pas de colo présent') return False
def terraformer(player, asset): error, success = False, False for p in asset.planets: try: p.terraform() success = True except Exception as e: player.add_msg('Impossible de terraformer la planète %d sur %s: %s.'% (p.position + 1, asset.name, str(e))) error = False if success and error: player.add_msg('Terraformation partielle de %s.' % asset.name) elif success and not error: player.add_msg('Terraformation de %s.' % asset.name) return not error
def construction_B(player, asset, building, count): assert(I('building') in building.caracs) asset.add_construction(build(building, count, None)) player.add_msg('Lancement de %d %s sur %s.' % (count, buidling.name, asset.name)) return True
def construction_Bp(player, asset, building, count, planet): assert(I('building') in building.caracs) asset.add_construction(build(building, count, planet)) player.add_msg('Lancement de %d %s sur %s %d.' % (count, building.name, asset.name, planet.position)) return True
def construction_Sf(player, asset, scheme, count, fleet): asset.add_construction(build(scheme, count, fleet.id)) player.add_msg('Lancement de %d %s pour la flotte %s sur %s.' % (count, scheme.name, fleet.name, asset.name)) return True
def change_policy(player, asset, policy): asset.policy = policy player.add_msg('Changement de politique sur %s: %s.' % (asset.name, S(policy))) return True
def change_taxe_p(player, asset, planet, taxe): planet.taxe = taxe player.add_msg('Changement de taxation sur la planète %d de %s: %s.' % (planet.position + 1, asset.name, S(taxe))) return True
def change_taxe(player, asset, taxe): for p in asset.planets.itervalues(): p.taxe = taxe player.add_msg('Changement de taxation sur %s: %s.' % (asset.name, S(taxe))) return True
def construction_S(player, asset, scheme, count): asset.add_construction(build(scheme, count, None)) player.add_msg('Lancement de %d %s sur %s.' % (count, scheme.name, asset.name)) return True