Commit graph

89 commits

Author SHA1 Message Date
Martin Hrubý (hrubymar10)
bc4d22dc72 Migrate links to https if available - Fwd c18537edc0 2018-07-16 19:07:08 +11:00
Charles Dang
78ea6db7e8 Cleaned up a few unnecessary AI-related includes outside ai/ 2018-04-29 06:45:41 +11:00
gfgtdf
79072b7c3d fix OOS when undoing actions with synced choices
The problm was that the old code tried to use `undo_stack().can_undo()`
to check whether the current action can be undone. But
`undo_stack().can_undo()` uses the undo stack which is only updated at
the end of each action, so it cannot be used to check whether the action
that is currently executed can be undone.

This code removes some assertion that were wrong due to the
justmentioned.
2018-04-04 10:43:26 +11:00
Matthias Krüger
a2168d2e24 codespell fixes to /src 2018-02-08 21:54:09 +11:00
Gregory A Lundberg
b5f76eff79
Bump copyright to 2018 2018-01-19 00:02:20 -06:00
Charles Dang
693735d90c Fixed a bunch of log output and code comment typos
[ci skip]
2017-11-24 01:14:03 +11:00
Charles Dang
20eb42477c Cleaned up shared_ptr assignment
Made use of reset, make_shared, or direct assignment instead of creating new shared_ptrs.
2017-09-12 11:15:47 +11:00
Celtic Minstrel
96ca0b026e Replace config_of with new variadic config constructor 2017-05-21 16:27:46 -04:00
Charles Dang
e90d11d02a Renamed namespace 'random' to 'randomness'
This is because GCC 4.x has a problem with symbol name collisions with 'random'
2017-04-21 03:05:52 +11:00
Charles Dang
d8ed11c2b1 Drop the _new suffix from random_new
The 'old' random code has long been removed.
2017-04-20 08:48:47 +11:00
Celtic Minstrel
b4dc11ce36 Belated 2017 copyright update 2017-03-19 10:05:38 -04:00
gfgtdf
41c4ecbe7d remove some now unused code 2017-02-24 00:46:31 +01:00
Charles Dang
e22c8967ee Cleaned up global.hpp includes 2016-12-17 15:21:04 +11:00
Charles Dang
9baabccf91 Use standard library includes instead of C includes when possible 2016-11-30 11:48:10 +11:00
gfgtdf
f37d5d941f Don't freeze the application when waiting too long for a random seed. 2016-09-08 22:14:49 +02:00
gfgtdf
e75325a399 fix assertion in synced_context::ask_server_choice 2016-08-04 17:53:51 +02:00
Charles Dang
05092ba2f6 Refactor most boost pointer related stuff to use their stdlib counterparts
This constitutes drop-in replacements for:

* boost::shared_ptr
* boost::scoped_ptr
* boost::weak_ptr
* boost::enable_shared_from_this
* boost::static_pointer_cast
* boost::dynamic_pointer_cast

This excludes boost::intrusive_ptr, except for stray includes. Refactoring that is more complicated.
2016-07-25 09:28:42 +11:00
Charles Dang
211ba2e770 Converted remaining cases of boost::lexical_cast to our own lexical_cast implementation
Excludes uses in tools/
2016-07-24 17:28:51 +11:00
gfgtdf
dca57bd5b0 remove uses of network::error and fix gui2 mp lobby 2016-06-05 14:50:53 +02:00
gfgtdf
c27a026608 add a comment 2016-06-05 14:50:53 +02:00
gfgtdf
52f0e3ecd6 refactor mp and menu_events code
This adds play_controller::is_networked_mp() and
play_controller::send_to_wesnothd() which are now used to comminucate
with wesnothd during a game instead of using network::send_data and
network::nconnections() directly.

The main intention is to make future changes to this code easier
specially:
1) to have more than one connection during a game, for example to check
for updates
2) to replace the clientsided network code with boost asio.

