Fold AI savegame logic into game_io
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
widelands |
Fix Released
|
Low
|
TiborB |
Bug Description
Tibor and myself have been thinking about how the AI can serialize data into savegames correctly. This bug should figure out the design in a discussion and track it's implementation.
Let's start by hashing out the requirements. There are the following scenarios I can think about?
- Game starts with AI, saved and is restarted with AI.
This is the simplest - the AI can just reload its state from the saved game and continue as if there was no interruption.
- Game starts without AI, saved and is restarted with a human player replaced with AI.
This is lazy initialization and it can happen in any situation. But if the AI can handle this properly, why does it even need to save any state?
- Game starts with AI, saved. On load a human player plays the AI, but this player eventually drops. What happens now?
Question:
- did I forget a scenario?
- what is the AI actually saving right now?
- why can this not be recalculated like on lazy initialization.
Related branches
- SirVer: Approve
- TiborB: Needs Resubmitting
-
Diff: 1852 lines (+739/-281)26 files modifiedsrc/ai/ai_help_structs.h (+10/-2)
src/ai/defaultai.cc (+222/-178)
src/ai/defaultai.h (+7/-14)
src/game_io/CMakeLists.txt (+2/-0)
src/game_io/game_data_packet.h (+2/-1)
src/game_io/game_loader.cc (+5/-0)
src/game_io/game_player_ai_persistent_packet.cc (+104/-0)
src/game_io/game_player_ai_persistent_packet.h (+37/-0)
src/game_io/game_player_info_packet.cc (+3/-11)
src/game_io/game_saver.cc (+5/-0)
src/logic/map_objects/tribes/ship.cc (+28/-2)
src/logic/map_objects/tribes/ship.h (+6/-0)
src/logic/map_objects/tribes/tribe_descr.cc (+2/-0)
src/logic/map_objects/tribes/tribe_descr.h (+3/-0)
src/logic/player.cc (+41/-49)
src/logic/player.h (+32/-19)
src/map_io/map_allowed_building_types_packet.cc (+1/-0)
src/scripting/lua_map.cc (+17/-0)
src/scripting/lua_map.h (+1/-0)
src/wui/shipwindow.cc (+5/-4)
test/maps/ship_transportation.wmf/scripting/test_many_ships.lua (+37/-0)
tribes/atlanteans.lua (+61/-0)
tribes/barbarians.lua (+37/-0)
tribes/buildings/trainingsites/atlanteans/labyrinth/init.lua (+1/-1)
tribes/buildings/trainingsites/empire/colosseum/init.lua (+1/-0)
tribes/empire.lua (+69/-0)
Changed in widelands: | |
status: | New → Incomplete |
milestone: | none → build19-rc1 |
Changed in widelands: | |
status: | Fix Committed → Fix Released |
So input from me is expected here:)
The purpose of saving ai data is to provide some continuance after game is quited and reloaded. Most common scenario is AI|AI|AI|AI - player plays one map over multiple sessions.
AI generates huge amount of data (observers, info on buildable flags, data related to attacking), but saves only handful of them.
Currently AI has reserved:
8 x uint16_t
8 x uint32_t
8 x int32_t
This is saved as a part of player object - the space is allocated regardless of who is playing the position right now.
AI can from this data say if they are "uninitialized" (all zeros) or already contains some data.
Human player does not touch that data. And these data can "survive" if a human player plays after AI player.
Data IA stores are divided into two groups
1.) a parameters, that are generated once and are intended to give some "personality" to AI. AI is using many parameters and many of them have no "right" value, but allow range of values.
Examples: military_ loneliness_ attack_ margin_ wood_difference _ tes_ratio_ early_militarys ites
ai_personality_
ai_personality_
ai_personality_
ai_productionsi
ai_personality_
2.) Run-time variables - that are changed during the game like: player_ start_time_ score_ military_ score_ expeditions_
colony_scan_area_
last_attacked_
expedition_
ships_utilization_
least_military_
target_
no_more_
All remaining data of AI are regenerated after each initialization...
OK, scenarios
Generally no problems with scenarios like:
Human|AI
AI|Human
AI|AI|AI
Human|Human|Human
what can be small problem (but not significant) is scenario: expeditions_ =true).
AI|Human|AI
Because some "run-time" data will not be actual. AI has no idea, that a player used to play on that slot. Worst thing could be that AI will be tricked that expedition lasts too long and decide that there are no more opportunities to create a colonisation port and gave up. (But it is not able to cancel expedition, it would only set no_more_
All other runtime variables - if not actual - are completely harmless
Questions? :)