Package schlachtfeld ::
Module schlachtfeld
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Schlachtensimulation nach den Regeln des Ein Würfel Systems
24
25 """
26
27
28
29
30
31 from random import randrange as rnd
32 from random import shuffle
33 import math
34
35 import sys
36
37 from ews import pmw6
38
39 from ews.fight import fight
40
41 import namen
42
43 from amov import Charakter, Versionsverwaltung
44
45 from Group import *
46 from Char import *
47
48
49
50
51
52
53
54
55
56
57
58
59 biasfactor = 1.4
60
61
62 biasmultiplier = 2.0
63
64
65 biascutoff = 8
66
67
68
69
70
71 expfactor = 1
72
73
74 exp_logfactor = 1.5
75
76
77
78
79
80 inactvalue = 0.7
81
82
83 woundvalue = 0.4
84
85
86 powervalue = 0.2
87
88
89
90
91
92
93
94
95 name_objekt = namen.Name()
96 verbose = True
97
98
99
100
101
102
103
104
106 """Do one roll with the plusminus d6 die (wrapper for a function in pmw6)."""
107 return pmw6.pmw6()
108
110 """Check if a given skill test reached a min-value (wrapper for a function in pmw6)."""
111 return pmw6.check(skill,MW)
112
114 """Return the degree of success / failure for a skill check (wrapper for a function in pmw6)."""
115 return pmw6.ocheck(skill,MW)
116
117
118
119
120
121
122
123
125
127 '''
128 Create a new battle with armies, groups, leaders, soldiers and characters. Contains of several consecutive battle-rounds.
129 armies should be a list of combattants (usually 2) containing in a list:
130 1. their army settings - (name,resignratio,fleeratio)
131 2. a list of settings for the contained groups - (name,resignratio,fleeratio)
132 3. a dictionary containing the template-nameswith a tuple containing template-switch and a list of corresponding tuples (number of soldiers, index number of host(0 is army),chartype) - {'template_name_1':(True, [(number_count_1a,host#1a,Typus1a),(number_count_1b,host#1b,Typus1b)]), 'template_name_2':(False,[(number_count_2,host#2,Typus2)]), ...}
133 '''
134 self.output = ""
135 if verbose:
136 output = "Pitching the following armies against each other: " + str(armies)
137 print output
138 self.output += output
139 self.Armies = []
140 self.Groups = []
141 self.Soldiers = []
142 self.Leaders = []
143 self.Heroes = []
144 for i in range(len(armies)):
145 self.Armies.append(Army(armies[i][0][0],armies[i][0][1],armies[i][0][2]))
146 self.Armies[-1].setbattlefield(self)
147 for j in range(len(armies[i][1])):
148 self.Groups.append(Group(armies[i][1][j][0],armies[i][1][j][1],armies[i][1][j][2]))
149 self.Groups[-1].sethhost(self.Armies[i])
150 self.Groups[-1].setbattlefield(self)
151 self.Armies[-1].groups.append(self.Groups[-1])
152 for j in armies[i][2]:
153 if j[3] == 'Soldat':
154 concern = self.Soldiers
155 Model = Char
156 elif j[3] == 'Anführer':
157 concern = self.Leaders
158 Model = Leader
159 elif j[3] == 'Held':
160 concern = self.Heroes
161 Model = Hero
162 else:
163 raise UnmatchedChartype
164 for k in range(j[1]):
165 spawn = Model(source=j[0],template=j[4])
166 if j[2] == -1:
167 spawn.sethost(self.Armies[-1])
168 else:
169 spawn.sethost(self.Armies[-1].groups[j[2]])
170 concern.append(spawn)
171 spawn.host.active.append(spawn)
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193 self.Pairs = []
194 self.gPairs = []
195 self.fGroups = self.Armies + self.Groups
196 print "fGrous:", self.fGroups
197 return
198
199
201 '''
202 Execute a single round of the battle together with organization of Armies, Groups and Characters.
203 Performs the following steps:
204 1. Enemy finding for single groups
205 2. Characters prepare themselves
206 3. Groups prepare themselves
207 4. Pairs of groups evaluate their combat modifiers
208 5. Pairs of soldiers are formed
209 6. They fight each other
210 '''
211 print self.Armies
212 self.auto_enemy()
213 print "\ngPairs:", self.gPairs
214 self.char_preparations()
215 self.group_preparations()
216 for i in self.gPairs:
217 self.group_pairings(i)
218 self.char_pairings(i)
219 self.fight_rows()
220 return
221
222
224 '''Automatically assign enemies to groups / armies.'''
225 shuffle(self.fGroups)
226 if verbose:
227 print "\nCreating pairs from the following groups:", self.fGroups, "\n"
228 for i in range(len(self.fGroups)):
229 if len(self.fGroups) == 0:
230 print "fGroups is empty."
231 break
232 elif len(self.fGroups) == 1:
233 print "fGroups has only one member."
234 break
235 else:
236 print "\nGroup", i
237 guy = self.fGroups.pop()
238 if verbose:
239 print "Group 0:", guy
240 if i == len(self.fGroups):
241 if verbose:
242 print "no groups left to pair with each other."
243 break
244
245
246
247
248 cnt = -1
249 while cnt == -1:
250 print "cnt:", cnt, "len(self.fGroups):", len(self.fGroups)
251 guy.enemy = self.fGroups[cnt]
252 cnt -= 1
253 if cnt + len(self.fGroups) == 0:
254 break
255 if guy.enemy:
256 if verbose:
257 print "paired with:", guy.enemy, "."
258 guy.enemy.enemy = guy
259 if (0 - cnt - 1) != len(self.fGroups):
260 self.fGroups = self.fGroups[:cnt-1] + self.fGroups[cnt+1:]
261 else:
262 self.fGroups = self.fGroups[cnt+1:]
263 self.gPairs.append((guy, guy.enemy))
264 return
265
266
268 '''
269 Make all the characters still involved do their preparations:
270 Leader(): .plan, .speak and .checkmorale
271 Hero(): .motivate and .checkmorale
272 Char(): .checkmorale
273 '''
274 for i in self.Leaders:
275 if i.alive and not i.queue and not i.fled and i.host:
276 i.plan()
277 i.speak()
278 i.checkmorale()
279 for i in self.Heroes:
280 if i.alive and not i.queue and not i.fled and i.host:
281 i.motivate()
282 i.checkmorale()
283 for i in self.Soldiers:
284 if i.alive and not i.queue and not i.fled and i.host:
285 i.checkmorale()
286 return
287
288
290 '''
291 Make all non-empty groups do their preparations for battle:
292 1. find enemies
293 2. count numbers
294 '''
295 for i in self.Armies + self.Groups:
296 i.count()
297 i.fleeresigncheck()
298
299 return
300
301
303 '''Take selected pairs of groups to calculate their powerratio/aliveratio and evaluate their relative bias.'''
304 powercheck(groups)
305 bias_me(groups)
306 return
307
308
310 '''
311 Pair the Characters from two Groups to fight each other. Only the Characters from the front line are taken into account.
312 groups: should be a tuple of two Group() or Army() instances.
313 '''
314 self.Pairs = []
315 n = min([i.line for i in groups])
316 if verbose:
317 print "\nPairs: n =", n
318 for i in range(n):
319 self.Pairs.append([j.active[i] for j in groups])
320 return
321
322
327
328
330 '''Nice printout of current situation on the BattleField().'''
331 scribble = 'Yeah, the proper printout is still lacking'
332 return scribble
333
334
336 '''Automatically executes battles plus intermediate output until the battle ends (flight, extermination, resignation).'''
337 return
338
339
341 '''Give one of the Armies/Groups additional support in form of new soldiers, leaders, heroes or entire groups.'''
342
343 return
344
345
346
347
348
349
350
351
352
353
355 """Compare the ratio between fighters who are alive in each group (but not necessarily able to fight)."""
356 for i in Groups:
357 i.aliveratio = float(i.nact + i.ninact * inactvalue) / max(1, i.n)
358 for i in range(len(Groups)):
359
360 if Groups[1-i].aliveratio != 0:
361 Groups[i].powerratio = Groups[i].aliveratio / Groups[1-i].aliveratio
362
363 else:
364 Groups[i].powerratio = 1
365
366
379
380
381
382
384
385 for j in range(2):
386 expadd = max(math.log(max(chars[1-j].exp, 1), exp_logfactor), 1) / max(chars[j].exp, 3)
387 chars[j].upgrade(expadd)
388 chars[j].escape_check()
389 if verbose:
390 print '\n', chars[j]
391 if verbose:
392 print '\n\n'
393
394
395
396 if __name__ == '__main__':
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485 armies = [(('Menschen Armee',0.5,0.4), [], [("tag:1w6.org,2007:Mensch",10,-1,'Soldat',True)]),
486 (('Goblin Armee',0.4,0.4), [], [("tag:1w6.org,2007:Goblin",15,-1,'Soldat',True)])]
487
488 test = BattleField(armies)
489 for i in range(5):
490 test.battle()
491 for i in test.Armies:
492 print i
493 print '\n'
494 print '... done!'
495
496
497
498