Ejemplo n.º 1
0
// cinematic.Activate(entity ent, entity target)
// Activates Camera on ent and points it at target.
static int Cinematic_Activate(lua_State *L) {
	lent_t *ent;
	lent_t *target;

	ent = Lua_GetEntity(L, 1);
	if(!ent) return 0;

	target = Lua_GetEntity(L, 2);
	if(!target) return 0;

	Cinematic_ActivateCameraMode(ent->e, target->e);

	return 0;
}
Ejemplo n.º 2
0
static int weapon_Damage(lua_State *L) {
	gentity_t *target, *inflictor, *attacker;
	vec_t *dir, *point;
	int damage, dflags, mod;

	target = Lua_GetEntity(L, 1)->e;
	inflictor = Lua_GetEntity(L, 2)->e;
	attacker = Lua_GetEntity(L, 3)->e;
	dir = Lua_GetVector(L, 4);
	point = Lua_GetVector(L, 5);
	damage = (int)luaL_checknumber(L, 6);
	dflags = (int)luaL_checknumber(L, 7);
	mod = (int)luaL_checknumber(L, 8);

	G_Damage(target, inflictor, attacker, dir, point, damage, dflags, mod);

	return 0;
}
Ejemplo n.º 3
0
/***
Moves ent with a given speed to the specified values. Can also be stowed in a vector pos.
@function ToPosition
@param ent Entity or entity number.
@param speed Speed to move with.
@param x X coordinates.
@param y Y coordinates.
@param z Z coordinates.
@return Success or failure.
*/
static int Mover_ToPosition(lua_State * L)
{
	vec3_t          newOrigin;
	lent_t			*lent;
	gentity_t      *ent = NULL;
	float           speed;
	vec_t          *target;
	int				id = 0;

	if(lua_isnumber(L, 1)) {
		id = luaL_checkint(L, 1);
		if(id < 0 ||id > MAX_GENTITIES - 1) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = &g_entities[id];
		if(ent == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
	} else {
		lent = Lua_GetEntity(L,1);
		if(lent == NULL || lent->e == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = lent->e;
	}

	speed = (float)luaL_checknumber(L, 2);

	if(Lua_IsVector(L, 3))
	{
		target = Lua_GetVector(L, 3);
		VectorCopy(target, newOrigin);
	}
	else
	{
		newOrigin[0] = luaL_checkint(L, 3);
		newOrigin[1] = luaL_checkint(L, 4);
		newOrigin[2] = luaL_checkint(L, 5);
	}
	

	LUA_DEBUG("Mover_ToPosition - start: ent=%d pos=%s speed=%f", ent->s.number, vtos(newOrigin), speed);
	if(ent)
	{
		BG_EvaluateTrajectory(&ent->s.pos, level.time, ent->s.pos.trBase);
		SetTrajectoryLinear(&ent->s.pos, speed, newOrigin);
		ent->moverState = MOVER_LUA;
		trap_LinkEntity(ent);
		LUA_DEBUG("Mover_ToPosition - return: moving");
	}
	lua_pushboolean(L, qtrue);
	return 1;
}
Ejemplo n.º 4
0
/***
Damage and player or entity.
@function Damage
@param target Target entity.
@param inflictor Inflicting entity. Can be nil.
@param attacker Attacking entity. Can be nil.
@param direction Direction of knockback. Can be nil.
@param point Point where the damage is inflicted. Can be nil.
@param damage Ammount of damage.
@param dflags Damage flags.
@param mod Means of death.
@return Success or fail.
*/
static int Game_Damage(lua_State *L) {
	lent_t *lent;
	gentity_t *targ = NULL, *inflictor = NULL, *attacker = NULL;
	vec_t *dir = NULL, *point = NULL;
	int damage = 0, dflags = 0, mod = 0;

	LUA_DEBUG("BEGIN - game.Damage");

	lent = Lua_GetEntity(L, 1);
	if(lent == NULL || lent->e == NULL) {
		LUA_DEBUG("ERROR - game.Damage - entity NULL");
		lua_pushboolean(L, qfalse);
		return 1;
	}
	targ = lent->e;
	if(!lua_isnil(L, 2)) {
		lent = Lua_GetEntity(L, 2);
		if(lent && lent->e)  {
			inflictor = lent->e;
		}
	}
	if(!lua_isnil(L, 3)) {
		lent = Lua_GetEntity(L, 3);
		if(lent && lent->e) {
			attacker = lent->e;
		}
	}
	if(!lua_isnil(L, 4)) {
		dir = Lua_GetVector(L, 4);
	}
	if(!lua_isnil(L, 5)) {
		point = Lua_GetVector(L, 5);
	}
	damage = (int)luaL_checknumber(L, 6);
	dflags = (int)luaL_checknumber(L, 7);
	mod = (int)luaL_checknumber(L, 8);

	G_Damage(targ, inflictor, attacker, dir, point, damage, dflags, mod);

	lua_pushboolean(L, qtrue);
	LUA_DEBUG("END - game.Damage");
	return 1;
}
Ejemplo n.º 5
0
// cinematic.ActivateGlobal(entity target)
// Activates broadcasting of target.
static int Cinematic_ActivateGlobal(lua_State *L) {
	lent_t *target;

	target = Lua_GetEntity(L, 2);
	if(!target) return 0;

	Cinematic_ActivateGlobalCameraMode(target->e);

	return 0;
}
Ejemplo n.º 6
0
// cinematic.Deactivate(entity ent)
// Deactivates camera on ent.
static int Cinematic_Deactivate(lua_State *L) {
	lent_t *ent;

	ent = Lua_GetEntity(L, 1);
	if(!ent) return 0;

	Cinematic_DeactivateCameraMode(ent->e);

	return 0;
}
Ejemplo n.º 7
0
/***
Set the position of ent to the specified value.
@function SetPosition
@param ent Entity or entity number.
@param vec Vector containing the new position.
@return Success or failure.
*/
static int Mover_SetPosition(lua_State * L)
{
	vec3_t          newOrigin;
	lent_t			*lent;
	gentity_t      *ent = NULL;
	vec_t          *target;
	int				id = 0;

	if(lua_isnumber(L, 1)) {
		id = luaL_checkint(L, 1);
		if(id < 0 || id > MAX_GENTITIES - 1) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = &g_entities[id];
		if(ent == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
	} else {
		lent = Lua_GetEntity(L, 1);
		if(lent == NULL || lent->e == NULL)
		{
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = lent->e;
	}

	if(Lua_IsVector(L, 2))
	{
		target = Lua_GetVector(L, 2);
		VectorCopy(target, newOrigin);
	}
	else
	{
		newOrigin[0] = luaL_checkint(L, 2);
		newOrigin[1] = luaL_checkint(L, 3);
		newOrigin[2] = luaL_checkint(L, 4);
	}
	LUA_DEBUG("Mover_SetPosition - start: ent=%d pos=%s", ent->s.number, vtos(newOrigin));
	if(ent)
	{
		G_SetOrigin(ent, newOrigin);
		trap_LinkEntity(ent);
		LUA_DEBUG("Mover_SetPosition - return: moved");
	}
	lua_pushboolean(L, qtrue);
	return 1;
}
Ejemplo n.º 8
0
// sound.PlaySound(entity ent, string sound, integer chan)
// * ent the entity the sound will be played on
// * sound the sound file which will be played
// * chan the sound channel the sound will be played on
static int Sound_PlaySound(lua_State *L) {
	char	*sound;
	int		snd;
	int		chan;
	lent_t	*l;

	l = Lua_GetEntity(L,1);
	if(!l || !l->e) return 1;

	sound = (char*)luaL_checkstring(L,2);
	if(!sound[0]) return 1;

	chan = luaL_checknumber(L,3);

	snd = G_SoundIndex(sound);
	G_AddEvent(l->e, EV_SCRIPT_SOUND, snd + (chan << 8));

	return 1;
}
Ejemplo n.º 9
0
/***
Repair an entity.
@function Repair
@param target Target entity.
@param rate Repair rate.
@return Success or fail.
*/
static int Game_Repair(lua_State *L) {
	lent_t *lent;
	float rate;

	LUA_DEBUG("BEGIN - game.Repair");

	lent = Lua_GetEntity(L, 1);
	if(lent == NULL || lent->e == NULL) {
		LUA_DEBUG("ERROR - game.Repair - entity NULL");
		lua_pushboolean(L, qfalse);
		return 1;
	}
	
	rate = (float)luaL_checknumber(L, 2);

	G_Repair(lent->e, NULL, rate); // FIXME ... trance ent?

	LUA_DEBUG("END - game.Repair");
	lua_pushboolean(L, qtrue);
	return 1;
}
Ejemplo n.º 10
0
/***
Stops rotational movement on ent immediately.
@function HaltAngles
@param ent Entity or entity number.
@return Success or failure.
*/
static int Mover_HaltAngles(lua_State * L)
{
	lent_t			*lent;
	gentity_t       *ent = NULL;
	int				id = 0;

	if(lua_isnumber(L, 1)) {
		id = luaL_checkint(L, 1);
		if(id < 0 || id > MAX_GENTITIES - 1) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = &g_entities[id];
		if(ent) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
	} else {
		lent = Lua_GetEntity(L, 1);
		if(lent == NULL || lent->e == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = lent->e;
	}

	LUA_DEBUG("Mover_HaltAngles - start: ent=%d", ent->s.number);
	if(ent)
	{
		BG_EvaluateTrajectory(&ent->s.apos, level.time, ent->s.apos.trBase);
		ent->s.apos.trType = TR_STATIONARY;
		ent->s.apos.trTime = level.time;
		trap_LinkEntity(ent);
		LUA_DEBUG("Mover_HaltAngles - return: halted ent");
	}

	lua_pushboolean(L, qtrue);
	return 1;
}
Ejemplo n.º 11
0
/***
Stops translational movement on ent immediately.
@function Halt
@param ent Entity or entity number.
@return Success or failure.
*/
static int Mover_Halt(lua_State *L) {
	lent_t		*lent;
	gentity_t	*ent = NULL;
	int			id = 0;
	
	if(lua_isnumber(L, 1)) {
		id =  luaL_checkint(L, 1);
		if(id < 0 || id > MAX_GENTITIES - 1) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = &g_entities[id];
		if(ent == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
	} else {
		lent = Lua_GetEntity(L, 1);
		if(lent == NULL || lent->e == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = lent->e;
	}

	LUA_DEBUG("Mover_Halt - start: end=%d", ent->s.number);
	BG_EvaluateTrajectory(&ent->s.pos, level.time, ent->r.currentOrigin);
	VectorCopy(ent->r.currentOrigin, ent->s.pos.trBase);
	ent->s.pos.trType = TR_STATIONARY;
	ent->s.pos.trTime = level.time;
	ent->nextthink = 0;
	ent->think = NULL;
	ent->nextTrain = NULL;
	trap_LinkEntity(ent);
	LUA_DEBUG("Mover_Halt - return: halted ent");
	lua_pushboolean(L, qtrue);
	return 1;
}
Ejemplo n.º 12
0
/***
Moves an entity like a func_train entity. Targets have to be path_corner entities.
@function AsTrain
@param mover Entity to move.
@param target path_corner entity to move to.
@param speed Speed to move with to the first path_corner.
@return Success or failure.
 */
static int Mover_AsTrain(lua_State * L)
{
	lent_t			*lent, *tlent;
	gentity_t      *ent = NULL;
	gentity_t      *targ = NULL;
	vec3_t          move;
	float           length;
	int				id = 0, tid = 0;

	float           speed = (float)luaL_checknumber(L, 3);

	if(lua_isnumber(L, 1)) {
		id = luaL_checkint(L, 1);
		if(id < 0 || id > MAX_GENTITIES - 1) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = &g_entities[id];
		if(ent == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
	} else {
		lent = Lua_GetEntity(L, 1);
		if(lent == NULL || lent->e == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		ent = lent->e;
	}
	if(luaL_checkint(L, 2)) {
		tid = luaL_checkint(L, 2);
		if(tid < 0 || tid > MAX_GENTITIES - 1) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		targ = &g_entities[tid];
		if(targ == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
	} else {
		tlent = Lua_GetEntity(L, 2);
		if(!tlent || tlent->e == NULL) {
			lua_pushboolean(L, qfalse);
			return 1;
		}
		targ = tlent->e;
	}

	LUA_DEBUG("Mover_AsTrain - start: ent=%d target=%d speed=%f", ent->s.number, targ->s.number, speed);

	if(ent == NULL || targ == NULL)
	{
		LUA_DEBUG("Mover_AsTrain - return: ent or/and target missing");
		lua_pushboolean(L, qfalse);
		return 1;
	}
	if(speed < 1)
	{
		LUA_DEBUG("Mover_AsTrain - moving: speed less than 1 fixed");
		speed = 1;
	}

	if(ent->nextTrain)
	{
		LUA_DEBUG("Mover_AsTrain - pathing: NextTrain=%d ", ent->nextTrain->s.number);
	}

	ent->speed = speed;
	ent->nextTrain = targ;
	ent->reached = Reached_Train;
	ent->target = G_NewString(targ->targetname);

	Think_SetupTrainTargets(ent);

	BG_EvaluateTrajectory(&ent->s.pos, level.time, ent->r.currentOrigin);
	VectorCopy(ent->r.currentOrigin, ent->s.origin);

	VectorCopy(ent->s.origin, ent->pos1);
	VectorCopy(ent->nextTrain->s.origin, ent->pos2);

	VectorSubtract(ent->pos2, ent->pos1, move);
	length = VectorLength(move);

	if(length <= 0.05)
	{
		G_SetOrigin(ent, ent->pos2);
		LUA_DEBUG("Mover_AsTrain - return: snapped to target, length too small length=%f", length);
		lua_pushboolean(L, qtrue);
		return 1;
	}

	ent->s.pos.trDuration = length * 1000 / speed;

	ent->s.loopSound = ent->nextTrain->soundLoop;

	SetMoverState(ent, MOVER_1TO2, level.time);

	LUA_DEBUG("Mover_AsTrain - return: moving to target, length=%f duration=%d", length, ent->s.pos.trDuration);
	lua_pushboolean(L, qtrue);
	return 1;
}