1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ASYLUM_RESOURCES_ACTOR_H
#define ASYLUM_RESOURCES_ACTOR_H
#include "common/array.h"
#include "common/rect.h"
#include "common/serializer.h"
#include "common/stream.h"
#include "asylum/shared.h"
#include "asylum/resources/inventory.h"
namespace Asylum {
class AsylumEngine;
class GraphicResource;
class Screen;
struct ActionArea;
struct GraphicFrame;
struct ActorData : public Common::Serializable {
uint32 count;
int32 current;
Common::Point points[120];
ActorDirection directions[120];
ActorData() {
count = 0;
current = 0;
memset(&directions, 0, sizeof(directions));
}
virtual ~ActorData() {}
void load(Common::SeekableReadStream *stream) {
count = stream->readUint32LE();
current = stream->readUint32LE();
for (int32 i = 0; i < 120; i++) {
points[i].x = stream->readSint32LE();
points[i].y = stream->readSint32LE();
}
for (int32 i = 0; i < 120; i++)
directions[i] = (ActorDirection)stream->readSint32LE();
}
// Serializable
void saveLoadWithSerializer(Common::Serializer &s) {
s.syncAsUint32LE(count);
s.syncAsSint32LE(current);
for (int32 i = 0; i < ARRAYSIZE(points); i++) {
s.syncAsSint32LE(points[i].x);
s.syncAsSint32LE(points[i].y);
}
for (int32 i = 0; i < ARRAYSIZE(directions); i++)
s.syncAsSint32LE(directions[i]);
}
};
class Actor : public Common::Serializable {
public:
Actor(AsylumEngine *engine, ActorIndex index);
virtual ~Actor() {};
//////////////////////////////////////////////////////////////////////////
// Public variables & accessors
//////////////////////////////////////////////////////////////////////////
int32 flags;
int32 actionType; // ActionType enum value
Inventory inventory;
void setActionIndex2(int32 index) { _actionIdx2 = index; }
void setObjectIndex(int32 index) { _objectIndex = index; }
void setDirection(ActorDirection dir) { _direction = dir; }
void setFrameCount(int32 count) { _frameCount = count; }
void setFrameIndex(int32 number) { _frameIndex = number; }
void setLastScreenUpdate(int32 tick) { _lastScreenUpdate = tick; }
void setNumberFlag01(int32 number) { _numberFlag01 = number; }
void setPriority(int32 priority) { _priority = priority; }
void setResourceId(ResourceId id) { _resourceId = id; }
void setSoundResourceId(ResourceId id) { _soundResourceId = id; }
void setStatus(ActorStatus status) { _status = status; }
void setTransparency(int32 val) { _transparency = val; }
void setTickCount(int32 tickCount) { _tickCount = tickCount; }
void setField934(int32 val) { _field_934 = val; }
void setField938(int32 val) { _field_938 = val; }
void setField944(int32 val) { _field_944 = val; }
int32 getActionIndex3() { return _actionIdx3; }
Common::Rect *getBoundingRect() { return &_boundingRect; }
ActorDirection getDirection() { return _direction; }
uint32 getFrameCount() { return _frameCount; }
uint32 getFrameIndex() { return _frameIndex; }
char *getName() { return (char *)&_name; }
ActorIndex getNextActorIndex() { return _nextActorIndex; }
int32 getNumberValue01() { return _numberValue01; }
Common::Point *getPoint() { return &_point; }
Common::Point *getPoint1() { return &_point1; }
Common::Point *getPoint2() { return &_point2; }
int32 getPriority() { return _priority; }
ResourceId getResourceId() { return _resourceId; }
ResourceId getResourcesId(uint32 index) { return _graphicResourceIds[index]; }
int32 getScriptIndex() { return _scriptIndex; }
bool shouldInvertPriority() { return _invertPriority; }
ResourceId getSoundResourceId() { return _soundResourceId; }
ActorStatus getStatus() { return _status; }
int32 getTickCount() { return _tickCount; }
int32 getField934() { return _field_934; }
int32 getField944() { return _field_944; }
int32 getField948() { return _field_948; }
int32 getField94C() { return _field_94C; }
// For saving
ActorData *getData() { return &_data; }
/////////////////////////////////////////////////////////////////////////
// Data
/////////////////////////////////////////////////////////////////////////
/**
* Loads the actor
*
* @param stream If non-null, the Common::SeekableReadStream to load from
*/
void load(Common::SeekableReadStream *stream);
/////////////////////////////////////////////////////////////////////////
// Visibility
/////////////////////////////////////////////////////////////////////////
/**
* Query if this actor is visible.
*
* @return true if visible, false if not.
*/
bool isVisible() { return flags & kActorFlagVisible; }
/**
* Query if this actor is on screen.
*
* @return true if on screen, false if not.
*/
bool isOnScreen();
/**
* Shows this actor.
*/
void show() { setVisible(true); }
/**
* Hides this actor.
*/
void hide() { setVisible(false); }
/////////////////////////////////////////////////////////////////////////
// Drawing & update
//////////////////////////////////////////////////////////////////////////
/**
* Draws the actor
*/
void draw();
/**
* Draw number text (called on scene drawing)
*/
void drawNumber();
/**
* Updates the actor.
*/
void update();
/**
* Enables the actor
*/
void enable() { changeStatus(kActorStatusEnabled); }
/**
* Changes the actor status.
*
* @param status The status.
*/
void changeStatus(ActorStatus status);
/////////////////////////////////////////////////////////////////////////
// Direction & position
/////////////////////////////////////////////////////////////////////////
/**
* Updates the actor's mirror image.
*/
void updateReflectionData();
/**
* Updates resource Id using the actor direction.
*
* @param direction The direction.
*/
void changeDirection(ActorDirection direction);
/**
* Face a target from a certain direction
*
* @param target Identifier for the target.
* @param from direction to face from.
*/
void faceTarget(uint32 target, DirectionFrom from);
/**
* Initialize the x1/y1 values of the actor, update the active animation frame and, if the current direction isn't 8, update the actor's direction.
*
* @param newX The new x coordinate.
* @param newY The new y coordinate.
* @param newDirection The new direction.
* @param frame The frame.
*/
void setPosition(int16 newX, int16 newY, ActorDirection newDirection, uint32 frame);
/**
* Query if a graphic resource is present.
*
* @param index Zero-based index of the graphic resource.
*
* @return true if the graphic resource is present.
*/
bool canChangeStatus(int index) const;
/**
* Adjust coordinates.
*
* @param point The point.
*/
void adjustCoordinates(Common::Point *point);
/////////////////////////////////////////////////////////////////////////
// Misc
/////////////////////////////////////////////////////////////////////////
/**
* Stop the actor related sounds
*/
void stopSound();
/**
* Convert this object into a string representation.
*
* @param shortString toggle whether to output a summary or
* detailed view of the actor object
* @return A string representation of this object.
*/
Common::String toString(bool shortString = true);
/**
* Clears reflection-related data fields
*/
void clearReflectionData();
bool canReach(const Common::Point &point);
void forceTo(int16 actorX, int16 actorY, bool doSpeech);
void setupReflectionData(ActorIndex nextActor, int32 actionAreaId, ActorDirection nextDirection, const Common::Point &nextPosition, bool invertPriority, const Common::Point &nextPositionOffset);
bool aNicePlaceToTalk(Common::Point *point, int32 *param);
bool canMove(Common::Point *point, ActorDirection direction, uint32 count, bool hasDelta);
void move(ActorDirection dir, uint32 distance);
bool testActorCollision(Common::Point *point, ActorDirection direction);
void drawInventory();
void stopWalking();
/**
* Query if the object resource is present in the resource table between indices 10 & 20
*
* @return true if resource present between 15 & 20, false if not.
*/
bool checkBoredStatus() const;
//////////////////////////////////////////////////////////////////////////
// Static update methods
//////////////////////////////////////////////////////////////////////////
static void crowsReturn(AsylumEngine *engine);
/**
* Updates the player appearance in chapter 9.
*
* @param [in,out] engine If non-null, the engine.
* @param nextPlayer The next player index
*/
static void morphInto(AsylumEngine *engine, int nextPlayer);
/**
* Gets a direction using the angle between the two vectors.
*
* @param vec1 The first vector.
* @param vec2 The second vector.
*
* @return The direction
*/
static ActorDirection getAngle(const Common::Point &vec1, const Common::Point &vec2);
/**
* Gets the euclidean distance between two points.
*
* @param point1 The first point.
* @param point2 The second point.
*
* @return the distance.
*/
static uint32 euclidianDistance(const Common::Point &point1, const Common::Point &point2);
// Serializable
void saveLoadWithSerializer(Common::Serializer &s);
private:
AsylumEngine *_vm;
// Our current index
ActorIndex _index;
//////////////////////////////////////////////////////////////////////////
// Data
//////////////////////////////////////////////////////////////////////////
Common::Point _point;
ResourceId _resourceId;
int32 _objectIndex;
uint32 _frameIndex;
uint32 _frameCount;
Common::Point _point1;
Common::Point _point2;
Common::Rect _boundingRect;
ActorDirection _direction;
int32 _field_3C;
ActorStatus _status;
int32 _field_44;
int32 _priority;
//flags
int32 _field_50;
int32 _field_54;
int32 _field_58;
int32 _field_5C;
int32 _field_60;
int32 _actionIdx3;
// TODO field_68 till field_617
ResourceId _walkingSound1;
ResourceId _walkingSound2;
ResourceId _walkingSound3;
ResourceId _walkingSound4;
uint32 _field_64C;
uint32 _field_650;
ResourceId _graphicResourceIds[55];
char _name[256];
int32 _distancesEO[20];
int32 _distancesNS[20];
int32 _distancesNSEO[20];
int32 _actionIdx2;
int32 _field_924;
uint32 _lastScreenUpdate;
int32 _scriptIndex;
//actionType
int32 _field_934;
int32 _field_938;
ResourceId _soundResourceId; // field_93C
int32 _numberValue01;
int32 _field_944; // has collision ?!
int32 _field_948;
int32 _field_94C;
int32 _numberFlag01;
int16 _numberStringWidth;
Common::Point _numberPoint;
char _numberString01[8];
int32 _field_968;
int32 _transparency;
bool _processNewDirection;
bool _invertPriority;
ActorDirection _nextDirection;
int32 _nextActionIndex;
ActorIndex _nextActorIndex;
Common::Point _nextPositionOffset;
Common::Point _nextPosition;
int32 _field_994;
int32 _field_998;
int32 _field_99C;
int32 _field_9A0;
//////////////////////////////////////////////////////////////////////////
// Actor data
//////////////////////////////////////////////////////////////////////////
ActorData _data;
int32 _tickCount;
uint32 _updateCounter;
//////////////////////////////////////////////////////////////////////////
// Update methods
//////////////////////////////////////////////////////////////////////////
void updateStatusInteracting();
void checkPumpkinDeath();
void updatePumpkin(GameFlag flagToCheck, GameFlag flagToSet, ObjectId objectToUpdate, ObjectId objectToDisable);
void updateStatusEnabled();
void updateStatusEnabledProcessStatus(int16 testX, int16 testY, uint32 counter, int16 setX, int16 setY);
void updateStatusBored();
void CrowClosesIn();
void ScareCrowClosesIn();
void TentacleRises();
void updateStatusEnabled2();
void CrowHoveringBeforeKill();
void CrowStatusQuo();
void TentacleWigglesForSarah();
void CrowDives();
void MaxGetsHit();
void MaxAttacks();
void checkScareCrowDeath();
bool checkCrowDeath();
void ScareCrowAttacks();
bool actorsIntersect(ActorIndex actorIndex1, ActorIndex actorIndex2);
void TentacleWhips();
void SarahAttacks();
void MaxGetsSome();
void SarahGetsSome();
void TentacleDies();
void CrowSwoops();
void ScareCrowRetreats();
void updateStatusMorphing();
void actionAreaCheck();
//////////////////////////////////////////////////////////////////////////
// Path finding functions
//////////////////////////////////////////////////////////////////////////
uint32 _frameNumber;
bool findLeftPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
bool findRightPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
bool findUpPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
bool findDownPath(Common::Point source, const Common::Point &destination, Common::Array<int> *actions);
bool tryDirection(const Common::Point &source, Common::Array<int> *actions, Common::Point *point, ActorDirection direction, const Common::Point &destination, bool *flag);
bool canGetToDest(Common::Array<int> *actions, const Common::Point &point, ActorDirection direction, int16 loopcount);
bool testPolyInLink(const Common::Point &pt, Common::Array<int> *actions);
//////////////////////////////////////////////////////////////////////////
// Misc
//////////////////////////////////////////////////////////////////////////
/**
* Sets actor visibility
*
* @param value true to set to visible, false to set to hidden.
*/
void setVisible(bool value);
/**
* Sets the volume.
*/
void setVolume();
void TentacleBlocksSarah(const Common::Point &vec1, Common::Point vec2);
void SarahDies();
/**
* Updates the actor "number" data if the item is "1".
*
* @param item The item.
* @param point The coordinates
*/
void updateNumbers(uint item, const Common::Point &point);
/**
* Determine if the supplied point is in the action area
*
* @param pt The point.
* @param [in,out] area If non-null, the area.
*
* @return true if in the action area, false otherwise
*/
bool isInActionArea(const Common::Point &pt, ActionArea *area);
//////////////////////////////////////////////////////////////////////////
// Helper methods
//////////////////////////////////////////////////////////////////////////
/**
* Updates the actor graphic information
*
* @param offset The offset used to get the id from the _graphicResourceIds table
*/
void updateGraphicData(uint32 offset);
/**
* Gets the graphics flag for queuing the actor graphics (mirrored or normal)
*
* @return The graphics flag.
*/
DrawFlags getGraphicsFlags();
/**
* Gets the absolute value of the walk increment for a frame.
*
* @param direction The direction.
* @param frameIndex Zero-based index of the frame.
*
* @return The absolute value of the walk increment.
*/
int32 getStride(ActorDirection direction, uint32 frameIndex) const;
/**
* Gets the walk increment for a frame.
*
* @param direction The direction.
* @param frameIndex Zero-based index of the frame.
*
* @return The walk increment.
*/
int32 getWalkIncrement(ActorDirection direction, uint32 frameIndex) const;
/**
* Updates the coordinates depending on the direction.
*
* @param direction The direction.
* @param delta The delta.
* @param [in,out] point If non-null, the point.
*/
static void incPosition(ActorDirection direction, int16 delta, Common::Point *point);
/**
* Get the angle between the two vectors
*
* @param p1 The first vector.
* @param p2 The second vector.
*
* @return the angle
*/
static int32 getAngleOfVector(const Common::Point &vec1, const Common::Point &vec2);
/**
* Computes the Scare Crow's strike zone.
*
* @param rect The strike zone.
* @param direction The direction.
* @param point The point.
*/
static void getCrowStrikeZone(Common::Rect *rect, ActorDirection direction, const Common::Point &point);
/**
* Determines the direction of the shortest rotation between two vectors.
*
* @param vec1 The first vector.
* @param vec2 The second vector.
*
* @return true if CCW, false if CW.
*/
static bool determineLeftOrRight(const Common::Point &vec1, const Common::Point &vec2);
/**
* Gets the adjustment for the X-coordinate of the supplied point.
*
* @param rect The rectangle.
* @param point The test point.
*
* @return value depending on the horizontal position of the point relative to the rectangle.
*/
static int16 pointInRectXAdjust(const Common::Rect &rect, const Common::Point &point);
/**
* Gets the adjustment for the Y-coordinate of the supplied point.
*
* @param rect The rectangle.
* @param point The test point.
*
* @return value depending on the vertical position of the point relative to the rectangle.
*/
static int16 pointInRectYAdjust(const Common::Rect &rect, const Common::Point &point);
}; // end of class MainActor
} // end of namespace Asylum
#endif // ASYLUM_RESOURCES_ACTOR_H
|