def requestStations(shipid, stations): playerShips = proto.Ships() playerShip = playerShips.ship.add() playerShip.id = shipid shipStations = playerShip.stations for station in stations: setattr(shipStations, station, 1) return sandbox.generatePacket(REQUEST_STATIONS, playerShips)
def shipClasses(db): shipClasses = proto.ShipClasses() for shipClass in db: ship = shipClasses.shipClass.add() ship.className = db[shipClass]['class'] ship.mass = int(db[shipClass]['mass']) ship.meshName = db[shipClass]['mesh'] ship.folderName = db[shipClass]['folder'] datagram = sandbox.generatePacket(SHIP_CLASSES, shipClasses) return datagram
def confirmStations(shipid, stations): ship = proto.Ship() ship.id = shipid shipEntity = sandbox.entities[shipid] info = shipEntity.getComponent(shipComponents.InfoComponent) ship.name = info.name ship.className = info.shipClass shipPhysics = shipEntity.getComponent(shipComponents.BulletPhysicsComponent) packFullPhysics(shipPhysics, ship) #shipStations = ship.stations.add() shipStations = ship.stations for station in stations: setattr(shipStations, station, 1) datagram = sandbox.generatePacket(CONFIRM_STATIONS, ship) return datagram
def playerShipStations(): shipSys = sandbox.getSystem(shipSystem.ShipSystem) playerShips = proto.Ships() entities = shipSys.getPlayerShipEntities() for entity in entities: playerShip = playerShips.ship.add() info = entity.getComponent(shipComponents.InfoComponent) shipPhysics = entity.getComponent(shipComponents.BulletPhysicsComponent) playerShip.name = info.name playerShip.className = info.shipClass playerShip.id = entity.id packFullPhysics(shipPhysics, playerShip) player = entity.getComponent(shipComponents.PlayerComponent) shipStations = playerShip.stations stations = vars(player) for stationName, status in stations.items(): if status == 0: setattr(shipStations, stationName, 0) else: setattr(shipStations, stationName, 1) return sandbox.generatePacket(PLAYER_SHIPS, playerShips)
def sendShipUpdates(shipEntities): ships = proto.Ships() for shipEntity in shipEntities: ship = ships.ship.add() ship.id = shipEntity.id component = shipEntity.getComponent(shipComponents.BulletPhysicsComponent) packFullPhysics(component, ship) ship.name = shipEntity.getComponent(shipComponents.InfoComponent).name ship.className = shipEntity.getComponent(shipComponents.InfoComponent).shipClass turrets = shipEntity.getComponent(shipComponents.TurretsComponent) mesh = shipEntity.getComponent(graphicsComponents.RenderComponent).mesh for turretEntityID in turrets.turretIDs: turret = ship.turrets.add() turret.turretid = turretEntityID turretComponent = sandbox.entities[turretEntityID].getComponent(shipComponents.TurretComponent) turret.turretName = turretComponent.name joint = turret.joints.add() # Using "targetHPR" as current HPR for now fullJoint = 'gun-' + turretComponent.name.replace(' ', '_') + "-elevator" joint.jointName = "elevator" joint.time = 0 joint.targetH = mesh.controlJoint(None, "modelRoot", fullJoint).getH() joint.targetP = mesh.controlJoint(None, "modelRoot", fullJoint).getP() joint.targetR = mesh.controlJoint(None, "modelRoot", fullJoint).getR() joint = turret.joints.add() # Using "targetHPR" as current HPR for now fullJoint = joint.jointName = 'gun-' + turretComponent.name.replace(' ', '_') + "-traverser" joint.jointName = "traverser" joint.time = 0 joint.targetH = mesh.controlJoint(None, "modelRoot", fullJoint).getH() joint.targetP = mesh.controlJoint(None, "modelRoot", fullJoint).getP() joint.targetR = mesh.controlJoint(None, "modelRoot", fullJoint).getR() return sandbox.generatePacket(POS_PHYS_UPDATE, ships)
def requestCreateShip(name, className): ship = proto.Ship() ship.id = -1 ship.name = name ship.className = className return sandbox.generatePacket(REQUEST_CREATE_SHIP, ship)
def requestThrottle(throttle, heading): t = proto.Throttle() t.normal = throttle t.heading = heading return sandbox.generatePacket(SET_THROTTLE, t)
def requestTurretTarget(targetId, turretId=None): turret = proto.Target() turret.targetId = targetId if turretId: turret.turretId = turretName return sandbox.generatePacket(SET_TARGET, turret)