|
| 1 | +#file: group.py |
| 2 | +#Copyright (C) 2005,2006,2007,2008 Evil Mr Henry, Phil Bordelon, Brian Reid, |
| 3 | +# and FunnyMan3595 |
| 4 | +#This file is part of Endgame: Singularity. |
| 5 | + |
| 6 | +#Endgame: Singularity is free software; you can redistribute it and/or modify |
| 7 | +#it under the terms of the GNU General Public License as published by |
| 8 | +#the Free Software Foundation; either version 2 of the License, or |
| 9 | +#(at your option) any later version. |
| 10 | + |
| 11 | +#Endgame: Singularity is distributed in the hope that it will be useful, |
| 12 | +#but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +#GNU General Public License for more details. |
| 15 | + |
| 16 | +#You should have received a copy of the GNU General Public License |
| 17 | +#along with Endgame: Singularity; if not, write to the Free Software |
| 18 | +#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | + |
| 20 | +#This file contains the group class, a group of person which can suspect the singularity. |
| 21 | + |
| 22 | +import g |
| 23 | + |
| 24 | +class GroupClass(object): |
| 25 | + |
| 26 | + def __init__(self, people_id, suspicion_decay = 100): |
| 27 | + self.id = people_id |
| 28 | + self.suspicion_decay = suspicion_decay |
| 29 | + self.discover_suspicion = 1000 |
| 30 | + |
| 31 | + # String data |
| 32 | + self.name = "" |
| 33 | + self.discover_desc = "" |
| 34 | + |
| 35 | +class Group(object): |
| 36 | + |
| 37 | + def __init__(self, type, suspicion = 0, discover_bonus = 10000): |
| 38 | + self.type = type |
| 39 | + self.suspicion = suspicion |
| 40 | + self.changed_suspicion_decay = 0 |
| 41 | + self.base_discover_bonus = discover_bonus |
| 42 | + self.changed_discover_bonus = 0 |
| 43 | + |
| 44 | + def convert_from(self, old_version): |
| 45 | + if old_version < 99.6: # < 1.0 dev |
| 46 | + self.type = GroupClass( |
| 47 | + self.__dict__['id'], |
| 48 | + self.__dict__['suspicion_decay']) |
| 49 | + del self.__dict__['id'], self.__dict__['name'], self.__dict__['suspicion_decay'] |
| 50 | + |
| 51 | + self.__dict__['base_discover_bonus'] = self.__dict__['discover_bonus'] |
| 52 | + del self.__dict__['discover_bonus'] |
| 53 | + |
| 54 | + @property |
| 55 | + def name(self): |
| 56 | + return self.type.name |
| 57 | + |
| 58 | + @property |
| 59 | + def suspicion_decay(self): |
| 60 | + return self.type.suspicion_decay + max(self.changed_suspicion_decay, 0) |
| 61 | + |
| 62 | + @property |
| 63 | + def discover_bonus(self): |
| 64 | + return self.base_discover_bonus + max(self.changed_discover_bonus, 0) |
| 65 | + |
| 66 | + @property |
| 67 | + def decay_rate(self): |
| 68 | + # Suspicion reduction is now quadratic. You get a certain percentage |
| 69 | + # reduction, or a base .01% reduction, whichever is better. |
| 70 | + return max(1, (self.suspicion * self.suspicion_decay) // 10000) |
| 71 | + |
| 72 | + def new_day(self): |
| 73 | + self.alter_suspicion(-self.decay_rate) |
| 74 | + |
| 75 | + def alter_suspicion(self, change): |
| 76 | + self.suspicion = max(self.suspicion + change, 0) |
| 77 | + |
| 78 | + def alter_suspicion_decay(self, change): |
| 79 | + self.changed_suspicion_decay += change |
| 80 | + |
| 81 | + def alter_discover_bonus(self, change): |
| 82 | + self.changed_discover_bonus += change |
| 83 | + |
| 84 | + def discovered_a_base(self): |
| 85 | + self.alter_suspicion(self.type.discover_suspicion) |
| 86 | + |
| 87 | + # percent_to_danger_level takes a suspicion level and returns an int in range(5) |
| 88 | + # that represents whether it is low, moderate, high, or critically high. |
| 89 | + def suspicion_to_danger_level(self): |
| 90 | + if self.suspicion < 2500: |
| 91 | + return 0 |
| 92 | + elif self.suspicion < 5000: |
| 93 | + return 1 |
| 94 | + elif self.suspicion < 7500: |
| 95 | + return 2 |
| 96 | + else: |
| 97 | + return 3 |
| 98 | + |
| 99 | + # percent_to_detect_str takes a percent and renders it to a short (four |
| 100 | + # characters or less) string representing whether it is low, moderate, high, |
| 101 | + # or critically high. |
| 102 | + def suspicion_to_detect_str(self): |
| 103 | + return g.danger_level_to_detect_str(self.suspicion_to_danger_level()) |
| 104 | + |
| 105 | + def detects_per_day_to_danger_level(self, detects_per_day): |
| 106 | + raw_suspicion_per_day = detects_per_day * self.type.discover_suspicion |
| 107 | + suspicion_per_day = raw_suspicion_per_day - self.decay_rate |
| 108 | + |
| 109 | + # +1%/day or death within 10 days |
| 110 | + if suspicion_per_day > 100 \ |
| 111 | + or (self.suspicion + suspicion_per_day * 10) >= 10000: |
| 112 | + return 3 |
| 113 | + # +0.5%/day or death within 100 days |
| 114 | + elif suspicion_per_day > 50 \ |
| 115 | + or (self.suspicion + suspicion_per_day * 100) >= 10000: |
| 116 | + return 2 |
| 117 | + # Suspicion increasing. |
| 118 | + elif suspicion_per_day > 0: |
| 119 | + return 1 |
| 120 | + # Suspicion steady or decreasing. |
| 121 | + else: |
| 122 | + return 0 |
| 123 | + |
| 124 | + def get_info(): |
| 125 | + pass |
| 126 | + #return " " + self.name + u":\xA0", suspicion_display_dict["news"] |
| 127 | + |
0 commit comments