Exemplo n.º 1
0
 def load_other_cars():
     if not cars:
         return self.mdt.fsm.demand('Countdown')
     car = cars.pop(0)
     car_class = Car
     if Server().is_active:
         car_class = NetworkCar  # if car in player_cars else Car
     if Client().is_active:
         car_class = NetworkCar
     s_p = self.track.get_start_pos(grid.index(car))
     pos, hpr = s_p[0] + (0, 0, .2), s_p[1]
     func = load_other_cars
     no_p = car not in player_cars
     srv_or_sng = Server().is_active or not Client().is_active
     car_class = AiCar if no_p and srv_or_sng else car_class
     drv = r_p.drivers[car]
     car_props = CarProps(
         car, r_p.coll_path, r_p.coll_name, pos, hpr, func,
         self.mdt, r_p.laps, r_p.keys, r_p.joystick, r_p.sounds,
         r_p.color_main, r_p.color, r_p.font, r_p.car_path,
         r_p.phys_file, r_p.wheel_names, r_p.tuning_engine,
         r_p.tuning_tires, r_p.tuning_suspensions, r_p.road_name,
         r_p.model_name, r_p.damage_paths, r_p.wheel_gfx_names,
         r_p.particle_path, drv.logic.engine, drv.logic.tires,
         drv.logic.suspensions, r_p.rocket_path, r_p.camera_vec,
         self.mdt.track.phys.waypoints, r_p.respawn_name,
         r_p.pitstop_name, r_p.wall_name, r_p.goal_name,
         r_p.bonus_name, r_p.roads_names, r_p.cars)
     new_car = car_class(car_props)
     game.cars += [new_car]
Exemplo n.º 2
0
 def process_srv(self, data_lst, sender):
     if data_lst[0] == NetMsgs.client_ready:
         ipaddr = sender.getAddress().getIpString()
         eng.log('client ready: ' + ipaddr)
         self.ready_clients += [sender]
         connections = Server().connections
         if all(client in self.ready_clients for client in connections):
             self.start_play()
             Server().send([NetMsgs.start_race])
Exemplo n.º 3
0
 def on_car(self, car):
     eng.log('car selected: ' + car)
     Server().send([NetMsgs.car_selection, car])
     for btn in self._buttons(car):
         btn['state'] = DISABLED
         btn.setAlphaScale(.25)
     if self in self.current_cars:
         curr_car = self.current_cars[self]
         eng.log('car deselected: ' + curr_car)
         Server().send([NetMsgs.car_deselection, curr_car])
         for btn in self._buttons(curr_car):
             btn['state'] = NORMAL
             btn.setAlphaScale(1)
     self.current_cars[self] = car
     eng.car_mapping['self'] = car
     self.evaluate_starting()
Exemplo n.º 4
0
 def process_srv(self, data_lst, sender):
     if data_lst[0] == NetMsgs.car_request:
         car = data_lst[1]
         eng.log('car requested: ' + car)
         btn = self._buttons(car)[0]
         if btn['state'] == DISABLED:
             Server().send([NetMsgs.car_deny], sender)
             eng.log('car already selected: ' + car)
         elif btn['state'] == NORMAL:
             eng.log('car selected: ' + car)
             if sender in self.current_cars:
                 _btn = self._buttons(self.current_cars[sender])[0]
                 _btn['state'] = NORMAL
                 _btn.setAlphaScale(1)
             self.current_cars[sender] = car
             btn['state'] = DISABLED
             btn.setAlphaScale(.25)
             Server().send([NetMsgs.car_confirm, car], sender)
             Server().send([NetMsgs.car_selection, car])
             eng.car_mapping[sender] = car
             self.evaluate_starting()
Exemplo n.º 5
0
 def enterRace(self, track_path='', car_path='', drivers=''):
     LogMgr().log('entering Race state')
     base.ignore('escape-up')
     if 'save' not in self.mdt.options.dct:
         self.mdt.options['save'] = {}
     self.mdt.options['save']['track'] = track_path
     self.mdt.options['save']['car'] = car_path
     self.mdt.options['save']['drivers'] = drivers
     self.mdt.options.store()
     keys = self.mdt.options['settings']['keys']
     joystick = self.mdt.options['settings']['joystick']
     sounds = {
         'engine': 'assets/sfx/engine.ogg',
         'brake': 'assets/sfx/brake.ogg',
         'crash': 'assets/sfx/crash.ogg',
         'crash_hs': 'assets/sfx/crash_high_speed.ogg',
         'lap': 'assets/sfx/lap.ogg',
         'landing': 'assets/sfx/landing.ogg'
     }
     if Server().is_active:
         self.season.create_race_server(keys, joystick, sounds)
     elif Client().is_active:
         self.season.create_race_client(keys, joystick, sounds)
     else:
         race_props = self.mdt.logic.build_race_props(
             car_path, drivers, track_path, keys, joystick, sounds)
         self.mdt.logic.season.create_race(race_props)
     LogMgr().log('selected drivers: ' + str(drivers))
     self.mdt.logic.season.race.logic.drivers = drivers
     track_name_transl = track_path
     track_dct = {
         'desert': _('desert'),
         'mountain': _('mountain'),
         'amusement': _('amusement park')
     }
     if track_path in track_dct:
         track_name_transl = track_dct[track_path]
     singlerace = game.logic.season.__class__ == SingleRaceSeason
     self.mdt.logic.season.race.fsm.demand(
         'Loading', track_path, car_path, [], drivers,
         ['prototype', 'desert', 'mountain', 'amusement'],
         track_name_transl, singlerace, [
             'kronos', 'themis', 'diones', 'iapeto', 'phoibe', 'rea',
             'iperion'
         ], 'assets/images/cars/%s_sel.png',
         'assets/images/drivers/driver%s_sel.png',
         game.options['settings']['joystick'],
         game.options['settings']['keys'],
         Utils().menu_args, 'assets/sfx/countdown.ogg')
     self.mdt.logic.season.race.attach_obs(self.mdt.logic.on_race_loaded)
     exit_meth = self.mdt.logic.on_ingame_exit_confirm
     self.mdt.logic.season.race.attach_obs(exit_meth)
