Workaround for func_breakables without origin brush

* added lua function SetAngles2 to mover lib
* Added work around for func_breakables without origin brush
* Set angles2 to origin (note determin in Radiant)
* Set n00bcount to approx radius of the entity
* add spawnflag NOORIGIN (512)
This commit is contained in:
Walter Julius Hennecke 2012-11-13 19:39:44 +01:00
parent 71d607d39f
commit 0f9ef785f5
4 changed files with 72 additions and 12 deletions

View file

@ -245,7 +245,7 @@ void breakable_spawn_trigger(gentity_t *ent) {
//RPG-X | GSIO01 | 09/05/2009 EOE
/*QUAKED func_breakable (0 .8 .5) ? x x x x INVINCIBLE x x x REPAIRABLE
/*QUAKED func_breakable (0 .8 .5) ? x x x x INVINCIBLE x x x REPAIRABLE NOORIGIN
INVINCIBLE - can only be broken by being used
REPAIRABLE - con be repaired with hyperspanner

View file

@ -1576,13 +1576,18 @@ void G_Repair(gentity_t *ent, gentity_t *tr_ent, float rate) {
}
// check if player is near the breakable
VectorSubtract(tr_ent->s.origin, ent->r.currentOrigin, help);
distance = VectorLength(help);
for(i = 0; i < 3; i++) {
if(tr_ent->r.maxs[i] > max) {
max = tr_ent->r.maxs[i];
if(tr_ent->spawnflags & 512) {
VectorSubtract(tr_ent->s.angles2, ent->r.currentOrigin, help);
max = tr_ent->n00bCount;
} else {
VectorSubtract(tr_ent->s.origin, ent->r.currentOrigin, help);
for(i = 0; i < 3; i++) {
if(tr_ent->r.maxs[i] > max) {
max = tr_ent->r.maxs[i];
}
}
}
distance = VectorLength(help);
//G_Printf("goodDst=%f, curDst=%f\n", 80 + max, distance);
if(distance > 80 + max) {
@ -1591,7 +1596,6 @@ void G_Repair(gentity_t *ent, gentity_t *tr_ent, float rate) {
// check if the player is facing it
AngleVectors(ent->client->ps.viewangles, forward, NULL, NULL);
VectorSubtract(tr_ent->s.origin, ent->client->ps.origin, help);
if(DotProduct(help, forward) < 0.4) {
return;
}

View file

@ -116,7 +116,7 @@ static void WP_FireHyperspanner(gentity_t *ent, qboolean alt_fire) {
int i, nearest = -1;
float nearestd = 65000;
vec3_t dVec, end;
vec3_t mins = { -40, -40, -40 }, maxs = { 40, 40, 40 };
vec3_t mins = { -40, -40, 0 }, maxs = { 40, 40, 0 };
char* classnames[] = { "func_breakable", "misc_model_breakable" };
/* find all vlaid entities in range */
@ -126,15 +126,25 @@ static void WP_FireHyperspanner(gentity_t *ent, qboolean alt_fire) {
trace_t tr;
for(i = 0; i < count; i++) {
// TODO: fix problems with small distance
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.origin, dVec);
VectorMA(validEnts[i]->s.origin, 1024, dVec, end);
if(validEnts[i]->spawnflags & 512) {
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.angles2, dVec);
VectorMA(validEnts[i]->s.angles2, 1024, dVec, end);
trap_Trace(&tr, validEnts[i]->s.angles2, mins, maxs, end, validEnts[i]->s.number, MASK_SHOT);
} else {
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.origin, dVec);
VectorMA(validEnts[i]->s.origin, 1024, dVec, end);
trap_Trace(&tr, validEnts[i]->s.origin, mins, maxs, end, validEnts[i]->s.number, MASK_SHOT);
}
//G_Printf("Checking entity: %d\n", i);
trap_Trace(&tr, validEnts[i]->s.origin, mins, maxs, end, validEnts[i]->s.number, MASK_SHOT);
if(tr.entityNum != ent->s.number) {
continue;
}
//G_Printf("Nothing is blocking view ...\n");
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.origin, dVec);
if(validEnts[i]->spawnflags & 512) {
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.angles2, dVec);
} else {
VectorSubtract(ent->r.currentOrigin, validEnts[i]->s.origin, dVec);
}
if(VectorLength(dVec) < nearestd) {
nearest = validEnts[i]->s.number;
nearestd = VectorLength(dVec);

View file

@ -203,6 +203,51 @@ static int Mover_SetAngles(lua_State * L)
return 0;
}
// mover.SetAngles2(entity ent, vector angles) or
// mover.SetAngles2(entity ent, float y, float z, float x)
// Sets the angles of ent to the specified value(s).
// Values are sorted Pitch (around Y-Axis), Yaw (around Z-Axis) and
// Roll (around X-Axis). These can also be stowed in a vector angles.
static int Mover_SetAngles2(lua_State * L)
{
vec3_t newAngles;
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) return 1;
ent = &g_entities[id];
if(!ent) return 1;
} else {
lent = Lua_GetEntity(L, 1);
if(!lent || !lent->e) return 1;
ent = lent->e;
}
if(Lua_IsVector(L, 2))
{
target = Lua_GetVector(L, 2);
VectorCopy(target, newAngles);
}
else
{
newAngles[0] = luaL_checkint(L, 2);
newAngles[1] = luaL_checkint(L, 3);
newAngles[2] = luaL_checkint(L, 4);
}
LUA_DEBUG("Mover_SetAngles2 - start: ent=%d angles=%s", ent->s.number, vtos(newAngles));
if(ent)
{
VectorCopy(newAngles, ent->s.angles2);
trap_LinkEntity(ent);
LUA_DEBUG("Mover_SetAngles2 - return: moved");
}
return 0;
}
// mover.SetPosition(entity ent, vector pos) or
// mover.SetPosition(entity ent, float x, float y, float z)
// Set the position of ent to the specified value(s). Can also be stowed in a vector pos.
@ -369,6 +414,7 @@ static const luaL_Reg lib_mover[] = {
{"SetOrigin", Mover_SetPosition},
{"ToPosition", Mover_ToPosition},
{"SetAngles", Mover_SetAngles},
{"SetAngles2", Mover_SetAngles2},
{"ToAngles", Mover_ToAngles},
{NULL, NULL}
};