| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/editor/TerrainDialog.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:39 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Terrain dialog implementaion |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 75 4/29/99 3:49p Matt |
| 30 | * Fixed compiler warning |
| 31 | * |
| 32 | * 74 4/27/99 3:38p Jason |
| 33 | * fixed occlusion bug |
| 34 | * |
| 35 | * 73 4/17/99 6:15p Samir |
| 36 | * replaced gr.h with grdefs.h and fixed resulting compile bugs. |
| 37 | * |
| 38 | * 72 2/26/99 3:32p Jason |
| 39 | * made satellites clip properly |
| 40 | * |
| 41 | * 71 2/21/99 12:28p Matt |
| 42 | * Added terrain sound system |
| 43 | * |
| 44 | * 70 1/24/99 5:44p Jason |
| 45 | * added more selection choice for terrain |
| 46 | * |
| 47 | * 69 1/22/99 3:59p Jason |
| 48 | * added 256x256 textures to help with terrain skies |
| 49 | * |
| 50 | * 68 1/21/99 11:15p Jeff |
| 51 | * pulled out some structs and defines from header files and moved them |
| 52 | * into seperate header files so that multiplayer dlls don't require major |
| 53 | * game headers, just those new headers. Side effect is a shorter build |
| 54 | * time. Also cleaned up some header file #includes that weren't needed. |
| 55 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 56 | * manage.h and multi.h |
| 57 | * |
| 58 | * 67 1/21/99 12:31a Jason |
| 59 | * fixed stack bug |
| 60 | * |
| 61 | * 66 1/20/99 10:50a Jason |
| 62 | * added new terrain |
| 63 | * |
| 64 | * 65 1/15/99 7:52p Chris |
| 65 | * Updated ObjSetPos() to include a f_update_attach_children flag |
| 66 | * |
| 67 | * 64 1/05/99 4:14p Matt |
| 68 | * Fixed compile warning |
| 69 | * |
| 70 | * 63 11/18/98 4:30p Jason |
| 71 | * added some functionality to terrain fog |
| 72 | * |
| 73 | * 62 11/11/98 11:42a Jason |
| 74 | * added sunlight damage |
| 75 | * |
| 76 | * 61 10/14/98 2:48p Kevin |
| 77 | * Changed memory code to comply with mem lib |
| 78 | * |
| 79 | * 60 10/08/98 4:24p Kevin |
| 80 | * Changed code to comply with memory library usage. Always use mem_malloc |
| 81 | * , mem_free and mem_strdup |
| 82 | * |
| 83 | * 59 9/29/98 12:53p Jason |
| 84 | * added "force visiblity" for Luke |
| 85 | * |
| 86 | * 58 8/19/98 2:19p Jeff |
| 87 | * moved detail globals to a struct |
| 88 | * |
| 89 | * 57 8/13/98 1:13p Jason |
| 90 | * fixed terrain distance bug |
| 91 | * |
| 92 | * 56 7/20/98 12:04p Jason |
| 93 | * added per level satellite lighting |
| 94 | * |
| 95 | * 55 6/04/98 6:45p Jason |
| 96 | * made objects use the terrain occlusion system |
| 97 | * |
| 98 | * 54 6/04/98 6:16p Jason |
| 99 | * added terrain occlusion system |
| 100 | * |
| 101 | * 53 5/19/98 3:19p Jason |
| 102 | * cleaned up some texture flags |
| 103 | * |
| 104 | * 52 5/01/98 3:51p Jason |
| 105 | * sped up terrain rendering by precaching all megacell lod bitmaps |
| 106 | * |
| 107 | * 51 4/29/98 5:00p Matt |
| 108 | * Fixed stupid bug |
| 109 | * |
| 110 | * 50 4/29/98 3:58p Matt |
| 111 | * Made the drop terrain function take a desired height, instead of always |
| 112 | * moving the terrain to zero. |
| 113 | * |
| 114 | * 49 4/23/98 6:38p Jason |
| 115 | * made bitmaps use 1555 format |
| 116 | * |
| 117 | * 48 4/01/98 11:25a Jeff |
| 118 | * Added an editor bool to skip Terrain object rendering |
| 119 | * |
| 120 | * 47 3/30/98 5:43p Jason |
| 121 | * fixed pcx exporting |
| 122 | * |
| 123 | * 46 3/30/98 3:29p Jason |
| 124 | * added the ability to save a pcx version of the terrain |
| 125 | * |
| 126 | * 45 3/23/98 6:06p Matt |
| 127 | * Added code to "drop" the terrain so the lowest point has y==0, and to |
| 128 | * move the buildings, objects, & paths with it. |
| 129 | * |
| 130 | * 44 3/06/98 6:15p Jason |
| 131 | * Give message if no cells selected in smooth terrain |
| 132 | * |
| 133 | * 43 3/06/98 6:13p Jason |
| 134 | * Made terrain smoothing work on selected cells only |
| 135 | * |
| 136 | * 42 2/17/98 4:17p Jason |
| 137 | * fixed satellite placement |
| 138 | * |
| 139 | * 41 1/26/98 2:16p Jason |
| 140 | * allowed toggle of visibility to multiple cells |
| 141 | * |
| 142 | * 40 1/16/98 8:06p Jason |
| 143 | * added selectable halos and atmosphere blends to satellites |
| 144 | * |
| 145 | * 39 1/10/98 2:23p Jason |
| 146 | * fixed terrain checksum problem |
| 147 | * |
| 148 | * 38 1/07/98 4:19p Jason |
| 149 | * added dome to terrain sky |
| 150 | * |
| 151 | * 37 12/30/97 5:45p Jason |
| 152 | * added toggleable fog |
| 153 | * |
| 154 | * 36 12/17/97 5:26p Jason |
| 155 | * added support for selectable wraparound sky |
| 156 | * |
| 157 | * 35 12/11/97 1:41p Jason |
| 158 | * added terrain smoothing |
| 159 | * |
| 160 | * 34 12/02/97 5:31p Samir |
| 161 | * New file dialog interface implemented. |
| 162 | * |
| 163 | * 33 12/01/97 10:52a Jason |
| 164 | * separated satellite and star rendering flags |
| 165 | * |
| 166 | * 32 10/15/97 5:20p Jason |
| 167 | * did a HUGE overhaul of the bitmap system |
| 168 | * |
| 169 | * 31 10/06/97 12:16p Jason |
| 170 | * Ripped out old mine/terrain connection code, plus added ability to move |
| 171 | * satellites |
| 172 | * |
| 173 | * 30 10/02/97 6:10p Jason |
| 174 | * made invisible cells not be LODable |
| 175 | * |
| 176 | * 29 10/02/97 2:45p Jason |
| 177 | * got invisible terrain cells working |
| 178 | * |
| 179 | * 28 9/25/97 5:02p Jason |
| 180 | * fixed bug caused by last rev where pixelerror and terraindistance would |
| 181 | * be displayed |
| 182 | * |
| 183 | * 27 9/23/97 2:29p Jason |
| 184 | * did terrain editing enhancements |
| 185 | * |
| 186 | * 26 9/17/97 1:01p Matt |
| 187 | * Ripped out segment code |
| 188 | * |
| 189 | * 25 9/17/97 11:50a Jason |
| 190 | * ripped out segment engine |
| 191 | * |
| 192 | * 24 9/15/97 5:54p Jason |
| 193 | * delete room portals when deleting rooms connected to terrain |
| 194 | * |
| 195 | * 23 9/05/97 6:18p Jason |
| 196 | * made pixel error setable to 0 |
| 197 | * |
| 198 | * 22 9/02/97 10:47a Jason |
| 199 | * use separate variables for game and editor LOD engine status |
| 200 | * |
| 201 | * 21 8/26/97 4:36p Jason |
| 202 | * added terrain radiosity |
| 203 | * |
| 204 | * 20 8/25/97 12:04p Samir |
| 205 | * Added scrolling capabilities for dialog. |
| 206 | * |
| 207 | * 19 8/22/97 10:17a Matt |
| 208 | * When adding a room to the terrain, set the current face to be the one |
| 209 | * opposite the portal face. |
| 210 | * |
| 211 | * $NoKeywords: $ |
| 212 | */ |
| 213 | |
| 214 | #include <algorithm> |
| 215 | |
| 216 | #include "stdafx.h" |
| 217 | #include "editor.h" |
| 218 | #include "TerrainDialog.h" |
| 219 | #include "terrain.h" |
| 220 | #include "gametexture.h" |
| 221 | #include "bitmap.h" |
| 222 | #include "group.h" |
| 223 | #include "editor/d3edit.h" |
| 224 | #include "room.h" |
| 225 | #include "erooms.h" |
| 226 | #include "roomuvs.h" |
| 227 | #include "SelectRangeDialog.h" |
| 228 | #include "findintersection.h" |
| 229 | #include "config.h" |
| 230 | #include "mem.h" |
| 231 | #include "gr.h" |
| 232 | |
| 233 | #ifdef _DEBUG |
| 234 | #define new DEBUG_NEW |
| 235 | #undef THIS_FILE |
| 236 | static char THIS_FILE[] = __FILE__; |
| 237 | #endif |
| 238 | |
| 239 | ///////////////////////////////////////////////////////////////////////////// |
| 240 | // CTerrainDialog dialog |
| 241 | |
| 242 | CTerrainDialog::CTerrainDialog(CWnd *pParent /*=NULL*/) : CKeypadDialog(CTerrainDialog::IDD, pParent) { |
| 243 | //{{AFX_DATA_INIT(CTerrainDialog) |
| 244 | // NOTE: the ClassWizard will add member initialization here |
| 245 | //}}AFX_DATA_INIT |
| 246 | |
| 247 | cc_mode = CC_MODE_SKY; |
| 248 | } |
| 249 | |
| 250 | void CTerrainDialog::DoDataExchange(CDataExchange *pDX) { |
| 251 | CDialog::DoDataExchange(pDX); |
| 252 | //{{AFX_DATA_MAP(CTerrainDialog) |
| 253 | // NOTE: the ClassWizard will add DDX and DDV calls here |
| 254 | //}}AFX_DATA_MAP |
| 255 | } |
| 256 | |
| 257 | BEGIN_MESSAGE_MAP(CTerrainDialog, CDialog) |
| 258 | //{{AFX_MSG_MAP(CTerrainDialog) |
| 259 | ON_WM_SIZE() |
| 260 | ON_BN_CLICKED(IDC_TERRPAD_MOVE_UP, OnTerrpadMoveUp) |
| 261 | ON_BN_CLICKED(IDC_TERRPAD_MOVE_DOWN, OnTerrpadMoveDown) |
| 262 | ON_BN_CLICKED(IDC_TERRPAD_IMPORT, OnTerrpadImport) |
| 263 | ON_BN_CLICKED(IDC_TERRPAD_RENORMALIZE, OnTerrpadRenormalize) |
| 264 | ON_BN_CLICKED(IDC_TERRPAD_RAISE10, OnTerrpadRaise10) |
| 265 | ON_BN_CLICKED(IDC_TERRPAD_LOWER10, OnTerrpadLower10) |
| 266 | ON_BN_CLICKED(IDC_SKY_TEXTURE, OnSkyTexture) |
| 267 | ON_BN_CLICKED(IDC_TERRPAD_SELECT_NONE, OnTerrpadSelectNone) |
| 268 | ON_BN_CLICKED(IDC_TERRPAD_ROT_TEXTURE, OnTerrpadRotTexture) |
| 269 | ON_BN_CLICKED(IDC_SKY_NEARER, OnSkyNearer) |
| 270 | ON_BN_CLICKED(IDC_SKY_FARTHER, OnSkyFarther) |
| 271 | ON_BN_CLICKED(IDC_STARS_CHECK, OnStarsCheck) |
| 272 | ON_BN_CLICKED(IDC_FAST_TERRAIN_CHECK, OnFastTerrainCheck) |
| 273 | ON_BN_CLICKED(IDC_TERRPAD_FILL_AREA, OnTerrpadFillArea) |
| 274 | ON_BN_CLICKED(IDC_TERRPAD_REDO_TOPMAP, OnTerrpadRedoTopmap) |
| 275 | ON_BN_CLICKED(IDC_TERRPAD_MAKE_MAX, OnTerrpadMakeMax) |
| 276 | ON_BN_CLICKED(IDC_TERRPAD_MAKE_MIN, OnTerrpadMakeMin) |
| 277 | ON_BN_CLICKED(IDC_TERRPAD_MAKE_ZERO, OnTerrpadMakeZero) |
| 278 | ON_BN_CLICKED(IDC_TERRPAD_PYRAMID, OnTerrpadPyramid) |
| 279 | ON_BN_CLICKED(IDC_TERRPAD_HILL, OnTerrpadHill) |
| 280 | ON_BN_CLICKED(IDC_TERRPAD_PANCAKES, OnTerrpadPancakes) |
| 281 | ON_BN_CLICKED(IDC_TERR_MOVE_MOON, OnTerrMoveMoon) |
| 282 | ON_BN_CLICKED(IDC_TERR_RANDOMIZE_SKY, OnTerrRandomizeSky) |
| 283 | ON_WM_PAINT() |
| 284 | ON_BN_CLICKED(IDC_TERR_MORE_MOONS, OnTerrMoreMoons) |
| 285 | ON_BN_CLICKED(IDC_TERR_LESS_MOONS, OnTerrLessMoons) |
| 286 | ON_BN_CLICKED(IDC_TERR_NEXT_MOON, OnTerrNextMoon) |
| 287 | ON_BN_CLICKED(IDC_TERR_PREV_MOON, OnTerrPrevMoon) |
| 288 | ON_BN_CLICKED(IDC_SHOW_TERRAIN, OnShowTerrain) |
| 289 | ON_BN_CLICKED(IDC_FLAT_SHADE_TERRAIN_CHECK, OnFlatShadeTerrainCheck) |
| 290 | ON_WM_HELPINFO() |
| 291 | ON_BN_CLICKED(IDC_TERR_SELECT_ALL, OnTerrSelectAll) |
| 292 | ON_BN_CLICKED(IDC_TERRAIN_2D, OnTerrain2d) |
| 293 | ON_BN_CLICKED(IDC_TEXTURE_SKY, OnTextureSky) |
| 294 | ON_EN_KILLFOCUS(IDC_SKY_RED_EDIT, OnKillfocusSkyRedEdit) |
| 295 | ON_EN_KILLFOCUS(IDC_SKY_GREEN_EDIT, OnKillfocusSkyGreenEdit) |
| 296 | ON_EN_KILLFOCUS(IDC_SKY_BLUE_EDIT, OnKillfocusSkyBlueEdit) |
| 297 | ON_BN_CLICKED(IDC_NO_LOD_ENGINE, OnNoLodEngine) |
| 298 | ON_EN_KILLFOCUS(IDC_FOG_DISTANCE_EDIT, OnKillfocusFogDistanceEdit) |
| 299 | ON_EN_KILLFOCUS(IDC_PIXEL_ERROR_EDIT, OnKillfocusPixelErrorEdit) |
| 300 | ON_BN_CLICKED(IDC_TERRPAD_SELECTRANGE, OnTerrpadSelectrange) |
| 301 | ON_WM_VSCROLL() |
| 302 | ON_WM_HSCROLL() |
| 303 | ON_BN_CLICKED(IDC_SKY_RADIO, OnSkyRadio) |
| 304 | ON_BN_CLICKED(IDC_HORIZON_RADIO, OnHorizonRadio) |
| 305 | ON_BN_CLICKED(IDC_FOG_RADIO, OnFogRadio) |
| 306 | ON_BN_CLICKED(IDC_TOGGLE_VISIBILITY, OnToggleVisibility) |
| 307 | ON_BN_CLICKED(IDC_SHOW_INVISIBLE, OnShowInvisible) |
| 308 | ON_BN_CLICKED(IDC_TERR_MOVE_MOON_AWAY, OnTerrMoveMoonAway) |
| 309 | ON_BN_CLICKED(IDC_MOVE_SAT_UP, OnMoveSatUp) |
| 310 | ON_BN_CLICKED(IDC_MOVE_SAT_DOWN, OnMoveSatDown) |
| 311 | ON_BN_CLICKED(IDC_MOVE_SAT_LEFT, OnMoveSatLeft) |
| 312 | ON_BN_CLICKED(IDC_MOVE_SAT_RIGHT, OnMoveSatRight) |
| 313 | ON_BN_CLICKED(IDC_SATELLITE_CHECK, OnSatelliteCheck) |
| 314 | ON_BN_CLICKED(IDC_SMOOTH_TERRAIN, OnSmoothTerrain) |
| 315 | ON_BN_CLICKED(IDC_USE_FOG, OnUseFog) |
| 316 | ON_BN_CLICKED(IDC_USE_HALO, OnUseHalo) |
| 317 | ON_BN_CLICKED(IDC_USE_ATMOSPHERE, OnUseAtmosphere) |
| 318 | ON_BN_CLICKED(IDC_DROP_TERRAIN, OnDropTerrain) |
| 319 | ON_BN_CLICKED(IDC_SAVE_AS_PCX, OnSaveAsPcx) |
| 320 | ON_BN_CLICKED(IDC_NO_EXT_ROOMS_OBJS, OnNoExtRoomsObjs) |
| 321 | ON_BN_CLICKED(IDC_TERRAIN_OCCLUSION, OnTerrainOcclusion) |
| 322 | ON_BN_CLICKED(IDC_SATELLITE_RADIO, OnSatelliteRadio) |
| 323 | ON_BN_CLICKED(IDC_FORCE_VISIBLE, OnForceVisible) |
| 324 | ON_EN_KILLFOCUS(IDC_DAMAGE_PER_SEC_EDIT, OnKillfocusDamagePerSecEdit) |
| 325 | ON_EN_KILLFOCUS(IDC_FOG_SCALAR_EDIT, OnKillfocusFogScalarEdit) |
| 326 | ON_BN_CLICKED(IDC_ROTATE_STARS, OnRotateStars) |
| 327 | ON_BN_CLICKED(IDC_ROTATE_SKY, OnRotateSky) |
| 328 | ON_EN_KILLFOCUS(IDC_ROTATE_SPEED_EDIT, OnKillfocusRotateSpeedEdit) |
| 329 | ON_BN_CLICKED(IDC_TILE_MORE, OnTileMore) |
| 330 | ON_BN_CLICKED(IDC_TILE_LESS, OnTileLess) |
| 331 | ON_BN_CLICKED(IDC_TERR_SOUND, OnTerrSound) |
| 332 | //}}AFX_MSG_MAP |
| 333 | END_MESSAGE_MAP() |
| 334 | |
| 335 | ///////////////////////////////////////////////////////////////////////////// |
| 336 | // CTerrainDialog message handlers |
| 337 | |
| 338 | void CTerrainDialog::OnSize(UINT nType, int cx, int cy) { |
| 339 | CKeypadDialog::OnSize(nType, cx, cy); |
| 340 | |
| 341 | Current_satellite = 0; |
| 342 | cc_mode = CC_MODE_SKY; |
| 343 | } |
| 344 | |
| 345 | void CTerrainDialog::DrawSwatch(int handle, int r, int g, int b) { |
| 346 | CWnd *texwnd; |
| 347 | RECT rect; |
| 348 | int w, h; |
| 349 | |
| 350 | texwnd = GetDlgItem(handle); |
| 351 | texwnd->GetWindowRect(&rect); |
| 352 | ScreenToClient(&rect); |
| 353 | |
| 354 | Desktop_surf->attach_to_window((unsigned)m_hWnd); |
| 355 | |
| 356 | w = rect.right - rect.left; |
| 357 | h = rect.bottom - rect.top; |
| 358 | |
| 359 | ddgr_color color = GR_RGB(r, g, b); |
| 360 | |
| 361 | Desktop_surf->clear(rect.left, rect.top, w, h, color); |
| 362 | |
| 363 | Desktop_surf->attach_to_window(NULL); |
| 364 | } |
| 365 | |
| 366 | void CTerrainDialog::UpdateDialog() { |
| 367 | CButton *bbox; |
| 368 | char str[20]; |
| 369 | CEdit *ebox; |
| 370 | |
| 371 | if (!m_Active) |
| 372 | return; |
| 373 | |
| 374 | ebox = (CEdit *)GetDlgItem(IDC_DAMAGE_PER_SEC_EDIT); |
| 375 | sprintf(str, "%f", Terrain_sky.damage_per_second); |
| 376 | ebox->SetWindowText(str); |
| 377 | |
| 378 | ebox = (CEdit *)GetDlgItem(IDC_FOG_SCALAR_EDIT); |
| 379 | sprintf(str, "%f", Terrain_sky.fog_scalar); |
| 380 | ebox->SetWindowText(str); |
| 381 | |
| 382 | ebox = (CEdit *)GetDlgItem(IDC_FOG_DISTANCE_EDIT); |
| 383 | sprintf(str, "%f", Detail_settings.Terrain_render_distance / TERRAIN_SIZE); |
| 384 | ebox->SetWindowText(str); |
| 385 | |
| 386 | ebox = (CEdit *)GetDlgItem(IDC_PIXEL_ERROR_EDIT); |
| 387 | sprintf(str, "%f", Detail_settings.Pixel_error); |
| 388 | ebox->SetWindowText(str); |
| 389 | |
| 390 | ebox = (CEdit *)GetDlgItem(IDC_NUM_MOONS_STATIC); |
| 391 | sprintf(str, "Num of sats:%d", Terrain_sky.num_satellites); |
| 392 | ebox->SetWindowText(str); |
| 393 | |
| 394 | ebox = (CEdit *)GetDlgItem(IDC_CUR_MOON_STATIC); |
| 395 | sprintf(str, "Current sat:%d", Current_satellite); |
| 396 | ebox->SetWindowText(str); |
| 397 | |
| 398 | ebox = (CEdit *)GetDlgItem(IDC_ROTATE_SPEED_EDIT); |
| 399 | sprintf(str, "%f", Terrain_sky.rotate_rate); |
| 400 | ebox->SetWindowText(str); |
| 401 | |
| 402 | CheckDlgButton(IDC_TEXTURE_SKY, Terrain_sky.textured ? 1 : 0); |
| 403 | CheckDlgButton(IDC_STARS_CHECK, Terrain_sky.flags & TF_STARS ? 1 : 0); |
| 404 | CheckDlgButton(IDC_ROTATE_STARS, Terrain_sky.flags & TF_ROTATE_STARS ? 1 : 0); |
| 405 | CheckDlgButton(IDC_ROTATE_SKY, Terrain_sky.flags & TF_ROTATE_SKY ? 1 : 0); |
| 406 | CheckDlgButton(IDC_SATELLITE_CHECK, Terrain_sky.flags & TF_SATELLITES ? 1 : 0); |
| 407 | CheckDlgButton(IDC_USE_FOG, Terrain_sky.flags & TF_FOG ? 1 : 0); |
| 408 | CheckDlgButton(IDC_USE_HALO, Terrain_sky.satellite_flags[Current_satellite] & TSF_HALO ? 1 : 0); |
| 409 | CheckDlgButton(IDC_USE_ATMOSPHERE, Terrain_sky.satellite_flags[Current_satellite] & TSF_ATMOSPHERE ? 1 : 0); |
| 410 | |
| 411 | CheckDlgButton(IDC_FAST_TERRAIN_CHECK, Fast_terrain ? 1 : 0); |
| 412 | CheckDlgButton(IDC_SHOW_TERRAIN, D3EditState.terrain_dots ? 1 : 0); |
| 413 | CheckDlgButton(IDC_FLAT_SHADE_TERRAIN_CHECK, D3EditState.terrain_flat_shade ? 1 : 0); |
| 414 | CheckDlgButton(IDC_NO_LOD_ENGINE, Editor_LOD_engine_off ? 1 : 0); |
| 415 | CheckDlgButton(IDC_NO_EXT_ROOMS_OBJS, Terrain_render_ext_room_objs ? 0 : 1); |
| 416 | |
| 417 | bbox = (CButton *)GetDlgItem(IDC_SKY_RADIO); |
| 418 | bbox->SetCheck(cc_mode == CC_MODE_SKY); |
| 419 | |
| 420 | bbox = (CButton *)GetDlgItem(IDC_HORIZON_RADIO); |
| 421 | bbox->SetCheck(cc_mode == CC_MODE_HORIZON); |
| 422 | |
| 423 | bbox = (CButton *)GetDlgItem(IDC_FOG_RADIO); |
| 424 | bbox->SetCheck(cc_mode == CC_MODE_FOG); |
| 425 | |
| 426 | bbox = (CButton *)GetDlgItem(IDC_SATELLITE_RADIO); |
| 427 | bbox->SetCheck(cc_mode == CC_MODE_SAT); |
| 428 | |
| 429 | // Draw swatches |
| 430 | DrawSwatch(IDC_SKY_SWATCH, GR_COLOR_RED(Terrain_sky.sky_color), GR_COLOR_GREEN(Terrain_sky.sky_color), |
| 431 | GR_COLOR_BLUE(Terrain_sky.sky_color)); |
| 432 | DrawSwatch(IDC_HORIZON_SWATCH, GR_COLOR_RED(Terrain_sky.horizon_color), GR_COLOR_GREEN(Terrain_sky.horizon_color), |
| 433 | GR_COLOR_BLUE(Terrain_sky.horizon_color)); |
| 434 | DrawSwatch(IDC_FOG_SWATCH, GR_COLOR_RED(Terrain_sky.fog_color), GR_COLOR_GREEN(Terrain_sky.fog_color), |
| 435 | GR_COLOR_BLUE(Terrain_sky.fog_color)); |
| 436 | |
| 437 | // Draw satellite swatch |
| 438 | float maxc = std::max(Terrain_sky.satellite_r[Current_satellite], Terrain_sky.satellite_g[Current_satellite]); |
| 439 | maxc = std::max(Terrain_sky.satellite_b[Current_satellite], maxc); |
| 440 | |
| 441 | float r, g, b; |
| 442 | |
| 443 | if (maxc > 1.0) { |
| 444 | r = Terrain_sky.satellite_r[Current_satellite] / maxc; |
| 445 | g = Terrain_sky.satellite_g[Current_satellite] / maxc; |
| 446 | b = Terrain_sky.satellite_b[Current_satellite] / maxc; |
| 447 | } else { |
| 448 | r = Terrain_sky.satellite_r[Current_satellite]; |
| 449 | g = Terrain_sky.satellite_g[Current_satellite]; |
| 450 | b = Terrain_sky.satellite_b[Current_satellite]; |
| 451 | } |
| 452 | |
| 453 | r *= 255.0; |
| 454 | g *= 255.0; |
| 455 | b *= 255.0; |
| 456 | |
| 457 | DrawSwatch(IDC_SATELLITE_SWATCH, r, g, b); |
| 458 | |
| 459 | if (cc_mode != CC_MODE_SAT) { |
| 460 | int r, g, b; |
| 461 | |
| 462 | if (cc_mode == CC_MODE_SKY) { |
| 463 | r = GR_COLOR_RED(Terrain_sky.sky_color); |
| 464 | g = GR_COLOR_GREEN(Terrain_sky.sky_color); |
| 465 | b = GR_COLOR_BLUE(Terrain_sky.sky_color); |
| 466 | } else if (cc_mode == CC_MODE_HORIZON) { |
| 467 | r = GR_COLOR_RED(Terrain_sky.horizon_color); |
| 468 | g = GR_COLOR_GREEN(Terrain_sky.horizon_color); |
| 469 | b = GR_COLOR_BLUE(Terrain_sky.horizon_color); |
| 470 | } else { |
| 471 | r = GR_COLOR_RED(Terrain_sky.fog_color); |
| 472 | g = GR_COLOR_GREEN(Terrain_sky.fog_color); |
| 473 | b = GR_COLOR_BLUE(Terrain_sky.fog_color); |
| 474 | } |
| 475 | |
| 476 | ebox = (CEdit *)GetDlgItem(IDC_SKY_RED_EDIT); |
| 477 | sprintf(str, "%d", r); |
| 478 | ebox->SetWindowText(str); |
| 479 | |
| 480 | ebox = (CEdit *)GetDlgItem(IDC_SKY_GREEN_EDIT); |
| 481 | sprintf(str, "%d", g); |
| 482 | ebox->SetWindowText(str); |
| 483 | |
| 484 | ebox = (CEdit *)GetDlgItem(IDC_SKY_BLUE_EDIT); |
| 485 | sprintf(str, "%d", b); |
| 486 | ebox->SetWindowText(str); |
| 487 | } else { |
| 488 | |
| 489 | ebox = (CEdit *)GetDlgItem(IDC_SKY_RED_EDIT); |
| 490 | sprintf(str, "%f", Terrain_sky.satellite_r[Current_satellite]); |
| 491 | ebox->SetWindowText(str); |
| 492 | |
| 493 | ebox = (CEdit *)GetDlgItem(IDC_SKY_GREEN_EDIT); |
| 494 | sprintf(str, "%f", Terrain_sky.satellite_g[Current_satellite]); |
| 495 | ebox->SetWindowText(str); |
| 496 | |
| 497 | ebox = (CEdit *)GetDlgItem(IDC_SKY_BLUE_EDIT); |
| 498 | sprintf(str, "%f", Terrain_sky.satellite_b[Current_satellite]); |
| 499 | ebox->SetWindowText(str); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | void CTerrainDialog::OnTerrpadMoveUp() { |
| 504 | int i; |
| 505 | |
| 506 | for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) { |
| 507 | if (TerrainSelected[i]) { |
| 508 | int cury = Terrain_seg[i].ypos; |
| 509 | if (cury <= 254) { |
| 510 | Terrain_seg[i].ypos++; |
| 511 | Terrain_seg[i].y += (float)(TERRAIN_HEIGHT_INCREMENT); |
| 512 | TV_changed++; |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | void CTerrainDialog::OnTerrpadMoveDown() { |
| 519 | for (int i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) { |
| 520 | if (TerrainSelected[i]) { |
| 521 | int cury = Terrain_seg[i].ypos; |
| 522 | if (cury > 0) { |
| 523 | Terrain_seg[i].ypos--; |
| 524 | Terrain_seg[i].y -= (float)(TERRAIN_HEIGHT_INCREMENT); |
| 525 | TV_changed++; |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | void CTerrainDialog::RunKeypadFunction(int code) { |
| 532 | switch (code) { |
| 533 | case VK_ADD: |
| 534 | OnTerrpadMoveDown(); |
| 535 | break; |
| 536 | case VK_SUBTRACT: |
| 537 | OnTerrpadMoveUp(); |
| 538 | break; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | void CTerrainDialog::OnTerrpadImport() { |
| 543 | char filename[255]; |
| 544 | |
| 545 | CString filter = "PCX files (*.pcx)|*.pcx||"; |
| 546 | |
| 547 | if (!OpenFileDialog(this, (LPCSTR)filter, filename, Current_bitmap_dir, sizeof(Current_bitmap_dir))) |
| 548 | return; |
| 549 | |
| 550 | // Okay, we selected a file. Lets do what needs to be done here. |
| 551 | LoadPCXTerrain(filename); |
| 552 | } |
| 553 | |
| 554 | void CTerrainDialog::OnTerrpadRenormalize() { |
| 555 | mprintf(0, "Building terrain normals...this might take a couple of seconds.\n"); |
| 556 | |
| 557 | Terrain_checksum = -1; |
| 558 | BuildMinMaxTerrain(); |
| 559 | BuildTerrainNormals(); |
| 560 | State_changed = 1; |
| 561 | } |
| 562 | |
| 563 | void CTerrainDialog::OnTerrpadRaise10() { |
| 564 | for (int i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) { |
| 565 | if (TerrainSelected[i]) { |
| 566 | int cury = Terrain_seg[i].ypos; |
| 567 | if (cury < 255 - 10) { |
| 568 | Terrain_seg[i].ypos += 10; |
| 569 | Terrain_seg[i].y += (float)(10 * (TERRAIN_HEIGHT_INCREMENT)); |
| 570 | TV_changed++; |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | void CTerrainDialog::OnTerrpadLower10() { |
| 577 | |
| 578 | for (int i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) { |
| 579 | if (TerrainSelected[i]) { |
| 580 | int cury = Terrain_seg[i].ypos; |
| 581 | if (cury > 9) { |
| 582 | Terrain_seg[i].ypos -= 10; |
| 583 | Terrain_seg[i].y -= (float)(10 * (TERRAIN_HEIGHT_INCREMENT)); |
| 584 | TV_changed++; |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | void CTerrainDialog::OnSkyTexture() { TV_changed = 1; } |
| 591 | |
| 592 | void CTerrainDialog::OnTerrpadSelectNone() { |
| 593 | for (int i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) |
| 594 | TerrainSelected[i] = 0; |
| 595 | Num_terrain_selected = 0; |
| 596 | World_changed = 1; |
| 597 | } |
| 598 | |
| 599 | void CTerrainDialog::OnTerrpadRotTexture() { |
| 600 | int i; |
| 601 | uint8_t touched[TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH]; |
| 602 | memset(touched, 0, TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH); |
| 603 | |
| 604 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 605 | if (TerrainSelected[i]) { |
| 606 | if (!touched[Terrain_seg[i].texseg_index]) { |
| 607 | int val = Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation & 0x0F; |
| 608 | val++; |
| 609 | val %= 4; |
| 610 | Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation &= ~0x0F; |
| 611 | Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation |= val; |
| 612 | touched[Terrain_seg[i].texseg_index] = 1; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | World_changed = 1; |
| 618 | TV_changed = 1; |
| 619 | } |
| 620 | |
| 621 | void CTerrainDialog::OnSkyNearer() { |
| 622 | |
| 623 | if (Terrain_sky.radius > 500) { |
| 624 | |
| 625 | SetupSky(Terrain_sky.radius - 500, Terrain_sky.flags); |
| 626 | TV_changed = 1; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | void CTerrainDialog::OnSkyFarther() { |
| 631 | SetupSky(Terrain_sky.radius + 500, Terrain_sky.flags); |
| 632 | TV_changed = 1; |
| 633 | } |
| 634 | |
| 635 | void CTerrainDialog::OnStarsCheck() { |
| 636 | int c = IsDlgButtonChecked(IDC_STARS_CHECK); |
| 637 | |
| 638 | if (c) |
| 639 | Terrain_sky.flags |= TF_STARS; |
| 640 | else |
| 641 | Terrain_sky.flags &= ~TF_STARS; |
| 642 | |
| 643 | TV_changed = 1; |
| 644 | } |
| 645 | |
| 646 | void CTerrainDialog::OnFastTerrainCheck() { |
| 647 | int c = IsDlgButtonChecked(IDC_FAST_TERRAIN_CHECK); |
| 648 | |
| 649 | if (c) |
| 650 | Fast_terrain = 1; |
| 651 | else |
| 652 | Fast_terrain = 0; |
| 653 | |
| 654 | TV_changed = 1; |
| 655 | } |
| 656 | |
| 657 | void CTerrainDialog::OnTerrpadFillArea() { |
| 658 | int i; |
| 659 | |
| 660 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) |
| 661 | if (TerrainSelected[i]) |
| 662 | Terrain_tex_seg[Terrain_seg[i].texseg_index].tex_index = D3EditState.texdlg_texture; |
| 663 | |
| 664 | World_changed = 1; |
| 665 | } |
| 666 | |
| 667 | void CTerrainDialog::OnTerrpadRedoTopmap() { World_changed = 1; } |
| 668 | |
| 669 | void CTerrainDialog::OnTerrpadMakeMax() { |
| 670 | int max_so_far = 0, i; |
| 671 | |
| 672 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 673 | if (TerrainSelected[i]) { |
| 674 | if (Terrain_seg[i].ypos > max_so_far) |
| 675 | max_so_far = Terrain_seg[i].ypos; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 680 | if (TerrainSelected[i]) { |
| 681 | Terrain_seg[i].ypos = max_so_far; |
| 682 | Terrain_seg[i].y = max_so_far * (TERRAIN_HEIGHT_INCREMENT); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | World_changed = 1; |
| 687 | } |
| 688 | |
| 689 | void CTerrainDialog::OnTerrpadMakeMin() { |
| 690 | int min_so_far = 9999, i; |
| 691 | |
| 692 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 693 | if (TerrainSelected[i]) { |
| 694 | if (Terrain_seg[i].ypos < min_so_far) |
| 695 | min_so_far = Terrain_seg[i].ypos; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 700 | if (TerrainSelected[i]) { |
| 701 | Terrain_seg[i].ypos = min_so_far; |
| 702 | Terrain_seg[i].y = min_so_far * (TERRAIN_HEIGHT_INCREMENT); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | World_changed = 1; |
| 707 | } |
| 708 | |
| 709 | void CTerrainDialog::OnTerrpadMakeZero() { |
| 710 | int i; |
| 711 | |
| 712 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 713 | if (TerrainSelected[i]) { |
| 714 | Terrain_seg[i].ypos = 0; |
| 715 | Terrain_seg[i].y = 0; |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | World_changed = 1; |
| 720 | } |
| 721 | |
| 722 | // Makes a pyramid out of the selected region |
| 723 | void CTerrainDialog::OnTerrpadPyramid() { |
| 724 | int left = TERRAIN_WIDTH, right = 0; |
| 725 | int top = TERRAIN_DEPTH, bottom = 0; |
| 726 | |
| 727 | int i, t, x, y; |
| 728 | int max_so_far = 0; |
| 729 | int min_so_far = 999; |
| 730 | |
| 731 | // First find highest/lowest point |
| 732 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 733 | if (TerrainSelected[i]) { |
| 734 | if (Terrain_seg[i].ypos > max_so_far) |
| 735 | max_so_far = Terrain_seg[i].ypos; |
| 736 | if (Terrain_seg[i].ypos < min_so_far) |
| 737 | min_so_far = Terrain_seg[i].ypos; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | // Now get dimensions of selection |
| 742 | for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) { |
| 743 | if (TerrainSelected[i]) { |
| 744 | x = i % TERRAIN_WIDTH; |
| 745 | y = i / TERRAIN_WIDTH; |
| 746 | |
| 747 | if (x > right) |
| 748 | right = x; |
| 749 | if (x < left) |
| 750 | left = x; |
| 751 | |
| 752 | if (y > bottom) |
| 753 | bottom = y; |
| 754 | |
| 755 | if (y < top) |
| 756 | top = y; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | int width = (right - left); |
| 761 | int height = (bottom - top); |
| 762 | |
| 763 | int hdiff = max_so_far - min_so_far; |
| 764 | |
| 765 | if (hdiff == 0) { |
| 766 | MessageBox("The area you selected is flat. Pull a point up to the desired height and then retry this operation."); |
| 767 | return; |
| 768 | } |
| 769 | |
| 770 | fix xstep = IntToFix(hdiff) / (width / 2); |
| 771 | fix ystep = IntToFix(hdiff) / (height / 2); |
| 772 | |
| 773 | // upper left |
| 774 | for (i = 0; i <= (height / 2); i++) { |
| 775 | for (t = 0; t <= (width / 2); t++) { |
| 776 | |
| 777 | int xa, ya, a; |
| 778 | |
| 779 | xa = FixToInt(xstep * t); |
| 780 | ya = FixToInt(ystep * i); |
| 781 | |
| 782 | a = std::max(xa, ya); |
| 783 | |
| 784 | int seg = ((top + i) * TERRAIN_WIDTH) + (t + left); |
| 785 | |
| 786 | Terrain_seg[seg].ypos = min_so_far + a; |
| 787 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | // upper right |
| 792 | for (i = 0; i <= (height / 2); i++) { |
| 793 | for (t = 0; t <= (width / 2); t++) { |
| 794 | |
| 795 | int xa, ya, a; |
| 796 | |
| 797 | xa = FixToInt(xstep * t); |
| 798 | ya = FixToInt(ystep * i); |
| 799 | |
| 800 | a = std::max(xa, ya); |
| 801 | |
| 802 | int seg = ((top + i) * TERRAIN_WIDTH) + (right - t); |
| 803 | |
| 804 | Terrain_seg[seg].ypos = min_so_far + a; |
| 805 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | // lower left |
| 810 | for (i = 0; i <= (height / 2); i++) { |
| 811 | for (t = 0; t <= (width / 2); t++) { |
| 812 | |
| 813 | int xa, ya, a; |
| 814 | |
| 815 | xa = FixToInt(xstep * t); |
| 816 | ya = FixToInt(ystep * i); |
| 817 | |
| 818 | a = std::max(xa, ya); |
| 819 | |
| 820 | int seg = ((bottom - i) * TERRAIN_WIDTH) + (left + t); |
| 821 | |
| 822 | Terrain_seg[seg].ypos = min_so_far + a; |
| 823 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | // lower right |
| 828 | for (i = 0; i <= (height / 2); i++) { |
| 829 | for (t = 0; t <= (width / 2); t++) { |
| 830 | |
| 831 | int xa, ya, a; |
| 832 | |
| 833 | xa = FixToInt(xstep * t); |
| 834 | ya = FixToInt(ystep * i); |
| 835 | |
| 836 | a = std::max(xa, ya); |
| 837 | |
| 838 | int seg = ((bottom - i) * TERRAIN_WIDTH) + (right - t); |
| 839 | |
| 840 | Terrain_seg[seg].ypos = min_so_far + a; |
| 841 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | World_changed = 1; |
| 846 | } |
| 847 | |
| 848 | void CTerrainDialog::OnTerrpadHill() {} |
| 849 | |
| 850 | void CTerrainDialog::OnTerrpadPancakes() { |
| 851 | int left = TERRAIN_WIDTH, right = 0; |
| 852 | int top = TERRAIN_DEPTH, bottom = 0; |
| 853 | |
| 854 | int i, t, x, y; |
| 855 | int max_so_far = 0; |
| 856 | int min_so_far = 999; |
| 857 | |
| 858 | // First find highest/lowest point |
| 859 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 860 | if (TerrainSelected[i]) { |
| 861 | if (Terrain_seg[i].ypos > max_so_far) |
| 862 | max_so_far = Terrain_seg[i].ypos; |
| 863 | if (Terrain_seg[i].ypos < min_so_far) |
| 864 | min_so_far = Terrain_seg[i].ypos; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | // Now get dimensions of selection |
| 869 | for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++) { |
| 870 | if (TerrainSelected[i]) { |
| 871 | x = i % TERRAIN_WIDTH; |
| 872 | y = i / TERRAIN_WIDTH; |
| 873 | |
| 874 | if (x > right) |
| 875 | right = x; |
| 876 | if (x < left) |
| 877 | left = x; |
| 878 | |
| 879 | if (y > bottom) |
| 880 | bottom = y; |
| 881 | |
| 882 | if (y < top) |
| 883 | top = y; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | int width = (right - left); |
| 888 | int height = (bottom - top); |
| 889 | |
| 890 | int hdiff = max_so_far - min_so_far; |
| 891 | |
| 892 | if (hdiff == 0) { |
| 893 | MessageBox("The area you selected is flat. Pull a point up to the desired height and then retry this operation."); |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | fix xstep = IntToFix(hdiff) / (width / 2); |
| 898 | fix ystep = IntToFix(hdiff) / (height / 2); |
| 899 | |
| 900 | // upper left |
| 901 | for (i = 0; i <= (height / 2); i++) { |
| 902 | for (t = 0; t <= (width / 2); t++) { |
| 903 | |
| 904 | int xa, ya, a; |
| 905 | |
| 906 | xa = FixToInt(xstep * t); |
| 907 | ya = FixToInt(ystep * i); |
| 908 | |
| 909 | a = std::max(xa, ya); |
| 910 | |
| 911 | int seg = ((top + i) * TERRAIN_WIDTH) + (t + left); |
| 912 | |
| 913 | Terrain_seg[seg].ypos = min_so_far + a; |
| 914 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | // upper right |
| 919 | for (i = 0; i <= (height / 2); i++) { |
| 920 | for (t = 0; t <= (width / 2); t++) { |
| 921 | |
| 922 | int xa, ya, a; |
| 923 | |
| 924 | xa = FixToInt(xstep * t); |
| 925 | ya = FixToInt(ystep * i); |
| 926 | |
| 927 | a = std::max(xa, ya); |
| 928 | |
| 929 | int seg = ((top + i) * TERRAIN_WIDTH) + (right - t); |
| 930 | |
| 931 | Terrain_seg[seg].ypos = min_so_far + a; |
| 932 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | // lower left |
| 937 | for (i = 0; i <= (height / 2); i++) { |
| 938 | for (t = 0; t <= (width / 2); t++) { |
| 939 | |
| 940 | int xa, ya, a; |
| 941 | |
| 942 | xa = FixToInt(xstep * t); |
| 943 | ya = FixToInt(ystep * i); |
| 944 | |
| 945 | a = std::max(xa, ya); |
| 946 | |
| 947 | int seg = ((bottom - i) * TERRAIN_WIDTH) + (left + t); |
| 948 | |
| 949 | Terrain_seg[seg].ypos = min_so_far + a; |
| 950 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | // lower right |
| 955 | for (i = 0; i <= (height / 2); i++) { |
| 956 | for (t = 0; t <= (width / 2); t++) { |
| 957 | |
| 958 | int xa, ya, a; |
| 959 | |
| 960 | xa = FixToInt(xstep * t); |
| 961 | ya = FixToInt(ystep * i); |
| 962 | |
| 963 | a = std::max(xa, ya); |
| 964 | |
| 965 | int seg = ((bottom - i) * TERRAIN_WIDTH) + (right - t); |
| 966 | |
| 967 | Terrain_seg[seg].ypos = min_so_far + a; |
| 968 | Terrain_seg[seg].y = (min_so_far + a) * (TERRAIN_HEIGHT_INCREMENT); |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | World_changed = 1; |
| 973 | } |
| 974 | |
| 975 | void CTerrainDialog::OnTerrMoveMoon() { |
| 976 | int n = Current_satellite; |
| 977 | |
| 978 | Terrain_sky.satellite_size[n] *= 1.1f; |
| 979 | |
| 980 | TV_changed = 1; |
| 981 | } |
| 982 | |
| 983 | void CTerrainDialog::OnTerrRandomizeSky() { |
| 984 | SetupSky(Terrain_sky.radius, Terrain_sky.flags, 1); |
| 985 | TV_changed = 1; |
| 986 | } |
| 987 | |
| 988 | void CTerrainDialog::OnPaint() { |
| 989 | CPaintDC dc(this); // device context for painting |
| 990 | |
| 991 | UpdateDialog(); |
| 992 | |
| 993 | // Do not call CDialog::OnPaint() for painting messages |
| 994 | } |
| 995 | |
| 996 | void CTerrainDialog::OnTerrMoreMoons() { |
| 997 | if (Terrain_sky.num_satellites < 5) |
| 998 | Terrain_sky.num_satellites++; |
| 999 | |
| 1000 | TV_changed = 1; |
| 1001 | |
| 1002 | UpdateDialog(); |
| 1003 | } |
| 1004 | |
| 1005 | void CTerrainDialog::OnTerrLessMoons() { |
| 1006 | if (Terrain_sky.num_satellites > 0) |
| 1007 | Terrain_sky.num_satellites--; |
| 1008 | |
| 1009 | TV_changed = 1; |
| 1010 | |
| 1011 | UpdateDialog(); |
| 1012 | } |
| 1013 | |
| 1014 | void CTerrainDialog::OnTerrNextMoon() { |
| 1015 | Current_satellite++; |
| 1016 | |
| 1017 | Current_satellite %= 5; |
| 1018 | |
| 1019 | UpdateDialog(); |
| 1020 | } |
| 1021 | |
| 1022 | void CTerrainDialog::OnTerrPrevMoon() { |
| 1023 | Current_satellite--; |
| 1024 | if (Current_satellite < 0) |
| 1025 | Current_satellite = 4; |
| 1026 | |
| 1027 | UpdateDialog(); |
| 1028 | } |
| 1029 | |
| 1030 | void CTerrainDialog::OnShowTerrain() { |
| 1031 | int c = IsDlgButtonChecked(IDC_SHOW_TERRAIN); |
| 1032 | |
| 1033 | D3EditState.terrain_dots = (c != 0); |
| 1034 | |
| 1035 | State_changed = 1; |
| 1036 | } |
| 1037 | |
| 1038 | void CTerrainDialog::OnFlatShadeTerrainCheck() { |
| 1039 | int c = IsDlgButtonChecked(IDC_FLAT_SHADE_TERRAIN_CHECK); |
| 1040 | |
| 1041 | D3EditState.terrain_flat_shade = (c != 0); |
| 1042 | |
| 1043 | if (c) { |
| 1044 | Terrain_texture_distance = 0; |
| 1045 | Detail_settings.Terrain_render_distance = DEFAULT_VISIBLE_TERRAIN_DISTANCE * 2; |
| 1046 | } else { |
| 1047 | Terrain_texture_distance = 9999999; |
| 1048 | Detail_settings.Terrain_render_distance = DEFAULT_VISIBLE_TERRAIN_DISTANCE; |
| 1049 | } |
| 1050 | |
| 1051 | State_changed = 1; |
| 1052 | } |
| 1053 | |
| 1054 | BOOL CTerrainDialog::OnHelpInfo(HELPINFO *pHelpInfo) { |
| 1055 | |
| 1056 | WinHelp(HID_TERRAINTAB, HELP_CONTEXT); |
| 1057 | return TRUE; |
| 1058 | // return CDialog::OnHelpInfo(pHelpInfo); |
| 1059 | } |
| 1060 | |
| 1061 | void CTerrainDialog::OnTerrSelectAll() { |
| 1062 | |
| 1063 | int i; |
| 1064 | |
| 1065 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) |
| 1066 | TerrainSelected[i] = 1; |
| 1067 | |
| 1068 | Num_terrain_selected = TERRAIN_WIDTH * TERRAIN_DEPTH; |
| 1069 | World_changed = 1; |
| 1070 | } |
| 1071 | |
| 1072 | void CTerrainDialog::OnTerrain2d() { |
| 1073 | int c = IsDlgButtonChecked(IDC_TERRAIN_2D); |
| 1074 | |
| 1075 | if (c) { |
| 1076 | Flat_terrain = 1; |
| 1077 | } else { |
| 1078 | Flat_terrain = 0; |
| 1079 | } |
| 1080 | |
| 1081 | State_changed = 1; |
| 1082 | } |
| 1083 | |
| 1084 | void CTerrainDialog::SetCurrentMoon(int n) { |
| 1085 | Current_satellite = n; |
| 1086 | UpdateDialog(); |
| 1087 | } |
| 1088 | |
| 1089 | void CTerrainDialog::OnTextureSky() { |
| 1090 | int c = IsDlgButtonChecked(IDC_TEXTURE_SKY); |
| 1091 | Terrain_sky.textured = c; |
| 1092 | |
| 1093 | World_changed = 1; |
| 1094 | } |
| 1095 | |
| 1096 | void CTerrainDialog::OnKillfocusSkyRedEdit() { |
| 1097 | CEdit *ebox; |
| 1098 | char str[20]; |
| 1099 | int r, g, b, nr; |
| 1100 | float fv; |
| 1101 | |
| 1102 | if (cc_mode == CC_MODE_SKY) { |
| 1103 | r = GR_COLOR_RED(Terrain_sky.sky_color); |
| 1104 | g = GR_COLOR_GREEN(Terrain_sky.sky_color); |
| 1105 | b = GR_COLOR_BLUE(Terrain_sky.sky_color); |
| 1106 | } else if (cc_mode == CC_MODE_HORIZON) { |
| 1107 | r = GR_COLOR_RED(Terrain_sky.horizon_color); |
| 1108 | g = GR_COLOR_GREEN(Terrain_sky.horizon_color); |
| 1109 | b = GR_COLOR_BLUE(Terrain_sky.horizon_color); |
| 1110 | } else { |
| 1111 | r = GR_COLOR_RED(Terrain_sky.fog_color); |
| 1112 | g = GR_COLOR_GREEN(Terrain_sky.fog_color); |
| 1113 | b = GR_COLOR_BLUE(Terrain_sky.fog_color); |
| 1114 | } |
| 1115 | |
| 1116 | ebox = (CEdit *)GetDlgItem(IDC_SKY_RED_EDIT); |
| 1117 | ebox->GetWindowText(str, 20); |
| 1118 | |
| 1119 | if (cc_mode != CC_MODE_SAT) { |
| 1120 | nr = atoi(str); |
| 1121 | if (nr < 0) |
| 1122 | nr = 0; |
| 1123 | if (nr > 255) |
| 1124 | nr = 255; |
| 1125 | |
| 1126 | if (cc_mode == CC_MODE_SKY) |
| 1127 | Terrain_sky.sky_color = GR_RGB(nr, g, b); |
| 1128 | else if (cc_mode == CC_MODE_HORIZON) |
| 1129 | Terrain_sky.horizon_color = GR_RGB(nr, g, b); |
| 1130 | else |
| 1131 | Terrain_sky.fog_color = GR_RGB(nr, g, b); |
| 1132 | } else { |
| 1133 | fv = atof(str); |
| 1134 | if (fv < 0) |
| 1135 | fv = 0; |
| 1136 | |
| 1137 | Terrain_sky.satellite_r[Current_satellite] = fv; |
| 1138 | } |
| 1139 | |
| 1140 | World_changed = 1; |
| 1141 | UpdateDialog(); |
| 1142 | } |
| 1143 | |
| 1144 | void CTerrainDialog::OnKillfocusSkyGreenEdit() { |
| 1145 | CEdit *ebox; |
| 1146 | char str[20]; |
| 1147 | int r, g, b, nr; |
| 1148 | float fv; |
| 1149 | |
| 1150 | if (cc_mode == CC_MODE_SKY) { |
| 1151 | r = GR_COLOR_RED(Terrain_sky.sky_color); |
| 1152 | g = GR_COLOR_GREEN(Terrain_sky.sky_color); |
| 1153 | b = GR_COLOR_BLUE(Terrain_sky.sky_color); |
| 1154 | } else if (cc_mode == CC_MODE_HORIZON) { |
| 1155 | r = GR_COLOR_RED(Terrain_sky.horizon_color); |
| 1156 | g = GR_COLOR_GREEN(Terrain_sky.horizon_color); |
| 1157 | b = GR_COLOR_BLUE(Terrain_sky.horizon_color); |
| 1158 | } else { |
| 1159 | r = GR_COLOR_RED(Terrain_sky.fog_color); |
| 1160 | g = GR_COLOR_GREEN(Terrain_sky.fog_color); |
| 1161 | b = GR_COLOR_BLUE(Terrain_sky.fog_color); |
| 1162 | } |
| 1163 | |
| 1164 | ebox = (CEdit *)GetDlgItem(IDC_SKY_GREEN_EDIT); |
| 1165 | ebox->GetWindowText(str, 20); |
| 1166 | |
| 1167 | if (cc_mode != CC_MODE_SAT) { |
| 1168 | nr = atoi(str); |
| 1169 | if (nr < 0) |
| 1170 | nr = 0; |
| 1171 | if (nr > 255) |
| 1172 | nr = 255; |
| 1173 | |
| 1174 | if (cc_mode == CC_MODE_SKY) |
| 1175 | Terrain_sky.sky_color = GR_RGB(r, nr, b); |
| 1176 | else if (cc_mode == CC_MODE_HORIZON) |
| 1177 | Terrain_sky.horizon_color = GR_RGB(r, nr, b); |
| 1178 | else |
| 1179 | Terrain_sky.fog_color = GR_RGB(r, nr, b); |
| 1180 | } else { |
| 1181 | fv = atof(str); |
| 1182 | if (fv < 0) |
| 1183 | fv = 0; |
| 1184 | |
| 1185 | Terrain_sky.satellite_g[Current_satellite] = fv; |
| 1186 | } |
| 1187 | |
| 1188 | World_changed = 1; |
| 1189 | UpdateDialog(); |
| 1190 | } |
| 1191 | |
| 1192 | void CTerrainDialog::OnKillfocusSkyBlueEdit() { |
| 1193 | CEdit *ebox; |
| 1194 | char str[20]; |
| 1195 | int r, g, b, nr; |
| 1196 | float fv; |
| 1197 | |
| 1198 | if (cc_mode == CC_MODE_SKY) { |
| 1199 | r = GR_COLOR_RED(Terrain_sky.sky_color); |
| 1200 | g = GR_COLOR_GREEN(Terrain_sky.sky_color); |
| 1201 | b = GR_COLOR_BLUE(Terrain_sky.sky_color); |
| 1202 | } else if (cc_mode == CC_MODE_HORIZON) { |
| 1203 | r = GR_COLOR_RED(Terrain_sky.horizon_color); |
| 1204 | g = GR_COLOR_GREEN(Terrain_sky.horizon_color); |
| 1205 | b = GR_COLOR_BLUE(Terrain_sky.horizon_color); |
| 1206 | } else { |
| 1207 | r = GR_COLOR_RED(Terrain_sky.fog_color); |
| 1208 | g = GR_COLOR_GREEN(Terrain_sky.fog_color); |
| 1209 | b = GR_COLOR_BLUE(Terrain_sky.fog_color); |
| 1210 | } |
| 1211 | |
| 1212 | ebox = (CEdit *)GetDlgItem(IDC_SKY_BLUE_EDIT); |
| 1213 | ebox->GetWindowText(str, 20); |
| 1214 | |
| 1215 | if (cc_mode != CC_MODE_SAT) { |
| 1216 | nr = atoi(str); |
| 1217 | if (nr < 0) |
| 1218 | nr = 0; |
| 1219 | if (nr > 255) |
| 1220 | nr = 255; |
| 1221 | |
| 1222 | if (cc_mode == CC_MODE_SKY) |
| 1223 | Terrain_sky.sky_color = GR_RGB(r, g, nr); |
| 1224 | else if (cc_mode == CC_MODE_HORIZON) |
| 1225 | Terrain_sky.horizon_color = GR_RGB(r, g, nr); |
| 1226 | else |
| 1227 | Terrain_sky.fog_color = GR_RGB(r, g, nr); |
| 1228 | } else { |
| 1229 | fv = atof(str); |
| 1230 | if (fv < 0) |
| 1231 | fv = 0; |
| 1232 | |
| 1233 | Terrain_sky.satellite_b[Current_satellite] = fv; |
| 1234 | } |
| 1235 | |
| 1236 | World_changed = 1; |
| 1237 | UpdateDialog(); |
| 1238 | } |
| 1239 | |
| 1240 | void CTerrainDialog::OnNoLodEngine() { |
| 1241 | |
| 1242 | int c = IsDlgButtonChecked(IDC_NO_LOD_ENGINE); |
| 1243 | |
| 1244 | Editor_LOD_engine_off = c; |
| 1245 | |
| 1246 | State_changed = 1; |
| 1247 | } |
| 1248 | |
| 1249 | void CTerrainDialog::OnKillfocusFogDistanceEdit() { |
| 1250 | CEdit *ebox; |
| 1251 | char str[20]; |
| 1252 | float predist; |
| 1253 | float dist; |
| 1254 | |
| 1255 | ebox = (CEdit *)GetDlgItem(IDC_FOG_DISTANCE_EDIT); |
| 1256 | ebox->GetWindowText(str, 20); |
| 1257 | |
| 1258 | predist = atof(str); |
| 1259 | |
| 1260 | if (predist < 20) |
| 1261 | predist = 20; |
| 1262 | if (predist > 200) |
| 1263 | predist = 200; |
| 1264 | |
| 1265 | dist = predist * TERRAIN_SIZE; |
| 1266 | |
| 1267 | Detail_settings.Terrain_render_distance = dist; |
| 1268 | |
| 1269 | World_changed = 1; |
| 1270 | UpdateDialog(); |
| 1271 | } |
| 1272 | |
| 1273 | void CTerrainDialog::OnKillfocusPixelErrorEdit() { |
| 1274 | CEdit *ebox; |
| 1275 | char str[20]; |
| 1276 | float err; |
| 1277 | |
| 1278 | ebox = (CEdit *)GetDlgItem(IDC_PIXEL_ERROR_EDIT); |
| 1279 | ebox->GetWindowText(str, 20); |
| 1280 | |
| 1281 | err = atof(str); |
| 1282 | if (err < 0) |
| 1283 | err = 0; |
| 1284 | if (err > 64) |
| 1285 | err = 64; |
| 1286 | |
| 1287 | Detail_settings.Pixel_error = err; |
| 1288 | |
| 1289 | World_changed = 1; |
| 1290 | UpdateDialog(); |
| 1291 | } |
| 1292 | |
| 1293 | void CTerrainDialog::OnTerrpadSelectrange() { |
| 1294 | SelectRangeDialog dlg; |
| 1295 | |
| 1296 | theApp.pause(); |
| 1297 | dlg.DoModal(); |
| 1298 | World_changed = 1; |
| 1299 | theApp.resume(); |
| 1300 | } |
| 1301 | |
| 1302 | // These functions allow the terrain keypad to scroll!! |
| 1303 | |
| 1304 | void CTerrainDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 1305 | // TODO: Add your message handler code here and/or call default |
| 1306 | |
| 1307 | CKeypadDialog::OnVScroll(nSBCode, nPos, pScrollBar); |
| 1308 | } |
| 1309 | |
| 1310 | void CTerrainDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 1311 | // TODO: Add your message handler code here and/or call default |
| 1312 | |
| 1313 | CKeypadDialog::OnHScroll(nSBCode, nPos, pScrollBar); |
| 1314 | } |
| 1315 | |
| 1316 | void CTerrainDialog::OnSkyRadio() { |
| 1317 | |
| 1318 | cc_mode = CC_MODE_SKY; |
| 1319 | UpdateDialog(); |
| 1320 | } |
| 1321 | |
| 1322 | void CTerrainDialog::OnHorizonRadio() { |
| 1323 | |
| 1324 | cc_mode = CC_MODE_HORIZON; |
| 1325 | UpdateDialog(); |
| 1326 | } |
| 1327 | |
| 1328 | void CTerrainDialog::OnFogRadio() { |
| 1329 | cc_mode = CC_MODE_FOG; |
| 1330 | UpdateDialog(); |
| 1331 | } |
| 1332 | |
| 1333 | void CTerrainDialog::OnToggleVisibility() { |
| 1334 | |
| 1335 | for (int i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 1336 | if (TerrainSelected[i]) { |
| 1337 | int c = Terrain_seg[i].flags & TF_INVISIBLE; |
| 1338 | |
| 1339 | if (c) |
| 1340 | Terrain_seg[i].flags &= ~TF_INVISIBLE; |
| 1341 | else |
| 1342 | Terrain_seg[i].flags |= TF_INVISIBLE; |
| 1343 | |
| 1344 | World_changed = 1; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (World_changed) |
| 1349 | GenerateLODDeltas(); |
| 1350 | } |
| 1351 | |
| 1352 | void CTerrainDialog::OnShowInvisible() { |
| 1353 | int c = IsDlgButtonChecked(IDC_SHOW_INVISIBLE); |
| 1354 | |
| 1355 | Show_invisible_terrain = c; |
| 1356 | |
| 1357 | State_changed = 1; |
| 1358 | } |
| 1359 | |
| 1360 | void CTerrainDialog::OnTerrMoveMoonAway() { |
| 1361 | int n = Current_satellite; |
| 1362 | |
| 1363 | Terrain_sky.satellite_size[n] *= .9f; |
| 1364 | |
| 1365 | TV_changed = 1; |
| 1366 | } |
| 1367 | |
| 1368 | void CTerrainDialog::MoveSat(int pitch, int heading) { |
| 1369 | int n = Current_satellite; |
| 1370 | matrix rot_matrix, orient; |
| 1371 | vm_AnglesToMatrix(&rot_matrix, pitch, heading, 0); // move up a little |
| 1372 | |
| 1373 | orient = rot_matrix; |
| 1374 | |
| 1375 | vector sat_vec = Terrain_sky.satellite_vectors[n] - Viewer_object->pos; |
| 1376 | float mag = vm_GetMagnitude(&sat_vec); |
| 1377 | vector rot_vec; |
| 1378 | |
| 1379 | vm_NormalizeVector(&sat_vec); |
| 1380 | vm_MatrixMulVector(&rot_vec, &sat_vec, &orient); |
| 1381 | |
| 1382 | Terrain_sky.satellite_vectors[n] = Viewer_object->pos + (rot_vec * mag); |
| 1383 | } |
| 1384 | |
| 1385 | void CTerrainDialog::OnMoveSatUp() { |
| 1386 | MoveSat(1500, 0); |
| 1387 | TV_changed = 1; |
| 1388 | } |
| 1389 | |
| 1390 | void CTerrainDialog::OnMoveSatDown() { |
| 1391 | MoveSat(64000, 0); |
| 1392 | TV_changed = 1; |
| 1393 | } |
| 1394 | |
| 1395 | void CTerrainDialog::OnMoveSatLeft() { |
| 1396 | MoveSat(0, 64000); |
| 1397 | TV_changed = 1; |
| 1398 | } |
| 1399 | |
| 1400 | void CTerrainDialog::OnMoveSatRight() { |
| 1401 | MoveSat(0, 1500); |
| 1402 | TV_changed = 1; |
| 1403 | } |
| 1404 | |
| 1405 | void CTerrainDialog::OnSatelliteCheck() { |
| 1406 | int c = IsDlgButtonChecked(IDC_SATELLITE_CHECK); |
| 1407 | |
| 1408 | if (c) |
| 1409 | Terrain_sky.flags |= TF_SATELLITES; |
| 1410 | else |
| 1411 | Terrain_sky.flags &= ~TF_SATELLITES; |
| 1412 | |
| 1413 | TV_changed = 1; |
| 1414 | } |
| 1415 | |
| 1416 | void CTerrainDialog::OnSmoothTerrain() { |
| 1417 | uint8_t *src_data; |
| 1418 | int y, x; |
| 1419 | |
| 1420 | if (Num_terrain_selected == 0) { |
| 1421 | OutrageMessageBox("This operation works on selected cells. You have no cells selected!"); |
| 1422 | return; |
| 1423 | } |
| 1424 | |
| 1425 | if ((MessageBox("Are you sure you wish to smooth the terrain? This operation cannot be undone.", "Question", |
| 1426 | MB_YESNO)) == IDNO) |
| 1427 | return; |
| 1428 | |
| 1429 | src_data = (uint8_t *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1430 | ASSERT(src_data); // Ran out of memory! |
| 1431 | |
| 1432 | for (int i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) |
| 1433 | src_data[i] = Terrain_seg[i].ypos; |
| 1434 | |
| 1435 | int w = TERRAIN_WIDTH; |
| 1436 | int h = TERRAIN_DEPTH; |
| 1437 | |
| 1438 | for (y = 0; y < h; y++) { |
| 1439 | for (x = 0; x < w; x++) { |
| 1440 | if (!TerrainSelected[y * w + x]) |
| 1441 | continue; |
| 1442 | |
| 1443 | int total = 0; |
| 1444 | int num = 0; |
| 1445 | |
| 1446 | total += src_data[y * w + x]; |
| 1447 | num++; |
| 1448 | |
| 1449 | // Left edge |
| 1450 | if (x != 0) { |
| 1451 | |
| 1452 | total += src_data[y * w + (x - 1)]; |
| 1453 | num++; |
| 1454 | |
| 1455 | if (y != 0) { |
| 1456 | total += src_data[(y - 1) * w + (x - 1)]; |
| 1457 | num++; |
| 1458 | } |
| 1459 | |
| 1460 | if (y != h - 1) { |
| 1461 | total += src_data[(y + 1) * w + (x - 1)]; |
| 1462 | num++; |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | // Right edge |
| 1467 | if (x != (w - 1)) { |
| 1468 | total += src_data[(y)*w + (x + 1)]; |
| 1469 | num++; |
| 1470 | |
| 1471 | if (y != 0) { |
| 1472 | total += src_data[(y - 1) * w + (x + 1)]; |
| 1473 | num++; |
| 1474 | } |
| 1475 | |
| 1476 | if (y != h - 1) { |
| 1477 | total += src_data[(y + 1) * w + (x + 1)]; |
| 1478 | num++; |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | // Center |
| 1483 | if (y != 0) { |
| 1484 | total += src_data[(y - 1) * w + (x)]; |
| 1485 | num++; |
| 1486 | } |
| 1487 | |
| 1488 | if (y != h - 1) { |
| 1489 | total += src_data[(y + 1) * w + (x)]; |
| 1490 | num++; |
| 1491 | } |
| 1492 | |
| 1493 | if (num > 0) { |
| 1494 | total /= num; |
| 1495 | Terrain_seg[y * w + x].ypos = total; |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | mem_free(src_data); |
| 1501 | BuildMinMaxTerrain(); |
| 1502 | OutrageMessageBox("Terrain smoothed!"); |
| 1503 | World_changed = 1; |
| 1504 | } |
| 1505 | |
| 1506 | void CTerrainDialog::OnUseFog() { |
| 1507 | int c = IsDlgButtonChecked(IDC_USE_FOG); |
| 1508 | |
| 1509 | if (c) |
| 1510 | Terrain_sky.flags |= TF_FOG; |
| 1511 | else |
| 1512 | Terrain_sky.flags &= ~TF_FOG; |
| 1513 | |
| 1514 | World_changed = 1; |
| 1515 | } |
| 1516 | |
| 1517 | void CTerrainDialog::OnUseHalo() { |
| 1518 | int n = Current_satellite; |
| 1519 | int c = IsDlgButtonChecked(IDC_USE_HALO); |
| 1520 | |
| 1521 | if (c) |
| 1522 | Terrain_sky.satellite_flags[n] |= TSF_HALO; |
| 1523 | else |
| 1524 | Terrain_sky.satellite_flags[n] &= ~TSF_HALO; |
| 1525 | |
| 1526 | World_changed = 1; |
| 1527 | } |
| 1528 | |
| 1529 | void CTerrainDialog::OnUseAtmosphere() { |
| 1530 | int n = Current_satellite; |
| 1531 | int c = IsDlgButtonChecked(IDC_USE_ATMOSPHERE); |
| 1532 | |
| 1533 | if (c) |
| 1534 | Terrain_sky.satellite_flags[n] |= TSF_ATMOSPHERE; |
| 1535 | else |
| 1536 | Terrain_sky.satellite_flags[n] &= ~TSF_ATMOSPHERE; |
| 1537 | |
| 1538 | World_changed = 1; |
| 1539 | } |
| 1540 | |
| 1541 | #include "gamepath.h" |
| 1542 | #include "EditLineDialog.h" |
| 1543 | |
| 1544 | void CTerrainDialog::OnDropTerrain() { |
| 1545 | int desired_height, lowest_height, highest_height, delta_height; |
| 1546 | int x, y; |
| 1547 | |
| 1548 | // Find lowest & highest terrain values |
| 1549 | for (x = 0, lowest_height = INT_MAX, highest_height = 0; x < TERRAIN_WIDTH; x++) |
| 1550 | for (y = 0; y < TERRAIN_DEPTH; y++) { |
| 1551 | if (Terrain_seg[x * TERRAIN_WIDTH + y].ypos < lowest_height) |
| 1552 | lowest_height = Terrain_seg[x * TERRAIN_WIDTH + y].ypos; |
| 1553 | if (Terrain_seg[x * TERRAIN_WIDTH + y].ypos > highest_height) |
| 1554 | highest_height = Terrain_seg[x * TERRAIN_WIDTH + y].ypos; |
| 1555 | } |
| 1556 | |
| 1557 | // Get desired terrain level |
| 1558 | get_height:; |
| 1559 | if (!InputNumber(&desired_height, "Raise/Lower Terrain", "Enter the desired height for the lowest terrain point:")) |
| 1560 | return; |
| 1561 | |
| 1562 | // Check valid values |
| 1563 | if ((desired_height < 0) || (desired_height > 255)) { |
| 1564 | OutrageMessageBox("Invalid value: the height must be between 0 and 255, inclusive."); |
| 1565 | goto get_height; |
| 1566 | } |
| 1567 | if (((highest_height - lowest_height) + desired_height) > 255) { |
| 1568 | OutrageMessageBox("The delta height of the terrain is %d, so you cannot set the lowest point above %d.", |
| 1569 | highest_height - lowest_height, 255 - (highest_height - lowest_height)); |
| 1570 | goto get_height; |
| 1571 | } |
| 1572 | |
| 1573 | // Compute delta |
| 1574 | delta_height = desired_height - lowest_height; |
| 1575 | |
| 1576 | // Now lower the terrain |
| 1577 | for (x = 0; x < TERRAIN_WIDTH; x++) |
| 1578 | for (y = 0; y < TERRAIN_DEPTH; y++) |
| 1579 | Terrain_seg[x * TERRAIN_WIDTH + y].ypos += delta_height; |
| 1580 | |
| 1581 | // Update stuff |
| 1582 | BuildMinMaxTerrain(); |
| 1583 | |
| 1584 | // How much we move by |
| 1585 | float delta_y = delta_height * TERRAIN_HEIGHT_INCREMENT; |
| 1586 | |
| 1587 | int r, v, o, p, n; |
| 1588 | room *rp; |
| 1589 | |
| 1590 | // Drop all the rooms |
| 1591 | for (r = 0, rp = Rooms; r <= Highest_room_index; r++, rp++) |
| 1592 | if (rp->used) |
| 1593 | for (v = 0; v < rp->num_verts; v++) |
| 1594 | rp->verts[v].y += delta_y; |
| 1595 | |
| 1596 | // Drop all the objects |
| 1597 | for (o = 0; o <= Highest_object_index; o++) |
| 1598 | if (Objects[o].type != OBJ_NONE) { |
| 1599 | vector new_pos = Objects[o].pos; |
| 1600 | new_pos.y += delta_y; |
| 1601 | ObjSetPos(&Objects[o], &new_pos, Objects[o].roomnum, NULL, false); |
| 1602 | } |
| 1603 | |
| 1604 | // Drop all the paths |
| 1605 | for (p = 0; p < Num_game_paths; p++) |
| 1606 | for (n = 0; n < GamePaths[p].num_nodes; n++) |
| 1607 | GamePaths[p].pathnodes[n].pos.y += delta_y; |
| 1608 | |
| 1609 | // Done |
| 1610 | EditorStatus("Terrain moved by by %d to %d", delta_height, desired_height); |
| 1611 | World_changed = 1; |
| 1612 | } |
| 1613 | |
| 1614 | void CTerrainDialog::OnSaveAsPcx() { |
| 1615 | |
| 1616 | char filename[255]; |
| 1617 | |
| 1618 | CString filter = "PCX files (*.pcx)|*.pcx||"; |
| 1619 | |
| 1620 | if (!SaveFileDialog(this, (LPCSTR)filter, filename, Current_bitmap_dir, sizeof(Current_bitmap_dir))) |
| 1621 | return; |
| 1622 | |
| 1623 | CFILE *outfile; |
| 1624 | |
| 1625 | outfile = (CFILE *)cfopen(filename, "wb"); |
| 1626 | if (!outfile) { |
| 1627 | OutrageMessageBox("Couldn't open that filename to save to!"); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
| 1631 | // Header info |
| 1632 | cf_WriteByte(outfile, 10); |
| 1633 | cf_WriteByte(outfile, 5); |
| 1634 | cf_WriteByte(outfile, 1); |
| 1635 | cf_WriteByte(outfile, 8); |
| 1636 | |
| 1637 | // Dimensions of image |
| 1638 | cf_WriteShort(outfile, 0); |
| 1639 | cf_WriteShort(outfile, 0); |
| 1640 | cf_WriteShort(outfile, 255); |
| 1641 | cf_WriteShort(outfile, 255); |
| 1642 | |
| 1643 | // Display adapter dimensions (bash to 256) |
| 1644 | cf_WriteShort(outfile, 256); |
| 1645 | cf_WriteShort(outfile, 256); |
| 1646 | |
| 1647 | for (int i = 0; i < 48; i++) |
| 1648 | cf_WriteByte(outfile, 0); |
| 1649 | |
| 1650 | cf_WriteByte(outfile, 0); |
| 1651 | cf_WriteByte(outfile, 1); |
| 1652 | cf_WriteShort(outfile, 256); |
| 1653 | cf_WriteShort(outfile, 2); |
| 1654 | |
| 1655 | for (i = 0; i < 58; i++) |
| 1656 | cf_WriteByte(outfile, 0); |
| 1657 | |
| 1658 | for (i = 0; i < TERRAIN_DEPTH; i++) { |
| 1659 | for (int t = 0; t < TERRAIN_WIDTH; t++) { |
| 1660 | uint8_t val = Terrain_seg[(((TERRAIN_DEPTH - 1) - i) * TERRAIN_WIDTH) + t].ypos; |
| 1661 | uint8_t runlen = 0xc1; |
| 1662 | |
| 1663 | cf_WriteByte(outfile, runlen); |
| 1664 | cf_WriteByte(outfile, val); |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | cf_WriteByte(outfile, 12); |
| 1669 | for (i = 0; i < 256; i++) { |
| 1670 | cf_WriteByte(outfile, i); |
| 1671 | cf_WriteByte(outfile, i); |
| 1672 | cf_WriteByte(outfile, i); |
| 1673 | } |
| 1674 | |
| 1675 | cfclose(outfile); |
| 1676 | OutrageMessageBox("PCX exported!\n"); |
| 1677 | } |
| 1678 | |
| 1679 | void CTerrainDialog::OnNoExtRoomsObjs() { |
| 1680 | if (IsDlgButtonChecked(IDC_NO_EXT_ROOMS_OBJS)) { |
| 1681 | Terrain_render_ext_room_objs = false; |
| 1682 | } else { |
| 1683 | Terrain_render_ext_room_objs = true; |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | #define FILL_COLOR 1 |
| 1688 | static uint8_t *Terrain_heights, *Terrain_fill; |
| 1689 | |
| 1690 | #define PUSH_FILL(x) \ |
| 1691 | { \ |
| 1692 | fill_stack[stack_count] = x; \ |
| 1693 | Terrain_fill[x] = 1; \ |
| 1694 | stack_count++; \ |
| 1695 | ASSERT(stack_count < 65536); \ |
| 1696 | } |
| 1697 | #define POP_FILL() \ |
| 1698 | { \ |
| 1699 | stack_count--; \ |
| 1700 | cell = fill_stack[stack_count]; \ |
| 1701 | } |
| 1702 | |
| 1703 | void FillTerrainHeights(int cell) { |
| 1704 | terrain_segment *tseg = &Terrain_seg[cell]; |
| 1705 | uint16_t fill_stack[65536]; |
| 1706 | int stack_count = 0; |
| 1707 | |
| 1708 | ASSERT(cell >= 0 && cell < TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1709 | |
| 1710 | memset(Terrain_fill, 0, TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1711 | |
| 1712 | PUSH_FILL(cell); |
| 1713 | |
| 1714 | while (stack_count > 0) { |
| 1715 | POP_FILL(); |
| 1716 | if (Terrain_heights[cell] == 0) { |
| 1717 | int x = cell % 256; |
| 1718 | int z = cell / 256; |
| 1719 | |
| 1720 | Terrain_heights[cell] = FILL_COLOR; |
| 1721 | |
| 1722 | if (x != 0 && Terrain_fill[cell - 1] == 0) |
| 1723 | PUSH_FILL(cell - 1); |
| 1724 | if (x != TERRAIN_WIDTH - 1 && Terrain_fill[cell + 1] == 0) |
| 1725 | PUSH_FILL(cell + 1); |
| 1726 | if (z != 0 && Terrain_fill[cell - TERRAIN_WIDTH] == 0) |
| 1727 | PUSH_FILL(cell - TERRAIN_WIDTH); |
| 1728 | if (z != TERRAIN_DEPTH - 1 && Terrain_fill[cell + TERRAIN_WIDTH] == 0) |
| 1729 | PUSH_FILL(cell + TERRAIN_DEPTH); |
| 1730 | } |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | void CTerrainDialog::OnTerrainOcclusion() { |
| 1735 | // TODO: Add your control notification handler code here |
| 1736 | if (Terrain_occlusion_checksum == (Terrain_checksum + 1)) { |
| 1737 | OutrageMessageBox("The occlusion map is already calculated for this terrain."); |
| 1738 | // return; |
| 1739 | } |
| 1740 | |
| 1741 | if ((MessageBox("Are you sure you wish to calculate terrain occlusion?", "Question", MB_YESNO)) == IDNO) |
| 1742 | return; |
| 1743 | |
| 1744 | mprintf(0, "Now doing occlusion tests...\n"); |
| 1745 | |
| 1746 | int count = 0; |
| 1747 | int occlude_count = 0; |
| 1748 | uint8_t *touch_buffer[256]; |
| 1749 | |
| 1750 | for (int i = 0; i < 256; i++) { |
| 1751 | memset(Terrain_occlusion_map[i], 0, 32); |
| 1752 | touch_buffer[i] = (uint8_t *)mem_malloc(256); |
| 1753 | ASSERT(touch_buffer[i]); |
| 1754 | memset(touch_buffer[i], 255, 256); |
| 1755 | } |
| 1756 | |
| 1757 | uint8_t *save_buffer; |
| 1758 | |
| 1759 | // Build a height map so we can flood fill |
| 1760 | Terrain_heights = (uint8_t *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1761 | Terrain_fill = (uint8_t *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1762 | save_buffer = (uint8_t *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1763 | |
| 1764 | ASSERT(Terrain_heights); |
| 1765 | ASSERT(save_buffer); |
| 1766 | ASSERT(Terrain_fill); |
| 1767 | |
| 1768 | memset(save_buffer, 0, TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1769 | memset(Terrain_fill, 0, TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1770 | |
| 1771 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 1772 | if (Terrain_seg[i].ypos == 255) |
| 1773 | save_buffer[i] = 255; |
| 1774 | } |
| 1775 | |
| 1776 | for (i = 0; i < OCCLUSION_SIZE; i++) { |
| 1777 | for (int t = 0; t < OCCLUSION_SIZE; t++) { |
| 1778 | int src_occlusion_index = i * OCCLUSION_SIZE + t; |
| 1779 | int start_x = t * OCCLUSION_SIZE; |
| 1780 | int start_z = i * OCCLUSION_SIZE; |
| 1781 | int k, j; |
| 1782 | int dest_x, dest_z; |
| 1783 | |
| 1784 | for (dest_z = 0; dest_z < OCCLUSION_SIZE; dest_z++) { |
| 1785 | for (dest_x = 0; dest_x < OCCLUSION_SIZE; dest_x++) { |
| 1786 | int end_z = dest_z * OCCLUSION_SIZE; |
| 1787 | int end_x = dest_x * OCCLUSION_SIZE; |
| 1788 | int dest_occlusion_index = dest_z * OCCLUSION_SIZE + dest_x; |
| 1789 | |
| 1790 | mprintf_at(2, 5, 0, "Count=%7d", count++); |
| 1791 | |
| 1792 | if (dest_occlusion_index == src_occlusion_index) { |
| 1793 | // This is us! |
| 1794 | int occ_byte = dest_occlusion_index / 8; |
| 1795 | int occ_bit = dest_occlusion_index % 8; |
| 1796 | |
| 1797 | Terrain_occlusion_map[src_occlusion_index][occ_byte] |= (1 << occ_bit); |
| 1798 | touch_buffer[src_occlusion_index][dest_occlusion_index] = 1; |
| 1799 | continue; |
| 1800 | } |
| 1801 | |
| 1802 | if (touch_buffer[dest_occlusion_index][src_occlusion_index] != 255) { |
| 1803 | // this one has already been computed |
| 1804 | int hit = touch_buffer[dest_occlusion_index][src_occlusion_index]; |
| 1805 | |
| 1806 | int dest_occ_byte = dest_occlusion_index / 8; |
| 1807 | int dest_occ_bit = dest_occlusion_index % 8; |
| 1808 | |
| 1809 | if (hit) |
| 1810 | Terrain_occlusion_map[src_occlusion_index][dest_occ_byte] |= (1 << dest_occ_bit); |
| 1811 | else |
| 1812 | Terrain_occlusion_map[src_occlusion_index][dest_occ_byte] &= ~(1 << dest_occ_bit); |
| 1813 | |
| 1814 | touch_buffer[src_occlusion_index][dest_occlusion_index] = hit; |
| 1815 | continue; |
| 1816 | } |
| 1817 | |
| 1818 | // See if this ray is close enough |
| 1819 | vector src_vec, dest_vec; |
| 1820 | |
| 1821 | src_vec.x = start_x; |
| 1822 | src_vec.y = 0; |
| 1823 | src_vec.z = start_z; |
| 1824 | |
| 1825 | dest_vec.x = end_x; |
| 1826 | dest_vec.y = 0; |
| 1827 | dest_vec.z = end_z; |
| 1828 | |
| 1829 | // vector subvec=dest_vec-src_vec; |
| 1830 | |
| 1831 | // Set our heights to max |
| 1832 | memset(Terrain_heights, 255, TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 1833 | |
| 1834 | // Now carve out a path from the src to the dest |
| 1835 | int x_major = 1; |
| 1836 | if (abs(end_z - start_z) > abs(end_x - start_x)) |
| 1837 | x_major = 0; |
| 1838 | |
| 1839 | // We're iterating over the x axis |
| 1840 | if (x_major) { |
| 1841 | int x_add = 1; |
| 1842 | int limit = end_x - start_x; |
| 1843 | if (limit < 0) { |
| 1844 | x_add = -1; |
| 1845 | limit = -limit; |
| 1846 | } |
| 1847 | |
| 1848 | int cur_x = start_x; |
| 1849 | float cur_z = start_z; |
| 1850 | float delta_z = (float)(end_z - start_z) / (float)limit; |
| 1851 | |
| 1852 | for (j = 0; j < limit; j++, cur_x += x_add, cur_z += delta_z) { |
| 1853 | for (int z = 0; z < OCCLUSION_SIZE; z++) { |
| 1854 | for (int x = 0; x < OCCLUSION_SIZE; x++) { |
| 1855 | int index = (cur_z + z) * TERRAIN_WIDTH; |
| 1856 | index += (cur_x + x); |
| 1857 | |
| 1858 | Terrain_heights[index] = 0; |
| 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | } else // iterate over z axis |
| 1863 | { |
| 1864 | int z_add = 1; |
| 1865 | int limit = end_z - start_z; |
| 1866 | if (limit < 0) { |
| 1867 | z_add = -1; |
| 1868 | limit = -limit; |
| 1869 | } |
| 1870 | |
| 1871 | int cur_z = start_z; |
| 1872 | float cur_x = start_x; |
| 1873 | float delta_x = (float)(end_x - start_x) / (float)limit; |
| 1874 | |
| 1875 | for (j = 0; j < limit; j++, cur_z += z_add, cur_x += delta_x) { |
| 1876 | for (int z = 0; z < OCCLUSION_SIZE; z++) { |
| 1877 | for (int x = 0; x < OCCLUSION_SIZE; x++) { |
| 1878 | int index = (cur_z + z) * TERRAIN_WIDTH; |
| 1879 | index += (cur_x + x); |
| 1880 | |
| 1881 | Terrain_heights[index] = 0; |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | // Ok, we have a carved path |
| 1888 | // Now put back in all the max values from our original map |
| 1889 | for (k = 0; k < TERRAIN_WIDTH * TERRAIN_DEPTH; k++) { |
| 1890 | if (save_buffer[k] == 255) |
| 1891 | Terrain_heights[k] = 255; |
| 1892 | } |
| 1893 | |
| 1894 | // Set our src block to zero |
| 1895 | for (k = 0; k < OCCLUSION_SIZE; k++) { |
| 1896 | for (j = 0; j < OCCLUSION_SIZE; j++) { |
| 1897 | Terrain_heights[((start_z + k) * TERRAIN_WIDTH) + start_x + j] = 0; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | // Fill that valley |
| 1902 | FillTerrainHeights((start_z * TERRAIN_WIDTH) + start_x); |
| 1903 | |
| 1904 | // Check to see if we hit our destination |
| 1905 | int seen = 0; |
| 1906 | for (int z = 0; z < OCCLUSION_SIZE && !seen; z++) { |
| 1907 | for (int x = 0; x < OCCLUSION_SIZE && !seen; x++) { |
| 1908 | int index = (end_z + z) * TERRAIN_WIDTH; |
| 1909 | index += (end_x + x); |
| 1910 | |
| 1911 | if (Terrain_heights[index] == 1) |
| 1912 | seen = 1; |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | touch_buffer[src_occlusion_index][dest_occlusion_index] = seen; |
| 1917 | if (seen) { |
| 1918 | int occ_byte = dest_occlusion_index / 8; |
| 1919 | int occ_bit = dest_occlusion_index % 8; |
| 1920 | Terrain_occlusion_map[src_occlusion_index][occ_byte] |= (1 << occ_bit); |
| 1921 | } else { |
| 1922 | int occ_byte = dest_occlusion_index / 8; |
| 1923 | int occ_bit = dest_occlusion_index % 8; |
| 1924 | Terrain_occlusion_map[src_occlusion_index][occ_byte] &= ~(1 << occ_bit); |
| 1925 | |
| 1926 | occlude_count++; |
| 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | mem_free(Terrain_heights); |
| 1934 | mem_free(Terrain_fill); |
| 1935 | mem_free(save_buffer); |
| 1936 | |
| 1937 | for (i = 0; i < 256; i++) |
| 1938 | mem_free(touch_buffer[i]); |
| 1939 | |
| 1940 | Terrain_occlusion_checksum = Terrain_checksum + 1; |
| 1941 | |
| 1942 | mprintf(0, "%d cells were occluded.\n", occlude_count); |
| 1943 | OutrageMessageBox("Occlusion checking complete. Remember to save!"); |
| 1944 | } |
| 1945 | |
| 1946 | void CTerrainDialog::OnSatelliteRadio() { |
| 1947 | cc_mode = CC_MODE_SAT; |
| 1948 | UpdateDialog(); |
| 1949 | } |
| 1950 | |
| 1951 | void CTerrainDialog::OnForceVisible() { |
| 1952 | for (int i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 1953 | if (TerrainSelected[i]) { |
| 1954 | int c = Terrain_seg[i].flags & TF_INVISIBLE; |
| 1955 | |
| 1956 | if (c) { |
| 1957 | Terrain_seg[i].flags &= ~TF_INVISIBLE; |
| 1958 | World_changed = 1; |
| 1959 | } |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | if (World_changed) |
| 1964 | GenerateLODDeltas(); |
| 1965 | } |
| 1966 | |
| 1967 | void CTerrainDialog::OnKillfocusDamagePerSecEdit() { |
| 1968 | CEdit *ebox; |
| 1969 | char str[20]; |
| 1970 | float err; |
| 1971 | |
| 1972 | ebox = (CEdit *)GetDlgItem(IDC_DAMAGE_PER_SEC_EDIT); |
| 1973 | ebox->GetWindowText(str, 20); |
| 1974 | |
| 1975 | err = atof(str); |
| 1976 | if (err < 0) |
| 1977 | err = 0; |
| 1978 | if (err > 200) |
| 1979 | err = 200; |
| 1980 | |
| 1981 | Terrain_sky.damage_per_second = err; |
| 1982 | |
| 1983 | World_changed = 1; |
| 1984 | UpdateDialog(); |
| 1985 | } |
| 1986 | |
| 1987 | void CTerrainDialog::OnKillfocusFogScalarEdit() { |
| 1988 | CEdit *ebox; |
| 1989 | char str[20]; |
| 1990 | float err; |
| 1991 | |
| 1992 | ebox = (CEdit *)GetDlgItem(IDC_FOG_SCALAR_EDIT); |
| 1993 | ebox->GetWindowText(str, 20); |
| 1994 | |
| 1995 | err = atof(str); |
| 1996 | if (err < .2) |
| 1997 | err = .2f; |
| 1998 | if (err > 1.0) |
| 1999 | err = 1.0; |
| 2000 | |
| 2001 | Terrain_sky.fog_scalar = err; |
| 2002 | |
| 2003 | World_changed = 1; |
| 2004 | UpdateDialog(); |
| 2005 | } |
| 2006 | |
| 2007 | void CTerrainDialog::OnRotateStars() { |
| 2008 | int c = IsDlgButtonChecked(IDC_ROTATE_STARS); |
| 2009 | |
| 2010 | if (c) |
| 2011 | Terrain_sky.flags |= TF_ROTATE_STARS; |
| 2012 | else |
| 2013 | Terrain_sky.flags &= ~TF_ROTATE_STARS; |
| 2014 | |
| 2015 | TV_changed = 1; |
| 2016 | } |
| 2017 | |
| 2018 | void CTerrainDialog::OnRotateSky() { |
| 2019 | int c = IsDlgButtonChecked(IDC_ROTATE_SKY); |
| 2020 | |
| 2021 | if (c) |
| 2022 | Terrain_sky.flags |= TF_ROTATE_SKY; |
| 2023 | else |
| 2024 | Terrain_sky.flags &= ~TF_ROTATE_SKY; |
| 2025 | |
| 2026 | TV_changed = 1; |
| 2027 | } |
| 2028 | |
| 2029 | void CTerrainDialog::OnKillfocusRotateSpeedEdit() { |
| 2030 | CEdit *ebox; |
| 2031 | char str[20]; |
| 2032 | float err; |
| 2033 | |
| 2034 | ebox = (CEdit *)GetDlgItem(IDC_ROTATE_SPEED_EDIT); |
| 2035 | ebox->GetWindowText(str, 20); |
| 2036 | |
| 2037 | err = atof(str); |
| 2038 | if (err < 0) |
| 2039 | err = 0; |
| 2040 | if (err > 180) |
| 2041 | err = 180; |
| 2042 | |
| 2043 | Terrain_sky.rotate_rate = err; |
| 2044 | |
| 2045 | World_changed = 1; |
| 2046 | UpdateDialog(); |
| 2047 | } |
| 2048 | |
| 2049 | void CTerrainDialog::OnTileMore() { |
| 2050 | int i; |
| 2051 | uint8_t touched[TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH]; |
| 2052 | memset(touched, 0, TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH); |
| 2053 | |
| 2054 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 2055 | if (TerrainSelected[i]) { |
| 2056 | if (!touched[Terrain_seg[i].texseg_index]) { |
| 2057 | int val = Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation >> 4; |
| 2058 | if (val < 8) |
| 2059 | val++; |
| 2060 | |
| 2061 | val <<= 4; |
| 2062 | |
| 2063 | Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation &= ~0xF0; |
| 2064 | Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation |= val; |
| 2065 | touched[Terrain_seg[i].texseg_index] = 1; |
| 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | World_changed = 1; |
| 2071 | TV_changed = 1; |
| 2072 | } |
| 2073 | |
| 2074 | void CTerrainDialog::OnTileLess() { |
| 2075 | int i; |
| 2076 | uint8_t touched[TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH]; |
| 2077 | memset(touched, 0, TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH); |
| 2078 | |
| 2079 | for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) { |
| 2080 | if (TerrainSelected[i]) { |
| 2081 | if (!touched[Terrain_seg[i].texseg_index]) { |
| 2082 | int val = Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation >> 4; |
| 2083 | if (val > 1) |
| 2084 | val--; |
| 2085 | |
| 2086 | val <<= 4; |
| 2087 | |
| 2088 | Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation &= ~0xF0; |
| 2089 | Terrain_tex_seg[Terrain_seg[i].texseg_index].rotation |= val; |
| 2090 | touched[Terrain_seg[i].texseg_index] = 1; |
| 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | World_changed = 1; |
| 2096 | TV_changed = 1; |
| 2097 | } |
| 2098 | |
| 2099 | #include "TerrainSoundDialog.h" |
| 2100 | |
| 2101 | void CTerrainDialog::OnTerrSound() { |
| 2102 | CTerrainSoundDialog dlg; |
| 2103 | |
| 2104 | dlg.DoModal(); |
| 2105 | } |