示例#1
0
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
示例#2
0
def inscription(name, domain, race):
    p = player(name, domain, race, world.tour)
    print "inscript id = " + str(p.id)
    z = zone(race)
    for a in world.neutral.assets.itervalues():
        if in_zone(a.referer.position, z):
            p.add_asset(a)
            world.neutral.del_asset(a.id)
            break
    else:
        raise Exception('Init system not found')
    
    # ajout des technos publiques
    for t in world.technos.itervalues():
        if I('public') in t.caracs:
            p.add_techno(t)
    p.compute_ftech(world)

    # ajout des plans publiques
    for v in world.schemes.itervalues():
        if v.domain == I('public'):
            p.add_scheme(v)

    #creation des flottes
    fl = fleet(p, 'Flotte de départ', a.referer.position)
    fl.add_ships(world.def_ships['Chasseur Standart'], race, 10, 0)
    fl.add_ships(world.def_ships['Chasseur Lourd'], race, 5, 0)
    fl.add_ships(world.def_ships['Colonisateur Standart'], race, 15, 0)
    fl.add_ships(world.def_ships['Sonde Standart'], race, 2, 0)
    fl.add_ships(world.def_ships['Croiseur'], race, 1, 0)
    fl.add_ships(world.def_ships['Vaisseau Usine'], race, 5, 0)
    fl.add_ships(world.def_ships['mdcIV'], race, 5, 0)
    p.add_fleet(fl)
    
    world.players[p.id]= p
示例#3
0
    def build_construction(self, c):
        ore = c.what.get_carac(I('cost_ore')) * c.count
        if ore > self.ore:
            raise Exception('pas assez de minerai')
        cent = c.what.get_carac(I('cost_prod')) * c.count
        if cent > self.owner.bank[0]:
            raise Exception('pas assez de centaure')
        if isinstance(c.what, scheme) and not c.what.valid:
            raise Exception('plan invalide')

        self.remove_ore(ore)
        self.owner.set_budget(I('budget_const'), cent)
        if isinstance(c.what, techno):
            if c.target:
                if c.what in c.target.constructions:
                    c.target.constructions[c.what] += c.count
                else:
                    c.target.constructions[c.what] = c.count
                self.owner.add_msg(('Construction de %d %s sur la planete %d '
                                    'de %s.') % (c.count, c.what.name, 
                                                 c.target.position +1, 
                                                 self.name))
            else:
                self.add_constructions(c.what, c.count)
                self.owner.add_msg('Construction de %d %s sur %s.' %
                                   (c.count, c.what.name, self.name))
        else:
            ok = True

            if c.target in self.owner.fleets:
                f = self.owner.fleets[c.target]
                if (I('civilian') in f.caracs and 
                    I('military') in c.what.caracs and
                    self.owner.state[I('lim_flmil')] >= 
                                        self.owner.limits[I('lim_flmil')]):
                    ok = False

                if dist(f.position, self.referer.position) > 20:
                    ok = False
            else:
                ok = False

            if not ok:
                for fl in self.owner.fleets.itervalues():
                    if (I('civilian') in fl.caracs and 
                        I('military') in c.what.caracs):
                        continue
                    
                    if fl.position == self.referer.position:
                        f = fl
                        ok = True

            if not ok:
                if I('military') in c.what.caracs:
                    lim = I('lim_flmil')
                else:
                    lim = I('lim_flciv')

                if self.owner.state[lim] < self.owner.limits[lim]:
                    f = fleet(self.owner, "Fleet " + self.name, 
                                  self.referer.position)
                    self.owner.add_fleet(f)
                    ok = True

            if not ok:
                d = 999 # FIXME MAX_INT
                for fl in self.owner.fleets.itervalues():
                    if I('civilian') in fl.caracs and I('military') in c.what.caracs:
                        continue
                    if dist(fl.position, self.referer.position) < d:
                        d = dist(fl.position, self.referer.position)
                        f = fl
                        ok = True
            
            assert(ok)
            f.add_ships(c.what, self.get_race(), c.count, 0)
            self.owner.add_msg('Construction de %d %s sur %s %s %s' %
                               (c.count, c.what.name, self.name, 
                               'intégré dans', f.name))