[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 5839a4670aba9513fc430771f9439ba2e90cb7b0
julio (none)
julio at julio-desktop.
Sun Aug 8 18:54:17 UTC 2010
The following commit has been merged in the master branch:
commit 5839a4670aba9513fc430771f9439ba2e90cb7b0
Author: julio <julio at julio-desktop.(none)>
Date: Sun Aug 8 13:53:35 2010 -0500
Adding fog and visibility per player.
diff --git a/configure.ac b/configure.ac
index 4ee9db8..3ab1a6c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -181,7 +181,7 @@ AC_CHECK_LIB([m],
dnl Check for LibLua: --------------------------------------------------------
PKG_CHECK_MODULES([LUA],
- [lua],
+ [lua50],
,
[
[echo "LUA not found via pkg_config, checking with AC_CHECK_LIB:"]
@@ -198,8 +198,6 @@ CFLAGS="$CFLAGS $LUA_CFLAGS"
LIBS="$LIBS $LUA_LIBS"
-
-
dnl Check for SDL_Pango: --------------------------------------------------------
dnl SDL_Pango is enabled by default.
diff --git a/data/images/others/Makefile.am b/data/images/others/Makefile.am
index 6742f43..aae53fa 100644
--- a/data/images/others/Makefile.am
+++ b/data/images/others/Makefile.am
@@ -7,4 +7,6 @@ othersdir = $(pkgdatadir)/images/others
dist_others_DATA = isomapper.png \
select.png \
go.png \
+novisible.png \
+explored.png \
wrong.png
diff --git a/data/images/others/explored.png b/data/images/others/explored.png
new file mode 100644
index 0000000..cbf680f
Binary files /dev/null and b/data/images/others/explored.png differ
diff --git a/data/images/others/novisible.png b/data/images/others/novisible.png
new file mode 100644
index 0000000..4a39480
Binary files /dev/null and b/data/images/others/novisible.png differ
diff --git a/data/maps/map.xml b/data/maps/map.xml
index 188a7ca..b5856ef 100644
--- a/data/maps/map.xml
+++ b/data/maps/map.xml
@@ -10,14 +10,14 @@
<tilde>
<height>0</height>
<terrain>GRASSLAND</terrain>
- <object>FOREST_MIXED</object>
+ <object player=0>FOREST_MIXED</object>
<unit></unit>
<building></building>
</tilde>
<tilde>
<height>1</height>
<terrain>GRASSLAND</terrain>
- <object>FOREST_RAIN</object>
+ <object player=0>FOREST_RAIN</object>
<unit></unit>
<building></building>
</tilde>
@@ -194,9 +194,7 @@
<tilde>
<height>1</height>
<terrain>GRASSLAND</terrain>
- <object>VILLAGER_MILKMAID</object>
- <unit>VILLAGER_MILKMAID</unit>
- <building></building>
+ <object player=1>VILLAGER_MILKMAID</object>
</tilde>
<tilde>
<height>1</height>
@@ -1839,7 +1837,7 @@
<tilde>
<height>1</height>
<terrain>SWAMP</terrain>
- <object>FOREST_MIXED</object>
+ <object player=0>FOREST_MIXED</object>
<unit></unit>
<building></building>
</tilde>
diff --git a/data/objects/objects.xml b/data/objects/objects.xml
index 09a5b04..ec1cb1c 100644
--- a/data/objects/objects.xml
+++ b/data/objects/objects.xml
@@ -42,6 +42,7 @@
<rname>Vilager</rname>
<description>This unit can create buildings, and recolect resources.</description>
<live>25</live>
+ <vision>3</vision>
<defence>1</defence>
<attack>3</attack>
<move>1</move>
diff --git a/src/fileops.h b/src/fileops.h
index 0adfe5e..a196c82 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -73,6 +73,8 @@ enum {
IMG_ISOSELECT,
IMG_ISOGO,
IMG_ISOWRONG,
+ IMG_EXPLORED,
+ IMG_NOVISIBLE,
IMG_GUIBG_BYZANTINE,
NUM_IMAGES
};
diff --git a/src/fileops_media.c b/src/fileops_media.c
index 32b0829..bb8b53c 100644
--- a/src/fileops_media.c
+++ b/src/fileops_media.c
@@ -65,6 +65,8 @@ int load_image_data()
"others/select.png",
"others/go.png",
"others/wrong.png",
+ "others/explored.png",
+ "others/novisible.png",
"gui/byzantine.png"
};
diff --git a/src/game.c b/src/game.c
index 904cd21..dced55c 100644
--- a/src/game.c
+++ b/src/game.c
@@ -106,7 +106,7 @@ io_vars io;
static int game_init(void);
-static void game_draw(void);
+static void game_draw(int player);
static void game_handle_user_events(void);
static void game_handle_mouse(void);
static int game_mouse_event(SDL_Event event);
@@ -217,7 +217,7 @@ int game(void)
;//SwitchScreenMode(); //Huh??
}
- if(game_init())
+ if(!game_init())
{
DEBUGMSG(debug_game, "Error loading game using game_init()\n");
return -1;
@@ -233,7 +233,7 @@ int game(void)
game_handle_mouse();
game_status = check_exit_conditions();
- game_draw();
+ game_draw(this_player);
SDL_Flip(screen);
if(paused)
@@ -253,18 +253,76 @@ int game(void)
}
}
game_over(game_status);
+ return 1;
}
-static void game_draw(void)
+static void draw_unexplored(int player, th_point point)
+{
+ int l;
+ SDL_Rect dest;
+
+ if(point.x == -1)
+ return;
+ if(point.y == -1)
+ return;
+
+ //Is the point in screen?
+ if( gmaps[0][point.x][point.y].rect.x >= (Pscreen.x - images[IMG_EXPLORED]->w) &&
+ gmaps[0][point.x][point.y].rect.x < (Pscreen.x + screen->w) &&
+ gmaps[0][point.x][point.y].rect.y >= (Pscreen.y - images[IMG_EXPLORED]->h) &&
+ gmaps[0][point.x][point.y].rect.y < (Pscreen.x + screen->w) &&
+ gmaps[player][point.x][point.y].drawed == 0 )
+ {
+ //printf(" + ");
+ dest.x = gmaps[0][point.x][point.y].rect.x - Pscreen.x;
+ dest.y = gmaps[0][point.x][point.y].rect.y - Pscreen.y;
+
+ //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!
+ for(l = 0; l <= NUM_DIRS; l++)
+ {
+ if(gmaps[player][point.x][point.y].nodes_flag[l] == 1)
+ {
+ if(gmaps[player][point.x][point.y].nodes[l] != NULL)
+ {
+ //printf(" -%d(%d,%d)- \n", l, point.x, point.y);
+ draw_unexplored(player, gmaps[player][point.x][point.y].nodes[l]->point);
+ }
+ }
+ }
+ }
+ //else
+ /*printf("NO DRAW: drawed:%d, (%d,%d) is not in (%d,%d)\n",
+ gmaps[player][point.x][point.y].drawed,
+ gmaps[0][point.x][point.y].rect.x,
+ gmaps[0][point.x][point.y].rect.y,
+ (Pscreen.x - images[IMG_EXPLORED]->w),
+ (Pscreen.y - images[IMG_EXPLORED]->h));*/
+}
+
+
+
+
+static void game_draw(int player)
{
SDL_Rect dest;
list_node *obj_node;
char tmp_text[50];
+ th_point point;
+ th_point dest_point;
+
origin.x = Pscreen.x;
origin.y = Pscreen.y;
- dest.x = 0;
+ dest.x = 0;
dest.y = 0;
@@ -273,6 +331,19 @@ static void game_draw(void)
/*First layer: terrain*/
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;
diff --git a/src/graphs.c b/src/graphs.c
index 626e332..afb2668 100644
--- a/src/graphs.c
+++ b/src/graphs.c
@@ -84,6 +84,8 @@ int create_gmaps(int players)
gmaps[i][j][k].object = NULL;
gmaps[i][j][k].point.x = j;
gmaps[i][j][k].point.y = k;
+ gmaps[i][j][k].drawed = 0;
+
if(i == 0)
{
gmaps[i][j][k].visible = 1;
@@ -97,13 +99,17 @@ int create_gmaps(int players)
for(l = 0; l < NUM_DIRS; l++)
{
+ point.x = j;
+ point.y = k;
vector = get_vector(point, l);
if(vector.x != -2 && vector.y != -2)
{
- gmaps[i][j][k].nodes[l] = &gmaps[0][j+vector.x][k+vector.y];
+ gmaps[i][j][k].nodes_flag[l] = 1;
+ gmaps[i][j][k].nodes[l] = &gmaps[i][j+vector.x][k+vector.y];
}
else
{
+ gmaps[i][j][k].nodes_flag[l] = 0;
gmaps[i][j][k].nodes[l] = NULL;
}
}
diff --git a/src/graphs.h b/src/graphs.h
index b581de6..d59fa3d 100644
--- a/src/graphs.h
+++ b/src/graphs.h
@@ -40,8 +40,10 @@ typedef struct gnode{
th_point anchor; //Anchors in main map surface.
int visible;
int explored;
+ int drawed;
int usable;
- struct gnode *nodes[NUM_DIRS-1];
+ struct gnode *nodes[NUM_DIRS];
+ int nodes_flag[NUM_DIRS];
th_obj *object;
int terrain;
}gnode;
diff --git a/src/players.c b/src/players.c
index 9194d53..6deacd9 100644
--- a/src/players.c
+++ b/src/players.c
@@ -24,10 +24,10 @@ int init_players(int players)
num_of_players = players;
if(players_alloc(num_of_players))
{
- return 1;
+ return 0;
}
last_player = -1;
- return 0;
+ return 1;
}
int add_player(char *name, int civ, int max_pop, int stone,
int wood, int food, int gold, th_point pos)
diff --git a/src/tuxrts.c b/src/tuxrts.c
index 5f58481..294c84f 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -20,19 +20,26 @@ int tuxrts_init(char *object_name, char *map_name, int players)
object_counter = 0;
+ if(!init_players(players))
+ {
+ printf("No players created!\n");
+ DEBUGMSG(debug_game, "No players created!");
+ return 0;
+ }
+
fp = LoadObj("objects");
if(fp == NULL)
{
printf("File not found!\n");
DEBUGMSG(debug_game, "File not found!");
- return 1;
+ return 0;
}
printf("Object files in memory!\n");
if(objects_xml(fp))
{
printf("Error parsing file!");
DEBUGMSG(debug_game, "Error loading the objects description file.\n");
- return 1;
+ return 0;
}
printf("Object file parsed.\n");
@@ -40,7 +47,7 @@ int tuxrts_init(char *object_name, char *map_name, int players)
if(fp == NULL)
{
DEBUGMSG(debug_game, "File not found!");
- return 1;
+ return 0;
}
printf("Map file in memory.\n");
@@ -48,13 +55,13 @@ int tuxrts_init(char *object_name, char *map_name, int players)
{
printf("Error parsing file!");
DEBUGMSG(debug_game, "Error loading the map file.\n");
- return 1;
+ return 0;
}
printf("Map file parsed!\n");
if(create_gmaps(players))
{
printf("Couldn't generate grpah mesh!\n");
- return 1;
+ return 0;
}
generate_map();
@@ -74,7 +81,7 @@ int tuxrts_init(char *object_name, char *map_name, int players)
images[IMG_GUIBG_BYZANTINE] = tmp_surf;
- return 0;
+ return 1;
}
// Returns 1 if the tile is valid to use for a player, and unit
@@ -164,6 +171,7 @@ static void rts_set_visible(int player, th_point point, int deph, int count)
gmaps[player][point.x][point.y].explored = 1;
gmaps[player][point.x][point.y].visible = 1;
+
for(l = 0; l < NUM_DIRS; l++)
{
if(gmaps[player][point.x][point.y].nodes[l])
@@ -179,7 +187,7 @@ int rts_update_game(void)
th_point point;
// Update gmaps...
- for(player = 1; player <= num_of_players; player++)
+ for(player = 0; player <= num_of_players; player++)
{
for(i = 0; i <= x_tildes; i++)
{
@@ -187,6 +195,7 @@ int rts_update_game(void)
{
gmaps[player][i][j].visible = 0;
gmaps[player][i][j].object = NULL;
+ gmaps[player][i][j].drawed = 0;
}
}
}
--
tuxhistory - Educational history game
More information about the Tux4kids-commits
mailing list