djcev.com

//

Git Repos / fte_dogmode / qc / triggers / textstory.qc

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

Show textstory.qc

//==============================================================================
// trigger_textstory
//==============================================================================

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

const float TEXTSTORY_SILENT = 1;
const float TEXTSTORY_NOFADE = 2;

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

// base_textstory
void(entity controller) base_textstory_hide;
void(entity controller) base_textstory_show;

// trigger_textstory
void() trigger_textstory_hide;
void() trigger_textstory_show;
void() trigger_textstory_touch;
void(entity e) trigger_textstory_init;
void() trigger_textstory;

// target_textstory_helper
void() target_textstory_helper_hide;
void() target_textstory_helper_show;
entity(entity src, entity tgt, float nthink, float atkfinished)
spawn_target_textstory_helper;
void(entity e) target_textstory_helper_init;
void() target_textstory_helper;

// target_textstory
void(entity tgt) target_textstory_spawn_helper;
void() target_textstory_use;
void(entity e) target_textstory_init;
void() target_textstory;

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

//----------------------------------------------------------------------
// base textstory class
//----------------------------------------------------------------------
// class base_textstory: base_trigger
// {
//--------------------------------------------------------------
// hide a textstory
//--------------------------------------------------------------
void(entity controller) base_textstory_hide =
{
if (!self.enemy || !(self.enemy.flags & FL_CLIENT))
return;

self.enemy.suppressCenterPrint = FALSE;
centerprint (self.enemy, "");

if (controller.noise2 != __NULL__ && controller.noise2 != "")
sound (self.enemy, CHAN_BODY, controller.noise2, 1,
ATTN_NORM);

if (!(controller.spawnflags & TEXTSTORY_NOFADE))
csf_fade (self.enemy, 0, '0 0 0', 0.5);
};

//--------------------------------------------------------------
// show a textstory
//--------------------------------------------------------------
void(entity controller) base_textstory_show =
{
if (!self.enemy || !(self.enemy.flags & FL_CLIENT))
return;

self.enemy.suppressCenterPrint = TRUE;

centerprint_builtin (self.enemy, controller.message);

if (!self.state)
{
if (controller.noise1 != __NULL__ &&
controller.noise1 != "")
{
sound (self.enemy, CHAN_BODY, controller.noise1,
1, ATTN_NORM);
}

if (!(controller.spawnflags & TEXTSTORY_NOFADE))
{
//custom fade amount --dumptruck_ds
if (!self.fade_amt)
csf_fade (self.enemy, 160, '0 0 0', 1);
else
csf_fade (self.enemy, self.fade_amt,
'0 0 0', 1);
}
}

self.state = 1;
};
// };

//----------------------------------------------------------------------
// trigger_textstory -- centerprint text when inside this trigger
//----------------------------------------------------------------------
// class trigger_textstory: base_textstory
// {
//--------------------------------------------------------------
// hide text
//--------------------------------------------------------------
void() trigger_textstory_hide =
{
base_textstory_hide (self);

self.enemy = world;
self.state = 0;
};

//--------------------------------------------------------------
// show text
//--------------------------------------------------------------
void() trigger_textstory_show =
{
base_textstory_show (self);

self.think = trigger_textstory_hide;
self.nextthink = time + 0.2;
};

//--------------------------------------------------------------
void() trigger_textstory_touch =
{
if (!(other.flags & FL_CLIENT))
return;

if (self.estate != STATE_ACTIVE)
return;

// don't show message if another player is already triggering it
if (other != self.enemy && self.state == 1)
return;

if (self.mangle && !is_in_angle (other.v_angle, self.mangle,
self.view_ofs))
{
return;
}

if (self.attack_finished < time)
{
self.attack_finished = time + 0.1;
self.enemy = other;

trigger_textstory_show ();
}
};

