[gnome-mud] changes to automap



Hello,
I begun adding support for room types (like street, hill, forest, etc.)
to the automap since I am playing a mud with large areas of rooms that
are created as needed and have exits to all directions so the exit graph
contains no information only room types are of interest. But since I'm
only beginning to write in C for Gnome it might be improvable. I added
the diff nontheless.
I found the map file format hard to extend and would suggest switching
to XML.
Please contact me if you need/want further help with coding.
	Felix Benner

PS: comments on my code and english are welcome.
-- 
Felix Benner             Telefon: 0711 720 7900
Fanny-Leicht-Stra� 14   Mobil  : 0177 339 4145          ==^,^^^,^=-_
70563 Stuttgart          E-Mail : Felix Benner Imail de

--- map.h.old	2004-09-20 12:22:09.544186760 +0200
+++ map.h	2004-09-20 12:23:11.084831160 +0200
@@ -33,6 +33,8 @@
     Map *map;
     int conn; /* The number of node connections (discounting up/down) */
 
+	gint room_type;
+
     GHashTable* gates; /* Gates are link with unusal name like farm, in, out, gate, enter... */
 	GHashTable* in_gates; /* Unusuals gates which leads to this node */
 	
@@ -50,6 +52,7 @@
 
     GtkWidget *window;
     GtkWidget *draw_area;
+	GtkWidget *type_chooser;
 	GtkWidget *hint;      // A label used to display hints or automap status
     GdkPixmap *pixmap;
 	
--- map.c.old	2004-09-20 12:22:05.575790048 +0200
+++ map.c	2004-09-20 14:09:04.180013888 +0200
@@ -45,6 +45,7 @@
 #endif
 
 #define _(string) gettext(string)
+#define N_(string) string
 
 static char const rcsid[] =
     "$Id: map.c,v 1.23 2004/01/09 12:57:13 jordim Exp $";
@@ -106,6 +107,25 @@
 char *direction[] = { "N", "NE", "E", "SE", "S", "SW", "W", "NW", "U", "D" };
 char *direction_long[] = { "North", "Northeast", "East", "Southeast", "South", "Southwest", "West", "Northwest", "Up", "Down" };
 
+struct RoomType {
+	gchar *name;
+	GdkColor color;
+};
+
+#define MAX_TYPE_INDEX 9
+struct RoomType room_types[] = {
+	{N_("Street"), {0, 250 << 8, 235 << 8, 215 << 8}},
+	{N_("House"), {0, 47 << 8, 79 << 8, 79 << 8}},
+	{N_("Plain"), {0, 0, 255 << 8, 128 << 8}},
+	{N_("Forest"), {0, 0, 100 << 8, 0}},
+	{N_("River"), {0, 106 << 8, 90 << 8, 205 << 8}},
+	{N_("Lake"), {0, 46 << 8, 139 << 8, 87 << 8}},
+	{N_("Ocean"), {0, 0, 0, 128 << 8}},
+	{N_("Coast"), {0, 244 << 8, 164 << 8, 96 << 8}},
+	{N_("Hill"), {0, 139 << 8, 69 << 8, 19 << 8}},
+	{N_("Mountain"), {0, 245 << 8, 245 << 8, 245 << 8}},
+};
+
 /* Other button codes */
 #define REMOVE   10
 #define LOAD     11
@@ -515,6 +535,7 @@
         automap->player = automap->map->nodelist->data;
     }
 
+	gtk_option_menu_set_history(GTK_OPTION_MENU(automap->type_chooser), automap->player->room_type);
     g_hash_table_destroy(hash);
 	automap->map->nodelist = g_list_remove(automap->map->nodelist, curr);
     node_hash_remove(automap->map->nodes, curr);
@@ -771,6 +792,7 @@
 			Map* new_map;
 			node->x = 0;
 			node->y = 0;
+			node->room_type = gtk_option_menu_get_history(GTK_OPTION_MENU(data->automap->type_chooser));
 			
 			/* Verify that the name is unique */
 			while (retry)
