forked from Atlantis-PBEM/Atlantis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.cpp
155 lines (139 loc) · 3.33 KB
/
market.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
// START A3HEADER
//
// This source file is part of the Atlantis PBM game program.
// Copyright (C) 1995-1999 Geoff Dunbar
//
// This program 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.
//
// This program 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 this program, in the file license.txt. If not, write
// to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// See the Atlantis Project web page for details:
// http://www.prankster.com/project
//
// END A3HEADER
#include "market.h"
#include "items.h"
#include "gameio.h"
#include "gamedata.h"
Market::Market()
{
activity = 0;
}
Market::Market(int a, int b, int c, int d, int e, int f, int g, int h)
{
type = a;
item = b;
price = c;
amount = d;
minpop = e;
maxpop = f;
minamt = g;
maxamt = h;
baseprice = price;
activity = 0;
}
void Market::PostTurn(int population, int wages)
{
// Nothing to do to the markets.
if (!(Globals->VARIABLE_ECONOMY)) return;
//
// Unlimited, unchanging market.
//
if (amount == -1) return;
if (ItemDefs[item].type & IT_MAN) {
float ratio = ItemDefs[item].baseprice /
(10 * (float)Globals->BASE_MAN_COST);
// hack: included new wage factor of ten in float assignment above
price = (int)((float) wages * 4 * ratio);
if (ItemDefs[item].type & IT_LEADER)
amount = population / 125;
else
amount = population / 25;
return;
}
int tarprice = price;
if (amount) {
int fluctuation = (baseprice * activity)/amount;
if (type == M_BUY)
tarprice = (2 * baseprice + fluctuation) / 2;
else
tarprice = (3 * baseprice - fluctuation) / 2;
}
price = price + (tarprice - price) / 5;
if (population <= minpop)
amount = minamt;
else {
if (population >= maxpop)
amount = maxamt;
else {
amount = minamt + ((maxamt - minamt) *
(population - minpop)) /
(maxpop - minpop);
}
}
}
void Market::Writeout(Aoutfile *f)
{
f->PutInt(type);
if (item != -1) f->PutStr(ItemDefs[item].abr);
else f->PutStr("NO_ITEM");
f->PutInt(price);
f->PutInt(amount);
f->PutInt(minpop);
f->PutInt(maxpop);
f->PutInt(minamt);
f->PutInt(maxamt);
f->PutInt(baseprice);
}
void Market::Readin(Ainfile *f)
{
AString *temp;
type = f->GetInt();
temp = f->GetStr();
item = LookupItem(temp);
delete temp;
price = f->GetInt();
amount = f->GetInt();
minpop = f->GetInt();
maxpop = f->GetInt();
minamt = f->GetInt();
maxamt = f->GetInt();
baseprice = f->GetInt();
}
AString Market::Report()
{
AString temp;
temp += ItemString(item, amount) + " at $" + price;
return temp;
}
void MarketList::PostTurn(int population, int wages)
{
forlist(this) {
((Market *) elem)->PostTurn(population, wages);
}
}
void MarketList::Writeout(Aoutfile *f)
{
f->PutInt(Num());
forlist (this) ((Market *) elem)->Writeout(f);
}
void MarketList::Readin(Ainfile *f)
{
int n = f->GetInt();
for (int i=0; i<n; i++) {
Market *m = new Market;
m->Readin(f);
Add(m);
}
}