e_event_actorstatechange.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2002-2010 UFO: Alien Invasion.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 */
00024 
00025 #include "../../../../client.h"
00026 #include "../../../../ui/ui_main.h"
00027 #include "../../../cl_localentity.h"
00028 #include "../../../cl_actor.h"
00029 #include "e_event_actorstatechange.h"
00030 
00031 void CL_ActorStateChange (const eventRegister_t *self, struct dbuffer *msg)
00032 {
00033     le_t *le;
00034     int entnum, state;
00035     character_t *chr;
00036 
00037     NET_ReadFormat(msg, self->formatString, &entnum, &state);
00038 
00039     le = LE_Get(entnum);
00040     if (!le)
00041         LE_NotFoundError(entnum);
00042 
00043     if (!LE_IsActor(le)) {
00044         Com_Printf("StateChange message ignored... LE is no actor (number: %i, state: %i, type: %i)\n",
00045             entnum, state, le->type);
00046         return;
00047     }
00048 
00049     /* If standing up or crouching down remove the reserved-state for crouching. */
00050     if (((state & STATE_CROUCHED) && !LE_IsCrouched(le)) ||
00051          (!(state & STATE_CROUCHED) && LE_IsCrouched(le))) {
00052         if (CL_ActorUsableTUs(le) < TU_CROUCH && CL_ActorReservedTUs(le, RES_CROUCH) >= TU_CROUCH) {
00053             /* We have not enough non-reserved TUs,
00054              * but some reserved for crouching/standing up.
00055              * i.e. we only reset the reservation for crouching if it's the very last attempt. */
00056             CL_ActorReserveTUs(le, RES_CROUCH, 0); /* Reset reserved TUs (0 TUs) */
00057         }
00058     }
00059 
00060     /* killed by the server: no animation is played, etc. */
00061     if ((state & STATE_DEAD) && LE_IsLivingActor(le)) {
00062         le->state = state;
00063         FLOOR(le) = NULL;
00064         LE_SetThink(le, NULL);
00065         VectorCopy(player_dead_maxs, le->maxs);
00066         CL_ActorRemoveFromTeamList(le);
00067         return;
00068     } else {
00069         le->state = state;
00070         LE_SetThink(le, LET_StartIdle);
00071     }
00072 
00073     /* save those states that the actor should also carry over to other missions */
00074     chr = CL_ActorGetChr(le);
00075     if (!chr)
00076         return;
00077 
00078     chr->state = (le->state & STATE_REACTION);
00079 
00080     if (!(le->state & STATE_REACTION)) {
00081         UI_ExecuteConfunc("disable_reaction");
00082     } else {
00083         /* change reaction button state */
00084         if (le->state & STATE_REACTION_MANY)
00085             UI_ExecuteConfunc("startreactionmany");
00086         else if (le->state & STATE_REACTION_ONCE)
00087             UI_ExecuteConfunc("startreactiononce");
00088     }
00089 
00090     /* state change may have affected move length */
00091     CL_ActorConditionalMoveCalc(le);
00092 }

Generated by  doxygen 1.6.2