<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -51,6 +51,7 @@
          walk_timer,
          walk_prev,
          walk_path,
+         walk_changed,
          npc}).
 
 -record(map_state,</diff>
      <filename>include/records.hrl</filename>
    </modified>
    <modified>
      <diff>@@ -21,7 +21,7 @@
 (defmacro close ()
   `(begin
      (: log debug '&quot;Sending close button.&quot;)
-     (: zone_npc close player npc)
+     (: zone_npc close player (npc-id))
      (receive
       ('close
        (: log debug '&quot;Player clicked close.&quot;)
@@ -30,7 +30,7 @@
 (defmacro next ()
   `(begin
      (: log debug '&quot;Sending next button.&quot;)
-     (: zone_npc next player npc)
+     (: zone_npc next player (npc-id))
      (receive
       ('continue
        (: log debug '&quot;Player clicked next.&quot;)))))
@@ -44,7 +44,7 @@
   (os
    `(let ((options (eval-all ,@os)))
       (: log debug '&quot;Sending menu.&quot; `(#(menu ',options)))
-      (: zone_npc menu player npc (: lists map (lambda (a) (: lists nth 1 a)) options))
+      (: zone_npc menu player (npc-id) (: lists map (lambda (a) (: lists nth 1 a)) options))
       (receive
         (index
          (: log debug '&quot;Player selected menu item.&quot; `(#(index ,index)))
@@ -66,6 +66,6 @@
                      (: lists concat (: lists map (fun eval 1) ,m))))))
       (begin
         (: log error '&quot;Saying message.&quot; `(#(msg ,msg) #(original ,,m) #(head ,(: erlang hd ,m))))
-        (: zone_npc say player npc msg)
+        (: zone_npc say player (npc-id) msg)
         (say ,@ms)))))
 </diff>
      <filename>lib/npc.lfh</filename>
    </modified>
    <modified>
      <diff>@@ -29,7 +29,7 @@ start_link(TCP) -&gt;
 init(TCP) -&gt;
     {ok, locked, #zone_state{tcp = TCP}}.
 
-locked({connect, AccountID, CharacterID, SessionIDa, Gender}, State) -&gt;
+locked({connect, AccountID, CharacterID, SessionIDa, _Gender}, State) -&gt;
     {char, CharNode} = config:get_env(zone, server.char),
     Session = gen_server_tcp:call({server, CharNode},
                                   {verify_session, AccountID, CharacterID, SessionIDa}),
@@ -108,7 +108,7 @@ valid({npc_activate, ActorID}, State = #zone_state{map_server = MapServer}) -&gt;
             log:warning(&quot;NPC found.&quot;,
                         [{id, ActorID}]),
 
-            Mod = (NPC#npc.main):new(self(), NPC),
+            Mod = (NPC#npc.main):new(self()),
             log:debug(&quot;NPC initialized.&quot;,
                       [{result, Mod}]),
 
@@ -121,13 +121,14 @@ valid({npc_activate, ActorID}, State = #zone_state{map_server = MapServer}) -&gt;
 
             {next_state, valid, State}
     end;
-valid({npc_menu_select, ActorID, Selection}, State = #zone_state{npc = {Pid, NPC}}) -&gt;
+valid({npc_menu_select, _ActorID, Selection},
+      State = #zone_state{npc = {Pid, _NPC}}) -&gt;
     Pid ! Selection,
     {next_state, valid, State};
-valid({npc_next, ActorID}, State = #zone_state{npc = {Pid, NPC}}) -&gt;
+valid({npc_next, _ActorID}, State = #zone_state{npc = {Pid, _NPC}}) -&gt;
     Pid ! continue,
     {next_state, valid, State};
-valid({npc_close, ActorID}, State = #zone_state{npc = {Pid, NPC}}) -&gt;
+valid({npc_close, _ActorID}, State = #zone_state{npc = {Pid, _NPC}}) -&gt;
     Pid ! close,
     {next_state, valid, State};
 valid(map_loaded, State) -&gt;
@@ -216,7 +217,7 @@ valid({walk, {ToX, ToY, ToD}},
     case PathFound of
         {ok, [{SX, SY, SDir} | Path]} -&gt;
             {ok, Timer} = walk_interval(SDir),
-            {FX, FY, FDir} = lists:last(element(2, PathFound)),
+            {FX, FY, _FDir} = lists:last(element(2, PathFound)),
 
             gen_server:cast(MapServer,
                             {send_to_other_players_in_sight,
@@ -251,31 +252,42 @@ valid(Event, State) -&gt;
     ?MODULE:handle_event(Event, valid, State).
 
 walking({walk, {ToX, ToY, ToD}},
-        State = #zone_state{tcp = TCP,
-                            map = Map,
-                            map_server = MapServer,
-                            account = #account{id = AccountID},
-                            char = C = #char{id = CharacterID,
-                                             x = X,
-                                             y = Y},
-                            walk_timer = OldTimer}) -&gt;
-    timer:cancel(OldTimer),
-
+        State = #zone_state{map = Map,
+                            char = #char{x = X,
+                                         y = Y}}) -&gt;
     log:error(&quot;Walk request while walking.&quot;,
               [{coords, {ToX, ToY, ToD}},
                {current_position, {X, Y}}]),
 
-    valid({walk, {ToX, ToY, ToD}}, State);
+    {Time, PathFound} = timer:tc(c_interface, pathfind, [Map, {X, Y}, {ToX, ToY}]),
+
+    log:error(&quot;Path found.&quot;,
+              [{map_size, {bit_size(Map#map.cells), byte_size(Map#map.cells)}},
+               {path, PathFound},
+               {elapsed, Time}]),
+
+    case PathFound of
+        {ok, Path} -&gt;
+            {next_state, walking, State#zone_state{walk_path = Path,
+                                                   walk_changed = {X, Y}}};
+        _Error -&gt;
+            {next_state, valid, State}
+    end;
 walking(step, State = #zone_state{char = C,
+                                  account = A,
+                                  tcp = TCP,
+                                  map_server = MapServer,
                                   walk_timer = Timer,
                                   walk_prev = {Time, PDir},
-                                  walk_path = Path}) -&gt;
+                                  walk_path = Path,
+                                  walk_changed = Changed}) -&gt;
     case Path of
         [] -&gt;
             timer:cancel(Timer),
             log:error(&quot;Done walking.&quot;),
             {next_state, valid, State#zone_state{walk_timer = undefined,
-                                                 walk_path = undefined}};
+                                                 walk_path = undefined,
+                                                 walk_changed = false}};
         [{CX, CY, CDir} | Rest] -&gt;
             if
                 CDir == PDir -&gt;
@@ -286,6 +298,21 @@ walking(step, State = #zone_state{char = C,
                     {ok, NewTimer} = walk_interval(CDir)
             end,
 
+            case Changed of
+                {X, Y} -&gt;
+                    {FX, FY, _FDir} = lists:last(Rest),
+
+                    gen_server:cast(MapServer,
+                                    {send_to_other_players_in_sight,
+                                     {X, Y},
+                                     C#char.id,
+                                     16#86,
+                                     {A#account.id, {X, Y}, {FX, FY}, zone_master:tick()}}),
+
+                    TCP ! {16#87, {{X, Y}, {FX, FY}, zone_master:tick()}};
+                _ -&gt; ok
+            end,
+
             log:warning(&quot;Stepping.&quot;, [{direction, CDir},
                                       {elapsed, trunc(timer:now_diff(now(), Time) / 1000)},
                                       {current_pos, {CX, CY}}]),
@@ -293,7 +320,8 @@ walking(step, State = #zone_state{char = C,
             {next_state, walking, State#zone_state{char = C#char{x = CX, y = CY},
                                                    walk_timer = NewTimer,
                                                    walk_prev = {Time, CDir},
-                                                   walk_path = Rest}}
+                                                   walk_path = Rest,
+                                                   walk_changed = false}}
     end;
 walking(Event, State) -&gt;
     ?MODULE:handle_event(Event, walking, State).
@@ -430,15 +458,17 @@ code_change(_OldVsn, StateName, StateData, _Extra) -&gt;
 
 
 % Helper walking function
-walk_interval(N) when N band 1 == 1 -&gt;
-    log:debug(&quot;Walking diagonally.&quot;),
-    timer:apply_interval(trunc(?WALKSPEED * 1.4),
-                         gen_fsm,
-                         send_event,
-                         [self(), step]);
-walk_interval(_) -&gt;
-    log:debug(&quot;Walking straight.&quot;),
-    timer:apply_interval(?WALKSPEED,
+walk_interval(N) -&gt;
+    Interval = case N band 1 of
+                   1 -&gt;
+                       log:debug(&quot;Walking diagonally.&quot;),
+                       trunc(?WALKSPEED * 1.4);
+                   0 -&gt;
+                       log:debug(&quot;Walking straight.&quot;),
+                       ?WALKSPEED
+               end,
+
+    timer:apply_interval(Interval,
                          gen_fsm,
                          send_event,
                          [self(), step]).</diff>
      <filename>src/zone/zone_fsm.erl</filename>
    </modified>
    <modified>
      <diff>@@ -33,12 +33,17 @@ load_script([Script | Scripts], N) -&gt;
                                []
                        end,
 
-            Attrs = lists:map(fun([K, V]) -&gt; [define, [list_to_atom(lists:concat([&quot;npc-&quot;, K]))], [quote, V]] end, Attributes),
+            Attrs = [[define, ['npc-id'], N] |
+                     lists:map(fun([K, V]) -&gt;
+                                   [define,
+                                    [list_to_atom(lists:concat([&quot;npc-&quot;, K]))],
+                                    [quote, V]]
+                               end, Attributes)],
 
             Body = lists:filter(fun(Sexp) -&gt; lists:nth(1, Sexp) /= include end, Rest),
 
             Code = [[defmodule,
-                     [Name, player, npc],
+                     [Name, player],
                      [export, [main, 0]]] |
                      [([progn,
                         ['include-file', &quot;lib/npc.lfh&quot;]] ++ Includes ++ Attrs) |
@@ -92,24 +97,24 @@ say(FSM, NPC, Message) -&gt;
     gen_fsm:send_all_state_event(FSM,
                                  {send_packet,
                                   16#b4,
-                                  {NPC#npc.id,
+                                  {NPC,
                                    Message}}).
 
 menu(FSM, NPC, Choices) -&gt;
     gen_fsm:send_all_state_event(FSM,
                                  {send_packet,
                                   16#b7,
-                                  {NPC#npc.id,
+                                  {NPC,
                                    Choices}}).
 
 next(FSM, NPC) -&gt;
     gen_fsm:send_all_state_event(FSM,
                                  {send_packet,
                                   16#b5,
-                                  NPC#npc.id}).
+                                  NPC}).
 
 close(FSM, NPC) -&gt;
     gen_fsm:send_all_state_event(FSM,
                                  {send_packet,
                                   16#b6,
-                                  NPC#npc.id}).
+                                  NPC}).</diff>
      <filename>src/zone/zone_npc.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8672d1f9094595ba0711e69f248947b644bc4b51</id>
    </parent>
  </parents>
  <author>
    <name>Alex Suraci</name>
    <email>i.am@toogeneric.com</email>
  </author>
  <url>http://github.com/aliter/aliter/commit/0510049c7345770517707bc711e0b4114dffc434</url>
  <id>0510049c7345770517707bc711e0b4114dffc434</id>
  <committed-date>2009-10-31T09:21:01-07:00</committed-date>
  <authored-date>2009-10-31T09:21:01-07:00</authored-date>
  <message>* Walking is now much smoother; the next walk packet is sent after the next step.
* Fixed all the useless warnings in zone_fsm.
* No longer pass NPC as second argument to modules; unnecessary.</message>
  <tree>d46d76ee74f426d781801952e307544b7e23ec08</tree>
  <committer>
    <name>Alex Suraci</name>
    <email>i.am@toogeneric.com</email>
  </committer>
</commit>
