From f94a56f032d102ea192178664ea08a8caf8f26b6 Mon Sep 17 00:00:00 2001 From: Mircea Kitsune Date: Sat, 29 Oct 2011 19:08:19 +0300 Subject: [PATCH] Re-implement remembering of old movetype for objects, and also persist it in storage. For example: If you set an object to MOVETYPE_PHYSICAL, attach it to another object (during which it becomes MOVETYPE_FOLLOW), restart the server, then go back and detach the object, it will know to go back to MOVETYPE_PHYSICAL. This does not add any extra info, as movetype was already added to the storage for child objects, and was useless before this. --- qcsrc/server/mutators/sandbox.qc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc index f3185d789..e76f74020 100644 --- a/qcsrc/server/mutators/sandbox.qc +++ b/qcsrc/server/mutators/sandbox.qc @@ -60,6 +60,7 @@ void sandbox_ObjectEdit_Scale(entity e, float f) } } +.float old_movetype; void sandbox_ObjectAttach_Remove(entity e); void sandbox_ObjectAttach_Set(entity e, entity parent, string s) { @@ -68,6 +69,7 @@ void sandbox_ObjectAttach_Set(entity e, entity parent, string s) // we can't attach to an attachment, for obvious reasons sandbox_ObjectAttach_Remove(e); + e.old_movetype = e.movetype; // persist physics e.movetype = MOVETYPE_FOLLOW; e.solid = SOLID_NOT; e.takedamage = DAMAGE_NO; @@ -86,7 +88,7 @@ void sandbox_ObjectAttach_Remove(entity e) if(head.owner == e) { vector org; - head.movetype = MOVETYPE_TOSS; // default + head.movetype = head.old_movetype; // restore persisted physics head.solid = SOLID_BBOX; head.takedamage = DAMAGE_AIM; @@ -168,21 +170,22 @@ string sandbox_ObjectPort_Save(entity e, float database) for(head = world; (head = find(head, classname, "object")); ) { // the main object needs to be first in the array [0] with attached objects following - float slot; - string tagindex; + float slot, physics; + string tagname; if(head == e) // this is the main object, place it first { slot = 0; - tagindex = string_null; // the main object is not attached to anything + physics = head.movetype; // applied physics are normal physics for parents } else if(head.owner == e) // child object, list them in order { i += 1; // children start from 1 slot = i; + physics = head.old_movetype; // persisted physics are normal physics for children // get the name of the tag our object is attached to gettaginfo(head.owner, head.tag_index); - tagindex = gettaginfo_name; + tagname = gettaginfo_name; } else continue; @@ -191,7 +194,7 @@ string sandbox_ObjectPort_Save(entity e, float database) if(slot) { // properties stored only for child objects - if(tagindex) port_string[slot] = strcat(port_string[slot], "\"", tagindex, "\" "); else port_string[slot] = strcat(port_string[slot], "- "); // none + if(tagname) port_string[slot] = strcat(port_string[slot], "\"", tagname, "\" "); else port_string[slot] = strcat(port_string[slot], "- "); // none } else { @@ -210,7 +213,7 @@ string sandbox_ObjectPort_Save(entity e, float database) port_string[slot] = strcat(port_string[slot], sprintf("\"%.9v\"", head.glowmod), " "); port_string[slot] = strcat(port_string[slot], ftos(head.frame), " "); port_string[slot] = strcat(port_string[slot], ftos(head.scale), " "); - port_string[slot] = strcat(port_string[slot], ftos(head.movetype), " "); + port_string[slot] = strcat(port_string[slot], ftos(physics), " "); port_string[slot] = strcat(port_string[slot], ftos(head.damageforcescale), " "); if(head.material) port_string[slot] = strcat(port_string[slot], "\"", head.material, "\" "); else port_string[slot] = strcat(port_string[slot], "- "); // none if(database) @@ -246,6 +249,7 @@ entity sandbox_ObjectPort_Load(string s, float database) for(i = 0; i < n; ++i) { float argv_num; + string tagname; argv_num = 0; tokenize_console(port_string[i]); e = sandbox_ObjectSpawn(database); @@ -254,7 +258,7 @@ entity sandbox_ObjectPort_Load(string s, float database) if(i) { // properties stored only for child objects - if(argv(argv_num) != "-") sandbox_ObjectAttach_Set(e, parent, argv(argv_num)); else sandbox_ObjectAttach_Set(e, parent, ""); ++argv_num; + if(argv(argv_num) != "-") tagname = argv(argv_num); else tagname = string_null; ++argv_num; } else { @@ -274,7 +278,7 @@ entity sandbox_ObjectPort_Load(string s, float database) e.glowmod = stov(argv(argv_num)); ++argv_num; e.frame = stof(argv(argv_num)); ++argv_num; sandbox_ObjectEdit_Scale(e, stof(argv(argv_num))); ++argv_num; - e.movetype = stof(argv(argv_num)); ++argv_num; + e.movetype = e.old_movetype = stof(argv(argv_num)); ++argv_num; e.damageforcescale = stof(argv(argv_num)); ++argv_num; if(e.material) strunzone(e.material); if(argv(argv_num) != "-") e.material = strzone(argv(argv_num)); else e.material = string_null; ++argv_num; if(database) @@ -282,6 +286,9 @@ entity sandbox_ObjectPort_Load(string s, float database) // properties stored only for the database if(e.crypto_idfp) strunzone(e.crypto_idfp); if(argv(argv_num) != "-") e.crypto_idfp = strzone(argv(argv_num)); else e.crypto_idfp = string_null; ++argv_num; } + + // attach last + sandbox_ObjectAttach_Set(e, parent, tagname); } for(i = 0; i <= MAX_STORAGE_ATTACHMENTS; ++i) -- 2.39.2