static void PF_precache_model() { if (!Server.IsLoading) { Progs.RunError("PF_Precache_*: Precache can only be done in spawn functions"); } string s = GetString(OFS.OFS_PARM0); ReturnInt(GetInt(OFS.OFS_PARM0)); //G_INT(OFS_RETURN) = G_INT(OFS_PARM0); CheckEmptyString(s); for (int i = 0; i < QDef.MAX_MODELS; i++) { if (Server.sv.model_precache[i] == null) { Server.sv.model_precache[i] = s; Server.sv.models[i] = Mod.ForName(s, true); return; } if (Server.sv.model_precache[i] == s) { return; } } Progs.RunError("PF_precache_model: overflow"); }
static void PF_precache_sound() { if (!Server.IsLoading) { Progs.RunError("PF_Precache_*: Precache can only be done in spawn functions"); } string s = GetString(OFS.OFS_PARM0); ReturnInt(GetInt(OFS.OFS_PARM0)); // G_INT(OFS_RETURN) = G_INT(OFS_PARM0); CheckEmptyString(s); for (int i = 0; i < QDef.MAX_SOUNDS; i++) { if (Server.sv.sound_precache[i] == null) { Server.sv.sound_precache[i] = s; return; } if (Server.sv.sound_precache[i] == s) { return; } } Progs.RunError("PF_precache_sound: overflow"); }
static void CheckEmptyString(string s) { if (s == null || s.Length == 0 || s[0] <= ' ') { Progs.RunError("Bad string"); } }
/// <summary> /// PF_Find /// entity (entity start, .string field, string match) find = #5; /// </summary> static void PF_Find() { int e = GetInt(OFS.OFS_PARM0); int f = GetInt(OFS.OFS_PARM1); string s = GetString(OFS.OFS_PARM2); if (s == null) { Progs.RunError("PF_Find: bad search string"); } for (e++; e < Server.sv.num_edicts; e++) { edict_t ed = Server.EdictNum(e); if (ed.free) { continue; } string t = Progs.GetString(ed.GetInt(f)); // E_STRING(ed, f); if (String.IsNullOrEmpty(t)) { continue; } if (t == s) { ReturnEdict(ed); return; } } ReturnEdict(Server.sv.edicts[0]); }
/* * ============== * PF_setspawnparms * ============== */ static void PF_setspawnparms() { edict_t ent = GetEdict(OFS.OFS_PARM0); int i = Server.NumForEdict(ent); if (i < 1 || i > Server.svs.maxclients) { Progs.RunError("Entity is not a client"); } // copy spawn parms out of the client_t client_t client = Server.svs.clients[i - 1]; Progs.GlobalStruct.SetParams(client.spawn_parms); }
//============================================================================ /// <summary> /// PF_stuffcmd /// Sends text over to the client's execution buffer /// stuffcmd (clientent, value) /// </summary> static void PF_stuffcmd() { int entnum = Server.NumForEdict(GetEdict(OFS.OFS_PARM0)); if (entnum < 1 || entnum > Server.svs.maxclients) { Progs.RunError("Parm 0 not a client"); } string str = GetString(OFS.OFS_PARM1); client_t old = Host.HostClient; Host.HostClient = Server.svs.clients[entnum - 1]; Host.ClientCommands("{0}", str); Host.HostClient = old; }
/* * ================= * PF_setmodel * * setmodel(entity, model) * ================= */ static void PF_setmodel() { edict_t e = GetEdict(OFS.OFS_PARM0); int m_idx = GetInt(OFS.OFS_PARM1); string m = Progs.GetString(m_idx); // check to see if model was properly precached for (int i = 0; i < Server.sv.model_precache.Length; i++) { string check = Server.sv.model_precache[i]; if (check == null) { break; } if (check == m) { e.v.model = m_idx; // m - pr_strings; e.v.modelindex = i; Model mod = Server.sv.models[(int)e.v.modelindex]; if (mod != null) { SetMinMaxSize(e, ref mod.mins, ref mod.maxs, true); } else { SetMinMaxSize(e, ref Common.ZeroVector, ref Common.ZeroVector, true); } return; } } Progs.RunError("no precache: {0}\n", m); }
static void SetMinMaxSize(edict_t e, ref Vector3 min, ref Vector3 max, bool rotate) { if (min.X > max.X || min.Y > max.Y || min.Z > max.Z) { Progs.RunError("backwards mins/maxs"); } rotate = false; // FIXME: implement rotation properly again Vector3 rmin = min, rmax = max; if (!rotate) { //rmin = min; //rmax = max; } else { // find min / max for rotations //angles = e.v.angles; //a = angles[1] / 180 * M_PI; //xvector[0] = cos(a); //xvector[1] = sin(a); //yvector[0] = -sin(a); //yvector[1] = cos(a); //VectorCopy(min, bounds[0]); //VectorCopy(max, bounds[1]); //rmin[0] = rmin[1] = rmin[2] = 9999; //rmax[0] = rmax[1] = rmax[2] = -9999; //for (i = 0; i <= 1; i++) //{ // base[0] = bounds[i][0]; // for (j = 0; j <= 1; j++) // { // base[1] = bounds[j][1]; // for (k = 0; k <= 1; k++) // { // base[2] = bounds[k][2]; // // transform the point // transformed[0] = xvector[0] * base[0] + yvector[0] * base[1]; // transformed[1] = xvector[1] * base[0] + yvector[1] * base[1]; // transformed[2] = base[2]; // for (l = 0; l < 3; l++) // { // if (transformed[l] < rmin[l]) // rmin[l] = transformed[l]; // if (transformed[l] > rmax[l]) // rmax[l] = transformed[l]; // } // } // } //} } // set derived values Mathlib.Copy(ref rmin, out e.v.mins); Mathlib.Copy(ref rmax, out e.v.maxs); Vector3 s = max - min; Mathlib.Copy(ref s, out e.v.size); Server.LinkEdict(e, false); }
static void PF_Fixme() { Progs.RunError("unimplemented bulitin"); }