本文整理汇总了C++中Weapon类的典型用法代码示例。如果您正苦于以下问题:C++ Weapon类的具体用法?C++ Weapon怎么用?C++ Weapon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Weapon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: useEquipment
bool Fruit::useEquipment(Equipment *equipment, Entity *target)
{
if (((equipment->getType() >= EQUIPMENT_TEA_SPOON) && (equipment->getType() <= EQUIPMENT_SALT_SNIPER)) || ((equipment->getType() == EQUIPMENT_JUICE_NEEDLE)))
{
Weapon *weapon = (Weapon*)equipment;
return weapon->use(target);
}
else if (equipment->getType() == EQUIPMENT_PEELER)
{
Peeler *peeler = (Peeler*)equipment;
return peeler->use(target);
}
else if (equipment->getType() == EQUIPMENT_RELOADER)
{
Loader *loader = (Loader*)equipment;
return loader->use(target);
}
return false;
}
示例2: Ignore
void
NetPlayer::SetShip(Ship* s)
{
if (ship != s) {
if (ship) {
ship->EnableRepair(true);
Ignore(ship);
}
ship = s;
if (ship) {
Observe(ship);
ship->SetNetworkControl(this);
ship->SetObjID(objid);
iff = ship->GetIFF();
// Turn off auto-repair. All repair data should
// come in over the network from the remote player:
ship->EnableRepair(false);
// Set all ship weapons back to manual fire control.
// All trigger events should come over the network,
// not from weapon auto aiming ai:
ListIter<WeaponGroup> iter = ship->Weapons();
while (++iter) {
WeaponGroup* group = iter.value();
ListIter<Weapon> w_iter = group->GetWeapons();
while (++w_iter) {
Weapon* weapon = w_iter.value();
weapon->SetFiringOrders(Weapon::MANUAL);
}
}
}
}
}
示例3: while
void CharacterCore::addSpell(SpellID id, int slotNr) {
Weapon* wep = dynamic_cast<Weapon*>(m_equippedItems.at(ItemType::Equipment_weapon));
if (wep == nullptr) return;
if (!wep->isSpellAllowed(slotNr, id)) return;
// check if this spell is already in another slot, if yes, remove that
for (auto& it : m_data.equippedWeaponSlots) {
if (it.first == id) {
it.first = SpellID::VOID;
it.second.clear();
}
}
while (m_data.equippedWeaponSlots.size() - 1 < slotNr) {
m_data.equippedWeaponSlots.push_back(std::pair<SpellID, std::vector<SpellModifier>>({SpellID::VOID, std::vector<SpellModifier>()}));
}
m_data.equippedWeaponSlots.at(slotNr).first = id;
m_data.equippedWeaponSlots.at(slotNr).second.clear();
reloadWeaponSlots();
}
示例4: main
int main()
{
{
Weapon club = Weapon("crude spiked club");
HumanA bob("Bob", club);
bob.attack();
club.setType("some other type of club");
bob.attack();
}
{
Weapon club = Weapon("crude spiked club");
HumanB jim("Jim");
jim.setWeapon(club);
jim.attack();
club.setType("some other type of club");
jim.attack();
}
return 0;
}
示例5: fire
void Ship::fire(int weaponIndex)
{
if (weaponIndex >= 0 && weaponIndex < (int)weapons_.size())
{
transform_->getMatrix(weaponTransformation_, false);
//keeping weapon's local direction
Weapon* weapon = weapons_[weaponIndex].first;
weapon->currentDirection = weapon->direction;
weapon->currentDirection.rotateVector(weaponTransformation_);
//keeping weapon's local position
Vector3 weaponPos = weapons_[weaponIndex].second;
weaponPos.rotateVector(weaponTransformation_);
weapon->position = transform_->getPosition() + weaponPos;
weapon->fire();
}
else
Logger::PrintWarning("Ship::fire - invalid argument\n");
}
示例6: reloadWeaponSlots
void CharacterCore::addModifier(const SpellModifier& modifier, int slotNr)
{
Weapon* wep = dynamic_cast<Weapon*>(m_equippedItems.at(ItemType::Equipment_weapon));
if (wep == nullptr) return;
if (wep->addModifier(slotNr, modifier, true))
{
std::pair<SpellID, std::vector<SpellModifier>>& slot = m_data.equippedWeaponSlots.at(slotNr);
// check if this type already exists. if yes, remove it.
for (auto& it = slot.second.begin(); it != slot.second.end(); /* don't increment here */)
{
if (it->type == modifier.type)
{
it = slot.second.erase(it);
}
else ++it;
}
slot.second.push_back(modifier);
}
reloadWeaponSlots();
}
示例7: if
void SideScroller::Update(float elapsed) {
if (state == STATE_TITLE)
{
return;
}
else if (state == STATE_GAME)
{
if (enemySpawnTimer > 0.8f && enemies.size() < 50) {
Enemy* tempEnemy = new PewRunner(tex);
tempEnemy->y = player->y + 4.0f;
tempEnemy->x = player->x + 10.0f;
tempEnemy->setScale(2.5f);
if (genRandomNumber(0.0f, 1.0f) > 0.93f) {
//Grant him knighthood
tempEnemy->hp += 30;
Weapon* weapon = new Weapon(tex);
weapon->changeWeapon(SWORD);
tempEnemy->equip(weapon);
entities.push_back(weapon);
}
tempEnemy->setWalkLeft(0.8f);
enemies.push_back(tempEnemy);
entities.push_back(tempEnemy);
enemySpawnTimer = genRandomNumber(0.0f, 0.75f);
}
for (size_t i = 0; i < entities.size(); i++) {
entities[i]->Update(elapsed);
}
for (size_t i = 0; i < projectiles.size(); i++) {
projectiles[i]->Update(elapsed);
}
enemySpawnTimer += elapsed;
}
}
示例8: do_zap
//do_zap: Perform a zap with a wand
bool do_zap()
{
Coord delta;
if (!get_dir(&delta))
return false;
Item *item = get_item("zap with", STICK);
if (!item)
return false;
Stick* stick = dynamic_cast<Stick*>(item);
Weapon* weapon = dynamic_cast<Weapon*>(item);
if (!(stick || (weapon && weapon->is_vorpalized() && weapon->charges()))) {
//mdk: zapping with non-stick doesn't count as turn
msg("you can't zap with that!");
return false;
}
// Handle the special case of a vorpalized weapon
if (weapon) {
game->screen().play_sound("zap");
if (weapon->zap_vorpalized_weapon(delta)) {
weapon->use_charge();
}
return true;
}
// Zap the appropriate stick
if (stick->charges() == 0) {
msg("nothing happens");
}
else{
game->screen().play_sound("zap");
if (stick->Zap(delta)) {
stick->use_charge();
}
}
return true;
}
示例9: Run
void Obstacle::Run(Weapon &weapon1,Player &player1,Weapon &weapon2,Player &player2)
{
double b1x=weapon1.GetBullet()->x();
double b1y=weapon1.GetBullet()->y();
int p1x=player1.getX();
int p1y=player1.getY();
double b2x=weapon2.GetBullet()->x();
double b2y=weapon2.GetBullet()->y();
int p2x=player2.getX();
int p2y=player2.getY();
Draw(p1x,p1y,p2x,p2y);
Move();
CheckCollision(b1x,b1y,b2x,b2y);
if (hstate1==1) {
player1.health-=0.2;
hstate1=0;
}
if (hstate2==1) {
player2.health-=0.2;
hstate2=0;
}
if (state1==1)
{
countdown+=0.9;
if (countdown>1.2)
{
state1=0;
countdown=0;
}
}
if (state2==1)
{
countdown+=0.9;
if (countdown>1.2)
{
state2=0;
countdown=0;
}
}
}
示例10: tryAddEffectsFromWeapon
void StatusEffectsHandler::tryAddEffectsFromWeapon(const Weapon& wpn, const bool IS_MELEE) {
const ItemDefinition& wpnDef = wpn.getDef();
StatusEffect* wpnEffect = IS_MELEE ? wpnDef.meleeStatusEffect : wpnDef.rangedStatusEffect;
if(wpnEffect != NULL) {
//Make a new copy of the weapon effect
StatusEffect* cpy = wpnEffect->copy();
//Attempt to add the effect to the actor.
//If attempt fails (saving throw succeeds, immune, etc), the copy is destroyed.
tryAddEffect(cpy);
}
}
示例11: assert
void DebriefMenu::handleGameEvent(GameEvent evt) {
if (evt.type_ == GameEvent::GE_SEARCH) {
// A research has ended, so check which type
Research *pRes = static_cast<Research *> (evt.pCtxt_);
// Is it equipment or mods research?
if (pRes->getType() == Research::EQUIPS) {
// Get researched weapon type
Weapon::WeaponType wt= pRes->getSearchWeapon();
assert(wt);
// Get weapon
Weapon *pWeap = g_App.weapons().getWeapon(wt);
assert(pWeap);
// Draw name of it
getStatic(txtSearchId_)->setTextFormated("#DEBRIEF_SEARCH", pWeap->getName());
} else {
// Must be mods research so draw it
getStatic(txtSearchId_)->setTextFormated("#DEBRIEF_SEARCH", pRes->getName().c_str());
}
}
}
示例12: while
bool
StarshipAI::AssessTargetPointDefense()
{
if (Game::GameTime() - point_defense_time < 3500)
return tgt_point_defense;
tgt_point_defense = false;
if (!target || target->Type() != SimObject::SIM_SHIP || GetAILevel() < 2)
return tgt_point_defense;
Ship* tgt_ship = (Ship*) target;
if (!tgt_ship->IsStarship())
return tgt_point_defense;
Weapon* subtgt = 0;
Point svec = ship->Location() - tgt_ship->Location();
point_defense_time = Game::GameTime();
// first pass: turrets
ListIter<WeaponGroup> g_iter = tgt_ship->Weapons();
while (++g_iter && !tgt_point_defense) {
WeaponGroup* g = g_iter.value();
if (g->CanTarget(1)) {
ListIter<Weapon> w_iter = g->GetWeapons();
while (++w_iter && !tgt_point_defense) {
Weapon* w = w_iter.value();
if (w->Availability() > 35 && w->GetAimVector() * svec > 0)
tgt_point_defense = true;
}
}
}
return tgt_point_defense;
}
示例13: while
int
WeaponGroup::Status() const
{
int status = System::NOMINAL;
int critical = true;
ListIter<Weapon> iter = (List<Weapon>&) weapons; // cast-away const
while (++iter) {
Weapon* w = iter.value();
if (w->Status() < System::NOMINAL)
status = System::DEGRADED;
if (w->Status() > System::CRITICAL)
critical = false;
}
if (critical)
return System::CRITICAL;
return status;
}
示例14: ASSERT
// Enter the state
void PlayerReloadingState::enter(PlayerUnit *ref)
{
ASSERT(ref->getActualWeapon());
Weapon *w = ref->getActualWeapon();
// depending of the weapon, we will get the animation
switch(w->getType()){
case Weapon::W_SHORT:
ref->changeAnimation(PlayerUnit::ANIM_RELOAD_SHORT);
break;
case Weapon::W_LONG:
ref->changeAnimation(PlayerUnit::ANIM_RELOAD_LONG);
break;
default:
ASSERT(false);
}
ASSERT(w->getAmmunition() > 0);
}
示例15: usesMeleeWeapons
void BasicMonster::useBestWeapon()
{
bool melee = usesMeleeWeapons();
bool ranged = usesRangedWeapons();
int bestScore = -1;
symbol bestWeapon = '\0';
for (auto it = inventory.begin(); it != inventory.end(); it++)
{
if (it->second->getType() != ITEM_WEAPON) continue;
Weapon* weapon = static_cast<Weapon*>(it->second);
if (weapon->getRange() <= 1 && !melee) continue;
if (weapon->getRange() > 1 && !ranged) continue;
int score = scoreWeapon(weapon);
if (score > bestScore)
{
bestScore = score;
bestWeapon = it->first;
}
}
mainWeapon = bestWeapon;
}