Added support for large events, allowed field move-related event names to have other text in their names

This commit is contained in:
Maruno17
2021-04-03 01:10:27 +01:00
parent af33799cb7
commit afd76503b2
21 changed files with 336 additions and 278 deletions

View File

@@ -62,6 +62,7 @@ class Game_Map
for i in @map.events.keys
@events[i] = Game_Event.new(@map_id, @map.events[i],self)
end
# TODO: These should be moved to Spriteset_Global as we only need one copy of them.
@common_events = {}
for i in 1...$data_common_events.size
@common_events[i] = Game_CommonEvent.new(i)
@@ -147,10 +148,10 @@ class Game_Map
bit = (1 << (d / 2 - 1)) & 0x0f
for event in events.values
next if event.tile_id <= 0
next if GameData::TerrainTag.try_get(@terrain_tags[event.tile_id]).ignore_passability
next if event == self_event
next if event.x != x || event.y != y
next if !event.at_coordinate?(x, y)
next if event.through
next if GameData::TerrainTag.try_get(@terrain_tags[event.tile_id]).ignore_passability
passage = @passages[event.tile_id]
return false if passage & bit != 0
return false if passage & 0x0f == 0x0f
@@ -158,7 +159,8 @@ class Game_Map
end
return playerPassable?(x, y, d, self_event) if self_event==$game_player
# All other events
newx = x; newy = y
newx = x
newy = y
case d
when 1
newx -= 1
@@ -185,7 +187,6 @@ class Game_Map
for i in [2, 1, 0]
tile_id = data[x, y, i]
terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id])
passage = @passages[tile_id]
# If already on water, only allow movement to another water tile
if self_event != nil && terrain.can_surf_freely
for j in [2, 1, 0]
@@ -211,6 +212,7 @@ class Game_Map
end
# Regular passability checks
if !terrain || !terrain.ignore_passability
passage = @passages[tile_id]
return false if passage & bit != 0 || passage & 0x0f == 0x0f
return true if @priorities[tile_id] == 0
end
@@ -251,7 +253,7 @@ class Game_Map
return false if !valid?(x, y)
for event in events.values
next if event == self_event || event.tile_id < 0 || event.through
next if event.x != x || event.y != y
next if !event.at_coordinate?(x, y)
next if GameData::TerrainTag.try_get(@terrain_tags[event.tile_id]).ignore_passability
return false if @passages[event.tile_id] & 0x0f != 0
return true if @priorities[event.tile_id] == 0
@@ -307,9 +309,10 @@ class Game_Map
return GameData::TerrainTag.get(:None)
end
# Unused.
def check_event(x,y)
for event in self.events.values
return event.id if event.x == x and event.y == y
return event.id if event.at_coordinate?(x, y)
end
end

View File

@@ -183,7 +183,7 @@ class PokemonMapFactory
end
# Check passability of event(s) in that spot
for event in map.events.values
next if event.x != x || event.y != y || event == thisEvent
next if event == thisEvent || !event.at_coordinate?(x, y)
return false if !event.through && event.character_name != ""
end
# Check passability of player
@@ -210,7 +210,7 @@ class PokemonMapFactory
return false if !map.passableStrict?(x,y,0,thisEvent)
end
for event in map.events.values
next if event == thisEvent || event.x != x || event.y != y
next if event == thisEvent || !event.at_coordinate?(x, y)
return false if !event.through && event.character_name!=""
end
return true
@@ -221,6 +221,7 @@ class PokemonMapFactory
return map.terrain_tag(x,y,countBridge)
end
# NOTE: Assumes the event is 1x1 tile in size. Only returns one terrain tag.
def getFacingTerrainTag(dir=nil,event=nil)
tile = getFacingTile(dir,event)
return GameData::TerrainTag.get(:None) if !tile
@@ -281,12 +282,14 @@ class PokemonMapFactory
thisEvent.map.map_id,thisEvent.x,thisEvent.y,otherMapID,otherX,otherY)
end
# Unused
def getOffsetEventPos(event,xOffset,yOffset)
event = $game_player if !event
return nil if !event
return getRealTilePos(event.map.map_id,event.x+xOffset,event.y+yOffset)
end
# NOTE: Assumes the event is 1x1 tile in size. Only returns one tile.
def getFacingTile(direction=nil,event=nil,steps=1)
event = $game_player if event==nil
return [0,0,0] if !event

View File

