TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

[PATCH MADE] Map function: Offset of target from current loc

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Thu Jan 19, 2012 5:03 pm    Post subject: [PATCH MADE] Map function: Offset of target from current loc Reply with quote

Please can we have a function that provides the reverse of the #MAP JUMP <x> <y> <z> command, i.e. when given a target room vnumber it will display on-screen the necessary <x>, <y> and <z> values that would get to that room from the current one? When laying out a map, especially if from a flat picture with "up" and "down" links between rooms on different z-axis values and where the map is bigger than a screen full in size it can be very difficult to join the ends up of a circular route (by judicious #MAP INSERT / UNINSERTs) if the free ends are not on the same horizontal plane!

Of course, if the two rooms actually coincide in all three coordinates a 0,0,0 result is useful as well as there is no way the map drawing routine can show two rooms in the same space simultaniously...


Last edited by Slysven on Fri Aug 10, 2012 4:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Thu Jan 19, 2012 5:33 pm    Post subject: Reply with quote

I've added it to my todo list.
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Fri Aug 10, 2012 4:31 pm    Post subject: Reply with quote

Here is a patch that adds a #MAP LOCATE {VNUM} [{<VARIABLE>}] command that displays (or if given a variable stores the result in that) the offset of the given VNUM from the current room. This is quite useful when you want to find out how far away another room is especially if it is not on the same level (z is different).

Given a variable name e.g. "offset" as a second argument to the command, if the room is located then offset[x], offset[y] and offset[z] will contain the numbers that if input into a #MAP JUMP command in the current room will move to the desired vnum room.

This patch creates a modified version of the spatialgrid_find() function called spatialgrid_locate() that instead returns the x,y,z offsets for a given room vnum whereas the original function returns the vnum for given x,y,z offsets. This patch was built against the 2.00.9 beta as it was on 23 July 2012. You may apply it with something like "patch -i patchfile" in the src directory where patchfile is what you have called the text in the patch below (try it with a --dry-run first to see whether it'll go in for you):
Code:
diff -u -p ./src_original/mapper.c ./src_map_locate_mod/mapper.c
--- ./src_original/mapper.c   2012-04-04 03:22:14.000000000 +0100
+++ ./src_map_locate_mod/mapper.c   2012-08-10 21:47:48.643571700 +0100
@@ -1070,6 +1070,49 @@ DO_MAP(map_list)
    }
 }
 