In order to do that i needed a little change to the chat_handler class
which is used both ingame and in the mp lobby. And to do that i
had to cleanup up the menu_events.cpp file and move huge helper
classes into their own files.
2016-06-05 14:50:53 +02:00
Celtic Minstrel
4af12203d8 [on_undo] and [on_redo] now get a snapshot of the event context
This means they can access auto-stored variables.
However, using [unstore_unit] for $unit or $second_unit is not recommended.
Also, $unit.x and $unit.y may not be the same as they were during the original event.
(The same with $second_unit)
2016-04-05 21:21:48 -04:00
Celtic Minstrel
3ac7f8d970 NULL -> nullptr
A few cases of NULL were missed, since changing them led to errors
(Mainly instances where it was passed to a boost::function)
2016-03-31 00:42:38 -04:00
Charles Dang
876710af8c Use std::to_string() or equivalent wherever possible
This commit removes the utility srt_cast() function and replaces its calls,
along with calls to lexical_cast<std::string>() (and its boost variant),
with std::to_string().

In a few cases where the input type isn't compatible with to_string,
lexical_cast<std::string> is still used.

In other cases where lexical_cast was operating on MAKE_ENUM enums, the
call has been replaced with ENUM::enum_to_string, which is faster.
2016-03-31 11:18:51 +11:00
Celtic Minstrel
bc711f5f43 Consolidate related files into subdirectories 2016-03-20 16:20:09 -04:00
Charles Dang
800a590525 Moved synced_context replay check deeper
It's caught by more calls this way.
2016-02-24 01:10:13 +11:00
Chris Beck
ba51524f6e update copyright to year 2016
using this shell script:

find src -type f -print0 | xargs -0 sed -i "s|Copyright (C) \([[:digit:]]*\)\([ ]*\)-\([ ]*\)2015|Copyright (C) \1\2-\32016|g"
2016-01-02 23:59:31 -05:00
Elvish_Hunter
9b7b1751fd Removed trailing tabs and whitespaces from C++ source
I used this command line: find <source directory> -name \*.\[ch\]pp -print0 | xargs -0 sed -i 's/[[:blank:]]*$//'
2015-12-21 20:39:46 +01:00
gfgtdf
de3db53447 refactor get_user_choice
this prepares a patch to implement wait dialogs for user choices during
prestart events.
2015-09-20 21:52:48 +02:00
gfgtdf
6010455f56 add [on_undo]/[on_redo] actionwml
[on_undo]/[on_redo] contains tags that are executed when undoing the
current actions.
2015-09-11 22:33:32 +02:00
gfgtdf
12b901933a make the unit id manager a member of game_board
previously it was a singleton

the next unit id counter is part of the gamestate so it should be part of the game_state object.
2015-09-09 16:31:34 +02:00
gfgtdf
f5c64af8de use mt19937 also in default random generator
previously rng::next_random_impl() returned rand() which is in range
1-2^16. so random_new::generator->next_random() would return a number
1-2^16 in unsynced context and a number in 1-2^32 in synced contexts.
Now it always returns a number in 1-2^32.
2015-08-04 20:25:50 +02:00
gfgtdf
e4962c47f8 refactor set_scontext_(un)synced classes
renamed set_scontext_local_choice to leave_synced_context and
set_scontext_leave_for_draw to set_scontext_unsynced.
The old names do not fit anymore because set_scontext_leave_for_draw is
also used for wml menu items.

Also simplified the implementation of set_scontext_leave_for_draw.
2015-07-12 21:56:05 +02:00
gfgtdf
3b01d92547 refactor random seed server choices
we add a more generic server choice mechnism. The plan is to use it also
for controller changes by wml.
2015-07-08 03:02:24 +02:00
gfgtdf
b34dc86e37 fix an assertion when reloading an mp game 2015-06-25 20:44:29 +02:00
gfgtdf
99d88e0910 Fix an OOS
Previously it could happen that a client would wait for a remote user
imput while still having a non-empty undo stack. Becasue of this the
client would not send the move that issued the user input (because the
client thinks it is undoable) to the other clients which then never gave
the user input.

This resulted in a situation where the game could not proceed and had to
be aborted.

Fixed it by calling resources::undo_stack->clear() as soon as we know
that a remote user input is needed
(synced_context::set_is_simultaneously()). Also added some assertions to
guard against this situation.
2015-06-15 14:42:04 +02:00
gfgtdf
4a1c3f7898 add an assert 2015-05-29 23:09:10 +02:00
gfgtdf
b9904f6557 dont do replay checkup in set_sconext_synced destructor
Previously it was dont this way because we also wanted a replay chack in
case of an end_level_exception which was thrown by check_victory. Since
check_victory doesnt throw anymore this is not needed anymore.
2015-03-06 05:19:33 +01:00
gfgtdf
bb0ecd14c0 recorder writes directly into saved_game object
Previously recorder had config memaber and saved_game had a config
memeber.
And when saving a game the config was copied from recorder to saved_game
and the other way when loading a game.

