Ground war rework

This commit is contained in:
Khopa
2020-05-24 20:32:45 +02:00
parent 5884d9d120
commit f57e453d8d
74 changed files with 1255 additions and 1965 deletions

View File

View File

@@ -1,10 +0,0 @@
from tests.integration import baseattack, convoystrike, frontlineattack, insurgentattack, intercept, navalintercept, strike
if __name__ == "__main__":
baseattack.execute_all()
convoystrike.execute_all()
frontlineattack.execute_all()
insurgentattack.execute_all()
intercept.execute_all()
navalintercept.execute_all()
strike.execute_all()

View File

@@ -1,46 +0,0 @@
from theater.caucasus import CaucasusTheater
from theater.nevada import NevadaTheater
from tests.integration.util import *
PLAYER_COUNTRY = "USA"
ENEMY_COUNTRY = "Russia"
def execute(game, player_cp, enemy_cp, departure_cp = None):
e = BaseAttackEvent(game, player_cp, enemy_cp, enemy_cp.position, PLAYER_COUNTRY, ENEMY_COUNTRY)
departures = [departure_cp] if departure_cp else game.theater.player_points()
for departure_cp in departures:
if e.is_departure_available_from(departure_cp):
print("{} for {} ({}) - {}".format(e, player_cp, departure_cp, enemy_cp))
e.departure_cp = departure_cp
e.player_attacking(autoflights_for(e, PLAYER_COUNTRY))
e.generate()
execute_autocommit(e)
e.generate_quick()
execute_autocommit(e)
def execute_theater(theater_klass):
print("Theater: {}".format(theater_klass))
game, theater = init(PLAYER_COUNTRY, ENEMY_COUNTRY, theater_klass)
total_events = 0
while len(theater.enemy_points()) > 0:
for player_cp, enemy_cp in theater.conflicts():
execute(game, player_cp, enemy_cp)
enemy_cp.captured = True
print("Total: {}".format(total_events))
def execute_all():
for theater_klass in [CaucasusTheater, PersianGulfTheater, NevadaTheater]:
execute_theater(theater_klass)
if __name__ == "__main__":
execute_all()

View File

@@ -1,50 +0,0 @@
from theater.caucasus import CaucasusTheater
from theater.nevada import NevadaTheater
from tests.integration.util import *
PLAYER_COUNTRY = "USA"
ENEMY_COUNTRY = "Russia"
def execute(game, player_cp, enemy_cp, departure_cp = None):
e = ConvoyStrikeEvent(game, player_cp, enemy_cp, enemy_cp.position, PLAYER_COUNTRY, ENEMY_COUNTRY)
departures = [departure_cp] if departure_cp else game.theater.player_points()
for departure_cp in departures:
if e.is_departure_available_from(departure_cp):
enemy_cp.base.strength = 1
for _ in range(10):
print("{} for {} ({}) - {} ({})".format(e, player_cp, departure_cp, enemy_cp, enemy_cp.base.strength))
e.departure_cp = departure_cp
e.player_attacking(autoflights_for(e, PLAYER_COUNTRY))
e.generate()
execute_autocommit(e)
e.generate_quick()
execute_autocommit(e)
enemy_cp.base.affect_strength(-0.1)
def execute_theater(theater_klass):
print("Theater: {}".format(theater_klass))
game, theater = init(PLAYER_COUNTRY, ENEMY_COUNTRY, theater_klass)
total_events = 0
while len(theater.enemy_points()) > 0:
for player_cp, enemy_cp in theater.conflicts():
execute(game, player_cp, enemy_cp)
enemy_cp.captured = True
print("Total: {}".format(total_events))
def execute_all():
for theater_klass in [CaucasusTheater, PersianGulfTheater, NevadaTheater]:
execute_theater(theater_klass)
if __name__ == "__main__":
execute_all()

View File

@@ -1,52 +0,0 @@
from theater.caucasus import CaucasusTheater
from theater.nevada import NevadaTheater
from game.event.frontlineattack import FrontlineAttackEvent
from tests.integration.util import *
PLAYER_COUNTRY = "USA"
ENEMY_COUNTRY = "Russia"
def execute(game, player_cp, enemy_cp, departure_cp = None):
e = FrontlineAttackEvent(game, player_cp, enemy_cp, enemy_cp.position, PLAYER_COUNTRY, ENEMY_COUNTRY)
departures = [departure_cp] if departure_cp else game.theater.player_points()
for departure_cp in departures:
if e.is_departure_available_from(departure_cp):
enemy_cp.base.strength = 1
for _ in range(10):
print("{} for {} ({}) - {} ({})".format(e, player_cp, departure_cp, enemy_cp, enemy_cp.base.strength))
e.departure_cp = departure_cp
e.player_attacking(autoflights_for(e, PLAYER_COUNTRY))
e.generate()
execute_autocommit(e)
e.generate_quick()
execute_autocommit(e)
enemy_cp.base.affect_strength(-0.1)
def execute_theater(theater_klass):
print("Theater: {}".format(theater_klass))
game, theater = init(PLAYER_COUNTRY, ENEMY_COUNTRY, theater_klass)
total_events = 0
while len(theater.enemy_points()) > 0:
for player_cp, enemy_cp in theater.conflicts():
execute(game, player_cp, enemy_cp)
enemy_cp.captured = True
print("Total: {}".format(total_events))
def execute_all():
for theater_klass in [CaucasusTheater, PersianGulfTheater, NevadaTheater]:
execute_theater(theater_klass)
if __name__ == "__main__":
execute_all()

