Package schlachtfeld :: Module Group
[hide private]
[frames] | no frames]

Source Code for Module schlachtfeld.Group

  1  #!/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3   
  4  # Schlachtfeld - Großk�mpfe im EWS System  
  5  #   http://rpg-tools-1d6.sf.net 
  6  # Copyright © 2007 - 2007 Achim Zien 
  7   
  8  # This program is free software; you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation; either version 2 of the License, or 
 11  # (at your option) any later version. 
 12   
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17   
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program; if not, write to the Free Software 
 20  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 
 21  # MA 02110-1301 USA 
 22   
 23   
 24  ''' 
 25  Characters and methods for use in schlachtfeld module. 
 26  Characters act on their own now and can be imported and saved via amov module. 
 27  ''' 
 28   
 29   
 30  #### IMPORTS #### 
 31   
 32  # for the fighting 
 33  from random import randrange as rnd 
 34  from random import shuffle 
 35  import math 
 36  # For selection of armies through command line arguments:  
 37  import sys 
 38  # EWS standard dice 
 39  from ews import pmw6 
 40  # Name-Generator 
 41  import namen 
 42  # Obtain Charakters from yaml-files 
 43  from amov import Charakter, Versionsverwaltung 
 44  # replaced the alias with the real directory.  
 45   
 46  #### IMPORTS #### 
 47   
 48   
 49   
 50   
 51  #### Top-Level Objects #### 
 52   
 53  name_objekt = namen.Name() 
 54   
 55  # squareroot of maximal one-line-formation 
 56  line_cut = 5 
 57   
 58  # minimum absolute remaining fraction of fighters until resign/flee 
 59  powervalue = 0.2 
 60   
 61  #### Top-Level Objects #### 
 62   
 63   
 64   
 65   
 66  #### WRAPPERS #### 
 67   
68 -def ews():
69 """Do one roll with the plusminus d6 die (wrapper for a function in pmw6).""" 70 return pmw6.pmw6()
71
72 -def check(skill,MW):
73 """Check if a given skill test reached a min-value (wrapper for a function in pmw6).""" 74 return pmw6.check(skill,MW)
75
76 -def ocheck(skill,MW):
77 """Return the degree of success / failure for a skill check (wrapper for a function in pmw6).""" 78 return pmw6.ocheck(skill,MW)
79
80 -def name_it(language):
81 '''Return a name corresponding to the characters language.''' 82 return name_object.erzuege(language)
83 84 #### WRAPPERS #### 85 86 87 88 89 #### CLASSES #### 90
91 -class Group:
92 """A group of fighters of one type"""
93 - def __init__(self,name=u'unknown group',resign=0.1,flee=0.3):
94 # global group parameters 95 self.situation = [12,0,0,0,0] # general, bias, leaders, heroes, other 96 self.command = (resign,flee) 97 # soldier's rows 98 self.active = [] 99 self.inactive = [] 100 self.dead = [] 101 self.fled = [] 102 # special entities 103 self.leader = None 104 self.enemy = None 105 self.battlefield = None 106 self.name = name 107 self.grouptype = "Gruppe" 108 # statistics 109 self.nact = 0 110 self.ninact = 0 111 self.n = self.nact + self.ninact 112 self.powerratio = 1 113 self.aliveratio = 1 114 self.empty = True 115 self.status = None 116 return
117 118
119 - def __repr__(self):
120 # nice printout 121 scribble = self.name 122 scribble += '\nTypus: ' + `self.grouptype` 123 scribble += '\nAktiv: ' + `self.nact` 124 scribble += '\nInaktiv: ' + `self.ninact` 125 scribble += '\nTot, geflohen: ' + `len(self.dead)` + `len(self.fled)` 126 return scribble
127 128
129 - def count(self):
130 '''Count through the lines to establish size of group.''' 131 self.nact = len(self.active) 132 if self.nact > 0: 133 self.empty = False 134 else: 135 self.empty = True 136 self.ninact = len(self.inactive) 137 self.line = max(self.nact, int(round(line_cut*math.sqrt(self.nact)))) 138 return
139 140
141 - def fleeresigncheck(self):
142 if self.powerratio < self.command[1] or self.aliveratio < self.command[1] * powervalue: 143 self.battlefield.fGroups.append(self.enemy) 144 self.status = 'fled' 145 elif self.powerratio < self.command[0] or self.aliveratio < self.command[0] * powervalue: 146 self.status = 'resigned' 147 self.battlefield.fGroups.append(self.enemy) 148 return
149 150
151 - def setenemy(self, enemy):
152 '''Convey information about the enemy to a group.''' 153 self.enemy = enemy 154 return
155 156
157 - def setbattlefield(self, battlefield):
158 self.battlefield = battlefield 159 return
160 161 162
163 -class Army(Group):
164 """One of the sides. Can contain of several Groups and is in itself a group. Army leaders affect all groups."""
165 - def __init__(self,aname=u'unknown army',aresign=0.1,aflee=0.3):
166 Group.__init__(self,name=aname,resign=aresign,flee=aflee) 167 self.groups = [] 168 self.grouptype = "Armee" 169 return
170 171 172 #### CLASSES #### 173