[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 541ddcba4b6b27556e35a37cec8b7b482623ebb6
julio (none)
julio at julio-desktop.
Thu Aug 12 19:32:55 UTC 2010
The following commit has been merged in the master branch:
commit 541ddcba4b6b27556e35a37cec8b7b482623ebb6
Author: julio <julio at julio-desktop.(none)>
Date: Thu Aug 12 14:31:53 2010 -0500
Villagers can now build
diff --git a/data/images/others/Makefile.am b/data/images/others/Makefile.am
index ff6b8ea..361e721 100644
--- a/data/images/others/Makefile.am
+++ b/data/images/others/Makefile.am
@@ -12,4 +12,5 @@ explored.png \
used_forest.png \
gold.png \
stone.png \
-wrong.png
+wrong.png \
+construction.png
diff --git a/data/images/others/construction.png b/data/images/others/construction.png
new file mode 100644
index 0000000..273bf71
Binary files /dev/null and b/data/images/others/construction.png differ
diff --git a/data/objects/objects.xml b/data/objects/objects.xml
index 582dc34..8ef359b 100644
--- a/data/objects/objects.xml
+++ b/data/objects/objects.xml
@@ -8,6 +8,10 @@
<description>Cut this trees and get 375 woods</description>
<live>375</live>
<vision>1</vision>
+ <food>100</food>
+ <wood>100</wood>
+ <gold>0</gold>
+ <stone>0</stone>
</object>
<object>
<type>FOREST</type>
@@ -16,7 +20,11 @@
<description>Cut this trees and get 350 woods</description>
<live>350</live>
<vision>1</vision>
- </object>
+ <food>100</food>
+ <wood>100</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>FOREST</type>
<name>FOREST_SCRUB</name>
@@ -24,7 +32,11 @@
<description>Cut this trees and get 250 woods</description>
<live>250</live>
<vision>1</vision>
- </object>
+ <food>100</food>
+ <wood>100</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>FOREST</type>
<name>FOREST_CONIFER</name>
@@ -32,7 +44,11 @@
<description>Cut this trees and get 400 woods</description>
<live>400</live>
<vision>1</vision>
- </object>
+ <food>100</food>
+ <wood>100</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>FOREST</type>
<name>FOREST_RAIN</name>
@@ -40,7 +56,11 @@
<description>Cut this trees and get 300 woods</description>
<live>300</live>
<vision>1</vision>
- </object>
+ <food>100</food>
+ <wood>100</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>GOLD</type>
<name>REC_GOLD_1</name>
@@ -48,7 +68,11 @@
<description>Get 450 gold</description>
<live>450</live>
<vision>1</vision>
- </object>
+ <food>0</food>
+ <wood>0</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>STONE</type>
<name>REC_STONE_1</name>
@@ -56,7 +80,11 @@
<description>Get 450 Stone</description>
<live>450</live>
<vision>1</vision>
- </object>
+ <food>0</food>
+ <wood>0</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>UNIT</type>
<name>VILLAGER_MILKMAID</name>
@@ -67,7 +95,11 @@
<defence>1</defence>
<attack>3</attack>
<move>1</move>
- </object>
+ <food>50</food>
+ <wood>0</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>BUILDING</type>
<name>HOUSE</name>
@@ -78,7 +110,11 @@
<defence>0</defence>
<attack>0</attack>
<move>0</move>
- </object>
+ <food>0</food>
+ <wood>50</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>BUILDING</type>
<name>HUT</name>
@@ -89,7 +125,11 @@
<defence>0</defence>
<attack>0</attack>
<move>0</move>
- </object>
+ <food>0</food>
+ <wood>50</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>BUILDING</type>
<name>FARM</name>
@@ -100,7 +140,11 @@
<defence>0</defence>
<attack>0</attack>
<move>0</move>
- </object>
+ <food>0</food>
+ <wood>75</wood>
+ <gold>0</gold>
+ <stone>0</stone>
+ </object>
<object>
<type>BUILDING</type>
<name>VILLAGE_CENTER</name>
@@ -111,6 +155,10 @@
<defence>0</defence>
<attack>0</attack>
<move>0</move>
- </object>
+ <food>100</food>
+ <wood>200</wood>
+ <gold>0</gold>
+ <stone>50</stone>
+ </object>
</data>
diff --git a/src/ai.c b/src/ai.c
index 27dd9a1..7566b19 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -300,6 +300,10 @@ int ai_modify_state(int player, th_obj *object, int state)
object->state.old_state = object->state.state;
object->state.state = state;
object->state.flag = 1;
+ if(state == CONSTRUCTION)
+ {
+ object->actual_live = 1;
+ }
printf("State Modified from %d to %d!\n",object->state.old_state,object->state.state );
return 1;
}
@@ -483,7 +487,17 @@ int ai_state_update(list_node *node)
node->obj.state.agains_flag = 0;
node->obj.state.action_againts = 0;
node->obj.state.path_flag = 1;
- }
+ }
+ if(node->obj.state.state == BUILD)
+ {
+ printf("Go to build!\n");
+ 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.state == DIE)
{
@@ -661,7 +675,39 @@ int ai_state_update(list_node *node)
node->obj.state.count = 0;
}
}
+ if(node->obj.state.state == BUILD)
+ {
+ //printf("Building and not walking...\n");
+ if(ai_close_obj(&(node->obj), node->obj.state.target_obj))
+ {
+ node->obj.state.count++;
+ if(node->obj.state.count > 10)
+ {
+ node->obj.state.count = 0;
+ node->obj.state.target_obj->state.action_againts = BUILD;
+ node->obj.state.target_obj->state.agains_flag = 1;
+ tmp = node->obj.attack;
+ node->obj.state.target_obj->actual_live = node->obj.state.target_obj->actual_live + tmp;
+ if(node->obj.state.target_obj->actual_live > node->obj.state.target_obj->live)
+ {
+ node->obj.state.target_obj->actual_live = node->obj.state.target_obj->live;
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ ai_modify_state(node->obj.player, node->obj.state.target_obj, INACTIVE);
+ node->obj.state.target_obj = NULL;
+ node->obj.state.count = 0;
+ }
+ }
+ }
+ else
+ {
+ printf("Not close to the objective!\n");
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ node->obj.state.target_obj = NULL;
+ node->obj.state.count = 0;
+ }
+ }
}
+
if(node->obj.actual_live <= 0)
ai_modify_state(node->obj.player, &(node->obj), DIE);
diff --git a/src/fileops.h b/src/fileops.h
index 6211f08..3fb07c0 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -75,6 +75,7 @@ enum {
IMG_ISOWRONG,
IMG_EXPLORED,
IMG_NOVISIBLE,
+ IMG_CONSTRUCTION,
IMG_GUIBG_BYZANTINE,
IMG_GUIBUILD,
IMG_GUIKILL,
diff --git a/src/fileops_media.c b/src/fileops_media.c
index fe75be4..d93cebd 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -67,6 +67,7 @@ int load_image_data()
"others/wrong.png",
"others/explored.png",
"others/novisible.png",
+ "others/construction.png",
"gui/byzantine.png",
"gui/build.png",
"gui/kill.png",
diff --git a/src/game.c b/src/game.c
index 6353b71..4fab270 100644
--- a/src/game.c
+++ b/src/game.c
@@ -376,11 +376,23 @@ static void game_draw(int player)
origin.x - objects[obj_node->obj.name_enum]->w/2 + panel.panel_game.x;
dest.y = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y -
origin.y - objects[obj_node->obj.name_enum]->h/2 + panel.panel_game.y;
- if(obj_node->obj.actual_live < obj_node->obj.live
+ if(obj_node->obj.state.state == CONSTRUCTION)
+ {
+ dest.x = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x -
+ origin.x - images[IMG_CONSTRUCTION]->w/2 + panel.panel_game.x;
+ dest.y = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y -
+ origin.y - images[IMG_CONSTRUCTION]->h/2 + panel.panel_game.y;
+ SDL_BlitSurface(images[IMG_CONSTRUCTION], NULL, screen, &dest);
+ }
+ else if(obj_node->obj.actual_live < obj_node->obj.live
&& obj_node->obj.type == FOREST)
+ {
SDL_BlitSurface(objects[FOREST_USED], NULL, screen, &dest);
+ }
else
+ {
SDL_BlitSurface(objects[obj_node->obj.name_enum], NULL, screen, &dest);
+ }
}
// Is any object selected?
if(selection.selected_num != -1)
@@ -556,7 +568,7 @@ static void game_handle_mouse(void)
if(io.build_flag >= 0)
{
Pmousemap = mouse_map(io.Plclick, Pscreen);
- //rts_build(selection.selected_objs[0], io.build_flag, Pmousemap);
+ rts_build(selection.selected_objs[0], io.build_flag, Pmousemap);
io.build_flag = -1;
}
else if((io.build_flag = panel_click(&io.Plclick, selection.selected_objs[0])) != -1)
diff --git a/src/objects.c b/src/objects.c
index e9ec837..ceaba16 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -49,7 +49,7 @@ int objects_xml(FILE *fp)
mxml_node_t *node;
mxml_node_t *inode;
- objects_hash = make_hashtable(hashtable_default_hash, 1000);
+ objects_hash = make_hashtable(hashtable_default_hash, NUM_OBJECT_HASH);
if(objects_hash == NULL)
return 1;
@@ -222,7 +222,90 @@ int objects_xml(FILE *fp)
return 1;
}
}
- }
+ node = mxmlFindElement(inode, inode, "food",
+ NULL, NULL, MXML_DESCEND);
+
+ if(node != NULL)
+ {
+ if(atoi(node->child->value.opaque) >= 0)
+ {
+ object[i].cost[REC_FOOD] = atoi(node->child->value.opaque);
+ }
+ else
+ {
+ object[i].cost[REC_WOOD] = -1;
+ printf("objects_xml: Error loading objects description file.\n");
+ return 1;
+ }
+ }
+ else
+ {
+ object[i].cost[REC_FOOD] = 0;
+ }
+
+ node = mxmlFindElement(inode, inode, "wood",
+ NULL, NULL, MXML_DESCEND);
+
+ if(node != NULL)
+ {
+ if(atoi(node->child->value.opaque) >= 0)
+ {
+ object[i].cost[REC_WOOD] = atoi(node->child->value.opaque);
+ }
+ else
+ {
+ object[i].cost[REC_WOOD] = -1;
+ printf("objects_xml: Error loading objects description file.\n");
+ return 1;
+ }
+ }
+ else
+ {
+ object[i].cost[REC_WOOD] = 0;
+ }
+
+ node = mxmlFindElement(inode, inode, "gold",
+ NULL, NULL, MXML_DESCEND);
+
+ if(node != NULL)
+ {
+ if(atoi(node->child->value.opaque) >= 0)
+ {
+ object[i].cost[REC_GOLD] = atoi(node->child->value.opaque);
+ }
+ else
+ {
+ object[i].cost[REC_WOOD] = -1;
+ printf("objects_xml: Error loading objects description file.\n");
+ return 1;
+ }
+ }
+ else
+ {
+ object[i].cost[REC_GOLD] = 0;
+ }
+
+ node = mxmlFindElement(inode, inode, "stone",
+ NULL, NULL, MXML_DESCEND);
+
+ if(node != NULL)
+ {
+ if(atoi(node->child->value.opaque) >= 0)
+ {
+ object[i].cost[REC_STONE] = atoi(node->child->value.opaque);
+ }
+ else
+ {
+ object[i].cost[REC_WOOD] = -1;
+ printf("objects_xml: Error loading objects description file.\n");
+ return 1;
+ }
+ }
+ else
+ {
+ object[i].cost[REC_STONE] = 0;
+ }
+ }
else
{
object[i].defence = -1;
@@ -264,6 +347,7 @@ int objects_xml(FILE *fp)
/* End of debug */
hashtable_add(objects_hash, object[i].name, &object[i]);
+ strcpy(object_names[object[i].name_enum],object[i].name);
i++;
}
diff --git a/src/objects.h b/src/objects.h
index 9b3fa6b..e5f7e59 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -4,6 +4,8 @@
#include "globals.h"
#include "hashtable.h"
+#define NUM_OBJECT_HASH 1000
+
enum{
REC_NONE,
REC_GOLD,
@@ -68,12 +70,14 @@ typedef struct th_obj{
int defence;
int attack;
int move;
+ int cost[NUM_RESOURCES];
int player;
struct th_state state;
}th_obj;
struct hashtable *obj_table_hash; //Strings to enums
struct hashtable *objects_hash; //Names to objects
+char object_names[NUM_OBJECT_HASH][30];
th_obj *object;
int object_counter;
diff --git a/src/tuxrts.c b/src/tuxrts.c
index 48953ba..c19fc9e 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -248,9 +248,17 @@ int rts_goto(th_obj *obj, th_point point)
}
else
{
- if(node->obj.type == BUILDING)
+ if(node->obj.type == BUILDING && obj->name_enum == VILLAGER_MILKMAID)
{
- if(node->obj.name_enum == VILLAGE_CENTER &&
+ if(node->obj.state.state == CONSTRUCTION)
+ {
+ 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 = BUILD;
+ }
+ else if(node->obj.name_enum == VILLAGE_CENTER &&
obj->state.carrying > 0)
{
obj->state.target_point = tmp_point;
@@ -259,7 +267,6 @@ int rts_goto(th_obj *obj, th_point point)
}
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;
@@ -317,6 +324,11 @@ int rts_build(th_obj *obj, int type, th_point point)
int l;
int action;
+ if(type >= NUM_OBJECTS)
+ {
+ printf("I can't build this object, Object not in list!\n");
+ return 0;
+ }
if(!obj)
{
printf("rts_goto error: object invalid!\n");
@@ -327,6 +339,8 @@ int rts_build(th_obj *obj, int type, th_point point)
return 0;
}
+
+
action = BUILD;
node = list_nodes;
@@ -348,74 +362,78 @@ int rts_build(th_obj *obj, int type, th_point point)
if(tmp_point.x == -1 && tmp_point.y == -1)
return 0;
- sprintf(obj_name, "%d", type);
- obj_template = hashtable_lookup(obj_table_hash, obj_name);
+ // Creating new object: Extract the object tempalte from object hash
+ // modify this object and add it to the object list with CONSTRUCTION
+ // state.
+ printf("Searching for object template %s\n", object_names[type]);
+ obj_template = hashtable_lookup(objects_hash, object_names[type]);
if(!obj_template)
return 0;
+ printf("\nObject found, addint object to list.\n");
+
new_obj = *obj_template;
- list_add(&list_nodes, new_obj);
-/*
- printf("Finding a new action!\n");
+ //if(obj->player <= num_of_players)
+ //{
+ if( player_vars[obj->player].wood - new_obj.cost[REC_WOOD] > 0 &&
+ player_vars[obj->player].food - new_obj.cost[REC_FOOD] > 0 &&
+ player_vars[obj->player].gold - new_obj.cost[REC_GOLD] > 0 &&
+ player_vars[obj->player].stone - new_obj.cost[REC_STONE] > 0 )
+ {
+ player_vars[obj->player].wood = player_vars[obj->player].wood - new_obj.cost[REC_WOOD];
+ player_vars[obj->player].food = player_vars[obj->player].food - new_obj.cost[REC_FOOD];
+ player_vars[obj->player].gold = player_vars[obj->player].gold - new_obj.cost[REC_GOLD];
+ player_vars[obj->player].stone = player_vars[obj->player].stone - new_obj.cost[REC_STONE];
+ }
+ else
+ {
+ printf("Not enoght resources! You need wood: %d food: %d gold: %d stone: %d\n",
+ new_obj.cost[REC_WOOD],
+ new_obj.cost[REC_FOOD],
+ new_obj.cost[REC_GOLD],
+ new_obj.cost[REC_STONE]);
+ return 0;
+ }
+ //}
+ new_obj.id = object_counter;
+ new_obj.player = obj->player;
+ new_obj.x = tmp_point.x;
+ new_obj.y = tmp_point.y;
+ ai_modify_state(obj->player, &new_obj, CONSTRUCTION);
+ list_add(&list_nodes, new_obj);
- else
- {
- if(node->obj.type == BUILDING)
- {
- if(node->obj.name_enum == VILLAGE_CENTER &&
- obj->state.carrying > 0)
- {
- obj->state.target_point = tmp_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;
- obj->state.target_obj = &(node->obj);
- action = REPAIR;
- }
- }
- }
- break;
- }
- node = node->next;
- }while(node);
+ object_counter++;
- printf("Change %s state: go from (%d,%d) to (%d,%d)\n",
- obj->rname,
- obj->x,
- obj->y,
- point.x,
- point.y);
+ // Find the shortes path to a close tile, and chanche the object
+ // state to build
source.x = obj->x;
source.y = obj->y;
-
- if(!(path = ai_shortes_path(obj->player,obj->type,source, point)))
+ if(!(path = ai_shortes_path(obj->player,obj->type, source, point)))
{
printf("No shortes path found or a error ocurred!\n");
return 1;
}
-
+
+ node = list_nodes;
+ do{
+ if(node->obj.x == tmp_point.x && node->obj.y == tmp_point.y)
+ {
+ obj_template = &(node->obj);
+ break;
+ }
+ node = node->next;
+ }while(node);
+
+ obj->state.target_point = point;
+ obj->state.target_obj = obj_template;
obj->state.path = path;
ai_modify_state(obj->player, obj, action);
- printf("Path found!\n");
-*/
return 1;
}
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list