[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. f322a52f1b5c5f2a79dff3fce83f8d51ef53cd36
julio (none)
julio at julio-desktop.
Mon Aug 9 00:02:44 UTC 2010
The following commit has been merged in the master branch:
commit f322a52f1b5c5f2a79dff3fce83f8d51ef53cd36
Author: julio <julio at julio-desktop.(none)>
Date: Sun Aug 8 19:01:40 2010 -0500
Move improvements
diff --git a/configure.ac b/configure.ac
index 3ab1a6c..19fc53e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -466,6 +466,7 @@ data/images/status/Makefile
data/images/title/Makefile
data/images/tux/Makefile
data/images/units/Makefile
+data/images/buildings/Makefile
data/images/terrain/Makefile
data/images/terrain/arctic/Makefile
data/images/terrain/desert/Makefile
diff --git a/data/images/Makefile.am b/data/images/Makefile.am
index 9908a56..d36fcf8 100644
--- a/data/images/Makefile.am
+++ b/data/images/Makefile.am
@@ -11,5 +11,6 @@ SUBDIRS = backgrounds \
status \
title \
tux \
- units
+ units \
+ buildings
diff --git a/data/images/buildings/Makefile.am b/data/images/buildings/Makefile.am
new file mode 100644
index 0000000..241530b
--- /dev/null
+++ b/data/images/buildings/Makefile.am
@@ -0,0 +1,9 @@
+## Makefile.am for tuxhistory data/images/buildings:
+
+## Process with AutoMake:
+
+buildingsdir = $(pkgdatadir)/images/buildings
+
+dist_buildings_DATA = villagehouse.png \
+hut.png \
+monolit.png
diff --git a/data/maps/map.xml b/data/maps/map.xml
index b5856ef..16562be 100644
--- a/data/maps/map.xml
+++ b/data/maps/map.xml
@@ -935,9 +935,7 @@
<tilde>
<height>1</height>
<terrain>GRASSLAND</terrain>
- <object></object>
- <unit></unit>
- <building></building>
+ <object player=1>HOUSE</object>
</tilde>
<tilde>
<height>1</height>
@@ -949,10 +947,11 @@
<tilde>
<height>1</height>
<terrain>SWAMP</terrain>
- <object></object>
+ <object player=1>HOUSE</object>
<unit></unit>
<building></building>
- </tilde> <tilde>
+ </tilde> i
+ <tilde>
<height>0</height>
<terrain>OCEAN</terrain>
<object></object>
@@ -976,7 +975,7 @@
<tilde>
<height>1</height>
<terrain>SWAMP</terrain>
- <object></object>
+ <object player=2>HUT</object>
<unit></unit>
<building></building>
</tilde>
diff --git a/data/objects/objects.xml b/data/objects/objects.xml
index ec1cb1c..b26e35d 100644
--- a/data/objects/objects.xml
+++ b/data/objects/objects.xml
@@ -42,10 +42,21 @@
<rname>Vilager</rname>
<description>This unit can create buildings, and recolect resources.</description>
<live>25</live>
- <vision>3</vision>
+ <vision>2</vision>
<defence>1</defence>
<attack>3</attack>
<move>1</move>
</object>
+ <object>
+ <type>BUILDING</type>
+ <name>HOUSE</name>
+ <rname>House</rname>
+ <description>Bulid houses to increment population limit</description>
+ <live>50</live>
+ <vision>2</vision>
+ <defence>0</defence>
+ <attack>0</attack>
+ <move>0</move>
+ </object>
</data>
diff --git a/src/ai.c b/src/ai.c
index d7df36c..0aa0447 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -25,6 +25,11 @@
#include "bheap.h"
#include "hashtable.h"
#include "objects.h"
+#include "fileops.h"
+#include "loaders.h"
+#include "map.h"
+#include "players.h"
+#include "llist.h"
// Hueristic distance between to points
#define HDIST(x1, y1, x2, y2) (((x1<x2)?(x2-x1):(x1-x2) + ((y1<y2)?(y2-y1):(y1-y2)))*10)
@@ -44,6 +49,41 @@ void ai_free(void)
{
lua_close(L);
}
+// Returns 1 if the tile is valid to use for a player, and unit
+// and 0 if not.
+int ai_valid_tile(int player, int unit, th_point coords)
+{
+ list_node *node;
+ th_obj *obj_p;
+ if(coords.x < 0 || coords.x > x_tildes)
+ return 0;
+ if(coords.y < 0 || coords.y > y_tildes)
+ return 0;
+ if(player < 0 || player > num_of_players)
+ return 0;
+
+ //unit_p = list_search(list_nodes, unit);
+
+ if(gmaps[player][coords.x][coords.y].terrain == OCEAN)
+ {
+ return 0;
+ }
+ else if(gmaps[player][coords.x][coords.y].terrain == HIGHSEA)
+ {
+ return 0;
+ }
+
+ //Is a object there?
+ node = list_nodes;
+ do{
+ if(node->obj.x == coords.x && node->obj.y == coords.y)
+ {
+ return 0;
+ }
+ node = node->next;
+ }while(node);
+ return 1;
+}
th_path *ai_shortes_path(int player, int unit, th_point source, th_point goal)
{
@@ -140,7 +180,7 @@ th_path *ai_shortes_path(int player, int unit, th_point source, th_point goal)
while(n->parent)
{
- //printf("(%d,%d)\n",n->point.x, n->point.y);
+ printf("(%d,%d)\n",n->point.x, n->point.y);
solution[i] = n->point;
n = n->parent;
i++;
@@ -168,7 +208,7 @@ th_path *ai_shortes_path(int player, int unit, th_point source, th_point goal)
pt.x = vector.x + n->point.x;
pt.y = vector.y + n->point.y;
- if(rts_valid_tile(player, unit, pt))
+ if(ai_valid_tile(player, unit, pt))
{
//printf("Adding direction %d to open list!\n", a);
@@ -265,6 +305,11 @@ int ai_modify_state(int player, th_obj *object, int state)
printf("Not a valid player to modify objects state!");
return 0;
}
+static int ai_is_tile_free(th_point point)
+{
+ return 0;
+}
+
int ai_state_update(list_node *node)
{
@@ -282,6 +327,33 @@ int ai_state_update(list_node *node)
node->obj.state.action_againts = 0;
node->obj.state.path_flag = 1;
}
+ if(node->obj.state.state == ATTACK)
+ {
+ node->obj.state.path_count = node->obj.state.path->size;
+ node->obj.state.count = 0;
+ node->obj.state.flag = 0;
+ node->obj.state.agains_flag = 0;
+ node->obj.state.action_againts = 0;
+ node->obj.state.path_flag = 1;
+ }
+ if(node->obj.state.state == USE)
+ {
+ node->obj.state.path_count = node->obj.state.path->size;
+ node->obj.state.count = 0;
+ node->obj.state.flag = 0;
+ node->obj.state.agains_flag = 0;
+ node->obj.state.action_againts = 0;
+ node->obj.state.path_flag = 1;
+ }
+ if(node->obj.state.state == REPAIR)
+ {
+ node->obj.state.path_count = node->obj.state.path->size;
+ node->obj.state.count = 0;
+ node->obj.state.flag = 0;
+ node->obj.state.agains_flag = 0;
+ node->obj.state.action_againts = 0;
+ node->obj.state.path_flag = 1;
+ }
node->obj.state.flag = 0;
}
if(node->obj.state.agains_flag)
@@ -295,6 +367,12 @@ int ai_state_update(list_node *node)
node->obj.state.count = 0;
if(node->obj.state.path_count >= 0)
{
+ /*if(gmaps[human_player][node->obj.state.path->path[node->obj.state.path_count].x]
+ [node->obj.state.path->path[node->obj.state.path_count].y].object)
+ {
+ rts_goto(&(node->obj), node->obj.state.path->path[node->obj.state.path->size]);
+ continue;
+ }*/
node->obj.x = node->obj.state.path->path[node->obj.state.path_count].x;
node->obj.y = node->obj.state.path->path[node->obj.state.path_count].y;
printf("Modify path count %d -> (%d,%d)\n", node->obj.state.path_count,
@@ -313,6 +391,5 @@ int ai_state_update(list_node *node)
}
node = node->next;
}while(node != NULL);
- return 1;
}
diff --git a/src/ai.h b/src/ai.h
index 4b31ab0..945607b 100644
--- a/src/ai.h
+++ b/src/ai.h
@@ -33,4 +33,5 @@ int ai_modify_state(int player, th_obj *object, int state);
int ai_state_update(list_node *node);
+int ai_valid_tile(int player, int unit, th_point coords);
#endif
diff --git a/src/fileops.h b/src/fileops.h
index a196c82..a48f00b 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -375,6 +375,9 @@ enum{
FOREST_RAIN,
FOREST_BROADLEAF,
VILLAGER_MILKMAID,
+ HOUSE,
+ HUT,
+ VILLAGE_CENTER,
NUM_OBJECTS // Must be at the end.
};
diff --git a/src/fileops_media.c b/src/fileops_media.c
index bb8b53c..5c03bb4 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -308,7 +308,10 @@ int load_image_data()
"forest/wetland.png",
"forest/rain.png",
"forest/broadleaf.png",
- "units/milkmaid.png"
+ "units/milkmaid.png",
+ "buildings/villagehouse.png",
+ "buildings/hut.png",
+ "buildings/monolit.png"
};
diff --git a/src/objects.c b/src/objects.c
index 47756e1..b897295 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -25,6 +25,9 @@ static int init_obj_hash(void)
hashtable_add(obj_table_hash, "FOREST_WETLAND", FOREST_WETLAND);
hashtable_add(obj_table_hash, "FOREST_RAIN", FOREST_RAIN);
hashtable_add(obj_table_hash, "VILLAGER_MILKMAID", VILLAGER_MILKMAID);
+ hashtable_add(obj_table_hash, "HOUSE", HOUSE);
+ hashtable_add(obj_table_hash, "HUT", HUT);
+ hashtable_add(obj_table_hash, "VILLAGE_CENTER", VILLAGE_CENTER);
hashtable_add(obj_table_hash, "FOREST", FOREST);
hashtable_add(obj_table_hash, "GOLD", GOLD);
diff --git a/src/objects.h b/src/objects.h
index bf6a5fd..92f4dc6 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -47,6 +47,7 @@ typedef struct th_state{
int carrying;
int resource_type;
struct th_obj *target_obj;
+ th_point target_point;
}th_state;
diff --git a/src/players.h b/src/players.h
index 88ec0e5..6f2ff8e 100644
--- a/src/players.h
+++ b/src/players.h
@@ -15,8 +15,9 @@ typedef struct th_players{
char name[NAME_LEN];
int player_num;
int civ;
- int max_pop;
+ int max_pop; // Maximum of slots avaiable.
int pop;
+ int limit_pop; // 4 slots per house
int stone;
int wood;
int food;
diff --git a/src/tuxrts.c b/src/tuxrts.c
index 6aa201b..9323598 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -88,7 +88,7 @@ int tuxrts_init(char *object_name, char *map_name, int players)
// and 0 if not.
int rts_valid_tile(int player, int unit, th_point coords)
{
- list_node *unit_p;
+ list_node *node;
th_obj *obj_p;
if(coords.x < 0 || coords.x > x_tildes)
return 0;
@@ -97,7 +97,7 @@ int rts_valid_tile(int player, int unit, th_point coords)
if(player < 0 || player > num_of_players)
return 0;
- unit_p = list_search(list_nodes, unit);
+ //unit_p = list_search(list_nodes, unit);
if(gmaps[player][coords.x][coords.y].terrain == OCEAN)
{
@@ -107,28 +107,8 @@ int rts_valid_tile(int player, int unit, th_point coords)
{
return 0;
}
- else if(gmaps[player][coords.x][coords.y].object != NULL)
- {
-
- obj_p = rts_get_object(player, coords);
- if(obj_p != NULL)
- {
- if( obj_p->type == FOREST ||
- obj_p->type == GOLD ||
- obj_p->type == STONE)
- return 0;
- else
- return 1;
- }
- else
- {
- return 1;
- }
- }
- else
- {
- return 1;
- }
+
+ return 1;
}
th_obj *rts_get_object(int player, th_point coords)
@@ -221,13 +201,81 @@ int rts_update_game(void)
int rts_goto(th_obj *obj, th_point point)
{
+ list_node *node;
th_path *path;
th_point source;
+ th_point tmp_point;
+ int l;
+ int action;
+
if(!obj)
{
printf("rts_goto error: object invalid!\n");
return 0;
}
+ if(obj->type != UNIT)
+ {
+ return 0;
+ }
+
+ action = GOTO;
+
+ node = list_nodes;
+ do{
+ if(node->obj.x == point.x && node->obj.y == point.y)
+ {
+ tmp_point.x = -1;
+ tmp_point.y = -1;
+ printf("A object is on the goal tile\n");
+ for(l=0; l<NUM_DIRS; l++)
+ {
+ if(gmaps[human_player][point.x][point.y].nodes[l])
+ {
+ if(ai_valid_tile(human_player, 0, gmaps[human_player][point.x][point.y].nodes[l]->point)){
+ tmp_point = point;
+ point = gmaps[human_player][point.x][point.y].nodes[l]->point;
+ printf("New goal tile: (%d,%d)\n", point.x, point.y);
+ break;
+ }
+ //printf("Try direcction %d\n", l);
+ }
+ }
+
+ if(tmp_point.x == -1 && tmp_point.y == -1)
+ return 0;
+
+ printf("Finding a new action!\n");
+ if(node->obj.player != human_player)
+ {
+ if(node->obj.type == BUILDING || node->obj.type == UNIT)
+ {
+ obj->state.target_point = tmp_point;
+ obj->state.target_obj = &(node->obj);
+ action = ATTACK;
+ }
+ else if(node->obj.type == FOREST ||
+ node->obj.type == GOLD ||
+ node->obj.type == STONE)
+ {
+ obj->state.target_point = tmp_point;
+ obj->state.target_obj = &(node->obj);
+ action = USE;
+ }
+ }
+ else
+ {
+ if(node->obj.type == BUILDING)
+ {
+ obj->state.target_point = tmp_point;
+ obj->state.target_obj = &(node->obj);
+ action = REPAIR;
+ }
+ }
+ break;
+ }
+ node = node->next;
+ }while(node);
+
printf("Chanche %s state: go from (%d,%d) to (%d,%d)\n",
obj->rname,
obj->x,
@@ -241,16 +289,16 @@ int rts_goto(th_obj *obj, th_point point)
if(!(path = ai_shortes_path(obj->player,obj->type,source, point)))
{
printf("No shortes path found or a error ocurred!\n");
- return 0;
+ return 1;
}
obj->state.path = path;
- ai_modify_state(obj->player, obj, GOTO);
+ ai_modify_state(obj->player, obj, action);
//printf("Path found!\n");
- return 0;
+ return 1;
}
int rts_build(th_obj *obj, int type, th_point point)
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list