e_event_actorappear.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 "../../../cl_localentity.h"
00027 #include "../../../cl_ugv.h"
00028 #include "../../../cl_actor.h"
00029 #include "../../../cl_hud.h"
00030 #include "../../../../cl_game.h"
00031 #include "../../../cl_particle.h"
00032 #include "e_event_actorappear.h"
00033 #include "../../../../../common/grid.h"
00034 
00035 int CL_ActorAppearTime (const eventRegister_t *self, struct dbuffer *msg, const int dt)
00036 {
00037 #if 0
00038     nextTime += 600;
00039 #else
00040     return cl.time + 600;
00041 #endif
00042 }
00043 
00047 static void CL_DrawLineOfSight (const le_t *watcher, const le_t *target)
00048 {
00049     ptl_t *ptl;
00050     vec3_t eyes;
00051 
00052     if (!watcher || !target)
00053         return;
00054 
00055     /* start is the watchers origin */
00056     VectorCopy(watcher->origin, eyes);
00057     if (LE_IsCrouched(watcher))
00058         eyes[2] += EYE_HT_CROUCH;
00059     else
00060         eyes[2] += EYE_HT_STAND;
00061 
00062     ptl = CL_ParticleSpawn("fadeTracer", 0, eyes, target->origin, NULL);
00063 
00064     if (LE_IsCivilian(target))
00065         VectorSet(ptl->color, 0.2, 0.2, 1);
00066 }
00067 
00074 void CL_ActorAppear (const eventRegister_t *self, struct dbuffer *msg)
00075 {
00076     le_t *le, *leResponsible;
00077     int entnum, entnumResponsible, modelnum1, modelnum2;
00078     int teamDefID = -1;
00079 
00080     /* check if the actor is already visible */
00081     entnum = NET_ReadShort(msg);
00082     entnumResponsible = NET_ReadShort(msg);
00083     le = LE_Get(entnum);
00084     leResponsible = LE_Get(entnumResponsible);
00085 
00086     if (entnumResponsible != SKIP_LOCAL_ENTITY && !leResponsible)
00087         LE_NotFoundError(entnumResponsible);
00088 
00089     /* mission start - no actor is spawned yet - so create it */
00090     if (!le)
00091         le = LE_Add(entnum);
00092 
00093     /* Locking should be unnecessary if CL_CheckDefault filters this call, since this event starts and
00094      * ends in this function only.  Adding lock/unlock just to be sure. */
00095     LE_Lock(le);
00096 
00097     /* maybe added via CL_ActorAdd before */
00098     le->invis = qfalse;
00099 
00100     /* get the info */
00101     NET_ReadFormat(msg, self->formatString,
00102             &le->team, &teamDefID, &le->gender, &le->pnum, &le->pos,
00103             &le->dir, &le->right, &le->left,
00104             &modelnum1, &modelnum2, &le->skinnum,
00105             &le->state, &le->fieldSize,
00106             &le->maxTU, &le->maxMorale, &le->maxHP);
00107 
00108     if (teamDefID < 0 || teamDefID > csi.numTeamDefs)
00109         Com_Printf("CL_ActorAppear: Invalid teamDef index\n");
00110     else
00111         le->teamDef = &csi.teamDef[teamDefID];
00112 
00113     switch (le->fieldSize) {
00114     case ACTOR_SIZE_NORMAL:
00115         le->addFunc = CL_AddActor;
00116         le->type = ET_ACTOR;
00117         break;
00118     case ACTOR_SIZE_2x2:
00119         le->addFunc = CL_AddUGV;
00120         le->type = ET_ACTOR2x2;
00121         break;
00122     default:
00123         Com_Error(ERR_DROP, "Unknown fieldSize for le in CL_ActorAppear (EV_ACTOR_APPEAR)");
00124     }
00125     le->modelnum1 = modelnum1;
00126     le->modelnum2 = modelnum2;
00127     le->model1 = cl.model_draw[modelnum1];
00128     le->model2 = cl.model_draw[modelnum2];
00129     Grid_PosToVec(cl.mapData->map, le->fieldSize, le->pos, le->origin);
00130     le->angles[YAW] = directionAngles[le->dir];
00131 
00132     le->contents = CONTENTS_ACTOR;
00133     VectorCopy(player_mins, le->mins);
00134     if (LE_IsDead(le))
00135         VectorCopy(player_dead_maxs, le->maxs);
00136     else
00137         VectorCopy(player_maxs, le->maxs);
00138 
00139     LE_SetThink(le, LET_StartIdle);
00140 
00141     /* count spotted aliens (also stunned) */
00142     if (LE_IsLivingActor(le) && le->team != cls.team && le->team != TEAM_CIVILIAN)
00143         cl.numAliensSpotted++;
00144 
00145     if (LE_IsLivingActor(le)) {
00146         /* center view (if wanted) */
00147         if (cl.actTeam != cls.team)
00148             LE_CenterView(le);
00149 
00150         /* draw line of sight */
00151         if (le->team != cls.team) {
00152             if (leResponsible)
00153                 CL_DrawLineOfSight(leResponsible, le);
00154 
00155             /* message */
00156             if (le->team != TEAM_CIVILIAN) {
00157                 if (GAME_TeamIsKnown(le->teamDef)) {
00158                     char tmpbuf[128];
00159                     Com_sprintf(tmpbuf, sizeof(tmpbuf), _("Enemy spotted: %s!"), _(le->teamDef->name));
00160                     HUD_DisplayMessage(tmpbuf);
00161                 } else
00162                     HUD_DisplayMessage(_("Enemy spotted!\n"));
00163             } else
00164                 HUD_DisplayMessage(_("Civilian spotted!\n"));
00165 
00166             /* update pathing as new actor could block path */
00167             CL_ActorConditionalMoveCalc(leResponsible ? leResponsible : selActor);
00168         }
00169     }
00170 
00171     /* add team members to the actor list */
00172     CL_ActorAddToTeamList(le);
00173     LE_Unlock(le);
00174 }

Generated by  doxygen 1.6.2