g_trigger.c
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "g_local.h"
00031
00032 edict_t* G_TriggerSpawn (edict_t *owner)
00033 {
00034 edict_t* trigger;
00035 vec3_t mins, maxs;
00036
00037 trigger = G_Spawn();
00038 trigger->classname = "trigger";
00039 trigger->type = ET_TRIGGER;
00040
00041 trigger->owner = owner;
00042
00043 VectorCopy(owner->absmin, mins);
00044 VectorCopy(owner->absmax, maxs);
00045
00046
00047 mins[0] -= (UNIT_SIZE / 2);
00048 mins[1] -= (UNIT_SIZE / 2);
00049 maxs[0] += (UNIT_SIZE / 2);
00050 maxs[1] += (UNIT_SIZE / 2);
00051
00052 VectorCopy(mins, trigger->mins);
00053 VectorCopy(maxs, trigger->maxs);
00054
00055 trigger->solid = SOLID_TRIGGER;
00056
00057
00058 gi.LinkEdict(trigger);
00059
00060 return trigger;
00061 }
00062
00067 static qboolean Touch_HurtTrigger (edict_t *self, edict_t *activator)
00068 {
00069
00070 assert(!G_IsDead(activator));
00071 assert(!G_IsStunned(activator));
00072
00073 if (self->spawnflags & 2) {
00074 activator->STUN += self->dmg;
00075 if (activator->HP <= activator->STUN)
00076 G_SetStunned(activator);
00077 } else if (self->spawnflags & 4) {
00079 } else {
00080 G_TakeDamage(activator, self->dmg);
00081 if (activator->HP == 0)
00082 G_SetDead(activator);
00083 }
00084
00085 return qtrue;
00086 }
00087
00093 void SP_trigger_hurt (edict_t *ent)
00094 {
00095 ent->classname = "trigger_hurt";
00096 ent->type = ET_TRIGGER_HURT;
00097
00098 if (!ent->dmg)
00099 ent->dmg = 5;
00100
00101 ent->solid = SOLID_TRIGGER;
00102 gi.SetModel(ent, ent->model);
00103
00104 ent->touch = Touch_HurtTrigger;
00105 ent->child = NULL;
00106
00107 gi.LinkEdict(ent);
00108 }
00109
00114 static qboolean Touch_TouchTrigger (edict_t *self, edict_t *activator)
00115 {
00116
00117 assert(!G_IsDead(activator));
00118 assert(!G_IsDead(activator));
00119
00120 self->owner = G_FindTargetEntity(self->target);
00121 if (!self->owner) {
00122 gi.DPrintf("Target '%s' wasn't found for %s\n", self->target, self->classname);
00123 G_FreeEdict(self);
00124 return qfalse;
00125 }
00126
00127 if (!self->owner->use) {
00128 gi.DPrintf("Owner of %s doesn't have a use function\n", self->classname);
00129 G_FreeEdict(self);
00130 return qfalse;
00131 }
00132
00133 self->owner->use(self->owner, activator);
00134
00135 return qfalse;
00136 }
00137
00143 void SP_trigger_touch (edict_t *ent)
00144 {
00145 ent->classname = "trigger_touch";
00146 ent->type = ET_TRIGGER_TOUCH;
00147
00148 if (!ent->target) {
00149 gi.DPrintf("No target given for %s\n", ent->classname);
00150 G_FreeEdict(ent);
00151 return;
00152 }
00153
00154 ent->solid = SOLID_TRIGGER;
00155 gi.SetModel(ent, ent->model);
00156
00157 ent->touch = Touch_TouchTrigger;
00158 ent->child = NULL;
00159
00160 gi.LinkEdict(ent);
00161 }
00162
00167 static qboolean Touch_RescueTrigger (edict_t *self, edict_t *activator)
00168 {
00169
00170 assert(!G_IsDead(activator));
00171 assert(!G_IsDead(activator));
00172
00173 if (self->team == activator->team)
00174 G_ActorSetInRescueZone(activator, qtrue);
00175
00176 return qfalse;
00177 }
00178
00179 static void Reset_RescueTrigger (edict_t *self, edict_t *activator)
00180 {
00181 if (self->team == activator->team)
00182 G_ActorSetInRescueZone(activator, qfalse);
00183 }
00184
00192 void SP_trigger_rescue (edict_t *ent)
00193 {
00194 ent->classname = "trigger_rescue";
00195 ent->type = ET_TRIGGER_RESCUE;
00196
00197 ent->solid = SOLID_TRIGGER;
00198 gi.SetModel(ent, ent->model);
00199
00200 ent->touch = Touch_RescueTrigger;
00201 ent->reset = Reset_RescueTrigger;
00202 ent->child = NULL;
00203
00204 gi.LinkEdict(ent);
00205 }