File: aistate_interface.py

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (39 lines) | stat: -rw-r--r-- 860 bytes parent folder | download
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
"""
This module provides an interface for a quasi-singleton AIstate instance.

The AIstate must be initialized after module imports using either
   * create_new_aistate
   * load_aistate
This should happen only once per session and be triggered by the game client.

Access to the AIstate is provided via get_aistate().

Example usage:
    from aistate_interface import get_aistate()
    get_aistate().get_all_fleet_missions()

"""
_aistate = None


def create_new_aistate(*args, **kwargs):
    import AIstate

    global _aistate
    _aistate = AIstate.AIstate(*args, **kwargs)
    return _aistate


def load_aistate(savegame_string: str):
    import savegame_codec

    global _aistate
    _aistate = savegame_codec.load_savegame_string(savegame_string)
    return _aistate


def get_aistate():
    """
    :rtype: AIstate.AIstate
    """
    return _aistate