~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/noCharburnerPile.cpp

  • Committer: FloSoft
  • Date: 2014-04-25 15:35:50 UTC
  • Revision ID: flosoft@siedler25.org-20140425153550-9muu4vodhlqu58m0
committing subversion revision 9357 by FloSoft
astyle

modified:
s25client/trunk/
s25client/trunk/contrib/lua/lin32/include/
s25client/trunk/contrib/lua/lin64/include/
s25client/trunk/contrib/lua/mac/include/
s25client/trunk/contrib/lua/win32/include/
s25client/trunk/contrib/lua/win64/include/
s25client/trunk/driver/audio/SDL/src/
s25client/trunk/driver/src/
s25client/trunk/driver/video/GLFW/src/
s25client/trunk/driver/video/SDL/src/
s25client/trunk/driver/video/WinAPI/src/
s25client/trunk/src/
s25client/trunk/win32/
s25client/trunk/win32/prebuild-mutex/src/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: noCharburnerPile.cpp 7521 2011-09-08 20:45:55Z FloSoft $
 
1
// $Id: noCharburnerPile.cpp 9357 2014-04-25 15:35:25Z FloSoft $
2
2
//
3
3
// Copyright (c) 2005 - 2011 Settlers Freaks (sf-team at siedler25.org)
4
4
//
32
32
///////////////////////////////////////////////////////////////////////////////
33
33
// Makros / Defines
34
34
#if defined _WIN32 && defined _DEBUG && defined _MSC_VER
35
 
        #define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
36
 
        #undef THIS_FILE
37
 
        static char THIS_FILE[] = __FILE__;
 
35
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
 
36
#undef THIS_FILE
 
37
static char THIS_FILE[] = __FILE__;
38
38
#endif
39
39
 
40
40
 
42
42
const unsigned SMOLDERING_LENGTH = 3000;
43
43
 
44
44
/// Work steps for the construction of the wood pile and the cover
45
 
const unsigned short CONSTRUCTION_WORKING_STEPS[2] = {6,6};
 
45
const unsigned short CONSTRUCTION_WORKING_STEPS[2] = {6, 6};
46
46
/// Work steps for one graphical step during the remove of the cover
47
47
const unsigned short REMOVECOVER_WORK_STEPS = 1;
48
48
/// Work steps for one graphical step during the "harvest"
49
49
const unsigned short HARVEST_WORK_STEPS = 1;
50
50
 
51
 
noCharburnerPile::noCharburnerPile(const unsigned short x, const unsigned short y) : noCoordBase(NOP_CHARBURNERPILE,x,y),
52
 
state(STATE_WOOD), step(0), sub_step(1), event(NULL)
 
51
noCharburnerPile::noCharburnerPile(const unsigned short x, const unsigned short y) : noCoordBase(NOP_CHARBURNERPILE, x, y),
 
52
    state(STATE_WOOD), step(0), sub_step(1), event(NULL)
53
53
{
54
54
}
55
55
 
56
56
noCharburnerPile::~noCharburnerPile()
57
57
{
58
 
        
 
58
 
59
59
}
60
60
 
61
61
void noCharburnerPile::Destroy_noCharburnerPile()
62
62
{
63
 
        em->RemoveEvent(event);
64
 
 
65
 
        // Bauplätze drumrum neu berechnen
66
 
        gwg->RecalcBQAroundPointBig(x,y);
67
 
 
68
 
        Destroy_noCoordBase();
69
 
}
70
 
 
71
 
void noCharburnerPile::Serialize_noCharburnerPile(SerializedGameData * sgd) const
72
 
{
73
 
        Serialize_noCoordBase(sgd);
74
 
 
75
 
        sgd->PushUnsignedChar(static_cast<unsigned char>(state));
76
 
        sgd->PushUnsignedShort(step);
77
 
        sgd->PushUnsignedShort(sub_step);
78
 
        sgd->PushObject(event,true);
79
 
}
80
 
 
81
 
noCharburnerPile::noCharburnerPile(SerializedGameData * sgd, const unsigned obj_id) : noCoordBase(sgd,obj_id),
82
 
state(State(sgd->PopUnsignedChar())),
83
 
step(sgd->PopUnsignedShort()),
84
 
