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
|
// $Id: RoadSegment.h 9357 2014-04-25 15:35:25Z FloSoft $
//
// Copyright (c) 2005 - 2011 Settlers Freaks (sf-team at siedler25.org)
//
// This file is part of Return To The Roots.
//
// Return To The Roots 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 2 of the License, or
// (at your option) any later version.
//
// Return To The Roots 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 Return To The Roots. If not, see <http://www.gnu.org/licenses/>.
#ifndef ROADSEGMENT_H_INCLUDED
#define ROADSEGMENT_H_INCLUDED
#pragma once
#include "GameObject.h"
class nofCarrier;
class noRoadNode;
class noFlag;
class noFigure;
class RoadSegment : public GameObject
{
public:
enum RoadType
{
RT_NORMAL, ///< Normale Straße bzw. Bergstraße
RT_DONKEY, ///< Eselstraße
RT_BOAT ///< Wasserstraße
};
public:
RoadSegment(const RoadType rt, noRoadNode* const f1, noRoadNode* const f2, const std::vector<unsigned char>& route);
RoadSegment(SerializedGameData* sgd, const unsigned obj_id);
/// zerstört das Objekt.
void Destroy(void) { Destroy_RoadSegment(); }
/// serialisiert das Objekt.
void Serialize(SerializedGameData* sgd) const { Serialize_RoadSegment(sgd); }
/// liefert den GO-Type.
inline GO_Type GetGOT() const { return GOT_ROADSEGMENT; }
/// Gibt die ID (0 oder 1) eines RoadNodes dieser Straße zurück (die Flagge muss zu dieser Straße gehören, sonst kommt Müll raus!!)
inline bool GetNodeID(const noRoadNode* rn) { return (rn == f2); }
/// Gibt Straßen-Typ zurück
inline RoadType GetRoadType() const { return rt; }
/// Gibt die Länge der Staße zurück
inline unsigned GetLength() const { return route.size(); }
/// gibt Flagge 1 zurück
inline noRoadNode* GetF1() const { return f1; }
/// setzt Flagge 1 auf o
inline void SetF1(noRoadNode* o) { f1 = o; }
/// gibt Flagge 2 zurück
inline noRoadNode* GetF2() const { return f2; }
/// setzt Flagge 2 auf o
inline void SetF2(noRoadNode* o) { f2 = o; }
/// gibt die Route nr zurück
inline unsigned char GetRoute(unsigned short nr) const { return route.at(nr); }
/// setzt die Route nr auf r
inline void SetRoute(unsigned short nr, unsigned char r) { route[nr] = r; }
/// gibt den Carrier nr zurück
inline nofCarrier* getCarrier(unsigned char nr) const { return carrier[nr]; }
/// setzt den Carrier nr auf c
inline void setCarrier(unsigned char nr, nofCarrier* c) { carrier[nr] = c; }
/// haben wir den Carrier "nr"?
inline bool hasCarrier(unsigned char nr) const { return (carrier[nr] != NULL); }
/// Braucht die Straße einen Esel? Nur wenn sie auch einen Träger schon hat!
inline bool NeedDonkey() const { return (rt == RT_DONKEY && carrier[0] && !carrier[1]); }
/// Hat einen Esel als Arbeiter dazubekommen.
inline void GotDonkey(nofCarrier* donkey) { assert(!carrier[1]); carrier[1] = donkey; }
/// haben wir überhaupt Carrier?
inline bool isOccupied() const
{
return((carrier[0]) || (carrier[1]));
}
inline unsigned char GetDir(const bool dir, const unsigned int id) const
{
if(dir)
return (route[route.size() - id - 1] + 3) % 6;
else
return route[id];
}
/// zerteilt die Straße in 2 Teile.
void SplitRoad(noFlag* splitflag);
/// Überprüft ob es an den Flaggen noch Waren zu tragen gibt für den Träger.
bool AreWareJobs(const bool flag, unsigned int carrier_type, const bool take_ware_immediately) const;
/// Eine Ware sagt Bescheid, dass sie über dem Weg getragen werden will.
void AddWareJob(const noRoadNode* rn);
/// Eine Ware will nicht mehr befördert werden.
void WareJobRemoved(const noFigure* const exception);
/// Baut die Straße zu einer Eselstraße aus.
void UpgradeDonkeyRoad();
/// Soll versuchen einen Esel zu bekommen.
void TryGetDonkey();
/// Ein Träger muss kündigen, aus welchen Gründen auch immer.
void CarrierAbrogated(nofCarrier* carrier);
/// given a flag returns the other end location
noFlag* GetOtherFlag(const noFlag* flag);
/// given a flag returns last direction of the route towards the other flag
unsigned char GetOtherFlagDir(const noFlag* flag);
protected:
/// zerstört das Objekt.
void Destroy_RoadSegment(void);
/// serialisiert das Objekt.
void Serialize_RoadSegment(SerializedGameData* sgd) const;
private:
/// Straßentyp
RoadType rt;
/// die 2 Roadnodes, die den Weg eingrenzen
noRoadNode* f1, *f2;
/// Beschreibung des Weges, ist length groß und liegt als Beschreibung der einzelnen Richtungen vor (von f1 zu f2)
std::vector<unsigned char> route;
/// Träger (und ggf. Esel), der auf diesem Weg arbeitet
nofCarrier* carrier[2];
};
#endif // !ROADSEGMENT_H_INCLUDED
|