Esempio n. 1
0
/**
* Handle a pickup by a unit.
*
* @return True on success, false on failure (e.g. wrong weapon for ammo box)
**/
bool PickupType::doUse(Unit *u)
{
	GameState *st = u->getGameState();

	switch (this->type) {
		case PICKUP_TYPE_WEAPON:
			assert(this->wt);
			st->addHUDMessage(u->slot, "Picked up a ", this->wt->title);
			u->pickupWeapon(this->wt);
			break;

		case PICKUP_TYPE_AMMO:
			{
				bool success = false;
				if (this->wt == NULL) {
					WeaponType *wt = u->getWeaponTypeCurr();
					if (wt == NULL) return false;
					success = u->pickupAmmo(wt);
				} else {
					success = u->pickupAmmo(this->wt);
				}

				if (! success) return false;

				st->addHUDMessage(u->slot, "Picked up some ammo");
			}
			break;

		case PICKUP_TYPE_POWERUP:
			u->applyPickupAdjust(this->perm);
			u->applyPickupAdjust(this->temp);
			u->addActivePickup(this);

			if (!this->title.empty()) {
				st->addHUDMessage(u->slot, "Picked up a ", this->title);
			}

			// Apply any combos
			for (vector<PowerupCombo>::iterator it = this->combos.begin(); it != this->combos.end(); ++it) {
				if ((*it).benefit != NULL && u->hasActivePickup((*it).second)) {
					(*it).benefit->doUse(u);
				}
			}
			break;

		case PICKUP_TYPE_CURSOR:
			return false;
			break;

		default:
			assert(0);
	}

	return true;
}