Crossfire Server, Trunk  R20513
Macros | Functions
button.c File Reference

This handles triggers, buttons, altars and associated objects. More...

#include "global.h"
#include <stdlib.h>
#include <string.h>
#include "sproto.h"
Include dependency graph for button.c:

Go to the source code of this file.

Macros

#define ARCH_SACRIFICE(xyz)   ((xyz)->slaying)
 
#define NROF_SACRIFICE(xyz)   ((uint32_t)(xyz)->stats.food)
 

Functions

void add_button_link (object *button, mapstruct *map, int connected)
 Links specified object in the map. More...
 
void animate_turning (object *op)
 Animates one step of object. More...
 
int check_altar_sacrifice (const object *altar, const object *sacrifice, int remove_others, int *toremove)
 Checks whether the altar has enough to sacrifice. More...
 
void check_inv (object *op, object *trig)
 Function to search the inventory, of a player and then based on a set of conditions, the square will activate connected items. More...
 
objectcheck_inv_recursive (object *op, const object *trig)
 Checks object and its inventory for specific item. More...
 
int check_trigger (object *op, object *cause)
 
static objectlinkget_button_links (const object *button)
 Return the first objectlink in the objects linked to this one. More...
 
int get_button_value (const object *button)
 Returns the first value linked to this button. More...
 
static int matches_sacrifice (const object *altar, const object *sacrifice)
 Helper function to check if the item matches altar's requested sacrifice. More...
 
int operate_altar (object *altar, object **sacrifice)
 Checks if sacrifice was accepted and removes sacrificed objects. More...
 
void push_button (object *op)
 Push the specified object. More...
 
void remove_button_link (object *op)
 Remove the object from the linked lists of buttons in the map. More...
 
void trigger_connected (objectlink *ol, object *cause, const int state)
 Trigger every object in an objectlink. More...
 
static void trigger_move (object *op, int state)
 
void update_button (object *op)
 Updates everything connected with the button op. More...
 
void update_buttons (mapstruct *m)
 Updates every button on the map (by calling update_button() for them). More...
 
void use_trigger (object *op)
 Toggles the state of specified button. More...
 
void verify_button_links (const mapstruct *map)
 This does a minimal check of the button link consistency for object map. More...
 

Detailed Description

This handles triggers, buttons, altars and associated objects.

Definition in file button.c.

Macro Definition Documentation

#define ARCH_SACRIFICE (   xyz)    ((xyz)->slaying)

Definition at line 288 of file button.c.

Referenced by check_altar_sacrifice(), and matches_sacrifice().

#define NROF_SACRIFICE (   xyz)    ((uint32_t)(xyz)->stats.food)

Definition at line 289 of file button.c.

Referenced by check_altar_sacrifice().

Function Documentation

void add_button_link ( object button,
mapstruct map,
int  connected 
)

Links specified object in the map.

Parameters
buttonobject to link. Must not be NULL.
mapmap we are on. Should not be NULL.
connectedconnection value for the item.

Definition at line 661 of file button.c.

References mapdef::buttons, obj::count, FLAG_IS_LINKED, free_objectlink(), get_objectlink(), get_objectlinkpt(), oblnk::id, oblinkpt::link, llevError, LOG(), oblnk::next, oblinkpt::next, oblnk::ob, SET_FLAG, and oblinkpt::value.

Referenced by apply_builder_item(), and include_map_in_map().

Here is the call graph for this function:

Here is the caller graph for this function:

void animate_turning ( object op)

Animates one step of object.

Parameters
opobject to animate.
Note
animate_object() should be used instead of this, but it can't handle animations in the 8 directions
Todo:
check if object is really animated?

Definition at line 275 of file button.c.

References obj::direction, FIREWALL, NUM_ANIMATIONS, object_update(), SET_ANIMATION, liv::sp, obj::state, obj::stats, obj::type, and UP_OBJ_FACE.

Referenced by legacy_ob_process(), and trigger_connected().

Here is the call graph for this function:

Here is the caller graph for this function:

int check_altar_sacrifice ( const object altar,
const object sacrifice,
int  remove_others,
int *  toremove 
)

Checks whether the altar has enough to sacrifice.