sub_step(sgd->PopUnsignedShort()),
85
 
event(sgd->PopObject<EventManager::Event>(GOT_EVENT))
86
 
{
87
 
}
88
 
 
89
 
void noCharburnerPile::Draw( int x,     int y)
90
 
{
91
 
        switch(state)
92
 
        {
93
 
        case STATE_WOOD:
94
 
                {
95
 
                        // Draw sand on which the wood stack is constructed
96
 
                        LOADER.GetImageN("charburner_bobs",25)->Draw(x,y);
97
 
 
98
 
                        glArchivItem_Bitmap * image;
99
 
                        if(step == 0)
100
 
                                image = LOADER.GetImageN("charburner_bobs",26);
101
 
                        else 
102
 
                        {
103
 
                                image = LOADER.GetImageN("charburner_bobs",28);
104
 
 
105
 
                                // Draw wood pile beneath the cover
106
 
                                 LOADER.GetImageN("charburner_bobs",26)->Draw(x,y);
107
 
                        }
108
 
 
109
 
                        unsigned short progress = sub_step*image->getHeight() / CONSTRUCTION_WORKING_STEPS[step];
110
 
                        unsigned short height = image->getHeight() - progress;
111
 
                        if(progress != 0)
112
 
                                image->Draw(x, y+height, 0, 0, 0, height, 0, progress);
113
 
                } return;
114
 
        case STATE_SMOLDERING:
115
 
                {
116
 
                        LOADER.GetImageN("charburner_bobs",27+GameClient::inst().
117
 
                                GetGlobalAnimation(2,10,1,obj_id+this->x*10+this->y*10))->Draw(x,y);
118
 
                                
119
 
                        // Dann Qualm zeichnen 
120
 
                        LOADER.GetMapImageN(692+1*8+GAMECLIENT.GetGlobalAnimation(8,5,2,(this->x+this->y)*100))
121
 
                                        ->Draw(x+21,y-11,0,0,0,0,0,0,0x99EEEEEE);
122
 
                        LOADER.GetMapImageN(692+2*8+GAMECLIENT.GetGlobalAnimation(8,5,2,(this->x+this->y)*100))
123
 
                                        ->Draw(x-2,y-06,0,0,0,0,0,0,0x99EEEEEE);
124
 
                        LOADER.GetMapImageN(692+1*8+GAMECLIENT.GetGlobalAnimation(8,5,2,(this->x+this->y)*100))
125
 
                                        ->Draw(x-25,y-11,0,0,0,0,0,0,0x99EEEEEE);
126
 
                        LOADER.GetMapImageN(692+3*8+GAMECLIENT.GetGlobalAnimation(8,5,2,(this->x+this->y)*100))
127
 
                                        ->Draw(x-2,y-35,0,0,0,0,0,0,0x99EEEEEE);
128
 
                } return;
129
 
        case STATE_REMOVECOVER:
130
 
                {
131
 
                        LOADER.GetImageN("charburner_bobs",28+step)->Draw(x,y);
132
 
                } return;
133
 
        case STATE_HARVEST:
134
 
                {
135
 
                        LOADER.GetImageN("charburner_bobs",34+step)->Draw(x,y);
136
 
 
137
 
                } return;
138
 
        default: return;
139
 
        }
 
63
    em->RemoveEvent(event);
 
64
 
 
65
    // Bauplätze drumrum neu berechnen
 
66
    gwg->RecalcBQAroundPointBig(x, y);
 
67
 
 
68
    Destroy_noCoordBase();
 
69
}
 
70
 
 
71
void noCharburnerPile::Serialize_noCharburnerPile(SerializedGameData* sgd) const
 
72
{
 
73
    Serialize_noCoordBase(sgd);
 
74
 
 
75
    sgd->PushUnsignedChar(static_cast<unsigned char>(state));
 
76
    sgd->PushUnsignedShort(step);
 
77
    sgd->PushUnsignedShort(sub_step);
 
78
    sgd->PushObject(event, true);
 
79
}
 
80
 
 
81
noCharburnerPile::noCharburnerPile(SerializedGameData* sgd, const unsigned obj_id) : noCoordBase(sgd, obj_id),
 
82
    state(State(sgd->PopUnsignedChar())),
 
83
    step(sgd->PopUnsignedShort()),
 
