[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. ea3ca20e6423303d88f6f2261964eac2311d4604
julio (none)
julio at julio-desktop.
Fri Jul 16 04:42:10 UTC 2010
The following commit has been merged in the master branch:
commit ea3ca20e6423303d88f6f2261964eac2311d4604
Author: julio <julio at julio-desktop.(none)>
Date: Thu Jul 15 23:41:02 2010 -0500
Compiling without errors and now tuxhistory can load the objects description file from XML reading full string lenght in to a hash table.
diff --git a/data/objects/.objects.xml.swp b/data/objects/.objects.xml.swp
new file mode 100644
index 0000000..a304f8d
Binary files /dev/null and b/data/objects/.objects.xml.swp differ
diff --git a/data/objects/Makefile.am b/data/objects/Makefile.am
new file mode 100644
index 0000000..da39dc8
--- /dev/null
+++ b/data/objects/Makefile.am
@@ -0,0 +1,6 @@
+## Makefile.am for tuxhistory data/objects:
+
+## Process with AutoMake:
+objectsdir = $(pkgdatadir)/objects
+
+dist_objects_DATA = objects.xml
diff --git a/data/objects/objects.xml b/data/objects/objects.xml
new file mode 100644
index 0000000..b2770e7
--- /dev/null
+++ b/data/objects/objects.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+
+<data>
+ <object>
+ <type>FOREST</type>
+ <name>FOREST_MIXED</name>
+ <rname>"Mixed Forest"</rname>
+ <description>Cut this trees and get 375 woods</description>
+ <live>375</live>
+ </object>
+ <object>
+ <type>FOREST</type>
+ <name>FOREST_TROPICAL</name>
+ <rname>Tropical forest</rname>
+ <description>Cut this trees and get 350 woods</description>
+ <live>350</live>
+ </object>
+ <object>
+ <type>FOREST</type>
+ <name>FOREST_SCRUB</name>
+ <rname>Scrub Forest</rname>
+ <description>Cut this trees and get 250 woods</description>
+ <live>250</live>
+ </object>
+ <object>
+ <type>FOREST</type>
+ <name>FOREST_CONIFER</name>
+ <rname>Conifer Forest</rname>
+ <description>Cut this trees and get 400 woods</description>
+ <live>400</live>
+ </object>
+ <object>
+ <type>FOREST</type>
+ <name>FOREST_RAIN</name>
+ <rname>Rain Forest</rname>
+ <description>Cut this trees and get 300 woods</description>
+ <live>300</live>
+ </object>
+</data>
+
diff --git a/src/game.c b/src/game.c
index ba194be..e34cda8 100644
--- a/src/game.c
+++ b/src/game.c
@@ -35,6 +35,7 @@
#include "SDL_extras.h"
#include "pixels.h"
#include "map.h"
+#include "objects.h"
#define FPS 15 /* 15 frames per second */
@@ -147,8 +148,27 @@ static int game_init(void)
return 1;
}
+ fp = LoadObj("objects");
+ if(fp == NULL)
+ {
+ DEBUGMSG(debug_game, "File not found!");
+ return 1;
+ }
+ if(objects_xml(fp))
+ {
+ printf("Error parsing file!");
+ DEBUGMSG(debug_game, "Error loading the objects description file.\n");
+ return 1;
+ }
+
+ if(create_gmaps(2))
+ {
+ printf("Couldn't generate grpah mesh!\n");
+ }
generate_map();
+
+
return 0;
}
diff --git a/src/graphs.c b/src/graphs.c
index ddf8bb6..42bdfd7 100644
--- a/src/graphs.c
+++ b/src/graphs.c
@@ -17,6 +17,7 @@
#include "graphs.h"
#include "players.h"
+
static int gmaps_alloc(int xsize, int ysize, int maps);
static void gmaps_free(int xsize, int ysize, int maps);
@@ -25,6 +26,8 @@ static void gmaps_free(int xsize, int ysize, int maps);
static int gmaps_alloc(int xsize, int ysize, int maps)
{
int i,j;
+ xsize++;
+ ysize++;
gmaps = (gnode ***)malloc(maps * sizeof(gnode **));
if(gmaps[i] == NULL)
{
@@ -67,6 +70,7 @@ int create_gmaps(int players)
return 1;
}
+ printf("x_tiles: %d, y_tiles: %d\n", x_tildes, y_tildes);
for(i = 1; i < players; i++)
{
count = 0;
@@ -104,6 +108,7 @@ int create_gmaps(int players)
}
}
}
+ return 0;
}
int update_gmaps(void)
diff --git a/src/graphs.h b/src/graphs.h
index 0406713..79b4ef5 100644
--- a/src/graphs.h
+++ b/src/graphs.h
@@ -15,6 +15,7 @@
#define GRAPHS_H
#include "globals.h"
+#include "objects.h"
#include "map.h"
enum
@@ -56,4 +57,4 @@ int update_gmaps(void);
// Use this function to cleanup after a game.
void clean_gmaps(int players);
-#endif GRAPHS_H
+#endif
diff --git a/src/map.c b/src/map.c
index 7b411a3..2d8fd9e 100644
--- a/src/map.c
+++ b/src/map.c
@@ -40,8 +40,6 @@ static void str_upper(char *);
static int init_map_hash(void)
{
- th_obj object_types[NUM_OF_TYPES];
-
map_table_hash = make_hashtable(hashtable_default_hash, 30);
if(map_table_hash == NULL)
@@ -140,7 +138,7 @@ int map_xml(FILE *fp)
{
if(node->child->value.text.string)
printf("(%s", node->child->value.text.string);
- value=hashtable_lookup(map_table_hash, node->child->value.text.string);
+ value=(int)hashtable_lookup(map_table_hash, node->child->value.text.string);
if(value!=-1)
{
printf(" Hash object: %d) ", value);
@@ -205,7 +203,6 @@ int map_xml(FILE *fp)
//Return array has 9 elements
static int *get_context_tildes(int x, int y)
{
- int i;
int *a;
a = (int *)malloc(9*sizeof(int));
@@ -376,7 +373,6 @@ static th_vector get_iso_vector(int dir)
th_vector get_vector(th_point point, int iso_dir)
{
- int i;
th_vector vector;
vector = get_iso_vector(iso_dir);
@@ -590,23 +586,20 @@ int generate_map(void)
anchor.x = dest.x + terrain[*img_enums]->w/2;
anchor.y = dest.y + terrain[*img_enums]->h/2;
- gmap[0][i][j].anchor = anchor;
+ gmaps[0][i][j].anchor = anchor;
// TODO: This is better in graph.h
if(map[i][j].terrain == HIGHSEA ||
map[i][j].terrain == OCEAN)
{
- gmap[0][i][j].usable = 0;
+ gmaps[0][i][j].usable = 0;
}
else
{
- gmap[0][i][j].usable = 1;
+ gmaps[0][i][j].usable = 1;
}
- gmap[0][i][j].terrain = map[i][j].terrain;
-
-
-
+ gmaps[0][i][j].terrain = map[i][j].terrain;
//Prepare te new coords for the next tile
dest.x = dest.x - (terrain[*img_enums]->w/2);
diff --git a/src/objects.c b/src/objects.c
index 3ab9e0e..a2eedf0 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -3,6 +3,7 @@
#include<ctype.h>
#include<mxml.h>
+#include "fileops.h"
#include "objects.h"
static int init_obj_hash(void);
@@ -41,7 +42,7 @@ int objects_xml(FILE *fp)
th_obj object;
- tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK);
+ tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
if(init_obj_hash())
return 1;
@@ -51,13 +52,13 @@ int objects_xml(FILE *fp)
inode = mxmlFindElement(inode, tree, "object",
NULL, NULL, MXML_DESCEND))
{
- node = mxmlFindElement(jnode, jnode, "type",
+ node = mxmlFindElement(inode, inode, "type",
NULL, NULL, MXML_DESCEND);
if(node != NULL)
{
if(value != -1)
{
- value = (int)hashtable_lookup(map_table_hash, node->child->value.text.string);
+ value = (int)hashtable_lookup(obj_table_hash, node->child->value.opaque);
object.type = value;
}
}
@@ -68,15 +69,15 @@ int objects_xml(FILE *fp)
return 1;
}
- node = mxmlFindElement(jnode, jnode, "name",
+ node = mxmlFindElement(inode, inode, "name",
NULL, NULL, MXML_DESCEND);
if(node != NULL)
{
- value = (int)hashtable_lookup(map_table_hash, node->child->value.text.string);
+ value = (int)hashtable_lookup(obj_table_hash, node->child->value.opaque);
if(value != -1)
{
object.name_enum = value;
- strcpy(object.name, node->child->value.text.string);
+ strcpy(object.name, node->child->value.opaque);
}
}
else
@@ -86,11 +87,11 @@ int objects_xml(FILE *fp)
return 1;
}
- node = mxmlFindElement(jnode, jnode, "rname",
+ node = mxmlFindElement(inode, inode, "rname",
NULL, NULL, MXML_DESCEND);
if(node != NULL)
{
- strcpy(object.rname, node->child->value.text.string);
+ strcpy(object.rname, node->child->value.opaque);
}
else
{
@@ -98,11 +99,12 @@ int objects_xml(FILE *fp)
printf("objects_xml: Error loading objects description file");
return 1;
}
- node = mxmlFindElement(jnode, jnode, "description",
+ node = mxmlFindElement(inode, inode, "description",
NULL, NULL, MXML_DESCEND);
if(node != NULL)
{
- strcpy(object.description, node->child->value.text.string);
+ strcpy(object.description, node->child->value.opaque);
+ printf(" string: %s\n", node->child->value.opaque);
}
else
{
@@ -111,12 +113,12 @@ int objects_xml(FILE *fp)
return 1;
}
- node = mxmlFindElement(jnode, jnode, "live",
+ node = mxmlFindElement(inode, inode, "live",
NULL, NULL, MXML_DESCEND);
- if(node->child->value.integer >= 0)
+ if(atoi(node->child->value.opaque) >= 0)
{
- object.live = node->child->value.integer;
+ object.live = atoi(node->child->value.opaque);
}
else
{
@@ -132,13 +134,12 @@ int objects_xml(FILE *fp)
object.name_enum,
object.rname,
object.description,
- object.lives);
+ object.live);
}
- free_hashtable(map_table_hash);
+ free_hashtable(obj_table_hash);
- mxmlDelete(jnode);
mxmlDelete(inode);
mxmlDelete(node);
diff --git a/src/players.c b/src/players.c
index bfdd51d..9194d53 100644
--- a/src/players.c
+++ b/src/players.c
@@ -4,7 +4,7 @@
#include "globals.h"
#include "players.h"
-#include "graph.h"
+#include "graphs.h"
static int players_alloc(int players);
@@ -32,7 +32,7 @@ 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)
{
- last_payer++;
+ last_player++;
if(last_player > num_of_players)
{
printf("add_player(): player out of limit\n");
@@ -52,12 +52,12 @@ int add_player(char *name, int civ, int max_pop, int stone,
player[last_player].gold = gold;
player[last_player].pop = 0;
player[last_player].player_num = last_player;
- if(gmap == NULL)
+ if(gmaps == NULL)
{
- printf("add_player(): gmap isn't allocated, cant giva a position in map to player!\n");
+ printf("add_player(): gmaps isn't allocated, cant giva a position in map to player!\n");
return 1;
}
- player[last_player].pos = &gmap[0][pos.x][pos.y];
+ player[last_player].pos = &gmaps[0][pos.x][pos.y];
return 0;
}
diff --git a/src/players.h b/src/players.h
index c4155fc..8427511 100644
--- a/src/players.h
+++ b/src/players.h
@@ -25,8 +25,8 @@ 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);
+ int wood, int food, int gold, th_point pos);
+void clean_players(void);
diff --git a/src/tuxhistory.h b/src/tuxhistory.h
index c763cbf..f6ac8c3 100644
--- a/src/tuxhistory.h
+++ b/src/tuxhistory.h
@@ -15,8 +15,6 @@
(briefly - GNU GPL v2 or later)
*/
-
-
#ifndef TUXHISTORY_H
#define TUXHISTORY_H
@@ -30,6 +28,7 @@
#endif
#include "map.h"
+#include "objects.h"
#define MAX_SPRITE_FRAMES 30
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list