Create Citadel class that inherits from Ship. Add Service slots

This commit is contained in:
blitzmann
2016-05-15 22:23:23 -04:00
parent 10f51b41b7
commit 4041ecddc4
6 changed files with 62 additions and 8 deletions

42
eos/saveddata/citadel.py Normal file
View File

@@ -0,0 +1,42 @@
#===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of eos.
#
# eos is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# eos is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with eos. If not, see <http://www.gnu.org/licenses/>.
#===============================================================================
from eos.modifiedAttributeDict import ModifiedAttributeDict, ItemAttrShortcut
from eos.effectHandlerHelpers import HandledItem
from eos.saveddata.mode import Mode
import eos.db
from eos.types import Ship
import logging
logger = logging.getLogger(__name__)
class Citadel(Ship):
def validate(self, item):
if item.category.name != "Structure":
raise ValueError('Passed item "%s" (category: (%s)) is not under Structure category'%(item.name, item.category.name))
def __deepcopy__(self, memo):
copy = Citadel(self.item)
return copy
def __repr__(self):
return "Citadel(ID={}, name={}) at {}".format(
self.item.ID, self.item.name, hex(id(self))
)

View File

@@ -24,7 +24,7 @@ from itertools import chain
from eos import capSim
from copy import deepcopy
from math import sqrt, log, asinh
from eos.types import Drone, Cargo, Ship, Character, State, Slot, Module, Implant, Booster, Skill
from eos.types import Drone, Cargo, Ship, Character, State, Slot, Module, Implant, Booster, Skill, Citadel
from eos.saveddata.module import State, Hardpoint
from eos.saveddata.mode import Mode
import eos.db
@@ -92,7 +92,11 @@ class Fit(object):
return
try:
self.__ship = Ship(item, self)
try:
self.__ship = Ship(item, self)
except ValueError:
self.__ship = Citadel(item, self)
print self.__ship
# @todo extra attributes is now useless, however it set to be
# the same as ship attributes for ease (so we don't have to
# change all instances in source). Remove this at some point
@@ -564,7 +568,7 @@ class Fit(object):
if self.ship is None:
return
for slotType in (Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM):
for slotType in (Slot.LOW, Slot.MED, Slot.HIGH, Slot.RIG, Slot.SUBSYSTEM, Slot.SERVICE):
amount = self.getSlotsFree(slotType, True)
if amount > 0:
for _ in xrange(int(amount)):
@@ -639,6 +643,7 @@ class Fit(object):
Slot.HIGH: "hiSlots",
Slot.RIG: "rigSlots",
Slot.SUBSYSTEM: "maxSubSystems",
Slot.SERVICE: "serviceSlots",
Slot.F_LIGHT: "fighterLightSlots",
Slot.F_SUPPORT: "fighterSupportSlots",
Slot.F_HEAVY: "fighterHeavySlots"}

View File

@@ -46,6 +46,8 @@ class Slot(Enum):
# system effects. They are projected "modules" and pyfa assumes all modules
# have a slot. In this case, make one up.
SYSTEM = 7
# used for citadel services
SERVICE = 8
# fighter 'slots'. Just easier to put them here...
F_LIGHT = 10
F_SUPPORT = 11
@@ -534,7 +536,8 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
"loPower" : Slot.LOW,
"medPower" : Slot.MED,
"hiPower" : Slot.HIGH,
"subSystem" : Slot.SUBSYSTEM}
"subSystem" : Slot.SUBSYSTEM,
"serviceSlot": Slot.SERVICE}
if item is None:
return None
for effectName, slot in effectSlotMap.iteritems():

View File

@@ -42,9 +42,7 @@ class Ship(ItemAttrShortcut, HandledItem):
}
def __init__(self, item, parent=None):
if item.category.name not in ("Ship", "Structure"):
raise ValueError('Passed item "%s" (category: (%s)) is not under Ship category'%(item.name, item.category.name))
self.validate(item)
self.__item = item
self.__modeItems = self.__getModeItems()
@@ -58,6 +56,10 @@ class Ship(ItemAttrShortcut, HandledItem):
self.parent = parent
self.commandBonus = 0
def validate(self, item):
if item.category.name != "Ship":
raise ValueError('Passed item "%s" (category: (%s)) is not under Ship category'%(item.name, item.category.name))
@property
def item(self):
return self.__item

View File

@@ -35,9 +35,11 @@ from eos.saveddata.implantSet import ImplantSet
from eos.saveddata.booster import SideEffect
from eos.saveddata.booster import Booster
from eos.saveddata.ship import Ship
from eos.saveddata.citadel import Citadel
from eos.saveddata.fit import Fit, ImplantLocation
from eos.saveddata.mode import Mode
from eos.saveddata.fleet import Fleet, Wing, Squad
from eos.saveddata.miscData import MiscData
from eos.saveddata.override import Override
import eos.db

View File

@@ -395,7 +395,7 @@ class FittingView(d.Display):
sFit = service.Fit.getInstance()
fit = sFit.getFit(self.activeFitID)
slotOrder = [Slot.SUBSYSTEM, Slot.HIGH, Slot.MED, Slot.LOW, Slot.RIG]
slotOrder = [Slot.SUBSYSTEM, Slot.HIGH, Slot.MED, Slot.LOW, Slot.RIG, Slot.SERVICE]
if fit is not None:
self.mods = fit.modules[:]