From cc0e29d7a28b1314c6062c6425b20ba9a2bffac8 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 22 Aug 2015 20:43:04 +0000 Subject: [PATCH] Blank out non-robot AI on save --- similar/main/ai.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index 76d8e7f6c..0f209f514 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -4368,7 +4368,7 @@ void init_robots_for_level(void) } // Following functions convert ai_local/ai_cloak_info to ai_local/ai_cloak_info_rw to be written to/read from Savegames. Convertin back is not done here - reading is done specifically together with swapping (if necessary). These structs differ in terms of timer values (fix/fix64). as we reset GameTime64 for writing so it can fit into fix it's not necessary to increment savegame version. But if we once store something else into object which might be useful after restoring, it might be handy to increment Savegame version and actually store these new infos. -static void state_ai_local_to_ai_local_rw(ai_local *ail, ai_local_rw *ail_rw) +static void state_ai_local_to_ai_local_rw(const ai_local *ail, ai_local_rw *ail_rw) { int i = 0; @@ -4433,6 +4433,16 @@ ASSERT_SERIAL_UDT_MESSAGE_SIZE(point_seg, 16); DEFINE_SERIAL_MUTABLE_UDT_TO_MESSAGE(point_seg_array_t, p, (static_cast &>(p))); DEFINE_SERIAL_CONST_UDT_TO_MESSAGE(point_seg_array_t, p, (static_cast &>(p))); +static void ai_save_one_ai_local(PHYSFS_File *fp, const object &i) +{ + ai_local_rw ail_rw; + if (i.type == OBJ_ROBOT) + state_ai_local_to_ai_local_rw(&i.ctype.ai_info.ail, &ail_rw); + else + ail_rw = {}; + PHYSFS_write(fp, &ail_rw, sizeof(ail_rw), 1); +} + int ai_save_state(PHYSFS_file *fp) { fix tmptime32 = 0; @@ -4440,12 +4450,7 @@ int ai_save_state(PHYSFS_file *fp) PHYSFS_write(fp, &Ai_initialized, sizeof(int), 1); PHYSFS_write(fp, &Overall_agitation, sizeof(int), 1); range_for (auto &i, Objects) - { - ai_local_rw ail_rw; - ai_local *ailp = &i.ctype.ai_info.ail; - state_ai_local_to_ai_local_rw(ailp, &ail_rw); - PHYSFS_write(fp, &ail_rw, sizeof(ail_rw), 1); - } + ai_save_one_ai_local(fp, i); PHYSFSX_serialize_write(fp, Point_segs); //PHYSFS_write(fp, Ai_cloak_info, sizeof(ai_cloak_info) * MAX_AI_CLOAK_INFO, 1); range_for (auto &i, Ai_cloak_info)