def sendShipUpdates(self, task): ships = sandbox.getSystem(shipSystem.ShipSystem).getPlayerShipEntities() ships += sandbox.getEntitiesByComponentType(shipComponents.AIPilotComponent) #self.broadcastData(protocol.sendShipUpdates(ships)) for ship in ships: self.broadcastData(protocol.sendShipUpdates([ship])) return task.again
def sendShipUpdates(self, task): ships = sandbox.getSystem( shipSystem.ShipSystem).getPlayerShipEntities() ships += sandbox.getEntitiesByComponentType( shipComponents.AIPilotComponent) #self.broadcastData(protocol.sendShipUpdates(ships)) for ship in ships: self.broadcastData(protocol.sendShipUpdates([ship])) return task.again
def setTarget(self, masterShipID, data): # TODO: Support client sending specific turrets # Get ship turrets allTurrets = sandbox.getEntitiesByComponentType(shipComponents.TurretComponent) turrets = [] for turret in allTurrets: if turret.getComponent(shipComponents.TurretComponent).parentID == masterShipID: if data.turretId == -1: turrets.append(turret.getComponent(shipComponents.TurretComponent)) elif data.turretId == turrent.id: turrets.append(turret.getComponent(shipComponents.TurretComponent)) for turret in turrets: turret.targetID = data.targetId
def setTarget(self, masterShipID, data): # TODO: Support client sending specific turrets # Get ship turrets allTurrets = sandbox.getEntitiesByComponentType( shipComponents.TurretComponent) turrets = [] for turret in allTurrets: if turret.getComponent( shipComponents.TurretComponent).parentID == masterShipID: if data.turretId == -1: turrets.append( turret.getComponent(shipComponents.TurretComponent)) elif data.turretId == turrent.id: turrets.append( turret.getComponent(shipComponents.TurretComponent)) for turret in turrets: turret.targetID = data.targetId
def process(self, entity): shipPhysics = entity.getComponent(shipComponents.BulletPhysicsComponent) if not shipPhysics.node.is_active(): shipPhysics.node.setActive(True) bodies = sandbox.getEntitiesByComponentType(solarSystem.CelestialComponent) # Probably very expensive. Will need optimization later # We assume a single star solar system. Will need to update the # solary system structure for multiple star solar systems soi = False previousR = 0 for body in bodies: bodyComponent = body.getComponent(solarSystem.CelestialComponent) distance = (bodyComponent.truePos - shipPhysics.getTruePos()).length() if distance < bodyComponent.soi: if not soi: previousR = distance soi = True shipPhysics.currentSOI = body.id elif distance < previousR: shipPhysics.currentSOI = body.id if not soi: shipPhysics.currentSOI = universals.defaultSOIid body = sandbox.entities[shipPhysics.currentSOI] celestial = body.getComponent(solarSystem.CelestialComponent) vector = celestial.truePos - shipPhysics.getTruePos() distance = vector.length() * 1000 gravityForce = Vec3(0, 0, 0) if distance: gravity = universals.G * celestial.mass * shipPhysics.node.getMass() / distance ** 2 #print "Gravity", universals.G, celestial.mass, shipPhysics.node.getMass(), distance, gravity gravityForce = vector * -gravity thrust = universals.solarSystemRoot.getRelativeVector(shipPhysics.nodePath, (0, shipPhysics.currentThrust, 0)) #force = (gravityForce + thrust) / 1000.0 #print gravityForce, thrust / 1000.0 #force = thrust / 1000.0 force = thrust shipPhysics.node.applyCentralForce(force) shipPhysics.node.applyTorque(Vec3(0, 0, -shipPhysics.currentTorque))
def getPlayerShipEntities(self): return sandbox.getEntitiesByComponentType(shipComponents.PlayerComponent)
def getPlayerShipEntities(self): return sandbox.getEntitiesByComponentType( shipComponents.PlayerComponent)