Skip to content

Commit

Permalink
BLADERUNNER: added picking up of items
Browse files Browse the repository at this point in the history
and some formatting
  • Loading branch information
peterkohaut committed Oct 12, 2016
1 parent 8720c3a commit 577c3b5
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 169 deletions.
4 changes: 2 additions & 2 deletions engines/bladerunner/actor.cpp
Expand Up @@ -228,7 +228,7 @@ bool Actor::loopWalk(const Vector3 &destination, int destinationOffset, bool a3,
break;
}
return false;
} else {
} else {
//TODO:
// original code, not yet working
*isRunning = false;
Expand Down Expand Up @@ -511,7 +511,7 @@ void Actor::draw() {
// TODO: Handle SHORTY mode

_vm->_sliceRenderer->drawInWorld(_animationId, _animationFrame, drawPosition, drawAngle, drawScale, _vm->_surface2, _vm->_zBuffer2);
//todo udpate screenrect
_vm->_sliceRenderer->getScreenRectangle(&_screenRectangle, _animationId, _animationFrame, drawPosition, drawAngle, drawScale);
}

int Actor::getSetId() {
Expand Down
49 changes: 25 additions & 24 deletions engines/bladerunner/bladerunner.cpp
Expand Up @@ -65,10 +65,10 @@
namespace BladeRunner {

BladeRunnerEngine::BladeRunnerEngine(OSystem *syst)
: Engine(syst),
_rnd("bladerunner") {
: Engine(syst),
_rnd("bladerunner") {
_windowIsActive = true;
_gameIsRunning = true;
_gameIsRunning = true;
_playerLosesControlCounter = 0;

_crimesDatabase = nullptr;
Expand Down Expand Up @@ -286,7 +286,7 @@ bool BladeRunnerEngine::startup(bool hasSavegames) {

_mainFont = new Font(this);
_mainFont->open("KIA6PT.FON", 640, 480, -1, 0, 0x252D);
_mainFont->setSpacing(1, 0);
_mainFont->setSpacing(1, 0);

for (int i = 0; i != 43; ++i) {
Shape *shape = new Shape(this);
Expand Down Expand Up @@ -428,7 +428,7 @@ void BladeRunnerEngine::shutdown() {
if (isArchiveOpen("SPCHSFX.TLK"))
closeArchive("SPCHSFX.TLK");

if(_mainFont) {
if (_mainFont) {
_mainFont->close();
delete _mainFont;
_mainFont = nullptr;
Expand Down Expand Up @@ -524,7 +524,7 @@ void BladeRunnerEngine::gameLoop() {

#if _DEBUG

void drawBBox(Vector3 start, Vector3 end, View* view, Graphics::Surface *surface, int color) {
void drawBBox(Vector3 start, Vector3 end, View *view, Graphics::Surface *surface, int color) {
Vector3 bfl = view->calculateScreenPosition(Vector3(start.x, start.y, start.z));
Vector3 bfr = view->calculateScreenPosition(Vector3(start.x, end.y, start.z));
Vector3 bbr = view->calculateScreenPosition(Vector3(end.x, end.y, start.z));
Expand Down Expand Up @@ -584,7 +584,7 @@ void BladeRunnerEngine::gameTick() {
}
(void)backgroundChanged;
_surface2.copyFrom(_surface1);
memcpy(_zBuffer2, _zBuffer1, 640*480*2);
memcpy(_zBuffer2, _zBuffer1, 640 * 480 * 2);

#if 0
{
Expand Down Expand Up @@ -613,7 +613,7 @@ void BladeRunnerEngine::gameTick() {
//int setId = _scene->_setId;
for (int i = 0, end = _gameInfo->getActorCount(); i != end; ++i) {
//if (_actors[i]->getSetId() == setId) {
if (i == 0 || i == 23){ // Currently limited to McCoy and Officer Leroy
if (i == 0 || i == 23) { // Currently limited to McCoy and Officer Leroy
_actors[i]->tick(backgroundChanged);
}
}
Expand All @@ -638,7 +638,7 @@ void BladeRunnerEngine::gameTick() {
_walkSoundId = -1;
}

#if false
#if 0
//draw scene objects
int count = _sceneObjects->_count;
if (count > 0) {
Expand All @@ -655,24 +655,25 @@ void BladeRunnerEngine::gameTick() {
}
if (sceneObject->_sceneObjectType == SceneObjectTypeObject) {
color = 0b011110111101111;
//if (sceneObject->_isObstacle)
// color += 0b100000000000000;
//if (sceneObject->_isObstacle)
// color += 0b100000000000000;
if (sceneObject->_isClickable)
color = 0b000001111100000;
//if (sceneObject->_isTarget)
// color += 0b000000000010000;
//if (sceneObject->_isTarget)
// color += 0b000000000010000;
}

sceneObject->_sceneObjectId;
drawBBox(a, b, _view, &_surface2, color);

//_surface2.frameRect(sceneObject->_screenRectangle, color);

Vector3 pos = _view->calculateScreenPosition(0.5 * (a + b));
switch(sceneObject->_sceneObjectType) {
switch (sceneObject->_sceneObjectType) {
case SceneObjectTypeActor:
_mainFont->drawColor(_textActorNames->getText(sceneObject->_sceneObjectId - SCENE_OBJECTS_ACTORS_OFFSET), _surface2, pos.x, pos.y, color);
break;
case SceneObjectTypeItem:
_mainFont->draw("item", _surface2, pos.x, pos.y);
_mainFont->drawColor("item", _surface2, pos.x, pos.y, color);
break;
case SceneObjectTypeObject:
_mainFont->drawColor(_scene->objectGetName(sceneObject->_sceneObjectId - SCENE_OBJECTS_OBJECTS_OFFSET), _surface2, pos.x, pos.y, color);
Expand All @@ -683,13 +684,13 @@ void BladeRunnerEngine::gameTick() {

//draw regions
for (int i = 0; i < 10; i++) {
Region* region = &_scene->_regions->_regions[i];
Region *region = &_scene->_regions->_regions[i];
if (!region->_present) continue;
_surface2.frameRect(region->_rectangle, 0b000000000011111);
}

for (int i = 0; i < 10; i++) {
Region* region = &_scene->_exits->_regions[i];
Region *region = &_scene->_exits->_regions[i];
if (!region->_present) continue;
_surface2.frameRect(region->_rectangle, 0b111111111111111);
}
Expand All @@ -700,7 +701,7 @@ void BladeRunnerEngine::gameTick() {
for (int j = 0; j < walkbox->_vertexCount; j++) {
Vector3 start = _view->calculateScreenPosition(walkbox->_vertices[j]);
Vector3 end = _view->calculateScreenPosition(walkbox->_vertices[(j + 1) % walkbox->_vertexCount]);
//debug("walkbox[%i][%i] = x=%f y=%f x=%f y=%f", i, j, start.x, start.y, end.x, end.y);
//debug("walkbox[%i][%i] = x=%f y=%f x=%f y=%f", i, j, start.x, start.y, end.x, end.y);
_surface2.drawLine(start.x, start.y, end.x, end.y, 0b111111111100000);
Vector3 pos = _view->calculateScreenPosition(0.5 * (start + end));
_mainFont->drawColor(walkbox->_name, _surface2, pos.x, pos.y, 0b111111111100000);
Expand All @@ -717,7 +718,7 @@ void BladeRunnerEngine::gameTick() {
int colorG = (light->_color.g * 31.0f);
int colorB = (light->_color.b * 31.0f);
int color = (colorR << 10) + (colorG << 5) + colorB;
drawBBox(pos-size, pos+size, _view, &_surface2, color);
drawBBox(pos - size, pos + size, _view, &_surface2, color);

}
#endif
Expand Down Expand Up @@ -759,7 +760,7 @@ void BladeRunnerEngine::handleMouseClick(int x, int y) {
int isTarget;

int sceneObjectId = _sceneObjects->findByXYZ(&isClickable, &isObstacle, &isTarget, mousePosition.x, mousePosition.y, mousePosition.z, 1, 0, 1);
int exitIndex = _scene->_exits->getRegionAtXY(x, y);
int exitIndex = _scene->_exits->getRegionAtXY(x, y);

debug("%d %d", sceneObjectId, exitIndex);

Expand Down Expand Up @@ -819,7 +820,7 @@ void BladeRunnerEngine::handleMouseClickActor(int x, int y, int actorId) {
}

void BladeRunnerEngine::gameWaitForActive() {
while(!_windowIsActive) {
while (!_windowIsActive) {
handleEvents();
}
}
Expand Down Expand Up @@ -873,7 +874,7 @@ bool BladeRunnerEngine::openArchive(const Common::String &name) {

bool BladeRunnerEngine::closeArchive(const Common::String &name) {
for (uint i = 0; i != 10; ++i) {
if (_archives[i].isOpen() &&_archives[i].getName() == name) {
if (_archives[i].isOpen() && _archives[i].getName() == name) {
_archives[i].close();
return true;
}
Expand All @@ -885,7 +886,7 @@ bool BladeRunnerEngine::closeArchive(const Common::String &name) {

bool BladeRunnerEngine::isArchiveOpen(const Common::String &name) {
for (uint i = 0; i != 10; ++i) {
if (_archives[i].isOpen() &&_archives[i].getName() == name)
if (_archives[i].isOpen() && _archives[i].getName() == name)
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions engines/bladerunner/bladerunner.h
Expand Up @@ -131,7 +131,7 @@ class BladeRunnerEngine : public Engine {
int _walkSoundId;
int _walkSoundVolume;
int _walkSoundBalance;
int _walkingActorId;
int _walkingActorId;
private:
static const int kArchiveCount = 10;
MIXArchive _archives[kArchiveCount];
Expand Down Expand Up @@ -178,8 +178,7 @@ class BladeRunnerEngine : public Engine {
void ISez(const char *str);
};

static inline
const Graphics::PixelFormat createRGB555() {
static inline const Graphics::PixelFormat createRGB555() {
return Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
}

Expand Down
3 changes: 2 additions & 1 deletion engines/bladerunner/item.cpp
Expand Up @@ -80,7 +80,8 @@ void Item::tick(bool special) {
Vector3 postition(_position.x, -_position.z, _position.y);
int animationId = _animationId + (special ? 1 : 0);
_vm->_sliceRenderer->drawInWorld(animationId, 0, postition, M_PI - _angle, 1.0f, _vm->_surface2, _vm->_zBuffer2);
//todo udpate screenrect
_vm->_sliceRenderer->getScreenRectangle(&_screenRectangle, animationId, 0, postition, M_PI - _angle, 1.0f);

if (_isSpinning) {
_facing += _facingChange;

Expand Down
7 changes: 3 additions & 4 deletions engines/bladerunner/item.h
Expand Up @@ -60,18 +60,17 @@ class Item {
bool _isPoliceMazeEnemy;

public:
Item(BladeRunnerEngine* vm);
Item(BladeRunnerEngine *vm);
~Item();

void getXYZ(float *x, float *y, float *z);
void setXYZ(Vector3 position);
void getWidthHeight(int * width, int * height);
void getWidthHeight(int *width, int *height);

bool isTargetable();
void tick(bool special);

void setup(int itemId, int setId, int animationId, Vector3 position, int facing, int height, int width, bool isTargetable, bool isVisible, bool isPoliceMazeEnemy);

};

}
Expand Down
30 changes: 22 additions & 8 deletions engines/bladerunner/items.cpp
Expand Up @@ -32,12 +32,12 @@ Items::Items(BladeRunnerEngine *vm) {
}

Items::~Items() {
for(int i = _items.size() - 1; i >= 0; i--) {
for (int i = _items.size() - 1; i >= 0; i--) {
delete _items.remove_at(i);
}
}

void Items::getXYZ(int itemId, float* x, float* y, float* z) {
void Items::getXYZ(int itemId, float *x, float *y, float *z) {
int itemIndex = findItem(itemId);
assert(itemIndex != -1);

Expand All @@ -53,40 +53,54 @@ void Items::getWidthHeight(int itemId, int *width, int *height) {

void Items::tick() {
int setId = _vm->_scene->getSetId();
for(int i = 0; i < (int)_items.size(); i++) {
if(_items[i]->_setId != setId) {
for (int i = 0; i < (int)_items.size(); i++) {
if (_items[i]->_setId != setId) {
continue;
}
bool set14NotTarget = setId == 14 && !_items[i]->isTargetable();
_items[i]->tick(set14NotTarget);
}
}

bool Items::add(int itemId, int animationId, int setId, Vector3 position, int facing, int height, int width, bool isTargetable, bool isVisible, bool isPoliceMazeEnemy, bool addToSet) {
bool Items::addToWorld(int itemId, int animationId, int setId, Vector3 position, int facing, int height, int width, bool isTargetable, bool isVisible, bool isPoliceMazeEnemy, bool addToSet) {
if (_items.size() >= 100) {
return false;
}
int itemIndex = findItem(itemId);
if(itemIndex == -1) {
if (itemIndex == -1) {
itemIndex = _items.size();
}

Item *item = new Item(_vm);
item->setup(itemId, setId, animationId, position, facing, height, width, isTargetable, isVisible, isPoliceMazeEnemy);
_items.push_back(item);

if(addToSet && setId == _vm->_scene->getSetId()) {
if (addToSet && setId == _vm->_scene->getSetId()) {
return _vm->_sceneObjects->addItem(itemId + SCENE_OBJECTS_ITEMS_OFFSET, &item->_boundingBox, &item->_screenRectangle, isTargetable, isVisible);
}
return true;
}

bool Items::addToSet(int setId) {
int itemsCount = _vm->_items->_items.size();
if (itemsCount == 0) {
return true;
}
for (int i = 0; i < itemsCount; i++) {
Item *item = _vm->_items->_items[i];
if (item->_setId == setId) {
_vm->_sceneObjects->addItem(item->_itemId + SCENE_OBJECTS_ITEMS_OFFSET, &item->_boundingBox, &item->_screenRectangle, item->isTargetable(), item->_isVisible);
}
}
return true;
}

bool Items::remove(int itemId) {
if (_items.size() == 0) {
return false;
}
int itemIndex = findItem(itemId);
if(itemIndex == -1) {
if (itemIndex == -1) {
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions engines/bladerunner/items.h
Expand Up @@ -40,12 +40,13 @@ class Items {
~Items();

void getXYZ(int itemId, float *x, float *y, float *z);
void getWidthHeight(int itemId, int * width, int * height);
void getWidthHeight(int itemId, int *width, int *height);

void tick();
bool add(int itemId, int animationId, int setId, Vector3 position, int facing, int height, int width, bool isTargetable, bool isVisible, bool isPoliceMazeEnemy, bool b);
bool addToWorld(int itemId, int animationId, int setId, Vector3 position, int facing, int height, int width, bool isTargetable, bool isVisible, bool isPoliceMazeEnemy, bool b);
bool addToSet(int itemId);
bool remove(int itemId);

private:
int findItem(int itemId);
};
Expand Down

0 comments on commit 577c3b5

Please sign in to comment.