Nuclide
Software Development Kit for id Technology
NSIO.h
1/*
2 * Copyright (c) 2016-2024 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
26class NSIO
27{
28public:
29 void NSIO(void);
30
35 virtual void Spawned(void);
36
39 virtual void Respawn(void);
40
44 virtual void SpawnKey(string,string);
45
46 /* EntityDef interactions */
48 nonvirtual float GetDefAct(string);
50 nonvirtual string GetDefString(string);
52 nonvirtual float GetDefFloat(string);
54 nonvirtual bool GetDefBool(string);
56 nonvirtual int GetDefInt(string);
58 nonvirtual vector GetDefVector(string);
59
61 nonvirtual float GetSubDefAct(string, string);
63 nonvirtual string GetSubDefString(string, string);
65 nonvirtual float GetSubDefFloat(string, string);
67 nonvirtual bool GetSubDefBool(string, string);
69 nonvirtual int GetSubDefInt(string, string);
71 nonvirtual vector GetSubDefVector(string, string);
72
74 nonvirtual void Destroy(void);
76 virtual void OnRemoveEntity(void);
77
78#ifdef SERVER
82 virtual void Save(float);
83
87 virtual void Restore(string,string);
88
90 virtual void RestoreComplete(void);
91
93 virtual void TransitionComplete(void);
94
96 virtual void Input(entity,string,string);
97
98 /* helper functions to allocate outputs */
100 nonvirtual void UseOutput(entity,string);
106 nonvirtual string PrepareOutput(string,string);
107
113 nonvirtual string CreateOutput(string);
114
117 nonvirtual bool CheckOutput(string);
118
120 virtual void ParentUpdate(void);
121
122 /* save game related methods */
124 nonvirtual void SaveFloat(float,string,float);
126 nonvirtual void SaveInt(float,string,int);
128 nonvirtual void SaveString(float,string,string);
130 nonvirtual void SaveVector(float,string,vector);
132 nonvirtual void SaveBool(float,string,bool);
134 nonvirtual void SaveEntity(float,string,entity);
135
136#endif
137
139 nonvirtual float GetSpawnFloat(string);
141 nonvirtual int GetSpawnInt(string);
143 nonvirtual string GetSpawnString(string);
145 nonvirtual vector GetSpawnVector(string);
147 nonvirtual bool GetSpawnBool(string);
151 nonvirtual entity GetSpawnEntity(string, entity);
152
153 /* load game/spawn helper functions */
155 nonvirtual float ReadFloat(string);
157 nonvirtual int ReadInt(string);
159 nonvirtual string ReadString(string);
161 nonvirtual vector ReadVector(string);
163 nonvirtual bool ReadBool(string);
165 nonvirtual entity ReadEntity(string);
166
172 nonvirtual float GetTime(void);
173
174 /* save game related methods */
176 nonvirtual void DebugFloat(string,float);
178 nonvirtual void DebugInt(string,int);
180 nonvirtual void DebugString(string,string);
182 nonvirtual void DebugVector(string,vector);
184 nonvirtual void DebugBool(string,bool);
186 nonvirtual void DebugEntity(string,entity);
188 nonvirtual void SetEditorIcon(string);
189
190private:
191 string m_strEditorIcon;
192 string m_strSpawnData;
193#ifdef SERVER
194 string m_strOnTrigger;
195 string m_strOnUser1;
196 string m_strOnUser2;
197 string m_strOnUser3;
198 string m_strOnUser4;
199
200 /* entityDef powered modelevent callbacks */
201 string m_strModelEventCB;
202#endif
203};
204
205.bool isActor;
206.bool _mapspawned;
207
208void
209_NSEntLog(string className, string functionName, float edictNum, string warnMessage)
210{
211 if (autocvar_g_logTimestamps)
212 print(sprintf("^9%f ^7%s (%d)^7: %s\n", time, className, edictNum, warnMessage));
213 else
214 print(sprintf("^7%s (%d)^7: %s\n", className, edictNum, warnMessage));
215}
216
217void
218_NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
219{
220 if (autocvar_g_logTimestamps)
221 print(sprintf("^9%f ^3%s (%d)^7: %s\n", time, functionName, edictNum, warnMessage));
222 else
223 print(sprintf("^3%s (%d)^7: %s\n", functionName, edictNum, warnMessage));
224}
225
226void
227_NSEntError(string className, string functionName, float edictNum, string warnMessage)
228{
229 if (autocvar_g_logTimestamps)
230 print(sprintf("^9%f ^1%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
231 else
232 print(sprintf("^1%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
233}
238#define EntLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
239
244#define EntWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
245
250#define EntError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSEntError(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
This class is responsible for handling core entity functionality.
Definition: NSIO.h:27
nonvirtual int GetDefInt(string)
Looks up the integer value of a key within this entity's declaration.
Definition: NSIO.qc:117
nonvirtual bool GetDefBool(string)
Looks up the boolean value of a key within this entity's declaration.
Definition: NSIO.qc:111
nonvirtual void SaveFloat(float, string, float)
Saves a floating point key/value pair to a filehandle.
Definition: NSIO.qc:424
nonvirtual bool GetSubDefBool(string, string)
Like GetDefBool, but queries a specified def, falling back to reading from our own if it's not define...
Definition: NSIO.qc:192
nonvirtual void SaveEntity(float, string, entity)
Saves an entity id key/value pair to a filehandle.
Definition: NSIO.qc:448
nonvirtual int GetSubDefInt(string, string)
Like GetDefInt, but queries a specified def, falling back to reading from our own if it's not defined...
Definition: NSIO.qc:198
nonvirtual float GetDefAct(string)
Looks up a sequence from an act of a key within this entity's declaration.
Definition: NSIO.qc:160
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: NSIO.qc:46
nonvirtual float GetDefFloat(string)
Looks up the floating-point value of a key within this entity's declaration.
Definition: NSIO.qc:105
nonvirtual void DebugVector(string, vector)
Debug print for a given vector.
Definition: NSIO.qc:961
void NSIO(void)
Definition: NSIO.qc:18
nonvirtual vector GetDefVector(string)
Looks up the integer value of a key within this entity's declaration.
Definition: NSIO.qc:99
nonvirtual bool GetSpawnBool(string)
Returns the boolean value of a named key in the entity's spawn data.
Definition: NSIO.qc:254
nonvirtual void SaveInt(float, string, int)
Saves a integer key/value pair to a filehandle.
Definition: NSIO.qc:430
nonvirtual int GetSpawnInt(string)
Returns the integer value of a named key in the entity's spawn data.
Definition: NSIO.qc:266
nonvirtual float GetSpawnFloat(string)
Returns the floating-point value of a named key in the entity's spawn data.
Definition: NSIO.qc:260
nonvirtual vector ReadVector(string)
Returns a vector from a string.
Definition: NSIO.qc:235
nonvirtual float GetTime(void)
Get the level time the entity finds itself in.
Definition: NSIO.qc:934
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: NSIO.qc:391
nonvirtual string GetSubDefString(string, string)
Like GetDefString, but queries a specified def, falling back to reading from our own if it's not defi...
Definition: NSIO.qc:166
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: NSIO.qc:52
nonvirtual vector GetSubDefVector(string, string)
Like GetDefVector, but queries a specified def, falling back to reading from our own if it's not defi...
Definition: NSIO.qc:180
virtual void Restore(string, string)
Similar to NSIO::SpawnKey but for save-game fields.
Definition: NSIO.qc:561
nonvirtual int ReadInt(string)
Returns an integer value from a string.
Definition: NSIO.qc:219
nonvirtual string CreateOutput(string)
Called at the end of setting up an entity's output field.
Definition: NSIO.qc:323
nonvirtual void DebugEntity(string, entity)
Debug print for a given entity.
Definition: NSIO.qc:966
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: NSIO.qc:457
nonvirtual void DebugBool(string, bool)
Debug print for a given boolean.
Definition: NSIO.qc:941
nonvirtual void DebugFloat(string, float)
Debug print for a given float.
Definition: NSIO.qc:946
nonvirtual void SaveBool(float, string, bool)
Saves a boolean key/value pair to a filehandle.
Definition: NSIO.qc:418
nonvirtual void UseOutput(entity, string)
Triggers an output field that has been created beforehand.
Definition: NSIO.qc:302
nonvirtual void SetEditorIcon(string)
Sets the editor icon.
Definition: NSIO.qc:972
virtual void RestoreComplete(void)
Called when the entity has been successfully restored from a savegame file.
Definition: NSIO.qc:861
virtual void OnRemoveEntity(void)
Handles what happens before the entity gets removed from the client game.
Definition: NSIO.qc:70
nonvirtual void DebugString(string, string)
Debug print for a given string.
Definition: NSIO.qc:956
nonvirtual string PrepareOutput(string, string)
Prepares an output field.
Definition: NSIO.qc:381
nonvirtual entity GetSpawnEntity(string, entity)
Returns an entity of a named key in the entity's spawn data.
Definition: NSIO.qc:293
nonvirtual float ReadFloat(string)
Returns a floating point value from a string value.
Definition: NSIO.qc:212
nonvirtual float GetSubDefAct(string, string)
Like GetDefAct, but queries a specified def, falling back to reading from our own if it's not defined...
Definition: NSIO.qc:124
nonvirtual void SaveVector(float, string, vector)
Saves a vector key/value pair to a filehandle.
Definition: NSIO.qc:442
nonvirtual bool CheckOutput(string)
Returns whether the Output is ready, or has done firing - not currently scheduled to fire,...
Definition: NSIO.qc:368
nonvirtual string GetDefString(string)
Looks up the string value of a key within this entity's declaration.
Definition: NSIO.qc:93
nonvirtual string ReadString(string)
Returns a string value from a string (with error checking).
Definition: NSIO.qc:226
nonvirtual vector GetSpawnVector(string)
Returns the vector value of a named key in the entity's spawn data.
Definition: NSIO.qc:287
nonvirtual entity ReadEntity(string)
Reads an entity id from a string and returns the entity.
Definition: NSIO.qc:242
virtual void TransitionComplete(void)
Called when the entity has successfully completed a level transition.
Definition: NSIO.qc:866
nonvirtual void Destroy(void)
When called, will remove the entity from the game entirely.
Definition: NSIO.qc:75
nonvirtual void SaveString(float, string, string)
Saves a string key/value pair to a filehandle.
Definition: NSIO.qc:436
nonvirtual void DebugInt(string, int)
Debug print for a given integer.
Definition: NSIO.qc:951
nonvirtual bool ReadBool(string)
Returns a boolean value from a string.
Definition: NSIO.qc:205
nonvirtual string GetSpawnString(string)
Returns the string value of a named key in the entity's spawn data.
Definition: NSIO.qc:272
nonvirtual float GetSubDefFloat(string, string)
Like GetDefFloat, but queries a specified def, falling back to reading from our own if it's not defin...
Definition: NSIO.qc:186
virtual void ParentUpdate(void)
Called when we need to re-align the entity to our parent entity.
Definition: NSIO.qc:871
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: NSIO.qc:878