diff --git a/src/character_editor.cc b/src/character_editor.cc index ecf370d..c56e33c 100644 --- a/src/character_editor.cc +++ b/src/character_editor.cc @@ -4542,7 +4542,7 @@ static int characterPrintToFile(const char* fileName) // SFALL for (int index = 0; index < gCustomTownReputationEntries.size(); index++) { const TownReputationEntry* pair = &(gCustomTownReputationEntries[index]); - if (_wmAreaIsKnown(pair->city)) { + if (wmAreaIsKnown(pair->city)) { if (!hasTownReputationHeading) { fileWriteString("\n", stream); @@ -4552,7 +4552,7 @@ static int characterPrintToFile(const char* fileName) hasTownReputationHeading = true; } - _wmGetAreaIdxName(pair->city, title2); + wmGetAreaIdxName(pair->city, title2); int townReputation = gGameGlobalVars[pair->gvar]; @@ -5531,7 +5531,7 @@ static void characterEditorDrawKarmaFolder() // SFALL for (int index = 0; index < gCustomTownReputationEntries.size(); index++) { const TownReputationEntry* pair = &(gCustomTownReputationEntries[index]); - if (_wmAreaIsKnown(pair->city)) { + if (wmAreaIsKnown(pair->city)) { if (!hasTownReputationHeading) { msg = getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 4000); if (characterEditorFolderViewDrawHeading(msg)) { @@ -5544,7 +5544,7 @@ static void characterEditorDrawKarmaFolder() } char cityShortName[40]; - _wmGetAreaIdxName(pair->city, cityShortName); + wmGetAreaIdxName(pair->city, cityShortName); int townReputation = gGameGlobalVars[pair->gvar]; diff --git a/src/critter.cc b/src/critter.cc index 64c0f17..48ff332 100644 --- a/src/critter.cc +++ b/src/critter.cc @@ -1303,7 +1303,7 @@ int _critter_set_who_hit_me(Object* a1, Object* a2) bool _critter_can_obj_dude_rest() { bool v1 = false; - if (!_wmMapCanRestHere(gElevation)) { + if (!wmMapCanRestHere(gElevation)) { v1 = true; } diff --git a/src/endgame.cc b/src/endgame.cc index 9a72a56..8b6961a 100644 --- a/src/endgame.cc +++ b/src/endgame.cc @@ -1158,13 +1158,13 @@ static int endgameDeathEndingValidate(int* percentage) } if (deathEnding->worldAreaKnown != -1) { - if (!_wmAreaIsKnown(deathEnding->worldAreaKnown)) { + if (!wmAreaIsKnown(deathEnding->worldAreaKnown)) { continue; } } if (deathEnding->worldAreaNotKnown != -1) { - if (_wmAreaIsKnown(deathEnding->worldAreaNotKnown)) { + if (wmAreaIsKnown(deathEnding->worldAreaNotKnown)) { continue; } } diff --git a/src/game.cc b/src/game.cc index 8741db9..422ee2d 100644 --- a/src/game.cc +++ b/src/game.cc @@ -268,7 +268,7 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4 debugPrint(">scr_game_init\t"); - if (worldmapInit() != 0) { + if (wmWorldMap_init() != 0) { debugPrint("Failed on wmWorldMap_init\n"); return -1; } @@ -376,7 +376,7 @@ void gameReset() _scr_reset(); gameLoadGlobalVars(); scriptsReset(); - worldmapReset(); + wmWorldMap_reset(); partyMembersReset(); characterEditorInit(); pipboyReset(); @@ -425,7 +425,7 @@ void gameExit() badwordsExit(); automapExit(); paletteExit(); - worldmapExit(); + wmWorldMap_exit(); partyMembersExit(); endgameDeathEndingExit(); interfaceFontsExit(); diff --git a/src/game_sound.cc b/src/game_sound.cc index 86da397..43e2315 100644 --- a/src/game_sound.cc +++ b/src/game_sound.cc @@ -2105,8 +2105,8 @@ int ambientSoundEffectEventProcess(Object* a1, void* data) if (soundEffectEvent != NULL) { ambientSoundEffectIndex = soundEffectEvent->ambientSoundEffectIndex; } else { - if (ambientSoundEffectGetLength() > 0) { - ambientSoundEffectIndex = ambientSoundEffectGetRandom(); + if (wmSfxMaxCount() > 0) { + ambientSoundEffectIndex = wmSfxRollNextIdx(); } } @@ -2120,8 +2120,8 @@ int ambientSoundEffectEventProcess(Object* a1, void* data) } int delay = 10 * randomBetween(15, 20); - if (ambientSoundEffectGetLength() > 0) { - nextSoundEffectEvent->ambientSoundEffectIndex = ambientSoundEffectGetRandom(); + if (wmSfxMaxCount() > 0) { + nextSoundEffectEvent->ambientSoundEffectIndex = wmSfxRollNextIdx(); if (queueAddEvent(delay, NULL, nextSoundEffectEvent, EVENT_TYPE_GSOUND_SFX_EVENT) == -1) { return -1; } @@ -2133,7 +2133,7 @@ int ambientSoundEffectEventProcess(Object* a1, void* data) if (ambientSoundEffectIndex != -1) { char* fileName; - if (ambientSoundEffectGetName(ambientSoundEffectIndex, &fileName) == 0) { + if (wmSfxIdxName(ambientSoundEffectIndex, &fileName) == 0) { int v7 = _get_bk_time(); if (getTicksBetween(v7, _lastTime_1) >= 5000) { if (soundPlayFile(fileName) == -1) { diff --git a/src/interpreter_extra.cc b/src/interpreter_extra.cc index c153b10..9cae6c1 100644 --- a/src/interpreter_extra.cc +++ b/src/interpreter_extra.cc @@ -799,13 +799,13 @@ static void opMarkAreaKnown(Program* program) // TODO: Provide meaningful names. if (data[2] == 0) { if (data[0] == CITY_STATE_INVISIBLE) { - _wmAreaSetVisibleState(data[1], 0, 1); + wmAreaSetVisibleState(data[1], 0, 1); } else { - _wmAreaSetVisibleState(data[1], 1, 1); - _wmAreaMarkVisitedState(data[1], data[0]); + wmAreaSetVisibleState(data[1], 1, 1); + wmAreaMarkVisitedState(data[1], data[0]); } } else if (data[2] == 1) { - _wmMapMarkVisited(data[1]); + wmMapMarkVisited(data[1]); } } @@ -2031,12 +2031,12 @@ static void opMetarule3(Program* program) result.integerValue = killsGetByType(param1.integerValue); break; case METARULE3_MARK_MAP_ENTRANCE: - result.integerValue = _wmMapMarkMapEntranceState(param1.integerValue, param2.integerValue, param3.integerValue); + result.integerValue = wmMapMarkMapEntranceState(param1.integerValue, param2.integerValue, param3.integerValue); break; case METARULE3_WM_SUBTILE_STATE: if (1) { int state; - if (_wmSubTileGetVisitedState(param1.integerValue, param2.integerValue, &state) == 0) { + if (wmSubTileGetVisitedState(param1.integerValue, param2.integerValue, &state) == 0) { result.integerValue = state; } } @@ -2090,7 +2090,7 @@ static void opMetarule3(Program* program) result.integerValue = aiGetChemUse(static_cast(param1.pointerValue)); break; case METARULE3_110: - result.integerValue = carIsEmpty() ? 1 : 0; + result.integerValue = wmCarIsOutOfGas() ? 1 : 0; break; case METARULE3_111: result.integerValue = _map_target_load_area(); @@ -2108,7 +2108,7 @@ static void opSetMapMusic(Program* program) int mapIndex = programStackPopInteger(program); debugPrint("\nset_map_music: %d, %s", mapIndex, string); - worldmapSetMapMusic(mapIndex, string); + wmSetMapMusic(mapIndex, string); } // NOTE: Function name is a bit misleading. Last parameter is a boolean value @@ -2184,7 +2184,7 @@ static void opLoadMap(Program* program) if (mapName != NULL) { gGameGlobalVars[GVAR_LOAD_MAP_INDEX] = param; - mapIndex = mapGetIndexByFileName(mapName); + mapIndex = wmMapMatchNameToIdx(mapName); } else { if (mapIndexOrName.integerValue >= 0) { gGameGlobalVars[GVAR_LOAD_MAP_INDEX] = param; @@ -2210,7 +2210,7 @@ static void opWorldmapCitySetPos(Program* program) int x = programStackPopInteger(program); int city = programStackPopInteger(program); - if (worldmapCitySetPos(city, x, y) == -1) { + if (wmAreaSetWorldPos(city, x, y) == -1) { scriptPredefinedError(program, "wm_area_set_pos", SCRIPT_ERROR_FOLLOWS); debugPrint("Invalid Parameter!"); } @@ -3210,25 +3210,25 @@ static void opMetarule(Program* program) result = _getPartyMemberCount(); break; case METARULE_AREA_KNOWN: - result = _wmAreaVisitedState(param.integerValue); + result = wmAreaVisitedState(param.integerValue); break; case METARULE_WHO_ON_DRUGS: result = queueHasEvent(static_cast(param.pointerValue), EVENT_TYPE_DRUG); break; case METARULE_MAP_KNOWN: - result = _wmMapIsKnown(param.integerValue); + result = wmMapIsKnown(param.integerValue); break; case METARULE_IS_LOADGAME: result = _isLoadingGame(); break; case METARULE_CAR_CURRENT_TOWN: - result = carGetCity(); + result = wmCarCurrentArea(); break; case METARULE_GIVE_CAR_TO_PARTY: - result = _wmCarGiveToParty(); + result = wmCarGiveToParty(); break; case METARULE_GIVE_CAR_GAS: - result = carAddFuel(param.integerValue); + result = wmCarFillGas(param.integerValue); break; case METARULE_SKILL_CHECK_TAG: result = skillIsTagged(param.integerValue); @@ -3268,13 +3268,13 @@ static void opMetarule(Program* program) } break; case METARULE_GET_WORLDMAP_XPOS: - _wmGetPartyWorldPos(&result, NULL); + wmGetPartyWorldPos(&result, NULL); break; case METARULE_GET_WORLDMAP_YPOS: - _wmGetPartyWorldPos(NULL, &result); + wmGetPartyWorldPos(NULL, &result); break; case METARULE_CURRENT_TOWN: - if (_wmGetPartyCurArea(&result) == -1) { + if (wmGetPartyCurArea(&result) == -1) { debugPrint("\nIntextra: Error: metarule: current_town"); } break; diff --git a/src/loadsave.cc b/src/loadsave.cc index ab9749d..64bcb72 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -216,7 +216,7 @@ static SaveGameHandler* _master_save_list[LOAD_SAVE_HANDLER_COUNT] = { automapSave, preferencesSave, characterEditorSave, - worldmapSave, + wmWorldMap_save, pipboySave, gameMoviesSave, skillsUsageSave, @@ -247,7 +247,7 @@ static LoadGameHandler* _master_load_list[LOAD_SAVE_HANDLER_COUNT] = { automapLoad, preferencesLoad, characterEditorLoad, - worldmapLoad, + wmWorldMap_load, pipboyLoad, gameMoviesLoad, skillsUsageLoad, @@ -2217,7 +2217,7 @@ static int _PrepLoad(File* stream) // 0x47F4C8 static int _EndLoad(File* stream) { - worldmapStartMapMusic(); + wmMapMusicStart(); dudeSetName(_LSData[_slot_cursor].character_name); interfaceBarRefresh(); indicatorBarRefresh(); diff --git a/src/main.cc b/src/main.cc index f80258d..f841448 100644 --- a/src/main.cc +++ b/src/main.cc @@ -401,7 +401,7 @@ static int _main_load_new(char* mapFileName) gameMouseSetCursor(MOUSE_CURSOR_NONE); mouseShowCursor(); mapLoadByName(mapFileName); - worldmapStartMapMusic(); + wmMapMusicStart(); paletteFadeTo(gPaletteWhite); windowDestroy(win); colorPaletteLoad("color.pal"); diff --git a/src/map.cc b/src/map.cc index 1b3a3d5..aa404c7 100644 --- a/src/map.cc +++ b/src/map.cc @@ -367,7 +367,7 @@ int mapSetElevation(int elevation) } if (elevation != gElevation) { - _wmMapMarkMapEntranceState(gMapHeader.field_34, elevation, 1); + wmMapMarkMapEntranceState(gMapHeader.field_34, elevation, 1); } gElevation = elevation; @@ -465,7 +465,7 @@ void mapSetStart(int tile, int elevation, int rotation) // 0x4824CC char* mapGetName(int map, int elevation) { - if (map < 0 || map >= mapGetCount()) { + if (map < 0 || map >= wmMapMaxCount()) { return NULL; } @@ -482,29 +482,29 @@ char* mapGetName(int map, int elevation) // 0x482528 bool _is_map_idx_same(int map1, int map2) { - if (map1 < 0 || map1 >= mapGetCount()) { + if (map1 < 0 || map1 >= wmMapMaxCount()) { return 0; } - if (map2 < 0 || map2 >= mapGetCount()) { + if (map2 < 0 || map2 >= wmMapMaxCount()) { return 0; } - if (!_wmMapIdxIsSaveable(map1)) { + if (!wmMapIdxIsSaveable(map1)) { return 0; } - if (!_wmMapIdxIsSaveable(map2)) { + if (!wmMapIdxIsSaveable(map2)) { return 0; } int city1; - if (_wmMatchAreaContainingMapIdx(map1, &city1) == -1) { + if (wmMatchAreaContainingMapIdx(map1, &city1) == -1) { return 0; } int city2; - if (_wmMatchAreaContainingMapIdx(map2, &city2) == -1) { + if (wmMatchAreaContainingMapIdx(map2, &city2) == -1) { return 0; } @@ -515,12 +515,12 @@ bool _is_map_idx_same(int map1, int map2) int _get_map_idx_same(int map1, int map2) { int city1 = -1; - if (_wmMatchAreaContainingMapIdx(map1, &city1) == -1) { + if (wmMatchAreaContainingMapIdx(map1, &city1) == -1) { return -1; } int city2 = -2; - if (_wmMatchAreaContainingMapIdx(map2, &city2) == -1) { + if (wmMatchAreaContainingMapIdx(map2, &city2) == -1) { return -1; } @@ -535,7 +535,7 @@ int _get_map_idx_same(int map1, int map2) char* mapGetCityName(int map) { int city; - if (_wmMatchAreaContainingMapIdx(map, &city) == -1) { + if (wmMatchAreaContainingMapIdx(map, &city) == -1) { return _aErrorF2; } @@ -548,8 +548,8 @@ char* mapGetCityName(int map) char* _map_get_description_idx_(int map) { int city; - if (_wmMatchAreaContainingMapIdx(map, &city) == 0) { - _wmGetAreaIdxName(city, _scratchStr); + if (wmMatchAreaContainingMapIdx(map, &city) == 0) { + wmGetAreaIdxName(city, _scratchStr); } else { strcpy(_scratchStr, _errMapName); } @@ -739,7 +739,7 @@ int mapLoadByName(char* fileName) if (stream != NULL) { fileClose(stream); rc = mapLoadSaved(fileName); - worldmapStartMapMusic(); + wmMapMusicStart(); } } @@ -766,7 +766,7 @@ int mapLoadById(int map) scriptSetFixedParam(gMapSid, map); char name[16]; - if (mapGetFileName(map, name) == -1) { + if (wmMapIdxToName(map, name) == -1) { return -1; } @@ -774,7 +774,7 @@ int mapLoadById(int map) int rc = mapLoadByName(name); - worldmapStartMapMusic(); + wmMapMusicStart(); return rc; } @@ -898,7 +898,7 @@ static int mapLoad(File* stream) lightSetLightLevel(LIGHT_LEVEL_MAX, false); objectSetLocation(gDude, gCenterTile, gElevation, NULL); objectSetRotation(gDude, gEnteringRotation, NULL); - gMapHeader.field_34 = mapGetIndexByFileName(gMapHeader.name); + gMapHeader.field_34 = wmMapMatchNameToIdx(gMapHeader.name); if ((gMapHeader.flags & 1) == 0) { char path[COMPAT_MAX_PATH]; @@ -946,7 +946,7 @@ static int mapLoad(File* stream) _scr_spatials_enable(); error = "Error Setting up random encounter"; - if (worldmapSetupRandomEncounter() == -1) { + if (wmSetupRandomEncounter() == -1) { goto err; } } @@ -996,10 +996,10 @@ err: rc = -1; } - _wmMapMarkVisited(gMapHeader.field_34); - _wmMapMarkMapEntranceState(gMapHeader.field_34, gElevation, 1); + wmMapMarkVisited(gMapHeader.field_34); + wmMapMarkMapEntranceState(gMapHeader.field_34, gElevation, 1); - if (_wmCheckGameAreaEvents() != 0) { + if (wmCheckGameAreaEvents() != 0) { rc = -1; } @@ -1043,7 +1043,7 @@ int mapLoadSaved(char* fileName) } } - if (!_wmMapIsSaveable()) { + if (!wmMapIsSaveable()) { debugPrint("\nDestroying RANDOM encounter map."); char v15[16]; @@ -1062,7 +1062,7 @@ int mapLoadSaved(char* fileName) // 0x48328C static int _map_age_dead_critters() { - if (!_wmMapDeadBodiesAge()) { + if (!wmMapDeadBodiesAge()) { return 0; } @@ -1175,7 +1175,7 @@ static int _map_age_dead_critters() int _map_target_load_area() { int city = -1; - if (_wmMatchAreaContainingMapIdx(gMapHeader.field_34, &city) == -1) { + if (wmMatchAreaContainingMapIdx(gMapHeader.field_34, &city) == -1) { city = -1; } return city; @@ -1215,13 +1215,13 @@ int mapHandleTransition() if (gMapTransition.map == -1) { if (!isInCombat()) { animationStop(); - _wmTownMap(); + wmTownMap(); memset(&gMapTransition, 0, sizeof(gMapTransition)); } } else if (gMapTransition.map == -2) { if (!isInCombat()) { animationStop(); - _wmWorldMap(); + wmWorldMap(); memset(&gMapTransition, 0, sizeof(gMapTransition)); } } else { @@ -1245,8 +1245,8 @@ int mapHandleTransition() memset(&gMapTransition, 0, sizeof(gMapTransition)); int city; - _wmMatchAreaContainingMapIdx(gMapHeader.field_34, &city); - if (_wmTeleportToArea(city) == -1) { + wmMatchAreaContainingMapIdx(gMapHeader.field_34, &city); + if (wmTeleportToArea(city) == -1) { debugPrint("\nError: couldn't make jump on worldmap for map jump!"); } } @@ -1425,7 +1425,7 @@ int _map_save_in_game(bool a1) char name[16]; - if (a1 && !_wmMapIsSaveable()) { + if (a1 && !wmMapIsSaveable()) { debugPrint("\nNot saving RANDOM encounter map."); strcpy(name, gMapHeader.name); diff --git a/src/object.cc b/src/object.cc index 02d2ba2..3e547bf 100644 --- a/src/object.cc +++ b/src/object.cc @@ -1484,7 +1484,7 @@ int objectSetLocation(Object* obj, int tile, int elevation, Rect* rect) transition.rotation = data->misc.rotation; mapSetTransition(&transition); - _wmMapMarkMapEntranceState(transition.map, transition.elevation, 1); + wmMapMarkMapEntranceState(transition.map, transition.elevation, 1); } } } diff --git a/src/pipboy.cc b/src/pipboy.cc index ec4efa1..e6be2fb 100644 --- a/src/pipboy.cc +++ b/src/pipboy.cc @@ -401,7 +401,7 @@ static int gPipboyPrevTab; // 0x497004 int pipboyOpen(int intent) { - if (!_wmMapPipboyActive()) { + if (!wmMapPipboyActive()) { // You aren't wearing the pipboy! const char* text = getmsg(&gMiscMessageList, &gPipboyMessageListItem, 7000); showDialogBox(text, NULL, 0, 192, 135, _colorTable[32328], NULL, _colorTable[32328], 1); @@ -1504,7 +1504,7 @@ static int _PrintAMelevList(int a1) } } - int mapCount = mapGetCount(); + int mapCount = wmMapMaxCount(); for (int map = 0; map < mapCount; map++) { if (map == _amcty_indx) { continue; @@ -1579,7 +1579,7 @@ static int _PrintAMList(int a1) int count = 0; int index = 0; - int mapCount = mapGetCount(); + int mapCount = wmMapMaxCount(); for (int map = 0; map < mapCount; map++) { int elevation; for (elevation = 0; elevation < ELEVATION_COUNT; elevation++) { diff --git a/src/proto_instance.cc b/src/proto_instance.cc index 807c290..98a8319 100644 --- a/src/proto_instance.cc +++ b/src/proto_instance.cc @@ -473,7 +473,7 @@ int _obj_examine_func(Object* critter, Object* target, void (*fn)(char* string)) } if (car != 0) { - sprintf(formattedText, carMessageListItem.text, 100 * carGetFuel() / 80000); + sprintf(formattedText, carMessageListItem.text, 100 * wmCarGasAmount() / 80000); } else { strcpy(formattedText, carMessageListItem.text); } @@ -954,12 +954,12 @@ static int _obj_use_power_on_car(Object* item) // SFALL: Fix for cells getting consumed even when the car is already fully // charged. int rc; - if (carGetFuel() < CAR_FUEL_MAX) { + if (wmCarGasAmount() < CAR_FUEL_MAX) { int energy = ammoGetQuantity(item) * energyDensity; int capacity = ammoGetCapacity(item); // NOTE: that function will never return -1 - if (carAddFuel(energy / capacity) == -1) { + if (wmCarFillGas(energy / capacity) == -1) { return -1; } @@ -1520,7 +1520,7 @@ static int useLadderDown(Object* a1, Object* ladder, int a3) mapSetTransition(&transition); - _wmMapMarkMapEntranceState(transition.map, elevation, 1); + wmMapMarkMapEntranceState(transition.map, elevation, 1); } else { Rect updatedRect; if (objectSetLocation(a1, tile, elevation, &updatedRect) == -1) { @@ -1554,7 +1554,7 @@ static int useLadderUp(Object* a1, Object* ladder, int a3) mapSetTransition(&transition); - _wmMapMarkMapEntranceState(transition.map, elevation, 1); + wmMapMarkMapEntranceState(transition.map, elevation, 1); } else { Rect updatedRect; if (objectSetLocation(a1, tile, elevation, &updatedRect) == -1) { @@ -1588,7 +1588,7 @@ static int useStairs(Object* a1, Object* stairs, int a3) mapSetTransition(&transition); - _wmMapMarkMapEntranceState(transition.map, elevation, 1); + wmMapMarkMapEntranceState(transition.map, elevation, 1); } else { Rect updatedRect; if (objectSetLocation(a1, tile, elevation, &updatedRect) == -1) { @@ -2241,13 +2241,13 @@ int _objPMAttemptPlacement(Object* obj, int tile, int elevation) int v9 = tile; int v7 = 0; - if (!_wmEvalTileNumForPlacement(tile)) { + if (!wmEvalTileNumForPlacement(tile)) { v9 = gDude->tile; for (int v4 = 1; v4 <= 100; v4++) { // TODO: Check. v7++; v9 = tileGetTileInDirection(v9, v7 % ROTATION_COUNT, 1); - if (_wmEvalTileNumForPlacement(v9) != 0) { + if (wmEvalTileNumForPlacement(v9) != 0) { break; } diff --git a/src/scripts.cc b/src/scripts.cc index 8c8e768..33f3d21 100644 --- a/src/scripts.cc +++ b/src/scripts.cc @@ -443,9 +443,9 @@ int _scriptsCheckGameEvents(int* moviePtr, int window) movie = MOVIE_ARTIMER4; if (!gameMovieIsSeen(MOVIE_ARTIMER4)) { adjustRep = true; - _wmAreaSetVisibleState(CITY_ARROYO, 0, 1); - _wmAreaSetVisibleState(CITY_DESTROYED_ARROYO, 1, 1); - _wmAreaMarkVisitedState(CITY_DESTROYED_ARROYO, 2); + wmAreaSetVisibleState(CITY_ARROYO, 0, 1); + wmAreaSetVisibleState(CITY_DESTROYED_ARROYO, 1, 1); + wmAreaMarkVisitedState(CITY_DESTROYED_ARROYO, 2); } } else if (day >= 270 && gameGetGlobalVar(GVAR_FALLOUT_2) != 3) { adjustRep = true; @@ -907,12 +907,12 @@ int scriptsHandleRequests() if ((gScriptsRequests & SCRIPT_REQUEST_0x02) != 0) { gScriptsRequests &= ~SCRIPT_REQUEST_0x02; - _wmTownMap(); + wmTownMap(); } if ((gScriptsRequests & SCRIPT_REQUEST_WORLD_MAP) != 0) { gScriptsRequests &= ~SCRIPT_REQUEST_WORLD_MAP; - _wmWorldMap(); + wmWorldMap(); } if ((gScriptsRequests & SCRIPT_REQUEST_ELEVATOR) != 0) { diff --git a/src/worldmap.cc b/src/worldmap.cc index 1216f4f..5af0105 100644 --- a/src/worldmap.cc +++ b/src/worldmap.cc @@ -163,19 +163,17 @@ typedef enum Daytime { DAY_PART_COUNT, } Daytime; +typedef enum LockState { + LOCK_STATE_UNLOCKED, + LOCK_STATE_LOCKED, +} LockState; + typedef enum SubtileState { SUBTILE_STATE_UNKNOWN, SUBTILE_STATE_KNOWN, SUBTILE_STATE_VISITED, } SubtileState; -typedef enum CitySize { - CITY_SIZE_SMALL, - CITY_SIZE_MEDIUM, - CITY_SIZE_LARGE, - CITY_SIZE_COUNT, -} CitySize; - typedef enum WorldMapEncounterFrm { WORLD_MAP_ENCOUNTER_FRM_RANDOM_BRIGHT, WORLD_MAP_ENCOUNTER_FRM_RANDOM_DARK, @@ -190,6 +188,13 @@ typedef enum WorldmapArrowFrm { WORLDMAP_ARROW_FRM_COUNT, } WorldmapArrowFrm; +typedef enum CitySize { + CITY_SIZE_SMALL, + CITY_SIZE_MEDIUM, + CITY_SIZE_LARGE, + CITY_SIZE_COUNT, +} CitySize; + typedef struct EntranceInfo { int state; int x; @@ -202,14 +207,13 @@ typedef struct EntranceInfo { typedef struct CityInfo { char name[CITY_NAME_SIZE]; - int field_28; + int areaId; int x; int y; int size; int state; - // lock state - int field_3C; - int field_40; + int lockState; + int visitedState; int mapFid; int labelFid; int entrancesLength; @@ -241,7 +245,7 @@ typedef struct MapInfo { } MapInfo; typedef struct Terrain { - char field_0[40]; + char lookupName[40]; int difficulty; int mapsLength; int maps[20]; @@ -339,7 +343,6 @@ typedef struct TileInfo { SubtileInfo subtiles[SUBTILE_GRID_HEIGHT][SUBTILE_GRID_WIDTH]; } TileInfo; -// typedef struct CitySizeDescription { int fid; int width; @@ -348,6 +351,221 @@ typedef struct CitySizeDescription { unsigned char* data; } CitySizeDescription; +typedef struct WmGenData { + bool mousePressed; + bool didMeetFrankHorrigan; + + int currentAreaId; + int worldPosX; + int worldPosY; + SubtileInfo* currentSubtile; + + int dword_672E18; + + bool isWalking; + int walkDestinationX; + int walkDestinationY; + int walkDistance; + int walkLineDelta; + int walkLineDeltaMainAxisStep; + int walkLineDeltaCrossAxisStep; + int walkWorldPosMainAxisStepX; + int walkWorldPosCrossAxisStepX; + int walkWorldPosMainAxisStepY; + int walkWorldPosCrossAxisStepY; + + int encounterIconIsVisible; + int encounterMapId; + int encounterTableId; + int encounterEntryId; + int encounterCursorId; + + int oldWorldPosX; + int oldWorldPosY; + + bool isInCar; + int currentCarAreaId; + int carFuel; + + CacheEntry* carImageFrmHandle; + Art* carImageFrm; + int carImageFrmWidth; + int carImageFrmHeight; + int carImageCurrentFrameIndex; + + CacheEntry* hotspotNormalFrmHandle; + unsigned char* hotspotNormalFrmData; + CacheEntry* hotspotPressedFrmHandle; + unsigned char* hotspotPressedFrmData; + int hotspotFrmWidth; + int hotspotFrmHeight; + + CacheEntry* destinationMarkerFrmHandle; + unsigned char* destinationMarkerFrmData; + int destinationMarkerFrmWidth; + int destinationMarkerFrmHeight; + + CacheEntry* locationMarkerFrmHandle; + unsigned char* locationMarkerFrmData; + int locationMarkerFrmWidth; + int locationMarkerFrmHeight; + + CacheEntry* encounterCursorFrmHandle[WORLD_MAP_ENCOUNTER_FRM_COUNT]; + unsigned char* encounterCursorFrmData[WORLD_MAP_ENCOUNTER_FRM_COUNT]; + int encounterCursorFrmWidths[WORLD_MAP_ENCOUNTER_FRM_COUNT]; + int encounterCursorFrmHeights[WORLD_MAP_ENCOUNTER_FRM_COUNT]; + + int viewportMaxX; + int viewportMaxY; + + CacheEntry* tabsBackgroundFrmHandle; + int tabsBackgroundFrmWidth; + int tabsBackgroundFrmHeight; + int tabsOffsetY; + unsigned char* tabsBackgroundFrmData; + + CacheEntry* tabsBorderFrmHandle; + unsigned char* tabsBorderFrmData; + + CacheEntry* dialFrmHandle; + int dialFrmWidth; + int dialFrmHeight; + int dialFrmCurrentFrameIndex; + Art* dialFrm; + + CacheEntry* carImageOverlayFrmHandle; + int carImageOverlayFrmWidth; + int carImageOverlayFrmHeight; + unsigned char* carImageOverlayFrmData; + + CacheEntry* globeOverlayFrmHandle; + int globeOverlayFrmWidth; + int globeOverlayFrmHeight; + unsigned char* globeOverlayFrmData; + + int oldTabsOffsetY; + int tabsScrollingDelta; + + CacheEntry* littleRedButtonNormalFrmHandle; + CacheEntry* littleRedButtonPressedFrmHandle; + unsigned char* littleRedButtonNormalFrmData; + unsigned char* littleRedButtonPressedFrmData; + + CacheEntry* scrollUpButtonFrmHandle[WORLDMAP_ARROW_FRM_COUNT]; + int scrollUpButtonFrmWidth; + int scrollUpButtonFrmHeight; + unsigned char* scrollUpButtonFrmData[WORLDMAP_ARROW_FRM_COUNT]; + + CacheEntry* scrollDownButtonFrmHandle[WORLDMAP_ARROW_FRM_COUNT]; + int scrollDownButtonFrmWidth; + int scrollDownButtonFrmHeight; + unsigned char* scrollDownButtonFrmData[WORLDMAP_ARROW_FRM_COUNT]; + + CacheEntry* monthsFrmHandle; + Art* monthsFrm; + + CacheEntry* numbersFrmHandle; + Art* numbersFrm; + + int oldFont; +} WmGenData; + +static void wmSetFlags(int* flagsPtr, int flag, int value); +static int wmGenDataInit(); +static int wmGenDataReset(); +static int wmWorldMapSaveTempData(); +static int wmWorldMapLoadTempData(); +static int wmConfigInit(); +static int wmReadEncounterType(Config* config, char* lookupName, char* sectionKey); +static int wmParseEncounterTableIndex(EncounterEntry* entry, char* string); +static int wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr); +static int wmParseFindSubEncTypeMatch(char* str, int* valuePtr); +static int wmFindEncBaseTypeMatch(char* str, int* valuePtr); +static int wmReadEncBaseType(char* name, int* valuePtr); +static int wmParseEncBaseSubTypeStr(ENC_BASE_TYPE_38* ptr, char** stringPtr); +static int wmEncBaseTypeSlotInit(ENC_BASE_TYPE* entry); +static int wmEncBaseSubTypeSlotInit(ENC_BASE_TYPE_38* entry); +static int wmEncounterSubEncSlotInit(ENCOUNTER_ENTRY_ENC* entry); +static int wmEncounterTypeSlotInit(EncounterEntry* entry); +static int wmEncounterTableSlotInit(EncounterTable* encounterTable); +static int wmTileSlotInit(TileInfo* tile); +static int wmTerrainTypeSlotInit(Terrain* terrain); +static int wmConditionalDataInit(EncounterCondition* condition); +static int wmParseTerrainTypes(Config* config, char* string); +static int wmParseTerrainRndMaps(Config* config, Terrain* terrain); +static int wmParseSubTileInfo(TileInfo* tile, int row, int column, char* string); +static int wmParseFindEncounterTypeMatch(char* string, int* valuePtr); +static int wmParseFindTerrainTypeMatch(char* string, int* valuePtr); +static int wmParseEncounterItemType(char** stringPtr, ENC_BASE_TYPE_38_48* a2, int* a3, const char* delim); +static int wmParseItemType(char* string, ENC_BASE_TYPE_38_48* ptr); +static int wmParseConditional(char** stringPtr, const char* a2, EncounterCondition* condition); +static int wmParseSubConditional(char** stringPtr, const char* a2, int* typePtr, int* operatorPtr, int* paramPtr, int* valuePtr); +static int wmParseConditionalEval(char** stringPtr, int* conditionalOperatorPtr); +static int wmAreaSlotInit(CityInfo* area); +static int wmAreaInit(); +static int wmParseFindMapIdxMatch(char* string, int* valuePtr); +static int wmEntranceSlotInit(EntranceInfo* entrance); +static int wmMapSlotInit(MapInfo* map); +static int wmMapInit(); +static int wmRStartSlotInit(MapStartPointInfo* rsp); +static int wmMatchEntranceFromMap(int areaIdx, int mapIdx, int* entranceIdxPtr); +static int wmMatchEntranceElevFromMap(int areaIdx, int mapIdx, int elevation, int* entranceIdxPtr); +static int wmMatchAreaFromMap(int mapIdx, int* areaIdxPtr); +static int wmWorldMapFunc(int a1); +static int wmInterfaceCenterOnParty(); +static void wmCheckGameEvents(); +static int wmRndEncounterOccurred(); +static int wmPartyFindCurSubTile(); +static int wmFindCurSubTileFromPos(int x, int y, SubtileInfo** subtilePtr); +static int wmFindCurTileFromPos(int x, int y, TileInfo** tilePtr); +static int wmRndEncounterPick(); +static int wmSetupCritterObjs(int type_idx, Object** critterPtr, int critterCount); +static int wmSetupRndNextTileNumInit(ENC_BASE_TYPE* a1); +static int wmSetupRndNextTileNum(ENC_BASE_TYPE* a1, ENC_BASE_TYPE_38* a2, int* out_tile_num); +static bool wmEvalConditional(EncounterCondition* a1, int* a2); +static bool wmEvalSubConditional(int operand1, int condionalOperator, int operand2); +static bool wmGameTimeIncrement(int ticksToAdd); +static int wmGrabTileWalkMask(int tileIdx); +static bool wmWorldPosInvalid(int x, int y); +static void wmPartyInitWalking(int x, int y); +static void wmPartyWalkingStep(); +static void wmInterfaceScrollTabsStart(int delta); +static void wmInterfaceScrollTabsStop(); +static void wmInterfaceScrollTabsUpdate(); +static int wmInterfaceInit(); +static int wmInterfaceExit(); +static int wmInterfaceScroll(int dx, int dy, bool* successPtr); +static int wmInterfaceScrollPixel(int stepX, int stepY, int dx, int dy, bool* success, bool shouldRefresh); +static void wmMouseBkProc(); +static int wmMarkSubTileOffsetVisited(int tile, int subtileX, int subtileY, int offsetX, int offsetY); +static int wmMarkSubTileOffsetKnown(int tile, int subtileX, int subtileY, int offsetX, int offsetY); +static int wmMarkSubTileOffsetVisitedFunc(int tile, int subtileX, int subtileY, int offsetX, int offsetY, int subtileState); +static void wmMarkSubTileRadiusVisited(int x, int y); +static int wmTileGrabArt(int tileIdx); +static int wmInterfaceRefresh(); +static void wmInterfaceRefreshDate(bool shouldRefreshWindow); +static int wmMatchWorldPosToArea(int x, int y, int* areaIdxPtr); +static int wmInterfaceDrawCircleOverlay(CityInfo* cityInfo, CitySizeDescription* citySizeInfo, unsigned char* buffer, int x, int y); +static void wmInterfaceDrawSubTileRectFogged(unsigned char* dest, int width, int height, int pitch); +static int wmInterfaceDrawSubTileList(TileInfo* tileInfo, int column, int row, int x, int y, int a6); +static int wmDrawCursorStopped(); +static bool wmCursorIsVisible(); +static int wmGetAreaName(CityInfo* city, char* name); +static void wmMarkAllSubTiles(int state); +static int wmTownMapFunc(int* mapIdxPtr); +static int wmTownMapInit(); +static int wmTownMapRefresh(); +static int wmTownMapExit(); +static int wmRefreshInterfaceOverlay(bool shouldRefreshWindow); +static void wmInterfaceRefreshCarFuel(); +static int wmRefreshTabs(); +static int wmMakeTabsLabelList(int** quickDestinationsPtr, int* quickDestinationsLengthPtr); +static int wmTabsCompareNames(const void* a1, const void* a2); +static int wmFreeTabsLabelList(int** quickDestinationsListPtr, int* quickDestinationsLengthPtr); +static void wmRefreshInterfaceDial(bool shouldRefreshWindow); +static void wmInterfaceDialSyncTime(bool shouldRefreshWindow); +static int wmAreaFindFirstValidMap(int* mapIdxPtr); + // 0x4BC860 static const int _can_rest_here[ELEVATION_COUNT] = { MAP_CAN_REST_ELEVATION_0, @@ -363,13 +581,13 @@ static const int gDayPartEncounterFrequencyModifiers[DAY_PART_COUNT] = { }; // 0x4BC878 -static const char* off_4BC878[2] = { +static const char* gWorldmapEncDefaultMsg[2] = { "You detect something up ahead.", "Do you wish to encounter it?", }; // 0x4BC880 -static MessageListItem stru_4BC880; +static MessageListItem gWorldmapMessageListItem; // 0x50EE44 static char _aCricket[] = "cricket"; @@ -378,19 +596,19 @@ static char _aCricket[] = "cricket"; static char _aCricket1[] = "cricket1"; // 0x51DD88 -static const char* _wmStateStrs[2] = { +static const char* wmStateStrs[2] = { "off", "on" }; // 0x51DD90 -static const char* _wmYesNoStrs[2] = { +static const char* wmYesNoStrs[2] = { "no", "yes", }; // 0x51DD98 -static const char* gEncounterFrequencyTypeKeys[ENCOUNTER_FREQUENCY_TYPE_COUNT] = { +static const char* wmFreqStrs[ENCOUNTER_FREQUENCY_TYPE_COUNT] = { "none", "rare", "uncommon", @@ -400,7 +618,7 @@ static const char* gEncounterFrequencyTypeKeys[ENCOUNTER_FREQUENCY_TYPE_COUNT] = }; // 0x51DDB0 -static const char* _wmFillStrs[9] = { +static const char* wmFillStrs[9] = { "no_fill", "fill_n", "fill_s", @@ -413,7 +631,7 @@ static const char* _wmFillStrs[9] = { }; // 0x51DDD4 -static const char* _wmSceneryStrs[ENCOUNTER_SCENERY_TYPE_COUNT] = { +static const char* wmSceneryStrs[ENCOUNTER_SCENERY_TYPE_COUNT] = { "none", "light", "normal", @@ -421,85 +639,85 @@ static const char* _wmSceneryStrs[ENCOUNTER_SCENERY_TYPE_COUNT] = { }; // 0x51DDE4 -static Terrain* gTerrains = NULL; +static Terrain* wmTerrainTypeList = NULL; // 0x51DDE8 -static int gTerrainsLength = 0; +static int wmMaxTerrainTypes = 0; // 0x51DDEC -static TileInfo* gWorldmapTiles = NULL; +static TileInfo* wmTileInfoList = NULL; // 0x51DDF0 -static int gWorldmapTilesLength = 0; +static int wmMaxTileNum = 0; // The width of worldmap grid in tiles. // // There is no separate variable for grid height, instead its calculated as -// [gWorldmapTilesLength] / [gWorldmapTilesGridWidth]. +// [wmMaxTileNum] / [gWorldmapTilesGridWidth]. // // num_horizontal_tiles // 0x51DDF4 -static int gWorldmapGridWidth = 0; +static int wmNumHorizontalTiles = 0; // 0x51DDF8 -static CityInfo* gCities = NULL; +static CityInfo* wmAreaInfoList = NULL; // 0x51DDFC -static int gCitiesLength = 0; +static int wmMaxAreaNum = 0; // 0x51DE00 -static const char* gCitySizeKeys[CITY_SIZE_COUNT] = { +static const char* wmAreaSizeStrs[CITY_SIZE_COUNT] = { "small", "medium", "large", }; // 0x51DE0C -static MapInfo* gMaps = NULL; +static MapInfo* wmMapInfoList = NULL; // 0x51DE10 -static int gMapsLength = 0; +static int wmMaxMapNum = 0; // 0x51DE14 -static int gWorldmapWindow = -1; +static int wmBkWin = -1; // 0x51DE18 -static CacheEntry* gWorldmapBoxFrmHandle = INVALID_CACHE_ENTRY; +static CacheEntry* wmBkKey = INVALID_CACHE_ENTRY; // 0x51DE1C -static int gWorldmapBoxFrmWidth = 0; +static int wmBkWidth = 0; // 0x51DE20 -static int gWorldmapBoxFrmHeight = 0; +static int wmBkHeight = 0; // 0x51DE24 -static unsigned char* gWorldmapWindowBuffer = NULL; +static unsigned char* wmBkWinBuf = NULL; // 0x51DE28 -static unsigned char* gWorldmapBoxFrmData = NULL; +static unsigned char* wmBkArtBuf = NULL; // 0x51DE2C -static int gWorldmapOffsetX = 0; +static int wmWorldOffsetX = 0; // 0x51DE30 -static int gWorldmapOffsetY = 0; +static int wmWorldOffsetY = 0; -// -static unsigned char* _circleBlendTable = NULL; +// 0x51DE34 +unsigned char* circleBlendTable = NULL; -// -static int _wmInterfaceWasInitialized = 0; +// 0x51DE38 +static int wmInterfaceWasInitialized = 0; -// encounter types -static const char* _wmEncOpStrs[ENCOUNTER_SITUATION_COUNT] = { +// 0x51DE3C +static const char* wmEncOpStrs[ENCOUNTER_SITUATION_COUNT] = { "nothing", "ambush", "fighting", "and", }; -// operators -static const char* _wmConditionalOpStrs[ENCOUNTER_CONDITIONAL_OPERATOR_COUNT] = { +// 0x51DE4C +static const char* wmConditionalOpStrs[ENCOUNTER_CONDITIONAL_OPERATOR_COUNT] = { "_", "==", "!=", @@ -507,8 +725,14 @@ static const char* _wmConditionalOpStrs[ENCOUNTER_CONDITIONAL_OPERATOR_COUNT] = ">", }; +// 0x51DE64 +static const char* wmConditionalQualifierStrs[2] = { + "and", + "or", +}; + // 0x51DE6C -static const char* gEncounterFormationTypeKeys[ENCOUNTER_FORMATION_TYPE_COUNT] = { +static const char* wmFormationStrs[ENCOUNTER_FORMATION_TYPE_COUNT] = { "surrounding", "straight_line", "double_line", @@ -518,7 +742,7 @@ static const char* gEncounterFormationTypeKeys[ENCOUNTER_FORMATION_TYPE_COUNT] = }; // 0x51DE84 -static int gWorldmapEncounterFrmIds[WORLD_MAP_ENCOUNTER_FRM_COUNT] = { +static const int wmRndCursorFids[WORLD_MAP_ENCOUNTER_FRM_COUNT] = { 154, 155, 438, @@ -526,22 +750,22 @@ static int gWorldmapEncounterFrmIds[WORLD_MAP_ENCOUNTER_FRM_COUNT] = { }; // 0x51DE94 -static int* gQuickDestinations = NULL; +static int* wmLabelList = NULL; // 0x51DE98 -static int gQuickDestinationsLength = 0; +static int wmLabelCount = 0; // 0x51DE9C -static int _wmTownMapCurArea = -1; +static int wmTownMapCurArea = -1; // 0x51DEA0 -static unsigned int _wmLastRndTime = 0; +static unsigned int wmLastRndTime = 0; // 0x51DEA4 -static int _wmRndIndex = 0; +static int wmRndIndex = 0; // 0x51DEA8 -static int _wmRndCallCount = 0; +static int wmRndCallCount = 0; // 0x51DEAC static int _terrainCounter = 1; @@ -553,462 +777,89 @@ static unsigned int _lastTime_2 = 0; static bool _couldScroll = true; // 0x51DEB8 -static unsigned char* gWorldmapCityMapFrmData = NULL; +static unsigned char* wmTownBuffer = NULL; // 0x51DEBC -static CacheEntry* gWorldmapCityMapFrmHandle = INVALID_CACHE_ENTRY; +static CacheEntry* wmTownKey = INVALID_CACHE_ENTRY; // 0x51DEC0 -static int gWorldmapCityMapFrmWidth = 0; +static int wmTownWidth = 0; // 0x51DEC4 -static int gWorldmapCityMapFrmHeight = 0; +static int wmTownHeight = 0; // 0x51DEC8 -static char* _wmRemapSfxList[2] = { +static char* wmRemapSfxList[2] = { _aCricket, _aCricket1, }; // 0x672DB8 -static int _wmRndTileDirs[2]; +static int wmRndTileDirs[2]; // 0x672DC0 -static int _wmRndCenterTiles[2]; +static int wmRndCenterTiles[2]; // 0x672DC8 -static int _wmRndCenterRotations[2]; +static int wmRndCenterRotations[2]; // 0x672DD0 -static int _wmRndRotOffsets[2]; +static int wmRndRotOffsets[2]; // Buttons for city entrances. // // 0x672DD8 -static int _wmTownMapButtonId[ENTRANCE_LIST_CAPACITY]; +static int wmTownMapButtonId[ENTRANCE_LIST_CAPACITY]; +// NOTE: There are no symbols in |mapper2.exe| for the range between |wmGenData| +// and |wmMsgFile| implying everything in between are fields of the large +// struct. +// // 0x672E00 -static int _wmGenData; - -// 0x672E04 -static int _Meet_Frank_Horrigan; - -// Current_town. -// -// 0x672E08 -static int _WorldMapCurrArea; - -// Current town x. -// -// 0x672E0C -static int _world_xpos; - -// Current town y. -// -// 0x672E10 -static int _world_ypos; - -// 0x672E14 -static SubtileInfo* _world_subtile; - -// 0x672E18 -static int dword_672E18; - -// 0x672E1C -static bool gWorldmapIsTravelling; - -// 0x672E20 -static int gWorldmapTravelDestX; - -// 0x672E24 -static int gWorldmapTravelDestY; - -// 0x672E28 -static int dword_672E28; - -// 0x672E2C -static int dword_672E2C; - -// 0x672E30 -static int dword_672E30; - -// 0x672E34 -static int dword_672E34; - -// 0x672E38 -static int _x_line_inc; - -// 0x672E3C -static int dword_672E3C; - -// 0x672E40 -static int _y_line_inc; - -// 0x672E44 -static int dword_672E44; - -// 0x672E48 -static int _wmEncounterIconShow; - -// 0x672E4C -static int _EncounterMapID; - -// 0x672E50 -static int dword_672E50; - -// 0x672E54 -static int dword_672E54; - -// 0x672E58 -static int _wmRndCursorFid; - -// 0x672E5C -static int _old_world_xpos; - -// 0x672E60 -static int _old_world_ypos; - -// 0x672E64 -static bool gWorldmapIsInCar; - -// 0x672E68 -static int _carCurrentArea; - -// 0x672E6C -static int gWorldmapCarFuel; - -// 0x672E70 -static CacheEntry* gWorldmapCarFrmHandle; - -// 0x672E74 -static Art* gWorldmapCarFrm; - -// 0x672E78 -static int gWorldmapCarFrmWidth; - -// 0x672E7C -static int gWorldmapCarFrmHeight; - -// 0x672E80 -static int gWorldmapCarFrmCurrentFrame; - -// 0x672E84 -static CacheEntry* gWorldmapHotspotUpFrmHandle; - -// 0x672E88 -static unsigned char* gWorldmapHotspotUpFrmData; - -// 0x672E8C -static CacheEntry* gWorldmapHotspotDownFrmHandle; - -// 0x672E90 -static unsigned char* gWorldmapHotspotDownFrmData; - -// 0x672E94 -static int gWorldmapHotspotUpFrmWidth; - -// 0x672E98 -static int gWorldmapHotspotUpFrmHeight; - -// 0x672E9C -static CacheEntry* gWorldmapDestinationMarkerFrmHandle; - -// 0x672EA0 -static unsigned char* gWorldmapDestinationMarkerFrmData; - -// 0x672EA4 -static int gWorldmapDestinationMarkerFrmWidth; - -// 0x672EA8 -static int gWorldmapDestinationMarkerFrmHeight; - -// 0x672EAC -static CacheEntry* gWorldmapLocationMarkerFrmHandle; - -// 0x672EB0 -static unsigned char* gWorldmapLocationMarkerFrmData; - -// 0x672EB4 -static int gWorldmapLocationMarkerFrmWidth; - -// 0x672EB8 -static int gWorldmapLocationMarkerFrmHeight; - -// 0x672EBC -static CacheEntry* gWorldmapEncounterFrmHandles[WORLD_MAP_ENCOUNTER_FRM_COUNT]; - -// 0x672ECC -static unsigned char* gWorldmapEncounterFrmData[WORLD_MAP_ENCOUNTER_FRM_COUNT]; - -// 0x672EDC -static int gWorldmapEncounterFrmWidths[WORLD_MAP_ENCOUNTER_FRM_COUNT]; - -// 0x672EEC -static int gWorldmapEncounterFrmHeights[WORLD_MAP_ENCOUNTER_FRM_COUNT]; - -// 0x672EFC -static int _wmViewportRightScrlLimit; - -// 0x672F00 -static int _wmViewportBottomtScrlLimit; - -// 0x672F04 -static CacheEntry* gWorldmapTownTabsUnderlayFrmHandle; - -// 0x672F08 -static int gWorldmapTownTabsUnderlayFrmWidth; - -// 0x672F0C -static int gWorldmapTownTabsUnderlayFrmHeight; - -// 0x672F10 -static int _LastTabsYOffset; - -// 0x672F14 -static unsigned char* gWorldmapTownTabsUnderlayFrmData; - -// 0x672F18 -static CacheEntry* gWorldmapTownTabsEdgeFrmHandle; - -// 0x672F1C -static unsigned char* gWorldmapTownTabsEdgeFrmData; - -// 0x672F20 -static CacheEntry* gWorldmapDialFrmHandle; - -// 0x672F24 -static int gWorldmapDialFrmWidth; - -// 0x672F28 -static int gWorldmapDialFrmHeight; - -// 0x672F2C -static int gWorldmapDialFrmCurrentFrame; - -// 0x672F30 -static Art* gWorldmapDialFrm; - -// 0x672F34 -static CacheEntry* gWorldmapCarOverlayFrmHandle; - -// 0x672F38 -static int gWorldmapCarOverlayFrmWidth; - -// 0x672F3C -static int gWorldmapCarOverlayFrmHeight; - -// 0x672F40 -static unsigned char* gWorldmapCarOverlayFrmData; - -// 0x672F44 -static CacheEntry* gWorldmapGlobeOverlayFrmHandle; - -// 0x672F48 -static int gWorldmapGlobeOverlayFrmWidth; - -// 0x672F4C -static int gWorldmapGloveOverlayFrmHeight; - -// 0x672F50 -static unsigned char* gWorldmapGlobeOverlayFrmData; - -// 0x672F54 -static int dword_672F54; - -// 0x672F58 -static int _tabsOffset; - -// 0x672F5C -static CacheEntry* gWorldmapLittleRedButtonUpFrmHandle; - -// 0x672F60 -static CacheEntry* gWorldmapLittleRedButtonDownFrmHandle; - -// 0x672F64 -static unsigned char* gWorldmapLittleRedButtonUpFrmData; - -// 0x672F68 -static unsigned char* gWorldmapLittleRedButtonDownFrmData; - -// 0x672F6C -static CacheEntry* gWorldmapTownListScrollUpFrmHandle[WORLDMAP_ARROW_FRM_COUNT]; - -// 0x672F74 -static int gWorldmapTownListScrollUpFrmWidth; - -// 0x672F78 -static int gWorldmapTownListScrollUpFrmHeight; - -// 0x672F7C -static unsigned char* gWorldmapTownListScrollUpFrmData[WORLDMAP_ARROW_FRM_COUNT]; - -// 0x672F84 -static CacheEntry* gWorldmapTownListScrollDownFrmHandle[WORLDMAP_ARROW_FRM_COUNT]; - -// 0x672F8C -static int gWorldmapTownListScrollDownFrmWidth; - -// 0x672F90 -static int gWorldmapTownListScrollDownFrmHeight; - -// 0x672F94 -static unsigned char* gWorldmapTownListScrollDownFrmData[WORLDMAP_ARROW_FRM_COUNT]; - -// 0x672F9C -static CacheEntry* gWorldmapMonthsFrmHandle; - -// 0x672FA0 -static Art* gWorldmapMonthsFrm; - -// 0x672FA4 -static CacheEntry* gWorldmapNumbersFrmHandle; - -// 0x672FA8 -static Art* gWorldmapNumbersFrm; - -// 0x672FAC -static int _fontnum; +static WmGenData wmGenData; // worldmap.msg // // 0x672FB0 -static MessageList gWorldmapMessageList; +static MessageList wmMsgFile; // 0x672FB8 -static int _wmFreqValues[6]; +static int wmFreqValues[6]; // 0x672FD0 -static int _wmRndOriginalCenterTile; +static int wmRndOriginalCenterTile; // worldmap.txt // // 0x672FD4 -static Config* gWorldmapConfig; +static Config* pConfigCfg; // 0x672FD8 -static int _wmTownMapSubButtonIds[7]; +static int wmTownMapSubButtonIds[7]; // 0x672FF4 -static ENC_BASE_TYPE* _wmEncBaseTypeList; +static ENC_BASE_TYPE* wmEncBaseTypeList; // 0x672FF8 -static CitySizeDescription gCitySizeDescriptions[CITY_SIZE_COUNT]; +static CitySizeDescription wmSphereData[CITY_SIZE_COUNT]; // 0x673034 -static EncounterTable* gEncounterTables; +static EncounterTable* wmEncounterTableList; // Number of enc_base_types. // // 0x673038 -static int _wmMaxEncBaseTypes; +static int wmMaxEncBaseTypes; // 0x67303C -static int gEncounterTablesLength; +static int wmMaxEncounterInfoTables; static bool gTownMapHotkeysFix; static double gGameTimeIncRemainder = 0.0; -static void wmSetFlags(int* flagsPtr, int flag, int value); -static int _wmGenDataInit(); -static int _wmGenDataReset(); -static int _wmWorldMapSaveTempData(); -static int _wmWorldMapLoadTempData(); -static int worldmapConfigInit(); -static int worldmapConfigLoadEncounterTable(Config* config, char* lookup_name, char* section); -static int worldmapConfigLoadEncounterEntry(EncounterEntry* entry, char* str); -static int _wmParseEncounterSubEncStr(EncounterEntry* entry, char** str_ptr); -static int _wmParseFindSubEncTypeMatch(char* str, int* out_value); -static int _wmFindEncBaseTypeMatch(char* str, int* out_value); -static int _wmReadEncBaseType(char* str, int* out_value); -static int _wmParseEncBaseSubTypeStr(ENC_BASE_TYPE_38* ptr, char** str_ptr); -static int _wmEncBaseTypeSlotInit(ENC_BASE_TYPE* entry); -static int _wmEncBaseSubTypeSlotInit(ENC_BASE_TYPE_38* entry); -static int _wmEncounterSubEncSlotInit(ENCOUNTER_ENTRY_ENC* entry); -static int worldmapEncounterTableEntryInit(EncounterEntry* entry); -static int worldmapEncounterTableInit(EncounterTable* encounterTable); -static int worldmapTileInfoInit(TileInfo* tile); -static int worldmapTerrainInfoInit(Terrain* terrain); -static int worldmapConfigInitEncounterCondition(EncounterCondition* condition); -static int _wmParseTerrainTypes(Config* config, char* str); -static int _wmParseTerrainRndMaps(Config* config, Terrain* terrain); -static int worldmapConfigLoadSubtile(TileInfo* tile, int x, int y, char* str); -static int worldmapFindEncounterTableByLookupName(char* str, int* out_value); -static int worldmapFindTerrainByLookupName(char* str, int* out_value); -static int _wmParseEncounterItemType(char** str_ptr, ENC_BASE_TYPE_38_48* a2, int* a3, const char* delim); -static int _wmParseItemType(char* str, ENC_BASE_TYPE_38_48* ptr); -static int worldmapConfigParseCondition(char** stringPtr, const char* a2, EncounterCondition* condition); -static int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typePtr, int* operatorPtr, int* paramPtr, int* valuePtr); -static int worldmapConfigParseEncounterConditionalOperator(char** str_ptr, int* out_op); -static int worldmapCityInfoInit(CityInfo* area); -static int cityInit(); -static int worldmapFindMapByLookupName(char* str, int* out_value); -static int worldmapCityEntranceInfoInit(EntranceInfo* entrance); -static int worldmapMapInfoInit(MapInfo* map); -static int _wmMapInit(); -static int worldmapRandomStartingPointInit(MapStartPointInfo* rsp); -static int _wmMatchEntranceFromMap(int cityIndex, int mapIndex, int* entranceIndexPtr); -static int _wmMatchEntranceElevFromMap(int cityIndex, int map, int elevation, int* entranceIndexPtr); -static int _wmMatchAreaFromMap(int a1, int* out_a2); -static int _wmWorldMapFunc(int a1); -static int _wmInterfaceCenterOnParty(); -static void wmCheckGameEvents(); -static int _wmRndEncounterOccurred(); -static int _wmPartyFindCurSubTile(); -static int _wmFindCurSubTileFromPos(int x, int y, SubtileInfo** subtile); -static int _wmFindCurTileFromPos(int x, int y, TileInfo** tile); -static int _wmRndEncounterPick(); -static int worldmapSetupCritters(int type_idx, Object** out_critter, int a3); -static int _wmSetupRndNextTileNumInit(ENC_BASE_TYPE* a1); -static int _wmSetupRndNextTileNum(ENC_BASE_TYPE* a1, ENC_BASE_TYPE_38* a2, int* out_tile_num); -static bool _wmEvalConditional(EncounterCondition* a1, int* a2); -static bool _wmEvalSubConditional(int a1, int a2, int a3); -static bool _wmGameTimeIncrement(int ticksToAdd); -static int _wmGrabTileWalkMask(int tile_index); -static bool _wmWorldPosInvalid(int a1, int a2); -static void _wmPartyInitWalking(int x, int y); -static void worldmapPerformTravel(); -static void _wmInterfaceScrollTabsStart(int a1); -static void _wmInterfaceScrollTabsStop(); -static void wmInterfaceScrollTabsUpdate(); -static int worldmapWindowInit(); -static int worldmapWindowFree(); -static int wmInterfaceScroll(int dx, int dy, bool* successPtr); -static int worldmapWindowScroll(int a1, int a2, int a3, int a4, bool* a5, bool a6); -static void worldmapWindowHandleMouseScrolling(); -static int wmMarkSubTileOffsetVisited(int tile, int subtileX, int subtileY, int offsetX, int offsetY); -static int wmMarkSubTileOffsetKnown(int tile, int subtileX, int subtileY, int offsetX, int offsetY); -static int wmMarkSubTileOffsetVisitedFunc(int tile, int subtileX, int subtileY, int offsetX, int offsetY, int subtileState); -static void _wmMarkSubTileRadiusVisited(int x, int y); -static int _wmTileGrabArt(int tile_index); -static int worldmapWindowRefresh(); -static void worldmapWindowRenderDate(bool shouldRefreshWindow); -static int _wmMatchWorldPosToArea(int a1, int a2, int* a3); -static int worldmapWindowRenderCity(CityInfo* cityInfo, CitySizeDescription* citySizeInfo, unsigned char* buffer, int x, int y); -static void worldmapWindowDimRect(unsigned char* dest, int width, int height, int pitch); -static int worldmapWindowDimSubtile(TileInfo* tileInfo, int a2, int a3, int a4, int a5, int a6); -static int _wmDrawCursorStopped(); -static bool _wmCursorIsVisible(); -static int wmGetAreaName(CityInfo* city, char* name); -static int wmAreaMarkVisited(int cityIndex); -static void _wmMarkAllSubTiles(int a1); -static int worldmapCityMapViewSelect(int* mapIndexPtr); -static int worldmapCityMapViewInit(); -static int worldmapCityMapViewRefresh(); -static int worldmapCityMapViewFree(); -static int carConsumeFuel(int a1); -static int worldmapWindowRenderChrome(bool shouldRefreshWindow); -static void worldmapWindowRenderCarFuelBar(); -static int worldmapRenderQuickDestinations(); -static int _wmMakeTabsLabelList(int** out_cities, int* out_len); -static int worldmapCompareCitiesByName(const void* a1, const void* a2); -static int wmFreeTabsLabelList(int** quickDestinationsListPtr, int* quickDestinationsLengthPtr); -static void worldmapWindowRenderDial(bool shouldRefreshWindow); -static void wmInterfaceDialSyncTime(bool shouldRefreshWindow); -static int _wmAreaFindFirstValidMap(int* out_a1); - static inline bool cityIsValid(int city) { - return city >= 0 && city < gCitiesLength; + return city >= 0 && city < wmMaxAreaNum; } // 0x4BC890 @@ -1021,36 +872,35 @@ static void wmSetFlags(int* flagsPtr, int flag, int value) } } -// wmWorldMap_init // 0x4BC89C -int worldmapInit() +int wmWorldMap_init() { char path[COMPAT_MAX_PATH]; - if (_wmGenDataInit() == -1) { + if (wmGenDataInit() == -1) { return -1; } - if (!messageListInit(&gWorldmapMessageList)) { + if (!messageListInit(&wmMsgFile)) { return -1; } sprintf(path, "%s%s", asc_5186C8, "worldmap.msg"); - if (!messageListLoad(&gWorldmapMessageList, path)) { + if (!messageListLoad(&wmMsgFile, path)) { return -1; } - if (worldmapConfigInit() == -1) { + if (wmConfigInit() == -1) { return -1; } - _wmViewportRightScrlLimit = WM_TILE_WIDTH * gWorldmapGridWidth - WM_VIEW_WIDTH; - _wmViewportBottomtScrlLimit = WM_TILE_HEIGHT * (gWorldmapTilesLength / gWorldmapGridWidth) - WM_VIEW_HEIGHT; - _circleBlendTable = _getColorBlendTable(_colorTable[992]); + wmGenData.viewportMaxX = WM_TILE_WIDTH * wmNumHorizontalTiles - WM_VIEW_WIDTH; + wmGenData.viewportMaxY = WM_TILE_HEIGHT * (wmMaxTileNum / wmNumHorizontalTiles) - WM_VIEW_HEIGHT; + circleBlendTable = _getColorBlendTable(_colorTable[992]); - _wmMarkSubTileRadiusVisited(_world_xpos, _world_ypos); - _wmWorldMapSaveTempData(); + wmMarkSubTileRadiusVisited(wmGenData.worldPosX, wmGenData.worldPosY); + wmWorldMapSaveTempData(); // SFALL gTownMapHotkeysFix = true; @@ -1060,264 +910,264 @@ int worldmapInit() } // 0x4BC984 -int _wmGenDataInit() +static int wmGenDataInit() { - _Meet_Frank_Horrigan = 0; - _WorldMapCurrArea = -1; - _world_xpos = 173; - _world_ypos = 122; - _world_subtile = 0; - dword_672E18 = 0; - gWorldmapIsTravelling = false; - gWorldmapTravelDestX = -1; - gWorldmapTravelDestY = -1; - dword_672E28 = 0; - dword_672E2C = 0; - dword_672E30 = 0; - dword_672E34 = 0; - _x_line_inc = 0; - _y_line_inc = 0; - dword_672E44 = 0; - _wmEncounterIconShow = 0; - _EncounterMapID = -1; - dword_672E50 = -1; - dword_672E54 = -1; - _wmRndCursorFid = -1; - _old_world_xpos = 0; - _old_world_ypos = 0; - gWorldmapIsInCar = false; - _carCurrentArea = -1; - gWorldmapCarFuel = CAR_FUEL_MAX; - gWorldmapCarFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapCarFrmWidth = 0; - gWorldmapCarFrmHeight = 0; - gWorldmapCarFrmCurrentFrame = 0; - gWorldmapHotspotUpFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapHotspotUpFrmData = NULL; - gWorldmapHotspotDownFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapHotspotDownFrmData = NULL; - gWorldmapHotspotUpFrmWidth = 0; - gWorldmapHotspotUpFrmHeight = 0; - gWorldmapDestinationMarkerFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapDestinationMarkerFrmData = NULL; - gWorldmapDestinationMarkerFrmWidth = 0; - gWorldmapDestinationMarkerFrmHeight = 0; - gWorldmapLocationMarkerFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapLocationMarkerFrmData = NULL; - gWorldmapLocationMarkerFrmWidth = 0; - _wmGenData = 0; - dword_672E3C = 0; - gWorldmapLocationMarkerFrmHeight = 0; - gWorldmapCarFrm = NULL; + wmGenData.didMeetFrankHorrigan = false; + wmGenData.currentAreaId = -1; + wmGenData.worldPosX = 173; + wmGenData.worldPosY = 122; + wmGenData.currentSubtile = NULL; + wmGenData.dword_672E18 = 0; + wmGenData.isWalking = false; + wmGenData.walkDestinationX = -1; + wmGenData.walkDestinationY = -1; + wmGenData.walkDistance = 0; + wmGenData.walkLineDelta = 0; + wmGenData.walkLineDeltaMainAxisStep = 0; + wmGenData.walkLineDeltaCrossAxisStep = 0; + wmGenData.walkWorldPosMainAxisStepX = 0; + wmGenData.walkWorldPosMainAxisStepY = 0; + wmGenData.walkWorldPosCrossAxisStepY = 0; + wmGenData.encounterIconIsVisible = 0; + wmGenData.encounterMapId = -1; + wmGenData.encounterTableId = -1; + wmGenData.encounterEntryId = -1; + wmGenData.encounterCursorId = -1; + wmGenData.oldWorldPosX = 0; + wmGenData.oldWorldPosY = 0; + wmGenData.isInCar = false; + wmGenData.currentCarAreaId = -1; + wmGenData.carFuel = CAR_FUEL_MAX; + wmGenData.carImageFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.carImageFrmWidth = 0; + wmGenData.carImageFrmHeight = 0; + wmGenData.carImageCurrentFrameIndex = 0; + wmGenData.hotspotNormalFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.hotspotNormalFrmData = NULL; + wmGenData.hotspotPressedFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.hotspotPressedFrmData = NULL; + wmGenData.hotspotFrmWidth = 0; + wmGenData.hotspotFrmHeight = 0; + wmGenData.destinationMarkerFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.destinationMarkerFrmData = NULL; + wmGenData.destinationMarkerFrmWidth = 0; + wmGenData.destinationMarkerFrmHeight = 0; + wmGenData.locationMarkerFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.locationMarkerFrmData = NULL; + wmGenData.locationMarkerFrmWidth = 0; + wmGenData.mousePressed = false; + wmGenData.walkWorldPosCrossAxisStepX = 0; + wmGenData.locationMarkerFrmHeight = 0; + wmGenData.carImageFrm = NULL; for (int index = 0; index < WORLD_MAP_ENCOUNTER_FRM_COUNT; index++) { - gWorldmapEncounterFrmHandles[index] = INVALID_CACHE_ENTRY; - gWorldmapEncounterFrmData[index] = NULL; - gWorldmapEncounterFrmWidths[index] = 0; - gWorldmapEncounterFrmHeights[index] = 0; + wmGenData.encounterCursorFrmHandle[index] = INVALID_CACHE_ENTRY; + wmGenData.encounterCursorFrmData[index] = NULL; + wmGenData.encounterCursorFrmWidths[index] = 0; + wmGenData.encounterCursorFrmHeights[index] = 0; } - _wmViewportBottomtScrlLimit = 0; - gWorldmapTownTabsUnderlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapTownTabsUnderlayFrmData = NULL; - gWorldmapTownTabsUnderlayFrmWidth = 0; - gWorldmapTownTabsUnderlayFrmHeight = 0; - _LastTabsYOffset = 0; - gWorldmapTownTabsEdgeFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapTownTabsEdgeFrmData = 0; - gWorldmapDialFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapDialFrm = NULL; - gWorldmapDialFrmWidth = 0; - gWorldmapDialFrmHeight = 0; - gWorldmapDialFrmCurrentFrame = 0; - gWorldmapCarOverlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapCarOverlayFrmData = NULL; - gWorldmapCarOverlayFrmWidth = 0; - gWorldmapCarOverlayFrmHeight = 0; - gWorldmapGlobeOverlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapGlobeOverlayFrmData = NULL; - gWorldmapGlobeOverlayFrmWidth = 0; - gWorldmapGloveOverlayFrmHeight = 0; - dword_672F54 = 0; - _tabsOffset = 0; - gWorldmapLittleRedButtonUpFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapLittleRedButtonDownFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapLittleRedButtonUpFrmData = NULL; - gWorldmapLittleRedButtonDownFrmData = NULL; - _wmViewportRightScrlLimit = 0; + wmGenData.viewportMaxY = 0; + wmGenData.tabsBackgroundFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.tabsBackgroundFrmData = NULL; + wmGenData.tabsBackgroundFrmWidth = 0; + wmGenData.tabsBackgroundFrmHeight = 0; + wmGenData.tabsOffsetY = 0; + wmGenData.tabsBorderFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.tabsBorderFrmData = 0; + wmGenData.dialFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.dialFrm = NULL; + wmGenData.dialFrmWidth = 0; + wmGenData.dialFrmHeight = 0; + wmGenData.dialFrmCurrentFrameIndex = 0; + wmGenData.carImageOverlayFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.carImageOverlayFrmData = NULL; + wmGenData.carImageOverlayFrmWidth = 0; + wmGenData.carImageOverlayFrmHeight = 0; + wmGenData.globeOverlayFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.globeOverlayFrmData = NULL; + wmGenData.globeOverlayFrmWidth = 0; + wmGenData.globeOverlayFrmHeight = 0; + wmGenData.oldTabsOffsetY = 0; + wmGenData.tabsScrollingDelta = 0; + wmGenData.littleRedButtonNormalFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.littleRedButtonPressedFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.littleRedButtonNormalFrmData = NULL; + wmGenData.littleRedButtonPressedFrmData = NULL; + wmGenData.viewportMaxX = 0; for (int index = 0; index < WORLDMAP_ARROW_FRM_COUNT; index++) { - gWorldmapTownListScrollDownFrmHandle[index] = INVALID_CACHE_ENTRY; - gWorldmapTownListScrollUpFrmHandle[index] = INVALID_CACHE_ENTRY; - gWorldmapTownListScrollUpFrmData[index] = NULL; - gWorldmapTownListScrollDownFrmData[index] = NULL; + wmGenData.scrollDownButtonFrmHandle[index] = INVALID_CACHE_ENTRY; + wmGenData.scrollUpButtonFrmHandle[index] = INVALID_CACHE_ENTRY; + wmGenData.scrollUpButtonFrmData[index] = NULL; + wmGenData.scrollDownButtonFrmData[index] = NULL; } - gWorldmapTownListScrollUpFrmHeight = 0; - gWorldmapTownListScrollDownFrmWidth = 0; - gWorldmapTownListScrollDownFrmHeight = 0; - gWorldmapMonthsFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapMonthsFrm = NULL; - gWorldmapNumbersFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapNumbersFrm = NULL; - gWorldmapTownListScrollUpFrmWidth = 0; + wmGenData.scrollUpButtonFrmHeight = 0; + wmGenData.scrollDownButtonFrmWidth = 0; + wmGenData.scrollDownButtonFrmHeight = 0; + wmGenData.monthsFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.monthsFrm = NULL; + wmGenData.numbersFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.numbersFrm = NULL; + wmGenData.scrollUpButtonFrmWidth = 0; return 0; } // 0x4BCBFC -int _wmGenDataReset() +static int wmGenDataReset() { - _Meet_Frank_Horrigan = 0; - _world_subtile = 0; - dword_672E18 = 0; - gWorldmapIsTravelling = false; - dword_672E28 = 0; - dword_672E2C = 0; - dword_672E30 = 0; - dword_672E34 = 0; - _x_line_inc = 0; - _y_line_inc = 0; - dword_672E44 = 0; - _wmEncounterIconShow = 0; - _wmGenData = 0; - _WorldMapCurrArea = -1; - _world_xpos = 173; - _world_ypos = 122; - gWorldmapTravelDestX = -1; - gWorldmapTravelDestY = -1; - _EncounterMapID = -1; - dword_672E50 = -1; - dword_672E54 = -1; - _wmRndCursorFid = -1; - _carCurrentArea = -1; - gWorldmapCarFuel = CAR_FUEL_MAX; - gWorldmapCarFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapTownTabsUnderlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapTownTabsEdgeFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapDialFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapCarOverlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapGlobeOverlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapLittleRedButtonUpFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapLittleRedButtonDownFrmHandle = INVALID_CACHE_ENTRY; - dword_672E3C = 0; - _old_world_xpos = 0; - _old_world_ypos = 0; - gWorldmapIsInCar = false; - gWorldmapCarFrmWidth = 0; - gWorldmapCarFrmHeight = 0; - gWorldmapCarFrmCurrentFrame = 0; - gWorldmapTownTabsUnderlayFrmData = NULL; - gWorldmapTownTabsUnderlayFrmHeight = 0; - _LastTabsYOffset = 0; - gWorldmapTownTabsEdgeFrmData = 0; - gWorldmapDialFrm = NULL; - gWorldmapDialFrmWidth = 0; - gWorldmapDialFrmHeight = 0; - gWorldmapDialFrmCurrentFrame = 0; - gWorldmapCarOverlayFrmData = NULL; - gWorldmapCarOverlayFrmWidth = 0; - gWorldmapCarOverlayFrmHeight = 0; - gWorldmapGlobeOverlayFrmData = NULL; - gWorldmapGlobeOverlayFrmWidth = 0; - gWorldmapGloveOverlayFrmHeight = 0; - dword_672F54 = 0; - _tabsOffset = 0; - gWorldmapLittleRedButtonUpFrmData = NULL; - gWorldmapLittleRedButtonDownFrmData = NULL; - gWorldmapTownTabsUnderlayFrmWidth = 0; - gWorldmapCarFrm = NULL; + wmGenData.didMeetFrankHorrigan = false; + wmGenData.currentSubtile = NULL; + wmGenData.dword_672E18 = 0; + wmGenData.isWalking = false; + wmGenData.walkDistance = 0; + wmGenData.walkLineDelta = 0; + wmGenData.walkLineDeltaMainAxisStep = 0; + wmGenData.walkLineDeltaCrossAxisStep = 0; + wmGenData.walkWorldPosMainAxisStepX = 0; + wmGenData.walkWorldPosMainAxisStepY = 0; + wmGenData.walkWorldPosCrossAxisStepY = 0; + wmGenData.encounterIconIsVisible = 0; + wmGenData.mousePressed = false; + wmGenData.currentAreaId = -1; + wmGenData.worldPosX = 173; + wmGenData.worldPosY = 122; + wmGenData.walkDestinationX = -1; + wmGenData.walkDestinationY = -1; + wmGenData.encounterMapId = -1; + wmGenData.encounterTableId = -1; + wmGenData.encounterEntryId = -1; + wmGenData.encounterCursorId = -1; + wmGenData.currentCarAreaId = -1; + wmGenData.carFuel = CAR_FUEL_MAX; + wmGenData.carImageFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.tabsBackgroundFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.tabsBorderFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.dialFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.carImageOverlayFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.globeOverlayFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.littleRedButtonNormalFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.littleRedButtonPressedFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.walkWorldPosCrossAxisStepX = 0; + wmGenData.oldWorldPosX = 0; + wmGenData.oldWorldPosY = 0; + wmGenData.isInCar = false; + wmGenData.carImageFrmWidth = 0; + wmGenData.carImageFrmHeight = 0; + wmGenData.carImageCurrentFrameIndex = 0; + wmGenData.tabsBackgroundFrmData = NULL; + wmGenData.tabsBackgroundFrmHeight = 0; + wmGenData.tabsOffsetY = 0; + wmGenData.tabsBorderFrmData = 0; + wmGenData.dialFrm = NULL; + wmGenData.dialFrmWidth = 0; + wmGenData.dialFrmHeight = 0; + wmGenData.dialFrmCurrentFrameIndex = 0; + wmGenData.carImageOverlayFrmData = NULL; + wmGenData.carImageOverlayFrmWidth = 0; + wmGenData.carImageOverlayFrmHeight = 0; + wmGenData.globeOverlayFrmData = NULL; + wmGenData.globeOverlayFrmWidth = 0; + wmGenData.globeOverlayFrmHeight = 0; + wmGenData.oldTabsOffsetY = 0; + wmGenData.tabsScrollingDelta = 0; + wmGenData.littleRedButtonNormalFrmData = NULL; + wmGenData.littleRedButtonPressedFrmData = NULL; + wmGenData.tabsBackgroundFrmWidth = 0; + wmGenData.carImageFrm = NULL; for (int index = 0; index < WORLDMAP_ARROW_FRM_COUNT; index++) { - gWorldmapTownListScrollUpFrmData[index] = NULL; - gWorldmapTownListScrollDownFrmHandle[index] = INVALID_CACHE_ENTRY; + wmGenData.scrollUpButtonFrmData[index] = NULL; + wmGenData.scrollDownButtonFrmHandle[index] = INVALID_CACHE_ENTRY; - gWorldmapTownListScrollDownFrmData[index] = NULL; - gWorldmapTownListScrollUpFrmHandle[index] = INVALID_CACHE_ENTRY; + wmGenData.scrollDownButtonFrmData[index] = NULL; + wmGenData.scrollUpButtonFrmHandle[index] = INVALID_CACHE_ENTRY; } - gWorldmapMonthsFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapNumbersFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapTownListScrollUpFrmWidth = 0; - gWorldmapTownListScrollUpFrmHeight = 0; - gWorldmapTownListScrollDownFrmWidth = 0; - gWorldmapTownListScrollDownFrmHeight = 0; - gWorldmapMonthsFrm = NULL; - gWorldmapNumbersFrm = NULL; + wmGenData.monthsFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.numbersFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.scrollUpButtonFrmWidth = 0; + wmGenData.scrollUpButtonFrmHeight = 0; + wmGenData.scrollDownButtonFrmWidth = 0; + wmGenData.scrollDownButtonFrmHeight = 0; + wmGenData.monthsFrm = NULL; + wmGenData.numbersFrm = NULL; - _wmMarkSubTileRadiusVisited(_world_xpos, _world_ypos); + wmMarkSubTileRadiusVisited(wmGenData.worldPosX, wmGenData.worldPosY); return 0; } // 0x4BCE00 -void worldmapExit() +void wmWorldMap_exit() { - if (gTerrains != NULL) { - internal_free(gTerrains); - gTerrains = NULL; + if (wmTerrainTypeList != NULL) { + internal_free(wmTerrainTypeList); + wmTerrainTypeList = NULL; } - if (gWorldmapTiles) { - internal_free(gWorldmapTiles); - gWorldmapTiles = NULL; + if (wmTileInfoList) { + internal_free(wmTileInfoList); + wmTileInfoList = NULL; } - gWorldmapGridWidth = 0; - gWorldmapTilesLength = 0; + wmNumHorizontalTiles = 0; + wmMaxTileNum = 0; - if (gEncounterTables != NULL) { - internal_free(gEncounterTables); - gEncounterTables = NULL; + if (wmEncounterTableList != NULL) { + internal_free(wmEncounterTableList); + wmEncounterTableList = NULL; } - gEncounterTablesLength = 0; + wmMaxEncounterInfoTables = 0; - if (_wmEncBaseTypeList != NULL) { - internal_free(_wmEncBaseTypeList); - _wmEncBaseTypeList = NULL; + if (wmEncBaseTypeList != NULL) { + internal_free(wmEncBaseTypeList); + wmEncBaseTypeList = NULL; } - _wmMaxEncBaseTypes = 0; + wmMaxEncBaseTypes = 0; - if (gCities != NULL) { - internal_free(gCities); - gCities = NULL; + if (wmAreaInfoList != NULL) { + internal_free(wmAreaInfoList); + wmAreaInfoList = NULL; } - gCitiesLength = 0; + wmMaxAreaNum = 0; - if (gMaps != NULL) { - internal_free(gMaps); + if (wmMapInfoList != NULL) { + internal_free(wmMapInfoList); } - gMapsLength = 0; + wmMaxMapNum = 0; - if (_circleBlendTable != NULL) { + if (circleBlendTable != NULL) { _freeColorBlendTable(_colorTable[992]); - _circleBlendTable = NULL; + circleBlendTable = NULL; } - messageListFree(&gWorldmapMessageList); + messageListFree(&wmMsgFile); } // 0x4BCEF8 -int worldmapReset() +int wmWorldMap_reset() { - gWorldmapOffsetX = 0; - gWorldmapOffsetY = 0; + wmWorldOffsetX = 0; + wmWorldOffsetY = 0; // CE: Fix Pathfinder perk. gGameTimeIncRemainder = 0.0; - _wmWorldMapLoadTempData(); - _wmMarkAllSubTiles(0); + wmWorldMapLoadTempData(); + wmMarkAllSubTiles(0); - return _wmGenDataReset(); + return wmGenDataReset(); } // 0x4BCF28 -int worldmapSave(File* stream) +int wmWorldMap_save(File* stream) { int i; int j; @@ -1325,38 +1175,38 @@ int worldmapSave(File* stream) EncounterTable* encounter_table; EncounterEntry* encounter_entry; - if (fileWriteInt32(stream, _Meet_Frank_Horrigan) == -1) return -1; - if (fileWriteInt32(stream, _WorldMapCurrArea) == -1) return -1; - if (fileWriteInt32(stream, _world_xpos) == -1) return -1; - if (fileWriteInt32(stream, _world_ypos) == -1) return -1; - if (fileWriteInt32(stream, _wmEncounterIconShow) == -1) return -1; - if (fileWriteInt32(stream, _EncounterMapID) == -1) return -1; - if (fileWriteInt32(stream, dword_672E50) == -1) return -1; - if (fileWriteInt32(stream, dword_672E54) == -1) return -1; - if (fileWriteBool(stream, gWorldmapIsInCar) == -1) return -1; - if (fileWriteInt32(stream, _carCurrentArea) == -1) return -1; - if (fileWriteInt32(stream, gWorldmapCarFuel) == -1) return -1; - if (fileWriteInt32(stream, gCitiesLength) == -1) return -1; + if (fileWriteBool(stream, wmGenData.didMeetFrankHorrigan) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.currentAreaId) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.worldPosX) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.worldPosY) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.encounterIconIsVisible) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.encounterMapId) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.encounterTableId) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.encounterEntryId) == -1) return -1; + if (fileWriteBool(stream, wmGenData.isInCar) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.currentCarAreaId) == -1) return -1; + if (fileWriteInt32(stream, wmGenData.carFuel) == -1) return -1; + if (fileWriteInt32(stream, wmMaxAreaNum) == -1) return -1; - for (int cityIndex = 0; cityIndex < gCitiesLength; cityIndex++) { - CityInfo* cityInfo = &(gCities[cityIndex]); + for (int areaIdx = 0; areaIdx < wmMaxAreaNum; areaIdx++) { + CityInfo* cityInfo = &(wmAreaInfoList[areaIdx]); if (fileWriteInt32(stream, cityInfo->x) == -1) return -1; if (fileWriteInt32(stream, cityInfo->y) == -1) return -1; if (fileWriteInt32(stream, cityInfo->state) == -1) return -1; - if (fileWriteInt32(stream, cityInfo->field_40) == -1) return -1; + if (fileWriteInt32(stream, cityInfo->visitedState) == -1) return -1; if (fileWriteInt32(stream, cityInfo->entrancesLength) == -1) return -1; - for (int entranceIndex = 0; entranceIndex < cityInfo->entrancesLength; entranceIndex++) { - EntranceInfo* entrance = &(cityInfo->entrances[entranceIndex]); + for (int entranceIdx = 0; entranceIdx < cityInfo->entrancesLength; entranceIdx++) { + EntranceInfo* entrance = &(cityInfo->entrances[entranceIdx]); if (fileWriteInt32(stream, entrance->state) == -1) return -1; } } - if (fileWriteInt32(stream, gWorldmapTilesLength) == -1) return -1; - if (fileWriteInt32(stream, gWorldmapGridWidth) == -1) return -1; + if (fileWriteInt32(stream, wmMaxTileNum) == -1) return -1; + if (fileWriteInt32(stream, wmNumHorizontalTiles) == -1) return -1; - for (int tileIndex = 0; tileIndex < gWorldmapTilesLength; tileIndex++) { - TileInfo* tileInfo = &(gWorldmapTiles[tileIndex]); + for (int tileIndex = 0; tileIndex < wmMaxTileNum; tileIndex++) { + TileInfo* tileInfo = &(wmTileInfoList[tileIndex]); for (int column = 0; column < SUBTILE_GRID_HEIGHT; column++) { for (int row = 0; row < SUBTILE_GRID_WIDTH; row++) { @@ -1368,8 +1218,8 @@ int worldmapSave(File* stream) } k = 0; - for (i = 0; i < gEncounterTablesLength; i++) { - encounter_table = &(gEncounterTables[i]); + for (i = 0; i < wmMaxEncounterInfoTables; i++) { + encounter_table = &(wmEncounterTableList[i]); for (j = 0; j < encounter_table->entriesLength; j++) { encounter_entry = &(encounter_table->entries[j]); @@ -1382,8 +1232,8 @@ int worldmapSave(File* stream) if (fileWriteInt32(stream, k) == -1) return -1; - for (i = 0; i < gEncounterTablesLength; i++) { - encounter_table = &(gEncounterTables[i]); + for (i = 0; i < wmMaxEncounterInfoTables; i++) { + encounter_table = &(wmEncounterTableList[i]); for (j = 0; j < encounter_table->entriesLength; j++) { encounter_entry = &(encounter_table->entries[j]); @@ -1400,7 +1250,7 @@ int worldmapSave(File* stream) } // 0x4BD28C -int worldmapLoad(File* stream) +int wmWorldMap_load(File* stream) { int i; int j; @@ -1412,34 +1262,34 @@ int worldmapLoad(File* stream) EncounterTable* encounter_table; EncounterEntry* encounter_entry; - if (fileReadInt32(stream, &(_Meet_Frank_Horrigan)) == -1) return -1; - if (fileReadInt32(stream, &(_WorldMapCurrArea)) == -1) return -1; - if (fileReadInt32(stream, &(_world_xpos)) == -1) return -1; - if (fileReadInt32(stream, &(_world_ypos)) == -1) return -1; - if (fileReadInt32(stream, &(_wmEncounterIconShow)) == -1) return -1; - if (fileReadInt32(stream, &(_EncounterMapID)) == -1) return -1; - if (fileReadInt32(stream, &(dword_672E50)) == -1) return -1; - if (fileReadInt32(stream, &(dword_672E54)) == -1) return -1; - if (fileReadBool(stream, &(gWorldmapIsInCar)) == -1) return -1; - if (fileReadInt32(stream, &(_carCurrentArea)) == -1) return -1; - if (fileReadInt32(stream, &(gWorldmapCarFuel)) == -1) return -1; + if (fileReadBool(stream, &(wmGenData.didMeetFrankHorrigan)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.currentAreaId)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.worldPosX)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.worldPosY)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.encounterIconIsVisible)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.encounterMapId)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.encounterTableId)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.encounterEntryId)) == -1) return -1; + if (fileReadBool(stream, &(wmGenData.isInCar)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.currentCarAreaId)) == -1) return -1; + if (fileReadInt32(stream, &(wmGenData.carFuel)) == -1) return -1; if (fileReadInt32(stream, &(cities_count)) == -1) return -1; - for (int cityIndex = 0; cityIndex < cities_count; cityIndex++) { - CityInfo* city = &(gCities[cityIndex]); + for (int areaIdx = 0; areaIdx < cities_count; areaIdx++) { + CityInfo* city = &(wmAreaInfoList[areaIdx]); if (fileReadInt32(stream, &(city->x)) == -1) return -1; if (fileReadInt32(stream, &(city->y)) == -1) return -1; if (fileReadInt32(stream, &(city->state)) == -1) return -1; - if (fileReadInt32(stream, &(city->field_40)) == -1) return -1; + if (fileReadInt32(stream, &(city->visitedState)) == -1) return -1; int entranceCount; if (fileReadInt32(stream, &(entranceCount)) == -1) { return -1; } - for (int entranceIndex = 0; entranceIndex < entranceCount; entranceIndex++) { - EntranceInfo* entrance = &(city->entrances[entranceIndex]); + for (int entranceIdx = 0; entranceIdx < entranceCount; entranceIdx++) { + EntranceInfo* entrance = &(city->entrances[entranceIdx]); if (fileReadInt32(stream, &(entrance->state)) == -1) { return -1; @@ -1451,7 +1301,7 @@ int worldmapLoad(File* stream) if (fileReadInt32(stream, &(v38)) == -1) return -1; for (int tileIndex = 0; tileIndex < v39; tileIndex++) { - TileInfo* tile = &(gWorldmapTiles[tileIndex]); + TileInfo* tile = &(wmTileInfoList[tileIndex]); for (int column = 0; column < SUBTILE_GRID_HEIGHT; column++) { for (int row = 0; row < SUBTILE_GRID_WIDTH; row++) { @@ -1466,7 +1316,7 @@ int worldmapLoad(File* stream) for (i = 0; i < v35; i++) { if (fileReadInt32(stream, &(j)) == -1) return -1; - encounter_table = &(gEncounterTables[j]); + encounter_table = &(wmEncounterTableList[j]); if (fileReadInt32(stream, &(k)) == -1) return -1; encounter_entry = &(encounter_table->entries[k]); @@ -1474,13 +1324,13 @@ int worldmapLoad(File* stream) if (fileReadInt32(stream, &(encounter_entry->counter)) == -1) return -1; } - _wmInterfaceCenterOnParty(); + wmInterfaceCenterOnParty(); return 0; } // 0x4BD678 -int _wmWorldMapSaveTempData() +static int wmWorldMapSaveTempData() { File* stream = fileOpen("worldmap.dat", "wb"); if (stream == NULL) { @@ -1488,7 +1338,7 @@ int _wmWorldMapSaveTempData() } int rc = 0; - if (worldmapSave(stream) == -1) { + if (wmWorldMap_save(stream) == -1) { rc = -1; } @@ -1498,7 +1348,7 @@ int _wmWorldMapSaveTempData() } // 0x4BD6B4 -int _wmWorldMapLoadTempData() +static int wmWorldMapLoadTempData() { File* stream = fileOpen("worldmap.dat", "rb"); if (stream == NULL) { @@ -1506,7 +1356,7 @@ int _wmWorldMapLoadTempData() } int rc = 0; - if (worldmapLoad(stream) == -1) { + if (wmWorldMap_load(stream) == -1) { rc = -1; } @@ -1516,9 +1366,9 @@ int _wmWorldMapLoadTempData() } // 0x4BD6F0 -int worldmapConfigInit() +static int wmConfigInit() { - if (cityInit() == -1) { + if (wmAreaInit() == -1) { return -1; } @@ -1529,14 +1379,14 @@ int worldmapConfigInit() if (configRead(&config, "data\\worldmap.txt", true)) { for (int index = 0; index < ENCOUNTER_FREQUENCY_TYPE_COUNT; index++) { - if (!configGetInt(&config, "data", gEncounterFrequencyTypeKeys[index], &(_wmFreqValues[index]))) { + if (!configGetInt(&config, "data", wmFreqStrs[index], &(wmFreqValues[index]))) { break; } } char* terrainTypes; configGetString(&config, "data", "terrain_types", &terrainTypes); - _wmParseTerrainTypes(&config, terrainTypes); + wmParseTerrainTypes(&config, terrainTypes); for (int index = 0;; index++) { char section[40]; @@ -1547,12 +1397,12 @@ int worldmapConfigInit() break; } - if (worldmapConfigLoadEncounterTable(&config, lookupName, section) == -1) { + if (wmReadEncounterType(&config, lookupName, section) == -1) { return -1; } } - if (!configGetInt(&config, "Tile Data", "num_horizontal_tiles", &gWorldmapGridWidth)) { + if (!configGetInt(&config, "Tile Data", "num_horizontal_tiles", &wmNumHorizontalTiles)) { showMesageBox("\nwmConfigInit::Error loading tile data!"); return -1; } @@ -1566,20 +1416,20 @@ int worldmapConfigInit() break; } - gWorldmapTilesLength++; + wmMaxTileNum++; - TileInfo* worldmapTiles = (TileInfo*)internal_realloc(gWorldmapTiles, sizeof(*gWorldmapTiles) * gWorldmapTilesLength); + TileInfo* worldmapTiles = (TileInfo*)internal_realloc(wmTileInfoList, sizeof(*wmTileInfoList) * wmMaxTileNum); if (worldmapTiles == NULL) { showMesageBox("\nwmConfigInit::Error loading tiles!"); exit(1); } - gWorldmapTiles = worldmapTiles; + wmTileInfoList = worldmapTiles; - TileInfo* tile = &(worldmapTiles[gWorldmapTilesLength - 1]); + TileInfo* tile = &(worldmapTiles[wmMaxTileNum - 1]); // NOTE: Uninline. - worldmapTileInfoInit(tile); + wmTileSlotInit(tile); tile->fid = buildFid(OBJ_TYPE_INTERFACE, artIndex, 0, 0, 0); @@ -1604,7 +1454,7 @@ int worldmapConfigInit() exit(1); } - if (worldmapConfigLoadSubtile(tile, row, column, subtileProps) == -1) { + if (wmParseSubTileInfo(tile, row, column, subtileProps) == -1) { showMesageBox("\nwmConfigInit::Error loading tiles!"); exit(1); } @@ -1619,24 +1469,24 @@ int worldmapConfigInit() } // 0x4BD9F0 -int worldmapConfigLoadEncounterTable(Config* config, char* lookupName, char* sectionKey) +static int wmReadEncounterType(Config* config, char* lookupName, char* sectionKey) { - gEncounterTablesLength++; + wmMaxEncounterInfoTables++; - EncounterTable* encounterTables = (EncounterTable*)internal_realloc(gEncounterTables, sizeof(EncounterTable) * gEncounterTablesLength); + EncounterTable* encounterTables = (EncounterTable*)internal_realloc(wmEncounterTableList, sizeof(EncounterTable) * wmMaxEncounterInfoTables); if (encounterTables == NULL) { showMesageBox("\nwmConfigInit::Error loading Encounter Table!"); exit(1); } - gEncounterTables = encounterTables; + wmEncounterTableList = encounterTables; - EncounterTable* encounterTable = &(encounterTables[gEncounterTablesLength - 1]); + EncounterTable* encounterTable = &(encounterTables[wmMaxEncounterInfoTables - 1]); // NOTE: Uninline. - worldmapEncounterTableInit(encounterTable); + wmEncounterTableSlotInit(encounterTable); - encounterTable->field_28 = gEncounterTablesLength - 1; + encounterTable->field_28 = wmMaxEncounterInfoTables - 1; strncpy(encounterTable->lookupName, lookupName, 40); char* str; @@ -1646,7 +1496,7 @@ int worldmapConfigLoadEncounterTable(Config* config, char* lookupName, char* sec break; } - if (strParseStrFromFunc(&str, &(encounterTable->maps[encounterTable->mapsLength]), worldmapFindMapByLookupName) == -1) { + if (strParseStrFromFunc(&str, &(encounterTable->maps[encounterTable->mapsLength]), wmParseFindMapIdxMatch) == -1) { break; } @@ -1668,9 +1518,9 @@ int worldmapConfigLoadEncounterTable(Config* config, char* lookupName, char* sec exit(1); } - gWorldmapConfig = config; + pConfigCfg = config; - if (worldmapConfigLoadEncounterEntry(&(encounterTable->entries[encounterTable->entriesLength]), str) == -1) { + if (wmParseEncounterTableIndex(&(encounterTable->entries[encounterTable->entriesLength]), str) == -1) { return -1; } @@ -1681,10 +1531,10 @@ int worldmapConfigLoadEncounterTable(Config* config, char* lookupName, char* sec } // 0x4BDB64 -int worldmapConfigLoadEncounterEntry(EncounterEntry* entry, char* string) +static int wmParseEncounterTableIndex(EncounterEntry* entry, char* string) { // NOTE: Uninline. - if (worldmapEncounterTableEntryInit(entry) == -1) { + if (wmEncounterTypeSlotInit(entry) == -1) { return -1; } @@ -1701,11 +1551,11 @@ int worldmapConfigLoadEncounterEntry(EncounterEntry* entry, char* string) char* pch = strstr(string, "map:"); if (pch != NULL) { string = pch + 4; - strParseStrFromFunc(&string, &(entry->map), worldmapFindMapByLookupName); + strParseStrFromFunc(&string, &(entry->map), wmParseFindMapIdxMatch); } } - if (_wmParseEncounterSubEncStr(entry, &string) == -1) { + if (wmParseEncounterSubEncStr(entry, &string) == -1) { break; } @@ -1713,18 +1563,18 @@ int worldmapConfigLoadEncounterEntry(EncounterEntry* entry, char* string) char* pch = strstr(string, "scenery:"); if (pch != NULL) { string = pch + 8; - strParseStrFromList(&string, &(entry->scenery), _wmSceneryStrs, ENCOUNTER_SCENERY_TYPE_COUNT); + strParseStrFromList(&string, &(entry->scenery), wmSceneryStrs, ENCOUNTER_SCENERY_TYPE_COUNT); } } - worldmapConfigParseCondition(&string, "if", &(entry->condition)); + wmParseConditional(&string, "if", &(entry->condition)); } return 0; } // 0x4BDCA8 -int _wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr) +static int wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr) { char* string = *stringPtr; if (compat_strnicmp(string, "enc:", 4) != 0) { @@ -1748,7 +1598,7 @@ int _wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr) ENCOUNTER_ENTRY_ENC* entry = &(encounterEntry->field_54[encounterEntry->field_50]); // NOTE: Uninline. - _wmEncounterSubEncSlotInit(entry); + wmEncounterSubEncSlotInit(entry); if (*string == '(') { string++; @@ -1785,7 +1635,7 @@ int _wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr) char ch = *end; *end = '\0'; - if (strParseStrFromFunc(&string, &(entry->field_8), _wmParseFindSubEncTypeMatch) == -1) { + if (strParseStrFromFunc(&string, &(entry->field_8), wmParseFindSubEncTypeMatch) == -1) { return -1; } @@ -1804,7 +1654,7 @@ int _wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr) *end = '\0'; if (*string != '\0') { - strParseStrFromList(&string, &(entry->situation), _wmEncOpStrs, ENCOUNTER_SITUATION_COUNT); + strParseStrFromList(&string, &(entry->situation), wmEncOpStrs, ENCOUNTER_SITUATION_COUNT); } *end = ch; @@ -1828,7 +1678,7 @@ int _wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr) } // 0x4BDE94 -int _wmParseFindSubEncTypeMatch(char* str, int* valuePtr) +static int wmParseFindSubEncTypeMatch(char* str, int* valuePtr) { *valuePtr = 0; @@ -1837,11 +1687,11 @@ int _wmParseFindSubEncTypeMatch(char* str, int* valuePtr) return 0; } - if (_wmFindEncBaseTypeMatch(str, valuePtr) == 0) { + if (wmFindEncBaseTypeMatch(str, valuePtr) == 0) { return 0; } - if (_wmReadEncBaseType(str, valuePtr) == 0) { + if (wmReadEncBaseType(str, valuePtr) == 0) { return 0; } @@ -1849,10 +1699,10 @@ int _wmParseFindSubEncTypeMatch(char* str, int* valuePtr) } // 0x4BDED8 -int _wmFindEncBaseTypeMatch(char* str, int* valuePtr) +static int wmFindEncBaseTypeMatch(char* str, int* valuePtr) { - for (int index = 0; index < _wmMaxEncBaseTypes; index++) { - if (compat_stricmp(_wmEncBaseTypeList[index].name, str) == 0) { + for (int index = 0; index < wmMaxEncBaseTypes; index++) { + if (compat_stricmp(wmEncBaseTypeList[index].name, str) == 0) { *valuePtr = index; return 0; } @@ -1863,7 +1713,7 @@ int _wmFindEncBaseTypeMatch(char* str, int* valuePtr) } // 0x4BDF34 -int _wmReadEncBaseType(char* name, int* valuePtr) +static int wmReadEncBaseType(char* name, int* valuePtr) { char section[40]; sprintf(section, "Encounter: %s", name); @@ -1872,29 +1722,29 @@ int _wmReadEncBaseType(char* name, int* valuePtr) sprintf(key, "type_00"); char* string; - if (!configGetString(gWorldmapConfig, section, key, &string)) { + if (!configGetString(pConfigCfg, section, key, &string)) { return -1; } - _wmMaxEncBaseTypes++; + wmMaxEncBaseTypes++; - ENC_BASE_TYPE* arr = (ENC_BASE_TYPE*)internal_realloc(_wmEncBaseTypeList, sizeof(*_wmEncBaseTypeList) * _wmMaxEncBaseTypes); + ENC_BASE_TYPE* arr = (ENC_BASE_TYPE*)internal_realloc(wmEncBaseTypeList, sizeof(*wmEncBaseTypeList) * wmMaxEncBaseTypes); if (arr == NULL) { showMesageBox("\nwmConfigInit::Error Reading EncBaseType!"); exit(1); } - _wmEncBaseTypeList = arr; + wmEncBaseTypeList = arr; - ENC_BASE_TYPE* entry = &(arr[_wmMaxEncBaseTypes - 1]); + ENC_BASE_TYPE* entry = &(arr[wmMaxEncBaseTypes - 1]); // NOTE: Uninline. - _wmEncBaseTypeSlotInit(entry); + wmEncBaseTypeSlotInit(entry); strncpy(entry->name, name, 40); while (1) { - if (_wmParseEncBaseSubTypeStr(&(entry->field_38[entry->field_34]), &string) == -1) { + if (wmParseEncBaseSubTypeStr(&(entry->field_38[entry->field_34]), &string) == -1) { return -1; } @@ -1902,9 +1752,9 @@ int _wmReadEncBaseType(char* name, int* valuePtr) sprintf(key, "type_%02d", entry->field_34); - if (!configGetString(gWorldmapConfig, section, key, &string)) { + if (!configGetString(pConfigCfg, section, key, &string)) { int team; - configGetInt(gWorldmapConfig, section, "team_num", &team); + configGetInt(pConfigCfg, section, "team_num", &team); for (int index = 0; index < entry->field_34; index++) { ENC_BASE_TYPE_38* ptr = &(entry->field_38[index]); @@ -1913,13 +1763,13 @@ int _wmReadEncBaseType(char* name, int* valuePtr) } } - if (configGetString(gWorldmapConfig, section, "position", &string)) { - strParseStrFromList(&string, &(entry->position), gEncounterFormationTypeKeys, ENCOUNTER_FORMATION_TYPE_COUNT); + if (configGetString(pConfigCfg, section, "position", &string)) { + strParseStrFromList(&string, &(entry->position), wmFormationStrs, ENCOUNTER_FORMATION_TYPE_COUNT); strParseIntWithKey(&string, "spacing", &(entry->spacing), ":"); strParseIntWithKey(&string, "distance", &(entry->distance), ":"); } - *valuePtr = _wmMaxEncBaseTypes - 1; + *valuePtr = wmMaxEncBaseTypes - 1; return 0; } @@ -1929,12 +1779,12 @@ int _wmReadEncBaseType(char* name, int* valuePtr) } // 0x4BE140 -int _wmParseEncBaseSubTypeStr(ENC_BASE_TYPE_38* ptr, char** stringPtr) +static int wmParseEncBaseSubTypeStr(ENC_BASE_TYPE_38* ptr, char** stringPtr) { char* string = *stringPtr; // NOTE: Uninline. - if (_wmEncBaseSubTypeSlotInit(ptr) == -1) { + if (wmEncBaseSubTypeSlotInit(ptr) == -1) { return -1; } @@ -1960,11 +1810,11 @@ int _wmParseEncBaseSubTypeStr(ENC_BASE_TYPE_38* ptr, char** stringPtr) break; } - _wmParseEncounterItemType(&string, &(ptr->items[ptr->itemsLength]), &(ptr->itemsLength), ":"); + wmParseEncounterItemType(&string, &(ptr->items[ptr->itemsLength]), &(ptr->itemsLength), ":"); } strParseIntWithKey(&string, "script", &(ptr->script), ":"); - worldmapConfigParseCondition(&string, "if", &(ptr->condition)); + wmParseConditional(&string, "if", &(ptr->condition)); return 0; } @@ -1972,7 +1822,7 @@ int _wmParseEncBaseSubTypeStr(ENC_BASE_TYPE_38* ptr, char** stringPtr) // NOTE: Inlined. // // 0x4BE2A0 -int _wmEncBaseTypeSlotInit(ENC_BASE_TYPE* entry) +static int wmEncBaseTypeSlotInit(ENC_BASE_TYPE* entry) { entry->name[0] = '\0'; entry->position = ENCOUNTER_FORMATION_TYPE_SURROUNDING; @@ -1986,7 +1836,7 @@ int _wmEncBaseTypeSlotInit(ENC_BASE_TYPE* entry) // NOTE: Inlined. // // 0x4BE2C4 -int _wmEncBaseSubTypeSlotInit(ENC_BASE_TYPE_38* entry) +static int wmEncBaseSubTypeSlotInit(ENC_BASE_TYPE_38* entry) { entry->field_28 = -1; entry->field_2C = 1; @@ -1999,13 +1849,13 @@ int _wmEncBaseSubTypeSlotInit(ENC_BASE_TYPE_38* entry) entry->script = -1; entry->team = -1; - return worldmapConfigInitEncounterCondition(&(entry->condition)); + return wmConditionalDataInit(&(entry->condition)); } // NOTE: Inlined. // // 0x4BE32C -int _wmEncounterSubEncSlotInit(ENCOUNTER_ENTRY_ENC* entry) +static int wmEncounterSubEncSlotInit(ENCOUNTER_ENTRY_ENC* entry) { entry->minQuantity = 1; entry->maxQuantity = 1; @@ -2018,7 +1868,7 @@ int _wmEncounterSubEncSlotInit(ENCOUNTER_ENTRY_ENC* entry) // NOTE: Inlined. // // 0x4BE34C -int worldmapEncounterTableEntryInit(EncounterEntry* entry) +static int wmEncounterTypeSlotInit(EncounterEntry* entry) { entry->flags = 0; entry->map = -1; @@ -2027,13 +1877,13 @@ int worldmapEncounterTableEntryInit(EncounterEntry* entry) entry->counter = -1; entry->field_50 = 0; - return worldmapConfigInitEncounterCondition(&(entry->condition)); + return wmConditionalDataInit(&(entry->condition)); } // NOTE: Inlined. // // 0x4BE3B8 -int worldmapEncounterTableInit(EncounterTable* encounterTable) +static int wmEncounterTableSlotInit(EncounterTable* encounterTable) { encounterTable->lookupName[0] = '\0'; encounterTable->mapsLength = 0; @@ -2046,7 +1896,7 @@ int worldmapEncounterTableInit(EncounterTable* encounterTable) // NOTE: Inlined. // // 0x4BE3D4 -int worldmapTileInfoInit(TileInfo* tile) +static int wmTileSlotInit(TileInfo* tile) { tile->fid = -1; tile->handle = INVALID_CACHE_ENTRY; @@ -2061,9 +1911,9 @@ int worldmapTileInfoInit(TileInfo* tile) // NOTE: Inlined. // // 0x4BE400 -int worldmapTerrainInfoInit(Terrain* terrain) +static int wmTerrainTypeSlotInit(Terrain* terrain) { - terrain->field_0[0] = '\0'; + terrain->lookupName[0] = '\0'; terrain->difficulty = 0; terrain->mapsLength = 0; @@ -2071,7 +1921,7 @@ int worldmapTerrainInfoInit(Terrain* terrain) } // 0x4BE378 -int worldmapConfigInitEncounterCondition(EncounterCondition* condition) +static int wmConditionalDataInit(EncounterCondition* condition) { condition->entriesLength = 0; @@ -2091,7 +1941,7 @@ int worldmapConfigInitEncounterCondition(EncounterCondition* condition) } // 0x4BE414 -int _wmParseTerrainTypes(Config* config, char* string) +static int wmParseTerrainTypes(Config* config, char* string) { if (*string == '\0') { return -1; @@ -2107,25 +1957,25 @@ int _wmParseTerrainTypes(Config* config, char* string) pch++; } - gTerrainsLength = terrainCount; + wmMaxTerrainTypes = terrainCount; - gTerrains = (Terrain*)internal_malloc(sizeof(*gTerrains) * terrainCount); - if (gTerrains == NULL) { + wmTerrainTypeList = (Terrain*)internal_malloc(sizeof(*wmTerrainTypeList) * terrainCount); + if (wmTerrainTypeList == NULL) { return -1; } - for (int index = 0; index < gTerrainsLength; index++) { - Terrain* terrain = &(gTerrains[index]); + for (int index = 0; index < wmMaxTerrainTypes; index++) { + Terrain* terrain = &(wmTerrainTypeList[index]); // NOTE: Uninline. - worldmapTerrainInfoInit(terrain); + wmTerrainTypeSlotInit(terrain); } compat_strlwr(string); pch = string; - for (int index = 0; index < gTerrainsLength; index++) { - Terrain* terrain = &(gTerrains[index]); + for (int index = 0; index < wmMaxTerrainTypes; index++) { + Terrain* terrain = &(wmTerrainTypeList[index]); pch += strspn(pch, " "); @@ -2137,7 +1987,7 @@ int _wmParseTerrainTypes(Config* config, char* string) char delimeter = pch[delimeterPos]; pch[delimeterPos] = '\0'; - strncpy(terrain->field_0, pch, 40); + strncpy(terrain->lookupName, pch, 40); terrain->difficulty = atoi(pch + delimeterPos + 1); pch[delimeterPos] = delimeter; @@ -2148,18 +1998,18 @@ int _wmParseTerrainTypes(Config* config, char* string) } } - for (int index = 0; index < gTerrainsLength; index++) { - _wmParseTerrainRndMaps(config, &(gTerrains[index])); + for (int index = 0; index < wmMaxTerrainTypes; index++) { + wmParseTerrainRndMaps(config, &(wmTerrainTypeList[index])); } return 0; } // 0x4BE598 -int _wmParseTerrainRndMaps(Config* config, Terrain* terrain) +static int wmParseTerrainRndMaps(Config* config, Terrain* terrain) { char section[40]; - sprintf(section, "Random Maps: %s", terrain->field_0); + sprintf(section, "Random Maps: %s", terrain->lookupName); for (;;) { char key[40]; @@ -2170,7 +2020,7 @@ int _wmParseTerrainRndMaps(Config* config, Terrain* terrain) break; } - if (strParseStrFromFunc(&string, &(terrain->maps[terrain->mapsLength]), worldmapFindMapByLookupName) == -1) { + if (strParseStrFromFunc(&string, &(terrain->maps[terrain->mapsLength]), wmParseFindMapIdxMatch) == -1) { return -1; } @@ -2185,26 +2035,26 @@ int _wmParseTerrainRndMaps(Config* config, Terrain* terrain) } // 0x4BE61C -int worldmapConfigLoadSubtile(TileInfo* tile, int row, int column, char* string) +static int wmParseSubTileInfo(TileInfo* tile, int row, int column, char* string) { SubtileInfo* subtile = &(tile->subtiles[column][row]); subtile->state = SUBTILE_STATE_UNKNOWN; - if (strParseStrFromFunc(&string, &(subtile->terrain), worldmapFindTerrainByLookupName) == -1) { + if (strParseStrFromFunc(&string, &(subtile->terrain), wmParseFindTerrainTypeMatch) == -1) { return -1; } - if (strParseStrFromList(&string, &(subtile->field_4), _wmFillStrs, 9) == -1) { + if (strParseStrFromList(&string, &(subtile->field_4), wmFillStrs, 9) == -1) { return -1; } for (int index = 0; index < DAY_PART_COUNT; index++) { - if (strParseStrFromList(&string, &(subtile->encounterChance[index]), gEncounterFrequencyTypeKeys, ENCOUNTER_FREQUENCY_TYPE_COUNT) == -1) { + if (strParseStrFromList(&string, &(subtile->encounterChance[index]), wmFreqStrs, ENCOUNTER_FREQUENCY_TYPE_COUNT) == -1) { return -1; } } - if (strParseStrFromFunc(&string, &(subtile->encounterType), worldmapFindEncounterTableByLookupName) == -1) { + if (strParseStrFromFunc(&string, &(subtile->encounterType), wmParseFindEncounterTypeMatch) == -1) { return -1; } @@ -2212,10 +2062,10 @@ int worldmapConfigLoadSubtile(TileInfo* tile, int row, int column, char* string) } // 0x4BE6D4 -int worldmapFindEncounterTableByLookupName(char* string, int* valuePtr) +static int wmParseFindEncounterTypeMatch(char* string, int* valuePtr) { - for (int index = 0; index < gEncounterTablesLength; index++) { - if (compat_stricmp(string, gEncounterTables[index].lookupName) == 0) { + for (int index = 0; index < wmMaxEncounterInfoTables; index++) { + if (compat_stricmp(string, wmEncounterTableList[index].lookupName) == 0) { *valuePtr = index; return 0; } @@ -2229,11 +2079,11 @@ int worldmapFindEncounterTableByLookupName(char* string, int* valuePtr) } // 0x4BE73C -int worldmapFindTerrainByLookupName(char* string, int* valuePtr) +static int wmParseFindTerrainTypeMatch(char* string, int* valuePtr) { - for (int index = 0; index < gTerrainsLength; index++) { - Terrain* terrain = &(gTerrains[index]); - if (compat_stricmp(string, terrain->field_0) == 0) { + for (int index = 0; index < wmMaxTerrainTypes; index++) { + Terrain* terrain = &(wmTerrainTypeList[index]); + if (compat_stricmp(string, terrain->lookupName) == 0) { *valuePtr = index; return 0; } @@ -2247,7 +2097,7 @@ int worldmapFindTerrainByLookupName(char* string, int* valuePtr) } // 0x4BE7A4 -int _wmParseEncounterItemType(char** stringPtr, ENC_BASE_TYPE_38_48* a2, int* a3, const char* delim) +static int wmParseEncounterItemType(char** stringPtr, ENC_BASE_TYPE_38_48* a2, int* a3, const char* delim) { char* string; size_t v2, v3; @@ -2282,7 +2132,7 @@ int _wmParseEncounterItemType(char** stringPtr, ENC_BASE_TYPE_38_48* a2, int* a3 if (strcmp(string, "item") == 0) { *stringPtr += v2 + 1; v20 = 1; - _wmParseItemType(string + v3 + 1, a2); + wmParseItemType(string + v3 + 1, a2); *a3 = *a3 + 1; } @@ -2293,7 +2143,7 @@ int _wmParseEncounterItemType(char** stringPtr, ENC_BASE_TYPE_38_48* a2, int* a3 } // 0x4BE888 -int _wmParseItemType(char* string, ENC_BASE_TYPE_38_48* ptr) +static int wmParseItemType(char* string, ENC_BASE_TYPE_38_48* ptr) { while (*string == ' ') { string++; @@ -2354,11 +2204,11 @@ int _wmParseItemType(char* string, ENC_BASE_TYPE_38_48* ptr) } // 0x4BE988 -int worldmapConfigParseCondition(char** stringPtr, const char* a2, EncounterCondition* condition) +static int wmParseConditional(char** stringPtr, const char* a2, EncounterCondition* condition) { while (condition->entriesLength < 3) { EncounterConditionEntry* conditionEntry = &(condition->entries[condition->entriesLength]); - if (worldmapConfigParseConditionEntry(stringPtr, a2, &(conditionEntry->type), &(conditionEntry->conditionalOperator), &(conditionEntry->param), &(conditionEntry->value)) == -1) { + if (wmParseSubConditional(stringPtr, a2, &(conditionEntry->type), &(conditionEntry->conditionalOperator), &(conditionEntry->param), &(conditionEntry->value)) == -1) { return -1; } @@ -2385,7 +2235,7 @@ int worldmapConfigParseCondition(char** stringPtr, const char* a2, EncounterCond } // 0x4BEA24 -int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typePtr, int* operatorPtr, int* paramPtr, int* valuePtr) +static int wmParseSubConditional(char** stringPtr, const char* a2, int* typePtr, int* operatorPtr, int* paramPtr, int* valuePtr) { char* pch; size_t v2; @@ -2473,7 +2323,7 @@ int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typ string++; } - if (worldmapConfigParseEncounterConditionalOperator(&string, operatorPtr) != -1) { + if (wmParseConditionalEval(&string, operatorPtr) != -1) { *valuePtr = atoi(string); pch = strstr(string, ")"); @@ -2496,7 +2346,7 @@ int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typ string++; } - if (worldmapConfigParseEncounterConditionalOperator(&string, operatorPtr) != -1) { + if (wmParseConditionalEval(&string, operatorPtr) != -1) { *valuePtr = atoi(string); pch = strstr(string, ")"); @@ -2519,7 +2369,7 @@ int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typ string++; } - if (worldmapConfigParseEncounterConditionalOperator(&string, operatorPtr) != -1) { + if (wmParseConditionalEval(&string, operatorPtr) != -1) { *valuePtr = atoi(string); pch = strstr(string, ")"); @@ -2542,7 +2392,7 @@ int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typ string++; } - if (worldmapConfigParseEncounterConditionalOperator(&string, operatorPtr) != -1) { + if (wmParseConditionalEval(&string, operatorPtr) != -1) { *valuePtr = atoi(string); pch = strstr(string, ")"); @@ -2565,7 +2415,7 @@ int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typ string++; } - if (worldmapConfigParseEncounterConditionalOperator(&string, operatorPtr) != -1) { + if (wmParseConditionalEval(&string, operatorPtr) != -1) { *valuePtr = atoi(string); pch = strstr(string, ")"); @@ -2589,7 +2439,7 @@ int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typ } // 0x4BEEBC -int worldmapConfigParseEncounterConditionalOperator(char** stringPtr, int* conditionalOperatorPtr) +static int wmParseConditionalEval(char** stringPtr, int* conditionalOperatorPtr) { char* string = *stringPtr; @@ -2597,7 +2447,7 @@ int worldmapConfigParseEncounterConditionalOperator(char** stringPtr, int* condi int index; for (index = 0; index < ENCOUNTER_CONDITIONAL_OPERATOR_COUNT; index++) { - if (strstr(string, _wmConditionalOpStrs[index]) == string) { + if (strstr(string, wmConditionalOpStrs[index]) == string) { break; } } @@ -2608,7 +2458,7 @@ int worldmapConfigParseEncounterConditionalOperator(char** stringPtr, int* condi *conditionalOperatorPtr = index; - string += strlen(_wmConditionalOpStrs[index]); + string += strlen(wmConditionalOpStrs[index]); while (*string == ' ') { string++; } @@ -2621,16 +2471,16 @@ int worldmapConfigParseEncounterConditionalOperator(char** stringPtr, int* condi // NOTE: Inlined. // // 0x4BEF1C -int worldmapCityInfoInit(CityInfo* area) +static int wmAreaSlotInit(CityInfo* area) { area->name[0] = '\0'; - area->field_28 = -1; + area->areaId = -1; area->x = 0; area->y = 0; area->size = CITY_SIZE_LARGE; - area->state = 0; - area->field_3C = 0; - area->field_40 = 0; + area->state = CITY_STATE_UNKNOWN; + area->lockState = LOCK_STATE_UNLOCKED; + area->visitedState = 0; area->mapFid = -1; area->labelFid = -1; area->entrancesLength = 0; @@ -2639,7 +2489,7 @@ int worldmapCityInfoInit(CityInfo* area) } // 0x4BEF68 -int cityInit() +static int wmAreaInit() { Config cfg; char section[40]; @@ -2651,7 +2501,7 @@ int cityInit() CityInfo* city; EntranceInfo* entrance; - if (_wmMapInit() == -1) { + if (wmMapInit() == -1) { return -1; } @@ -2667,22 +2517,22 @@ int cityInit() break; } - gCitiesLength++; + wmMaxAreaNum++; - cities = (CityInfo*)internal_realloc(gCities, sizeof(CityInfo) * gCitiesLength); + cities = (CityInfo*)internal_realloc(wmAreaInfoList, sizeof(CityInfo) * wmMaxAreaNum); if (cities == NULL) { showMesageBox("\nwmConfigInit::Error loading areas!"); exit(1); } - gCities = cities; + wmAreaInfoList = cities; - city = &(cities[gCitiesLength - 1]); + city = &(cities[wmMaxAreaNum - 1]); // NOTE: Uninline. - worldmapCityInfoInit(city); + wmAreaSlotInit(city); - city->field_28 = area_idx; + city->areaId = area_idx; if (num != -1) { num = buildFid(OBJ_TYPE_INTERFACE, num, 0, 0, 0); @@ -2723,12 +2573,12 @@ int cityInit() exit(1); } - if (strParseStrFromList(&str, &(city->state), _wmStateStrs, 2) == -1) { + if (strParseStrFromList(&str, &(city->state), wmStateStrs, 2) == -1) { return -1; } if (configGetString(&cfg, section, "lock_state", &str)) { - if (strParseStrFromList(&str, &(city->field_3C), _wmStateStrs, 2) == -1) { + if (strParseStrFromList(&str, &(city->lockState), wmStateStrs, 2) == -1) { return -1; } } @@ -2738,7 +2588,7 @@ int cityInit() exit(1); } - if (strParseStrFromList(&str, &(city->size), gCitySizeKeys, 3) == -1) { + if (strParseStrFromList(&str, &(city->size), wmAreaSizeStrs, 3) == -1) { return -1; } @@ -2752,9 +2602,9 @@ int cityInit() entrance = &(city->entrances[city->entrancesLength]); // NOTE: Uninline. - worldmapCityEntranceInfoInit(entrance); + wmEntranceSlotInit(entrance); - if (strParseStrFromList(&str, &(entrance->state), _wmStateStrs, 2) == -1) { + if (strParseStrFromList(&str, &(entrance->state), wmStateStrs, 2) == -1) { return -1; } @@ -2766,7 +2616,7 @@ int cityInit() return -1; } - if (strParseStrFromFunc(&str, &(entrance->map), &worldmapFindMapByLookupName) == -1) { + if (strParseStrFromFunc(&str, &(entrance->map), &wmParseFindMapIdxMatch) == -1) { return -1; } @@ -2791,7 +2641,7 @@ int cityInit() configFree(&cfg); - if (gCitiesLength != CITY_COUNT) { + if (wmMaxAreaNum != CITY_COUNT) { showMesageBox("\nwmAreaInit::Error loading Cities!"); exit(1); } @@ -2800,10 +2650,10 @@ int cityInit() } // 0x4BF3E0 -int worldmapFindMapByLookupName(char* string, int* valuePtr) +static int wmParseFindMapIdxMatch(char* string, int* valuePtr) { - for (int index = 0; index < gMapsLength; index++) { - MapInfo* map = &(gMaps[index]); + for (int index = 0; index < wmMaxMapNum; index++) { + MapInfo* map = &(wmMapInfoList[index]); if (compat_stricmp(string, map->lookupName) == 0) { *valuePtr = index; return 0; @@ -2819,7 +2669,7 @@ int worldmapFindMapByLookupName(char* string, int* valuePtr) // NOTE: Inlined. // // 0x4BF448 -int worldmapCityEntranceInfoInit(EntranceInfo* entrance) +static int wmEntranceSlotInit(EntranceInfo* entrance) { entrance->state = 0; entrance->x = 0; @@ -2833,7 +2683,7 @@ int worldmapCityEntranceInfoInit(EntranceInfo* entrance) } // 0x4BF47C -int worldmapMapInfoInit(MapInfo* map) +static int wmMapSlotInit(MapInfo* map) { map->lookupName[0] = '\0'; map->field_28 = -1; @@ -2848,7 +2698,7 @@ int worldmapMapInfoInit(MapInfo* map) } // 0x4BF4BC -int _wmMapInit() +static int wmMapInit() { char* str; int num; @@ -2864,26 +2714,26 @@ int _wmMapInit() } if (configRead(&config, "data\\maps.txt", true)) { - for (int mapIndex = 0;; mapIndex++) { + for (int mapIdx = 0;; mapIdx++) { char section[40]; - sprintf(section, "Map %03d", mapIndex); + sprintf(section, "Map %03d", mapIdx); if (!configGetString(&config, section, "lookup_name", &str)) { break; } - gMapsLength++; + wmMaxMapNum++; - maps = (MapInfo*)internal_realloc(gMaps, sizeof(*gMaps) * gMapsLength); + maps = (MapInfo*)internal_realloc(wmMapInfoList, sizeof(*wmMapInfoList) * wmMaxMapNum); if (maps == NULL) { showMesageBox("\nwmConfigInit::Error loading maps!"); exit(1); } - gMaps = maps; + wmMapInfoList = maps; - map = &(maps[gMapsLength - 1]); - worldmapMapInfoInit(map); + map = &(maps[wmMaxMapNum - 1]); + wmMapSlotInit(map); strncpy(map->lookupName, str, 40); @@ -2914,7 +2764,7 @@ int _wmMapInit() if (map->ambientSoundEffectsLength >= MAP_AMBIENT_SOUND_EFFECTS_CAPACITY) { if (str != NULL) { - debugPrint("\nwmMapInit::Error reading ambient sfx. Too many! Str: %s, MapIdx: %d", map->lookupName, mapIndex); + debugPrint("\nwmMapInit::Error reading ambient sfx. Too many! Str: %s, MapIdx: %d", map->lookupName, mapIdx); str = NULL; } } @@ -2922,7 +2772,7 @@ int _wmMapInit() } if (configGetString(&config, section, "saved", &str)) { - if (strParseStrFromList(&str, &num, _wmYesNoStrs, 2) == -1) { + if (strParseStrFromList(&str, &num, wmYesNoStrs, 2) == -1) { return -1; } @@ -2931,7 +2781,7 @@ int _wmMapInit() } if (configGetString(&config, section, "dead_bodies_age", &str)) { - if (strParseStrFromList(&str, &num, _wmYesNoStrs, 2) == -1) { + if (strParseStrFromList(&str, &num, wmYesNoStrs, 2) == -1) { return -1; } @@ -2940,21 +2790,21 @@ int _wmMapInit() } if (configGetString(&config, section, "can_rest_here", &str)) { - if (strParseStrFromList(&str, &num, _wmYesNoStrs, 2) == -1) { + if (strParseStrFromList(&str, &num, wmYesNoStrs, 2) == -1) { return -1; } // NOTE: Uninline. wmSetFlags(&(map->flags), MAP_CAN_REST_ELEVATION_0, num); - if (strParseStrFromList(&str, &num, _wmYesNoStrs, 2) == -1) { + if (strParseStrFromList(&str, &num, wmYesNoStrs, 2) == -1) { return -1; } // NOTE: Uninline. wmSetFlags(&(map->flags), MAP_CAN_REST_ELEVATION_1, num); - if (strParseStrFromList(&str, &num, _wmYesNoStrs, 2) == -1) { + if (strParseStrFromList(&str, &num, wmYesNoStrs, 2) == -1) { return -1; } @@ -2963,7 +2813,7 @@ int _wmMapInit() } if (configGetString(&config, section, "pipboy_active", &str)) { - if (strParseStrFromList(&str, &num, _wmYesNoStrs, 2) == -1) { + if (strParseStrFromList(&str, &num, wmYesNoStrs, 2) == -1) { return -1; } @@ -2973,11 +2823,11 @@ int _wmMapInit() // SFALL: Pip-boy automaps patch. if (configGetString(&config, section, "automap", &str)) { - if (strParseStrFromList(&str, &num, _wmYesNoStrs, 2) == -1) { + if (strParseStrFromList(&str, &num, wmYesNoStrs, 2) == -1) { return -1; } - automapSetDisplayMap(mapIndex, num); + automapSetDisplayMap(mapIdx, num); } if (configGetString(&config, section, "random_start_point_0", &str)) { @@ -2991,7 +2841,7 @@ int _wmMapInit() rsp = &(map->startPoints[map->startPointsLength]); // NOTE: Uninline. - worldmapRandomStartingPointInit(rsp); + wmRStartSlotInit(rsp); strParseIntWithKey(&str, "elev", &(rsp->elevation), ":"); strParseIntWithKey(&str, "tile_num", &(rsp->tile), ":"); @@ -3018,7 +2868,7 @@ int _wmMapInit() // NOTE: Inlined. // // 0x4BF954 -int worldmapRandomStartingPointInit(MapStartPointInfo* rsp) +static int wmRStartSlotInit(MapStartPointInfo* rsp) { rsp->elevation = 0; rsp->tile = -1; @@ -3028,25 +2878,25 @@ int worldmapRandomStartingPointInit(MapStartPointInfo* rsp) } // 0x4BF96C -int mapGetCount() +int wmMapMaxCount() { - return gMapsLength; + return wmMaxMapNum; } // 0x4BF974 -int mapGetFileName(int map, char* dest) +int wmMapIdxToName(int mapIdx, char* dest) { - if (map == -1 || map > gMapsLength) { + if (mapIdx == -1 || mapIdx > wmMaxMapNum) { dest[0] = '\0'; return -1; } - sprintf(dest, "%s.MAP", gMaps[map].mapFileName); + sprintf(dest, "%s.MAP", wmMapInfoList[mapIdx].mapFileName); return 0; } // 0x4BF9BC -int mapGetIndexByFileName(char* name) +int wmMapMatchNameToIdx(char* name) { compat_strlwr(name); @@ -3063,8 +2913,8 @@ int mapGetIndexByFileName(char* name) int map = -1; - for (int index = 0; index < gMapsLength; index++) { - if (strcmp(gMaps[index].mapFileName, name) == 0) { + for (int index = 0; index < wmMaxMapNum; index++) { + if (strcmp(wmMapInfoList[index].mapFileName, name) == 0) { map = index; break; } @@ -3078,167 +2928,167 @@ int mapGetIndexByFileName(char* name) } // 0x4BFA44 -bool _wmMapIdxIsSaveable(int map_index) +bool wmMapIdxIsSaveable(int mapIdx) { - return (gMaps[map_index].flags & MAP_SAVED) != 0; + return (wmMapInfoList[mapIdx].flags & MAP_SAVED) != 0; } // 0x4BFA64 -bool _wmMapIsSaveable() +bool wmMapIsSaveable() { - return (gMaps[gMapHeader.field_34].flags & MAP_SAVED) != 0; + return (wmMapInfoList[gMapHeader.field_34].flags & MAP_SAVED) != 0; } // 0x4BFA90 -bool _wmMapDeadBodiesAge() +bool wmMapDeadBodiesAge() { - return (gMaps[gMapHeader.field_34].flags & MAP_DEAD_BODIES_AGE) != 0; + return (wmMapInfoList[gMapHeader.field_34].flags & MAP_DEAD_BODIES_AGE) != 0; } // 0x4BFABC -bool _wmMapCanRestHere(int elevation) +bool wmMapCanRestHere(int elevation) { int flags[3]; // NOTE: I'm not sure why they're copied. memcpy(flags, _can_rest_here, sizeof(flags)); - MapInfo* map = &(gMaps[gMapHeader.field_34]); + MapInfo* map = &(wmMapInfoList[gMapHeader.field_34]); return (map->flags & flags[elevation]) != 0; } // 0x4BFAFC -bool _wmMapPipboyActive() +bool wmMapPipboyActive() { return gameMovieIsSeen(MOVIE_VSUIT); } // 0x4BFB08 -int _wmMapMarkVisited(int mapIndex) +int wmMapMarkVisited(int mapIdx) { - if (mapIndex < 0 || mapIndex >= gMapsLength) { + if (mapIdx < 0 || mapIdx >= wmMaxMapNum) { return -1; } - MapInfo* map = &(gMaps[mapIndex]); + MapInfo* map = &(wmMapInfoList[mapIdx]); if ((map->flags & MAP_SAVED) == 0) { return 0; } - int cityIndex; - if (_wmMatchAreaContainingMapIdx(mapIndex, &cityIndex) == -1) { + int areaIdx; + if (wmMatchAreaContainingMapIdx(mapIdx, &areaIdx) == -1) { return -1; } // NOTE: Uninline. - wmAreaMarkVisited(cityIndex); + wmAreaMarkVisited(areaIdx); return 0; } // 0x4BFB64 -int _wmMatchEntranceFromMap(int cityIndex, int mapIndex, int* entranceIndexPtr) +static int wmMatchEntranceFromMap(int areaIdx, int mapIdx, int* entranceIdxPtr) { - CityInfo* city = &(gCities[cityIndex]); + CityInfo* city = &(wmAreaInfoList[areaIdx]); - for (int entranceIndex = 0; entranceIndex < city->entrancesLength; entranceIndex++) { - EntranceInfo* entrance = &(city->entrances[entranceIndex]); + for (int entranceIdx = 0; entranceIdx < city->entrancesLength; entranceIdx++) { + EntranceInfo* entrance = &(city->entrances[entranceIdx]); - if (mapIndex == entrance->map) { - *entranceIndexPtr = entranceIndex; + if (mapIdx == entrance->map) { + *entranceIdxPtr = entranceIdx; return 0; } } - *entranceIndexPtr = -1; + *entranceIdxPtr = -1; return -1; } // 0x4BFBE8 -int _wmMatchEntranceElevFromMap(int cityIndex, int map, int elevation, int* entranceIndexPtr) +static int wmMatchEntranceElevFromMap(int areaIdx, int mapIdx, int elevation, int* entranceIdxPtr) { - CityInfo* city = &(gCities[cityIndex]); + CityInfo* city = &(wmAreaInfoList[areaIdx]); - for (int entranceIndex = 0; entranceIndex < city->entrancesLength; entranceIndex++) { - EntranceInfo* entrance = &(city->entrances[entranceIndex]); - if (entrance->map == map) { + for (int entranceIdx = 0; entranceIdx < city->entrancesLength; entranceIdx++) { + EntranceInfo* entrance = &(city->entrances[entranceIdx]); + if (entrance->map == mapIdx) { if (elevation == -1 || entrance->elevation == -1 || elevation == entrance->elevation) { - *entranceIndexPtr = entranceIndex; + *entranceIdxPtr = entranceIdx; return 0; } } } - *entranceIndexPtr = -1; + *entranceIdxPtr = -1; return -1; } // 0x4BFC7C -int _wmMatchAreaFromMap(int mapIndex, int* cityIndexPtr) +static int wmMatchAreaFromMap(int mapIdx, int* areaIdxPtr) { - for (int cityIndex = 0; cityIndex < gCitiesLength; cityIndex++) { - CityInfo* city = &(gCities[cityIndex]); + for (int areaIdx = 0; areaIdx < wmMaxAreaNum; areaIdx++) { + CityInfo* city = &(wmAreaInfoList[areaIdx]); - for (int entranceIndex = 0; entranceIndex < city->entrancesLength; entranceIndex++) { - EntranceInfo* entrance = &(city->entrances[entranceIndex]); - if (mapIndex == entrance->map) { - *cityIndexPtr = cityIndex; + for (int entranceIdx = 0; entranceIdx < city->entrancesLength; entranceIdx++) { + EntranceInfo* entrance = &(city->entrances[entranceIdx]); + if (mapIdx == entrance->map) { + *areaIdxPtr = areaIdx; return 0; } } } - *cityIndexPtr = -1; + *areaIdxPtr = -1; return -1; } // Mark map entrance. // // 0x4BFD50 -int _wmMapMarkMapEntranceState(int mapIndex, int elevation, int state) +int wmMapMarkMapEntranceState(int mapIdx, int elevation, int state) { - if (mapIndex < 0 || mapIndex >= gMapsLength) { + if (mapIdx < 0 || mapIdx >= wmMaxMapNum) { return -1; } - MapInfo* map = &(gMaps[mapIndex]); + MapInfo* map = &(wmMapInfoList[mapIdx]); if ((map->flags & MAP_SAVED) == 0) { return -1; } - int cityIndex; - if (_wmMatchAreaContainingMapIdx(mapIndex, &cityIndex) == -1) { + int areaIdx; + if (wmMatchAreaContainingMapIdx(mapIdx, &areaIdx) == -1) { return -1; } - int entranceIndex; - if (_wmMatchEntranceElevFromMap(cityIndex, mapIndex, elevation, &entranceIndex) == -1) { + int entranceIdx; + if (wmMatchEntranceElevFromMap(areaIdx, mapIdx, elevation, &entranceIdx) == -1) { return -1; } - CityInfo* city = &(gCities[cityIndex]); - EntranceInfo* entrance = &(city->entrances[entranceIndex]); + CityInfo* city = &(wmAreaInfoList[areaIdx]); + EntranceInfo* entrance = &(city->entrances[entranceIdx]); entrance->state = state; return 0; } // 0x4BFE0C -void _wmWorldMap() +void wmWorldMap() { - _wmWorldMapFunc(0); + wmWorldMapFunc(0); } // 0x4BFE10 -int _wmWorldMapFunc(int a1) +static int wmWorldMapFunc(int a1) { - if (worldmapWindowInit() == -1) { - worldmapWindowFree(); + if (wmInterfaceInit() == -1) { + wmInterfaceExit(); return -1; } - _wmMatchWorldPosToArea(_world_xpos, _world_ypos, &_WorldMapCurrArea); + wmMatchWorldPosToArea(wmGenData.worldPosX, wmGenData.worldPosY, &(wmGenData.currentAreaId)); unsigned int v24 = 0; int map = -1; @@ -3251,10 +3101,10 @@ int _wmWorldMapFunc(int a1) int mouseX; int mouseY; - mouseGetPositionInWindow(gWorldmapWindow, &mouseX, &mouseY); + mouseGetPositionInWindow(wmBkWin, &mouseX, &mouseY); - int v4 = gWorldmapOffsetX + mouseX - WM_VIEW_X; - int v5 = gWorldmapOffsetY + mouseY - WM_VIEW_Y; + int v4 = wmWorldOffsetX + mouseX - WM_VIEW_X; + int v5 = wmWorldOffsetY + mouseY - WM_VIEW_Y; if (keyCode == KEY_CTRL_Q || keyCode == KEY_CTRL_X || keyCode == KEY_F10) { showQuitConfirmationDialog(); @@ -3269,67 +3119,67 @@ int _wmWorldMapFunc(int a1) int mouseEvent = mouseGetEvent(); - if (gWorldmapIsTravelling) { - worldmapPerformTravel(); + if (wmGenData.isWalking) { + wmPartyWalkingStep(); - if (gWorldmapIsInCar) { - worldmapPerformTravel(); - worldmapPerformTravel(); - worldmapPerformTravel(); + if (wmGenData.isInCar) { + wmPartyWalkingStep(); + wmPartyWalkingStep(); + wmPartyWalkingStep(); if (gameGetGlobalVar(GVAR_CAR_BLOWER)) { - worldmapPerformTravel(); + wmPartyWalkingStep(); } if (gameGetGlobalVar(GVAR_NEW_RENO_CAR_UPGRADE)) { - worldmapPerformTravel(); + wmPartyWalkingStep(); } if (gameGetGlobalVar(GVAR_NEW_RENO_SUPER_CAR)) { - worldmapPerformTravel(); - worldmapPerformTravel(); - worldmapPerformTravel(); + wmPartyWalkingStep(); + wmPartyWalkingStep(); + wmPartyWalkingStep(); } - gWorldmapCarFrmCurrentFrame++; - if (gWorldmapCarFrmCurrentFrame >= artGetFrameCount(gWorldmapCarFrm)) { - gWorldmapCarFrmCurrentFrame = 0; + wmGenData.carImageCurrentFrameIndex++; + if (wmGenData.carImageCurrentFrameIndex >= artGetFrameCount(wmGenData.carImageFrm)) { + wmGenData.carImageCurrentFrameIndex = 0; } - carConsumeFuel(100); + wmCarUseGas(100); - if (gWorldmapCarFuel <= 0) { - gWorldmapTravelDestX = 0; - gWorldmapTravelDestY = 0; - gWorldmapIsTravelling = false; + if (wmGenData.carFuel <= 0) { + wmGenData.walkDestinationX = 0; + wmGenData.walkDestinationY = 0; + wmGenData.isWalking = false; - _wmMatchWorldPosToArea(v4, v5, &_WorldMapCurrArea); + wmMatchWorldPosToArea(v4, v5, &(wmGenData.currentAreaId)); - gWorldmapIsInCar = false; + wmGenData.isInCar = false; - if (_WorldMapCurrArea == -1) { - _carCurrentArea = CITY_CAR_OUT_OF_GAS; + if (wmGenData.currentAreaId == -1) { + wmGenData.currentCarAreaId = CITY_CAR_OUT_OF_GAS; - CityInfo* city = &(gCities[CITY_CAR_OUT_OF_GAS]); + CityInfo* city = &(wmAreaInfoList[CITY_CAR_OUT_OF_GAS]); - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[city->size]); - int worldmapX = _world_xpos + gWorldmapHotspotUpFrmWidth / 2 + citySizeDescription->width / 2; - int worldmapY = _world_ypos + gWorldmapHotspotUpFrmHeight / 2 + citySizeDescription->height / 2; - worldmapCitySetPos(CITY_CAR_OUT_OF_GAS, worldmapX, worldmapY); + CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]); + int worldmapX = wmGenData.worldPosX + wmGenData.hotspotFrmWidth / 2 + citySizeDescription->width / 2; + int worldmapY = wmGenData.worldPosY + wmGenData.hotspotFrmHeight / 2 + citySizeDescription->height / 2; + wmAreaSetWorldPos(CITY_CAR_OUT_OF_GAS, worldmapX, worldmapY); - city->state = 1; - city->field_40 = 1; + city->state = CITY_STATE_KNOWN; + city->visitedState = 1; - _WorldMapCurrArea = CITY_CAR_OUT_OF_GAS; + wmGenData.currentAreaId = CITY_CAR_OUT_OF_GAS; } else { - _carCurrentArea = _WorldMapCurrArea; + wmGenData.currentCarAreaId = wmGenData.currentAreaId; } debugPrint("\nRan outta gas!"); } } - worldmapWindowRefresh(); + wmInterfaceRefresh(); if (getTicksBetween(tick, v24) > 1000) { if (_partyMemberRestingHeal(3)) { @@ -3338,28 +3188,28 @@ int _wmWorldMapFunc(int a1) } } - _wmMarkSubTileRadiusVisited(_world_xpos, _world_ypos); + wmMarkSubTileRadiusVisited(wmGenData.worldPosX, wmGenData.worldPosY); - if (dword_672E28 <= 0) { - gWorldmapIsTravelling = false; - _wmMatchWorldPosToArea(_world_xpos, _world_ypos, &_WorldMapCurrArea); + if (wmGenData.walkDistance <= 0) { + wmGenData.isWalking = false; + wmMatchWorldPosToArea(wmGenData.worldPosX, wmGenData.worldPosY, &(wmGenData.currentAreaId)); } - worldmapWindowRefresh(); + wmInterfaceRefresh(); - if (_wmGameTimeIncrement(18000)) { + if (wmGameTimeIncrement(18000)) { if (_game_user_wants_to_quit != 0) { break; } } - if (gWorldmapIsTravelling) { - if (_wmRndEncounterOccurred()) { - if (_EncounterMapID != -1) { - if (gWorldmapIsInCar) { - _wmMatchAreaContainingMapIdx(_EncounterMapID, &_carCurrentArea); + if (wmGenData.isWalking) { + if (wmRndEncounterOccurred()) { + if (wmGenData.encounterMapId != -1) { + if (wmGenData.isInCar) { + wmMatchAreaContainingMapIdx(wmGenData.encounterMapId, &(wmGenData.currentCarAreaId)); } - mapLoadById(_EncounterMapID); + mapLoadById(wmGenData.encounterMapId); } break; } @@ -3367,10 +3217,10 @@ int _wmWorldMapFunc(int a1) } if ((mouseEvent & MOUSE_EVENT_LEFT_BUTTON_DOWN) != 0 && (mouseEvent & MOUSE_EVENT_LEFT_BUTTON_REPEAT) == 0) { - if (mouseHitTestInWindow(gWorldmapWindow, WM_VIEW_X, WM_VIEW_Y, 472, 465)) { - if (!gWorldmapIsTravelling && !_wmGenData && abs(_world_xpos - v4) < 5 && abs(_world_ypos - v5) < 5) { - _wmGenData = true; - worldmapWindowRefresh(); + if (mouseHitTestInWindow(wmBkWin, WM_VIEW_X, WM_VIEW_Y, 472, 465)) { + if (!wmGenData.isWalking && !wmGenData.mousePressed && abs(wmGenData.worldPosX - v4) < 5 && abs(wmGenData.worldPosY - v5) < 5) { + wmGenData.mousePressed = true; + wmInterfaceRefresh(); } } else { continue; @@ -3378,37 +3228,37 @@ int _wmWorldMapFunc(int a1) } if ((mouseEvent & MOUSE_EVENT_LEFT_BUTTON_UP) != 0) { - if (_wmGenData) { - _wmGenData = false; - worldmapWindowRefresh(); + if (wmGenData.mousePressed) { + wmGenData.mousePressed = false; + wmInterfaceRefresh(); - if (abs(_world_xpos - v4) < 5 && abs(_world_ypos - v5) < 5) { - if (_WorldMapCurrArea != -1) { - CityInfo* city = &(gCities[_WorldMapCurrArea]); - if (city->field_40 == 2 && city->mapFid != -1) { - if (worldmapCityMapViewSelect(&map) == -1) { + if (abs(wmGenData.worldPosX - v4) < 5 && abs(wmGenData.worldPosY - v5) < 5) { + if (wmGenData.currentAreaId != -1) { + CityInfo* city = &(wmAreaInfoList[wmGenData.currentAreaId]); + if (city->visitedState == 2 && city->mapFid != -1) { + if (wmTownMapFunc(&map) == -1) { v25 = -1; break; } } else { - if (_wmAreaFindFirstValidMap(&map) == -1) { + if (wmAreaFindFirstValidMap(&map) == -1) { v25 = -1; break; } - city->field_40 = 2; + city->visitedState = 2; } } else { map = 0; } if (map != -1) { - if (gWorldmapIsInCar) { - gWorldmapIsInCar = false; - if (_WorldMapCurrArea == -1) { - _wmMatchAreaContainingMapIdx(map, &_carCurrentArea); + if (wmGenData.isInCar) { + wmGenData.isInCar = false; + if (wmGenData.currentAreaId == -1) { + wmMatchAreaContainingMapIdx(map, &(wmGenData.currentCarAreaId)); } else { - _carCurrentArea = _WorldMapCurrArea; + wmGenData.currentCarAreaId = wmGenData.currentAreaId; } } mapLoadById(map); @@ -3416,11 +3266,11 @@ int _wmWorldMapFunc(int a1) } } } else { - if (mouseHitTestInWindow(gWorldmapWindow, WM_VIEW_X, WM_VIEW_Y, 472, 465)) { - _wmPartyInitWalking(v4, v5); + if (mouseHitTestInWindow(wmBkWin, WM_VIEW_X, WM_VIEW_Y, 472, 465)) { + wmPartyInitWalking(v4, v5); } - _wmGenData = 0; + wmGenData.mousePressed = false; } } @@ -3428,16 +3278,16 @@ int _wmWorldMapFunc(int a1) wmInterfaceScrollTabsUpdate(); if (keyCode == KEY_UPPERCASE_T || keyCode == KEY_LOWERCASE_T) { - if (!gWorldmapIsTravelling && _WorldMapCurrArea != -1) { - CityInfo* city = &(gCities[_WorldMapCurrArea]); - if (city->field_40 == 2 && city->mapFid != -1) { - if (worldmapCityMapViewSelect(&map) == -1) { + if (!wmGenData.isWalking && wmGenData.currentAreaId != -1) { + CityInfo* city = &(wmAreaInfoList[wmGenData.currentAreaId]); + if (city->visitedState == 2 && city->mapFid != -1) { + if (wmTownMapFunc(&map) == -1) { rc = -1; } if (map != -1) { - if (gWorldmapIsInCar) { - _wmMatchAreaContainingMapIdx(map, &_carCurrentArea); + if (wmGenData.isInCar) { + wmMatchAreaContainingMapIdx(map, &(wmGenData.currentCarAreaId)); } mapLoadById(map); @@ -3445,7 +3295,7 @@ int _wmWorldMapFunc(int a1) } } } else if (keyCode == KEY_HOME) { - _wmInterfaceCenterOnParty(); + wmInterfaceCenterOnParty(); } else if (keyCode == KEY_ARROW_UP) { // NOTE: Uninline. wmInterfaceScroll(0, -1, NULL); @@ -3459,26 +3309,26 @@ int _wmWorldMapFunc(int a1) // NOTE: Uninline. wmInterfaceScroll(1, 0, NULL); } else if (keyCode == KEY_CTRL_ARROW_UP) { - _wmInterfaceScrollTabsStart(-27); + wmInterfaceScrollTabsStart(-27); } else if (keyCode == KEY_CTRL_ARROW_DOWN) { - _wmInterfaceScrollTabsStart(27); + wmInterfaceScrollTabsStart(27); } else if (keyCode >= KEY_CTRL_F1 && keyCode <= KEY_CTRL_F7) { - int quickDestinationIndex = _LastTabsYOffset / 27 + (keyCode - KEY_CTRL_F1); - if (quickDestinationIndex < gQuickDestinationsLength) { - int cityIndex = gQuickDestinations[quickDestinationIndex]; - CityInfo* city = &(gCities[cityIndex]); - if (_wmAreaIsKnown(city->field_28)) { - if (_WorldMapCurrArea != cityIndex) { + int quickDestinationIndex = wmGenData.tabsOffsetY / 27 + (keyCode - KEY_CTRL_F1); + if (quickDestinationIndex < wmLabelCount) { + int areaIdx = wmLabelList[quickDestinationIndex]; + CityInfo* city = &(wmAreaInfoList[areaIdx]); + if (wmAreaIsKnown(city->areaId)) { + if (wmGenData.currentAreaId != areaIdx) { // SFALL: Fix the position of the destination marker for // small/medium location circles. - // CE: Fix is slightly different. `_wmPartyInitWalking` + // CE: Fix is slightly different. `wmPartyInitWalking` // assumes x/y are compensated for worldmap viewport // offset (as can be seen earlier in this function). - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[city->size]); + CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]); int destX = city->x + citySizeDescription->width / 2 - WM_VIEW_X; int destY = city->y + citySizeDescription->height / 2 - WM_VIEW_Y; - _wmPartyInitWalking(destX, destY); - _wmGenData = 0; + wmPartyInitWalking(destX, destY); + wmGenData.mousePressed = 0; } } } @@ -3489,11 +3339,11 @@ int _wmWorldMapFunc(int a1) int wheelY; mouseGetWheel(&wheelX, &wheelY); - if (mouseHitTestInWindow(gWorldmapWindow, WM_VIEW_X, WM_VIEW_Y, 472, 465)) { - worldmapWindowScroll(20, 20, wheelX, -wheelY, NULL, true); - } else if (mouseHitTestInWindow(gWorldmapWindow, 501, 135, 501 + 119, 135 + 178)) { + if (mouseHitTestInWindow(wmBkWin, WM_VIEW_X, WM_VIEW_Y, 472, 465)) { + wmInterfaceScrollPixel(20, 20, wheelX, -wheelY, NULL, true); + } else if (mouseHitTestInWindow(wmBkWin, 501, 135, 501 + 119, 135 + 178)) { if (wheelY != 0) { - _wmInterfaceScrollTabsStart(wheelY > 0 ? 27 : -27); + wmInterfaceScrollTabsStart(wheelY > 0 ? 27 : -27); } } } @@ -3503,7 +3353,7 @@ int _wmWorldMapFunc(int a1) } } - if (worldmapWindowFree() == -1) { + if (wmInterfaceExit() == -1) { return -1; } @@ -3511,51 +3361,51 @@ int _wmWorldMapFunc(int a1) } // 0x4C056C -int _wmCheckGameAreaEvents() +int wmCheckGameAreaEvents() { - if (_WorldMapCurrArea == CITY_FAKE_VAULT_13_A) { - if (_WorldMapCurrArea < gCitiesLength) { - gCities[CITY_FAKE_VAULT_13_A].state = 0; + if (wmGenData.currentAreaId == CITY_FAKE_VAULT_13_A) { + if (wmGenData.currentAreaId < wmMaxAreaNum) { + wmAreaInfoList[CITY_FAKE_VAULT_13_A].state = CITY_STATE_UNKNOWN; } - if (gCitiesLength > CITY_FAKE_VAULT_13_B) { - gCities[CITY_FAKE_VAULT_13_B].state = 1; + if (wmMaxAreaNum > CITY_FAKE_VAULT_13_B) { + wmAreaInfoList[CITY_FAKE_VAULT_13_B].state = CITY_STATE_KNOWN; } - _wmAreaMarkVisitedState(CITY_FAKE_VAULT_13_B, 2); + wmAreaMarkVisitedState(CITY_FAKE_VAULT_13_B, 2); } return 0; } // 0x4C05C4 -int _wmInterfaceCenterOnParty() +static int wmInterfaceCenterOnParty() { int v0; int v1; - v0 = _world_xpos - 203; + v0 = wmGenData.worldPosX - 203; if ((v0 & 0x80000000) == 0) { - if (v0 > _wmViewportRightScrlLimit) { - v0 = _wmViewportRightScrlLimit; + if (v0 > wmGenData.viewportMaxX) { + v0 = wmGenData.viewportMaxX; } } else { v0 = 0; } - v1 = _world_ypos - 200; + v1 = wmGenData.worldPosY - 200; if ((v1 & 0x80000000) == 0) { - if (v1 > _wmViewportBottomtScrlLimit) { - v1 = _wmViewportBottomtScrlLimit; + if (v1 > wmGenData.viewportMaxY) { + v1 = wmGenData.viewportMaxY; } } else { v1 = 0; } - gWorldmapOffsetX = v0; - gWorldmapOffsetY = v1; + wmWorldOffsetX = v0; + wmWorldOffsetY = v1; - worldmapWindowRefresh(); + wmInterfaceRefresh(); return 0; } @@ -3565,55 +3415,55 @@ int _wmInterfaceCenterOnParty() // 0x4C0624 static void wmCheckGameEvents() { - _scriptsCheckGameEvents(NULL, gWorldmapWindow); + _scriptsCheckGameEvents(NULL, wmBkWin); } // 0x4C0634 -int _wmRndEncounterOccurred() +static int wmRndEncounterOccurred() { unsigned int v0 = _get_time(); - if (getTicksBetween(v0, _wmLastRndTime) < 1500) { + if (getTicksBetween(v0, wmLastRndTime) < 1500) { return 0; } - _wmLastRndTime = v0; + wmLastRndTime = v0; - if (abs(_old_world_xpos - _world_xpos) < 3) { + if (abs(wmGenData.oldWorldPosX - wmGenData.worldPosX) < 3) { return 0; } - if (abs(_old_world_ypos - _world_ypos) < 3) { + if (abs(wmGenData.oldWorldPosY - wmGenData.worldPosY) < 3) { return 0; } int v26; - _wmMatchWorldPosToArea(_world_xpos, _world_ypos, &v26); + wmMatchWorldPosToArea(wmGenData.worldPosX, wmGenData.worldPosY, &v26); if (v26 != -1) { return 0; } - if (!_Meet_Frank_Horrigan) { + if (!wmGenData.didMeetFrankHorrigan) { unsigned int gameTime = gameTimeGetTime(); if (gameTime / GAME_TIME_TICKS_PER_DAY > 35) { // SFALL: Add a flashing icon to the Horrigan encounter. - _wmEncounterIconShow = 1; + wmGenData.encounterIconIsVisible = 1; for (int index = 0; index < 7; index++) { - _wmRndCursorFid = index % 2 == 0 + wmGenData.encounterCursorId = index % 2 == 0 ? WORLD_MAP_ENCOUNTER_FRM_SPECIAL_DARK : WORLD_MAP_ENCOUNTER_FRM_SPECIAL_BRIGHT; - if (worldmapWindowRefresh() == -1) { + if (wmInterfaceRefresh() == -1) { return -1; } coreDelay(200); } - _EncounterMapID = v26; - _Meet_Frank_Horrigan = true; - if (gWorldmapIsInCar) { - _wmMatchAreaContainingMapIdx(MAP_IN_GAME_MOVIE1, &_carCurrentArea); + wmGenData.encounterMapId = v26; + wmGenData.didMeetFrankHorrigan = true; + if (wmGenData.isInCar) { + wmMatchAreaContainingMapIdx(MAP_IN_GAME_MOVIE1, &(wmGenData.currentCarAreaId)); } mapLoadById(MAP_IN_GAME_MOVIE1); return 1; @@ -3621,7 +3471,7 @@ int _wmRndEncounterOccurred() } // NOTE: Uninline. - _wmPartyFindCurSubTile(); + wmPartyFindCurSubTile(); int dayPart; int gameTimeHour = gameTimeGetHour(); @@ -3633,7 +3483,7 @@ int _wmRndEncounterOccurred() dayPart = DAY_PART_MORNING; } - int frequency = _wmFreqValues[_world_subtile->encounterChance[dayPart]]; + int frequency = wmFreqValues[wmGenData.currentSubtile->encounterChance[dayPart]]; if (frequency > 0 && frequency < 100) { int gameDifficulty = GAME_DIFFICULTY_NORMAL; if (configGetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_GAME_DIFFICULTY_KEY, &gameDifficulty)) { @@ -3654,45 +3504,45 @@ int _wmRndEncounterOccurred() return 0; } - _wmRndEncounterPick(); + wmRndEncounterPick(); int v8 = 1; - _wmEncounterIconShow = 1; - _wmRndCursorFid = 0; + wmGenData.encounterIconIsVisible = 1; + wmGenData.encounterCursorId = 0; - EncounterTable* encounterTable = &(gEncounterTables[dword_672E50]); - EncounterEntry* encounter = &(encounterTable->entries[dword_672E54]); + EncounterTable* encounterTable = &(wmEncounterTableList[wmGenData.encounterTableId]); + EncounterEntry* encounter = &(encounterTable->entries[wmGenData.encounterEntryId]); if ((encounter->flags & ENCOUNTER_ENTRY_SPECIAL) != 0) { - _wmRndCursorFid = 2; - _wmMatchAreaContainingMapIdx(_EncounterMapID, &v26); + wmGenData.encounterCursorId = 2; + wmMatchAreaContainingMapIdx(wmGenData.encounterMapId, &v26); - CityInfo* city = &(gCities[v26]); - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[city->size]); - int worldmapX = _world_xpos + gWorldmapHotspotUpFrmWidth / 2 + citySizeDescription->width / 2; - int worldmapY = _world_ypos + gWorldmapHotspotUpFrmHeight / 2 + citySizeDescription->height / 2; - worldmapCitySetPos(v26, worldmapX, worldmapY); + CityInfo* city = &(wmAreaInfoList[v26]); + CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]); + int worldmapX = wmGenData.worldPosX + wmGenData.hotspotFrmWidth / 2 + citySizeDescription->width / 2; + int worldmapY = wmGenData.worldPosY + wmGenData.hotspotFrmHeight / 2 + citySizeDescription->height / 2; + wmAreaSetWorldPos(v26, worldmapX, worldmapY); v8 = 3; - if (v26 >= 0 && v26 < gCitiesLength) { - CityInfo* city = &(gCities[v26]); - if (city->field_3C != 1) { - city->state = 1; + if (v26 >= 0 && v26 < wmMaxAreaNum) { + CityInfo* city = &(wmAreaInfoList[v26]); + if (city->lockState != LOCK_STATE_LOCKED) { + city->state = CITY_STATE_KNOWN; } } } // Blinking. for (int index = 0; index < 7; index++) { - _wmRndCursorFid = v8 - _wmRndCursorFid; + wmGenData.encounterCursorId = v8 - wmGenData.encounterCursorId; - if (worldmapWindowRefresh() == -1) { + if (wmInterfaceRefresh() == -1) { return -1; } coreDelay(200); } - if (gWorldmapIsInCar) { + if (wmGenData.isInCar) { int modifiers[DAY_PART_COUNT]; // NOTE: I'm not sure why they're copied. @@ -3717,7 +3567,7 @@ int _wmRndEncounterOccurred() TileInfo* tile; // NOTE: Uninline. - _wmFindCurTileFromPos(_world_xpos, _world_ypos, &tile); + wmFindCurTileFromPos(wmGenData.worldPosX, wmGenData.worldPosY, &tile); debugPrint("\nEncounter Difficulty Mod: %d", tile->encounterDifficultyModifier); outdoorsman += tile->encounterDifficultyModifier; @@ -3748,22 +3598,22 @@ int _wmRndEncounterOccurred() randomEncounterIsDetected = true; } - _old_world_xpos = _world_xpos; - _old_world_ypos = _world_ypos; + wmGenData.oldWorldPosX = wmGenData.worldPosX; + wmGenData.oldWorldPosY = wmGenData.worldPosY; if (randomEncounterIsDetected) { MessageListItem messageListItem; - const char* title = off_4BC878[0]; - const char* body = off_4BC878[1]; + const char* title = gWorldmapEncDefaultMsg[0]; + const char* body = gWorldmapEncDefaultMsg[1]; - title = getmsg(&gWorldmapMessageList, &messageListItem, 2999); - body = getmsg(&gWorldmapMessageList, &messageListItem, 3000 + 50 * dword_672E50 + dword_672E54); + title = getmsg(&wmMsgFile, &messageListItem, 2999); + body = getmsg(&wmMsgFile, &messageListItem, 3000 + 50 * wmGenData.encounterTableId + wmGenData.encounterEntryId); if (showDialogBox(title, &body, 1, 169, 116, _colorTable[32328], NULL, _colorTable[32328], DIALOG_BOX_LARGE | DIALOG_BOX_YES_NO) == 0) { - _wmEncounterIconShow = 0; - _EncounterMapID = -1; - dword_672E50 = -1; - dword_672E54 = -1; + wmGenData.encounterIconIsVisible = 0; + wmGenData.encounterMapId = -1; + wmGenData.encounterTableId = -1; + wmGenData.encounterEntryId = -1; return 0; } } @@ -3774,20 +3624,20 @@ int _wmRndEncounterOccurred() // NOTE: Inlined. // // 0x4C0BE4 -int _wmPartyFindCurSubTile() +static int wmPartyFindCurSubTile() { - return _wmFindCurSubTileFromPos(_world_xpos, _world_ypos, &_world_subtile); + return wmFindCurSubTileFromPos(wmGenData.worldPosX, wmGenData.worldPosY, &(wmGenData.currentSubtile)); } // 0x4C0C00 -int _wmFindCurSubTileFromPos(int x, int y, SubtileInfo** subtile) +static int wmFindCurSubTileFromPos(int x, int y, SubtileInfo** subtilePtr) { - int tileIndex = y / WM_TILE_HEIGHT * gWorldmapGridWidth + x / WM_TILE_WIDTH % gWorldmapGridWidth; - TileInfo* tile = &(gWorldmapTiles[tileIndex]); + int tileIndex = y / WM_TILE_HEIGHT * wmNumHorizontalTiles + x / WM_TILE_WIDTH % wmNumHorizontalTiles; + TileInfo* tile = &(wmTileInfoList[tileIndex]); int column = y % WM_TILE_HEIGHT / WM_SUBTILE_SIZE; int row = x % WM_TILE_WIDTH / WM_SUBTILE_SIZE; - *subtile = &(tile->subtiles[column][row]); + *subtilePtr = &(tile->subtiles[column][row]); return 0; } @@ -3795,25 +3645,25 @@ int _wmFindCurSubTileFromPos(int x, int y, SubtileInfo** subtile) // NOTE: Inlined. // // 0x4C0CA8 -int _wmFindCurTileFromPos(int x, int y, TileInfo** tile) +static int wmFindCurTileFromPos(int x, int y, TileInfo** tilePtr) { - int tileIndex = y / WM_TILE_HEIGHT * gWorldmapGridWidth + x / WM_TILE_WIDTH % gWorldmapGridWidth; - *tile = &(gWorldmapTiles[tileIndex]); + int tileIndex = y / WM_TILE_HEIGHT * wmNumHorizontalTiles + x / WM_TILE_WIDTH % wmNumHorizontalTiles; + *tilePtr = &(wmTileInfoList[tileIndex]); return 0; } // 0x4C0CF4 -int _wmRndEncounterPick() +static int wmRndEncounterPick() { - if (_world_subtile == NULL) { + if (wmGenData.currentSubtile == NULL) { // NOTE: Uninline. - _wmPartyFindCurSubTile(); + wmPartyFindCurSubTile(); } - dword_672E50 = _world_subtile->encounterType; + wmGenData.encounterTableId = wmGenData.currentSubtile->encounterType; - EncounterTable* encounterTable = &(gEncounterTables[dword_672E50]); + EncounterTable* encounterTable = &(wmEncounterTableList[wmGenData.encounterTableId]); int candidates[41]; int candidatesLength = 0; @@ -3822,7 +3672,7 @@ int _wmRndEncounterPick() EncounterEntry* encounterTableEntry = &(encounterTable->entries[index]); bool selected = true; - if (_wmEvalConditional(&(encounterTableEntry->condition), NULL) == 0) { + if (wmEvalConditional(&(encounterTableEntry->condition), NULL) == 0) { selected = false; } @@ -3883,48 +3733,47 @@ int _wmRndEncounterPick() index = candidatesLength - 1; } - dword_672E54 = candidates[index]; + wmGenData.encounterEntryId = candidates[index]; - EncounterEntry* encounterTableEntry = &(encounterTable->entries[dword_672E54]); + EncounterEntry* encounterTableEntry = &(encounterTable->entries[wmGenData.encounterEntryId]); if (encounterTableEntry->counter > 0) { encounterTableEntry->counter--; } if (encounterTableEntry->map == -1) { if (encounterTable->mapsLength <= 0) { - Terrain* terrain = &(gTerrains[_world_subtile->terrain]); - int randomMapIndex = randomBetween(0, terrain->mapsLength - 1); - _EncounterMapID = terrain->maps[randomMapIndex]; + Terrain* terrain = &(wmTerrainTypeList[wmGenData.currentSubtile->terrain]); + int randommapIdx = randomBetween(0, terrain->mapsLength - 1); + wmGenData.encounterMapId = terrain->maps[randommapIdx]; } else { - int randomMapIndex = randomBetween(0, encounterTable->mapsLength - 1); - _EncounterMapID = encounterTable->maps[randomMapIndex]; + int randommapIdx = randomBetween(0, encounterTable->mapsLength - 1); + wmGenData.encounterMapId = encounterTable->maps[randommapIdx]; } } else { - _EncounterMapID = encounterTableEntry->map; + wmGenData.encounterMapId = encounterTableEntry->map; } return 0; } -// wmSetupRandomEncounter // 0x4C0FA4 -int worldmapSetupRandomEncounter() +int wmSetupRandomEncounter() { MessageListItem messageListItem; char* msg; - if (_EncounterMapID == -1) { + if (wmGenData.encounterMapId == -1) { return 0; } - EncounterTable* encounterTable = &(gEncounterTables[dword_672E50]); - EncounterEntry* encounterTableEntry = &(encounterTable->entries[dword_672E54]); + EncounterTable* encounterTable = &(wmEncounterTableList[wmGenData.encounterTableId]); + EncounterEntry* encounterTableEntry = &(encounterTable->entries[wmGenData.encounterEntryId]); // You encounter: - msg = getmsg(&gWorldmapMessageList, &messageListItem, 2998); + msg = getmsg(&wmMsgFile, &messageListItem, 2998); displayMonitorAddMessage(msg); - msg = getmsg(&gWorldmapMessageList, &messageListItem, 3000 + 50 * dword_672E50 + dword_672E54); + msg = getmsg(&wmMsgFile, &messageListItem, 3000 + 50 * wmGenData.encounterTableId + wmGenData.encounterEntryId); displayMonitorAddMessage(msg); int gameDifficulty; @@ -3933,7 +3782,7 @@ int worldmapSetupRandomEncounter() case ENCOUNTER_SCENERY_TYPE_LIGHT: case ENCOUNTER_SCENERY_TYPE_NORMAL: case ENCOUNTER_SCENERY_TYPE_HEAVY: - debugPrint("\nwmSetupRandomEncounter: Scenery Type: %s", _wmSceneryStrs[encounterTableEntry->scenery]); + debugPrint("\nwmSetupRandomEncounter: Scenery Type: %s", wmSceneryStrs[encounterTableEntry->scenery]); configGetInt(&gGameConfig, GAME_CONFIG_PREFERENCES_KEY, GAME_CONFIG_GAME_DIFFICULTY_KEY, &gameDifficulty); break; default: @@ -3966,7 +3815,7 @@ int worldmapSetupRandomEncounter() if (v9 != 0) { Object* v35; - if (worldmapSetupCritters(v3->field_8, &v35, v9) == -1) { + if (wmSetupCritterObjs(v3->field_8, &v35, v9) == -1) { scriptsRequestWorldMap(); return -1; } @@ -4023,7 +3872,7 @@ int worldmapSetupRandomEncounter() // wmSetupCritterObjs // 0x4C11FC -int worldmapSetupCritters(int type_idx, Object** critterPtr, int critterCount) +static int wmSetupCritterObjs(int type_idx, Object** critterPtr, int critterCount) { if (type_idx == -1) { return 0; @@ -4031,11 +3880,11 @@ int worldmapSetupCritters(int type_idx, Object** critterPtr, int critterCount) *critterPtr = 0; - ENC_BASE_TYPE* v25 = &(_wmEncBaseTypeList[type_idx]); + ENC_BASE_TYPE* v25 = &(wmEncBaseTypeList[type_idx]); - debugPrint("\nwmSetupCritterObjs: typeIdx: %d, Formation: %s", type_idx, gEncounterFormationTypeKeys[v25->position]); + debugPrint("\nwmSetupCritterObjs: typeIdx: %d, Formation: %s", type_idx, wmFormationStrs[v25->position]); - if (_wmSetupRndNextTileNumInit(v25) == -1) { + if (wmSetupRndNextTileNumInit(v25) == -1) { return -1; } @@ -4046,7 +3895,7 @@ int worldmapSetupCritters(int type_idx, Object** critterPtr, int critterCount) continue; } - if (!_wmEvalConditional(&(v5->condition), &critterCount)) { + if (!wmEvalConditional(&(v5->condition), &critterCount)) { continue; } @@ -4068,7 +3917,7 @@ int worldmapSetupCritters(int type_idx, Object** critterPtr, int critterCount) for (int j = 0; j < v23; j++) { int tile; - if (_wmSetupRndNextTileNum(v25, v5, &tile) == -1) { + if (wmSetupRndNextTileNum(v25, v5, &tile) == -1) { debugPrint("\nERROR: wmSetupCritterObjs: wmSetupRndNextTileNum:"); continue; } @@ -4156,28 +4005,28 @@ int worldmapSetupCritters(int type_idx, Object** critterPtr, int critterCount) } // 0x4C155C -int _wmSetupRndNextTileNumInit(ENC_BASE_TYPE* a1) +static int wmSetupRndNextTileNumInit(ENC_BASE_TYPE* a1) { for (int index = 0; index < 2; index++) { - _wmRndCenterRotations[index] = 0; - _wmRndTileDirs[index] = 0; - _wmRndCenterTiles[index] = -1; + wmRndCenterRotations[index] = 0; + wmRndTileDirs[index] = 0; + wmRndCenterTiles[index] = -1; if (index & 1) { - _wmRndRotOffsets[index] = 5; + wmRndRotOffsets[index] = 5; } else { - _wmRndRotOffsets[index] = 1; + wmRndRotOffsets[index] = 1; } } - _wmRndCallCount = 0; + wmRndCallCount = 0; switch (a1->position) { case ENCOUNTER_FORMATION_TYPE_SURROUNDING: - _wmRndCenterTiles[0] = gDude->tile; - _wmRndTileDirs[0] = randomBetween(0, ROTATION_COUNT - 1); + wmRndCenterTiles[0] = gDude->tile; + wmRndTileDirs[0] = randomBetween(0, ROTATION_COUNT - 1); - _wmRndOriginalCenterTile = _wmRndCenterTiles[0]; + wmRndOriginalCenterTile = wmRndCenterTiles[0]; return 0; case ENCOUNTER_FORMATION_TYPE_STRAIGHT_LINE: @@ -4186,28 +4035,28 @@ int _wmSetupRndNextTileNumInit(ENC_BASE_TYPE* a1) case ENCOUNTER_FORMATION_TYPE_CONE: case ENCOUNTER_FORMATION_TYPE_HUDDLE: if (1) { - MapInfo* map = &(gMaps[gMapHeader.field_34]); + MapInfo* map = &(wmMapInfoList[gMapHeader.field_34]); if (map->startPointsLength != 0) { int rspIndex = randomBetween(0, map->startPointsLength - 1); MapStartPointInfo* rsp = &(map->startPoints[rspIndex]); - _wmRndCenterTiles[0] = rsp->tile; - _wmRndCenterTiles[1] = _wmRndCenterTiles[0]; + wmRndCenterTiles[0] = rsp->tile; + wmRndCenterTiles[1] = wmRndCenterTiles[0]; - _wmRndCenterRotations[0] = rsp->field_8; - _wmRndCenterRotations[1] = _wmRndCenterRotations[0]; + wmRndCenterRotations[0] = rsp->field_8; + wmRndCenterRotations[1] = wmRndCenterRotations[0]; } else { - _wmRndCenterRotations[0] = 0; - _wmRndCenterRotations[1] = 0; + wmRndCenterRotations[0] = 0; + wmRndCenterRotations[1] = 0; - _wmRndCenterTiles[0] = gDude->tile; - _wmRndCenterTiles[1] = gDude->tile; + wmRndCenterTiles[0] = gDude->tile; + wmRndCenterTiles[1] = gDude->tile; } - _wmRndTileDirs[0] = tileGetRotationTo(_wmRndCenterTiles[0], gDude->tile); - _wmRndTileDirs[1] = tileGetRotationTo(_wmRndCenterTiles[1], gDude->tile); + wmRndTileDirs[0] = tileGetRotationTo(wmRndCenterTiles[0], gDude->tile); + wmRndTileDirs[1] = tileGetRotationTo(wmRndCenterTiles[1], gDude->tile); - _wmRndOriginalCenterTile = _wmRndCenterTiles[0]; + wmRndOriginalCenterTile = wmRndCenterTiles[0]; return 0; } @@ -4220,7 +4069,7 @@ int _wmSetupRndNextTileNumInit(ENC_BASE_TYPE* a1) // wmSetupRndNextTileNum // 0x4C16F0 -int _wmSetupRndNextTileNum(ENC_BASE_TYPE* a1, ENC_BASE_TYPE_38* a2, int* out_tile_num) +static int wmSetupRndNextTileNum(ENC_BASE_TYPE* a1, ENC_BASE_TYPE_38* a2, int* out_tile_num) { int tile_num; @@ -4248,62 +4097,62 @@ int _wmSetupRndNextTileNum(ENC_BASE_TYPE* a1, ENC_BASE_TYPE_38* a2, int* out_til int origin = a2->tile; if (origin == -1) { - origin = tileGetTileInDirection(gDude->tile, _wmRndTileDirs[0], distance); + origin = tileGetTileInDirection(gDude->tile, wmRndTileDirs[0], distance); } - if (++_wmRndTileDirs[0] >= ROTATION_COUNT) { - _wmRndTileDirs[0] = 0; + if (++wmRndTileDirs[0] >= ROTATION_COUNT) { + wmRndTileDirs[0] = 0; } int randomizedDistance = randomBetween(0, distance / 2); int randomizedRotation = randomBetween(0, ROTATION_COUNT - 1); - tile_num = tileGetTileInDirection(origin, (randomizedRotation + _wmRndTileDirs[0]) % ROTATION_COUNT, randomizedDistance); + tile_num = tileGetTileInDirection(origin, (randomizedRotation + wmRndTileDirs[0]) % ROTATION_COUNT, randomizedDistance); } break; case ENCOUNTER_FORMATION_TYPE_STRAIGHT_LINE: - tile_num = _wmRndCenterTiles[_wmRndIndex]; - if (_wmRndCallCount != 0) { - int rotation = (_wmRndRotOffsets[_wmRndIndex] + _wmRndTileDirs[_wmRndIndex]) % ROTATION_COUNT; - int origin = tileGetTileInDirection(_wmRndCenterTiles[_wmRndIndex], rotation, a1->spacing); - int v13 = tileGetTileInDirection(origin, (rotation + _wmRndRotOffsets[_wmRndIndex]) % ROTATION_COUNT, a1->spacing); - _wmRndCenterTiles[_wmRndIndex] = v13; - _wmRndIndex = 1 - _wmRndIndex; + tile_num = wmRndCenterTiles[wmRndIndex]; + if (wmRndCallCount != 0) { + int rotation = (wmRndRotOffsets[wmRndIndex] + wmRndTileDirs[wmRndIndex]) % ROTATION_COUNT; + int origin = tileGetTileInDirection(wmRndCenterTiles[wmRndIndex], rotation, a1->spacing); + int v13 = tileGetTileInDirection(origin, (rotation + wmRndRotOffsets[wmRndIndex]) % ROTATION_COUNT, a1->spacing); + wmRndCenterTiles[wmRndIndex] = v13; + wmRndIndex = 1 - wmRndIndex; tile_num = v13; } break; case ENCOUNTER_FORMATION_TYPE_DOUBLE_LINE: - tile_num = _wmRndCenterTiles[_wmRndIndex]; - if (_wmRndCallCount != 0) { - int rotation = (_wmRndRotOffsets[_wmRndIndex] + _wmRndTileDirs[_wmRndIndex]) % ROTATION_COUNT; - int origin = tileGetTileInDirection(_wmRndCenterTiles[_wmRndIndex], rotation, a1->spacing); - int v17 = tileGetTileInDirection(origin, (rotation + _wmRndRotOffsets[_wmRndIndex]) % ROTATION_COUNT, a1->spacing); - _wmRndCenterTiles[_wmRndIndex] = v17; - _wmRndIndex = 1 - _wmRndIndex; + tile_num = wmRndCenterTiles[wmRndIndex]; + if (wmRndCallCount != 0) { + int rotation = (wmRndRotOffsets[wmRndIndex] + wmRndTileDirs[wmRndIndex]) % ROTATION_COUNT; + int origin = tileGetTileInDirection(wmRndCenterTiles[wmRndIndex], rotation, a1->spacing); + int v17 = tileGetTileInDirection(origin, (rotation + wmRndRotOffsets[wmRndIndex]) % ROTATION_COUNT, a1->spacing); + wmRndCenterTiles[wmRndIndex] = v17; + wmRndIndex = 1 - wmRndIndex; tile_num = v17; } break; case ENCOUNTER_FORMATION_TYPE_WEDGE: - tile_num = _wmRndCenterTiles[_wmRndIndex]; - if (_wmRndCallCount != 0) { - tile_num = tileGetTileInDirection(_wmRndCenterTiles[_wmRndIndex], (_wmRndRotOffsets[_wmRndIndex] + _wmRndTileDirs[_wmRndIndex]) % ROTATION_COUNT, a1->spacing); - _wmRndCenterTiles[_wmRndIndex] = tile_num; - _wmRndIndex = 1 - _wmRndIndex; + tile_num = wmRndCenterTiles[wmRndIndex]; + if (wmRndCallCount != 0) { + tile_num = tileGetTileInDirection(wmRndCenterTiles[wmRndIndex], (wmRndRotOffsets[wmRndIndex] + wmRndTileDirs[wmRndIndex]) % ROTATION_COUNT, a1->spacing); + wmRndCenterTiles[wmRndIndex] = tile_num; + wmRndIndex = 1 - wmRndIndex; } break; case ENCOUNTER_FORMATION_TYPE_CONE: - tile_num = _wmRndCenterTiles[_wmRndIndex]; - if (_wmRndCallCount != 0) { - tile_num = tileGetTileInDirection(_wmRndCenterTiles[_wmRndIndex], (_wmRndTileDirs[_wmRndIndex] + 3 + _wmRndRotOffsets[_wmRndIndex]) % ROTATION_COUNT, a1->spacing); - _wmRndCenterTiles[_wmRndIndex] = tile_num; - _wmRndIndex = 1 - _wmRndIndex; + tile_num = wmRndCenterTiles[wmRndIndex]; + if (wmRndCallCount != 0) { + tile_num = tileGetTileInDirection(wmRndCenterTiles[wmRndIndex], (wmRndTileDirs[wmRndIndex] + 3 + wmRndRotOffsets[wmRndIndex]) % ROTATION_COUNT, a1->spacing); + wmRndCenterTiles[wmRndIndex] = tile_num; + wmRndIndex = 1 - wmRndIndex; } break; case ENCOUNTER_FORMATION_TYPE_HUDDLE: - tile_num = _wmRndCenterTiles[0]; - if (_wmRndCallCount != 0) { - _wmRndTileDirs[0] = (_wmRndTileDirs[0] + 1) % ROTATION_COUNT; - tile_num = tileGetTileInDirection(_wmRndCenterTiles[0], _wmRndTileDirs[0], a1->spacing); - _wmRndCenterTiles[0] = tile_num; + tile_num = wmRndCenterTiles[0]; + if (wmRndCallCount != 0) { + wmRndTileDirs[0] = (wmRndTileDirs[0] + 1) % ROTATION_COUNT; + tile_num = tileGetTileInDirection(wmRndCenterTiles[0], wmRndTileDirs[0], a1->spacing); + wmRndCenterTiles[0] = tile_num; } break; default: @@ -4311,15 +4160,15 @@ int _wmSetupRndNextTileNum(ENC_BASE_TYPE* a1, ENC_BASE_TYPE_38* a2, int* out_til } ++attempt; - ++_wmRndCallCount; + ++wmRndCallCount; - if (_wmEvalTileNumForPlacement(tile_num)) { + if (wmEvalTileNumForPlacement(tile_num)) { break; } debugPrint("\nWARNING: EVAL-TILE-NUM FAILED!"); - if (tileDistanceBetween(_wmRndOriginalCenterTile, _wmRndCenterTiles[_wmRndIndex]) > 25) { + if (tileDistanceBetween(wmRndOriginalCenterTile, wmRndCenterTiles[wmRndIndex]) > 25) { return -1; } @@ -4336,7 +4185,7 @@ int _wmSetupRndNextTileNum(ENC_BASE_TYPE* a1, ENC_BASE_TYPE_38* a2, int* out_til } // 0x4C1A64 -bool _wmEvalTileNumForPlacement(int tile) +bool wmEvalTileNumForPlacement(int tile) { if (_obj_blocking_at(gDude, tile, gElevation) != NULL) { return false; @@ -4350,7 +4199,7 @@ bool _wmEvalTileNumForPlacement(int tile) } // 0x4C1AC8 -bool _wmEvalConditional(EncounterCondition* a1, int* a2) +static bool wmEvalConditional(EncounterCondition* a1, int* a2) { int value; @@ -4362,12 +4211,12 @@ bool _wmEvalConditional(EncounterCondition* a1, int* a2) switch (ptr->type) { case ENCOUNTER_CONDITION_TYPE_GLOBAL: value = gameGetGlobalVar(ptr->param); - if (!_wmEvalSubConditional(value, ptr->conditionalOperator, ptr->value)) { + if (!wmEvalSubConditional(value, ptr->conditionalOperator, ptr->value)) { matches = false; } break; case ENCOUNTER_CONDITION_TYPE_NUMBER_OF_CRITTERS: - if (!_wmEvalSubConditional(*a2, ptr->conditionalOperator, ptr->value)) { + if (!wmEvalSubConditional(*a2, ptr->conditionalOperator, ptr->value)) { matches = false; } break; @@ -4379,19 +4228,19 @@ bool _wmEvalConditional(EncounterCondition* a1, int* a2) break; case ENCOUNTER_CONDITION_TYPE_PLAYER: value = pcGetStat(PC_STAT_LEVEL); - if (!_wmEvalSubConditional(value, ptr->conditionalOperator, ptr->value)) { + if (!wmEvalSubConditional(value, ptr->conditionalOperator, ptr->value)) { matches = false; } break; case ENCOUNTER_CONDITION_TYPE_DAYS_PLAYED: value = gameTimeGetTime(); - if (!_wmEvalSubConditional(value / GAME_TIME_TICKS_PER_DAY, ptr->conditionalOperator, ptr->value)) { + if (!wmEvalSubConditional(value / GAME_TIME_TICKS_PER_DAY, ptr->conditionalOperator, ptr->value)) { matches = false; } break; case ENCOUNTER_CONDITION_TYPE_TIME_OF_DAY: value = gameTimeGetHour(); - if (!_wmEvalSubConditional(value / 100, ptr->conditionalOperator, ptr->value)) { + if (!wmEvalSubConditional(value / 100, ptr->conditionalOperator, ptr->value)) { matches = false; } break; @@ -4409,7 +4258,7 @@ bool _wmEvalConditional(EncounterCondition* a1, int* a2) } // 0x4C1C0C -bool _wmEvalSubConditional(int operand1, int condionalOperator, int operand2) +static bool wmEvalSubConditional(int operand1, int condionalOperator, int operand2) { switch (condionalOperator) { case ENCOUNTER_CONDITIONAL_OPERATOR_EQUAL: @@ -4426,7 +4275,7 @@ bool _wmEvalSubConditional(int operand1, int condionalOperator, int operand2) } // 0x4C1C50 -bool _wmGameTimeIncrement(int ticksToAdd) +static bool wmGameTimeIncrement(int ticksToAdd) { if (ticksToAdd == 0) { return false; @@ -4449,7 +4298,7 @@ bool _wmGameTimeIncrement(int ticksToAdd) // NOTE: Uninline. wmInterfaceDialSyncTime(true); - worldmapWindowRenderDate(true); + wmInterfaceRefreshDate(true); if (queueProcessEvents()) { break; @@ -4462,9 +4311,9 @@ bool _wmGameTimeIncrement(int ticksToAdd) // Reads .msk file if needed. // // 0x4C1CE8 -int _wmGrabTileWalkMask(int tile) +static int wmGrabTileWalkMask(int tileIdx) { - TileInfo* tileInfo = &(gWorldmapTiles[tile]); + TileInfo* tileInfo = &(wmTileInfoList[tileIdx]); if (tileInfo->walkMaskData != NULL) { return 0; } @@ -4498,14 +4347,14 @@ int _wmGrabTileWalkMask(int tile) } // 0x4C1D9C -bool _wmWorldPosInvalid(int a1, int a2) +static bool wmWorldPosInvalid(int x, int y) { - int v3 = a2 / WM_TILE_HEIGHT * gWorldmapGridWidth + a1 / WM_TILE_WIDTH % gWorldmapGridWidth; - if (_wmGrabTileWalkMask(v3) == -1) { + int tileIdx = y / WM_TILE_HEIGHT * wmNumHorizontalTiles + x / WM_TILE_WIDTH % wmNumHorizontalTiles; + if (wmGrabTileWalkMask(tileIdx) == -1) { return false; } - TileInfo* tileDescription = &(gWorldmapTiles[v3]); + TileInfo* tileDescription = &(wmTileInfoList[tileIdx]); unsigned char* mask = tileDescription->walkMaskData; if (mask == NULL) { return false; @@ -4514,61 +4363,61 @@ bool _wmWorldPosInvalid(int a1, int a2) // Mask length is 13200, which is 300 * 44 // 44 * 8 is 352, which is probably left 2 bytes intact // TODO: Check math. - int pos = (a2 % WM_TILE_HEIGHT) * 44 + (a1 % WM_TILE_WIDTH) / 8; - int bit = 1 << (((a1 % WM_TILE_WIDTH) / 8) & 3); + int pos = (y % WM_TILE_HEIGHT) * 44 + (x % WM_TILE_WIDTH) / 8; + int bit = 1 << (((x % WM_TILE_WIDTH) / 8) & 3); return (mask[pos] & bit) != 0; } // 0x4C1E54 -void _wmPartyInitWalking(int x, int y) +static void wmPartyInitWalking(int x, int y) { - gWorldmapTravelDestX = x; - gWorldmapTravelDestY = y; - _WorldMapCurrArea = -1; - gWorldmapIsTravelling = true; + wmGenData.walkDestinationX = x; + wmGenData.walkDestinationY = y; + wmGenData.currentAreaId = -1; + wmGenData.isWalking = true; - int dx = abs(x - _world_xpos); - int dy = abs(y - _world_ypos); + int dx = abs(x - wmGenData.worldPosX); + int dy = abs(y - wmGenData.worldPosY); if (dx < dy) { - dword_672E28 = dy; - dword_672E30 = 2 * dx; - _x_line_inc = 0; - dword_672E2C = 2 * dx - dy; - dword_672E34 = 2 * (dx - dy); - dword_672E3C = 1; - _y_line_inc = 1; - dword_672E44 = 1; + wmGenData.walkDistance = dy; + wmGenData.walkLineDeltaMainAxisStep = 2 * dx; + wmGenData.walkWorldPosMainAxisStepX = 0; + wmGenData.walkLineDelta = 2 * dx - dy; + wmGenData.walkLineDeltaCrossAxisStep = 2 * (dx - dy); + wmGenData.walkWorldPosCrossAxisStepX = 1; + wmGenData.walkWorldPosMainAxisStepY = 1; + wmGenData.walkWorldPosCrossAxisStepY = 1; } else { - dword_672E28 = dx; - dword_672E30 = 2 * dy; - _y_line_inc = 0; - dword_672E2C = 2 * dy - dx; - dword_672E34 = 2 * (dy - dx); - _x_line_inc = 1; - dword_672E3C = 1; - dword_672E44 = 1; + wmGenData.walkDistance = dx; + wmGenData.walkLineDeltaMainAxisStep = 2 * dy; + wmGenData.walkWorldPosMainAxisStepY = 0; + wmGenData.walkLineDelta = 2 * dy - dx; + wmGenData.walkLineDeltaCrossAxisStep = 2 * (dy - dx); + wmGenData.walkWorldPosMainAxisStepX = 1; + wmGenData.walkWorldPosCrossAxisStepX = 1; + wmGenData.walkWorldPosCrossAxisStepY = 1; } - if (gWorldmapTravelDestX < _world_xpos) { - dword_672E3C = -dword_672E3C; - _x_line_inc = -_x_line_inc; + if (wmGenData.walkDestinationX < wmGenData.worldPosX) { + wmGenData.walkWorldPosCrossAxisStepX = -wmGenData.walkWorldPosCrossAxisStepX; + wmGenData.walkWorldPosMainAxisStepX = -wmGenData.walkWorldPosMainAxisStepX; } - if (gWorldmapTravelDestY < _world_ypos) { - dword_672E44 = -dword_672E44; - _y_line_inc = -_y_line_inc; + if (wmGenData.walkDestinationY < wmGenData.worldPosY) { + wmGenData.walkWorldPosCrossAxisStepY = -wmGenData.walkWorldPosCrossAxisStepY; + wmGenData.walkWorldPosMainAxisStepY = -wmGenData.walkWorldPosMainAxisStepY; } - if (!_wmCursorIsVisible()) { - _wmInterfaceCenterOnParty(); + if (!wmCursorIsVisible()) { + wmInterfaceCenterOnParty(); } } // 0x4C1F90 -void worldmapPerformTravel() +static void wmPartyWalkingStep() { - if (dword_672E28 <= 0) { + if (wmGenData.walkDistance <= 0) { return; } @@ -4578,9 +4427,9 @@ void worldmapPerformTravel() } // NOTE: Uninline. - _wmPartyFindCurSubTile(); + wmPartyFindCurSubTile(); - Terrain* terrain = &(gTerrains[_world_subtile->terrain]); + Terrain* terrain = &(wmTerrainTypeList[wmGenData.currentSubtile->terrain]); // SFALL: Fix Pathfinder perk. int terrainDifficulty = terrain->difficulty; if (terrainDifficulty < 1) { @@ -4590,83 +4439,83 @@ void worldmapPerformTravel() if (_terrainCounter / terrainDifficulty >= 1) { int v3; int v4; - if (dword_672E2C >= 0) { - if (_wmWorldPosInvalid(dword_672E3C + _world_xpos, dword_672E44 + _world_ypos)) { - gWorldmapTravelDestX = 0; - gWorldmapTravelDestY = 0; - gWorldmapIsTravelling = false; - _wmMatchWorldPosToArea(_world_xpos, _world_xpos, &_WorldMapCurrArea); - dword_672E28 = 0; + if (wmGenData.walkLineDelta >= 0) { + if (wmWorldPosInvalid(wmGenData.walkWorldPosCrossAxisStepX + wmGenData.worldPosX, wmGenData.walkWorldPosCrossAxisStepY + wmGenData.worldPosY)) { + wmGenData.walkDestinationX = 0; + wmGenData.walkDestinationY = 0; + wmGenData.isWalking = false; + wmMatchWorldPosToArea(wmGenData.worldPosX, wmGenData.worldPosX, &(wmGenData.currentAreaId)); + wmGenData.walkDistance = 0; return; } - v3 = dword_672E3C; - dword_672E2C += dword_672E34; - _world_xpos += dword_672E3C; - v4 = dword_672E44; - _world_ypos += dword_672E44; + v3 = wmGenData.walkWorldPosCrossAxisStepX; + wmGenData.walkLineDelta += wmGenData.walkLineDeltaCrossAxisStep; + wmGenData.worldPosX += wmGenData.walkWorldPosCrossAxisStepX; + v4 = wmGenData.walkWorldPosCrossAxisStepY; + wmGenData.worldPosY += wmGenData.walkWorldPosCrossAxisStepY; } else { - if (_wmWorldPosInvalid(_x_line_inc + _world_xpos, _y_line_inc + _world_ypos) == 1) { - gWorldmapTravelDestX = 0; - gWorldmapTravelDestY = 0; - gWorldmapIsTravelling = false; - _wmMatchWorldPosToArea(_world_xpos, _world_xpos, &_WorldMapCurrArea); - dword_672E28 = 0; + if (wmWorldPosInvalid(wmGenData.walkWorldPosMainAxisStepX + wmGenData.worldPosX, wmGenData.walkWorldPosMainAxisStepY + wmGenData.worldPosY) == 1) { + wmGenData.walkDestinationX = 0; + wmGenData.walkDestinationY = 0; + wmGenData.isWalking = false; + wmMatchWorldPosToArea(wmGenData.worldPosX, wmGenData.worldPosX, &(wmGenData.currentAreaId)); + wmGenData.walkDistance = 0; return; } - v3 = _x_line_inc; - dword_672E2C += dword_672E30; - _world_ypos += _y_line_inc; - v4 = _y_line_inc; - _world_xpos += _x_line_inc; + v3 = wmGenData.walkWorldPosMainAxisStepX; + wmGenData.walkLineDelta += wmGenData.walkLineDeltaMainAxisStep; + wmGenData.worldPosY += wmGenData.walkWorldPosMainAxisStepY; + v4 = wmGenData.walkWorldPosMainAxisStepY; + wmGenData.worldPosX += wmGenData.walkWorldPosMainAxisStepX; } - worldmapWindowScroll(1, 1, v3, v4, NULL, false); + wmInterfaceScrollPixel(1, 1, v3, v4, NULL, false); - dword_672E28 -= 1; - if (dword_672E28 == 0) { - gWorldmapTravelDestY = 0; - gWorldmapIsTravelling = false; - gWorldmapTravelDestX = 0; + wmGenData.walkDistance -= 1; + if (wmGenData.walkDistance == 0) { + wmGenData.walkDestinationY = 0; + wmGenData.isWalking = false; + wmGenData.walkDestinationX = 0; } } } // 0x4C219C -void _wmInterfaceScrollTabsStart(int a1) +static void wmInterfaceScrollTabsStart(int delta) { int i; int v3; for (i = 0; i < 7; i++) { - buttonDisable(_wmTownMapSubButtonIds[i]); + buttonDisable(wmTownMapSubButtonIds[i]); } - dword_672F54 = _LastTabsYOffset; + wmGenData.oldTabsOffsetY = wmGenData.tabsOffsetY; - v3 = _LastTabsYOffset + 7 * a1; + v3 = wmGenData.tabsOffsetY + 7 * delta; - if (a1 >= 0) { - if (gWorldmapTownTabsUnderlayFrmHeight - 230 <= dword_672F54) { + if (delta >= 0) { + if (wmGenData.tabsBackgroundFrmHeight - 230 <= wmGenData.oldTabsOffsetY) { goto L11; } else { - dword_672F54 = _LastTabsYOffset + 7 * a1; - if (v3 > gWorldmapTownTabsUnderlayFrmHeight - 230) { + wmGenData.oldTabsOffsetY = wmGenData.tabsOffsetY + 7 * delta; + if (v3 > wmGenData.tabsBackgroundFrmHeight - 230) { } } } else { - if (_LastTabsYOffset <= 0) { + if (wmGenData.tabsOffsetY <= 0) { goto L11; } else { - dword_672F54 = _LastTabsYOffset + 7 * a1; + wmGenData.oldTabsOffsetY = wmGenData.tabsOffsetY + 7 * delta; if (v3 < 0) { - dword_672F54 = 0; + wmGenData.oldTabsOffsetY = 0; } } } - _tabsOffset = a1; + wmGenData.tabsScrollingDelta = delta; L11: @@ -4675,14 +4524,14 @@ L11: } // 0x4C2270 -void _wmInterfaceScrollTabsStop() +static void wmInterfaceScrollTabsStop() { int i; - _tabsOffset = 0; + wmGenData.tabsScrollingDelta = 0; for (i = 0; i < 7; i++) { - buttonEnable(_wmTownMapSubButtonIds[i]); + buttonEnable(wmTownMapSubButtonIds[i]); } } @@ -4691,42 +4540,42 @@ void _wmInterfaceScrollTabsStop() // 0x4C2290 static void wmInterfaceScrollTabsUpdate() { - if (_tabsOffset != 0) { - _LastTabsYOffset += _tabsOffset; - worldmapWindowRenderChrome(1); + if (wmGenData.tabsScrollingDelta != 0) { + wmGenData.tabsOffsetY += wmGenData.tabsScrollingDelta; + wmRefreshInterfaceOverlay(1); - if (_tabsOffset >= 0) { - if (dword_672F54 <= _LastTabsYOffset) { + if (wmGenData.tabsScrollingDelta >= 0) { + if (wmGenData.oldTabsOffsetY <= wmGenData.tabsOffsetY) { // NOTE: Uninline. - _wmInterfaceScrollTabsStop(); + wmInterfaceScrollTabsStop(); } } else { - if (dword_672F54 >= _LastTabsYOffset) { + if (wmGenData.oldTabsOffsetY >= wmGenData.tabsOffsetY) { // NOTE: Uninline. - _wmInterfaceScrollTabsStop(); + wmInterfaceScrollTabsStop(); } } } } // 0x4C2324 -int worldmapWindowInit() +static int wmInterfaceInit() { int fid; Art* frm; CacheEntry* frmHandle; - _wmLastRndTime = _get_time(); + wmLastRndTime = _get_time(); // SFALL: Fix default worldmap font. // CE: This setting affects only city names. In Sfall it's configurable via // WorldMapFontPatch and is turned off by default. - _fontnum = fontGetCurrent(); + wmGenData.oldFont = fontGetCurrent(); fontSetCurrent(101); _map_save_in_game(true); - const char* backgroundSoundFileName = gWorldmapIsInCar ? "20car" : "23world"; + const char* backgroundSoundFileName = wmGenData.isInCar ? "20car" : "23world"; _gsound_background_play_level_music(backgroundSoundFileName, 12); indicatorBarHide(); @@ -4736,38 +4585,38 @@ int worldmapWindowInit() int worldmapWindowX = (screenGetWidth() - WM_WINDOW_WIDTH) / 2; int worldmapWindowY = (screenGetHeight() - WM_WINDOW_HEIGHT) / 2; - gWorldmapWindow = windowCreate(worldmapWindowX, worldmapWindowY, WM_WINDOW_WIDTH, WM_WINDOW_HEIGHT, _colorTable[0], WINDOW_FLAG_0x04); - if (gWorldmapWindow == -1) { + wmBkWin = windowCreate(worldmapWindowX, worldmapWindowY, WM_WINDOW_WIDTH, WM_WINDOW_HEIGHT, _colorTable[0], WINDOW_FLAG_0x04); + if (wmBkWin == -1) { return -1; } fid = buildFid(OBJ_TYPE_INTERFACE, 136, 0, 0, 0); - frm = artLock(fid, &gWorldmapBoxFrmHandle); + frm = artLock(fid, &wmBkKey); if (frm == NULL) { return -1; } - gWorldmapBoxFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapBoxFrmHeight = artGetHeight(frm, 0, 0); + wmBkWidth = artGetWidth(frm, 0, 0); + wmBkHeight = artGetHeight(frm, 0, 0); - artUnlock(gWorldmapBoxFrmHandle); - gWorldmapBoxFrmHandle = INVALID_CACHE_ENTRY; + artUnlock(wmBkKey); + wmBkKey = INVALID_CACHE_ENTRY; fid = buildFid(OBJ_TYPE_INTERFACE, 136, 0, 0, 0); - gWorldmapBoxFrmData = artLockFrameData(fid, 0, 0, &gWorldmapBoxFrmHandle); - if (gWorldmapBoxFrmData == NULL) { + wmBkArtBuf = artLockFrameData(fid, 0, 0, &wmBkKey); + if (wmBkArtBuf == NULL) { return -1; } - gWorldmapWindowBuffer = windowGetBuffer(gWorldmapWindow); - if (gWorldmapWindowBuffer == NULL) { + wmBkWinBuf = windowGetBuffer(wmBkWin); + if (wmBkWinBuf == NULL) { return -1; } - blitBufferToBuffer(gWorldmapBoxFrmData, gWorldmapBoxFrmWidth, gWorldmapBoxFrmHeight, gWorldmapBoxFrmWidth, gWorldmapWindowBuffer, WM_WINDOW_WIDTH); + blitBufferToBuffer(wmBkArtBuf, wmBkWidth, wmBkHeight, wmBkWidth, wmBkWinBuf, WM_WINDOW_WIDTH); for (int citySize = 0; citySize < CITY_SIZE_COUNT; citySize++) { - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[citySize]); + CitySizeDescription* citySizeDescription = &(wmSphereData[citySize]); fid = buildFid(OBJ_TYPE_INTERFACE, 336 + citySize, 0, 0, 0); citySizeDescription->fid = fid; @@ -4791,86 +4640,86 @@ int worldmapWindowInit() } fid = buildFid(OBJ_TYPE_INTERFACE, 168, 0, 0, 0); - frm = artLock(fid, &gWorldmapHotspotUpFrmHandle); + frm = artLock(fid, &(wmGenData.hotspotNormalFrmHandle)); if (frm == NULL) { return -1; } - gWorldmapHotspotUpFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapHotspotUpFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.hotspotFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.hotspotFrmHeight = artGetHeight(frm, 0, 0); - artUnlock(gWorldmapHotspotUpFrmHandle); - gWorldmapHotspotUpFrmHandle = INVALID_CACHE_ENTRY; + artUnlock(wmGenData.hotspotNormalFrmHandle); + wmGenData.hotspotNormalFrmHandle = INVALID_CACHE_ENTRY; // hotspot1.frm - town map selector shape #1 fid = buildFid(OBJ_TYPE_INTERFACE, 168, 0, 0, 0); - gWorldmapHotspotUpFrmData = artLockFrameData(fid, 0, 0, &gWorldmapHotspotUpFrmHandle); + wmGenData.hotspotNormalFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.hotspotNormalFrmHandle)); // hotspot2.frm - town map selector shape #2 fid = buildFid(OBJ_TYPE_INTERFACE, 223, 0, 0, 0); - gWorldmapHotspotDownFrmData = artLockFrameData(fid, 0, 0, &gWorldmapHotspotDownFrmHandle); - if (gWorldmapHotspotDownFrmData == NULL) { + wmGenData.hotspotPressedFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.hotspotPressedFrmHandle)); + if (wmGenData.hotspotPressedFrmData == NULL) { return -1; } // wmaptarg.frm - world map move target maker #1 fid = buildFid(OBJ_TYPE_INTERFACE, 139, 0, 0, 0); - frm = artLock(fid, &gWorldmapDestinationMarkerFrmHandle); + frm = artLock(fid, &(wmGenData.destinationMarkerFrmHandle)); if (frm == NULL) { return -1; } - gWorldmapDestinationMarkerFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapDestinationMarkerFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.destinationMarkerFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.destinationMarkerFrmHeight = artGetHeight(frm, 0, 0); - artUnlock(gWorldmapDestinationMarkerFrmHandle); - gWorldmapDestinationMarkerFrmHandle = INVALID_CACHE_ENTRY; + artUnlock(wmGenData.destinationMarkerFrmHandle); + wmGenData.destinationMarkerFrmHandle = INVALID_CACHE_ENTRY; // wmaploc.frm - world map location marker fid = buildFid(OBJ_TYPE_INTERFACE, 138, 0, 0, 0); - frm = artLock(fid, &gWorldmapLocationMarkerFrmHandle); + frm = artLock(fid, &(wmGenData.locationMarkerFrmHandle)); if (frm == NULL) { return -1; } - gWorldmapLocationMarkerFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapLocationMarkerFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.locationMarkerFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.locationMarkerFrmHeight = artGetHeight(frm, 0, 0); - artUnlock(gWorldmapLocationMarkerFrmHandle); - gWorldmapLocationMarkerFrmHandle = INVALID_CACHE_ENTRY; + artUnlock(wmGenData.locationMarkerFrmHandle); + wmGenData.locationMarkerFrmHandle = INVALID_CACHE_ENTRY; // wmaptarg.frm - world map move target maker #1 fid = buildFid(OBJ_TYPE_INTERFACE, 139, 0, 0, 0); - gWorldmapDestinationMarkerFrmData = artLockFrameData(fid, 0, 0, &gWorldmapDestinationMarkerFrmHandle); - if (gWorldmapDestinationMarkerFrmData == NULL) { + wmGenData.destinationMarkerFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.destinationMarkerFrmHandle)); + if (wmGenData.destinationMarkerFrmData == NULL) { return -1; } // wmaploc.frm - world map location marker fid = buildFid(OBJ_TYPE_INTERFACE, 138, 0, 0, 0); - gWorldmapLocationMarkerFrmData = artLockFrameData(fid, 0, 0, &gWorldmapLocationMarkerFrmHandle); - if (gWorldmapLocationMarkerFrmData == NULL) { + wmGenData.locationMarkerFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.locationMarkerFrmHandle)); + if (wmGenData.locationMarkerFrmData == NULL) { return -1; } for (int index = 0; index < WORLD_MAP_ENCOUNTER_FRM_COUNT; index++) { - fid = buildFid(OBJ_TYPE_INTERFACE, gWorldmapEncounterFrmIds[index], 0, 0, 0); - frm = artLock(fid, &(gWorldmapEncounterFrmHandles[index])); + fid = buildFid(OBJ_TYPE_INTERFACE, wmRndCursorFids[index], 0, 0, 0); + frm = artLock(fid, &(wmGenData.encounterCursorFrmHandle[index])); if (frm == NULL) { return -1; } - gWorldmapEncounterFrmWidths[index] = artGetWidth(frm, 0, 0); - gWorldmapEncounterFrmHeights[index] = artGetHeight(frm, 0, 0); + wmGenData.encounterCursorFrmWidths[index] = artGetWidth(frm, 0, 0); + wmGenData.encounterCursorFrmHeights[index] = artGetHeight(frm, 0, 0); - artUnlock(gWorldmapEncounterFrmHandles[index]); + artUnlock(wmGenData.encounterCursorFrmHandle[index]); - gWorldmapEncounterFrmHandles[index] = INVALID_CACHE_ENTRY; - gWorldmapEncounterFrmData[index] = artLockFrameData(fid, 0, 0, &(gWorldmapEncounterFrmHandles[index])); + wmGenData.encounterCursorFrmHandle[index] = INVALID_CACHE_ENTRY; + wmGenData.encounterCursorFrmData[index] = artLockFrameData(fid, 0, 0, &(wmGenData.encounterCursorFrmHandle[index])); } - for (int index = 0; index < gWorldmapTilesLength; index++) { - gWorldmapTiles[index].handle = INVALID_CACHE_ENTRY; + for (int index = 0; index < wmMaxTileNum; index++) { + wmTileInfoList[index].handle = INVALID_CACHE_ENTRY; } // wmtabs.frm - worldmap town tabs underlay @@ -4880,32 +4729,32 @@ int worldmapWindowInit() return -1; } - gWorldmapTownTabsUnderlayFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapTownTabsUnderlayFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.tabsBackgroundFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.tabsBackgroundFrmHeight = artGetHeight(frm, 0, 0); artUnlock(frmHandle); - gWorldmapTownTabsUnderlayFrmData = artLockFrameData(fid, 0, 0, &gWorldmapTownTabsUnderlayFrmHandle) + gWorldmapTownTabsUnderlayFrmWidth * 27; - if (gWorldmapTownTabsUnderlayFrmData == NULL) { + wmGenData.tabsBackgroundFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.tabsBackgroundFrmHandle)) + wmGenData.tabsBackgroundFrmWidth * 27; + if (wmGenData.tabsBackgroundFrmData == NULL) { return -1; } // wmtbedge.frm - worldmap town tabs edging overlay fid = buildFid(OBJ_TYPE_INTERFACE, 367, 0, 0, 0); - gWorldmapTownTabsEdgeFrmData = artLockFrameData(fid, 0, 0, &gWorldmapTownTabsEdgeFrmHandle); - if (gWorldmapTownTabsEdgeFrmData == NULL) { + wmGenData.tabsBorderFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.tabsBorderFrmHandle)); + if (wmGenData.tabsBorderFrmData == NULL) { return -1; } // wmdial.frm - worldmap night/day dial fid = buildFid(OBJ_TYPE_INTERFACE, 365, 0, 0, 0); - gWorldmapDialFrm = artLock(fid, &gWorldmapDialFrmHandle); - if (gWorldmapDialFrm == NULL) { + wmGenData.dialFrm = artLock(fid, &(wmGenData.dialFrmHandle)); + if (wmGenData.dialFrm == NULL) { return -1; } - gWorldmapDialFrmWidth = artGetWidth(gWorldmapDialFrm, 0, 0); - gWorldmapDialFrmHeight = artGetHeight(gWorldmapDialFrm, 0, 0); + wmGenData.dialFrmWidth = artGetWidth(wmGenData.dialFrm, 0, 0); + wmGenData.dialFrmHeight = artGetHeight(wmGenData.dialFrm, 0, 0); // wmscreen - worldmap overlay screen fid = buildFid(OBJ_TYPE_INTERFACE, 363, 0, 0, 0); @@ -4914,13 +4763,13 @@ int worldmapWindowInit() return -1; } - gWorldmapCarOverlayFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapCarOverlayFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.carImageOverlayFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.carImageOverlayFrmHeight = artGetHeight(frm, 0, 0); artUnlock(frmHandle); - gWorldmapCarOverlayFrmData = artLockFrameData(fid, 0, 0, &gWorldmapCarOverlayFrmHandle); - if (gWorldmapCarOverlayFrmData == NULL) { + wmGenData.carImageOverlayFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.carImageOverlayFrmHandle)); + if (wmGenData.carImageOverlayFrmData == NULL) { return -1; } @@ -4931,13 +4780,13 @@ int worldmapWindowInit() return -1; } - gWorldmapGlobeOverlayFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapGloveOverlayFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.globeOverlayFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.globeOverlayFrmHeight = artGetHeight(frm, 0, 0); artUnlock(frmHandle); - gWorldmapGlobeOverlayFrmData = artLockFrameData(fid, 0, 0, &gWorldmapGlobeOverlayFrmHandle); - if (gWorldmapGlobeOverlayFrmData == NULL) { + wmGenData.globeOverlayFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.globeOverlayFrmHandle)); + if (wmGenData.globeOverlayFrmData == NULL) { return -1; } @@ -4953,28 +4802,28 @@ int worldmapWindowInit() artUnlock(frmHandle); - gWorldmapLittleRedButtonUpFrmData = artLockFrameData(fid, 0, 0, &gWorldmapLittleRedButtonUpFrmHandle); + wmGenData.littleRedButtonNormalFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.littleRedButtonNormalFrmHandle)); // lilreddn.frm - little red button down fid = buildFid(OBJ_TYPE_INTERFACE, 9, 0, 0, 0); - gWorldmapLittleRedButtonDownFrmData = artLockFrameData(fid, 0, 0, &gWorldmapLittleRedButtonDownFrmHandle); + wmGenData.littleRedButtonPressedFrmData = artLockFrameData(fid, 0, 0, &(wmGenData.littleRedButtonPressedFrmHandle)); // months.frm - month strings for pip boy fid = buildFid(OBJ_TYPE_INTERFACE, 129, 0, 0, 0); - gWorldmapMonthsFrm = artLock(fid, &gWorldmapMonthsFrmHandle); - if (gWorldmapMonthsFrm == NULL) { + wmGenData.monthsFrm = artLock(fid, &(wmGenData.monthsFrmHandle)); + if (wmGenData.monthsFrm == NULL) { return -1; } // numbers.frm - numbers for the hit points and fatigue counters fid = buildFid(OBJ_TYPE_INTERFACE, 82, 0, 0, 0); - gWorldmapNumbersFrm = artLock(fid, &gWorldmapNumbersFrmHandle); - if (gWorldmapNumbersFrm == NULL) { + wmGenData.numbersFrm = artLock(fid, &(wmGenData.numbersFrmHandle)); + if (wmGenData.numbersFrm == NULL) { return -1; } // create town/world switch button - int switchBtn = buttonCreate(gWorldmapWindow, + int switchBtn = buttonCreate(wmBkWin, WM_TOWN_WORLD_SWITCH_X, WM_TOWN_WORLD_SWITCH_Y, littleRedButtonUpWidth, @@ -4983,8 +4832,8 @@ int worldmapWindowInit() -1, -1, KEY_UPPERCASE_T, - gWorldmapLittleRedButtonUpFrmData, - gWorldmapLittleRedButtonDownFrmData, + wmGenData.littleRedButtonNormalFrmData, + wmGenData.littleRedButtonPressedFrmData, NULL, BUTTON_FLAG_TRANSPARENT); @@ -4994,7 +4843,7 @@ int worldmapWindowInit() } for (int index = 0; index < 7; index++) { - _wmTownMapSubButtonIds[index] = buttonCreate(gWorldmapWindow, + wmTownMapSubButtonIds[index] = buttonCreate(wmBkWin, 508, 138 + 27 * index, littleRedButtonUpWidth, @@ -5003,14 +4852,14 @@ int worldmapWindowInit() -1, -1, KEY_CTRL_F1 + index, - gWorldmapLittleRedButtonUpFrmData, - gWorldmapLittleRedButtonDownFrmData, + wmGenData.littleRedButtonNormalFrmData, + wmGenData.littleRedButtonPressedFrmData, NULL, BUTTON_FLAG_TRANSPARENT); // SFALL: Add missing button sounds. - if (_wmTownMapSubButtonIds[index] != -1) { - buttonSetCallbacks(_wmTownMapSubButtonIds[index], _gsound_red_butt_press, _gsound_red_butt_release); + if (wmTownMapSubButtonIds[index] != -1) { + buttonSetCallbacks(wmTownMapSubButtonIds[index], _gsound_red_butt_press, _gsound_red_butt_release); } } @@ -5019,14 +4868,14 @@ int worldmapWindowInit() // 199 - uparwoff.frm - character editor // SFALL: Fix images for scroll buttons. fid = buildFid(OBJ_TYPE_INTERFACE, 199 + index, 0, 0, 0); - frm = artLock(fid, &(gWorldmapTownListScrollUpFrmHandle[index])); + frm = artLock(fid, &(wmGenData.scrollUpButtonFrmHandle[index])); if (frm == NULL) { return -1; } - gWorldmapTownListScrollUpFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapTownListScrollUpFrmHeight = artGetHeight(frm, 0, 0); - gWorldmapTownListScrollUpFrmData[index] = artGetFrameData(frm, 0, 0); + wmGenData.scrollUpButtonFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.scrollUpButtonFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.scrollUpButtonFrmData[index] = artGetFrameData(frm, 0, 0); } for (int index = 0; index < WORLDMAP_ARROW_FRM_COUNT; index++) { @@ -5034,28 +4883,28 @@ int worldmapWindowInit() // 181 - dnarwoff.frm - character editor // SFALL: Fix images for scroll buttons. fid = buildFid(OBJ_TYPE_INTERFACE, 181 + index, 0, 0, 0); - frm = artLock(fid, &(gWorldmapTownListScrollDownFrmHandle[index])); + frm = artLock(fid, &(wmGenData.scrollDownButtonFrmHandle[index])); if (frm == NULL) { return -1; } - gWorldmapTownListScrollDownFrmWidth = artGetWidth(frm, 0, 0); - gWorldmapTownListScrollDownFrmHeight = artGetHeight(frm, 0, 0); - gWorldmapTownListScrollDownFrmData[index] = artGetFrameData(frm, 0, 0); + wmGenData.scrollDownButtonFrmWidth = artGetWidth(frm, 0, 0); + wmGenData.scrollDownButtonFrmHeight = artGetHeight(frm, 0, 0); + wmGenData.scrollDownButtonFrmData[index] = artGetFrameData(frm, 0, 0); } // Scroll up button. - int scrollUpBtn = buttonCreate(gWorldmapWindow, + int scrollUpBtn = buttonCreate(wmBkWin, WM_TOWN_LIST_SCROLL_UP_X, WM_TOWN_LIST_SCROLL_UP_Y, - gWorldmapTownListScrollUpFrmWidth, - gWorldmapTownListScrollUpFrmHeight, + wmGenData.scrollUpButtonFrmWidth, + wmGenData.scrollUpButtonFrmHeight, -1, -1, -1, KEY_CTRL_ARROW_UP, - gWorldmapTownListScrollUpFrmData[WORLDMAP_ARROW_FRM_NORMAL], - gWorldmapTownListScrollUpFrmData[WORLDMAP_ARROW_FRM_PRESSED], + wmGenData.scrollUpButtonFrmData[WORLDMAP_ARROW_FRM_NORMAL], + wmGenData.scrollUpButtonFrmData[WORLDMAP_ARROW_FRM_PRESSED], NULL, BUTTON_FLAG_TRANSPARENT); @@ -5065,17 +4914,17 @@ int worldmapWindowInit() } // Scroll down button. - int scrollDownBtn = buttonCreate(gWorldmapWindow, + int scrollDownBtn = buttonCreate(wmBkWin, WM_TOWN_LIST_SCROLL_DOWN_X, WM_TOWN_LIST_SCROLL_DOWN_Y, - gWorldmapTownListScrollDownFrmWidth, - gWorldmapTownListScrollDownFrmHeight, + wmGenData.scrollDownButtonFrmWidth, + wmGenData.scrollDownButtonFrmHeight, -1, -1, -1, KEY_CTRL_ARROW_DOWN, - gWorldmapTownListScrollDownFrmData[WORLDMAP_ARROW_FRM_NORMAL], - gWorldmapTownListScrollDownFrmData[WORLDMAP_ARROW_FRM_PRESSED], + wmGenData.scrollDownButtonFrmData[WORLDMAP_ARROW_FRM_NORMAL], + wmGenData.scrollDownButtonFrmData[WORLDMAP_ARROW_FRM_PRESSED], NULL, BUTTON_FLAG_TRANSPARENT); @@ -5084,31 +4933,31 @@ int worldmapWindowInit() buttonSetCallbacks(scrollDownBtn, _gsound_red_butt_press, _gsound_red_butt_release); } - if (gWorldmapIsInCar) { + if (wmGenData.isInCar) { // wmcarmve.frm - worldmap car movie fid = buildFid(OBJ_TYPE_INTERFACE, 433, 0, 0, 0); - gWorldmapCarFrm = artLock(fid, &gWorldmapCarFrmHandle); - if (gWorldmapCarFrm == NULL) { + wmGenData.carImageFrm = artLock(fid, &(wmGenData.carImageFrmHandle)); + if (wmGenData.carImageFrm == NULL) { return -1; } - gWorldmapCarFrmWidth = artGetWidth(gWorldmapCarFrm, 0, 0); - gWorldmapCarFrmHeight = artGetHeight(gWorldmapCarFrm, 0, 0); + wmGenData.carImageFrmWidth = artGetWidth(wmGenData.carImageFrm, 0, 0); + wmGenData.carImageFrmHeight = artGetHeight(wmGenData.carImageFrm, 0, 0); } - tickersAdd(worldmapWindowHandleMouseScrolling); + tickersAdd(wmMouseBkProc); - if (_wmMakeTabsLabelList(&gQuickDestinations, &gQuickDestinationsLength) == -1) { + if (wmMakeTabsLabelList(&wmLabelList, &wmLabelCount) == -1) { return -1; } - _wmInterfaceWasInitialized = 1; + wmInterfaceWasInitialized = 1; - if (worldmapWindowRefresh() == -1) { + if (wmInterfaceRefresh() == -1) { return -1; } - windowRefresh(gWorldmapWindow); + windowRefresh(wmBkWin); scriptsDisable(); _scr_remove_all(); @@ -5116,61 +4965,61 @@ int worldmapWindowInit() } // 0x4C2E44 -int worldmapWindowFree() +static int wmInterfaceExit() { int i; TileInfo* tile; - tickersRemove(worldmapWindowHandleMouseScrolling); + tickersRemove(wmMouseBkProc); - if (gWorldmapBoxFrmData != NULL) { - artUnlock(gWorldmapBoxFrmHandle); - gWorldmapBoxFrmData = NULL; + if (wmBkArtBuf != NULL) { + artUnlock(wmBkKey); + wmBkArtBuf = NULL; } - gWorldmapBoxFrmHandle = INVALID_CACHE_ENTRY; + wmBkKey = INVALID_CACHE_ENTRY; - if (gWorldmapWindow != -1) { - windowDestroy(gWorldmapWindow); - gWorldmapWindow = -1; + if (wmBkWin != -1) { + windowDestroy(wmBkWin); + wmBkWin = -1; } - if (gWorldmapHotspotUpFrmHandle != INVALID_CACHE_ENTRY) { - artUnlock(gWorldmapHotspotUpFrmHandle); + if (wmGenData.hotspotNormalFrmHandle != INVALID_CACHE_ENTRY) { + artUnlock(wmGenData.hotspotNormalFrmHandle); } - gWorldmapHotspotUpFrmData = NULL; + wmGenData.hotspotNormalFrmData = NULL; - if (gWorldmapHotspotDownFrmHandle != INVALID_CACHE_ENTRY) { - artUnlock(gWorldmapHotspotDownFrmHandle); + if (wmGenData.hotspotPressedFrmHandle != INVALID_CACHE_ENTRY) { + artUnlock(wmGenData.hotspotPressedFrmHandle); } - gWorldmapHotspotDownFrmData = NULL; + wmGenData.hotspotPressedFrmData = NULL; - if (gWorldmapDestinationMarkerFrmHandle != INVALID_CACHE_ENTRY) { - artUnlock(gWorldmapDestinationMarkerFrmHandle); + if (wmGenData.destinationMarkerFrmHandle != INVALID_CACHE_ENTRY) { + artUnlock(wmGenData.destinationMarkerFrmHandle); } - gWorldmapDestinationMarkerFrmData = NULL; + wmGenData.destinationMarkerFrmData = NULL; - if (gWorldmapLocationMarkerFrmHandle != INVALID_CACHE_ENTRY) { - artUnlock(gWorldmapLocationMarkerFrmHandle); + if (wmGenData.locationMarkerFrmHandle != INVALID_CACHE_ENTRY) { + artUnlock(wmGenData.locationMarkerFrmHandle); } - gWorldmapLocationMarkerFrmData = NULL; + wmGenData.locationMarkerFrmData = NULL; for (i = 0; i < 4; i++) { - if (gWorldmapEncounterFrmHandles[i] != INVALID_CACHE_ENTRY) { - artUnlock(gWorldmapEncounterFrmHandles[i]); + if (wmGenData.encounterCursorFrmHandle[i] != INVALID_CACHE_ENTRY) { + artUnlock(wmGenData.encounterCursorFrmHandle[i]); } - gWorldmapEncounterFrmData[i] = NULL; + wmGenData.encounterCursorFrmData[i] = NULL; } for (i = 0; i < CITY_SIZE_COUNT; i++) { - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[i]); + CitySizeDescription* citySizeDescription = &(wmSphereData[i]); // FIXME: probably unsafe code, no check for -1 artUnlock(citySizeDescription->handle); citySizeDescription->handle = INVALID_CACHE_ENTRY; citySizeDescription->data = NULL; } - for (i = 0; i < gWorldmapTilesLength; i++) { - tile = &(gWorldmapTiles[i]); + for (i = 0; i < wmMaxTileNum; i++) { + tile = &(wmTileInfoList[i]); if (tile->handle != INVALID_CACHE_ENTRY) { artUnlock(tile->handle); tile->handle = INVALID_CACHE_ENTRY; @@ -5183,98 +5032,98 @@ int worldmapWindowFree() } } - if (gWorldmapTownTabsUnderlayFrmData != NULL) { - artUnlock(gWorldmapTownTabsUnderlayFrmHandle); - gWorldmapTownTabsUnderlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapTownTabsUnderlayFrmData = NULL; + if (wmGenData.tabsBackgroundFrmData != NULL) { + artUnlock(wmGenData.tabsBackgroundFrmHandle); + wmGenData.tabsBackgroundFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.tabsBackgroundFrmData = NULL; } - if (gWorldmapTownTabsEdgeFrmData != NULL) { - artUnlock(gWorldmapTownTabsEdgeFrmHandle); - gWorldmapTownTabsEdgeFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapTownTabsEdgeFrmData = NULL; + if (wmGenData.tabsBorderFrmData != NULL) { + artUnlock(wmGenData.tabsBorderFrmHandle); + wmGenData.tabsBorderFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.tabsBorderFrmData = NULL; } - if (gWorldmapDialFrm != NULL) { - artUnlock(gWorldmapDialFrmHandle); - gWorldmapDialFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapDialFrm = NULL; + if (wmGenData.dialFrm != NULL) { + artUnlock(wmGenData.dialFrmHandle); + wmGenData.dialFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.dialFrm = NULL; } - if (gWorldmapCarOverlayFrmData != NULL) { - artUnlock(gWorldmapCarOverlayFrmHandle); - gWorldmapCarOverlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapCarOverlayFrmData = NULL; + if (wmGenData.carImageOverlayFrmData != NULL) { + artUnlock(wmGenData.carImageOverlayFrmHandle); + wmGenData.carImageOverlayFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.carImageOverlayFrmData = NULL; } - if (gWorldmapGlobeOverlayFrmData != NULL) { - artUnlock(gWorldmapGlobeOverlayFrmHandle); - gWorldmapGlobeOverlayFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapGlobeOverlayFrmData = NULL; + if (wmGenData.globeOverlayFrmData != NULL) { + artUnlock(wmGenData.globeOverlayFrmHandle); + wmGenData.globeOverlayFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.globeOverlayFrmData = NULL; } - if (gWorldmapLittleRedButtonUpFrmData != NULL) { - artUnlock(gWorldmapLittleRedButtonUpFrmHandle); - gWorldmapLittleRedButtonUpFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapLittleRedButtonUpFrmData = NULL; + if (wmGenData.littleRedButtonNormalFrmData != NULL) { + artUnlock(wmGenData.littleRedButtonNormalFrmHandle); + wmGenData.littleRedButtonNormalFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.littleRedButtonNormalFrmData = NULL; } - if (gWorldmapLittleRedButtonDownFrmData != NULL) { - artUnlock(gWorldmapLittleRedButtonDownFrmHandle); - gWorldmapLittleRedButtonDownFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapLittleRedButtonDownFrmData = NULL; + if (wmGenData.littleRedButtonPressedFrmData != NULL) { + artUnlock(wmGenData.littleRedButtonPressedFrmHandle); + wmGenData.littleRedButtonPressedFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.littleRedButtonPressedFrmData = NULL; } for (i = 0; i < 2; i++) { - artUnlock(gWorldmapTownListScrollUpFrmHandle[i]); - gWorldmapTownListScrollUpFrmHandle[i] = INVALID_CACHE_ENTRY; - gWorldmapTownListScrollUpFrmData[i] = NULL; + artUnlock(wmGenData.scrollUpButtonFrmHandle[i]); + wmGenData.scrollUpButtonFrmHandle[i] = INVALID_CACHE_ENTRY; + wmGenData.scrollUpButtonFrmData[i] = NULL; - artUnlock(gWorldmapTownListScrollDownFrmHandle[i]); - gWorldmapTownListScrollDownFrmHandle[i] = INVALID_CACHE_ENTRY; - gWorldmapTownListScrollDownFrmData[i] = NULL; + artUnlock(wmGenData.scrollDownButtonFrmHandle[i]); + wmGenData.scrollDownButtonFrmHandle[i] = INVALID_CACHE_ENTRY; + wmGenData.scrollDownButtonFrmData[i] = NULL; } - gWorldmapTownListScrollUpFrmHeight = 0; - gWorldmapTownListScrollDownFrmWidth = 0; - gWorldmapTownListScrollDownFrmHeight = 0; - gWorldmapTownListScrollUpFrmWidth = 0; + wmGenData.scrollUpButtonFrmHeight = 0; + wmGenData.scrollDownButtonFrmWidth = 0; + wmGenData.scrollDownButtonFrmHeight = 0; + wmGenData.scrollUpButtonFrmWidth = 0; - if (gWorldmapMonthsFrm != NULL) { - artUnlock(gWorldmapMonthsFrmHandle); - gWorldmapMonthsFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapMonthsFrm = NULL; + if (wmGenData.monthsFrm != NULL) { + artUnlock(wmGenData.monthsFrmHandle); + wmGenData.monthsFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.monthsFrm = NULL; } - if (gWorldmapNumbersFrm != NULL) { - artUnlock(gWorldmapNumbersFrmHandle); - gWorldmapNumbersFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapNumbersFrm = NULL; + if (wmGenData.numbersFrm != NULL) { + artUnlock(wmGenData.numbersFrmHandle); + wmGenData.numbersFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.numbersFrm = NULL; } - if (gWorldmapCarFrm != NULL) { - artUnlock(gWorldmapCarFrmHandle); - gWorldmapCarFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapCarFrm = NULL; + if (wmGenData.carImageFrm != NULL) { + artUnlock(wmGenData.carImageFrmHandle); + wmGenData.carImageFrmHandle = INVALID_CACHE_ENTRY; + wmGenData.carImageFrm = NULL; - gWorldmapCarFrmWidth = 0; - gWorldmapCarFrmHeight = 0; + wmGenData.carImageFrmWidth = 0; + wmGenData.carImageFrmHeight = 0; } - _wmEncounterIconShow = 0; - _EncounterMapID = -1; - dword_672E50 = -1; - dword_672E54 = -1; + wmGenData.encounterIconIsVisible = 0; + wmGenData.encounterMapId = -1; + wmGenData.encounterTableId = -1; + wmGenData.encounterEntryId = -1; indicatorBarShow(); isoEnable(); colorCycleEnable(); - fontSetCurrent(_fontnum); + fontSetCurrent(wmGenData.oldFont); // NOTE: Uninline. - wmFreeTabsLabelList(&gQuickDestinations, &gQuickDestinationsLength); + wmFreeTabsLabelList(&wmLabelList, &wmLabelCount); - _wmInterfaceWasInitialized = 0; + wmInterfaceWasInitialized = 0; scriptsEnable(); @@ -5286,7 +5135,7 @@ int worldmapWindowFree() // 0x4C31E8 static int wmInterfaceScroll(int dx, int dy, bool* successPtr) { - return worldmapWindowScroll(20, 20, dx, dy, successPtr, 1); + return wmInterfaceScrollPixel(20, 20, dx, dy, successPtr, 1); } // FIXME: There is small bug in this function. There is [success] flag returned @@ -5296,10 +5145,10 @@ static int wmInterfaceScroll(int dx, int dy, bool* successPtr) // error. // // 0x4C3200 -int worldmapWindowScroll(int stepX, int stepY, int dx, int dy, bool* success, bool shouldRefresh) +static int wmInterfaceScrollPixel(int stepX, int stepY, int dx, int dy, bool* success, bool shouldRefresh) { - int v6 = gWorldmapOffsetY; - int v7 = gWorldmapOffsetX; + int v6 = wmWorldOffsetY; + int v7 = wmWorldOffsetX; if (success != NULL) { *success = true; @@ -5317,10 +5166,10 @@ int worldmapWindowScroll(int stepX, int stepY, int dx, int dy, bool* success, bo } } } else if (dy > 0) { - if (v6 < _wmViewportBottomtScrlLimit) { + if (v6 < wmGenData.viewportMaxY) { v6 += stepY; - if (v6 > _wmViewportBottomtScrlLimit) { - v6 = _wmViewportBottomtScrlLimit; + if (v6 > wmGenData.viewportMaxY) { + v6 = wmGenData.viewportMaxY; } } else { if (success != NULL) { @@ -5341,10 +5190,10 @@ int worldmapWindowScroll(int stepX, int stepY, int dx, int dy, bool* success, bo } } } else if (dx > 0) { - if (v7 < _wmViewportRightScrlLimit) { + if (v7 < wmGenData.viewportMaxX) { v7 += stepX; - if (v7 > _wmViewportRightScrlLimit) { - v7 = _wmViewportRightScrlLimit; + if (v7 > wmGenData.viewportMaxX) { + v7 = wmGenData.viewportMaxX; } } else { if (success != NULL) { @@ -5353,11 +5202,11 @@ int worldmapWindowScroll(int stepX, int stepY, int dx, int dy, bool* success, bo } } - gWorldmapOffsetY = v6; - gWorldmapOffsetX = v7; + wmWorldOffsetY = v6; + wmWorldOffsetX = v7; if (shouldRefresh) { - if (worldmapWindowRefresh() == -1) { + if (wmInterfaceRefresh() == -1) { return -1; } } @@ -5366,11 +5215,11 @@ int worldmapWindowScroll(int stepX, int stepY, int dx, int dy, bool* success, bo } // 0x4C32EC -void worldmapWindowHandleMouseScrolling() +static void wmMouseBkProc() { int x; int y; - mouseGetPositionInWindow(gWorldmapWindow, &x, &y); + mouseGetPositionInWindow(wmBkWin, &x, &y); int dx = 0; if (x == 639) { @@ -5466,7 +5315,7 @@ static int wmMarkSubTileOffsetVisitedFunc(int tile, int subtileX, int subtileY, if (actualSubtileX >= 0) { if (actualSubtileX >= SUBTILE_GRID_WIDTH) { - if (tile % gWorldmapGridWidth == gWorldmapGridWidth - 1) { + if (tile % wmNumHorizontalTiles == wmNumHorizontalTiles - 1) { return -1; } @@ -5474,7 +5323,7 @@ static int wmMarkSubTileOffsetVisitedFunc(int tile, int subtileX, int subtileY, actualSubtileX %= SUBTILE_GRID_WIDTH; } } else { - if (!(tile % gWorldmapGridWidth)) { + if (!(tile % wmNumHorizontalTiles)) { return -1; } @@ -5484,23 +5333,23 @@ static int wmMarkSubTileOffsetVisitedFunc(int tile, int subtileX, int subtileY, if (actualSubtileY >= 0) { if (actualSubtileY >= SUBTILE_GRID_HEIGHT) { - if (actualTile > gWorldmapTilesLength - gWorldmapGridWidth - 1) { + if (actualTile > wmMaxTileNum - wmNumHorizontalTiles - 1) { return -1; } - actualTile += gWorldmapGridWidth; + actualTile += wmNumHorizontalTiles; actualSubtileY %= SUBTILE_GRID_HEIGHT; } } else { - if (actualTile < gWorldmapGridWidth) { + if (actualTile < wmNumHorizontalTiles) { return -1; } actualSubtileY += SUBTILE_GRID_HEIGHT; - actualTile -= gWorldmapGridWidth; + actualTile -= wmNumHorizontalTiles; } - tileInfo = &(gWorldmapTiles[actualTile]); + tileInfo = &(wmTileInfoList[actualTile]); subtileInfo = &(tileInfo->subtiles[actualSubtileY][actualSubtileX]); if (subtileState != SUBTILE_STATE_KNOWN || subtileInfo->state == SUBTILE_STATE_UNKNOWN) { subtileInfo->state = subtileState; @@ -5510,7 +5359,7 @@ static int wmMarkSubTileOffsetVisitedFunc(int tile, int subtileX, int subtileY, } // 0x4C3550 -void _wmMarkSubTileRadiusVisited(int x, int y) +static void wmMarkSubTileRadiusVisited(int x, int y) { int radius = 1; @@ -5531,7 +5380,7 @@ int wmSubTileMarkRadiusVisited(int x, int y, int radius) int offsetY; SubtileInfo* subtile; - tile = x / WM_TILE_WIDTH % gWorldmapGridWidth + y / WM_TILE_HEIGHT * gWorldmapGridWidth; + tile = x / WM_TILE_WIDTH % wmNumHorizontalTiles + y / WM_TILE_HEIGHT * wmNumHorizontalTiles; subtileX = x % WM_TILE_WIDTH / WM_SUBTILE_SIZE; subtileY = y % WM_TILE_HEIGHT / WM_SUBTILE_SIZE; @@ -5542,7 +5391,7 @@ int wmSubTileMarkRadiusVisited(int x, int y, int radius) } } - subtile = &(gWorldmapTiles[tile].subtiles[subtileY][subtileX]); + subtile = &(wmTileInfoList[tile].subtiles[subtileY][subtileX]); subtile->state = SUBTILE_STATE_VISITED; switch (subtile->field_4) { @@ -5558,7 +5407,7 @@ int wmSubTileMarkRadiusVisited(int x, int y, int radius) wmMarkSubTileOffsetVisited(tile, subtileX, subtileY, 0, 0); } - if (tile % gWorldmapGridWidth > 0) { + if (tile % wmNumHorizontalTiles > 0) { for (subtileX = 0; subtileX < SUBTILE_GRID_WIDTH; subtileX++) { // NOTE: Uninline. wmMarkSubTileOffsetVisited(tile - 1, subtileX, subtileY, 0, 0); @@ -5571,14 +5420,14 @@ int wmSubTileMarkRadiusVisited(int x, int y, int radius) } // 0x4C3740 -int _wmSubTileGetVisitedState(int x, int y, int* a3) +int wmSubTileGetVisitedState(int x, int y, int* statePtr) { TileInfo* tile; - SubtileInfo* ptr; + SubtileInfo* subtile; - tile = &(gWorldmapTiles[y / WM_TILE_HEIGHT * gWorldmapGridWidth + x / WM_TILE_WIDTH % gWorldmapGridWidth]); - ptr = &(tile->subtiles[y % WM_TILE_HEIGHT / WM_SUBTILE_SIZE][x % WM_TILE_WIDTH / WM_SUBTILE_SIZE]); - *a3 = ptr->state; + tile = &(wmTileInfoList[y / WM_TILE_HEIGHT * wmNumHorizontalTiles + x / WM_TILE_WIDTH % wmNumHorizontalTiles]); + subtile = &(tile->subtiles[y % WM_TILE_HEIGHT / WM_SUBTILE_SIZE][x % WM_TILE_WIDTH / WM_SUBTILE_SIZE]); + *statePtr = subtile->state; return 0; } @@ -5586,9 +5435,9 @@ int _wmSubTileGetVisitedState(int x, int y, int* a3) // Load tile art if needed. // // 0x4C37EC -int _wmTileGrabArt(int tile_index) +static int wmTileGrabArt(int tileIdx) { - TileInfo* tile = &(gWorldmapTiles[tile_index]); + TileInfo* tile = &(wmTileInfoList[tileIdx]); if (tile->data != NULL) { return 0; } @@ -5598,20 +5447,20 @@ int _wmTileGrabArt(int tile_index) return 0; } - worldmapWindowFree(); + wmInterfaceExit(); return -1; } // 0x4C3830 -int worldmapWindowRefresh() +static int wmInterfaceRefresh() { - if (_wmInterfaceWasInitialized != 1) { + if (wmInterfaceWasInitialized != 1) { return 0; } - int v17 = gWorldmapOffsetX % WM_TILE_WIDTH; - int v18 = gWorldmapOffsetY % WM_TILE_HEIGHT; + int v17 = wmWorldOffsetX % WM_TILE_WIDTH; + int v18 = wmWorldOffsetY % WM_TILE_HEIGHT; int v20 = WM_TILE_HEIGHT - v18; int v21 = WM_TILE_WIDTH * v18; int v19 = WM_TILE_WIDTH - v17; @@ -5619,13 +5468,13 @@ int worldmapWindowRefresh() // Render tiles. int y = 0; int x = 0; - int v0 = gWorldmapOffsetY / WM_TILE_HEIGHT * gWorldmapGridWidth + gWorldmapOffsetX / WM_TILE_WIDTH % gWorldmapGridWidth; + int v0 = wmWorldOffsetY / WM_TILE_HEIGHT * wmNumHorizontalTiles + wmWorldOffsetX / WM_TILE_WIDTH % wmNumHorizontalTiles; while (y < WM_VIEW_HEIGHT) { x = 0; int v23 = 0; int height; while (x < WM_VIEW_WIDTH) { - if (_wmTileGrabArt(v0) == -1) { + if (wmTileGrabArt(v0) == -1) { return -1; } @@ -5651,12 +5500,12 @@ int worldmapWindowRefresh() height = WM_VIEW_HEIGHT - y; } - TileInfo* tileInfo = &(gWorldmapTiles[v0]); + TileInfo* tileInfo = &(wmTileInfoList[v0]); blitBufferToBuffer(tileInfo->data + srcX, width, height, WM_TILE_WIDTH, - gWorldmapWindowBuffer + WM_WINDOW_WIDTH * (y + WM_VIEW_Y) + WM_VIEW_X + x, + wmBkWinBuf + WM_WINDOW_WIDTH * (y + WM_VIEW_Y) + WM_VIEW_X + x, WM_WINDOW_WIDTH); v0++; @@ -5664,26 +5513,26 @@ int worldmapWindowRefresh() v23++; } - v0 += gWorldmapGridWidth - v23; + v0 += wmNumHorizontalTiles - v23; y += height; } // Render cities. - for (int index = 0; index < gCitiesLength; index++) { - CityInfo* cityInfo = &(gCities[index]); + for (int index = 0; index < wmMaxAreaNum; index++) { + CityInfo* cityInfo = &(wmAreaInfoList[index]); if (cityInfo->state != CITY_STATE_UNKNOWN) { - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[cityInfo->size]); - int cityX = cityInfo->x - gWorldmapOffsetX; - int cityY = cityInfo->y - gWorldmapOffsetY; + CitySizeDescription* citySizeDescription = &(wmSphereData[cityInfo->size]); + int cityX = cityInfo->x - wmWorldOffsetX; + int cityY = cityInfo->y - wmWorldOffsetY; if (cityX >= 0 && cityX <= 472 - citySizeDescription->width && cityY >= 0 && cityY <= 465 - citySizeDescription->height) { - worldmapWindowRenderCity(cityInfo, citySizeDescription, gWorldmapWindowBuffer, cityX, cityY); + wmInterfaceDrawCircleOverlay(cityInfo, citySizeDescription, wmBkWinBuf, cityX, cityY); } } } // Hide unknown subtiles, dim unvisited. - int v25 = gWorldmapOffsetX / WM_TILE_WIDTH % gWorldmapGridWidth + gWorldmapOffsetY / WM_TILE_HEIGHT * gWorldmapGridWidth; + int v25 = wmWorldOffsetX / WM_TILE_WIDTH % wmNumHorizontalTiles + wmWorldOffsetY / WM_TILE_HEIGHT * wmNumHorizontalTiles; int v30 = 0; while (v30 < WM_VIEW_HEIGHT) { int v24 = 0; @@ -5728,8 +5577,8 @@ int worldmapWindowRefresh() int v15 = v33 + v35; for (int column = 0; column < SUBTILE_GRID_WIDTH; column++) { - TileInfo* tileInfo = &(gWorldmapTiles[v25]); - worldmapWindowDimSubtile(tileInfo, column, row, v15, v34, 1); + TileInfo* tileInfo = &(wmTileInfoList[v25]); + wmInterfaceDrawSubTileList(tileInfo, column, row, v15, v34, 1); v15 += WM_SUBTILE_SIZE; v35 += WM_SUBTILE_SIZE; @@ -5744,19 +5593,19 @@ int worldmapWindowRefresh() v33 += v31; } - v25 += gWorldmapGridWidth - v24; + v25 += wmNumHorizontalTiles - v24; v30 += v29; } - _wmDrawCursorStopped(); + wmDrawCursorStopped(); - worldmapWindowRenderChrome(true); + wmRefreshInterfaceOverlay(true); return 0; } // 0x4C3C9C -void worldmapWindowRenderDate(bool shouldRefreshWindow) +static void wmInterfaceRefreshDate(bool shouldRefreshWindow) { int month; int day; @@ -5765,18 +5614,18 @@ void worldmapWindowRenderDate(bool shouldRefreshWindow) month--; - unsigned char* dest = gWorldmapWindowBuffer; + unsigned char* dest = wmBkWinBuf; - int numbersFrmWidth = artGetWidth(gWorldmapNumbersFrm, 0, 0); - int numbersFrmHeight = artGetHeight(gWorldmapNumbersFrm, 0, 0); - unsigned char* numbersFrmData = artGetFrameData(gWorldmapNumbersFrm, 0, 0); + int numbersFrmWidth = artGetWidth(wmGenData.numbersFrm, 0, 0); + int numbersFrmHeight = artGetHeight(wmGenData.numbersFrm, 0, 0); + unsigned char* numbersFrmData = artGetFrameData(wmGenData.numbersFrm, 0, 0); dest += WM_WINDOW_WIDTH * 12 + 487; blitBufferToBuffer(numbersFrmData + 9 * (day / 10), 9, numbersFrmHeight, numbersFrmWidth, dest, WM_WINDOW_WIDTH); blitBufferToBuffer(numbersFrmData + 9 * (day % 10), 9, numbersFrmHeight, numbersFrmWidth, dest + 9, WM_WINDOW_WIDTH); - int monthsFrmWidth = artGetWidth(gWorldmapMonthsFrm, 0, 0); - unsigned char* monthsFrmData = artGetFrameData(gWorldmapMonthsFrm, 0, 0); + int monthsFrmWidth = artGetWidth(wmGenData.monthsFrm, 0, 0); + unsigned char* monthsFrmData = artGetFrameData(wmGenData.monthsFrm, 0, 0); blitBufferToBuffer(monthsFrmData + monthsFrmWidth * 15 * month, 29, 14, 29, dest + WM_WINDOW_WIDTH + 26, WM_WINDOW_WIDTH); dest += 98; @@ -5800,22 +5649,22 @@ void worldmapWindowRenderDate(bool shouldRefreshWindow) rect.top = 12; rect.bottom = numbersFrmHeight + 12; rect.right = 630; - windowRefreshRect(gWorldmapWindow, &rect); + windowRefreshRect(wmBkWin, &rect); } } // 0x4C3F00 -int _wmMatchWorldPosToArea(int a1, int a2, int* a3) +static int wmMatchWorldPosToArea(int x, int y, int* areaIdxPtr) { - int v3 = a2 + WM_VIEW_Y; - int v4 = a1 + WM_VIEW_X; + int v3 = y + WM_VIEW_Y; + int v4 = x + WM_VIEW_X; int index; - for (index = 0; index < gCitiesLength; index++) { - CityInfo* city = &(gCities[index]); + for (index = 0; index < wmMaxAreaNum; index++) { + CityInfo* city = &(wmAreaInfoList[index]); if (city->state) { if (v4 >= city->x && v3 >= city->y) { - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[city->size]); + CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]); if (v4 <= city->x + citySizeDescription->width && v3 <= city->y + citySizeDescription->height) { break; } @@ -5823,17 +5672,17 @@ int _wmMatchWorldPosToArea(int a1, int a2, int* a3) } } - if (index == gCitiesLength) { - *a3 = -1; + if (index == wmMaxAreaNum) { + *areaIdxPtr = -1; } else { - *a3 = index; + *areaIdxPtr = index; } return 0; } // 0x4C3FA8 -int worldmapWindowRenderCity(CityInfo* city, CitySizeDescription* citySizeDescription, unsigned char* dest, int x, int y) +static int wmInterfaceDrawCircleOverlay(CityInfo* city, CitySizeDescription* citySizeDescription, unsigned char* dest, int x, int y) { _dark_translucent_trans_buf_to_buf(citySizeDescription->data, citySizeDescription->width, @@ -5844,7 +5693,7 @@ int worldmapWindowRenderCity(CityInfo* city, CitySizeDescription* citySizeDescri y, WM_WINDOW_WIDTH, 0x10000, - _circleBlendTable, + circleBlendTable, _commonGrayTable); // CE: Slightly increase whitespace between cirle and city name. @@ -5853,11 +5702,11 @@ int worldmapWindowRenderCity(CityInfo* city, CitySizeDescription* citySizeDescri if (nameY < maxY) { MessageListItem messageListItem; char name[40]; - if (_wmAreaIsKnown(city->field_28)) { + if (wmAreaIsKnown(city->areaId)) { // NOTE: Uninline. wmGetAreaName(city, name); } else { - strncpy(name, getmsg(&gWorldmapMessageList, &messageListItem, 1004), 40); + strncpy(name, getmsg(&wmMsgFile, &messageListItem, 1004), 40); } int width = fontGetStringWidth(name); @@ -5875,7 +5724,7 @@ int worldmapWindowRenderCity(CityInfo* city, CitySizeDescription* citySizeDescri // slightly darken subtile which is known, but not visited. // // 0x4C40A8 -void worldmapWindowDimRect(unsigned char* dest, int width, int height, int pitch) +static void wmInterfaceDrawSubTileRectFogged(unsigned char* dest, int width, int height, int pitch) { int skipY = pitch - width; @@ -5890,7 +5739,7 @@ void worldmapWindowDimRect(unsigned char* dest, int width, int height, int pitch } // 0x4C40E4 -int worldmapWindowDimSubtile(TileInfo* tileInfo, int column, int row, int x, int y, int a6) +static int wmInterfaceDrawSubTileList(TileInfo* tileInfo, int column, int row, int x, int y, int a6) { SubtileInfo* subtileInfo = &(tileInfo->subtiles[row][column]); @@ -5922,13 +5771,13 @@ int worldmapWindowDimSubtile(TileInfo* tileInfo, int column, int row, int x, int } if (width > 0 && height > 0) { - unsigned char* dest = gWorldmapWindowBuffer + WM_WINDOW_WIDTH * destY + destX; + unsigned char* dest = wmBkWinBuf + WM_WINDOW_WIDTH * destY + destX; switch (subtileInfo->state) { case SUBTILE_STATE_UNKNOWN: bufferFill(dest, width, height, WM_WINDOW_WIDTH, _colorTable[0]); break; case SUBTILE_STATE_KNOWN: - worldmapWindowDimRect(dest, width, height, WM_WINDOW_WIDTH); + wmInterfaceDrawSubTileRectFogged(dest, width, height, WM_WINDOW_WIDTH); break; } } @@ -5937,47 +5786,47 @@ int worldmapWindowDimSubtile(TileInfo* tileInfo, int column, int row, int x, int } // 0x4C41EC -int _wmDrawCursorStopped() +static int wmDrawCursorStopped() { unsigned char* src; int width; int height; - if (gWorldmapTravelDestX >= 1 || gWorldmapTravelDestY >= 1) { + if (wmGenData.walkDestinationX >= 1 || wmGenData.walkDestinationY >= 1) { - if (_wmEncounterIconShow == 1) { - src = gWorldmapEncounterFrmData[_wmRndCursorFid]; - width = gWorldmapEncounterFrmWidths[_wmRndCursorFid]; - height = gWorldmapEncounterFrmHeights[_wmRndCursorFid]; + if (wmGenData.encounterIconIsVisible == 1) { + src = wmGenData.encounterCursorFrmData[wmGenData.encounterCursorId]; + width = wmGenData.encounterCursorFrmWidths[wmGenData.encounterCursorId]; + height = wmGenData.encounterCursorFrmHeights[wmGenData.encounterCursorId]; } else { - src = gWorldmapLocationMarkerFrmData; - width = gWorldmapLocationMarkerFrmWidth; - height = gWorldmapLocationMarkerFrmHeight; + src = wmGenData.locationMarkerFrmData; + width = wmGenData.locationMarkerFrmWidth; + height = wmGenData.locationMarkerFrmHeight; } - if (_world_xpos >= gWorldmapOffsetX && _world_xpos < gWorldmapOffsetX + WM_VIEW_WIDTH - && _world_ypos >= gWorldmapOffsetY && _world_ypos < gWorldmapOffsetY + WM_VIEW_HEIGHT) { - blitBufferToBufferTrans(src, width, height, width, gWorldmapWindowBuffer + WM_WINDOW_WIDTH * (WM_VIEW_Y - gWorldmapOffsetY + _world_ypos - height / 2) + WM_VIEW_X - gWorldmapOffsetX + _world_xpos - width / 2, WM_WINDOW_WIDTH); + if (wmGenData.worldPosX >= wmWorldOffsetX && wmGenData.worldPosX < wmWorldOffsetX + WM_VIEW_WIDTH + && wmGenData.worldPosY >= wmWorldOffsetY && wmGenData.worldPosY < wmWorldOffsetY + WM_VIEW_HEIGHT) { + blitBufferToBufferTrans(src, width, height, width, wmBkWinBuf + WM_WINDOW_WIDTH * (WM_VIEW_Y - wmWorldOffsetY + wmGenData.worldPosY - height / 2) + WM_VIEW_X - wmWorldOffsetX + wmGenData.worldPosX - width / 2, WM_WINDOW_WIDTH); } - if (gWorldmapTravelDestX >= gWorldmapOffsetX && gWorldmapTravelDestX < gWorldmapOffsetX + WM_VIEW_WIDTH - && gWorldmapTravelDestY >= gWorldmapOffsetY && gWorldmapTravelDestY < gWorldmapOffsetY + WM_VIEW_HEIGHT) { - blitBufferToBufferTrans(gWorldmapDestinationMarkerFrmData, gWorldmapDestinationMarkerFrmWidth, gWorldmapDestinationMarkerFrmHeight, gWorldmapDestinationMarkerFrmWidth, gWorldmapWindowBuffer + WM_WINDOW_WIDTH * (WM_VIEW_Y - gWorldmapOffsetY + gWorldmapTravelDestY - gWorldmapDestinationMarkerFrmHeight / 2) + WM_VIEW_X - gWorldmapOffsetX + gWorldmapTravelDestX - gWorldmapDestinationMarkerFrmWidth / 2, WM_WINDOW_WIDTH); + if (wmGenData.walkDestinationX >= wmWorldOffsetX && wmGenData.walkDestinationX < wmWorldOffsetX + WM_VIEW_WIDTH + && wmGenData.walkDestinationY >= wmWorldOffsetY && wmGenData.walkDestinationY < wmWorldOffsetY + WM_VIEW_HEIGHT) { + blitBufferToBufferTrans(wmGenData.destinationMarkerFrmData, wmGenData.destinationMarkerFrmWidth, wmGenData.destinationMarkerFrmHeight, wmGenData.destinationMarkerFrmWidth, wmBkWinBuf + WM_WINDOW_WIDTH * (WM_VIEW_Y - wmWorldOffsetY + wmGenData.walkDestinationY - wmGenData.destinationMarkerFrmHeight / 2) + WM_VIEW_X - wmWorldOffsetX + wmGenData.walkDestinationX - wmGenData.destinationMarkerFrmWidth / 2, WM_WINDOW_WIDTH); } } else { - if (_wmEncounterIconShow == 1) { - src = gWorldmapEncounterFrmData[_wmRndCursorFid]; - width = gWorldmapEncounterFrmWidths[_wmRndCursorFid]; - height = gWorldmapEncounterFrmHeights[_wmRndCursorFid]; + if (wmGenData.encounterIconIsVisible == 1) { + src = wmGenData.encounterCursorFrmData[wmGenData.encounterCursorId]; + width = wmGenData.encounterCursorFrmWidths[wmGenData.encounterCursorId]; + height = wmGenData.encounterCursorFrmHeights[wmGenData.encounterCursorId]; } else { - src = _wmGenData ? gWorldmapHotspotDownFrmData : gWorldmapHotspotUpFrmData; - width = gWorldmapHotspotUpFrmWidth; - height = gWorldmapHotspotUpFrmHeight; + src = wmGenData.mousePressed ? wmGenData.hotspotPressedFrmData : wmGenData.hotspotNormalFrmData; + width = wmGenData.hotspotFrmWidth; + height = wmGenData.hotspotFrmHeight; } - if (_world_xpos >= gWorldmapOffsetX && _world_xpos < gWorldmapOffsetX + WM_VIEW_WIDTH - && _world_ypos >= gWorldmapOffsetY && _world_ypos < gWorldmapOffsetY + WM_VIEW_HEIGHT) { - blitBufferToBufferTrans(src, width, height, width, gWorldmapWindowBuffer + WM_WINDOW_WIDTH * (WM_VIEW_Y - gWorldmapOffsetY + _world_ypos - height / 2) + WM_VIEW_X - gWorldmapOffsetX + _world_xpos - width / 2, WM_WINDOW_WIDTH); + if (wmGenData.worldPosX >= wmWorldOffsetX && wmGenData.worldPosX < wmWorldOffsetX + WM_VIEW_WIDTH + && wmGenData.worldPosY >= wmWorldOffsetY && wmGenData.worldPosY < wmWorldOffsetY + WM_VIEW_HEIGHT) { + blitBufferToBufferTrans(src, width, height, width, wmBkWinBuf + WM_WINDOW_WIDTH * (WM_VIEW_Y - wmWorldOffsetY + wmGenData.worldPosY - height / 2) + WM_VIEW_X - wmWorldOffsetX + wmGenData.worldPosX - width / 2, WM_WINDOW_WIDTH); } } @@ -5985,12 +5834,12 @@ int _wmDrawCursorStopped() } // 0x4C4490 -bool _wmCursorIsVisible() +static bool wmCursorIsVisible() { - return _world_xpos >= gWorldmapOffsetX - && _world_ypos >= gWorldmapOffsetY - && _world_xpos < gWorldmapOffsetX + WM_VIEW_WIDTH - && _world_ypos < gWorldmapOffsetY + WM_VIEW_HEIGHT; + return wmGenData.worldPosX >= wmWorldOffsetX + && wmGenData.worldPosY >= wmWorldOffsetY + && wmGenData.worldPosX < wmWorldOffsetX + WM_VIEW_WIDTH + && wmGenData.worldPosY < wmWorldOffsetY + WM_VIEW_HEIGHT; } // NOTE: Inlined. @@ -6000,7 +5849,7 @@ static int wmGetAreaName(CityInfo* city, char* name) { MessageListItem messageListItem; - getmsg(&gMapMessageList, &messageListItem, city->field_28 + 1500); + getmsg(&gMapMessageList, &messageListItem, city->areaId + 1500); strncpy(name, messageListItem.text, 40); return 0; @@ -6009,11 +5858,11 @@ static int wmGetAreaName(CityInfo* city, char* name) // Copy city short name. // // 0x4C450C -int _wmGetAreaIdxName(int index, char* name) +int wmGetAreaIdxName(int areaIdx, char* name) { MessageListItem messageListItem; - getmsg(&gMapMessageList, &messageListItem, 1500 + index); + getmsg(&gMapMessageList, &messageListItem, 1500 + areaIdx); strncpy(name, messageListItem.text, 40); return 0; @@ -6022,14 +5871,14 @@ int _wmGetAreaIdxName(int index, char* name) // Returns true if world area is known. // // 0x4C453C -bool _wmAreaIsKnown(int cityIndex) +bool wmAreaIsKnown(int areaIdx) { - if (!cityIsValid(cityIndex)) { + if (!cityIsValid(areaIdx)) { return false; } - CityInfo* city = &(gCities[cityIndex]); - if (city->field_40) { + CityInfo* city = &(wmAreaInfoList[areaIdx]); + if (city->visitedState) { if (city->state == CITY_STATE_KNOWN) { return true; } @@ -6039,35 +5888,35 @@ bool _wmAreaIsKnown(int cityIndex) } // 0x4C457C -int _wmAreaVisitedState(int area) +int wmAreaVisitedState(int areaIdx) { - if (!cityIsValid(area)) { + if (!cityIsValid(areaIdx)) { return 0; } - CityInfo* city = &(gCities[area]); - if (city->field_40 && city->state == 1) { - return city->field_40; + CityInfo* city = &(wmAreaInfoList[areaIdx]); + if (city->visitedState && city->state == CITY_STATE_KNOWN) { + return city->visitedState; } return 0; } // 0x4C45BC -bool _wmMapIsKnown(int mapIndex) +bool wmMapIsKnown(int mapIdx) { - int cityIndex; - if (_wmMatchAreaFromMap(mapIndex, &cityIndex) != 0) { + int areaIdx; + if (wmMatchAreaFromMap(mapIdx, &areaIdx) != 0) { return false; } - int entranceIndex; - if (_wmMatchEntranceFromMap(cityIndex, mapIndex, &entranceIndex) != 0) { + int entranceIdx; + if (wmMatchEntranceFromMap(areaIdx, mapIdx, &entranceIdx) != 0) { return false; } - CityInfo* city = &(gCities[cityIndex]); - EntranceInfo* entrance = &(city->entrances[entranceIndex]); + CityInfo* city = &(wmAreaInfoList[areaIdx]); + EntranceInfo* entrance = &(city->entrances[entranceIdx]); if (entrance->state != 1) { return false; @@ -6077,73 +5926,72 @@ bool _wmMapIsKnown(int mapIndex) } // 0x4C4624 -static int wmAreaMarkVisited(int cityIndex) +int wmAreaMarkVisited(int areaIdx) { - return _wmAreaMarkVisitedState(cityIndex, CITY_STATE_VISITED); + return wmAreaMarkVisitedState(areaIdx, CITY_STATE_VISITED); } // 0x4C4634 -bool _wmAreaMarkVisitedState(int cityIndex, int a2) +bool wmAreaMarkVisitedState(int areaIdx, int state) { - if (!cityIsValid(cityIndex)) { + if (!cityIsValid(areaIdx)) { return false; } - CityInfo* city = &(gCities[cityIndex]); - int v5 = city->field_40; - if (city->state == 1 && a2 != 0) { - _wmMarkSubTileRadiusVisited(city->x, city->y); + CityInfo* city = &(wmAreaInfoList[areaIdx]); + int v5 = city->visitedState; + if (city->state == CITY_STATE_KNOWN && state != 0) { + wmMarkSubTileRadiusVisited(city->x, city->y); } - city->field_40 = a2; + city->visitedState = state; SubtileInfo* subtile; - if (_wmFindCurSubTileFromPos(city->x, city->y, &subtile) == -1) { + if (wmFindCurSubTileFromPos(city->x, city->y, &subtile) == -1) { return false; } - if (a2 == 1) { + if (state == 1) { subtile->state = SUBTILE_STATE_KNOWN; - } else if (a2 == 2 && v5 == 0) { - city->field_40 = 1; + } else if (state == 2 && v5 == 0) { + city->visitedState = 1; } return true; } // 0x4C46CC -bool _wmAreaSetVisibleState(int cityIndex, int a2, int a3) +bool wmAreaSetVisibleState(int areaIdx, int state, bool force) { - if (!cityIsValid(cityIndex)) { + if (!cityIsValid(areaIdx)) { return false; } - CityInfo* city = &(gCities[cityIndex]); - if (city->field_3C != 1 || a3) { - city->state = a2; + CityInfo* city = &(wmAreaInfoList[areaIdx]); + if (city->lockState != LOCK_STATE_LOCKED || force) { + city->state = state; return true; } return false; } -// wm_area_set_pos // 0x4C4710 -int worldmapCitySetPos(int cityIndex, int x, int y) +int wmAreaSetWorldPos(int areaIdx, int x, int y) { - if (!cityIsValid(cityIndex)) { + if (!cityIsValid(areaIdx)) { return -1; } - if (x < 0 || x >= WM_TILE_WIDTH * gWorldmapGridWidth) { + if (x < 0 || x >= WM_TILE_WIDTH * wmNumHorizontalTiles) { return -1; } - if (y < 0 || y >= WM_TILE_HEIGHT * (gWorldmapTilesLength / gWorldmapGridWidth)) { + if (y < 0 || y >= WM_TILE_HEIGHT * (wmMaxTileNum / wmNumHorizontalTiles)) { return -1; } - CityInfo* city = &(gCities[cityIndex]); + CityInfo* city = &(wmAreaInfoList[areaIdx]); city->x = x; city->y = y; @@ -6153,14 +6001,14 @@ int worldmapCitySetPos(int cityIndex, int x, int y) // Returns current town x/y. // // 0x4C47A4 -int _wmGetPartyWorldPos(int* out_x, int* out_y) +int wmGetPartyWorldPos(int* xPtr, int* yPtr) { - if (out_x != NULL) { - *out_x = _world_xpos; + if (xPtr != NULL) { + *xPtr = wmGenData.worldPosX; } - if (out_y != NULL) { - *out_y = _world_ypos; + if (yPtr != NULL) { + *yPtr = wmGenData.worldPosY; } return 0; @@ -6169,10 +6017,10 @@ int _wmGetPartyWorldPos(int* out_x, int* out_y) // Returns current town. // // 0x4C47C0 -int _wmGetPartyCurArea(int* a1) +int wmGetPartyCurArea(int* areaIdxPtr) { - if (a1) { - *a1 = _WorldMapCurrArea; + if (areaIdxPtr != NULL) { + *areaIdxPtr = wmGenData.currentAreaId; return 0; } @@ -6180,40 +6028,40 @@ int _wmGetPartyCurArea(int* a1) } // 0x4C47D8 -void _wmMarkAllSubTiles(int a1) +static void wmMarkAllSubTiles(int state) { - for (int tileIndex = 0; tileIndex < gWorldmapTilesLength; tileIndex++) { - TileInfo* tile = &(gWorldmapTiles[tileIndex]); + for (int tileIndex = 0; tileIndex < wmMaxTileNum; tileIndex++) { + TileInfo* tile = &(wmTileInfoList[tileIndex]); for (int column = 0; column < SUBTILE_GRID_HEIGHT; column++) { for (int row = 0; row < SUBTILE_GRID_WIDTH; row++) { SubtileInfo* subtile = &(tile->subtiles[column][row]); - subtile->state = a1; + subtile->state = state; } } } } // 0x4C4850 -void _wmTownMap() +void wmTownMap() { - _wmWorldMapFunc(1); + wmWorldMapFunc(1); } // 0x4C485C -int worldmapCityMapViewSelect(int* mapIndexPtr) +static int wmTownMapFunc(int* mapIdxPtr) { - *mapIndexPtr = -1; + *mapIdxPtr = -1; - if (worldmapCityMapViewInit() == -1) { - worldmapCityMapViewFree(); + if (wmTownMapInit() == -1) { + wmTownMapExit(); return -1; } - if (_WorldMapCurrArea == -1) { + if (wmGenData.currentAreaId == -1) { return -1; } - CityInfo* city = &(gCities[_WorldMapCurrArea]); + CityInfo* city = &(wmAreaInfoList[wmGenData.currentAreaId]); for (;;) { int keyCode = _get_input(); @@ -6241,7 +6089,7 @@ int worldmapCityMapViewSelect(int* mapIndexPtr) } } - *mapIndexPtr = entrance->map; + *mapIdxPtr = entrance->map; mapSetEnteringLocation(entrance->elevation, entrance->tile, entrance->rotation); @@ -6249,34 +6097,34 @@ int worldmapCityMapViewSelect(int* mapIndexPtr) } if (keyCode >= KEY_CTRL_F1 && keyCode <= KEY_CTRL_F7) { - int quickDestinationIndex = _LastTabsYOffset / 27 + keyCode - KEY_CTRL_F1; - if (quickDestinationIndex < gQuickDestinationsLength) { - int cityIndex = gQuickDestinations[quickDestinationIndex]; - CityInfo* city = &(gCities[cityIndex]); - if (!_wmAreaIsKnown(city->field_28)) { + int quickDestinationIndex = wmGenData.tabsOffsetY / 27 + keyCode - KEY_CTRL_F1; + if (quickDestinationIndex < wmLabelCount) { + int areaIdx = wmLabelList[quickDestinationIndex]; + CityInfo* city = &(wmAreaInfoList[areaIdx]); + if (!wmAreaIsKnown(city->areaId)) { break; } - if (cityIndex != _WorldMapCurrArea) { + if (areaIdx != wmGenData.currentAreaId) { // CE: Fix incorrect destination positioning. See - // `_wmWorldMapFunc` for explanation. - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[city->size]); + // `wmWorldMapFunc` for explanation. + CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]); int destX = city->x + citySizeDescription->width / 2 - WM_VIEW_X; int destY = city->y + citySizeDescription->height / 2 - WM_VIEW_Y; - _wmPartyInitWalking(destX, destY); + wmPartyInitWalking(destX, destY); - _wmGenData = 0; + wmGenData.mousePressed = false; break; } } } else { if (keyCode == KEY_CTRL_ARROW_UP) { - _wmInterfaceScrollTabsStart(-27); + wmInterfaceScrollTabsStart(-27); } else if (keyCode == KEY_CTRL_ARROW_DOWN) { - _wmInterfaceScrollTabsStart(27); + wmInterfaceScrollTabsStart(27); } else if (keyCode == 2069) { - if (worldmapCityMapViewRefresh() == -1) { + if (wmTownMapRefresh() == -1) { return -1; } } @@ -6292,7 +6140,7 @@ int worldmapCityMapViewSelect(int* mapIndexPtr) } } - if (worldmapCityMapViewFree() == -1) { + if (wmTownMapExit() == -1) { return -1; } @@ -6300,30 +6148,30 @@ int worldmapCityMapViewSelect(int* mapIndexPtr) } // 0x4C4A6C -int worldmapCityMapViewInit() +static int wmTownMapInit() { - _wmTownMapCurArea = _WorldMapCurrArea; + wmTownMapCurArea = wmGenData.currentAreaId; - CityInfo* city = &(gCities[_WorldMapCurrArea]); + CityInfo* city = &(wmAreaInfoList[wmGenData.currentAreaId]); - Art* mapFrm = artLock(city->mapFid, &gWorldmapCityMapFrmHandle); + Art* mapFrm = artLock(city->mapFid, &wmTownKey); if (mapFrm == NULL) { return -1; } - gWorldmapCityMapFrmWidth = artGetWidth(mapFrm, 0, 0); - gWorldmapCityMapFrmHeight = artGetHeight(mapFrm, 0, 0); + wmTownWidth = artGetWidth(mapFrm, 0, 0); + wmTownHeight = artGetHeight(mapFrm, 0, 0); - artUnlock(gWorldmapCityMapFrmHandle); - gWorldmapCityMapFrmHandle = INVALID_CACHE_ENTRY; + artUnlock(wmTownKey); + wmTownKey = INVALID_CACHE_ENTRY; - gWorldmapCityMapFrmData = artLockFrameData(city->mapFid, 0, 0, &gWorldmapCityMapFrmHandle); - if (gWorldmapCityMapFrmData == NULL) { + wmTownBuffer = artLockFrameData(city->mapFid, 0, 0, &wmTownKey); + if (wmTownBuffer == NULL) { return -1; } for (int index = 0; index < city->entrancesLength; index++) { - _wmTownMapButtonId[index] = -1; + wmTownMapButtonId[index] = -1; } for (int index = 0; index < city->entrancesLength; index++) { @@ -6336,28 +6184,28 @@ int worldmapCityMapViewInit() continue; } - _wmTownMapButtonId[index] = buttonCreate(gWorldmapWindow, + wmTownMapButtonId[index] = buttonCreate(wmBkWin, entrance->x, entrance->y, - gWorldmapHotspotUpFrmWidth, - gWorldmapHotspotUpFrmHeight, + wmGenData.hotspotFrmWidth, + wmGenData.hotspotFrmHeight, -1, 2069, -1, KEY_1 + index, - gWorldmapHotspotUpFrmData, - gWorldmapHotspotDownFrmData, + wmGenData.hotspotNormalFrmData, + wmGenData.hotspotPressedFrmData, NULL, BUTTON_FLAG_TRANSPARENT); - if (_wmTownMapButtonId[index] == -1) { + if (wmTownMapButtonId[index] == -1) { return -1; } } - tickersRemove(worldmapWindowHandleMouseScrolling); + tickersRemove(wmMouseBkProc); - if (worldmapCityMapViewRefresh() == -1) { + if (wmTownMapRefresh() == -1) { return -1; } @@ -6365,18 +6213,18 @@ int worldmapCityMapViewInit() } // 0x4C4BD0 -int worldmapCityMapViewRefresh() +static int wmTownMapRefresh() { - blitBufferToBuffer(gWorldmapCityMapFrmData, - gWorldmapCityMapFrmWidth, - gWorldmapCityMapFrmHeight, - gWorldmapCityMapFrmWidth, - gWorldmapWindowBuffer + WM_WINDOW_WIDTH * WM_VIEW_Y + WM_VIEW_X, + blitBufferToBuffer(wmTownBuffer, + wmTownWidth, + wmTownHeight, + wmTownWidth, + wmBkWinBuf + WM_WINDOW_WIDTH * WM_VIEW_Y + WM_VIEW_X, WM_WINDOW_WIDTH); - worldmapWindowRenderChrome(false); + wmRefreshInterfaceOverlay(false); - CityInfo* city = &(gCities[_WorldMapCurrArea]); + CityInfo* city = &(wmAreaInfoList[wmGenData.currentAreaId]); for (int index = 0; index < city->entrancesLength; index++) { EntranceInfo* entrance = &(city->entrances[index]); @@ -6389,53 +6237,53 @@ int worldmapCityMapViewRefresh() } MessageListItem messageListItem; - messageListItem.num = 200 + 10 * _wmTownMapCurArea + index; - if (messageListGetItem(&gWorldmapMessageList, &messageListItem)) { + messageListItem.num = 200 + 10 * wmTownMapCurArea + index; + if (messageListGetItem(&wmMsgFile, &messageListItem)) { if (messageListItem.text != NULL) { int width = fontGetStringWidth(messageListItem.text); // CE: Slightly increase whitespace between marker and entrance name. - windowDrawText(gWorldmapWindow, messageListItem.text, width, gWorldmapHotspotUpFrmWidth / 2 + entrance->x - width / 2, gWorldmapHotspotUpFrmHeight + entrance->y + 4, _colorTable[992] | 0x2010000); + windowDrawText(wmBkWin, messageListItem.text, width, wmGenData.hotspotFrmWidth / 2 + entrance->x - width / 2, wmGenData.hotspotFrmHeight + entrance->y + 4, _colorTable[992] | 0x2010000); } } } - windowRefresh(gWorldmapWindow); + windowRefresh(wmBkWin); return 0; } // 0x4C4D00 -int worldmapCityMapViewFree() +static int wmTownMapExit() { - if (gWorldmapCityMapFrmHandle != INVALID_CACHE_ENTRY) { - artUnlock(gWorldmapCityMapFrmHandle); - gWorldmapCityMapFrmHandle = INVALID_CACHE_ENTRY; - gWorldmapCityMapFrmData = NULL; - gWorldmapCityMapFrmWidth = 0; - gWorldmapCityMapFrmHeight = 0; + if (wmTownKey != INVALID_CACHE_ENTRY) { + artUnlock(wmTownKey); + wmTownKey = INVALID_CACHE_ENTRY; + wmTownBuffer = NULL; + wmTownWidth = 0; + wmTownHeight = 0; } - if (_wmTownMapCurArea != -1) { - CityInfo* city = &(gCities[_wmTownMapCurArea]); + if (wmTownMapCurArea != -1) { + CityInfo* city = &(wmAreaInfoList[wmTownMapCurArea]); for (int index = 0; index < city->entrancesLength; index++) { - if (_wmTownMapButtonId[index] != -1) { - buttonDestroy(_wmTownMapButtonId[index]); - _wmTownMapButtonId[index] = -1; + if (wmTownMapButtonId[index] != -1) { + buttonDestroy(wmTownMapButtonId[index]); + wmTownMapButtonId[index] = -1; } } } - if (worldmapWindowRefresh() == -1) { + if (wmInterfaceRefresh() == -1) { return -1; } - tickersAdd(worldmapWindowHandleMouseScrolling); + tickersAdd(wmMouseBkProc); return 0; } // 0x4C4DA4 -int carConsumeFuel(int amount) +int wmCarUseGas(int amount) { if (gameGetGlobalVar(GVAR_NEW_RENO_SUPER_CAR) != 0) { amount -= amount * 90 / 100; @@ -6449,10 +6297,10 @@ int carConsumeFuel(int amount) amount /= 2; } - gWorldmapCarFuel -= amount; + wmGenData.carFuel -= amount; - if (gWorldmapCarFuel < 0) { - gWorldmapCarFuel = 0; + if (wmGenData.carFuel < 0) { + wmGenData.carFuel = 0; } return 0; @@ -6461,52 +6309,52 @@ int carConsumeFuel(int amount) // Returns amount of fuel that does not fit into tank. // // 0x4C4E34 -int carAddFuel(int amount) +int wmCarFillGas(int amount) { - if ((amount + gWorldmapCarFuel) <= CAR_FUEL_MAX) { - gWorldmapCarFuel += amount; + if ((amount + wmGenData.carFuel) <= CAR_FUEL_MAX) { + wmGenData.carFuel += amount; return 0; } - int remaining = CAR_FUEL_MAX - gWorldmapCarFuel; + int remaining = CAR_FUEL_MAX - wmGenData.carFuel; - gWorldmapCarFuel = CAR_FUEL_MAX; + wmGenData.carFuel = CAR_FUEL_MAX; return remaining; } // 0x4C4E74 -int carGetFuel() +int wmCarGasAmount() { - return gWorldmapCarFuel; + return wmGenData.carFuel; } // 0x4C4E7C -bool carIsEmpty() +bool wmCarIsOutOfGas() { - return gWorldmapCarFuel <= 0; + return wmGenData.carFuel <= 0; } // 0x4C4E8C -int carGetCity() +int wmCarCurrentArea() { - return _carCurrentArea; + return wmGenData.currentCarAreaId; } // 0x4C4E94 -int _wmCarGiveToParty() +int wmCarGiveToParty() { MessageListItem messageListItem; - memcpy(&messageListItem, &stru_4BC880, sizeof(MessageListItem)); + memcpy(&messageListItem, &gWorldmapMessageListItem, sizeof(MessageListItem)); - if (gWorldmapCarFuel <= 0) { + if (wmGenData.carFuel <= 0) { // The car is out of power. - char* msg = getmsg(&gWorldmapMessageList, &messageListItem, 1502); + char* msg = getmsg(&wmMsgFile, &messageListItem, 1502); displayMonitorAddMessage(msg); return -1; } - gWorldmapIsInCar = true; + wmGenData.isInCar = true; MapTransition transition; memset(&transition, 0, sizeof(transition)); @@ -6514,34 +6362,34 @@ int _wmCarGiveToParty() transition.map = -2; mapSetTransition(&transition); - CityInfo* city = &(gCities[CITY_CAR_OUT_OF_GAS]); - city->state = 0; - city->field_40 = 0; + CityInfo* city = &(wmAreaInfoList[CITY_CAR_OUT_OF_GAS]); + city->state = CITY_STATE_UNKNOWN; + city->visitedState = 0; return 0; } // 0x4C4F28 -int ambientSoundEffectGetLength() +int wmSfxMaxCount() { - int mapIndex = mapGetCurrentMap(); - if (mapIndex < 0 || mapIndex >= gMapsLength) { + int mapIdx = mapGetCurrentMap(); + if (mapIdx < 0 || mapIdx >= wmMaxMapNum) { return -1; } - MapInfo* map = &(gMaps[mapIndex]); + MapInfo* map = &(wmMapInfoList[mapIdx]); return map->ambientSoundEffectsLength; } // 0x4C4F5C -int ambientSoundEffectGetRandom() +int wmSfxRollNextIdx() { - int mapIndex = mapGetCurrentMap(); - if (mapIndex < 0 || mapIndex >= gMapsLength) { + int mapIdx = mapGetCurrentMap(); + if (mapIdx < 0 || mapIdx >= wmMaxMapNum) { return -1; } - MapInfo* map = &(gMaps[mapIndex]); + MapInfo* map = &(wmMapInfoList[mapIdx]); int totalChances = 0; for (int index = 0; index < map->ambientSoundEffectsLength; index++) { @@ -6564,7 +6412,7 @@ int ambientSoundEffectGetRandom() } // 0x4C5004 -int ambientSoundEffectGetName(int ambientSoundEffectIndex, char** namePtr) +int wmSfxIdxName(int sfxIdx, char** namePtr) { if (namePtr == NULL) { return -1; @@ -6572,17 +6420,17 @@ int ambientSoundEffectGetName(int ambientSoundEffectIndex, char** namePtr) *namePtr = NULL; - int mapIndex = mapGetCurrentMap(); - if (mapIndex < 0 || mapIndex >= gMapsLength) { + int mapIdx = mapGetCurrentMap(); + if (mapIdx < 0 || mapIdx >= wmMaxMapNum) { return -1; } - MapInfo* map = &(gMaps[mapIndex]); - if (ambientSoundEffectIndex < 0 || ambientSoundEffectIndex >= map->ambientSoundEffectsLength) { + MapInfo* map = &(wmMapInfoList[mapIdx]); + if (sfxIdx < 0 || sfxIdx >= map->ambientSoundEffectsLength) { return -1; } - MapAmbientSoundEffectInfo* ambientSoundEffectInfo = &(map->ambientSoundEffects[ambientSoundEffectIndex]); + MapAmbientSoundEffectInfo* ambientSoundEffectInfo = &(map->ambientSoundEffects[sfxIdx]); *namePtr = ambientSoundEffectInfo->name; int v1 = 0; @@ -6605,7 +6453,7 @@ int ambientSoundEffectGetName(int ambientSoundEffectIndex, char** namePtr) } if (dayPart == DAY_PART_NIGHT) { - *namePtr = _wmRemapSfxList[v1 - 1]; + *namePtr = wmRemapSfxList[v1 - 1]; } } @@ -6613,70 +6461,70 @@ int ambientSoundEffectGetName(int ambientSoundEffectIndex, char** namePtr) } // 0x4C50F4 -int worldmapWindowRenderChrome(bool shouldRefreshWindow) +static int wmRefreshInterfaceOverlay(bool shouldRefreshWindow) { - blitBufferToBufferTrans(gWorldmapBoxFrmData, - gWorldmapBoxFrmWidth, - gWorldmapBoxFrmHeight, - gWorldmapBoxFrmWidth, - gWorldmapWindowBuffer, + blitBufferToBufferTrans(wmBkArtBuf, + wmBkWidth, + wmBkHeight, + wmBkWidth, + wmBkWinBuf, WM_WINDOW_WIDTH); - worldmapRenderQuickDestinations(); + wmRefreshTabs(); // NOTE: Uninline. wmInterfaceDialSyncTime(false); - worldmapWindowRenderDial(false); + wmRefreshInterfaceDial(false); - if (gWorldmapIsInCar) { - unsigned char* data = artGetFrameData(gWorldmapCarFrm, gWorldmapCarFrmCurrentFrame, 0); + if (wmGenData.isInCar) { + unsigned char* data = artGetFrameData(wmGenData.carImageFrm, wmGenData.carImageCurrentFrameIndex, 0); if (data == NULL) { return -1; } blitBufferToBuffer(data, - gWorldmapCarFrmWidth, - gWorldmapCarFrmHeight, - gWorldmapCarFrmWidth, - gWorldmapWindowBuffer + WM_WINDOW_WIDTH * WM_WINDOW_CAR_Y + WM_WINDOW_CAR_X, + wmGenData.carImageFrmWidth, + wmGenData.carImageFrmHeight, + wmGenData.carImageFrmWidth, + wmBkWinBuf + WM_WINDOW_WIDTH * WM_WINDOW_CAR_Y + WM_WINDOW_CAR_X, WM_WINDOW_WIDTH); - blitBufferToBufferTrans(gWorldmapCarOverlayFrmData, - gWorldmapCarOverlayFrmWidth, - gWorldmapCarOverlayFrmHeight, - gWorldmapCarOverlayFrmWidth, - gWorldmapWindowBuffer + WM_WINDOW_WIDTH * WM_WINDOW_CAR_OVERLAY_Y + WM_WINDOW_CAR_OVERLAY_X, + blitBufferToBufferTrans(wmGenData.carImageOverlayFrmData, + wmGenData.carImageOverlayFrmWidth, + wmGenData.carImageOverlayFrmHeight, + wmGenData.carImageOverlayFrmWidth, + wmBkWinBuf + WM_WINDOW_WIDTH * WM_WINDOW_CAR_OVERLAY_Y + WM_WINDOW_CAR_OVERLAY_X, WM_WINDOW_WIDTH); - worldmapWindowRenderCarFuelBar(); + wmInterfaceRefreshCarFuel(); } else { - blitBufferToBufferTrans(gWorldmapGlobeOverlayFrmData, - gWorldmapGlobeOverlayFrmWidth, - gWorldmapGloveOverlayFrmHeight, - gWorldmapGlobeOverlayFrmWidth, - gWorldmapWindowBuffer + WM_WINDOW_WIDTH * WM_WINDOW_GLOBE_OVERLAY_Y + WM_WINDOW_GLOBE_OVERLAY_X, + blitBufferToBufferTrans(wmGenData.globeOverlayFrmData, + wmGenData.globeOverlayFrmWidth, + wmGenData.globeOverlayFrmHeight, + wmGenData.globeOverlayFrmWidth, + wmBkWinBuf + WM_WINDOW_WIDTH * WM_WINDOW_GLOBE_OVERLAY_Y + WM_WINDOW_GLOBE_OVERLAY_X, WM_WINDOW_WIDTH); } - worldmapWindowRenderDate(false); + wmInterfaceRefreshDate(false); if (shouldRefreshWindow) { - windowRefresh(gWorldmapWindow); + windowRefresh(wmBkWin); } return 0; } // 0x4C5244 -void worldmapWindowRenderCarFuelBar() +static void wmInterfaceRefreshCarFuel() { - int ratio = (WM_WINDOW_CAR_FUEL_BAR_HEIGHT * gWorldmapCarFuel) / CAR_FUEL_MAX; + int ratio = (WM_WINDOW_CAR_FUEL_BAR_HEIGHT * wmGenData.carFuel) / CAR_FUEL_MAX; if ((ratio & 1) != 0) { ratio -= 1; } - unsigned char* dest = gWorldmapWindowBuffer + WM_WINDOW_WIDTH * WM_WINDOW_CAR_FUEL_BAR_Y + WM_WINDOW_CAR_FUEL_BAR_X; + unsigned char* dest = wmBkWinBuf + WM_WINDOW_WIDTH * WM_WINDOW_CAR_FUEL_BAR_Y + WM_WINDOW_CAR_FUEL_BAR_X; for (int index = WM_WINDOW_CAR_FUEL_BAR_HEIGHT; index > ratio; index--) { *dest = 14; @@ -6695,7 +6543,7 @@ void worldmapWindowRenderCarFuelBar() } // 0x4C52B0 -int worldmapRenderQuickDestinations() +static int wmRefreshTabs() { unsigned char* v30; unsigned char* v0; @@ -6712,14 +6560,14 @@ int worldmapRenderQuickDestinations() int v32; unsigned char* v13; - blitBufferToBufferTrans(gWorldmapTownTabsUnderlayFrmData + gWorldmapTownTabsUnderlayFrmWidth * _LastTabsYOffset + 9, 119, 178, gWorldmapTownTabsUnderlayFrmWidth, gWorldmapWindowBuffer + WM_WINDOW_WIDTH * 135 + 501, WM_WINDOW_WIDTH); + blitBufferToBufferTrans(wmGenData.tabsBackgroundFrmData + wmGenData.tabsBackgroundFrmWidth * wmGenData.tabsOffsetY + 9, 119, 178, wmGenData.tabsBackgroundFrmWidth, wmBkWinBuf + WM_WINDOW_WIDTH * 135 + 501, WM_WINDOW_WIDTH); - v30 = gWorldmapWindowBuffer + WM_WINDOW_WIDTH * 138 + 530; - v0 = gWorldmapWindowBuffer + WM_WINDOW_WIDTH * 138 + 530 - WM_WINDOW_WIDTH * (_LastTabsYOffset % 27); - v31 = _LastTabsYOffset / 27; + v30 = wmBkWinBuf + WM_WINDOW_WIDTH * 138 + 530; + v0 = wmBkWinBuf + WM_WINDOW_WIDTH * 138 + 530 - WM_WINDOW_WIDTH * (wmGenData.tabsOffsetY % 27); + v31 = wmGenData.tabsOffsetY / 27; - if (v31 < gQuickDestinationsLength) { - city = &(gCities[gQuickDestinations[v31]]); + if (v31 < wmLabelCount) { + city = &(wmAreaInfoList[wmLabelList[v31]]); if (city->labelFid != -1) { art = artLock(city->labelFid, &cache_entry); if (art == NULL) { @@ -6733,8 +6581,8 @@ int worldmapRenderQuickDestinations() return -1; } - v10 = height - _LastTabsYOffset % 27; - v11 = buf + width * (_LastTabsYOffset % 27); + v10 = height - wmGenData.tabsOffsetY % 27; + v11 = buf + width * (wmGenData.tabsOffsetY % 27); v12 = v0; if (v0 < v30 - WM_WINDOW_WIDTH) { @@ -6751,8 +6599,8 @@ int worldmapRenderQuickDestinations() v32 = v31 + 6; for (int v14 = v31 + 1; v14 < v32; v14++) { - if (v14 < gQuickDestinationsLength) { - city = &(gCities[gQuickDestinations[v14]]); + if (v14 < wmLabelCount) { + city = &(wmAreaInfoList[wmLabelList[v14]]); if (city->labelFid != -1) { art = artLock(city->labelFid, &cache_entry); if (art == NULL) { @@ -6775,8 +6623,8 @@ int worldmapRenderQuickDestinations() v13 += WM_WINDOW_WIDTH * 27; } - if (v31 + 6 < gQuickDestinationsLength) { - city = &(gCities[gQuickDestinations[v31 + 6]]); + if (v31 + 6 < wmLabelCount) { + city = &(wmAreaInfoList[wmLabelList[v31 + 6]]); if (city->labelFid != -1) { art = artLock(city->labelFid, &cache_entry); if (art == NULL) { @@ -6797,7 +6645,7 @@ int worldmapRenderQuickDestinations() } } - blitBufferToBufferTrans(gWorldmapTownTabsEdgeFrmData, 119, 178, 119, gWorldmapWindowBuffer + WM_WINDOW_WIDTH * 135 + 501, WM_WINDOW_WIDTH); + blitBufferToBufferTrans(wmGenData.tabsBorderFrmData, 119, 178, 119, wmBkWinBuf + WM_WINDOW_WIDTH * 135 + 501, WM_WINDOW_WIDTH); return 0; } @@ -6805,7 +6653,7 @@ int worldmapRenderQuickDestinations() // Creates array of cities available as quick destinations. // // 0x4C55D4 -int _wmMakeTabsLabelList(int** quickDestinationsPtr, int* quickDestinationsLengthPtr) +static int wmMakeTabsLabelList(int** quickDestinationsPtr, int* quickDestinationsLengthPtr) { int* quickDestinations = *quickDestinationsPtr; @@ -6822,8 +6670,8 @@ int _wmMakeTabsLabelList(int** quickDestinationsPtr, int* quickDestinationsLengt } int quickDestinationsLength = *quickDestinationsLengthPtr; - for (int index = 0; index < gCitiesLength; index++) { - if (_wmAreaIsKnown(index) && gCities[index].labelFid != -1) { + for (int index = 0; index < wmMaxAreaNum; index++) { + if (wmAreaIsKnown(index) && wmAreaInfoList[index].labelFid != -1) { quickDestinationsLength++; *quickDestinationsLengthPtr = quickDestinationsLength; @@ -6842,19 +6690,19 @@ int _wmMakeTabsLabelList(int** quickDestinationsPtr, int* quickDestinationsLengt } } - qsort(quickDestinations, quickDestinationsLength, sizeof(*quickDestinations), worldmapCompareCitiesByName); + qsort(quickDestinations, quickDestinationsLength, sizeof(*quickDestinations), wmTabsCompareNames); return 0; } // 0x4C56C8 -int worldmapCompareCitiesByName(const void* a1, const void* a2) +static int wmTabsCompareNames(const void* a1, const void* a2) { int v1 = *(int*)a1; int v2 = *(int*)a2; - CityInfo* city1 = &(gCities[v1]); - CityInfo* city2 = &(gCities[v2]); + CityInfo* city1 = &(wmAreaInfoList[v1]); + CityInfo* city2 = &(wmAreaInfoList[v2]); return compat_stricmp(city1->name, city2->name); } @@ -6875,23 +6723,23 @@ static int wmFreeTabsLabelList(int** quickDestinationsListPtr, int* quickDestina } // 0x4C5734 -void worldmapWindowRenderDial(bool shouldRefreshWindow) +static void wmRefreshInterfaceDial(bool shouldRefreshWindow) { - unsigned char* data = artGetFrameData(gWorldmapDialFrm, gWorldmapDialFrmCurrentFrame, 0); + unsigned char* data = artGetFrameData(wmGenData.dialFrm, wmGenData.dialFrmCurrentFrameIndex, 0); blitBufferToBufferTrans(data, - gWorldmapDialFrmWidth, - gWorldmapDialFrmHeight, - gWorldmapDialFrmWidth, - gWorldmapWindowBuffer + WM_WINDOW_WIDTH * WM_WINDOW_DIAL_Y + WM_WINDOW_DIAL_X, + wmGenData.dialFrmWidth, + wmGenData.dialFrmHeight, + wmGenData.dialFrmWidth, + wmBkWinBuf + WM_WINDOW_WIDTH * WM_WINDOW_DIAL_Y + WM_WINDOW_DIAL_X, WM_WINDOW_WIDTH); if (shouldRefreshWindow) { Rect rect; rect.left = WM_WINDOW_DIAL_X; rect.top = WM_WINDOW_DIAL_Y - 1; - rect.right = rect.left + gWorldmapDialFrmWidth; - rect.bottom = rect.top + gWorldmapDialFrmHeight; - windowRefreshRect(gWorldmapWindow, &rect); + rect.right = rect.left + wmGenData.dialFrmWidth; + rect.bottom = rect.top + wmGenData.dialFrmHeight; + windowRefreshRect(wmBkWin, &rect); } } @@ -6904,23 +6752,23 @@ static void wmInterfaceDialSyncTime(bool shouldRefreshWindow) int frame; gameHour = gameTimeGetHour(); - frame = (gameHour / 100 + 12) % artGetFrameCount(gWorldmapDialFrm); - if (frame != gWorldmapDialFrmCurrentFrame) { - gWorldmapDialFrmCurrentFrame = frame; - worldmapWindowRenderDial(shouldRefreshWindow); + frame = (gameHour / 100 + 12) % artGetFrameCount(wmGenData.dialFrm); + if (frame != wmGenData.dialFrmCurrentFrameIndex) { + wmGenData.dialFrmCurrentFrameIndex = frame; + wmRefreshInterfaceDial(shouldRefreshWindow); } } // 0x4C5804 -int _wmAreaFindFirstValidMap(int* out_a1) +static int wmAreaFindFirstValidMap(int* mapIdxPtr) { - *out_a1 = -1; + *mapIdxPtr = -1; - if (_WorldMapCurrArea == -1) { + if (wmGenData.currentAreaId == -1) { return -1; } - CityInfo* city = &(gCities[_WorldMapCurrArea]); + CityInfo* city = &(wmAreaInfoList[wmGenData.currentAreaId]); if (city->entrancesLength == 0) { return -1; } @@ -6928,7 +6776,7 @@ int _wmAreaFindFirstValidMap(int* out_a1) for (int index = 0; index < city->entrancesLength; index++) { EntranceInfo* entrance = &(city->entrances[index]); if (entrance->state != 0) { - *out_a1 = entrance->map; + *mapIdxPtr = entrance->map; return 0; } } @@ -6936,20 +6784,20 @@ int _wmAreaFindFirstValidMap(int* out_a1) EntranceInfo* entrance = &(city->entrances[0]); entrance->state = 1; - *out_a1 = entrance->map; + *mapIdxPtr = entrance->map; return 0; } // 0x4C58C0 -int worldmapStartMapMusic() +int wmMapMusicStart() { do { - int mapIndex = mapGetCurrentMap(); - if (mapIndex == -1 || mapIndex >= gMapsLength) { + int mapIdx = mapGetCurrentMap(); + if (mapIdx == -1 || mapIdx >= wmMaxMapNum) { break; } - MapInfo* map = &(gMaps[mapIndex]); + MapInfo* map = &(wmMapInfoList[mapIdx]); if (strlen(map->music) == 0) { break; } @@ -6966,11 +6814,10 @@ int worldmapStartMapMusic() return -1; } -// wmSetMapMusic // 0x4C5928 -int worldmapSetMapMusic(int mapIndex, const char* name) +int wmSetMapMusic(int mapIdx, const char* name) { - if (mapIndex == -1 || mapIndex >= gMapsLength) { + if (mapIdx == -1 || mapIdx >= wmMaxMapNum) { return -1; } @@ -6978,32 +6825,32 @@ int worldmapSetMapMusic(int mapIndex, const char* name) return -1; } - debugPrint("\nwmSetMapMusic: %d, %s", mapIndex, name); + debugPrint("\nwmSetMapMusic: %d, %s", mapIdx, name); - MapInfo* map = &(gMaps[mapIndex]); + MapInfo* map = &(wmMapInfoList[mapIdx]); strncpy(map->music, name, 40); map->music[39] = '\0'; - if (mapGetCurrentMap() == mapIndex) { + if (mapGetCurrentMap() == mapIdx) { backgroundSoundDelete(); - worldmapStartMapMusic(); + wmMapMusicStart(); } return 0; } // 0x4C59A4 -int _wmMatchAreaContainingMapIdx(int mapIndex, int* cityIndexPtr) +int wmMatchAreaContainingMapIdx(int mapIdx, int* areaIdxPtr) { - *cityIndexPtr = 0; + *areaIdxPtr = 0; - for (int cityIndex = 0; cityIndex < gCitiesLength; cityIndex++) { - CityInfo* cityInfo = &(gCities[cityIndex]); - for (int entranceIndex = 0; entranceIndex < cityInfo->entrancesLength; entranceIndex++) { - EntranceInfo* entranceInfo = &(cityInfo->entrances[entranceIndex]); - if (entranceInfo->map == mapIndex) { - *cityIndexPtr = cityIndex; + for (int areaIdx = 0; areaIdx < wmMaxAreaNum; areaIdx++) { + CityInfo* cityInfo = &(wmAreaInfoList[areaIdx]); + for (int entranceIdx = 0; entranceIdx < cityInfo->entrancesLength; entranceIdx++) { + EntranceInfo* entranceInfo = &(cityInfo->entrances[entranceIdx]); + if (entranceInfo->map == mapIdx) { + *areaIdxPtr = areaIdx; return 0; } } @@ -7013,25 +6860,25 @@ int _wmMatchAreaContainingMapIdx(int mapIndex, int* cityIndexPtr) } // 0x4C5A1C -int _wmTeleportToArea(int cityIndex) +int wmTeleportToArea(int areaIdx) { - if (!cityIsValid(cityIndex)) { + if (!cityIsValid(areaIdx)) { return -1; } - _WorldMapCurrArea = cityIndex; - gWorldmapTravelDestX = 0; - gWorldmapTravelDestY = 0; - gWorldmapIsTravelling = false; + wmGenData.currentAreaId = areaIdx; + wmGenData.walkDestinationX = 0; + wmGenData.walkDestinationY = 0; + wmGenData.isWalking = false; - CityInfo* city = &(gCities[cityIndex]); + CityInfo* city = &(wmAreaInfoList[areaIdx]); // SFALL: Fix for incorrect positioning after exiting small/medium // locations. - // CE: See `_wmWorldMapFunc` for explanation. - CitySizeDescription* citySizeDescription = &(gCitySizeDescriptions[city->size]); - _world_xpos = city->x + citySizeDescription->width / 2 - WM_VIEW_X; - _world_ypos = city->y + citySizeDescription->height / 2 - WM_VIEW_Y; + // CE: See `wmWorldMapFunc` for explanation. + CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]); + wmGenData.worldPosX = city->x + citySizeDescription->width / 2 - WM_VIEW_X; + wmGenData.worldPosY = city->y + citySizeDescription->height / 2 - WM_VIEW_Y; return 0; } diff --git a/src/worldmap.h b/src/worldmap.h index dcb9fbf..2d3d081 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -227,48 +227,52 @@ typedef enum Map { MAP_IN_GAME_MOVIE1 = 149, } Map; -int worldmapInit(); -void worldmapExit(); -int worldmapReset(); -int worldmapSave(File* stream); -int worldmapLoad(File* stream); -int mapGetCount(); -int mapGetFileName(int map_index, char* dest); -int mapGetIndexByFileName(char* name); -bool _wmMapIdxIsSaveable(int map_index); -bool _wmMapIsSaveable(); -bool _wmMapDeadBodiesAge(); -bool _wmMapCanRestHere(int elevation); -bool _wmMapPipboyActive(); -int _wmMapMarkVisited(int map_index); -int _wmMapMarkMapEntranceState(int a1, int a2, int a3); -void _wmWorldMap(); -int _wmCheckGameAreaEvents(); -int worldmapSetupRandomEncounter(); -bool _wmEvalTileNumForPlacement(int tile); +extern unsigned char* circleBlendTable; + +int wmWorldMap_init(); +void wmWorldMap_exit(); +int wmWorldMap_reset(); +int wmWorldMap_save(File* stream); +int wmWorldMap_load(File* stream); +int wmMapMaxCount(); +int wmMapIdxToName(int mapIdx, char* dest); +int wmMapMatchNameToIdx(char* name); +bool wmMapIdxIsSaveable(int mapIdx); +bool wmMapIsSaveable(); +bool wmMapDeadBodiesAge(); +bool wmMapCanRestHere(int elevation); +bool wmMapPipboyActive(); +int wmMapMarkVisited(int mapIdx); +int wmMapMarkMapEntranceState(int mapIdx, int elevation, int state); +void wmWorldMap(); +int wmCheckGameAreaEvents(); +int wmSetupRandomEncounter(); +bool wmEvalTileNumForPlacement(int tile); int wmSubTileMarkRadiusVisited(int x, int y, int radius); -int _wmSubTileGetVisitedState(int a1, int a2, int* a3); -int _wmGetAreaIdxName(int index, char* name); -bool _wmAreaIsKnown(int city_index); -int _wmAreaVisitedState(int a1); -bool _wmMapIsKnown(int map_index); -bool _wmAreaMarkVisitedState(int a1, int a2); -bool _wmAreaSetVisibleState(int a1, int a2, int a3); -int worldmapCitySetPos(int index, int x, int y); -int _wmGetPartyWorldPos(int* out_x, int* out_y); -int _wmGetPartyCurArea(int* a1); -void _wmTownMap(); -int carAddFuel(int a1); -int carGetFuel(); -bool carIsEmpty(); -int carGetCity(); -int _wmCarGiveToParty(); -int ambientSoundEffectGetLength(); -int ambientSoundEffectGetRandom(); -int ambientSoundEffectGetName(int ambientSoundEffectIndex, char** namePtr); -int worldmapStartMapMusic(); -int worldmapSetMapMusic(int a1, const char* name); -int _wmMatchAreaContainingMapIdx(int map_index, int* out_city_index); -int _wmTeleportToArea(int a1); +int wmSubTileGetVisitedState(int x, int y, int* statePtr); +int wmGetAreaIdxName(int areaIdx, char* name); +bool wmAreaIsKnown(int areaIdx); +int wmAreaVisitedState(int areaIdx); +bool wmMapIsKnown(int mapIdx); +int wmAreaMarkVisited(int areaIdx); +bool wmAreaMarkVisitedState(int areaIdx, int state); +bool wmAreaSetVisibleState(int areaIdx, int state, bool force); +int wmAreaSetWorldPos(int areaIdx, int x, int y); +int wmGetPartyWorldPos(int* xPtr, int* yPtr); +int wmGetPartyCurArea(int* areaIdxPtr); +void wmTownMap(); +int wmCarUseGas(int amount); +int wmCarFillGas(int amount); +int wmCarGasAmount(); +bool wmCarIsOutOfGas(); +int wmCarCurrentArea(); +int wmCarGiveToParty(); +int wmSfxMaxCount(); +int wmSfxRollNextIdx(); +int wmSfxIdxName(int sfxIdx, char** namePtr); +int wmMapMusicStart(); +int wmSetMapMusic(int mapIdx, const char* name); +int wmMatchAreaContainingMapIdx(int mapIdx, int* areaIdxPtr); +int wmTeleportToArea(int areaIdx); #endif /* WORLD_MAP_H */