/* * SWServ Plugins API * * These are defination of functions that plugins may use to * interact with the server. * * Most definations are actually macros to call functions on the * SWServ Plugins Context (see context.h). */ #ifndef SWSERV_PLUGINS_API_H #define SWSERV_PLUGINS_API_H #include "context.h" /* * User Data: */ #define SWServSetData(_ctx_,_data_) \ ((_ctx_)->set_data( \ (_ctx_), \ (_data_) \ )) #define SWServGetData(_ctx_) \ ((_ctx_)->get_data( \ (_ctx_) \ )) /* * Timming: */ #define SWServCurrentTimeMS(_ctx_) \ (*(_ctx_)->cur_millitime) #define SWServCurrentTimeSeconds(_ctx_) \ (*(_ctx_)->cur_systime) #define SWServLapsedMS(_ctx_) \ (*(_ctx_)->lapsed_millitime) #define SWServCurrentTimeCompensation(_ctx_) \ (*(_ctx_)->time_compensation) /* * Total Objects: */ #define SWServTotalObjects(_ctx_) \ (*(_ctx_)->total_objects) /* * Total OPMs: */ #define SWServTotalOPMs(_ctx_) \ (*(_ctx_)->total_opms) /* * Total OCSs: */ #define SWServTotalOCSs(_ctx_) \ (*(_ctx_)->total_ocss) /* * Total Connections: */ #define SWServTotalConnections(_ctx_) \ (*(_ctx_)->total_connections) /* * Checks if the connection is connected. */ #define SWServConIsConnected(_ctx_,_con_num_) \ ((_ctx_)->con_is_connected( \ (_con_num_) \ )) /* * Checks if the connection is logged in. */ #define SWServConIsLoggedIn(_ctx_,_con_num_) \ ((_ctx_)->con_is_logged_in( \ (_con_num_) \ )) /* * Returns the connection's object number. */ #define SWServConGetObjNum(_ctx_,_con_num_) \ ((_ctx_)->con_get_obj_num( \ (_con_num_) \ )) /* * Prints a message to the connection. * * If _con_num_ is -1 then the message is sent to all connections. */ #define SWServConNotify SWServConPrint #define SWServConPrint(_ctx_,_con_num_,_s_) \ ((_ctx_)->con_print( \ (_con_num_), \ (_s_) /* Message */ \ )) /* * Prints a message to the connection as a dialog. * * If _con_num_ is -1 then the message is sent to all connections. * * The code can be one of CS_SYSMESG_CODE_*. */ #define SWServConPrintDialog(_ctx_,_code_,_con_num_,_s_) \ ((_ctx_)->con_print_dialog( \ (_con_num_), \ (_code_), /* Code */ \ (_s_) /* Message */ \ )) /* * Returns the sysparm value as an int. */ #define SWServSysparmGetI(_ctx_,_parm_) \ ((_ctx_)->sysparm_get_i( \ (_parm_) /* Parm */ \ )) /* * Returns the sysparm value as a float. */ #define SWServSysparmGetF(_ctx_,_parm_) \ ((_ctx_)->sysparm_get_f( \ (_parm_) /* Parm */ \ )) /* * Returns the sysparm value as a string. */ #define SWServSysparmGetS(_ctx_,_parm_) \ ((_ctx_)->sysparm_get_s( \ (_parm_) /* Parm */ \ )) /* * Returns the universe legend. */ #define SWServGetLegend(_ctx_) \ ((_ctx_)->legend) \ /* * Checks if the object is garbage. */ #define SWServObjectIsGarbage(_ctx_,_obj_num_) \ ((_ctx_)->obj_is_garbage( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_obj_num_) \ )) /* * Returns the pointer to the specified object. */ #define SWServObjectGetPointer(_ctx_,_obj_num_) \ ((_ctx_)->obj_get_pointer( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_obj_num_) \ )) /* * Gets the player object that owns the specified object (not * just the immediate owner). */ #define SWServObjectGetPlayerOwner(_ctx_,_on_) \ ((_ctx_)->obj_get_player_owner( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on_) \ )) /* * Checks if the object is a player object that is currently * connected. */ #define SWServObjectIsConnected(_ctx_,_on_) \ ((_ctx_)->obj_is_connected( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on_) \ )) /* * Checks if the object is marked hidden on the server. */ #define SWServObjectIsHidden(_ctx_,_on_) \ ((_ctx_)->obj_is_hidden( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on_) \ )) /* * Gets the weapon object's weapon flags. * * Note that a weapon object's weapon flags are different from * an object's weapon's flags (flags for a weapon on an object) * which is otherwise accessable with obj->weapon[i]->flags. */ #define SWServWeaponGetFlags(_ctx_,_on_) \ ((_ctx_)->wep_get_flags( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on_) \ )) /* * Sets the weapon object's weapon flags. * * The _flags_ must be any of SW_WEP_FLAG_*. */ #define SWServWeaponSetFlags(_ctx_,_on_,_flags_) \ ((_ctx_)->wep_set_flags( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on_), (_flags_) \ )) /* * Unsets the weapon object's weapon flags. * * The _flags_ must be any of SW_WEP_FLAG_*. */ #define SWServWeaponUnsetFlags(_ctx_,_on_,_flags_) \ ((_ctx_)->wep_unset_flags( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on_), (_flags_) \ )) /* * Checks if the two objects are valid and in the same sector. */ #define SWServObjectsInSameSector(_ctx_,_on1_,_on2_) \ ((_ctx_)->obj_in_same_sector( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on1_), (_on2_) \ )) /* * Checks if the two objects are valid, in the same sector, * and in contact with each other. */ #define SWServObjectsInContact(_ctx_,_on1_,_on2_) \ ((_ctx_)->obj_in_contact( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on1_), (_on2_) \ )) /* * Checks if the two objects are valid, in the same sector, * and within the specified distance (in real units). */ #define SWServObjectsInRange(_ctx_,_on1_,_on2_,_d_) \ ((_ctx_)->obj_in_range( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on1_), (_on2_), \ (_d_) /* Distance in real units */ \ )) /* * Checks if the two objects are valid, in the same sector, * within the specified distance (in screen units), and if the * first object is at the specified bearing to the second * object and within the specified variance (in radians). */ #define SWServObjectsInVectorRange(_ctx_,_on1_,_on2_,_d_,_brg_,_var_) \ ((_ctx_)->obj_in_vector_range( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_on1_), (_on2_), \ (_d_), /* Distance in real units */ \ (_brg_), /* Bearing in radians */ \ (_var_) /* Variance in radians */ \ )) /* * Instructs the object to fire its selected weapon. */ #define SWServObjectFireWeapon(_ctx_,_obj_num_,_freq_,_yield_) \ ((_ctx_)->obj_fire_weapon( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_obj_num_), \ (_freq_), /* Weapon Frequency */ \ (_yield_) /* Weapon Yield [0.0 to 1.0] */ \ )) /* * Instructs the object to send a com message on the specified * channel. If msg is NULL then a hail is sent. */ #define SWServObjectSendMessage(_ctx_,_obj_num_,_tar_obj_num_,_channel_,_msg_) \ ((_ctx_)->obj_send_message( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_obj_num_), /* Sender */ \ (_tar_obj_num_), /* Receiver or -1 for general */ \ (_channel_), /* Channel */ \ (_msg_) /* Message or NULL for hail */ \ )) /* * Creates a new object of the specified type. * * Returns the new object's number or -1 on error. */ #define SWServObjectCreate(_ctx_,_type_) \ ((_ctx_)->obj_create( \ ((_ctx_)->xsw_object), ((_ctx_)->total_objects), \ (_type_) \ )) /* * Recycles the object. */ #define SWServObjectRecycle(_ctx_,_obj_num_) \ ((_ctx_)->obj_recycle( \ ((_ctx_)->xsw_object), ((_ctx_)->total_objects), \ (_obj_num_) \ )) /* * Sends out values to all connections interested about the * specified object. */ #define SWServObjectSyncConnections(_ctx_,_obj_num_,_is_new_) \ ((_ctx_)->obj_sync_connections( \ (*(_ctx_)->xsw_object), (*(_ctx_)->total_objects), \ (_obj_num_), \ (_is_new_) \ )) /* * Returns the pointer to the specified OPM. */ #define SWServOPMGetPointer(_ctx_,_opm_num_) \ ((_ctx_)->opm_get_pointer( \ (*(_ctx_)->opm), (*(_ctx_)->total_opms), \ (_opm_num_) \ )) /* * Returns the OPM that matches the specified name. */ #define SWServOPMGetByName(_ctx_,_name_) \ ((_ctx_)->opm_get_by_name( \ (*(_ctx_)->opm), (*(_ctx_)->total_opms), \ (_name_) \ )) /* * Models the object after the specified OPM. */ #define SWServOPMModelObject(_ctx_,_opm_num_,_obj_num_) \ ((_ctx_)->opm_model_object( \ (*(_ctx_)->opm), (*(_ctx_)->total_opms), \ (_opm_num_), (_obj_num_) \ )) /* * Returns the version number. */ #define SWServGetVersion(_ctx_,_major_rtn_,_minor_rtn_,_release_rtn_) \ ((_ctx_)->get_version( \ (_major_rtn_), \ (_minor_rtn_), \ (_release_rtn_) \ )) /* * Prints the specified message to stdout. */ #define SWServPrint(_ctx_,_s_) \ ((_ctx_)->print( \ (_s_) \ )) /* * Prints the specified message to stderr. */ #define SWServPrintError(_ctx_,_s_) \ ((_ctx_)->print_err( \ (_s_) \ )) #endif /* SWSERV_PLUGINS_API_H */