Added fast/slow speed modifier for tiles

This commit is contained in:
feber 2005-07-31 13:52:28 +00:00
parent 8e5dae35a3
commit 0a898e873d
9 changed files with 40 additions and 9 deletions

View file

@ -33,6 +33,7 @@
<ul>
<p><li>2.2 Released<p>
<ul>
<li>Added fast/slow speed modifier for tiles (from Fran&ccedil;ois Beerten).
<li>Added support for playing a movie in a campaign (from Jimmy Salmon).
<li>Fixed bug #1236481: Auto-repair doesn't work in network games (from Jimmy Salmon).
<li>Added SetTerrainEditable lua function (from Fran&ccedil;ois Beerten).

View file

@ -169,7 +169,6 @@ Note: This is the for the new map format. Not implented yet.
)
</pre>
<h2>Functions</h2>
<a name="LoadTileModels"></a>
<h3>LoadTileModels(luafile)</h3>
@ -178,7 +177,6 @@ Note: This is the for the new map format. Not implented yet.
Note: This function is used in the map files.
<p>
<dl>
<dt>luafile</dt>
<dd>The path to the lua file to load which will define the tilemodels.

View file

@ -155,7 +155,8 @@ int DoActionMove(Unit* unit)
d = 0;
}
move = UnitShowAnimation(unit, unit->Type->Animations->Move);
move = UnitShowAnimationScaled(unit, unit->Type->Animations->Move,
TheMap.Fields[unit->X + unit->Y*TheMap.Info.MapWidth].Cost);
unit->IX += xd * move;
unit->IY += yd * move;

View file

@ -86,7 +86,21 @@ static void UnitRotate(Unit* unit, int rotate)
**
** @return The flags of the current script step.
*/
int UnitShowAnimation(Unit* unit, const Animation* anim)
int UnitShowAnimation(Unit* unit, const Animation* anim)
{
return UnitShowAnimationScaled(unit, anim, 8);
}
/**
** Show unit animation.
**
** @param unit Unit of the animation.
** @param anim Animation script to handle.
** @param scale scaling factor of the wait times in animation (8 means no scaling).
**
** @return The flags of the current script step.
*/
int UnitShowAnimationScaled(Unit* unit, const Animation* anim, int scale)
{
int move;
@ -123,13 +137,15 @@ int UnitShowAnimation(Unit* unit, const Animation* anim)
break;
case AnimationWait:
unit->Anim.Wait = unit->Anim.Anim->D.Wait.Wait;
unit->Anim.Wait = unit->Anim.Anim->D.Wait.Wait << scale >> 8;
if (unit->Variable[SLOW_INDEX].Value) { // unit is slowed down
unit->Anim.Wait <<= 1;
}
if (unit->Variable[HASTE_INDEX].Value && unit->Anim.Wait > 1) { // unit is accelerated
unit->Anim.Wait >>= 1;
}
if (unit->Anim.Wait <= 0)
unit->Anim.Wait = 1;
break;
case AnimationRandomWait:
unit->Anim.Wait = unit->Anim.Anim->D.RandomWait.MinWait +

View file

@ -194,6 +194,8 @@ extern void HandleActionSpellCast(struct _unit_* unit);
-- Actions: actions.c
----------------------------------------------------------------------------*/
/// Handle the animation of a unit
extern int UnitShowAnimationScaled(struct _unit_* unit, const struct _animation_* anim, int scale);
/// Handle the animation of a unit
extern int UnitShowAnimation(struct _unit_* unit, const struct _animation_* anim);
/// Handle the animation of a unit

View file

@ -199,6 +199,7 @@ typedef struct _map_field_ {
unsigned short Tile; /// graphic tile number
unsigned short SeenTile; /// last seen tile (FOW)
unsigned short Flags; /// field flags
unsigned char Cost; /// Unit cost to move in this tile
// FIXME: Value can be removed, walls and regeneration can be handled
// different.
unsigned char Value; /// HP for walls/ Wood Regeneration
@ -210,9 +211,7 @@ typedef struct _map_field_ {
} MapField;
// Not used until now:
#if 0
#define MapFieldArray 0x0004 /// More than one unit on the field
#endif
#define MapFieldSpeedMask 0x0007 /// Move faster on this tile
#define MapFieldHuman 0x0008 /// Human is owner of the field (walls)

View file

@ -441,6 +441,8 @@ static int CclSetTile(lua_State* l)
TheMap.Fields[w + h * TheMap.Info.MapWidth].Tile = TheMap.Tileset.Table[tile];
TheMap.Fields[w + h * TheMap.Info.MapWidth].Value = 0;
TheMap.Fields[w + h * TheMap.Info.MapWidth].Flags = TheMap.Tileset.FlagsTable[tile];
TheMap.Fields[w + h * TheMap.Info.MapWidth].Cost =
1 << (TheMap.Tileset.FlagsTable[tile] & MapFieldSpeedMask);
return 0;
}

View file

@ -117,7 +117,7 @@ static void ParseTilesetTileFlags(lua_State* l, int* back, int* j)
//
// Parse the list: flags of the slot
//
flags = 0;
flags = 3;
while (1) {
lua_rawgeti(l, -1, *j + 1);
if (!lua_isstring(l, -1)) {
@ -157,6 +157,16 @@ static void ParseTilesetTileFlags(lua_State* l, int* back, int* j)
flags |= MapFieldBuilding;
} else if (!strcmp(value, "human")) {
flags |= MapFieldHuman;
} else if (!strcmp(value, "fastest")) {
flags = (flags & ~MapFieldSpeedMask);
} else if (!strcmp(value, "fast")) {
flags = (flags & ~MapFieldSpeedMask) | 1;
} else if (!strcmp(value, "slow")) {
flags = (flags & ~MapFieldSpeedMask) | 4;
} else if (!strcmp(value, "slower")) {
flags = (flags & ~MapFieldSpeedMask) | 5;
} else if (!strcmp(value, "slowest")) {
flags = (flags & ~MapFieldSpeedMask) | 7;
} else {
LuaError(l, "solid: unsupported tag: %s" _C_ value);
}

View file

@ -345,6 +345,8 @@ static int CostMoveTo(const Unit* unit, int ex, int ey, int mask, int current_co
// Tend against unknown tiles.
cost += AStarUnknownTerrainCost;
}
// Add tile movement cost
cost += TheMap.Fields[i + j * TheMap.Info.MapWidth].Cost;
}
}
return cost;