zCObjects
Set of functions for working with zCObject
and its subclasses instances.
Initialization
The best way to initialize all Ikarus functions is to call MEM_InitAll()
in the Init_Global()
initialization function.
Warning
If you want to use Ikarus in Gothic 1, it is best to define your own Init_Global()
function and call it from every world initialization function.
Implementation
Global instances
Ikarus package introduces the following instances:
The classes used here all have one thing in common: there is a maximum of one object of them at the same time (e.g. there is not two worlds or two sky at the same time).
MEM_InitGlobalInst
function sets the offsets of these instances to the corresponding unique object. While it has been called, all of the above instances can be used.
MEM_InitGlobalInst
Initializes global instances of commonly used objects in the game (is called by the MEM_InitAll
function).
Warning
MEM_InitGlobalInst
must be executed once after loading a savegame. The easiest way is do it is to call this function from INIT_GLOBAL
.
Functions
About zCClassDef
For every class (derived from zCObject
) there is an "administrative object" of type zCClassDef
. This encapsulates some useful information about all objects in this class.
Full Ikarus definition of this class, with members description can be found in Misc.d
file. The class is same for G1 and G2A engines.
MEM_GetClassDef
Returns a pointer to the zCClassDef
of the object. For more info see the About zCClassDef section above.
Passing these functions a pointer that does not point to a zCObject will most likely result in a crash lead.
var int objPtr
A pointer to the object whose class definition is to be retrieved
Return value
The function returns a pointer to the zCClassDef
of the object.
Example
This would return a pointer to the zCClassDef
object that belongs to the oCNpc
class.
MEM_GetClassName
This function returns the name of the class to which an object belongs.
var int objPtr
A pointer to the object whose class name is to be retrieved
Return value
The function returns the objects class name as a string, if the object is invalid an empty string is returned.
Example
This would return a name of the oCNpc
class as a string.
MEM_CheckInheritance
Checks if an object is derived from a specific class definition.
var int objPtr
A pointer to the object to be checkedvar int classDef
A pointer to the class definition to check against
Return value
The function returns TRUE
if the object is derived from the specified class definition, FALSE
is returned otherwise.
Hlp_Is_*
In addition MEM_CheckInheritance
function has some overloads with hardcoded classDef
parameter.
The usage of these functions is probably obvious, they checks if the given object belongs to class given in the function name.
MEM_InsertVob
Inserts a Vob with the visual vis
at the waypoint wp
. If the visual or waypoint does not exist, this is the behaviour this function undefined.
Note
The inserted Vob is even an oCMob
, so it can be given a focus name, for example. But you can treat it like a zCVob
), if you don't need the additional properties.
var string vis
Name of the inserted Vob visual ("FAKESCROLL.3DS"
,"FIRE.PFX"
,"SNA_BODY.ASC"
,"CHESTSMALL_NW_POOR_LOCKED.MDS"
,"ADD_PIRATEFLAG.MMS"
etc.)var string wp
Name of the waypoint to insert Vob on
Return value
The function returns a pointer to the created object.
MEM_DeleteVob
Deletes a specific Vob form world.
var int vobPtr
Pointer to azCVob
object to be deleted
MEM_RenameVob
Renames the passed Vob to the newName
that is also passed.
The object becomes this first removed from the Vob-hashtable, then unnamed and then again inserted into the Vob-hashtable under a new name.
var int vobPtr
Pointer to azCVob
object to be renamedvar string newName
The new Name of the Vob
MEM_TriggerVob
Sends a trigger message to the Vob.
var int vobPtr
Pointer to a triggeredzCVob
Danger
If triggering the Vob has immediate effects (even before MEM_TriggerVob is exited), the name of the Vob is corrupted during this time. It is not advisable to rename, trigger again or destroy the object at this moment, the behavior in such cases is untested.
MEM_UntriggerVob
Sends an untrigger message to the Vob.
var int vobPtr
Pointer to an untriggeredzCVob
Danger
If untriggering the Vob has immediate effects (even before MEM_TriggerVob is exited), the name of the Vob is corrupted during this time. It is not advisable to rename, trigger again or destroy the object at this moment, the behavior in such cases is untested.
MEM_SearchVobByName
Returns the address of a zCVob
named str
if such a Vob exists.
var string str
Name of searchedzCVob
Return value
The function returns a pointer to the zCVob
if the object with the given name exist. 0
is returned otherwise.
MEM_SearchAllVobsByName
Variation of MEM_SearchVobByName
. Creates a zCArray
in which all pointers are to Vobs with the name str
. If no Vob with the name exists, an empty zCArray
is created. A pointer to the created zCArray
is then returned. This can be evaluated, but should be released again with MEM_ArrayFree
before the end of the frame (before the player can load) to avoid memory leaks.
var string str
Name of searchedzCVob
Return value
The function returns a pointer to the created zCArray
, that contains pointers to the all Vobs with the specified name.
MEM_GetBufferCRC32
Calculates the CRC32 hash value from a byte array starting at the address specified by buf
and having a length of buflen
.
-
var int buf
Address of a byte array, the hash calculation will begin from -
var int buflen
The length of the byte array starting from the address specified bybuf
Return value
The function returns the calculated CRC32 hash value.
MEM_GetStringHash
Calculates the CRC32 hash value for a string.
var string str
A string for which the hash value is to be calculated
Return value
The function returns an integer representing the calculated hash value for the input string.