[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 4de5b46a4790a5f8f7654329390eda86efd9bae3

julio (none) julio at julio-desktop.
Thu Aug 12 01:40:07 UTC 2010


The following commit has been merged in the master branch:
commit 4de5b46a4790a5f8f7654329390eda86efd9bae3
Author: julio <julio at julio-desktop.(none)>
Date:   Wed Aug 11 20:39:00 2010 -0500

    GUI interface advances, and some segfaults fixed.

diff --git a/data/images/buildings/Makefile.am b/data/images/buildings/Makefile.am
index 241530b..1643703 100644
--- a/data/images/buildings/Makefile.am
+++ b/data/images/buildings/Makefile.am
@@ -5,5 +5,10 @@
 buildingsdir = $(pkgdatadir)/images/buildings
 
 dist_buildings_DATA = villagehouse.png \
+villagehouse_new.png \
 hut.png \
-monolit.png
+hut_new.png \
+monolit.png \
+monolit_new.png \
+farm.png \
+farm_new.png 
diff --git a/data/images/buildings/farm.png b/data/images/buildings/farm.png
new file mode 100644
index 0000000..2f84ed3
Binary files /dev/null and b/data/images/buildings/farm.png differ
diff --git a/data/images/buildings/hut.png b/data/images/buildings/hut.png
index 5f91090..98b5990 100644
Binary files a/data/images/buildings/hut.png and b/data/images/buildings/hut.png differ
diff --git a/data/images/buildings/hut_new.png b/data/images/buildings/hut_new.png
new file mode 100644
index 0000000..7a17b12
Binary files /dev/null and b/data/images/buildings/hut_new.png differ
diff --git a/data/images/buildings/monolit.png b/data/images/buildings/monolit.png
index 78d17b0..21f1232 100644
Binary files a/data/images/buildings/monolit.png and b/data/images/buildings/monolit.png differ
diff --git a/data/images/buildings/monolit_new.png b/data/images/buildings/monolit_new.png
new file mode 100644
index 0000000..157d26e
Binary files /dev/null and b/data/images/buildings/monolit_new.png differ
diff --git a/data/images/buildings/villagehouse.png b/data/images/buildings/villagehouse.png
index 8bcd836..49aecef 100644
Binary files a/data/images/buildings/villagehouse.png and b/data/images/buildings/villagehouse.png differ
diff --git a/data/images/buildings/villagehouse_new.png b/data/images/buildings/villagehouse_new.png
new file mode 100644
index 0000000..49e1366
Binary files /dev/null and b/data/images/buildings/villagehouse_new.png differ
diff --git a/data/images/others/explored.png b/data/images/others/explored.png
index cbf680f..6732e6a 100644
Binary files a/data/images/others/explored.png and b/data/images/others/explored.png differ
diff --git a/data/maps/map.xml b/data/maps/map.xml
index 2af727d..ee233b9 100644
--- a/data/maps/map.xml
+++ b/data/maps/map.xml
@@ -367,7 +367,7 @@
         <tilde>
             <height>1</height>
             <terrain>GRASSLAND</terrain>
-            <object></object>
+            <object player=1>FARM</object>
             <unit></unit>
             <building></building>
         </tilde>
diff --git a/data/objects/objects.xml b/data/objects/objects.xml
index 787260d..582dc34 100644
--- a/data/objects/objects.xml
+++ b/data/objects/objects.xml
@@ -92,6 +92,17 @@
     </object>
     <object>
         <type>BUILDING</type>
+        <name>FARM</name>
+        <rname>Farm</rname>
+        <description>Bulid farms to produce food.</description>
+        <live>250</live>
+        <vision>2</vision>
+        <defence>0</defence>
+        <attack>0</attack>
+        <move>0</move>
+    </object>
+    <object>
+        <type>BUILDING</type>
         <name>VILLAGE_CENTER</name>
         <rname>Center</rname>
         <description>This building can create villagers and you can store resources here</description>
diff --git a/src/ai.c b/src/ai.c
index 9ebdafa..527ef3a 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -385,14 +385,20 @@ static th_point ai_find_closest_center(th_point point)
 
 int ai_state_update(list_node *node)
 {
+    list_node *node_tmp;
     int tmp;
+    int i;
     th_point tmp_point, point;
     if(!node)
         return 0;
+    
+    i = 0;
+    
     do{
+        i++;
         if(node->obj.state.flag)
         {
-            //printf("Enter to process state\n");
+            printf("Enter to process state\n");
             if(node->obj.state.state == GOTO)
             {
                 node->obj.state.path_count = node->obj.state.path->size;
@@ -442,7 +448,10 @@ int ai_state_update(list_node *node)
             node->obj.state.flag = 0;
             if(node->obj.state.state == DIE)
             {
+                node_tmp = node->next;
                 ai_kill_object(node);
+                node = node_tmp;
+                continue;
             }
         }
         if(node->obj.state.agains_flag)
@@ -530,6 +539,9 @@ int ai_state_update(list_node *node)
                             node->obj.state.resource_type = REC_GOLD;
                         if(node->obj.state.target_obj->type == STONE)
                             node->obj.state.resource_type = REC_STONE;
+                        if(node->obj.state.target_obj->name_enum == FARM)
+                            node->obj.state.resource_type = REC_FOOD;
+
                         printf("%s using %s, %s live is %d\n", node->obj.rname,
                             node->obj.state.target_obj->rname, 
                             node->obj.state.target_obj->rname, 
diff --git a/src/fileops.h b/src/fileops.h
index 14d48e4..6211f08 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -382,8 +382,13 @@ enum{
     REC_STONE_1,
     VILLAGER_MILKMAID,
     HOUSE,
+    HOUSE_NEW,
     HUT,
+    HUT_NEW,
     VILLAGE_CENTER,
+    VILLAGE_CENTER_NEW,
+    FARM,
+    FARM_NEW,
     NUM_OBJECTS // Must be at the end.
 };
 
diff --git a/src/fileops_media.c b/src/fileops_media.c
index fc0e95f..fe75be4 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -316,8 +316,13 @@ int load_image_data()
       "others/stone.png",
       "units/milkmaid.png",
       "buildings/villagehouse.png",
+      "buildings/villagehouse_new.png",
       "buildings/hut.png",
-      "buildings/monolit.png"
+      "buildings/hut_new.png",
+      "buildings/monolit.png",
+      "buildings/monolit_new.png",
+      "buildings/farm.png",
+      "buildings/farm_new.png"
   };
 
 
diff --git a/src/game.c b/src/game.c
index c26cf97..304e276 100644
--- a/src/game.c
+++ b/src/game.c
@@ -100,6 +100,8 @@ typedef struct io_vars
     SDL_Rect go_rect;
     SDL_Rect go_rect_dest;
     int go_valid_flag;
+    int build_flag; //-1 if no building to alloc, and 0+ to specify the 
+                    //building type.
 }io_vars;
 
 io_vars io;
@@ -197,6 +199,7 @@ static int game_init(void)
     io.go_rect_dest.w = 0;
     io.go_rect_dest.h = 0;
     io.go_valid_flag = 0;
+    io.build_flag = -1;
 
     // Player?
     this_player = 1;
@@ -417,9 +420,31 @@ static void game_draw(int player)
     }
    
     io.go_valid_flag = 0;
+
+    //Draw a preview of a future building if the building flag is on
+
+    dest_point = mouse_map(io.Pmouse, Pscreen);
+    if(dest_point.x != -1)
+    {
+        if(dest_point.y != -1)
+        {
+            if(io.build_flag >= 0)
+            {
+                dest.x = gmaps[0][dest_point.x][dest_point.y].anchor.x - 
+                    origin.x - objects[io.build_flag]->w/2 + panel.panel_game.x;
+                dest.y = gmaps[0][dest_point.x][dest_point.y].anchor.y - 
+                    origin.y - objects[io.build_flag]->w/2 + panel.panel_game.y;
+
+                SDL_BlitSurface(objects[io.build_flag+1], NULL, screen, &dest);
+            }
+        }
+    }
+
     point.x = 0;
     point.y = 0;
     dest_point = mouse_map(point, Pscreen);
+
+    // Draw no visible areas black
     if(dest_point.x == -1 || dest_point.y == -1)
     {
         point.x = Pscreen.x + 10;
@@ -459,6 +484,7 @@ static void game_handle_mouse(void)
     th_point Pdtmap;
     th_point *path;
     int i, j;
+    int tmp;
     
     Pmousemap = mouse_map(io.Pmouse, Pscreen);
     Pdtmap = Pscreen;
@@ -521,14 +547,17 @@ static void game_handle_mouse(void)
             io.select_rect_dest.x = -1;
             io.select_rect_dest.y = -1;
         }
+
     }
     if(io.mousedown_flag != 0)
     {
         if(io.mouseclicked_flag != 0)
         {
-            if(panel_click(&io.Plclick))
+            if((io.build_flag = panel_click(&io.Plclick, selection.selected_objs[0])) != -1)
             {
                 io.mouseclicked_flag = 0;
+                if(io.build_flag == -3)
+                    selection.selected_objs[0] = NULL;
             }
             else
             {
diff --git a/src/map.c b/src/map.c
index 5e16212..70ef268 100644
--- a/src/map.c
+++ b/src/map.c
@@ -455,6 +455,11 @@ static int *get_draw_tilde(int *array, int oe)
     int *a;
     int i,j;
 
+    if(!array)
+    {
+        return NULL;
+    }
+
     // Allocate a as a dinamic array, please free it using FREE()
     a = (int *)malloc(9*sizeof(int));
     if( a == NULL )
diff --git a/src/objects.c b/src/objects.c
index ac5cd7f..e9ec837 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -30,6 +30,7 @@ static int init_obj_hash(void)
     hashtable_add(obj_table_hash, "VILLAGE_CENTER", VILLAGE_CENTER);
     hashtable_add(obj_table_hash, "REC_GOLD_1", REC_GOLD_1);
     hashtable_add(obj_table_hash, "REC_STONE_1", REC_STONE_1);
+    hashtable_add(obj_table_hash, "FARM", FARM);
 
     hashtable_add(obj_table_hash, "FOREST", FOREST);
     hashtable_add(obj_table_hash, "GOLD", GOLD);
diff --git a/src/panel.c b/src/panel.c
index 790ec81..4321152 100644
--- a/src/panel.c
+++ b/src/panel.c
@@ -24,6 +24,7 @@
 #include "fileops.h"
 #include "players.h"
 
+static int rect_coll(th_point *p, SDL_Rect *r);
 
 int panel_init(void)
 {
@@ -44,18 +45,13 @@ int panel_init(void)
     for(i = 0; i < 5; i++)
     {
         panel.panel_option[i].x = panel.panel_description.x + 
-            panel.panel_description.w + 10 + (images[IMG_GUIBUILD]->w+10)*i;
+                panel.panel_description.w + 10 + (images[IMG_GUIBUILD]->w+10)*i;
         panel.panel_option[i].y = panel.panel_description.y;
         panel.panel_option[i].w = images[IMG_GUIBUILD]->w;
         panel.panel_option[i].h = images[IMG_GUIBUILD]->h;
+        panel.panel_actions[i] = INACTIVE;
     }
 
-    panel.panel_actions[0] = INACTIVE;
-    panel.panel_actions[1] = INACTIVE;
-    panel.panel_actions[2] = INACTIVE;
-    panel.panel_actions[3] = INACTIVE;
-    panel.panel_actions[4] = INACTIVE;
-
     panel.panel_header_dest.x = 0;
     panel.panel_header_dest.y = 0;
     panel.panel_header_dest.w = screen->w;
@@ -100,12 +96,16 @@ int panel_init(void)
 // from the object xml file info!
 void panel_draw(th_obj *select, int num)
 {
-    SDL_Rect dest, dest2;
+    SDL_Rect dest, dest2, rect;
     char tmp_text[100];
     int menu_y =(screen->h / 5) * 4;
 
     //TODO: Write a panel function to manipulate the game...
 
+    rect.x = 0;
+    rect.y = 0;
+    rect.w = images[IMG_GUIKILL]->w;
+    rect.h = images[IMG_GUIKILL]->h;
 
     SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], &panel.panel_header_dest, screen, 
             &panel.panel_header_origin);
@@ -140,15 +140,28 @@ void panel_draw(th_obj *select, int num)
             SDL_BlitSurface(objects[select->name_enum], NULL, screen, &dest);
             
             if(select->name_enum == VILLAGER_MILKMAID)
-            {
-                SDL_BlitSurface(images[IMG_GUIBUILD], NULL, screen, &panel.panel_option[0]);
+            { 
+                rect.x = objects[VILLAGE_CENTER]->w/2 - panel.panel_option[0].w/2;
+                SDL_FillRect(screen, &panel.panel_option[0], 0x000000);
+                SDL_BlitSurface(objects[VILLAGE_CENTER], &rect, screen, &panel.panel_option[0]);
                 panel.panel_actions[0] = BUILD;
+                panel.panel_actions_obj[0] = VILLAGE_CENTER;
+
+                rect.x = objects[FARM]->w/2 - panel.panel_option[1].w/2;
+                SDL_FillRect(screen, &panel.panel_option[1], 0x000000);
+                SDL_BlitSurface(objects[FARM], &rect, screen, &panel.panel_option[1]);
+                panel.panel_actions[1] = BUILD;
+                panel.panel_actions_obj[1] = FARM;               
+
+                rect.x = objects[HOUSE]->w/2 - panel.panel_option[2].w/2;
+                SDL_FillRect(screen, &panel.panel_option[2], 0x000000);
+                SDL_BlitSurface(objects[HOUSE], &rect, screen, &panel.panel_option[2]);
+                panel.panel_actions[2] = BUILD;
+                panel.panel_actions_obj[2] = HOUSE;
 
                 SDL_BlitSurface(images[IMG_GUIKILL], NULL, screen, &panel.panel_option[4]);
                 panel.panel_actions[4] = DIE;
 
-                panel.panel_actions[1] = INACTIVE;
-                panel.panel_actions[2] = INACTIVE;  
                 panel.panel_actions[3] = INACTIVE;
             }
             else if(select->name_enum == VILLAGE_CENTER)
@@ -197,14 +210,17 @@ static int rect_coll(th_point *p, SDL_Rect *r)
         return 0;
 }
 
+// Return -2 if a non building option was clicked, -1 if no click in
+// the panel was done, and 0+ to specify the building type to
+// create.
 
-
-int panel_click(th_point *point)
+int panel_click(th_point *point, th_obj *obj)
 {
+    int i;
     if(rect_coll(point, &panel.panel_header_dest))
     {
         printf("Click in header!\n");
-        return 1;
+        return -2;
     }
     else if(rect_coll(point, &panel.panel_dest))
     {
@@ -214,13 +230,31 @@ int panel_click(th_point *point)
         {
             printf("Click in the object description\n");
         }
-        if(rect_coll(point, &panel.panel_minimap))
+        else if(rect_coll(point, &panel.panel_minimap))
         {
             printf("Click in minimap!\n");
         }
-        return 1;
+        else
+        {
+            for(i = 0; i < 5; i++)
+            {
+                if(rect_coll(point, &panel.panel_option[i]))
+                {
+                    printf("Action: %d, target %d \n", panel.panel_actions[i],
+                            panel.panel_actions_obj[i]);
+                    if(panel.panel_actions[i] == DIE)
+                    {
+                        ai_modify_state(human_player, obj, DIE);
+                        return -3;
+                    }
+                    return panel.panel_actions_obj[i];
+                    return -2;
+                }
+            }
+        }
+        return -2;
     }
-    return 0;
+    return -1;
 }
 
 
diff --git a/src/panel.h b/src/panel.h
index 06604ff..333308e 100644
--- a/src/panel.h
+++ b/src/panel.h
@@ -22,6 +22,7 @@ typedef struct th_panel{
     SDL_Rect panel_description;
     SDL_Rect panel_option[5];
     int panel_actions[5];
+    int panel_actions_obj[5];
     SDL_Rect panel_dest;
     SDL_Rect panel_origin;
     SDL_Rect panel_header_dest;
@@ -33,7 +34,7 @@ th_panel panel;
 
 int panel_init(void);
 void panel_draw(th_obj *, int);
-int panel_click(th_point *point);
+int panel_click(th_point *point, th_obj *obj);
 int panel_rclick(th_point *point);
 
 #endif
diff --git a/src/tuxrts.c b/src/tuxrts.c
index bc6714c..f5ec83e 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -63,6 +63,7 @@ int tuxrts_init(char *object_name, char *map_name, int players)
         printf("Couldn't generate grpah mesh!\n");
         return 0;
     }
+    
     generate_map();
 
 
@@ -244,7 +245,7 @@ int rts_goto(th_obj *obj, th_point point)
                 }
                 else if(node->obj.type == FOREST ||
                         node->obj.type == GOLD   ||
-                        node->obj.type == STONE) 
+                        node->obj.type == STONE ) 
                 {
                     obj->state.target_point = tmp_point;
                     obj->state.rec_point = tmp_point;
@@ -264,6 +265,15 @@ int rts_goto(th_obj *obj, th_point point)
                         obj->state.target_obj = &(node->obj);
                         action = STORE;
                     }
+                    else if(node->obj.name_enum == FARM)
+                    {
+                        printf("It is a farm!");
+                        obj->state.target_point = tmp_point;
+                        obj->state.target_obj = &(node->obj);
+                        obj->state.rec_point = tmp_point;
+                        obj->state.rec_point_flag = 1;    
+                        action = USE;
+                    }
                     else
                     {
                         obj->state.target_point = tmp_point;

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list