-
Notifications
You must be signed in to change notification settings - Fork 0
/
BRB.py
421 lines (368 loc) · 15.3 KB
/
BRB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
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
#! /usr/bin/env python
from warhammer import ward,armor,wound,hit
import random
import Lizardmen
#### Dice Rolls
def D6(num):
return map(lambda x:random.randint(1,6),range(num))
def D3(num):
return map(lambda x:random.randint(1,3),range(num))
def ArtilDice(num):
return map(lambda x:2*random.randint(1,5),range(num))
#### Organized Attack functions
def Attack(Def,verbose,):
"""
The generic Attack model, which has no special rules applied to it.
"""
return ward(armor(wound(hit(self.Ata,self.WepS,Def.WepS,verbose)[0],self.Str,Def.Tuf,verbose),self.Str,Def.Tuf,verbose),Def.Ward,verbose)
def PoisonedAttack(Def,verbose):
"""
Poisoned Attacks; any dice which hits on a 6 automatically wounds
"""
wounds = 0
hits,rolls = hit(self.Ata,self.WepS,Def.WepS,verbose)
for dice in rolls:
if dice == 6:
wounds += 1
hits -= 1
wounds += wound(hits,self.Str,Def.Tuf,verbose)
return ward(armor(wounds,self.Str,Def.Armr),Def.Ward)
def HatredAttacks(Def,verbose):
"""
Attacks made with Hatred of the opponent can reroll misses.
Most opponents have normal hatred which can only be applied
in the first round of combat.
This rule is intended to be used beside a normal attack,
and only applied in the first round of combat.
"""
hits,rolls = hit(self.Ata,self.WepS,Def.WepS,verbose)
hits += hit(self.Ata-hits,self.WepS,Def.WepS,verbose)[0]
return ward(armor(wound(hits,self.Str,Def.Tuf,verbose),self.Str,Def.Armr,verbose),Def.Ward,verbose)
#### CLASSES
class Model(object):
"""
All models use this basic class. Methods can be overwritten
through superclassing for specialty subclasses
"""
def __init__(self,Mov,WepS,BalS,Str,Tuf,Wnd,ini,ata,Led,Armr,Ward,Points):
"""
Set the model's basic GURPS style stats
"""
self.Mov = Mov
self.WepS = WepS
self.BalS = BalS
self.Str = Str
self.Tuf = Tuf
self.Wnd = Wnd
self.Ini = ini
self.Ata = ata
self.Led = Led
self.Armr = Armr
self.Ward = Ward
self.Pts = Points
self.Attack = Attack
class Unit(object):
def __init__(self):
pass
#### SPECIAL RULE APPLICATION METHODS
def BuildModel(unitList,Mov,WepS,BalS,Str,Tuf,Wnd,ini,ata,Led,Armr,Ward,Points):
unitList.append(Model())
setattr(unitList[-1],'Movement',Mov)
setattr(unitList[-1],'WeaponSkill',WepS)
setattr(unitList[-1],'BallisticSkill',BalS)
setattr(unitList[-1],'Strength',Str)
setattr(unitList[-1],'Toughness',Tuf)
setattr(unitList[-1],'Wounds',Wnd)
setattr(unitList[-1],'Initiative',ini)
setattr(unitList[-1],'Attacks',ata)
setattr(unitList[-1],'Leadership',Led)
setattr(unitList[-1],'ArmorPts',Armr)
setattr(unitList[-1],'WardPts',Ward)
setattr(unitList[-1],'Points',Points)
return unitList[-1];
def Regenerate(Model,Points):
pass
def ASL(Model,Points):
setattr(Model,'ASL',1)
Model.Points += Points
return Model;
def Skirmishers(Model,Points):
setattr(Model,'Skirmishers',1)
Model.Points += Points
return Model;
def Handweapon(Model,Points):
setattr(Model,'HandWeapon',1)
Model.Points += Points
return Model;
def Shield(Model,Points):
setattr(Model,'Shield',1)
Model.ArmorPts += 1
if Model.WardPts == 0:
Model.WardPts = 1
Model.Points += Points
return Model;
def Spear(Model,Points):
setattr(Model,'Spears',1)
Model.Points += Points
return Model;
def Champion(Model,Points):
setattr(Model,'Champion',1)
Model.Points += Points
def Musician(Model,Points):
setattr(Model,'Musician',1)
Model.Points += Points
return Model;
def Standard(Model,Points):
setattr(Model,'Standard',1)
Model.Points += Points
return Model;
def Javelin(Model,Points):
setattr(Model,'Javelin',1)
Model.Points += Points
return Model;
def GreatWeapon(Model,Points):
setattr(Model,'GreatWeapon',1)
Model.Points += Points
Model.Strength += 2
ASL(Model,0)
return Model;
def AHW(Model,Points):
setattr(Model,'AHW',1)
Model.Points += Points
return Model;
def Halberd(Model,Points):
setattr(Model,'Halberd',1)
Model.Points += Points
return Model;
def LA(Model,Points):
setattr(Model,'LA',1)
Model.ArmorPts += 1
Model.Points += Points
return Model;
def Fear(Model,Points):
setattr(Model,'Fear',1)
Model.Points += Points
return Model;
def Stupidity(Model,Points):
setattr(Model,'Stupidity',1)
Model.Points += Points
return Model;
def Terror(Model,Points):
setattr(Model,'Terror',1)
Model.Points += Points
return Model;
def Monster(Model,Points):
Terror(Model,0)
setattr(Model,'Monster',1)
setattr(Model,'ThunderStomp',1)
return Model;
#### MOUNTS
def Cavalry(Rider,Mount,ThickSkinned,Points):
setattr(Rider,'Mounted',1)
setattr(Mount,'Mount',1)
if ThickSkinned == 1:
Rider.ArmorPts += 2
else:
Rider.ArmorPts += 1
Rider.Points += Points
return Rider,Mount;
def MonsterMount(Rider,Mount,Points):
setattr(Rider,'MonsterMounted',1)
setattr(Mount,'MonsterMount',1)
Monster(Mount,0)
Cavalry(Rider,Mount,0,Points)
delattr(Mount,'Mount')
return Rider,Mount;
def ColdOne(Unit,Points):
Mountee = Unit.pop()
Lizardmen.BuildModel(UnitList,7,3,0,4,4,1,2,1,3,2,0,0)
setattr(Mount,'ColdOne',1)
Stupidity(Fear(Mount,0),0)
Cavalry(Mountee,Mount,1,Points)
UnitList.append(Mountee)
#### MOVEMENT RULES
def Charge(UnitList,distance,dice,verbose):
dicerolls = [random.randint(1,6) for x in range(dice)]
Chargedist = sum(dicerolls) + UnitList[1].Movement
if Chargedist < distance:
if verbose >= 4:
print "Charge Failed!"
distance -= max(dicerolls)
else:
if verbose >= 4:
print "Charge Made!"
distance = 0
return distance;
def flee(UnitList1,UnitList2,Chargedist,distance,verbose):
distance1 = random.randint(1,6) + random.randint(1,6)
distance2 = random.randint(1,6) + random.randint(1,6) + Chargedist
if verbose >= 4:
print "Attempting to flee! Ran a distance of " + str(distance1) + ". Pursuers ran "+str(distance2)+". Initial Separation distance was %i." %distance
return (distance1 + distance - distance2);
def breaktest(UnitList,CombatRes,verbose):
if hasattr(UnitList[1],"ColdBlooded"):
rollList = [random.randint(1,6) for x in range(3)]
rollList.sort()
rolls = sum(rollList[0:2])
if verbose >= 4:
print "Cold Blooded Break Test Roll on Modifier -%i!" %CombatRes, rollList, rolls
else:
rolls = random.randint(1,6) + random.randint(1,6)
if verbose >= 4:
print "Break Test Roll total on Modifier -%i!" %CombatRes, rolls
if rolls == 2:
if verbose >= 3:
print "Leadership Test Passed!"
return 1;
rolls += (0 if hasattr(UnitList[1],"Stubborn") else CombatRes)
if rolls > max([UnitList[x].Leadership for x in range(1,len(UnitList))]):
if verbose >= 3:
print "Leadership Test Failed!"
return 0;
else:
if verbose >= 3:
print "Leadership Test Passed!"
return 1;
def runaway(UnitListFlee,UnitListPursue,verbose):
distance = flee(UnitListFlee,UnitListPursue,0,0,verbose)
stand = 0
while stand == 0:
if distance <= 0:
for x in range(len(UnitListFlee)-1):
UnitListFlee.pop()
if verbose >= 2:
print "Unit was cut down in flight!"
return; 4893122
else:
stand = breaktest(UnitListFlee,0,verbose)
if stand == 1 and verbose >= 2:
print "Unit Rallied!"
if stand == 0:
distance = flee(UnitListFlee,UnitListPursue,UnitListPursue[1].Movement,distance,verbose)
#### MELEE COMBAT SECTION
def BreathRanged():
pass
def BreathMelee():
pass
def PoisonedAttacks(AttackUnit,DefenseModel,AttackingModelsList,x,verbose):
if x <AttackUnit[0].Width:
Hits,ToHitRolls = hit(AttackUnit[AttackingModelsList[x]].Attacks,AttackUnit[AttackingModelsList[x]].WeaponSkill,DefenseModel.WeaponSkill,verbose)
for y in range(Hits):
if ToHitRolls[y] == 6:
if verbose >=4:
print "Poisoned Attack Landed! Automatic Wound!"
kills += ward(armor(1,AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.ArmorPts,verbose),DefenseModel.WardPts,verbose)
else:
kills += ward(armor(wound(1,AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.Toughness,verbose),AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.ArmorPts,verbose),DefenseModel.WardPts,verbose)
else:
Hits,ToHitRolls = hit(1,AttackUnit[AttackingModelsList[x]].WeaponSkill,DefenseModel.WeaponSkill,verbose)
for y in range(Hits):
if ToHitRolls[y] == 6:
kills += ward(armor(1,AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.ArmorPts,verbose),DefenseModel.WardPts,verbose)
else:
kills += ward(armor(wound(1,AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.Toughness,verbose),AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.ArmorPts,verbose),DefenseModel.WardPts,verbose)
def CarnosaurAttacks(AttackUnit,DefenseModel,AttackingModelsList,x,verbose):
wounds = ward(armor(wound(hit(AttackUnit[AttackingModelsList[x]].Attacks,AttackUnit[AttackingModelsList[x]].WeaponSkill,DefenseModel.WeaponSkill,verbose)[0],AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.Toughness,verbose),AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.ArmorPts,verbose),DefenseModel.WardPts,verbose)
if wounds > 0 and not hasattr(AttackUnit[AttackingModelsList[x]],'Frenzy'):
setattr(AttackUnit[AttackingModelsList[x]],'Frenzy',2)
AttackUnit[AttackingModelsList[x]].Attacks += 1
kills = 0
for x in range(wounds):
kills += random.randint(1,3)
if verbose >= 3:
print kills, "Carnosaur Wounds Total"
return kills;
def attack(AttackUnit,DefenseModel,AttackingModelsList,verbose):
kills = 0
for x in range(len(AttackingModelsList)):
if hasattr(AttackUnit[AttackingModelsList[x]],'JunglePoisons') or hasattr(AttackUnit[AttackingModelsList[x]],'PoisonedAttacks'):
kills += PoisonedAttacks(AttackUnit,DefenseModel,AttackingModelsList,x,verbose)
elif hasattr(AttackUnit[AttackingModelsList[x]],'Blood-frenzy') and hasattr(AttackUnit[AttackingModelsList[x]],'UltimatePredator'):
kills += CarnosaurAttacks(AttackUnit,DefenseModel,AttackingModelsList,x,verbose)
else:
if x <AttackUnit[0].Width:
kills += ward(armor(wound(hit(AttackUnit[AttackingModelsList[x]].Attacks,AttackUnit[AttackingModelsList[x]].WeaponSkill,DefenseModel.WeaponSkill,verbose)[0],AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.Toughness,verbose),AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.ArmorPts,verbose),DefenseModel.WardPts,verbose)
else:
kills += ward(armor(wound(hit(1,AttackUnit[AttackingModelsList[x]].WeaponSkill,DefenseModel.WeaponSkill,verbose)[0],AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.Toughness,verbose),AttackUnit[AttackingModelsList[x]].Strength,DefenseModel.ArmorPts,verbose),DefenseModel.WardPts,verbose)
if verbose >= 3:
print kills, "Wounds Total"
return kills;
def inicheck(UnitList1,UnitList2):
inilist = []
for x in range(1,len(UnitList1)):
if not UnitList1[x].Initiative in inilist:
inilist.append(UnitList1[x].Initiative)
for x in range(1,len(UnitList2)):
if not UnitList2[x].Initiative in inilist:
inilist.append(UnitList2[x].Initiative)
inilist.sort()
inilist.reverse()
return inilist;
def takewounds(UnitList,Wounds):
for y in range(Wounds):
if len(UnitList) >= 2:
if UnitList[-1].Wounds > 1:
UnitList[-1].Wounds -= 1
else:
Model = UnitList.pop()
if hasattr(Model,'Mounted') and hasattr(UnitList[1],'Mount'):
UnitList.pop()
return Wounds;
def Stomp(UnitList1,UnitList2,roundwnds1,roundwnds2,verbose):
if len(UnitList2) > 1:
for x in range(1,len(UnitList1)):
if hasattr(UnitList1[x],'Stomp'):
roundwnds2 += ward(armor(wound(1,UnitList1[x].Strength,UnitList2[-1].Toughness,verbose),UnitList1[x].Strength,UnitList2[-1].ArmorPts,verbose),UnitList2[-1].WardPts,verbose)
elif hasattr(UnitList1[x],'ThunderStomp'):
roundwnds2 += ward(armor(wound(random.randint(1,6),UnitList1[x].Strength,UnitList2[-1].Toughness,verbose),UnitList1[x].Strength,UnitList2[-1].ArmorPts,verbose),UnitList2[-1].WardPts,verbose)
if len(UnitList1) > 1:
for x in range(1,len(UnitList2)):
if hasattr(UnitList2[x],'Stomp'):
roundwnds1 += ward(armor(wound(1,UnitList2[x].Strength,UnitList1[-1].Toughness,verbose),UnitList2[x].Strength,UnitList1[-1].ArmorPts,verbose),UnitList1[-1].WardPts,verbose)
elif hasattr(UnitList2[x],'ThunderStomp'):
roundwnds1 += ward(armor(wound(random.randint(1,6),UnitList2[x].Strength,UnitList1[-1].Toughness,verbose),UnitList2[x].Strength,UnitList1[-1].ArmorPts,verbose),UnitList1[-1].WardPts,verbose)
return roundwnds1,roundwnds2;
def combatround(UnitList1,UnitList2,verbose):
if verbose >= 2:
print "Start round of combat!\n", "Army One has "+str(len(UnitList1)-1)+" Units left, Army Two has " +str(len(UnitList2)-1) + " left."
IniList = inicheck(UnitList1,UnitList2)
roundwndsA = 0
roundwndsB = 0
Models1 = 0
Models2 = 0
MaxModels1 = 2*UnitList1[0].Width
MaxModels2 = 2*UnitList2[0].Width
for x in range(len(IniList)):
if verbose >= 3: print "Fighting at initiative "+str(x)
AttackingModelsListA = []
AttackingModelsListB = []
AWounds = 0
BWounds = 0
for y in range(1,len(UnitList1)):
if UnitList1[y].Initiative == IniList[x] and Models1 <MaxModels1:
AttackingModelsListA.append(y)
Models1 += 1
for y in range(1,len(UnitList2)):
if UnitList2[y].Initiative == IniList[x] and Models2 <MaxModels2:
AttackingModelsListB.append(y)
Models2 += 1
if len(AttackingModelsListA) > 0 and len(UnitList2) > 1:
if verbose >= 3:
print "First Army Attacks!"
BWounds = attack(UnitList1,UnitList2[-1],AttackingModelsListA,verbose)
roundwndsB += BWounds
if len(AttackingModelsListB) > 0 and len(UnitList1) > 1:
if verbose >= 3:
print "Second Army Attacks!"
AWounds = attack(UnitList2,UnitList1[-1],AttackingModelsListB,verbose)
roundwndsA += AWounds
takewounds(UnitList1,AWounds)
takewounds(UnitList2,BWounds)
roundwndsA,roundwndsB = Stomp(UnitList1,UnitList2,roundwndsA,roundwndsB,verbose)
ARanks = int(len(UnitList1)/UnitList1[0].Width)
BRanks = int(len(UnitList2)/UnitList2[0].Width)
combatres = ARanks - BRanks + roundwndsB - roundwndsA
return combatres;
#### POST COMBAT
if __name__ == '__main__':
print ArtilDice(5)