diff --git a/src/cdogs/actors.c b/src/cdogs/actors.c index 3b948b731..c7eb0f1da 100644 --- a/src/cdogs/actors.c +++ b/src/cdogs/actors.c @@ -572,6 +572,8 @@ void ActorReplaceGun(const NActorReplaceGun rg) { return; } + LOG(LM_ACTOR, LL_DEBUG, "actor uid(%d) replacing gun(%s) idx(%d) size(%d)", + (int)rg.UID, rg.Gun, rg.GunIdx, (int)a->guns.size); Weapon w = WeaponCreate(gun); if (a->guns.size <= rg.GunIdx) { @@ -1310,6 +1312,7 @@ void ActorSwitchGun(const NActorSwitchGun sg) { TActor *a = ActorGetByUID(sg.UID); if (a == NULL || !a->isInUse) return; + CASSERT(sg.GunIdx < a->guns.size, "can't switch to unavailable gun"); a->gunIndex = sg.GunIdx; SoundPlayAt( &gSoundDevice, diff --git a/src/cdogs/pickup.c b/src/cdogs/pickup.c index 83a9c0367..c8c741c7a 100644 --- a/src/cdogs/pickup.c +++ b/src/cdogs/pickup.c @@ -203,8 +203,9 @@ void PickupPickup(TActor *a, Pickup *p, const bool pickupAll) GameEvent e = GameEventNew(GAME_EVENT_ACTOR_REPLACE_GUN); e.u.ActorReplaceGun.UID = a->uid; e.u.ActorReplaceGun.GunIdx = - (int)a->guns.size == MAX_WEAPONS ? - a->gunIndex : (int)a->guns.size; + a->guns.size == MAX_WEAPONS ? a->gunIndex : a->guns.size; + CASSERT(e.u.ActorReplaceGun.GunIdx <= a->guns.size, + "invalid replace gun index"); strcpy(e.u.ActorReplaceGun.Gun, gun->name); GameEventsEnqueue(&gGameEvents, e);