Replaces three independently hand-rolled battlefighter_t JSON readers/ writers (party.jsonc roster loading, BATTLE_START enemy definitions, and the v1 save-file party member format) with one generic pair in battlefighter.c: battleFighterParse(fighter, obj) and its inverse battleFighterSerialize(fighter, doc). Covers team/controller/status (optional, default ally/player/normal), the 7 base stats (required), current health/mp (optional, default to max), and an optional abilities name array. - party.c: partyInit now parses each roster member via battleFighterParse directly, dropping the old partyParseStats/partyParseStatField. - cutscenebattlestart.c/.h: cutscenebattlestartenemy_t now embeds a full battlefighter_t, parsed once at Load time; Start just copies it into the enemy pool instead of re-initializing. battletest.jsonc's enemies are now flat (dropped the "stats" wrapper) to match. - saveslotver1.c/.h: rewritten in place to use the shared parser/ serializer, changing the v1 on-disk field names/shape (no migration - acceptable pre-release, documented in saveslotver1.h). Co-Authored-By: Claude Sonnet 5 <[email protected]>
127 lines
4.3 KiB
C
127 lines
4.3 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "rpg/battle/fighter/battlefighter.h"
|
|
#include "yyjson.h"
|
|
|
|
#define PARTY_MEMBER_COUNT_MAX 10
|
|
#define PARTY_ACTIVE_SIZE_MAX 4
|
|
#define PARTY_KEY_LENGTH_MAX 32
|
|
#define PARTY_ORDER_EMPTY 0xFF
|
|
#define PARTY_MEMBER_NOT_FOUND 0xFF
|
|
|
|
typedef struct {
|
|
battlefighter_t members[PARTY_MEMBER_COUNT_MAX];
|
|
char_t keys[PARTY_MEMBER_COUNT_MAX][PARTY_KEY_LENGTH_MAX];
|
|
uint8_t order[PARTY_ACTIVE_SIZE_MAX];
|
|
} party_t;
|
|
|
|
/**
|
|
* Initializes party with an empty order, then seeds every roster slot
|
|
* directly from party.jsonc's "members" object (each key/value pair fills
|
|
* the next members[]/keys[] slot in the object's iteration order, key
|
|
* copied into keys[] and value parsed via battleFighterParse) - unlike
|
|
* partyAddMember, this never touches order itself except for one
|
|
* placeholder default: if party.jsonc defines at least one member,
|
|
* order[0] is set to 0 (the first member starts active in the first party
|
|
* position). Replace this default once there's a real starting-party/
|
|
* character-creation flow.
|
|
*
|
|
* @param party The party to initialize.
|
|
* @return Error if party.jsonc fails to load/parse, defines more members
|
|
* than PARTY_MEMBER_COUNT_MAX has room for, or a key exceeds
|
|
* PARTY_KEY_LENGTH_MAX.
|
|
*/
|
|
errorret_t partyInit(party_t *party);
|
|
|
|
/**
|
|
* Looks up a roster member's index by its party.jsonc key (see
|
|
* party_t.keys).
|
|
*
|
|
* @param key The member's key to search for.
|
|
* @return The matching roster index, or PARTY_MEMBER_NOT_FOUND if no
|
|
* member has that key.
|
|
*/
|
|
uint8_t partyGetMemberIndexByKey(const char_t *key);
|
|
|
|
/**
|
|
* Gets a roster member's party.jsonc key by index (see party_t.keys).
|
|
*
|
|
* @param memberIndex The roster member index to query.
|
|
* @return The member's key - "" if memberIndex is past however many
|
|
* members party.jsonc actually defines.
|
|
*/
|
|
const char_t *partyGetMemberKey(const uint8_t memberIndex);
|
|
|
|
/**
|
|
* Checks whether memberIndex currently occupies a slot in the current save
|
|
* slot's party order (i.e. is actively in the party right now).
|
|
*
|
|
* @param memberIndex The roster member index to check.
|
|
* @return True if memberIndex appears anywhere in order.
|
|
*/
|
|
bool_t partyIsMemberActive(const uint8_t memberIndex);
|
|
|
|
/**
|
|
* Adds an existing roster member (see partyInit - every roster slot
|
|
* always exists once initialized) to the current save slot's active party
|
|
* order, in the first free order slot. No-op if memberIndex is already
|
|
* active, or if there is no free order slot.
|
|
*
|
|
* @param memberIndex The roster member index to activate.
|
|
*/
|
|
void partyAddMember(const uint8_t memberIndex);
|
|
|
|
/**
|
|
* Gets the roster member currently occupying an active order slot in the
|
|
* current save slot's party.
|
|
*
|
|
* @param slot The active order slot to query.
|
|
* @return Pointer to the member in that slot, or NULL if the slot is
|
|
* empty.
|
|
*/
|
|
battlefighter_t *partyGetOrderMember(const uint8_t slot);
|
|
|
|
/**
|
|
* Assigns a roster member to an active order slot in the current save
|
|
* slot's party, replacing whatever was there. Use PARTY_ORDER_EMPTY to
|
|
* clear a slot.
|
|
*
|
|
* @param slot The active order slot to assign.
|
|
* @param memberIndex The roster member index to place there, or
|
|
* PARTY_ORDER_EMPTY to clear the slot.
|
|
*/
|
|
void partySetOrder(const uint8_t slot, const uint8_t memberIndex);
|
|
|
|
/**
|
|
* Removes memberIndex from the current save slot's active party order -
|
|
* the roster member itself is untouched (it still exists, per partyInit;
|
|
* it's simply no longer active) - shifting every later order entry down
|
|
* one slot to close the gap, so order stays packed with no holes between
|
|
* active members. No-op if memberIndex isn't currently active.
|
|
*
|
|
* @param memberIndex The roster member index to deactivate.
|
|
*/
|
|
void partyRemoveMember(const uint8_t memberIndex);
|
|
|
|
/**
|
|
* Fully restores a roster member's health/mp to their max and clears a
|
|
* dead status back to normal - unlike battleFighterHeal, this can revive
|
|
* a dead member (there's no combat context here to keep them down). No-op
|
|
* if the slot is empty.
|
|
*
|
|
* @param memberIndex The roster member index to heal.
|
|
*/
|
|
void partyHealMember(const uint8_t memberIndex);
|
|
|
|
/**
|
|
* Calls partyHealMember for every occupied slot in the current save
|
|
* slot's party roster.
|
|
*/
|
|
void partyHealAll(void);
|