Nuclide
Software Development Kit for id Technology (BETA)
IO.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
77class ncIO
78{
79public:
80 void ncIO(void);
81
86 virtual void Spawned(void);
87
90 virtual void Respawn(void);
91
95 virtual void SpawnKey(string,string);
96
97 /* EntityDef interactions */
99 nonvirtual float GetDefAct(string);
101 nonvirtual string GetDefString(string);
103 nonvirtual float GetDefFloat(string);
105 nonvirtual bool GetDefBool(string);
107 nonvirtual int GetDefInt(string);
109 nonvirtual vector GetDefVector(string);
110
112 nonvirtual float GetSubDefAct(string, string);
114 nonvirtual string GetSubDefString(string, string);
116 nonvirtual float GetSubDefFloat(string, string);
118 nonvirtual bool GetSubDefBool(string, string);
120 nonvirtual int GetSubDefInt(string, string);
122 nonvirtual vector GetSubDefVector(string, string);
123
125 nonvirtual void Destroy(void);
127 virtual void OnRemoveEntity(void);
128
131 nonvirtual float GetNextThinkTime(void);
133 nonvirtual bool IsThinking(void);
135 nonvirtual void ReleaseThink(void);
137 nonvirtual void ThinkBusy(float);
138
141 nonvirtual void SetThink(void());
145 nonvirtual void SetNextThink(float);
150 nonvirtual void ScheduleThink(void(void),float);
151
152#ifdef SERVER
156 virtual void Save(float);
157
161 virtual void Restore(string,string);
162
164 virtual void RestoreComplete(void);
165
167 virtual void TransitionComplete(void);
168
170 virtual void Input(entity,string,string);
171
172 /* helper functions to allocate outputs */
174 nonvirtual void UseOutput(entity,string);
180 nonvirtual string PrepareOutput(string,string);
181
187 nonvirtual string CreateOutput(string);
188
191 nonvirtual bool CheckOutput(string);
192
194 virtual void ParentUpdate(void);
195
196 /* save game related methods */
198 nonvirtual void SaveFloat(float,string,float);
200 nonvirtual void SaveInt(float,string,int);
202 nonvirtual void SaveString(float,string,string);
204 nonvirtual void SaveVector(float,string,vector);
206 nonvirtual void SaveBool(float,string,bool);
208 nonvirtual void SaveEntity(float,string,entity);
209
210#endif
211
213 nonvirtual float GetSpawnFloat(string);
215 nonvirtual int GetSpawnInt(string);
217 nonvirtual string GetSpawnString(string);
219 nonvirtual vector GetSpawnVector(string);
221 nonvirtual bool GetSpawnBool(string);
225 nonvirtual entity GetSpawnEntity(string, entity);
226
227 /* load game/spawn helper functions */
229 nonvirtual float ReadFloat(string);
231 nonvirtual int ReadInt(string);
233 nonvirtual string ReadString(string);
235 nonvirtual vector ReadVector(string);
237 nonvirtual bool ReadBool(string);
239 nonvirtual entity ReadEntity(string);
240
246 nonvirtual float GetTime(void);
247
248 /* save game related methods */
250 nonvirtual void DebugFloat(string,float);
252 nonvirtual void DebugInt(string,int);
254 nonvirtual void DebugString(string,string);
256 nonvirtual void DebugVector(string,vector);
258 nonvirtual void DebugBool(string,bool);
260 nonvirtual void DebugEntity(string,entity);
262 nonvirtual void SetEditorIcon(string);
263
264private:
265 string m_strEditorIcon;
266 string m_strSpawnData;
267#ifdef SERVER
268 string m_strOnTrigger;
269 string m_strOnUser1;
270 string m_strOnUser2;
271 string m_strOnUser3;
272 string m_strOnUser4;
273
274 /* entityDef powered modelevent callbacks */
275 string m_strModelEventCB;
276#endif
277};
278
279#define CREATE_OUTPUT(x) if (STRING_SET(x)) { \
280 x = CreateOutput(x); \
281 }
282
283.bool isActor;
284.bool _mapspawned;
285
286void
287_NSEntLog(string className, string functionName, float edictNum, string warnMessage)
288{
289 if (autocvar_g_logTimestamps)
290 print(sprintf("^9%f ^7%s (%d)^7: %s\n", time, className, edictNum, warnMessage));
291 else
292 print(sprintf("^7%s (%d)^7: %s\n", className, edictNum, warnMessage));
293}
294
295void
296_NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
297{
298 if (autocvar_g_logTimestamps)
299 print(sprintf("^9%f ^3%s (%d)^7: %s\n", time, functionName, edictNum, warnMessage));
300 else
301 print(sprintf("^3%s (%d)^7: %s\n", functionName, edictNum, warnMessage));
302}
303
304void
305_NSEntError(string className, string functionName, float edictNum, string warnMessage)
306{
307 if (autocvar_g_logTimestamps)
308 print(sprintf("^9%f ^1%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
309 else
310 print(sprintf("^1%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
311}
316#define EntLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
317
322#define EntWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
323
328#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: IO.h:78
virtual void OnRemoveEntity(void)
Handles what happens before the entity gets removed from the client game.
Definition: IO.qc:70
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: IO.qc:163
nonvirtual bool ReadBool(string)
Returns a boolean value from a string.
Definition: IO.qc:182
nonvirtual float GetDefAct(string)
Looks up a sequence from an act of a key within this entity's declaration.
Definition: IO.qc:137
nonvirtual bool CheckOutput(string)
Returns whether the Output is ready, or has done firing - not currently scheduled to fire,...
Definition: IO.qc:359
nonvirtual void DebugEntity(string, entity)
Debug print for a given entity.
Definition: IO.qc:960
nonvirtual void ScheduleThink(void(void), float)
Schedules a think timer.
Definition: IO.qc:1023
nonvirtual void DebugString(string, string)
Debug print for a given string.
Definition: IO.qc:950
nonvirtual int GetDefInt(string)
Looks up the integer value of a key within this entity's declaration.
Definition: IO.qc:124
nonvirtual string CreateOutput(string)
Called at the end of setting up an entity's output field.
Definition: IO.qc:304
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: IO.qc:46
nonvirtual string GetDefString(string)
Looks up the string value of a key within this entity's declaration.
Definition: IO.qc:100
nonvirtual void DebugBool(string, bool)
Debug print for a given boolean.
Definition: IO.qc:935
nonvirtual string ReadString(string)
Returns a string value from a string (with error checking).
Definition: IO.qc:203
nonvirtual void SetThink(void())
Overrides the Think function of the entity.
Definition: IO.qc:1000
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: IO.qc:869
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: IO.qc:131
nonvirtual float GetSpawnFloat(string)
Returns the floating-point value of a named key in the entity's spawn data.
Definition: IO.qc:237
virtual void ParentUpdate(void)
Called when we need to re-align the entity to our parent entity.
Definition: IO.qc:862
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: IO.qc:52
nonvirtual float GetDefFloat(string)
Looks up the floating-point value of a key within this entity's declaration.
Definition: IO.qc:112
nonvirtual void SaveEntity(float, string, entity)
Saves an entity id key/value pair to a filehandle.
Definition: IO.qc:439
nonvirtual void SaveFloat(float, string, float)
Saves a floating point key/value pair to a filehandle.
Definition: IO.qc:415
nonvirtual bool GetSpawnBool(string)
Returns the boolean value of a named key in the entity's spawn data.
Definition: IO.qc:231
nonvirtual vector GetSpawnVector(string)
Returns the vector value of a named key in the entity's spawn data.
Definition: IO.qc:264
nonvirtual void SaveInt(float, string, int)
Saves a integer key/value pair to a filehandle.
Definition: IO.qc:421
nonvirtual void SetNextThink(float)
Sets the next think timer of the entity.
Definition: IO.qc:1006
nonvirtual float GetTime(void)
Get the level time the entity finds itself in.
Definition: IO.qc:928
nonvirtual void SaveVector(float, string, vector)
Saves a vector key/value pair to a filehandle.
Definition: IO.qc:433
nonvirtual bool GetDefBool(string)
Looks up the boolean value of a key within this entity's declaration.
Definition: IO.qc:118
nonvirtual void DebugFloat(string, float)
Debug print for a given float.
Definition: IO.qc:940
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: IO.qc:175
nonvirtual void ThinkBusy(float)
When called, will make the entity think busy for the specified amount of time.
Definition: IO.qc:991
nonvirtual vector ReadVector(string)
Returns a vector from a string.
Definition: IO.qc:212
nonvirtual void DebugVector(string, vector)
Debug print for a given vector.
Definition: IO.qc:955
nonvirtual void SaveBool(float, string, bool)
Saves a boolean key/value pair to a filehandle.
Definition: IO.qc:409
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: IO.qc:157
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: IO.qc:143
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: IO.qc:382
nonvirtual float GetNextThinkTime(void)
Returns an absolute value of when the entity will be think again.
Definition: IO.qc:972
nonvirtual entity GetSpawnEntity(string, entity)
Returns an entity of a named key in the entity's spawn data.
Definition: IO.qc:270
nonvirtual string PrepareOutput(string, string)
Prepares an output field.
Definition: IO.qc:372
nonvirtual entity ReadEntity(string)
Reads an entity id from a string and returns the entity.
Definition: IO.qc:219
nonvirtual void Destroy(void)
When called, will remove the entity from the game entirely.
Definition: IO.qc:75
nonvirtual vector GetDefVector(string)
Looks up the integer value of a key within this entity's declaration.
Definition: IO.qc:106
void ncIO(void)
Definition: IO.qc:18
nonvirtual bool IsThinking(void)
Returns whether or not we're currently expecting to think any time soon.
Definition: IO.qc:978
virtual void RestoreComplete(void)
Called when the entity has been successfully restored from a savegame file.
Definition: IO.qc:852
virtual void TransitionComplete(void)
Called when the entity has successfully completed a level transition.
Definition: IO.qc:857
nonvirtual void SaveString(float, string, string)
Saves a string key/value pair to a filehandle.
Definition: IO.qc:427
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: IO.qc:448
nonvirtual string GetSpawnString(string)
Returns the string value of a named key in the entity's spawn data.
Definition: IO.qc:249
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: IO.qc:169
nonvirtual void ReleaseThink(void)
When called, will unset anything related to ongoing think operations.
Definition: IO.qc:984
nonvirtual void UseOutput(entity, string)
Triggers an output field that has been created beforehand.
Definition: IO.qc:279
nonvirtual void SetEditorIcon(string)
Sets the editor icon.
Definition: IO.qc:966
nonvirtual void DebugInt(string, int)
Debug print for a given integer.
Definition: IO.qc:945
nonvirtual int ReadInt(string)
Returns an integer value from a string.
Definition: IO.qc:196
nonvirtual float ReadFloat(string)
Returns a floating point value from a string value.
Definition: IO.qc:189
nonvirtual int GetSpawnInt(string)
Returns the integer value of a named key in the entity's spawn data.
Definition: IO.qc:243
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: IO.qc:552