Day.png);">
Apprendre


Vous êtes
nouveau sur
Oniromancie?

Visite guidée
du site


Découvrir
RPG Maker

RM 95
RM 2000/2003
RM XP
RM VX/VX Ace
RM MV/MZ

Apprendre
RPG Maker

Tutoriels
Guides
Making-of

Dans le
Forum

Section Entraide

Sorties: "Dread Mac Farlane", (...) / Tutos: Checklist de la composition (...) / Sorties: Dread Mac Farlane - episode 8 / Sorties: Dread Mac Farlane - episode 7 / Jeux: Ce qui vit Dessous / Chat

Bienvenue
visiteur !




publicité RPG Maker!

Statistiques

Liste des
membres


Contact

Mentions légales

364 connectés actuellement

29415834 visiteurs
depuis l'ouverture

8374 visiteurs
aujourd'hui



Barre de séparation

Partenaires

Indiexpo

Akademiya RPG Maker

Blog Alioune Fall

Fairy Tail Constellations

Lunae - le bazar d'Emz0

Guelnika & E-magination

RPG Maker VX

Tous nos partenaires

Devenir
partenaire



forums

Index du forum > Vos créations > RPGMVXace script de pathfinding(recherche de chemin automatique vers une position)


madmanu - posté le 01/04/2012 à 17:09:29 (85 messages postés)

❤ 0

Bonjour j'aimerais vous présenté un script pour RPGMVXace de pathfinding (ceux qui utilise game creator ne seront pas déroutés) . Ce n'est pas moi qui l'ai crée (soyons honnête :rit2) mais comme le site d'origine est en anglais et que j'ai galairée à le trouver , je vous le fais partager.

Le principe


Le pathfinding est une recherche de chemin automatisé .C'est pratique car ça permet à un event d'aller jusqu'a un point précis de la map et ce depuis n'importe laquelle des positions!

Le script



Portion de code : Tout sélectionner

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
===============================================================================
# [VXA] Pathfinding
#-------------------------------------------------------------------------------
# Version: 1.0
# Author: cozziekuns (rmrk)
# Last Date Updated: 12/31/2011 (MM/DD/YYYY)
#===============================================================================
# Description:
#-------------------------------------------------------------------------------
# This script allows you to move any character to another tile using the  
# shortest path possible. It takes a significantly longer time on large maps.
#===============================================================================
# Updates
# ------------------------------------------------------------------------------
# o 12/31/2011 - Started Script 
#===============================================================================
# To-do List
#------------------------------------------------------------------------------- 
# o Allow for dynamic recalculation if one wants to repeat the pathfinding 
#   process for any reason.
#===============================================================================
# Instructions
#-------------------------------------------------------------------------------
# To use, create a move route event and as a script command use: 
#
# find_path(target_x, target_y)
#
# Additionally, one can force a path through a script using the following call:
# 
# force_path(target_x, target_y)
#
# There is a known bug that is present in Modern Algebra's script regarding the 
# recalculation of a path once found. Since some of this script is simply
# a convert from his VX version (only the algorithm is different by being
# slightly slower and sloppier :P), the bug is also found in this script.
#===============================================================================
 
#==============================================================================
# ** Game_Map
#==============================================================================
 
