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

julio (none) julio at julio-desktop.
Thu Jul 15 06:49:02 UTC 2010


The following commit has been merged in the master branch:
commit afc0c06bef0757cb53065dde798636579fd41785
Author: julio <julio at julio-desktop.(none)>
Date:   Thu Jul 15 01:48:01 2010 -0500

    Players have their functions... not included now in compilation.

diff --git a/src/graphs.c b/src/graphs.c
index 0a50fb9..817d706 100644
--- a/src/graphs.c
+++ b/src/graphs.c
@@ -18,6 +18,7 @@
 #include "players.h"
 
 static int gmaps_alloc(int xsize, int ysize, int maps);
+static void gmaps_free(int xsize, int ysize, int maps);
 
 //gmaps is a tree dimensional array og gnode's, each 
 //gnode must be linked with their niehboors.
@@ -47,12 +48,24 @@ static int gmaps_alloc(int xsize, int ysize, int maps)
                 printf("Error: Allocation of objects faild!\n");
                 return 1; 
             }
-
         }
     }
     return 0;
 }
 
+static void gmaps_free(int xsize, int ysize, int maps)
+{
+    int i, j;
+    for(i = 0; i < maps; i++)
+    {
+        for(j = 0; j < xsize; j++)
+        {
+            FREE(gmaps[i][j]);
+        }
+        FREE(gmaps[i]);
+    }
+}
+
 int create_gmaps(int players)
 {
     int i,j,k,l;
@@ -82,13 +95,23 @@ int create_gmaps(int players)
                     point.y = k;
                     vector = get_vector(point, l);
                     if(vector.x != -2 && vector.y != -2)
+                    {
                         gmaps[i][j][k].nodes[l] = &gmaps[0][j+vector.x][k+vector.y];
+                    }
                     else
-                        gmaps[i][j][k].nodes[l] = NULL; 
+                    {
+                        gmaps[i][j][k].nodes[l] = NULL;
+                    }
                     if(i > 0)
+                    {
                         gmaps[i][j][k].visible = 1;
+                        gmaps[i][j][k].explored = 1;
+                    }
                     else
+                    {
                         gmaps[i][j][k].visible = 0;
+                        gmaps[i][j][k].explored = 0;
+                    }
                 }
                 gmaps[i][j][k].id = count;
             }
@@ -96,26 +119,22 @@ int create_gmaps(int players)
     }
 }
 
-    
-
-
-
-
-
-
-void cleanup_gmaps(int maps, int xsize)
+static void gmaps_free(int xsize, int ysize, int maps)
 {
-    int i,j;
+    int i, j;
     for(i = 0; i < maps; i++)
     {
         for(j = 0; j < xsize; j++)
         {
             FREE(gmaps[i][j]);
         }
+        FREE(gmaps[i]);
     }
 }
 
-
-
+void clean_gmaps(int players)
+{
+   gmaps_free(x_tildes, y_tildes, players);
+}
 
 
diff --git a/src/graphs.h b/src/graphs.h
index 2c7b349..addf227 100644
--- a/src/graphs.h
+++ b/src/graphs.h
@@ -33,6 +33,8 @@ typedef struct gnode{
     int id;
     int anchor_x, anchor_y; //Anchors in main map surface.
     int visible;
+    int explored;
+    int usable;
     struct gnode *nodes[8];
     th_obj *object;
     int terrain;
@@ -46,4 +48,11 @@ gnode ***gmaps;
 //This function uses **map as reference and x_size y_size
 int create_gmaps(int players);
 
+int init_gmaps(void);
+
+int update_gmaps(void);
+
+// Use this function to cleanup after a game.
+void clean_gmaps(int players);
+
 #endif GRAPHS_H
diff --git a/src/map.c b/src/map.c
index 6bb2769..26a5d97 100644
--- a/src/map.c
+++ b/src/map.c
@@ -486,8 +486,6 @@ static int *get_draw_tilde(int *array, int oe)
                     printf("Error parsing tiles\n");
                     return NULL;
                 }
-                //printf("NUM: %d, %d, %d\n", *(array + i), (NUM_COMPTILDE - 1), 
-                //    *(array + i) * (NUM_COMPTILDE) + j);
                 *(a + i) = *(array + i) * (NUM_COMPTILDE) + j;
             }
             else