Exemplo n.º 6
0
 def process_srv(self, data_lst, sender):
     if data_lst[0] == NetMsgs.player_info:
         self.__process_player_info(data_lst, sender)
     if data_lst[0] == NetMsgs.end_race_player:
         Server().send([NetMsgs.end_race])
         dct = {
             'kronos': 0,
             'themis': 0,
             'diones': 0,
             'iapeto': 0,
             'phoibe': 0,
             'rea': 0
         }
         self.mdt.fsm.demand('Results', dct)
         # forward the actual ranking
         self.mdt.gui.results.show(dct)
Exemplo n.º 7
0
 def on_frame(self):
     if not hasattr(self.mdt.logic, 'player_car') or \
             not hasattr(self.mdt.logic.player_car, 'phys') or \
             any([not hasattr(car, 'phys') for car in game.cars]):
         return  # still loading; attach when the race has started
     pos = self.mdt.logic.player_car.getPos()
     hpr = self.mdt.logic.player_car.getHpr()
     velocity = self.mdt.logic.player_car.getLinearVelocity()
     self.server_info['server'] = (pos, hpr, velocity)
     for car in [car for car in game.cars if car.ai_cls == CarAi]:
         pos = car.get_pos()
         hpr = car.get_hpr()
         velocity = car.getLinearVelocity()
         self.server_info[car] = (pos, hpr, velocity)
     if globalClock.getFrameTime() - self.last_sent > .2:
         Server().send(self.__prepare_game_packet())
         self.last_sent = globalClock.getFrameTime()
Exemplo n.º 8
0
    def evaluate_starting(self):
        connections = eng.connections + [self]
        if all(conn in self.current_cars for conn in connections):
            packet = [NetMsgs.start_race, len(self.current_cars)]

            def process(k):
                '''Processes a car.'''
                return 'server' if k == self else k.getAddress().getIpString()

            for k, val in self.current_cars.items():
                packet += [process(k), val]
            Server().send(packet)
            eng.log('start race: ' + str(packet))
            curr_car = self.current_cars[self]
            # manage as event
            game.logic.season = SingleRaceSeason()
            game.fsm.demand('Race', self.track_path, curr_car, packet[2:])
Exemplo n.º 9
0
 def build_page(self):
     menu_gui = self.menu.gui
     menu_args = self.menu.gui.menu_args
     sock = socket(AF_INET, SOCK_DGRAM)
     try:
         sock.connect(('ya2.it', 0))
         local_addr = sock.getsockname()[0]
         public_addr = load(urlopen('http://httpbin.org/ip'))['origin']
         addr = local_addr + ' - ' + public_addr
         self.add_widget(
             OnscreenText(text=addr,
                          scale=.12,
                          pos=(0, .4),
                          font=menu_args.font,
                          fg=menu_args.text_fg))
     except gaierror:
         eng.log('no connection')
     self.conn_txt = OnscreenText(scale=.12,
                                  pos=(0, .2),
                                  font=menu_args.font,
                                  fg=menu_args.text_fg)
     self.add_widget(self.conn_txt)
     tp_props = TrackPageProps(self.props.cars, self.props.car_path,
                               self.props.phys_path, self.props.tracks,
                               self.props.tracks_tr, self.props.track_img,
                               self.props.player_name,
                               self.props.drivers_img, self.props.cars_img,
                               self.props.drivers)
     self.add_widget(
         DirectButton(text=_('Start'),
                      pos=(0, 1, -.5),
                      command=lambda: self.menu.push_page(
                          TrackPageServer(self.menu, tp_props)),
                      **menu_gui.btn_args))
     ThanksPageGui.build_page(self)
     evt = self.mdt.event
     Server().start(evt.process_msg, evt.process_connection)
Exemplo n.º 10
0
 def _process_end_goal(self):
     Server().send([NetMsgs.end_race])
     CarPlayerEvent._process_end_goal(self)
Exemplo n.º 11
0
 def exit_play(self):
     Server().destroy()
     RaceLogic.exit_play(self)
Exemplo n.º 12
0
 def on_track(self, track):
     self.menu.track = track
     self.menu.push_page(CarPageServer(self.menu))
     Server().send([NetMsgs.track_selected, track])