@@ -834,6 +856,7 @@
 			data->automap->map = target->map;
 			data->automap->x = target->x;
 			data->automap->y = target->y;
+			gtk_option_menu_set_history(GTK_OPTION_MENU(data->automap->type_chooser), target->room_type);
 			
 			/* Notify the map change and redraw */
 			maplink_change_map(target->map);
@@ -1055,6 +1078,7 @@
 			data->automap->map = target->map;
 			data->automap->x = target->x;
 			data->automap->y = target->y;
+			gtk_option_menu_set_history(GTK_OPTION_MENU(data->automap->type_chooser), target->room_type);
 
 			g_snprintf(command, 25, "%s\r\n", data->exists_path_name);
 			connection_send(main_connection, command);
@@ -1204,6 +1228,7 @@
 	automap->player = node;
 	automap->create_link_data->link = link_add(NULL, LK_NODE, 2 * node->x, 2 * node->y);
 	automap->create_link_data->link->node = node;
+	gtk_option_menu_set_history(GTK_OPTION_MENU(automap->type_chooser), node->room_type);
 	
 	g_free(data);
 }
@@ -1860,12 +1885,14 @@
     	blit_nodes(automap, ws, nodelist);
 
 	    nodelist[0] = automap->player = target;
+		gtk_option_menu_set_history(GTK_OPTION_MENU(automap->type_chooser), target->room_type);
     	draw_player(automap, ws, automap->player);
     	blit_nodes(automap, ws, nodelist);
 	}
 	else
 	{
 		automap->player = target;
+		gtk_option_menu_set_history(GTK_OPTION_MENU(automap->type_chooser), target->room_type);
 		automap->map = target->map;
 		maplink_change_map(automap->map);
 		redraw_map(automap);
@@ -1878,13 +1905,22 @@
      * edge (not its diagonal edge)
      */
     gint nodewidth = ws->mapped_unit / 4 - 1;
+	GdkGC *gc;
 
     Point p = { node->x, node->y };
     translate(automap, ws, &p);
 
+	if (node->room_type < MAX_TYPE_INDEX) {
+		if (room_types[node->room_type].color.pixel == 0)
+   			gdk_color_alloc(gtk_widget_get_colormap(automap->draw_area), &room_types[node->room_type].color);
+		gc = gdk_gc_new(automap->draw_area->window);
+		gdk_gc_set_foreground(gc, &room_types[node->room_type].color);
+	} else
+		gc = automap->draw_area->style->white_gc;
+
     /* Clear the area first */
     gdk_draw_rectangle(automap->pixmap,
-                       automap->draw_area->style->white_gc, TRUE,
+                       gc, TRUE,
                        p.x - nodewidth, p.y - nodewidth,
                        nodewidth * 2, nodewidth * 2);
 
@@ -2495,7 +2531,7 @@
 	guint *nbr_links = data[4];
     int i;
 
-    fprintf(file, "%d (%d, %d) %d ", *num, node->x, node->y, (gint) g_hash_table_lookup(hash_maps, node->map->name));
+    fprintf(file, "%d !%s (%d, %d) %d ", *num, room_types[node->room_type].name, node->x, node->y, (gint) g_hash_table_lookup(hash_maps, node->map->name));
 
     for (i = 0; i < 10; i++)
     {
@@ -3095,6 +3131,7 @@
         /* If the node is on a different map, recenter the map */
         automap->map    = next->map;
         automap->player = next;
+		gtk_option_menu_set_history(GTK_OPTION_MENU(automap->type_chooser), next->room_type);
 
         if (automap->map != this->map)
         {
@@ -3126,6 +3163,7 @@
 
             /* Link the two nodes up */
             next->map = automap->map;
+			next->room_type = gtk_option_menu_get_history(GTK_OPTION_MENU(automap->type_chooser));
 			maplink_change_map(next->map);
             next->connections[opposite].node = automap->player;
             automap->player->connections[type].node = next;
@@ -3190,6 +3228,7 @@
                         automap->map->nodelist =
                             g_list_remove(automap->map->nodelist, next_start_node);
 
+					gtk_option_menu_set_history(GTK_OPTION_MENU(automap->type_chooser), next->room_type);
                 }
             }
 			else
@@ -3199,6 +3238,7 @@
 
                 next->x = node.x;
                 next->y = node.y;
+				next->room_type = gtk_option_menu_get_history(GTK_OPTION_MENU(automap->type_chooser));
 
  				node_hash_prepend(automap->map->nodes, next);
 				
@@ -3397,6 +3437,13 @@
         redraw_map(automap);
 }
 
