2023-07-24 00:56:01 +02:00
|
|
|
#ifndef LIB_OBJ_H
|
|
|
|
|
#define LIB_OBJ_H
|
2023-06-04 11:57:41 +02:00
|
|
|
|
2023-06-08 21:36:09 +02:00
|
|
|
#include "define_lite.h"
|
|
|
|
|
#include "define_extra.h"
|
|
|
|
|
|
2024-05-19 00:15:01 +02:00
|
|
|
/**
|
2024-05-20 12:41:02 +02:00
|
|
|
* Object name or (null) if it's 0. Helps to avoid crashes when debugging.
|
|
|
|
|
* @arg {ObjectPtr} obj
|
|
|
|
|
* @ret {string}
|
2024-05-19 00:15:01 +02:00
|
|
|
*/
|
2023-06-04 11:57:41 +02:00
|
|
|
#define obj_name_safe(obj) (obj_name(obj) if obj else "(null)")
|
2024-05-19 00:15:01 +02:00
|
|
|
|
|
|
|
|
/**
|
2024-05-20 12:41:02 +02:00
|
|
|
* Active weapon of a given *critter* (player or NPC).
|
|
|
|
|
* @arg {ObjectPtr} critter
|
|
|
|
|
* @ret {ObjectPtr}
|
2024-05-19 00:15:01 +02:00
|
|
|
*/
|
2023-06-04 11:57:41 +02:00
|
|
|
#define get_active_weapon(critter) critter_inven_obj(critter, (2 - active_hand) if critter == dude_obj else INVEN_TYPE_RIGHT_HAND)
|
2024-05-19 00:15:01 +02:00
|
|
|
|
|
|
|
|
/**
|
2024-05-20 12:41:02 +02:00
|
|
|
* Checks if given *critter* has line-of-fire to the given *target*.
|
|
|
|
|
* In FO2, regular "line of sight" checks are usually unreliable, due to how scenery flags are configured. So LoF checks are a good alternative.
|
|
|
|
|
* @arg {ObjectPtr} critter
|
|
|
|
|
* @arg {ObjectPtr} target
|
|
|
|
|
* @ret {bool}
|
2024-05-19 00:15:01 +02:00
|
|
|
*/
|
2023-07-30 22:24:44 +02:00
|
|
|
#define obj_has_lof_to_obj(critter, target) (obj_blocking_line(critter, tile_num(target), BLOCKING_TYPE_SHOOT) == target)
|
2024-05-19 00:15:01 +02:00
|
|
|
|
|
|
|
|
/**
|
2024-05-20 12:41:02 +02:00
|
|
|
* Checks if given *critter* has line-of-fire to *target* and also passes a normal perception check (can "hear" it).
|
|
|
|
|
* @arg {ObjectPtr} critter
|
|
|
|
|
* @arg {ObjectPtr} target
|
|
|
|
|
* @ret {bool}
|
2024-05-19 00:15:01 +02:00
|
|
|
*/
|
2023-07-30 22:24:44 +02:00
|
|
|
#define obj_can_hear_and_shoot_obj(critter, target) (obj_can_hear_obj(critter, target) and obj_has_lof_to_obj(critter, target))
|
2023-06-04 11:57:41 +02:00
|
|
|
|
2023-07-10 23:56:58 +02:00
|
|
|
#endif
|