-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathsimple_game.cpp
130 lines (119 loc) · 4.51 KB
/
simple_game.cpp
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
#include "stdafx.h"
#include "simple_game.h"
#include "creature_name.h"
#include "creature_attributes.h"
#include "collective_config.h"
#include "resource_info.h"
#include "content_factory.h"
#include "resource_counts.h"
#include "furniture.h"
#include "item.h"
#include "enemy_info.h"
#include "main_loop.h"
static PCreature getCreature(ContentFactory* factory, CreatureId id) {
return factory->getCreatures().fromId(id, TribeId::getDarkKeeper());
}
void SimpleGame::addResourcesForLevel(int level) {
auto resourceCounts = chooseResourceCounts(Random, factory->resources, level);
for (auto& count : resourceCounts->elems)
if (auto drop = factory->furniture.getData(count.type).getItemDrop()) {
for (int patch : Range(count.countFurther + count.countStartingPos))
for (int i : Range(Random.get(count.size)))
for (auto& item : drop->random(factory, 0))
++resources[*item->getResourceId()];
}
}
SimpleGame::SimpleGame(ContentFactory* factory, MainLoop* mainLoop) : factory(factory), mainLoop(mainLoop) {
auto& info = factory->keeperCreatures[0].second;
for (auto elem : info.immigrantGroups)
append(immigrants, factory->immigrantsData.at(elem));
minions.push_back(getCreature(factory, info.creatureId[0]));
auto allZLevels = factory->zLevels.at("evil");
allZLevels.append(factory->zLevels.at("basic"));
for (int i : Range(1, 100))
zLevels.push_back(*chooseZLevel(Random, allZLevels, i));
addResourcesForLevel(0);
}
bool SimpleGame::meetsRequirements(const ImmigrantInfo& info) {
if (!info.getTraits().contains(MinionTrait::FIGHTER) || minions.size() >= maxPopulation)
return false;
for (auto& req : info.requirements)
if (!req.type.visit<bool>(
[&](TechId id) { return technology.researched.count(id); },
[](const auto&) { return true; }
))
return false;
return true;
}
void SimpleGame::addImmigrant() {
}
bool SimpleGame::fightEnemy(EnemyId id) {
/* auto& enemy = factory->enemies.at(id).settlement;
const int numTries = 10;
int res = mainLoop->battleTest(numTries, DirectoryPath::current().file("battle2.txt"), getWeakPointers(minions),
{enemy.inhabitants.fighters, enemy.inhabitants.leader});
std::cout << "Fighting " << enemy.race.value_or("unknown enemy") << ": " << res << "/" << numTries;*/
return true;
}
void SimpleGame::increaseZLevel() {
auto level = zLevels[zLevel + 1];
auto result = level.visit(
[&](const FullZLevel& l) {
if (l.enemy)
return fightEnemy(*l.enemy);
return true;
},
[](const auto&) { return true; }
);
if (result)
addResourcesForLevel(++zLevel);
}
void SimpleGame::research() {
}
vector<pair<string, SimpleGame::SimpleAction>> SimpleGame::getActions() {
vector<pair<string, function<void()>>> ret;
if (maxPopulation > minions.size())
ret.push_back(make_pair("Add immigrant", [this]{ addImmigrant(); }));
ret.push_back(make_pair("Increase z-level", [this]{ increaseZLevel(); }));
if (dungeonLevel.numResearchAvailable() > 0)
ret.push_back(make_pair("Research", [this]{ research(); }));
return ret;
}
void SimpleGame::update() {
std::cout << "Minions: ";
/* for (auto& c : minions)
std::cout << c->getName().bare() << " " << c->getBestAttackValue() << ", ";
std::cout << "\n";
std::cout << "Researched technologies: ";
for (auto& tech : technology.researched)
std::cout << tech.data() << ", ";
if (dungeonLevel.numResearchAvailable() > 0) {
std::cout << "Available technologies (" << dungeonLevel.numResearchAvailable() << "): ";
for (auto& tech : technology.getNextTechs())
std::cout << tech.data() << ", ";
}
std::cout << "\n";
std::cout << "Current z-level: " << zLevel << "\n";
std::cout << "Resources: ";
for (auto& resource : factory->resourceInfo)
std::cout << resources[resource.first] << " " << resource.second.name << ", ";
std::cout << "\n";
std::cout << "Population: " << minions.size() << "/" << maxPopulation << "\n";
std::cout << "Immigrants: ";
for (int i : All(immigrants))
if (meetsRequirements(immigrants[i])) {
auto c = getCreature(factory, immigrants[i].getId(0));
std::cout << i << ". " << c->getName().bare() << "(" << c->getBestAttackValue() << "), ";
}
std::cout << "\n";
auto actions = getActions();
std::cout << "Actions:\n";
for (int i : All(actions))
std::cout << i << ". " << actions[i].first << "\n";
int index;
std::cin >> index;
if (index >= 0 && index < actions.size())
actions[index].second();
else
std::cout << "Bad index\n";*/
}