g_morale.c
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "g_local.h"
00026
00027
00034 static void G_MoralePanic (edict_t * ent, qboolean sanity)
00035 {
00036 G_ClientPrintf(G_PLAYER_FROM_ENT(ent), PRINT_HUD, _("%s panics!\n"), ent->chr.name);
00037
00038
00039 if (!sanity && ent->chr.teamDef->weapons) {
00040 if (RIGHT(ent))
00041 G_ActorInvMove(ent, INVDEF(gi.csi->idRight), RIGHT(ent),
00042 INVDEF(gi.csi->idFloor), NONE, NONE, qtrue);
00043 if (LEFT(ent))
00044 G_ActorInvMove(ent, INVDEF(gi.csi->idLeft), LEFT(ent),
00045 INVDEF(gi.csi->idFloor), NONE, NONE, qtrue);
00046 }
00047
00048
00049 G_RemoveCrouched(ent);
00050 G_ActorSetMaxs(ent);
00051
00052
00053 G_SetPanic(ent);
00054 G_SendState(G_VisToPM(ent->visflags), ent);
00055
00056
00057 G_CenterView(ent);
00058
00059
00060 AI_ActorThink(G_PLAYER_FROM_ENT(ent), ent);
00061
00062
00063 G_ActorSetTU(ent, 0);
00064 }
00065
00074 static void G_MoraleStopPanic (edict_t * ent)
00075 {
00076 if (ent->morale / mor_panic->value > m_panic_stop->value * frand())
00077 G_RemovePanic(ent);
00078 else
00079 G_MoralePanic(ent, qtrue);
00080 }
00081
00088 static void G_MoraleRage (edict_t * ent, qboolean sanity)
00089 {
00090 if (sanity)
00091 G_SetRage(ent);
00092 else
00093 G_SetInsane(ent);
00094 G_SendState(G_VisToPM(ent->visflags), ent);
00095
00096 if (sanity)
00097 gi.BroadcastPrintf(PRINT_HUD, _("%s is on a rampage.\n"), ent->chr.name);
00098 else
00099 gi.BroadcastPrintf(PRINT_HUD, _("%s is consumed by mad rage!\n"), ent->chr.name);
00100 AI_ActorThink(G_PLAYER_FROM_ENT(ent), ent);
00101 }
00102
00111 static void G_MoraleStopRage (edict_t * ent)
00112 {
00113 if (ent->morale / mor_panic->value > m_rage_stop->value * frand()) {
00114 G_RemoveInsane(ent);
00115 G_SendState(G_VisToPM(ent->visflags), ent);
00116 } else
00117 G_MoralePanic(ent, qtrue);
00118 }
00119
00125 static qboolean G_IsMoraleEnabled (void)
00126 {
00127 if (sv_maxclients->integer == 1)
00128 return qtrue;
00129
00130 if (sv_maxclients->integer >= 2 && sv_enablemorale->integer == 1)
00131 return qtrue;
00132
00133 return qfalse;
00134 }
00135
00144 void G_MoraleBehaviour (int team)
00145 {
00146 edict_t *ent = NULL;
00147 int newMorale;
00148
00149 while ((ent = G_EdictsGetNextInUse(ent))) {
00150
00151 if (ent->type == ET_ACTOR && ent->team == team && !G_IsDead(ent)) {
00152
00153 if (sv_maxclients->integer >= 2 && level.activeTeam == TEAM_CIVILIAN && 0.5 > frand())
00154 G_MoralePanic(ent, qfalse);
00155
00156
00157 if (G_IsMoraleEnabled()) {
00158
00159 if (ent->morale <= mor_panic->value && !G_IsPaniced(ent) && !G_IsRaged(ent)) {
00160 qboolean sanity;
00161 if ((float) ent->morale / mor_panic->value > (m_sanity->value * frand()))
00162 sanity = qtrue;
00163 else
00164 sanity = qfalse;
00165 if ((float) ent->morale / mor_panic->value > (m_rage->value * frand()))
00166 G_MoralePanic(ent, sanity);
00167 else
00168 G_MoraleRage(ent, sanity);
00169
00170 } else if (ent->morale <= mor_shaken->value && !G_IsPaniced(ent)
00171 && !G_IsRaged(ent)) {
00172
00173 G_SetShaken(ent);
00174 G_SetState(ent, STATE_REACTION_MANY);
00175 G_SendState(G_VisToPM(ent->visflags), ent);
00176 G_ClientPrintf(G_PLAYER_FROM_ENT(ent), PRINT_HUD, _("%s is currently shaken.\n"),
00177 ent->chr.name);
00178 } else {
00179 if (G_IsPaniced(ent))
00180 G_MoraleStopPanic(ent);
00181 else if (G_IsRaged(ent))
00182 G_MoraleStopRage(ent);
00183 }
00184 }
00185
00186 G_ActorSetMaxs(ent);
00187
00188
00189 newMorale = ent->morale + MORALE_RANDOM(mor_regeneration->value);
00190 if (newMorale > GET_MORALE(ent->chr.score.skills[ABILITY_MIND]))
00191 ent->morale = GET_MORALE(ent->chr.score.skills[ABILITY_MIND]);
00192 else
00193 ent->morale = newMorale;
00194
00195
00196 G_SendStats(ent);
00197 gi.EndEvents();
00198 }
00199 }
00200 }