* Around a position, run a certain function for all tiles within a certain radius. * * @note Radius is in a 1/4th of a tile unit. * * @param radius The radius of the to-update tiles. * @param position The position to go from. * @param unit The unit to update for (can be NULL if function < 2). * @param function The function to call. */
| 1026 | * @param function The function to call. |
| 1027 | */ |
| 1028 | void Map_UpdateAround(uint16 radius, tile32 position, Unit *unit, uint8 function) |
| 1029 | { |
| 1030 | static const uint16 tileOffsets[] = { |
| 1031 | 0x0080, 0x0088, 0x0090, 0x0098, |
| 1032 | 0x00A0, 0x00A8, 0x00B0, 0x00B8, |
| 1033 | 0x00C0, 0x00C8, 0x00D0, 0x00D8, |
| 1034 | 0x00E0, 0x00E8, 0x00F0, 0x00F8, |
| 1035 | 0x0100, 0x0180 |
| 1036 | }; |
| 1037 | |
| 1038 | int16 i, j; |
| 1039 | tile32 diff; |
| 1040 | uint16 lastPacked; |
| 1041 | |
| 1042 | if (radius == 0 || (position.x == 0 && position.y == 0)) return; |
| 1043 | |
| 1044 | radius--; |
| 1045 | |
| 1046 | /* If radius is bigger or equal than 32, update all tiles in a 5x5 grid around the unit. */ |
| 1047 | if (radius >= 32) { |
| 1048 | uint16 x = Tile_GetPosX(position); |
| 1049 | uint16 y = Tile_GetPosY(position); |
| 1050 | |
| 1051 | for (i = -2; i <= 2; i++) { |
| 1052 | for (j = -2; j <= 2; j++) { |
| 1053 | uint16 curPacked; |
| 1054 | |
| 1055 | if (x + i < 0 || x + i >= 64 || y + j < 0 || y + j >= 64) continue; |
| 1056 | |
| 1057 | curPacked = Tile_PackXY(x + i, y + j); |
| 1058 | BitArray_Set(g_dirtyViewport, curPacked); |
| 1059 | g_dirtyViewportCount++; |
| 1060 | |
| 1061 | switch (function) { |
| 1062 | case 0: Map_Update(curPacked, 0, false); break; |
| 1063 | case 1: Map_Update(curPacked, 3, false); break; |
| 1064 | case 2: Unit_RemoveFromTile(unit, curPacked); break; |
| 1065 | case 3: Unit_AddToTile(unit, curPacked); break; |
| 1066 | default: break; |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | radius = max(radius, 15); |
| 1074 | position.x -= tileOffsets[radius - 15]; |
| 1075 | position.y -= tileOffsets[radius - 15]; |
| 1076 | |
| 1077 | diff.x = 0; |
| 1078 | diff.y = 0; |
| 1079 | lastPacked = 0; |
| 1080 | |
| 1081 | i = 0; |
| 1082 | do { |
| 1083 | tile32 curTile = Tile_AddTileDiff(position, diff); |
| 1084 | |
| 1085 | if (Tile_IsValid(curTile)) { |
no test coverage detected