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 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 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 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 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 __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 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 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 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, ): 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) 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()) 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 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 __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.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 shipClass and mastInfo: self.setShipInfo(shipClass, mastInfo) elif self.shipId: shipOVs = base.cr.getOwnerViewDoList(DistributedPlayerSimpleShipOV) 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]) self.accept('setShipClass-%s' % self.shipId, self.setHullType) self.accept('setMastType-%s' % self.shipId, self.setMastType) 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)