Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to set the ruleset based on the tileset #1167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions client/client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,15 @@ int client_main(int argc, char *argv[])
boot_help_texts(client_current_nation_set(), tileset_help(tileset));

fill_topo_ts_default();

if (!forced_tileset_name.isEmpty()) {
if (!tilespec_try_read(qUtf8Printable(forced_tileset_name), true, -1,
true)) {
if (!tilespec_try_read(forced_tileset_name, true, -1)) {
qCritical(_("Can't load requested tileset %s!"),
qUtf8Printable(forced_tileset_name));
client_exit();
return EXIT_FAILURE;
}
} else {
tilespec_try_read(gui_options.default_tileset_name, false, -1, true);
tilespec_try_read(QString(), false, -1);
}

audio_real_init(sound_set_name, music_set_name, sound_plugin_name);
Expand Down
39 changes: 1 addition & 38 deletions client/connectdlg_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static int find_next_free_port(int starting_port, int highest_port)
bool client_start_server(const QString &user_name)
{
QStringList arguments;
QString trueFcser, ruleset, storage, port_buf, savesdir, scensdir;
QString trueFcser, storage, port_buf, savesdir, scensdir;
char buf[512];
int connect_tries = 0;

Expand Down Expand Up @@ -233,8 +233,6 @@ bool client_start_server(const QString &user_name)
return false;
}

ruleset = QString::fromUtf8(tileset_what_ruleset(tileset));

// Set up the command-line parameters.
port_buf = QString::number(internal_server_port);
savesdir = QStringLiteral("%1/saves").arg(storage);
Expand All @@ -256,9 +254,6 @@ bool client_start_server(const QString &user_name)
if (savefile.isEmpty()) {
arguments << QStringLiteral("--file") << savefile;
}
if (ruleset != nullptr) {
arguments << QStringLiteral("--ruleset") << ruleset;
}

// Look for a server binary
const QString server_name = QStringLiteral("freeciv21-server");
Expand Down Expand Up @@ -330,38 +325,6 @@ bool client_start_server(const QString &user_name)
return false;
}

/* We set the topology to match the view.
*
* When a typical player launches a game, he wants the map orientation to
* match the tileset orientation. So if you use an isometric tileset you
* get an iso-map and for a classic tileset you get a classic map. In
* both cases the map wraps in the X direction by default.
*
* This works with hex maps too now. A hex map always has
* tileset_is_isometric(tileset) return TRUE. An iso-hex map has
* tileset_hex_height(tileset) != 0, while a non-iso hex map
* has tileset_hex_width(tileset) != 0.
*
* Setting the option here is a bit of a hack, but so long as the client
* has sufficient permissions to do so (it doesn't have HACK access yet) it
* is safe enough. Note that if you load a savegame the topology will be
* set but then overwritten during the load.
*
* Don't send it now, it will be sent to the server when receiving the
* server setting infos. */
{
char topobuf[16];

fc_strlcpy(topobuf, "WRAPX", sizeof(topobuf));
if (tileset_is_isometric(tileset) && 0 == tileset_hex_height(tileset)) {
fc_strlcat(topobuf, "|ISO", sizeof(topobuf));
}
if (0 < tileset_hex_width(tileset) || 0 < tileset_hex_height(tileset)) {
fc_strlcat(topobuf, "|HEX", sizeof(topobuf));
}
desired_settable_option_update("topology", topobuf, false);
}

return true;
}

Expand Down
21 changes: 3 additions & 18 deletions client/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ struct client_options gui_options = {

/** Migrations **/
false, //.first_boot =
"\0", //.default_tileset_name =
"\0", //.default_tileset_overhead_name =
"\0", //.default_tileset_iso_name =
false, //.gui_qt_migrated_from_2_5 =
Expand Down Expand Up @@ -4418,11 +4417,6 @@ void options_load()
secfile_lookup_bool_default(sf, gui_options.gui_qt_migrated_from_2_5,
"%s.migration_qt_from_2_5", prefix);

str =
secfile_lookup_str_default(sf, nullptr, "client.default_tileset_name");
if (str != nullptr) {
sz_strlcpy(gui_options.default_tileset_name, str);
}
str = secfile_lookup_str_default(sf, nullptr,
"client.default_tileset_overhead_name");
if (str != nullptr) {
Expand Down Expand Up @@ -4531,11 +4525,6 @@ void options_save(option_save_log_callback log_cb)
client_options_iterate_all(poption) { client_option_save(poption, sf); }
client_options_iterate_all_end;

if (gui_options.default_tileset_name[0] != '\0') {
secfile_insert_str(sf, gui_options.default_tileset_name,
"client.default_tileset_name");
}

message_options_save(sf, "client");
options_dialogs_save(sf);

Expand Down Expand Up @@ -4878,10 +4867,6 @@ const char *tileset_name_for_topology(int topology_id)
break;
}

if (tsn == nullptr) {
tsn = gui_options.default_tileset_name;
}

return tsn;
}

