added nice looking new castles from Ayin
This commit is contained in:
parent
8eed6184eb
commit
9163a72271
44 changed files with 291 additions and 21 deletions
|
@ -2,6 +2,7 @@
|
||||||
name=The Sceptre of Fire
|
name=The Sceptre of Fire
|
||||||
id=Sceptre
|
id=Sceptre
|
||||||
scenario_generation=cave
|
scenario_generation=cave
|
||||||
|
next_scenario=A_Choice_Must_Be_Made
|
||||||
|
|
||||||
[generator]
|
[generator]
|
||||||
|
|
||||||
|
|
BIN
images/terrain/castle-e-e-e.png
Normal file
BIN
images/terrain/castle-e-e-e.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-e-e-nw.png
Normal file
BIN
images/terrain/castle-e-e-nw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-e-e-sw.png
Normal file
BIN
images/terrain/castle-e-e-sw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-e-i-e.png
Normal file
BIN
images/terrain/castle-e-i-e.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-e-i-nw.png
Normal file
BIN
images/terrain/castle-e-i-nw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-e-i-sw.png
Normal file
BIN
images/terrain/castle-e-i-sw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-ne-e-ne.png
Normal file
BIN
images/terrain/castle-ne-e-ne.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-ne-e-se.png
Normal file
BIN
images/terrain/castle-ne-e-se.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-ne-e-w.png
Normal file
BIN
images/terrain/castle-ne-e-w.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-ne-i-ne.png
Normal file
BIN
images/terrain/castle-ne-i-ne.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-ne-i-se.png
Normal file
BIN
images/terrain/castle-ne-i-se.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-ne-i-w.png
Normal file
BIN
images/terrain/castle-ne-i-w.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-nw-e-e.png
Normal file
BIN
images/terrain/castle-nw-e-e.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-nw-e-nw.png
Normal file
BIN
images/terrain/castle-nw-e-nw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-nw-e-sw.png
Normal file
BIN
images/terrain/castle-nw-e-sw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-nw-i-e.png
Normal file
BIN
images/terrain/castle-nw-i-e.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-nw-i-nw.png
Normal file
BIN
images/terrain/castle-nw-i-nw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-nw-i-sw.png
Normal file
BIN
images/terrain/castle-nw-i-sw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-se-e-ne.png
Normal file
BIN
images/terrain/castle-se-e-ne.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-se-e-se.png
Normal file
BIN
images/terrain/castle-se-e-se.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-se-e-w.png
Normal file
BIN
images/terrain/castle-se-e-w.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-se-i-ne.png
Normal file
BIN
images/terrain/castle-se-i-ne.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-se-i-se.png
Normal file
BIN
images/terrain/castle-se-i-se.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-se-i-w.png
Normal file
BIN
images/terrain/castle-se-i-w.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-sw-e-e.png
Normal file
BIN
images/terrain/castle-sw-e-e.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-sw-e-nw.png
Normal file
BIN
images/terrain/castle-sw-e-nw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-sw-e-sw.png
Normal file
BIN
images/terrain/castle-sw-e-sw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-sw-i-e.png
Normal file
BIN
images/terrain/castle-sw-i-e.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-sw-i-nw.png
Normal file
BIN
images/terrain/castle-sw-i-nw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-sw-i-sw.png
Normal file
BIN
images/terrain/castle-sw-i-sw.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-w-e-ne.png
Normal file
BIN
images/terrain/castle-w-e-ne.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-w-e-se.png
Normal file
BIN
images/terrain/castle-w-e-se.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-w-e-w.png
Normal file
BIN
images/terrain/castle-w-e-w.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-w-i-ne.png
Normal file
BIN
images/terrain/castle-w-i-ne.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-w-i-se.png
Normal file
BIN
images/terrain/castle-w-i-se.png
Normal file
Binary file not shown.
BIN
images/terrain/castle-w-i-w.png
Normal file
BIN
images/terrain/castle-w-i-w.png
Normal file
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 8.4 KiB |
109
src/display.cpp
109
src/display.cpp
|
@ -1247,7 +1247,15 @@ void display::draw_tile_adjacent(int x, int y, image::TYPE image_type, ADJACENT_
|
||||||
|
|
||||||
const std::vector<shared_sdl_surface>& adj = getAdjacentTerrain(x,y,image_type,type);
|
const std::vector<shared_sdl_surface>& adj = getAdjacentTerrain(x,y,image_type,type);
|
||||||
|
|
||||||
for(std::vector<shared_sdl_surface>::const_iterator i = adj.begin(); i != adj.end(); ++i) {
|
std::vector<shared_sdl_surface>::const_iterator i;
|
||||||
|
for(i = adj.begin(); i != adj.end(); ++i) {
|
||||||
|
SDL_Rect dstrect = { xpos, ypos, 0, 0 };
|
||||||
|
SDL_BlitSurface(*i,NULL,dst,&dstrect);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<shared_sdl_surface>& built = getBuiltTerrain(x,y,image_type,type);
|
||||||
|
|
||||||
|
for(i = built.begin(); i != built.end(); ++i) {
|
||||||
SDL_Rect dstrect = { xpos, ypos, 0, 0 };
|
SDL_Rect dstrect = { xpos, ypos, 0, 0 };
|
||||||
SDL_BlitSurface(*i,NULL,dst,&dstrect);
|
SDL_BlitSurface(*i,NULL,dst,&dstrect);
|
||||||
}
|
}
|
||||||
|
@ -1257,7 +1265,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image, double alpha, Uin
|
||||||
{
|
{
|
||||||
if(updatesLocked_)
|
if(updatesLocked_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const gamemap::location loc(x,y);
|
const gamemap::location loc(x,y);
|
||||||
int xpos = int(get_location_x(loc));
|
int xpos = int(get_location_x(loc));
|
||||||
int ypos = int(get_location_y(loc));
|
int ypos = int(get_location_y(loc));
|
||||||
|
@ -1317,7 +1325,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image, double alpha, Uin
|
||||||
SDL_BlitSurface(flag,NULL,dst,&dstrect);
|
SDL_BlitSurface(flag,NULL,dst,&dstrect);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_tile_adjacent(x,y,image_type,ADJACENT_TERRAIN);
|
draw_tile_adjacent(x,y,image_type,ADJACENT_BACKGROUND);
|
||||||
|
|
||||||
typedef std::multimap<gamemap::location,std::string>::const_iterator Itor;
|
typedef std::multimap<gamemap::location,std::string>::const_iterator Itor;
|
||||||
|
|
||||||
|
@ -1348,7 +1356,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image, double alpha, Uin
|
||||||
draw_unit_on_tile(x,y,unit_image,alpha,blend_to);
|
draw_unit_on_tile(x,y,unit_image,alpha,blend_to);
|
||||||
|
|
||||||
if(!shrouded(x,y)) {
|
if(!shrouded(x,y)) {
|
||||||
draw_tile_adjacent(x,y,image_type,ADJACENT_FOG);
|
draw_tile_adjacent(x,y,image_type,ADJACENT_FOREGROUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(grid_) {
|
if(grid_) {
|
||||||
|
@ -1450,19 +1458,22 @@ void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const std::string& get_direction(int n)
|
const std::string& get_direction(size_t n)
|
||||||
{
|
{
|
||||||
static std::map<int,std::string> dirs;
|
const static std::string dirs[6] = {"-n","-ne","-se","-s","-sw","-nw"};
|
||||||
if(dirs.empty()) {
|
return dirs[n >= sizeof(dirs)/sizeof(*dirs) ? 0 : n];
|
||||||
dirs[0] = "-n";
|
}
|
||||||
dirs[1] = "-ne";
|
|
||||||
dirs[2] = "-se";
|
|
||||||
dirs[3] = "-s";
|
|
||||||
dirs[4] = "-sw";
|
|
||||||
dirs[5] = "-nw";
|
|
||||||
}
|
|
||||||
|
|
||||||
return dirs[n];
|
bool angle_is_northern(size_t n)
|
||||||
|
{
|
||||||
|
const static bool results[6] = {true,false,false,false,false,true};
|
||||||
|
return results[n >= sizeof(results)/sizeof(*results) ? 0 : n];
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& get_angle_direction(size_t n)
|
||||||
|
{
|
||||||
|
const static std::string dirs[6] = {"-ne","-e","-se","-sw","-w","-nw"};
|
||||||
|
return dirs[n >= sizeof(dirs)/sizeof(*dirs) ? 0 : n];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1478,9 +1489,9 @@ std::vector<shared_sdl_surface> display::getAdjacentTerrain(int x, int y, image:
|
||||||
get_adjacent_tiles(loc,adjacent);
|
get_adjacent_tiles(loc,adjacent);
|
||||||
int tiles[6];
|
int tiles[6];
|
||||||
for(int i = 0; i != 6; ++i) {
|
for(int i = 0; i != 6; ++i) {
|
||||||
if(terrain_type == ADJACENT_FOG && shrouded(adjacent[i].x,adjacent[i].y))
|
if(terrain_type == ADJACENT_FOREGROUND && shrouded(adjacent[i].x,adjacent[i].y))
|
||||||
tiles[i] = gamemap::VOID_TERRAIN;
|
tiles[i] = gamemap::VOID_TERRAIN;
|
||||||
else if(terrain_type == ADJACENT_FOG && !fogged(x,y) && fogged(adjacent[i].x,adjacent[i].y))
|
else if(terrain_type == ADJACENT_FOREGROUND && !fogged(x,y) && fogged(adjacent[i].x,adjacent[i].y))
|
||||||
tiles[i] = gamemap::FOGGED;
|
tiles[i] = gamemap::FOGGED;
|
||||||
else
|
else
|
||||||
tiles[i] = map_.get_terrain(adjacent[i]);
|
tiles[i] = map_.get_terrain(adjacent[i]);
|
||||||
|
@ -1492,7 +1503,7 @@ std::vector<shared_sdl_surface> display::getAdjacentTerrain(int x, int y, image:
|
||||||
fog_shroud.push_back(gamemap::FOGGED);
|
fog_shroud.push_back(gamemap::FOGGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<gamemap::TERRAIN>& precedence = (terrain_type == ADJACENT_TERRAIN) ?
|
const std::vector<gamemap::TERRAIN>& precedence = (terrain_type == ADJACENT_BACKGROUND) ?
|
||||||
map_.get_terrain_precedence() : fog_shroud;
|
map_.get_terrain_precedence() : fog_shroud;
|
||||||
std::vector<gamemap::TERRAIN>::const_iterator terrain =
|
std::vector<gamemap::TERRAIN>::const_iterator terrain =
|
||||||
std::find(precedence.begin(),precedence.end(),current_terrain);
|
std::find(precedence.begin(),precedence.end(),current_terrain);
|
||||||
|
@ -1552,6 +1563,68 @@ std::vector<shared_sdl_surface> display::getAdjacentTerrain(int x, int y, image:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<shared_sdl_surface> display::getBuiltTerrain(int x, int y, image::TYPE image_type, ADJACENT_TERRAIN_TYPE terrain_type)
|
||||||
|
{
|
||||||
|
std::vector<shared_sdl_surface> res;
|
||||||
|
gamemap::location loc(x,y);
|
||||||
|
|
||||||
|
// If the current tile is a castle tile, or if any adjacent tile is, this tile will have
|
||||||
|
// some castle-wall adjustable decorations.
|
||||||
|
// For now, the type of tiles (castle, !castle) is built-in.
|
||||||
|
|
||||||
|
gamemap::location adjacent[6];
|
||||||
|
get_adjacent_tiles(loc,adjacent);
|
||||||
|
|
||||||
|
char angle_type;
|
||||||
|
bool ti, tj, to;
|
||||||
|
|
||||||
|
// TODO: change this to something like map_.is_castle(blah) to support
|
||||||
|
// keeps, elven/orcish castles, etc.
|
||||||
|
gamemap::TERRAIN terrain = gamemap::CASTLE;
|
||||||
|
to = map_.is_built(loc);
|
||||||
|
|
||||||
|
for(int i = 0; i != 6; ++i) {
|
||||||
|
int j = i+1;
|
||||||
|
if(j == 6)
|
||||||
|
j = 0;
|
||||||
|
|
||||||
|
ti = map_.is_built(adjacent[i]);
|
||||||
|
tj = map_.is_built(adjacent[j]);
|
||||||
|
|
||||||
|
int ncastles = (to?1:0) + (ti?1:0) + (tj?1:0);
|
||||||
|
|
||||||
|
if ((ti != to) && (tj != to)) {
|
||||||
|
angle_type = i;
|
||||||
|
} else if ((ti == to) && (tj != to)) {
|
||||||
|
angle_type = (i+4) % 6;
|
||||||
|
} else if ((ti != to) && (tj == to)) {
|
||||||
|
angle_type = (i+2) % 6;
|
||||||
|
} else {
|
||||||
|
angle_type = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(angle_type == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool angle_northern = angle_is_northern(i);
|
||||||
|
if(angle_northern && terrain_type == ADJACENT_FOREGROUND ||
|
||||||
|
!angle_northern && terrain_type == ADJACENT_BACKGROUND) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << get_angle_direction(angle_type) <<
|
||||||
|
(ncastles == 2? "-e" : "-i") << get_angle_direction(i);
|
||||||
|
const shared_sdl_surface surface(getTerrain(terrain,
|
||||||
|
image_type,x,y,stream.str()));
|
||||||
|
if(surface != NULL)
|
||||||
|
res.push_back(surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Surface* display::getTerrain(gamemap::TERRAIN terrain,image::TYPE image_type,
|
SDL_Surface* display::getTerrain(gamemap::TERRAIN terrain,image::TYPE image_type,
|
||||||
int x, int y, const std::string& direction)
|
int x, int y, const std::string& direction)
|
||||||
{
|
{
|
||||||
|
|
|
@ -173,7 +173,7 @@ private:
|
||||||
void draw_unit_on_tile(int x, int y, SDL_Surface* unit_image=NULL,
|
void draw_unit_on_tile(int x, int y, SDL_Surface* unit_image=NULL,
|
||||||
double alpha=1.0, Uint32 blend_to=0);
|
double alpha=1.0, Uint32 blend_to=0);
|
||||||
|
|
||||||
enum ADJACENT_TERRAIN_TYPE { ADJACENT_TERRAIN, ADJACENT_FOG };
|
enum ADJACENT_TERRAIN_TYPE { ADJACENT_BACKGROUND, ADJACENT_FOREGROUND };
|
||||||
void draw_tile_adjacent(int x, int y, image::TYPE image_type, ADJACENT_TERRAIN_TYPE type);
|
void draw_tile_adjacent(int x, int y, image::TYPE image_type, ADJACENT_TERRAIN_TYPE type);
|
||||||
|
|
||||||
|
|
||||||
|
@ -338,6 +338,7 @@ private:
|
||||||
void bounds_check_position();
|
void bounds_check_position();
|
||||||
|
|
||||||
std::vector<shared_sdl_surface> getAdjacentTerrain(int x, int y, image::TYPE type, ADJACENT_TERRAIN_TYPE terrain_type);
|
std::vector<shared_sdl_surface> getAdjacentTerrain(int x, int y, image::TYPE type, ADJACENT_TERRAIN_TYPE terrain_type);
|
||||||
|
std::vector<shared_sdl_surface> getBuiltTerrain(int x, int y, image::TYPE type, ADJACENT_TERRAIN_TYPE terrain_type);
|
||||||
|
|
||||||
//this surface must be freed by the caller
|
//this surface must be freed by the caller
|
||||||
SDL_Surface* getTerrain(gamemap::TERRAIN, image::TYPE type,
|
SDL_Surface* getTerrain(gamemap::TERRAIN, image::TYPE type,
|
||||||
|
|
|
@ -295,6 +295,15 @@ const std::vector<gamemap::TERRAIN>& gamemap::get_terrain_precedence() const
|
||||||
return terrainPrecedence_;
|
return terrainPrecedence_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gamemap::is_built(const location &loc) const
|
||||||
|
{
|
||||||
|
gamemap::TERRAIN terrain = get_terrain(loc);
|
||||||
|
if((terrain == gamemap::CASTLE) || (terrain == gamemap::KEEP))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void gamemap::set_terrain(const gamemap::location& loc, gamemap::TERRAIN ter)
|
void gamemap::set_terrain(const gamemap::location& loc, gamemap::TERRAIN ter)
|
||||||
{
|
{
|
||||||
if(!on_board(loc))
|
if(!on_board(loc))
|
||||||
|
|
|
@ -125,6 +125,8 @@ public:
|
||||||
//other terrain types. Has no effect on gameplay, only display.
|
//other terrain types. Has no effect on gameplay, only display.
|
||||||
const std::vector<TERRAIN>& get_terrain_precedence() const;
|
const std::vector<TERRAIN>& get_terrain_precedence() const;
|
||||||
|
|
||||||
|
bool is_built(const location& loc) const;
|
||||||
|
|
||||||
//clobbers over the terrain at location 'loc', with the given terrain
|
//clobbers over the terrain at location 'loc', with the given terrain
|
||||||
void set_terrain(const location& loc, TERRAIN ter);
|
void set_terrain(const location& loc, TERRAIN ter);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -559,8 +559,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
||||||
return ESCAPE_DIALOG;
|
return ESCAPE_DIALOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!key_down && key[SDLK_ESCAPE] &&
|
if(!key_down && key[SDLK_ESCAPE]) {
|
||||||
(type == YES_NO || type == OK_CANCEL)) {
|
|
||||||
|
|
||||||
if(menu_.height() == 0) {
|
if(menu_.height() == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
185
tools/mk-castle.sh
Executable file
185
tools/mk-castle.sh
Executable file
|
@ -0,0 +1,185 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
|
||||||
|
syntaxerror() {
|
||||||
|
echo "usage: $0 [-c <cutout>] [-m <mask>] file"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
cutoutf="cutout.png"
|
||||||
|
maskf="mask.png"
|
||||||
|
output="castle"
|
||||||
|
|
||||||
|
while [ $# -ne 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
-c* )
|
||||||
|
shift
|
||||||
|
cutoutf="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-m* )
|
||||||
|
shift
|
||||||
|
maskf="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-o* )
|
||||||
|
shift
|
||||||
|
output="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-* )
|
||||||
|
syntaxerror
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
file="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$file" ]; then
|
||||||
|
syntaxerror
|
||||||
|
fi
|
||||||
|
|
||||||
|
# File location definitions
|
||||||
|
|
||||||
|
tmpdir=`mktemp -d /tmp/mk-castle.XXXXXXX`
|
||||||
|
mask="$tmpdir/mask.pgm"
|
||||||
|
cutout="$tmpdir/cutout.pbm"
|
||||||
|
castle="$tmpdir/castle.ppm"
|
||||||
|
alpha="$tmpdir/alpha.pgm"
|
||||||
|
|
||||||
|
# Creates pnm files from the original png files
|
||||||
|
|
||||||
|
pngtopnm "$maskf" | ppmtopgm | pnminvert > "$mask"
|
||||||
|
pngtopnm "$cutoutf" > "$cutout"
|
||||||
|
pngtopnm "$file" > "$castle"
|
||||||
|
pngtopnm -alpha "$file" > "$alpha"
|
||||||
|
|
||||||
|
# Generates the 12 cutout masks from the cutout file
|
||||||
|
|
||||||
|
colors="rgbi:1/0/0 rgbi:1/0/1 rgbi:0/0/1 rgbi:0/1/1 rgbi:0/1/0 rgbi:1/1/0 rgbi:.5/0/0 rgbi:.5/0/.5 rgbi:0/0/.5 rgbi:0/.5/.5 rgbi:0/.5/0 rgbi:.5/.5/0"
|
||||||
|
i=0
|
||||||
|
|
||||||
|
for color in $colors; do
|
||||||
|
cmask[$i]="$tmpdir/cmask$i.pbm"
|
||||||
|
ppmcolormask $color $cutout | pnminvert > ${cmask[$i]}
|
||||||
|
i=$(($i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Cuts the castle, and the castle's alpha, according to the 12 masks
|
||||||
|
|
||||||
|
directions="ne-e e-e se-e sw-e w-e nw-e ne-i e-i se-i sw-i w-i nw-i"
|
||||||
|
i=0
|
||||||
|
|
||||||
|
for direction in $directions; do
|
||||||
|
ccastle[$i]="$tmpdir/castle-$direction"
|
||||||
|
calpha[$i]="$tmpdir/alpha-$direction"
|
||||||
|
pnmarith -multiply ${cmask[$i]} $castle > ${ccastle[$i]}.ppm
|
||||||
|
pnmarith -multiply ${cmask[$i]} $alpha > ${calpha[$i]}.pgm
|
||||||
|
i=$(($i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
# For each cut castle & image tile, extract its 3 hexagons
|
||||||
|
|
||||||
|
# Coordinates of the angles 0
|
||||||
|
|
||||||
|
angle0e="71,35"
|
||||||
|
angle0i="177,35"
|
||||||
|
|
||||||
|
# Coordinates of each other angle, relative to angle 0
|
||||||
|
|
||||||
|
angles_relative="0,0 17,35 0,70 -36,70 -53,35 -36,0"
|
||||||
|
|
||||||
|
x0e=${angle0e%,*}
|
||||||
|
y0e=${angle0e#*,}
|
||||||
|
x0i=${angle0i%,*}
|
||||||
|
y0i=${angle0i#*,}
|
||||||
|
i=0
|
||||||
|
|
||||||
|
# Compose the actual list of coordinates for each angle
|
||||||
|
|
||||||
|
for angle in $angles_relative; do
|
||||||
|
xr=${angle%,*}
|
||||||
|
yr=${angle#*,}
|
||||||
|
|
||||||
|
echo "Angle is $angle"
|
||||||
|
x=$(($xr + $x0e))
|
||||||
|
y=$(($yr + $y0e))
|
||||||
|
angles[$i]="$x,$y"
|
||||||
|
|
||||||
|
x=$(($xr + $x0i))
|
||||||
|
y=$(($yr + $y0i))
|
||||||
|
angles[$((i+6))]="$x,$y"
|
||||||
|
|
||||||
|
i=$(($i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Move each angle on a corner of the hexagon, cut the image
|
||||||
|
# to 70x70 size, then apply mask
|
||||||
|
|
||||||
|
hexcorners_even="53,0 53,70 0,35"
|
||||||
|
hexcorners_names_even=(ne se w)
|
||||||
|
hexcorners_odd="70,35 17,70 17,0"
|
||||||
|
hexcorners_names_odd=(e sw nw)
|
||||||
|
margin=200 # Adds a margin to files
|
||||||
|
width=70
|
||||||
|
height=70
|
||||||
|
i=0
|
||||||
|
|
||||||
|
for angle in ${angles[*]}; do
|
||||||
|
mcastle=${ccastle[$i]}
|
||||||
|
malpha=${calpha[$i]}
|
||||||
|
|
||||||
|
pnmmargin "$margin" "$mcastle.ppm" > "$mcastle-m.ppm"
|
||||||
|
pnmmargin "$margin" "$malpha.pgm" > "$malpha-m.pgm"
|
||||||
|
|
||||||
|
if [ $(($i % 2)) -eq 0 ]; then
|
||||||
|
prefix="_even"
|
||||||
|
else
|
||||||
|
prefix="_odd"
|
||||||
|
fi
|
||||||
|
|
||||||
|
xangle=${angle%,*}
|
||||||
|
yangle=${angle#*,}
|
||||||
|
j=0
|
||||||
|
hexcorners_n="hexcorners$prefix"
|
||||||
|
for corner in ${!hexcorners_n}; do
|
||||||
|
name_n="hexcorners_names$prefix[$j]"
|
||||||
|
name=${!name_n}
|
||||||
|
xcorner=${corner%,*}
|
||||||
|
ycorner=${corner#*,}
|
||||||
|
|
||||||
|
xdelta=$(($xangle - $xcorner + $margin))
|
||||||
|
ydelta=$(($yangle - $ycorner + $margin))
|
||||||
|
|
||||||
|
pnmcut -left $xdelta -top $ydelta -width $width \
|
||||||
|
-height $height "$mcastle-m.ppm" > \
|
||||||
|
"$mcastle-$name-x.ppm"
|
||||||
|
pnmarith -multiply "$mask" "$mcastle-$name-x.ppm" > \
|
||||||
|
"$mcastle-$name.ppm"
|
||||||
|
|
||||||
|
pnmcut -left $xdelta -top $ydelta -width $width \
|
||||||
|
-height $height "$malpha-m.pgm" > \
|
||||||
|
"$malpha-$name-x.pgm"
|
||||||
|
pnmarith -multiply "$mask" "$malpha-$name-x.pgm" > \
|
||||||
|
"$malpha-$name.pgm"
|
||||||
|
|
||||||
|
pnmtopng -alpha "$malpha-$name.pgm" "$mcastle-$name.ppm" > \
|
||||||
|
"$mcastle-$name.png"
|
||||||
|
|
||||||
|
j=$(($j+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ \! -d "$output" ]; then
|
||||||
|
mkdir $output || die "Unable to create output directory"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Harvests the generated PNGs, and erase all those generated files.
|
||||||
|
|
||||||
|
cp "$tmpdir"/*.png $output
|
||||||
|
rm -r "$tmpdir"
|
||||||
|
|
Loading…
Add table
Reference in a new issue