1 (* 2 * Hedgewars, a free turn based strategy game 3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> 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; version 2 of the License 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 *) 18 19 {$INCLUDE "options.inc"} 20 21 unit uConsts; 22 interface 23 24 uses SDLh, uFloat, GLunit; 25 26 {$INCLUDE "config.inc"} 27 28 const 29 HDPIScaleFactor = 1; 30 31 // application return codes 32 HaltNoError = 0; // Hedgewars quits normally 33 34 // error codes are placed in range 50-99 because that way then don't overlap with run-time errors of pascal 35 // see https://www.freepascal.org/docs-html/user/userap4.html 36 HaltUsageError = 51; // Hedgewars was invoked incorrectly (e.g. bad command-line parameter) 37 HaltFatalError = 52; // Fatal internal error. See logs for more. Also reports error to frontend 38 HaltStartupError = 53; // Failure loading critical resources 39 HaltFatalErrorNoIPC = 54; // Fatal internal error, IPC socket is not available 40 41 // for automatic tests 42 HaltTestSuccess = 0; // Test result: success 43 HaltTestFailed = 60; // Test result: failed 44 HaltTestLuaError = 61; // Lua runtime error 45 HaltTestUnexpected = 62; // Unexpected error 46 47 48 // maximum ScreenFadeValue 49 sfMax = 1000; 50 51 // log message constants 52 errmsgCreateSurface = 'Error creating SDL surface'; 53 errmsgTransparentSet = 'Error setting transparent color'; 54 errmsgUnknownCommand = 'Unknown command'; 55 errmsgUnknownVariable = 'Unknown variable'; 56 errmsgIncorrectUse = 'Incorrect use'; 57 errmsgShouldntRun = 'This program shouldn''t be run manually'; 58 errmsgWrongNumber = 'Wrong parameters number'; 59 errmsgLuaTestTerm = 'WARNING: Lua test terminated before the test was properly finished with EndLuaTest()!'; 60 61 msgLoading = 'Loading '; 62 msgOK = 'ok'; 63 msgFailed = 'failed'; 64 msgFailedSize = 'failed due to size'; 65 msgGettingConfig = 'Getting game config...'; 66 67 // camera movement multipliers 68 cameraKeyboardSpeed : LongInt = 10; 69 cameraKeyboardSpeedSlow : LongInt = 3; 70 71 // color constants 72 cWhiteColorChannels : TSDL_Color = (r:$FF; g:$FF; b:$FF; a:$FF); 73 cNearBlackColorChannels : TSDL_Color = (r:$00; g:$00; b:$10; a:$FF); 74 cInvertTextColorAt : Byte = 64; 75 76 cWhiteColor : Longword = $FFFFFFFF; // white 77 cNearBlackColor : Longword = $FF000010; // nearly black 78 79 capcolDefault : Longword = $FFFFFFFF; // default caption color 80 capcolSetting : Longword = $FFCCCCCC; // caption color for changing client setting like volume or auto camera 81 capcolDefaultLua : Longword = $FFFFFFFF; // capcolDefault for Lua 82 capcolSettingLua : Longword = $CCCCCCFF; // capcolSetting for Lua 83 84 cCentralMessageColor : Longword = $FFFFFF00; // color of message in center of screen like quit or pause 85 86 {$WARNINGS OFF} 87 cAirPlaneSpeed: hwFloat = (isNegative: false; QWordValue: 3006477107); // 1.4 88 cBombsSpeed : hwFloat = (isNegative: false; QWordValue: 429496729); 89 {$WARNINGS ON} 90 91 // reducedquality flags 92 rqNone = $00000000; // don't reduce quality 93 rqLowRes = $00000001; // use half land array 94 rqBlurryLand = $00000002; // downscaled terrain 95 rqNoBackground= $00000004; // don't draw background 96 rqSimpleRope = $00000008; // draw rope using lines only 97 rq2DWater = $00000010; // disable 3D water effect 98 rqAntiBoom = $00000020; // no fancy explosion effects 99 rqKillFlakes = $00000040; // no flakes 100 rqSlowMenu = $00000080; // ammomenu appears with no animation 101 rqPlainSplash = $00000100; // no droplets 102 rqClampLess = $00000200; // don't clamp textures 103 rqTooltipsOff = $00000400; // tooltips are not drawn 104 rqDesyncVBlank= $00000800; // don't sync on vblank 105 106 // image flags (for LoadImage()) 107 // TODO: discuss whether ifAlpha and ifColorKey are actually needed and if and where we want to support which colorkeys 108 ifNone = $00000000; // nothing special 109 ifAlpha = $00000001; // use alpha channel (unused right now?) 110 ifCritical = $00000002; // image is critical for gameplay (exit game if unable to load) 111 ifColorKey = $00000004; // image uses transparent pixels (color keying) 112 ifIgnoreCaps = $00000008; // ignore hardware capabilities when loading (i.e. image will not be drawn using OpenGL) 113 ifDigestAlpha = $00000010; // add alpha channel to the digest 114 ifDigestAll = $00000020; // add all channels to the digest 115 116 // texture priority (allows OpenGL to keep frequently used textures in video memory more easily) 117 tpLowest = 0.00; 118 tpLow = 0.25; 119 tpMedium = 0.50; 120 tpHigh = 0.75; 121 tpHighest = 1.00; 122 123 // To allow these to layer, going to treat them as masks. The bottom byte is reserved for objects 124 // TODO - set lfBasic for all solid land, ensure all uses of the flags can handle multiple flag bits 125 // lfObject and lfBasic are only to be different *graphically* in all other ways they should be treated the same 126 lfBasic = $8000; // normal destructible terrain (mask.png: black) 127 lfIndestructible = $4000; // indestructible terrain (mask.png: red) 128 lfObject = $2000; // destructible terrain, land object (mask.png: white) 129 lfDamaged = $1000; // 130 lfIce = $0800; // icy terrain (mask.png: blue) 131 lfBouncy = $0400; // bouncy terrain (mask.png: green) 132 lfLandMask = $FF00; // upper byte is used for terrain, not objects. 133 134 lfCurHogCrate = $0080; // CurrentHedgehog, and crates, for convenience of AI. Since an active hog would instantly collect the crate, this does not impact playj 135 lfNotCurHogCrate = $FF7F; // inverse of above. frequently used 136 lfObjMask = $007F; // lower 7 bits used for hogs and explosives and mines 137 lfNotObjMask = $FF80; // inverse of above. 138 139 // breaking up hogs would makes it easier to differentiate 140 // colliding with a hog from colliding with other things 141 // if overlapping hogs are less common than objects, the division can be altered. 142 // 3 bits for objects, 4 for hogs, that is, overlap 7 barrels/mines before possible dents, and 15 hogs. 143 lfHHMask = $000F; // lower 4 bits used only for hogs 144 lfNotHHObjMask = $0070; // next 3 bits used for non-hog things 145 lfNotHHObjShift = 4; 146 lfNotHHObjSize = lfNotHHObjMask shr lfNotHHObjShift; 147 148 // lower byte is for objects. 149 // consists of 0-127 counted for object checkins and $80 as a bit flag for current hog. 150 lfAllObjMask = $00FF; // lfCurHogCrate or lfObjMask 151 152 lfAll = $FFFF; // everything 153 154 155 156 cMaxPower = 1500; // maximum power value for ammo that powers up 157 cMaxAngle = 2048; // maximum positive value for Gear angle 158 cPowerDivisor = 1500; 159 160 MAXNAMELEN = 192; 161 MAXROPEPOINTS = 3840; 162 MAXROPELAYERS = 16; 163 164 {$IFNDEF PAS2C} 165 // some opengl headers do not have these macros 166 GL_BGR = $80E0; 167 GL_BGRA = $80E1; 168 GL_CLAMP_TO_EDGE = $812F; 169 GL_TEXTURE_PRIORITY = $8066; 170 {$ENDIF} 171 172 cVisibleWater : LongInt = 128; 173 cTeamHealthWidth : LongInt = 128; 174 cGearContourThreshold : LongInt = 179; // if water opacity is higher than this, draw contour for some gears when in water 175 176 cifRandomize = $00000001; 177 cifTheme = $00000002; 178 cifMap = $00000002; // either theme or map (or map+theme) 179 cifAllInited = cifRandomize or cifTheme or cifMap; 180 181 RGB_LUMINANCE_RED = 0.212671; 182 RGB_LUMINANCE_GREEN = 0.715160; 183 RGB_LUMINANCE_BLUE = 0.072169; 184 185 // hedgehog info 186 cMaxTeams = 8; // maximum number of teams 187 cMaxHHIndex = 7; // maximum hedgehog index (counting starts at 0) 188 // NOTE: If you change cMaxHHIndex, also change cMaxHogHealth! 189 cMaxHHs = cMaxTeams * (cMaxHHIndex+1); // maximum number of hogs 190 191 cClanColors = 9; // number of possible clan colors 192 193 cMaxEdgePoints = 32768; 194 195 cBorderWidth = 6; // width of indestructible border 196 // width of 3 allowed hogs to be knocked through with grenade 197 198 cHHRadius = 9; // hedgehog radius 199 cHHStepTicks = 29; 200 201 cMaxHogHealth = 268435455; // maximum hedgehog health 202 // cMaxHogHealth was calculated by: High(LongInt) div (cMaxHHIndex+1); 203 204 ouchDmg = 55; // least amount of damage a hog must take in one blow for sndOuch to play 205 206 // Z levels 207 cHHZ = 1000; 208 cCurrHHZ = Succ(cHHZ); 209 210 // some gear constants 211 cBarrelHealth = 60; // initial barrel health 212 cShotgunRadius = 22; // radius of land a shotgun shot destroys 213 cBlowTorchC = 6; // blow torch gear radius component (added to cHHRadius to get the full radius) 214 cakeDmg = 75; // default cake damage 215 216 // key stuff 217 cKeyMaxIndex = 1600; 218 cKbdMaxIndex = 65536;//need more room for the modifier keys 219 220 // font stuff 221 cFontBorder = 2 * HDPIScaleFactor; 222 cFontPadding = 2 * HDPIScaleFactor; 223 224 cDefaultBuildMaxDist = 256; // default max. building distance with girder/rubber 225 cResurrectorDist = 100; // effect distance of resurrector 226 cSeductionDist = 250; // effect distance of seduction 227 228 ExtraTime = 30000; // amount of time (ms) given for using Extra Time 229 230 // do not change this value 231 cDefaultZoomLevel = 2.0; // 100% zoom 232 233 // game flags 234 gfAny = $FFFFFFFF; // mask for all possible gameflags 235 gfOneClanMode = $00000001; // Game does not end if there's only one clan in play. For missions 236 gfMultiWeapon = $00000002; // Enter multishoot mode after attack with infinite shots. For target practice 237 gfSolidLand = $00000004; // (almost) indestrutible land 238 gfBorder = $00000008; // border at top, left and right 239 gfDivideTeams = $00000010; // each clan spawns their hogs on own side of terrain 240 gfLowGravity = $00000020; // low gravity 241 gfLaserSight = $00000040; // laser sight for all 242 gfInvulnerable = $00000080; // invulerable for all 243 gfResetHealth = $00000100; // heal hogs health up to InitialHealth each turn 244 gfVampiric = $00000200; // vampirism for all 245 gfKarma = $00000400; // receive damage you deal 246 gfArtillery = $00000800; // hogs can't walk 247 gfSwitchHog = $00001000; // free switch hog at turn start 248 gfRandomOrder = $00002000; // hogs play in random order 249 gfKing = $00004000; // King Mode 250 gfPlaceHog = $00008000; // place all hogs at game start 251 gfSharedAmmo = $00010000; // ammo is shared per-clan 252 gfDisableGirders = $00020000; // disable land girders 253 gfDisableLandObjects = $00040000; // disable land objects 254 gfAISurvival = $00080000; // AI is revived 255 gfInfAttack = $00100000; // infinite attack 256 gfResetWeps = $00200000; // reset weapons each turn 257 gfPerHogAmmo = $00400000; // each hog has its own ammo 258 gfDisableWind = $00800000; // don't automatically change wind 259 gfMoreWind = $01000000; // wind influences most gears 260 gfTagTeam = $02000000; // hogs of same clan share their turn time 261 gfBottomBorder = $04000000; // border at bottom 262 gfShoppaBorder = $08000000; // Surround terrain with fancy "security border". Pure eye candy 263 // NOTE: When adding new game flags, ask yourself 264 // if a "game start notice" would be useful. If so, 265 // add one in uWorld.pas - look for "AddGoal". 266 267 // gear states 268 gstDrowning = $00000001; // drowning 269 gstHHDriven = $00000002; // hog is controlled by current player 270 gstMoving = $00000004; // moving 271 gstAttacked = $00000008; // after attack 272 gstAttacking = $00000010; // while attacking 273 gstCollision = $00000020; // it has *just* collided 274 gstChooseTarget = $00000040; // choosing target 275 gstHHJumping = $00000100; // hog is doing long jump 276 gsttmpFlag = $00000200; // temporary wildcard flag, use it for anything you want 277 gstHHThinking = $00000800; // AI hog is thinking 278 gstNoDamage = $00001000; // gear is immune to damage 279 gstHHHJump = $00002000; // hog is doing high jump 280 gstAnimation = $00004000; // hog is playing an animation 281 gstHHDeath = $00008000; // hog is dying 282 gstWinner = $00010000; // indicates if hog did well 283 gstWait = $00020000; 284 gstNotKickable = $00040000; // gear cannot be pushed by forces 285 gstLoser = $00080000; // indicates if hog screwed up 286 gstHHGone = $00100000; // hog is gone (teamgone event) 287 gstInvisible = $00200000; // invisible 288 gstSubmersible = $00400000; // can survive in water 289 gstFrozen = $00800000; // frozen 290 gstNoGravity = $01000000; // ignores gravity 291 gstInBounceEdge = $02000000; // spawned in bounce edge 292 293 // gear messages 294 gmLeft = $00000001; // left 295 gmRight = $00000002; // right 296 gmUp = $00000004; // up 297 gmDown = $00000008; // down 298 gmSwitch = $00000010; // switch hedgehog 299 gmAttack = $00000020; // attack 300 gmLJump = $00000040; // long jump 301 gmHJump = $00000080; // high jump 302 gmDestroy = $00000100; // request to self-destruct 303 gmSlot = $00000200; // slot key; with param 304 gmWeapon = $00000400; // direct weapon selection (SetWeapon); with param 305 gmTimer = $00000800; // set timer; with param 306 gmAnimate = $00001000; // start animation; with param 307 gmPrecise = $00002000; // precise aim 308 309 // gmAddToList and gmRemoveFromList are used when changing order of gears in the gear list. They are used together when changing a gear's Z (drawing order) 310 gmRemoveFromList = $00004000; // remove gear from gear list 311 gmAddToList = $00008000; // add gear to gear list 312 313 gmDelete = $00010000; // delete gear 314 gmAllStoppable = gmLeft or gmRight or gmUp or gmDown or gmAttack or gmPrecise; 315 316 // ammo slots 317 cMaxSlotIndex = 10; // maximum slot index (including hidden slot) (row in ammo menu) 318 cHiddenSlotIndex = cMaxSlotIndex; // slot for hidden ammo types, not visible and has no key 319 cMaxSlotAmmoIndex = 5; // maximum index for ammos per slot (column in ammo menu) 320 321 // AI hints to be set for any gear 322 aihUsualProcessing = $00000000; // treat gear as usual 323 aihDoesntMatter = $00000001; // ignore gear in attack calculations and don't intentionally attack it 324 aihAmmosChanged = $00000002; // set when ammos were changed within this turn but not processed yet 325 326 // ammo properties 327 ammoprop_Timerable = $00000001; // can set timer 328 ammoprop_Power = $00000002; // can power up fire strength 329 ammoprop_NeedTarget = $00000004; // must select target 330 ammoprop_ForwMsgs = $00000008; // received gear messages are forwarded to the spawned gear 331 ammoprop_AttackInMove = $00000010; // can attack while moving / in mid-air 332 ammoprop_DoesntStopTimerWhileAttacking 333 = $00000020; // doesn't stop timer while attacker is attacking 334 ammoprop_NoCrosshair = $00000040; // no crosshair rendered 335 ammoprop_AttackingPut = $00000080; // selecting a target is considered an attack 336 ammoprop_DontHold = $00000100; // don't keep ammo selected in next turn 337 ammoprop_AltAttack = $00000200; // ammo can equip alternate ammo (ammoprop_AltUse) 338 ammoprop_AltUse = $00000400; // ammo can be equipped by an ammo with ammoprop_AltAttack 339 ammoprop_NotBorder = $00000800; // ammo is not available if map has border 340 ammoprop_Utility = $00001000; // ammo is considered an utility instead of a weapon 341 ammoprop_Effect = $00002000; // ammo is considered an effect like extra time or vampirism 342 ammoprop_SetBounce = $00004000; // can set bounciness 343 ammoprop_NeedUpDown = $00008000; // used by TouchInterface to show or hide up/down widgets 344 ammoprop_OscAim = $00010000; // oscillating aim 345 ammoprop_NoMoveAfter = $00020000; // can't move after attacking 346 ammoprop_Track = $00040000; // ammo follows the landscape, used by AI 347 ammoprop_DoesntStopTimerInMultiShoot 348 = $00080000; // doesn't stop timer after entering multi-shoot mode 349 ammoprop_DoesntStopTimerWhileAttackingInInfAttackMode 350 = $00100000; // doesn't stop timer while Attacking gear msg is set and inf. attack mode is on 351 ammoprop_ForceTurnEnd = $00200000; // always ends turn after usage, ignoring inf. attack 352 ammoprop_NoTargetAfter= $00400000; // disable target selection after attack 353 ammoprop_NoWrapTarget = $00800000; // allow to select target beyond wrap world edge limits 354 ammoprop_ShowSelIcon = $01000000; // show icon when selected 355 ammoprop_NoRoundEnd = $10000000; // ammo doesn't end turn 356 357 AMMO_INFINITE = 100; // internal representation of infinite ammo count 358 AMMO_FINITE_MAX = 99; // maximum possible finite ammo count 359 360 JETPACK_FUEL_INFINITE : LongInt = Low(LongInt); // internal representation of infinite jetpack fuel 361 BIRDY_ENERGY_INFINITE : LongInt = Low(LongInt); // as above, but for Birdy 362 363 // Special msgParam value used internally for invalid/non-existing value 364 // Must not be sent over the network! 365 MSGPARAM_INVALID = High(LongWord); 366 367 // raw probability values for crate drops 368 probabilityLevels: array [0..8] of LongWord = (0,20,30,60,100,200,400,600,800); 369 370 // raw bounciness values for each of the player-selectable bounciness levels 371 defaultBounciness = 1000; 372 bouncinessLevels: array [0..4] of LongWord = (350, 700, defaultBounciness, 2000, 4000); 373 374 // explosion flags 375 // By default, an explosion removes land, damages and pushes gears, 376 // spawns an explosion animation and plays no sound. 377 //EXPLAllDamageInRadius = $00000001; Completely unused for ages 378 EXPLAutoSound = $00000002; // enable sound (if appropriate) 379 EXPLNoDamage = $00000004; // don't damage gears 380 EXPLDoNotTouchHH = $00000008; // don't push hogs 381 EXPLDontDraw = $00000010; // don't remove land 382 EXPLNoGfx = $00000020; // don't spawn visual effects 383 EXPLPoisoned = $00000040; // poison hogs in effect radius 384 EXPLDoNotTouchAny = $00000080; // don't push anything 385 EXPLForceDraw = $00000100; // remove land even with gfSolidLand 386 387 // Pos flags for gtCase 388 posCaseAmmo = $00000001; // ammo crate 389 posCaseHealth = $00000002; // health crate 390 posCaseUtility = $00000004; // utility crate 391 posCaseDummy = $00000008; // dummy crate 392 posCaseExplode = $00000010; // crate explodes when touched 393 posCasePoison = $00000020; // crate poisons hog when touched 394 395 cCaseHealthRadius = 14; 396 397 // hog tag mask 398 //htNone = $00; 399 htTeamName = $01; 400 htName = $02; 401 htHealth = $04; 402 htTransparent = $08; 403 404 NoPointX = Low(LongInt); // special value for CursorX/CursorY if cursor's disabled 405 cTargetPointRef : TPoint = (x: NoPointX; y: 0); 406 407 kSystemSoundID_Vibrate = $00000FFF; 408 409 cMinPlayWidth = 200; 410 cWorldEdgeDist = 200; 411 412 cMaxLaserSightWraps = 1; // maximum number of world wraps of laser sight 413 414 cMaxTurnTime = Pred(High(LongInt)); // maximum possible turn time 415 416 implementation 417 418 end. 419