Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externalise pickups #475

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
493 changes: 493 additions & 0 deletions TheForceEngine/ExternalData/DarkForces/pickups.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions TheForceEngine/TFE_DarkForces/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,16 @@ namespace TFE_DarkForces
memset(&saveData, 0, sizeof(LevelSaveData));
memset(data, 0, sizeof(AgentData));

saveData.inv[0] = 0xff;
saveData.inv[2] = 0xff;
saveData.inv[6] = 0xff;
saveData.inv[30] = WPN_PISTOL;
saveData.inv[31] = 3;

saveData.ammo[0] = 100;
saveData.ammo[7] = 100;
saveData.ammo[8] = 100;
saveData.ammo[9] = FIXED(2);
saveData.inv[0] = 0xff; // bryar pistol
saveData.inv[2] = 0xff; // s_itemUnknown1
saveData.inv[6] = 0xff; // s_itemUnknown2
saveData.inv[30] = WPN_PISTOL; // current weapon
saveData.inv[31] = 3; // lives

saveData.ammo[0] = min(s_ammoEnergyMax, 100); // energy
saveData.ammo[7] = 100; // shields
saveData.ammo[8] = 100; // health
saveData.ammo[9] = FIXED(2); // battery

strCopyAndZero(data->name, name, 32);
data->difficulty = 1;
Expand Down
36 changes: 34 additions & 2 deletions TheForceEngine/TFE_DarkForces/darkForcesMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <TFE_Jedi/IMuse/imuse.h>
#include <TFE_Jedi/Serialization/serialization.h>
#include <TFE_ExternalData/weaponExternal.h>
#include <TFE_ExternalData/pickupExternal.h>
#include <assert.h>

// Add texture callbacks.
Expand Down Expand Up @@ -964,6 +965,12 @@ namespace TFE_DarkForces
TFE_ExternalData::parseExternalEffects(buffer, true);
free(buffer);
}
else if (strcasecmp(fname, "pickups.json") == 0)
{
char* buffer = extractTextFileFromZip(zipArchive, i);
TFE_ExternalData::parseExternalPickups(buffer, true);
free(buffer);
}
else
{
char name2[TFE_MAX_PATH];
Expand Down Expand Up @@ -1155,6 +1162,25 @@ namespace TFE_DarkForces
free(data);
}
}

char pickupsJsonPath[TFE_MAX_PATH];
sprintf(pickupsJsonPath, "%s%s", modPath, "pickups.json");
if (FileUtil::exists(pickupsJsonPath))
{
FileStream file;
if (!file.open(pickupsJsonPath, FileStream::MODE_READ)) { return; }
const size_t size = file.getSize();
char* data = (char*)malloc(size + 1);

if (size > 0 && data)
{
file.readBuffer(data, (u32)size);
data[size] = 0;
file.close();
TFE_ExternalData::parseExternalPickups(data, true);
free(data);
}
}
}
}
}
Expand Down Expand Up @@ -1299,15 +1325,19 @@ namespace TFE_DarkForces
loadMapNumFont();
inf_loadSounds();
actor_loadSounds();
item_loadData();
player_init();
actor_allocatePhysicsActorList();
loadCutsceneList();
weapon_startup();
loadLangHotkeys();

TFE_ExternalData::loadCustomLogics();

TFE_ExternalData::loadExternalPickups();
if (!TFE_ExternalData::validateExternalPickups())
{
TFE_System::logWrite(LOG_ERROR, "EXTERNAL_DATA", "Warning: Pickup data is incomplete. PICKUPS.JSON may have been altered. Pickups may not behave as expected.");
}

