void Game_Player::Update() { bool last_moving = IsMoving(); if (!IsMoving() && !Game_Map::GetInterpreter().IsRunning() && !IsMoveRouteOverwritten() && !Game_Message::message_waiting) { switch (Input::dir4) { case 2: MoveDown(); break; case 4: MoveLeft(); break; case 6: MoveRight(); break; case 8: MoveUp(); } } int last_real_x = real_x; int last_real_y = real_y; Game_Character::Update(); UpdateScroll(last_real_x, last_real_y); UpdateNonMoving(last_moving); }
void Game_Player::CancelMoveRoute() { if (!IsMoveRouteOverwritten()) return; // Bugfix: Moved up from end of function. The fix for #1051 in CheckTouchEvent made the Touch check always returning // false because the MoveRoute was still marked as overwritten Game_Character::CancelMoveRoute(); // If the last executed command of the move route was a Move command, check touch and collision triggers const RPG::MoveRoute& active_route = GetMoveRoute(); int index = GetMoveRouteIndex(); if (!active_route.move_commands.empty()) { int move_size = static_cast<int>(active_route.move_commands.size()); if (index >= move_size) { index = move_size - 1; } // Touch/Collision events are only triggered after the end of a move route when the last command of the move // route was any movement command. // "any_move_successful" handles the corner case that the last command was a movement but the Player never // changed the tile (because the way was blocked), then no event handling occurs. if (active_route.move_commands[index].command_id <= RPG::MoveCommand::Code::move_forward && any_move_successful) { CheckTouchEvent(); CheckCollisionEvent(); } } }
bool Game_Player::CheckTouchEvent() { if (InAirship()) return false; if (IsMoveRouteOverwritten()) return false; return CheckEventTriggerHere({RPG::EventPage::Trigger_touched}); }
void Game_Character::Update() { if (IsJumping()) { UpdateJump(); if (IsSpinning()) anime_count++; } else if (IsMoving()) { remaining_step -= 1 << (1 + GetMoveSpeed()); if (IsSpinning() || (animation_type != RPG::EventPage::AnimType_fixed_graphic && walk_animation)) anime_count++; } else { stop_count++; if (IsSpinning() || IsContinuous() || pattern != original_pattern) anime_count++; } if (anime_count >= GetSteppingSpeed()) { if (IsSpinning()) { SetSpriteDirection((GetSpriteDirection() + 1) % 4); } else if (!IsContinuous() && IsStopping()) { pattern = original_pattern; last_pattern = last_pattern == RPG::EventPage::Frame_left ? RPG::EventPage::Frame_right : RPG::EventPage::Frame_left; } else { if (last_pattern == RPG::EventPage::Frame_left) { if (pattern == RPG::EventPage::Frame_right) { pattern = RPG::EventPage::Frame_middle; last_pattern = RPG::EventPage::Frame_right; } else { pattern = RPG::EventPage::Frame_right; } } else { if (pattern == RPG::EventPage::Frame_left) { pattern = RPG::EventPage::Frame_middle; last_pattern = RPG::EventPage::Frame_left; } else { pattern = RPG::EventPage::Frame_left; } } } anime_count = 0; } if (wait_count > 0) { wait_count -= 1; return; } if (stop_count >= max_stop_count) { if (IsMoveRouteOverwritten()) { MoveTypeCustom(); } else { // Only events UpdateSelfMovement(); } } }
void Game_Character::Update() { if (IsJumping()) { UpdateJump(); anime_count += (IsSpinning() ? 1.0 : 0); } else if (IsContinuous() || IsSpinning()) { UpdateMove(); UpdateStop(); } else { if (IsMoving()) { UpdateMove(); } else { UpdateStop(); } } if (anime_count > 36.0/(GetMoveSpeed()+1)) { if (IsSpinning()) { SetPrelockDirection((GetPrelockDirection() + 1) % 4); } else if (!IsContinuous() && IsStopping()) { pattern = original_pattern; last_pattern = last_pattern == RPG::EventPage::Frame_left ? RPG::EventPage::Frame_right : RPG::EventPage::Frame_left; } else { if (last_pattern == RPG::EventPage::Frame_left) { if (pattern == RPG::EventPage::Frame_right) { pattern = RPG::EventPage::Frame_middle; last_pattern = RPG::EventPage::Frame_right; } else { pattern = RPG::EventPage::Frame_right; } } else { if (pattern == RPG::EventPage::Frame_left) { pattern = RPG::EventPage::Frame_middle; last_pattern = RPG::EventPage::Frame_left; } else { pattern = RPG::EventPage::Frame_left; } } } anime_count = 0; } if (wait_count > 0) { wait_count -= 1; return; } if (stop_count >= ((GetMoveFrequency() > 7) ? 0 : pow(2.0, 9 - GetMoveFrequency()))) { if (IsMoveRouteOverwritten()) { MoveTypeCustom(); } else if (Game_Message::GetContinueEvents() || !Game_Message::message_waiting) { UpdateSelfMovement(); } } }
bool Game_Player::IsMovable() const { if (IsMoving() || IsJumping()) return false; if (IsMoveRouteOverwritten()) return false; if (location.boarding || location.unboarding) return false; if (Game_Message::message_waiting) return false; if (InAirship() && !GetVehicle()->IsMovable()) return false; return true; }
void Game_Character::Update() { if (wait_count == 0 && stop_count >= max_stop_count) { if (IsMoveRouteOverwritten()) { MoveTypeCustom(); } else { // Only events UpdateSelfMovement(); } } if (wait_count > 0) { --wait_count; } }
bool Game_Player::IsMovable() const { if (IsMoving()) return false; if (IsMoveRouteOverwritten()) return false; if (vehicle_getting_on) return false; if (vehicle_getting_off) return false; if (Game_Message::visible) return false; if (InAirship() && !Game_Map::GetVehicle(Game_Vehicle::Airship)->IsMovable()) return false; return true; }
bool Game_Player::IsBlockedByMoveRoute() const { if (!IsMoveRouteOverwritten()) return false; // Check if it includes a blocking move command for (const auto& move_command : GetMoveRoute().move_commands) { int code = move_command.command_id; if ((code <= RPG::MoveCommand::Code::move_forward) || // Move (code <= RPG::MoveCommand::Code::face_away_from_hero && GetMoveFrequency() < 8) || // Turn (code == RPG::MoveCommand::Code::wait || code == RPG::MoveCommand::Code::begin_jump)) // Wait or jump return true; } return false; }
void Game_Player::CancelMoveRoute() { if (!IsMoveRouteOverwritten()) return; // If the last executed command of the move route was a Move command, check touch and collision triggers const RPG::MoveRoute& active_route = GetMoveRoute(); int index = GetMoveRouteIndex(); if (!active_route.move_commands.empty()) { int move_size = (int)active_route.move_commands.size(); if (index >= active_route.move_commands.size()) { index = move_size - 1; } if (active_route.move_commands[index].command_id <= RPG::MoveCommand::Code::move_forward) { CheckTouchEvent(); CheckCollisionEvent(); } } Game_Character::CancelMoveRoute(); }
void Game_Player::UpdateNonMoving(bool last_moving) { if (IsMoving() || IsMoveRouteOverwritten()) return; if (last_moving && location.boarding) { // Boarding completed location.aboard = true; location.boarding = false; SetMoveSpeed(GetVehicle()->GetMoveSpeed()); SetDirection(GetVehicle()->GetDirection()); return; } if (last_moving && location.unboarding) { // Unboarding completed location.unboarding = false; location.vehicle = Game_Vehicle::None; CheckTouchEvent(); return; } if (InAirship() && !GetVehicle()->IsInUse()) { // Airship has landed Unboard(); location.vehicle = Game_Vehicle::None; SetDirection(RPG::EventPage::Direction_down); } if (last_moving && CheckTouchEvent()) return; if (!Game_Message::visible && Input::IsTriggered(Input::DECISION)) { if ( GetOnOffVehicle() ) return; if ( CheckActionEvent() ) return; } if (last_moving) Game_Map::UpdateEncounterSteps(); }
void Game_Character::MoveTypeCustom() { // Detect if custom movement or event overwrite const RPG::MoveRoute* active_route; int active_route_index; bool overwrite_changed = IsMoveRouteOverwritten(); if (IsMoveRouteOverwritten()) { active_route = &GetMoveRoute(); active_route_index = GetMoveRouteIndex(); } else { active_route = &original_move_route; active_route_index = GetOriginalMoveRouteIndex(); } if (IsStopping()) { move_failed = false; for (; (size_t)active_route_index < active_route->move_commands.size(); ++active_route_index) { if (!IsStopping() || wait_count > 0 || stop_count < max_stop_count) break; const RPG::MoveCommand& move_command = active_route->move_commands[active_route_index]; switch (move_command.command_id) { case RPG::MoveCommand::Code::move_up: case RPG::MoveCommand::Code::move_right: case RPG::MoveCommand::Code::move_down: case RPG::MoveCommand::Code::move_left: case RPG::MoveCommand::Code::move_upright: case RPG::MoveCommand::Code::move_downright: case RPG::MoveCommand::Code::move_downleft: case RPG::MoveCommand::Code::move_upleft: Move(move_command.command_id); break; case RPG::MoveCommand::Code::move_random: MoveRandom(); break; case RPG::MoveCommand::Code::move_towards_hero: MoveTowardsPlayer(); break; case RPG::MoveCommand::Code::move_away_from_hero: MoveAwayFromPlayer(); break; case RPG::MoveCommand::Code::move_forward: MoveForward(); break; case RPG::MoveCommand::Code::face_up: Turn(Up); break; case RPG::MoveCommand::Code::face_right: Turn(Right); break; case RPG::MoveCommand::Code::face_down: Turn(Down); break; case RPG::MoveCommand::Code::face_left: Turn(Left); break; case RPG::MoveCommand::Code::turn_90_degree_right: Turn90DegreeRight(); break; case RPG::MoveCommand::Code::turn_90_degree_left: Turn90DegreeLeft(); break; case RPG::MoveCommand::Code::turn_180_degree: Turn180Degree(); break; case RPG::MoveCommand::Code::turn_90_degree_random: Turn90DegreeLeftOrRight(); break; case RPG::MoveCommand::Code::face_random_direction: FaceRandomDirection(); break; case RPG::MoveCommand::Code::face_hero: TurnTowardHero(); break; case RPG::MoveCommand::Code::face_away_from_hero: TurnAwayFromHero(); break; case RPG::MoveCommand::Code::wait: Wait(); break; case RPG::MoveCommand::Code::begin_jump: BeginJump(active_route, &active_route_index); break; case RPG::MoveCommand::Code::end_jump: // EndJump(); break; case RPG::MoveCommand::Code::lock_facing: SetFacingLocked(true); break; case RPG::MoveCommand::Code::unlock_facing: SetFacingLocked(false); break; case RPG::MoveCommand::Code::increase_movement_speed: SetMoveSpeed(min(GetMoveSpeed() + 1, 6)); break; case RPG::MoveCommand::Code::decrease_movement_speed: SetMoveSpeed(max(GetMoveSpeed() - 1, 1)); break; case RPG::MoveCommand::Code::increase_movement_frequence: SetMoveFrequency(min(GetMoveFrequency() + 1, 8)); break; case RPG::MoveCommand::Code::decrease_movement_frequence: SetMoveFrequency(max(GetMoveFrequency() - 1, 1)); break; case RPG::MoveCommand::Code::switch_on: // Parameter A: Switch to turn on Game_Switches[move_command.parameter_a] = true; Game_Map::SetNeedRefresh(Game_Map::Refresh_All); break; case RPG::MoveCommand::Code::switch_off: // Parameter A: Switch to turn off Game_Switches[move_command.parameter_a] = false; Game_Map::SetNeedRefresh(Game_Map::Refresh_All); break; case RPG::MoveCommand::Code::change_graphic: // String: File, Parameter A: index SetGraphic(move_command.parameter_string, move_command.parameter_a); break; case RPG::MoveCommand::Code::play_sound_effect: // String: File, Parameters: Volume, Tempo, Balance if (move_command.parameter_string != "(OFF)" && move_command.parameter_string != "(Brak)") { RPG::Sound sound; sound.name = move_command.parameter_string; sound.volume = move_command.parameter_a; sound.tempo = move_command.parameter_b; sound.balance = move_command.parameter_c; Game_System::SePlay(sound); } break; case RPG::MoveCommand::Code::walk_everywhere_on: through = true; break; case RPG::MoveCommand::Code::walk_everywhere_off: through = false; break; case RPG::MoveCommand::Code::stop_animation: walk_animation = false; break; case RPG::MoveCommand::Code::start_animation: walk_animation = true; break; case RPG::MoveCommand::Code::increase_transp: SetOpacity(max(40, GetOpacity() - 45)); break; case RPG::MoveCommand::Code::decrease_transp: SetOpacity(GetOpacity() + 45); break; } last_move_failed = move_failed; if (move_failed) { if (active_route->skippable) { last_move_failed = false; continue; } break; } } if ((size_t)active_route_index >= active_route->move_commands.size() && IsStopping()) { // End of Move list if (active_route->repeat) { active_route_index = 0; SetMoveRouteRepeated(true); } else if (IsMoveRouteOverwritten()) { CancelMoveRoute(); Game_Map::RemovePendingMove(this); stop_count = 0; } } } // When the overwrite status changed the active_index belongs to the // current non-active move route if (overwrite_changed != IsMoveRouteOverwritten()) { if (IsMoveRouteOverwritten()) { SetOriginalMoveRouteIndex(active_route_index); } else { SetMoveRouteIndex(active_route_index); } } else { if (IsMoveRouteOverwritten()) { SetMoveRouteIndex(active_route_index); } else { SetOriginalMoveRouteIndex(active_route_index); } } }
void Game_Event::Setup(const RPG::EventPage* new_page) { bool from_null = page == nullptr; const RPG::EventPage* old_page = page; page = new_page; // Free resources if needed if (interpreter) { // If the new page is null and the interpreter is running, it should // carry on executing its command list during this frame if (page) interpreter->Clear(); Game_Map::ReserveInterpreterDeletion(interpreter); interpreter.reset(); } if (page == nullptr) { tile_id = 0; SetSpriteName(""); SetSpriteIndex(0); SetDirection(RPG::EventPage::Direction_down); //move_type = 0; trigger = -1; list.clear(); return; } SetSpriteName(page->character_name); SetSpriteIndex(page->character_index); tile_id = page->character_name.empty() ? page->character_index : 0; pattern = page->character_pattern; move_type = page->move_type; SetMoveSpeed(page->move_speed); SetMoveFrequency(page->move_frequency); if (!IsMoveRouteOverwritten()) { max_stop_count = (GetMoveFrequency() > 7) ? 0 : (int) pow(2.0, 8 - GetMoveFrequency()); } original_move_frequency = page->move_frequency; original_move_route = page->move_route; SetOriginalMoveRouteIndex(0); bool same_direction_as_on_old_page = old_page && old_page->character_direction == new_page->character_direction; animation_type = page->animation_type; if (from_null || !(same_direction_as_on_old_page || IsMoving()) || IsDirectionFixed()) { SetSpriteDirection(page->character_direction); SetDirection(page->character_direction); } SetOpacity(page->translucent ? 160 : 255); SetLayer(page->layer); data.overlap_forbidden = page->overlap_forbidden; trigger = page->trigger; list = page->event_commands; if (trigger == RPG::EventPage::Trigger_parallel) { interpreter.reset(new Game_Interpreter_Map()); } }
void Game_Character::MoveTypeCustom() { // Detect if custom movement or event overwrite const RPG::MoveRoute* active_route; int active_route_index; bool overwrite_changed = IsMoveRouteOverwritten(); if (IsMoveRouteOverwritten()) { active_route = &GetMoveRoute(); active_route_index = GetMoveRouteIndex(); } else { active_route = &original_move_route; active_route_index = GetOriginalMoveRouteIndex(); } if (IsStopping()) { move_failed = false; if ((size_t)active_route_index >= active_route->move_commands.size()) { // End of Move list if (active_route->repeat) { active_route_index = 0; SetMoveRouteRepeated(true); } else if (IsMoveRouteOverwritten()) { SetMoveRouteOverwritten(false); EndMoveRoute(); stop_count = 0; } } else { do { const RPG::MoveCommand& move_command = active_route->move_commands[active_route_index]; int command_id = move_command.command_id; if (!jumping && command_id == RPG::MoveCommand::Code::begin_jump) { active_route_index = BeginJump(active_route, active_route_index); } switch (move_command.command_id) { case RPG::MoveCommand::Code::move_up: MoveUp(); break; case RPG::MoveCommand::Code::move_right: MoveRight(); break; case RPG::MoveCommand::Code::move_down: MoveDown(); break; case RPG::MoveCommand::Code::move_left: MoveLeft(); break; case RPG::MoveCommand::Code::move_upright: MoveUpRight(); break; case RPG::MoveCommand::Code::move_downright: MoveDownRight(); break; case RPG::MoveCommand::Code::move_downleft: MoveDownLeft(); break; case RPG::MoveCommand::Code::move_upleft: MoveUpLeft(); break; case RPG::MoveCommand::Code::move_random: MoveRandom(); break; case RPG::MoveCommand::Code::move_towards_hero: MoveTowardsPlayer(); break; case RPG::MoveCommand::Code::move_away_from_hero: MoveAwayFromPlayer(); break; case RPG::MoveCommand::Code::move_forward: MoveForward(); break; case RPG::MoveCommand::Code::face_up: TurnUp(); break; case RPG::MoveCommand::Code::face_right: TurnRight(); break; case RPG::MoveCommand::Code::face_down: TurnDown(); break; case RPG::MoveCommand::Code::face_left: TurnLeft(); break; case RPG::MoveCommand::Code::turn_90_degree_right: Turn90DegreeRight(); break; case RPG::MoveCommand::Code::turn_90_degree_left: Turn90DegreeLeft(); break; case RPG::MoveCommand::Code::turn_180_degree: Turn180Degree(); break; case RPG::MoveCommand::Code::turn_90_degree_random: Turn90DegreeLeftOrRight(); break; case RPG::MoveCommand::Code::face_random_direction: FaceRandomDirection(); break; case RPG::MoveCommand::Code::face_hero: TurnTowardHero(); break; case RPG::MoveCommand::Code::face_away_from_hero: TurnAwayFromHero(); break; case RPG::MoveCommand::Code::wait: Wait(); break; case RPG::MoveCommand::Code::begin_jump: // Multiple BeginJumps are ignored break; case RPG::MoveCommand::Code::end_jump: active_route_index = EndJump(active_route, active_route_index); break; case RPG::MoveCommand::Code::lock_facing: SetFacingLocked(true); break; case RPG::MoveCommand::Code::unlock_facing: SetFacingLocked(false); break; case RPG::MoveCommand::Code::increase_movement_speed: SetMoveSpeed(min(GetMoveSpeed() + 1, 6)); break; case RPG::MoveCommand::Code::decrease_movement_speed: SetMoveSpeed(max(GetMoveSpeed() - 1, 1)); break; case RPG::MoveCommand::Code::increase_movement_frequence: SetMoveFrequency(min(GetMoveFrequency() + 1, 8)); break; case RPG::MoveCommand::Code::decrease_movement_frequence: SetMoveFrequency(max(GetMoveFrequency() - 1, 1)); break; case RPG::MoveCommand::Code::switch_on: // Parameter A: Switch to turn on Game_Switches[move_command.parameter_a] = true; Game_Map::SetNeedRefresh(true); break; case RPG::MoveCommand::Code::switch_off: // Parameter A: Switch to turn off Game_Switches[move_command.parameter_a] = false; Game_Map::SetNeedRefresh(true); break; case RPG::MoveCommand::Code::change_graphic: // String: File, Parameter A: index SetGraphic(move_command.parameter_string, move_command.parameter_a); break; case RPG::MoveCommand::Code::play_sound_effect: // String: File, Parameters: Volume, Tempo, Balance if (move_command.parameter_string != "(OFF)") { Audio().SE_Play(move_command.parameter_string, move_command.parameter_a, move_command.parameter_b); } break; case RPG::MoveCommand::Code::walk_everywhere_on: through = true; break; case RPG::MoveCommand::Code::walk_everywhere_off: through = false; break; case RPG::MoveCommand::Code::stop_animation: walk_animation = false; break; case RPG::MoveCommand::Code::start_animation: walk_animation = true; break; case RPG::MoveCommand::Code::increase_transp: SetOpacity(max(40, GetOpacity() - 45)); break; case RPG::MoveCommand::Code::decrease_transp: SetOpacity(GetOpacity() + 45); break; } if (active_route->skippable || !move_failed) { ++active_route_index; } } while (jumping); if ((size_t)active_route_index >= active_route->move_commands.size()) { stop_count = (active_route->repeat ? 0 : 256); } } } // When the overwrite status changed the active_index belongs to the // current non-active move route if (overwrite_changed != IsMoveRouteOverwritten()) { if (IsMoveRouteOverwritten()) { SetOriginalMoveRouteIndex(active_route_index); } else { SetMoveRouteIndex(active_route_index); } } else { if (IsMoveRouteOverwritten()) { SetMoveRouteIndex(active_route_index); } else { SetOriginalMoveRouteIndex(active_route_index); } } }