84
    sub_step(sgd->PopUnsignedShort()),
 
85
    event(sgd->PopObject<EventManager::Event>(GOT_EVENT))
 
86
{
 
87
}
 
88
 
 
89
void noCharburnerPile::Draw( int x, int y)
 
90
{
 
91
    switch(state)
 
92
    {
 
93
        case STATE_WOOD:
 
94
        {
 
95
            // Draw sand on which the wood stack is constructed
 
96
            LOADER.GetImageN("charburner_bobs", 25)->Draw(x, y);
 
97
 
 
98
            glArchivItem_Bitmap* image;
 
99
            if(step == 0)
 
100
                image = LOADER.GetImageN("charburner_bobs", 26);
 
101
            else
 
102
            {
 
103
                image = LOADER.GetImageN("charburner_bobs", 28);
 
104
 
 
105
                // Draw wood pile beneath the cover
 
106
                LOADER.GetImageN("charburner_bobs", 26)->Draw(x, y);
 
107
            }
 
108
 
 
109
            unsigned short progress = sub_step * image->getHeight() / CONSTRUCTION_WORKING_STEPS[step];
 
110
            unsigned short height = image->getHeight() - progress;
 
111
            if(progress != 0)
 
112
                image->Draw(x, y + height, 0, 0, 0, height, 0, progress);
 
113
        } return;
 
114
        case STATE_SMOLDERING:
 
115
        {
 
116
            LOADER.GetImageN("charburner_bobs", 27 + GameClient::inst().
 
117
                             GetGlobalAnimation(2, 10, 1, obj_id + this->x * 10 + this->y * 10))->Draw(x, y);
 
118
 
 
119
            // Dann Qualm zeichnen
 
120
            LOADER.GetMapImageN(692 + 1 * 8 + GAMECLIENT.GetGlobalAnimation(8, 5, 2, (this->x + this->y) * 100))
 
121
            ->Draw(x + 21, y - 11, 0, 0, 0, 0, 0, 0, 0x99EEEEEE);
 
122
            LOADER.GetMapImageN(692 + 2 * 8 + GAMECLIENT.GetGlobalAnimation(8, 5, 2, (this->x + this->y) * 100))
 
123
            ->Draw(x - 2, y - 06, 0, 0, 0, 0, 0, 0, 0x99EEEEEE);
 
124
            LOADER.GetMapImageN(692 + 1 * 8 + GAMECLIENT.GetGlobalAnimation(8, 5, 2, (this->x + this->y) * 100))
 
125
            ->Draw(x - 25, y - 11, 0, 0, 0, 0, 0, 0, 0x99EEEEEE);
 
126
            LOADER.GetMapImageN(692 + 3 * 8 + GAMECLIENT.GetGlobalAnimation(8, 5, 2, (this->x + this->y) * 100))
 
127
            ->Draw(x - 2, y - 35, 0, 0, 0, 0, 0, 0, 0x99EEEEEE);
 
128
        } return;
 
129
        case STATE_REMOVECOVER:
 
130
        {
 
131
            LOADER.GetImageN("charburner_bobs", 28 + step)->Draw(x, y);
 
132
        } return;
 
133
        case STATE_HARVEST:
 
134
        {
 
135
            LOADER.GetImageN("charburner_bobs", 34 + step)->Draw(x, y);
 
136
 
 
137
        } return;
 
138
        default: return;
 
139
    }
140
140
}
141
141
 
142
142
void noCharburnerPile::HandleEvent(const unsigned int id)
143
143
{
144
 
        // Smoldering is over 
145
 
        // Pile is ready for the remove of the cover
146
 
        state = STATE_REMOVECOVER;
147
 
        event = NULL;
 
144
    // Smoldering is over
 
145
    // Pile is ready for the remove of the cover
 
146
    state = STATE_REMOVECOVER;
 
147
    event = NULL;
148
148
}
149
149
 
150
150
 
