[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 81945d9180d0cc1ac406875c7b470db618f6d085

julio (none) julio at julio-desktop.
Mon Aug 2 04:22:03 UTC 2010


The following commit has been merged in the master branch:
commit 81945d9180d0cc1ac406875c7b470db618f6d085
Author: julio <julio at julio-desktop.(none)>
Date:   Sun Aug 1 23:21:06 2010 -0500

    Fixing segfaults...

diff --git a/data/images/others/wrong.png b/data/images/others/wrong.png
new file mode 100644
index 0000000..43abf06
Binary files /dev/null and b/data/images/others/wrong.png differ
diff --git a/src/game.c b/src/game.c
index e059c53..e852579 100644
--- a/src/game.c
+++ b/src/game.c
@@ -38,6 +38,7 @@
 #include "map.h"
 #include "objects.h"
 #include "llist.h"
+#include "tuxrts.h"
 
 
 #define FPS 15 /* 15 frames per second */
@@ -121,7 +122,6 @@ static SDL_Surface* current_bkgd()
 
 static int game_init(void)
 {
-    FILE *fp;
 
     //SDL variables init
     SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
@@ -155,42 +155,9 @@ static int game_init(void)
     SDL_quit_received = 0;
     escape_received = 0;
 
-    fp = LoadObj("objects");
-    if(fp == NULL)
-    {
-        printf("File not found!\n");
-        DEBUGMSG(debug_game, "File not found!");
-        return 1;
-    }
-    printf("Object files in memory!\n");
-    if(objects_xml(fp))
-    {
-        printf("Error parsing file!");
-        DEBUGMSG(debug_game, "Error loading the objects description file.\n");
-        return 1;
-    }
-    printf("Object file parsed.\n");
-   
-    fp = LoadMap("map");
-    if(fp == NULL)
-    {
-        DEBUGMSG(debug_game, "File not found!");
-        return 1;
-    }
-    printf("Map file in memory.\n");
 
-    if(map_xml(fp))
-    {
-        printf("Error parsing file!");
-        DEBUGMSG(debug_game, "Error loading the map file.\n");
+    if(tuxrts_init("objects", "map", 2))
         return 1;
-    }
-    printf("Map file parsed!\n");
-    if(create_gmaps(2))
-    {
-        printf("Couldn't generate grpah mesh!\n");
-    }
-    generate_map();
 
     return 0;
 }
@@ -221,6 +188,8 @@ int game(void)
         game_handle_mouse();
 
         game_status = check_exit_conditions();
+        if(rts_valid_tile(0,1,io.go_xy))
+            printf("Is a valid tile... ");
         game_proces();
         game_draw();
         SDL_Flip(screen);
@@ -310,10 +279,7 @@ static void game_draw(void)
 
 static void game_proces(void)
 {
-    // TODO: Need to proces per player
     int i, j;
-    //io.go_xy.x = 0;
-    //io.go_xy.y = 0;
     if( io.go_rect.x != -1 &&
         io.go_rect.y != -1 )
     {
@@ -322,29 +288,34 @@ static void game_proces(void)
         {
             if(gmaps[0][io.go_xy.x][io.go_xy.y].terrain == OCEAN)
             {
+                printf("INVALID: Ocean tile");
                 io.go_valid_flag = 0;
             }
             else if(gmaps[0][io.go_xy.x][io.go_xy.y].terrain == HIGHSEA)
             {
+                printf("INVALID: Highsea tile");
                 io.go_valid_flag = 0;
             }
             else if(gmaps[0][io.go_xy.x][io.go_xy.y].object != NULL)
             {
-                if( gmaps[0][io.go_xy.x][io.go_xy.y].object->type == FOREST   ||
+                /*if( gmaps[0][io.go_xy.x][io.go_xy.y].object->type == FOREST   ||
                     gmaps[0][io.go_xy.x][io.go_xy.y].object->type == GOLD     ||
                     gmaps[0][io.go_xy.x][io.go_xy.y].object->type == STONE ) 
                 {
+                    printf("INVALID: Object in tile");
                     io.go_valid_flag = 0;
                     // From to condition... Ships may use wather, 
                     // pawns may une FOREST, GOLD, AND STONE
                 }
                 else
                 {
+                    printf("VALID: The target tile is valid");
                     io.go_valid_flag = 1;
-                }
+                }*/
             }
             else
             {
+                printf("VALID: The target tile is valid");
                 io.go_valid_flag = 1;
             }
         }
@@ -418,6 +389,7 @@ static void game_handle_mouse(void)
     }
     if(io.mousedown_flag != 0)
     {
+        printf("Mouse down, ... ");
         if(io.mouseclicked_flag != 0)
         {
             Pmousemap = mouse_map(io.Plclick, Pscreen);
@@ -434,7 +406,7 @@ static void game_handle_mouse(void)
         Pmousemap = mouse_map(io.Prclick, Pscreen);
         io.go_rect.x = gmaps[0][Pmousemap.x][Pmousemap.y].rect.x; 
         io.go_rect.y = gmaps[0][Pmousemap.x][Pmousemap.y].rect.y;
-        printf("Go select: %d %d \n", io.go_rect.x, io.go_rect.y);
+        printf("Go select: %d %d ", io.go_rect.x, io.go_rect.y);
         io.mousedownr_flag = 0;
         if( io.go_rect.x > Pscreen.x &&
             io.go_rect.x < Pscreen.x + screen->w &&
diff --git a/src/tuxrts.c b/src/tuxrts.c
index 9b4faf1..add0d9e 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -1,42 +1,63 @@
 #include "tuxrts.h"
+#include "globals.h"
 #include "tuxhistory.h"
+#include "fileops.h"
 #include "loaders.h"
-#include "maps.h"
+#include "map.h"
 #include "players.h"
 #include "graphs.h"
 #include "llist.h"
-/*
-int tuxrts_init(char *map_name, th_players *players)
+
+int tuxrts_init(char *object_name, char *map_name, int players)
 {
+    FILE *fp;
 
     object_counter = 0;
 
-    fp = LoadMap("map");
+    fp = LoadObj("objects");
     if(fp == NULL)
     {
+        printf("File not found!\n");
         DEBUGMSG(debug_game, "File not found!");
         return 1;
     }
+    printf("Object files in memory!\n");
+    if(objects_xml(fp))
+    {
+        printf("Error parsing file!");
+        DEBUGMSG(debug_game, "Error loading the objects description file.\n");
+        return 1;
+    }
+    printf("Object file parsed.\n");
+   
+    fp = LoadMap(map_name);
+    if(fp == NULL)
+    {
+        DEBUGMSG(debug_game, "File not found!");
+        return 1;
+    }
+    printf("Map file in memory.\n");
 
-    
     if(map_xml(fp))
     {
         printf("Error parsing file!");
         DEBUGMSG(debug_game, "Error loading the map file.\n");
         return 1;
     }
-
-    if(create_gmaps(2))
+    printf("Map file parsed!\n");
+    if(create_gmaps(players))
     {
+        printf("Couldn't generate grpah mesh!\n");
         return 1;
     }
     generate_map();
+
     return 0;
 }
-*/
+
 // Returns 1 if the tile is valid to use for a player, and unit
 // and 0 if not.
-static int rts_valid_tile(int player, int unit, th_point coords)
+int rts_valid_tile(int player, int unit, th_point coords)
 {
     list_node *unit_p;
     if(coords.x < 0 || coords.x > x_tildes)
@@ -56,7 +77,7 @@ static int rts_valid_tile(int player, int unit, th_point coords)
     {
         return 0;
     }
-    else if(gmaps[player][coords.x][coords.y].object != NULL)
+    /*else if(gmaps[player][coords.x][coords.y].object != NULL)
     {
         if( gmaps[player][coords.x][coords.y].object->type == FOREST   ||
             gmaps[player][coords.x][coords.y].object->type == GOLD     ||
@@ -70,7 +91,7 @@ static int rts_valid_tile(int player, int unit, th_point coords)
         {
             return 1;
         }
-    }
+    }*/
     else
     {
         return 1;
diff --git a/src/tuxrts.h b/src/tuxrts.h
index 7e8c970..cc09d59 100644
--- a/src/tuxrts.h
+++ b/src/tuxrts.h
@@ -1,13 +1,23 @@
 #ifndef TUXRTS_H
 #define TUXRTS_H
 
+#include "tuxhistory.h"
+#include "globals.h"
 #include "map.h"
+#include "players.h"
+#include "llist.h"
 
 /* tuxrts_mapinit(): Inizialize all map vars. This is
- * the fisrt function to call when we begin the game.*/
+ * the fisrt function to call when we begin the game.
+ * char *: Object file name, without .xml
+ * char *: Map file name, without .xml
+ * int   : Number of players*/
 
-int tuxrts_init(char *map_name, th_player *players);
+int tuxrts_init(char *, char *, int);
+int rts_valid_tile(int, int, th_point);
 
 void tuxrts_cleanup(void);
 
+list_node *selected_node;
+
 #endif

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list