DataDict = Data() DataDict = playerSetUp(DataDict) # Loop over 25 missions in game for i in range(25): # Determine Mission Event EventResult = DetermineEvent() # Determine Bomber position in formation DataDict = DeterminePosition(EventResult, DataDict) # Determine position in formation skill = dataDict["BomberData"]["Skill"] positionRoll = d10() + skill if positionRoll <= 6: position = "middle" elif positionRoll <= 8: position = "rear" elif positionRoll <=1 10: position = "front" else: position = "lead" if eventData["Bump2Lead"]: position = "lead" dataDict["BomberData"]["Position"] = position # Determine encounters
def BanditAttack(year, position, eventDict, dataDict): """ Created on Sun Jul 26 13:44:49 2020 This routine computes the outcome of a bandit attack on the formation the bomber is in Parameters ---------- year : python integer (1942-44) The year the action is taking place position : string Position of the bomber in the formation (middle, front, rear, lead) eventDict: python dictionary Dictionary containing the adjustments due to the event dataDict : Python dictionary dictionary containing data used in simulation Returns ------- outcome : string Text message describing the outcome dataDict : dictionary updated data dictionary shotDown : Boolean was bomber shot down? @author: wtdic """ from B17Dice import d10 from crewFires import bomberFires from BanditFires import banditFires # Extract Bomber Data dictionary bomberData = DataDict["BomberData"] bomberFast = eventDict["EventSwitches"]["BomberFast"] # Extract Damage status engineStatus = bomberData["DamageStatus"]["Engine"] frameStatus = bomberData["DamageStatus"]["Frame"] if engineStatus == "OK" and frameStatus == "OK": damageStatus = "undamaged" else: damageStatus = "damaged" # Set shot Down status to false shotDown = False ############################################# # Determine if attack on bomber takes place # ############################################# # Find modifier for bandit attack on plane modifier = 0 if year == 1942: # Modify for year modifier = -2 elif year == 1944: modifier = -1 if damageStatus == "damaged": # Modify for damaged status modifier += 4 # Modify for position in formation if position == "lead": modifier += 3 elif position == "front": modifier += 2 elif position == "rear" modifier += 1 roll = d10() + modifier() # Modified die roll if roll < 8: # No attack # No bandit attack. Return safe text. return("OK\nBomber Group wards off attack.\nYou are safe for now.") else: ######################################### # Bomber is attacked. Compute Results. # ######################################### # Find Bandit Type banditType = dataDict["BanditType"][d10()] banditDefense = dataDict["BanditDefense"][banditType] returnText = banditType # Determine direction of attack if position == "front": # Modifier depending on position in formation modifier = 2 elif position == "lead": modifier = 3 elif position == "rear": modifier = -2 else: modifier = 0 roll = modifier + d10() # Roll for direction if roll < 4 or eventDict["EventSwitches"]["ReadOnly"]: attackDirection = "rear" returnText += " Bandit! 6 O'clock!\n" elif roll <6: attackDirection = "port" returnText += " Bandit! 9 O'clock!\n" elif roll < 8: attackDirection = "starboard" returnText += " Bandit! 3 O'clock!\n" else: attackDirection = "front" returnText += " Bandit! 12 O'clock!\n" # Determine if crew is fast modifier = bomberData["Skill"] # Check if bomber fires first due to skill or bomber fast event if d10() + modifier >= 8 or bomeberFast: fastCrew = True returnText += "RATATATATATATAATATATATATAT\n" else: fastCrew = False returnText += "[Tracers whip past the cockpit]\n}" ##################### # Determine outcome # ##################### # If bomber crew is fast # Bomber crew fires first if fastCrew: banditStatus, returnText = bomberFires(position, eventData, banditDefense, bomberData, returnText, dataDict ) if banditStatus = "OK": shotDown, returnText, dataDict = banditFires(eventData, returnText, dataDict ) # Bandit fires if crew is slow else:
2ndBanditProb = 2 FlackProb = 5 BanditProb2 = 7 FlackProb2 = 0 2ndBandit2 = 3 else: BanditProb = 6 2ndBanditProb = 2 FlackProb = 9 BanditProb2 = 6 FlackProb2 = 3 2ndBandit2 = 3 Encounters = [] BanditPull = d10() if BanditPull <= 2ndBanditProb: Encounters.append("2Bandits") elif BanditPull <= BanditProb: Encounters.append("Bandit") if d10() <= FlackProb: Encounters.append("Flack") Encounters.append("BombRun") if d10() <= FlackProb2: Encountes.append("Flack") BanditPull = d10() if BanditPull <= 2ndBandit2:
def DetermineEvent(): """ Created on Sat August 15, 2020 This routine determines the mission event Parameters ---------- none Returns ------- EventDict : Python dictionary Values to set Bandit Ata, Bomber AtA, and embeded dictionary with switches for rear attack only bumped to lead, crew wounded only, hit damage +1, Bomber is Fast, Flack -1, Replacement Ball gunner, Bandit attacks two turns. @author: wtdic """ from B17Dice import d10 # initialize event values and switches BanditAtA = 0 BomberAtA = 0 BomberAtG = 0 RearOnly = False Bump2Lead = False CrewWound = False HitDamage = 1 BomberFast = False FlackDamage = -1 ReplaceBall = False BanditAttack2 = False # draw event event = d10() - 1 # Set event results if event == 0: BanditAtA = -1 elif event == 1: BomberAtA = 1 BomberAtG = 1 elif event == 2: RearOnly = True elif event == 3: Bump2Lead = True elif event == 4: CrewWound = True elif event == 5: HitDamage = 1 elif event == 6: BomberFast = True elif event == 7: FlackDamage = -1 elif event == 8: ReplaceBall = True else: BanditAttack2 = True EventSwitches = {"RearOnly": RearOnly, "Bump2Lead": Bump2Lead, "CrewWound": CrewWound, "BomberFast": BomberFast, "ReplaceBall": ReplaceBall, "BanditAttack2": BanditAttack2 } EventDict = {"BanditAtA": BanditAtA, "BomberAtA": BomberAtA, "BomberAtG": BomberAtG, "HitDamage": HitDamage, "FLackDamage": FlackDamage, "EventSwithces": EventSwitches } return(EventDict)
returnText: String Contains the text description of events to be reported to the player dataDict: Dictionary Contains game data @author: wtdic """ from B17Dice import d10 from BomberHit import DetermineDamage # Determine bandit to hit number banditAtA = dataDict["BanditAtA"] + EventDict["BanditAtA"] if year == 1942: # Add year modifier banditAtA -= 1 elif year == 1944: banditAtA += 1 # Results of bandid fire if d10() < banditAtA: # Miss returnText += "OK\nWhew that was close!\n" else: # Hit shotDown, returnText, dataDict = DetermineDamage(dataDict, returnText, EventDict ) return(shotDown, returnText, dataDict)