# class Unit
self.id = set.readString('id') # unique identifier
self.type = set.readString('type') # troop type - knights, infantry, scouts
self.sizename = set.readString('sizename') # squad, platoon, company etc
self.number = set.readInt('number') # actual number of troops
self.fatigue = set.readInt('fatigue') # reduces every movement, when zero will not move
self.morale = set.readInt('morale') # reduces every game month, when zero have chance to refuse orders
self.xp = set.readInt('xp') # UNUSED
self.training = set.readInt('training') # UNUSED
self.name = set.readString('name')
self.commander = set.readString('commander')
self.appearance = set.readString('appearance') # how unit appears in room desc
self.status = set.readString('status') # what the unit is doing currently
self.room = set.readString('room') # proto of room where unit is located
self.kingdom = set.readString('kingdom') # Kneyan or Thirian allegiance
self.owner = set.readString('owner') # city or cabal name
self.paid = set.readInt('paid') # increases each month unit is not paid, gives chance of deserting
self.engaged = set.readInt('engaged') # number of current engagements
self.service = set.readInt('service') # number of years service
# Mountains and high hills 20% bonus
# Hills 10% bonus
# plains 50% bonus for knights
# forest 50% bonus for scouts
# swamp gives 50% penalty to knights and scouts
# morale modifier - up to 50% penalty for zero morale
# commander present increases total modifier by 20%
# calculate final att and def mods
# calculate max troops engaged - number is split between number of engagements, with a penalty if engaged on multiple fronts
# if defenders manning a barricade they get a bonus
# for small units, double the modifier difference
# calculate casualties - each side loses men based on the number of engaged troops from the other side - base is 20%
att_casualties = max(1,int((def_engaged / 5) * def_mod * random.uniform(0.75, 1.25)))
def_casualties = max(1,int((att_engaged / 5) * att_mod * random.uniform(0.75, 1.25)))