Function put in (0.92.1) so that identify altars won't grab money unnecessarily - we can see if there is sufficient money, see if something needs to be identified, and then remove money if needed.

0.93.4: Linked objects (ie, objects that are connected) can not be sacrificed. This fixes a bug of trying to put multiple altars/related objects on the same space that take the same sacrifice.

The function will now check for all items sitting on the altar, so that the player can put various matching but non merging items on the altar.

This function can potentially remove other items, if remove_others is set.

Parameters
altaritem to which there is a sacrifice
sacrificeobject that may be sacrifed
remove_othersif 1, will remove enough items apart sacrifice to compensate for not having enough in sacrifice itself.
[out]toremovewill contain the nrof of sacrifice to really remove to finish operating. Will be set if not NULL only if the function returns 1.
Returns
1 if the sacrifice meets the needs of the altar, 0 else

Definition at line 352 of file button.c.

References ARCH_SACRIFICE, FLAG_UNPAID, FOR_ABOVE_FINISH, FOR_ABOVE_PREPARE, llevError, LOG(), obj::map, matches_sacrifice(), obj::nrof, NROF_SACRIFICE, object_decrease_nrof(), object_remove(), mapdef::path, QUERY_FLAG, and obj::value.

Referenced by identify_altar_type_move_on(), and operate_altar().

Here is the call graph for this function:

Here is the caller graph for this function:

void check_inv ( object op,
object trig 
)

Function to search the inventory, of a player and then based on a set of conditions, the square will activate connected items.

Monsters can't trigger this square (for now) Values are: last_sp = 1/0 obj/no obj triggers last_heal = 1/0 remove/dont remove obj if triggered -b.t. (thoma.nosp@m.s@no.nosp@m.mad.a.nosp@m.stro.nosp@m..psu..nosp@m.edu

Parameters
opobject to check. Must be a player.
trigtrigger object that may be activated.

Definition at line 826 of file button.c.

References check_inv_recursive(), obj::last_heal, obj::last_sp, object_decrease_nrof_by_one, PLAYER, obj::type, and use_trigger().

Referenced by check_inv_type_move_on().

Here is the call graph for this function:

Here is the caller graph for this function:

object* check_inv_recursive ( object op,
const object trig 
)

Checks object and its inventory for specific item.

It will descend through containers to find the object. slaying = match object slaying flag race = match object archetype name flag hp = match object type (excpt type '0'== PLAYER) title = match object title Searching by title only is not recommended, as it can be a rather slow operation; use it in combination with archetype or type.

Parameters
opobject of which to search inventory
trigwhat to search
Returns
object that matches, or NULL if none matched.

Definition at line 786 of file button.c.

References obj::arch, check_inv_recursive(), FOR_INV_FINISH, FOR_INV_PREPARE, liv::hp, archt::name, obj::race, obj::slaying, obj::stats, obj::title, and obj::type.

Referenced by blocked_link(), cast_create_town_portal(), check_inv(), and check_inv_recursive().

Here is the call graph for this function:

Here is the caller graph for this function:

int check_trigger ( object op,
object cause 
)
Todo:
document properly cause != NULL: something has moved on top of op

cause == NULL: nothing has moved, we have been called from animate_trigger().

TRIGGER_ALTAR: Returns 1 if 'cause' was destroyed, 0 if not.

TRIGGER: Returns 1 if handle could be moved, 0 if not.

TRIGGER_BUTTON, TRIGGER_PEDESTAL: Returns 0.

Definition at line 523 of file button.c.

References liv::ac, FOR_ABOVE_FINISH, FOR_ABOVE_PREPARE, obj::last_sp, llevDebug, LOG(), obj::move_on, obj::move_type, obj::name, NUM_ANIMATIONS, object_update(), object_update_speed(), operate_altar(), PLAYER, push(), obj::race, SET_ANIMATION, obj::slaying, obj::speed, obj::stats, TRIGGER, TRIGGER_ALTAR, TRIGGER_BUTTON, trigger_move(), TRIGGER_PEDESTAL, obj::type, UP_OBJ_FACE, obj::value, liv::wc, and obj::weight.

