NSEntity: Save/Restore behaviour for some more fields.

This commit is contained in:
Marco Cawthorne 2021-10-22 21:20:22 +02:00
parent fa5cdd5a80
commit 4c2b37c34d
Signed by: eukara
GPG key ID: C196CD8BA993248A
2 changed files with 40 additions and 14 deletions

View file

@ -352,8 +352,14 @@ void
NSEntity::Save(float handle) NSEntity::Save(float handle)
{ {
SaveVector(handle, "origin", origin); SaveVector(handle, "origin", origin);
SaveVector(handle, "absmin", absmin);
SaveVector(handle, "absmax", absmax);
SaveVector(handle, "mins", mins);
SaveVector(handle, "maxs", mins);
SaveString(handle, "model", model); SaveString(handle, "model", model);
SaveVector(handle, "angles", angles); SaveVector(handle, "angles", angles);
SaveFloat(handle, "solid", solid);
SaveFloat(handle, "movetype", movetype);
SaveString(handle, "targetname", targetname); SaveString(handle, "targetname", targetname);
SaveString(handle, "target", target); SaveString(handle, "target", target);
SaveFloat(handle, "health", health); SaveFloat(handle, "health", health);
@ -368,6 +374,18 @@ NSEntity::Restore(string strKey, string strValue)
case "origin": case "origin":
origin = stov(strValue); origin = stov(strValue);
break; break;
case "absmin":
absmin = stov(strValue);
break;
case "absmax":
absmax = stov(strValue);
break;
case "mins":
mins = stov(strValue);
break;
case "maxs":
maxs = stov(strValue);
break;
case "model": case "model":
model = strValue; model = strValue;
break; break;
@ -377,6 +395,9 @@ NSEntity::Restore(string strKey, string strValue)
case "solid": case "solid":
solid = stof(strValue); solid = stof(strValue);
break; break;
case "movetype":
movetype = stof(strValue);
break;
case "targetname": case "targetname":
targetname = strValue; targetname = strValue;
break; break;

View file

@ -653,6 +653,7 @@ SV_ShouldPause(float newstatus)
return newstatus; return newstatus;
} }
//#define REEDICT 0
void void
SV_PerformLoad(float fh) SV_PerformLoad(float fh)
{ {
@ -660,40 +661,42 @@ SV_PerformLoad(float fh)
entity eold; entity eold;
string l; string l;
float n; float n;
e = world; NSEntity loadent;
int braced; int braced;
NSEntity loadent;
/* #ifdef REEDICT
while ((e=nextent(e))) { while ((e=nextent(e))) {
if (edict_num(1) != e) if (edict_num(1) != e)
remove(e); remove(e);
} }
*/ #else
entity e = world;
#endif
#if 1
/* read line per line of our file handle */ /* read line per line of our file handle */
while ((l=fgets(fh))) { while ((l=fgets(fh))) {
float args = tokenize(l); float args = tokenize_console(l);
if (!args) if (!args)
break; break;
if (argv(0) == "ENTITY") { if (argv(0) == "ENTITY") {
string cname; string cname;
#ifndef REEDICT
n = stof(argv(1)); n = stof(argv(1));
cname = argv(2);
e = edict_num(n); e = edict_num(n);
#else
entity e = spawn();
#endif
cname = argv(2);
loadent = __NULL__; loadent = __NULL__;
__fullspawndata = fgets(fh); __fullspawndata = fgets(fh);
print(sprintf("Try spawning %s\n", cname));
/* call the constructor if one is present, init the default fields */ /* call the constructor if one is present, init the default fields */
if (isfunction(strcat("spawnfunc_", cname))) { if (isfunction(strcat("spawnfunc_", cname))) {
e.classname = cname; e.classname = cname;
print(sprintf("I'm actually spawning %s\n", cname));
eold = self; eold = self;
self = e; self = e;
@ -707,19 +710,21 @@ SV_PerformLoad(float fh)
continue; continue;
} }
} else if (argv(0) == "{") { } else if (argv(0) == "{") {
braced++;
} else if (argv(0) == "}") { } else if (argv(0) == "}") {
braced--; if (loadent) {
} else if (braced == 1) { loadent.Respawn();
loadent = __NULL__;
}
} else {
if (loadent) { if (loadent) {
int c = tokenize(l); int c = tokenize(l);
if (c == 2) if (c == 2) {
loadent.Restore(argv(0), argv(1)); loadent.Restore(argv(0), argv(1));
}
} }
} }
} }
#endif
} }
void void