def setHullType(self, type): if self.panels: return None if not type: return None self.shipClass = type self.modelClass = ShipGlobals.getModelClass(type) modelType = ShipGlobals.getModelClass(type) filePrefix = HullDict.get(modelType) self.hull = loader.loadModel(filePrefix) self.hull.reparentTo(self.modelRoot) allPanels = self.hull.findAllMatches('**/panel_*') for i in range(len(allPanels)): panel = self.hull.find('**/panel_' + str(i)) if not panel.isEmpty(): self.panels.append(panel) self.panelStates.append(0) self.smokeEffects.append(None) continue self.bowsprit = self.hull.find('**/bowsprit') self.ram = self.hull.find('**/ram') self.cabin = self.hull.find('**/cabin') self.bowsprit.detachNode() if self.modelClass == 1: self.cabin.detachNode() self.placeMasts()
def getAIShip(self, shipClass): ShipAI = ShipAI import pirates.ship modelClass = ShipGlobals.getModelClass(shipClass) hull = self.getHull(modelClass, 0) root = NodePath('Ship') collisions = root.attachNewNode('collisions') mastSetup = ShipGlobals.getMastSetup(shipClass) for data in [ (0, 'location_mainmast_0'), (1, 'location_mainmast_1'), (2, 'location_mainmast_2'), (3, 'location_aftmast*'), (4, 'location_foremast*')]: mastData = mastSetup.get(data[0]) if mastData: mast = self.mastSets[mastData[0]].getMastSet(mastData[1] - 1) model = NodePath(mast.charRoot) model.setPos(hull.locators.find('**/%s' % data[1]).getPos(hull.locators)) model.setHpr(hull.locators.find('**/%s' % data[1]).getHpr(hull.locators)) model.setScale(hull.locators.find('**/%s' % data[1]).getScale(hull.locators)) if modelClass > ShipGlobals.INTERCEPTORL3 or data[0] != 3: mastCode = str(data[0]) else: mastCode = '0' mast.collisions.find('**/collision_masts').setTag('Mast Code', mastCode) collisions.node().stealChildren(mast.collisions.node()) continue collisions.node().stealChildren(hull.collisions.node()) hull.locators.reparentTo(root) ship = ShipAI.ShipAI(root, collisions, hull.locators) ship.modelRoot.setTag('Mast Code', str(255)) ship.modelRoot.setTag('Hull Code', str(255)) return ship
def updateStats(self): self.statData = [] stats = ShipGlobals.getShipConfig(self.purchaseInventory[0][0]) maxStats = ShipGlobals.getMaxShipStats() self.statData.append([ PLocalizer.Hull, stats['hp'], maxStats['hp']]) self.statData.append([ PLocalizer.Speed, int(stats['sp'] / 10), 4 + maxStats['sp'] / 10]) self.statData.append([ PLocalizer.Speed, int(stats['maxSpeed'] / 10), 4 + maxStats['maxSpeed'] / 10]) self.statData.append([ PLocalizer.Cannon, stats['maxCannons'], maxStats['maxCannons']]) self.statData.append([ PLocalizer.Broadsides, stats['maxBroadsides'], maxStats['maxBroadsides']]) self.statData.append([ PLocalizer.Cargo, stats['maxCargo'], maxStats['maxCargo']]) self.statData.append([ PLocalizer.Crew, stats['maxCrew'], maxStats['maxCrew']])
def loadStats(self): self.stats = ShipGlobals.getShipConfig(self.shipClass) self.maxHp = self.stats['hp'] self.maxSp = self.stats['sp'] self.maxMastHealth = ShipGlobals.getMastHealth(self.shipClass, self.maxSp) self.maxArmor = ShipGlobals.getHullArmor(self.modelClass) self.maxHp = int( self.maxHp * ShipUpgradeGlobals.HULL_TYPES[self.customHull]['Armor']) self.Hp = self.maxHp * (self.healthState / 100.0) self.maxCrew = self.stats['maxCrew'] self.acceleration = self.stats['acceleration'] self.maxSpeed = self.stats['maxSpeed'] self.reverseAcceleration = self.stats['reverseAcceleration'] self.maxReverseSpeed = self.stats['maxReverseSpeed'] self.turnRate = self.stats['turn'] self.maxTurn = self.stats['maxTurn'] shipTypeInfo = ShipGlobals.getShipConfig(self.shipClass) self.maxCargo = int( shipTypeInfo['maxCargo'] * ShipUpgradeGlobals.HULL_TYPES[self.customHull]['Cargo']) self.cannonConfig = self.stats['cannons'] self.lBroadsideConfig = self.stats['leftBroadsides'] self.rBroadsideConfig = self.stats['rightBroadsides']
def setHullType(self, type): if self.panels: return if not type: return self.shipClass = type self.modelClass = ShipGlobals.getModelClass(type) modelType = ShipGlobals.getModelClass(type) filePrefix = HullDict.get(modelType) self.hull = loader.loadModel(filePrefix) self.hull.reparentTo(self.modelRoot) shipHullType = self.shipHullType if not shipHullType: shipHullType = 1 hullColor = ShipUpgradeGlobals.HULL_TYPES[shipHullType]['PreviewColor'] self.hull.setColor(hullColor) allPanels = self.hull.findAllMatches('**/panel_*') for i in range(len(allPanels)): panel = self.hull.find('**/panel_' + str(i)) if not panel.isEmpty(): self.panels.append(panel) self.panelStates.append(0) self.smokeEffects.append(None) self.bowsprit = self.hull.find('**/bowsprit') self.ram = self.hull.find('**/ram') self.cabin = self.hull.find('**/cabin') if self.bowsprit: self.bowsprit.detachNode() if self.modelClass == 1: self.cabin.detachNode() self.placeMasts() return
def __init__(self, shipId, shipClass=0, mastInfo=[], siegeTeam=0): NodePath.__init__(self, 'ShipMeter') self.shipId = shipId self.team = 0 self.siegeTeam = siegeTeam self.shipClass = shipClass self.shipSailPattern = None self.shipHullType = None self.shipRiggingType = None self.modelClass = ShipGlobals.getModelClass(shipClass) self.hull = None self.panels = [] self.masts = [None, None, None, None, None] self.sails = [None, None, None, None, None] self.mastModels = [None, None, None, None, None] self.bowsprit = None self.ram = None self.cabin = None self.panelStates = [] self.mastStates = [None, None, None, None, None] self.mastTypes = [None, None, None, None, None] self.smokeEffects = [] self.oldHullHp = [] self.oldMastHp = [[], [], [], [], []] self.modelRoot = self.attachNewNode('modelRoot') if not (self.shipSailPattern) and not (self.shipHullType) or not ( self.shipRiggingType): shipOVs = base.cr.getOwnerViewDoList(DistributedPlayerSimpleShipOV) shipOVs = _[1] for currShipOV in shipOVs: self.shipSailPattern = currShipOV.customSailPattern self.shipHullType = currShipOV.customHull self.shipRiggingType = currShipOV.customRigging continue if shipClass and mastInfo: self.setShipInfo(shipClass, mastInfo) elif self.shipId: shipOVs = base.cr.getOwnerViewDoList(DistributedPlayerSimpleShipOV) shipOVs = _[1] for currShipOV in shipOVs: self.setHullType(currShipOV.shipClass) masts = ShipGlobals.getMastSetup(currShipOV.shipClass) for i in range(5): if masts[i]: self.setMastType(i, masts[i][0], masts[i][1]) continue [] self.accept('setShipClass-%s' % self.shipId, self.setHullType) self.accept('setMastType-%s' % self.shipId, self.setMastType) self.accept('ShipChanged-%s' % self.shipId, self.shipCustomColor) self.accept('setHullHp-%s' % self.shipId, self.setHullHp) self.accept('setBowspritHp-%s' % self.shipId, self.setBowspritHp) self.accept('setCabinHp-%s' % self.shipId, self.setCabinHp) self.accept('setMastHp-%s' % self.shipId, self.setMastHp) self.accept('setSailHp-%s' % self.shipId, self.setSailHp)
def setupBoardingSphere(self, bitmask = PiratesGlobals.RadarShipBitmask): self.removeBoardingSphere() tubeName = self.uniqueName('proximityCollision') result = self.createShipTube(tubeName, bitmask) self.interactTube = result[2] self.interactTube.setTag('objType', str(PiratesGlobals.COLL_AV)) self.interactTube.setTag('avId', str(self.doId)) sphereScale = ShipGlobals.getBoardingSphereScale(self.modelClass) spherePosH = ShipGlobals.getBoardingSpherePosH(self.modelClass) self.interactTube.setY(spherePosH[0][1]) self.proximityCollisionEnterEvent = 'enter' + tubeName
def setupBoardingSphere(self, bitmask=PiratesGlobals.RadarShipBitmask): self.removeBoardingSphere() tubeName = self.uniqueName('proximityCollision') result = self.createShipTube(tubeName, bitmask) self.interactTube = result[2] self.interactTube.setTag('objType', str(PiratesGlobals.COLL_AV)) self.interactTube.setTag('avId', str(self.doId)) sphereScale = ShipGlobals.getBoardingSphereScale(self.modelClass) spherePosH = ShipGlobals.getBoardingSpherePosH(self.modelClass) self.interactTube.setY(spherePosH[0][1]) self.proximityCollisionEnterEvent = 'enter' + tubeName
def splitShip(self): if not self.isSplit: self.isSplit = True self.modelGeom.instanceTo(self.clipParent2) planeNode1 = NodePath(PlaneNode('planeNode1', Plane(Vec4(0, 1, 0, 0)))) planeNode1.reparentTo(self.clipParent1) planeNode1.setY(ShipGlobals.getShipSplitOffset(self.shipClass)) self.clipParent1.setClipPlane(planeNode1) planeNode2 = NodePath(PlaneNode('planeNode2', Plane(Vec4(0, -1, 0, 0)))) planeNode2.reparentTo(self.clipParent2) planeNode2.setY(ShipGlobals.getShipSplitOffset(self.shipClass)) self.clipParent2.setClipPlane(planeNode2)
def enableStats(self, shipName='', shipClass=0, mastInfo=[], hp=0, sp=0, cargo=0, crew=0, time=0): hullInfo = ShipGlobals.getShipConfig(shipClass) self.shipClass = shipClass self.snapShot = ShipSnapshot(self, None, self['siegeTeam'], shipName, shipClass, mastInfo, hp, hullInfo['hp'], sp, hullInfo['sp'], cargo, hullInfo['maxCargo'], crew, hullInfo['maxCrew'], time, pos=self['snapShotPos']) typeStr = self['avatarName'] if self['shipType'] is ShipFrameSelect.STBand: self.button['text'] = PLocalizer.BoardShip else: if self['shipType'] is ShipFrameSelect.STGuild: self.button['text'] = PLocalizer.BoardShip else: if self['shipType'] is ShipFrameSelect.STFriend: self.button['text'] = PLocalizer.BoardShip else: if self['shipType'] is ShipFrameSelect.STPublic: self.button['text'] = PLocalizer.BoardShip else: typeStr = '' stateStr = PLocalizer.ShipAtSea if hp <= 0: self.button['state'] = DGG.DISABLED stateStr = '\x01red\x01%s\x02' % (PLocalizer.ShipSunk,) self['shipColorScale'] = VBase4(0.8, 0.3, 0.3, 1) else: if crew >= hullInfo['maxCrew']: self.button['state'] = DGG.DISABLED stateStr = '\x01red\x01%s\x02' % (PLocalizer.ShipFull,) self['shipColorScale'] = VBase4(0.4, 0.4, 0.4, 1) else: self.button['state'] = DGG.NORMAL if typeStr: self.typeLabel['text'] = '\x01smallCaps\x01(%s)\x02' % typeStr return
def addOwnShip(self, shipId, callback): shipOV = base.cr.getOwnerView(shipId) if (not shipOV or self._siegeTeam) and localAvatar.getSiegeTeam( ) and localAvatar.getSiegeTeam() != self._siegeTeam: return None shipFrame = self.getFrame(shipId) if not shipFrame: mastInfo = ShipGlobals.getMastSetup(shipOV.shipClass) shipFrame = ShipFrameDeploy(parent=None, shipId=shipId, shipName=shipOV.name, shipClass=shipOV.shipClass, mastInfo=mastInfo, shipType=ShipFrameDeploy.STOwn, siegeTeam=self._siegeTeam, command=callback, extraArgs=[shipId]) shipFrame.enableStatsOV(shipOV) if not Freebooter.getPaidStatus(base.localAvatar.getDoId( )) and shipOV.shipClass not in ShipGlobals.UNPAID_SHIPS: shipFrame.nameLabel['text'] = PLocalizer.noFreebooterCap shipFrame.nameLabel['text_fg'] = (1, 0.69999999999999996, 0.69999999999999996, 1) self.addFrameOwn(shipFrame)
def placeMasts(self): masts = ShipGlobals.getMastSetup(self.shipClass) for index in range(5): mast = self.masts[index] if mast: self.mastModels[index].reparentTo(self.modelRoot) type = self.mastTypes[index] id = masts[index][0] if id in (ShipGlobals.Masts.Fore_Multi, ShipGlobals.Masts.Fore_Tri, ShipGlobals.Masts.Skel_Fore): locator = self.hull.find('**/location_foremast;+s') elif id in (ShipGlobals.Masts.Main_Square, ShipGlobals.Masts.Main_Tri, ShipGlobals.Masts.Skel_Main_A, ShipGlobals.Masts.Skel_Main_B, ShipGlobals.Masts.Skel_Tri): if self.modelClass == 11 and index == 1: locator = self.hull.find('**/location_mainmast_2;+s') else: locator = self.hull.find('**/location_mainmast_' + str(index) + ';+s') elif id in (ShipGlobals.Masts.Aft_Tri, ShipGlobals.Masts.Skel_Aft): locator = self.hull.find('**/location_aftmast;+s') if locator: self.mastModels[index].setPos(locator.getPos()) self.mastModels[index].setHpr(locator.getHpr()) self.mastModels[index].setScale(locator.getScale())
def addPublicShip(self, shipInfo, callback): (ownerId, shipId, shipHp, shipSp, cargo, crew, time, shipClass, shipName, siegeTeam, avatarName, customHull, customRigging, customPattern, customLogo) = shipInfo if localAvatar.getSiegeTeam() and localAvatar.getSiegeTeam() != siegeTeam: return None shipFrame = self._makeFrame(shipId, shipName, shipClass, ShipGlobals.getMastSetup(shipClass), shipHp, shipSp, cargo, crew, time, siegeTeam, avatarName, customHull, customRigging, customPattern, customLogo, callback) self.addFramePublic(shipFrame)
def enableStats(self, shipName = '', shipClass = 0, mastInfo = [], hp = 0, sp = 0, cargo = 0, crew = 0, time = 0): hullInfo = ShipGlobals.getShipConfig(shipClass) self.shipClass = shipClass self.snapShot = ShipSnapshot(self, None, self['siegeTeam'], shipName, shipClass, mastInfo, hp, hullInfo['hp'], sp, hullInfo['sp'], cargo, hullInfo['maxCargo'], crew, hullInfo['maxCrew'], time, pos = self['snapShotPos']) typeStr = self['avatarName'] if self['shipType'] is ShipFrameSelect.STBand: self.button['text'] = PLocalizer.BoardShip elif self['shipType'] is ShipFrameSelect.STGuild: self.button['text'] = PLocalizer.BoardShip elif self['shipType'] is ShipFrameSelect.STFriend: self.button['text'] = PLocalizer.BoardShip elif self['shipType'] is ShipFrameSelect.STPublic: self.button['text'] = PLocalizer.BoardShip else: typeStr = '' stateStr = PLocalizer.ShipAtSea if hp <= 0: self.button['state'] = DGG.DISABLED stateStr = '\x01red\x01%s\x02' % (PLocalizer.ShipSunk,) self['shipColorScale'] = VBase4(0.80000000000000004, 0.29999999999999999, 0.29999999999999999, 1) elif crew >= hullInfo['maxCrew']: self.button['state'] = DGG.DISABLED stateStr = '\x01red\x01%s\x02' % (PLocalizer.ShipFull,) self['shipColorScale'] = VBase4(0.40000000000000002, 0.40000000000000002, 0.40000000000000002, 1) else: self.button['state'] = DGG.NORMAL if typeStr: self.typeLabel['text'] = '\x01smallCaps\x01(%s)\x02' % typeStr
def manufactureCannons(self, detailLevel = 2): stats = ShipGlobals.getShipConfig(self.shipClass) cannonConfig = stats['cannons'] leftConfig = stats['leftBroadsides'] rightConfig = stats['rightBroadsides'] cannons = { } for i in range(len(cannonConfig)): cannonType = cannonConfig[i] cannon = Cannon.Cannon(None) cannon.loadModel(None, cannonType) cannons[i] = [ cannon, 0] broadsides = [ [ [], []], None] for i in range(len(leftConfig)): if leftConfig[i] > 0: cannon = CannonPort.CannonPort(leftConfig[i], 0, i) broadsides[0][0].append(cannon) continue broadsides[0][0].append(None) for i in range(len(rightConfig)): if rightConfig[i] > 0: cannon = CannonPort.CannonPort(rightConfig[i], 1, i) broadsides[0][1].append(cannon) continue broadsides[0][1].append(None) self.setupCannons(cannons, broadsides, detailLevel)
def setCargo(self, cargo): self.cargo = cargo shipTypeInfo = ShipGlobals.getShipConfig(self.shipClass) maxCargo = int(shipTypeInfo['maxCargo'] * ShipUpgradeGlobals.HULL_TYPES[self.customHull]['Cargo']) messenger.send('setShipCargo-%s' % self.getDoId(), [self.cargo, maxCargo])
def manufactureCannons(self, detailLevel=2): stats = ShipGlobals.getShipConfig(self.shipClass) cannonConfig = stats['cannons'] leftConfig = stats['leftBroadsides'] rightConfig = stats['rightBroadsides'] cannons = {} for i in range(len(cannonConfig)): cannonType = cannonConfig[i] cannon = Cannon.Cannon(None) cannon.loadModel(None, cannonType) cannons[i] = [cannon, 0] broadsides = [[[], []], None] for i in range(len(leftConfig)): if leftConfig[i] > 0: cannon = CannonPort.CannonPort(leftConfig[i], 0, i) broadsides[0][0].append(cannon) continue broadsides[0][0].append(None) for i in range(len(rightConfig)): if rightConfig[i] > 0: cannon = CannonPort.CannonPort(rightConfig[i], 1, i) broadsides[0][1].append(cannon) continue broadsides[0][1].append(None) self.setupCannons(cannons, broadsides, detailLevel)
def addGuildShip(self, shipInfo, callback): (guildmateId, shipId, shipHp, shipSp, cargo, crew, time, shipClass, shipName, siegeTeam, avatarName, customHull, customRigging, customPattern, customLogo) = shipInfo if localAvatar.getSiegeTeam() and localAvatar.getSiegeTeam() != siegeTeam: return None shipFrame = self._makeFrame(shipId, shipName, shipClass, ShipGlobals.getMastSetup(shipClass), shipHp, shipSp, cargo, crew, time, siegeTeam, avatarName, customHull, customRigging, customPattern, customLogo, callback) shipFrame.addCrewMemberName(avatarName) self.addFrameGuild(shipFrame)
def addFriendShip(self, shipInfo, callback): (friendId, shipId, shipHp, shipSp, cargo, crew, time, shipClass, shipName, siegeTeam, avatarName) = shipInfo if localAvatar.getSiegeTeam() and localAvatar.getSiegeTeam() != siegeTeam: return None shipFrame = self._makeFrame(shipId, shipName, shipClass, ShipGlobals.getMastSetup(shipClass), shipHp, shipSp, cargo, crew, time, siegeTeam, avatarName, callback) shipFrame.addCrewMemberName(avatarName) self.addFrameFriend(shipFrame)
def loadStats(self): self.stats = ShipGlobals.getShipConfig(self.shipClass) self.maxHp = self.stats['hp'] self.maxSp = self.stats['sp'] self.maxMastHealth = ShipGlobals.getMastHealth(self.shipClass, self.maxSp) self.maxArmor = ShipGlobals.getHullArmor(self.modelClass) self.maxCrew = self.stats['maxCrew'] self.acceleration = self.stats['acceleration'] self.maxSpeed = self.stats['maxSpeed'] self.reverseAcceleration = self.stats['reverseAcceleration'] self.maxReverseSpeed = self.stats['maxReverseSpeed'] self.turnRate = self.stats['turn'] self.maxTurn = self.stats['maxTurn'] self.maxCargo = self.stats['maxCargo'] self.cannonConfig = self.stats['cannons'] self.lBroadsideConfig = self.stats['leftBroadsides'] self.rBroadsideConfig = self.stats['rightBroadsides']
def setCustomization(self, customHull, customRigging, customPattern, customLogo): shipTypeInfo = ShipGlobals.getShipConfig(self['shipClass']) shipHullInfo = ShipUpgradeGlobals.HULL_TYPES.get(customHull) cargoMult = shipHullInfo['Cargo'] if self['shipOV']: cargo = len(self['shipOV'].cargo) maxCargo = shipTypeInfo['maxCargo'] else: cargo = self['cargo'] maxCargo = shipTypeInfo['maxCargo'] self.cargoMeter['text'] = '%d/%d' % (cargo, maxCargo * cargoMult)
def addBandShip(self, shipInfo, callback): (bandMemberId, shipId, shipHp, shipSp, cargo, crew, time, siegeTeam, avatarName, customHull, customRigging, customPattern, customLogo) = shipInfo if localAvatar.getSiegeTeam() and localAvatar.getSiegeTeam() != siegeTeam: return None bandMember = base.cr.getDo(bandMemberId) if bandMember: shipInfo = bandMember.getShipInfo() if shipInfo and shipInfo[0] == shipId: (shipId, shipName, shipClass, mastInfo) = shipInfo shipFrame = self._makeFrame(shipId, shipName, shipClass, ShipGlobals.getMastSetup(shipClass), shipHp, shipSp, cargo, crew, time, siegeTeam, avatarName, customHull, customRigging, customPattern, customLogo, callback) shipFrame.addCrewMemberName(avatarName) self.addFrameCrew(shipFrame)
def spawnDoomTentacle(self): targetShip = self.getTargetShip() if targetShip and not self.doomTentacle: self.doomTentacle = DoomTentacle(self.uniqueName) self.doomTentacle.reparentTo(self) self.doomTentacle.setScale(targetShip.dimensions[1] / 400) self.doomTentacle.setEffectsScale(targetShip.dimensions[1] / 100) self.doomTentacle.setPos( targetShip, -targetShip.dimensions[0] / 1.3, -1 * ShipGlobals.getShipSplitOffset(targetShip.shipClass) + 2, -15) self.doomTentacle.setHpr(targetShip, 90, 0, 0) self.doomTentacle.setPlayRate(1.2, 'emerge') self.doomTentacle.play('emerge')
def avatarBoardShipFromShip(self, ship, fromShip, showMovie, ts): self.av.wrtReparentTo(fromShip.getModelRoot()) avPos = self.av.getPos() deckPos = None deckPos = ship.getClosestBoardingPos() if not deckPos: (deckPos, h) = ShipGlobals.getBoardingSpherePosH(ship.modelClass) offset = Point3(4 * random.random() - 2, 4 * random.random() - 2, 0) deckPos += offset endPos = self.av.getParent().getRelativePoint(ship.getModelRoot(), Point3(deckPos) + Point3(0, 0, 10)) if showMovie: (rope, ropeActor, ropeEndNode) = self.av.getRope() ropeAnchorNode = fromShip.getRopeAnchorNode(self.av, ropeEndNode) rightHand = self.av.rightHandNode leftHand = self.av.leftHandNode rope.setup(3, ((None, Point3(0, 0, 0)), (self.av, Point3(10, 20, 40)), (ropeAnchorNode, Point3(0, 0, 0)))) rope.reparentTo(ropeEndNode) ropeActor.reparentTo(leftHand) ropeActor.hide() midPos = (avPos + endPos) * 0.5 tWaitToTranslateZ = self.av.getDuration('swing_aboard', fromFrame = 0, toFrame = 42) tTranslateZ = self.av.getDuration('swing_aboard', fromFrame = 42, toFrame = 45) tWaitToAttachRope = self.av.getDuration('swing_aboard', fromFrame = 0, toFrame = 45) tWaitToDetachRope = self.av.getDuration('swing_aboard', fromFrame = 0, toFrame = 75) tRopeSwingDown = 0.75 tRopeSwing = tWaitToDetachRope - tWaitToAttachRope tRopeSwingAway = 0.75 if self.swingTrack: self.swingTrack.pause() self.swingTrack = None if self.av.isLocal(): ship.forceZoneLevel(0) swingTrack = Sequence(Func(self.av.lookAt, ship.getModelRoot()), Func(ship.boardingInit, self.av, fromShip), Func(ropeEndNode.wrtReparentTo, self.av), Parallel(self.av.actorInterval('swing_aboard'), ActorInterval(ropeActor, 'swing_aboard'), Sequence(Wait(tWaitToAttachRope - tRopeSwingDown), LerpPosInterval(ropeEndNode, tRopeSwingDown, Point3(1.0, 0, 3.0))), Sequence(Wait(tWaitToTranslateZ), LerpPosInterval(self.av, tTranslateZ, avPos + Point3(0.0, 0, 25.0))), Sequence(Wait(tWaitToAttachRope), Func(rope.reparentTo, leftHand), Func(ropeActor.show), LerpPosInterval(self.av, tRopeSwing / 2.0, midPos), Func(self.av.wrtReparentTo, ship.getModelRoot()), LerpPosInterval(self.av, tRopeSwing / 2.0, deckPos)), Sequence(Wait(tWaitToDetachRope), Func(rope.reparentTo, ropeEndNode), Func(ropeActor.detachNode), LerpPosInterval(ropeEndNode, tRopeSwingAway, Point3(0, 50, 50)))), Func(fromShip.boardingLeaveShip, self.av), Func(ship.boardingFinish, self.av, deckPos)) self.swingTrack = swingTrack self.swingTrack.start(ts) elif self.swingTrack: self.swingTrack.pause() self.swingTrack = None ship.boardingInit(self.av, ship) self.av.setPos(deckPos) fromShip.boardingLeaveShip(self.av) if self._shipBoardingFinishCall: self._shipBoardingFinishCall.destroy() self._shipBoardingFinishCall = FrameDelayedCall('shipToShipBoardingFinish-%s-%s' % (ship.doId, self.av.doId), Functor(ship.boardingFinish, self.av, deckPos))
def spawnDoomTentacle(self): targetShip = self.getTargetShip() if targetShip and not (self.doomTentacle): self.doomTentacle = DoomTentacle(self.uniqueName) self.doomTentacle.reparentTo(self) self.doomTentacle.setScale(targetShip.dimensions[1] / 400) self.doomTentacle.setEffectsScale(targetShip.dimensions[1] / 100) self.doomTentacle.setPos( targetShip, -targetShip.dimensions[0] / 1.3, -1 * ShipGlobals.getShipSplitOffset(targetShip.shipClass) + 2, -15, ) self.doomTentacle.setHpr(targetShip, 90, 0, 0) self.doomTentacle.setPlayRate(1.2, "emerge") self.doomTentacle.play("emerge")
def avatarBoardShipFromShip(self, ship, fromShip, showMovie, ts): self.av.wrtReparentTo(fromShip.getModelRoot()) avPos = self.av.getPos() deckPos = None deckPos = ship.getClosestBoardingPos() if not deckPos: deckPos, h = ShipGlobals.getBoardingSpherePosH(ship.modelClass) offset = Point3(4 * random.random() - 2, 4 * random.random() - 2, 0) deckPos += offset endPos = self.av.getParent().getRelativePoint(ship.getModelRoot(), Point3(deckPos) + Point3(0, 0, 10)) if showMovie: rope, ropeActor, ropeEndNode = self.av.getRope() ropeAnchorNode = fromShip.getRopeAnchorNode(self.av, ropeEndNode) rightHand = self.av.rightHandNode leftHand = self.av.leftHandNode rope.setup(3, ((None, Point3(0, 0, 0)), (self.av, Point3(10, 20, 40)), (ropeAnchorNode, Point3(0, 0, 0)))) rope.reparentTo(ropeEndNode) ropeActor.reparentTo(leftHand) ropeActor.hide() midPos = (avPos + endPos) * 0.5 tWaitToTranslateZ = self.av.getDuration('swing_aboard', fromFrame=0, toFrame=42) tTranslateZ = self.av.getDuration('swing_aboard', fromFrame=42, toFrame=45) tWaitToAttachRope = self.av.getDuration('swing_aboard', fromFrame=0, toFrame=45) tWaitToDetachRope = self.av.getDuration('swing_aboard', fromFrame=0, toFrame=75) tRopeSwingDown = 0.75 tRopeSwing = tWaitToDetachRope - tWaitToAttachRope tRopeSwingAway = 0.75 if self.swingTrack: self.swingTrack.pause() self.swingTrack = None if self.av.isLocal(): ship.forceZoneLevel(0) swingTrack = Sequence(Func(self.av.lookAt, ship.getModelRoot()), Func(ship.boardingInit, self.av, fromShip), Func(ropeEndNode.wrtReparentTo, self.av), Parallel(self.av.actorInterval('swing_aboard'), ActorInterval(ropeActor, 'swing_aboard'), Sequence(Wait(tWaitToAttachRope - tRopeSwingDown), LerpPosInterval(ropeEndNode, tRopeSwingDown, Point3(1.0, 0, 3.0))), Sequence(Wait(tWaitToTranslateZ), LerpPosInterval(self.av, tTranslateZ, avPos + Point3(0.0, 0, 25.0))), Sequence(Wait(tWaitToAttachRope), Func(rope.reparentTo, leftHand), Func(ropeActor.show), LerpPosInterval(self.av, tRopeSwing / 2.0, midPos), Func(self.av.wrtReparentTo, ship.getModelRoot()), LerpPosInterval(self.av, tRopeSwing / 2.0, deckPos)), Sequence(Wait(tWaitToDetachRope), Func(rope.reparentTo, ropeEndNode), Func(ropeActor.detachNode), LerpPosInterval(ropeEndNode, tRopeSwingAway, Point3(0, 50, 50)))), Func(fromShip.boardingLeaveShip, self.av), Func(ship.boardingFinish, self.av, deckPos)) self.swingTrack = swingTrack self.swingTrack.start(ts) else: if self.swingTrack: self.swingTrack.pause() self.swingTrack = None ship.boardingInit(self.av, ship) self.av.setPos(deckPos) fromShip.boardingLeaveShip(self.av) if self._shipBoardingFinishCall: self._shipBoardingFinishCall.destroy() self._shipBoardingFinishCall = FrameDelayedCall('shipToShipBoardingFinish-%s-%s' % (ship.doId, self.av.doId), Functor(ship.boardingFinish, self.av, deckPos)) return
def addOwnShip(self, shipId, callback): shipOV = base.cr.getOwnerView(shipId) if (not shipOV or self._siegeTeam) and localAvatar.getSiegeTeam() and localAvatar.getSiegeTeam() != self._siegeTeam: return None shipFrame = self.getFrame(shipId) if not shipFrame: mastInfo = ShipGlobals.getMastSetup(shipOV.shipClass) shipFrame = ShipFrameDeploy(parent = None, shipId = shipId, shipName = shipOV.name, shipClass = shipOV.shipClass, mastInfo = mastInfo, shipType = ShipFrameDeploy.STOwn, siegeTeam = self._siegeTeam, command = callback, extraArgs = [ shipId]) shipFrame.enableStatsOV(shipOV) if not Freebooter.getPaidStatus(base.localAvatar.getDoId()) and shipOV.shipClass not in ShipGlobals.UNPAID_SHIPS: shipFrame.nameLabel['text'] = PLocalizer.noFreebooterCap shipFrame.nameLabel['text_fg'] = (1, 0.69999999999999996, 0.69999999999999996, 1) self.addFrameOwn(shipFrame)
def setShipClass(self, shipClass): self.shipClass = shipClass messenger.send('setShipClass-%s' % self.getDoId(), [self.shipClass]) self.modelClass = ShipGlobals.getModelClass(shipClass) self.loadStats()
def avatarBoardShip(self, ship, showMovie, ts, fromWater = 0): boardingPosHpr = ship.getBoardingPosHpr() if self.av.isLocal() and boardingPosHpr: self.notify.warning('local avatar boarding from %s' % boardingPosHpr) self.av.reparentTo(render) self.av.setPos(boardingPosHpr[0]) self.av.setH(boardingPosHpr[1][0]) startingPos = self.av.getPos() deckPos = None if ship: deckPos = ship.getClosestBoardingPos() endPos = self.av.getParent().getRelativePoint(ship.getModelRoot(), deckPos) if showMovie: if fromWater: grabAnim = 'rope_grab' else: grabAnim = 'rope_grab_from_idle' tRopeSwingDown = 0.75 tWaitToAttachRope = self.av.getDuration(grabAnim, fromFrame = 0, toFrame = 42) (rope, ropeActor, ropeEndNode) = self.av.getRope() ropeAnchorNode = ship.getRopeAnchorNode(self.av, ropeEndNode) ropeMidNode = ship.attachNewNode('ropeMidNode') midNodeStartPos = (ropeAnchorNode.getPos(ship) + ropeEndNode.getPos(ship)) * 0.5 midNodeStartPos.setX(midNodeStartPos.getX() * 0.80000000000000004) ropeMidNode.setPos(midNodeStartPos) midNodeEndPos = (ropeAnchorNode.getPos(ship) + deckPos) * 0.5 midNodeEndPos.setX(midNodeEndPos.getX() * 1.2) rightHand = self.av.rightHandNode def playSplash(): if fromWater: splashEffect = SmallSplash.getEffect() if splashEffect: splashEffect.reparentTo(self.av) splashEffect.play() def setupRope(ropeParent): rope.setup(2, ((None, Point3(0, 0, 0)), (ropeAnchorNode, Point3(0, 0, 0)))) rope.reparentTo(ropeParent) setupRope(ropeEndNode) if self.swingTrack: self.swingTrack.pause() self.swingTrack = None boardAnimDur = self.av.getDuration('rope_board') boardingRopeH = ShipGlobals.getBoardingRopeH(ship.modelClass) boardingInterval = Sequence(Func(ropeEndNode.wrtReparentTo, self.av), Sequence(Wait(tWaitToAttachRope - tRopeSwingDown), Parallel(ActorInterval(self.av, grabAnim), LerpPosInterval(ropeEndNode, tRopeSwingDown, Point3(1.0, 0, 1.0)))), Func(self.av.lookAt, ship), Func(setupRope, rightHand), Parallel(ProjectileInterval(self.av, startPos = startingPos, endPos = endPos, duration = boardAnimDur, gravityMult = boardingRopeH), ProjectileInterval(ropeMidNode, startPos = midNodeStartPos, endPos = midNodeEndPos, duration = boardAnimDur), Sequence(Wait(0.20000000000000001), Func(ship.boardingInit, self.av, ship)), Sequence(Wait(boardAnimDur - 0.20000000000000001), Func(rope.detachNode)), self.av.actorInterval('rope_board', playRate = 1.0)), Parallel(self.av.actorInterval('rope_dismount', endFrame = 24), Sequence(Wait(0.5), Func(ropeMidNode.detachNode), Func(ship.boardingFinish, self.av, deckPos)))) self.swingTrack = boardingInterval self.swingTrack.start(ts) else: base.transitions.fadeOut(0.0) if self.swingTrack: self.swingTrack.pause() self.swingTrack = None ship.boardingInit(self.av, ship) self.av.setPos(endPos) if self._shipBoardingFinishCall: self._shipBoardingFinishCall.destroy() self._shipBoardingFinishCall = FrameDelayedCall('shipBoardingFinish-%s-%s' % (ship.doId, self.av.doId), Functor(ship.boardingFinish, self.av, deckPos, False))
def avatarBoardShip(self, ship, showMovie, ts, fromWater=0): boardingPosHpr = ship.getBoardingPosHpr() if self.av.isLocal() and boardingPosHpr: self.notify.warning('local avatar boarding from %s' % boardingPosHpr) self.av.reparentTo(render) self.av.setPos(boardingPosHpr[0]) self.av.setH(boardingPosHpr[1][0]) startingPos = self.av.getPos() deckPos = None if ship: deckPos = ship.getClosestBoardingPos() endPos = self.av.getParent().getRelativePoint(ship.getModelRoot(), deckPos) if showMovie: if fromWater: grabAnim = 'rope_grab' else: grabAnim = 'rope_grab_from_idle' tRopeSwingDown = 0.75 tWaitToAttachRope = self.av.getDuration(grabAnim, fromFrame=0, toFrame=42) rope, ropeActor, ropeEndNode = self.av.getRope() ropeAnchorNode = ship.getRopeAnchorNode(self.av, ropeEndNode) ropeMidNode = ship.attachNewNode('ropeMidNode') midNodeStartPos = (ropeAnchorNode.getPos(ship) + ropeEndNode.getPos(ship)) * 0.5 midNodeStartPos.setX(midNodeStartPos.getX() * 0.8) ropeMidNode.setPos(midNodeStartPos) midNodeEndPos = (ropeAnchorNode.getPos(ship) + deckPos) * 0.5 midNodeEndPos.setX(midNodeEndPos.getX() * 1.2) rightHand = self.av.rightHandNode def playSplash(): if fromWater: splashEffect = SmallSplash.getEffect() if splashEffect: splashEffect.reparentTo(self.av) splashEffect.play() def setupRope(ropeParent): rope.setup(2, ((None, Point3(0, 0, 0)), (ropeAnchorNode, Point3(0, 0, 0)))) rope.reparentTo(ropeParent) return setupRope(ropeEndNode) if self.swingTrack: self.swingTrack.pause() self.swingTrack = None boardAnimDur = self.av.getDuration('rope_board') boardingRopeH = ShipGlobals.getBoardingRopeH(ship.modelClass) boardingInterval = Sequence( Func(ropeEndNode.wrtReparentTo, self.av), Sequence( Wait(tWaitToAttachRope - tRopeSwingDown), Parallel( ActorInterval(self.av, grabAnim), LerpPosInterval(ropeEndNode, tRopeSwingDown, Point3(1.0, 0, 1.0)))), Func(self.av.lookAt, ship), Func(setupRope, rightHand), Parallel( ProjectileInterval(self.av, startPos=startingPos, endPos=endPos, duration=boardAnimDur, gravityMult=boardingRopeH), ProjectileInterval(ropeMidNode, startPos=midNodeStartPos, endPos=midNodeEndPos, duration=boardAnimDur), Sequence(Wait(0.2), Func(ship.boardingInit, self.av, ship)), Sequence(Wait(boardAnimDur - 0.2), Func(rope.detachNode)), self.av.actorInterval('rope_board', playRate=1.0)), Parallel( self.av.actorInterval('rope_dismount', endFrame=24), Sequence(Wait(0.5), Func(ropeMidNode.detachNode), Func(ship.boardingFinish, self.av, deckPos)))) self.swingTrack = boardingInterval self.swingTrack.start(ts) else: base.transitions.fadeOut(0.0) if self.swingTrack: self.swingTrack.pause() self.swingTrack = None ship.boardingInit(self.av, ship) self.av.setPos(endPos) if self._shipBoardingFinishCall: self._shipBoardingFinishCall.destroy() self._shipBoardingFinishCall = FrameDelayedCall( 'shipBoardingFinish-%s-%s' % (ship.doId, self.av.doId), Functor(ship.boardingFinish, self.av, deckPos, False)) return
def getShip(self, shipClass, style=ShipGlobals.Styles.Undefined, logo=ShipGlobals.Logos.Undefined, hullDesign=None, detailLevel=2, wantWheel=True, hullMaterial=None, sailMaterial=None, sailPattern=None, prowType=None, invertLogo=False): Ship = Ship import pirates.ship modelClass = ShipGlobals.getModelClass(shipClass) shipConfig = ShipGlobals.getShipConfig(shipClass) if style == ShipGlobals.Styles.Undefined: style = shipConfig['defaultStyle'] complexCustomization = 0 if sailPattern and sailMaterial and hullMaterial or SailReplace.has_key( shipClass): complexCustomization = 1 if not prowType: prowType = shipConfig['prow'] if not hullMaterial: hullMaterial = style if not sailMaterial: if SailReplace.has_key(shipClass): sailMaterial = SailReplace[shipClass] else: sailMaterial = style if not sailPattern: sailPattern = style shipHullTexture = ShipBlueprints.getShipTexture(hullMaterial) shipTextureSail = ShipBlueprints.getShipTexture(sailMaterial) logoTex = None if logo: logoTex = ShipBlueprints.getLogoTexture(logo) sailPatternTex = None if sailPattern: sailPatternTex = ShipBlueprints.getSailTexture(sailPattern) self.notify.debug('%s %s' % (sailPattern, logo)) if logo == ShipGlobals.Logos.Undefined: logo = shipConfig['sailLogo'] if logo in ShipGlobals.MAST_LOGO_PLACEMENT_LIST: placeLogos = 1 else: placeLogos = 0 if modelClass <= ShipGlobals.INTERCEPTORL3: mastHax = True else: mastHax = False customHull = hullDesign is not None if not logo != 0: pass customMasts = sailPattern != 0 hull = self.getHull(modelClass, customHull) breakAnims = {} metaAnims = {} hitAnims = {} root = NodePath('Ship') hull.locators.reparentTo(root) charRoot = root.attachNewNode(Character('ShipChar')) collisions = root.attachNewNode('collisions') lodNode = charRoot.attachNewNode(LODNode('lod')) if detailLevel == 0: lodNode.node().addSwitch(200, 0) lodNode.node().addSwitch(800, 200) lodNode.node().addSwitch(100000, 800) high = lodNode.attachNewNode('high') low = lodNode.attachNewNode('low') med = NodePath('med') superlow = lodNode.attachNewNode('superlow') elif detailLevel == 1: lodNode.node().addSwitch(300, 0) lodNode.node().addSwitch(1000, 300) lodNode.node().addSwitch(2000, 1000) lodNode.node().addSwitch(100000, 2000) high = lodNode.attachNewNode('high') med = lodNode.attachNewNode('med') low = lodNode.attachNewNode('low') superlow = lodNode.attachNewNode('superlow') else: lodNode.node().addSwitch(750, 0) lodNode.node().addSwitch(3000, 750) lodNode.node().addSwitch(8000, 3000) lodNode.node().addSwitch(100000, 8000) high = lodNode.attachNewNode('high') med = lodNode.attachNewNode('med') low = lodNode.attachNewNode('low') superlow = lodNode.attachNewNode('superlow') mastSetup = ShipGlobals.getMastSetup(shipClass) for data in [(0, 'location_mainmast_0'), (1, 'location_mainmast_1'), (2, 'location_mainmast_2'), (3, 'location_aftmast*'), (4, 'location_foremast*')]: mastData = mastSetup.get(data[0]) if mastData: mast = self.mastSets[mastData[0]].getMastSet( mastData[1] - 1, customMasts) mastRoot = hull.locators.find('**/%s' % data[1]).getTransform( hull.locators) model = NodePath(mast.charRoot) model.setTransform(mastRoot) if complexCustomization: model.setTexture(shipTextureSail) useLogoTex = logoTex if placeLogos: mastNum = data[0] if mastNum not in ShipGlobals.MAST_LOGO_PLACEMENT.get( modelClass): useLogoTex = None charBundle = mast.charRoot.getBundle(0) if data[0] < 3: for side in ['left', 'right']: ropeNode = hull.locators.find( '**/location_ropeLadder_%s_%s' % (side, data[0])) if ropeNode: transform = ropeNode.getTransform( NodePath(mast.charRoot)) charBundle.findChild('def_ladder_0_%s' % side).applyFreeze(transform) continue if sailPatternTex and useLogoTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) if invertLogo: node.setTexture(self.logoLayerInv, logoTex) else: node.setTexture(self.logoLayer, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif sailPatternTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif useLogoTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) if invertLogo: node.setTexture(self.logoLayerNoColorInv, logoTex) else: node.setTexture(self.logoLayerNoColor, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) model.flattenLight() if detailLevel == 0: model.find('**/low').copyTo(high) model.find('**/low').copyTo(low) model.find('**/superlow').copyTo(superlow) elif detailLevel == 1: model.find('**/med').copyTo(high) model.find('**/med').copyTo(med) low.node().stealChildren(model.find('**/low').node()) superlow.node().stealChildren( model.find('**/superlow').node()) elif detailLevel == 2: high.node().stealChildren(model.find('**/high').node()) med.node().stealChildren(model.find('**/med').node()) low.node().stealChildren(model.find('**/low').node()) superlow.node().stealChildren( model.find('**/superlow').node()) mastRoot = mast.collisions.find('**/collision_masts') if modelClass > ShipGlobals.INTERCEPTORL3 or data[0] != 3: mastCode = str(data[0]) mastRoot.setTag('Mast Code', mastCode) else: mastRoot.setName('colldision_sub_mast') mastRoot.reparentTo(collisions.find('**/collision_masts')) mastCode = '0' for coll in mast.collisions.findAllMatches( '**/collision_sail_*'): coll.setName('Sail-%s' % data[0]) coll.setTag('Mast Code', mastCode) for coll in mast.collisions.findAllMatches('**/sail_*'): coll.setName('Sail-%s' % data[0]) coll.setTag('Mast Code', mastCode) collisions.node().stealChildren(mast.collisions.node()) charBundle = mast.charRoot.getBundle(0) if mastHax and data[0] == 3: breakAnims[0][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), '1') breakAnims[0][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), '1') tempHit = hitAnims[0] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), '1') tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), '1') else: breakAnims[data[0]] = (AnimControlCollection(), AnimControlCollection()) breakAnims[data[0]][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), '0') breakAnims[data[0]][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), '0') tempHit = [ AnimControlCollection(), AnimControlCollection() ] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), '0') tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), '0') hitAnims[data[0]] = tempHit for (anim, fileName) in mast.metaAnims.iteritems(): if anim not in metaAnims: metaAnims[anim] = AnimControlCollection() if anim not in MissingAnims.get(modelClass, []): ac = charBundle.loadBindAnim(loader.loader, fileName, -1, SailSubset, True) if ac: metaAnims[anim].storeAnim( ac, str(metaAnims[anim].getNumAnims())) charRoot.node().combineWith(mast.charRoot) continue if self.wantProws and prowType: (highSprit, medSprit, lowSprit) = self.sprits[prowType].getAsset() transform = hull.locators.find( '**/location_bowsprit').getTransform(hull.locators) highSprit.setTransform(transform) medSprit.setTransform(transform) lowSprit.setTransform(transform) highSprit.reparentTo(hull.geoms[0]) medSprit.reparentTo(hull.geoms[1]) lowSprit.reparentTo(hull.geoms[2]) if wantWheel: shipWheel = ShipBlueprints.getWheel() wheelPoint = hull.locators.find( '**/location_wheel;+s').getTransform(hull.locators) shipWheel.setTransform(wheelPoint) shipWheel.flattenLight() shipWheel.find('**/collisions').copyTo(collisions) hull.geoms[0].node().stealChildren( shipWheel.find('**/high').node()) hull.geoms[1].node().stealChildren(shipWheel.find('**/med').node()) hull.geoms[2].node().stealChildren(shipWheel.find('**/low').node()) if complexCustomization: hull.geoms[0].setTexture(shipHullTexture) hull.geoms[0].flattenLight() hull.geoms[1].setTexture(shipHullTexture) hull.geoms[1].flattenLight() hull.geoms[2].setTexture(shipHullTexture) hull.geoms[2].flattenLight() hull.geoms[3].setTexture(shipHullTexture) hull.geoms[3].flattenLight() high.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[0].node()) med.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[1].node()) low.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[2].node()) superlow.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[3].node()) collisions.node().stealChildren(hull.collisions.node()) hull.locators.stash() charRoot.flattenStrong() ship = Ship.Ship(shipClass, root, breakAnims, hitAnims, metaAnims, collisions, hull.locators) if not complexCustomization: ship.char.setTexture(shipHullTexture) return ship
def fireBroadside(self, side, targetId=0, aimCode=0): zoneId = 0 target = self.cr.doId2do.get(targetId) if target: if isinstance(target, DistributedSimpleShip): targetPos = target.getTransNode().getPos(render) else: targetPos = target.getPos(render) zoneId = self.cr.activeWorld.worldGrid.getZoneFromXYZ(targetPos) zonePos = self.cr.activeWorld.worldGrid.getZoneCellOrigin(zoneId) shipPos = self.ship.getPos(render) cannonList = [] if side == 0: if self.leftBroadside and self.leftBroadsideConfig: cannonList = self.leftBroadside elif side == 1: if self.rightBroadside and self.rightBroadsideConfig: cannonList = self.rightBroadside spread = 1 flightTime = 0 if target and self.ship: dist = self.ship.getDistance(target) spread = max(0.5, dist / 1000.0) flightTime = dist / CannonGlobals.CLIENT_BROADSIDE_FIRE_VELOCITY broadsideMaxDelay = ShipGlobals.getBroadsideMaxDelay( self.ship.modelClass) targetShipVel = 0 if target: fvel = target.smoother.getSmoothForwardVelocity() faxis = target.smoother.getForwardAxis() targetShipVel = faxis * fvel * (flightTime + broadsideMaxDelay / 2.0) if targetShipVel: targetPos = Vec3(targetPos[0] + targetShipVel[0], targetPos[1] + targetShipVel[1], targetPos[2] + targetShipVel[2]) if __dev__ and config.GetBool('want-broadside-assist', 0): self.tracker.setPos(render, targetPos) delays = [] hitPosList = [] if side == 0: for i in range(len(self.leftBroadsideConfig)): if cannonList[i]: delays.append(random.uniform(0, broadsideMaxDelay)) if target: randX = random.gauss(0.0, 5.0 * spread) randY = random.gauss(0.0, 5.0 * spread) randZ = random.gauss(2.0, 3.0 * spread) cannonPos = cannonList[i].locator.getPos(render) diffX = shipPos[0] - cannonPos[0] diffY = shipPos[1] - cannonPos[1] hitPosList.append( ((targetPos[0] - zonePos[0]) + randX - diffX, (targetPos[1] - zonePos[1]) + randY - diffY, (targetPos[2] - zonePos[2]) + randZ)) else: hitPosList.append((100, 100, 100)) delays.append(0) hitPosList.append((100, 100, 100)) elif side == 1: for i in range(len(self.rightBroadsideConfig)): if cannonList[i]: delays.append(random.uniform(0, broadsideMaxDelay)) if target: randX = random.gauss(0.0, 5.0 * spread) randY = random.gauss(0.0, 5.0 * spread) randZ = random.gauss(2.0, 3.0 * spread) cannonPos = cannonList[i].locator.getPos(render) diffX = shipPos[0] - cannonPos[0] diffY = shipPos[1] - cannonPos[1] hitPosList.append( ((targetPos[0] - zonePos[0]) + randX - diffX, (targetPos[1] - zonePos[1]) + randY - diffY, (targetPos[2] - zonePos[2]) + randZ)) else: hitPosList.append((100, 100, 100)) delays.append(0) hitPosList.append((100, 100, 100)) delays[0] = 0.0 if len(delays) > 4: delays[1] = 0.0 random.shuffle(delays) self.doBroadside(side, delays, hitPosList, zoneId, flightTime, clientFire=1) self.sendUpdate('requestBroadside', [side, delays, hitPosList, zoneId, flightTime])
def attachToShip(self, ship): self.taskName = ship.taskName('wake') draw_shadow = True shadow_offset_x = 0.0 shadow_offset_y = 0.0 shadow_offset_z = 0.0 scale_x = 1.0 scale_y = 1.0 scale_z = 1.0 wake_offset_x = 0.0 wake_offset_y = 125.0 wake_offset_z = 0.0 wake_scale = 0.6 string = 'UNKNOWN' self.shadow_model = None model = ShipGlobals.getModelClass(ship.shipClass) if model == ShipGlobals.INTERCEPTORL1: scale_x = 0.7 scale_y = 0.55 if hasattr(base, 'pe'): shadow_offset_y = 10 else: shadow_offset_y = -10.0 self.shadow_model = loader.loadModel('models/sea/shadow_merchant') if hasattr(base, 'pe'): wake_offset_y = -16.5 else: wake_offset_y = 22.5 wake_scale = 0.18 string = 'INTERCEPTORL1' if model == ShipGlobals.INTERCEPTORL2: scale_x = 0.7 / 0.75 scale_y = 0.55 / 0.75 self.shadow_model = loader.loadModel('models/sea/shadow_merchant') if hasattr(base, 'pe'): wake_offset_y = -26.5 / 0.75 else: wake_offset_y = 22.5 / 0.75 wake_scale = 0.18 / 0.75 string = 'INTERCEPTORL2' if model == ShipGlobals.INTERCEPTORL3 or model == ShipGlobals.SKEL_INTERCEPTORL3: scale_x = 0.7 / 0.75 / 0.75 scale_y = 0.55 / 0.75 / 0.75 self.shadow_model = loader.loadModel('models/sea/shadow_merchant') if hasattr(base, 'pe'): wake_offset_y = -26.5 / 0.75 / 0.75 else: wake_offset_y = 22.5 / 0.75 / 0.75 wake_scale = 0.18 / 0.75 / 0.75 string = 'INTERCEPTORL3' if model == ShipGlobals.QUEEN_ANNES_REVENGE: scale_x = 0.7 / 0.75 / 0.75 scale_y = 0.55 / 0.75 / 0.75 self.shadow_model = loader.loadModel('models/sea/shadow_merchant') if hasattr(base, 'pe'): wake_offset_y = -26.5 / 0.75 / 0.75 else: wake_offset_y = 22.5 / 0.75 / 0.75 wake_scale = 0.18 / 0.75 / 0.75 string = 'QUEEN_ANNES_REVENGE' if model == ShipGlobals.MERCHANTL1: scale_x = 1.05 scale_y = 1.05 self.shadow_model = loader.loadModel('models/sea/shadow_merchant') if hasattr(base, 'pe'): wake_offset_y = -80.0 * 0.7 else: wake_offset_y = 80.0 * 0.7 wake_scale = 0.5 * 0.7 string = 'MERCHANTL1' if model == ShipGlobals.MERCHANTL2: scale_x = 1.5 scale_y = 1.5 self.shadow_model = loader.loadModel('models/sea/shadow_merchant') if hasattr(base, 'pe'): wake_offset_y = -80.0 else: wake_offset_y = 80.0 wake_scale = 0.5 string = 'MERCHANTL2' if model == ShipGlobals.MERCHANTL3: scale_x = 1.85 scale_y = 1.85 self.shadow_model = loader.loadModel('models/sea/shadow_merchant') if hasattr(base, 'pe'): wake_offset_y = -80.0 * 1.2333 else: wake_offset_y = 80.0 * 1.2333 wake_scale = 0.5 * 1.2333 string = 'MERCHANTL3' if model == ShipGlobals.WARSHIPL1: scale_x = 1.08 * 0.75 * 0.75 scale_y = 1.01 * 0.75 * 0.75 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 * 0.7 * 0.7 if hasattr(base, 'pe'): wake_offset_y = -125.0 * 0.7 * 0.7 else: wake_offset_y = 125.0 * 0.7 * 0.7 string = 'WARSHIPL1' if model == ShipGlobals.WARSHIPL2: scale_x = 1.08 * 0.75 scale_y = 1.01 * 0.75 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 * 0.7 if hasattr(base, 'pe'): wake_offset_y = -125.0 * 0.7 else: wake_offset_y = 125.0 * 0.7 string = 'WARSHIPL2' if model == ShipGlobals.WARSHIPL3: scale_x = 1.08 scale_y = 1.05 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 if hasattr(base, 'pe'): wake_offset_y = -125.0 else: wake_offset_y = 125.0 string = 'WARSHIPL3' if model == ShipGlobals.BRIGL1: scale_x = 1.08 * 0.75 * 0.75 scale_y = 1.01 * 0.75 * 0.8 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 * 0.7 * 0.7 if hasattr(base, 'pe'): wake_offset_y = -125.0 * 0.7 * 0.7 else: wake_offset_y = 125.0 * 0.7 * 0.7 string = 'BRIGL1' if model == ShipGlobals.BRIGL2: scale_x = 1.08 * 0.75 scale_y = 1.01 * 0.8 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 * 0.7 if hasattr(base, 'pe'): wake_offset_y = -125.0 * 0.7 else: wake_offset_y = 125.0 * 0.7 string = 'BRIGL2' if model == ShipGlobals.BRIGL3: scale_x = 1.08 * 0.95 scale_y = 1.05 * 1.1 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 if hasattr(base, 'pe'): wake_offset_y = -125.0 else: wake_offset_y = 125.0 string = 'BRIGL3' if model == ShipGlobals.SKEL_WARSHIPL3: scale = 0.725 scale_x = 1.08 * scale scale_y = 1.22 * scale if hasattr(base, 'pe'): shadow_offset_y = 10.0 else: shadow_offset_y = -12.5 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.5 * scale if hasattr(base, 'pe'): wake_offset_y = -85.0 * scale else: wake_offset_y = 85.0 * scale string = 'SKEL_WARSHIPL3' if model == ShipGlobals.BLACK_PEARL: scale_x = 1.05 scale_y = 1.08 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 wake_offset_y = 100.0 string = 'BLACK_PEARL' if model == ShipGlobals.SHIP_OF_THE_LINE: scale_x = 1.05 scale_y = 1.08 self.shadow_model = loader.loadModel('models/sea/shadow_warship') wake_scale = 0.6 wake_offset_y = 100.0 string = 'SHIP_OF_THE_LINE' if model == ShipGlobals.DAUNTLESS: string = 'DAUNTLESS' if model == ShipGlobals.FLYING_DUTCHMAN: string = 'FLYING_DUTCHMAN' if draw_shadow: if self.shadow_model: water_shadow = WaterShadow('p_ship_shadow', self.shadow_model, ship) water_shadow.setPos(shadow_offset_x, shadow_offset_y, shadow_offset_z) water_shadow.setScale(scale_x, scale_y, scale_z) if not hasattr(base, 'pe'): water_shadow.setHpr(180, 0, 0) self.shadow = water_shadow else: print 'ERROR: -------------- shadow model not found for ship class', ship.shipClass self.wake.setScale(wake_scale) if not hasattr(base, 'pe'): self.wake.setHpr(180, 0, 0) self.wake.setPos(wake_offset_x, wake_offset_y, wake_offset_z) self.wake.reparentTo(ship) self.wake.hide() return
def setShipClass(self, shipClass): (self.hpModifier, self.cargoModifier, self.expModifier) = ShipGlobals.getModifiedShipStats(self.level) DistributedPlayerSimpleShip.setShipClass(self, shipClass)