class Game_Map
  
  def find_path(target_x, target_y, sx, sy, passable, char)
    path = []
    max_elements = width * height + 2
    checked_items = 0
    @open_list_items = 0
    @open_list = Table.new(max_elements)
    @nodes = Table.new(max_elements, 2)
    open = Table.new(width, height)
    closed = Table.new(width, height)
    parent = Table.new(width, height, 3)
    @f_cost = Table.new(width, height)
    @open_list[0] = 0
    @nodes[0, 0] = sx
    @nodes[0, 1] = sy
    next_point = [sx, sy]
    closed[sx, sy] = 1
    loop do
      next_point = delete_from_heap if not next_point == [sx, sy]
      return path if next_point.nil?
      open[next_point[0], next_point[1]] = 0
      closed[next_point[0], next_point[1]] = 2 if not next_point == [sx, sy]
      parent_x, parent_y = next_point[0], next_point[1]
      for i in 1..4
        x, y = case i * 2 
        when 2; [parent_x, parent_y + 1]
        when 4; [parent_x - 1, parent_y]
        when 6; [parent_x + 1, parent_y]
        when 8; [parent_x, parent_y - 1]
        end
        next if closed[x, y] == 2
        next unless char.passable?(parent_x, parent_y, i * 2) 
        if not open[x, y] == 1
          open[x, y] = 1
          parent[x, y, 0] = parent_x
          parent[x, y, 1] = parent_y
          parent[x, y, 2] = parent[parent_x, parent_y, 2] + 10
          g = parent[x, y, 2] + 10
          h = ((target_x - x).abs + (target_y - y).abs) * 10
          @f_cost[x, y] = g 
          checked_items += 1
          @open_list_items += 1
          @nodes[checked_items, 0] = x
          @nodes[checked_items, 1] = y
          add_to_heap(checked_items)
        else
          old_g = parent[x, y, 2] + 10
          new_g = parent[parent_x, parent_y, 2] + 20
          next if old_g < new_g
          parent[x, y, 0] = parent_x
          parent[x, y, 1] = parent_y
          parent[x, y, 2] = new_g
          g = parent[x, y, 2] + 10
          h = ((target_x - x).abs + (target_y - y).abs) * 10
          @f_cost[x, y] = g 
        end
      end
      next_point = nil
      break if closed[target_x, target_y] == 2
    end    
    path_x, path_y = target_x, target_y    
    loop do   
      parent_x = parent[path_x, path_y, 0]
      parent_y = parent[path_x, path_y, 1]
      if path_x < parent_x
        code = 2
      elsif path_x > parent_x
        code = 3
      else
        code = path_y < parent_y ? 4 : 1
      end      
      path.push(RPG::MoveCommand.new(code))
      path_x, path_y = parent_x, parent_y      
      break if path_x == sx and path_y == sy
    end
    return path
  end
  
  def add_to_heap(value)
    m = @open_list_items
    @open_list[m] = value
    while m != 1
      if fcost(@open_list[m]) < fcost(@open_list[m / 2])
        temp = @open_list[m / 2]
        @open_list[m / 2] = @open_list[m]
        @open_list[m] = temp
        m /= 2
      else
        break
      end
    end
  end
  
  def delete_from_heap
    next_point = @open_list[0]
    @open_list[0] = @open_list[@open_list_items]
    @open_list_items -= 1
    v = 1
    loop do
      u = v
      w = 2 * u
      if w + 1 <= @open_list_items
        v = w if fcost(@open_list[u - 1]) >= fcost(@open_list[w - 1])
        v = w + 1 if fcost(@open_list[v - 1]) >= fcost(@open_list[w]) 
      elsif w <= @open_list_items
        v = w if fcost(@open_list[u - 1]) >= fcost(@open_list[w - 1])
      end
      if u != v
        temp = @open_list[u - 1]
        @open_list[u - 1] = @open_list[v - 1]
        @open_list[v - 1] = temp 
      else
        break
      end
    end
    return @nodes[next_point, 0], @nodes[next_point, 1]
  end
  
  def fcost(point)
    x = @nodes[point, 0]
    y = @nodes[point, 1]
    return @f_cost[x, y]
  end
  
end
 
#==============================================================================
# ** Game_CharacterBase
#==============================================================================
 
class Game_CharacterBase
 
  def find_path(target_x, target_y)
    path = $game_map.find_path(target_x, target_y, @x, @y, false, self)
    @move_route.list.delete_at(@move_route_index)
    path.each { |i| @move_route.list.insert(@move_route_index, i) }
    @move_route_index -= 1
  end
  
  def force_path(target_x, target_y)
    path = $game_map.find_path(target_x, target_y, @x, @y, false, self)
    path.reverse!
    path.push (RPG::MoveCommand.new(0))
    move_route = RPG::MoveRoute.new
    move_route.list = path
    move_route.repeat = false
    force_move_route(move_route)
  end
  
  def count_iterations(target_x, target_y)
    path = $game_map.find_path(target_x, target_y, @x, @y, true, self)
    return path.size
  end
  