151
151
/// Charburner has worked on it --> Goto next step
152
152
void noCharburnerPile::NextStep()
153
153
{
154
 
        switch(state)
155
 
        {
156
 
        default: return;
157
 
        case STATE_WOOD:
158
 
                {
159
 
                        ++sub_step;
160
 
                        if(sub_step == CONSTRUCTION_WORKING_STEPS[step])
161
 
                        {
162
 
                                ++step;
163
 
                                sub_step = 0;
164
 
 
165
 
                                // Reached new state?
166
 
                                if(step == 2)
167
 
                                {
168
 
                                        step = 0;
169
 
                                        state = STATE_SMOLDERING;
170
 
                                        event = em->AddEvent(this,SMOLDERING_LENGTH,0);
171
 
                                }
172
 
                        }
173
 
 
174
 
                } return;
175
 
        case STATE_REMOVECOVER:
176
 
                {
177
 
                        ++sub_step;
178
 
                        if(sub_step == REMOVECOVER_WORK_STEPS)
179
 
                        {
180
 
                                ++step;
181
 
                                sub_step = 0;
182
 
 
183
 
                                // Reached new state?
184
 
                                if(step == 6)
185
 
                                {
186
 
                                        state = STATE_HARVEST;
187
 
                                        step = 0;
188
 
                                }
189
 
                        }
190
 
 
191
 
                } return;
192
 
        case STATE_HARVEST:
193
 
                {
194
 
                        ++sub_step;
195
 
                        if(sub_step == HARVEST_WORK_STEPS)
196
 
                        {
197
 
                                ++step;
198
 
                                sub_step = 0;
199
 
 
200
 
                                // Reached new state?
201
 
                                if(step == 6)
202
 
                                {
203
 
                                        // Add an empty pile as environmental object
204
 
                                        gwg->SetNO(new noEnvObject(x,y,40,6),x,y);
205
 
                                        em->AddToKillList(this);
206
 
 
207
 
                                        // BQ drumrum neu berechnen
208
 
                                        gwg->RecalcBQAroundPoint(x,y);
209
 
                                }
210
 
                        }
211
 
                } return;
212
 
 
213
 
        }
 
154
    switch(state)
 
155
    {
 
156
        default: return;
 
157
        case STATE_WOOD:
 
158
        {
 
159
            ++sub_step;
 
160
            if(sub_step == CONSTRUCTION_WORKING_STEPS[step])
 
161
            {
 
162
                ++step;
 
163
                sub_step = 0;
 
164
 
 
165
                // Reached new state?
 
166
                if(step == 2)
 
167
                {
 
168
                    step = 0;
 
169
                    state = STATE_SMOLDERING;
 
170
                    event = em->AddEvent(this, SMOLDERING_LENGTH, 0);
 
171
                }
 
172
            }
 
173
 
 
174
        } return;
 
175
        case STATE_REMOVECOVER:
 
176
        {
 
177
            ++sub_step;
 
178
            if(sub_step == REMOVECOVER_WORK_STEPS)
 
179
            {
 
180
                ++step;
 
181
                sub_step = 0;
 
182
 
 
183
                // Reached new state?
 
184
                if(step == 6)
 
185
                {
 
186
                    state = STATE_HARVEST;
 
187
                    step = 0;
 
188
                }
 
189
            }
 
190
 
 
191
        } return;
 
192
        case STATE_HARVEST:
 
193
        {
 
194
            ++sub_step;
 
195
            if(sub_step == HARVEST_WORK_STEPS)
 
196
            {
 
197
                ++step;
 
198
                sub_step = 0;
 
199
 
 
200
                // Reached new state?
 
201
                if(step == 6)
 
202
                {
 
203
                    // Add an empty pile as environmental object
 
204
                    gwg->SetNO(new noEnvObject(x, y, 40, 6), x, y);
 
205
                    em->AddToKillList(this);
 
206
 
 
207
                    // BQ drumrum neu berechnen
 
208
                    gwg->RecalcBQAroundPoint(x, y);
 
209
                }
 
210
            }
 
211
        } return;
 
212
 
 
213
    }
214
214
}
215
215
 
216
216
 
217
217
noCharburnerPile::WareType noCharburnerPile::GetNeededWareType() const
218
218
{
219
 
        if(sub_step % 2 == 0)
220
 
                return WT_WOOD;
221
 
        else 
222
 
                return WT_GRAIN;
 
219
    if(sub_step % 2 == 0)
 
220
        return WT_WOOD;
 
221
    else
 
222
        return WT_GRAIN;
223
223
}