]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
At the expense of the developer's sanity, get the save system working with arrays...
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 28 Oct 2011 23:09:41 +0000 (02:09 +0300)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Fri, 28 Oct 2011 23:09:41 +0000 (02:09 +0300)
defaultXonotic.cfg
qcsrc/server/mutators/sandbox.qc

index 74d2afe7d3ddc239235b790232404947c6daaaf3..f7b33003cc55c6f064f43fd062feb84eb9b0eb6f 100644 (file)
@@ -547,7 +547,7 @@ seta g_balance_cloaked_alpha 0.25
 set g_sandbox 0 "allow players to spawn and edit objects around the map"
 set g_sandbox_info 1 "print object information to the server. 1 prints info about spawned / removed objects, 2 also prints info about edited objects"
 set g_sandbox_storage_name default "name of the selected storage to use"
-set g_sandbox_storage_autosave 10 "storage is automatically saved every specified number of seconds"
+set g_sandbox_storage_autosave 5 "storage is automatically saved every specified number of seconds"
 set g_sandbox_storage_autoload 1 "if a storage file exists for the given map, automatically load it at startup"
 set g_sandbox_editor_maxobjects 1000 "maximum number of objects that may exist at a time"
 set g_sandbox_editor_free 0 "when enabled, players can edit any object on the map, not just the objects they've spawned"
index cfa7ce960e31bf9b8e0d6ad40503667d29abb070..a53a6fca73ea0d9f6a36be1ed365a59fa8647cbb 100644 (file)
@@ -1,3 +1,4 @@
+const float MAX_STORAGE_ATTACHMENTS = 16;
 float object_count;
 .string object_clipboard;
 .entity object_attach;
@@ -150,40 +151,52 @@ void sandbox_ObjectRemove(entity e)
        object_count -= 1;
 }
 
-string sandbox_ObjectPort_Save_string(entity e, float database)
-{
-       string s;
-       s = strcat(s, e.model, " ");
-       s = strcat(s, ftos(e.skin), " ");
-       s = strcat(s, ftos(e.alpha), " ");
-       s = strcat(s, sprintf("\"%.9v\"", e.colormod), " ");
-       s = strcat(s, sprintf("\"%.9v\"", e.glowmod), " ");
-       s = strcat(s, ftos(e.frame), " ");
-       s = strcat(s, ftos(e.scale), " ");
-       s = strcat(s, ftos(e.movetype), " ");
-       s = strcat(s, ftos(e.damageforcescale), " ");
-       if(e.material)  s = strcat(s, e.material, " "); else    s = strcat(s, "- "); // none
-       if(database)
-       {
-               if(e.crypto_idfp)       s = strcat(s, e.crypto_idfp, " ");      else    s = strcat(s, "- "); // none
-               s = strcat(s, sprintf("\"%.9v\"", e.origin), " ");
-               s = strcat(s, sprintf("\"%.9v\"", e.angles), " ");
-       }
-       s = strcat(s, "; ");
-       return s;
-}
+string save_string[MAX_STORAGE_ATTACHMENTS]; // fteqcc crashes if this isn't defined as a global
 string sandbox_ObjectPort_Save(entity e, float database)
 {
        // save object properties
+       float i;
        string s;
        entity head;
 
-       // first set the properties of the main object, then those of each child
-       s = sandbox_ObjectPort_Save_string(e, database);
        for(head = world; (head = find(head, classname, "object")); )
        {
-               if(head.owner == e)
-                       s = strcat(s, sandbox_ObjectPort_Save_string(head, database));
+               // the main object needs to be saved first in the array, with attached objects following after
+               float tmp;
+               if(head == e)
+                       tmp = 0;
+               else if(head.owner == e)
+               {
+                       i += 1; // child objects start from 1
+                       tmp = i;
+               }
+               else
+                       continue;
+
+               save_string[tmp] = strcat(save_string[tmp], head.model, " ");
+               save_string[tmp] = strcat(save_string[tmp], ftos(head.skin), " ");
+               save_string[tmp] = strcat(save_string[tmp], ftos(head.alpha), " ");
+               save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.colormod), " ");
+               save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.glowmod), " ");
+               save_string[tmp] = strcat(save_string[tmp], ftos(head.frame), " ");
+               save_string[tmp] = strcat(save_string[tmp], ftos(head.scale), " ");
+               save_string[tmp] = strcat(save_string[tmp], ftos(head.movetype), " ");
+               save_string[tmp] = strcat(save_string[tmp], ftos(head.damageforcescale), " ");
+               if(head.material)       save_string[tmp] = strcat(save_string[tmp], head.material, " ");        else    save_string[tmp] = strcat(save_string[tmp], "- "); // none
+               if(database)
+               {
+                       if(head.crypto_idfp)    save_string[tmp] = strcat(save_string[tmp], head.crypto_idfp, " ");     else    save_string[tmp] = strcat(save_string[tmp], "- "); // none
+                       save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.origin), " ");
+                       save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.angles), " ");
+               }
+       }
+
+       // now apply the array to a simple string, with ; separating objects
+       for(i = 0; i <= MAX_STORAGE_ATTACHMENTS; ++i)
+       {
+               if(save_string[i])
+                       s = strcat(s, save_string[i], "; ");
+               save_string[i] = string_null; // fully clear the string
        }
 
        return s;
@@ -622,7 +635,7 @@ MUTATOR_HOOKFUNCTION(sandbox_StartFrame)
 {
        if(!autocvar_g_sandbox_storage_autosave)
                return FALSE;
-       if(time < autocvar_g_sandbox_storage_autosave)
+       if(time < autosave_time)
                return FALSE;
        autosave_time = time + autocvar_g_sandbox_storage_autosave;