@@ -6,6 +6,8 @@ class Game_Character
attr_reader :y
attr_reader :real_x
attr_reader :real_y
attr_accessor :width
attr_accessor :height
attr_accessor :sprite_size
attr_reader :tile_id
attr_accessor :character_name
@@ -33,6 +35,8 @@ class Game_Character
@y = 0
@real_x = 0
@real_y = 0
@width = 1
@height = 1
@sprite_size = [Game_Map::TILE_WIDTH, Game_Map::TILE_HEIGHT]
@tile_id = 0
@character_name = ""
@@ -73,6 +77,24 @@ class Game_Character
@prelock_direction = 0
end
def at_coordinate?(check_x, check_y)
return check_x >= @x && check_x < @x + @width &&
check_y > @y - @height && check_y <= @y
end
def in_line_with_coordinate?(check_x, check_y)
return (check_x >= @x && check_x < @x + @width) ||
(check_y > @y - @height && check_y <= @y)
end
def each_occupied_tile
for i in @x...(@x + @width)
for j in (@y - @height + 1)..@y
yield i, j
end
end
end
def move_speed=(val)
return if val==@move_speed
@move_speed = val
@@ -182,7 +204,7 @@ class Game_Character
#=============================================================================
# Passability
#=============================================================================
def passableEx?(x, y, d, strict=false)
def passable?(x, y, d, strict = false)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
return false unless self.map.valid?(new_x, new_y)
@@ -195,7 +217,7 @@ class Game_Character
return false unless self.map.passable?(new_x, new_y, 10 - d, self)
end
for event in self.map.events.values
next if event.x != new_x || event.y != new_y || event.through
next if self == event || !event.at_coordinate?(new_x, new_y) || event.through
return false if self != $game_player || event.character_name != ""
end
if $game_player.x == new_x and $game_player.y == new_y
@@ -204,12 +226,49 @@ class Game_Character
return true
end
def passable?(x,y,d)
return passableEx?(x,y,d,false)
def can_move_from_coordinate?(start_x, start_y, dir, strict = false)
case dir
when 2, 8 # Down, up
y_diff = (dir == 8) ? @height - 1 : 0
for i in start_x...(start_x + @width)
return false if !passable?(i, start_y - y_diff, dir, strict)
end
return true
when 4, 6 # Left, right
x_diff = (dir == 6) ? @width - 1 : 0
for i in (start_y - @height + 1)..start_y
return false if !passable?(start_x + x_diff, i, dir, strict)
end
return true
when 1, 3 # Down diagonals
# Treated as moving down first and then horizontally, because that
# describes which tiles the character's feet touch
for i in start_x...(start_x + @width)
return false if !passable?(i, start_y, 2, strict)
end
x_diff = (dir == 3) ? @width - 1 : 0
for i in (start_y - @height + 1)..start_y
return false if !passable?(start_x + x_diff, i + 1, dir + 3, strict)
end
return true
when 7, 9 # Up diagonals
# Treated as moving horizontally first and then up, because that describes
# which tiles the character's feet touch
x_diff = (dir == 9) ? @width - 1 : 0
for i in (start_y - @height + 1)..start_y
return false if !passable?(start_x + x_diff, i, dir - 3, strict)
end
x_offset = (dir == 9) ? 1 : -1
for i in start_x...(start_x + @width)
return false if !passable?(i + x_offset, start_y - @height + 1, 8, strict)
end
return true
end
return false
end
def passableStrict?(x,y,d)
return passableEx?(x,y,d,true)
def can_move_in_direction?(dir, strict = false)
return can_move_from_coordinate?(@x, @y, dir, strict)
end
#=============================================================================
@@ -217,7 +276,7 @@ class Game_Character
#=============================================================================
def screen_x
ret = ((@real_x - self.map.display_x) / Game_Map::X_SUBPIXELS).round
ret += Game_Map::TILE_WIDTH/2
ret += @width * Game_Map::TILE_WIDTH / 2
return ret
end
@@ -321,8 +380,8 @@ class Game_Character
end
def move_type_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
if sx.abs + sy.abs >= 20
move_random
return
@@ -441,7 +500,7 @@ class Game_Character
turn_generic(dir) if turn_enabled
x_offset = (dir == 4) ? -1 : (dir == 6) ? 1 : 0
y_offset = (dir == 8) ? -1 : (dir == 2) ? 1 : 0
if passable?(@x, @y, dir)
if can_move_in_direction?(dir)
turn_generic(dir)
@x += x_offset
@y += y_offset
@@ -471,8 +530,7 @@ class Game_Character
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
if can_move_in_direction?(7)
@x -= 1
@y -= 1
increase_steps
@@ -483,8 +541,7 @@ class Game_Character
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
if can_move_in_direction?(9)
@x += 1
@y -= 1
increase_steps
@@ -495,8 +552,7 @@ class Game_Character
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
if can_move_in_direction?(1)
@x -= 1
@y += 1
increase_steps
@@ -507,8 +563,7 @@ class Game_Character
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
if can_move_in_direction?(3)
@x += 1
@y += 1
increase_steps
@@ -574,8 +629,8 @@ class Game_Character
end
def move_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
return if sx == 0 and sy == 0
abs_sx = sx.abs
abs_sy = sy.abs
@@ -596,8 +651,8 @@ class Game_Character
end
def move_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
return if sx == 0 and sy == 0
abs_sx = sx.abs
abs_sy = sy.abs
@@ -639,35 +694,32 @@ class Game_Character
end
def jump(x_plus, y_plus)
if x_plus != 0 or y_plus != 0
if x_plus != 0 || y_plus != 0
if x_plus.abs > y_plus.abs
(x_plus < 0) ? turn_left : turn_right
else
(y_plus < 0) ? turn_up : turn_down
end
each_occupied_tile { |i, j| return if !passable?(i + x_plus, j + y_plus, 0) }
end
new_x = @x + x_plus
new_y = @y + y_plus
if (x_plus == 0 and y_plus == 0) || passable?(new_x, new_y, 0)
@x = new_x
@y = new_y
real_distance = Math::sqrt(x_plus * x_plus + y_plus * y_plus)
distance = [1, real_distance].max
@jump_peak = distance * Game_Map::TILE_HEIGHT * 3 / 8 # 3/4 of tile for ledge jumping
@jump_distance = [x_plus.abs * Game_Map::REAL_RES_X, y_plus.abs * Game_Map::REAL_RES_Y].max
@jump_distance_left = 1 # Just needs to be non-zero
if real_distance > 0 # Jumping to somewhere else
@jump_count = 0
else # Jumping on the spot
@jump_speed_real = nil # Reset jump speed
@jump_count = Game_Map::REAL_RES_X / jump_speed_real # Number of frames to jump one tile
end
@stop_count = 0
if self.is_a?(Game_Player)
$PokemonTemp.dependentEvents.pbMoveDependentEvents
end
triggerLeaveTile
@x = @x + x_plus
@y = @y + y_plus
real_distance = Math::sqrt(x_plus * x_plus + y_plus * y_plus)
distance = [1, real_distance].max
@jump_peak = distance * Game_Map::TILE_HEIGHT * 3 / 8 # 3/4 of tile for ledge jumping
@jump_distance = [x_plus.abs * Game_Map::REAL_RES_X, y_plus.abs * Game_Map::REAL_RES_Y].max
@jump_distance_left = 1 # Just needs to be non-zero
if real_distance > 0 # Jumping to somewhere else
@jump_count = 0
else # Jumping on the spot
@jump_speed_real = nil # Reset jump speed
@jump_count = Game_Map::REAL_RES_X / jump_speed_real # Number of frames to jump one tile
end
@stop_count = 0
if self.is_a?(Game_Player)
$PokemonTemp.dependentEvents.pbMoveDependentEvents
end
triggerLeaveTile
end
def jumpForward
@@ -742,8 +794,8 @@ class Game_Character
end
def turn_toward_player
sx = @x - $game_player.x
sy = @y - $game_player.y
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
return if sx == 0 and sy == 0
if sx.abs > sy.abs
(sx > 0) ? turn_left : turn_right
@@ -753,8 +805,8 @@ class Game_Character
end
def turn_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
sx = @x + @width / 2.0 - ($game_player.x + $game_player.width / 2.0)
sy = @y - @height / 2.0 - ($game_player.y - $game_player.height / 2.0)
return if sx == 0 and sy == 0
if sx.abs > sy.abs
(sx > 0) ? turn_right : turn_left

