forked from gecube/opencaesar3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraining_building.cpp
198 lines (161 loc) · 4.86 KB
/
training_building.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// This file is part of openCaesar3.
//
// openCaesar3 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.
//
// openCaesar3 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 openCaesar3. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2012-2013 Gregoire Athanase, gathanase@gmail.com
#include "training_building.hpp"
#include <iostream>
#include "scenario.hpp"
#include "walker.hpp"
#include "exception.hpp"
#include "gui_info_box.hpp"
#include "gettext.hpp"
namespace {
static const char* rcEntertaimentGroup = "entertainment";
}
TrainingBuilding::TrainingBuilding()
{
setMaxWorkers(5);
setWorkers(0);
_trainingTimer = 0;
_trainingDelay = 80;
}
void TrainingBuilding::timeStep(const unsigned long time)
{
Building::timeStep(time);
if (_trainingTimer == 0)
{
deliverTrainee();
_trainingTimer = _trainingDelay;
}
else if (_trainingTimer > 0)
{
_trainingTimer -= 1;
}
_animation.nextFrame();
Picture *pic = _animation.get_current_picture();
if (pic != NULL)
{
int level = _fgPictures.size()-1;
_fgPictures[level] = _animation.get_current_picture();
}
}
// void TrainingBuilding::deliverTrainee()
// {
// // make a service walker and send him to his wandering
// ServiceWalker *walker = new ServiceWalker(_service);
// walker->setServiceBuilding(*this);
// walker->start();
// }
void TrainingBuilding::serialize(OutputSerialStream &stream)
{
WorkingBuilding::serialize(stream);
stream.write_int(_trainingTimer, 2, 0, 1000);
stream.write_int(_trainingDelay, 2, 0, 1000);
}
void TrainingBuilding::unserialize(InputSerialStream &stream)
{
WorkingBuilding::unserialize(stream);
_trainingTimer = stream.read_int(2, 0, 1000);
_trainingDelay = stream.read_int(2, 0, 1000);
}
//GuiInfoBox* TrainingBuilding::makeInfoBox()
//{
// GuiInfoService* box = new GuiInfoService(*this);
// return box;
//}
BuildingActor::BuildingActor()
{
setType(B_ACTOR);
_size = 3;
setPicture(PicLoader::instance().get_picture(rcEntertaimentGroup, 81));
AnimLoader animLoader(PicLoader::instance());
animLoader.fill_animation(_animation, rcEntertaimentGroup, 82, 9);
animLoader.change_offset(_animation, 68, -6);
_fgPictures.resize(1);
}
BuildingActor* BuildingActor::clone() const
{
return new BuildingActor(*this);
}
void BuildingActor::deliverTrainee()
{
// std::cout << "Deliver trainee!" << std::endl;
TraineeWalker *trainee = new TraineeWalker(WTT_ACTOR);
trainee->setOriginBuilding(*this);
trainee->start();
}
BuildingGladiator::BuildingGladiator()
{
setType(B_GLADIATOR);
_size = 3;
setPicture(PicLoader::instance().get_picture(rcEntertaimentGroup, 51));
AnimLoader animLoader(PicLoader::instance());
animLoader.fill_animation(_animation, rcEntertaimentGroup, 52, 10);
animLoader.change_offset(_animation, 62, 24);
_fgPictures.resize(1);
}
BuildingGladiator* BuildingGladiator::clone() const
{
return new BuildingGladiator(*this);
}
void BuildingGladiator::deliverTrainee()
{
// std::cout << "Deliver trainee!" << std::endl;
TraineeWalker *trainee = new TraineeWalker(WTT_GLADIATOR);
trainee->setOriginBuilding(*this);
trainee->start();
}
BuildingLion::BuildingLion()
{
setType(B_LION);
_size = 3;
setPicture(PicLoader::instance().get_picture(rcEntertaimentGroup, 62));
AnimLoader animLoader(PicLoader::instance());
animLoader.fill_animation(_animation, rcEntertaimentGroup, 63, 18);
animLoader.change_offset(_animation, 78, 21);
_fgPictures.resize(1);
}
BuildingLion* BuildingLion::clone() const
{
return new BuildingLion(*this);
}
void BuildingLion::deliverTrainee()
{
// std::cout << "Deliver trainee!" << std::endl;
TraineeWalker *trainee = new TraineeWalker(WTT_TAMER);
trainee->setOriginBuilding(*this);
trainee->start();
}
BuildingChariot::BuildingChariot()
{
setType(B_CHARIOT);
_size = 3;
setPicture(PicLoader::instance().get_picture(rcEntertaimentGroup, 91));
AnimLoader animLoader(PicLoader::instance());
animLoader.fill_animation(_animation, rcEntertaimentGroup, 92, 10);
animLoader.change_offset(_animation, 54, 23);
_fgPictures.resize(1);
}
BuildingChariot* BuildingChariot::clone() const
{
return new BuildingChariot(*this);
}
void BuildingChariot::deliverTrainee()
{
// std::cout << "Deliver trainee!" << std::endl;
TraineeWalker *trainee = new TraineeWalker(WTT_CHARIOT);
trainee->setOriginBuilding(*this);
trainee->start();
}