View File

@@ -1,48 +0,0 @@
from theater.caucasus import CaucasusTheater
from theater.nevada import NevadaTheater
from game.event.insurgentattack import InsurgentAttackEvent
from tests.integration.util import *
PLAYER_COUNTRY = "USA"
ENEMY_COUNTRY = "Russia"
def execute(game, player_cp, enemy_cp, departure_cp = None):
e = InsurgentAttackEvent(game, enemy_cp, player_cp, player_cp.position, ENEMY_COUNTRY, PLAYER_COUNTRY)
departures = [departure_cp] if departure_cp else game.theater.player_points()
for departure_cp in departures:
if e.is_departure_available_from(departure_cp):
print("{} for {} ({}) - {} ({})".format(e, player_cp, departure_cp, enemy_cp, enemy_cp.base.strength))
e.departure_cp = departure_cp
e.player_defending(autoflights_for(e, PLAYER_COUNTRY))
e.generate()
execute_autocommit(e)
e.generate_quick()
execute_autocommit(e)
def execute_theater(theater_klass):
print("Theater: {}".format(theater_klass))
game, theater = init(PLAYER_COUNTRY, ENEMY_COUNTRY, theater_klass)
total_events = 0
while len(theater.enemy_points()) > 0:
for player_cp, enemy_cp in theater.conflicts():
execute(game, player_cp, enemy_cp)
enemy_cp.captured = True
print("Total: {}".format(total_events))
def execute_all():
for theater_klass in [CaucasusTheater, PersianGulfTheater, NevadaTheater]:
execute_theater(theater_klass)
if __name__ == "__main__":
execute_all()

View File

@@ -1,48 +0,0 @@
from theater.caucasus import CaucasusTheater
from theater.nevada import NevadaTheater
from game.event.intercept import InterceptEvent
from tests.integration.util import *
PLAYER_COUNTRY = "USA"
ENEMY_COUNTRY = "Russia"
def execute(game, player_cp, enemy_cp, departure_cp = None):
e = InterceptEvent(game, player_cp, enemy_cp, enemy_cp.position, PLAYER_COUNTRY, ENEMY_COUNTRY)
departures = [departure_cp] if departure_cp else game.theater.player_points()
for departure_cp in departures:
if e.is_departure_available_from(departure_cp):
print("{} for {} ({}) - {} ({})".format(e, player_cp, departure_cp, enemy_cp, enemy_cp.base.strength))
e.departure_cp = departure_cp
e.player_attacking(autoflights_for(e, PLAYER_COUNTRY))
e.generate()
execute_autocommit(e)
e.generate_quick()
execute_autocommit(e)
def execute_theater(theater_klass):
print("Theater: {}".format(theater_klass))
game, theater = init(PLAYER_COUNTRY, ENEMY_COUNTRY, theater_klass)
total_events = 0
while len(theater.enemy_points()) > 0:
for player_cp, enemy_cp in theater.conflicts():
execute(game, player_cp, enemy_cp)
enemy_cp.captured = True
print("Total: {}".format(total_events))
def execute_all():
for theater_klass in [CaucasusTheater, PersianGulfTheater, NevadaTheater]:
execute_theater(theater_klass)
if __name__ == "__main__":
execute_all()

View File

@@ -1,49 +0,0 @@
from theater.caucasus import CaucasusTheater
from theater.nevada import NevadaTheater
from game.event.intercept import InterceptEvent
from tests.integration.util import *
PLAYER_COUNTRY = "USA"
ENEMY_COUNTRY = "Russia"
def execute(game, player_cp, enemy_cp, departure_cp = None):
e = NavalInterceptEvent(game, player_cp, enemy_cp, enemy_cp.position, PLAYER_COUNTRY, ENEMY_COUNTRY)
departures = [departure_cp] if departure_cp else game.theater.player_points()
for departure_cp in departures:
if e.is_departure_available_from(departure_cp):
print("{} for {} ({}) - {} ({})".format(e, player_cp, departure_cp, enemy_cp, enemy_cp.base.strength))
e.departure_cp = departure_cp
e.player_attacking(autoflights_for(e, PLAYER_COUNTRY))
e.generate()
execute_autocommit(e)
e.generate_quick()
execute_autocommit(e)
def execute_theater(theater_klass):
print("Theater: {}".format(theater_klass))
game, theater = init(PLAYER_COUNTRY, ENEMY_COUNTRY, theater_klass)
total_events = 0
while len(theater.enemy_points()) > 0:
for player_cp, enemy_cp in theater.conflicts():
if enemy_cp.radials != LAND:
execute(game, player_cp, enemy_cp)
enemy_cp.captured = True
print("Total: {}".format(total_events))
def execute_all():
for theater_klass in [CaucasusTheater, PersianGulfTheater, NevadaTheater]:
execute_theater(theater_klass)
if __name__ == "__main__":
execute_all()