View File

@@ -13,6 +13,10 @@ class Game_Event < Game_Character
@id = @event.id
@original_x = @event.x
@original_y = @event.y
if @event.name[/size\((\d+),(\d+)\)/i]
@width = $~[1].to_i
@height = $~[2].to_i
end
@erased = false
@starting = false
@need_refresh = false
@@ -119,14 +123,16 @@ class Game_Event < Game_Character
end
def onEvent?
return @map_id == $game_map.map_id && $game_player.x == self.x && $game_player.y == self.y
return @map_id == $game_map.map_id && at_coordinate?($game_player.x, $game_player.y)
end
def over_trigger?
return false if @character_name!="" and not @through
return false if @character_name != "" && !@through
return false if @event.name[/hiddenitem/i]
return false if !self.map.passable?(@x, @y, 0, $game_player)
return true
each_occupied_tile do |i, j|
return true if self.map.passable?(i, j, 0, $game_player)
end
return false
end
def pbCheckEventTriggerAfterTurning
@@ -141,15 +147,15 @@ class Game_Event < Game_Character
def check_event_trigger_touch(x, y)
return if $game_system.map_interpreter.running?
return if @trigger!=2
return if x != $game_player.x || y != $game_player.y
return if @trigger != 2 # Event touch
return if !at_coordinate?($game_player.xm $game_player.y)
return if jumping? || over_trigger?
start
end
def check_event_trigger_auto
if @trigger == 2 # Event touch
if @x == $game_player.x and @y == $game_player.y
if at_coordinate?($game_player.x, $game_player.y)
start if not jumping? and over_trigger?
end
elsif @trigger == 3 # Autorun

