Commit graph

7240 commits

Author SHA1 Message Date
kon
2374d6ea49 Allow limiting the length of text in gcn::TextField
Add gcn::TextField::setMaxLengthBytes and
gcn::TextField::getMaxLengthBytes.  Publish them to Lua.
Nothing calls these functions yet.
2011-10-02 08:05:21 +00:00
kon
9787d06786 Return true from gcn::TextField::keyPress if recognized
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.
2011-10-02 08:05:09 +00:00
kon
f81d8dcd97 Don't let gcn::TextField::mCaretPosition get out of range 2011-10-02 08:05:01 +00:00
kon
b7c156e5ff Remove unused hotkey functions in gcn::KeyListener
Virtual functions gcn::KeyListener::hotKeyPress and
gcn::KeyListener::hotKeyRelease were no-ops and never called.
2011-10-02 08:04:52 +00:00
kon
6e737ac698 Document the bool return values of keyboard functions 2011-10-02 08:04:43 +00:00
kon
56f9762b8a Remove unused gcn::KeyInput::mButton 2011-10-02 08:04:34 +00:00
kon
a052aeaaa4 Fall back to "ai-passive" only.
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.
2011-09-30 17:42:27 +00:00
kon
7fd148d1fd Fix Lua error backtrace in LuaCallback
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.
2011-08-08 05:09:52 +00:00
kon
25d5eb732c Remove CclGetResourceByName
The CclGetResourceByName calls were removed in bos SVN trunk r8780 on
2007-04-27.
2011-07-26 17:25:10 +00:00
feb
e5ec703759 Fix and speed up png screenshots when the display uses 24 bpp.
Untested.
2011-07-17 19:45:15 +00:00
feb
f8fc99df26 Remove variables which are set but unused. 2011-07-17 19:30:31 +00:00
kon
716cdb44ef Document the weird numbering of frames in missiles. 2011-07-17 11:13:41 +00:00
kon
493fd5ae42 Removed dead variable neg in MissileNewHeadingFromXY 2011-07-17 11:13:34 +00:00
kon
28005301b9 More comments in MissileNewHeadingFromXY 2011-07-17 11:13:29 +00:00
kon
b9a47bba45 Remove Lua variable UnitTypes
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.
2011-07-16 21:05:14 +00:00
kon
fe54b27d51 Blacklist 42 more variables from being saved
And remove "Upgrades" from the blacklist because nothing uses that
variable nowadays.
2011-07-16 19:23:30 +00:00
kon
98fe835bc5 Move the Lua variable blacklist to a separate function 2011-07-16 19:23:25 +00:00
feb
c196f1809d Fix some of the GCC 4.6.1 compiler warnings with -Wall -Werror triggered by [-Werror=unused-but-set-variable]. 2011-07-08 21:42:53 +00:00
kon
d923dca483 Remove AI class names.
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.
2011-07-08 21:23:29 +00:00
feb
06be930584 Fix compilation error about a missing tolua++.h header file.
That header should not be included in script_player.h. tolua++.h is only needed by tolua++ itself.
2011-03-09 21:02:09 +00:00
kon
3efba8c31c Add optional param unittype to ChangeUnitsOwner.
And rewrite the function using tolua++.
2011-03-05 14:02:44 +00:00
kon
9ac3a69fc3 Move common code to new func TriggerMatchUnitType.
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.
2011-03-05 14:02:34 +00:00
kon
c84ac83904 Fixed crash when exiting because Graphics and GraphicHash are freed before CPatchManager
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.
2011-03-05 14:02:21 +00:00
kon
da3b369551 Let Lua update AStar*UnitCrossingCost
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.
2010-11-25 15:52:12 +00:00
kon
f850a25529 Remove documentation of SetFogOfWarOpacity
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.
2010-11-25 15:51:33 +00:00
kon
3fe67cb65c Pass std::string from Lua to C++ by value
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.
2010-11-25 15:51:27 +00:00
kon
7e79f989b0 Add comment about OpenGL in CGraphic::Flip 2010-11-25 15:44:06 +00:00
kon
81dd5ca909 Build magma pump on right-click
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.
2010-11-10 20:43:06 +00:00
kon
8989c431f5 Don't implicitly add NULLs to AnimationMap, UnitTypeMap
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.
2010-11-10 20:42:59 +00:00
kon
d5f4c63e99 Fix tablet input in full-screen mode
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)
2010-10-17 12:57:03 +00:00
kon
55fcc46871 Unmark unit field flags for pathfinder calls
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)
2010-09-19 12:21:29 +00:00
kon
430c9a4321 Help the AI find places to build shipyards
Fixes part of: http://savannah.nongnu.org/bugs/?30994
 (Make AI work with naval units)
2010-09-19 12:21:22 +00:00
kon
1bd0fe5c1e Preserve WEAK_TARGET flag in more places
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)
2010-09-19 12:15:25 +00:00
kon
c461e5edf5 After a unit is fully harvested, look for similar ones
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)
2010-09-19 12:11:58 +00:00
kon
8ab5bc2edb Correct assertions in CBuildRestrictionTerrain::Check
Reported in: http://savannah.nongnu.org/bugs/?30994
 (Make AI work with naval units)
2010-09-10 23:32:59 +00:00
kon
28f89124e6 Base the CanTarget checks on MovementMask
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.
2010-09-07 19:57:51 +00:00
kon
d9721992df Show cursor coordinates in status line of map editor
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.
2010-09-05 18:51:42 +00:00
kon
f2e5dc6abf Prevent training big ships in shallow shipyards
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.
2010-09-05 16:48:04 +00:00
kon
45a1ce1f1e Allow at most 8 land tiles under the shipyard
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.
2010-09-05 15:33:48 +00:00
kon
76586dbc5c Remove GameSound::WorkComplete
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.
2010-09-05 11:00:02 +00:00
kon
321923d281 Remove CUnitSound::Repair
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.
2010-09-05 10:59:56 +00:00
kon
dec50dbd61 Remove CUnitSound::Harvest
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.
2010-09-05 10:59:50 +00:00
kon
f97af9c9c6 Remove DefineUnitType RightMouseAction="sail"
It has been equivalent to "move" since r5329, and no unit types use it.
2010-09-05 10:52:38 +00:00
kon
45ca2cdfdb Remove LandUnit, AirUnit, SeaUnit flags from CUnitType
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.
2010-09-04 09:25:27 +00:00
kon
9524e0438f Add undo groups to the map editor
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.
2010-07-07 11:25:19 +00:00
kon
f6b5084e09 Fix 24bpp RGB patch support in minimap
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.
2010-07-06 08:02:25 +00:00
jim4
a45c0fae42 Fixed crash using opengl and switching from 640x480 to 800x600 2010-07-02 05:58:27 +00:00
jim4
523824f7ea Don't show buttons for buildings or units that aren't allowed 2010-07-02 05:42:53 +00:00
jim4
bb7b3f7232 Fixed crash when exiting because Graphics and GraphicHash are freed before CPatchManager 2010-07-02 05:42:32 +00:00
jim4
358ad0fdf7 Added ctrl-shift-t hotkey to tile the selected patch 2010-07-02 03:08:57 +00:00