[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 2eda5ef2a0741ea737b43cec9b3ed096c8f24320
julio (none)
julio at julio-desktop.
Sun Aug 8 21:35:27 UTC 2010
The following commit has been merged in the master branch:
commit 2eda5ef2a0741ea737b43cec9b3ed096c8f24320
Author: julio <julio at julio-desktop.(none)>
Date: Sun Aug 8 16:34:53 2010 -0500
Units can walk
diff --git a/src/ai.c b/src/ai.c
index 3eb5989..d7df36c 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -136,17 +136,18 @@ th_path *ai_shortes_path(int player, int unit, th_point source, th_point goal)
if(!path)
return NULL;
- i = n->deph - 1;
+ i=0;
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++;
}
path->path = solution;
- path->size = i;
+ path->size = i - 1;
free_hashtable(closed);
bheap_free(open);
@@ -274,12 +275,14 @@ int ai_state_update(list_node *node)
{
if(node->obj.state.state == GOTO)
{
- node->obj.state.count = node->obj.state.path->size;
+ 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)
{
@@ -287,19 +290,25 @@ int ai_state_update(list_node *node)
if(node->obj.state.path_flag)
{
node->obj.state.count++;
- if(node->obj.state.path_count < 0)
+ if(node->obj.state.count > 10)
{
- node->obj.x = node->obj.state.path->path[node->obj.state.path_count].x;
- node->obj.x = node->obj.state.path->path[node->obj.state.path_count].y;
- node->obj.state.path_count--;
- }
- else
- {
- if(node->obj.state.state == GOTO)
+ node->obj.state.count = 0;
+ if(node->obj.state.path_count >= 0)
+ {
+ 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);
+ node->obj.state.path_count = node->obj.state.path_count - 1;
+ }
+ else
{
- ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ if(node->obj.state.state == GOTO)
+ {
+ ai_modify_state(node->obj.player, &(node->obj), INACTIVE);
+ }
+ //ai_free_path(node->obj.state.path);
}
- ai_free_path(node->obj.state.path);
}
}
node = node->next;
diff --git a/src/game.c b/src/game.c
index dced55c..273a5e6 100644
--- a/src/game.c
+++ b/src/game.c
@@ -39,6 +39,7 @@
#include "objects.h"
#include "llist.h"
#include "tuxrts.h"
+#include "ai.h"
#define FPS 50 /* 15 frames per second */
@@ -232,6 +233,8 @@ int game(void)
game_handle_user_events();
game_handle_mouse();
+ ai_state_update(list_nodes);
+
game_status = check_exit_conditions();
game_draw(this_player);
SDL_Flip(screen);
@@ -279,10 +282,16 @@ static void draw_unexplored(int player, th_point point)
//Is the point visible or unexplored? If so plaint!
if(gmaps[player][point.x][point.y].visible == 0)
+ {
if(gmaps[player][point.x][point.y].explored == 1)
+ {
SDL_BlitSurface(images[IMG_EXPLORED], NULL, screen, &dest);
+ }
else
+ {
SDL_BlitSurface(images[IMG_NOVISIBLE], NULL, screen, &dest);
+ }
+ }
gmaps[player][point.x][point.y].drawed = 1;
//Call neighboors to draw!
@@ -317,7 +326,8 @@ static void game_draw(int player)
char tmp_text[50];
th_point point;
th_point dest_point;
-
+ th_point tmp_point;
+ int temp1, temp2, i, j;
origin.x = Pscreen.x;
origin.y = Pscreen.y;
@@ -332,24 +342,13 @@ static void game_draw(int player)
SDL_BlitSurface(map_image, &origin, screen, &dest);
- point.x = 0;
- point.y = 0;
- dest_point = mouse_map(point, Pscreen);
- while(dest_point.x == -1 && dest_point.y == -1)
- {
- point.x = point.x + images[IMG_EXPLORED]->w;
- point.y = point.y + images[IMG_EXPLORED]->h;
- dest_point = mouse_map(point, Pscreen);
- }
- //printf("Init in: (%d,%d)\n", dest_point.x, dest_point.y);
- draw_unexplored(player, dest_point);
-
/*Second layer: objects*/
obj_node = list_nodes;
if(obj_node != NULL)
{
do{
+ // Is the object in the visible screen?
if( gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x > origin.x -
objects[obj_node->obj.name_enum]->w/2&&
gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y > origin.y -
@@ -357,12 +356,24 @@ static void game_draw(int player)
gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x < origin.x + origin.w &&
gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.y < origin.y + origin.w)
{
- dest.x = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x -
- 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);
-
+ // Can the human player see this object?
+ if(gmaps[human_player][obj_node->obj.x][obj_node->obj.y].visible ||
+ (
+ gmaps[human_player][obj_node->obj.x][obj_node->obj.y].explored &&
+ (
+ obj_node->obj.type == FOREST ||
+ obj_node->obj.type == GOLD ||
+ obj_node->obj.type == STONE
+ )
+ )
+ )
+ {
+ dest.x = gmaps[0][obj_node->obj.x][obj_node->obj.y].anchor.x -
+ 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);
+ }
// Is the any object selected?
if(selection.selected_num != -1)
{
@@ -401,6 +412,36 @@ static void game_draw(int player)
}
io.go_valid_flag = 0;
+ point.x = 0;
+ point.y = 0;
+ dest_point = mouse_map(point, Pscreen);
+ if(dest_point.x == -1 || dest_point.y == -1)
+ {
+ point.x = Pscreen.x + 10;
+ point.y = Pscreen.y + 10;
+ dest_point = mouse_map(point, Pscreen);
+ temp1 = screen->w/images[IMG_EXPLORED]->w;
+ temp2 = screen->h/images[IMG_EXPLORED]->h;
+ for(i = 0; i < temp1; i++)
+ {
+ for(j = 0; j < temp2; j++)
+ {
+ tmp_point.x = i * images[IMG_EXPLORED]->w;
+ tmp_point.y = i * images[IMG_EXPLORED]->h;
+ dest_point = mouse_map(tmp_point, Pscreen);
+ if(dest_point.x != -1 || dest_point.y != -1)
+ {
+ draw_unexplored(player, dest_point);
+ goto unexp_draw;
+ }
+ }
+ }
+ return;
+ }
+ //printf("Init in: (%d,%d)\n", dest_point.x, dest_point.y);
+ draw_unexplored(player, dest_point);
+
+unexp_draw:
/*Third layer: User Interface*/
@@ -508,6 +549,7 @@ static void game_handle_mouse(void)
}
}
+ // TODO: Selecting rectangle is incompleat
if( io.select_rect.x > Pscreen.x &&
io.select_rect.x < Pscreen.x + screen->w &&
io.select_rect.y > Pscreen.y &&
@@ -542,7 +584,7 @@ static void game_handle_mouse(void)
// Search for a object in current selected tile and
// select that object
- selection.selected_objs[0]=rts_get_object(0,Pmousemap);
+ selection.selected_objs[0]=rts_get_object(human_player,Pmousemap);
if(selection.selected_objs[0] != NULL)
{
@@ -611,10 +653,11 @@ static void game_handle_mouse(void)
selection.selected_objs[0]->y,
io.go_xy.x,
io.go_xy.y);
- if(!(path = ai_shortes_path(0,0,Pmousemap, io.go_xy)))
+ rts_goto(selection.selected_objs[0], io.go_xy);
+/* if(!(path = ai_shortes_path(human_player,0,Pmousemap, io.go_xy)))
printf("No shortes path found or a error ocurred!\n");
else
- printf("Path found!\n");
+ printf("Path found!\n");*/
}
}
diff --git a/src/players.c b/src/players.c
index 6deacd9..63986c9 100644
--- a/src/players.c
+++ b/src/players.c
@@ -10,7 +10,7 @@ static int players_alloc(int players);
static int players_alloc(int players)
{
- player = malloc(players * sizeof(int));
+ player = malloc((1 + players) * sizeof(th_players));
if(player == NULL)
{
printf("players_alloc: Couldn't allocate memory for palyer\n");
@@ -19,14 +19,25 @@ static int players_alloc(int players)
return 0;
}
-int init_players(int players)
+int init_players(int players, int human)
{
+ th_point pos;
num_of_players = players;
if(players_alloc(num_of_players))
{
return 0;
}
- last_player = -1;
+ last_player = 0;
+
+ //TODO: This information should be readen from a map
+
+ pos.x = 0;
+ pos.y = 0;
+ add_player("Human", CIV_DEFAULT, 50, 200,
+ 200, 200, 200, pos);
+ add_player("Computer", CIV_DEFAULT, 50, 200,
+ 200, 200, 200, pos);
+ human_player = human;
return 1;
}
int add_player(char *name, int civ, int max_pop, int stone,
@@ -52,13 +63,13 @@ 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(gmaps == NULL)
+ /*if(gmaps == NULL)
{
printf("add_player(): gmaps isn't allocated, cant giva a position in map to player!\n");
return 1;
}
player[last_player].pos = &gmaps[0][pos.x][pos.y];
-
+ */
return 0;
}
diff --git a/src/players.h b/src/players.h
index 8427511..88ec0e5 100644
--- a/src/players.h
+++ b/src/players.h
@@ -6,6 +6,11 @@
#define NAME_LEN 50
+enum{
+ CIV_DEFAULT,
+ NUM_CIVILIZATIONS
+};
+
typedef struct th_players{
char name[NAME_LEN];
int player_num;
@@ -20,10 +25,11 @@ typedef struct th_players{
}th_players;
int num_of_players;
+int human_player;
int last_player;
th_players *player;
-int init_players(int players);
+int init_players(int players, int human);
int add_player(char *name, int civ, int max_pop, int stone,
int wood, int food, int gold, th_point pos);
void clean_players(void);
diff --git a/src/tuxrts.c b/src/tuxrts.c
index 294c84f..6aa201b 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -20,7 +20,7 @@ int tuxrts_init(char *object_name, char *map_name, int players)
object_counter = 0;
- if(!init_players(players))
+ if(!init_players(players, 1))
{
printf("No players created!\n");
DEBUGMSG(debug_game, "No players created!");
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list