Now the recorder object directly writes into the saved_game object. This
saves some copying when saving and loading data.

I also moved the pos_ variable from the recorder object to the
saved_game replay_recorder_base object, This fixes a bug where saving a
game during a replay also caused to not yet played turns to be written
into the savefile.
2015-03-06 05:19:31 +01:00
gfgtdf
fb68590637 more refactor of play_side and game_end_exception.hpp
Instead of having different exceptions (ai_end_turn_exception,
end_level_exception and restart_turn_exception) we now have one exception
(return_to_play_side_exception) that is used to escape from play_ai_turn
or play_slice and is catched in the play_side related functions.
The information why we returned to play_side is already stored in the
playsingle_controller object. That is also why we do not need the
possible_end_play_signal return value anymore.

play_controller::check_victory does not throw exceptions anymore
Also do_replay and thus turn_info::process_network_data don't throw
exceptions anymore when the scenario is finished by victory or defeat.
Instead it returns REPLAY_FOUND_END_LEVEL, this means
return_to_play_side_exception is not thrown during replay at all.

this also fixed up a previous commit 'refactor play_side' where
accidently play_idle_loop was called instead of play_human_turn in
play_side.
2015-03-03 21:49:30 +01:00
gfgtdf
9df349d646 more checks in [do_command]
also we fix run_in_synced_context_if_not_already it it supposed not to
execute the action if we are in a replay in an unsynced context.
2015-03-02 18:14:53 +01:00
gfgtdf
341c31a6b9 add "scenario_end" event
unlike 'victory' and 'defeat' events this event is synced.
2015-03-01 16:36:06 +01:00
gfgtdf
1fa8a29842 fix OOS caused by undo stack missmatch
see https://gna.org/bugs/?23323 for more description
2015-02-26 19:34:15 +01:00
gfgtdf
4251252506 refactor end_turn_exception
end_turn_exception was split into 2 exceptions.
restart_turn_exception/struct which is used when a side got reassigned
this case covers most of end_turn_exceptions previous usecases.
and ai_end_turn_exception which is only used by the ai internally, we
also move the throwing of ai_end_turn_exception fom
playsingle/mp_controller::handle_generic_event to
ai::action_result::execute so that non ai code that might call
handle_generic_event doesn't have to think about ai_end_turn_exception.

This also partly fixes a bug where undroiding a side caused the sides turn to end.
2015-02-26 17:11:12 +01:00
gfgtdf
277fffcb0c use replay::process_error instead of ERR_REPLAY for OOS
since replay::process_error might throw we cannot do this in
set_sconext_synced destructor anymore and have to call
do_final_checkup() ealier.
2015-02-04 15:55:17 +01:00
gfgtdf
7dc3969eec restore last unit_id when undoing/redoing
otherwise the unit ids would be come out of sync when undoing,
2015-02-04 15:55:15 +01:00
gfgtdf
ca8bae296e add oos check for next_unit_id 2015-01-30 00:40:52 +01:00
gfgtdf
dbb75bdd47 add oos debug mode and mp_debug_checkup class
The game sometimes does some checkup to test whether the calculated results in a replay match the ones calculated during the original game.
This data was stored in the replay inside the [command] for that action. The problem is that this doesn't work in networked mp because we often send the [command] before calculating the results.
I added an alternative mode that used get_user_choice to compare the results, this also works in networked mp but it causes a little more network traffic.
2015-01-08 17:09:07 +01:00
gfgtdf
88de21a5ff check is_replay on [set_global_variable] and [do_command]
adds a new method is_replay() to check whether we are in a replay.
fixes http://gna.org/bugs/?21906
Also also we make [do_command]/run_in_synced_context_if_not_already more
robust by checking is_replay
2015-01-06 23:54:40 +01:00
Ignacio R. Morelle
57ae45387a New Year copyright update 2015-01-01 19:07:35 -03:00