Exemplo n.º 1
0
    def begin(self):
        if self.cReader.dataAvailable():
            datagram = NetDatagram()  # catch the incoming data in this instance
            # Check the return value; if we were threaded, someone else could have
            # snagged this data before we did
            if self.cReader.getData(datagram):
                myIterator = PyDatagramIterator(datagram)
                msgID = myIterator.getUint8()

                #If not in our protocol range then we just reject
                if msgID < 0 or msgID > 200:
                    return

                #Order of these will need to be optimized later
                #We now pull out the rest of our headers
                remotePacketCount = myIterator.getUint8()
                ack = myIterator.getUint8()
                acks = myIterator.getUint16()
                hashID = myIterator.getUint16()
                sourceOfMessage = datagram.getConnection()

                if msgID == protocol.NEW_SHIP:
                    log.info("New ship")
                    playerPilotID = myIterator.getUint16()
                    shipID = myIterator.getUint16()
                    shipName = myIterator.getString()
                    health = myIterator.getUint8()
                    position = Point3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    linearVelocity = Vec3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    rotiation = VBase3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    angularVelocity = Vec3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    ship = sandbox.addEntity(shipID)
                    component = ships.PilotComponent()
                    component.accountEntityID = playerPilotID
                    ship.addComponent(component)
                    component = ships.BulletPhysicsComponent()
                    messenger.send("addSpaceShip", [component, shipName, position, linearVelocity])
                    ship.addComponent(component)
                    component = ships.ThrustComponent()
                    ship.addComponent(component)
                    component = ships.InfoComponent()
                    component.health = health
                    component.name = shipName
                    ship.addComponent(component)
                elif msgID == protocol.PLAYER_MOVED_SHIP:
                    log.debug("Player moved ship")
                    accountID = myIterator.getUint16()
                    shipID = myIterator.getUint16()
                    print sandbox.components[shipID]
                    universals.shipNode = sandbox.components[shipID][ships.BulletPhysicsComponent].nodePath
                elif msgID == protocol.LOGIN_ACCEPTED:
                    log.info("Login accepted")
                    entityID = myIterator.getUint8()
                    universals.day = myIterator.getFloat32()
                elif msgID == protocol.LOGIN_DENIED:
                    log.info("Login failed")
Exemplo n.º 2
0
    def spawnShip(
        self, shipName, shipClass, spawnPoint=LPoint3d(0, 0, 0),
        playerShip=False, entityid=-1, turrets=None
    ):
        if shipName == '' or shipClass == '':
            return
        if entityid == -1:
            ship = sandbox.createEntity()
        else:
            ship = sandbox.addEntity(entityid)
        if playerShip:
            component = shipComponents.PlayerComponent()
            ship.addComponent(component)
        else:
            component = shipComponents.AIPilotComponent()
            ship.addComponent(component)
        shape = BulletSphereShape(1)
        velocity = Vec3(0, 0, 0)
        truex = spawnPoint.getX()
        truey = spawnPoint.getY()
        component = physics.addNewBody(shipName, shape, shipClasses[shipClass]['mass'], truex, truey, velocity)
        ship.addComponent(component)
        component = shipComponents.ThrustComponent()
        for engine in shipClasses[shipClass]['engines']:
            component.forward += engine['thrust'] / CONVERT
        component.heading = shipClasses[shipClass]['torque'] / CONVERT
        ship.addComponent(component)
        component = shipComponents.InfoComponent()
        component.shipClass = shipClass
        component.name = shipName
        ship.addComponent(component)

        component = graphicsComponents.RenderComponent()
        #component.mesh = sandbox.base.loader.loadModel('ships/' + shipClasses[shipClass]['path'])
        component.mesh = Actor('ships/' + shipClasses[shipClass]['path'])
        component.mesh.reparentTo(sandbox.ships)
        component.mesh.getPart('modelRoot').setPythonTag('entityID', ship.id)
        component.mesh.setScale(1 / CONVERT)
        if universals.runClient and not playerShip:
            sandbox.send('makePickable', [component.mesh])
        ship.addComponent(component)

        # Load turret info here. Also check if gun is actually on ship!
        def containsAny(string, check):
            return 1 in [c in string for c in check]

        turretsComponent = shipComponents.TurretsComponent()

        if not turrets:
            for weapon in shipClasses[shipClass]['weapons']:
                turretEntity = sandbox.createEntity()
                turret = shipComponents.TurretComponent()
                if not containsAny(shipClasses[shipClass]['weapons'][weapon]['decay'], 'abcdefghijklmnopqrstuvwyz'):
                    turret.decay = lambda x: eval(shipClasses[shipClass]['weapons'][weapon]['decay'])
                turret.name = weapon
                turret.damage = shipClasses[shipClass]['weapons'][weapon]['damage']
                if 'traverser' in shipClasses[shipClass]['weapons'][weapon]['joints']:
                    turret.traverser = shipClasses[shipClass]['weapons'][weapon]['joints']['traverser']['axes']
                if 'elevator' in shipClasses[shipClass]['weapons'][weapon]['joints']:
                    turret.elevator = shipClasses[shipClass]['weapons'][weapon]['joints']['elevator']['axes']
                turret.parentID = ship.id
                turretEntity.addComponent(turret)
                turretsComponent.turretIDs.append(turretEntity.id)
        if turrets:
            for t in turrets:
                turretEntity = sandbox.addEntity(t.turretid)
                turret = shipComponents.TurretComponent()
                weapon = t.turretName
                if not containsAny(shipClasses[shipClass]['weapons'][weapon]['decay'], 'abcdefghijklmnopqrstuvwyz'):
                    turret.decay = lambda x: eval(shipClasses[shipClass]['weapons'][weapon]['decay'])
                turret.name = weapon
                turret.damage = shipClasses[shipClass]['weapons'][weapon]['damage']
                if 'traverser' in shipClasses[shipClass]['weapons'][weapon]['joints']:
                    turret.traverser = shipClasses[shipClass]['weapons'][weapon]['joints']['traverser']['axes']
                if 'elevator' in shipClasses[shipClass]['weapons'][weapon]['joints']:
                    turret.elevator = shipClasses[shipClass]['weapons'][weapon]['joints']['elevator']['axes']
                turret.parentID = ship.id
                turretEntity.addComponent(turret)
                turretsComponent.turretIDs.append(turretEntity.id)

        ship.addComponent(turretsComponent)

        #sandbox.send("shipGenerated", [ship, playerShip])
        log.info("Ship spawned: " + shipName + " " + shipClass)