View File

@@ -1,48 +0,0 @@
from theater.caucasus import CaucasusTheater
from theater.nevada import NevadaTheater
from game.event.intercept import InterceptEvent
from tests.integration.util import *
PLAYER_COUNTRY = "USA"
ENEMY_COUNTRY = "Russia"
def execute(game, player_cp, enemy_cp, departure_cp = None):
e = StrikeEvent(game, player_cp, enemy_cp, enemy_cp.position, PLAYER_COUNTRY, ENEMY_COUNTRY)
departures = [departure_cp] if departure_cp else game.theater.player_points()
for departure_cp in departures:
if e.is_departure_available_from(departure_cp):
print("{} for {} ({}) - {} ({})".format(e, player_cp, departure_cp, enemy_cp, enemy_cp.base.strength))
e.departure_cp = departure_cp
e.player_attacking(autoflights_for(e, PLAYER_COUNTRY))
e.generate()
execute_autocommit(e)
e.generate_quick()
execute_autocommit(e)
def execute_theater(theater_klass):
print("Theater: {}".format(theater_klass))
game, theater = init(PLAYER_COUNTRY, ENEMY_COUNTRY, theater_klass)
total_events = 0
while len(theater.enemy_points()) > 0:
for player_cp, enemy_cp in theater.conflicts():
execute(game, player_cp, enemy_cp)
enemy_cp.captured = True
print("Total: {}".format(total_events))
def execute_all():
for theater_klass in [CaucasusTheater, PersianGulfTheater, NevadaTheater]:
execute_theater(theater_klass)
if __name__ == "__main__":
execute_all()

View File

@@ -1,81 +0,0 @@
from dcs.mission import Mission
from game import *
from game.event import *
from game.db import *
from theater.persiangulf import *
from theater import start_generator
PLAYER_COUNTRY = None
ENEMY_COUNTRY = None
def init(player_country: str, enemy_country: str, theater_klass: typing.Type[ConflictTheater]) -> typing.Tuple[Game, ConflictTheater]:
global PLAYER_COUNTRY
global ENEMY_COUNTRY
PLAYER_COUNTRY = player_country
ENEMY_COUNTRY = enemy_country
# prerequisites
persistency.setup("./tests/userfolder/")
theater = theater_klass()
start_generator.generate_inital_units(theater, ENEMY_COUNTRY, True, 1)
game = Game(PLAYER_COUNTRY, ENEMY_COUNTRY, theater)
start_generator.generate_groundobjects(theater, game)
return game, theater
def autoflights_for(event: Event, country: str) -> TaskForceDict:
result = {}
for task in event.tasks:
result[task] = {find_unittype(task, country)[0]: (1, 1)}
return result
class AutodebriefType(Enum):
EVERYONE_DEAD = 0
PLAYER_DEAD = 1
ENEMY_DEAD = 2
def autodebrief_for(event: Event, type: AutodebriefType) -> Debriefing:
mission = event.operation.current_mission # type: Mission
countries = []
if type == AutodebriefType.PLAYER_DEAD or type == AutodebriefType.EVERYONE_DEAD:
countries.append(mission.country(PLAYER_COUNTRY))
if type == AutodebriefType.ENEMY_DEAD or type == AutodebriefType.EVERYONE_DEAD:
countries.append(mission.country(ENEMY_COUNTRY))
dead_units = []
for country in countries:
for group in country.plane_group + country.vehicle_group + country.helicopter_group:
for unit in group.units:
dead_units.append(str(unit.name))
return Debriefing(dead_units, [], [])
def event_state_save(e: Event) -> typing.Tuple[Base, Base]:
return (copy.deepcopy(e.from_cp.base), copy.deepcopy(e.to_cp.base))
def event_state_restore(e: Event, state: typing.Tuple[Base, Base]):
e.from_cp.base, e.to_cp.base = state[0], state[1]
def execute_autocommit(e: Event):
state = event_state_save(e)
e.commit(autodebrief_for(e, AutodebriefType.EVERYONE_DEAD))
event_state_restore(e, state)
state = event_state_save(e)
e.commit(autodebrief_for(e, AutodebriefType.PLAYER_DEAD))
event_state_restore(e, state)
state = event_state_save(e)
e.commit(autodebrief_for(e, AutodebriefType.ENEMY_DEAD))
event_state_restore(e, state)