Referenced by animate_trigger(), apply_auto_fix(), cfapi_object_check_trigger(), do_auto_apply(), trigger_altar_type_move_on(), trigger_button_type_move_on(), trigger_pedestal_type_move_on(), trigger_type_apply(), and trigger_type_process().

Here is the call graph for this function:

Here is the caller graph for this function:

static objectlink * get_button_links ( const object button)
static

Return the first objectlink in the objects linked to this one.

Parameters
buttonobject to check. Must not be NULL.
Returns
objectlink for this object, or NULL.

Definition at line 732 of file button.c.

References mapdef::buttons, obj::count, oblnk::id, oblinkpt::link, obj::map, oblnk::next, oblinkpt::next, and oblnk::ob.

Referenced by push_button(), and update_button().

Here is the caller graph for this function:

int get_button_value ( const object button)

Returns the first value linked to this button.

Made as a separate function to increase efficiency

Parameters
buttonobject to check. Must not be NULL.
Returns
connection value, or 0 if not connected.

Definition at line 754 of file button.c.

References mapdef::buttons, obj::count, oblnk::id, oblinkpt::link, obj::map, oblnk::next, oblinkpt::next, oblnk::ob, and oblinkpt::value.

Referenced by examine(), and get_ob_diff().

Here is the caller graph for this function:

static int matches_sacrifice ( const object altar,
const object sacrifice 
)
static

Helper function to check if the item matches altar's requested sacrifice.

The number of objects is not taken into account.

Parameters
altaraltar we're checking for. Can't be NULL.
sacrificewhat object to check for. Can't be NULL.
Returns
1 if object is suitable for the altar (number not taken into account), 0 else.

Definition at line 302 of file button.c.

References obj::arch, ARCH_SACRIFICE, FLAG_ALIVE, FLAG_IS_LINKED, MAX_BUF, MONEY, obj::name, archt::name, object_get_value(), PLAYER, query_base_name(), QUERY_FLAG, obj::slaying, and obj::type.

Referenced by check_altar_sacrifice().

Here is the call graph for this function:

Here is the caller graph for this function:

int operate_altar ( object altar,
object **  sacrifice 
)

Checks if sacrifice was accepted and removes sacrificed objects.

Might be better to call check_altar_sacrifice (above) than depend on the return value, since operate_altar will remove the sacrifice also.

If this function returns 1, '*sacrifice' is modified to point to the remaining sacrifice, or is set to NULL if the sacrifice was used up.

Parameters
altaritem to which there is a sacrifice
sacrificeobject that may be sacrifed
Returns
1 if sacrifice was accepted, else 0

Definition at line 468 of file button.c.

References check_altar_sacrifice(), ext_info_map(), llevError, LOG(), obj::map, obj::msg, MSG_TYPE_DIALOG, MSG_TYPE_DIALOG_ALTAR, NDI_BLACK, object_decrease_nrof(), obj::slaying, and obj::value.

Referenced by altar_type_move_on(), check_trigger(), and identify_altar_type_move_on().

Here is the call graph for this function:

Here is the caller graph for this function:

void push_button ( object op)

Push the specified object.

This can affect other buttons/gates/handles altars/pedestals/holes in the whole map. Changed the routine to loop through all linked objects. Better hurry with that linked list...

Parameters
opobject to push.

Definition at line 154 of file button.c.

References get_button_links(), trigger_connected(), and obj::value.

Referenced by altar_type_move_on(), cf_handle_type_apply(), move_detector(), update_button(), and use_trigger().

Here is the call graph for this function:

Here is the caller graph for this function:

void remove_button_link ( object op)

Remove the object from the linked lists of buttons in the map.

This is only needed by editors.

Parameters
opobject to remove. Must be on a map, and linked.

Definition at line 698 of file button.c.

References mapdef::buttons, CLEAR_FLAG, FLAG_IS_LINKED, oblinkpt::link, llevError, LOG(), obj::map, oblnk::next, oblinkpt::next, oblnk::ob, and QUERY_FLAG.

Referenced by apply_builder_remove(), clean_object(), and delete_unique_items().

Here is the call graph for this function:

Here is the caller graph for this function:

void trigger_connected ( objectlink ol,
object cause,
const int  state 
)

Trigger every object in an objectlink.

