-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_campaign_data_locations.py
More file actions
109 lines (95 loc) · 4.61 KB
/
test_campaign_data_locations.py
File metadata and controls
109 lines (95 loc) · 4.61 KB
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
"""This file contains tests to ensure all specified locations pass basic sanity checks.
Imports From:
campaign.py
report.py
Functions:
test_campaign_data_locations()
"""
from campaign import Campaign
from report import Report
def test_campaign_data_locations(current_campaign: Campaign) -> Report:
"""Test all locations specified for sanity
Parameters:
current_campaign: Campaign | The parsed campaign to be tested
Returns:
Report | The completed Report to be returned
"""
report = Report()
player_bases: list[int] = []
if current_campaign.campaign_data.parsed:
for location in current_campaign.campaign_data.locations:
if "PLAYER_BASE" in location.functions:
player_bases.append(location.location_id)
if location.alignment != "FRIENDLY":
report.errors.append(
f"ERROR: Location ID {location.location_id} is marked as "
"PLAYER BASE but is ENEMY alligned."
)
if (
"INSERTION"
in current_campaign.campaign_data.player_mission_data["types"]
):
if "INSERTION" not in location.mission_types:
report.errors.append(
"ERROR: INSERTION mission type defined but player base location ID "
f"{location.location_id} does not specify "
"INSERTION as a valid MissionType."
)
if (
"LAND_STRIKE"
in current_campaign.campaign_data.player_mission_data["types"]
):
if "LAND_STRIKE" not in location.mission_types:
report.errors.append(
"ERROR: LAND_STRIKE mission type defined but player base location ID "
f"{location.location_id} does not specify "
"LAND_STRIKE as a valid MissionType."
)
if "LAND_STRIKE_TARGET" in location.functions:
if f"LAND_STRIKE_LOCATION_{location.location_id}" not in [
mission.name for mission in current_campaign.missions
]:
report.errors.append(
f"ERROR: Location ID {location.location_id} specified as "
"LAND_STRIKE_TARGET but mission file LAND_STRIKE_LOCATION_"
f"{location.location_id} not found."
)
if "INSERTION_TARGET" in location.functions:
if f"INSERTION_LOCATION_{location.location_id}" not in [
mission.name for mission in current_campaign.missions
]:
report.errors.append(
f"ERROR: Location ID {location.location_id} specified as INSERTION_TARGET "
"but mission file INSERTION_LOCATION_{location.location_id} not found."
)
if not player_bases:
report.errors.append("ERROR: No location specified as PLAYER_BASE found.")
elif len(player_bases) > 1:
report.errors.append(
"ERROR: More than one Location specified as PLAYER_BASE."
f"Only one PLAYER_BASE may be specified: {player_bases}"
)
# Check SOSUS lines
for location in current_campaign.campaign_data.locations:
if not location.related_sosus:
if "SOSUS_NODE" in location.functions:
report.warnings.append(
f"WARNING: Location ID {location.location_id} specified "
"as SOSUS_NODE but no related SOSUS found."
)
else:
if "SOSUS_NODE" not in location.functions:
report.warnings.append(
f"WARNING: Location ID {location.location_id} has related SOSUS lines "
f"{location.related_sosus} but not specified as SOSUS_NODE."
)
for sosus_line in location.related_sosus:
if sosus_line not in [
sosus_line.name
for sosus_line in current_campaign.campaign_data.sosus_lines
]:
report.errors.append(
f"ERROR: Location ID {location.location_id} has related SOSUS "
f"line {sosus_line} which is not a valid SOSUS line."
)
return report