Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Goto MAI: Ensure that persistent data always are in WML table format

This also means that keys cannot contain certain symbols and, as a
result, potentially user-provided strings need to be stored in the
values, not keys.  This fixes bug #20924 about the Goto MAI corrupting
saves.
  • Loading branch information...
commit b83e68711cb72f318d4e78699c25dd77fc709f39 1 parent f25223b
mattsc authored June 22, 2013

Showing 1 changed file with 18 additions and 15 deletions. Show diff stats Hide diff stats

  1. 33  data/ai/micro_ais/ais/mai_goto_engine.lua
33  data/ai/micro_ais/ais/mai_goto_engine.lua
@@ -13,9 +13,10 @@ return {
13 13
             -- whether the goal has already been reached, in
14 14
             -- which case we do not do anything
15 15
             if cfg.release_all_units_at_goal then
16  
-                local str = cfg.ca_id .. '-release-all'
17  
-                if self.data[str] then
18  
-                    return 0
  16
+                for rel in H.child_range(self.data, "goto_release_all") do
  17
+                    if (rel.id == cfg.ca_id) then
  18
+                        return 0
  19
+                    end
19 20
                 end
20 21
             end
21 22
 
@@ -33,11 +34,11 @@ return {
33 34
             -- If 'unique_goals' is set, check whether there are locations left to go to
34 35
             if cfg.unique_goals then
35 36
                 -- First, some cleanup of previous turn data
36  
-                local str = 'goals_taken-' .. (wesnoth.current.turn - 1)
  37
+                local str = 'goals_taken_' .. (wesnoth.current.turn - 1)
37 38
                 self.data[str] = nil
38 39
 
39 40
                 -- Now on to the current turn
40  
-                local str = 'goals_taken-' .. wesnoth.current.turn
  41
+                local str = 'goals_taken_' .. wesnoth.current.turn
41 42
                 for i = #locs,1,-1 do
42 43
                     if self.data[str] and self.data[str]:get(locs[i][1], locs[i][2]) then
43 44
                         table.remove(locs, i)
@@ -54,10 +55,12 @@ return {
54 55
 
55 56
             -- Exclude released units
56 57
             if cfg.release_unit_at_goal then
57  
-                for i=#units,1,-1 do
58  
-                    local str = cfg.ca_id .. '-release-' .. units[i].id
59  
-                    if self.data[str] then
60  
-                        table.remove(units, i)
  58
+                for i_unit=#units,1,-1 do
  59
+                    for rel in H.child_range(self.data, "goto_release_unit") do
  60
+                        if (rel.id == cfg.ca_id .. '_' .. units[i_unit].id) then
  61
+                           table.remove(units, i_unit)
  62
+                           break
  63
+                        end
61 64
                     end
62 65
                 end
63 66
             end
@@ -119,7 +122,7 @@ return {
119 122
 
120 123
             -- If 'unique_goals' is set, mark this location as being taken
121 124
             if cfg.unique_goals then
122  
-                local str = 'goals_taken-' .. wesnoth.current.turn
  125
+                local str = 'goals_taken_' .. wesnoth.current.turn
123 126
                 if (not self.data[str]) then self.data[str] = LS.create() end
124 127
                 self.data[str]:insert(closest_hex[1], closest_hex[2])
125 128
             end
@@ -138,17 +141,17 @@ return {
138 141
                 end
139 142
 
140 143
                 -- If a unit was found, mark either it or all units as released
  144
+                -- Needs to be stored persistently in self.data meaning:
  145
+                -- 1. Needs to be in WML table format
  146
+                -- 2. Keys cannot contain certain characters -> everything potentially user-defined needs to be in values
141 147
                 if unit_at_goal then
142 148
                     if cfg.release_unit_at_goal then
143  
-                        local str = cfg.ca_id .. '-release-' .. best_unit.id
144  
-                        --print("Made it to goal: ", best_unit.id, str)
145  
-                        self.data[str] = true
  149
+                        table.insert(self.data, { "goto_release_unit" , { id = cfg.ca_id .. '_' .. best_unit.id } } )
146 150
                     end
147 151
 
148 152
                     if cfg.release_all_units_at_goal then
149  
-                        local str = cfg.ca_id .. '-release-all'
150 153
                         --print("Releasing all units")
151  
-                        self.data[str] = true
  154
+                        table.insert(self.data, { "goto_release_all", { id = cfg.ca_id } } )
152 155
                     end
153 156
                 end
154 157
             end

0 notes on commit b83e687

Please sign in to comment.
Something went wrong with that request. Please try again.