This was originally part of push_button but has been extracted to make it possible to trigger the connected object on a map from a plugin without requiring a source object. This method will take care of calling EVENT_TRIGGER of all elligible object in list (see state parameter)

Parameters
olthe objectlink to trigger. This can be acquire from map
causethe object that cause this path to trigger, may be NULL
statewhich object to apply. 0=all object with FLAG_ACTIVATE_ON_PUSH other=all object with FLAG_ACTIVATE_ON_RELEASE

Definition at line 41 of file button.c.

References ALTAR, animate_turning(), obj::arch, BUTTON, CF_HANDLE, archt::clone, obj::count, obj::direction, DIRECTOR, EVENT_TRIGGER, execute_event(), ext_info_map(), FIREWALL, FLAG_ACTIVATE_ON_PUSH, FLAG_ACTIVATE_ON_RELEASE, FLAG_ANIMATE, FLAG_FREED, liv::food, GATE, HOLE, liv::hp, oblnk::id, obj::last_eat, llevError, LOG(), obj::map, liv::maxhp, liv::maxsp, obj::more, move_firewall(), obj::msg, MSG_SUBTYPE_NONE, MSG_TYPE_SIGN, obj::name, NDI_NAVY, NDI_UNIQUE, oblnk::next, oblnk::ob, ob_trigger(), object_update(), object_update_speed(), PEDESTAL, QUERY_FLAG, SCRIPT_FIX_ALL, SET_ANIMATION, SIGN, liv::sp, obj::speed, obj::stats, TIMED_GATE, obj::type, UP_OBJ_FACE, and obj::value.

Referenced by cfapi_map_trigger_connected(), and push_button().

Here is the call graph for this function:

Here is the caller graph for this function:

static void trigger_move ( object op,
int  state 
)
static
Todo:
document?

Definition at line 493 of file button.c.

References liv::exp, object_update_speed(), obj::speed, obj::speed_left, obj::stats, use_trigger(), and liv::wc.

Referenced by check_trigger().

Here is the call graph for this function:

Here is the caller graph for this function:

void update_button ( object op)

Updates everything connected with the button op.

After changing the state of a button, this function must be called to make sure that all gates and other buttons connected to the button reacts to the (eventual) change of state.

Parameters
opobject to update.

Definition at line 167 of file button.c.

References BUTTON, obj::count, FOR_ABOVE_FINISH, FOR_ABOVE_PREPARE, get_button_links(), obj::head, oblnk::id, llevDebug, LOG(), obj::move_on, obj::move_type, obj::name, oblnk::next, oblnk::ob, object_update(), PEDESTAL, PLAYER, push_button(), obj::race, SET_ANIMATION, obj::slaying, SPECIAL_KEY, obj::type, UP_OBJ_FACE, obj::value, and obj::weight.

Referenced by button_type_move_on(), pedestal_type_move_on(), and update_buttons().

Here is the call graph for this function:

Here is the caller graph for this function:

void update_buttons ( mapstruct m)

Updates every button on the map (by calling update_button() for them).

Definition at line 232 of file button.c.

References BUTTON, mapdef::buttons, obj::count, oblnk::id, oblinkpt::link, llevError, LOG(), obj::name, oblnk::next, oblinkpt::next, oblnk::ob, PEDESTAL, obj::type, update_button(), oblinkpt::value, obj::x, and obj::y.

Referenced by mapfile_load().

Here is the call graph for this function:

Here is the caller graph for this function:

void use_trigger ( object op)

Toggles the state of specified button.

Parameters
opobject to toggle.

Definition at line 259 of file button.c.

References push_button(), and obj::value.

Referenced by check_inv(), monster_do_talk_npc(), spring_trap(), and trigger_move().

Here is the call graph for this function:

Here is the caller graph for this function:

void verify_button_links ( const mapstruct map)

This does a minimal check of the button link consistency for object map.

All it really does it much sure the object id link that is set matches what the object has.

Will log to error level.

Parameters
mapmap to check.

Definition at line 851 of file button.c.

References mapdef::buttons, obj::count, oblnk::id, oblinkpt::link, llevError, LOG(), obj::name, oblnk::next, oblinkpt::next, and oblnk::ob.

Here is the call graph for this function: