1def check_validity(value): 2 """checks if value is valid""" 3 return value is not None and value >= 0 4 5 6class EnumItem(int): 7 def __new__(self, number, name, enum_name): 8 obj = int.__new__(EnumItem, number) 9 obj.name = name 10 obj.enum_name = enum_name 11 return obj 12 13 def __str__(self): 14 return "%s.%s" % (self.enum_name, self.name) 15 16 17class EnumMeta(type): 18 @staticmethod 19 def __new__(cls, name, bases, attrs): 20 super_new = super(EnumMeta, cls).__new__ 21 parents = [b for b in bases if isinstance(b, EnumMeta)] 22 if not parents: 23 return super_new(cls, name, bases, attrs) 24 25 for k, v in attrs.items(): 26 if not k.startswith('_') and isinstance(v, int): 27 attrs[k] = EnumItem(v, k, name) 28 return super_new(cls, name, bases, attrs) 29 30 31class Enum(metaclass=EnumMeta): 32 @classmethod 33 def range(cls, start, end): 34 result = [] 35 current_range = range(start, end) 36 for key in dir(cls): 37 if not key.startswith('_'): 38 value = getattr(cls, key) 39 if isinstance(value, EnumItem) and value in current_range: 40 result.append(value) 41 return sorted(result) 42 43 @classmethod 44 def has_item(cls, item): 45 """Return True if specified item is a member of the enum 46 47 :type item: EnumItem 48 :rtype: bool 49 """ 50 return hasattr(cls, item.name) and isinstance(getattr(cls, item.name), EnumItem) 51 52 53class PriorityType(Enum): 54 RESOURCE_GROWTH = 1 55 RESOURCE_PRODUCTION = 2 56 RESOURCE_RESEARCH = 3 57 RESOURCE_TRADE = 4 58 RESOURCE_CONSTRUCTION = 5 59 PRODUCTION_EXPLORATION = 6 60 PRODUCTION_OUTPOST = 7 61 PRODUCTION_COLONISATION = 8 62 PRODUCTION_INVASION = 9 63 PRODUCTION_MILITARY = 10 64 PRODUCTION_BUILDINGS = 11 65 RESEARCH_LEARNING = 12 66 RESEARCH_GROWTH = 13 67 RESEARCH_PRODUCTION = 14 68 RESEARCH_CONSTRUCTION = 15 69 RESEARCH_ECONOMICS = 16 70 RESEARCH_SHIPS = 17 71 RESEARCH_DEFENSE = 18 72 PRODUCTION_ORBITAL_DEFENSE = 19 73 PRODUCTION_ORBITAL_INVASION = 20 74 PRODUCTION_ORBITAL_OUTPOST = 21 75 PRODUCTION_ORBITAL_COLONISATION = 22 76 77 78def get_priority_resource_types(): 79 return PriorityType.range(1, 6) 80 81 82def get_priority_production_types(): 83 return PriorityType.range(6, 12) 84 85 86class MissionType(Enum): 87 OUTPOST = 1 88 COLONISATION = 2 89 SPLIT_FLEET = 3 90 MERGE_FLEET = 4 # not really supported yet 91 EXPLORATION = 5 92 INVASION = 9 93 MILITARY = 10 94 # mostly same as MILITARY, but waits for system removal from all targeted system lists 95 # (invasion, colonization, outpost, blockade) before clearing 96 SECURE = 11 97 ORBITAL_DEFENSE = 12 98 ORBITAL_INVASION = 13 99 ORBITAL_OUTPOST = 14 100 # ORBITAL_COLONISATION = 15 Not implemented yet 101 PROTECT_REGION = 16 102 103 104class ShipRoleType(Enum): # this is also used in determining fleetRoles 105 INVALID = -1 106 MILITARY_ATTACK = 1 107 MILITARY_MISSILES = 2 108 MILITARY_POINTDEFENSE = 3 109 CIVILIAN_EXPLORATION = 4 110 CIVILIAN_COLONISATION = 5 111 CIVILIAN_OUTPOST = 6 112 MILITARY_INVASION = 7 113 MILITARY = 8 114 BASE_DEFENSE = 9 115 BASE_INVASION = 10 116 BASE_OUTPOST = 11 117 BASE_COLONISATION = 12 118 119 120class EmpireProductionTypes(Enum): 121 BT_NOT_BUILDING = 0 # ///< no building is taking place 122 BT_BUILDING = 1 # ///< a Building object is being built 123 BT_SHIP = 2 # ///< a Ship object is being built 124 125 126class FocusType: 127 FOCUS_PROTECTION = "FOCUS_PROTECTION" 128 FOCUS_GROWTH = "FOCUS_GROWTH" 129 FOCUS_INDUSTRY = "FOCUS_INDUSTRY" 130 FOCUS_RESEARCH = "FOCUS_RESEARCH" 131 FOCUS_TRADE = "FOCUS_TRADE" 132 FOCUS_CONSTRUCTION = "FOCUS_CONSTRUCTION" 133 134 135class EmpireMeters: 136 DETECTION_STRENGTH = "METER_DETECTION_STRENGTH" 137