1 : |
agomez |
1 |
#include "fleet.h" |
2 : |
|
|
#include "areatime.h" |
3 : |
|
|
#include "keeper.h" |
4 : |
|
|
#include "totalpredator.h" |
5 : |
|
|
#include "linearpredator.h" |
6 : |
|
|
#include "numberpredator.h" |
7 : |
|
|
#include "effortpredator.h" |
8 : |
|
|
#include "quotapredator.h" |
9 : |
|
|
#include "readfunc.h" |
10 : |
|
|
#include "readword.h" |
11 : |
|
|
#include "errorhandler.h" |
12 : |
|
|
#include "gadget.h" |
13 : |
|
|
#include "global.h" |
14 : |
|
|
|
15 : |
|
|
Fleet::Fleet(CommentStream& infile, const char* givenname, const AreaClass* const Area,
|
16 : |
|
|
const TimeClass* const TimeInfo, Keeper* const keeper, FleetType ftype)
|
17 : |
|
|
: BaseClass(givenname), predator(0) {
|
18 : |
|
|
|
19 : |
|
|
type = ftype;
|
20 : |
|
|
char text[MaxStrLength];
|
21 : |
|
|
strncpy(text, "", MaxStrLength);
|
22 : |
|
|
ifstream subfile;
|
23 : |
|
|
CommentStream subcomment(subfile);
|
24 : |
|
|
int tmpint = 0;
|
25 : |
|
|
Formula multscaler;
|
26 : |
|
|
IntVector tmpareas;
|
27 : |
|
|
|
28 : |
|
|
keeper->addString("fleet");
|
29 : |
|
|
keeper->addString(this->getName());
|
30 : |
|
|
infile >> text >> ws;
|
31 : |
|
|
if (strcasecmp(text, "livesonareas") != 0)
|
32 : |
|
|
handle.logFileUnexpected(LOGFAIL, "livesonareas", text);
|
33 : |
|
|
|
34 : |
|
|
char c = infile.peek();
|
35 : |
|
|
while (isdigit(c) && !infile.eof()) {
|
36 : |
|
|
infile >> tmpint >> ws;
|
37 : |
|
|
tmpareas.resize(1, Area->getInnerArea(tmpint));
|
38 : |
|
|
c = infile.peek();
|
39 : |
|
|
}
|
40 : |
|
|
this->storeAreas(tmpareas);
|
41 : |
|
|
|
42 : |
|
|
infile >> ws;
|
43 : |
|
|
c = infile.peek();
|
44 : |
|
|
//JMB - removed the need to read in the fleet lengths
|
45 : |
|
|
if ((c == 'l') || (c == 'L')) {
|
46 : |
|
|
handle.logMessage(LOGWARN, "Warning in fleet - length data ignored");
|
47 : |
|
|
infile.get(c);
|
48 : |
|
|
while (c != '\n' && !infile.eof())
|
49 : |
|
|
infile.get(c);
|
50 : |
|
|
infile >> ws;
|
51 : |
|
|
c = infile.peek();
|
52 : |
|
|
}
|
53 : |
|
|
|
54 : |
|
|
if ((c == 'm') || (c == 'M'))
|
55 : |
|
|
readWordAndVariable(infile, "multiplicative", multscaler);
|
56 : |
|
|
else
|
57 : |
|
|
multscaler.setValue(1.0);
|
58 : |
|
|
|
59 : |
|
|
switch (type) {
|
60 : |
|
|
case TOTALFLEET:
|
61 : |
|
|
predator = new TotalPredator(infile, this->getName(), areas, TimeInfo, keeper, multscaler);
|
62 : |
|
|
break;
|
63 : |
|
|
case LINEARFLEET:
|
64 : |
|
|
predator = new LinearPredator(infile, this->getName(), areas, TimeInfo, keeper, multscaler);
|
65 : |
|
|
break;
|
66 : |
|
|
case NUMBERFLEET:
|
67 : |
|
|
predator = new NumberPredator(infile, this->getName(), areas, TimeInfo, keeper, multscaler);
|
68 : |
|
|
break;
|
69 : |
|
|
case EFFORTFLEET:
|
70 : |
|
|
predator = new EffortPredator(infile, this->getName(), areas, TimeInfo, keeper, multscaler);
|
71 : |
|
|
break;
|
72 : |
|
|
case QUOTAFLEET:
|
73 : |
|
|
predator = new QuotaPredator(infile, this->getName(), areas, TimeInfo, keeper, multscaler);
|
74 : |
|
|
break;
|
75 : |
|
|
default:
|
76 : |
|
|
handle.logMessage(LOGFAIL, "Error in fleet - unrecognised fleet type for", this->getName());
|
77 : |
|
|
}
|
78 : |
|
|
|
79 : |
|
|
//the next entry in the file will be the name of the amounts datafile
|
80 : |
|
|
infile >> text >> ws;
|
81 : |
|
|
subfile.open(text, ios::in);
|
82 : |
|
|
handle.checkIfFailure(subfile, text);
|
83 : |
|
|
handle.Open(text);
|
84 : |
|
|
readAmounts(subcomment, areas, TimeInfo, Area, amount, this->getName());
|
85 : |
|
|
amount.Inform(keeper);
|
86 : |
|
|
handle.Close();
|
87 : |
|
|
subfile.close();
|
88 : |
|
|
subfile.clear();
|
89 : |
|
|
|
90 : |
|
|
//resize tmpPopulation, and set the weight to 1 since this will never change
|
91 : |
|
|
PopInfo tmppop;
|
92 : |
|
|
tmppop.W = 1.0;
|
93 : |
|
|
tmpPopulation.AddRows(Area->numAreas(), 1, tmppop);
|
94 : |
|
|
|
95 : |
|
|
keeper->clearLast();
|
96 : |
|
|
keeper->clearLast();
|
97 : |
|
|
}
|
98 : |
|
|
|
99 : |
|
|
Fleet::~Fleet() {
|
100 : |
|
|
delete predator;
|
101 : |
|
|
}
|
102 : |
|
|
|
103 : |
|
|
void Fleet::calcEat(int area,
|
104 : |
|
|
const AreaClass* const Area, const TimeClass* const TimeInfo) {
|
105 : |
|
|
|
106 : |
|
|
if (this->isFleetStepArea(area, TimeInfo))
|
107 : |
|
|
predator->Eat(area, Area, TimeInfo);
|
108 : |
|
|
}
|
109 : |
|
|
|
110 : |
|
|
void Fleet::adjustEat(int area, const TimeClass* const TimeInfo) {
|
111 : |
|
|
if (this->isFleetStepArea(area, TimeInfo))
|
112 : |
|
|
predator->adjustConsumption(area, TimeInfo);
|
113 : |
|
|
}
|
114 : |
|
|
|
115 : |
|
|
void Fleet::calcNumbers(int area, const TimeClass* const TimeInfo) {
|
116 : |
|
|
if (this->isFleetStepArea(area, TimeInfo))
|
117 : |
|
|
predator->Sum(tmpPopulation[this->areaNum(area)], area);
|
118 : |
|
|
}
|
119 : |
|
|
|
120 : |
|
|
void Fleet::Reset(const TimeClass* const TimeInfo) {
|
121 : |
|
|
int i;
|
122 : |
|
|
predator->Reset(TimeInfo);
|
123 : |
|
|
for (i = 0; i < tmpPopulation.Nrow(); i++)
|
124 : |
|
|
if (this->isFleetStepArea(i, TimeInfo))
|
125 : |
|
|
tmpPopulation[this->areaNum(i)][0].N = amount[TimeInfo->getTime()][this->areaNum(i)];
|
126 : |
|
|
}
|
127 : |
|
|
|
128 : |
|
|
void Fleet::Print(ofstream& outfile) const {
|
129 : |
|
|
outfile << "\nFleet - type ";
|
130 : |
|
|
predator->Print(outfile);
|
131 : |
|
|
}
|
132 : |
|
|
|
133 : |
|
|
int Fleet::isFleetStepArea(int area, const TimeClass* const TimeInfo) {
|
134 : |
|
|
if ((this->isInArea(area) == 0) || isZero(predator->getMultScaler()))
|
135 : |
|
|
return 0;
|
136 : |
|
|
if (amount[TimeInfo->getTime()][this->areaNum(area)] < 0.0)
|
137 : |
|
|
handle.logMessage(LOGWARN, "Warning in fleet - negative amount consumed for", this->getName());
|
138 : |
|
|
if ((predator->getType() == QUOTAPREDATOR) && (TimeInfo->getStep() == 1))
|
139 : |
|
|
return 1; //JMB need to check the first step
|
140 : |
|
|
if (isZero(amount[TimeInfo->getTime()][this->areaNum(area)]))
|
141 : |
|
|
return 0;
|
142 : |
|
|
return 1;
|
143 : |
|
|
}
|