1218 Commits

Author SHA1 Message Date
Chris Beck
6603de667b move animations vector to animation component, drop header in unit 2014-06-17 11:52:44 -04:00
Chris Beck
504e4932b5 split off animation fcs from unit to unit_animation_component
This is a strict refactor, all we do is move the functions and
variables used just for animations to "unit_animation_component",
and include the necessary headers appropriate.

With a bit more work we can probably remove the graphics related
headers from unit.hpp
2014-06-17 02:18:46 -04:00
Chris Beck
0be1d731d5 add drawable unit class
drawable unit inherits from unit, and implements the draw function,
used only by the display. when the display wants to use the function,
it casts a unit pointer to a drawable_unit, and draws it. this
improves encapsulation.
2014-06-16 22:10:31 -04:00
Chris Beck
ab23b03b22 move actions::unit_can_move to be a method of display_context::
I would have put it in game board but it needs to be available
to display / drawing code... would be good to refactor to simplify
this.
2014-06-16 21:01:36 -04:00
Chris Beck
9e7dc5ba00 unit_map, lua, team recall lists use reference counted UnitPtr
Defines a UnitPtr (boost::intrusive_ptr<unit>, after irc
discussion), which the engine will use to pass units between
different modules, and which it is planned that the animation
engine will also hold, to avoid segfaulting.

Unfortunately this commit could not really be made smaller, it is
necessary to change all of these things over at once, or specify
very complicated deletion policies for the units at the
boundaries of the modules.

The main intention of the commit is to get these three modules
using a reference counting system to hold units, even as they
are passed between the modules. Eventually the fake units and
other kinds of units will all also be held in such pointers, and
the unit_map::unit_pod object will be replaced itself with a
single smart pointer.

Finally the animations objects will hold weak pointers to units,
to fix the segfault issues.

This commit required us to change over the whiteboard, most of
the action_wml, and the AI modules, since these make use of the
recall list from the team class.

We also add the unit_ptr.hpp header file, to allow to forward
declare the UnitPtr object essentially, and it's const variation.

If we forward declare the intrusive_ptr functions, we can forward
declare the UnitPtr type and avoid including unit in a bunch of
places that we don't need to. (Good as that is a very heavy
include.)

The declaration is now in unit_ptr.hpp

Since we can't forward declare inheritance, the easiest way to
resolve linker problems is to not derive unit from the
reference_counted_object class and just include the intrusive_ptr
boilerplate as usual instead.
2014-06-15 14:57:47 -04:00
Chris Beck
a60d5b0018 move formula ai features of unit to a unit formula manager
This use of handle-body idiom saves *alot* of includes, since a
huge number of objects include unit indirectly, and make no use
of the ai formula features.
2014-06-14 18:39:57 -04:00
Chris Beck
1796b4d7a0 remove unnecessary resources.hpp include from unit.hpp
It turned out that alot of compilation units were using resources
but not including the header, and only getting circuitously
through the display.hpp header which got it from unit.hpp. This
is an improvement since unit itself doesn't need the header,
and most classes probably don't either.
2014-06-14 17:17:45 -04:00
Chris Beck
85de1c2c55 remove unused portrait function from unit
This function was entirely unused, and deleting it allows us to
remove the "portrait.hpp" include from the unit.hpp header. (!)
2014-06-14 16:38:34 -04:00
Chris Beck
22cc827d71 finish removing resources::game_map
The remaining uses are just, checking whether or not the pointer
is null, or resets to its value, or simply storing it in a local
variable.

It might be appropriate to add resources::game_map back as a
function taking no parameters, at least this is flexible
enough to be changed later easily.
2014-06-10 21:26:41 -04:00
Chris Beck
aab7edd88c remove resources::game_map (part 2)
This the result of executing, in folder src/, the following

find . -type f -exec sed -i 's/\*resources\:\:game_map/resources\:\:gameboard->map()/g' '{}' \;

and carefully inspecting the result.

We also had to add game_board.hpp includes in various places,
and change the arguent order of unit::is_visible_to_team --
this function was taking *resources::game_map as its default
argument, and we do not want to include game_board in unit.hpp,
as it creates cyclic dependencies. This was resolved by
eliminating this as a default value -- this is an improvement,
since usually when this function was called it was in a context
where a game_map was available already locally anyways.
2014-06-10 20:53:00 -04:00
Chris Beck
4830b8ee3c partially remove resources::game_map (part 1)
This is the result of running, in src/ directory, the following:

