e_event_invreload.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 "../../../../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
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
00073
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
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
00086 ic->item.a = ammo;
00087 ic->item.m = INVSH_GetItemByIDX(type);
00088 }