Skip to content

Commit

Permalink
Added code for the AI accepting quests
Browse files Browse the repository at this point in the history
Currently deactivated, because some quests shouldn't be competitive and
should be allowed only for a specific faction, but they are being
enabled for all factions of a particular civilization due to the current
low quest quantity
  • Loading branch information
Andrettin committed Aug 20, 2016
1 parent 0f7b239 commit 03ebb13
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/stratagus/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,14 @@ void CPlayer::AvailableQuestsChanged()
}
}
}

if (this->AiEnabled) { // if is an AI player, accept all quests that it can
for (int i = ((int) this->AvailableQuests.size() - 1); i >= 0; --i) {
if (this->CanAcceptQuest(this->AvailableQuests[i])) { // something may have changed, so recheck if the player is able to accept the quest
// this->AcceptQuest(this->AvailableQuests[i]);
}
}
}
}

void CPlayer::UpdateCurrentQuests()
Expand Down Expand Up @@ -1864,6 +1872,20 @@ void CPlayer::FailQuest(CQuest *quest)
// SetObjective(quest->Objectives[i].c_str());
CclCommand("RemovePlayerObjective(" + std::to_string((long long) this->Index) + ", \"" + quest->Objectives[i] + "\");");
}

std::string fail_reason;
if (quest->CurrentCompleted) { // quest already completed by someone else
fail_reason = "Another faction has completed the quest before you.";
} else {
for (size_t i = 0; i < this->QuestDestroyUniques.size(); ++i) {
if (std::get<0>(this->QuestDestroyUniques[i]) == quest && std::get<2>(this->QuestDestroyUniques[i]) == true && std::get<1>(this->QuestDestroyUniques[i])->CanDrop()) { // if is supposed to destroy a unique, but it is nowhere to be found, fail the quest
fail_reason = "The target no longer exists.";
break;
}
}
}

CclCommand("if (GenericDialog ~= nil) then GenericDialog(\"Quest Failed\", \"You have failed the " + quest->Name + " quest! " + fail_reason + "\", nil, \"" + quest->Icon.Name + "\", \"" + PlayerColorNames[quest->PlayerColor] + "\") end;");
}
}

Expand Down

0 comments on commit 03ebb13

Please sign in to comment.