Exemple #1
0
    def __init__(self, world, instanceName, connection):
        SNetActor.__init__(self, instanceName)
        self.world = world
        self.connection = connection
        self.sight = None
        self.pawn = None

        sightX, sightY = 4, 4
        self.sight = SSight(world,
                            location=(32 * sightX, 32 * sightY),
                            instanceName=instanceName + 'Sight',
                            sightRange=2,
                            user=self.channel).channel

        self.pawn = SPrey(world,
                          location=(32 * sightX + 16, 32 * sightY + 16),
                          velocity=0,
                          angle=90,
                          instanceName=self.instanceName + 'Pawn',
                          stamina=100,
                          maxStamina=100,
                          intention='SYNCING').channel

        self.world.send((self.channel, "JOIN",
                         ActorProperties(self.__class__.__name__,
                                         instanceName=self.instanceName,
                                         physical=False,
                                         public=False)))

        self.info('about to send OWNERSHIP...!')
        self.sendCommand(('OWNERSHIP', id(self.pawn)))
        self.info('OWNERSHIP sent...!')
        # The tasklet will hold a reference to the user keeping the instance
        # alive as long as it is handling commands.
        NamedTasklet(self.Run)()
Exemple #2
0
    def startTickTasklet(self, tickOnlyOnce=False):
        assert self.tickTasklet == None

        self.tickLoopEnable = True
        self.tickOnlyOnce = tickOnlyOnce

        self.tickTasklet = NamedTasklet(self.tickLoop)()
        self.tickTasklet.name = 'WorldTick'
Exemple #3
0
    def __init__(self, world, instanceName):
        SActor.__init__(self, instanceName)
        self.world = world
        self.users = weakref.WeakValueDictionary()
        
        NamedTasklet(self.startServerLoop)()

        self.world.send((self.channel, "JOIN",
                         ActorProperties(self.__class__.__name__,
                                         instanceName=self.instanceName,
                                         physical=False, public=False)))
Exemple #4
0
    def __init__(self, world, instanceName, serverAddress):
        SNetActor.__init__(self, instanceName)
        self.world = world
        self.serverAddress = serverAddress
        self.blankActors = {}
        self.ownedActorId = None
        self.socket = None

        NamedTasklet(self.startClientLoop)()

        self.world.send((self.channel, 'JOIN',
                         ActorProperties(self.__class__.__name__,
                                         instanceName=self.instanceName,
                                         physical=False,
                                         public=False)))
Exemple #5
0
    def defaultMessageAction(self, args):
        sentFrom, msg, msgArgs = args[0], args[1], args[2:]
        if msg == 'WORLD_STATE':
            ws = msgArgs[0]
            self.deltaTime = ws.time - self.time
            self.time = ws.time

            for k, v in self.tasklets.iteritems():
                v.send(None)

        elif msg == 'COLLISION':
            pass

        elif msg == 'ACQUIRE':
            gathering = msgArgs[0]
            gatheringCount = msgArgs[1]

            self.gatherings[gathering] = self.gatherings.get(
                gathering, 0) + gatheringCount

            self.info('%d %s acquired. Now have %d.' %
                      (gatheringCount, gathering, self.gatherings[gathering]))

        elif msg == 'GIVE_ME_GATHERINGS':

            requests = msgArgs[0]
            reply = {}
            for k in list(requests):

                if self.gatherings.get(k, 0) >= requests[k]:

                    self.gatherings[k] = self.gatherings.get(k,
                                                             0) - requests[k]
                    reply[k] = requests[k]

            sentFrom.send((self.channel, 'ACQUIRE', reply))

        elif msg == 'NEIGHBORS_LEFT':
            self._neighbors.difference_update(msgArgs[0])
            self.debug('Left:%s' % msgArgs[0])
            for newlyLeft, _ in msgArgs[0]:
                cname = str(newlyLeft) + ':AddStamina'
                self.tasklets[cname].send_exception(TaskletExit)
                del self.tasklets[cname]

        elif msg == 'NEIGHBORS_ENTERED':
            self._neighbors.update(msgArgs[0])
            self.debug('Entered:%s' % msgArgs[0])
            for newlyEntered, _ in msgArgs[0]:
                c = NamedChannel()
                c.name = str(newlyEntered) + ':AddStamina'
                self.tasklets[c.name] = c
                NamedTasklet(self.taskAddStamina)(c, newlyEntered)
        elif msg == 'REQUEST_VOCA':
            if msgArgs[0] == 'DESTROY':
                self.deathReason = 'ATTACKING'
                self.world.send((self.channel, 'KILLME'))
        elif msg == 'YOU_ARE_DEAD':
            self.info('I am dead by %s.' % self.deathReason)
        else:
            raise UnknownMessageError(msg, sentFrom)
Exemple #6
0
    def __init__(self,
                 world,
                 windowTitle='Falling Sun',
                 client=None,
                 swidth=TS * 10,
                 sheight=TS * 10,
                 sightedActorsOnly=False):
        SActor.__init__(self, 'DisplayWindow')
        self.frame = 0
        self.world = world
        self.icons = {}
        self.time = 0
        self._client = client
        self.swidth = swidth
        self.sheight = sheight
        self.sightedActorsOnly = sightedActorsOnly
        self.sightedActors = None

        self.camX = self.camY = 0
        self.camdX = self.camdY = 0
        self.camKey = [False] * 4
        self.camOff = None

        VPX = swidth // TS
        VPY = sheight // TS

        pygame.init()
        pygame.display.set_caption(windowTitle)
        pygame.display.set_mode(
            (swidth + TS * 2, sheight + TS * 2 + COM_PANEL_HEIGHT))
        self.mainSurface = pygame.Surface((TS * VPX, TS * VPY))

        self.font = pygame.font.Font('C:\windows\Fonts\GULIM.TTC', 10)
        self.bigFont = pygame.font.Font('C:\windows\Fonts\ARIALNBI.ttf', 12)
        self.dustRoadTile = pygame.image.load(
            os.path.join('../data', '004-G_Ground02.png'))
        self.waterTile = pygame.image.load(
            os.path.join('../data', '001-G_Water01.png'))
        self.grasslandTile = pygame.image.load(
            os.path.join('../data', '001-Grassland01.png'))
        self.fighterTile = pygame.image.load(
            os.path.join('../data', '001-Fighter01.png'))
        self.thiefTile = pygame.image.load(
            os.path.join('../data', '018-Thief03.png'))
        self.farmerTile = pygame.image.load(
            os.path.join('../data', '143-Farmer01.png'))
        self.headmanTile = pygame.image.load(
            os.path.join('../data', '109-Civilian09.png'))

        self._fadeoutTextManager = FadeoutTextManager(self)
        self._comPanelManager = ComPanelManager()
        self._alertManager = alert.DAlertManager(self)

        self.world.send((self.channel, "JOIN",
                         ActorProperties(self.__class__.__name__,
                                         public=False,
                                         instanceName=self.instanceName)))
        self.world.send((self.channel, "TELL_ME_WORLD_SIZE"))

        if client:
            client.send((self.channel, 'I_AM_DISPLAY'))

        NamedTasklet(self.pygameEventLoop)()

        self.debug('Created.')