34 #include <QImageWriter>
53 #define NUM_PIXEL TILE_SIZE *TILE_SIZE
65 const struct player *pplayer,
bool knowledge);
71 .
x = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
72 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5},
73 .y = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
74 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5}};
77 const struct player *pplayer,
80 const struct player *pplayer,
83 const struct player *pplayer,
86 const struct player *pplayer,
89 const struct player *pplayer,
98 2, 3, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
99 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 2, 3,
102 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
103 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7,
107 const struct player *pplayer,
110 const struct player *pplayer,
113 const struct player *pplayer,
116 const struct player *pplayer,
119 const struct player *pplayer,
126 .
x = {2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7,
127 0, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 2, 3, 4, 5},
128 .y = {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
129 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5}};
132 const struct player *pplayer,
135 const struct player *pplayer,
138 const struct player *pplayer,
141 const struct player *pplayer,
144 const struct player *pplayer,
151 #define ARG_PLRBV "plrbv"
152 #define ARG_PLRID "plrid"
153 #define ARG_PLRNAME "plrname"
156 #define SPECENUM_NAME mapdef_arg
157 #define SPECENUM_VALUE0 MAPDEF_FORMAT
158 #define SPECENUM_VALUE0NAME "format"
159 #define SPECENUM_VALUE1 MAPDEF_MAP
160 #define SPECENUM_VALUE1NAME "map"
161 #define SPECENUM_VALUE2 MAPDEF_PLRBV
162 #define SPECENUM_VALUE2NAME ARG_PLRBV
163 #define SPECENUM_VALUE3 MAPDEF_PLRID
164 #define SPECENUM_VALUE3NAME ARG_PLRID
165 #define SPECENUM_VALUE4 MAPDEF_PLRNAME
166 #define SPECENUM_VALUE4NAME ARG_PLRNAME
167 #define SPECENUM_VALUE5 MAPDEF_SHOW
168 #define SPECENUM_VALUE5NAME "show"
169 #define SPECENUM_VALUE6 MAPDEF_TURNS
170 #define SPECENUM_VALUE6NAME "turns"
171 #define SPECENUM_VALUE7 MAPDEF_ZOOM
172 #define SPECENUM_VALUE7NAME "zoom"
173 #define SPECENUM_COUNT MAPDEF_COUNT
174 #include "specenum_gen.h"
179 #define SPECENUM_NAME show_player
180 #define SPECENUM_VALUE0 SHOW_NONE
181 #define SPECENUM_VALUE0NAME "none"
182 #define SPECENUM_VALUE1 SHOW_EACH
183 #define SPECENUM_VALUE1NAME "each"
184 #define SPECENUM_VALUE2 SHOW_HUMAN
185 #define SPECENUM_VALUE2NAME "human"
186 #define SPECENUM_VALUE3 SHOW_ALL
187 #define SPECENUM_VALUE3NAME "all"
189 #define SPECENUM_VALUE4 SHOW_PLRNAME
190 #define SPECENUM_VALUE4NAME ARG_PLRNAME
192 #define SPECENUM_VALUE5 SHOW_PLRID
193 #define SPECENUM_VALUE5NAME ARG_PLRID
195 #define SPECENUM_VALUE6 SHOW_PLRBV
196 #define SPECENUM_VALUE6NAME ARG_PLRBV
197 #include "specenum_gen.h"
204 #define SPECENUM_NAME mapimg_status
205 #define SPECENUM_VALUE0 MAPIMG_STATUS_UNKNOWN
206 #define SPECENUM_VALUE0NAME _("not checked")
207 #define SPECENUM_VALUE1 MAPIMG_STATUS_OK
208 #define SPECENUM_VALUE1NAME _("OK")
209 #define SPECENUM_VALUE2 MAPIMG_STATUS_ERROR
210 #define SPECENUM_VALUE2NAME _("error")
211 #include "specenum_gen.h"
213 #define MAX_LEN_MAPARG MAX_LEN_MAPDEF
214 #define MAX_NUM_MAPIMG 10
221 const char *val,
bool check);
231 enum mapimg_status
status;
237 enum show_player
show;
255 #define SPECLIST_TAG mapdef
256 #define SPECLIST_TYPE struct mapdef
259 #define mapdef_list_iterate(mapdef_list, pmapdef) \
260 TYPED_LIST_ITERATE(struct mapdef, mapdef_list, pmapdef)
261 #define mapdef_list_iterate_end LIST_ITERATE_END
296 static inline int img_index(
const int x,
const int y,
297 const struct img *pimg);
299 const struct rgbcolor *pcolor,
const bv_pixel pixel);
302 const bv_pixel pixel);
303 static bool img_save(
const struct img *pimg,
const char *mapimgfile,
305 static bool img_filename(
const char *mapimgfile,
const QByteArray &format,
306 char *filename,
size_t filename_len);
310 #define MAX_LEN_ERRORBUF 1024
313 static void mapimg_log(
const char *file,
const char *
function,
int line,
314 const char *format, ...)
316 #define MAPIMG_LOG(format, ...) \
317 mapimg_log(__FILE__, __FUNCTION__, __FC_LINE__, format, ##__VA_ARGS__)
318 #define MAPIMG_ASSERT_RET_VAL(cond, expr) \
319 fc_assert_action(cond, MAPIMG_LOG(_("internal error")); return (expr))
363 mapimg.mapdef = mapdef_list_new();
392 if (mapdef_list_size(
mapimg.mapdef) > 0) {
395 mapdef_list_remove(
mapimg.mapdef, pmapdef);
412 mapdef_list_destroy(
mapimg.mapdef);
426 return mapdef_list_size(
mapimg.mapdef);
436 return _(
"no players, only terrain");
438 return _(
"one image per player");
440 return _(
"one image per human player");
442 return _(
"all players on a single image");
444 return _(
"just the player named with 'plrname'");
446 return _(
"just the player specified with 'plrid'");
448 return _(
"one image per player in 'plrbv'");
460 enum show_player showplr;
461 enum mapimg_layer layer;
462 QString defaults[MAPDEF_COUNT];
463 QString str_showplr, help;
466 if (help.length() > 0) {
473 QImageWriter::supportedImageFormats().join(QByteArrayLiteral(
", "));
476 for (showplr = show_player_begin(); showplr != show_player_end();
477 showplr = show_player_next(showplr)) {
478 const char *nameptr = show_player_name(showplr);
480 if (nameptr !=
nullptr) {
484 str_showplr += QStringLiteral(
" - %1 %2")
487 if (showplr != show_player_max()) {
488 str_showplr += QStringLiteral(
"\n");
494 defaults[MAPDEF_FORMAT] =
496 defaults[MAPDEF_SHOW] =
497 QStringLiteral(
"(%1)").arg(show_player_name(pmapdef->
player.
show));
498 defaults[MAPDEF_TURNS] =
499 QStringLiteral(
"(%1)").arg(QString::number(pmapdef->
turns));
500 defaults[MAPDEF_ZOOM] = QStringLiteral(
"(%1)").arg(pmapdef->
zoom);
501 defaults[MAPDEF_MAP] = QStringLiteral(
"(");
502 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
503 layer = mapimg_layer_next(layer)) {
504 if (pmapdef->
layers[layer]) {
505 defaults[MAPDEF_MAP] +=
506 QStringLiteral(
"%1").arg(mapimg_layer_name(layer)[0]);
509 defaults[MAPDEF_MAP] += QLatin1String(
")");
518 _(
"This command controls the creation of map images. Supported "
520 " define <mapdef> - define a map image; returns numeric <id>\n"
521 " show <id>|all - list map image definitions or show a "
524 " create <id>|all - manually save image(s) for current map "
526 " delete <id>|all - delete map image definition(s)\n"
527 " colortest - create test image(s) showing all colors\n"
529 "Multiple definitions can be active at once. "
530 "A definition <mapdef> consists of colon-separated options:\n"
532 "option (default) description\n"
534 "format=<format> %1 file format\n"
535 "show=<show> %2 which players to show\n"
536 " plrname=<name> player name\n"
537 " plrid=<id> numeric player id\n"
538 " plrbv=<bit vector> see example; first char = "
541 "turns=<turns> %3 save image each <turns> turns\n"
542 " (0=no autosave, save with "
544 "zoom=<zoom> %4 magnification factor (1-5)\n"
545 "map=<map> %5 which map layers to draw\n"
547 "<format> = use image format <format>. The following formats "
551 "<show> determines which players are represented and how many "
552 "images are saved by this definition:\n"
555 "<map> can contain one or more of the following layers:\n"
556 " - 'a' show area within borders of specified players\n"
557 " - 'b' show borders of specified players\n"
558 " - 'c' show cities of specified players\n"
559 " - 'f' show fog of war (single-player images only)\n"
560 " - 'k' show only player knowledge (single-player images only)\n"
561 " - 't' full display of terrain types\n"
562 " - 'u' show units of specified players\n"
564 "Examples of <mapdef>:\n"
565 " 'zoom=1:map=tcub:show=all:format=png'\n"
566 " 'zoom=2:map=tcub:show=each:format=png'\n"
567 " 'zoom=1:map=tcub:show=plrname:plrname=Otto:format=bmp'\n"
568 " 'zoom=3:map=cu:show=plrbv:plrbv=010011:format=jpg'\n"
569 " 'zoom=1:map=t:show=none:format=jpg'"))
570 .arg(defaults[MAPDEF_FORMAT], -10)
571 .arg(defaults[MAPDEF_SHOW], -10)
572 .arg(defaults[MAPDEF_TURNS], -10)
573 .arg(defaults[MAPDEF_ZOOM], -10)
574 .arg(defaults[MAPDEF_MAP])
575 .arg(str_format, str_showplr);
592 struct mapdef *pmapdef =
nullptr;
593 QStringList mapargs, mapopts;
606 MAPIMG_LOG(
_(
"map definition string too long (max %d characters)"),
612 MAPIMG_LOG(
_(
"maximum number of map definitions reached (%d)"),
618 pmapdef = mapdef_list_get(
mapimg.mapdef, i);
620 MAPIMG_LOG(
_(
"duplicate of map image definition %d ('%s')"), i,
629 mapargs = QString(
maparg).split(QStringLiteral(
":"));
631 for (
const auto &str : qAsConst(mapargs)) {
633 mapopts = str.split(QStringLiteral(
"="));
635 if (mapopts.count() == 2) {
636 enum mapdef_arg arg =
637 mapdef_arg_by_name(qUtf8Printable(mapopts.at(0)), strcmp);
638 if (mapdef_arg_is_valid(arg)) {
643 MAPIMG_LOG(
_(
"unknown map option: '%s'"), qUtf8Printable(str));
647 MAPIMG_LOG(
_(
"unknown map option: '%s'"), qUtf8Printable(str));
660 MAPIMG_LOG(
_(
"'show=%s' but no player name 'plrname'"),
661 show_player_name(SHOW_PLRNAME));
667 MAPIMG_LOG(
_(
"'show=%s' but no player id 'plrid'"),
668 show_player_name(SHOW_PLRID));
674 MAPIMG_LOG(
_(
"'show=%s' but no player bitvector 'plrbv'"),
675 show_player_name(SHOW_PLRBV));
698 mapdef_list_append(
mapimg.mapdef, pmapdef);
705 #undef NUM_MAX_MAPARGS
706 #undef NUM_MAX_MAPOPTS
712 const char *val,
bool check)
716 log_debug(
"Option '%s' for mapimg used more than once.",
717 mapdef_arg_name(arg));
726 if (QImageWriter::supportedImageFormats().contains(val)) {
736 int len = qstrlen(val), l;
737 enum mapimg_layer layer;
740 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
741 layer = mapimg_layer_next(layer)) {
742 pmapdef->
layers[layer] =
false;
745 for (l = 0; l <
len; l++) {
747 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
748 layer = mapimg_layer_next(layer)) {
749 if (val[l] == mapimg_layer_name(layer)[0]) {
750 pmapdef->
layers[layer] =
true;
770 for (i = 0; i < qstrlen(val); i++) {
771 if (!strchr(
"01", val[i])) {
772 MAPIMG_LOG(
_(
"invalid character in bitvector: '%c' (%s)"),
775 }
else if (val[i] ==
'1') {
791 if (sscanf(val,
"%d", &plrid) != 0) {
793 MAPIMG_LOG(
_(
"'plrid' should be between 0 and %d"),
808 if (strlen(val) >
sizeof(pmapdef->
player.
name)) {
809 MAPIMG_LOG(
_(
"player name too long: '%s' (max: %lu)"), val,
810 (
unsigned long)
sizeof(pmapdef->
player.
name));
821 enum show_player showplr;
823 showplr = show_player_by_name(val, strcmp);
824 if (show_player_is_valid(showplr)) {
837 if (sscanf(val,
"%d", &
turns) != 0) {
838 if (turns < 0 || turns > 99) {
839 MAPIMG_LOG(
_(
"'turns' should be between 0 and 99"));
855 if (sscanf(val,
"%d", &
zoom) != 0) {
856 if (zoom < 1 || zoom > 5) {
857 MAPIMG_LOG(
_(
"'zoom' factor should be between 1 and 5"));
876 MAPIMG_LOG(
_(
"invalid value for option '%s': '%s'"), mapdef_arg_name(arg),
880 #undef NUM_MAX_FORMATARGS
888 struct mapdef *pmapdef =
nullptr;
895 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
898 switch (pmapdef->
status) {
899 case MAPIMG_STATUS_UNKNOWN:
900 MAPIMG_LOG(
_(
"map definition not checked (game not started)"));
903 case MAPIMG_STATUS_ERROR:
907 case MAPIMG_STATUS_OK:
920 struct mapdef *pmapdef =
nullptr;
928 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
929 mapdef_list_remove(
mapimg.mapdef, pmapdef);
939 struct mapdef *pmapdef =
nullptr;
946 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
954 _(
"Detailed information for map image "
957 if (pmapdef->
status == MAPIMG_STATUS_ERROR) {
959 _(
" - status: %s (%s)\n"),
960 mapimg_status_name(pmapdef->
status), pmapdef->
error);
963 mapimg_status_name(pmapdef->
status));
971 cat_snprintf(str, str_len,
_(
" - show area within borders: %s\n"),
972 pmapdef->
layers[MAPIMG_LAYER_AREA] ?
_(
"yes") :
_(
"no"));
974 pmapdef->
layers[MAPIMG_LAYER_BORDERS] ?
_(
"yes") :
_(
"no"));
976 pmapdef->
layers[MAPIMG_LAYER_CITIES] ?
_(
"yes") :
_(
"no"));
978 pmapdef->
layers[MAPIMG_LAYER_FOGOFWAR] ?
_(
"yes")
980 cat_snprintf(str, str_len,
_(
" - show player knowledge: %s\n"),
981 pmapdef->
layers[MAPIMG_LAYER_KNOWLEDGE] ?
_(
"yes")
984 pmapdef->
layers[MAPIMG_LAYER_TERRAIN] ?
_(
"full")
987 pmapdef->
layers[MAPIMG_LAYER_UNITS] ?
_(
"yes") :
_(
"no"));
1013 if (pmapdef->
status == MAPIMG_STATUS_ERROR) {
1015 mapimg_status_name(pmapdef->
status), pmapdef->
error);
1018 mapimg_status_name(pmapdef->
status));
1031 struct mapdef *pmapdef =
nullptr;
1038 pmapdef = mapdef_list_get(
mapimg.mapdef,
id);
1056 #ifdef FREECIV_DEBUG
1068 if (pmapdef->
status != MAPIMG_STATUS_OK) {
1069 MAPIMG_LOG(
_(
"map definition not checked or error"));
1083 #ifdef FREECIV_DEBUG
1102 if (!
img_save(pimg, mapimgfile, path)) {
1127 if (!
img_save(pimg, mapimgfile, path)) {
1140 #ifdef FREECIV_DEBUG
1141 log_debug(
"Image generation time: %g seconds (%g apparent)",
1164 int max_playercolor =
mapimg.mapimg_plrcolor_count();
1174 pixel = pimg->
pixel_tile(
nullptr,
nullptr,
false);
1177 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1184 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1185 if (i >= max_playercolor) {
1191 pcolor =
mapimg.mapimg_plrcolor_get(i);
1197 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1204 for (i = 0; i <
MAX(max_playercolor, max_terraincolor); i++) {
1205 if (i >= max_terraincolor) {
1219 for (
const auto &
format : QImageWriter::supportedImageFormats()) {
1229 if (!
img_save(pimg, mapimgfile, path)) {
1262 MAPIMG_LOG(
_(
"no map definition with id %d"),
id);
1274 enum mapimg_layer layer;
1275 char buf[MAPIMG_LAYER_COUNT + 1];
1278 if (pmapdef->
status != MAPIMG_STATUS_OK) {
1279 MAPIMG_LOG(
_(
"map definition not checked or error"));
1289 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
1290 layer = mapimg_layer_next(layer)) {
1291 if (pmapdef->
layers[layer]) {
1292 buf[i++] = mapimg_layer_name(layer)[0];
1304 "show=%s:", show_player_name(pmapdef->
player.
show));
1307 cat_snprintf(str, str_len,
"show=%s:", show_player_name(SHOW_PLRBV));
1312 cat_snprintf(str, str_len,
"show=%s:", show_player_name(SHOW_PLRNAME));
1316 cat_snprintf(str, str_len,
"show=%s:", show_player_name(SHOW_PLRID));
1335 if (!recheck && pmapdef->
status == MAPIMG_STATUS_ERROR) {
1360 if (pplayer !=
nullptr) {
1363 pmapdef->
status = MAPIMG_STATUS_ERROR;
1366 _(
"unknown player name: '%s'"), pmapdef->
player.
name);
1376 if (pplayer !=
nullptr) {
1379 pmapdef->
status = MAPIMG_STATUS_ERROR;
1382 _(
"invalid player id: %d"), pmapdef->
player.
id);
1389 pmapdef->
status = MAPIMG_STATUS_OK;
1398 static void mapimg_log(
const char *file,
const char *
function,
int line,
1399 const char *format, ...)
1403 va_start(args, format);
1407 #ifdef FREECIV_DEBUG
1426 static char mapstr[256];
1428 enum mapimg_layer layer;
1429 int i, count = 0, plr_id = -1;
1461 }
else if (count == 1 && plr_id != -1) {
1462 fc_snprintf(str_show,
sizeof(str_show),
"%03d%s", plr_id,
1469 for (layer = mapimg_layer_begin(); layer != mapimg_layer_end();
1470 layer = mapimg_layer_next(layer)) {
1471 if (pmapdef->
layers[layer]) {
1472 const char *lname = mapimg_layer_name(layer);
1474 if (lname !=
nullptr) {
1499 auto *pmapdef =
new mapdef;
1502 pmapdef->maparg[0] =
'\0';
1503 pmapdef->error[0] =
'\0';
1504 pmapdef->status = MAPIMG_STATUS_UNKNOWN;
1508 pmapdef->layers[MAPIMG_LAYER_TERRAIN] =
false;
1509 pmapdef->layers[MAPIMG_LAYER_CITIES] =
true;
1510 pmapdef->layers[MAPIMG_LAYER_UNITS] =
true;
1511 pmapdef->layers[MAPIMG_LAYER_BORDERS] =
true;
1512 pmapdef->layers[MAPIMG_LAYER_FOGOFWAR] =
false;
1513 pmapdef->layers[MAPIMG_LAYER_KNOWLEDGE] =
true;
1514 pmapdef->layers[MAPIMG_LAYER_AREA] =
false;
1515 pmapdef->player.show = SHOW_ALL;
1530 if (pmapdef ==
nullptr) {
1549 auto *pimg =
new img;
1639 if (pimg !=
nullptr) {
1654 qCritical(
"invalid index: 0 <= %d < %d", mindex,
1659 pimg->
map[mindex] = pcolor;
1678 const struct rgbcolor *pcolor,
const bv_pixel pixel)
1680 int base_x, base_y, i, mindex;
1702 const bv_pixel pixel)
1719 if (!QFileInfo(mapimgfile).isAbsolute() && path !=
nullptr) {
1723 if (tmpname[0] !=
'\0') {
1742 if (image.isNull()) {
1743 MAPIMG_LOG(
_(
"could not allocate memory for image"));
1748 image.setText(QStringLiteral(
"Description"),
1749 QStringLiteral(
"color test"));
1761 QStringLiteral(
"Player %1 color").arg(
player_number(pplayer)),
1762 QStringLiteral(
"(%1, %2, %3)")
1767 QStringLiteral(
"Player %1 name").arg(
player_number(pplayer)),
1773 image.setDevicePixelRatio(pimg->
def->
zoom);
1774 image.fill(Qt::transparent);
1782 if (
const auto pcolor = pimg->
map[
img_index(
x,
y, pimg)]; pcolor) {
1783 p.fillRect(
x,
y, 1, 1, QColor(pcolor->r, pcolor->g, pcolor->b));
1790 image.save(pngname);
1791 qDebug(
"Map image saved as '%s'.", pngname);
1800 char *filename,
size_t filename_len)
1802 fc_snprintf(filename, filename_len,
"%s.map.%s", mapimgfile,
1817 struct player *pplayer =
nullptr;
1818 struct player *plr_tile =
nullptr, *plr_city =
nullptr,
1819 *plr_unit =
nullptr;
1821 struct terrain *pterrain =
nullptr;
1822 bool plr_knowledge = pimg->
def->
layers[MAPIMG_LAYER_KNOWLEDGE];
1834 mapimg.mapimg_tile_known(ptile, pplayer, plr_knowledge);
1842 if (plr_knowledge && pplayer !=
nullptr
1849 pterrain =
mapimg.mapimg_tile_terrain(ptile, pplayer, plr_knowledge);
1850 if (pimg->
def->
layers[MAPIMG_LAYER_TERRAIN]) {
1852 pixel = pimg->
pixel_tile(ptile, pplayer, plr_knowledge);
1857 pixel = pimg->
pixel_tile(ptile, pplayer, plr_knowledge);
1866 plr_tile =
mapimg.mapimg_tile_owner(ptile, pplayer, plr_knowledge);
1867 if (
game.
info.borders > 0 &&
nullptr != plr_tile) {
1872 pixel = pimg->
pixel_tile(ptile, pplayer, plr_knowledge);
1875 }
else if (pimg->
def->
layers[MAPIMG_LAYER_BORDERS]
1877 || (plr_knowledge && pplayer !=
nullptr))) {
1880 pixel = pimg->
pixel_border(ptile, pplayer, plr_knowledge);
1887 plr_city =
mapimg.mapimg_tile_city(ptile, pplayer, plr_knowledge);
1888 plr_unit =
mapimg.mapimg_tile_unit(ptile, pplayer, plr_knowledge);
1889 if (pimg->
def->
layers[MAPIMG_LAYER_CITIES] && plr_city) {
1892 || (plr_knowledge && pplayer !=
nullptr)) {
1895 pixel = pimg->
pixel_city(ptile, pplayer, plr_knowledge);
1899 }
else if (pimg->
def->
layers[MAPIMG_LAYER_UNITS] && plr_unit) {
1902 || (plr_knowledge && pplayer !=
nullptr)) {
1905 pixel = pimg->
pixel_unit(ptile, pplayer, plr_knowledge);
1945 const struct player *pplayer,
bool knowledge)
1966 const struct player *pplayer,
bool knowledge)
2004 const struct player *pplayer,
bool knowledge)
2029 const struct player *pplayer,
2074 const struct player *pplayer,
2085 owner =
mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
2086 if (
nullptr == owner) {
2094 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2106 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2118 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2130 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2164 const struct player *pplayer,
bool knowledge)
2187 const struct player *pplayer,
bool knowledge)
2230 const struct player *pplayer,
bool knowledge)
2257 const struct player *pplayer,
2299 const struct player *pplayer,
2310 owner =
mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
2311 if (
nullptr == owner) {
2319 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2330 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2339 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2349 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2360 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2369 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2402 const struct player *pplayer,
2424 const struct player *pplayer,
2466 const struct player *pplayer,
2492 const struct player *pplayer,
2538 const struct player *pplayer,
2549 owner =
mapimg.mapimg_tile_owner(ptile, pplayer, knowledge);
2550 if (
nullptr == owner) {
2558 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2570 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2579 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2588 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2600 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2609 &&
mapimg.mapimg_tile_owner(pnext, pplayer, knowledge) != owner)) {
2654 for (; i >= 0; i--) {
2655 buf[i] =
BV_ISSET(plrbv, i) ?
'1' :
'0';
2705 static struct rgbcolor rgb_special[] = {
2718 return &rgb_special[imgcolor];
2734 return pplayer->
rgb;
2749 return pterrain->
rgb;
bool BV_ISSET(const BV &bv, int bit)
#define BV_ISSET_ANY(vec)
const char * calendar_text()
Produce a statically allocated textual representation of the current calendar time.
#define MAX_NUM_PLAYER_SLOTS
int generate_save_name(const char *format, char *buf, int buflen, const char *reason)
Generate a default save file name and place it in the provided buffer.
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Step from the given tile in the given direction.
#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)
Return the number of players defined in a map image definition.
static bv_pixel pixel_fogofwar_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
0 – 2 – 4 – – 7 – 9 – 11 12 – 14 – 16 – – 19 – 21 – 23 24 – 26 – 28 – – 31 – 33 – 35
static const auto MAPIMG_DEFAULT_IMGFORMAT
static char error_buffer[MAX_LEN_ERRORBUF]
bool mapimg_id2str(int id, char *str, size_t str_len)
Return the map image definition 'id' as a mapdef string.
void mapimg_reset()
Reset the map image subsystem.
mapimg_tile_player_func mapimg_tile_owner
static bool mapimg_test(int id)
Check if the map image subsystem is initialised and the given ID is valid.
static bool mapimg_def2str(struct mapdef *pmapdef, char *str, size_t str_len)
Return a mapdef string for the map image definition given by 'pmapdef'.
static void base_coor_hexa(struct img *pimg, int *base_x, int *base_y, int x, int y)
Base coordinates for the tiles on a hexa topology,.
bool mapimg_colortest(const char *savename, const char *path)
Create images which shows all map colors (playercolor, terrain colors).
static bv_pixel pixel_city_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
BV_DEFINE(bv_pixel, NUM_PIXEL)
static bv_pixel pixel_border_hexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
[W] 0 1 [N] 2 – – 5 6 – – – – 11 [SW] 12 – – – – 17 [NE] 18 – – – – 23 24 – – – – 29 30 – – 33 [S] 34...
mapimg_tile_terrain_func mapimg_tile_terrain
int mapimg_count()
Return the number of map image definitions.
mapimg_tile_player_func mapimg_tile_city
static struct mapdef * mapdef_new(bool colortest)
Create a new map image definition with default values.
static void img_destroy(struct img *pimg)
Destroy a image.
static struct img * img_new(struct mapdef *mapdef, int topo, int xsize, int ysize)
Create a new image.
bv_pixel(* plot_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
mapimg_tile_player_func mapimg_tile_unit
static bool img_filename(const char *mapimgfile, const QByteArray &format, char *filename, size_t filename_len)
Generate the final filename.
static void img_plot(struct img *pimg, int x, int y, const struct rgbcolor *pcolor, const bv_pixel pixel)
Plot one tile at (x,y).
static const char * showname_help(enum show_player showplr)
Describe the 'show' settings.
static const struct rgbcolor * imgcolor_terrain(const struct terrain *pterrain)
Return rgbcolor for terrain.
static void img_createmap(struct img *pimg)
Create the map considering the options (terrain, player(s), cities, units, borders,...
const char * mapimg_error()
Returns the last error.
static bool mapimg_initialised()
Check if the map image subsustem is initialised.
struct mapdef * mapimg_isvalid(int id)
Check if a map image definition is valid.
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)
Initialisation of the map image subsystem.
static void mapimg_log(const char *file, const char *function, int line, const char *format,...) fc__attribute((__format__(__printf__
Edit the error_buffer.
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)
Get the index for an (x,y) image coordinate.
static struct tile_shape tile_rect
mapimg_tile_known_func mapimg_tile_known
static bool img_save(const struct img *pimg, const char *mapimgfile, const char *path)
Save an image.
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)
void mapimg_free()
Free all memory allocated by the map image subsystem.
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)
Define on map image.
bool mapimg_delete(int id)
Delete a map image definition.
static const struct rgbcolor * imgcolor_player(int plr_id)
Return rgbcolor for player.
#define MAPIMG_LOG(format,...)
static const char * bvplayers_str(const bv_player &plrbv)
Convert the player bitvector to a string.
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)
Base coordinates for the tiles on a (isometric) rectange topology,.
static struct tile_shape tile_hexa
#define MAPIMG_ASSERT_RET_VAL(cond, expr)
static char * mapimg_generate_name(struct mapdef *pmapdef)
Generate an identifier for a map image.
struct mapdef_list * mapdef
static bv_pixel pixel_unit_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
char * mapimg_help(const char *cmdname)
Return a help string for the 'mapimg' command.
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)
Plot one tile.
static void base_coor_isohexa(struct img *pimg, int *base_x, int *base_y, int x, int y)
Base coordinates for the tiles on a isometric hexa topology,.
static void mapdef_destroy(struct mapdef *pmapdef)
Destroy a map image definition.
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
Create the requested map image.
static const struct rgbcolor * imgcolor_special(enum img_special imgcolor)
Return rgbcolor for img_special.
static bv_pixel pixel_border_isohexa(const struct tile *ptile, const struct player *pplayer, bool knowledge)
#define mapdef_list_iterate(mapdef_list, pmapdef)
static struct tile_shape tile_isohexa
bool mapimg_show(int id, char *str, size_t str_len, bool detail)
Show a map image definition.
static bool mapimg_define_arg(struct mapdef *pmapdef, enum mapdef_arg arg, const char *val, bool check)
Helper function for mapimg_define().
static bool mapimg_checkplayers(struct mapdef *pmapdef, bool recheck)
Check the player selection.
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)
Set the color of one pixel.
static bv_pixel pixel_tile_rect(const struct tile *ptile, const struct player *pplayer, bool knowledge)
0 1 2 3 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
int(* mapimg_plrcolor_count_func)()
struct player *(* mapimg_tile_player_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
enum known_type(* mapimg_tile_known_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
struct rgbcolor *(* mapimg_plrcolor_get_func)(int)
struct terrain *(* mapimg_tile_terrain_func)(const struct tile *ptile, const struct player *pplayer, bool knowledge)
struct player * player_by_number(const int player_id)
Return struct player pointer for the given player index.
int player_number(const struct player *pplayer)
Return the player index/number/id.
struct player * player_by_name_prefix(const char *name, enum m_pre_result *result)
Find player by its name prefix.
int player_count()
Return the number of players.
int player_index(const struct player *pplayer)
Return the player index.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
#define players_iterate_end
#define players_iterate(_pplayer)
bool make_dir(const QString &pathname)
If the directory "pathname" does not exist, recursively create all directories until it does.
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::@43 player
bool layers[MAPIMG_LAYER_COUNT]
char maparg[MAX_LEN_MAPARG]
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
#define sz_strlcpy(dest, src)
int fc__attribute((nonnull(1, 3)))
#define sz_strlcat(dest, src)
Terrain_type_id terrain_count()
Return the number of terrains.
struct terrain * terrain_by_number(const Terrain_type_id type)
Return the terrain for the given terrain index.
#define is_ocean(pterrain)
void timer_destroy(civtimer *t)
Deletes timer.
double timer_read_seconds(civtimer *t)
Read value from timer.
civtimer * timer_new(enum timer_timetype type, enum timer_use use)
Allocate a new timer with specified "type" and "use".
void timer_start(civtimer *t)
Start timing, adding to previous accumulated time if timer has not been cleared.