e_event_invreload.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_game.h"
00028 #include "e_event_invreload.h"
00029 
00030 int CL_InvReloadTime (const eventRegister_t *self, struct dbuffer *msg, const int dt)
00031 {
00032 #if 0
00033     /* let the reload sound play */
00034     nextTime += 600;
00035 #else
00036     return cl.time + 600;
00037 #endif
00038 }
00039 
00043 void CL_InvReload (const eventRegister_t *self, struct dbuffer *msg)
00044 {
00045     invList_t   *ic;
00046     le_t    *le;
00047     int     number;
00048     int     ammo, type, x, y;
00049     containerIndex_t container;
00050     equipDef_t *ed;
00051 
00052     NET_ReadFormat(msg, self->formatString, &number, &ammo, &type, &container, &x, &y);
00053 
00054     le = LE_Get(number);
00055     if (!le)
00056         return;
00057 
00058     if (le->team != cls.team)
00059         return;
00060 
00061     assert(container >= 0);
00062     assert(container < MAX_INVDEFS);
00063     ic = INVSH_SearchInInventory(&le->i, INVDEF(container), x, y);
00064     if (!ic)
00065         return;
00066 
00070     S_PlaySample(le->origin, S_LoadSample("weapons/reload-pistol"), SOUND_ATTN_IDLE, SND_VOLUME_WEAPONS);
00071 
00072     /* if the displaced clip had any remaining bullets
00073      * store them as loose, unless the removed clip was full */
00074     ed = GAME_GetEquipmentDefinition();
00075     if (ed && ic->item.a > 0 && ic->item.a != ic->item.t->ammo) {
00076         assert(ammo == ic->item.t->ammo);
00077         ed->numItemsLoose[ic->item.m->idx] += ic->item.a;
00078         /* Accumulate loose ammo into clips (only accessible post-mission) */
00079         if (ed->numItemsLoose[ic->item.m->idx] >= ic->item.t->ammo) {
00080             ed->numItemsLoose[ic->item.m->idx] -= ic->item.t->ammo;
00081             ed->numItems[ic->item.m->idx]++;
00082         }
00083     }
00084 
00085     /* set new ammo */
00086     ic->item.a = ammo;
00087     ic->item.m = INVSH_GetItemByIDX(type);
00088 }

Generated by  doxygen 1.6.2