static void LoadPlayerTemplate( PlayerTemplate *t, json_t *node, const int version) { strcpy(t->name, json_find_first_label(node, "Name")->child->text); t->Class = StrCharacterClass( json_find_first_label(node, "Face")->child->text); CASSERT(t->Class != NULL, "cannot find character class"); if (version == 1) { // Version 1 used integer palettes int skin, arms, body, legs, hair; LoadInt(&skin, node, "Skin"); LoadInt(&arms, node, "Arms"); LoadInt(&body, node, "Body"); LoadInt(&legs, node, "Legs"); LoadInt(&hair, node, "Hair"); ConvertCharacterColors(skin, arms, body, legs, hair, &t->Colors); } else { LoadColor(&t->Colors.Skin, node, "Skin"); LoadColor(&t->Colors.Arms, node, "Arms"); LoadColor(&t->Colors.Body, node, "Body"); LoadColor(&t->Colors.Legs, node, "Legs"); LoadColor(&t->Colors.Hair, node, "Hair"); } }
void LoadCharacters( CharacterStore *c, json_t *charactersNode, const int version) { json_t *child = charactersNode->child; CharacterStoreTerminate(c); CharacterStoreInit(c); while (child) { Character *ch = CharacterStoreAddOther(c); char *tmp; if (version < 7) { // Old version stored character looks as palette indices int face; LoadInt(&face, child, "face"); ch->Class = IntCharacterClass(face); int skin, arm, body, leg, hair; LoadInt(&skin, child, "skin"); LoadInt(&arm, child, "arm"); LoadInt(&body, child, "body"); LoadInt(&leg, child, "leg"); LoadInt(&hair, child, "hair"); ConvertCharacterColors(skin, arm, body, leg, hair, &ch->Colors); } else { tmp = GetString(child, "Class"); ch->Class = StrCharacterClass(tmp); CFREE(tmp); LoadColor(&ch->Colors.Skin, child, "Skin"); LoadColor(&ch->Colors.Arms, child, "Arms"); LoadColor(&ch->Colors.Body, child, "Body"); LoadColor(&ch->Colors.Legs, child, "Legs"); LoadColor(&ch->Colors.Hair, child, "Hair"); } LoadInt(&ch->speed, child, "speed"); tmp = GetString(child, "Gun"); ch->Gun = StrGunDescription(tmp); CFREE(tmp); LoadInt(&ch->maxHealth, child, "maxHealth"); LoadInt(&ch->flags, child, "flags"); LoadInt(&ch->bot->probabilityToMove, child, "probabilityToMove"); LoadInt(&ch->bot->probabilityToTrack, child, "probabilityToTrack"); LoadInt(&ch->bot->probabilityToShoot, child, "probabilityToShoot"); LoadInt(&ch->bot->actionDelay, child, "actionDelay"); child = child->next; } }