find . -type f -exec sed -i 's/resources::game_map->/resources::gameboard->map()./g' '{}' \;

and carefully inspecting the result, and adding "game_board.hpp"
2014-06-10 20:13:11 -04:00
Chris Beck
ca01a4be02 facing and hidden become mutable attributes of unit
This is needed to be able to do animation with const units.
2014-06-10 12:58:53 -04:00
Chris Beck
390babf184 unit animation fcns become const
This commit makes the main unit animation accessor / mutator
functions applicable to const units, and makes the animation
state member variables mutable to allow this.

const'ed member functions:

set standning
idling
selecting
ghosted
disabed_ghosted
clear_haloes
refresh
invalidate
redraw

mutable member variables:

animation state enum
boost scoped pointer anim_ (can be reset in the redraw fcn)
next_idling_
frame_begin_time_
unit_halo_
refreshing_
draw_bars_

The purpose of this is to improve encapsulation of units, as now
we can use const units in the display functions, and reserve non-
const unit references for use in the game logic.
2014-06-10 01:10:00 -04:00
Chris Beck
2282f6e90a remove unnnecessary location argument from unit::invalidate
This function was always called with the current location of the
unit as the argument, so we simplify it.
2014-06-09 23:55:40 -04:00
Chris Beck
654fd22ba8 pass display as an argument to unit::invalidate
Previously it always used the singleton display function, but this
seems better.
2014-06-09 23:55:40 -04:00
Mark de Wever
e35f4bb501 Strip trailing whitespace. 2014-06-09 15:26:19 +02:00
Chris Beck
bdd3edd58c catch exceptions thrown in unit_movement_resetter dtor 2014-06-07 23:43:19 -04:00
Chris Beck
0e24beb6aa catch exceptions thrown in unit dtor 2014-06-07 23:42:06 -04:00
Chris Beck
94b057f231 Merge branch 'move_temp_unit_structs_to_game_board' 2014-06-03 15:35:31 -04:00
Chris Beck
1ec273c882 move temporary unit movers to game_board, adapt slightly. 2014-06-03 15:17:54 -04:00
Alexander van Gessel
eb9076af9a Merge pull request #186 from cbeck88/fixup_statue_orbs
no movement orbs for enemy statues
2014-06-03 19:44:21 +02:00
Chris Beck
0f2777e167 no movement orbs for enemy statues
Putting a movement orb on an enemy petrified unit is rather
redundant, so this commit prevents that behavior. Statues owned
by the viewing team will still have orbs, which seems acceptable.
2014-06-03 10:38:10 -04:00
Boldizsár Lipka
ac96a2b91b Move some functions to sdl/rect. 2014-06-03 10:30:12 +02:00
Chris Beck
096cb97cc1 Merge pull request #180 from cbeck88/add_game_board_struct_alternate
This is a refactor to introduce an object encapsulating the unit map, the game map, and the list of teams. Introducing this object permits us to move a substantial amount of code out of the play_controller object, and also to give a home to some helper functions in unit.?pp that previously sat in the global namespace. It also allows us to simplify the construction of some of the clients of play_controller.

This refactor is ongoing WIP. The goals are

(1) better organize the architecture of the engine, to make saving and reloading easier.
(2) Facilitate the introduction of an improved pathfinding mechanism, which will need to sit between most of the other engine modules and the unit map / game map.
(3) Refactoring clarifies what the existing code is doing, therefore it may help us to find bugs in the current system, which may be fixed independently of the refactor in 1.12.
2014-06-01 13:42:10 -04:00
Chris Beck
df74d891d2 give global fcn's (find/get)_visible_unit a home in game_board
Unit tested and playtested after moving the functions decalarations,
and definitions, adding links to play_controller::game_board from
resources.?pp, and executing find and replace commands:

git grep -lz 'find_visible_unit(' | xargs -0 perl -i'' -pE "s/find_visible_unit\(/resources::gameboard->find_visible_unit\(/g"
git grep -lz 'get_visible_unit(' | xargs -0 perl -i'' -pE "s/get_visible_unit\(/resources::gameboard->get_visible_unit\(/g"
2014-06-01 11:31:47 -04:00
Mark de Wever
954e068a54 Move create_rect to the sdl namespace.
This library dependency issues with CMake.
2014-05-31 22:04:36 +02:00
Chris Beck
30c179b92d refactor enum casts: prefer lexical cast default and cfg["x"].str() 2014-05-27 03:44:23 -04:00
Chris Beck
f09d405629 cleanup previous two find and replace results
Just wanted to remove the empty strings that got created:

