const char *ParseAnimationSet(const char *pText) { const char *pName = GetNextToken(pText, &pText); if(MFString_Compare(pName, "{")) SkipToken(pText, "{"); const char *pTok = GetNextToken(pText, &pText); while(MFString_Compare(pTok, "}")) { if(!MFString_Compare(pTok, "Animation")) { pText = ParseAnimation(pText); } else { MFDebug_Warn(4, MFStr("Unexpected token '%s'\n", pTok)); SkipSection(pText); } pTok = GetNextToken(pText, &pText); } return pText; }
/** ** Define a unit-type animation set. ** ** @param l Lua state. */ static int CclDefineAnimations(lua_State *l) { LuaCheckArgs(l, 2); if (!lua_istable(l, 2)) { LuaError(l, "incorrect argument"); } const char *name = LuaToString(l, 1); CAnimations *anims = AnimationsByIdent(name); if (!anims) { anims = new CAnimations; AnimationMap[name] = anims; } lua_pushnil(l); while (lua_next(l, 2)) { const char *value = LuaToString(l, -2); if (!strcmp(value, "Start")) { anims->Start = ParseAnimation(l, -1); } else if (!strncmp(value, "Still", 5)) { anims->Still = ParseAnimation(l, -1); } else if (!strncmp(value, "Death", 5)) { if (strlen(value) > 5) { const int death = ExtraDeathIndex(value + 6); if (death == ANIMATIONS_DEATHTYPES) { anims->Death[ANIMATIONS_DEATHTYPES] = ParseAnimation(l, -1); } else { anims->Death[death] = ParseAnimation(l, -1); } } else { anims->Death[ANIMATIONS_DEATHTYPES] = ParseAnimation(l, -1); } } else if (!strcmp(value, "Attack")) { anims->Attack = ParseAnimation(l, -1); } else if (!strcmp(value, "SpellCast")) { anims->SpellCast = ParseAnimation(l, -1); } else if (!strcmp(value, "Move")) { anims->Move = ParseAnimation(l, -1); } else if (!strcmp(value, "Repair")) { anims->Repair = ParseAnimation(l, -1); } else if (!strcmp(value, "Train")) { anims->Train = ParseAnimation(l, -1); } else if (!strcmp(value, "Research")) { anims->Research = ParseAnimation(l, -1); } else if (!strcmp(value, "Upgrade")) { anims->Upgrade = ParseAnimation(l, -1); } else if (!strcmp(value, "Build")) { anims->Build = ParseAnimation(l, -1); } else if (!strncmp(value, "Harvest_", 8)) { const int res = GetResourceIdByName(l, value + 8); anims->Harvest[res] = ParseAnimation(l, -1); } else { LuaError(l, "Unsupported animation: %s" _C_ value); } lua_pop(l, 1); } // Must add to array in a fixed order for save games AddAnimationToArray(anims->Start); AddAnimationToArray(anims->Still); for (int i = 0; i != ANIMATIONS_DEATHTYPES + 1; ++i) { AddAnimationToArray(anims->Death[i]); } AddAnimationToArray(anims->Attack); AddAnimationToArray(anims->SpellCast); AddAnimationToArray(anims->Move); AddAnimationToArray(anims->Repair); AddAnimationToArray(anims->Train); for (int i = 0; i != MaxCosts; ++i) { AddAnimationToArray(anims->Harvest[i]); } return 0; }