TFE_ExternalData::loadExternalProjectiles();
if (!TFE_ExternalData::validateExternalProjectiles())
{
Expand All @@ -1322,6 +1352,8 @@ namespace TFE_DarkForces

projectile_startup();
hitEffect_startup();
item_loadData();
player_init();

FilePath filePath;
TFE_Paths::getFilePath("swfont1.fnt", &filePath);
Expand Down
4 changes: 2 additions & 2 deletions TheForceEngine/TFE_DarkForces/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ namespace TFE_DarkForces
s_hudWorkPalette[3] = 55;
s_hudWorkPalette[4] = 55;

strcpy(shieldStr, "200");
sprintf(shieldStr, "%03d", s_shieldsMax);
}
else
{
Expand Down Expand Up @@ -984,7 +984,7 @@ namespace TFE_DarkForces
s_hudWorkPalette[3] = 55;
s_hudWorkPalette[4] = 55;

strcpy(shieldStr, "200");
sprintf(shieldStr, "%03d", s_shieldsMax);
}
else
{
Expand Down
23 changes: 15 additions & 8 deletions TheForceEngine/TFE_DarkForces/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pickup.h"
#include "animLogic.h"
#include <TFE_FileSystem/paths.h>
#include <TFE_ExternalData/pickupExternal.h>

using namespace TFE_Jedi;

Expand All @@ -12,7 +13,8 @@ namespace TFE_DarkForces
///////////////////////////////////////////
// Constants
///////////////////////////////////////////
// TODO: Move into data file for TFE, rather than hardcoding here.

/* TFE: Moved to external data
static const char* c_itemResoure[ITEM_COUNT] =
{
"IDPLANS.WAX", // ITEM_PLANS
Expand Down Expand Up @@ -61,14 +63,14 @@ namespace TFE_DarkForces
"IMEDKIT.FME", // ITEM_MEDKIT
"IPILE.FME", // ITEM_PILE
"ITEM10.WAX", // ITEM_UNUSED
};
}; */

///////////////////////////////////////////
// Shared State
///////////////////////////////////////////
SoundSourceId s_powerupPickupSnd;
SoundSourceId s_invItemPickupSnd;
SoundSourceId s_wpnPickupSnd;
SoundSourceId s_objectivePickupSnd;
SoundSourceId s_itemPickupSnd;
ItemData s_itemData[ITEM_COUNT];

///////////////////////////////////////////
Expand All @@ -77,13 +79,16 @@ namespace TFE_DarkForces
void item_loadData()
{
s_powerupPickupSnd = sound_load("bonus.voc", SOUND_PRIORITY_HIGH4);
s_invItemPickupSnd = sound_load("complete.voc", SOUND_PRIORITY_HIGH5);
s_wpnPickupSnd = sound_load("key.voc", SOUND_PRIORITY_MED5);
s_objectivePickupSnd = sound_load("complete.voc", SOUND_PRIORITY_HIGH5);
s_itemPickupSnd = sound_load("key.voc", SOUND_PRIORITY_MED5);

TFE_ExternalData::ExternalPickup* externalPickups = TFE_ExternalData::getExternalPickups();
char ext[16];
for (s32 i = 0; i < ITEM_COUNT; i++)
{
const char* item = c_itemResoure[i];
if (strstr(item, ".WAX"))
const char* item = externalPickups[i].asset;
FileUtil::getFileExtension(item, ext);
if (strcasecmp(ext, "WAX") == 0)
{
s_itemData[i].wax = TFE_Sprite_Jedi::getWax(item, POOL_GAME);
s_itemData[i].isWax = JTRUE;
Expand All @@ -93,6 +98,7 @@ namespace TFE_DarkForces
s_itemData[i].frame = TFE_Sprite_Jedi::getFrame(item, POOL_GAME);
s_itemData[i].isWax = JFALSE;
}
// TODO: should we also add support for 3DO dropitems??
}
}

Expand All @@ -108,6 +114,7 @@ namespace TFE_DarkForces
{
frame_setData(newObj, s_itemData[itemId].frame);
}
// TODO: should we also add support for 3DO dropitems??

obj_createPickup(newObj, itemId);
if (s_itemData[itemId].isWax)
Expand Down
8 changes: 4 additions & 4 deletions TheForceEngine/TFE_DarkForces/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ namespace TFE_DarkForces
ITYPE_OBJECTIVE= 1, // Mission objective item.
ITYPE_WEAPON = 2, // Weapons
ITYPE_AMMO = 4, // Pickups that refill ammo, health, shields, etc.
ITYPE_KEY_ITEM = 8, // Keys and usable inventory items.
ITYPE_INV_ITEM = 16, // Non-usable Inventory Items
ITYPE_USABLE = 8, // Keys and usable inventory items.
ITYPE_CODEKEY = 16, // Code keys (Non-usable Inventory Items)
ITYPE_POWERUP = 32, // Powerups & Extra lives.
ITYPE_SPECIAL = 64, // Special - only a single item fits in this type (ITEM_PILE).
};
Expand All @@ -84,8 +84,8 @@ namespace TFE_DarkForces
};

extern SoundSourceId s_powerupPickupSnd;
extern SoundSourceId s_invItemPickupSnd;
extern SoundSourceId s_wpnPickupSnd;
extern SoundSourceId s_objectivePickupSnd;
extern SoundSourceId s_itemPickupSnd;
extern ItemData s_itemData[ITEM_COUNT];

void item_loadData();
Expand Down
Loading
Loading