bool BattleTarget::SetTarget(BattleActor* attacker, vt_global::GLOBAL_TARGET type, BattleActor* target, uint32_t attack_point) { if((type <= GLOBAL_TARGET_INVALID) || (type >= GLOBAL_TARGET_TOTAL)) { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type argument: " << type << std::endl; return false; } if (attacker == nullptr) { PRINT_ERROR << "BattleTarget::SetTarget() called wirh nullptr attacker." << std::endl; return false; } InvalidateTarget(); // Set the target party according to the target type std::deque<BattleActor *>* party_target = nullptr; switch(type) { case GLOBAL_TARGET_SELF_POINT: case GLOBAL_TARGET_ALLY_POINT: case GLOBAL_TARGET_SELF: case GLOBAL_TARGET_ALLY: case GLOBAL_TARGET_ALLY_EVEN_DEAD: case GLOBAL_TARGET_DEAD_ALLY_ONLY: case GLOBAL_TARGET_ALL_ALLIES: if(attacker->IsEnemy()) party_target = &BattleMode::CurrentInstance()->GetEnemyParty(); else party_target = &BattleMode::CurrentInstance()->GetCharacterParty(); break; case GLOBAL_TARGET_FOE_POINT: case GLOBAL_TARGET_FOE: case GLOBAL_TARGET_ALL_FOES: if(attacker->IsEnemy()) party_target = &BattleMode::CurrentInstance()->GetCharacterParty(); else party_target = &BattleMode::CurrentInstance()->GetEnemyParty(); break; default: // Shouldn't happen PRINT_WARNING << "Invalid target type argument: " << type << std::endl; return false; break; } // Check whether the actor is actually part of the party and fix this if needed. if (target && std::find(party_target->begin(), party_target->end(), target) == party_target->end()) target = party_target->at(0); if (target != nullptr) _actor_target = target; else _actor_target = party_target->at(0); _type = type; _party_target.clear(); for (size_t i = 0; i < party_target->size(); ++i) { if (type != GLOBAL_TARGET_ALL_FOES) { _party_target.push_back(party_target->at(i)); } else { if (party_target->at(i)->CanFight()) { _party_target.push_back(party_target->at(i)); } } } _attack_point = attack_point; if (_attack_point >= _actor_target->GetAttackPoints().size()) _attack_point = 0; // If the target is not a party and not the user themselves, select the first valid actor if (type != GLOBAL_TARGET_ALL_FOES && (!IsValid() && !SelectNextActor())) { InvalidateTarget(); PRINT_WARNING << "Could not find an initial actor that was a valid target" << std::endl; return false; } return true; }
bool BattleTarget::SetInitialTarget(BattleActor* user, GLOBAL_TARGET type) { InvalidateTarget(); if (user == NULL) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL argument" << std::endl; return false; } if ((type <= GLOBAL_TARGET_INVALID) || (type >= GLOBAL_TARGET_TOTAL)) { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type argument: " << type << std::endl; return false; } // Determine what party the initial target will exist in std::deque<BattleActor*>* target_party; if ((type == GLOBAL_TARGET_ALLY_POINT) || (type == GLOBAL_TARGET_ALLY) || (type == GLOBAL_TARGET_ALL_ALLIES) || (type == GLOBAL_TARGET_ALLY_EVEN_DEAD)) { if (user->IsEnemy() == false) target_party = &BattleMode::CurrentInstance()->GetCharacterParty(); else target_party = &BattleMode::CurrentInstance()->GetEnemyParty(); } else if ((type == GLOBAL_TARGET_FOE_POINT) || (type == GLOBAL_TARGET_FOE) || (type == GLOBAL_TARGET_ALL_FOES)) { if (user->IsEnemy() == false) target_party = &BattleMode::CurrentInstance()->GetEnemyParty(); else target_party = &BattleMode::CurrentInstance()->GetCharacterParty(); } else { target_party = NULL; } // Set the actor/party according to the target type switch (type) { case GLOBAL_TARGET_SELF_POINT: case GLOBAL_TARGET_SELF: case GLOBAL_TARGET_ALLY_POINT: case GLOBAL_TARGET_ALLY: _actor = user; break; case GLOBAL_TARGET_ALLY_EVEN_DEAD: case GLOBAL_TARGET_FOE_POINT: case GLOBAL_TARGET_FOE: _actor = target_party->at(0); break; case GLOBAL_TARGET_ALL_ALLIES: case GLOBAL_TARGET_ALL_FOES: _party = target_party; break; default: IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid type: " << type << std::endl; return false; } _type = type; // If the target is not a party and not the user themselves, select the first valid actor if ((_actor != NULL) && (_actor != user)) { if (!IsValid()) { if (!SelectNextActor(user, true, true)) { IF_PRINT_WARNING(BATTLE_DEBUG) << "could not find an initial actor that was a valid target" << std::endl; return false; } } } return true; }