static void DrawWeaponStatus( HUD *hud, const TActor *actor, Vec2i pos, const FontAlign hAlign, const FontAlign vAlign) { const Weapon *weapon = ActorGetGun(actor); // Draw gun icon, and allocate padding to draw the gun icon const GunDescription *g = ActorGetGun(actor)->Gun; const Vec2i iconPos = Vec2iAligned( Vec2iNew(pos.x - 2, pos.y - 2), g->Icon->size, hAlign, vAlign, gGraphicsDevice.cachedConfig.Res); Blit(&gGraphicsDevice, g->Icon, iconPos); // don't draw gauge if not reloading if (weapon->lock > 0) { const Vec2i gaugePos = Vec2iAdd(pos, Vec2iNew(-1 + GUN_ICON_PAD, -1)); const Vec2i size = Vec2iNew(GAUGE_WIDTH - GUN_ICON_PAD, FontH() + 2); const color_t barColor = { 0, 0, 255, 255 }; const int maxLock = weapon->Gun->Lock; int innerWidth; color_t backColor = { 128, 128, 128, 255 }; if (maxLock == 0) { innerWidth = 0; } else { innerWidth = MAX(1, size.x * (maxLock - weapon->lock) / maxLock); } DrawGauge( hud->device, gaugePos, size, innerWidth, barColor, backColor, hAlign, vAlign); } FontOpts opts = FontOptsNew(); opts.HAlign = hAlign; opts.VAlign = vAlign; opts.Area = gGraphicsDevice.cachedConfig.Res; opts.Pad = Vec2iNew(pos.x + GUN_ICON_PAD, pos.y); char buf[128]; if (ConfigGetBool(&gConfig, "Game.Ammo") && weapon->Gun->AmmoId >= 0) { // Include ammo counter sprintf(buf, "%s %d/%d", weapon->Gun->name, ActorGunGetAmmo(actor, weapon), AmmoGetById(&gAmmo, weapon->Gun->AmmoId)->Max); } else { strcpy(buf, weapon->Gun->name); } FontStrOpt(buf, Vec2iZero(), opts); }
static void AddPickupAtObject(const TObject *o, const PickupType type) { GameEvent e = GameEventNew(GAME_EVENT_ADD_PICKUP); switch (type) { case PICKUP_JEWEL: CASSERT(false, "unexpected pickup type"); break; case PICKUP_HEALTH: if (!ConfigGetBool(&gConfig, "Game.HealthPickups")) { return; } strcpy(e.u.AddPickup.PickupClass, "health"); break; case PICKUP_AMMO: if (!ConfigGetBool(&gConfig, "Game.Ammo")) { return; } // Pick a random ammo type and spawn it { const int ammoId = rand() % AmmoGetNumClasses(&gAmmo); const Ammo *a = AmmoGetById(&gAmmo, ammoId); sprintf(e.u.AddPickup.PickupClass, "ammo_%s", a->Name); } break; case PICKUP_KEYCARD: CASSERT(false, "unexpected pickup type"); break; case PICKUP_GUN: // Pick a random mission gun type and spawn it { const int gunId = (int)(rand() % gMission.Weapons.size); const WeaponClass **wc = CArrayGet(&gMission.Weapons, gunId); sprintf(e.u.AddPickup.PickupClass, "gun_%s", (*wc)->name); } break; default: CASSERT(false, "unexpected pickup type"); break; } e.u.AddPickup.UID = PickupsGetNextUID(); e.u.AddPickup.Pos = Vec2ToNet(o->thing.Pos); e.u.AddPickup.IsRandomSpawned = true; e.u.AddPickup.SpawnerUID = -1; e.u.AddPickup.ThingFlags = 0; GameEventsEnqueue(&gGameEvents, e); }
// TODO: use map structure? Ammo *StrAmmo(const char *s) { return AmmoGetById(&gAmmo, StrAmmoId(s)); }