Return true if the key has a meaning in this widget and therefore
should not be treated as a hot key of another widget. Do this even if
the action of the key could not be taken.
Also, if Bos Wars exits because of missing AI scripts,
then print the error message with fprintf rather than DebugPrint
so that it appears in release builds too, and exit with Exit(1)
rather than Exit(0) so that the parent process will know about
the error in case it cares.
Fix two bugs in error handling of LuaCallback::run:
1. It used the Lua function _TRACEBACK, which exists in Lua 5.0 but
not in Lua 5.1. In bos/stratagus SVN trunk r8495 on 2007-01-07,
LuaCall was changed to use debug.trace instead. Do the same to
LuaCallback.
2. It passed the wrong Lua stack index to lua_pcall as the error
handler function. lua_gettop returns the index of the topmost
value, not the index that the next pushed value will get.
Also, remove _TRACEBACK from the blacklist now that it is used neither
in Bos Wars nor in any version of Lua supported by Bos Wars.
UnitTypes["unit-assault"] was a shorthand for UnitTypeByIdent("unit-assault")
but all Lua scripts used the latter directly. Also, the UnitTypes variable
ended up in saved games (as UnitTypes = {}) and I suspect that would have
discarded the metatable and thereby prevented the shorthand from working.
Originally, a map author could define a separate AI script for each
(class, race) combination. Each of those scripts also required a
unique name. Because support for races has been removed, AI class
names are no longer useful.
Remove CAiType::Class; use CAiType::Name instead. Remove the class
parameter of DefineAi; it was called only from RegisterAi, which
passed the same string as name and class.
Remove CAiType::Script and PlayerAi::Script; use CAiType::Name
instead. Ignore the "script" tag of DefineAiPlayer when loading
a game, and do not generate it when saving.
This commit does not require any changes in individual AI scripts.
This changes the behavior of CclGetNumUnitsAt a little. It now checks
unit->Constructed even if unittype is a category rather than an
individual type. This does not affect the bundled maps because the
only use of GetNumUnitsAt is in campaigns/swindler/level01.sms,
which searches for "unit-assault", and assault units do not appear
on the map before they are fully trained.
The earlier fix in bos SVN trunk r9918 on 2010-07-02 does not work
reliably with GCC 4.4.5; it seems std::map::~map does not bother
marking the map as empty. Instead, rely on C++ constructing objects
in the order of definition and destructing them in the opposite order.
In DEBUG builds, also add assertions to catch any attempt to access
Graphics or GraphicsHash before they are constructed or after they are
destructed.
SetAStarFixedUnitCrossingCost and SetAStarMovingUnitCrossingCost only
validated the new costs. Make them set the corresponding variables too.
CostMoveTo in pathfinder.cpp still doesn't actually use
AStarFixedUnitCrossingCost. There is a FIXME comment about that.
I don't know why these costs must be greater than three.
AStarFindPath increments them by one for each step anyway.
This function was removed in bos SVN trunk r9190 on 2007-10-13.
The FogOfWarOpacity variable still exists but is no longer modified.
Make it const for good measure.
Don't tell tolua++ that some functions take const std::string &
parameters. Pretend they are plain std::string instead.
This stops tolua++ from generating code to copy the strings
back to Lua after each call. The const has no effect on that.
The effect is most noticeable in tolua_stratagus_CPatchManager_newPatchType00.
If the player selects an engineer and right-clicks on a hot spot,
order the engineer to build a magma pump there. More generally,
try to build something on top of the clicked unit.
AnimationsByIdent returned AnimationMap[ident]; UnitTypeByIdent
likewise UnitTypeMap[ident]. std::map::operator[] always returns a
reference to a value in the map; if it doesn't find the key in the
map, it adds it there with a default value. This could cause spurious
NULL values to be added to these maps, for example if buttons were
defined for nonexistent unit types.
Work around an SDL 1.2 misfeature that makes Bos Wars in full-screen
mode unplayable with tablet devices that report absolute coordinates.
Fixes: http://bugs.debian.org/559615
(boswars: uncontrollable with Wacom tablet when in full-screen mode)
Without this, 2x2 units such as unit-pathfinder get blocked by
themselves, and AI forces containing only such units never find an
enemy unit to attack.
Fixes part of: http://savannah.nongnu.org/bugs/?30994
(Make AI work with naval units)
This was a bug in engine/action/action_attack.cpp. The priority/cost
computations did not get called because the attacking unit forgot that
its goal was weak. One way to trigger the bug was by telling an
assault unit to go attack a place near an enemy camp. The assault
unit moved part of the way, then noticed an enemy engineer near the
camp, took him as a weak goal, and killed him. Next, SubAction became
0 again, and the assault unit was about to continue to the ordered
place, but HandleActionAttack noted that SubAction was 0, and called
CheckForTargetInRange, which found the enemy training camp and set
that as another weak goal, setting unit->SubAction |= WEAK_TARGET.
SubAction thus became 2 = WEAK_TARGET, but HandleActionAttack (still
in "case 0:") noticed that the assault unit now had a goal (weak or
not), and because the training camp was close enough, began also
attacking it and set unit->SubAction = ATTACK_TARGET. And that's
where the WEAK_TARGET flag was lost. I guess the same could have
happened without the enemy engineer.
Fix by preserving the WEAK_TARGET flag in each place where SubAction
is changed, unless the flag must be clear there (in which case, assert
that), or the whole order is being replaced (from SavedOrder or just
cleared out).
Fixes: http://savannah.nongnu.org/bugs/?30971
(Units attack buildings too stubbornly)
When a worker finishes harvesting and has no other orders, it looks
for another harvestable unit. Change this so that if the harvested
unit (e.g. a tree or a rock) contained only one type of resource
(energy or magma), then the worker looks only for units that contain
the same type of resource. This should help the income stay balanced.
Fixes: http://savannah.nongnu.org/bugs/?30856
(Workers swich to other resourse type after one deposit complete)
The shipyard is a naval unit but also allowed on land. It is not a
ShoreBuilding because there aren't enough coast tiles in the Gosh
patches. This combination made it attackable only by units that have
CanTargetSea=true; CanTargetLand had no effect even though the
shipyard typically has 5 or so land tiles under it.
To make the shipyard attackable also by units that have
CanTargetLand=true, change the CanTarget function so that it treats
UnitTypeLand and UnitTypeNaval as equivalent, and instead examines
MovementMask. With the Bos Wars game data, the shipyard is the only
unit type affected by this change, I think.
Before: "Patch: guerillawarfare.map - (0, 0): land"
After: "Patch (0, 0): guerillawarfare.map - Field (12, 34): land"
Also, it now shows the coordinates even if there is no patch under the
cursor.
To train a unit, you now need at least one suitable map field under
the trainer unit. You can thus no longer train big ships in a
shipyard built at a shallow lake. Previously, big ships built in such
a place came into existence over the nearest deep water, which could
be at the other side of the map. You can still get that effect if you
have a shipyard at a small but deep pool and build that full of big
ships, but at least it's now no worse than training an islandful of
engineers and having them leak over to the mainland.
This fixes the shipyard being too large to fit in the strip of water
that an engineer walking along the coast can survey by himself.
We've got a new type of build restriction now. I hope it will be
useful for other stuff too.
The engine played this sound when a worker finished a building from
inside the building. Support for that was removed in r9678 on
2010-03-14, and the Bos Wars game data did not have any sound file for
that event anyway.
The engine never plays this sound. Until r7108 on 2005-03-20, it was
used in AnimateActionBuild and DoActionRepairGeneric. Nowadays, the
animation script names the sound instead, so it need not be defined in
the unit type.
The engine never plays this sound. Until r7108 on 2005-03-20, it was
used in AnimateActionHarvest. Nowadays, the animation script names
the sound instead, so it need not be defined in the unit type.
CUnitType had UnitType, which selected between land, air, and sea;
and also separate LandUnit, AirUnit, and SeaUnit flags. Remove the
separate flags and always check UnitType instead. This change does
not affect gameplay because:
- The LandUnit and SeaUnit flags were not read at all.
- The AirUnit flag matched UnitType == UnitTypeFly in all unit types.
In the map editor, if the user first pressed Ctrl+Shift+t to tile the
selected patch type over the whole map but then wanted to undo that,
he had to press Ctrl+z for quite a while: first to remove all the
added patches one by one, and then to restore the original patches one
by one. Change this so that one Ctrl+z undoes the whole operation,
and one Ctrl+y redoes it.
Likewise, if the user adds a single patch on top of others and thus
causes the editor to remove them, one Ctrl+z will undo the addition
and all the removals.
It seems there aren't any editor commands that affect multiple units.
In OpenGL mode, the minimap did not draw any patches in 24bpp RGB
format, such as the "gosh" patches before r9913. This happened
because GetColor set the alpha as zero by default and the pixels then
became wholly transparent. Fix by making them wholly opaque.
According to feb, 24bpp RGB patches make blitting too slow and should
not be used. Anyway, they worked without OpenGL and should work with
OpenGL as well.