1413 Commits

Author SHA1 Message Date
Tóth Kornél
ad563d99e9
Map editor segmentation fault fix (#9564)
Fixed map editor crashing when creating or opening scenario after played local scenario before opening map editor. Resolves #9563. The cause of the bug was that the ai manager singleton pointer was not set to nullptr after it was destructed. Fixed this by making ai manager destructor set singleton to nullptr. Before this the ai_map_ map member has to be cleared in destructor because it might try to access the singleton when destructed.

---------

Co-authored-by: SomeName42 <>
2024-12-06 14:39:47 -06:00
Subhraman Sarkar
482c2817f9 fix clang-tidy warnings 2024-12-03 20:35:25 +05:30
JJ Marr
ecd273914c NOLINT exception to const reference rules
Specifically, this function is intended to cause a runtime error when a
pointer to an incorrect type is passed in.
2024-12-01 23:19:53 -05:00
JJ Marr
6999b294d5 Use std::move wherever possible 2024-12-01 23:19:53 -05:00
JJ Marr
fe5296aefd Make every possible param a const reference
This is important for performance. If a parameter doesn't have to be
modified, it should be a constant reference to the original.
2024-12-01 23:19:53 -05:00
gfgtdf
3d589f8d0d use synced_context::run for move actions
With this, finally all actions run though synced context::run,
so that we not only have a central place that happens before/after
synced actions, we also guarantee that there is no difference between
the original and the replay codepath for all actions.

This should also make upcoming changed to the undo code easier.
2024-11-17 21:30:22 +01:00
gfgtdf
d0050dac8e remove undo_stack parameter from move_unit
it was only there for the ai code to skip undo which it no longer does
2024-11-17 21:30:22 +01:00
gfgtdf
7782c50f83 simplify synced_context::run() calls by ai and whiteboard
- use_undo is not used anymore
- ignore_error_function has no effect since to_check()
already checks whether the unit exists
- show in whiteboard code was the default value.
- show is now determined inside the actions handler, this
has the advantage that the skip_ai_moves preference now
also works for networked ai sides.
-the attack code now used run_in_synced_context_if_not_already
just like the other commands
2024-11-17 21:30:22 +01:00
Charles Dang
12fa8f2844 Use standard chrono types consistently throughout the codebase
* Functions that return time values now return proper std::chrono::duration units (milliseconds,
  seconds, etc.). This removes the need to do manual unit conversions.
* Simple time-to-execute logging was replaced with `utils::optimer`.
* Most uses of `SDL_GetTicks()` have been replaced with `std::chrono::steady_clock`.
* Uses of events::pump_info::ticks() have been replaced with direct calls to steady_clock::now().
  This made the countdown_clock code significantly simpler. As for the music_tinker, that needs
  to be rethought wholesale.
2024-11-07 11:10:13 -05:00
Charles Dang
ebf825668d Add utils::erase to complement erase_if
Both can be replaced with their standard library counterparts once we use C++20 by default.
2024-10-25 13:20:59 -04:00
Charles Dang
cb4d8a8dff Deploy utils::erase_if 2024-10-25 04:03:23 -04:00
Charles Dang
491c236113 Config: deploy all_children_view en-mass 2024-10-16 09:36:59 -04:00
Charles Dang
f4fda31707 Map Location: convert direction to a scoped enum 2024-10-10 22:57:23 -04:00
Charles Dang
56cc3aee0f
Config: remove implicit conversion to int and bool (#9444)
Resolves #9009, closes #9384. Besides the issues that came from having both int and bool conversions (even with bool marked explicit), it doesn't make sense to use int for all numeric assignments. I didn't test whether it would be an issue in practice, but it seems better to let callers be explicit about what type they want for numeric values than risking overflow or wrapping for very large values.
2024-10-09 01:36:10 -04:00
Charles Dang
95c9f0c720
Config: use structured bindings with all_children_range (#9387) 2024-09-27 02:49:57 -04:00
Charles Dang
78676a27ad Use structured bindings for config attribute ranges in most places 2024-09-15 00:16:51 -04:00
Charles Dang
a5f7804277
Mass cleanup of index-based teams list access (#9290)
Mostly converting index-based loops to for loops. Includes a couple other non-team loops that were in the files I was editing.
2024-09-03 13:31:05 -04:00
Charles Dang
4058f866d6
Remove UNUSED (#9210) 2024-08-14 13:55:58 -04:00
Charles Dang
18b9bf7c23 AI/Manager: clean up a few constness things 2024-07-31 22:38:23 -04:00
Charles Dang
f3c569a10d AI/Manager: clean up unnecessary uses of this-> 2024-07-31 22:19:28 -04:00
Charles Dang
40a071fbc5 AI/Manager: clean up a nasty case of string concat 2024-07-31 22:11:06 -04:00
Celtic Minstrel
f6ae8ab850 Mass replace all std::optional with utils::optional
Also import bad_optional_access into the utils namespace so we can catch the exception when we need to
2024-07-23 09:29:20 -04:00
Celtic Minstrel
ac431ca9dd Revert "Remove macOS compat path for std::variant and std::any"
This reverts commit c2decdfb585b9f3551fb4f0eaa41d42c9fe14422.
2024-07-23 08:23:38 -04:00
Charles Dang
e45b46107e
FS: use optional<string> to represent non-existent paths (#9107) 2024-07-18 09:58:55 -04:00
Gunter Labes
e7acc0e3b9 Perform multiplication in result type for types larger than int
Makes the code do what is commonly expected and avoids needless overflow since
otherwise the multiplication is done as int.
2024-07-11 20:57:57 +02:00
Charles Dang
c2decdfb58 Remove macOS compat path for std::variant and std::any 2024-07-08 22:02:32 -04:00
Pentarctagon
971073055e
Refactor the preferences into a proper singleton. (#8930)
The current preferences handling is a mess:
* it's essentially a global config object that anything can modify in any way the caller wants, which is managed across multiple source files which have their own oddities and interdependencies.
* the general preferences has its own bit of SDL event handling and while I get the idea behind `events::sdl_handler` there's no reason to have SDL events handled in the preferences instead of just calling the relevant preferences setter for each event when it happens.
* the general preferences is where most of the preferences are handled and has its `base_manager` struct, which is part of the `manager` struct in the game preferences, which is then implicitly initialized as part of game_launcher's constructor.
* the editor preferences are the only preferences in a sub-namespace `preferences::editor` while all other preferences are just in the `preferences` namespace.
* the display, editor, and lobby preferences are all dependent on including the game preferences, the credentials are dependent on including the general preferences (but not the game preferences), the game preferences are dependent on including the general preferences, and the advanced preferences are entirely their own thing which is dependent on none of the other preference functionality and manages its own singleton.
* nothing checks whether the preferences file has actually been loaded before allowing values to be read from or written to the preferences config - if you attempt to get a value too early in wesnoth's initialization it will silently just give you whatever the default value for that preference happens to be.

With this there is instead a single access point (with exceptions handled via friend functions/classes), all predefined preferences are accessed via their own setter/getter, and all mainline preferences are defined in a single file (preference_list.hpp) so it's easily findable what preferences exist and where they're used. Having the list of all mainline preferences listed out also allows the lua preferences API to provide that full list rather than just the list of the preferences that have been set so far. Also it now checks for whether the location of the preferences file is known before attempting to load the preferences file and asserts if someone attempts to use the preferences too early.
2024-06-09 11:34:09 -05:00
Steve Cotton
f7fea77603 Move knowledge of attack_type out of movetype
The movetype data includes vulnerability to damage types, for example
`resistance_against("arcane")`. There was also a convenience wrapper
that took an attack_type, and returned the vulnerability to that
attack_type's damage type.

The logic of the wrapper is very basic, and does not use unit.cpp's
logic to check whether abilities that change the type are active.
Although it gained knowledge of alternative damage types in 3910817cf7,
it won't always return the same value as the unit.cpp function does.

The wrapper is now only used in FormulaAI, so let's move the code there,
which in effect marks it deprecated.
2024-04-11 00:07:23 +02:00
shijie.chen
d88ddec6f1
Remove unnecessary header files (#8531)
Co-authored-by: shijie.chen <shijie.chen@goland.cn>
2024-03-12 00:07:48 -04:00
P. J. McDermott
b5d073a2ad Rename src/lua/*.h to src/lua/wrapper_*.h
These will be changed to conditionally include system Lua headers,
e.g. "lua.h", instead of submodule Lua headers, e.g. "module/lua/lua.h".
If a header named "lua.h" includes "lua.h", the build will fail due to
recursion.

This can't be solved using angle brackets to include system headers,
because macos builds won't find them:

    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/registry.cpp:30:
    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/composite/aspect.hpp:24:
    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/lua/lua_object.hpp:25:
    /Users/runner/work/wesnoth/wesnoth/src/lua/lua.h:4:14: error: 'lua.h' file not found with <angled> include; use "quotes" instead
        #include <lua.h>
                 ^~~~~~~
                 "lua.h"

Renamed with (requires GNU sed):

    $ for f in src/lua/*.h; do
    >     git mv "${f}" "src/lua/wrapper_${f#src/lua/}";
    > done
    $ git grep -El -- '#[ \t]*include[ \t]+"lua/[^"]+[.]h"' src | \
    > xargs sed -Ei -- '
    > s|(#[ \t]*include[ \t]+"lua/)(lua[.]h")(            )?|\1wrapper_\2|;
    > s|(#[ \t]*include[ \t]+"lua/)(lualib[.]h")(         )?|\1wrapper_\2|;
    > s|(#[ \t]*include[ \t]+"lua/)(lauxlib[.]h")(        )?|\1wrapper_\2|;
    > '
2024-02-11 23:21:15 -06:00
pentarctagon
970163813d 2024 copyright update 2024-01-20 22:22:23 -06:00
gfgtdf
9f66b1e8ff Don't assert on config input.
assert() is not a good way to handle incorrect user input,
It is a debugging tool that should only be used for
conditions that the program guarantees to be true
(unless there a is a bug in the c++ code).
2023-12-13 17:01:28 +01:00
Steve Cotton
8d2d58d6ec Avoid using double-quote as a C++ raw string delimiter-char
This avoids warnings from xgettext, which considers `R"""..."""` to be
sufficiently unusual that it doesn't have support for it. This version
uses an empty d-char-sequence, as the only string which needed a longer
delimiter was removed in 10997c39a3d559d699143f67e9ede7947e2193b3.
2023-12-13 11:15:57 +01:00
Goncalo Gomes
cab2a1b8f1 fix #7821: all cases of the calculation should be cached
in the previous logic some cases return from the function and others
would set a return variable that would be set later.

this commit, changes all the cases into all assignment.
2023-09-14 10:10:17 +02:00
Charles Dang
7d05b3f441 We don't like unnecessary heap allocations 2023-08-11 15:07:03 -04:00
Pentarctagon
c44cc2742e Copyright update.. 2023-04-29 10:48:11 -05:00
gfgtdf
409cef794b Replace some if (false) wtih better code.
Trying to recover what the intention was here.
2023-04-03 18:49:13 +02:00
gfgtdf
f8bd32eb15 Deploy and refactor config::optional_child
Previously the config class had an operator bool and
it was a common pattern to use if(const config& = cfg.child(..)).
While this pattern was nice to use. It has severe drawbacks, in
particular it was unclear whether a function that took a config&
parameter allowed "invalid" configs, while most functions
did not, there were some that did. Furtheremore it lead to a few
buggy codes that were unconvered by this change (Not fixed though!),
in particular codes that tested local config objects that were
not references to being invalid, which could never be the case.
This commits replaces those with just `true` in order to not
change behaviour.

Some obvious cases were also removed including for example
things like `assert(config());` There is ony case in the ai code
that i'm not 100% sure of where one implementation of a virtual
function checked for an invalid config and another one that didn't.

With this, all code that check for a config child to be
present now uses config::optional_child which returns an object
that behaves similar to optional<(const) config&>, so it throws
on invalid dereferencing. But it also has operator[string] for
convinience, in particular to make is similary
easy to use the the previous `if (config& = .. child())`.
Also it has a tool DEBUG_CONFIG which tests whether all
optional_config values are checked before they are derefereneced.

Another method manditory_child was
added that throws when the key is not found, which replaces all
occurances of child() that did not check whether the result was
valid. This was neccecary (this= adding a new method instead of
renaming .child) to keep track of converted changes, and be sure
no occurances of child() were accidentally changed to the
throwing version.

We might want to rename one of mandatory_child or optional_child
to just child later. Not sure which one yet. I think it's better
to keep it in the current state (no config::child() ) for a while
though, so that people that currently used child() in their open
prs or other work get an error and not wrongly rely on the previous
behviour of config::child.

The interface of vconfig was not changed in this commit.
2023-04-03 00:39:12 +02:00
Tommy
c2ab49b887 Catch a few more missed logging newlines
Mostly with a space before the trailing newline.
2022-07-20 15:20:57 +12:00
Tommy
ba24612f73 Remove trailing newlines from multiline log messages 2022-07-20 15:20:57 +12:00
Tommy
a02709e0ff Remove \n from log lines with it as suffix on the final string 2022-07-20 15:20:57 +12:00
Tommy
1fe87c4e24 Remove "<< '\n';" from log lines 2022-07-20 15:20:57 +12:00
Tommy
6ace55e063 Remove << "\n"; from log lines 2022-07-20 15:20:57 +12:00
Tommy
1c25ebdfa2 Remove std::endl from log lines, now that it's added automatically 2022-07-20 15:20:57 +12:00
Tommy
6a1cda1f28 Remove newline from PLAIN_LOG entries, or use STREAMING_LOG 2022-07-20 15:20:57 +12:00
Celtic Minstrel
63ecdf5781 Add [event]filter_formula= for WFL event filtering 2022-07-18 21:56:42 -04:00
Pentarctagon
3874fe5f0d Remove <iostream> from a lot of places. 2022-07-06 20:11:11 -05:00
Pentarctagon
c8e948a62b std::cerr -> PLAIN_LOG, to stop bypassing the logging system 2022-07-06 20:11:11 -05:00
Tommy
738392069d Fix a whole bunch of bad indentation.
Mostly spaces where tabs should have been used.
2022-06-25 15:24:03 +12:00
mattsc
ce9ba142bc Add new AI aspect allow_ally_villages 2022-06-22 08:00:50 -07:00