Skip to content

Commit

Permalink
BLADERUNNER: Added combat
Browse files Browse the repository at this point in the history
Math cleanup
Fixed obstacle detection
  • Loading branch information
peterkohaut committed Mar 17, 2018
1 parent b272701 commit 19d9e4c
Show file tree
Hide file tree
Showing 47 changed files with 1,153 additions and 312 deletions.
61 changes: 42 additions & 19 deletions engines/bladerunner/actor.cpp
Expand Up @@ -22,11 +22,11 @@

#include "bladerunner/actor.h"

#include "bladerunner/bladerunner.h"
#include "bladerunner/actor_clues.h"
#include "bladerunner/actor_combat.h"
#include "bladerunner/actor_walk.h"
#include "bladerunner/audio_speech.h"
#include "bladerunner/bladerunner.h"
#include "bladerunner/boundingbox.h"
#include "bladerunner/game_info.h"
#include "bladerunner/items.h"
Expand Down Expand Up @@ -671,6 +671,12 @@ bool Actor::tick(bool forceDraw, Common::Rect *screenRect) {
return isVisible;
}

void Actor::tickCombat() {
if (_id != kActorMcCoy && !_isRetired && _inCombat) {
_combatInfo->tick();
}
}

bool Actor::draw(Common::Rect *screenRect) {
Vector3 drawPosition(_position.x, -_position.z, _position.y + 2.0);
float drawAngle = M_PI - _facing * (M_PI / 512.0f);
Expand Down Expand Up @@ -904,16 +910,6 @@ void Actor::setImmunityToObstacles(bool isImmune) {
_isImmuneToObstacles = isImmune;
}

void Actor::modifyCurrentHP(signed int change) {
_currentHP = CLIP(_currentHP + change, 0, 100);
if (_currentHP > 0)
retire(false, 0, 0, -1);
}

void Actor::modifyMaxHP(signed int change) {
_maxHP = CLIP(_maxHP + change, 0, 100);
}

void Actor::modifyCombatAggressiveness(signed int change) {
_combatAggressiveness = CLIP(_combatAggressiveness + change, 0, 100);
}
Expand Down Expand Up @@ -955,6 +951,13 @@ void Actor::setTarget(bool target) {
_isTarget = target;
}

void Actor::setCurrentHP(int hp) {
_currentHP = hp;
if (hp > 0) {
retire(false, 0, 0, -1);
}
}

void Actor::setHealth(int hp, int maxHp) {
_currentHP = hp;
_maxHP = maxHp;
Expand All @@ -963,13 +966,25 @@ void Actor::setHealth(int hp, int maxHp) {
}
}

void Actor::combatModeOn(int a2, int a3, int otherActorId, int a5, int animationModeCombatIdle, int animationModeCombatWalk, int animationModeCombatRun, int a9, int a10, int a11, int ammoDamage, int a13, int a14) {
void Actor::modifyCurrentHP(signed int change) {
_currentHP = CLIP(_currentHP + change, 0, 100);
if (_currentHP > 0) {
retire(false, 0, 0, -1);
}
}

void Actor::modifyMaxHP(signed int change) {
_maxHP = CLIP(_maxHP + change, 0, 100);
}


void Actor::combatModeOn(int initialState, bool rangedAttack, int enemyId, int waypointType, int animationModeCombatIdle, int animationModeCombatWalk, int animationModeCombatRun, int fleeRatio, int coverRatio, int actionRatio, int damage, int range, bool a14) {
_animationModeCombatIdle = animationModeCombatIdle;
_animationModeCombatWalk = animationModeCombatWalk;
_animationModeCombatRun = animationModeCombatRun;
_inCombat = true;
if (_id != kActorMcCoy) {
_combatInfo->combatOn(_id, a2, a3, otherActorId, a5, a9, a10, a11, ammoDamage, a13, a14);
_combatInfo->combatOn(_id, initialState, rangedAttack, enemyId, waypointType, fleeRatio, coverRatio, actionRatio, damage, range, a14);
}
stopWalking(false);
changeAnimationMode(_animationModeCombatIdle, false);
Expand Down Expand Up @@ -1002,6 +1017,16 @@ float Actor::distanceFromActor(int otherActorId) {
return (_position - _vm->_actors[otherActorId]->_position).length();
}

int Actor::angleTo(const Vector3 &target) const {
int angle = angle_1024(_position.x, _position.z, target.x, target.z) - _facing;
if (angle < -512) {
angle += 1024;
} else if (angle > 512) {
angle -= 1024;
}
return angle;
}

float Actor::getX() const {
return _position.x;
}
Expand All @@ -1014,10 +1039,8 @@ float Actor::getZ() const {
return _position.z;
}

void Actor::getXYZ(float *x, float *y, float *z) const {
*x = _position.x;
*y = _position.y;
*z = _position.z;
Vector3 Actor::getXYZ() const {
return _position;
}

int Actor::getFacing() const {
Expand Down Expand Up @@ -1112,8 +1135,8 @@ int Actor::soundBalance() const {
return 35.0f * (CLIP(screenPosition.x / 640.0f, 0.0f, 1.0f) * 2.0f - 1.0f);
}

bool Actor::isObstacleBetween(float targetX, float targetZ) {
return _vm->_sceneObjects->isObstacleBetween(_position.x, _position.z, targetX, targetZ, _position.y, -1);
bool Actor::isObstacleBetween(const Vector3 &target) {
return _vm->_sceneObjects->isObstacleBetween(_position, target, -1);
}

int Actor::findTargetUnderMouse(BladeRunnerEngine *vm, int mouseX, int mouseY) {
Expand Down
59 changes: 39 additions & 20 deletions engines/bladerunner/actor.h
Expand Up @@ -39,18 +39,17 @@ class MovementTrack;
class View;

class Actor {
friend class ScriptBase;
friend class KIA;

BladeRunnerEngine *_vm;

private:
public:
BoundingBox *_bbox;
Common::Rect _screenRectangle;
MovementTrack *_movementTrack;
ActorWalk *_walkInfo;
ActorCombat *_combatInfo;
ActorClues *_clues;

private:
int _honesty;
int _intelligence;
int _stability;
Expand All @@ -61,8 +60,6 @@ class Actor {
int _currentHP;
int _maxHP;

ActorClues *_clues;

int _id;
int _setId;
Vector3 _position;
Expand Down Expand Up @@ -124,7 +121,7 @@ class Actor {
float getX() const;
float getY() const;
float getZ() const;
void getXYZ(float *x, float *y, float *z) const;
Vector3 getXYZ() const;
int getFacing() const;
int getAnimationMode() const;

Expand Down Expand Up @@ -157,20 +154,24 @@ class Actor {
void run();

bool tick(bool forceUpdate, Common::Rect *screenRect);
void tickCombat();
bool draw(Common::Rect *screenRect);

int getSetId() const;
void setSetId(int setId);
BoundingBox *getBoundingBox() const { return _bbox; }
Common::Rect *getScreenRectangle() { return &_screenRectangle; }
int getWalkbox() const { return _walkboxId; }

bool isRetired() const { return _isRetired; }
bool isTarget() const { return _isTarget; }
bool isTarget() const { return true;/*return _isTarget; */}
void setTarget(bool targetable);
bool isImmuneToObstacles() const { return _isImmuneToObstacles; }
bool inCombat() const { return _inCombat; }

bool isMoving() const { return _isMoving; }
void setMoving(bool value) { _isMoving = value; }

bool inWalkLoop() const { return _inWalkLoop; }
bool isWalking() const;
bool isRunning() const;
Expand All @@ -184,33 +185,51 @@ class Actor {
void faceXYZ(const Vector3 &pos, bool animate);
void faceCurrentCamera(bool animate);
void faceHeading(int heading, bool animate);
void modifyFriendlinessToOther(int otherActorId, signed int change);
void setFacing(int facing, bool halfOrSet = true);

int getCurrentHP() const { return _currentHP; }
int getMaxHP() const { return _maxHP; }
void setCurrentHP(int hp);
void setHealth(int hp, int maxHp);
void modifyCurrentHP(signed int change);
void modifyMaxHP(signed int change);

int getFriendlinessToOther(int otherActorId) const { return _friendlinessToOther[otherActorId]; }
void setFriendlinessToOther(int otherActorId, int friendliness);
void modifyFriendlinessToOther(int otherActorId, signed int change);

int getHonesty() const { return _honesty; }
void setHonesty(int honesty);
void modifyHonesty(signed int change);

int getIntelligence() const { return _intelligence; }
void setIntelligence(int intelligence);
void modifyIntelligence(signed int change);

int getStability() const { return _stability; }
void setStability(int stability);
void modifyStability(signed int change);

int getCombatAggressiveness() const { return _combatAggressiveness; }
void setCombatAggressiveness(int combatAggressiveness);
void modifyCombatAggressiveness(signed int change);

void setInvisible(bool isInvisible);
void setImmunityToObstacles(bool isImmune);
void modifyCurrentHP(signed int change);
void modifyMaxHP(signed int change);
void modifyCombatAggressiveness(signed int change);
void modifyHonesty(signed int change);
void modifyIntelligence(signed int change);
void modifyStability(signed int change);

void setFlagDamageAnimIfMoving(bool value);
bool getFlagDamageAnimIfMoving() const;
void setHealth(int hp, int maxHp);
bool getFlagDamageAnimIfMoving() const;

void retire(bool isRetired, int width, int height, int retiredByActorId);

void combatModeOn(int a2, int a3, int a4, int a5, int combatAnimationMode, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14);
void combatModeOn(int initialState, bool rangedAttack, int enemyId, int waypointType, int animationModeCombatIdle, int animationModeCombatWalk, int animationModeCombatRun, int fleeRatio, int coverRatio, int actionRatio, int damage, int range, bool a14);
void combatModeOff();

void setGoal(int goalNumber);
int getGoal() const;

float distanceFromActor(int otherActorId);
int angleTo(const Vector3 &target) const;

void speechPlay(int sentenceId, bool voiceOver);
void speechStop();
Expand All @@ -225,11 +244,11 @@ class Actor {
int soundVolume() const;
int soundBalance() const;

bool isObstacleBetween(float targetX, float targetZ);
bool isObstacleBetween(const Vector3 &target);

static int findTargetUnderMouse(BladeRunnerEngine *vm, int mouseX, int mouseY);

private:
void setFacing(int facing, bool halfOrSet = true);
void setBoundingBox(const Vector3 &position, bool retired);
float distanceFromView(View *view) const;

Expand Down

0 comments on commit 19d9e4c

Please sign in to comment.