+DO_MAP(map_locate)
+{
+   int x,y,z,to;
+
+   arg = sub_arg_in_braces(ses, arg, arg1, GET_ONE, SUB_VAR|SUB_FUN);
+   arg = sub_arg_in_braces(ses, arg, arg2, GET_ONE, SUB_VAR|SUB_FUN);
+
+   if (*arg1)
+   {
+      to = atoi(arg1);
+
+      if (to <= 0 || to >= ses->map->size || ses->map->room_list[to] == NULL)
+      {
+         tintin_printf2(ses, "#MAP LOCATE {VNUM} [<VARIABLE>] - VNUM {%s} NOT VALID.\n"
+            "     MUST BE BETWEEN {1} AND {%d} AND BE AN EXISTING ROOM.", arg1, ses->map->size - 1);
+         return;
+      }
+
+      if (spatialgrid_locate(ses, ses->map->in_room, to, &x, &y, &z))
+      {
+         if (*arg2)
+         {
+            add_nest_node(ses->list[LIST_VARIABLE], arg2, "{x}{%d}{y}{%d}{z}{%d}", x, y, z);
+         }
+         else
+         {
+            show_message(ses, -1, "#MAP LOCATE: ROOM %d {%s} found at offset (%d, %d, %d) from current location.", to, ses->map->room_list[to]->name, x, y, z);
+         }
+      }
+      else
+      {
+         if (!(*arg2))
+         {
+            show_message(ses, -1, "#MAP LOCATE: COULD NOT FIND ROOM {%d} FROM CURRENT LOCATION.", to);
+         }
+      }
+   }
+   else
+   {
+      show_message(ses, -1, "#MAP LOCATE: <ROOM NUMBER> [<VARIABLE>] TO LOCATE POSITION OF ROOM FROM CURRENT LOCATION.");
+   }
+}
+
 DO_MAP(map_map)
 {
    char arg3[BUFFER_SIZE], buf[BUFFER_SIZE], out[BUFFER_SIZE];
@@ -3483,6 +3526,101 @@ int spatialgrid_find(struct session *ses
       }
 
       for (exit = room->f_exit ; exit ; exit = exit->next)
+      {
+         if (ses->map->display_stamp == ses->map->room_list[exit->vnum]->display_stamp)
+         {
+            if (room->length >= ses->map->room_list[exit->vnum]->length)
+            {
+               continue;
+            }
+         }
+
+         if (exit->dir == 0)
+         {
+            continue;
+         }
+
+         if (HAS_BIT(exit->flags, EXIT_FLAG_HIDE) || HAS_BIT(ses->map->room_list[exit->vnum]->flags, ROOM_FLAG_HIDE))
+         {
+            continue;
+         }
+
+         if (head == (tail + 1) % MAP_BF_SIZE)
+         {
+            break;
+         }
+
+         xx = node->x + (HAS_BIT(exit->dir, MAP_EXIT_E) ?  1 : HAS_BIT(exit->dir, MAP_EXIT_W) ? -1 : 0);
+         yy = node->y + (HAS_BIT(exit->dir, MAP_EXIT_N) ?  1 : HAS_BIT(exit->dir, MAP_EXIT_S) ? -1 : 0);
+         zz = node->z + (HAS_BIT(exit->dir, MAP_EXIT_U) ?  1 : HAS_BIT(exit->dir, MAP_EXIT_D) ? -1 : 0);
+
+         temp = &list[tail];
+
+         temp->vnum   = exit->vnum;
+         temp->x      = xx;
+         temp->y      = yy;
+         temp->z      = zz;
+         temp->length = node->length + 1;
+
+         tail = (tail + 1) % MAP_BF_SIZE;
+      }
+   }
+   pop_call();
+   return 0;
+}
+
+int spatialgrid_locate(struct session *ses, int vnum1, int vnum2, int *x, int *y, int *z)
+{
+   int head, tail;
+   struct grid_node *node, *temp, list[MAP_BF_SIZE];
+   struct exit_data *exit;
+   struct room_data *room;
+   int xx, yy, zz;
+
+   push_call("spatialgrid_locate(%s,%d,%d)", ses->name, vnum1, vnum2);
+
+   head = 0;
+   tail = 1;
+
+   node = &list[head];
+
+   node->vnum   = vnum1;
+   node->x      = 0;
+   node->y      = 0;
+   node->z      = 0;
+   node->length = 0;
+
+   ses->map->display_stamp++;
+
+   while (head != tail)
+   {
+      node = &list[head];
+
+      head = (head + 1) % MAP_BF_SIZE;
+
+      room = ses->map->room_list[node->vnum];
+
+      if (ses->map->display_stamp != room->display_stamp)
+      {
+         room->display_stamp = ses->map->display_stamp;
+      }
+      else if (room->length <= node->length)
+      {
+         continue;
+      }
+
+      room->length = node->length;
+
+      if (node->vnum == vnum2)
+      {
+         *x = node->x;
+         *y = node->y;
+         *z = node->z;
+         pop_call();
+         return 1;
+      }
+
+      for (exit = room->f_exit ; exit ; exit = exit->next)
       {
          if (ses->map->display_stamp == ses->map->room_list[exit->vnum]->display_stamp)
          {
diff -u -p ./src_original/tables.c ./src_map_locate_mod/tables.c
--- ./src_original/tables.c   2012-04-04 04:08:08.000000000 +0100
+++ ./src_map_locate_mod/tables.c   2012-08-10 21:45:22.224726600 +0100
@@ -479,6 +479,7 @@ struct map_type map_table[] =
    {     "LEGENDA",          map_legend,          1    },
    {     "LINK",             map_link,            2    },
    {     "LIST",             map_list,            2    },
+   {     "LOCATE",           map_locate,          2    },
    {     "MAP",              map_map,             2    },
    {     "MOVE",             map_move,            2    },
    {     "NAME",             map_name,            2    },
diff -u -p ./src_original/tintin.h ./src_map_locate_mod/tintin.h
--- ./src_original/tintin.h   2012-04-04 01:11:01.000000000 +0100
+++ ./src_map_locate_mod/tintin.h   2012-08-10 21:44:14.743856400 +0100
@@ -1203,6 +1203,7 @@ extern void shortest_path(struct session
 extern void explore_path(struct session *ses, int run, char *left, char *right);
 extern int find_coord(struct session *ses, char *arg);
 extern int spatialgrid_find(struct session *ses, int vnum, int x, int y, int z);
+extern int spatialgrid_locate(struct session *ses, int vnum1, int vnum2, int *x, int *y, int *z);
 extern void show_vtmap(struct session *ses);
 
 #endif
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed Oct 07, 2015 10:52 am    Post subject: Reply with quote

Is this function still missing ? Could be so useful
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Sun Aug 21, 2016 8:29 pm    Post subject: Reply with quote

Looks like I forgot about it, added to my TODO list.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Feature Requests All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group