UnitType only has one image file now, changed DefineUnitType to Image = {file, f, size, {x, y}}
This commit is contained in:
parent
1bd595e8ec
commit
eb85306207
4 changed files with 27 additions and 42 deletions
|
@ -297,7 +297,7 @@ Possible tags:
|
|||
<dd>The unit-type name shown in the game. F.E: "Knight", "Gold Mine".
|
||||
If the name is too long, it is split at space.
|
||||
</dd>
|
||||
<dt>File = {"default" or tileset-name, "file", ...}</dt>
|
||||
<dt>Image = {"file", filename, "size", {x, y}}</dt>
|
||||
<dd>Defines the graphics used to display the unit-type in game.</dd>
|
||||
<dt>Offset = {x, y}</dt>
|
||||
<dd>Defines the offset for the graphics in pixels used to display the unit-type</dd>
|
||||
|
@ -712,8 +712,7 @@ for the minimap color, and will force this. It takes a number from the palette h
|
|||
Sorry, but due to the huge number of available flags we can only show a limited example.
|
||||
<pre>
|
||||
DefineUnitType("unit-footman", { Name = "Footman",
|
||||
Files = {"tileset-summer", "alliance/units/footman.png"},
|
||||
Size = {72, 72},
|
||||
Image = {"file", "alliance/units/footman.png", "size", {72, 72}},
|
||||
Animations = "animations-footman", Icon = "icon-footman",
|
||||
Costs = {"time", 60, "gold", 600},
|
||||
Speed = 10, -- Variable Defined
|
||||
|
|
|
@ -871,7 +871,7 @@ struct _unit_type_ {
|
|||
char* Ident; /// Identifier
|
||||
char* Name; /// Pretty name shown from the engine
|
||||
int Slot; /// Type as number
|
||||
char* File[TilesetMax]; /// Sprite files
|
||||
char* File; /// Sprite files
|
||||
char* ShadowFile; /// Shadow file
|
||||
|
||||
int Width; /// Sprite width
|
||||
|
|
|
@ -284,7 +284,7 @@ static int CclDefineUnitType(lua_State* l)
|
|||
free(type->Name);
|
||||
}
|
||||
type->Name = strdup(LuaToString(l, -1));
|
||||
} else if (!strcmp(value, "Files")) {
|
||||
} else if (!strcmp(value, "Image")) {
|
||||
if (!lua_istable(l, -1)) {
|
||||
LuaError(l, "incorrect argument");
|
||||
}
|
||||
|
@ -295,26 +295,28 @@ static int CclDefineUnitType(lua_State* l)
|
|||
lua_pop(l, 1);
|
||||
++k;
|
||||
|
||||
// FIXME: use a general get tileset function here!
|
||||
i = 0;
|
||||
if (strcmp(value, "default")) {
|
||||
for (; i < NumTilesets; ++i) {
|
||||
if (!strcmp(value, Tilesets[i]->Ident) ||
|
||||
!strcmp(value, Tilesets[i]->Class)) {
|
||||
break;
|
||||
}
|
||||
if (!strcmp(value, "file")) {
|
||||
if (redefine) {
|
||||
free(type->File);
|
||||
}
|
||||
if (i == NumTilesets) {
|
||||
// This leaves half initialized unit-type
|
||||
LuaError(l, "Unsupported tileset tag '%s'" _C_ value);
|
||||
lua_rawgeti(l, -1, k + 1);
|
||||
type->File = strdup(LuaToString(l, -1));
|
||||
lua_pop(l, 1);
|
||||
} else if (!strcmp(value, "size")) {
|
||||
lua_rawgeti(l, -1, k + 1);
|
||||
if (!lua_istable(l, -1)) {
|
||||
LuaError(l, "incorrect argument");
|
||||
}
|
||||
lua_rawgeti(l, -1, 1);
|
||||
type->Width = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
lua_rawgeti(l, -1, 2);
|
||||
type->Height = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
lua_pop(l, 1);
|
||||
} else {
|
||||
LuaError(l, "Unsupported shadow tag: %s" _C_ value);
|
||||
}
|
||||
if (redefine) {
|
||||
free(type->File[i]);
|
||||
}
|
||||
lua_rawgeti(l, -1, k + 1);
|
||||
type->File[i] = strdup(LuaToString(l, -1));
|
||||
lua_pop(l, 1);
|
||||
}
|
||||
} else if (!strcmp(value, "Shadow")) {
|
||||
if (!lua_istable(l, -1)) {
|
||||
|
@ -346,7 +348,6 @@ static int CclDefineUnitType(lua_State* l)
|
|||
type->ShadowHeight = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
lua_pop(l, 1);
|
||||
} else if (!strcmp(value, "height")) {
|
||||
} else if (!strcmp(value, "offset")) {
|
||||
lua_rawgeti(l, -1, k + 1);
|
||||
if (!lua_istable(l, -1)) {
|
||||
|
@ -363,16 +364,6 @@ static int CclDefineUnitType(lua_State* l)
|
|||
LuaError(l, "Unsupported shadow tag: %s" _C_ value);
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(value, "Size")) {
|
||||
if (!lua_istable(l, -1) || luaL_getn(l, -1) != 2) {
|
||||
LuaError(l, "incorrect argument");
|
||||
}
|
||||
lua_rawgeti(l, -1, 1);
|
||||
type->Width = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
lua_rawgeti(l, -1, 2);
|
||||
type->Height = LuaToNumber(l, -1);
|
||||
lua_pop(l, 1);
|
||||
} else if (!strcmp(value, "Offset")) {
|
||||
if (!lua_istable(l, -1) || luaL_getn(l, -1) != 2) {
|
||||
LuaError(l, "incorrect argument");
|
||||
|
|
|
@ -454,7 +454,6 @@ void InitUnitTypes(int reset_player_stats)
|
|||
*/
|
||||
void LoadUnitTypeSprite(UnitType* type)
|
||||
{
|
||||
const char* file;
|
||||
ResourceInfo* resinfo;
|
||||
int i;
|
||||
|
||||
|
@ -491,10 +490,8 @@ void LoadUnitTypeSprite(UnitType* type)
|
|||
}
|
||||
}
|
||||
|
||||
file = type->File[0];
|
||||
|
||||
if (file) {
|
||||
type->Sprite = NewGraphic(file, type->Width, type->Height);
|
||||
if (type->File) {
|
||||
type->Sprite = NewGraphic(type->File, type->Width, type->Height);
|
||||
LoadGraphic(type->Sprite);
|
||||
if (type->Flip) {
|
||||
FlipGraphic(type->Sprite);
|
||||
|
@ -675,10 +672,8 @@ void CleanUnitTypes(void)
|
|||
}
|
||||
free(type->BuildingRules);
|
||||
}
|
||||
for (j = 0; j < TilesetMax; ++j) {
|
||||
if (type->File[j]) {
|
||||
free(type->File[j]);
|
||||
}
|
||||
if (type->File) {
|
||||
free(type->File);
|
||||
}
|
||||
if (type->ShadowFile) {
|
||||
free(type->ShadowFile);
|
||||
|
|
Loading…
Reference in a new issue