get_tile_fid correct for backwards compatibility and flexibility

- Allow to pass elevation using the free bits of the tileNum value to access elevations 1 and 2 (instead of defaulting to dude_elevation, which is not how it worked before)
- Access roof FID and raw data using mode flags in the top 4 bits
This commit is contained in:
phobos2077
2023-06-12 18:26:28 +02:00
parent 0d960ca326
commit 4b9008d53c
4 changed files with 33 additions and 6 deletions
+13 -1
View File
@@ -823,7 +823,11 @@
- name: Tiles and paths
items:
- name: get_tile_fid
detail: int get_tile_fid(int tile)
detail: int get_tile_fid(int tileData)
doc: |
- returns FID information about the square under the given tile at elevation 0
- pass elevation as 4-bit number in bits 25-28 to access other elevations
- pass result mode in bits 29-32: 0 - Ground FID, 1 - Roof FID, 2 - Raw data.
opcode: 0x823a
- name: tile_under_cursor
detail: int tile_under_cursor
@@ -850,6 +854,14 @@
- returns the tile number at the x, y position relative to the top-left corner of the screen
- if the position is outside of the range of tiles, it will return -1
macro: sfall.h
- name: get_tile_ground_fid
detail: int get_tile_ground_fid(int tileNum, int elevation)
doc: Returns FID of a ground tile at given tileNum and elevation.
macro: sfall.h
- name: get_tile_roof_fid
detail: int get_tile_roof_fid(int tileNum, int elevation)
doc: Returns FID of a roof tile at given tileNum and elevation. Note that FID of 1 is used when there is no actual roof.
macro: sfall.h
- name: obj_blocking_line
detail: ObjectPtr obj_blocking_line(ObjectPtr objFrom, int tileTo, int blockingType)
+3
View File
@@ -321,6 +321,9 @@
#define get_npc_stat_max(stat) sfall_func2("get_stat_max", stat, 1)
#define get_npc_stat_min(stat) sfall_func2("get_stat_min", stat, 1)
#define get_sfall_arg_at(argNum) sfall_func1("get_sfall_arg_at", argNum)
#define get_tile_fid_ext(tile, elev, mode) get_tile_fid(((mode bwand 0xF) * 0x10000000) bwor ((elev bwand 0xF) * 0x1000000) bwor (tile bwand 0xFFFFFF))
#define get_tile_ground_fid(tile, elev) get_tile_fid_ext(tile, elev, 0)
#define get_tile_roof_fid(tile, elev) get_tile_fid_ext(tile, elev, 1)
#define get_terrain_name(x, y) sfall_func2("get_terrain_name", x, y)
#define get_text_width(text) sfall_func1("get_text_width", text)
#define has_fake_perk_npc(npc, perk) sfall_func2("has_fake_perk_npc", npc, perk)
+1 -1
View File
@@ -216,7 +216,7 @@ VAR_(sneak_working, DWORD) // DWORD var
VAR_(sound_music_path1, char*)
VAR_(sound_music_path2, char*)
VAR_(speech_volume, DWORD)
VARA(square, DWORD*, 3)
VARA(square, DWORD*, 3) // use (square && 0xFFF) to get ground fid, and ((square >> 16) && 0xFFF) to get roof
VAR_(square_rect, fo::SquareRect) // _square_y
VAR_(squares, DWORD*)
VARA(stack, DWORD, 10)
+16 -4
View File
@@ -332,13 +332,25 @@ end:
}
void op_get_tile_fid(OpcodeContext& ctx) {
long tileX, tileY, squareNum,
elevation = fo::var::obj_dude->elevation,
tileNum = ctx.arg(0).rawValue();
long tileX, tileY, squareNum, squareData, result,
tileAndElev = ctx.arg(0).rawValue(),
tileNum = tileAndElev & 0xFFFFFF,
elevation = (tileAndElev >> 24) & 0x0F,
mode = tileAndElev >> 28;
fo::func::tile_coord(tileNum, &tileX, &tileY);
squareNum = fo::func::square_num(tileX, tileY, elevation);
ctx.setReturn(fo::var::square[elevation][squareNum]);
squareData = fo::var::square[elevation][squareNum];
switch (mode) {
case 1:
result = (squareData >> 16) & 0xFFF; // roof
break;
case 2:
result = squareData; // raw data
default:
result = squareData & 0xFFF; // this is how opcode worked prior to 4.3.9
}
ctx.setReturn(result);
}
void __declspec(naked) op_modified_ini() {