View File

@@ -72,7 +72,7 @@ class Game_Player < Game_Character
if !$PokemonTemp.encounterTriggered
x_offset = (dir == 4) ? -1 : (dir == 6) ? 1 : 0
y_offset = (dir == 8) ? -1 : (dir == 2) ? 1 : 0
if passable?(@x, @y, dir)
if can_move_in_direction?(dir)
return if pbLedge(x_offset, y_offset)
return if pbEndSurf(x_offset, y_offset)
turn_generic(dir, true)
@@ -146,21 +146,28 @@ class Game_Player < Game_Character
return true
end
def pbTerrainTag(countBridge = false)
return $MapFactory.getTerrainTag(self.map.map_id, @x, @y, countBridge) if $MapFactory
return $game_map.terrain_tag(@x, @y, countBridge)
end
def pbFacingEvent(ignoreInterpreter=false)
return nil if $game_system.map_interpreter.running? && !ignoreInterpreter
# Check the tile in front of the player for events
new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
return nil if !$game_map.valid?(new_x, new_y)
for event in $game_map.events.values
next if event.x != new_x || event.y != new_y
next if !event.at_coordinate?(new_x, new_y)
next if event.jumping? || event.over_trigger?
return event
end
# If the tile in front is a counter, check one tile beyond that for events
if $game_map.counter?(new_x, new_y)
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
for event in $game_map.events.values
next if event.x != new_x || event.y != new_y
next if !event.at_coordinate?(new_x, new_y)
next if event.jumping? || event.over_trigger?
return event
end
@@ -168,6 +175,13 @@ class Game_Player < Game_Character
return nil
end
def pbFacingTerrainTag(dir = nil)
dir = self.direction if !dir
return $MapFactory.getFacingTerrainTag(dir, self) if $MapFactory
facing = pbFacingTile(dir, self)
return $game_map.terrain_tag(facing[1], facing[2])
end
#-----------------------------------------------------------------------------
# * Passable Determinants
# x : x-coordinate
@@ -175,7 +189,7 @@ class Game_Player < Game_Character
# d : direction (0,2,4,6,8)
# * 0 = Determines if all directions are impassable (for jumping)
#-----------------------------------------------------------------------------
def passable?(x, y, d)
def passable?(x, y, d, strict = false)
# Get new coordinates
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
@@ -231,7 +245,8 @@ class Game_Player < Game_Character
end
#-----------------------------------------------------------------------------
# * Same Position Starting Determinant
# * Trigger event(s) at the same coordinates as self with the appropriate
# trigger(s) that can be triggered
#-----------------------------------------------------------------------------
def check_event_trigger_here(triggers)
result = false
@@ -240,7 +255,7 @@ class Game_Player < Game_Character
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
next if event.x != @x || event.y != @y
next if !event.at_coordinate?(@x, @y)
next if !triggers.include?(event.trigger)
# If starting determinant is same position event (other than jumping)
next if event.jumping? || !event.over_trigger?
@@ -264,7 +279,7 @@ class Game_Player < Game_Character
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
next if event.x != new_x || event.y != new_y
next if !event.at_coordinate?(new_x, new_y)
next if !triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
next if event.jumping? || event.over_trigger?
@@ -282,7 +297,7 @@ class Game_Player < Game_Character
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
next if event.x != new_x || event.y != new_y
next if !event.at_coordinate?(new_x, new_y)
next if !triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
next if event.jumping? || event.over_trigger?
@@ -304,7 +319,7 @@ class Game_Player < Game_Character
# All event loops
for event in $game_map.events.values
# If event coordinates and triggers are consistent
next if event.x != x || event.y != y
next if !event.at_coordinate?(x, y)
if event.name[/trainer\((\d+)\)/i]
distance = $~[1].to_i
next if !pbEventCanReachPlayer?(event,self,distance)

View File

@@ -26,7 +26,7 @@ class Game_Player < Game_Character
input = ($PokemonSystem.runstyle == 1) ^ Input.press?(Input::SPECIAL)
return input && $PokemonGlobal.runningShoes && !jumping? &&
!$PokemonGlobal.diving && !$PokemonGlobal.surfing &&
!$PokemonGlobal.bicycle && !pbGetTerrainTag.must_walk
!$PokemonGlobal.bicycle && !$game_player.pbTerrainTag.must_walk
end
def pbIsRunning?
@@ -52,7 +52,7 @@ class Game_Player < Game_Character
end
def update_command
if pbGetTerrainTag.ice
if $game_player.pbTerrainTag.ice
self.move_speed = 4 # Sliding on ice
elsif !moving? && !@move_route_forcing && $PokemonGlobal
if $PokemonGlobal.bicycle