forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleManufacture.cpp
More file actions
155 lines (141 loc) · 3.98 KB
/
Copy pathRuleManufacture.cpp
File metadata and controls
155 lines (141 loc) · 3.98 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RuleManufacture.h"
namespace OpenXcom
{
/**
* Creates a new Manufacture.
* @param name The unique manufacture name.
*/
RuleManufacture::RuleManufacture(const std::string &name) : _name(name), _space(0), _time(0), _cost(0), _listOrder(0)
{
_producedItems[name] = 1;
}
/**
* Loads the manufacture project from a YAML file.
* @param node YAML node.
* @param listOrder The list weight for this manufacture.
*/
void RuleManufacture::load(const YAML::Node &node, int listOrder)
{
bool same = (1 == _producedItems.size() && _name == _producedItems.begin()->first);
_name = node["name"].as<std::string>(_name);
if (same)
{
int value = _producedItems.begin()->second;
_producedItems.clear();
_producedItems[_name] = value;
}
_category = node["category"].as<std::string>(_category);
_requires = node["requires"].as< std::vector<std::string> >(_requires);
_space = node["space"].as<int>(_space);
_time = node["time"].as<int>(_time);
_cost = node["cost"].as<int>(_cost);
_requiredItems = node["requiredItems"].as< std::map<std::string, int> >(_requiredItems);
_producedItems = node["producedItems"].as< std::map<std::string, int> >(_producedItems);
_listOrder = node["listOrder"].as<int>(_listOrder);
if (!_listOrder)
{
_listOrder = listOrder;
}
}
/**
* Gets the unique name of the manufacture.
* @return The name.
*/
std::string RuleManufacture::getName() const
{
return _name;
}
/**
* Gets the category shown in the manufacture list.
* @return The category.
*/
std::string RuleManufacture::getCategory() const
{
return _category;
}
/**
* Gets the list of research required to
* manufacture this object.
* @return A list of research IDs.
*/
const std::vector<std::string> &RuleManufacture::getRequirements() const
{
return _requires;
}
/**
* Gets the required workspace to start production.
* @return The required workspace.
*/
int RuleManufacture::getRequiredSpace() const
{
return _space;
}
/**
* Gets the time needed to manufacture one object.
* @return The time needed to manufacture one object (in man/hour).
*/
int RuleManufacture::getManufactureTime() const
{
return _time;
}
/**
* Gets the cost of manufacturing one object.
* @return The cost of manufacturing one object.
*/
int RuleManufacture::getManufactureCost() const
{
return _cost;
}
/**
* Checks if there's enough funds to manufacture one object.
* @param funds Current funds.
* @return True if manufacture is possible.
*/
bool RuleManufacture::haveEnoughMoneyForOneMoreUnit(int64_t funds) const
{
// either we have enough money, or the production doesn't cost anything
return funds >= _cost || _cost <= 0;
}
/**
* Gets the list of items required to manufacture one object.
* @return The list of items required to manufacture one object.
*/
const std::map<std::string, int> & RuleManufacture::getRequiredItems() const
{
return _requiredItems;
}
/**
* Gets the list of items produced by completing "one object" of this project.
* @return The list of items produced by completing "one object" of this project.
*/
const std::map<std::string, int> & RuleManufacture::getProducedItems() const
{
return _producedItems;
}
/**
* Gets the list weight for this manufacture item.
* @return The list weight for this manufacture item.
*/
int RuleManufacture::getListOrder() const
{
return _listOrder;
}
}