int CArmor::CheckArmor (CPlayerEntity *Player, vec3_t point, vec3_t normal, int damage, int dflags){ if (!damage) return 0; if (dflags & DAMAGE_NO_ARMOR) return 0; int save = ceil (((dflags & DAMAGE_ENERGY) ? ((float)energyProtection / 100) : ((float)normalProtection / 100)) * damage); if (save >= Player->Client.pers.Inventory.Has(this)) save = Player->Client.pers.Inventory.Has(this); if (!save) return 0; Player->Client.pers.Inventory.Remove(GetIndex(), save); CTempEnt_Splashes::Sparks (point, normal, (dflags & DAMAGE_BULLET) ? CTempEnt_Splashes::STBulletSparks : CTempEnt_Splashes::STSparks, CTempEnt_Splashes::SPTSparks); // Ran out of armor? if (!Player->Client.pers.Inventory.Has(this)) Player->Client.pers.Armor = NULL; return save;}
bool CArmor::Pickup (edict_t *ent, CPlayerEntity *other){ if (normalProtection == -1) { if (other->Client.pers.Armor == NULL) { other->Client.pers.Inventory.Set (NItems::JacketArmor, 2); other->Client.pers.Armor = dynamic_cast<CArmor*>(NItems::JacketArmor); } else { if (maxCount != -1 && (other->Client.pers.Inventory.Has(other->Client.pers.Armor) >= maxCount)) return false; other->Client.pers.Inventory.Add (other->Client.pers.Armor, 2); if (maxCount != -1 && (other->Client.pers.Inventory.Has(other->Client.pers.Armor) > maxCount)) other->Client.pers.Inventory.Set(other->Client.pers.Armor, maxCount); } if (!(ent->spawnflags & DROPPED_ITEM) && (game.mode & GAME_DEATHMATCH)) SetRespawn (ent, 20); return true; } if (other->Client.pers.Armor != NULL) { if (normalProtection > other->Client.pers.Armor->normalProtection) { // calc new armor values int newCount = baseCount + (((float)other->Client.pers.Armor->normalProtection / (float)normalProtection) * other->Client.pers.Inventory.Has(other->Client.pers.Armor)); if (newCount > maxCount) newCount = maxCount; // zero count of old armor so it goes away other->Client.pers.Inventory.Set(other->Client.pers.Armor, 0); // change armor to new item with computed value other->Client.pers.Inventory.Set(this, newCount); other->Client.pers.Armor = this; } else { // calc new armor values int newCount = other->Client.pers.Inventory.Has(other->Client.pers.Armor) + (((float)normalProtection / (float)other->Client.pers.Armor->normalProtection) * this->baseCount); if (newCount > other->Client.pers.Armor->maxCount) newCount = other->Client.pers.Armor->maxCount; // if we're already maxed out then we don't need the new armor if (other->Client.pers.Inventory.Has(other->Client.pers.Armor) >= newCount) return false; // update current armor value other->Client.pers.Inventory.Set(other->Client.pers.Armor, newCount); } } // Player has no other armor, just use it else { other->Client.pers.Armor = this; other->Client.pers.Inventory.Set(this, baseCount); } if (!(ent->spawnflags & DROPPED_ITEM) && (game.mode & GAME_DEATHMATCH)) SetRespawn (ent, 20); return true;}