djcev.com

//

Git Repos / fte_dogmode / qc / misc / model.qc

Last update to this file was on 2024-03-24 at 02:40.

Show model.qc

//==============================================================================
// misc_model -- Joshua Skelton -- misc_model.qc requires math.qc
// Author: Joshua Skelton joshua.skelton@gmail.com
// Edited by: Inky 20201219 Minor changes for a better integration with their
// own code
// Edited by: bmFbr for solid and gravity spawnflags and custom bbox sizes
// Edited by: dumptruck_ds to add start and stop animations
//==============================================================================

//======================================================================
// constants
//======================================================================

const float MISC_MODEL_GRAVITY = 1;
const float MISC_MODEL_SOLID = 2;
const float MISC_MODEL_BACK_AND_FORTH = 4;
const float MISC_MODEL_ONLY_ONCE = 8;
const float MISC_MODEL_PLAY_COUNT = 16;
const float MISC_MODEL_STARTOFF = 32;

//======================================================================
// fields
//======================================================================

.float first_frame; // The starting frame of the animation
.float last_frame; // The ending frame of the animation

//======================================================================
// forward declarations
//======================================================================

// base_misc_model
void() base_misc_model_think;
void() base_misc_model_use;

// misc_model

//------------------------------------------------------------------------------

//----------------------------------------------------------------------
// class base_misc_model: base_mapentity
// {
//--------------------------------------------------------------
// misc_model_think -- Handles animation for misc_model entity.
//--------------------------------------------------------------
void() base_misc_model_think =
{
self.nextthink = time + fabs (self.speed);
if (self.estate != STATE_ACTIVE)
return;

self.frame = self.frame + sign (self.speed);

if (self.spawnflags & MISC_MODEL_BACK_AND_FORTH &&
self.frame < self.first_frame)
{
self.speed = -1 * self.speed;
self.frame += 2;
}
else if (self.spawnflags & MISC_MODEL_BACK_AND_FORTH
&& self.frame > self.last_frame)
{
self.speed = -1 * self.speed;
self.frame -= 2;
}
else
{
self.frame = wrap (self.frame, self.first_frame,
self.last_frame);
}

if (self.spawnflags & MISC_MODEL_ONLY_ONCE &&
self.frame == self.last_frame &&
self.last_frame != self.first_frame)
{
self.nextthink = -1;
}

if (self.spawnflags & MISC_MODEL_PLAY_COUNT &&
self.frame == self.last_frame &&
self.last_frame != self.first_frame)
{
if !(self.count)
objerror ("Error: set count to the number of "
" animation cycles!");
self.cnt = self.cnt + 1;
dprint (ftos(self.cnt));
dprint ("\n");
if (self.cnt != self.count)
return FALSE;
else
self.nextthink = -1;
}
};

//--------------------------------------------------------------
void() base_misc_model_use =
{
if (self.state == STATE_ACTIVE)
{
if (self.spawnflags & MISC_MODEL_SOLID)
self.solid = SOLID_NOT;
self.model = "";

self.state = STATE_INVISIBLE;
setorigin (self, self.origin);
}
else
{
if (self.spawnflags & MISC_MODEL_SOLID)
self.solid = SOLID_BBOX;
self.model = self.mdl;

self.state = STATE_ACTIVE;
setorigin (self, self.origin);
}
};

//--------------------------------------------------------------
void(entity e) base_misc_model_init =
{
base_mapentity_init (e);
};
// };

/*QUAKED misc_model (0 0.5 0.8) (-8 -8 -8) (8 8 8) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{
model ({"path" : mdl, "skin" : skin, "frame": frame});
}
An entity for displaying models. A frame range can be given to animate the
model.

mdl: The model to display. Can be of type mdl, bsp, or spr.

frame: The frame to display. Can be used to offset the animation.

first_frame: The starting frame of the animation.

last_frame: The last frame of the animation.
*/
//----------------------------------------------------------------------
// class misc_model: base_misc_model
// {
//--------------------------------------------------------------
void(entity e) misc_model_init =
{
e.classname = "misc_model";
e.classtype = CT_MISC_MODEL;
base_misc_model_init (e);

if (!e.mdl || e.mdl == "")
objerror ("Model not defined");

if (!e.centeroffset)
e.centeroffset = '0 0 0';
if (!e.mdlsz)
e.mdlsz = '32 32 32';

vector vmin, vmax;

vmin_x = e.centeroffset_x - (e.mdlsz_x / 2);
vmin_y = e.centeroffset_y - (e.mdlsz_y / 2);
vmin_z = e.centeroffset_z - (e.mdlsz_z / 2);

vmax_x = e.centeroffset_x + (e.mdlsz_x / 2);
vmax_y = e.centeroffset_y + (e.mdlsz_y / 2);
vmax_z = e.centeroffset_z + (e.mdlsz_z / 2);

precache_model (e.mdl);
setmodel (e, e.mdl);

setsize (e, vmin, vmax);

if (e.spawnflags & MISC_MODEL_SOLID)
e.solid = SOLID_BBOX;
else
e.solid = SOLID_NOT;

if (e.spawnflags & MISC_MODEL_GRAVITY)
e.movetype = MOVETYPE_TOSS;
else
e.movetype = MOVETYPE_NONE;

if (!e.frame)
e.frame = e.first_frame;

// Make static (not animate) if not given a frame range, and
// not affected by gravity; also remains active if it has a
// targetname (so it can be killtargeted/toggled)
if (!e.last_frame &&
!(e.spawnflags & MISC_MODEL_GRAVITY) &&
!(e.spawnflags & MISC_MODEL_SOLID) &&
!e.targetname &&
!e.targetname2)
// !(e.spawnflags & MISC_MODEL_DONTMAKESTATIC) &&
{
makestatic (e);
}

// Make static (not animate) if not given a frame range, and
// not affected by gravity
// changed by bmFbr
// if (!e.last_frame &&
// !(e.spawnflags & MISC_MODEL_GRAVITY))
// {
// makestatic(e);
// return;
// }

// if it as a custom animation range
if (e.last_frame)
{
// Default animation speed to 10 fps
if (!e.speed)
e.speed = 0.1;
e.think = base_misc_model_think;
e.nextthink = time + e.speed;
}

if (e.spawnflags & MISC_MODEL_STARTOFF)
e.state = STATE_ACTIVE;
else
e.state = STATE_INVISIBLE;

sub_runvoidas (e, base_misc_model_use);
};

//--------------------------------------------------------------
void() misc_model =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

misc_model_init (self);
};
// };

Return to the top of this page or return to the overview of this repo.

Log model.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +125 -111
2024-01-31 Class based monster refactor & start projectiles cev +5 -1
2024-01-09 Continue OO / Class-based refactor cev +45 -31
2023-12-09 Start OO / class-based refactor, work on items cev +165 -154
2023-12-02 More refactoring & moving, begin adding mdls & snd cev +194  

Return to the top of this page or return to the overview of this repo.