20#ifdef HAVE_MAPIMG_MAGICKWAND
22 #include <MagickWand/MagickWand.h>
24 #include <wand/MagickWand.h>
58#ifndef MagickLibInterface
59# define MagickLibInterface 0
61#ifndef MagickLibVersion
62# define MagickLibVersion 0
67#if (MagickLibInterface > 3) || (MagickLibVersion >= 0x662)
68# define magickwand_size_t size_t
70# define magickwand_size_t unsigned long
89#define NUM_PIXEL TILE_SIZE * TILE_SIZE
101 const struct player *pplayer,
127 const struct player *pplayer,
130 const struct player *pplayer,
133 const struct player *pplayer,
136 const struct player *pplayer,
139 const struct player *pplayer,
169 const struct player *pplayer,
172 const struct player *pplayer,
175 const struct player *pplayer,
178 const struct player *pplayer,
181 const struct player *pplayer,
191 0, 1, 2, 3, 4, 5, 6, 7,
192 0, 1, 2, 3, 4, 5, 6, 7,
199 2, 2, 2, 2, 2, 2, 2, 2,
200 3, 3, 3, 3, 3, 3, 3, 3,
207 const struct player *pplayer,
210 const struct player *pplayer,
213 const struct player *pplayer,
216 const struct player *pplayer,
219 const struct player *pplayer,
226#define ARG_PLRBV "plrbv"
227#define ARG_PLRID "plrid"
228#define ARG_PLRNAME "plrname"
231#define SPECENUM_NAME mapdef_arg
232#define SPECENUM_VALUE0 MAPDEF_FORMAT
233#define SPECENUM_VALUE0NAME "format"
234#define SPECENUM_VALUE1 MAPDEF_MAP
235#define SPECENUM_VALUE1NAME "map"
236#define SPECENUM_VALUE2 MAPDEF_PLRBV
237#define SPECENUM_VALUE2NAME ARG_PLRBV
238#define SPECENUM_VALUE3 MAPDEF_PLRID
239#define SPECENUM_VALUE3NAME ARG_PLRID
240#define SPECENUM_VALUE4 MAPDEF_PLRNAME
241#define SPECENUM_VALUE4NAME ARG_PLRNAME
242#define SPECENUM_VALUE5 MAPDEF_SHOW
243#define SPECENUM_VALUE5NAME "show"
244#define SPECENUM_VALUE6 MAPDEF_TURNS
245#define SPECENUM_VALUE6NAME "turns"
246#define SPECENUM_VALUE7 MAPDEF_ZOOM
247#define SPECENUM_VALUE7NAME "zoom"
248#define SPECENUM_COUNT MAPDEF_COUNT
254#define SPECENUM_NAME imageformat
255#define SPECENUM_BITWISE
256#define SPECENUM_VALUE0 IMGFORMAT_GIF
257#define SPECENUM_VALUE0NAME "gif"
258#define SPECENUM_VALUE1 IMGFORMAT_PNG
259#define SPECENUM_VALUE1NAME "png"
260#define SPECENUM_VALUE2 IMGFORMAT_PPM
261#define SPECENUM_VALUE2NAME "ppm"
262#define SPECENUM_VALUE3 IMGFORMAT_JPG
263#define SPECENUM_VALUE3NAME "jpg"
267#define SPECENUM_NAME imagetool
268#define SPECENUM_VALUE0 IMGTOOL_PPM
269#define SPECENUM_VALUE0NAME "ppm"
270#define SPECENUM_VALUE1 IMGTOOL_MAGICKWAND
271#define SPECENUM_VALUE1NAME "magick"
275#define SPECENUM_NAME show_player
276#define SPECENUM_VALUE0 SHOW_NONE
277#define SPECENUM_VALUE0NAME "none"
278#define SPECENUM_VALUE1 SHOW_EACH
279#define SPECENUM_VALUE1NAME "each"
280#define SPECENUM_VALUE2 SHOW_HUMAN
281#define SPECENUM_VALUE2NAME "human"
282#define SPECENUM_VALUE3 SHOW_ALL
283#define SPECENUM_VALUE3NAME "all"
285#define SPECENUM_VALUE4 SHOW_PLRNAME
286#define SPECENUM_VALUE4NAME ARG_PLRNAME
288#define SPECENUM_VALUE5 SHOW_PLRID
289#define SPECENUM_VALUE5NAME ARG_PLRID
291#define SPECENUM_VALUE6 SHOW_PLRBV
292#define SPECENUM_VALUE6NAME ARG_PLRBV
300#define SPECENUM_NAME mapimg_status
301#define SPECENUM_VALUE0 MAPIMG_STATUS_UNKNOWN
302#define SPECENUM_VALUE0NAME _("not checked")
303#define SPECENUM_VALUE1 MAPIMG_STATUS_OK
304#define SPECENUM_VALUE1NAME _("OK")
305#define SPECENUM_VALUE2 MAPIMG_STATUS_ERROR
306#define SPECENUM_VALUE2NAME _("error")
309#define MAX_LEN_MAPARG MAX_LEN_MAPDEF
310#define MAX_NUM_MAPIMG 10
314 const char *val,
bool check);
348#define SPECLIST_TAG mapdef
349#define SPECLIST_TYPE struct mapdef
352#define mapdef_list_iterate(mapdef_list, pmapdef) \
353 TYPED_LIST_ITERATE(struct mapdef, mapdef_list, pmapdef)
354#define mapdef_list_iterate_end \
361#define IMG_BORDER_HEIGHT 5
362#define IMG_BORDER_WIDTH IMG_BORDER_HEIGHT
363#define IMG_SPACER_HEIGHT 5
364#define IMG_LINE_HEIGHT 5
365#define IMG_TEXT_HEIGHT 12
396static inline int img_index(
const int x,
const int y,
397 const struct img *pimg);
403static bool img_save(
const struct img *pimg,
const char *mapimgfile,
405static bool img_save_ppm(
const struct img *pimg,
const char *mapimgfile);
406#ifdef HAVE_MAPIMG_MAGICKWAND
407static bool img_save_magickwand(
const struct img *pimg,
408 const char *mapimgfile);
410static bool img_filename(
const char *mapimgfile,
enum imageformat format,
411 char *filename,
size_t filename_len);
416 const char *mapimgfile);
426#define GEN_TOOLKIT(_tool, _format_default, _formats, _save_func, _help) \
427 {_tool, _format_default, _formats, _save_func, _help},
430 GEN_TOOLKIT(IMGTOOL_PPM, IMGFORMAT_PPM, IMGFORMAT_PPM,
432 N_(
"Standard ppm files"))
433#ifdef HAVE_MAPIMG_MAGICKWAND
435 IMGFORMAT_GIF + IMGFORMAT_PNG + IMGFORMAT_PPM + IMGFORMAT_JPG,
443#ifdef HAVE_MAPIMG_MAGICKWAND
444 #define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_GIF
445 #define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_MAGICKWAND
447 #define MAPIMG_DEFAULT_IMGFORMAT IMGFORMAT_PPM
448 #define MAPIMG_DEFAULT_IMGTOOL IMGTOOL_PPM
453#define img_toolkit_iterate(_toolkit) \
456 for (_i = 0; _i < img_toolkits_count; _i++) { \
457 const struct toolkit *_toolkit = &img_toolkits[_i];
459#define img_toolkit_iterate_end \
464#define MAX_LEN_ERRORBUF 1024
467static void mapimg_log(
const char *file,
const char *function,
int line,
468 const char *format, ...)
470#define MAPIMG_LOG(format, ...) \
471 mapimg_log(__FILE__, __FUNCTION__, __FC_LINE__, format, ## __VA_ARGS__)
472#define MAPIMG_ASSERT_RET_VAL(cond, expr) \
473 fc_assert_action(cond, MAPIMG_LOG(_("internal error")); return (expr))
517 mapimg.mapdef = mapdef_list_new();
546 if (mapdef_list_size(
mapimg.mapdef) > 0) {
548 mapdef_list_remove(
mapimg.mapdef, pmapdef);
564 mapdef_list_destroy(
mapimg.mapdef);
578 return mapdef_list_size(
mapimg.mapdef);
587 case SHOW_NONE:
return _(
"no players, only terrain");
588 case SHOW_EACH:
return _(
"one image per player");
589 case SHOW_HUMAN:
return _(
"one image per human player");
590 case SHOW_ALL:
return _(
"all players on a single image");
591 case SHOW_PLRNAME:
return _(
"just the player named with 'plrname'");
592 case SHOW_PLRID:
return _(
"just the player specified with 'plrid'");
593 case SHOW_PLRBV:
return _(
"one image per player in 'plrbv'");
605 enum show_player showplr;
606 enum mapimg_layer layer;
607 struct astring defaults[MAPDEF_COUNT];
618 for (tool = imagetool_begin(); tool != imagetool_end();
619 tool = imagetool_next(tool)) {
620 enum imageformat format;
622 const char *separator =
"";
628 astr_add(&str_format,
" - '%s': ", imagetool_name(
tool));
630 for (format = imageformat_begin(); format != imageformat_end();
631 format = imageformat_next(format)) {
633 const char *
name = imageformat_name(format);
642 if (
tool != imagetool_max()) {
648 for (showplr = show_player_begin(); showplr != show_player_end();
649 showplr = show_player_next(showplr)) {
650 const char *nameptr = show_player_name(showplr);
652 if (nameptr != NULL) {
657 if (showplr != show_player_max()) {
666 "(%s|%s)", imagetool_name(pmapdef->
tool),
667 imageformat_name(pmapdef->
format));
670 "(%s)", show_player_name(pmapdef->
player.
show));
674 astr_set(&defaults[MAPDEF_ZOOM],
"(%d)", pmapdef->
zoom);
677 astr_set(&defaults[MAPDEF_MAP],
"(");
678 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
679 layer = mapimg_layer_next(layer)) {
680 if (pmapdef->
layers[layer]) {
681 astr_add(&defaults[MAPDEF_MAP],
"%c", mapimg_layer_name(layer)[0]);
684 astr_add(&defaults[MAPDEF_MAP],
")");
692 _(
"This command controls the creation of map images. Supported "
694 " define <mapdef> - define a map image; returns numeric <id>\n"
695 " show <id>|all - list map image definitions or show a specific one\n"
696 " create <id>|all - manually save image(s) for current map state\n"
697 " delete <id>|all - delete map image definition(s)\n"
698 " colortest - create test image(s) showing all colors\n"
700 "Multiple definitions can be active at once. "
701 "A definition <mapdef> consists of colon-separated options:\n"
703 "option (default) description\n"
705 "format=<[tool|]format> %-10s file format\n"
706 "show=<show> %-10s which players to show\n"
707 " plrname=<name> player name\n"
708 " plrid=<id> numeric player id\n"
709 " plrbv=<bit vector> see example; first char = id 0\n"
710 "turns=<turns> %-10s save image each <turns> turns\n"
711 " (0=no autosave, save with 'create')\n"
712 "zoom=<zoom> %-10s magnification factor (1-5)\n"
713 "map=<map> %-10s which map layers to draw\n"
715 "<[tool|]format> = use image format <format>, optionally specifying "
716 "toolkit <tool>. The following toolkits and formats are compiled in:\n"
719 "<show> determines which players are represented and how many "
720 "images are saved by this definition:\n"
723 "<map> can contain one or more of the following layers:\n"
724 " - 'a' show area within borders of specified players\n"
725 " - 'b' show borders of specified players\n"
726 " - 'c' show cities of specified players\n"
727 " - 'f' show fog of war (single-player images only)\n"
728 " - 'k' show only player knowledge (single-player images only)\n"
729 " - 't' full display of terrain types\n"
730 " - 'u' show units of specified players\n"
732 "Examples of <mapdef>:\n"
733 " 'zoom=1:map=tcub:show=all:format=ppm|ppm'\n"
734 " 'zoom=2:map=tcub:show=each:format=png'\n"
735 " 'zoom=1:map=tcub:show=plrname:plrname=Otto:format=gif'\n"
736 " 'zoom=3:map=cu:show=plrbv:plrbv=010011:format=jpg'\n"
737 " 'zoom=1:map=t:show=none:format=magick|jpg'"),
766#define NUM_MAX_MAPARGS 10
767#define NUM_MAX_MAPOPTS 2
770 struct mapdef *pmapdef = NULL;
772 int nmapargs, nmapopts, i;
784 MAPIMG_LOG(
_(
"map definition string too long (max %d characters)"),
790 MAPIMG_LOG(
_(
"maximum number of map definitions reached (%d)"),
796 pmapdef = mapdef_list_get(
mapimg.mapdef, i);
798 MAPIMG_LOG(
_(
"duplicate of map image definition %d ('%s')"), i,
809 for (i = 0; i < nmapargs; i++) {
814 enum mapdef_arg arg = mapdef_arg_by_name(mapopts[0], strcmp);
815 if (mapdef_arg_is_valid(arg)) {
819 MAPIMG_LOG(
_(
"unknown map option: '%s'"), mapargs[i]);
823 MAPIMG_LOG(
_(
"unknown map option: '%s'"), mapargs[i]);
839 MAPIMG_LOG(
_(
"'show=%s' but no player name 'plrname'"),
840 show_player_name(SHOW_PLRNAME));
846 MAPIMG_LOG(
_(
"'show=%s' but no player id 'plrid'"),
847 show_player_name(SHOW_PLRID));
853 MAPIMG_LOG(
_(
"'show=%s' but no player bitvector 'plrbv'"),
854 show_player_name(SHOW_PLRBV));
877 mapdef_list_append(
mapimg.mapdef, pmapdef);
884#undef NUM_MAX_MAPARGS
885#undef NUM_MAX_MAPOPTS
890#define NUM_MAX_FORMATARGS 2
892 const char *val,
bool check)
895 log_debug(
"Option '%s' for mapimg used more than once.",
896 mapdef_arg_name(arg));
915 if (nformatargs == 2) {
916 tool = imagetool_by_name(formatargs[0], strcmp);
917 format = imageformat_by_name(formatargs[1], strcmp);
919 if (imageformat_is_valid(
format) && imagetool_is_valid(
tool)) {
931 tool = imagetool_by_name(formatargs[0], strcmp);
932 if (imagetool_is_valid(
tool)) {
943 format = imageformat_by_name(formatargs[0], strcmp);
944 if (imageformat_is_valid(format)) {
970 int len = strlen(val), l;
971 enum mapimg_layer layer;
974 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
975 layer = mapimg_layer_next(layer)) {
979 for (l = 0; l <
len; l++) {
981 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
982 layer = mapimg_layer_next(layer)) {
983 if (val[l] == mapimg_layer_name(layer)[0]) {
1004 for (i = 0; i < strlen(val); i++) {
1005 if (!strchr(
"01", val[i])) {
1006 MAPIMG_LOG(
_(
"invalid character in bitvector: '%c' (%s)"),
1009 }
else if (val[i] ==
'1') {
1025 if (sscanf(val,
"%d", &plrid) != 0) {
1027 MAPIMG_LOG(
_(
"'plrid' should be between 0 and %d"),
1038 case MAPDEF_PLRNAME:
1042 if (strlen(val) >
sizeof(pmapdef->
player.
name)) {
1043 MAPIMG_LOG(
_(
"player name too long: '%s' (max: %lu)"), val,
1044 (
unsigned long)
sizeof(pmapdef->
player.
name));
1055 enum show_player showplr;
1057 showplr = show_player_by_name(val, strcmp);
1058 if (show_player_is_valid(showplr)) {
1071 if (sscanf(val,
"%d", &turns) != 0) {
1072 if (turns < 0 || turns > 99) {
1073 MAPIMG_LOG(
_(
"'turns' should be between 0 and 99"));
1076 pmapdef->
turns = turns;
1089 if (sscanf(val,
"%d", &zoom) != 0) {
1090 if (zoom < 1 || zoom > 5) {
1091 MAPIMG_LOG(
_(
"'zoom' factor should be between 1 and 5"));
1094 pmapdef->
zoom = zoom;
1110 MAPIMG_LOG(
_(
"invalid value for option '%s': '%s'"),
1111 mapdef_arg_name(arg), val);
1114#undef NUM_MAX_FORMATARGS
1122 struct mapdef *pmapdef = NULL;
1129 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
1132 switch (pmapdef->
status) {
1133 case MAPIMG_STATUS_UNKNOWN:
1134 MAPIMG_LOG(
_(
"map definition not checked (game not started)"));
1137 case MAPIMG_STATUS_ERROR:
1141 case MAPIMG_STATUS_OK:
1154 static struct strvec *format_list = NULL;
1156 if (NULL == format_list) {
1157 enum imagetool tool;
1161 for (tool = imagetool_begin(); tool != imagetool_end();
1162 tool = imagetool_next(tool)) {
1163 enum imageformat format;
1170 for (format = imageformat_begin(); format != imageformat_end();
1171 format = imageformat_next(format)) {
1173 char str_format[64];
1175 fc_snprintf(str_format,
sizeof(str_format),
"%s|%s",
1176 imagetool_name(
tool), imageformat_name(format));
1191 static char default_format[64];
1193 fc_snprintf(default_format,
sizeof(default_format),
"%s|%s",
1197 return default_format;
1205 struct mapdef *pmapdef = NULL;
1213 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
1214 mapdef_list_remove(
mapimg.mapdef, pmapdef);
1224 struct mapdef *pmapdef = NULL;
1231 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
1239 "definition %d\n"),
id);
1240 if (pmapdef->
status == MAPIMG_STATUS_ERROR) {
1242 mapimg_status_name(pmapdef->
status), pmapdef->
error);
1245 mapimg_status_name(pmapdef->
status));
1250 imagetool_name(pmapdef->
tool));
1252 imageformat_name(pmapdef->
format));
1256 pmapdef->
layers[MAPIMG_LAYER_AREA] ?
_(
"yes") :
_(
"no"));
1258 pmapdef->
layers[MAPIMG_LAYER_BORDERS] ?
_(
"yes") :
_(
"no"));
1260 pmapdef->
layers[MAPIMG_LAYER_CITIES] ?
_(
"yes") :
_(
"no"));
1262 pmapdef->
layers[MAPIMG_LAYER_FOGOFWAR] ?
_(
"yes") :
_(
"no"));
1264 pmapdef->
layers[MAPIMG_LAYER_KNOWLEDGE] ?
_(
"yes") :
_(
"no"));
1266 pmapdef->
layers[MAPIMG_LAYER_TERRAIN] ?
_(
"full") :
_(
"basic"));
1268 pmapdef->
layers[MAPIMG_LAYER_UNITS] ?
_(
"yes") :
_(
"no"));
1294 if (pmapdef->
status == MAPIMG_STATUS_ERROR) {
1296 mapimg_status_name(pmapdef->
status), pmapdef->
error);
1299 mapimg_status_name(pmapdef->
status));
1312 struct mapdef *pmapdef = NULL;
1319 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
1338 struct timer *timer_cpu, *timer_user;
1349 if (pmapdef->
status != MAPIMG_STATUS_OK) {
1350 MAPIMG_LOG(
_(
"map definition not checked or error"));
1383 if (!
img_save(pimg, mapimgfile, path)) {
1406 if (!
img_save(pimg, mapimgfile, path)) {
1419 log_debug(
"Image generation time: %g seconds (%g apparent)",
1443 int max_playercolor =
mapimg.mapimg_plrcolor_count();
1446 enum imagetool
tool;
1457 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1464 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1465 if (i >= max_playercolor) {
1477 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1484 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1485 if (i >= max_terraincolor) {
1499 for (
tool = imagetool_begin();
tool != imagetool_end();
1511 for (format = imageformat_begin(); format != imageformat_end();
1512 format = imageformat_next(format)) {
1515 const char *tname = imagetool_name(
tool);
1518 pmapdef->
format = format;
1520 if (tname != NULL) {
1521 fc_snprintf(buf,
sizeof(buf),
"colortest-%s", tname);
1528 if (!
img_save(pimg, mapimgfile, path)) {
1566 MAPIMG_LOG(
_(
"no map definition with id %d"),
id);
1578 enum mapimg_layer layer;
1579 char buf[MAPIMG_LAYER_COUNT + 1];
1582 if (pmapdef->
status != MAPIMG_STATUS_OK) {
1583 MAPIMG_LOG(
_(
"map definition not checked or error"));
1590 imagetool_name(pmapdef->
tool),
1591 imageformat_name(pmapdef->
format));
1595 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
1596 layer = mapimg_layer_next(layer)) {
1597 if (pmapdef->
layers[layer]) {
1598 buf[i++] = mapimg_layer_name(layer)[0];
1618 cat_snprintf(
str, str_len,
"show=%s:", show_player_name(SHOW_PLRNAME));
1641 if (!recheck && pmapdef->
status == MAPIMG_STATUS_ERROR) {
1666 if (pplayer != NULL) {
1669 pmapdef->
status = MAPIMG_STATUS_ERROR;
1672 _(
"unknown player name: '%s'"), pmapdef->
player.
name);
1682 if (pplayer != NULL) {
1685 pmapdef->
status = MAPIMG_STATUS_ERROR;
1688 _(
"invalid player id: %d"), pmapdef->
player.
id);
1695 pmapdef->
status = MAPIMG_STATUS_OK;
1704static void mapimg_log(
const char *file,
const char *function,
int line,
1705 const char *format, ...)
1709 va_start(args, format);
1733 static char mapstr[256];
1735 enum mapimg_layer layer;
1736 int i, count = 0, plr_id = -1;
1768 }
else if (count == 1 && plr_id != -1) {
1769 fc_snprintf(str_show,
sizeof(str_show),
"%03d%s", plr_id,
1776 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
1777 layer = mapimg_layer_next(layer)) {
1778 if (pmapdef->
layers[layer]) {
1779 const char *lname = mapimg_layer_name(layer);
1781 if (lname != NULL) {
1811 pmapdef->
maparg[0] =
'\0';
1812 pmapdef->
error[0] =
'\0';
1813 pmapdef->
status = MAPIMG_STATUS_UNKNOWN;
1821 pmapdef->
layers[MAPIMG_LAYER_BORDERS] =
TRUE;
1823 pmapdef->
layers[MAPIMG_LAYER_KNOWLEDGE] =
TRUE;
1840 if (pmapdef == NULL) {
1955 sizeof(*pimg->
map));
1981 log_error(
"invalid index: 0 <= %d < %d", mindex,
1993 const struct img *pimg)
2008 int base_x, base_y, i, mindex;
2044 enum imagetool tool = pimg->
def->
tool;
2095#ifdef HAVE_MAPIMG_MAGICKWAND
2096#define SET_COLOR(str, pcolor) \
2097 fc_snprintf(str, sizeof(str), "rgb(%d,%d,%d)", \
2098 pcolor->r, pcolor->g, pcolor->b);
2099static bool img_save_magickwand(
const struct img *pimg,
2100 const char *mapimgfile)
2103 struct player *pplr_now = NULL, *pplr_only = NULL;
2106 char str_color[32], comment[2048] =
"",
title[258];
2108 int x, y, xxx, yyy, row, i, mindex, plrwidth, plroffset, textoffset;
2112 sizeof(imagefile))) {
2119 PixelWand **pmw, *pw;
2122 MagickWandGenesis();
2124 mw = NewMagickWand();
2125 dw = NewDrawingWand();
2126 pw = NewPixelWand();
2138 PixelSetColor(pw, str_color);
2139 MagickNewImage(mw, img_width, img_height, pw);
2159 SET_COLOR(str_color,
pcolor);
2166 pmw = PixelGetNextIteratorRow(imw, &plr_color_square);
2169 PixelSetColor(pmw[x], str_color);
2171 PixelSyncIterator(imw);
2173 DestroyPixelIterator(imw);
2178 plroffset = (map_width -
MIN(map_width, plrwidth *
player_count())) / 2;
2186 pmw = PixelGetNextIteratorRow(imw, &map_width);
2189 for (x = plroffset; x < map_width; x++) {
2190 i = (x - plroffset) / plrwidth;
2200 SET_COLOR(str_color,
pcolor);
2201 PixelSetColor(pmw[x], str_color);
2202 }
else if (pplr_only != NULL) {
2218 SET_COLOR(str_color,
pcolor);
2219 PixelSetColor(pmw[x], str_color);
2223 PixelSyncIterator(imw);
2225 DestroyPixelIterator(imw);
2230 PixelSetColor(pw, str_color);
2231 DrawSetFillColor(dw, pw);
2232 DrawSetFont(dw,
"Times-New-Roman");
2236 (
unsigned char *)
title);
2237 MagickDrawImage(mw, dw);
2244 : 0), map_width, map_height);
2246 for (y = 0; y < pimg->
imgsize.
y; y++) {
2248 for (yyy = 0; yyy < pimg->
def->
zoom; yyy++) {
2250 pmw = PixelGetNextIteratorRow(imw, &map_width);
2253 for (x = 0; x < pimg->
imgsize.
x; x++) {
2258 SET_COLOR(str_color,
pcolor);
2261 for (xxx = 0; xxx < pimg->
def->
zoom; xxx++) {
2262 row = x * pimg->
def->
zoom + xxx;
2263 PixelSetColor(pmw[row], str_color);
2267 PixelSyncIterator(imw);
2270 DestroyPixelIterator(imw);
2272 cat_snprintf(comment,
sizeof(comment),
"map definition: %s\n",
2283 MagickCommentImage(mw, comment);
2285 if (!MagickWriteImage(mw, imagefile)) {
2286 MAPIMG_LOG(
_(
"error saving map image '%s'"), imagefile);
2289 log_verbose(
"Map image saved as '%s'.", imagefile);
2292 DestroyDrawingWand(dw);
2293 DestroyPixelWand(pw);
2294 DestroyMagickWand(mw);
2296 MagickWandTerminus();
2310 int x, y, xxx, yyy, mindex;
2313 if (pimg->
def->
format != IMGFORMAT_PPM) {
2314 MAPIMG_LOG(
_(
"the ppm toolkit can only create images in the ppm "
2319 if (!
img_filename(mapimgfile, IMGFORMAT_PPM, ppmname,
sizeof(ppmname))) {
2326 MAPIMG_LOG(
_(
"could not open file: %s"), ppmname);
2330 fprintf(fp,
"P3\n");
2331 fprintf(fp,
"# version:2\n");
2332 fprintf(fp,
"# map definition: %s\n", pimg->
def->
maparg);
2335 fprintf(fp,
"# color test\n");
2345 fprintf(fp,
"# no players\n");
2350 fprintf(fp,
"255\n");
2353 for (y = 0; y < pimg->
imgsize.
y; y++) {
2355 for (yyy = 0; yyy < pimg->
def->
zoom; yyy++) {
2357 for (x = 0; x < pimg->
imgsize.
x; x++) {
2362 for (xxx = 0; xxx < pimg->
def->
zoom; xxx++) {
2382 char *filename,
size_t filename_len)
2386 fc_snprintf(filename, filename_len,
"%s.map.%s", mapimgfile,
2387 imageformat_name(format));
2397 static char buf[512];
2401 "playerno:%d:color:(%3d, %3d, %3d):name:\"%s\"",
2417 struct player *pplayer = NULL;
2418 struct player *plr_tile = NULL, *plr_city = NULL, *plr_unit = NULL;
2420 struct terrain *pterrain = NULL;
2421 bool plr_knowledge = pimg->
def->
layers[MAPIMG_LAYER_KNOWLEDGE];
2430 tile_knowledge =
mapimg.mapimg_tile_known(ptile, pplayer,
2438 if (plr_knowledge && pplayer != NULL && tile_knowledge ==
TILE_UNKNOWN) {
2444 pterrain =
mapimg.mapimg_tile_terrain(ptile, pplayer, plr_knowledge);
2445 if (pimg->
def->
layers[MAPIMG_LAYER_TERRAIN]) {
2447 pixel = pimg->
pixel_tile(ptile, pplayer, plr_knowledge);
2452 pixel = pimg->
pixel_tile(ptile, pplayer, plr_knowledge);
2461 plr_tile =
mapimg.mapimg_tile_owner(ptile, pplayer, plr_knowledge);
2467 pixel = pimg->
pixel_tile(ptile, pplayer, plr_knowledge);
2470 }
else if (pimg->
def->
layers[MAPIMG_LAYER_BORDERS]
2472 || (plr_knowledge && pplayer != NULL))) {
2475 pixel = pimg->
pixel_border(ptile, pplayer, plr_knowledge);
2482 plr_city =
mapimg.mapimg_tile_city(ptile, pplayer, plr_knowledge);
2483 plr_unit =
mapimg.mapimg_tile_unit(ptile, pplayer, plr_knowledge);
2484 if (pimg->
def->
layers[MAPIMG_LAYER_CITIES] && plr_city) {
2487 || (plr_knowledge && pplayer != NULL)) {
2490 pixel = pimg->
pixel_city(ptile, pplayer, plr_knowledge);
2494 }
else if (pimg->
def->
layers[MAPIMG_LAYER_UNITS] && plr_unit) {
2497 || (plr_knowledge && pplayer != NULL)) {
2500 pixel = pimg->
pixel_unit(ptile, pplayer, plr_knowledge);
2540 const struct player *pplayer,
2559 const struct player *pplayer,
2595 const struct player *pplayer,
2618 const struct player *pplayer,
2660 const struct player *pplayer,
2671 if (NULL == ptile) {
2676 owner =
mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
2677 if (NULL ==
owner) {
2683 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2685 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2686 knowledge) !=
owner)) {
2696 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2698 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2699 knowledge) !=
owner)) {
2709 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2711 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2712 knowledge) !=
owner)) {
2722 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2724 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2725 knowledge) !=
owner)) {
2758 const struct player *pplayer,
2779 const struct player *pplayer,
2820 const struct player *pplayer,
2845 const struct player *pplayer,
2884 const struct player *pplayer,
2895 if (NULL == ptile) {
2900 owner =
mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
2901 if (NULL ==
owner) {
2907 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2909 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2910 knowledge) !=
owner)) {
2919 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2921 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2922 knowledge) !=
owner)) {
2929 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2931 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2932 knowledge) !=
owner)) {
2940 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2942 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2943 knowledge) !=
owner)) {
2952 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2954 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2955 knowledge) !=
owner)) {
2962 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
2964 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
2965 knowledge) !=
owner)) {
2997 const struct player *pplayer,
3016 const struct player *pplayer,
3055 const struct player *pplayer,
3078 const struct player *pplayer,
3120 const struct player *pplayer,
3131 if (NULL == ptile) {
3136 owner =
mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
3137 if (NULL ==
owner) {
3143 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
3145 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
3146 knowledge) !=
owner)) {
3156 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
3158 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
3159 knowledge) !=
owner)) {
3166 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
3168 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
3169 knowledge) !=
owner)) {
3176 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
3178 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
3179 knowledge) !=
owner)) {
3189 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
3191 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
3192 knowledge) !=
owner)) {
3199 if (!pnext || (
mapimg.mapimg_tile_known(pnext, pplayer,
3201 &&
mapimg.mapimg_tile_owner(pnext, pplayer,
3202 knowledge) !=
owner)) {
3247 for (; i >= 0; i--) {
3248 buf[i] =
BV_ISSET(plrbv, i) ?
'1' :
'0';
3298 static struct rgbcolor rgb_special[] = {
3305 { 255, 255, 255, NULL},
3311 return &rgb_special[imgcolor];
3327 return pplayer->
rgb;
3341 return pterrain->
rgb;
void astr_free(struct astring *astr)
void astr_set(struct astring *astr, const char *format,...)
void astr_init(struct astring *astr)
void astr_add(struct astring *astr, const char *format,...)
static size_t astr_len(const struct astring *astr) fc__attribute((nonnull(1)))
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
#define BV_DEFINE(name, bits)
#define BV_ISSET(bv, bit)
#define BV_ISSET_ANY(vec)
const char * calendar_text(void)
struct canvas int int struct sprite bool int int fog_y struct canvas struct sprite struct color * pcolor
void free_tokens(char **tokens, size_t ntokens)
int get_tokens(const char *str, char **tokens, size_t num_tokens, const char *delimiterset)
#define MAX_NUM_PLAYER_SLOTS
int generate_save_name(const char *format, char *buf, int buflen, const char *reason)
#define fc_assert_ret(condition)
#define log_verbose(message,...)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
#define log_error(message,...)
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
#define topo_has_flag(topo, flag)
#define MAP_TO_NATIVE_POS(pnat_x, pnat_y, map_x, map_y)
#define whole_map_iterate(_map, _tile)
#define whole_map_iterate_end
#define index_to_map_pos(pmap_x, pmap_y, mindex)
static bv_pixel pixel_fogofwar_hexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static int bvplayers_count(const struct mapdef *pmapdef)
static bv_pixel pixel_fogofwar_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
#define MAPIMG_DEFAULT_IMGFORMAT
static char error_buffer[MAX_LEN_ERRORBUF]
bool mapimg_id2str(int id, char *str, size_t str_len)
mapimg_tile_player_func mapimg_tile_owner
static bool mapimg_test(int id)
bool(* img_save_func)(const struct img *pimg, const char *mapimgfile)
const char * mapimg_get_format_default(void)
bool mapimg_initialised(void)
static bool mapimg_def2str(struct mapdef *pmapdef, char *str, size_t str_len)
static void base_coor_hexa(struct img *pimg, int *base_x, int *base_y, int x, int y)
bool mapimg_colortest(const char *savename, const char *path)
#define img_toolkit_iterate(_toolkit)
#define magickwand_size_t
static bv_pixel pixel_city_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
struct mapdef * mapimg_isvalid(int id)
static bv_pixel pixel_border_hexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
mapimg_tile_terrain_func mapimg_tile_terrain
mapimg_tile_player_func mapimg_tile_city
static struct mapdef * mapdef_new(bool colortest)
static bool img_save_ppm(const struct img *pimg, const char *mapimgfile)
static void img_destroy(struct img *pimg)
#define IMG_BORDER_HEIGHT
#define IMG_SPACER_HEIGHT
static struct img * img_new(struct mapdef *mapdef, int topo, int xsize, int ysize)
bv_pixel(* plot_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
mapimg_tile_player_func mapimg_tile_unit
static void img_plot(struct img *pimg, int x, int y, const struct rgbcolor *pcolor, const bv_pixel pixel)
static bool img_filename(const char *mapimgfile, enum imageformat format, char *filename, size_t filename_len)
static const struct rgbcolor * imgcolor_terrain(const struct terrain *pterrain)
static void img_createmap(struct img *pimg)
static const char * showname_help(enum show_player showplr)
static void mapimg_log(const char *file, const char *function, int line, const char *format,...) fc__attribute((__format__(__printf__
void mapimg_init(mapimg_tile_known_func mapimg_tile_known, mapimg_tile_terrain_func mapimg_tile_terrain, mapimg_tile_player_func mapimg_tile_owner, mapimg_tile_player_func mapimg_tile_city, mapimg_tile_player_func mapimg_tile_unit, mapimg_plrcolor_count_func mapimg_plrcolor_count, mapimg_plrcolor_get_func mapimg_plrcolor_get)
static bv_pixel pixel_border_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
#define mapdef_list_iterate_end
static int img_index(const int x, const int y, const struct img *pimg)
static struct tile_shape tile_rect
const struct strvec * mapimg_get_format_list(void)
mapimg_tile_known_func mapimg_tile_known
static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path)
static bv_pixel pixel_city_hexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static bv_pixel pixel_fogofwar_isohexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
void(* base_coor_func)(struct img *pimg, int *base_x, int *base_y, int x, int y)
#define img_toolkit_iterate_end
mapimg_plrcolor_get_func mapimg_plrcolor_get
static bv_pixel pixel_tile_isohexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
mapimg_plrcolor_count_func mapimg_plrcolor_count
bool mapimg_define(const char *maparg, bool check)
bool mapimg_delete(int id)
static const struct rgbcolor * imgcolor_player(int plr_id)
#define MAPIMG_DEFAULT_IMGTOOL
#define MAPIMG_LOG(format,...)
static bv_pixel pixel_tile_hexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static bv_pixel pixel_city_isohexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static void base_coor_rect(struct img *pimg, int *base_x, int *base_y, int x, int y)
static struct tile_shape tile_hexa
#define MAPIMG_ASSERT_RET_VAL(cond, expr)
static char * mapimg_generate_name(struct mapdef *pmapdef)
static bv_pixel pixel_unit_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static bv_pixel pixel_unit_hexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static void img_plot_tile(struct img *pimg, const struct tile *ptile, const struct rgbcolor *pcolor, const bv_pixel pixel)
static void base_coor_isohexa(struct img *pimg, int *base_x, int *base_y, int x, int y)
static const int img_toolkits_count
static void mapdef_destroy(struct mapdef *pmapdef)
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
static const struct rgbcolor * imgcolor_special(enum img_special imgcolor)
static bv_pixel pixel_border_isohexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
#define mapdef_list_iterate(mapdef_list, pmapdef)
const char * mapimg_error(void)
#define GEN_TOOLKIT(_tool, _format_default, _formats, _save_func, _help)
static const char * img_playerstr(const struct player *pplayer)
static struct tile_shape tile_isohexa
bool mapimg_show(int id, char *str, size_t str_len, bool detail)
static bool mapimg_define_arg(struct mapdef *pmapdef, enum mapdef_arg arg, const char *val, bool check)
static bool mapimg_checkplayers(struct mapdef *pmapdef, bool recheck)
static const struct toolkit * img_toolkit_get(enum imagetool tool)
static bv_pixel pixel_unit_isohexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static void img_set_pixel(struct img *pimg, const int mindex, const struct rgbcolor *pcolor)
static bv_pixel pixel_tile_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
static struct toolkit img_toolkits[]
#define NUM_MAX_FORMATARGS
char * mapimg_help(const char *cmdname)
static const char * bvplayers_str(const bv_player plrbv)
struct rgbcolor *(* mapimg_plrcolor_get_func)(int)
int(* mapimg_plrcolor_count_func)(void)
enum known_type(* mapimg_tile_known_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
struct terrain *(* mapimg_tile_terrain_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
struct player *(* mapimg_tile_player_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
#define fc_calloc(n, esz)
struct player * player_by_name_prefix(const char *name, enum m_pre_result *result)
struct player * player_by_number(const int player_id)
int player_slot_count(void)
int player_number(const struct player *pplayer)
const char * player_name(const struct player *pplayer)
int player_index(const struct player *pplayer)
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
bool gives_shared_vision(const struct player *me, const struct player *them)
#define players_iterate_end
#define players_iterate(_pplayer)
bool make_dir(const char *pathname)
bool path_is_absolute(const char *filename)
void strvec_append(struct strvec *psv, const char *string)
struct strvec * strvec_new(void)
struct packet_game_info info
struct tile_shape * tileshape
char title[MAX_LEN_MAPDEF]
const struct rgbcolor ** map
enum mapimg_status status
char error[MAX_LEN_MAPDEF]
struct mapdef::@45 player
bool layers[MAPIMG_LAYER_COUNT]
char maparg[MAX_LEN_MAPARG]
enum borders_mode borders
int fc_snprintf(char *str, size_t n, const char *format,...)
size_t fc_strlcpy(char *dest, const char *src, size_t n)
int fc_strcasecmp(const char *str0, const char *str1)
int cat_snprintf(char *str, size_t n, const char *format,...)
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
FILE * fc_fopen(const char *filename, const char *opentype)
#define sz_strlcpy(dest, src)
#define sz_strlcat(dest, src)
Terrain_type_id terrain_count(void)
struct terrain * terrain_by_number(const Terrain_type_id type)
#define is_ocean(pterrain)
struct timer * timer_new(enum timer_timetype type, enum timer_use use)
void timer_destroy(struct timer *t)
void timer_start(struct timer *t)
double timer_read_seconds(struct timer *t)