Exemplo n.º 3
0
    def spawnShip(self,
                  shipName,
                  shipClass,
                  spawnPoint=LPoint3d(0, 0, 0),
                  playerShip=False,
                  entityid=-1,
                  turrets=None):
        if shipName == '' or shipClass == '':
            return
        if entityid == -1:
            ship = sandbox.createEntity()
        else:
            ship = sandbox.addEntity(entityid)
        if playerShip:
            component = shipComponents.PlayerComponent()
            ship.addComponent(component)
        else:
            component = shipComponents.AIPilotComponent()
            ship.addComponent(component)
        shape = BulletSphereShape(1)
        velocity = Vec3(0, 0, 0)
        truex = spawnPoint.getX()
        truey = spawnPoint.getY()
        component = physics.addNewBody(shipName, shape,
                                       shipClasses[shipClass]['mass'], truex,
                                       truey, velocity)
        ship.addComponent(component)
        component = shipComponents.ThrustComponent()
        for engine in shipClasses[shipClass]['engines']:
            component.forward += engine['thrust'] / CONVERT
        component.heading = shipClasses[shipClass]['torque'] / CONVERT
        ship.addComponent(component)
        component = shipComponents.InfoComponent()
        component.shipClass = shipClass
        component.name = shipName
        ship.addComponent(component)

        component = graphicsComponents.RenderComponent()
        #component.mesh = sandbox.base.loader.loadModel('ships/' + shipClasses[shipClass]['path'])
        component.mesh = Actor('ships/' + shipClasses[shipClass]['path'])
        component.mesh.reparentTo(sandbox.ships)
        component.mesh.getPart('modelRoot').setPythonTag('entityID', ship.id)
        component.mesh.setScale(1 / CONVERT)
        if universals.runClient and not playerShip:
            sandbox.send('makePickable', [component.mesh])
        ship.addComponent(component)

        # Load turret info here. Also check if gun is actually on ship!
        def containsAny(string, check):
            return 1 in [c in string for c in check]

        turretsComponent = shipComponents.TurretsComponent()

        if not turrets:
            for weapon in shipClasses[shipClass]['weapons']:
                turretEntity = sandbox.createEntity()
                turret = shipComponents.TurretComponent()
                if not containsAny(
                        shipClasses[shipClass]['weapons'][weapon]['decay'],
                        'abcdefghijklmnopqrstuvwyz'):
                    turret.decay = lambda x: eval(shipClasses[shipClass][
                        'weapons'][weapon]['decay'])
                turret.name = weapon
                turret.damage = shipClasses[shipClass]['weapons'][weapon][
                    'damage']
                if 'traverser' in shipClasses[shipClass]['weapons'][weapon][
                        'joints']:
                    turret.traverser = shipClasses[shipClass]['weapons'][
                        weapon]['joints']['traverser']['axes']
                if 'elevator' in shipClasses[shipClass]['weapons'][weapon][
                        'joints']:
                    turret.elevator = shipClasses[shipClass]['weapons'][
                        weapon]['joints']['elevator']['axes']
                turret.parentID = ship.id
                turretEntity.addComponent(turret)
                turretsComponent.turretIDs.append(turretEntity.id)
        if turrets:
            for t in turrets:
                turretEntity = sandbox.addEntity(t.turretid)
                turret = shipComponents.TurretComponent()
                weapon = t.turretName
                if not containsAny(
                        shipClasses[shipClass]['weapons'][weapon]['decay'],
                        'abcdefghijklmnopqrstuvwyz'):
                    turret.decay = lambda x: eval(shipClasses[shipClass][
                        'weapons'][weapon]['decay'])
                turret.name = weapon
                turret.damage = shipClasses[shipClass]['weapons'][weapon][
                    'damage']
                if 'traverser' in shipClasses[shipClass]['weapons'][weapon][
                        'joints']:
                    turret.traverser = shipClasses[shipClass]['weapons'][
                        weapon]['joints']['traverser']['axes']
                if 'elevator' in shipClasses[shipClass]['weapons'][weapon][
                        'joints']:
                    turret.elevator = shipClasses[shipClass]['weapons'][
                        weapon]['joints']['elevator']['axes']
                turret.parentID = ship.id
                turretEntity.addComponent(turret)
                turretsComponent.turretIDs.append(turretEntity.id)

        ship.addComponent(turretsComponent)

        #sandbox.send("shipGenerated", [ship, playerShip])
        log.info("Ship spawned: " + shipName + " " + shipClass)