Expand Down Expand Up @@ -4957,15 +4942,15 @@ void fill_topo_ts_default()
sizeof(gui_options.default_tileset_square_name));
} else {
log_debug("Setting tileset for square topologies.");
tilespec_try_read(nullptr, false, 0, false);
tilespec_try_read(QString(), false, 0);
}
}
if (is_ts_option_unset("default_tileset_hex_name")) {
log_debug("Setting tileset for hex topology.");
tilespec_try_read(nullptr, false, TF_HEX, false);
tilespec_try_read(QString(), false, TF_HEX);
}
if (is_ts_option_unset("default_tileset_isohex_name")) {
log_debug("Setting tileset for isohex topology.");
tilespec_try_read(nullptr, false, TF_ISO | TF_HEX, false);
tilespec_try_read(QString(), false, TF_ISO | TF_HEX);
}
}
5 changes: 2 additions & 3 deletions client/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ struct client_options {
bool save_options_on_exit;

/** Migrations **/
bool first_boot; /* There was no earlier options saved.
* This affects some migrations, but not all. */
char default_tileset_name[512]; // pre-2.6 had just this one tileset name
bool first_boot; /* There was no earlier options saved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why reformat comments ? :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang-format because it aligns them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, breaks git blame. But ok I guess.

* This affects some migrations, but not all. */
char default_tileset_overhead_name[512]; /* 2.6 had separate tilesets for
... */
char default_tileset_iso_name[512]; // ...overhead and iso topologies.
Expand Down
63 changes: 17 additions & 46 deletions client/tilespec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,6 @@ struct tileset {

std::vector<tileset_log_entry> log;

char *for_ruleset;

std::vector<std::unique_ptr<freeciv::layer>> layers;
struct {
freeciv::layer_special *background, *middleground, *foreground;
Expand Down Expand Up @@ -367,7 +365,7 @@ int focus_unit_state = 0;

static bool tileset_update = false;

static struct tileset *tileset_read_toplevel(const char *tileset_name,
static struct tileset *tileset_read_toplevel(const QString &tileset_name,
bool verbose, int topology_id);

static bool load_river_sprites(struct tileset *t,
Expand Down Expand Up @@ -892,10 +890,8 @@ static void tileset_free_toplevel(struct tileset *t)

delete[] t->summary;
delete[] t->description;
delete[] t->for_ruleset;
t->summary = nullptr;
t->description = nullptr;
t->for_ruleset = nullptr;
}

/**
Expand Down Expand Up @@ -923,12 +919,12 @@ void tileset_free(struct tileset *t)

Returns TRUE iff tileset with suggested tileset_name was loaded.
*/
bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,
bool global_default)
bool tilespec_try_read(const QString &tileset_name, bool verbose,
int topo_id)
{
bool original;

if (tileset_name == nullptr
if (tileset_name.isEmpty()
|| !(tileset =
tileset_read_toplevel(tileset_name, verbose, topo_id))) {
QVector<QString> *list = fileinfolist(get_data_dirs(), TILESPEC_SUFFIX);
Expand Down Expand Up @@ -965,10 +961,6 @@ bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,
}
option_set_default_ts(tileset);

if (global_default) {
sz_strlcpy(gui_options.default_tileset_name, tileset_basename(tileset));
}

return original;
}

Expand All @@ -985,47 +977,42 @@ bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,

Returns TRUE iff new tileset has been succesfully loaded.
*/
bool tilespec_reread(const char *new_tileset_name,
bool game_fully_initialized)
bool tilespec_reread(const QString &name, bool game_fully_initialized)
{
int id;
struct tile *center_tile;
enum client_states state = client_state();
const char *name = new_tileset_name ? new_tileset_name : tileset->name;
bool new_tileset_in_use;

// Make local copies since these values may be freed down below
QString tileset_name = name;
QString old_name = tileset->name;

qInfo(_("Loading tileset \"%s\"."), qUtf8Printable(tileset_name));
qInfo(_("Loading tileset \"%s\"."), qUtf8Printable(name));

/* Step 0: Record old data.
*
* We record the current mapcanvas center, etc.
*/
center_tile = get_center_tile_mapcanvas();
auto center_tile = tileset ? get_center_tile_mapcanvas() : nullptr;

/* Step 1: Cleanup.
*
* Free old tileset.
*/
const char *old_name = nullptr;
if (tileset) {
old_name = tileset->name;
tileset_free(tileset);
}

/* Step 2: Read.
*
* We read in the new tileset. This should be pretty straightforward.
*/
tileset = tileset_read_toplevel(qUtf8Printable(tileset_name), false, -1);
tileset = tileset_read_toplevel(name, false, -1);
if (tileset != nullptr) {
new_tileset_in_use = true;
} else {
new_tileset_in_use = false;

if (!(tileset =
tileset_read_toplevel(qUtf8Printable(old_name), false, -1))) {
if (old_name
&& !(tileset = tileset_read_toplevel(old_name, false, -1))) {
// Always fails.
fc_assert_exit_msg(nullptr != tileset,
"Failed to re-read the currently loaded tileset.");
Expand Down Expand Up @@ -1143,10 +1130,6 @@ void tilespec_reread_callback(struct option *poption)

tileset_name = option_str_get(poption);

/* As it's going to be 'current' tileset, make it global default if
* options saved. */
sz_strlcpy(gui_options.default_tileset_name, tileset_name);

fc_assert_ret(nullptr != tileset_name && tileset_name[0] != '\0');
tileset_update = true;
tilespec_reread(tileset_name, client.conn.established);
Expand All @@ -1160,10 +1143,10 @@ void tilespec_reread_callback(struct option *poption)

See tilespec_reread() for details.
*/
void tilespec_reread_frozen_refresh(const char *tname)
void tilespec_reread_frozen_refresh(const QString &name)
{
tileset_update = true;
tilespec_reread(tname, true);
tilespec_reread(name, true);
tileset_update = false;
menus_init();
}
Expand Down Expand Up @@ -1594,7 +1577,7 @@ static void tileset_add_layer(struct tileset *t, mapview_layer layer)
intro files.
topology_id of -1 means any topology is acceptable.
*/
static struct tileset *tileset_read_toplevel(const char *tileset_name,
static struct tileset *tileset_read_toplevel(const QString &tileset_name,
bool verbose, int topology_id)
{
struct section_file *file;
Expand All @@ -1618,7 +1601,7 @@ static struct tileset *tileset_read_toplevel(const char *tileset_name,
fname = tilespec_fullname(tileset_name);
if (!fname) {
if (verbose) {
qCritical("Can't find tileset \"%s\".", tileset_name);
qCritical("Can't find tileset \"%s\".", qUtf8Printable(tileset_name));
}
return nullptr;
}
Expand Down Expand Up @@ -1685,14 +1668,7 @@ static struct tileset *tileset_read_toplevel(const char *tileset_name,
}
}

tstr = secfile_lookup_str_default(file, nullptr, "tilespec.for_ruleset");
if (tstr != nullptr) {
t->for_ruleset = fc_strdup(tstr);
} else {
t->for_ruleset = nullptr;
}

sz_strlcpy(t->name, tileset_name);
sz_strlcpy(t->name, tileset_name.toUtf8().data());
if (!secfile_lookup_int(file, &t->priority, "tilespec.priority")
|| !secfile_lookup_bool(file, &is_hex, "tilespec.is_hex")) {
qCritical("Tileset \"%s\" invalid: %s", t->name, secfile_error());
Expand Down Expand Up @@ -5682,11 +5658,6 @@ const char *tileset_summary(struct tileset *t) { return t->summary; }
*/
const char *tileset_description(struct tileset *t) { return t->description; }

/**
Return what ruleset this tileset is primarily meant for
*/
char *tileset_what_ruleset(struct tileset *t) { return t->for_ruleset; }

/**
Return tileset topology index
*/
Expand Down
9 changes: 4 additions & 5 deletions client/tilespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ bool tileset_has_error(const struct tileset *t);

void finish_loading_sprites(struct tileset *t);

bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,
bool global_default);
bool tilespec_reread(const char *tileset_name, bool game_fully_initialized);
bool tilespec_try_read(const QString &name, bool verbose, int topo_id);
bool tilespec_reread(const QString &tileset_name,
bool game_fully_initialized);
void tilespec_reread_callback(struct option *poption);
void tilespec_reread_frozen_refresh(const char *tname);
void tilespec_reread_frozen_refresh(const QString &name);

void tileset_setup_specialist_type(struct tileset *t, Specialist_type_id id);
void tileset_setup_unit_type(struct tileset *t, struct unit_type *punittype);
Expand Down Expand Up @@ -318,6 +318,5 @@ const char *tileset_name_get(struct tileset *t);
const char *tileset_version(struct tileset *t);
const char *tileset_summary(struct tileset *t);
const char *tileset_description(struct tileset *t);
char *tileset_what_ruleset(struct tileset *t);
int tileset_topo_index(struct tileset *t);
help_item *tileset_help(struct tileset *t);
3 changes: 0 additions & 3 deletions data/alio.tilespec
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ Tileset containing graphics suitable for playing with alien ruleset.\
; TODO: add more overall information fields on tiles,
; eg, authors, colors, etc.

; What is the primary ruleset this tileset is meant for.
for_ruleset = "alien"

; Basic tile sizes:
normal_tile_width = 126
normal_tile_height = 64
Expand Down
3 changes: 0 additions & 3 deletions data/amplio.tilespec
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ summary = _("Older variant of the current default tileset, Amplio2")
; TODO: add more overall information fields on tiles,
; eg, authors, colors, etc.

; What is the primary ruleset this tileset is meant for.
;for_ruleset = ""

; Basic tile sizes:
normal_tile_width = 96
normal_tile_height = 48
Expand Down
3 changes: 0 additions & 3 deletions data/amplio2.tilespec
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ summary = _("Large isometric tileset.")
; TODO: add more overall information fields on tiles,
; eg, authors, colors, etc.

; What is the primary ruleset this tileset is meant for.
;for_ruleset = ""

; Basic tile sizes:
normal_tile_width = 96
normal_tile_height = 48
Expand Down
Loading