Skip to content

Commit

Permalink
Merge pull request OpenEnroth#1313 from captainurist/macos_fixes_380
Browse files Browse the repository at this point in the history
More enums work
  • Loading branch information
captainurist authored Sep 19, 2023
2 parents 8fc1400 + 6125e13 commit 5afd52a
Show file tree
Hide file tree
Showing 60 changed files with 806 additions and 684 deletions.
8 changes: 5 additions & 3 deletions src/Application/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ void Game_StartDialogue(unsigned int actor_id) {
}

void Game_StartHirelingDialogue(unsigned int hireling_id) {
assert(hireling_id == 0 || hireling_id == 1);

if (bNoNPCHiring || current_screen_type != SCREEN_GAME) return;

engine->_messageQueue->clear();
Expand Down Expand Up @@ -482,7 +484,7 @@ void Game::processQueuedMessages() {
continue;
case UIMSG_StartHireling1Dialogue:
case UIMSG_StartHireling2Dialogue:
Game_StartHirelingDialogue(uMessage - UIMSG_StartHireling1Dialogue);
Game_StartHirelingDialogue(uMessage == UIMSG_StartHireling1Dialogue ? 0 : 1);
continue;
case UIMSG_HouseScreenClick:
if (window_SpeakInHouse) {
Expand Down Expand Up @@ -783,8 +785,8 @@ void Game::processQueuedMessages() {
onEscape();
continue;
case SCREEN_INPUT_BLV: // click escape
if (uCurrentHouse_Animation == 153)
playHouseSound((HOUSE_ID)0x99u, HouseSoundType(3)); // TODO(Nik-RE-dev): what is this?
if (uCurrentHouse_Animation == 153) // TODO(Nik-RE-dev): what is this? Btw, 153 == HOUSE_EARTH_GUILD_STONE_CITY.
playHouseSound(HOUSE_EARTH_GUILD_STONE_CITY, HOUSE_SOUND_MAGIC_GUILD_MEMBERS_ONLY);
pMediaPlayer->Unload();
if (npcIdToDismissAfterDialogue) {
pParty->hirelingScrollPosition = 0;
Expand Down
63 changes: 31 additions & 32 deletions src/Arcomage/Arcomage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Engine/Tables/AwardTable.h"
#include "Engine/AssetsManager.h"

#include "GUI/GUIFont.h"
#include "GUI/GUIWindow.h"
#include "GUI/UI/UIHouses.h"

Expand All @@ -20,6 +19,7 @@

#include "Library/Random/Random.h"

#include "Utility/IndexedArray.h"

void SetStartConditions();
void SetStartGameData();
Expand Down Expand Up @@ -72,20 +72,21 @@ struct ArcomageStartConditions {
int mastery_lvl;
};

const ArcomageStartConditions start_conditions[13] = {
{30, 100, 15, 5, 2, 2, 2, 10, 10, 10, 0},
{50, 150, 20, 5, 2, 2, 2, 5, 5, 5, 1},
{50, 150, 20, 5, 2, 2, 2, 5, 5, 5, 2},
{75, 200, 25, 10, 3, 3, 3, 5, 5, 5, 2},
{75, 200, 20, 10, 3, 3, 3, 5, 5, 5, 1},
{100, 300, 30, 15, 4, 4, 4, 10, 10, 10, 1},
{100, 300, 30, 15, 4, 4, 4, 10, 10, 10, 2},
{150, 400, 20, 10, 5, 5, 5, 25, 25, 25, 0},
{200, 500, 20, 10, 1, 1, 1, 15, 15, 15, 2},
{100, 300, 20, 50, 1, 1, 5, 5, 5, 25, 0},
{125, 350, 10, 20, 3, 1, 2, 15, 5, 10, 2},
{125, 350, 10, 20, 3, 1, 2, 15, 5, 10, 1},
{100, 300, 50, 50, 5, 3, 5, 20, 10, 20, 0}};
IndexedArray<ArcomageStartConditions, HOUSE_FIRST_ARCOMAGE_TAVERN, HOUSE_LAST_ARCOMAGE_TAVERN> start_conditions = {
{HOUSE_TAVERN_HARMONDALE, {30, 100, 15, 5, 2, 2, 2, 10, 10, 10, 0}},
{HOUSE_TAVERN_ERATHIA, {50, 150, 20, 5, 2, 2, 2, 5, 5, 5, 1}},
{HOUSE_TAVERN_TULAREAN_FOREST, {50, 150, 20, 5, 2, 2, 2, 5, 5, 5, 2}},
{HOUSE_TAVERN_DEYJA, {75, 200, 25, 10, 3, 3, 3, 5, 5, 5, 2}},
{HOUSE_TAVERN_BRACADA_DESERT, {75, 200, 20, 10, 3, 3, 3, 5, 5, 5, 1}},
{HOUSE_TAVERN_CELESTE, {100, 300, 30, 15, 4, 4, 4, 10, 10, 10, 1}},
{HOUSE_TAVERN_PIT, {100, 300, 30, 15, 4, 4, 4, 10, 10, 10, 2}},
{HOUSE_TAVERN_EVENMORN_ISLAND, {150, 400, 20, 10, 5, 5, 5, 25, 25, 25, 0}},
{HOUSE_TAVERN_MOUNT_NIGHON, {200, 500, 20, 10, 1, 1, 1, 15, 15, 15, 2}},
{HOUSE_TAVERN_BARROW_DOWNS, {100, 300, 20, 50, 1, 1, 5, 5, 5, 25, 0}},
{HOUSE_TAVERN_TATALIA, {125, 350, 10, 20, 3, 1, 2, 15, 5, 10, 2}},
{HOUSE_TAVERN_AVLEE, {125, 350, 10, 20, 3, 1, 2, 15, 5, 10, 1}},
{HOUSE_TAVERN_STONE_CITY, {100, 300, 50, 50, 5, 3, 5, 20, 10, 20, 0}}
};

constexpr auto SIG_MEMALOC = 0x67707274; // memory allocated;
constexpr auto SIG_MEMFREE = 0x78787878; // memory free;
Expand Down Expand Up @@ -571,7 +572,7 @@ bool ArcomageGame::LoadSprites() {

int CalculateCardPower(ArcomagePlayer *player, ArcomagePlayer *enemy,
ArcomageCard *pCard, int mastery) {
enum V_IND {
enum class V_IND {
P_TOWER_M10,
P_WALL_M10,
E_TOWER,
Expand All @@ -580,23 +581,23 @@ int CalculateCardPower(ArcomagePlayer *player, ArcomagePlayer *enemy,
E_QUARRY,
E_MAGIC,
E_ZOO,
E_RES,
V_INDEX_MAX
E_RES
};
using enum V_IND;

// mastery coeffs
// base mastery focus on growing walls + tower
// second level high priority on resource gen
const int mastery_coeff[V_INDEX_MAX][2] = {
{10, 5}, // P_TOWER_M10
{2, 1}, // P_WALL_M10
{1, 10}, // E_TOWER
{1, 3}, // E_WALL
{1, 7}, // E_BUILDINGS
{1, 5}, // E_QUARRY
{1, 40}, // E_MAGIC
{1, 40}, // E_ZOO
{1, 2} // E_RES
static constexpr IndexedArray<std::array<int, 2>, P_TOWER_M10, E_RES> mastery_coeff = {
{P_TOWER_M10, {{10, 5}}},
{P_WALL_M10, {{2, 1}}},
{E_TOWER, {{1, 10}}},
{E_WALL, {{1, 3}}},
{E_BUILDINGS, {{1, 7}}},
{E_QUARRY, {{1, 5}}},
{E_MAGIC, {{1, 40}}},
{E_ZOO, {{1, 40}}},
{E_RES, {{1, 2}}}
};

int card_power = 0;
Expand Down Expand Up @@ -2843,9 +2844,7 @@ void GameResultsApply() {
pArcomageGame->Victory_type = victory_type;
pArcomageGame->uGameWinner = winner;
if (winner == 1) {
// 108..120 - tavern ids
// TODO: get rid of static cast, just place HOUSE_ID in proper place
HOUSE_ID houseId = static_cast<HOUSE_ID>(window_SpeakInHouse->wData.val);
HOUSE_ID houseId = window_SpeakInHouse->houseId();
if (isArcomageTavern(houseId)) {
if (!pParty->pArcomageWins[houseId]) {
pParty->pArcomageWins[houseId] = 1;
Expand Down Expand Up @@ -2936,7 +2935,7 @@ void ArcomageGame::PrepareArcomage() {

void SetStartConditions() {
const ArcomageStartConditions *st_cond;
st_cond = &start_conditions[window_SpeakInHouse->wData.val - 108];
st_cond = &start_conditions[window_SpeakInHouse->houseId()];

// set start conditions
start_tower_height = st_cond->tower_height;
Expand Down
16 changes: 10 additions & 6 deletions src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ void DoPrepareWorld(bool bLoading, int _1_fullscreen_loading_2_box) {
// spawning grounds & walls of mist - no loot & exp from monsters

for (uint i = 0; i < pActors.size(); ++i) {
pActors[i].monsterInfo.uTreasureType = 0;
// TODO(captainurist): shouldn't we also set uTreasureLevel = ITEM_TREASURE_LEVEL_INVALID?
pActors[i].monsterInfo.uTreasureType = RANDOM_ITEM_ANY;
pActors[i].monsterInfo.uTreasureDiceRolls = 0;
pActors[i].monsterInfo.uExp = 0;
}
Expand Down Expand Up @@ -996,13 +997,13 @@ void Engine::_461103_load_level_sub() {
//{
// v3 = pActors[i].pMonsterInfo.uID;
v17 = 0;
if (pActors[i].monsterInfo.uID >= 115 &&
pActors[i].monsterInfo.uID <= 186 ||
pActors[i].monsterInfo.uID >= 232 &&
pActors[i].monsterInfo.uID <= 249)
if (pActors[i].monsterInfo.uID >= MONSTER_115 &&
pActors[i].monsterInfo.uID <= MONSTER_186 ||
pActors[i].monsterInfo.uID >= MONSTER_232 &&
pActors[i].monsterInfo.uID <= MONSTER_PEASANT_GOBLIN_MALE_3_3)
v17 = 1;
// v1 = 0;
v4 = (pActors[i].monsterInfo.uID - 1) % 3;
v4 = (std::to_underlying(pActors[i].monsterInfo.uID) - 1) % 3; // TODO(captainurist): encapsulate monster tier calculation.
if (2 == v4) {
if (pActors[i].npcId && pActors[i].npcId < 5000) continue;
} else {
Expand Down Expand Up @@ -1035,6 +1036,8 @@ void Engine::_461103_load_level_sub() {
v20 = 0;
// v16 = v1;

// TODO(captainurist): can drop this code?
#if 0
for (uint i = 0; i < pActors.size(); ++i) {
// v7 = (char *)&pActors[0].pMonsterInfo;
// do
Expand All @@ -1053,6 +1056,7 @@ void Engine::_461103_load_level_sub() {
//}
// while ( v16 < (signed int)v5 );
}
#endif

pGameLoadingUI_ProgressBar->Progress();

Expand Down
8 changes: 5 additions & 3 deletions src/Engine/Events/EventIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ std::string EventIR::toString() const {
case EVENT_MoveNPC:
return fmt::format("{}: MoveNPC({}, {})", step, data.npc_move_descr.npc_id, std::to_underlying(data.npc_move_descr.location_id));
case EVENT_GiveItem:
return fmt::format("{}: GiveItem({}, {}, {})", step, std::to_underlying(data.give_item_descr.treasure_level), data.give_item_descr.treasure_type, std::to_underlying(data.give_item_descr.item_id));
return fmt::format("{}: GiveItem({}, {}, {})", step, std::to_underlying(data.give_item_descr.treasure_level), std::to_underlying(data.give_item_descr.treasure_type), std::to_underlying(data.give_item_descr.item_id));
case EVENT_ChangeEvent:
return fmt::format("{}: ChangeEvent({})", step, data.event_id);
case EVENT_CheckSkill:
Expand Down Expand Up @@ -865,6 +865,8 @@ EventIR EventIR::parse(const RawEvent *evt, size_t size) {
return std::string(reinterpret_cast<const char *>(ptr), length);
};

// TODO(captainurist): verify enum ranges here.

switch (ir.type) {
case EVENT_Exit:
break;
Expand Down Expand Up @@ -1074,8 +1076,8 @@ EventIR EventIR::parse(const RawEvent *evt, size_t size) {
break;
case EVENT_GiveItem:
requireSize(11);
ir.data.give_item_descr.treasure_level = (ItemTreasureLevel)evt->v5;
ir.data.give_item_descr.treasure_type = evt->v6;
ir.data.give_item_descr.treasure_level = static_cast<ItemTreasureLevel>(evt->v5);
ir.data.give_item_descr.treasure_type = static_cast<RandomItemType>(evt->v6);
ir.data.give_item_descr.item_id = static_cast<ItemId>(EVT_DWORD(&evt->v7));
break;
case EVENT_ChangeEvent:
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Events/EventIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class EventIR {
} npc_groups_descr;
struct {
ItemTreasureLevel treasure_level;
int treasure_type;
RandomItemType treasure_type;
ItemId item_id;
} give_item_descr;
struct {
Expand Down
1 change: 0 additions & 1 deletion src/Engine/Graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ set(ENGINE_GRAPHICS_HEADERS
Level/Decoration.h
LightmapBuilder.h
LightsStack.h
LocationEnums.h
LocationFunctions.h
LocationInfo.h
LocationTime.h
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Graphics/Collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ void ProcessActorCollisionsBLV(Actor &actor, bool isAboveGround, bool isFlying)
}

if (type == OBJECT_Character) {
if (actor.GetActorsRelation(0)) {
if (actor.GetActorsRelation(0) != MonsterInfo::Hostility_Friendly) {
actor.speed.y = 0;
actor.speed.x = 0;

Expand Down Expand Up @@ -667,7 +667,7 @@ void ProcessActorCollisionsODM(Actor &actor, bool isFlying) {
}

if (type == OBJECT_Character) {
if (actor.GetActorsRelation(0)) {
if (actor.GetActorsRelation(0) != MonsterInfo::Hostility_Friendly) {
actor.speed.y = 0;
actor.speed.x = 0;

Expand Down
8 changes: 4 additions & 4 deletions src/Engine/Graphics/Indoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ void PrepareToLoadBLV(bool bLoading) {

// Party to start position
Actor this_;
this_.monsterInfo.uID = 45;
this_.monsterInfo.uID = MONSTER_45;
this_.PrepareSprites(0);
if (!bLoading) {
pParty->_viewPitch = 0;
Expand Down Expand Up @@ -1987,7 +1987,7 @@ int SpawnEncounterMonsters(MapInfo *map_info, int enc_index) {
}

//----- (00450521) --------------------------------------------------------
int DropTreasureAt(ItemTreasureLevel trs_level, int trs_type, Vec3i pos, uint16_t facing) {
int DropTreasureAt(ItemTreasureLevel trs_level, RandomItemType trs_type, Vec3i pos, uint16_t facing) {
SpriteObject a1;
pItemTable->generateItem(trs_level, trs_type, &a1.containing_item);
a1.uType = pItemTable->pItems[a1.containing_item.uItemID].uSpriteID;
Expand All @@ -2009,7 +2009,7 @@ void SpawnRandomTreasure(MapInfo *mapInfo, SpawnPoint *a2) {
int v34 = 0;
int v5 = grng->random(100);
ItemTreasureLevel v13 = grng->randomSample(RemapTreasureLevel(a2->uItemIndex, mapInfo->Treasure_prob));
if (v13 != ITEM_TREASURE_LEVEL_GUARANTEED_ARTIFACT) {
if (v13 != ITEM_TREASURE_LEVEL_7) {
// [0, 20) -- nothing
// [20, 60) -- gold
// [60, 100) -- item
Expand All @@ -2018,7 +2018,7 @@ void SpawnRandomTreasure(MapInfo *mapInfo, SpawnPoint *a2) {
return;

if (v5 >= 60) {
DropTreasureAt(v13, grng->random(27) + 20, a2->vPosition, 0);
DropTreasureAt(v13, grng->randomSample(allSpawnableRandomItemTypes()), a2->vPosition, 0);
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Engine/Graphics/Indoor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "BSPModel.h"
#include "LocationInfo.h"
#include "LocationTime.h"
#include "LocationEnums.h"
#include "LocationFunctions.h"

struct IndoorLocation;
Expand Down Expand Up @@ -317,7 +316,7 @@ int CalcDistPointToLine(int a1, int a2, int a3, int a4, int a5, int a6);
void PrepareDrawLists_BLV();
void PrepareToLoadBLV(bool bLoading);
int SpawnEncounterMonsters(struct MapInfo *a1, int a2);
int DropTreasureAt(ItemTreasureLevel trs_level, signed int trs_type, Vec3i pos, uint16_t facing);
int DropTreasureAt(ItemTreasureLevel trs_level, RandomItemType trs_type, Vec3i pos, uint16_t facing);
void SpawnRandomTreasure(MapInfo *mapInfo, SpawnPoint *a2);

void FindBillboardsLightLevels_BLV();
Expand Down
17 changes: 0 additions & 17 deletions src/Engine/Graphics/LocationEnums.h

This file was deleted.

5 changes: 4 additions & 1 deletion src/Engine/Graphics/LocationFunctions.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once

#include "LocationEnums.h"
#include "Engine/MapEnums.h"

#include "LocationInfo.h"
#include "LocationTime.h"

// TODO(captainurist): move to Engine/ and drop the Location- prefix, should be MapSmth.

extern LevelType uCurrentlyLoadedLevelType;

bool GetAlertStatus();
Expand Down
1 change: 1 addition & 0 deletions src/Engine/Graphics/LocationInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

// TODO(captainurist): we also have MapInfo, rename this into something more sane with Map- prefix.
struct LocationInfo {
int respawnCount = 0; // Number of times a location was respawned, including the initial spawn.
int lastRespawnDay = 0; // Day of the last respawn (days since GameTime zero to last respawn).
Expand Down
4 changes: 3 additions & 1 deletion src/Engine/Graphics/LocationTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include <string>

#include "Engine/Time.h"
#include "Engine/MapEnums.h"

// TODO(captainurist): rename to smth like MapTime.
struct LocationTime {
GameTime last_visit;
std::string sky_texture_name;
int day_attrib = 0; // TODO(captainurist): actually WeatherFlags, see DAY_ATTRIB_FOG.
MapWeatherFlags day_attrib = 0;
int day_fogrange_1 = 0;
int day_fogrange_2 = 0;
};
Loading

0 comments on commit 5afd52a

Please sign in to comment.