Conitec 3d gamestudio-source development User Manual

Page of 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       9
An
A5_INTERFACE
object named
a5
is initialized on startup of each DLL and can be used for
accessing the screen buffer, the Direct3D Device and the
MY
and
YOU
entity pointers. For directly
accessing any C-Script object from a DLL, the
a5dll.lib
can be used in a way described in the
following chapter.
DLL functions
Some functions in the
a5dll.lib
provide DLL access to internal C-Script variables, objects and
functions. This way, entity AI can be implemented in a DLL plugin, and can use most C-Script
instructions.
long a5dll_getwdlobj(char *name);
  
This function returns the address of the C-Script object or variable with the given name. It can
be used to read or write any defined C-Script object from inside a DLL plugin. If the object does
not exist,
NULL
is returned and an error message will pop up. Examples for DLL functions that
access C-Script objects:
  // adds the given value to the sky speed
  fixed AddToSkySpeed(fixed value)
  {
  // get the address of the variable
    fixed *skyspeed = (fixed *)a5dll_getwdlobj("sky_speed");
    if (!skyspeed) return 0;
  // add the value to both the x and y components
    skyspeed[0] += value;  // skyspeed X value
    skyspeed[1] += value;  // skyspeed y value
    return INT2FIX(1);
  }
  // zooms the camera view
  fixed ZoomIn(fixed value)
  {
    A4_VIEW *camera = (A4_VIEW *)a5dll_getwdlobj("camera");
    if (!camera) return 0;
    return (camera->arc -= value); // change the FOV and return it
  }
long a5dll_getwdlfunc(char *name);
This function returns the address of the C-Script function with the given name. It can be used to
call predefined C-Script functions from inside a DLL plugin. Not all C-Script functions are
available for DLLs. If the function is not available (as can be the case for some special C-Script
functions, like
wait()
or
inkey()
),
NULL
is returned and an error message will pop up.
Example for an entity AI DLL function that uses C-Script functions for scanning the
environment of an entity:
  // returns free distance in front of MY entity until next obstacle
  fixed DistAhead(long my)
  {
    if (!my) return 0;
  
  // retrieve the pointer to the given entity
    A4_ENTITY *ent = (A4_ENTITY *)my;