void Scene_Battle_Rpg2k::SelectNextActor() { std::vector<Game_Actor*> allies = Main_Data::game_party->GetActors(); if ((size_t)actor_index == allies.size()) { // All actor actions decided, player turn ends SetState(State_Battle); CreateEnemyActions(); CreateExecutionOrder(); NextTurn(); Game_Battle::RefreshEvents(); return; } active_actor = allies[actor_index]; status_window->SetIndex(actor_index); actor_index++; if (active_actor->IsDead()) { SelectNextActor(); return; } Game_Battler* random_target = NULL; if (active_actor->CanAct()) { switch (active_actor->GetSignificantRestriction()) { case RPG::State::Restriction_attack_ally: random_target = Main_Data::game_party->GetRandomActiveBattler(); break; case RPG::State::Restriction_attack_enemy: random_target = Main_Data::game_enemyparty->GetRandomActiveBattler(); break; } } else { active_actor->SetBattleAlgorithm(std::make_shared<Game_BattleAlgorithm::NoMove>(active_actor)); battle_actions.push_back(active_actor); SelectNextActor(); return; } if (random_target || auto_battle || active_actor->GetAutoBattle()) { if (!random_target) { random_target = Main_Data::game_enemyparty->GetRandomActiveBattler(); } // ToDo: Auto battle logic is dumb active_actor->SetBattleAlgorithm(std::make_shared<Game_BattleAlgorithm::Normal>(active_actor, random_target)); battle_actions.push_back(active_actor); SelectNextActor(); return; } SetState(Scene_Battle::State_SelectCommand); }
bool BattleTarget::SelectNextPoint(bool direction) { if(IsTargetPoint(_type) == false) { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl; return false; } if(_actor_target == nullptr || _party_target.empty()) { IF_PRINT_WARNING(BATTLE_DEBUG) << "No valid target set" << std::endl; return false; } // First check for the case where we need to select a new actor first if(!IsValid()) { _attack_point = 0; return SelectNextActor(); } // If the actor has only a single attack point, there's no way to select another attack point uint32_t num_points = _actor_target->GetAttackPoints().size(); if(num_points == 1) return true; if(direction == true) { ++_attack_point; if(_attack_point >= num_points) _attack_point = 0; } else { if(_attack_point == 0) _attack_point = num_points - 1; else --_attack_point; } return true; }
void KeyboardCallback(unsigned char key, int x, int y) { gKeys[key] = true; switch (key) { case 'r': { SelectNextActor(); break; } default: { break; } } }
void KeyboardCallback(unsigned char key, int /*x*/, int /*y*/) { gKeys[key] = true; switch (key) { case 'r': { SelectNextActor(); break; } case 'c': { bHWScene = !bHWScene; CreateScenario(); break; } default: { break; } } }
void KeyboardCallback(unsigned char key, int x, int y) { gKeys[key] = true; switch (key) { case 'r': { if (!bShapeSelectMode) { SelectNextActor(); } else { SelectNextShapeOnActor(gSelectedActor); } break; } default: { break; } } }
void Scene_Battle_Rpg2k3::Update() { switch (state) { case State_SelectActor: case State_AutoBattle: { if (battle_actions.empty()) { Game_Battle::UpdateGauges(); } SelectNextActor(); std::vector<Game_Battler*> enemies; Main_Data::game_enemyparty->GetActiveBattlers(enemies); for (std::vector<Game_Battler*>::iterator it = enemies.begin(); it != enemies.end(); ++it) { if ((*it)->IsGaugeFull() && !(*it)->GetBattleAlgorithm()) { Game_Enemy* enemy = static_cast<Game_Enemy*>(*it); const RPG::EnemyAction* action = enemy->ChooseRandomAction(); if (action) { CreateEnemyAction(enemy, action); } } } break; } default:; } for (std::vector<FloatText>::iterator it = floating_texts.begin(); it != floating_texts.end();) { (*it).second -= 1; if ((*it).second <= 0) { it = floating_texts.erase(it); } else { ++it; } } Scene_Battle::Update(); UpdateCursors(); //enemy_status_window->Update(); }
bool BattleTarget::SelectNextPoint(BattleActor* user, bool direction, bool valid_criteria, bool permit_dead_targets) { if (user == NULL) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL argument" << std::endl; return false; } if (IsTargetPoint(_type) == false) { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl; return false; } if (_actor == NULL) { IF_PRINT_WARNING(BATTLE_DEBUG) << "no valid actor target" << std::endl; return false; } // First check for the case where we need to select a new actor if (valid_criteria && !IsValid(permit_dead_targets)) { _point = 0; return SelectNextActor(user, direction, valid_criteria, permit_dead_targets); } // If the actor has only a single attack point, there's no way to select another attack point uint32 num_points = _actor->GetAttackPoints().size(); if (num_points == 1) { return false; } if (direction == true) { _point++; if (_point >= num_points) _point = 0; } else { if (_point == 0) _point = num_points - 1; else _point--; } return true; }
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; }
void Scene_Battle_Rpg2k::ProcessInput() { if (Input::IsTriggered(Input::DECISION)) { switch (state) { case State_Start: // no-op break; case State_SelectOption: // Interpreter message boxes pop up in this state if (!message_window->GetVisible()) { OptionSelected(); } break; case State_SelectActor: SetState(State_SelectCommand); SelectNextActor(); break; case State_AutoBattle: // no-op break; case State_SelectCommand: CommandSelected(); break; case State_SelectEnemyTarget: EnemySelected(); break; case State_SelectAllyTarget: AllySelected(); break; case State_Battle: // no-op break; case State_SelectItem: ItemSelected(); break; case State_SelectSkill: SkillSelected(); break; case State_Victory: case State_Defeat: case State_Escape: // no-op break; } } if (Input::IsTriggered(Input::CANCEL)) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cancel)); switch (state) { case State_Start: case State_SelectOption: // no-op break; case State_SelectActor: case State_AutoBattle: SetState(State_SelectOption); break; case State_SelectCommand: --actor_index; SelectPreviousActor(); break; case State_SelectEnemyTarget: case State_SelectItem: case State_SelectSkill: SetState(State_SelectCommand); break; case State_SelectAllyTarget: SetState(previous_state); break; case State_Battle: // no-op break; case State_Victory: case State_Defeat: case State_Escape: // no-op break; } } }
void Scene_Battle_Rpg2k::ProcessActions() { switch (state) { case State_Start: if (DisplayMonstersInMessageWindow()) { SetState(State_SelectOption); CheckResultConditions(); } break; case State_SelectOption: // No Auto battle/Escape when all actors are sleeping or similar if (!Main_Data::game_party->IsAnyControllable()) { SelectNextActor(); } break; case State_SelectActor: case State_AutoBattle: CheckResultConditions(); if (help_window->GetVisible() && message_timer > 0) { message_timer--; if (message_timer <= 0) help_window->SetVisible(false); } break; case State_Battle: if (!battle_actions.empty()) { if (battle_actions.front()->IsDead()) { // No zombies allowed ;) RemoveCurrentAction(); } else if (ProcessBattleAction(battle_actions.front()->GetBattleAlgorithm().get())) { RemoveCurrentAction(); battle_message_window->Clear(); if (CheckResultConditions()) { return; } } } else { // Everybody acted actor_index = 0; SetState(State_SelectOption); } break; case State_SelectEnemyTarget: { static int flash_count = 0; std::vector<Game_Battler*> enemies; Main_Data::game_enemyparty->GetActiveBattlers(enemies); Game_Enemy* target = static_cast<Game_Enemy*>(enemies[target_window->GetIndex()]); Sprite_Battler* sprite = Game_Battle::GetSpriteset().FindBattler(target); if (sprite) { ++flash_count; if (flash_count == 60) { sprite->Flash(Color(255, 255, 255, 100), 15); flash_count = 0; } } break; } case State_Victory: Scene::Pop(); break; case State_Defeat: if (Player::battle_test_flag || Game_Temp::battle_defeat_mode != 0) { Scene::Pop(); } else { Scene::Push(EASYRPG_MAKE_SHARED<Scene_Gameover>()); } break; case State_Escape: Escape(); break; default: break; } }
void Scene_Battle_Rpg2k::SetState(Scene_Battle::State new_state) { previous_state = state; state = new_state; options_window->SetActive(false); status_window->SetActive(false); command_window->SetActive(false); item_window->SetActive(false); skill_window->SetActive(false); target_window->SetActive(false); battle_message_window->SetActive(false); switch (state) { case State_Start: battle_message_window->SetActive(true); break; case State_SelectOption: options_window->SetActive(true); break; case State_SelectActor: status_window->SetActive(true); break; case State_AutoBattle: break; case State_SelectCommand: command_window->SetActive(true); RefreshCommandWindow(); break; case State_SelectEnemyTarget: break; case State_SelectAllyTarget: status_window->SetActive(true); break; case State_Battle: // no-op break; case State_SelectItem: item_window->SetActive(true); item_window->Refresh(); break; case State_SelectSkill: skill_window->SetActive(true); skill_window->SetActor(active_actor->GetId()); skill_window->SetIndex(0); break; case State_Victory: case State_Defeat: // no-op case State_Escape: battle_message_window->SetActive(true); break; } options_window->SetVisible(false); status_window->SetVisible(false); command_window->SetVisible(false); item_window->SetVisible(false); skill_window->SetVisible(false); help_window->SetVisible(false); target_window->SetVisible(false); battle_message_window->SetVisible(false); switch (state) { case State_Start: battle_message_window->SetVisible(true); break; case State_SelectOption: options_window->SetVisible(true); status_window->SetVisible(true); status_window->SetX(76); status_window->SetIndex(-1); status_window->Refresh(); break; case State_SelectActor: SelectNextActor(); break; case State_AutoBattle: SetState(State_SelectActor); break; case State_SelectCommand: status_window->SetVisible(true); command_window->SetVisible(true); status_window->SetX(0); break; case State_SelectEnemyTarget: status_window->SetVisible(true); command_window->SetVisible(true); target_window->SetActive(true); target_window->SetVisible(true); break; case State_SelectAllyTarget: status_window->SetVisible(true); status_window->SetX(0); command_window->SetVisible(true); break; case State_Battle: battle_message_window->SetVisible(true); break; case State_SelectItem: item_window->SetVisible(true); item_window->SetHelpWindow(help_window.get()); help_window->SetVisible(true); break; case State_SelectSkill: skill_window->SetVisible(true); skill_window->SetHelpWindow(help_window.get()); help_window->SetVisible(true); break; case State_Victory: case State_Defeat: // no-op break; case State_Escape: battle_message_window->SetVisible(true); break; } }
void KeyboardCallback(unsigned char key, int x, int y) { gKeys[key] = true; switch (key) { case 'r': { SelectNextActor(); break; } case 'c': { // Iterate overlap type int i = (int)gOverlapType; i = (++i) % 9; gOverlapType = (OverlapType)i; break; } case '1': if ((OVERLAP_SPHERE == gOverlapType) || (OVERLAP_CHECK_SPHERE == gOverlapType)) { gSphereCenter.z += 0.2f; } else if ((OVERLAP_CAPSULE == gOverlapType) || (OVERLAP_CHECK_CAPSULE == gOverlapType)) { gCapsuleSegment.p0.z += 0.2f; gCapsuleSegment.p1.z += 0.2f; } else if ((OVERLAP_AABB == gOverlapType) || (OVERLAP_CHECK_AABB == gOverlapType)) { gMIN.z += 0.2f; gMAX.z += 0.2f; } else if ((OVERLAP_OBB == gOverlapType) || (OVERLAP_CHECK_OBB == gOverlapType)) { gBoxCenter += NxVec3(0, 0, 0.2f); } break; case '2': if ((OVERLAP_SPHERE == gOverlapType) || (OVERLAP_CHECK_SPHERE == gOverlapType)) { gSphereCenter.z -= 0.2f; } else if ((OVERLAP_CAPSULE == gOverlapType) || (OVERLAP_CHECK_CAPSULE == gOverlapType)) { gCapsuleSegment.p0.z -= 0.2f; gCapsuleSegment.p1.z -= 0.2f; } else if ((OVERLAP_AABB == gOverlapType) || (OVERLAP_CHECK_AABB == gOverlapType)) { gMIN.z -= 0.2f; gMAX.z -= 0.2f; } else if ((OVERLAP_OBB == gOverlapType) || (OVERLAP_CHECK_OBB == gOverlapType)) { gBoxCenter += NxVec3(0, 0, -0.2f); } break; case '3': if ((OVERLAP_SPHERE == gOverlapType) || (OVERLAP_CHECK_SPHERE == gOverlapType)) { gSphereCenter.x += 0.2f; } else if ((OVERLAP_CAPSULE == gOverlapType) || (OVERLAP_CHECK_CAPSULE == gOverlapType)) { gCapsuleSegment.p0.x += 0.2f; gCapsuleSegment.p1.x += 0.2f; } else if ((OVERLAP_AABB == gOverlapType) || (OVERLAP_CHECK_AABB == gOverlapType)) { gMIN.x += 0.2f; gMAX.x += 0.2f; } else if ((OVERLAP_OBB == gOverlapType) || (OVERLAP_CHECK_OBB == gOverlapType)) { gBoxCenter += NxVec3(0.2f, 0, 0); } break; case '4': if ((OVERLAP_SPHERE == gOverlapType) || (OVERLAP_CHECK_SPHERE == gOverlapType)) { gSphereCenter.x -= 0.2f; } else if ((OVERLAP_CAPSULE == gOverlapType) || (OVERLAP_CHECK_CAPSULE == gOverlapType)) { gCapsuleSegment.p0.x -= 0.2f; gCapsuleSegment.p1.x -= 0.2f; } else if ((OVERLAP_AABB == gOverlapType) || (OVERLAP_CHECK_AABB == gOverlapType)) { gMIN.x -= 0.2f; gMAX.x -= 0.2f; } else if ((OVERLAP_OBB == gOverlapType) || (OVERLAP_CHECK_OBB == gOverlapType)) { gBoxCenter += NxVec3(-0.2f, 0, 0); } break; case '5': if ((OVERLAP_SPHERE == gOverlapType) || (OVERLAP_CHECK_SPHERE == gOverlapType)) { gSphereCenter.y += 0.2f; } else if ((OVERLAP_CAPSULE == gOverlapType) || (OVERLAP_CHECK_CAPSULE == gOverlapType)) { gCapsuleSegment.p0.y += 0.2f; gCapsuleSegment.p1.y += 0.2f; } else if ((OVERLAP_AABB == gOverlapType) || (OVERLAP_CHECK_AABB == gOverlapType)) { gMIN.y += 0.2f; gMAX.y += 0.2f; } else if ((OVERLAP_OBB == gOverlapType) || (OVERLAP_CHECK_OBB == gOverlapType)) { gBoxCenter += NxVec3(0, 0.2f, 0); } break; case '6': if ((OVERLAP_SPHERE == gOverlapType) || (OVERLAP_CHECK_SPHERE == gOverlapType)) { gSphereCenter.y -= 0.2f; } else if ((OVERLAP_CAPSULE == gOverlapType) || (OVERLAP_CHECK_CAPSULE == gOverlapType)) { gCapsuleSegment.p0.y -= 0.2f; gCapsuleSegment.p1.y -= 0.2f; } else if ((OVERLAP_AABB == gOverlapType) || (OVERLAP_CHECK_AABB == gOverlapType)) { gMIN.y -= 0.2f; gMAX.y -= 0.2f; } else if ((OVERLAP_OBB == gOverlapType) || (OVERLAP_CHECK_OBB == gOverlapType)) { gBoxCenter += NxVec3(0, -0.2f, 0); } break; default: { break; } } }
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; }