end



Appel aux scripteurs pour différentes amélioration
J'en propose déjà 2 (je ne sais pas très bien scripter) : pouvoir aller à une position désignée par des variables et si le chemins est impossibles aller jusqu’au point le plus proche de l'objectif

Toutes les instructions sont dans les commentaires mais pour les noobs en anglais X) il faut mettre dans une commandes de déplacement , dans la partie script mettre

Portion de code : Tout sélectionner

1
find_path(cible x ,cible y )


en remplaçant bien sur cible x par les coordonnés x de l'objectif et cible y par les coordonnés y de l'objectif


Moutarde - posté le 01/04/2012 à 17:10:49 (411 messages postés)

❤ 0

Hippopotame patate.

http://www.rpg-maker.fr/index.php?page=propart

-> 1f4v. + mu51qu3


Falco - posté le 02/04/2012 à 13:08:37 (19572 messages postés) -

❤ 0

Indie game Developer

Le script me parait vraiment court pour un système pareil, impressionnant.

Inexistence Rebirth - Inexistence - Portfolio


S4suk3 - posté le 02/04/2012 à 14:10:49 (555 messages postés)

❤ 0

-

Non globalement, niveau taille ça va.


madmanu - posté le 02/04/2012 à 16:29:27 (85 messages postés)

❤ 0

Edit : je crois que j'aie trouvé une nouvelle fonction force_path(x,y)

je continue les tests
:vampire
et au fait , comment on désigne une variable du jeu en script


S4suk3 - posté le 02/04/2012 à 16:41:14 (555 messages postés)

❤ 0

-

Portion de code : Tout sélectionner

1
$game_variables[ID_VARIABLE]



Citation:

Edit : je crois que j'aie trouvé une nouvelle fonction force_path(x,y)


Hum, le code est assez explicite... le commentaire encore plus.


madmanu - posté le 03/04/2012 à 17:56:06 (85 messages postés)

❤ 0

merci beaucoup!!:vampire

Index du forum > Vos créations > RPGMVXace script de pathfinding(recherche de chemin automatique vers une position)

repondre up

Suite à de nombreux abus, le post en invités a été désactivé. Veuillez vous inscrire si vous souhaitez participer à la conversation.

Haut de page

Merci de ne pas reproduire le contenu de ce site sans autorisation.
Contacter l'équipe - Mentions légales

Plan du site

Communauté: Accueil | Forum | Chat | Commentaires | News | Flash-news | Screen de la semaine | Sorties | Tests | Gaming-Live | Interviews | Galerie | OST | Blogs | Recherche
Apprendre: Visite guidée | RPG Maker 95 | RPG Maker 2003 | RPG Maker XP | RPG Maker VX | RPG Maker MV | Tutoriels | Guides | Making-of
Télécharger: Programmes | Scripts/Plugins | Ressources graphiques / sonores | Packs de ressources | Midis | Eléments séparés | Sprites
Jeux: Au hasard | Notre sélection | Sélection des membres | Tous les jeux | Jeux complets | Le cimetière | RPG Maker 95 | RPG Maker 2000 | RPG Maker 2003 | RPG Maker XP | RPG Maker VX | RPG Maker VX Ace | RPG Maker MV | Autres | Proposer
Ressources RPG Maker 2000/2003: Chipsets | Charsets | Panoramas | Backdrops | Facesets | Battle anims | Battle charsets | Monstres | Systems | Templates
Ressources RPG Maker XP: Tilesets | Autotiles | Characters | Battlers | Window skins | Icônes | Transitions | Fogs | Templates
Ressources RPG Maker VX: Tilesets | Charsets | Facesets | Systèmes
Ressources RPG Maker MV: Tilesets | Characters | Faces | Systèmes | Title | Battlebacks | Animations | SV/Ennemis
Archives: Palmarès | L'Annuaire | Livre d'or | Le Wiki | Divers