aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEugene Sandulenko2018-03-30 22:57:23 +0200
committerEugene Sandulenko2018-03-30 22:57:48 +0200
commita91d7ec44b6c5526a81ebce4cc44c69796384bdb (patch)
tree72bb7f9320c0d55743df8f46dee8e298c41ebd51 /engines
parent17d7fa328ab51feeb09044ef0027b2c22b79875b (diff)
downloadscummvm-rg350-a91d7ec44b6c5526a81ebce4cc44c69796384bdb.tar.gz
scummvm-rg350-a91d7ec44b6c5526a81ebce4cc44c69796384bdb.tar.bz2
scummvm-rg350-a91d7ec44b6c5526a81ebce4cc44c69796384bdb.zip
BLADERUNNER: Implemented ActorClues::acquireCluesByRelations()
Diffstat (limited to 'engines')
-rw-r--r--engines/bladerunner/actor_clues.cpp86
-rw-r--r--engines/bladerunner/actor_clues.h15
2 files changed, 95 insertions, 6 deletions
diff --git a/engines/bladerunner/actor_clues.cpp b/engines/bladerunner/actor_clues.cpp
index 16b9002765..028832b6d1 100644
--- a/engines/bladerunner/actor_clues.cpp
+++ b/engines/bladerunner/actor_clues.cpp
@@ -97,8 +97,92 @@ int ActorClues::getWeight(int clueId) const {
return _clues[clueIndex].weight;
}
+int ActorClues::getModifier(int actorId, int otherActorId, int clueId) {
+ warning("STUB: getModifier(%d, %d, %d)", actorId, otherActorId, clueId);
+
+ return 0;
+}
+
+static int cluesCompare(const void *p1, const void *p2) {
+ const ActorClues::CluesUS *clue1 = (const ActorClues::CluesUS *)p1;
+ const ActorClues::CluesUS *clue2 = (const ActorClues::CluesUS *)p2;
+
+ if (clue1->modifier > clue2->modifier)
+ return -1;
+
+ return (clue1->modifier < clue2->modifier);
+}
+
void ActorClues::acquireCluesByRelations(int actorId, int otherActorId) {
- warning("TODO: acquireCluesByRelations");
+ CluesUS clues1[kClueCount], clues2[kClueCount];
+
+ int count1 = findAcquirableCluesFromActor(actorId, otherActorId, clues1, kClueCount);
+ int count2 = findAcquirableCluesFromActor(otherActorId, actorId, clues2, kClueCount);
+
+ if (count1 || count2) {
+ for (int i = 0; i < count1; i++) {
+ clues1[i].modifier = getModifier(actorId, otherActorId, clues1[i].clueId);
+ }
+ qsort(clues1, count1, sizeof(CluesUS), cluesCompare);
+
+ for (int i = 0; i < count2; i++) {
+ clues2[i].modifier = getModifier(otherActorId, actorId, clues2[i].clueId);
+ }
+ qsort(clues2, count2, sizeof(CluesUS), cluesCompare);
+
+ Actor *actor = _vm->_actors[actorId];
+ Actor *otherActor = _vm->_actors[otherActorId];
+
+ int avgParameters = (otherActor->getHonesty() + otherActor->getIntelligence() + actor->getFriendlinessToOther(otherActorId)) / 3;
+ int clue1count = avgParameters * count1 / 100;
+
+ if (avgParameters >= 50 && !clue1count && count1 == 1) {
+ clue1count = 1;
+ }
+
+ avgParameters = (actor->getHonesty() + actor->getIntelligence() + otherActor->getFriendlinessToOther(actorId)) / 3;
+ int clue2count = avgParameters * count2 / 100;
+
+ if (avgParameters >= 50 && !clue2count && count2 == 1) {
+ clue2count = 1;
+ }
+
+ for (int i = 0; i < clue2count; i++) {
+ bool flag = false;
+ if (otherActor->_clues->isFlag2(clues2[i].clueId)) {
+ avgParameters = (2 * otherActor->getFriendlinessToOther(actorId) + otherActor->getHonesty()) / 3;
+
+ if (avgParameters > 70) {
+ avgParameters = 100;
+ } else if (avgParameters < 30) {
+ avgParameters = 0;
+ }
+ if (_vm->_rnd.getRandomNumberRng(1, 100) <= avgParameters) {
+ flag = true;
+ }
+ }
+
+ actor->_clues->acquire(clues2[i].clueId, flag, otherActorId);
+ }
+
+ for (int i = 0; i < clue1count; i++) {
+ bool flag = false;
+ if (actor->_clues->isFlag2(clues1[i].clueId)) {
+ avgParameters = (2 * actor->getFriendlinessToOther(otherActorId) + actor->getHonesty()) / 3;
+
+ if (avgParameters > 70) {
+ avgParameters = 100;
+ } else if (avgParameters < 30) {
+ avgParameters = 0;
+ }
+ if (_vm->_rnd.getRandomNumberRng(1, 100) <= avgParameters) {
+ flag = true;
+ }
+ }
+
+ otherActor->_clues->acquire(clues1[i].clueId, flag, actorId);
+ }
+ }
}
int ActorClues::findAcquirableCluesFromActor(int actorId, int targetActorId, CluesUS *list, int size) {
diff --git a/engines/bladerunner/actor_clues.h b/engines/bladerunner/actor_clues.h
index aa8693f71b..76690329d3 100644
--- a/engines/bladerunner/actor_clues.h
+++ b/engines/bladerunner/actor_clues.h
@@ -32,6 +32,8 @@ class SaveFileReadStream;
class SaveFileWriteStream;
class ActorClues {
+ static const int kClueCount = 288;
+
struct Clue {
int clueId;
int weight;
@@ -45,11 +47,6 @@ class ActorClues {
byte flags;
};
- struct CluesUS {
- int clueId;
- int modifier;
- };
-
BladeRunnerEngine *_vm;
int _count;
@@ -57,6 +54,12 @@ class ActorClues {
Common::Array<Clue> _clues;
public:
+ struct CluesUS {
+ int clueId;
+ int modifier;
+ };
+
+public:
ActorClues(BladeRunnerEngine *_vm, int cluesType);
void add(int actorId, int clueId, int unknown, bool acquired, bool unknownFlag, int fromActorId);
@@ -66,6 +69,8 @@ public:
bool isAcquired(int clueId) const;
int getWeight(int clueId) const;
+ int getModifier(int actorId, int otherActorId, int clueId);
+
void acquireCluesByRelations(int actorId, int otherActorId);
int findAcquirableCluesFromActor(int actorId, int targetActorId, CluesUS *list, int size);