ScummVM API documentation
colony.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Based on the original sources
21 * https://github.com/Croquetx/thecolony
22 * Copyright (C) 1988, David A. Smith
23 *
24 * Distributed under Apache Version 2.0 License
25 *
26 */
27
28#ifndef COLONY_H
29#define COLONY_H
30
31#include "common/array.h"
32#include "common/random.h"
33#include "common/rect.h"
34#include "common/rendermode.h"
35#include "engines/advancedDetector.h"
36#include "engines/engine.h"
37#include "graphics/pixelformat.h"
38#include "graphics/surface.h"
39
40namespace Common {
41struct Event;
42class MacResManager;
43class SeekableReadStreamEndian;
44}
45
46namespace Graphics {
47class Cursor;
48class Font;
49class FrameLimiter;
50class MacMenu;
51struct MacMenuItem;
52class MacWindowManager;
53class ManagedSurface;
54}
55
56namespace Colony {
57
58class Renderer;
59class Sound;
60
61// Engine-wide color packing. The OpenGL renderer's useColor() treats values
62// with the high byte == 0xFF as direct ARGB (R=bits 16-23, G=8-15, B=0-7) and
63// values with high byte 0 as palette indices. The PixelFormat below matches
64// that direct-ARGB layout exactly so we can build colors via ARGBToColor.
65inline Graphics::PixelFormat renderColorFormat() {
66 return Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
67}
68
69inline uint32 packRGB(byte r, byte g, byte b) {
70 return renderColorFormat().ARGBToColor(255, r, g, b);
71}
72
73// Mac native QuickDraw stores RGB as 16-bit-per-channel; we collapse to 8 bits.
74inline uint32 packMacColor(const uint16 rgb[3]) {
75 return packRGB((byte)(rgb[0] >> 8), (byte)(rgb[1] >> 8), (byte)(rgb[2] >> 8));
76}
77
78enum ColonyAction {
79 kActionNone,
80 kActionMoveForward,
81 kActionMoveBackward,
82 kActionStrafeLeft,
83 kActionStrafeRight,
84 kActionRotateLeft,
85 kActionRotateRight,
86 kActionLookLeft,
87 kActionLookRight,
88 kActionLookBehind,
89 kActionFaceForward,
90 kActionToggleMouselook,
91 kActionToggleDashboard,
92 kActionToggleWireframe,
93 kActionToggleFullscreen,
94 kActionEscape,
95 kActionFire,
96 kActionAutomapZoomIn,
97 kActionAutomapZoomOut
98};
99
100enum GameMode {
101 kModeColony = 2,
102 kModeBattle = 1
103};
104
105enum WallFeatureType {
106 kWallFeatureNone = 0,
107 kWallFeatureDoor = 2,
108 kWallFeatureWindow = 3,
109 kWallFeatureShelves = 4,
110 kWallFeatureUpStairs = 5,
111 kWallFeatureDnStairs = 6,
112 kWallFeatureChar = 7,
113 kWallFeatureGlyph = 8,
114 kWallFeatureElevator = 9,
115 kWallFeatureTunnel = 10,
116 kWallFeatureAirlock = 11,
117 kWallFeatureColor = 12
118};
119
120enum MapDirection {
121 kDirNorth = 0,
122 kDirEast = 1,
123 kDirWest = 2,
124 kDirSouth = 3,
125 kDirCenter = 4
126};
127
128enum RobotType {
129 kRobEye = 1,
130 kRobPyramid = 2,
131 kRobCube = 3,
132 kRobUPyramid = 4,
133 kRobFEye = 5,
134 kRobFPyramid = 6,
135 kRobFCube = 7,
136 kRobFUPyramid = 8,
137 kRobSEye = 9,
138 kRobSPyramid = 10,
139 kRobSCube = 11,
140 kRobSUPyramid = 12,
141 kRobMEye = 13,
142 kRobMPyramid = 14,
143 kRobMCube = 15,
144 kRobMUPyramid = 16,
145 kRobQueen = 17,
146 kRobDrone = 18,
147 kRobSoldier = 19,
148 kRobSnoop = 20
149};
150
151// 3D bounding radius (max XY extent from center) for each robot type.
152// Used by clampToWalls to keep robot geometry from intersecting wall polygons.
153// The original 2D wireframe renderer drew walls over robots (painter's algorithm);
154// in OpenGL 3D both exist as real geometry, so padding is needed.
155// Capped at 112 so the robot keeps at least 32 units of movement freedom
156// within a 256-unit cell (256 - 2*112 = 32).
157inline int robotWallPad(int robotType) {
158 const int kMaxPad = 112;
159 switch (robotType) {
160 case kRobEye: return 66;
161 case kRobPyramid:
162 case kRobUPyramid: return 85;
163 case kRobCube: return 100;
164 case kRobQueen: return kMaxPad; // actual 120
165 case kRobDrone:
166 case kRobSoldier: return kMaxPad; // actual 130
167 case kRobSnoop: return kMaxPad; // actual 180
168 default: return 40; // eggs and other small types
169 }
170}
171
172enum ObjectType {
173 kObjDesk = 21,
174 kObjPlant = 22,
175 kObjCChair = 23,
176 kObjBed = 24,
177 kObjTable = 25,
178 kObjCouch = 26,
179 kObjChair = 27,
180 kObjTV = 28,
181 kObjScreen = 29,
182 kObjConsole = 30,
183 kObjPowerSuit = 31,
184 kObjForkLift = 32,
185 kObjCryo = 33,
186 kObjBox1 = 34,
187 kObjBox2 = 35,
188 kObjTeleport = 36,
189 kObjDrawer = 37,
190 kObjTub = 38,
191 kObjSink = 39,
192 kObjToilet = 40,
193 kObjBench = 41,
194 kObjPToilet = 43,
195 kObjCBench = 44,
196 kObjProjector = 45,
197 kObjReactor = 46,
198 kObjFWall = 48,
199 kObjCWall = 49,
200 kObjBBed = 42
201};
202
203enum ObjColor {
204 kColorClear = 0,
205 kColorBlack = 1,
206 kColorBlue = 2,
207 kColorGreen = 3,
208 kColorCyan = 4,
209 kColorRed = 5,
210 kColorMagenta = 6,
211 kColorBrown = 7,
212 kColorWhite = 8,
213 kColorDkGray = 9,
214 kColorLtBlue = 10,
215 kColorLtGreen = 11,
216 kColorLtCyan = 12,
217 kColorLtRed = 13,
218 kColorLtMagenta = 14,
219 kColorYellow = 15,
220 kColorIntWhite = 16,
221 kColorBath = 17,
222 kColorWater = 18,
223 kColorSilver = 19,
224 kColorReactor = 20,
225 kColorBlanket = 21,
226 kColorSheet = 22,
227 kColorBed = 23,
228 kColorBox = 24,
229 kColorBench = 25,
230 kColorChair = 26,
231 kColorChairBase = 27,
232 kColorCouch = 28,
233 kColorConsole = 29,
234 kColorTV = 30,
235 kColorTVScreen = 31,
236 kColorDrawer = 32,
237 kColorDesk = 37,
238 kColorDeskTop = 38,
239 kColorDeskChair = 39,
240 kColorMac = 40,
241 kColorMacScreen = 41,
242 kColorCryo = 33,
243 kColorCryoGlass = 34,
244 kColorCryoBase = 35,
245 kColorForklift = 49,
246 kColorTread1 = 50,
247 kColorTread2 = 51,
248 kColorPot = 52,
249 kColorPlant = 53,
250 kColorPower = 54,
251 kColorPBase = 55,
252 kColorPSource = 56,
253 kColorTable = 61,
254 kColorTableBase = 62,
255 kColorPStand = 63,
256 kColorPLens = 64,
257 kColorProjector = 65,
258 kColorTele = 66,
259 kColorTeleDoor = 67,
260 kColorWall = 77,
261 kColorRainbow1 = 80,
262 kColorRainbow2 = 81,
263 kColorRainbow3 = 82,
264 kColorRainbow4 = 83,
265 // Robot colors
266 kColorCube = 36,
267 kColorDrone = 42,
268 kColorClaw1 = 43,
269 kColorClaw2 = 44,
270 kColorEyes = 45,
271 kColorEye = 46,
272 kColorIris = 47,
273 kColorPupil = 48,
274 kColorPyramid = 57,
275 kColorQueen = 58,
276 kColorTopSnoop = 59,
277 kColorBottomSnoop = 60,
278 kColorUPyramid = 68,
279 kColorShadow = 74,
280 kColorLtGray = 75,
281 kColorGray = 76,
282 // Animated reactor/power suit colors (Mac: c_hcore1..c_hcore4, c_ccore, c_color0..c_color3)
283 kColorHCore1 = 100,
284 kColorHCore2 = 101,
285 kColorHCore3 = 102,
286 kColorHCore4 = 103,
287 kColorCCore = 104,
288 // Semantic robot colors that need platform- or level-specific mapping.
289 kColorEyeball = 105,
290 kColorEyeIris = 106,
291 kColorMiniEyeIris = 107,
292 kColorDroneEye = 108,
293 kColorSoldierBody = 109,
294 kColorSoldierEye = 110,
295 kColorQueenBody = 111,
296 kColorQueenEye = 112,
297 kColorQueenWingRed = 113,
298 // The monolith is cBLACK in the DOS table but has its own Mac entry
299 // (c_monolith), so it cannot share the generic kColorBlack mapping.
300 kColorMonolith = 114
301};
302
303enum {
304 kColonyDebugMove = 1 << 0,
305 kColonyDebugRender = 1 << 1,
306 kColonyDebugAnimation = 1 << 2,
307 kColonyDebugMap = 1 << 3,
308 kColonyDebugSound = 1 << 4,
309 kColonyDebugUI = 1 << 5,
310 kColonyDebugCombat = 1 << 6,
311};
312
313// Mac menu action IDs (matching original Mac Colony menu structure)
314enum MenuAction {
315 kMenuActionAbout = 1,
316 kMenuActionNew,
317 kMenuActionOpen,
318 kMenuActionSave,
319 kMenuActionSaveAs,
320 kMenuActionQuit,
321 kMenuActionSound,
322 kMenuActionCrosshair,
323 kMenuActionPolyFill,
324 kMenuActionCursorShoot
325};
326
327// Menu bar order, matching inits.c:43-48 (myMenus[0..3]).
328enum MenuIndex {
329 kMenuApple = 0,
330 kMenuFile,
331 kMenuEdit,
332 kMenuOptions
333};
334
335// Object and robot angles keep the original's convention, where the sine table's
336// own 45-degree phase supplied the last 32 steps; player angles are already
337// world-absolute. Convert whenever one is used as the other.
338uint8 objWorldAng(uint8 objectAng);
339uint8 objAngFromPlayer(uint8 playerAng);
340
341const int kBaseObject = 20;
342const int kMeNum = 101;
343
344struct Locate {
345 uint8 ang = 0;
346 uint8 look = 0;
347 int8 lookY = 0;
348 int lookx = 0;
349 int delta = 0;
350 int xloc = 0;
351 int yloc = 0;
352 int xindex = 0;
353 int yindex = 0;
354 int xmx = 0, xmn = 0;
355 int zmx = 0, zmn = 0;
356 int32 power[3] = {};
357 int type = 0;
358 int dx = 0, dy = 0;
359 int dist = 0;
360 int wallPad = 0; // 3D bounding radius for wall clamping (0 = use default kWallPad)
361};
362
363struct Thing {
364 int type = 0;
365 int visible = 0;
366 int alive = 0;
367 Common::Rect clip;
368 int count = 0;
369 Locate where;
370 int opcode = 0;
371 int counter = 0;
372 int time = 0;
373 int grow = 0;
374 // void (*make)(); // To be implemented as virtual functions or member function pointers
375 // void (*think)();
376};
377
378// PATCH.C: Tracks object relocations across levels (forklift carry/drop).
380 struct { uint8 level, xindex, yindex; } from;
381 struct { uint8 level, xindex, yindex; int xloc, yloc; uint8 ang; } to;
382 uint8 type;
383 uint8 mapdata[5];
384};
385
386// Temporary location reference for carrying objects.
387struct PassPatch {
388 uint8 level, xindex, yindex;
389 int xloc, yloc;
390 uint8 ang;
391};
392
393// Per-level persistence: door and airlock states, and visit flags.
394struct LevelData {
395 uint8 visit;
396 uint8 queen;
397 uint8 object[kBaseObject + 1];
398 uint8 count; // airlock open count (termination check)
399 uint8 size; // number of saved wall changes (max 10)
400 uint8 location[10][3]; // [x, y, direction] of each changed wall
401 uint8 data[10][5]; // saved wall feature bytes (5 per location)
402 uint8 openDoors[31][31]; // direction bits for open ordinary doors
403};
404
405struct MacColor {
406 uint16 fg[3];
407 uint16 bg[3];
408 uint16 pattern;
409};
410
411struct Image {
412 int16 width;
413 int16 height;
414 int16 align;
415 int16 rowBytes;
416 int8 bits;
417 int8 planes;
418 byte *data;
419
420 Image() : width(0), height(0), align(0), rowBytes(0), bits(0), planes(0), data(nullptr) {}
421 ~Image() { delete[] data; }
422};
423
424struct Sprite {
425 Image *fg;
426 Image *mask;
427 Common::Rect clip;
428 Common::Rect locate;
429 bool used;
430
431 // Per-sprite render cache: bit-pattern + mask are baked into an
432 // alpha-keyed RGBA surface and uploaded once via drawSurface, instead
433 // of issuing setPixel per pixel each frame. Invalidated when the
434 // (fgColor, bgColor) pair changes (level/palette transition).
435 Graphics::Surface *baked;
436 uint64 bakedKey;
437
438 Sprite() : fg(nullptr), mask(nullptr), used(false), baked(nullptr), bakedKey(0) {}
439 ~Sprite() {
440 delete fg;
441 delete mask;
442 if (baked) {
443 baked->free();
444 delete baked;
445 }
446 }
447};
448
450 struct SubObject {
451 int16 spritenum;
452 int16 xloc, yloc;
453 };
455 Common::Rect bounds;
456 bool visible;
457 int16 current;
458 int16 xloc, yloc;
459 int16 acurrent;
460 int16 axloc, ayloc;
461 uint8 type;
462 uint8 frozen;
463 uint8 locked;
464 int16 link;
465 int16 key;
466 int16 lock;
467 bool onoff;
468
469 ComplexSprite() : visible(false), current(0), xloc(0), yloc(0), acurrent(0), axloc(0), ayloc(0), type(0), frozen(0), locked(0), link(0), key(0), lock(0), onoff(true) {}
470};
471
472class Debugger;
473
474class ColonyEngine : public Engine {
475 friend class Debugger;
476public:
477 ColonyEngine(OSystem *syst, const ADGameDescription *gd);
478 virtual ~ColonyEngine();
479
480 Common::Error run() override;
481 bool hasFeature(EngineFeature f) const override;
482 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
483 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
484 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
486 void pauseEngineIntern(bool pause) override;
487 void applyGameSettings() override;
488 Common::Platform getPlatform() const { return _gameDescription->platform; }
489 bool isSoundEnabled() const { return _soundOn; }
490 const Graphics::Surface *getSavedScreen() const { return _savedScreen; }
491 bool isMacRenderMode() const { return _renderMode == Common::kRenderMacintosh || _renderMode == Common::kRenderMacintoshBW; }
492 bool isMacColorMode() const { return _renderMode == Common::kRenderMacintosh && _hasMacColors; }
493
494 void initTrig();
495 void loadMacColors();
496 void loadMap(int mnum);
497 void startNewGame();
498 void corridor();
499 void quadrant();
500 bool hasInteractiveWallFeature(int cx, int cy, int dir) const;
501 void clampToWalls(Locate *p);
502 void clampToDiagonalWalls(Locate *p);
503 int checkwallMoveTo(int xnew, int ynew, int xind2, int yind2, Locate *pobject, uint8 trailCode);
504 int checkwallTryFeature(int xnew, int ynew, int xind2, int yind2, Locate *pobject, int dir);
505 int checkwall(int xnew, int ynew, Locate *pobject);
506 void clearPlayerCellMarker();
507 void setPlayerCellMarker();
508 bool playerIntersectsObjectFootprint(const Thing &obj, int xloc, int yloc) const;
509 bool playerStartsInsideObject(int rnum) const;
510 void cCommand(int xnew, int ynew, bool allowInteraction);
511 bool scrollInfo(const Graphics::Font *macFont = nullptr);
512 bool checkSkipRequested();
513 bool checkClickRequested();
514 bool waitForInput();
515 bool waitForMessageInput();
516 void checkCenter();
517 void fallThroughHole();
518 void playTunnelEffect(bool falling);
519 int rideTunnel(const uint8 *map, Locate *pobject);
520 void doDnStairs();
521
522 void doText(int entry, int center);
523 void inform(const char *text, bool hold);
524 void printMessage(const char *text[], bool hold);
525 void makeMessageRect(Common::Rect &r);
526 int runMacEndgameDialog(const Common::String &message);
527 int runMacSaveQuery();
528 void runMacAbout();
529
530private:
531 const ADGameDescription *_gameDescription;
532
533 uint8 _wall[32][32];
534 uint8 _mapData[31][31][5][5];
535 uint8 _robotArray[32][32];
536 uint8 _foodArray[32][32];
537 uint8 _dirXY[32][32];
538 bool _visited[8][32][32]; // per-level fog-of-war: _visited[level-1][x][y]
539 bool _showAutomap;
540 float _automapZoom; // automap scale factor, 1.0 = default cell size
541
542 Locate _me;
543 Common::Array<Thing> _objects;
544 int _level;
545 int _robotNum;
546 int _dynamicObjectBase = 0;
547
548 Renderer *_gfx = nullptr;
549 Sound *_sound = nullptr;
550 Graphics::FrameLimiter *_frameLimiter = nullptr;
551 Common::RenderMode _renderMode;
552 Graphics::Surface *_savedScreen = nullptr;
553 Graphics::Surface *_flIconSurf[5] = {};
554 bool _flIconsLoaded = false;
555
556
557 int _tsin = 0, _tcos = 0;
558 int _sint[256];
559 int _cost[256];
560 int _centerX, _centerY;
561 int _width, _height;
562 float _mouseSensitivity;
563 bool _mouseLocked;
564 bool _invertY;
565 bool _soundOn = true;
566 bool _showDashBoard;
567 bool _crosshair;
568 bool _cursorShoot = false;
569 bool _insight;
570 bool _hasKeycard;
571 bool _unlocked;
572 int _weapons;
573 bool _wireframe;
574 bool _widescreen;
575 bool _fullscreen;
576 int _speedShift; // 1-5, movement speed = 1 << (_speedShift - 1)
577
578 // Continuous movement flags (set/cleared by keymapper action events)
579 bool _moveForward;
580 bool _moveBackward;
581 bool _strafeLeft;
582 bool _strafeRight;
583 bool _rotateLeft;
584 bool _rotateRight;
585 bool _sprint;
586
587 // Sub-unit accumulators for deltaTime-based smooth movement.
588 // Position uses 256-units-per-cell integers, angles are uint8 — these
589 // retain fractional progress between frames so low speeds aren't lost.
590 float _moveAccumX;
591 float _moveAccumY;
592 float _rotAccum;
593
594 Common::RandomSource _randomSource;
595 Common::Point _mousePos;
596 uint8 _decode1[4];
597 uint8 _decode2[4];
598 uint8 _decode3[4];
599 uint8 _animDisplay[6];
600 int _coreState[2];
601 int _coreHeight[2];
602 int _corePower[3];
603 int _epower[3]; // log2 display levels for power bars (from qlog)
604 int _coreIndex;
605 int _orbit = 0;
606 int _armor = 0;
607 bool _gametest = false;
608 uint32 _blackoutColor = 0;
609 uint32 _lastClickTime = 0;
610 uint32 _displayCount = 0; // Frame counter for COLOR wall animation (Mac: count)
611 uint32 _lastColonyThinkTime = 0; // Last 125ms CThink tick, for render-only interpolation
612 uint32 _lastHotfootTime = 0; // Time-gate for HOTFOOT damage (~8fps)
613 uint32 _lastAnimUpdate = 0;
614 uint32 _lastWarningChimeTime = 0;
615 uint32 _lastCollisionSoundTime = 0;
616 int _bumpedObject = 0;
617 int _action0 = 0, _action1 = 0;
618 int _creature = 0;
619 bool _allGrow = false;
620 bool _suppressCollisionSound = false;
621
622 // Battle state (battle.c)
623 int _gameMode = kModeColony;
624 Locate _bfight[16]; // 16 battle enemies
625 Locate _battleEnter; // entrance structure
626 Locate _battleShip; // shuttle
627 Locate _battleProj; // enemy projectile
628 bool _projon = false; // projectile active
629 int _pcount = 0; // projectile countdown
630 int _mountains[256]; // mountain height profile
631 int _battledx = 0; // mountain parallax divisor (Width/59)
632 int _battleRound = 0; // AI round-robin counter
633 bool _battleSendFarX = false; // alternate robot respawn axis
634 Locate *_battlePwh[100] = {}; // visible object pointers (for hit detection)
635 int _battleMaxP = 0; // count of visible objects
636 Locate _pyramids[4][4][15]; // pyramid obstacles: 4x4 quadrants, 15 each
637
638 // PATCH.C: object relocation + wall state persistence
640 PassPatch _carryPatch[2]; // [0]=forklift, [1]=carried object
641 int _carryType; // type of object being carried
642 int _fl; // 0=not in forklift, 1=in forklift empty, 2=carrying object
643 LevelData _levelData[8]; // per-level wall state persistence
644
645 MacColor _macColors[145];
646 bool _hasMacColors;
647 Graphics::Cursor *_macCrossCursor = nullptr;
648 Graphics::Cursor *_macArrowCursor = nullptr;
649 int _lastLoggedCursorMode = -1;
650
651 // Mac menu bar (MacWindowManager overlay)
652 Graphics::MacWindowManager *_wm = nullptr;
653 Graphics::MacMenu *_macMenu = nullptr;
654 Graphics::ManagedSurface *_menuSurface = nullptr;
655 int _menuBarHeight = 0;
656 int _pendingMenuAction = 0;
657 int _pendingLoadSlot = -1;
658 void initMacMenus();
659 void drawMacMenuBar();
660 bool processMacMenuEvent(const Common::Event &event);
661 void processPendingMenuAction();
662 void loadMacCursorResources();
663 void handleMenuAction(int action);
664 static void menuCommandsCallback(int action, Common::String &text, void *data);
665 // getSubMenuItem() indexes a submenu; our ids are actions. Look up by action.
666 Graphics::MacMenuItem *macMenuItemForAction(int menuIndex, int action);
667 bool showSaveDialog();
668
669 int _frntxWall = 0, _frntyWall = 0;
670 int _sidexWall = 0, _sideyWall = 0;
671 int _frntx = 0, _frnty = 0;
672 int _sidex = 0, _sidey = 0;
673 int _front = 0, _side = 0;
674 int _direction = 0;
675
676 float _eyeDepthPull = 0.0f; // world units the eye parts are pulled at the camera
677 Common::Point _renderCamera;
678 // think.c: the snoop's snout bobs while it hunts (sniff/csniff).
679 int _snoopSnoutZ = 0;
680 int _snoopSniff = 5;
681 int _snoopSniffCount = 0;
682
683 Common::Rect _clip;
684 Common::Rect _screenR;
685 Common::Rect _dashBoardRect;
686 Common::Rect _compassRect; // DOS: compOval (after shrink); Mac: moveWindow
687 Common::Rect _headsUpRect; // DOS: floorRect; Mac: minimap inside moveWindow
688 Common::Rect _powerRect; // DOS: powerRect; Mac: infoWindow
689
690 // DOS dashboard layout (from original MetaWINDOW pix_per_Qinch values)
691 int _pQx = 0; // pixels per quarter-inch X (24 for EGA 640x350)
692 int _pQy = 0; // pixels per quarter-inch Y (18 for EGA 640x350)
693 int _powerWidth = 0; // width of each of the 3 power bar columns
694 int _powerHeight = 0; // pixel height per power bar unit (max 5)
695
696 // Cached Mac dashboard surfaces
697 Graphics::Surface *_pictPower = nullptr; // PICT -32755 (normal) or -32760 (trouble)
698 Graphics::Surface *_pictPowerNoArmor = nullptr; // B&W panel from DrawInfo()
699 Graphics::Surface *_pictCompass = nullptr; // PICT -32757
700 int _pictPowerID = 0; // Track which PICT is cached
701 Graphics::Surface *loadPictSurface(int resID);
702 void drawPictAt(Graphics::Surface *surf, int destX, int destY);
703
704 uint8 wallAt(int x, int y) const;
705 const uint8 *mapFeatureAt(int x, int y, int direction) const;
706 bool _visibleCell[32][32] = {};
707 void computeVisibleCells();
708 void drawStaticObjects();
709
710public:
712 int pointCount;
713 const int (*points)[3];
714 int surfaceCount;
715 const int (*surfaces)[8];
716 };
717
718private:
719 void draw3DPrism(Thing &obj, const PrismPartDef &def, bool useLook, int colorOverride = -1, bool accumulateBounds = false, bool forceVisible = false);
720 void draw3DLeaf(const Thing &obj, const PrismPartDef &def);
721 void draw3DSphere(Thing &obj, int pt0x, int pt0y, int pt0z,
722 int pt1x, int pt1y, int pt1z, uint32 fillColor, uint32 outlineColor,
723 bool accumulateBounds = false, bool dosFill = true);
724 void drawPrismOval3D(Thing &thing, const PrismPartDef &def, bool useLook, int colorOverride,
725 bool forceVisible = false, bool dosFill = true);
726 void drawEyeOverlays3D(Thing &thing, const PrismPartDef &irisDef, int irisColorOverride,
727 const PrismPartDef &pupilDef, int pupilColorOverride, bool useLook, bool dosFill = true);
728 void drawDOSEyeSlit3D(Thing &thing, const PrismPartDef &irisDef, bool useLook);
729 void drawBodyEye3D(Thing &obj, int eyeballColor, int pupilColor, float pull);
730 void drawEnemyEye3D(Thing &obj, Thing &eye, int eyeballColor, int irisColor, int pupilColor);
731 void pullTowardCamera(float *px, float *py, float *pz, int count) const;
732 float growRenderTickFraction() const;
733 bool drawInterpolatedGrowRobot(Thing &obj, int eyeballColor, int pupilColor);
734 void drawInterpolatedGrowPrism(Thing &obj, const PrismPartDef &fromDef, const PrismPartDef &toDef, float progress);
735 void drawInterpolatedGrowEye(Thing &obj, int fromStage, int toStage, float progress, int eyeballColor, int pupilColor);
736 bool drawStaticObjectPrisms3D(Thing &obj);
737 void initRobots();
738 void renderCorridor3D();
739 void computeRenderCamera();
740 void separateRenderCameraFromWall(int x, int y, uint8 bit, int separation, bool featuresVisible);
741 void drawWallFeatures3D();
742 bool isWallFeatureFacingCamera(int cellX, int cellY, int direction) const;
743 void drawWallFeature3D(int cellX, int cellY, int direction);
744 void drawCellFeature3D(int cellX, int cellY);
745 void getWallFace3D(int cellX, int cellY, int direction, float corners[4][3]);
746 bool isVisibleRecessFeature(int x, int y, int direction) const;
747 bool wallSegmentIsOpenWell(int x, int y, uint8 bit) const;
748 bool wallSegmentIsRendered(int x, int y, uint8 bit) const;
749 void getWallRecess3D(const float corners[4][3], float farC[4][3]) const;
750 void recessPoint(const float nearC[4][3], const float farC[4][3], float u, float v, float depth, float out[3]) const;
751 void recessLine(const float nearC[4][3], const float farC[4][3], float u1, float v1, float d1,
752 float u2, float v2, float d2, uint32 color);
753 void recessQuad(const float nearC[4][3], const float farC[4][3], const float *u, const float *v,
754 const float *d, int count, uint32 color);
755 void clipToWallFace(const float corners[4][3]);
756 void macFillRecess(const float nearC[4][3], const float farC[4][3], const float *u, const float *v,
757 const float *d, int count, int macIdx, bool macColors);
758 void getCellFace3D(int cellX, int cellY, bool ceiling, float corners[4][3]);
759
760 int occupiedObjectAt(int xnew, int ynew, int x, int y, const Locate *pobject);
761 void interactWithObject(int objNum);
762
763 // Mouse events (and warpMouse) speak window pixels, because we declare
764 // kSupportsArbitraryResolutions; the hit-test math (whichSprite, _screenR)
765 // is in logical coords. Convert both ways.
766 Common::Point eventMouseToLogical(const Common::Point &p) const;
767 void warpMouseLogical(int x, int y);
768
769 // shoot.c: shooting and power management
770 void setPower(int p0, int p1, int p2);
771 void cShoot();
772 bool isShootableRobotType(int type) const;
773 bool isShotBlockingObjectType(int type) const;
774 int findAimedObject(const Common::Point &aim, bool *isBlocker = nullptr, int *targetDist = nullptr) const;
775 bool hasAimedRobotTarget() const;
776 void destroyRobot(int num);
777 void explodeFlash(int silentFlips);
778 void invertViewport();
779 void doShootCircles(int cx, int cy);
780 void doBurnHole(int cx, int cy, int radius);
781 void meGetShot();
782
783 // battle.c: outdoor battle system (OpenGL 3D)
784 void battleInit();
785 void battleSet();
786 void battleThink();
787 void normalizeBattlePlayerPosition();
788 void enterColonyFromBattle(int mapNum, int xloc, int yloc);
789 void battleCommand(int xnew, int ynew);
790 void battleShoot();
791 void battleProjCommand(int xcheck, int ycheck);
792 void renderBattle();
793 void draw3DBattlePrism(const PrismPartDef &def, int worldX, int worldY, uint8 ang, int zShift = 0);
794 void battleBackdrop();
795 void battleDrawPyramids();
796 void battleDrawTanks();
797
798 // PATCH.C: object relocation + wall state persistence
799 void resetObjectSlot(int slot, int type, int xloc, int yloc, uint8 ang);
800 bool createObject(int type, int xloc, int yloc, uint8 ang);
801 void saveLevelState();
802 void saveOpenDoors();
803 void doPatch();
804 void saveWall(int x, int y, int direction);
805 void getWall();
806 void newPatch(int type, const PassPatch &from, const PassPatch &to, const uint8 *mapdata);
807 bool patchMapTo(const PassPatch &to, uint8 *mapdata);
808 bool patchMapFrom(const PassPatch &from, uint8 *mapdata);
809 void exitForklift();
810 void dropCarriedObject();
811 bool stepOutOfCell(uint8 angle, bool backwards = false);
812 bool exitTeleport();
813 void teleportPlayer();
814 bool setDoorState(int x, int y, int direction, int state);
815 int openAdjacentDoors(int x, int y);
816 int goToDestination(const uint8 *map, Locate *pobject);
817 int tryPassThroughFeature(int fromX, int fromY, int direction, Locate *pobject);
818 void playTunnelAirlockEffect();
819 void syncMacMenuChecks();
820 void updateMouseCapture(bool recenter = true);
821 Common::Point getAimPoint() const;
822 void updateViewportLayout();
823 bool updateScreenSize();
824 void drawDashboardStep1();
825 void drawDashboardMac();
826 void drawMacNoArmorPanel();
827 void drawDOSBarGraph(int x, int y, int height);
828 void updateDOSPowerBars();
829 void drawMiniMapMarker(int x, int y, int halfSize, uint32 color, bool isMac, const Common::Rect *clip = nullptr);
830 bool hasRobotAt(int x, int y) const;
831 bool hasFoodAt(int x, int y) const;
832 void drawMiniMap(uint32 lineColor);
833 void drawAutomap();
834 void changeAutomapZoom(bool zoomIn);
835 void drawAutomapCryoMarker(int x, int y, int halfSize, uint32 color, const Common::Rect &clip);
836 void drawAutomapTeleportMarker(int x, int y, int halfSize, uint32 color, const Common::Rect &clip);
837 void drawAutomapForkliftMarker(int x, int y, int halfSize, uint32 color, const Common::Rect &clip);
838 void drawAutomapQueenMarker(int x, int y, int halfSize, uint32 color, const Common::Rect &clip);
839 void drawAutomapSnoopMarker(int x, int y, int halfSize, int dirX, int dirY, uint32 color, const Common::Rect &clip);
840 void drawAutomapDroneMarker(int x, int y, int halfSize, uint32 color, const Common::Rect &clip);
841 void drawAutomapRobotMarker(int x, int y, int halfSize, uint32 color, const Common::Rect &clip);
842 void drawAutomapObjectMarker(int x, int y, int halfSize, uint32 color, const Common::Rect &clip);
843 void markVisited();
844 void automapCellCorner(int dx, int dy, int xloc, int yloc, int lExt, int tsin, int tcos, int ccx, int ccy, int &sx, int &sy);
845 void automapDrawWall(const Common::Rect &vp, int x1, int y1, int x2, int y2, uint32 color);
846 int automapWallFeature(int fx, int fy, int dir);
847 void automapDrawWallWithFeature(const Common::Rect &vp, int wx1, int wy1, int wx2, int wy2, int feat, int lExt, uint32 color);
848 void drawForkliftOverlay();
849 void loadForkliftIcons();
850 void drawCrosshair();
851 bool clipLineToRect(int &x1, int &y1, int &x2, int &y2, const Common::Rect &clip) const;
852 void wallLine(const float corners[4][3], float u1, float v1, float u2, float v2, uint32 color);
853 void wallPolygon(const float corners[4][3], const float *u, const float *v, int count, uint32 color);
854 void wallChar(const float corners[4][3], uint8 cnum);
855
856 struct TextIndex {
857 uint32 offset;
858 uint16 ch;
859 uint16 lines;
860 };
861
862 // Animation system
863 Common::Array<Sprite *> _cSprites;
865 Image *_backgroundMask = nullptr;
866 Image *_backgroundFG = nullptr;
867 // Same render cache convention as Sprite::baked, applied to the
868 // per-animation background image (no Sprite owner, so it lives here).
869 Graphics::Surface *_backgroundBaked = nullptr;
870 uint64 _backgroundBakedKey = 0;
871 Common::Rect _backgroundClip;
872 Common::Rect _backgroundLocate;
873 bool _backgroundActive;
874 Common::MacResManager *_resMan = nullptr;
875 Common::MacResManager *_colorResMan = nullptr;
876 byte _topBG[8] = {};
877 byte _bottomBG[8] = {};
878 int16 _divideBG;
879
880 // Cache for the animation background pattern. Regenerated only when
881 // pattern bytes / colors / split point change. Replaces a 110k-pixel
882 // setPixel loop with one texture upload, fixing cursor choppiness
883 // during animations on the OpenGL renderer.
884 Graphics::Surface *_animPatternSurface = nullptr;
885 byte _animPatternKeyTopBG[8] = {};
886 byte _animPatternKeyBottomBG[8] = {};
887 int16 _animPatternKeyDivide = -1;
888 uint32 _animPatternKeyTopColor = 0;
889 uint32 _animPatternKeyBotColor = 0;
890 int _animPatternKeyMode = -1; // 0=DOS, 1=Mac B&W, 2=Mac color
891 bool _animPatternValid = false;
892 Common::String _animationName;
893 Common::Array<int16> _animBMColors;
894 bool _animationRunning;
895 int _animationResult;
896 bool _animExitPressed = false;
897 bool _animExitInside = false;
898 Common::Rect _animExitStrip;
899 Common::Rect _animExitButton;
900 Common::Rect _messageSourceRect;
901 int _coderPick[4] = {};
902 int _coderCursor = 0;
903 int _coderPressed = -1;
904 bool _coderPressInside = false;
905 Image *_coderTiles[4] = {};
906 Image *_coderBtnUp = nullptr;
907 Image *_coderBtnDown = nullptr;
908 bool _coderTilesLoaded = false;
909 Common::Rect _coderWin;
910 Common::Rect _coderIconRects[4];
911 bool _doorOpen;
912 int _liftObject = 0; // sprite index for the carried object in lift animation
913 bool _liftUp = false; // current lift state: true=raised, false=lowered
914 int _elevatorFloor;
915 int _airlockX = -1;
916 int _airlockY = -1;
917 int _airlockDirection = -1;
918 bool _airlockTerminate = false;
919 int _teleportX = -1;
920 int _teleportY = -1;
921 bool _teleportInside = false;
922 bool _teleportDone = false;
923
924 void playIntro();
925 bool makeStars(const Common::Rect &r, int btn);
926 bool makeBlackHole();
927 bool makePlanet();
928 bool leavePlanet();
929 bool explodePlanet();
930 bool timeSquare(const Common::String &str, const Graphics::Font *macFont = nullptr, bool gameOver = false);
931 bool drawPict(int resID);
932 bool loadAnimation(const Common::String &name);
933 bool loadLiftAnimation(int objectType);
934 void deleteAnimation();
935 void takeOff();
936 void fullOfStars();
937 void gameOver(bool kill);
938 void gameOver(bool kill, int savedCryos);
939 int countSavedCryos() const;
940 void playAnimation();
941 void updateAnimation();
942 void drawAnimation();
943 void drawAnimationExitButton(int ox, int oy);
944 void drawColonyCoder(int animOx, int animOy);
945 void loadCoderTiles();
946 bool handleColonyCoderClick(const Common::Point &pt);
947 void drawComplexSprite(int index, int ox, int oy);
948 void drawAnimationImage(Image *img, Image *mask, int x, int y, uint32 fillColor,
949 Graphics::Surface *&bakedCache, uint64 &bakedCacheKey);
950 uint32 resolveAnimColor(int16 bmEntry) const;
951 Image *loadImage(Common::SeekableReadStreamEndian &file);
952 void unpackBytes(Common::SeekableReadStreamEndian &file, byte *dst, uint32 len);
954 int whichSprite(const Common::Point &p);
955 void handleAnimationClick(int item);
956 void playCollisionSound();
957 void handleDeskClick(int item);
958 void handleVanityClick(int item);
959 void handleSlidesClick(int item);
960 void handleTeleshowClick(int item);
961 void handleKeypadClick(int item);
962 void handleSuitClick(int item);
963 void handleDoorClick(int item);
964 void handleAirlockClick(int item);
965 void handleElevatorClick(int item);
966 void handleTeleportClick(int item);
967 void flashTeleportBooth();
968 void handleControlsClick(int item);
969 void dolSprite(int index);
970 void moveObject(int index);
971 void setObjectState(int num, int state);
972 int objectState(int num) const;
973 void setObjectOnOff(int num, bool on);
974 void refreshAnimationDisplay();
975 void cryptArray(uint8 sarray[6], int i, int j, int k, int l);
976 void terminateGame(bool blowup);
977
978 // think.c / shoot.c: colony robot AI, egg growth, and egg eating
979 void cThink();
980 void cubeThink(int num);
981 void pyramidThink(int num);
982 void upyramidThink(int num);
983 void eyeThink(int num);
984 void queenThink(int num);
985 void droneThink(int num);
986 void snoopThink(int num);
987 void eggThink(int num);
988 int getColonyActiveRobotLimit() const;
989 void copyOverflowObjectToSlot(int num);
990 bool layEgg(int type, int xindex, int yindex);
991 void moveThink(int num);
992 void bigGrow(int num);
993 void growRobot(int num);
994 int scanForPlayer(int num);
995 void robotShoot(int num);
996 void meEat();
997 void respawnObject(int num, int type);
998};
999
1000} // End of namespace Colony
1001
1002#endif // COLONY_H
Definition: colony.h:474
void applyGameSettings() override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
bool hasFeature(EngineFeature f) const override
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
void pauseEngineIntern(bool pause) override
Common::Error run() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: console.h:37
Definition: array.h:52
Definition: error.h:81
Definition: macresman.h:126
Definition: random.h:44
Definition: stream.h:944
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:155
EngineFeature
Definition: engine.h:293
Definition: cursor.h:42
Definition: font.h:83
Definition: framelimiter.h:40
Definition: macmenu.h:95
Definition: macwindowmanager.h:149
Definition: managed_surface.h:51
Definition: system.h:166
Platform
Definition: platform.h:93
RenderMode
Definition: rendermode.h:48
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: advancedDetector.h:164
Common::Platform platform
Definition: advancedDetector.h:199
Definition: colony.h:711
Definition: colony.h:450
Definition: colony.h:449
Definition: colony.h:411
Definition: colony.h:394
Definition: colony.h:344
Definition: colony.h:405
Definition: colony.h:387
Definition: colony.h:379
Definition: colony.h:424
Definition: colony.h:363
Definition: events.h:218
Definition: rect.h:144
Definition: rect.h:536
Definition: atari-cursor.h:35
Definition: macmenu.h:59
Definition: pixelformat.h:138
uint32 ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) const
Definition: pixelformat.h:278
Definition: surface.h:67