charob_script - Outerra/anteworld GitHub Wiki

Methods

const ot::objdef_params& get_objdef_params() const
Parameter Description Returns Description
return: objdef parameters Get the objdef parameters associated with the vehicle
bool resolve_path(ot::path_rel_to ref, const coid::token& path, ifc_out coid::charstr& dst) const
Parameter Description Returns Description
ref: reference path
path: relative path
dst: resolved path
return: false on argument error Resolve relative path
iref<ot::geomob> get_geomob(int id = 0) const
Parameter Description Returns Description
id: Object ID return: geomob object Retrieve geomob
bool get_objdef_info(ifc_out ot::pkginfo::obj& info) const
Parameter Description Returns Description
info: object information return: objdef information Retrieve objdef information
coid::token get_objdef_param(const coid::token& key, const coid::token& group = coid::token()) const
Parameter Description Returns Description
key: parameter key
group: group
return: parameter value Retrieve parameter from objdef
uint get_collision_group(ifc_out uint* mask) const
Parameter Description Returns Description
mask: optional mask value return: collision group id Get the collision group and mask
void set_collision_group(uint group, uint mask) const
Parameter Description Returns Description
group: collision group id
mask: collision mask
Set the collision group and mask
void fade(const coid::token& text) const
Parameter Description Returns Description
text: message to post to the fading log Post message to the fading log
ot::ECameraMode get_camera_mode() const
Parameter Description Returns Description
return: camera mode Get the camera mode
uint64 get_custom_data_value() const
Parameter Description Returns Description
return: custom data value Get the custom data value
float3 heading_pitch_roll() const
Parameter Description Returns Description
return: heading/pitch/roll angles Get heading/pitch/roll angles of the object in radians
void extra_force(const float3& mpos, const float3& force, bool worldspace = false) const
Parameter Description Returns Description
mpos: model-space postion to act on
force: model or world-space force vector
worldspace: true for world-space, false for model-space force vector
Add extra force to be applied to the object.
Multiple accumulated forces will remain active in simulation frames up until the next time extra forces are added.
To reset forces, an extra_force call with zero force vector needs to be called in sim or update frame
void extra_impulse(const float3& mpos, const float3& impulse, bool worldspace = false) const
Parameter Description Returns Description
mpos: model-space postion to act on
impulse: model or world-space force impulse vector
worldspace: true for world-space, false for model-space force vector
Apply extra force impulse (force * dt), one-time impulse, non-persistent
uint get_joint_id(const coid::token& name) const
Parameter Description Returns Description
name: Name of the joint return: joint/bone id or -1 if doesn't exist Get the joint/bone id for given bone name
uint get_mesh_id(const coid::token& name, uint8 lod_group = 0xff, uint8 mat_group = 0xff) const
Parameter Description Returns Description
name: Name of the mesh
lod_group: lod group for given base name (0xff if all lod groups)
mat_group: material group for given base name (0xff if all material groups)
return: mesh id for given params or -1 if doesn't exist Gets the mesh id
void fire(const float3& pos, const float3& dir, float speed, float caliber, const float3& color, uint joint = pkg::InvalidBoneId) const
Parameter Description Returns Description
pos: model-space launch position
dir: model-space launch direction
speed: firing velocity in m/s
caliber: diameter of the ray [m]
color: plasma color
joint: bone id to attach to
Fire a colored plasma projectile
void explode_ground(const ot::ground_explosion& ge) const
Parameter Description Returns Description
ge: explosion parameters Explode ground at model position
float elevation_test(const float3& pos, float maxdist, float negdist = -FLT_MIN, uint joint = pkg::InvalidBoneId) const
Parameter Description Returns Description
pos: model-space position
maxdist: max distance/height to check
negdist: max negative distance to test
joint: [optional] bone id to be relative to
return: height above terrrain or >= maxdist if no hit, <= negdist if under terrain Elevation test
float elevation_test_ext(const float3& pos, float maxdist, float negdist = -FLT_MIN, ifc_out ot::hitpoint* hp = 0, ot::hit_flags hpflags = {.hit = true, .normal = true}, uint joint = pkg::InvalidBoneId) const;
Parameter Description Returns Description
pos: model-space position
maxdist: max distance/height to check
negdist: max negative distance to test
hp: [out, optional] hitpoint result
hpflags: [optional] query flags (ot::hit_flags)
joint: [optional] bone id to be relative to
return: height above terrain or >= maxdist if no hit, <= negdist if under terrain Elevation test with extended info
float ray_test(const float3& pos, const float3& dir, float maxdist, float negdist = -FLT_MIN, ot::hitpoint* hp = 0, ot::hit_flags hpflags = {.hit = true, .normal = true}, uint joint = pkg::InvalidBoneId)
Parameter Description Returns Description
pos: model-space (or bone-space) position
dir: model-space (or bone-space) ray direction
maxdist: max distance/height to check
negdist: max negative distance to test
hp: [out, optional] hitpoint result
hpflags: [optional] query flags (ot::hit_flags)
joint: [optional] bone id to be relative to
return: intersection distance or >= maxdist if no hit, <= negdist if under terrain Test if ray from model intersects with terrain
iref<ot::object> object_test(const float3& pos, const float3& dir, float maxdist, ot::hitpoint* hp = 0, ot::hit_flags hpflags = {.hit = true, .normal = true, .objects = true, .dynamic = true, .selftest = false}, uint joint)
Parameter Description Returns Description
pos: model-space (or bone-space) position
dir: model-space (or bone-space) ray direction
maxdist: max ray distance to check (keep short if possible)
hp: [out, optional] hitpoint result
hpflags: [optional] query flags (ot::hit_flags)
joint: bone id to be relative to
return: object hit Test if ray from model hits an object
void attach_object(const iref<ot::object>& obj, uint joint_id, const float3& pos, const quat& rot, uint custom_id)
Parameter Description Returns Description
obj: Object to attach
joint_id: bone id
pos: attachment position
rot: attachment rotation
custom_id: id that can be used to identify the attached object when detaching
Attach object
iref<ot::object> detach_object(uint custom_id, bool activate)
Parameter Description Returns Description
custom_id: id set previously by attach_geom
activate: activate object (if it's not a static one)
return: detached object, if found Detach specified object
iref<ot::object> get_attached_to() const;
Parameter Description Returns Description
return: the object this object is attached to or nullptr if this object is free Get object we are attached to
bool detach_ot_object(const iref<ot::object>& object, bool activate)
Parameter Description Returns Description
object: attached object
activate: activate object (if it's not a static one)
return: true if successful Detach specified object
void set_fps_camera_pos(const float3& pos, uint joint_id = UMAX32, ot::EJointRotationMode joint_rotation = ot::JointRotModeEnable)
Parameter Description Returns Description
pos: position to set
joint_id: to set position to bone position
joint_rotation: to set rotation based on bone rotation
Set model space position for FPS camera
void set_fps_camera_rot(const quat& rot, ot::ERotationMode mouse_rotation)
Parameter Description Returns Description
rot: model space rotation
mouse_rotation: rotation mode:
0 freeze,
1 reset&disable,
2 enable,
3 reset & enable
Set model space rotation frame
void set_fps_camera_fov(float hfov, float vfov = 0)
Parameter Description Returns Description
hfov: horizontal fov in degrees, 0 to reset to the default one
vfov: optional vertical fov in degrees, otherwise computed from aspect ratio
Set FOV to chassis FPS preset and also to the current camera if vehicle is entered and FPC camera is active
float3 get_fps_camera_pos()
Parameter Description Returns Description
return: current FPS camera position Get current FPS camera position
quat get_fps_camera_rot(bool base = false)
Parameter Description Returns Description
base: true for the base orientation frame, false for current camera orientation as altered by mouse return: camera rotation Get current FPS camera rotation in model space
float2 get_fps_camera_fov()
Parameter Description Returns Description
return: camera FOV Get FPS camera FOV
void set_fps_camera_ypr(float yaw, float pitch, float roll, ot::ERotationMode mouse_rotation)
Parameter Description Returns Description
yaw: yaw angle in radians, positive values to the right
pitch: pitch pitch angle in radians, positive up
roll: roll angle in radians, positive clockwise
mouse_rotation: rotation mode:
0 freeze,
1 reset&disable,
2 enable,
3 reset & enable
Set model space orientation for FPS camera
float3 get_fps_camera_ypr(bool base = false)
Parameter Description Returns Description
base: true for the base orientation frame, false for current camera orientation as altered by mouse return: yaw/pitch/roll angles Get current yaw/pitch/roll angles of the camera in model space
bool set_fps_camera_tracking_point(const double3& target, bool level_horizon)
Parameter Description Returns Description
target: ECEF coordinates of the point
level_horizon: keep horizon level (roll the camera)
return: true if tracking was enabled, false if center wasn't on terrain or the current camera mode is not FPS Enable tracking of world point
bool set_fps_camera_tracking(bool level_horizon)
Parameter Description Returns Description
level_horizon: keep horizon level (roll the camera) return: true if tracking was enabled, false if center wasn't on terrain or the current camera mode is not FPS Enable tracking of the current world point (in screen center)
bool set_fps_camera_tracking_off()
Parameter Description Returns Description
Disable tracking
iref<ot::sndgrp> sound()
Parameter Description Returns Description
return: ot::snd_group interface Get sound interface
int register_handler_ext(const coid::token& name, uint group = 0)
Parameter Description Returns Description
name: hierarchic action name, file/group/action
group: activation group where the action is assigned (can be enabled/disabled together)
return: slot id or -1 on fail Register action handler for an existing knob
int register_event_ext(const coid::token& name, bool release_event, uint group)
Parameter Description Returns Description
name: hierarchic action name, file/group/action
release_event: true if handler should also receive release events (if bound to key)
group: activation group where the action is assigned (can be enabled/disabled together)
return: slot id or -1 on fail Register event action handler
int register_axis_ext(const coid::token& name, const ot::ramp_params& ramp, uint group = 0)
Parameter Description Returns Description
name: hierarchic action name, file/group/action
ramp: value limiter parameters (ignored for buttons)
group: activation group where the action is assigned (can be enabled/disabled together)
return: slot id or -1 on fail Register axis action handler
int register_handler(const coid::token& name, ot::fn_event_action&& handler, int handler_id, uint group)
Parameter Description Returns Description
name: hierarchic action name, file/group/action
handler: handler for changed value, void fn(int flags, uint code, uint channel, int handler_id)
handler_id: optional extra data for the handler
group: activation group where the action is assigned (can be enabled/disabled together)
return: slot id or -1 on fail Register input action for an existing knob, create new using def_ramp if doesn't exist
int register_handler_default(const coid::token& name, ot::fn_event_action&& handler, const ot::ramp_params& def_ramp, int handler_id, const float* def_val, uint group)
Parameter Description Returns Description
name hierarchic action name, file/group/action
handler handler for changed value, void fn(int flags, uint code, uint channel, int handler_id)
def_ramp: action options to use if knob wasn't found, if nullptr do not create
handler_id: optional extra data for the handler
def_val: optional default action value
group: activation group where the action is assigned (can be enabled/disabled together)
return: slot id or -1 on fail Register input action for an existing knob, if doesn't exist create new if def_ramp
int register_axis_handler(const coid::token& name, ot::fn_axis_action&& handler, const ot::ramp_params& ramp, int handler_id = 0, const float* def_val = nullptr, uint group = 0);
Parameter Description Returns Description
name: hierarchic action name, file/group/action
handler: optional handler for changed value, void fn(float val, uint code, uint channel, int handler_id)
ramp: ramp parameters
handler_id: optinal extra data for the handler
def_val: optional default action value
ramp: value limiter parameters
group: activation group where the action is assigned (can be enabled/disabled together)
return: slot ID or -1 on fail Register input action sending events on value change (full state button and axis)
int register_event_handler(const coid::token& name, ot::fn_event_action&& handler, int handler_id = 0, uint group = 0, uint extra_channels = 0);
Parameter Description Returns Description
name: hierarchic action name, file/group/action
handler: optional handler for changed value, void fn(int flags, uint code, uint channel, int handler_id)
handler_id: optional extra data for the handler
group: activation group where the action is assigned (can be enabled/disabled together)
extra_channels: number of extra channels that are handled (multiple engines etc)
return: slot ID or -1 on fail Register input action sending events on button press (value > 0)
int get_action_id(const coid::token& name) const;
Parameter Description Returns Description
return: action id, -1 if not found Get action id for given action name, -1 if not found
void action_group(uint group, bool activate);
Parameter Description Returns Description
group: group id
activate: activate/deactivate the group
Activate or deactivate the given action group
void set_center_value(int action, float center);
Parameter Description Returns Description
action: action id
center: center value, will be clamped to minval..maxval range
Set the value to center to, default 0
void set_action_value(int action, float value, bool hold);
Parameter Description Returns Description
action: action id
value: target action value, will be clamped to minval..maxval range
hold: true if the value should be held (disabled centering)
Set target action value
void set_instant_action_value(int action, float value, bool notify);
Parameter Description Returns Description
action: action id
value: instant action value, will be clamped to minval..maxval range
notify: invoke/don't invoke the handler
Set instant action value
uint add_spot_light(const float3& offset, const float3& dir, const ot::light_params& lp, const coid::token& joint = coid::token());
Parameter Description Returns Description
offset: model-space offset relative to the bone or model pivot
dir: light direction
lp: light parameters
joint: joint name to attach the light to
return: light emitter id Define a circular spotlight source. Can only be called from within init_chassis
uint add_point_light(const float3& offset, const ot::light_params& lp, const coid::token& joint = coid::token());
Parameter Description Returns Description
offset: model-space offset relative to the bone or model pivot
lp: light parameters
joint: joint name to attach the light to
return: light emitter ID Define a point light source. Can only be called from within init_chassis
void light(uint id, bool on);
Parameter Description Returns Description
id: light id
on: boolean flag to turn the light on/off
Turn light on or off
void light_mask(uint mask, bool on, uint offset = 0);
Parameter Description Returns Description
mask: bitmask for selecting lights
on: boolean flag to turn lights on/off
offset: optional offset for light bitmask
Turn lights on or off using a bitmask
void light_toggle(uint id);
Parameter Description Returns Description
id: light id Toggle the state of a light (on/off)
void light_toggle_mask(uint mask, uint offset = 0);
Parameter Description Returns Description
mask: bitmask for selecting lights
offset: optional offset for light bitmask
Toggle lights using a bitmask
void light_color(uint id, const float4& color, float range = 0);
Parameter Description Returns Description
id: light id
color: color and intensity of the light
range: optional range
Set the color and intensity of a light
void lights_off(bool instant = false);
Parameter Description Returns Description
instant: boolean flag to instantly turn off lights Turn off all lights with an option to turn them off instantly
void solar_time(ifc_out double& time, ifc_out float& sun_coef) const;
Parameter Description Returns Description
time: [out] solar time at vehicle location [s]
sun_coef: sun position relative to horizon: 0 sun at horizon, 1 sun at zenith, -1 sun at anti-zenith
Return current solar time and cosine of sun-zenith angle
int add_display(float width, float height, const coid::token& mesh_name);
Parameter Description Returns Description
width: display width
height: display height
mesh_name: name of the display mesh in geomob
return: ID of the display Add a new display
iref<ot::canvas> get_display_canvas(uint display_id);
Parameter Description Returns Description
display_id: id of the display return: canvas reference Get the canvas of a display
coid::dynarray<coid::charstr> get_display_names();
Parameter Description Returns Description
return: dynamic array of display names Get display names
uint add_smoke_emitter(const coid::token& joint, const coid::token& texture, const ot::particle_emitter_params& params);
Parameter Description Returns Description
joint: name of the joint emitter will be attached to
texture: relative path of the texture to use as particle billboard (must be in RGBA8 dds format)
params: emitter parameters
return: emitter ID Add a smoke emitter
uint add_dust_emitter(const coid::token& joint, const coid::token& texture);
Parameter Description Returns Description
joint: name of the joint emitter will be attached to
texture: relative path to the particle texture
return: emitter ID Add a dust emitter. Call in init_chassis
void set_emitter_color(uint emitter, ot::color color);
Parameter Description Returns Description
emitter: emitter id
color: particle color
Set overall emitter color
void pause_emitter(uint emitter, bool pause);
Parameter Description Returns Description
emitter: emitter id
pause: boolean flag to pause/unpause the emitter
Pause or unpause the emitter
uint load_sound(const coid::token& filename);
Parameter Description Returns Description
filename: path to the sound file return: sound id Load sound
uint add_sound_emitter(const coid::token& joint, int type = 0, float ref_distance = 0);
Parameter Description Returns Description
joint: bone name to attach to
type: sound type (-1 = interior, 0 = universal, 1 = exterior)
ref_distance: reference distance (saturated volume distance)
return: sound emitter ID Attach a sound emitter to a model joint by name
uint add_sound_emitter_id(uint joint_id, int type = 0, float ref_distance = 0);
Parameter Description Returns Description
joint_id: bone id to attach to
type: sound type (-1 = interior, 0 = universal, 1 = exterior)
ref_distance: reference distance (saturated volume distance)
return: sound emitter id Attach a sound emitter to a model joint by id
void set_interior_sound_attenuation(float att);
Parameter Description Returns Description
att: attenuation value Set attenuation for sounds coming from outside
void fetch_controls(coid::dynarray32<int32>& buf, bool append);
Parameter Description Returns Description
buf: Array to store retrieved control commands or states
append: true ifcontrols should be appended
Fetch controls
void apply_controls(const int32* cmd, uint ncmds);
Parameter Description Returns Description
cmd: controls to apply
ncmds: number of commands to process.
Apply commands
void open(int openid, ot::kbd_modifier modifiers);
Parameter Description Returns Description
openid: ID of the openable part (script specific)
modifiers: keyboard modifiers (LSHIFT=1, RSHIFT=2, LCTRL=4, RCTRL=8)
Insert an open door command
coref<ot::component::animator> get_animator();
Parameter Description Returns Description
return: animator component Get the animator component
iref<ot::object> spawn_object(const coid::token& model, const float3& pos, const glm::quat& rot, bool persistent);
Parameter Description Returns Description
model: full model path under packages directory
pos: relative position of the pivot point
rot: relative orientation of the model
persistent: true if the object should persist in the world
return: reference to the spawned object Spawn object
iref<ot::object> object_test_from_camera(float maxdist, ifc_out ot::hitpoint* hp = 0, ot::hit_flags hpflags = {.hit = true, .normal = true, .objects = true, .dynamic = true, .selftest = false}) const;
Parameter Description Returns Description
maxdist: max ray distance to check (keep short if possible)
hp: [out, optional] hitpoint result
hpflags: [optional] query flags (ot::hit_flags)
return: object hit Test if ray from camera hits an object
iref<ot::object> get_object_in_focus() const;
Parameter Description Returns Description
return: object that is in focus Get object that is currently in focus
void move(const float3& pos, float yawd = 0.0f, float pitch = 0.0f, float roll = 0.0f);
Parameter Description Returns Description
pos: relative position in tangent space, x side, y forward, z up
yawd: yaw angle delta [rad]
pitch: pitch angle [rad]
roll: roll angle [rad]
Move character relatively in tangent space. Only dynamic game objects can move
void rotate(const float3& fwd);
Parameter Description Returns Description
fwd: forward vector to align to (in ecef space) Set the rotation. Use this method mainly for initial setup of object's rotation, during runtime is better to rotate by move method
iref<ot::interactor> enter_vehicle(const iref<ot::object>& obj, uint bone_id = pkg::InvalidBoneId, bool preserve_position = true, const float3& pos = float3(), const quat& rot = quat(), ot::ECameraMode camode = ot::CamPrevious, ot::EControlsBinding bindio = ot::BindControls);
Parameter Description Returns Description
obj: object that should be entered. If this is a static scenery object, returned object may be different due to activation. Can be null if re-entering a different bone
bone_id: bone to attach this to. When invalid, model pivot is used
preserve_position: true to try and preserve current world position relative to the bone, false to reset to the bone
pos: relative position after entering
rot: relative rotation after entering
camode: camode camera mode to use bindio: bindio bind user controls
return: entered object (can be different than the one passed in, in case static object was awakened) Enter vehicle/interactor object
void exit_vehicle(bool preserve_position, const float3& pos = float3(), const quat& rot = quat(), ot::ECameraMode camode = ot::CamPrevious);
Parameter Description Returns Description
preserve_position: true to try and preserve current world position relative to the bone, false to reset to the bone
pos: relative position of this object to obj after exit
rot: relative rotation of this object to obj after exit
camode: camera mode to use
Exit entered object. Right now it is usable only for vehicles

Events

virtual ot::chassis_params init_chassis(const coid::charstr& params);
Parameter Description Returns Description
params: custom parameters from objdef return: ot::chassis_params Initialize chassis shared across all instances of the same type
virtual ot::chassis_params init_chassis_script(const coid::charstr& params);
Parameter Description Returns Description
params: custom parameters from objdef return: ot::chassis_params Initialize chassis from a script. This is typically used for scripted chassis initialization
virtual void update_actions_script(float dt, const coid::range<int32>& actbuf);
Parameter Description Returns Description
dt: delta time since the last update
actbuf: range of actions to process from the script
Invoke registered actions on the script side
virtual void engine(bool start);
Parameter Description Returns Description
start: boolean flag to start or stop the engine Called when engine is started/stopped
virtual float ext_param(const coid::token& name, const float* value);
Parameter Description Returns Description
name: name of the external parameter
value: value to set (or null to request the current value)
return: the new or existing parameter value Set/get an externally provided parameter
virtual void initialize(bool reload);
Parameter Description Returns Description
reload: boolean flag to indicate if the object is being reloaded Initialize the object instance
virtual void visual_update(float dt, float dtinterp);
Parameter Description Returns Description
dt: delta time since the last update
dtinterp: interpolation time ahead from the last simulation state
Update the object's visual model for rendering. Called each frame
virtual void simulation_step(float dt);
Parameter Description Returns Description
dt: delta time for the simulation step Called 60 times per second
virtual bool wants_tps_focus();
Parameter Description Returns Description
return:
virtual bool on_use();
Parameter Description Returns Description
return: true if the use action was handled Invoked to handle the player's "use" action. Use get_object_in_focus() to get the object to interact with
virtual bool on_open();
Parameter Description Returns Description
return: true if the open action was handled Invoked to handle the player's "open" action. Use get_object_in_focus() to get the object to interact with
virtual bool on_enter(uint joint);
Parameter Description Returns Description
joint: bone ID of the part being entered, or -1 return: true if the enter action was handled Invoked when character can enter an object. Use get_object_in_focus() to get the object to interact with
virtual void on_camera(ot::ECameraMode mode);
Parameter Description Returns Description
mode: camera mode or ot::CamFree on exit Invoked on camera change
virtual void on_activated();
Parameter Description Returns Description
Invoked when this object is used as interactor "entered by camera"
virtual void on_deactivated();
Parameter Description Returns Description
virtual void on_knob_action(uint16 action_id);
Parameter Description Returns Description
action_id: index of action as given in enter_object call Called when entered in object and that object is handling action registered from knobs
virtual void on_seat_action(uint16 seat_id);
Parameter Description Returns Description
seat_id: id of the seat
virtual void force_bind_script_events();
Parameter Description Returns Description
⚠️ **GitHub.com Fallback** ⚠️