//--------------------------------------------------------------
void(entity e) trigger_textstory_init =
{
e.classname = "trigger_textstory";
e.classtype = CT_TRIGGER_TEXTSTORY;
e.touch = trigger_textstory_touch;
base_trigger_init (e);

if (e.view_ofs == '0 0 0')
e.view_ofs = '90 90 0';

if (e.mangle)
e.mangle = normalize_angles180 (e.mangle);

if (e.noise1 == "")
e.noise1 = "misc/talk.wav";

if (e.noise2 == "")
e.noise2 = "misc/null.wav";

if (e.spawnflags & TEXTSTORY_SILENT)
{
e.noise1 = "";
e.noise2 = "";
}


if (e.noise1 != "")
precache_sound (e.noise1);
if (e.noise2 != "")
precache_sound (e.noise2);

sub_checkwaiting (e);
};

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

trigger_textstory_init (self);
};
// };

//------------------------------------------------------------------------------
// helper class spawned by target_textstory below
//------------------------------------------------------------------------------
// class target_textstory_helper: base_textstory
// {
//--------------------------------------------------------------
// hide text
//--------------------------------------------------------------
void() target_textstory_helper_hide =
{
base_textstory_hide (self.owner);
remove (self);
};

//--------------------------------------------------------------
// show text
//--------------------------------------------------------------
void() target_textstory_helper_show =
{
if (!self.enemy || !(self.enemy.flags & FL_CLIENT))
{
remove (self);
return;
}

base_textstory_show (self.owner);

if (self.attack_finished < time)
self.think = target_textstory_helper_hide;

self.nextthink = time + 0.1;
};

//--------------------------------------------------------------
entity(entity src, entity tgt, float nthink, float atkfinished)
spawn_target_textstory_helper =
{
local entity e = spawn ();
e.owner = src;
e.enemy = tgt;
e.nextthink = nthink;
e.attack_finished = atkfinished;
target_textstory_helper_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) target_textstory_helper_init =
{
e.classname = "target_textstory_helper";
e.classtype = CT_TARGET_TEXTSTORY_HELPER;
e.think = target_textstory_helper_show;

base_tempentity_init (e);
};

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

target_textstory_helper_init (self);
};
// };

//----------------------------------------------------------------------
// target_textstory: centerprint a message for an amount of time when used
//----------------------------------------------------------------------
// class target_textstory: base_textstory
// {
//--------------------------------------------------------------
// create the hidden object that'll show the actual message
//--------------------------------------------------------------
void(entity tgt) target_textstory_spawn_helper =
{
entity helper = spawn_target_textstory_helper (self, tgt,
time + 0.1, time + self.wait);
};

//--------------------------------------------------------------
void() target_textstory_use =
{
if (!(activator.flags & FL_CLIENT))
return;
if (self.estate != STATE_ACTIVE)
return;

local entity t;

if (self.spawnflags & TRIGGER_CENTERPRINTALL)
{
t = findfloat (world, classtype, CT_PLAYER);
while (t)
{
target_textstory_spawn_helper (t);
t = findfloat (t, classtype, CT_PLAYER);
}
}
else
{
target_textstory_spawn_helper (activator);
}
};

//--------------------------------------------------------------
void(entity e) target_textstory_init =
{
e.classname = "target_textstory";
e.classtype = CT_TARGET_TEXTSTORY;
base_mapentity_init (e);

if (e.noise1 == "")
e.noise1 = "misc/talk.wav";

if (e.noise2 == "")
e.noise2 = "misc/null.wav";

if (e.spawnflags & TEXTSTORY_SILENT) {
e.noise1 = "";
e.noise2 = "";
}

if (e.noise1 != "")
precache_sound (e.noise1);
if (e.noise2 != "")
precache_sound (e.noise2);

if (!e.wait)
e.wait = 5;

e.use = target_textstory_use;
};

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

target_textstory_init (self);
};
// };

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

Log textstory.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +176 -135
2024-01-31 Class based monster refactor & start projectiles cev +3 -3
2024-01-09 Continue OO / Class-based refactor cev +69 -32
2023-12-09 Start OO / class-based refactor, work on items cev +211 -166
2023-11-16 pmove bug fixes, moved q3 compat code, cleanup cev +225  

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