1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
//
//
#include "iff_defs/iff_defs.h"
#include "weapon/beam.h"
#include "beam.h"
#include "mc_info.h"
#include "object.h"
#include "subsystem.h"
#include "team.h"
#include "vecmath.h"
#include "weaponclass.h"
extern void beam_delete(beam *b);
namespace scripting {
namespace api {
//**********HANDLE: Beam
ADE_OBJ_DERIV(l_Beam, object_h, "beam", "Beam handle", l_Object);
ADE_VIRTVAR(Class, l_Beam, "weaponclass", "Weapon's class", "weaponclass", "Weapon class, or invalid weaponclass handle if beam handle is invalid")
{
object_h *oh=NULL;
int nc=-1;
if(!ade_get_args(L, "o|o", l_Beam.GetPtr(&oh), l_Weaponclass.Get(&nc)))
return ade_set_error(L, "o", l_Weaponclass.Set(-1));
if(!oh->isValid())
return ade_set_error(L, "o", l_Weaponclass.Set(-1));
beam *bp = &Beams[oh->objp()->instance];
if(ADE_SETTING_VAR && nc > -1) {
bp->weapon_info_index = nc;
}
return ade_set_args(L, "o", l_Weaponclass.Set(bp->weapon_info_index));
}
ADE_VIRTVAR(LastShot, l_Beam, "vector", "End point of the beam", "vector", "vector or null vector if beam handle is not valid")
{
object_h *oh=NULL;
vec3d *vec3 = nullptr;
if(!ade_get_args(L, "o|o", l_Beam.GetPtr(&oh), l_Vector.GetPtr(&vec3)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(!oh->isValid())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
beam *bp = &Beams[oh->objp()->instance];
if(ADE_SETTING_VAR && vec3) {
bp->last_shot = *vec3;
}
return ade_set_args(L, "o", l_Vector.Set(bp->last_shot));
}
ADE_VIRTVAR(LastStart, l_Beam, "vector", "Start point of the beam", "vector", "vector or null vector if beam handle is not valid")
{
object_h *oh=NULL;
vec3d *v3 = nullptr;
if(!ade_get_args(L, "o|o", l_Beam.GetPtr(&oh), l_Vector.GetPtr(&v3)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
if(!oh->isValid())
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
beam *bp = &Beams[oh->objp()->instance];
if(ADE_SETTING_VAR && v3) {
bp->last_start = *v3;
}
return ade_set_args(L, "o", l_Vector.Set(bp->last_start));
}
ADE_VIRTVAR(Target, l_Beam, "object", "Target of beam. Value may also be a deriviative of the 'object' class, such as 'ship'.", "object", "Beam target, or invalid object handle if beam handle is invalid")
{
object_h *objh;
object_h *newh = nullptr;
if(!ade_get_args(L, "o|o", l_Beam.GetPtr(&objh), l_Object.GetPtr(&newh)))
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_Object.Set(object_h()));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(ADE_SETTING_VAR)
{
if(newh && newh->isValid())
{
if(bp->target_sig != newh->sig)
{
bp->target = newh->objp();
bp->target_sig = newh->sig;
}
}
else
{
bp->target = NULL;
bp->target_sig = 0;
}
}
return ade_set_object_with_breed(L, OBJ_INDEX(bp->target));
}
ADE_VIRTVAR(TargetSubsystem, l_Beam, "subsystem", "Subsystem that beam is targeting.", "subsystem", "Target subsystem, or invalid subsystem handle if beam handle is invalid")
{
object_h *objh;
ship_subsys_h *newh = nullptr;
if(!ade_get_args(L, "o|o", l_Beam.GetPtr(&objh), l_Subsystem.GetPtr(&newh)))
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(ADE_SETTING_VAR)
{
if(newh && newh->isValid())
{
if(bp->target_sig != newh->objh.sig)
{
bp->target = newh->objh.objp();
bp->target_subsys = newh->ss;
bp->target_sig = newh->objh.sig;
}
}
else
{
bp->target = NULL;
bp->target_subsys = NULL;
}
}
return ade_set_args(L, "o", l_Subsystem.Set(ship_subsys_h(bp->target, bp->target_subsys)));
}
ADE_VIRTVAR(ParentShip, l_Beam, "object", "Parent of the beam.", "object", "Beam parent, or invalid object handle if beam handle is invalid")
{
object_h *objh;
object_h *newh = nullptr;
if(!ade_get_args(L, "o|o", l_Beam.GetPtr(&objh), l_Object.GetPtr(&newh)))
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_Object.Set(object_h()));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Object.Set(object_h()));
if(ADE_SETTING_VAR)
{
if(newh && newh->isValid())
{
if(bp->sig != newh->sig)
{
bp->objp = newh->objp();
bp->sig = newh->sig;
}
}
else
{
bp->objp = NULL;
bp->sig = 0;
}
}
return ade_set_object_with_breed(L, OBJ_INDEX(bp->objp));
}
ADE_VIRTVAR(ParentSubsystem, l_Beam, "subsystem", "Subsystem that beam is fired from.", "subsystem", "Parent subsystem, or invalid subsystem handle if beam handle is invalid")
{
object_h *objh;
ship_subsys_h *newh = nullptr;
if(!ade_get_args(L, "o|o", l_Beam.GetPtr(&objh), l_Subsystem.GetPtr(&newh)))
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(!objh->isValid())
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Subsystem.Set(ship_subsys_h()));
if(ADE_SETTING_VAR)
{
if(newh && newh->isValid())
{
if(bp->sig != newh->objh.sig)
{
bp->objp = newh->objh.objp();
bp->subsys = newh->ss;
}
}
else
{
bp->objp = NULL;
bp->subsys = NULL;
}
}
return ade_set_args(L, "o", l_Subsystem.Set(ship_subsys_h(bp->objp, bp->subsys)));
}
ADE_VIRTVAR(Team, l_Beam, "team", "Beam's team", "team", "Beam team, or invalid team handle if beam handle is invalid")
{
object_h* oh = nullptr;
int nt = -1;
if (!ade_get_args(L, "o|o", l_Beam.GetPtr(&oh), l_Team.Get(&nt)))
return ade_set_error(L, "o", l_Team.Set(-1));
if (!oh->isValid())
return ade_set_error(L, "o", l_Team.Set(-1));
beam* b = &Beams[oh->objp()->instance];
if (ADE_SETTING_VAR && nt >= 0 && nt < (int)Iff_info.size())
b->team = (char)nt;
return ade_set_args(L, "o", l_Team.Set(b->team));
}
ADE_FUNC(getCollisionCount, l_Beam, NULL, "Get the number of collisions in frame.", "number", "Number of beam collisions")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Beam.GetPtr(&objh)))
return ADE_RETURN_NIL;
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ADE_RETURN_NIL;
return ade_set_args(L, "i", bp->f_collision_count);
}
ADE_FUNC(getCollisionPosition, l_Beam, "number", "Get the position of the defined collision.", "vector", "World vector")
{
object_h *objh;
int idx;
if(!ade_get_args(L, "oi", l_Beam.GetPtr(&objh), &idx))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
// convert from Lua to C
idx--;
if ((idx >= MAX_FRAME_COLLISIONS) || (idx < 0))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
// so we have valid beam and valid indexer
return ade_set_args(L, "o", l_Vector.Set(bp->f_collisions[idx].cinfo.hit_point_world));
}
ADE_FUNC(getCollisionInformation, l_Beam, "number", "Get the collision information of the specified collision",
"collision_info", "handle to information or invalid handle on error")
{
object_h *objh;
int idx;
if(!ade_get_args(L, "oi", l_Beam.GetPtr(&objh), &idx))
return ade_set_error(L, "o", l_ColInfo.Set(mc_info_h()));
// convert from Lua to C
idx--;
if ((idx >= MAX_FRAME_COLLISIONS) || (idx < 0))
return ade_set_error(L, "o", l_ColInfo.Set(mc_info_h()));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_ColInfo.Set(mc_info_h()));
// so we have valid beam and valid indexer
return ade_set_args(L, "o", l_ColInfo.Set(mc_info_h(bp->f_collisions[idx].cinfo)));
}
ADE_FUNC(getCollisionObject, l_Beam, "number", "Get the target of the defined collision.", "object", "Object the beam collided with")
{
object_h *objh;
int idx;
if(!ade_get_args(L, "oi", l_Beam.GetPtr(&objh), &idx))
return ade_set_error(L, "o", l_Object.Set(object_h()));
// convert from Lua to C
idx--;
if ((idx >= MAX_FRAME_COLLISIONS) || (idx < 0))
return ade_set_error(L, "o", l_Object.Set(object_h()));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Object.Set(object_h()));
// so we have valid beam and valid indexer
return ade_set_object_with_breed(L, bp->f_collisions[idx].c_objnum);
}
ADE_FUNC(isExitCollision, l_Beam, "number", "Checks if the defined collision was exit collision.", "boolean", "True if the collision was exit collision, false if entry, nil otherwise")
{
object_h *objh;
int idx;
if(!ade_get_args(L, "oi", l_Beam.GetPtr(&objh), &idx))
return ADE_RETURN_NIL;
// convert from Lua to C
idx--;
if ((idx >= MAX_FRAME_COLLISIONS) || (idx < 0))
return ADE_RETURN_NIL;
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ADE_RETURN_NIL;
// so we have valid beam and valid indexer
if (bp->f_collisions[idx].is_exit_collision)
return ADE_RETURN_TRUE;
return ADE_RETURN_FALSE;
}
ADE_FUNC(getStartDirectionInfo, l_Beam, NULL, "Gets the start information about the direction. The vector is a normalized vector from LastStart showing the start direction of a slashing beam", "vector", "The start direction or null vector if invalid")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Beam.GetPtr(&objh)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
beam_info inf = bp->binfo;
return ade_set_args(L, "o", l_Vector.Set(inf.dir_a));
}
ADE_FUNC(getEndDirectionInfo, l_Beam, NULL, "Gets the end information about the direction. The vector is a normalized vector from LastStart showing the end direction of a slashing beam", "vector", "The start direction or null vector if invalid")
{
object_h *objh;
if(!ade_get_args(L, "o", l_Beam.GetPtr(&objh)))
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
beam *bp = NULL;
if(objh->objp()->instance > -1)
bp = &Beams[objh->objp()->instance];
else
return ade_set_error(L, "o", l_Vector.Set(vmd_zero_vector));
beam_info inf = bp->binfo;
return ade_set_args(L, "o", l_Vector.Set(inf.dir_b));
}
ADE_FUNC(vanish, l_Beam, nullptr, "Vanishes this beam from the mission.", "boolean", "True if the deletion was successful, false otherwise.")
{
object_h* objh;
if (!ade_get_args(L, "o", l_Beam.GetPtr(&objh)))
return ADE_RETURN_FALSE;
if (!objh->isValid())
return ADE_RETURN_FALSE;
beam_delete(&Beams[objh->objp()->instance]);
return ADE_RETURN_TRUE;
}
}
}
|