Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
merge: one mouse scheme, BAR style
Olcay Seygan6a06514965d7
diff --cc CHANGELOG.mdindex fb1543d28,4d5604f80..82fb51d0f--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -476,52 -391,16 +484,52 @@@ found and fixed — EA's own, not- The writing on screen grows with your monitor now. Every panel is stretched to your resolution and always was, but the text inside it stayed the size it was drawn at in 2003, and what growth there was stopped dead at twice - so on a 2560 wide screen a command bar three times its original size still wore eight point lettering. The keys on the build buttons, the prices and the build times were the worst of it: at 2K they were drawn, and unreadable.- The strip of everything your base is building follows the screen too, instead of staying a row of postage stamps under a command bar three times its size.-- On a widescreen monitor the command bar is three pieces instead of one stretched strip. It was drawn for a 4:3 screen and every measurement in it is multiplied by your resolution separately across and down, so at 16:9 the whole thing came out a third wider than it is tall: square build pictures as rectangles, and one slab of metal across the entire bottom edge. The radar now sits hard in the left corner, the build grid in the middle, the selected unit's panel hard in the right corner, each at the size it was drawn at, and the battlefield shows through the two gaps that opens. At 4:3 the three pieces meet and it is the bar it has always been. The three pieces reach the screen: the paintings stop a pixel or two inside their own edges, which left a hairline of ground down both sides and along the bottom, and anything that close to an edge is now that edge. The American middle piece stands on the bottom edge like the other two sides' do, instead of hanging ten units high with a band of battlefield under the build grid.-- Widescreen resolutions are back in the options menu.+- On a widescreen monitor the command bar is three pieces instead of one stretched strip. It was drawn for a 4:3 screen and every measurement in it is multiplied by your resolution separately across and down, so at 16:9 the whole thing came out a third wider than it is tall: square build pictures as rectangles, and one slab of metal across the entire bottom edge. The radar now sits hard in the left corner, the build grid in the middle, the selected unit's panel hard in the right corner, each at the size it was drawn at, and the battlefield shows through the two gaps that opens. At 4:3 the three pieces meet and it is the bar it has always been. The three pieces reach the screen: the paintings stop a pixel or two inside their own edges, which left a hairline of ground down both sides and along the bottom, and anything that close to an edge is now that edge. The American middle piece stands on the bottom edge like the other two sides' do, instead of hanging ten units high with a band of battlefield under the build grid, your money now sits in the middle of its readout instead of riding the top rim of it, and the build buttons are centred in the panel they are drawn on instead of pushing against its left edge with a strip of empty metal on the right. The stray pixels along the right-hand edges of the pieces are gone: a one-pixel light line down the side of the middle piece, and a lit speck sitting in the battlefield next to the bottom corner of the Chinese radar. Both were the same thing. The bar's artwork was being rescaled as it went to the graphics card, which left the last column of each picture holding a mirrored copy of it, and the last column of pixels on screen drew from there.+- The rest of the interface is drawn at the command bar's size, not the screen's width. The queue strip, the superweapon countdowns, the generals' powers bar down the right edge and the rank screen were each measured against how wide your monitor is, and the bar they sit beside is measured against the smaller of the two dimensions - so on a 16:9 screen a queue picture came out a third bigger than the build button it is a picture of, and the power slots were oblong where they were drawn square. One size for all of it now, and it is the bar's own.+- The generals' powers bar stands on the right edge of the screen instead of hanging off it. It slides in from the right when a power is ready, and the slide stopped one step short of where it was going and left the window there - twenty-one pixels out at 1024x768 - so the rightmost column of powers was drawn half off the monitor and could not be clicked. Every panel in the game that slides in sideways had the same fault; the ones that slide up and down never did.+- The writing on a build button keeps its size against the button. The hotkey letter, the price, the build time and the queue count were sized off how wide your monitor is while the bar they sit on is sized off the smaller of its width and its height, so the wider the screen the further the lettering grew away from the cameo underneath it. One size for both now, and it is the bar's.+- An ultrawide monitor gets the same interface as a 16:9 one. Everything still sized off how wide the screen is came apart at 32:9: on a 5120x1440 screen the lettering was drawn at two and a half times what the panel under it had grown to, the clock and speed readout crept into the top corner because its margins were flat pixels, and a health bar reached across the whole base of the building it belonged to. All of it now measures off the same number the command bar does. Scale a 32:9 screenshot down to 16:9 and the two lie on top of each other.+- The camera shows the same ground whatever shape your monitor is. The game holds the angle it sees across the screen fixed and lets the up-and-down angle shrink as the screen widens, which at 32:9 left fifteen degrees of world against twenty-nine at 16:9 - the same barracks filled twice the height of the screen, and it read as a zoom nobody asked for. Above 16:9 the view opens sideways instead, so a wider monitor buys more battlefield rather than a closer look at less of it. Nothing at 16:9 or below moves.+- The medals on the player info card are round on any screen. They were stretched across and down separately, so a wide monitor turned each one into an oval.+- Minimising the command bar sends all three panels down, and they slide back up when you bring them back. The old minimise dropped the bar a tenth of the screen and left a strip of metal, a readable money box and the top of the radar dish lying along the bottom edge, which is neither the bar nor out of the way. The radar and the middle go off the screen entirely; the selection panel stops with the row its minimise tab is in standing on the bottom corner, so what you click to bring the bar back is that tab with its own artwork behind it, not a button floating over the battlefield.+- Everything on the command bar that each faction places for itself lands where that faction's artwork paints it. The bar's own arithmetic was overwriting those positions with the ones it had used a moment earlier, so every panel wore the generic layout's vertical placement instead of its own: the minimise button drew a second tab below the painted one, arrow and all, and the GLA money sat high enough in its box to touch the frame. One arrow now, one tab, and the number in the middle of its readout - and the same correction reaches the worker, beacon, chat and options buttons down the side of the grid. The American power bar sits in its rail as well: it was drawing on the ledge above the rail, which put the left half of the bar on the battlefield rather than on the bar, and left the rail it reads in standing empty.+- Two stray letters, an "S" and an "M", no longer appear over the battlefield beside the selection panel the first time you minimise the bar and bring it back. They are the labels on the two unused minimise buttons the 2003 layout ships hidden; minimising hid them a second time and un-hid them on the way back.+- The markings on a build button - the shortcut letters, the price, the build time, the queue count - are set bold. At seven points against a busy cameo the light weight read as part of the picture.+- Menu panels slide in at the same speed whatever your monitor is. They travel the width of the+ screen but moved at a fixed forty pixels a step, so the wider the screen the longer every+ transition took: twenty steps at 800 wide, sixty-four at 2560.+- A screenshot no longer takes the game down when the window is bigger than the desktop. Asking for+ a 1600x1200 window on a 1080-tall monitor puts part of it off the screen, and the capture read+ the whole client area out of a buffer that stops at the desktop's edge.+- The arrow on a dropdown is square at every resolution. It was drawn into a slot of a fixed 21 pixels wide however tall the box around it was stretched, so the bigger the screen the more the arrow was squeezed.+- The promotion screen closes when you press its key again, however fast you press it. The screen fades in, and the fade drives the window itself for several frames either way - so a second press during the fade read the screen as still shut and opened it again, and a press just after it was closed was undone by the fade's next frame.+- The command bar stops changing under you while you are using it. With nothing selected the bar shows one of your builders so you can place a structure without picking a dozer first, and it showed whichever one happened to be idle - so a dozer finishing a building on the far side of the base took the bar over, dropping a half-typed build hotkey and taking the structure off your cursor. The builder you are working with keeps the bar.+- The command bar's artwork moves with the command bar. Minimising it slid the buttons off the bottom of the screen and left the metal they sit on painted over the battlefield; the same painting stood still through the slide the bar makes when a match opens. It travels with the bar and goes with it.+- Widescreen resolutions are back in the options menu, and the list works during a match. It was greyed out the moment a game started, because changing it rebuilt the menus and then pushed the main menu over whatever you were playing. It rebuilds the menus for later and leaves you on the battlefield with the command bar back up.+- Changing the resolution during a match no longer takes the game down. Two things were behind it. The old command bar's windows were handed back while the menu system still had them on its list, so the next thing that painted a button read whatever had since been written over it. And the bar itself was thrown away and built from scratch, which handed out fresh copies of every build button while your factories, your repair crews and the promotion screen went on pointing at the old ones. The bar's windows are rebuilt now and the bar keeps everything that is not a window.+- One command bar, not three. Changing the resolution during a match rebuilt the bar and left the old one behind, still drawn and still taking clicks at the size of the screen it was built for - and the confirmation box you answer afterwards rebuilds it a second time, so two mode changes in a row put three command bars on top of each other across the bottom of the battlefield. The code that was meant to throw the old one away asked the window system for a window called "ControlBar.wnd", and the bar's window is called "ControlBar.wnd:ControlBarParent", so it never found anything to throw away and never had.+- Your money is still your money after a resolution change. The command bar is rebuilt at the new size and its readout comes back holding the placeholder its layout ships with, three dollar signs, and the game only writes a number into it when the amount changes - so until you next sold, spent or collected something, that is what the box said.+- The menus you already had open are rebuilt at the new size too. A panel is stretched to the screen once, when it is built, so everything on screen when the mode changed - the in-game menu, the diplomacy panel, the chat line, the replay controls - carried on wearing the shape of the screen that had gone: drawn a proportion of a screen away from where it belongs, and on a smaller screen partly off the edge. The in-game menu is the one that mattered. It pauses the match and takes input off you until you press Return, and pressing Return is impossible when the button is no longer on the monitor.+- The command bar stays on the bottom edge of the screen. Minimising it and bringing it back lifted a few pieces that had never gone down in the first place, and every rebuild of the layout lifted them a little further, so over a long match the bar climbed off its own strip and the build tooltip, which is placed against it, ended up above the top of the screen. Each piece is now put back by exactly the amount it was moved by.+- The other half of that had the money readout, the general's tabs and the column of small buttons stranded a couple of hundred pixels above the bar, floating over the battlefield with the bar itself still sitting where it belongs. The bar takes a fifth of a second to slide back up when you un-minimise it, and anything that redrew the panel artwork during that fifth of a second measured every one of those pieces against a bar that had not arrived yet, then wrote the wrong answer down as if it were the right one. Switching general, changing faction colours and a resolution change all redraw it, so in a long match it happened sooner or later. The bar is put where it belongs before any of that is measured. Over six thousand frames of a match that minimises and rebuilds the bar every second, the top edge of everything it owns now reads the same number every single time.+- Tooltips stay on the screen. A tooltip is drawn to the right of the pointer, and near the right or bottom edge it jumps to the other side to make room, which was all the original code did about edges - the man who wrote it left a note saying so. Nothing then checked where it had jumped to. A wide one, and the game will wrap a tooltip to the full width of the screen when the text asks for it, jumped clean off the left edge with the first half of the sentence outside the monitor; a long narrow one hovered near the top went off the top. Both are put back on the screen now, and the pointer sits over the corner of the box rather than the words going where nobody can read them.+- The rank screen is one painting instead of a stretched one. It is sized from that painting at the same scale as everything else and centred on the screen, rather than multiplied out separately across and down from the corner it was authored in - which on a widescreen monitor made it a third too wide and pushed it off centre.- Borderless fullscreen: start with `-borderless` and the game fills the screen at your desktop resolution with no frame and no display mode change, so alt-tab is instant, nothing on the desktop gets shuffled around behind it, and a second monitor stays usable. Screen-edge scrolling works there, the way it does in fullscreen. The loading picture still opens as its own small window with your desktop around it, and the game only takes the screen once it has something to draw.-- Fullscreen, borderless and windowed are one saved setting now, so borderless no longer means adding a switch to your shortcut every time. `WindowMode` in `Options.ini` takes 0, 1 or 2 in that order; a switch on the command line still wins for that one run.+- Fullscreen, borderless and windowed are one saved setting now, so borderless no longer means adding a switch to your shortcut every time. `WindowMode` in `Options.ini` takes 0, 1 or 2 in that order; a switch on the command line still wins for that one run. Picking a different one applies when you press Accept instead of the next time you start the game: the window loses or gains its frame and the display device is rebuilt on the spot. Borderless takes your desktop resolution and nothing else, so while it is selected the resolution list greys out and the other two modes hand it straight back.- Antialiasing is a saved setting as well: `MSAA` in `Options.ini`, 0 for off through 4 for sixteen samples. `-msaa 4` still works and still wins for that run. Whatever your card will not give is stepped down instead of refused, so asking for six samples gets you four rather than nothing.+- Texture filtering is yours to set. `TextureFilter` in `Options.ini` takes 0 for bilinear, 1 for+ trilinear and 2 for anisotropic, and `Anisotropy` takes the sample count, 0 meaning whatever your+ card offers. The default is anisotropic at the card's maximum: retail shipped bilinear with point+ mip selection, which was a 2003 fill-rate budget and is why distant ground shimmered.- Picking High detail gives you high resolution textures. The setting was ignored: the resolution came from a machine benchmark that answers 'low' on anything modern, so there was no way to ask for better.- The main menu plays its battle again instead of showing one still picture. The game asks Windows how much memory the machine has and compares the answer against a 256MB minimum, and on a machine with more than 4GB installed that answer arrived as minus one - so the better the machine, the more certain the game was that it did not meet the 2003 minimum. It switched off the animated menu, forced textures down and, at the preset detail levels, took the trees out. It reads the real figure now.+- A setting you typed into `Options.ini` by hand survives opening the options screen. A value the+ matching slider could not reach was thrown away rather than clamped, and the slider then sat on+ its minimum - which is what got written back when you pressed Accept. Whatever the slider cannot+ show now reads as the nearest end of its track instead of the bottom of it.- The Default button in the options menu no longer throws away your resolution. It reset the display along with everything else, dropping you to 800x600 with no undo.- Text does not vanish at large sizes. Any font over 100 points simply failed to load, which on a 4K screen is a missing line of interface.- - Zoom further out, with the whole map drawn instead of black corners.+ - Zoom further out, with the whole map drawn instead of black corners. The ceiling is twice what it was again, which is the difference between watching your own half of the map and watching both.- The zoom-out ceiling is the same for everyone; no setting buys you a wider view.- The wheel covers that whole range in about six notches instead of thirty-eight.- Zoom toward the cursor works; the spot under your pointer stays there.diff --cc GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex f3b27bb8e,1d3201c28..ee4992ef7--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@@ -356,15 -354,8 +355,14 @@@ publicBool m_snapCameraRotateTo45; ///< quantize the camera heading to 45 degrees when a middle-drag rotate endsBool m_gridBuildPlacement; ///< quantize structure placement to the pathfinder's build gridBool m_nudgeBuildPlacement; ///< slide a blocked structure to the nearest spot it does fit+ Int m_moneyPerMinute; ///< income every player gets once a minute regardless of supply lines; 0 = off+ Real m_buildPlacementOpacity; ///< how solid the structure riding the cursor is drawn, 0..1+ Bool m_buildPlacementShadows; ///< whether that structure casts a shadow while it rides the cursor- Bool m_middleMousePans; ///< middle-button drag pans the camera instead of rotating itBool m_zoomToCursor; ///< the mouse wheel zooms toward whatever the cursor is over- Bool m_rightMouseScroll; ///< holding the right button drags the camera; off frees it for alternate mouse mode+ Bool m_formationDrag; ///< dragging the right button spreads the selection along the line drawn+ Int m_menuTransitionSpeed; ///< percent of the authored speed the menus slide and fade at; 100 = as drawn+ Int m_textureFilterMode; ///< 0 bilinear, 1 trilinear, 2 anisotropic+ Int m_anisotropyLevel; ///< samples anisotropic filtering may take; 0 = whatever the card offersBool m_showHudOverlay; ///< draw the fps / elapsed time / income line in the cornerBool m_showPlacementRangeRing; ///< while placing a structure, ring its weapon rangeBool m_workersReturnToSupply; ///< a worker that finishes a build job goes back to the dock it leftdiff --cc GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex 86fd653c6,aa31d4f36..7e05b7837--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@@ -195,12 -192,8 +195,11 @@@ GlobalData* GlobalData::m_theOriginal{ "SnapCameraRotateTo45", INI::parseBool, NULL, offsetof( GlobalData, m_snapCameraRotateTo45 ) },{ "GridBuildPlacement", INI::parseBool, NULL, offsetof( GlobalData, m_gridBuildPlacement ) },{ "NudgeBuildPlacement", INI::parseBool, NULL, offsetof( GlobalData, m_nudgeBuildPlacement ) },+ { "MoneyPerMinute", INI::parseInt, NULL, offsetof( GlobalData, m_moneyPerMinute ) },+ { "BuildPlacementOpacity", INI::parseReal, NULL, offsetof( GlobalData, m_buildPlacementOpacity ) },+ { "BuildPlacementShadows", INI::parseBool, NULL, offsetof( GlobalData, m_buildPlacementShadows ) },- { "MiddleMousePans", INI::parseBool, NULL, offsetof( GlobalData, m_middleMousePans ) },{ "ZoomToCursor", INI::parseBool, NULL, offsetof( GlobalData, m_zoomToCursor ) },- { "RightMouseScroll", INI::parseBool, NULL, offsetof( GlobalData, m_rightMouseScroll ) },+ { "FormationDrag", INI::parseBool, NULL, offsetof( GlobalData, m_formationDrag ) },{ "ShowHudOverlay", INI::parseBool, NULL, offsetof( GlobalData, m_showHudOverlay ) },{ "ShowPlacementRangeRing", INI::parseBool, NULL, offsetof( GlobalData, m_showPlacementRangeRing ) },{ "WorkersReturnToSupply", INI::parseBool, NULL, offsetof( GlobalData, m_workersReturnToSupply ) },@@@ -1089,13 -1050,9 +1088,12 @@@ GlobalData::GlobalData(//m_edgeScrollInWindowedMode = TRUE;m_snapCameraRotateTo45 = TRUE;- // middle-drag stays a rotate by default (it snaps to 45 degrees on release); pan is opt-in- m_middleMousePans = FALSE;m_zoomToCursor = TRUE;- m_rightMouseScroll = TRUE;+ // the right button no longer scrolls, so a right-drag is free to mean something+ m_formationDrag = TRUE;+ m_menuTransitionSpeed = 100;+ m_textureFilterMode = 2; // anisotropic; retail shipped bilinear on a 2003 fill-rate budget+ m_anisotropyLevel = 0; // whatever the card offers, capped at 16 in _Init_Filtersm_snapBuildPlacementTo45 = TRUE;m_gridBuildPlacement = TRUE;diff --cc GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cppindex 3289eef2f,df6f23c19..80962e0a7--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp@@@ -43,12 -42,10 +43,13 @@@OPTION_BOOL_ACCESSORS( m_edgeScrollInWindowedMode )OPTION_BOOL_ACCESSORS( m_snapCameraRotateTo45 )- OPTION_BOOL_ACCESSORS( m_middleMousePans )OPTION_BOOL_ACCESSORS( m_zoomToCursor )- OPTION_BOOL_ACCESSORS( m_rightMouseScroll )+ OPTION_BOOL_ACCESSORS( m_formationDrag )+ OPTION_INT_ACCESSORS( m_bloomIntensity )+ OPTION_INT_ACCESSORS( m_bloomThreshold )+OPTION_INT_ACCESSORS( m_menuTransitionSpeed )+OPTION_INT_ACCESSORS( m_textureFilterMode )+OPTION_INT_ACCESSORS( m_anisotropyLevel )OPTION_INT_ACCESSORS( m_windowMode )OPTION_INT_ACCESSORS( m_msaaLevel )OPTION_INT_ACCESSORS( m_healthBarMode )@@@ -175,34 -110,13 +174,34 @@@ const OptionDef TheOptionCatalog[]OPTION_BOOL, APPLY_LIVE, 0, 1,get_m_zoomToCursor, set_m_zoomToCursor },- // Alternate mouse mode moves commands onto the left button and selection onto the right, and- // then the right button is doing two jobs at once - every command drag also drags the camera.- // Turning this off leaves the middle button and the screen edge to scroll with.- { "RightMouseScroll", "", "",+ // A right drag over the ground spreads the selection along the line drawn instead of sending+ // everyone to one point. On by default - the right button stopped scrolling, so the drag was+ // free - and here for anyone who would rather a slipped click did nothing at all.+ { "FormationDrag", "", "",OPTION_BOOL, APPLY_LIVE, 0, 1,- get_m_rightMouseScroll, set_m_rightMouseScroll },+ get_m_formationDrag, set_m_formationDrag },+ // Percent of the speed the menu slides and fades were authored at. 100 is what the artists+ // drew; higher gets you through the shell faster, and nothing about a menu animation is worth+ // waiting for on the four hundredth launch.+ { "MenuTransitionSpeed", "", "",+ OPTION_INT, APPLY_LIVE, 25, 400,+ get_m_menuTransitionSpeed, set_m_menuTransitionSpeed },++ // 0 bilinear, 1 trilinear, 2 anisotropic. Retail shipped bilinear with point mip selection,+ // which is a 2003 fill-rate budget and is why distant ground used to shimmer; 2 is the default+ // here. The filter table is built when the device is made, so this needs a device reset.+ { "TextureFilter", "", "",+ OPTION_INT, APPLY_DEVICE_RESET, 0, 2,+ get_m_textureFilterMode, set_m_textureFilterMode },++ // Samples anisotropic filtering may take. 0 means whatever the card offers, capped at 16, and+ // asking for more than the card has still gets you the card's answer. Only read when the filter+ // above is anisotropic.+ { "Anisotropy", "", "",+ OPTION_INT, APPLY_DEVICE_RESET, 0, 16,+ get_m_anisotropyLevel, set_m_anisotropyLevel },+// Eight rows used to sit here: grid and nudge build placement, snap-to-45 building rotation, the// placement range ring, workers returning to supply, detailed build tooltips, the HUD overlay// and replay archiving. Every one of them is now on for everybody, decided in GlobalData'sdiff --cc GeneralsMD/Code/Tests/test_gameengine.cppindex 208f2a64f,a70911da5..cbf432980--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@@ -9101,1149 -8395,3 +9188,1150 @@@ TEST(a_tab_control_with_no_size_or_too_CHECK_EQ( GadgetTabControl_tabAtOffset( 100 * (NUM_TAB_PANES - 1), 100, 20 ), NUM_TAB_PANES - 1 );CHECK_EQ( GadgetTabControl_tabAtOffset( 100 * NUM_TAB_PANES, 100, 20 ), -1 );}++//----------------------------------------------------------------------------------------------------------+// The flow model's three charges.+//+// Each of them is a small piece of integer arithmetic that runs a few million times a frame and+// that nothing else in the game can be used to check. What matters about all three is the same+// thing: open ground is free, the charge is bounded, and the bound is a stated multiple of a step.+// A version that gets the bound wrong does not look wrong - it looks like the pathfinder got slow.+//----------------------------------------------------------------------------------------------------------++/** Twelve cells from anything, a body pays nothing for the ground it is on. This is the case that+ covers most of most maps, and a charge here would be a tax on every route in the game. */+TEST(open_ground_costs_a_route_nothing)+{+ const Int need = PF_CLEARANCE_ORTHO*1 + PF_CLEARANCE_ORTHO/2; // a one-cell body+ CHECK_EQ( Pathfinder_wallHugCost( 10, PF_CLEARANCE_MAX, need ), 0 );+ CHECK_EQ( Pathfinder_wallHugCost( 14, PF_CLEARANCE_MAX, need ), 0 );++ // and nothing is charged at or past the edge of the band. Just inside it the charge is real+ // but rounds away against a ten-unit step, which is the intent: the band tapers to nothing+ // rather than stepping off a cliff, so a route is not pulled about by its outer edge.+ CHECK_EQ( Pathfinder_wallHugCost( 10, need + PF_CLEARANCE_SOFT, need ), 0 );+ CHECK_EQ( Pathfinder_wallHugCost( 10, need + PF_CLEARANCE_SOFT - 1, need ), 0 );+ CHECK( Pathfinder_wallHugCost( 10, need + PF_CLEARANCE_SOFT/2, need ) > 0 );+}++/** A cell exactly as tight as the body costs PF_WALLHUG_NUM/DEN of a step and never more, however+ far into the terrain the cell is. Unbounded is what sends the search round the whole map. */+TEST(wall_hugging_is_capped_at_its_stated_multiple)+{+ const Int need = PF_CLEARANCE_ORTHO*2 + PF_CLEARANCE_ORTHO/2; // a two-cell body+ const Int peak = (10 * PF_WALLHUG_NUM) / PF_WALLHUG_DEN;+ CHECK_EQ( Pathfinder_wallHugCost( 10, need, need ), peak );+ CHECK_EQ( Pathfinder_wallHugCost( 10, 0, need ), peak ); // inside a wall: no worse+ CHECK_EQ( Pathfinder_wallHugCost( 10, need - 99, need ), peak ); // and negative slack does not wrap++ // a diagonal step is charged in proportion to itself+ CHECK_EQ( Pathfinder_wallHugCost( 14, need, need ), (14 * PF_WALLHUG_NUM) / PF_WALLHUG_DEN );+}++/** Quadratic, not linear: half way into the band costs about a quarter of the peak. A linear+ falloff was the first version of this and it taxed half the map at a third of a step. */+TEST(wall_hugging_falls_off_as_the_square_of_the_room_left)+{+ const Int need = 5;+ const Int peak = Pathfinder_wallHugCost( 100, need, need );+ const Int half = Pathfinder_wallHugCost( 100, need + PF_CLEARANCE_SOFT/2, need );+ CHECK( half * 3 < peak ); // a quarter-ish, comfortably under a third+ CHECK( half > 0 );+}++/** Traffic prices a queue, and it is capped for the same reason wall-hugging is: the heuristic+ cannot see any of it, so every cost it cannot see is paid in cells expanded. */+TEST(traffic_is_free_when_empty_and_capped_when_full)+{+ CHECK_EQ( Pathfinder_trafficCost( 10, 0 ), 0 );+ CHECK_EQ( Pathfinder_trafficCost( 10, -1 ), 0 );+ const Int peak = (10 * PF_TRAFFIC_NUM) / PF_TRAFFIC_DEN;+ CHECK_EQ( Pathfinder_trafficCost( 10, PF_TRAFFIC_FULL ), peak );+ CHECK_EQ( Pathfinder_trafficCost( 10, PF_TRAFFIC_MAX ), peak ); // saturated, not overflowing+ CHECK( Pathfinder_trafficCost( 10, PF_TRAFFIC_FULL/2 ) < peak );+ CHECK( Pathfinder_trafficCost( 10, PF_TRAFFIC_FULL/2 ) > 0 );+}++/** A claim spills into the buckets either side of its own at half strength, so weights arrive in+ halves. One half of one unit is not a crossing and must cost nothing at all - otherwise every+ cell within a bucket of anybody's plan is charged, which is most of a battlefield. */+TEST(half_a_unit_wanting_a_cell_is_not_a_crossing)+{+ CHECK_EQ( Pathfinder_crossingCost( 10, 0 ), 0 );+ CHECK_EQ( Pathfinder_crossingCost( 10, 1 ), 0 ); // the spill from a neighbouring bucket alone+ CHECK( Pathfinder_crossingCost( 10, 2 ) > 0 ); // one whole unit, at the moment we get there+}++/** And the crossing charge saturates: four units wanting one cell at one moment is as bad as a+ crossing gets, and a fifth must not make the route look impossible. */+TEST(a_crossing_charge_saturates_rather_than_growing)+{+ const Int peak = (10 * PF_CROSSING_NUM * PF_CLAIM_UNITS_MAX) / PF_CROSSING_DEN;+ CHECK_EQ( Pathfinder_crossingCost( 10, 2*PF_CLAIM_UNITS_MAX ), peak );+ CHECK_EQ( Pathfinder_crossingCost( 10, 2*PF_CLAIM_UNITS_MAX + 40 ), peak );+ CHECK_EQ( Pathfinder_crossingCost( 10, 0xFFFF ), peak );+}++/** The three charges together bound what the flow model can add to one step. This is the number+ that decides whether the search still steers or fans out, so it is pinned here rather than left+ to be rediscovered from a slow frame. */+TEST(the_whole_flow_charge_for_one_step_is_bounded)+{+ const Int base = 10;+ const Int worst = Pathfinder_wallHugCost( base, 0, 5 ) ++ Pathfinder_trafficCost( base, PF_TRAFFIC_MAX ) ++ Pathfinder_crossingCost( base, 0xFFFF );+ CHECK( worst <= 8 * base ); // 7.6 of a step: 1.6 wall-hug, 4 traffic, 2 crossing+ CHECK( worst >= 3 * base ); // and it is not so small that none of it does anything+}++/* Lanes. The route is a band and each unit rides somewhere across it; these two functions are the+ whole of that arithmetic, and every degenerate case below is one the map really produces - a+ doorway with no width at all, a unit that has already been shoved outside its own band, a body+ wider than the room measured for it. */++TEST(half_is_the_route_itself_however_lopsided_the_room_beside_it_is)+{+ /* The two sides of the band are scaled separately and meet at the centre line. The first+ version ran one scale from wall to wall, so half of a lopsided band was the middle of the+ free ground and a unit holding no particular lane slid sideways whenever the terrain was+ uneven - a mistake that grew with the probe and was worth 10% of the time spent blocked. */+ CHECK_NEAR( Pathfinder_laneFraction( 0.0f, 20.0f, 20.0f ), 0.5f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneOffset( 0.5f, 20.0f, 20.0f ), 0.0f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneOffset( 0.5f, 30.0f, 10.0f ), 0.0f, 0.0001f );+ // five feet left of the route, in a band with thirty feet of room on that side+ CHECK_NEAR( Pathfinder_laneFraction( 5.0f, 30.0f, 10.0f ), 0.5833f, 0.0001f );+ // the same five feet on the narrow side is a much bigger share of it+ CHECK_NEAR( Pathfinder_laneFraction( -5.0f, 30.0f, 10.0f ), 0.25f, 0.0001f );+}++TEST(a_lane_is_never_the_wall_itself)+{+ // a unit standing well outside its own band still gets a lane inside it+ CHECK_NEAR( Pathfinder_laneFraction( 500.0f, 20.0f, 20.0f ), 0.95f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneFraction( -500.0f, 20.0f, 20.0f ), 0.05f, 0.0001f );+ // and the offset that lane means keeps it off both edges+ CHECK( Pathfinder_laneOffset( 0.95f, 20.0f, 20.0f ) < 20.0f );+ CHECK( Pathfinder_laneOffset( 0.05f, 20.0f, 20.0f ) > -20.0f );+}++TEST(a_band_with_no_width_puts_everybody_on_the_centre_line)+{+ // a doorway, or a body as wide as the room beside it: laneExtent returns zero on both sides+ CHECK_NEAR( Pathfinder_laneFraction( 0.0f, 0.0f, 0.0f ), 0.5f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneFraction( 40.0f, 0.0f, 0.0f ), 0.5f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneOffset( 0.5f, 0.0f, 0.0f ), 0.0f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneOffset( 0.95f, 0.0f, 0.0f ), 0.0f, 0.0001f );+}++TEST(a_lane_fraction_and_its_offset_are_the_same_measurement_backwards)+{+ // what seedLaneFraction reads off the map, computePointOnPath has to be able to steer back to.+ // Only over the interior: the outer 5% at each edge is clamped away on purpose and does not+ // survive the round trip, which is the point of clamping it.+ const Real left = 25.0f, right = 15.0f;+ for (Real lateral = -13.0f; lateral <= 22.0f; lateral += 1.0f)+ {+ Real u = Pathfinder_laneFraction( lateral, left, right );+ CHECK_NEAR( Pathfinder_laneOffset( u, left, right ), lateral, 0.0001f );+ }+}++TEST(only_the_side_with_room_on_it_widens_the_band)+{+ // a route running along a wall: no room right, plenty left. The lane has to end up left of+ // centre, which is the asymmetry the clearance map cannot see and the reason it is not used here.+ CHECK( Pathfinder_laneOffset( 0.9f, 40.0f, 0.0f ) > 0.0f );+ CHECK_NEAR( Pathfinder_laneOffset( 0.0f, 40.0f, 0.0f ), 0.0f, 0.0001f ); // hard right is the wall, which is the centre line+ // twenty feet into forty feet of room is halfway across that side of the band+ CHECK_NEAR( Pathfinder_laneFraction( 20.0f, 40.0f, 0.0f ), 0.75f, 0.0001f );+ // and a body pushed onto the wall side of a route with no room there stays on the route+ CHECK_NEAR( Pathfinder_laneOffset( Pathfinder_laneFraction( -20.0f, 40.0f, 0.0f ), 40.0f, 0.0f ),+ 0.0f, 0.0001f );+}++TEST(a_lane_handed_to_a_group_member_is_a_distance_not_a_share_of_the_group)+{+ // A group's lanes are spaced by the size of its bodies, so what gets handed down has to mean+ // feet. The reference is the widest band the probe can find, and the same offset therefore+ // means the same distance whether it came from a tight blob or a wide box.+ const Real ref = Pathfinder_laneReference();+ CHECK( ref > 100.0f ); // 16 cells of 10; a tank is about 24 wide, so this is several of them++ CHECK_NEAR( Pathfinder_groupLane( 0.0f ), 0.5f, 0.0001f );+ CHECK_NEAR( Pathfinder_groupLane( ref * 0.5f ), 0.75f, 0.0001f );+ CHECK_NEAR( Pathfinder_groupLane( ref * -0.5f ), 0.25f, 0.0001f );++ // the edges are the clamp, not the wall itself+ CHECK( Pathfinder_groupLane( ref * 4.0f ) < 1.0f );+ CHECK( Pathfinder_groupLane( ref * -4.0f ) > 0.0f );++ // order is preserved: whoever was left of somebody stays left of them+ CHECK( Pathfinder_groupLane( -30.0f ) < Pathfinder_groupLane( 10.0f ) );++ /* Two tanks a body apart have to come out at least a body apart on a full-width band, or the+ spacing the group did the arithmetic for is thrown away here. Taken back out through+ laneOffset at the widest band the probe reports, which is what the group measured against. */+ Real uLeft = Pathfinder_groupLane( 14.0f );+ Real uRight = Pathfinder_groupLane( -14.0f );+ Real apart = Pathfinder_laneOffset( uLeft, ref, ref ) - Pathfinder_laneOffset( uRight, ref, ref );+ CHECK_NEAR( apart, 28.0f, 0.01f );++ // and a narrow road squeezes all of it rather than dropping anybody: quarter band, quarter gap+ Real narrow = Pathfinder_laneOffset( uLeft, ref * 0.25f, ref * 0.25f )+ - Pathfinder_laneOffset( uRight, ref * 0.25f, ref * 0.25f );+ CHECK_NEAR( narrow, 7.0f, 0.01f );+}++TEST(the_band_is_shut_before_the_goal_not_at_it)+{+ const Real cell = PATHFIND_CELL_SIZE_F;+ const Real taper = cell * (Real)PF_LANE_TAPER_CELLS;+ const Real close = cell * (Real)PF_LANE_CLOSE_CELLS;+ CHECK( close < taper );++ // out on the route, nothing is given up+ CHECK_NEAR( Pathfinder_laneTaper( taper * 4.0f ), 1.0f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneTaper( taper ), 1.0f, 0.0001f );++ /* The whole point of the close distance: at the goal, and for the last few cells before it,+ the lane is gone completely. A ramp that only reached zero at the goal left a unit riding+ the edge of a wide band still yards off its own route when it stopped, and a group ordered+ onto one point arrived spread across it. */+ CHECK_NEAR( Pathfinder_laneTaper( close ), 0.0f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneTaper( 0.0f ), 0.0f, 0.0001f );+ CHECK_NEAR( Pathfinder_laneTaper( -5.0f ), 0.0f, 0.0001f );++ // straight line between the two, and never a step backwards+ CHECK_NEAR( Pathfinder_laneTaper( (taper + close) * 0.5f ), 0.5f, 0.0001f );+ Real last = 0.0f;+ for (Real r = 0.0f; r < taper * 1.5f; r += 2.0f)+ {+ Real f = Pathfinder_laneTaper( r );+ CHECK( f >= last - 0.0001f );+ CHECK( f >= 0.0f && f <= 1.0f );+ last = f;+ }+}++TEST(the_taper_is_long_enough_for_the_band_it_has_to_close)+{+ /* A unit riding the edge of the widest band the probe can find has to be able to get back to+ the centre line before the lane is switched off, or it arrives beside its own goal. The+ taper is that distance, so it has to be at least as long as the offset it is undoing -+ anything shorter is a unit told to move sideways faster than it drives forwards. */+ const Real taper = PATHFIND_CELL_SIZE_F * (Real)PF_LANE_TAPER_CELLS;+ CHECK( taper >= Pathfinder_laneReference() * 0.5f );+}++TEST(crowd_corridor_measures_distance_along_the_route_not_samples)+{+ /* The sample's own `along` is quantised to the sample step, so a steering point taken from it+ hops a whole cell forward every time the unit crosses a boundary. alongOf is the unquantised+ answer: it has to grow smoothly as the unit advances, and it has to ignore sideways offset. */+ Coord3D pts[ 5 ];+ for (Int k = 0; k < 5; k++)+ {+ pts[ k ].x = (Real)k * 10.0f;+ pts[ k ].y = 0.0f;+ pts[ k ].z = 0.0f;+ }++ CrowdCorridor corr;+ corr.buildForTest( pts, 5, 20.0f );+ CHECK_EQ( corr.count(), 5 );+ CHECK_NEAR( corr.length(), 40.0f, 0.001f );++ Coord3D p;+ p.y = 0.0f;+ p.z = 0.0f;++ Real last = -1.0f;+ for (Real x = 0.0f; x <= 40.0f; x += 1.0f)+ {+ p.x = x;+ const Real a = corr.alongOf( corr.nearest( p, 0 ), p );+ CHECK_NEAR( a, x, 0.001f );+ CHECK( a > last ); // no plateau, which is what a sample-quantised answer would give+ last = a;+ }++ // standing off the line does not move a unit forwards or backwards along it+ p.x = 15.0f;+ p.y = 12.0f;+ CHECK_NEAR( corr.alongOf( corr.nearest( p, 0 ), p ), 15.0f, 0.001f );+}++TEST(crowd_corridor_steering_point_slides_instead_of_hopping)+{+ /* The wobble on light chassis was this: point() lands on a sample, so the aim point jumped ten+ feet at a time and on a bend the direction handed to the locomotor stepped with it. pointAt+ has to be continuous - consecutive queries a foot apart give answers a foot apart - and it has+ to agree with point() exactly where a sample sits. */+ Coord3D pts[ 6 ];+ pts[ 0 ].x = 0.0f; pts[ 0 ].y = 0.0f;+ pts[ 1 ].x = 10.0f; pts[ 1 ].y = 0.0f;+ pts[ 2 ].x = 20.0f; pts[ 2 ].y = 0.0f;+ pts[ 3 ].x = 28.0f; pts[ 3 ].y = 6.0f;+ pts[ 4 ].x = 34.0f; pts[ 4 ].y = 14.0f;+ pts[ 5 ].x = 36.0f; pts[ 5 ].y = 24.0f;+ for (Int k = 0; k < 6; k++)+ pts[ k ].z = 0.0f;++ CrowdCorridor corr;+ corr.buildForTest( pts, 6, 15.0f );++ // on a sample, the two agree+ for (Int k = 0; k < corr.count(); k++)+ {+ Coord3D a, b;+ corr.point( k, 4.0f, &a );+ corr.pointAt( corr.at( k ).along, 4.0f, &b );+ CHECK_NEAR( a.x, b.x, 0.001f );+ CHECK_NEAR( a.y, b.y, 0.001f );+ }++ // and between them it slides: a tenth of a foot of route never moves the point a foot+ Coord3D prev;+ corr.pointAt( 0.0f, 4.0f, &prev );+ for (Real s = 0.1f; s <= corr.length(); s += 0.1f)+ {+ Coord3D now;+ corr.pointAt( s, 4.0f, &now );+ const Real dx = now.x - prev.x;+ const Real dy = now.y - prev.y;+ CHECK( dx * dx + dy * dy < 1.0f );+ prev = now;+ }++ // the width follows too, and a lane wider than the band is still cut to the band+ CHECK_NEAR( corr.clampLatAt( 12.5f, 4.0f ), 4.0f, 0.001f );+ CHECK_NEAR( corr.clampLatAt( 12.5f, 90.0f ), 15.0f, 0.001f );+ CHECK_NEAR( corr.clampLatAt( 12.5f, -90.0f ), -15.0f, 0.001f );++ // off the ends is clamped, not indexed out of the vector+ Coord3D ends;+ corr.pointAt( -50.0f, 0.0f, &ends );+ CHECK_NEAR( ends.x, pts[ 0 ].x, 0.001f );+ corr.pointAt( corr.length() + 50.0f, 0.0f, &ends );+ CHECK_NEAR( ends.x, pts[ 5 ].x, 0.001f );+}++TEST(crowd_corridor_has_no_band_on_a_bridge_or_at_its_approaches)+{+ /* A bridge deck is not road with room either side of it, and the ground beside a bridge is a+ riverbank. A lane held across either one drives the unit off the side, and a lane held on the+ approach arrives beside the abutment instead of at the entrance - which is a unit that never+ gets onto the bridge and a queue behind it that never gets anywhere. The band closes over the+ deck and for CROWD_BRIDGE_SEAL samples each side of it. */+ Coord3D pts[ 20 ];+ PathfindLayerEnum layers[ 20 ];+ for (Int k = 0; k < 20; k++)+ {+ pts[ k ].x = (Real)k * 10.0f;+ pts[ k ].y = 0.0f;+ pts[ k ].z = 0.0f;+ layers[ k ] = LAYER_GROUND;+ }+ layers[ 10 ] = (PathfindLayerEnum)2; // the deck: three samples of it, out over the water+ layers[ 11 ] = (PathfindLayerEnum)2;+ layers[ 12 ] = (PathfindLayerEnum)2;++ CrowdCorridor corr;+ corr.buildForTest( pts, 20, 15.0f, layers );+ CHECK_EQ( corr.count(), 20 );++ // open road, far from the bridge either side: the band is what it was built with+ CHECK_NEAR( corr.at( 0 ).left, 15.0f, 0.001f );+ CHECK_NEAR( corr.at( 5 ).right, 15.0f, 0.001f );+ CHECK_NEAR( corr.at( 19 ).left, 15.0f, 0.001f );++ corr.sealBridges();++ const Int sealLo = 10 - (Int)CROWD_BRIDGE_SEAL;+ const Int sealHi = 12 + (Int)CROWD_BRIDGE_SEAL;++ // the deck itself, and the sealed samples each side of it+ for (Int k = sealLo; k <= sealHi; k++)+ {+ CHECK_NEAR( corr.at( k ).left, 0.0f, 0.001f );+ CHECK_NEAR( corr.at( k ).right, 0.0f, 0.001f );+ CHECK_NEAR( corr.clampLat( k, 12.0f ), 0.0f, 0.001f );+ CHECK_NEAR( corr.clampLatAt( corr.at( k ).along, -12.0f ), 0.0f, 0.001f );+ }++ // and the road on either side of that stretch keeps its band+ CHECK_NEAR( corr.at( sealLo - 1 ).left, 15.0f, 0.001f );+ CHECK_NEAR( corr.at( sealHi + 1 ).right, 15.0f, 0.001f );+ CHECK_NEAR( corr.clampLat( sealLo - 1, 12.0f ), 12.0f, 0.001f );++ // a route with no bridge on it is untouched+ CrowdCorridor plain;+ plain.buildForTest( pts, 20, 15.0f );+ plain.sealBridges();+ for (Int k = 0; k < plain.count(); k++)+ CHECK_NEAR( plain.at( k ).left, 15.0f, 0.001f );+}++TEST(the_rescue_ladder_never_runs_out_of_rungs)+{+ /* The promise: a unit that wants to move and is not moving always has something tried on it, in+ order, and when the ladder runs out it starts again rather than going quiet. Written against+ the shape rather than the frame counts, so tuning the thresholds does not break the test and+ skipping a rung does. */++ // nothing at all while the unit is still getting somewhere+ CHECK_EQ( AIUpdate_stuckRung( 0, 0 ), 0 );+ CHECK_EQ( AIUpdate_stuckRung( 1, 0 ), 0 );++ // long enough, and the rungs come one at a time and in order+ CHECK_EQ( AIUpdate_stuckRung( 1000, 0 ), 1 );+ CHECK_EQ( AIUpdate_stuckRung( 1000, 1 ), 2 );+ CHECK_EQ( AIUpdate_stuckRung( 1000, 2 ), 3 );++ // past the last one it restarts, and only after a further wait+ CHECK_EQ( AIUpdate_stuckRung( 1000, 3 ), -1 );+ CHECK_EQ( AIUpdate_stuckRung( 0, 3 ), 0 );++ /* No rung is ever skipped and none is ever offered early: whatever the frame count, the answer+ is either nothing or exactly the next one up. */+ for (Int stage = 0; stage <= 3; stage++)+ {+ Int seen = 0;+ for (Int f = 0; f < 400; f++)+ {+ const Int rung = AIUpdate_stuckRung( f, stage );+ CHECK( rung == 0 || rung == stage + 1 || rung == -1 );+ if (rung != 0)+ ++seen;+ }+ // and the ladder always eventually offers something, at every stage including the last+ CHECK( seen > 0 );+ }+}++TEST(driving_a_long_way_and_gaining_nothing_is_not_the_same_as_being_slow)+{+ const Real body = 24.0f; // a tank++ // going somewhere: what it covered is what it gained+ CHECK( !AIUpdate_isDithering( 200.0f, 210.0f, body ) );+ CHECK( !AIUpdate_isDithering( 90.0f, 100.0f, body ) );++ // round a corner, so some of the travel is spent turning: still going somewhere+ CHECK( !AIUpdate_isDithering( 140.0f, 200.0f, body ) );++ // back and forth beside a building: eight body lengths covered, half a body gained+ CHECK( AIUpdate_isDithering( 12.0f, 200.0f, body ) );+ CHECK( AIUpdate_isDithering( 0.0f, 100.0f, body ) );++ /* Slow is not dithering and neither is stopped. A unit that crept twenty units in three+ seconds has gained everything it covered, and one that never moved has covered nothing: both+ belong to the other test, and catching them here is what makes a rule fire on every unit+ politely slowing down to park. */+ CHECK( !AIUpdate_isDithering( 20.0f, 20.0f, body ) );+ CHECK( !AIUpdate_isDithering( 0.0f, 0.0f, body ) );+ CHECK( !AIUpdate_isDithering( 1.0f, 30.0f, body ) ); // under two body lengths of travel++ // and the floor scales with the body, so infantry are not held to a tank's yardstick+ CHECK( AIUpdate_isDithering( 1.0f, 30.0f, 6.0f ) );+}++TEST(a_steering_point_is_clamped_by_the_pinch_it_has_to_drive_through)+{+ /* A straight road, wide at both ends and one body wide in the middle. Clamping the aim point+ against the ground at either end says nothing is wrong with riding 30 units off the centre+ line, and the straight line between those two points goes through whatever is making the+ middle narrow. That is a unit driving into the corner of a building on a route that went+ round it. */+ Coord3D pts[ 7 ];+ Real width[ 7 ];+ for (Int k = 0; k < 7; k++)+ {+ pts[ k ].x = (Real)k * 10.0f;+ pts[ k ].y = 0.0f;+ pts[ k ].z = 0.0f;+ width[ k ] = (k == 3) ? 4.0f : 40.0f; // one sample of narrow ground in the middle+ }++ CrowdCorridor corr;+ corr.buildForTest( pts, 7, 40.0f, NULL, width );+ CHECK( !corr.isEmpty() );++ // each end on its own allows the whole offset+ CHECK_NEAR( corr.clampLatAt( 0.0f, 30.0f ), 30.0f, 0.001f );+ CHECK_NEAR( corr.clampLatAt( 60.0f, 30.0f ), 30.0f, 0.001f );++ // asked about the stretch that contains the pinch, it gives the pinch+ CHECK_NEAR( corr.clampLatNarrowest( 0.0f, 60.0f, 30.0f ), 4.0f, 0.001f );+ CHECK_NEAR( corr.clampLatNarrowest( 0.0f, 60.0f, -30.0f ), -4.0f, 0.001f );++ // argument order does not matter, and a stretch past the pinch is not cut by it+ CHECK_NEAR( corr.clampLatNarrowest( 60.0f, 0.0f, 30.0f ), 4.0f, 0.001f );+ CHECK_NEAR( corr.clampLatNarrowest( 40.0f, 60.0f, 30.0f ), 30.0f, 0.001f );++ // and it never widens anything: whatever comes back fits everywhere the walk looked+ CHECK_NEAR( corr.clampLatNarrowest( 0.0f, 60.0f, 2.0f ), 2.0f, 0.001f );+}++TEST(a_group_is_never_more_than_five_lanes_wide)+{+ const Real body = 24.0f; // about a tank, which is what the spacing is measured from++ // the ground decides, up to the cap: two lanes of room is two lanes+ CHECK_EQ( Crowd_laneCount( 0.0f, body, 0 ), 1 );+ CHECK_EQ( Crowd_laneCount( body, body, 0 ), 2 );+ CHECK_EQ( Crowd_laneCount( body * 3.0f, body, 0 ), 4 );++ // and then it stops. Open country is not a reason to arrive twenty abreast+ CHECK_EQ( Crowd_laneCount( body * 4.0f, body, 0 ), 5 );+ CHECK_EQ( Crowd_laneCount( body * 40.0f, body, 0 ), 5 );+ CHECK_EQ( Crowd_laneCount( 100000.0f, body, 0 ), 5 );++ // never more lanes than there are bodies to put in them+ CHECK_EQ( Crowd_laneCount( body * 40.0f, body, 3 ), 3 );+ CHECK_EQ( Crowd_laneCount( body * 40.0f, body, 9 ), 5 );++ // degenerate inputs are one lane, not a division by zero or a negative count+ CHECK_EQ( Crowd_laneCount( body * 4.0f, 0.0f, 4 ), 1 );+ CHECK_EQ( Crowd_laneCount( -50.0f, body, 4 ), 1 );+}++TEST(a_turn_costs_what_the_hull_takes_to_swing_it)+{+ // chassis is the cost of one radian: a hull that drives 40 units while turning one radian+ CHECK_EQ( Pathfinder_turnCost( 1.0f, 40, 60 ), 40 );+ CHECK_EQ( Pathfinder_turnCost( 0.5f, 40, 60 ), 20 );++ // the caps bite, and they are the two different ones the search uses+ CHECK_EQ( Pathfinder_turnCost( 3.14159f, 40, 60 ), 60 );+ CHECK_EQ( Pathfinder_turnCost( 3.14159f, 40, 28 ), 28 );++ // a hull that turns on the spot pays nothing, and so does the switch being off+ CHECK_EQ( Pathfinder_turnCost( 3.14159f, 0, 60 ), 0 );+ CHECK_EQ( Pathfinder_turnCost( 0.0f, 40, 60 ), 0 );++ // never negative, whatever it is handed+ CHECK_EQ( Pathfinder_turnCost( -1.0f, 40, 60 ), 0 );+ CHECK( Pathfinder_turnCost( 2.0f, 3, 60 ) >= 0 );+}++TEST(crowd_brake_only_reads_closing_time)+{+ const Int frames = 8;+ const Real full = 2.0f;++ // nobody in front of us is gaining on us: no brake at any gap+ CHECK_NEAR( Crowd_brakeSpeed( full, full, 1.0f, frames ), full, 0.0001f );+ CHECK_NEAR( Crowd_brakeSpeed( full, full + 1.0f, 0.0f, frames ), full, 0.0001f );++ // closing, but the gap is more than eight frames of closing: still no brake. This is the+ // distance-braking bug the measurement caught - a unit ten units back was being slowed to a+ // third of its speed for traffic it was never going to reach+ CHECK_NEAR( Crowd_brakeSpeed( full, 1.0f, 20.0f, frames ), full, 0.0001f );++ // inside that, the answer closes the gap over the eight frames rather than this one+ CHECK_NEAR( Crowd_brakeSpeed( full, 1.0f, 4.0f, frames ), 1.5f, 0.0001f );++ // touching a stopped unit is a stop, and nothing ever comes back negative+ CHECK_NEAR( Crowd_brakeSpeed( full, 0.0f, 0.0f, frames ), 0.0f, 0.0001f );+ CHECK_NEAR( Crowd_brakeSpeed( full, 0.0f, -3.0f, frames ), 0.0f, 0.0001f );++ // and the cap is never a speed-up+ for (Real g = -2.0f; g < 30.0f; g += 0.5f)+ CHECK( Crowd_brakeSpeed( full, 0.5f, g, frames ) <= full + 0.0001f );++ // a zero window is the rule switched off, not a division by zero+ CHECK_NEAR( Crowd_brakeSpeed( full, 0.0f, 0.0f, 0 ), full, 0.0001f );+}++//-------------------------------------------------------------------------------------------------+// A shadow request is filled in field by field by whoever makes it, and the debris draw module+// never touched the name at all. The shadow manager reads that name the moment its first byte is+// not zero, so an uninitialised stack was being strlen'd and copied as a texture name.+//-------------------------------------------------------------------------------------------------+TEST(a_shadow_request_starts_with_no_texture_name)+{+ // Build the request on top of a scribbled buffer, default-initialised the way a local+ // variable is. Without a constructor on the struct that leaves the pattern in place -+ // which is the whole failure - so this check cannot pass by accident.+ char raw[ sizeof(Shadow::ShadowTypeInfo) ];+ memset( raw, 0x7F, sizeof(raw) );++ Shadow::ShadowTypeInfo *info = ::new ( (void *)raw ) Shadow::ShadowTypeInfo;++ CHECK_EQ( info->m_ShadowName[ 0 ], '\0' );+ CHECK_EQ( (Int)strlen( info->m_ShadowName ), 0 );+ CHECK_EQ( (Int)info->m_type, (Int)SHADOW_NONE );+ CHECK_NEAR( info->m_sizeX, 0.0f, 0.0001f );+ CHECK_NEAR( info->m_sizeY, 0.0f, 0.0001f );+ CHECK_NEAR( info->m_offsetX, 0.0f, 0.0001f );+ CHECK_NEAR( info->m_offsetY, 0.0f, 0.0001f );+ CHECK( !info->allowUpdates );+ CHECK( !info->allowWorldAlign );+}++//-------------------------------------------------------------------------------------------------+// MenuTransitionSpeed scales the rate the shell's slides and fades step at. The catalog clamps the+// setting, but the function is what the menus actually call and a zero reaching it would be a+// division by nothing, so it clamps again on its own.+//-------------------------------------------------------------------------------------------------+TEST(menu_transition_speed_scales_the_step_rate_and_never_reaches_zero)+{+ GlobalData *saved = TheWritableGlobalData;+ GlobalData *scratch = NEW GlobalData;+ TheWritableGlobalData = scratch;++ // the default is the rate the menus were drawn at, unchanged+ CHECK_EQ( scratch->m_menuTransitionSpeed, 100 );+ CHECK_NEAR( GameClient_menuAnimStepsPerSec(), UI_ANIM_STEPS_PER_SEC, 0.0001f );++ scratch->m_menuTransitionSpeed = 200;+ CHECK_NEAR( GameClient_menuAnimStepsPerSec(), UI_ANIM_STEPS_PER_SEC * 2.0f, 0.0001f );++ scratch->m_menuTransitionSpeed = 50;+ CHECK_NEAR( GameClient_menuAnimStepsPerSec(), UI_ANIM_STEPS_PER_SEC * 0.5f, 0.0001f );++ // out of range on either side lands on the range, and nothing ever comes back at or below zero+ scratch->m_menuTransitionSpeed = 0;+ CHECK_NEAR( GameClient_menuAnimStepsPerSec(), UI_ANIM_STEPS_PER_SEC * 0.25f, 0.0001f );++ scratch->m_menuTransitionSpeed = -1000;+ CHECK( GameClient_menuAnimStepsPerSec() > 0.0f );++ scratch->m_menuTransitionSpeed = 100000;+ CHECK_NEAR( GameClient_menuAnimStepsPerSec(), UI_ANIM_STEPS_PER_SEC * 4.0f, 0.0001f );++ TheWritableGlobalData = saved;+ delete scratch;+}++//-------------------------------------------------------------------------------------------------+// The structure riding the cursor is drawn at BuildPlacementOpacity and casts a shadow or not+// according to BuildPlacementShadows. Both defaults have to be what the game always did, or every+// player who never touches GameData.ini gets a different picture than they had.+//-------------------------------------------------------------------------------------------------+TEST(build_placement_preview_defaults_are_the_ones_the_game_always_used)+{+ GlobalData *scratch = NEW GlobalData;++ CHECK_NEAR( scratch->m_buildPlacementOpacity, PLACEMENT_SILHOUETTE_OPACITY, 0.0001f );+ CHECK( scratch->m_buildPlacementShadows );++ // and the income trickle is off unless somebody asks for it+ CHECK_EQ( scratch->m_moneyPerMinute, 0 );+- // the right button still scrolls unless somebody turns it off- CHECK( scratch->m_rightMouseScroll );++ // the right button stopped scrolling when the mouse went onto one scheme, which is what freed++ // a right drag to draw a formation line; that is on unless somebody turns it off++ CHECK( scratch->m_formationDrag );++ delete scratch;+}++//-------------------------------------------------------------------------------------------------+// A map name with a non-ASCII byte in it reaches isalnum as a negative number, which is undefined+// and is what the CRT asserted on while building the map cache. Every byte over 127 has to encode,+// and the round trip has to bring it back.+//-------------------------------------------------------------------------------------------------+TEST(quoted_printable_survives_bytes_over_127)+{+ // every high byte, one after another - this is what an accented map name looks like+ char highBytes[ 130 ];+ Int n = 0;+ for( Int b = 128; b <= 255; ++b )+ highBytes[ n++ ] = (char)b;+ highBytes[ n ] = '\0';++ AsciiString original( highBytes );+ AsciiString encoded = AsciiStringToQuotedPrintable( original );++ // nothing high survives into the encoded form: it is all MAGIC_CHAR plus two hex digits+ for( Int i = 0; i < encoded.getLength(); ++i )+ CHECK( (unsigned char)encoded.getCharAt( i ) < 128 );++ CHECK_EQ( encoded.getLength(), original.getLength() * 3 );++ // and it comes back+ AsciiString decoded = QuotedPrintableToAsciiString( encoded );+ CHECK_STR( decoded.str(), original.str() );++ // a plain name is left alone, which is what makes the encoding readable in a cache file+ CHECK_STR( AsciiStringToQuotedPrintable( AsciiString( "Alpine" ) ).str(), "Alpine" );+}++/* Peace time is a truce between people. A computer player does not honour one - it stands still+ and then plays the same game - so a lobby with a bot in it has no peace time whatever the host+ picked. The rule lives in GameInfo::getPeaceTime(), which is what the options string on the+ wire, the lobby's combo box and GameLogic all read, so this is the one place it can be checked.+ The host's pick is masked, not cleared: take the bot back out and it is still there. */+TEST(peace_time_is_off_while_a_computer_player_is_in_the_lobby)+{+ GlobalData *saved = TheWritableGlobalData;+ TheWritableGlobalData = NEW GlobalData;++ SkirmishGameInfo game;+ game.init(); // leaves every slot closed; clearSlotList() would name them, and naming a+ // closed slot asks TheGameText, which the harness does not stand up++ UnicodeString name;+ name.translate( AsciiString( "Player" ) );++ GameSlot human;+ human.setState( SLOT_PLAYER, name );+ game.setSlot( 0, human );++ GameSlot other;+ other.setState( SLOT_PLAYER, name );+ game.setSlot( 1, other );++ game.setPeaceTime( 10 );+ CHECK( !game.hasAIPlayers() );+ CHECK_EQ( game.getPeaceTime(), 10 );++ // a bot in any seat turns it off, at every rung of the ladder+ static const SlotState rungs[] = { SLOT_EASY_AI, SLOT_MED_AI, SLOT_BRUTAL_AI };+ for( Int i = 0; i < 3; ++i )+ {+ GameSlot bot;+ bot.setState( rungs[ i ] );+ game.setSlot( 1, bot );+ CHECK( game.hasAIPlayers() );+ CHECK_EQ( game.getPeaceTime(), 0 );+ }++ // the pick was masked, not thrown away+ game.setSlot( 1, other );+ CHECK( !game.hasAIPlayers() );+ CHECK_EQ( game.getPeaceTime(), 10 );++ // and the setter still refuses a value the wire could not have come by honestly+ game.setPeaceTime( -5 );+ CHECK_EQ( game.getPeaceTime(), 0 );+ game.setPeaceTime( 9999 );+ CHECK_EQ( game.getPeaceTime(), 60 );++ delete TheWritableGlobalData;+ TheWritableGlobalData = saved;+}++/* nextToken used to return false on a spent source without touching the caller's token, so the+ token still held the *previous* one. Every loop written as "walk until the token comes back+ empty" then never ended. */+TEST(asciistring_nextToken_empties_the_token_when_the_source_runs_out)+{+ AsciiString path( "one\\two" );+ AsciiString tok;++ CHECK( path.nextToken( &tok, "\\/" ) );+ CHECK_STR( tok.str(), "one" );+ CHECK( path.nextToken( &tok, "\\/" ) );+ CHECK_STR( tok.str(), "two" );++ CHECK( !path.nextToken( &tok, "\\/" ) );+ CHECK_EQ( tok.getLength(), 0 );++ // and the same answer when the source was empty to begin with+ AsciiString none;+ AsciiString held( "stale" );+ CHECK( !none.nextToken( &held, "\\/" ) );+ CHECK_EQ( held.getLength(), 0 );++ // a token that is the source itself is still refused, and left as it was+ AsciiString self( "a\\b" );+ CHECK( !self.nextToken( &self, "\\/" ) );+ CHECK_STR( self.str(), "a\\b" );+}++/* -map "Maps\Twilight Flame\Twilight Flame.map" loses its quotes to WinMain's tokenizer and+ reaches this function as "Maps\Twilight". With no .map to stop on it grew a string one token+ at a time until AsciiString's 32767-byte ceiling threw ERROR_OUT_OF_MEMORY out of+ parseCommandLine, GameEngine::init caught it and ran on to its tail, and the first frame+ faulted on a NULL TheGameLogic - reported as a crash in update(), with no main menu. */+TEST(map_path_conversion_terminates_on_a_path_with_no_map_file)+{+ AsciiString longForm( "Maps\\Twilight Flame\\Twilight Flame.map" );+ ConvertShortMapPathToLongMapPath( longForm );+ CHECK_STR( longForm.str(), "Maps\\Twilight Flame\\Twilight Flame.map" );++ AsciiString shortForm( "Maps\\Alpine Assault.map" );+ ConvertShortMapPathToLongMapPath( shortForm );+ CHECK_STR( shortForm.str(), "Maps\\Alpine Assault\\Alpine Assault.map" );++ AsciiString truncated( "Maps\\Twilight" );+ ConvertShortMapPathToLongMapPath( truncated );+ CHECK_STR( truncated.str(), "Maps\\Twilight" );++ AsciiString noSeparator( "Twilight Flame.map" );+ ConvertShortMapPathToLongMapPath( noSeparator );+ CHECK_STR( noSeparator.str(), "Twilight Flame.map" );++ AsciiString trailing( "Maps\\Twilight\\" );+ ConvertShortMapPathToLongMapPath( trailing );+ CHECK_STR( trailing.str(), "Maps\\Twilight\\" );+}++/* ControlBar.cpp: layoutPanels used to lift every window in a minimised panel by that panel's+ slide, including the ones applyPanelSlide never moved. Each rebuild of the layout lifted them+ again, placeInPanel then recorded the lifted position as the authored one, and the bar walked+ off the top of its own strip - taking the build tooltip, which is placed against+ BackgroundMarker, off the screen with it. */+extern Int ControlBar_slideToUndo( Int slideAppliedToWindow, Int panelSlideOffsetNow );++TEST(the_bar_only_lifts_a_window_the_slide_actually_pushed_down)+{+ // a window the slide moved comes back by exactly what it was moved by+ CHECK_EQ( ControlBar_slideToUndo( 48, 48 ), 48 );++ //+ // and one it skipped is left alone, however far its panel says it went. A plate marker and+ // anything in a panel that was minimised immediately are both in this case.+ //+ CHECK_EQ( ControlBar_slideToUndo( 0, 48 ), 0 );+ CHECK_EQ( ControlBar_slideToUndo( 0, 121 ), 0 );++ // a window that went down before the panel's slide changed underneath it still comes back whole+ CHECK_EQ( ControlBar_slideToUndo( 30, 0 ), 30 );+ CHECK_EQ( ControlBar_slideToUndo( 30, 90 ), 30 );++ // the round trip is a round trip: pushed down by n, lifted by n, net zero+ static const Int pushes[] = { 0, 1, 17, 48, 121 };+ for( Int i = 0; i < 5; i++ )+ {+ const Int y = 400;+ const Int down = y + pushes[ i ];+ CHECK_EQ( down - ControlBar_slideToUndo( pushes[ i ], 121 ), y );+ }+}++/* ControlBar.cpp: a resolution change throws every window away and builds it again, but the bar+ itself has to survive - a production queue, a hunt update and the academy all hold a+ const CommandButton * that would be left pointing at a freed one. So the window half of init+ is its own pair of functions, and the teardown half runs twice on the way out: once from the+ rebuild, once from the destructor. */+TEST(the_bars_windows_can_be_torn_down_twice_without_taking_the_bar_with_them)+{+ ControlBar bar;++ bar.shutdownWindows();+ CHECK( !bar.getShowBuildTooltipLayout() );++ // again, on a bar that is already holding nothing - which is what the destructor does+ bar.shutdownWindows();+ CHECK( !bar.getShowBuildTooltipLayout() );++ // the command buttons are not window state and are not touched by any of it+ CHECK( bar.getCommandButtons() == NULL );+ CHECK( bar.findCommandButton( AsciiString( "NoSuchCommandButton" ) ) == NULL );+}++/* ControlBarScheme.cpp: the scheme places the money readout, the two general's tabs and the toolbar+ column by reading their parent's screen position and subtracting it, and layoutPanels then runs+ over the answer. Asking for the panels back is not the same as having them back - the slide is+ wall-clocked over a fifth of a second - so a scheme rebuilt while the bar was on its way down+ read a parent that was still travelling, and every child it placed came out that far too high.+ layoutPanels lifted the parent back afterwards and dragged them up again, placeInPanel recorded+ the lifted position as the authored one, and it stuck. Measured in a match: 524 with the panels+ sent home first, 294 without. clearPanelSlide is the "first". */+TEST(sending_the_panels_home_is_not_the_same_as_them_being_home)+{+ ControlBar bar;+ const Int left = ControlBar::CB_PANEL_LEFT;+ const Int right = ControlBar::CB_PANEL_RIGHT;+ const Int count = ControlBar::CB_PANEL_COUNT;++ // away, and all the way away this instant+ bar.showPanel( left, FALSE, TRUE );+ CHECK_NEAR( bar.getPanelSlideFraction( left ), 1.0f, 0.0001f );+ CHECK( bar.isPanelHidden( left ) );++ //+ // what switchControlBarStage( CONTROL_BAR_STAGE_DEFAULT ) does: it asks. The panel is still down+ // there, and anything reading a window's position on this frame reads it down there.+ //+ bar.showPanel( left, TRUE );+ CHECK_NEAR( bar.getPanelSlideFraction( left ), 1.0f, 0.0001f );++ // clearPanelSlide does not ask, it declares+ bar.clearPanelSlide();+ CHECK_NEAR( bar.getPanelSlideFraction( left ), 0.0f, 0.0001f );+ CHECK( !bar.isPanelHidden( left ) );++ // and it speaks for all three, not just the one that was asked about+ Int p;+ for( p = 0; p < count; p++ )+ bar.showPanel( p, FALSE, TRUE );+ bar.clearPanelSlide();+ for( p = 0; p < count; p++ )+ {+ CHECK_NEAR( bar.getPanelSlideFraction( p ), 0.0f, 0.0001f );+ CHECK( !bar.isPanelHidden( p ) );+ }++ // a panel that never left is left alone+ bar.clearPanelSlide();+ CHECK_NEAR( bar.getPanelSlideFraction( right ), 0.0f, 0.0001f );+}++/* Mouse.cpp: the tooltip box was placed by two flips and nothing else, under EA's own note that+ the tips still had to be kept somewhere readable. A flip is the right answer at the right and+ bottom edges and no answer at the left and top, and both are reachable: setCursorTooltip will+ wrap a tip to the full width of the display when a caller asks for it, and a caller that asks+ for less than ten pixels gets a 120-wide column that runs long text hundreds of pixels down. */+TEST(a_tooltip_is_put_back_on_the_screen_after_it_is_flipped)+{+ const Int screenW = 1024, screenH = 768;+ Int x, y;++ // the ordinary case: to the right of the pointer, level with it, untouched+ Mouse::placeTooltip( 400, 300, 286, 102, 0, 0, screenW, screenH, &x, &y );+ CHECK_EQ( x, 420 );+ CHECK_EQ( y, 300 );++ // right edge: the flip is what puts it on the roomier side, and it stays+ Mouse::placeTooltip( 1000, 300, 286, 20, 0, 0, screenW, screenH, &x, &y );+ CHECK_EQ( x, 714 );+ CHECK( x >= 0 && x + 286 <= screenW );++ // bottom edge, same+ Mouse::placeTooltip( 400, 760, 286, 40, 0, 0, screenW, screenH, &x, &y );+ CHECK_EQ( y, 720 );+ CHECK( y >= 0 && y + 40 <= screenH );++ //+ // A screen-wide tip with the pointer past the middle: too wide to fit on the right, and the+ // flip alone lands it at -60. This is the one a player sees with the left half of the text+ // missing.+ //+ Mouse::placeTooltip( 640, 300, 1000, 30, 0, 0, screenW, screenH, &x, &y );+ CHECK_EQ( x, 0 );++ // a narrow column of long text with the pointer high up: the flip alone puts it above the top+ Mouse::placeTooltip( 400, 300, 120, 500, 0, 0, screenW, screenH, &x, &y );+ CHECK_EQ( y, 0 );++ //+ // Nothing lands outside the screen, whatever is asked for. A box larger than the screen is+ // pinned to the top left corner, which loses its far edge and keeps its first words.+ //+ static const Int sizes[] = { 20, 120, 286, 700, 1000, 1200 };+ Int i, j, px, py;+ for( i = 0; i < 6; i++ )+ for( j = 0; j < 6; j++ )+ for( px = 0; px <= screenW; px += 128 )+ for( py = 0; py <= screenH; py += 128 )+ {+ Mouse::placeTooltip( px, py, sizes[ i ], sizes[ j ], 0, 0, screenW, screenH, &x, &y );+ CHECK( x >= 0 );+ CHECK( y >= 0 );+ if( sizes[ i ] + 4 <= screenW )+ CHECK( x + sizes[ i ] + 4 <= screenW );+ if( sizes[ j ] + 4 <= screenH )+ CHECK( y + sizes[ j ] + 4 <= screenH );+ }++ // the limits are read, not assumed: a windowed device with an origin away from zero holds too+ Mouse::placeTooltip( 200, 200, 400, 300, 100, 150, 500, 450, &x, &y );+ CHECK( x >= 100 );+ CHECK( y >= 150 );+}++/* The lobby's settings page is 119 layout units tall and the superweapon box sits in its second+ row, so the three entries it drops reach past the bottom of the panel they are drawn on. Hit+ testing walks the parents first and a panel does not contain them, so before this the rows drew,+ highlighted nothing and could not be picked - the dropdown looked open and was dead. An open+ box is asked before its panel is; a closed one is not asked at all, or every click anywhere near+ the last box the player touched would go to it. */+extern Bool OpenWindowOwnsPoint( Bool isOpen, Int originX, Int originY, Int width, Int height,+ Int x, Int y );++TEST(an_open_dropdown_owns_the_rows_that_hang_past_its_panel)+{+ /* the starting cash box at 1280x720: 29 pixels tall closed, 133 with its five entries down, on+ a panel whose bottom edge is at 598. The last two rows are past that edge. */+ const Int boxX = 748, boxY = 466, boxWidth = 288;+ const Int boxHeightClosed = 29, boxHeightOpen = 133;+ const Int panelBottom = 598;+ const Int rowInsidePanel = 520, rowPastPanel = 585, rowWellPastPanel = 595;++ CHECK( boxY + boxHeightClosed < panelBottom );+ CHECK( boxY + boxHeightOpen > panelBottom ); // or there is nothing here to get wrong++ CHECK( OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightOpen, 900, rowInsidePanel ) );+ CHECK( OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightOpen, 900, rowPastPanel ) );+ CHECK( OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightOpen, 900, rowWellPastPanel ) );++ // the closed box keeps its own row and nothing under it+ CHECK( OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightClosed, 900, 480 ) );+ CHECK( !OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightClosed, 900, rowPastPanel ) );++ // a box that is not open owns nothing, wherever the pointer is+ CHECK( !OpenWindowOwnsPoint( FALSE, boxX, boxY, boxWidth, boxHeightOpen, 900, rowPastPanel ) );+ CHECK( !OpenWindowOwnsPoint( FALSE, boxX, boxY, boxWidth, boxHeightOpen, 900, 480 ) );++ // and it never claims a click beside itself - PLAY GAME sits under the same rows+ CHECK( !OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightOpen, 300, rowPastPanel ) );+ CHECK( !OpenWindowOwnsPoint( TRUE, boxX, boxY, boxWidth, boxHeightOpen, 900, 660 ) );+}++/* The superweapon rule is a mode, and what a mode leaves you depends on who you are playing. The+ USA Superweapon General fields three superweapons and pays for them in everything else, so Limit+ leaves him four of each where it leaves everybody one, and No leaves him one where it bars+ everybody else outright. Player::canBuildMoreOfType asks SuperweaponBuildCap and nothing else+ decides it, so this is the whole rule. EA shipped the same field as a Yes/No checkbox where Yes+ meant one of each: that reads back as No Superweapons, not as some truthy value. */+TEST(the_superweapon_rule_is_a_mode_with_one_exception)+{+ const AsciiString superweaponGeneral( "FactionAmericaSuperWeaponGeneral" );+ const AsciiString laserGeneral( "FactionAmericaLaserGeneral" );+ const AsciiString gla( "FactionGLA" );++ // no rule at all: 0 is what canBuildMoreOfType reads as no cap+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_ALLOW, gla ), (Int)SUPERWEAPON_CAP_UNLIMITED );+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_ALLOW, superweaponGeneral ), (Int)SUPERWEAPON_CAP_UNLIMITED );++ // one each, four for the general the whole exception exists for+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_LIMIT, gla ), 1 );+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_LIMIT, laserGeneral ), 1 );+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_LIMIT, superweaponGeneral ), 4 );++ // banned, and he keeps one+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_NONE, gla ), (Int)SUPERWEAPON_CAP_BANNED );+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_NONE, laserGeneral ), (Int)SUPERWEAPON_CAP_BANNED );+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_NONE, superweaponGeneral ), 1 );++ // a player with no template at all - the civilian seat - is nobody's exception+ CHECK_EQ( SuperweaponBuildCap( SUPERWEAPONS_NONE, AsciiString::TheEmptyString ), (Int)SUPERWEAPON_CAP_BANNED );++ // and a mode from a build that knows one this one does not leaves the game unrestricted+ CHECK_EQ( SuperweaponBuildCap( 99, superweaponGeneral ), (Int)SUPERWEAPON_CAP_UNLIMITED );+ CHECK_EQ( SuperweaponBuildCap( 99, gla ), (Int)SUPERWEAPON_CAP_UNLIMITED );++ // the checkbox that used to be there, read by the dropdown that replaced it+ CHECK_EQ( SuperweaponRestrictionFromPreference( AsciiString( "Yes" ) ), (Int)SUPERWEAPONS_NONE );+ CHECK_EQ( SuperweaponRestrictionFromPreference( AsciiString( "no" ) ), (Int)SUPERWEAPONS_ALLOW );++ // and what this build writes, which is the mode+ CHECK_EQ( SuperweaponRestrictionFromPreference( AsciiString( "0" ) ), (Int)SUPERWEAPONS_ALLOW );+ CHECK_EQ( SuperweaponRestrictionFromPreference( AsciiString( "1" ) ), (Int)SUPERWEAPONS_LIMIT );+ CHECK_EQ( SuperweaponRestrictionFromPreference( AsciiString( "2" ) ), (Int)SUPERWEAPONS_NONE );++ // a line nobody wrote on purpose leaves the game unrestricted rather than at one of each+ CHECK_EQ( SuperweaponRestrictionFromPreference( AsciiString( "" ) ), (Int)SUPERWEAPONS_ALLOW );+ CHECK_EQ( SuperweaponRestrictionFromPreference( AsciiString( "maybe" ) ), (Int)SUPERWEAPONS_ALLOW );++ // the lobby carries the host's pick untouched - it is the wire's business, not the setter's+ GlobalData *saved = TheWritableGlobalData;+ TheWritableGlobalData = NEW GlobalData;++ SkirmishGameInfo game;+ game.init();+ CHECK_EQ( (Int)game.getSuperweaponRestriction(), (Int)SUPERWEAPONS_ALLOW );+ game.setSuperweaponRestriction( SUPERWEAPONS_LIMIT );+ CHECK_EQ( (Int)game.getSuperweaponRestriction(), (Int)SUPERWEAPONS_LIMIT );+ game.setSuperweaponRestriction( SUPERWEAPONS_NONE );+ CHECK_EQ( (Int)game.getSuperweaponRestriction(), (Int)SUPERWEAPONS_NONE );++ delete TheWritableGlobalData;+ TheWritableGlobalData = saved;+}++/* -scenario's line parser.+ *+ * A scenario file that gets half-read still plays a match and still writes a frame time table, so+ * the run produces numbers that answer a different question than the one asked. Every way a line+ * can be wrong therefore has to come back named. atoi is the specific trap the parser exists to+ * avoid: it reads "banana" as 0, 0 is a real frame number, and a typo in one field would put the+ * whole file on the first frame.+ */+TEST(scenario_parses_a_spawn_line)+{+ ScenarioAction action;++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 spawn 2 GLAInfantryAngryMobNexus 8 1200 900", &action ),+ (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.frame, 0 );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SPAWN );+ CHECK_EQ( action.slot, 2 );+ CHECK_STR( action.selector.str(), "GLAInfantryAngryMobNexus" );+ CHECK_EQ( action.count, 8 );+ CHECK_NEAR( action.at.x, 1200.0f, 0.01f );+ CHECK_NEAR( action.at.y, 900.0f, 0.01f );++ // spacing is optional, and the default has to be a real gap rather than zero+ CHECK( action.spacing > 0.0f );++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "30 spawn 1 AmericaVehicleHumvee 4 100 200 55", &action ),+ (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.frame, 30 );+ CHECK_NEAR( action.spacing, 55.0f, 0.01f );+}++TEST(scenario_parses_the_order_lines)+{+ ScenarioAction action;++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "120 move 2 * 800 600", &action ), (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_MOVE );+ CHECK_STR( action.selector.str(), "*" );+ CHECK_NEAR( action.at.x, 800.0f, 0.01f );+ CHECK_NEAR( action.at.y, 600.0f, 0.01f );++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "240 attackmove 2 GLAInfantryAngryMobNexus 2400 1500", &action ),+ (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_ATTACKMOVE );+ CHECK_NEAR( action.at.x, 2400.0f, 0.01f );++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "300 attack 2 * 1 AmericaCommandCenter", &action ),+ (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_ATTACK );+ CHECK_EQ( action.targetSlot, 1 );+ CHECK_STR( action.targetSelector.str(), "AmericaCommandCenter" );++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "900 stop 2 *", &action ), (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_STOP );+}++TEST(scenario_ignores_comments_and_blank_lines)+{+ ScenarioAction action;++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "", &action ), (Int)SCENARIO_PARSE_BLANK );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( " \t ", &action ), (Int)SCENARIO_PARSE_BLANK );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "# eight mobs on the ridge", &action ), (Int)SCENARIO_PARSE_BLANK );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( " # indented comment", &action ), (Int)SCENARIO_PARSE_BLANK );++ // a text-mode read still leaves the carriage return on a CRLF file+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "900 stop 2 *\r", &action ), (Int)SCENARIO_PARSE_OK );++ // and a comment after a real action does not eat the action+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "900 stop 2 * # everybody halt", &action ),+ (Int)SCENARIO_PARSE_OK );+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_STOP );+ CHECK_STR( action.selector.str(), "*" );+}++TEST(scenario_refuses_a_line_it_cannot_read)+{+ ScenarioAction action;++ // the atoi trap: none of these may come back as frame 0+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "banana spawn 2 X 1 0 0", &action ), (Int)SCENARIO_PARSE_BAD_FRAME );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "12x spawn 2 X 1 0 0", &action ), (Int)SCENARIO_PARSE_BAD_FRAME );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "-5 stop 2 *", &action ), (Int)SCENARIO_PARSE_BAD_FRAME );++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 teleport 2 *", &action ), (Int)SCENARIO_PARSE_BAD_ACTION );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 stop two *", &action ), (Int)SCENARIO_PARSE_BAD_SLOT );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 attack 2 * nobody Thing", &action ), (Int)SCENARIO_PARSE_BAD_SLOT );++ // a count of zero spawns nothing, which is a typo rather than an instruction+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 spawn 2 X 0 100 100", &action ), (Int)SCENARIO_PARSE_BAD_COUNT );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 spawn 2 X lots 100 100", &action ), (Int)SCENARIO_PARSE_BAD_COUNT );++ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 stop", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 move 2 *", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 move 2 * 100", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "0 spawn 2 X 4 100", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );++ // and every refusal has something to say for itself in the log+ CHECK_STR( ScenarioDrill_parseResultName( SCENARIO_PARSE_BAD_FRAME ), "frame is not a whole number" );+}diff --cc GeneralsMD/Code/Tools/optionsmenu_layout.pyindex 214e5add7,be47be0ec..c161e59f6--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py@@@ -77,12 -72,16 +77,16 @@@ DROP = ["ButtonKeyboardOptions"# positioned by hand, so it gets a name on the way through.NAME_THE_UNNAMED = [("GUI:AntiAliasing", "AntiAliasingLabel")]+ # Controls that are in the shipped file and are not wanted at all. CheckAlternateMouse chose+ # between the classic mouse and the alternate one; there is one mouse now, so the choice is gone.+ DELETE = ["CheckAlternateMouse"]+# The new controls, cloned from a control of the same kind that is already in the file.# (page, template, name, text key, left, top, width, height)- CHECK, LABEL, COMBO, SLIDER = "CheckAlternateMouse", "DetailLabel", "ComboBoxDetail", "SliderGamma"+ CHECK, LABEL, COMBO, SLIDER = "Retaliation", "DetailLabel", "ComboBoxDetail", "SliderGamma"CONTROLS = [- # Display: the two device settings and the two bloom knobs, in the space the audio panel left+ # Display: the two device settings and the two bloom levels, in the space the audio panel left("PageDisplay", LABEL, "LabelWindowMode", "GUI:WindowMode", 400, 104, 230, 24),("PageDisplay", COMBO, "ComboBoxWindowMode", None, 400, 128, 200, 24),("PageDisplay", LABEL, "LabelMSAA", "GUI:MSAA", 400, 160, 230, 24),@@@ -231,7 -235,8 +242,8 @@@ def build(layout)node.name = _named(name)drop_by_text(layout.root, HEADINGS)+ drop_by_name(layout.root, DELETE)- for name in RULES:+ for name in RULES + DROP:detach(old, name)pages = {}