+static void room_type_changed(GtkOptionMenu *option_menu, AutoMap *automap) {
+    struct win_scale *ws = map_coords(automap);
+	automap->player->room_type = gtk_option_menu_get_history(option_menu);
+	draw_dot(automap, ws, automap->player);
+    draw_player(automap, ws, automap->player);
+}
+
 static gint enter_notify_event (GtkWidget *widget, GdkEventCrossing *event,
 				AutoMap *automap)
 {
@@ -3431,7 +3478,7 @@
     AutoMap *automap = g_malloc0(sizeof(AutoMap));
     GtkWidget *hbox, *updownvbox, *loadsavevbox, *vbox, *sep;
     GtkWidget *n, *ne, *e, *se, *s, *sw, *w, *nw, *up, *down;
-    GtkWidget *load, *save, *remove;
+    GtkWidget *load, *save, *remove, *menu;
     GtkWidget *table, *table_draw;
 	GtkWidget *hint;
 
@@ -3572,6 +3619,23 @@
     save = gtk_button_new_with_label(_("Save"));
     remove = gtk_button_new_with_label(_("Remove"));
 
+	menu = gtk_menu_new();
+	{
+		gint i;
+		for (i = 0; i <= MAX_TYPE_INDEX; i++) {
+			GtkWidget *item = gtk_menu_item_new_with_label(room_types[i].name);
+			gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+			gtk_widget_show(item);
+		}
+	}
+
+	automap->type_chooser = gtk_option_menu_new();
+	gtk_option_menu_set_menu(GTK_OPTION_MENU(automap->type_chooser), menu);
+	gtk_widget_show(automap->type_chooser);
+
+    gtk_signal_connect(GTK_OBJECT(automap->type_chooser), "changed",
+                       GTK_SIGNAL_FUNC(room_type_changed), automap);
+
     /* Create button directions */
     n  = gtk_button_new_with_label(_("N" ));
     ne = gtk_button_new_with_label(_("NE"));
@@ -3609,6 +3673,7 @@
     gtk_box_pack_start(GTK_BOX(vbox), loadsavevbox, TRUE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(vbox), remove, TRUE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(vbox), sep, TRUE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(vbox), automap->type_chooser, TRUE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(vbox), updownvbox, TRUE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, FALSE, 0);
 
@@ -3924,6 +3989,17 @@
         bptr = get_token(bptr, token);
         num = atol(token);
         bptr = get_token(bptr, token);
+		if (token[0] == '!') {
+			gint i = 0;
+			while (i <= MAX_TYPE_INDEX && strcmp(&token[1], room_types[i].name) != 0)
+				i++;
+			if (i <= MAX_TYPE_INDEX)
+				node->room_type = i;
+			else
+				node->room_type = 0;
+			bptr = get_token(bptr, token);
+		}
+
         node->x = atol(token);
 
         bptr = get_token(bptr, token);
@@ -4137,6 +4213,7 @@
 
 
     automap->player = g_ptr_array_index(arr, GPOINTER_TO_INT(automap->player));
+	gtk_option_menu_set_history(GTK_OPTION_MENU(automap->type_chooser), automap->player->room_type);
 	maplink_change_map(automap->player->map);
     g_ptr_array_free(arr, TRUE);
     g_list_free(maps);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]