[+] Added ability to select required field for TypeVar
[-] Fixed upgrade-to stats update
This commit is contained in:
parent
bbcecfc5a2
commit
9d5069537f
7 changed files with 67 additions and 18 deletions
|
@ -122,18 +122,18 @@ static int TransformUnitIntoType(CUnit &unit, const CUnitType &newtype)
|
|||
const CUnitStats &newstats = newtype.Stats[player.Index];
|
||||
|
||||
for (unsigned int i = 0; i < UnitTypeVar.GetNumberVariable(); ++i) {
|
||||
if (unit.Variable[i].Max && unit.Variable[i].Value) {
|
||||
unit.Variable[i].Value = newstats.Variables[i].Max *
|
||||
unit.Variable[i].Value / unit.Variable[i].Max;
|
||||
} else {
|
||||
unit.Variable[i].Value = newstats.Variables[i].Value;
|
||||
}
|
||||
if (i == KILL_INDEX || i == XP_INDEX) {
|
||||
unit.Variable[i].Value = unit.Variable[i].Max;
|
||||
} else {
|
||||
unit.Variable[i].Max = newstats.Variables[i].Max;
|
||||
} else if (unit.Variable[i].Max && unit.Variable[i].Value) {
|
||||
unit.Variable[i].Value = newstats.Variables[i].Max *
|
||||
unit.Variable[i].Value / unit.Variable[i].Max;
|
||||
unit.Variable[i].Max = std::max(newstats.Variables[i].Max, unit.Variable[i].Max);
|
||||
unit.Variable[i].Increase = newstats.Variables[i].Increase;
|
||||
unit.Variable[i].Enable = newstats.Variables[i].Enable;
|
||||
} else {
|
||||
unit.Variable[i].Value = newstats.Variables[i].Value;
|
||||
unit.Variable[i].Max = unit.Variable[i].Value;
|
||||
unit.Variable[i].Enable = newstats.Variables[i].Enable;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -219,6 +219,7 @@ struct NumberDesc {
|
|||
CUnitType **Type; /// Which unit type.
|
||||
int Index; /// Which index variable.
|
||||
EnumVariable Component; /// Which component.
|
||||
int Loc; /// Location of Variables[].
|
||||
} TypeStat;
|
||||
struct {
|
||||
StringDesc *String; /// String.
|
||||
|
|
|
@ -76,7 +76,7 @@ struct UStrInt {
|
|||
/// Get component for unit variable.
|
||||
extern UStrInt GetComponent(const CUnit &unit, int index, EnumVariable e, int t);
|
||||
/// Get component for unit type variable.
|
||||
extern UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e);
|
||||
extern UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e, int t);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
|
@ -685,6 +685,11 @@ NumberDesc *CclParseNumberDesc(lua_State *l)
|
|||
if (res->D.TypeStat.Index == -1) {
|
||||
LuaError(l, "Bad variable name :'%s'" _C_ LuaToString(l, -1));
|
||||
}
|
||||
} else if (!strcmp(key, "Loc")) {
|
||||
res->D.TypeStat.Loc = LuaToNumber(l, -1);
|
||||
if (res->D.TypeStat.Loc < 0 || 2 < res->D.TypeStat.Loc) {
|
||||
LuaError(l, "Bad Loc number :'%d'" _C_ LuaToNumber(l, -1));
|
||||
}
|
||||
} else {
|
||||
LuaError(l, "Bad param %s for Unit" _C_ key);
|
||||
}
|
||||
|
@ -983,7 +988,7 @@ int EvalNumber(const NumberDesc *number)
|
|||
type = number->D.TypeStat.Type;
|
||||
if (type != NULL) {
|
||||
return GetComponent(**type, number->D.TypeStat.Index,
|
||||
number->D.TypeStat.Component).i;
|
||||
number->D.TypeStat.Component, number->D.TypeStat.Loc).i;
|
||||
} else { // ERROR.
|
||||
return 0;
|
||||
}
|
||||
|
@ -1292,8 +1297,8 @@ void FreeStringDesc(StringDesc *s)
|
|||
*/
|
||||
static int AliasTypeVar(lua_State *l, const char *s)
|
||||
{
|
||||
Assert(0 < lua_gettop(l) && lua_gettop(l) <= 2);
|
||||
|
||||
Assert(0 < lua_gettop(l) && lua_gettop(l) <= 3);
|
||||
int nargs = lua_gettop(l); // number of args in lua.
|
||||
lua_newtable(l);
|
||||
lua_pushnumber(l, 1);
|
||||
lua_pushstring(l, "TypeVar");
|
||||
|
@ -1308,7 +1313,33 @@ static int AliasTypeVar(lua_State *l, const char *s)
|
|||
lua_pushvalue(l, 1);
|
||||
lua_rawset(l, -3);
|
||||
lua_pushstring(l, "Component");
|
||||
lua_pushvalue(l, 2);
|
||||
if (nargs >= 2) {
|
||||
lua_pushvalue(l, 2);
|
||||
} else {
|
||||
lua_pushstring(l, "Value");
|
||||
}
|
||||
lua_rawset(l, -3);
|
||||
lua_pushstring(l, "Loc");
|
||||
if (nargs >= 3) {
|
||||
// Warning: type is for unit->Stats->Var...
|
||||
// and Initial is for unit->Type->Var... (no upgrade modification)
|
||||
const char *sloc[] = {"Unit", "Initial", "Type", NULL};
|
||||
int i;
|
||||
const char *key;
|
||||
|
||||
key = LuaToString(l, 3);
|
||||
for (i = 0; sloc[i] != NULL; i++) {
|
||||
if (!strcmp(key, sloc[i])) {
|
||||
lua_pushnumber(l, i);
|
||||
break ;
|
||||
}
|
||||
}
|
||||
if (sloc[i] == NULL) {
|
||||
LuaError(l, "Bad loc :'%s'" _C_ key);
|
||||
}
|
||||
} else {
|
||||
lua_pushnumber(l, 0);
|
||||
}
|
||||
lua_rawset(l, -3);
|
||||
|
||||
lua_rawset(l, -3);
|
||||
|
|
|
@ -366,7 +366,7 @@ static bool CanShowPopupContent(const PopupConditionPanel *condition,
|
|||
if (condition->Variables && type) {
|
||||
for (unsigned int i = 0; i < UnitTypeVar.GetNumberVariable(); ++i) {
|
||||
if (condition->Variables[i] != CONDITION_TRUE) {
|
||||
if ((condition->Variables[i] == CONDITION_ONLY) ^ type->DefaultStat.Variables[i].Enable) {
|
||||
if ((condition->Variables[i] == CONDITION_ONLY) ^ type->Stats[ThisPlayer->Index].Variables[i].Enable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -312,13 +312,28 @@ UStrInt GetComponent(const CUnit &unit, int index, EnumVariable e, int t)
|
|||
return val;
|
||||
}
|
||||
|
||||
UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e)
|
||||
UStrInt GetComponent(const CUnitType &type, int index, EnumVariable e, int t)
|
||||
{
|
||||
UStrInt val;
|
||||
CVariable *var = &type.Stats[ThisPlayer->Index].Variables[index];
|
||||
CVariable *var;
|
||||
|
||||
Assert((unsigned int) index < UnitTypeVar.GetNumberVariable());
|
||||
|
||||
switch (t) {
|
||||
case 0: // Unit:
|
||||
var = &type.Stats[ThisPlayer->Index].Variables[index];;
|
||||
break;
|
||||
case 1: // Type:
|
||||
var = &type.DefaultStat.Variables[index];
|
||||
break;
|
||||
case 2: // Stats:
|
||||
var = &type.Stats[ThisPlayer->Index].Variables[index];
|
||||
break;
|
||||
default:
|
||||
DebugPrint("Bad value for GetComponent: t = %d" _C_ t);
|
||||
var = &type.Stats[ThisPlayer->Index].Variables[index];
|
||||
break;
|
||||
}
|
||||
switch (e) {
|
||||
case VariableValue:
|
||||
val.type = USTRINT_INT;
|
||||
|
|
|
@ -544,6 +544,7 @@ static int CclDefineUnitType(lua_State *l)
|
|||
} else if (!strcmp(value, "MaxAttackRange")) {
|
||||
type->DefaultStat.Variables[ATTACKRANGE_INDEX].Value = LuaToNumber(l, -1);
|
||||
type->DefaultStat.Variables[ATTACKRANGE_INDEX].Max = LuaToNumber(l, -1);
|
||||
type->DefaultStat.Variables[ATTACKRANGE_INDEX].Enable = 1;
|
||||
} else if (!strcmp(value, "MaxHarvesters")) {
|
||||
type->DefaultStat.Variables[MAXHARVESTERS_INDEX].Value = LuaToNumber(l, -1);
|
||||
type->DefaultStat.Variables[MAXHARVESTERS_INDEX].Max = LuaToNumber(l, -1);
|
||||
|
|
|
@ -610,8 +610,9 @@ static void ApplyUpgradeModifier(CPlayer &player, const CUpgradeModifier *um)
|
|||
|
||||
unit.Variable[j].Max += um->Modifier.Variables[j].Max;
|
||||
unit.Variable[j].Max = std::max(unit.Variable[j].Max, 0);
|
||||
|
||||
clamp(&unit.Variable[j].Value, 0, unit.Variable[j].Max);
|
||||
if (unit.Variable[j].Max > 0) {
|
||||
clamp(&unit.Variable[j].Value, 0, unit.Variable[j].Max);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue