[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 0af747a6bc7c62ec74702069aab78d09c421bbfc
julio (none)
julio at julio-desktop.
Fri Aug 13 02:09:57 UTC 2010
The following commit has been merged in the master branch:
commit 0af747a6bc7c62ec74702069aab78d09c421bbfc
Author: julio <julio at julio-desktop.(none)>
Date: Thu Aug 12 21:08:57 2010 -0500
Buildings can now generate units, and a population and population limit mechanism is implemented. Also some bugs are fixed.
diff --git a/data/images/buildings/farm_new.png b/data/images/buildings/farm_new.png
new file mode 100644
index 0000000..374d66b
Binary files /dev/null and b/data/images/buildings/farm_new.png differ
diff --git a/data/images/others/pawn.png b/data/images/others/pawn.png
new file mode 100644
index 0000000..f0b701e
Binary files /dev/null and b/data/images/others/pawn.png differ
diff --git a/data/images/others/ska.png b/data/images/others/ska.png
new file mode 100644
index 0000000..a958ee6
Binary files /dev/null and b/data/images/others/ska.png differ
diff --git a/data/images/others/stop.png b/data/images/others/stop.png
new file mode 100644
index 0000000..3cb139e
Binary files /dev/null and b/data/images/others/stop.png differ
diff --git a/src/ai.c b/src/ai.c
index 7566b19..7acca58 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -304,7 +304,7 @@ int ai_modify_state(int player, th_obj *object, int state)
{
object->actual_live = 1;
}
- printf("State Modified from %d to %d!\n",object->state.old_state,object->state.state );
+ //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!");
@@ -314,8 +314,10 @@ static int ai_kill_object(list_node *node)
{
list_node *iter_node;
iter_node = list_nodes;
- do{
+ if(!node)
+ return 0;
+ do{
if(&(iter_node->obj) == node->obj.state.target_obj)
{
node->obj.state.target_obj = NULL;
@@ -325,6 +327,10 @@ static int ai_kill_object(list_node *node)
iter_node = iter_node->next;
}while(iter_node);
+ if(node->obj.type == UNIT)
+ player_vars[node->obj.player].pop--;
+ if(node->obj.name_enum == HOUSE)
+ player_vars[node->obj.player].limit_pop--;
list_remove(&node);
printf("Exito removiendo\n");
return 1;
@@ -390,6 +396,18 @@ th_point ai_alternative_tile(th_point p1, th_point p2)
th_point tmp_point;
prev_hdist = -1;
+ if(p1.x == p2.x && p1.y == p2.y)
+ {
+ for(l=0; l<NUM_DIRS; l++)
+ {
+ if(ai_valid_tile(human_player, 0, gmaps[human_player][p2.x][p2.y].nodes[l]->point))
+ {
+ tmp_point = gmaps[human_player][p2.x][p2.y].nodes[l]->point;
+ printf("Alternative point: (%d, %d)\n", tmp_point.x, tmp_point.y);
+ return tmp_point;
+ }
+ }
+ }
for(l=0; l<NUM_DIRS; l++)
{
if(gmaps[human_player][p2.x][p2.y].nodes[l])
@@ -412,14 +430,7 @@ th_point ai_alternative_tile(th_point p1, th_point p2)
}
}
}
-/* if(prev_hdist == -1)
- {
- for(l=0; l<NUM_DIRS; l++)
- {
- tmp_point = ai_alternative_tile(gmaps[human_player][p2.x][p2.y].nodes[l]->point, p2);
- break;
- }
- }*/
+
printf("Alternative point: (%d, %d)\n", tmp_point.x, tmp_point.y);
return tmp_point;
}
@@ -428,10 +439,15 @@ th_point ai_alternative_tile(th_point p1, th_point p2)
int ai_state_update(list_node *node)
{
+ th_point new_point;
+ th_point tmp_point;
+ th_point point;
+ th_obj *tmp_obj;
+ th_obj new_obj;
list_node *node_tmp;
int tmp;
int i;
- th_point tmp_point, point;
+
if(!node)
return 0;
@@ -498,7 +514,17 @@ int ai_state_update(list_node *node)
node->obj.state.action_againts = 0;
node->obj.state.path_flag = 1;
}
- node->obj.state.flag = 0;
+ if(node->obj.state.state == GENERATE)
+ {
+ printf("Generate object!\n");
+ node->obj.state.path_count = 0;
+ 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 = 0;
+ }
+ node->obj.state.flag = 0;
if(node->obj.state.state == DIE)
{
node_tmp = node->next;
@@ -521,8 +547,8 @@ int ai_state_update(list_node *node)
{
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,
- node->obj.x, node->obj.y);
+ //printf("Modify path count %d -> (%d,%d)\n", node->obj.state.path_count,
+ // node->obj.x, node->obj.y);
node->obj.state.path_count = node->obj.state.path_count - 1;
}
else
@@ -552,17 +578,17 @@ int ai_state_update(list_node *node)
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);
+ //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;
+ node->obj.state.target_obj->actual_live = node->obj.state.target_obj->actual_live - tmp;
else
- node->obj.state.target_obj->live = node->obj.state.target_obj->actual_live - 1;
+ node->obj.state.target_obj->actual_live = node->obj.state.target_obj->actual_live - 1;
}
}
else
@@ -595,10 +621,10 @@ int ai_state_update(list_node *node)
if(node->obj.state.target_obj->name_enum == FARM)
node->obj.state.resource_type = REC_FOOD;
- 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);
+ //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;
@@ -693,8 +719,11 @@ int ai_state_update(list_node *node)
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);
+ if(node->obj.state.target_obj->name_enum == HOUSE)
+ player_vars[node->obj.player].limit_pop += 4;
node->obj.state.target_obj = NULL;
node->obj.state.count = 0;
+
}
}
}
@@ -706,7 +735,40 @@ int ai_state_update(list_node *node)
node->obj.state.count = 0;
}
}
- }
+ if(node->obj.state.state == GENERATE)
+ {
+ //printf("Building and not walking...\n");
+ node->obj.state.count++;
+ if(node->obj.state.count > 10)
+ {
+ node->obj.state.count = 0;
+ node->obj.state.generate_count += 1;
+ if(node->obj.state.generate_count >= node->obj.state.generate_compl)
+ {
+ if(player_vars[node->obj.player].pop <= player_vars[node->obj.player].limit_pop)
+ {
+ tmp_obj = hashtable_lookup(objects_hash, object_names[node->obj.state.generate_type]);
+ new_obj = *tmp_obj;
+ tmp_point.x = node->obj.x;
+ tmp_point.y = node->obj.y;
+ new_point = ai_alternative_tile(tmp_point, tmp_point);
+ new_obj.x = new_point.x;
+ new_obj.y = new_point.y;
+ new_obj.player = node->obj.player;
+ new_obj.id = object_names;
+ list_add(list_nodes, new_obj);
+ object_counter++;
+
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ node->obj.state.target_obj = NULL;
+ node->obj.state.count = 0;
+ player_vars[node->obj.player].pop++;
+ }
+
+ }
+ }
+ }
+ }
if(node->obj.actual_live <= 0)
ai_modify_state(node->obj.player, &(node->obj), DIE);
diff --git a/src/game.c b/src/game.c
index 4fab270..d89db80 100644
--- a/src/game.c
+++ b/src/game.c
@@ -43,7 +43,7 @@
#include "panel.h"
-#define FPS 50 /* 15 frames per second */
+#define FPS 40 /* 15 frames per second */
#define MS_PER_FRAME (1000 / FPS)
#define IN_SCROLL 3 // Scroll speed
@@ -452,13 +452,14 @@ static void game_draw(int player)
}
}
- point.x = 0;
- point.y = 0;
+ point.x = screen->w/2;
+ point.y = screen->h/2;
dest_point = mouse_map(point, Pscreen);
// Draw no visible areas black
- if(dest_point.x == -1 || dest_point.y == -1)
+/* if(dest_point.x == -1 || dest_point.y == -1)
{
+ printf("No visible area to draw!\n");
point.x = Pscreen.x + 10;
point.y = Pscreen.y + 10;
dest_point = mouse_map(point, Pscreen);
@@ -481,9 +482,10 @@ static void game_draw(int player)
return;
}
//printf("Init in: (%d,%d)\n", dest_point.x, dest_point.y);
+ */
draw_unexplored(player, dest_point);
-unexp_draw:
+//unexp_draw:
panel_draw(selection.selected_objs[0], selection.selected_num);
@@ -565,6 +567,7 @@ static void game_handle_mouse(void)
{
if(io.mouseclicked_flag != 0)
{
+ // Is a option selected form panel and the origin object is a unit? Then build!
if(io.build_flag >= 0)
{
Pmousemap = mouse_map(io.Plclick, Pscreen);
@@ -573,6 +576,13 @@ static void game_handle_mouse(void)
}
else if((io.build_flag = panel_click(&io.Plclick, selection.selected_objs[0])) != -1)
{
+ // Is the clicked option from a building? Then generate the technologie or the
+ // unit.
+ if(io.build_flag >= 0 && selection.selected_objs[0]->type == BUILDING)
+ {
+ rts_generate(selection.selected_objs[0], io.build_flag);
+ io.build_flag = -1;
+ }
io.mouseclicked_flag = 0;
if(io.build_flag == -3)
selection.selected_objs[0] = NULL;
diff --git a/src/map.c b/src/map.c
index 70ef268..46c2478 100644
--- a/src/map.c
+++ b/src/map.c
@@ -30,6 +30,7 @@
#include "llist.h"
#include "graphs.h"
#include "panel.h"
+#include "players.h"
SDL_Surface* map_image;
SDL_Surface* mini_map_image;
@@ -181,6 +182,14 @@ int map_xml(FILE *fp)
tmp_obj.x = x;
tmp_obj.y = y;
list_add(&list_nodes, tmp_obj);
+ if(tmp_obj.type == UNIT)
+ {
+ player_vars[tmp_obj.player].pop++;
+ }
+ if(tmp_obj.name_enum == HOUSE)
+ {
+ player_vars[tmp_obj.player].limit_pop += 4;
+ }
object_counter++;
}
diff --git a/src/objects.c b/src/objects.c
index ceaba16..ec9904b 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -332,6 +332,10 @@ int objects_xml(FILE *fp)
object[i].state.rec_point_flag = 0;
object[i].state.rec_point.x = 0;
object[i].state.rec_point.y = 0;
+ object[i].state.generate_flag = 0;
+ object[i].state.generate_type = 0;
+ object[i].state.generate_compl = 0;
+ object[i].state.generate_count = 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 e5f7e59..96069e1 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -26,6 +26,7 @@ enum{
DIE,
STORE,
CONSTRUCTION,
+ GENERATE,
NUM_OF_STATES
};
@@ -54,6 +55,10 @@ typedef struct th_state{
th_point target_point;
th_point rec_point;
int rec_point_flag;
+ int generate_flag;
+ int generate_type;
+ int generate_compl;
+ int generate_count;
}th_state;
typedef struct th_obj{
diff --git a/src/panel.c b/src/panel.c
index 4321152..32d02c3 100644
--- a/src/panel.c
+++ b/src/panel.c
@@ -100,8 +100,6 @@ void panel_draw(th_obj *select, int num)
char tmp_text[100];
int menu_y =(screen->h / 5) * 4;
- //TODO: Write a panel function to manipulate the game...
-
rect.x = 0;
rect.y = 0;
rect.w = images[IMG_GUIKILL]->w;
@@ -109,11 +107,13 @@ void panel_draw(th_obj *select, int num)
SDL_BlitSurface(images[IMG_GUIBG_BYZANTINE], &panel.panel_header_dest, screen,
&panel.panel_header_origin);
- sprintf(tmp_text,"Wood %5d Food %5d Stone %5d Gold %5d ",
+ sprintf(tmp_text,"Wood %5d Food %5d Stone %5d Gold %5d Population: %d/%d",
player_vars[1].wood,
player_vars[1].food,
player_vars[1].stone,
- player_vars[1].gold);
+ player_vars[1].gold,
+ player_vars[human_player].pop,
+ player_vars[human_player].limit_pop);
th_ShowMessage(tmp_text, 16, panel.panel_header_dest.x+2, panel.panel_header_dest.y+2);
@@ -163,11 +163,13 @@ void panel_draw(th_obj *select, int num)
panel.panel_actions[4] = DIE;
panel.panel_actions[3] = INACTIVE;
+ panel.panel_actions_obj[3] = -1;
}
else if(select->name_enum == VILLAGE_CENTER)
{
SDL_BlitSurface(images[IMG_GUIPAWN], NULL, screen, &panel.panel_option[0]);
panel.panel_actions[0] = BUILD;
+ panel.panel_actions_obj[0] = VILLAGER_MILKMAID;
SDL_BlitSurface(images[IMG_GUIKILL], NULL, screen, &panel.panel_option[4]);
panel.panel_actions[4] = DIE;
diff --git a/src/players.c b/src/players.c
index 46a37c4..2302bda 100644
--- a/src/players.c
+++ b/src/players.c
@@ -62,6 +62,7 @@ int add_player(char *name, int civ, int max_pop, int stone,
player_vars[last_player].food = food;
player_vars[last_player].gold = gold;
player_vars[last_player].pop = 0;
+ player_vars[last_player].limit_pop = 0;
player_vars[last_player].player_num = last_player;
/*if(gmaps == NULL)
{
diff --git a/src/tuxrts.c b/src/tuxrts.c
index c19fc9e..1fa97c3 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -437,6 +437,52 @@ int rts_build(th_obj *obj, int type, th_point point)
return 1;
}
+// Discover a technologie or create a unit.
+int rts_generate(th_obj *obj, int type)
+{
+ th_obj *tmp_obj;
+
+ tmp_obj = hashtable_lookup(objects_hash, object_names[type]);
+
+ if( player_vars[obj->player].wood - tmp_obj->cost[REC_WOOD] > 0 &&
+ player_vars[obj->player].food - tmp_obj->cost[REC_FOOD] > 0 &&
+ player_vars[obj->player].gold - tmp_obj->cost[REC_GOLD] > 0 &&
+ player_vars[obj->player].stone - tmp_obj->cost[REC_STONE] > 0 )
+ {
+ player_vars[obj->player].wood = player_vars[obj->player].wood - tmp_obj->cost[REC_WOOD];
+ player_vars[obj->player].food = player_vars[obj->player].food - tmp_obj->cost[REC_FOOD];
+ player_vars[obj->player].gold = player_vars[obj->player].gold - tmp_obj->cost[REC_GOLD];
+ player_vars[obj->player].stone = player_vars[obj->player].stone - tmp_obj->cost[REC_STONE];
+ }
+ else
+ {
+ printf("Not enoght resources! You need wood: %d food: %d gold: %d stone: %d\n",
+ tmp_obj->cost[REC_WOOD],
+ tmp_obj->cost[REC_FOOD],
+ tmp_obj->cost[REC_GOLD],
+ tmp_obj->cost[REC_STONE]);
+ return 0;
+ }
+
+ if(obj->state.generate_type != type)
+ {
+ obj->state.generate_type = type;
+ obj->state.generate_flag = 0;
+ obj->state.generate_compl = tmp_obj->live;
+ obj->state.generate_count = 0;
+ }
+ else if(obj->state.generate_flag == 0)
+ {
+ obj->state.generate_type = type;
+ obj->state.generate_flag = 0;
+ obj->state.generate_compl = tmp_obj->live;
+ obj->state.generate_count = 0;
+ }
+ obj->state.generate_flag++;
+ ai_modify_state(obj->player, obj, GENERATE);
+ return 1;
+}
+
int rts_die(th_obj *obj)
{
return 1;
diff --git a/src/tuxrts.h b/src/tuxrts.h
index 4e54033..51ee9ea 100644
--- a/src/tuxrts.h
+++ b/src/tuxrts.h
@@ -68,4 +68,5 @@ int rts_repair(th_obj *obj, th_obj *target, th_point);
int rts_use(th_obj *obj, th_obj *target, th_point point);
+int rts_generate(th_obj *obj, int type);
#endif
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list