[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. dee9b14bdc68ee43bd3bed4da5598788c3f60553
julio (none)
julio at julio-desktop.
Mon Aug 9 05:20:25 UTC 2010
The following commit has been merged in the master branch:
commit dee9b14bdc68ee43bd3bed4da5598788c3f60553
Author: julio <julio at julio-desktop.(none)>
Date: Mon Aug 9 00:19:48 2010 -0500
More interactions between objects
diff --git a/data/images/others/Makefile.am b/data/images/others/Makefile.am
index aae53fa..52337c4 100644
--- a/data/images/others/Makefile.am
+++ b/data/images/others/Makefile.am
@@ -9,4 +9,5 @@ select.png \
go.png \
novisible.png \
explored.png \
+used_forest.png \
wrong.png
diff --git a/data/images/others/used_forest.png b/data/images/others/used_forest.png
new file mode 100644
index 0000000..1fa7050
Binary files /dev/null and b/data/images/others/used_forest.png differ
diff --git a/data/maps/map.xml b/data/maps/map.xml
index 16562be..3ee387e 100644
--- a/data/maps/map.xml
+++ b/data/maps/map.xml
@@ -705,7 +705,7 @@
<tilde>
<height>1</height>
<terrain>GRASSLAND</terrain>
- <object></object>
+ <object player=1>VILLAGE_CENTER</object>
<unit></unit>
<building></building>
</tilde>
@@ -718,21 +718,21 @@
</tilde>
<tilde>
<height>1</height>
- <terrain>SWAMP</terrain>
+ <terrain>SAVANNAH</terrain>
<object></object>
<unit></unit>
<building></building>
</tilde> <tilde>
<height>0</height>
- <terrain>OCEAN</terrain>
- <object></object>
+ <terrain>SAVANNAH</terrain>
+ <object player=1>VILLAGER_MILKMAID</object>
<unit></unit>
<building></building>
</tilde>
<tilde>
<height>1</height>
<terrain>GRASSLAND</terrain>
- <object></object>
+ <object>FOREST_TROPICAL</object>
<unit></unit>
<building></building>
</tilde>
@@ -953,14 +953,14 @@
</tilde> i
<tilde>
<height>0</height>
- <terrain>OCEAN</terrain>
+ <terrain>DESERT</terrain>
<object></object>
<unit></unit>
<building></building>
</tilde>
<tilde>
<height>1</height>
- <terrain>GRASSLAND</terrain>
+ <terrain>DESERT</terrain>
<object></object>
<unit></unit>
<building></building>
@@ -1068,7 +1068,7 @@
<building></building>
</tilde> <tilde>
<height>0</height>
- <terrain>OCEAN</terrain>
+ <terrain>DESERT</terrain>
<object></object>
<unit></unit>
<building></building>
diff --git a/data/objects/objects.xml b/data/objects/objects.xml
index b26e35d..420aea8 100644
--- a/data/objects/objects.xml
+++ b/data/objects/objects.xml
@@ -58,5 +58,27 @@
<attack>0</attack>
<move>0</move>
</object>
+ <object>
+ <type>BUILDING</type>
+ <name>HUT</name>
+ <rname>Hut</rname>
+ <description>Bulid houses to increment population limit</description>
+ <live>25</live>
+ <vision>1</vision>
+ <defence>0</defence>
+ <attack>0</attack>
+ <move>0</move>
+ </object>
+ <object>
+ <type>BUILDING</type>
+ <name>VILLAGE_CENTER</name>
+ <rname>Center</rname>
+ <description>This building can create villagers and you can store resources here</description>
+ <live>200</live>
+ <vision>3</vision>
+ <defence>0</defence>
+ <attack>0</attack>
+ <move>0</move>
+ </object>
</data>
diff --git a/src/ai.c b/src/ai.c
index 0aa0447..71a6bcc 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -300,6 +300,7 @@ 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;
+ printf("State Modified from %d to %d!\n",object->state.old_state,object->state.state );
return 1;
}
printf("Not a valid player to modify objects state!");
@@ -310,14 +311,63 @@ static int ai_is_tile_free(th_point point)
return 0;
}
+static int ai_close_obj(th_obj *obj1, th_obj *obj2)
+{
+ int l;
+ th_point point;
+ th_vector vector;
+ for(l = 0; l < NUM_DIRS; l++)
+ {
+ vector = get_iso_vector(l);
+ point.x = vector.x;
+ point.y = vector.y;
+ if(obj1->x + point.x == obj2->x &&
+ obj1->y + point.y == obj2->y)
+ {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static th_point ai_find_closest_center(th_point point)
+{
+ th_point lowest;
+ list_node *node;
+
+ lowest.x = -1;
+ lowest.y = -1;
+
+ node = list_nodes;
+ do{
+ if(node->obj.name_enum == VILLAGE_CENTER)
+ {
+ if( HDIST(point.x, point.y, node->obj.x, node->obj.y) <
+ HDIST(point.x, point.y, lowest.x, lowest.y))
+ {
+ lowest.x = node->obj.x;
+ lowest.y = node->obj.y;
+ }
+ }
+ node = node->next;
+ }while(node);
+ return lowest;
+}
+
+
+// ai_state_update modifies the values of all objects if they change their
+// state.
int ai_state_update(list_node *node)
{
+ int tmp;
+ th_point tmp_point, point;
if(!node)
return 0;
do{
if(node->obj.state.flag)
{
+ //printf("Enter to process state\n");
if(node->obj.state.state == GOTO)
{
node->obj.state.path_count = node->obj.state.path->size;
@@ -354,6 +404,16 @@ int ai_state_update(list_node *node)
node->obj.state.action_againts = 0;
node->obj.state.path_flag = 1;
}
+ if(node->obj.state.state == STORE)
+ {
+ printf("Go to store resources!\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.agains_flag)
@@ -361,18 +421,13 @@ int ai_state_update(list_node *node)
}
if(node->obj.state.path_flag)
{
+ //printf("path flag is on!\n");
node->obj.state.count++;
if(node->obj.state.count > 10)
{
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,
@@ -384,8 +439,137 @@ int ai_state_update(list_node *node)
if(node->obj.state.state == GOTO)
{
ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ node->obj.state.path_flag = 0;
+ }
+ else
+ {
+ node->obj.state.path_flag = 0;
+ node->obj.state.count = 0;
+ }
+ ai_free_path(node->obj.state.path);
+ }
+ }
+ }
+ else
+ {
+ if(node->obj.state.state == ATTACK)
+ {
+ //printf("Attacking 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;
+ printf("%s attacking %s, %s live is %d\n", node->obj.rname,
+ node->obj.state.target_obj->rname,
+ node->obj.state.target_obj->rname,
+ node->obj.state.target_obj->actual_live);
+ node->obj.state.target_obj->state.action_againts = ATTACK;
+ node->obj.state.target_obj->state.agains_flag = 1;
+ tmp = node->obj.attack - node->obj.state.target_obj->defence;
+ if(tmp > 0)
+ node->obj.state.target_obj->live = node->obj.state.target_obj->actual_live - tmp;
+ else
+ node->obj.state.target_obj->live = node->obj.state.target_obj->actual_live - 1;
+ }
+ }
+ else
+ {
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ node->obj.state.target_obj = NULL;
+ node->obj.state.count = 0;
+ }
+ }
+ if(node->obj.state.state == USE)
+ {
+ //printf("Using 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 = USE;
+ node->obj.state.target_obj->state.agains_flag = 1;
+ tmp = node->obj.attack;// - node->obj.state.target_obj->defence;
+ node->obj.state.target_obj->actual_live = node->obj.state.target_obj->actual_live - tmp;
+ node->obj.state.carrying = node->obj.state.carrying + tmp;
+ if(node->obj.state.target_obj->type == FOREST)
+ node->obj.state.resource_type = REC_WOOD;
+ if(node->obj.state.target_obj->type == GOLD)
+ node->obj.state.resource_type = REC_GOLD;
+ if(node->obj.state.target_obj->type == STONE)
+ node->obj.state.resource_type = REC_STONE;
+ printf("%s using %s, %s live is %d\n", node->obj.rname,
+ node->obj.state.target_obj->rname,
+ node->obj.state.target_obj->rname,
+ node->obj.state.target_obj->actual_live);
+ if(node->obj.state.carrying > 50)
+ {
+ tmp_point.x = node->obj.x;
+ tmp_point.y = node->obj.y;
+ point = ai_find_closest_center(tmp_point);
+ printf("Closest center al (%d, %d)\n", point.x, point.y);
+ rts_goto(&(node->obj), point);
+ node = node->next;
+ continue;
+ }
}
- //ai_free_path(node->obj.state.path);
+ }
+ else
+ {
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ node->obj.state.target_obj = NULL;
+ node->obj.state.count = 0;
+ }
+ }
+ if(node->obj.state.state == STORE)
+ {
+ if(ai_close_obj(&(node->obj), node->obj.state.target_obj))
+ {
+ if(node->obj.state.carrying > 0)
+ {
+ if(node->obj.state.resource_type == REC_WOOD)
+ player_vars[node->obj.player].wood += node->obj.state.carrying;
+ else if(node->obj.state.resource_type == REC_FOOD)
+ player_vars[node->obj.player].food += node->obj.state.carrying;
+ else if(node->obj.state.resource_type == REC_GOLD)
+ player_vars[node->obj.player].gold += node->obj.state.carrying;
+ else if(node->obj.state.resource_type == REC_STONE)
+ player_vars[node->obj.player].stone += node->obj.state.carrying;
+
+ printf("Player %d have now WOOD %d, FOOD %d, STONE %d, GOLD %d\n",
+ node->obj.player,
+ player_vars[node->obj.player].wood,
+ player_vars[node->obj.player].food,
+ player_vars[node->obj.player].stone,
+ player_vars[node->obj.player].gold);
+
+ node->obj.state.carrying = 0;
+ node->obj.state.resource_type = REC_NONE;
+
+ if(node->obj.state.rec_point_flag)
+ {
+ rts_goto(&(node->obj), node->obj.state.rec_point);
+ }
+ else
+ {
+ node->obj.state.rec_point_flag = 0;
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ }
+ }
+ else
+ {
+ node->obj.state.rec_point_flag = 0;
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ }
+ }
+ else
+ {
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ node->obj.state.target_obj = NULL;
+ node->obj.state.count = 0;
}
}
}
diff --git a/src/fileops.h b/src/fileops.h
index a48f00b..5eef3bc 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -374,6 +374,7 @@ enum{
FOREST_WETLAND,
FOREST_RAIN,
FOREST_BROADLEAF,
+ FOREST_USED,
VILLAGER_MILKMAID,
HOUSE,
HUT,
diff --git a/src/fileops_media.c b/src/fileops_media.c
index 5c03bb4..1a03cfd 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -308,6 +308,7 @@ int load_image_data()
"forest/wetland.png",
"forest/rain.png",
"forest/broadleaf.png",
+ "others/used_forest.png",
"units/milkmaid.png",
"buildings/villagehouse.png",
"buildings/hut.png",
diff --git a/src/game.c b/src/game.c
index 273a5e6..1a68407 100644
--- a/src/game.c
+++ b/src/game.c
@@ -322,8 +322,9 @@ static void draw_unexplored(int player, th_point point)
static void game_draw(int player)
{
SDL_Rect dest;
+ SDL_Rect dest2;
list_node *obj_node;
- char tmp_text[50];
+ char tmp_text[100];
th_point point;
th_point dest_point;
th_point tmp_point;
@@ -372,7 +373,11 @@ static void game_draw(int player)
origin.x - objects[obj_node->obj.name_enum]->w/2;
dest.y = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y -
origin.y - objects[obj_node->obj.name_enum]->h/2;
- SDL_BlitSurface(objects[obj_node->obj.name_enum], NULL, screen, &dest);
+ 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 the any object selected?
if(selection.selected_num != -1)
@@ -393,8 +398,8 @@ static void game_draw(int player)
}while(obj_node != NULL);
}
// User interaction
- if(io.select_rect_dest.x != -1 && io.select_rect_dest.y != -1)
- SDL_BlitSurface(images[IMG_ISOSELECT], NULL, screen, &io.select_rect_dest);
+ //if(io.select_rect_dest.x != -1 && io.select_rect_dest.y != -1)
+ // SDL_BlitSurface(images[IMG_ISOSELECT], NULL, screen, &io.select_rect_dest);
if((io.go_rect.x != -1 && io.go_rect.y != -1) &&
io.go_valid_flag == 1 && io.go_rect_dest.x != -1)
@@ -446,7 +451,23 @@ unexp_draw:
/*Third layer: User Interface*/
//TODO: Write a panel function to manipulate the game...
-
+ dest2.x = 0;
+ dest2.y = 0;//(screen->h / 20) * 19;
+ dest2.h = screen->h / 20;
+ dest2.w = images[IMG_GUIBG_BYZANTINE]->w;
+
+ dest.x = 0;
+ dest.y = 0;
+
+ SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], &dest2, screen, &dest);
+ sprintf(tmp_text,"Wood %5d Food %5d Stone %5d Gold %5d ",
+ player_vars[1].wood,
+ player_vars[1].food,
+ player_vars[1].stone,
+ player_vars[1].gold);
+
+ th_ShowMessage(tmp_text, 16, dest.x+2, dest.y+2);
+
dest.x = 0;
dest.y = (screen->h / 5) * 4;
SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], NULL, screen, &dest);
diff --git a/src/map.c b/src/map.c
index bffad15..e73397d 100644
--- a/src/map.c
+++ b/src/map.c
@@ -37,7 +37,6 @@ static int init_map_hash(void);
static void end_map_hash(void);
static int get_terrain_enum(char *);
static int *get_context_tildes(int, int);
-static th_vector get_iso_vector(int dir);
static int *get_draw_tilde(int *, int);
static int get_tile_num(int, int);
static void str_upper(char *);
@@ -370,7 +369,7 @@ static int *get_context_tildes(int x, int y)
// Returns a th_vector that contains a vector
// representing the tile walking of a isometric
// direction
-static th_vector get_iso_vector(int dir)
+th_vector get_iso_vector(int dir)
{
th_vector vector;
if(dir == ISO_NW)
diff --git a/src/map.h b/src/map.h
index 704c284..7939b60 100644
--- a/src/map.h
+++ b/src/map.h
@@ -62,7 +62,7 @@ void free_map(void);
void th_draw_map(void);
-
+th_vector get_iso_vector(int dir);
th_vector get_vector(th_point point, int iso_dir);
int generate_anchormap(void);
diff --git a/src/objects.c b/src/objects.c
index b897295..88481ad 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -12,7 +12,7 @@ static int init_obj_hash(void);
static int init_obj_hash(void)
{
- obj_table_hash = make_hashtable(hashtable_default_hash, NUM_OBJECTS+NUM_OF_TYPES);
+ obj_table_hash = make_hashtable(hashtable_default_hash, NUM_OBJECTS+NUM_OF_TYPES+1);
if(obj_table_hash == NULL)
return 1;
@@ -66,6 +66,8 @@ int objects_xml(FILE *fp)
printf("To many objects, the limit is %d", MAX_DEF_OBJECTS);
return 1;
}
+
+ object[i].vision_range = 0;
node = mxmlFindElement(inode, inode, "type",
NULL, NULL, MXML_DESCEND);
if(node != NULL)
@@ -239,7 +241,11 @@ int objects_xml(FILE *fp)
object[i].state.carrying = 0;
object[i].state.resource_type = REC_NONE;
object[i].state.target_obj = NULL;
-
+ object[i].state.target_point.x = 0;
+ object[i].state.target_point.y = 0;
+ object[i].state.rec_point_flag = 0;
+ object[i].state.rec_point.x = 0;
+ object[i].state.rec_point.y = 0;
/* Debug: print the values of current object */
printf("%d %s:%d(%s) %s lives: %d, def: %d, att: %d, mov: %d\n",
diff --git a/src/objects.h b/src/objects.h
index 92f4dc6..7ddc357 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -22,6 +22,7 @@ enum{
GOTO,
USE,
DIE,
+ STORE,
NUM_OF_STATES
};
@@ -48,9 +49,10 @@ typedef struct th_state{
int resource_type;
struct th_obj *target_obj;
th_point target_point;
+ th_point rec_point;
+ int rec_point_flag;
}th_state;
-
typedef struct th_obj{
int id;
int x, y; // (x,y) in the gmaps array
diff --git a/src/players.c b/src/players.c
index 63986c9..46a37c4 100644
--- a/src/players.c
+++ b/src/players.c
@@ -10,8 +10,8 @@ static int players_alloc(int players);
static int players_alloc(int players)
{
- player = malloc((1 + players) * sizeof(th_players));
- if(player == NULL)
+ player_vars = malloc((1 + players) * sizeof(th_players));
+ if(player_vars == NULL)
{
printf("players_alloc: Couldn't allocate memory for palyer\n");
return 1;
@@ -54,15 +54,15 @@ int add_player(char *name, int civ, int max_pop, int stone,
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;
+ (void) strcpy(player_vars[last_player].name, name);
+ player_vars[last_player].civ = civ;
+ player_vars[last_player].max_pop = max_pop;
+ player_vars[last_player].stone = stone;
+ player_vars[last_player].wood = wood;
+ player_vars[last_player].food = food;
+ player_vars[last_player].gold = gold;
+ player_vars[last_player].pop = 0;
+ player_vars[last_player].player_num = last_player;
/*if(gmaps == NULL)
{
printf("add_player(): gmaps isn't allocated, cant giva a position in map to player!\n");
@@ -76,5 +76,5 @@ int add_player(char *name, int civ, int max_pop, int stone,
void clean_players(void)
{
- FREE(player);
+ FREE(player_vars);
}
diff --git a/src/players.h b/src/players.h
index 6f2ff8e..57423d4 100644
--- a/src/players.h
+++ b/src/players.h
@@ -28,7 +28,7 @@ typedef struct th_players{
int num_of_players;
int human_player;
int last_player;
-th_players *player;
+th_players *player_vars;
int init_players(int players, int human);
int add_player(char *name, int civ, int max_pop, int stone,
diff --git a/src/tuxrts.c b/src/tuxrts.c
index 9323598..a0d25f8 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -237,7 +237,6 @@ int rts_goto(th_obj *obj, th_point point)
printf("New goal tile: (%d,%d)\n", point.x, point.y);
break;
}
- //printf("Try direcction %d\n", l);
}
}
@@ -258,6 +257,8 @@ int rts_goto(th_obj *obj, th_point point)
node->obj.type == STONE)
{
obj->state.target_point = tmp_point;
+ obj->state.rec_point = tmp_point;
+ obj->state.rec_point_flag = 1;
obj->state.target_obj = &(node->obj);
action = USE;
}
@@ -266,9 +267,19 @@ int rts_goto(th_obj *obj, th_point point)
{
if(node->obj.type == BUILDING)
{
- obj->state.target_point = tmp_point;
- obj->state.target_obj = &(node->obj);
- action = REPAIR;
+ 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
+ {
+ obj->state.target_point = tmp_point;
+ obj->state.target_obj = &(node->obj);
+ action = REPAIR;
+ }
}
}
break;
@@ -276,7 +287,7 @@ int rts_goto(th_obj *obj, th_point point)
node = node->next;
}while(node);
- printf("Chanche %s state: go from (%d,%d) to (%d,%d)\n",
+ printf("Change %s state: go from (%d,%d) to (%d,%d)\n",
obj->rname,
obj->x,
obj->y,
@@ -296,7 +307,7 @@ int rts_goto(th_obj *obj, th_point point)
ai_modify_state(obj->player, obj, action);
- //printf("Path found!\n");
+ printf("Path found!\n");
return 1;
}
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list