Skip to content

Saturday Sessions: 20240713 Equipment

Joshua Wierenga edited this page Jul 15, 2024 · 7 revisions

Cam started working on equipment inventory during this session. It does not appear to have been pushed to his branch yet. (I haven’t worked it out yet lol)

At the end, we were discussing how to best handle swapping between unlocked items.

Joshua’s proposal is to keep a 1d list for each of the available equipment, unlocked equipment and equipment arrays.

Then, when looping through each slot to change between acceptable items, use a counter to keep track of the number of loops completed, which caps at the number of items per slot(9 currently) until a valid item (possibly the same item) is found. Since the player will likely have an item that is not at start of that slots block in the unlocked equipment array, the current item index will need to wrap around in order for the player to be shown all items. https://www.desmos.com/calculator/dq3sh5k0i0

Example c like code, expect some issues:

// In either game.h or types.in.h
#define EquippedItemsSlots 7 // Number of slots
#define EquipmentSlotItems 9 // Number of items per slot

// In game.h
struct PlayerInfo {
  ...
  const struct EquipmentInfo *equippedItems[EquippedItemsSlots];
  ...
  bool unlockedItems[EquippedItemsSlots * EquipmentSlotItems];
  ...
};

struct GameInfo {
  ...
  const struct EquipmentInfo equipment[EquippedItemsSlots * EquipmentSlotItems];
  ...
}

// In HandleGameInput in game.c
EquipmentID curID = state->playerInfo.equippedItems[button.equipmentSlot].id + 1;
EquipmentID minID = EquipmentSlotItems * (curID / EquipmentSlotItems);
EquipmentID maxID = minID + EquipmentSlotItems;
for (uint_fast8_t slotsChecked = 0; i < EquipmentSlotsCount; ++i, ++curID) {
  if (curID == maxID) {
    curID = minID;
  }

  if (!state->playerInfo.unlockedItems[curID]) {
     continue;
  }

  state->playerInfo.equippedItems[button.equipmentSlot] = info->equipment + curID;
  UpdateStats(state);
  break;
}

minID(left number) and maxID(left number of next row) define the range of allowed values for each equipment slots as:

00-08: helmet
09-17: shirt
18-26: gloves
27-35: pants
36-44: boots
45-53: left hand weapon
54-62: right hand weapon

Clone this wiki locally