add "talking" as a tag in portrait definitions to show when unit is playing sound

This commit is contained in:
Tim Felgentreff 2022-04-08 08:38:35 +02:00
parent ef4527fda7
commit 9dbf9c1019
3 changed files with 17 additions and 1 deletions

View file

@ -549,6 +549,7 @@ public:
struct _portrait_ {
std::string *Files;
int Num;
int Talking; /// offset into portraits for talking portraits
Mng **Mngs;
mutable int CurrMng;
mutable int NumIterations;

View file

@ -304,6 +304,14 @@ void PlayUnitSound(const CUnit &unit, UnitVoiceGroup voice, bool sampleUnique)
}
SetChannelVolume(channel, CalculateVolume(false, ViewPointDistanceToUnit(unit), sound->Range));
SetChannelStereo(channel, CalculateStereo(unit));
#ifdef USE_MNG
const CUnitType &type = *unit.Type;
if (type.Portrait.Num && type.Portrait.Talking) {
type.Portrait.Mngs[type.Portrait.CurrMng]->Reset();
type.Portrait.CurrMng = (MyRand() % (type.Portrait.Num - type.Portrait.Talking)) + type.Portrait.Talking;
type.Portrait.NumIterations = 1;
}
#endif
}
/**

View file

@ -589,11 +589,18 @@ static int CclDefineUnitType(lua_State *l)
}
const int subargs = lua_rawlen(l, -1);
type->Portrait.Num = subargs;
type->Portrait.Talking = 0;
type->Portrait.Files = new std::string[type->Portrait.Num];
type->Portrait.Mngs = new Mng *[type->Portrait.Num];
memset(type->Portrait.Mngs, 0, type->Portrait.Num * sizeof(Mng *));
for (int k = 0; k < subargs; ++k) {
type->Portrait.Files[k] = LuaToString(l, -1, k + 1);
const char *s = LuaToString(l, -1, k + 1);
if (!strcmp("talking", s)) {
type->Portrait.Talking = k;
type->Portrait.Num--;
} else {
type->Portrait.Files[k - (type->Portrait.Talking ? 1 : 0)] = s;
}
}
#endif
} else if (!strcmp(value, "Costs")) {