find . -type f -exec sed -i 's/<< "" <</<</g' '{}' \;

find . -type f -exec sed -i 's/<<"" <</<</g' '{}' \;

I also unstaged tools/schema/tags.cpp, since I don't think I changed
that.
2014-05-20 15:54:16 -04:00
Chris Beck
03a956d05c Make sure all warning logs are flushed, so travis gets the results.
This is the result of running command, in src/,

find . -type f -exec sed -i 's/\(WRN.*\)\\n\"\;/\1\" << std::endl\;/g' '{}' \;

and inspecting the results.

Also ran this subsequently:

find . -type f -exec sed -i 's/\(WARN.*\)\\n\"\;/\1\" << std::endl\;/g' '{}' \;

which only affected render.cpp
2014-05-20 15:48:36 -04:00
Chris Beck
c73b5945d9 add static const members ZERO, default_dirs, of map_location
Replace local constants appearing elsewhere with these.
The definitions are inlined.
2014-05-20 04:49:12 -04:00
David Mikos
62e527c8b7 don't move health bar with unit where terrain elvation differs. 2014-05-18 15:11:50 +09:30
David Mikos
e92781614d smooth unit movement over terrain with elevation 2014-05-18 14:36:08 +09:30
gfgtdf
02a97838b8 enable msvc bool conversion check.
we now enable warning 4800. I ran though the msvc compile with this
warning and i found some (in overlay.hpp, unit.cpp, whiteboard/move.cpp)
unintended implicit bool b = cfg["attributename"] casts that use
the implicit attribute_value to int cast and then a int to bool cast.
So for attributename=true b would be false. So i believe this
is a useful warning.

There are also a lot of implicit int to bool cast from the SDL and LUA
C-libraries which use int instead of bool because C doesn't have bool.
In this case this warning is less useful, but i still think it's worth
it since a "!= 0" or "== 1" isn't cost.

Plus if someone really wants to disable this warning he can still
disable it in the msvc project settings, while before is was not
possible for someone to enable this warning the the settings.
2014-04-27 20:01:50 +02:00
David Mikos
83836b1516 Fix bug #21967: fix crash when unit modification to traits has empty id 2014-04-25 13:25:39 +09:30
gfgtdf
552b751731 fix 21909
previously we passed a temporary object and saved a reference to it in
unit_callable contructor. Leading to sefaults and undefined bahaviour.
2014-04-23 22:09:34 +02:00
Chris Beck
5626d89305 fixup blindfold to work with PR 121
fixes issue where using blindfold would cause OOS.
now we only check blindfold flag now when redrawing the unit,
not for other purposes
2014-04-14 16:21:07 -04:00
gfgtdf
75d81ee49c use new synced_context: use new rng
the plan is, that random_new::generator will be a object that does synced random calls during a synced context and otherwise not,
so that we cannot create OOS anymore by using random in unsynced actions like select event

the intention is also to unfy random calls for attacks and random calls and for other actions like traits and [set_variable] rand= .

the synced random generator will be set with the set_scontext_synced object.

the new rng will be similar to the old rng used for attacks becasue it will ask the server for a new seed for every new user action (=recruit, attack...) that requires random numbers.

Previously there were 2 different random generators, one for attacks, and one for other things, pr 121 is supposed to fix the problems with the "sending data over teh network first" an we try to throw the old rng for non attack things out. So that attacks and other tings use the same rng.

We use a new random generator which is automaticly synced during the execution of scned_context::run_in_scned_context, and otherwise not. So we cannot cause oos anymore by using rand= from an unsnced command like "select"
Alternativeley we can also set the new random synced by using the new RAII object set_sconext_sycned, this happens for example during prestart events.
Unlike the old random generator, the new random generator is not determinstic by default because it asks the server (or itself in a SP game) for a new seed, at every side command (attack, move, recruit ...) that requires random, similar to how the previous rand for attacks worked (it doesn't ask at the beginning, just the first time it is needed unlinke how attacks worked before). That way i can also use the same rng for attacks and for other random choices.

I also plan to move the code from set/get_random_results to syncec_checkup.cpp later.

this commit is part of pr 121.
2014-04-02 23:33:52 +02:00
Ignacio R. Morelle
bbe8b7a816 Merge branch 'Add-unit-instance-recall-costs' of https://github.com/Aishiko/wesnoth into Aishiko-Add-unit-instance-recall-costs
Conflicts:
	changelog
2014-03-21 01:05:39 -03:00
Aishiko
2a923b5a26 Corrected use of cfg["foo"], removed 2 assignments, and 2 whitespace fixes
Changed from cfg["foo"] > number, to !cfg["foo"].blank(). Turned a cfg call into
just a default assignment.  Added a .to_int to a cfg["foo"] call to prepare
against bad user input.  Finally added whitespace to 2 lines to get them to line
up with the rest of the lines.
2014-03-20 23:25:16 -04:00
Aishiko
c6d11a5f5e Implement unit instance recall costs.
Actually allows for the unit instance recall costs to be used. Proper
taking of the gold and undoing the cost for each unit is implemented
and works.  At advancement if the unit's current recall matches their
unit_type's recall_cost then it takes the new unit_type's recall_cost
otherwise it keeps whatever value it currently has until it fails this
check.  Recall costs are also now persistant and will carry over from
one scenario into the next as well.

If a cost is not set, it will continue to use the team/side/default
costs, these changes should not affect the current workings when
dealing with unaltered scenarios, and unit config files.  I repeat This
will not affect or change the currently way things work UNLESS a user
alters a file or includes the new recall_cost (as in copies and
modifies a unit in the scenario unit files) for a unit instance in
their scenario file(s).
2014-03-17 17:49:15 -04:00
Aishiko
a723d5fa59 Add single unit instance recall_costs
Add the variables, lua, and wml support variables to allow a scenario
designer the ability to define different from the standard recall costs
or team recall costs for both individual units and unit types.
from least to highest order of precendent we'll have default, team/side,
unit_type, and finally individual units.

The tag in the scenarios and in the unit config files is recall_cost=int.
2014-03-15 10:03:56 -04:00
fendrin
1e5d58af6a Made the orb and minimap colors configurable by the preferences. 2014-03-15 14:37:16 +01:00
Chris Beck
426721f03f repair unit_map unit tests
in an earlier commit these tests were disabled because they were segfaulting
and blocking the test suite from running. the cause was obscure: the tests
were based on making a dummy unit type and inserting / reinserting it
into the unit_map. however, it turns out that in the current code, a freshly
constructed unit_type is not safe to be used to construct a unit. the reason
is that then it does not have any genders defined, so when the unit is built
it will not find any genders and fail with segfault, or even more bizarrely,
a division by zero error. i found that even running with gdb did not give
an actual line number, and simply said that the failure occurred in the
unit constructor, a function whose initalizer list spans several pages.

the correct fix is to invoke "unit_types.build_unit_type" on the unit type
before using it. this permits the unit tests to run.

additionally i added an assert to the generate_genders function in unit.cpp,
which surely should have been there in the first place.
2014-03-11 00:26:34 -04:00
Alexander van Gessel
1c528a7a37 Make 'none' a special case for [unit_type]ellipse (bug #21724) 2014-02-28 20:59:22 +01:00
Chris Beck
874e9f0e74 fixup blindfold
fix a logic error -- actually if we are blindfolded, it doesn't matter if we are an observer, we shouldn't see any units. also this is more efficient.
2014-02-24 17:51:42 -05:00
Chris Beck
20440faa55 units now say that blind observers can't see them 2014-02-23 22:27:15 -05:00
Mark de Wever
0d88bc63fc Remove an unused constructor parameter. 2014-02-03 21:44:21 +01:00
mattsc
22dec61d3e Fix logic of [filter_vision] in Standard Unit Filters (SUFs)
Previously, the [filter_vision] tag would cause a false positive when a
unit was on terrain on which it was invisible and that also was under
fog/shroud.  There might have been other combinations that did not work
either, I did not check that.  I did check that all 8 combinations of
visble=yes/no, the unit hiding due to terrain or not, and the hex being
under fog/shroud or not work now.
2014-01-17 19:19:27 -08:00
Mark de Wever
ae4e97bc72 Fix a Doxygen style issue.
The comment was accidentally seen as Doxygen comment, but that was no
the intention.

The issue was found by Clang 3.4.
2014-01-05 16:40:45 +01:00
Ignacio R. Morelle
a4f47a63c7 New Year copyright update 2014-01-01 02:08:52 -03:00