make player shades configurable via lua

This commit is contained in:
nehalmistry 2005-06-17 00:26:08 +00:00
parent 9d817a863d
commit f31f0852bf
6 changed files with 57 additions and 6 deletions

View file

@ -59,6 +59,7 @@
<a href="#DefineConstruction">DefineConstruction</a>
<a href="#DefineEditorUnitTypes">DefineEditorUnitTypes</a>
<a href="#DefinePlayerColors">DefinePlayerColors</a>
<a href="#DefinePlayerShades">DefinePlayerShades</a>
<a href="#DefineRaceNames">DefineRaceNames</a>
<a href="#DefineRanks">DefineRanks</a>
<a href="#Diplomacy">Diplomacy</a>
@ -501,6 +502,27 @@ Define the player colors. There should be 16 colors defined and 4 shades of eac
)
</pre>
<a name="DefinePlayerShades"></a>
<h3>DefinePlayerShades(shadestart, numshades)</h3>
Define the graphic color indexes to be replaced by the player color.
<dl>
<dt>shadestart</dt>
<dd>Index of the first shade
</dd>
<dt>numshades</dt>
<dd>Total number of shades
</dd>
</dd>
</dl>
<h4>Example</h4>
<pre>
DefinePlayerShades(10, 5) -- for indexes 10-14
</pre>
<a name="DefineRaceNames"></a>
<h3>DefineRaceNames("race", {...}, "race", {...}, ... )</h3>

View file

@ -216,6 +216,8 @@
<dd></dd>
<dt><a href="game.html#DefinePlayerColors">DefinePlayerColors</a></dt>
<dd></dd>
<dt><a href="game.html#DefinePlayerShades">DefinePlayerShades</a></dt>
<dd></dd>
<dt><a href="mappresentation.html#DefinePlayerTypes">DefinePlayerTypes</a></dt>
<dd></dd>
<dt><a href="game.html#DefineRaceNames">DefineRaceNames</a></dt>

View file

@ -455,6 +455,12 @@ extern char* PlayerColorNames[PlayerMax]; /// Player color names
extern PlayerRace PlayerRaces; /// Player races
/**
** Which indexes to replace with player color
*/
extern int PlayerShadeStart;
extern int PlayerShadeCount;
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
@ -523,7 +529,7 @@ extern void PlayersEachSecond(int player);
#ifndef USE_OPENGL
/// Change current color set to new player of the sprite
extern void GraphicPlayerPixels(const struct _player_* player,
extern void GraphicPlayerPixels(struct _player_* player,
const Graphic* sprite);
#endif

View file

@ -73,6 +73,12 @@ Uint32 PlayerColors[PlayerMax][4];
char* PlayerColorNames[PlayerMax];
/**
** Which indexes to replace with player color
*/
int PlayerShadeStart;
int PlayerShadeCount;
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
@ -779,13 +785,15 @@ void PlayersEachSecond(int player)
** @param player Pointer to player.
** @param sprite The sprite in which the colors should be changed.
*/
void GraphicPlayerPixels(const Player* player, const Graphic* sprite)
void GraphicPlayerPixels(Player* player, const Graphic* sprite)
{
Assert(PlayerShadeCount);
SDL_LockSurface(sprite->Surface);
SDL_SetColors(sprite->Surface, ((Player*)player)->UnitColors.Colors, 208, 4);
SDL_SetColors(sprite->Surface, player->UnitColors.Colors, PlayerShadeStart, PlayerShadeCount);
if (sprite->SurfaceFlip) {
SDL_SetColors(sprite->SurfaceFlip,
((Player*)player)->UnitColors.Colors, 208, 4);
player->UnitColors.Colors, PlayerShadeStart, PlayerShadeCount);
}
SDL_UnlockSurface(sprite->Surface);
}

View file

@ -701,6 +701,18 @@ static int CclNewPlayerColors(lua_State* l)
return 0;
}
/**
** Define player shades
**
** @param l Lua state.
*/
static int CclDefinePlayerShades(lua_State* l)
{
PlayerShadeStart = LuaToNumber(l, 1);
PlayerShadeCount = LuaToNumber(l, 2);
return 0;
}
// ----------------------------------------------------------------------------
/**
@ -957,6 +969,7 @@ void PlayerCclRegister(void)
lua_register(Lua, "DefineRaceNames", CclDefineRaceNames);
lua_register(Lua, "DefinePlayerColors", CclDefinePlayerColors);
lua_register(Lua, "DefinePlayerShades", CclDefinePlayerShades);
lua_register(Lua, "NewColors", CclNewPlayerColors);

View file

@ -537,8 +537,8 @@ static void MakeTextures2(Graphic* g, GLuint texture, UnitColors* colors,
tp[3] = alpha;
}
if (colors) {
for (z = 0; z < 4; ++z) {
if (*sp == 208 + z) {
for (z = 0; z < PlayerShadeCount; ++z) {
if (*sp == PlayerShadeStart + z) {
p = colors->Colors[z];
tp[0] = p.r;
tp[1] = p.g;