e_event_addbrushmodel.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 "e_event_addbrushmodel.h"
00028 
00036 void CL_AddBrushModel (const eventRegister_t *self, struct dbuffer *msg)
00037 {
00038     le_t *le;
00039     int entnum, modelnum1, levelflags, speed;
00040     entity_type_t type;
00041     const cBspModel_t *model;
00042     int angle;
00043     vec3_t origin, angles;
00044 
00045     NET_ReadFormat(msg, self->formatString, &type, &entnum, &modelnum1, &levelflags, &origin, &angles, &speed, &angle);
00046 
00047     if (type != ET_BREAKABLE && type != ET_DOOR && type != ET_ROTATING)
00048         Com_Error(ERR_DROP, "Invalid le announced via EV_ADD_BRUSH_MODEL type: %i\n", type);
00049     else if (modelnum1 > MAX_MODELS || modelnum1 < 1)
00050         Com_Error(ERR_DROP, "Invalid le modelnum1 announced via EV_ADD_BRUSH_MODEL\n");
00051 
00052     /* check if the ent is already visible */
00053     le = LE_Get(entnum);
00054     if (le)
00055         Com_Error(ERR_DROP, "le announced a second time - le for entnum %i (type: %i) already exists (via EV_ADD_BRUSH_MODEL)\n", entnum, type);
00056 
00057     le = LE_Add(entnum);
00058     assert(le);
00059 
00060     le->rotationSpeed = speed / 100.0f;
00061     le->dir = angle;
00062     le->type = type;
00063     le->modelnum1 = modelnum1;
00064     le->levelflags = levelflags;
00065     le->addFunc = LE_BrushModelAction;
00066     LE_SetThink(le, LET_BrushModel);
00067     /* The origin and angles are REQUIRED for doors to work! */
00068     VectorCopy(origin, le->origin);
00069     VectorCopy(angles, le->angles);
00070 
00071     Com_sprintf(le->inlineModelName, sizeof(le->inlineModelName), "*%i", le->modelnum1);
00072     model = cl.model_clip[le->modelnum1];
00073     if (!model)
00074         Com_Error(ERR_DROP, "CL_AddBrushModel: Could not find inline model %i", le->modelnum1);
00075     le->model1 = R_RegisterModelShort(le->inlineModelName);
00076     if (!le->model1)
00077         Com_Error(ERR_DROP, "CL_AddBrushModel: Could not register inline model %i", le->modelnum1);
00078 
00079     /* Transfer model mins and maxs to entity */
00080     VectorCopy(model->mins, le->mins);
00081     VectorCopy(model->maxs, le->maxs);
00082     /* This is to help the entity collision code out */
00083     /* Copy entity origin and angles to model*/
00084     CM_SetInlineModelOrientation(cl.mapTiles, le->inlineModelName, le->origin, le->angles);
00085 
00086     /* to allow tracing against this le */
00087     le->contents = CONTENTS_SOLID;
00088 
00089     CL_RecalcRouting(le);
00090 }

Generated by  doxygen 1.6.2