diff --git a/src/players.c b/src/players.c
index e9e923b..8a527e9 100644
--- a/src/players.c
+++ b/src/players.c
@@ -1,11 +1,69 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "globals.h"
 #include "players.h"
+#include "graph.h"
+
+static int players_alloc(int players);
+
+static int players_alloc(int players)
+{
+    player = malloc(players * sizeof(int));
+    if(player == NULL)
+    {
+        printf("players_alloc: Couldn't allocate memory for palyer\n");
+        return 1;
+    }
+    return 0;
+}
 
-static int players_alloc();
-int init_players(num_players)
+int init_players(int players)
 {
-    num_of_players = num_players;
+    num_of_players = players;
     if(players_alloc(num_of_players))
+    {
         return 1;
+    }
+    last_player = -1;
     return 0;
 }
+int add_player(char *name, int civ, int max_pop, int stone, 
+                int wood, int food, int gold, th_point pos)
+{
+    last_payer++;
+    if(last_player > num_of_players)
+    {
+        printf("add_player(): player out of limit\n");
+        return 1;
+    }
+    if(strlen(name) > NAME_LEN)
+    {
+        printf("add_player(): Players name too large, plese choose another");
+        return 1;
+    }
+    (void) strcpy(player[last_player].name, name);
+    player[last_player].civ = civ;
+    player[last_player].max_pop = max_pop;
+    player[last_player].stone = stone;
+    player[last_player].wood = wood;
+    player[last_player].food = food;
+    player[last_player].gold = gold;
+    player[last_player].pop = 0;
+    player[last_player].player_num = last_player;
+    if(gmap == NULL)
+    {
+        printf("add_player(): gmap isn't allocated, cant giva a position in map to player!\n");
+        return 1;
+    }
+    player[last_player].pos = &gmap[0][point.x][point.y];
+
+    return 0;
+}   
+
 
+void clean_players(void)
+{
+    FREE(player);
+}
diff --git a/src/players.h b/src/players.h
index 5b1933d..c4155fc 100644
--- a/src/players.h
+++ b/src/players.h
@@ -1,18 +1,33 @@
 #ifndef PLAYERS_H
 #define PLAYERS_H
 
+#include "globals.h"
 #include "graphs.h"
 
-typedef struct players{
-    char name[50];
+#define NAME_LEN 50
+
+typedef struct th_players{
+    char name[NAME_LEN];
     int player_num;
     int civ;
     int max_pop;
+    int pop;
+    int stone;
+    int wood;
+    int food;
+    int gold;
     gnode *pos;
-}players;
+}th_players;
 
 int num_of_players;
+int last_player;
+th_players *player;
+
+int init_players(int players);
+int add_player(char *name, int civ, int max_pop, int stone, 
+                int wood, int food, int gold, th_point pos);
+void clean_players(int);
+
 
-players *player;
 
 #endif
diff --git a/src/tuxrts.c b/src/tuxrts.c
new file mode 100644
index 0000000..07359e2
--- /dev/null
+++ b/src/tuxrts.c
@@ -0,0 +1,25 @@
+#include "tuxrts.h"
+#include "loaders.h"
+#include "graphs.h"
+
+int tuxrts_mapinit(char *map_name, th_players *players)
+{
+    fp = LoadMap("map");
+    if(fp == NULL)
+    {
+        DEBUGMSG(debug_game, "File not found!");
+        return 1;
+    }
+
+    
+    if(map_xml(fp))
+    {
+        printf("Error parsing file!");
+        DEBUGMSG(debug_game, "Error loading the map file.\n");
+        return 1;
+    }
+
+    generate_map();
+    return 0;
+}
+
diff --git a/src/tuxrts.h b/src/tuxrts.h
new file mode 100644
index 0000000..7e8c970
--- /dev/null
+++ b/src/tuxrts.h
@@ -0,0 +1,13 @@
+#ifndef TUXRTS_H
+#define TUXRTS_H
+
+#include "map.h"
+
+/* tuxrts_mapinit(): Inizialize all map vars. This is
+ * the fisrt function to call when we begin the game.*/
+
+int tuxrts_init(char *map_name, th_player *players);
+
+void tuxrts_cleanup(void);
+
+#endif

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list