summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/skills.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2012-07-31 11:11:42 +0200
committerAdam Borowski <kilobyte@angband.pl>2012-07-31 23:22:42 +0200
commit3ef95bb148bdda6eea384d85c9c9ae012d273686 (patch)
treefeb22ca6438756ed60222c51b3c2020925954bab /crawl-ref/source/skills.cc
parent2679906a01466ccad88248ddfd067c454cce210d (diff)
downloadcrawl-ref-3ef95bb148bdda6eea384d85c9c9ae012d273686.tar.gz
crawl-ref-3ef95bb148bdda6eea384d85c9c9ae012d273686.zip
Actually fix loading dumps on most architectures.
The only popular one where this works is amd64, and even that reached 50% use in Linux on desktops/laptops only recently. Linux i386, Windows, arm*, etc, are still 32 bit, so are many less popular platforms. Nearly any use of "long" in portable code is a bug, except for some things where using a full machine word improves efficiency but you can still handle shorter words properly. Elsewhere else, either an int is enough (and you'd waste memory on 64 bit), or int is not enough and it will overflow on 32 bit.
Diffstat (limited to 'crawl-ref/source/skills.cc')
-rw-r--r--crawl-ref/source/skills.cc16
1 files changed, 8 insertions, 8 deletions
diff --git a/crawl-ref/source/skills.cc b/crawl-ref/source/skills.cc
index 9779cc7e2f..488429bdb4 100644
--- a/crawl-ref/source/skills.cc
+++ b/crawl-ref/source/skills.cc
@@ -490,8 +490,8 @@ void init_train()
}
}
-static bool _cmp_rest(const std::pair<skill_type,long>& a,
- const std::pair<skill_type,long>& b)
+static bool _cmp_rest(const std::pair<skill_type, int64_t>& a,
+ const std::pair<skill_type, int64_t>& b)
{
return a.second < b.second;
}
@@ -507,12 +507,12 @@ static bool _cmp_rest(const std::pair<skill_type,long>& a,
template <typename T, int SIZE>
static void _scale_array(FixedVector<T, SIZE> &array, int scale, bool exact)
{
- long total = 0;
+ int64_t total = 0;
// First, we calculate the sum of the values to be scaled.
for (int i = 0; i < NUM_SKILLS; ++i)
total += array[i];
- std::vector<std::pair<skill_type,long> > rests;
+ std::vector<std::pair<skill_type, int64_t> > rests;
int scaled_total = 0;
// All skills disabled, nothing to do.
@@ -523,10 +523,10 @@ static void _scale_array(FixedVector<T, SIZE> &array, int scale, bool exact)
for (int i = 0; i < NUM_SKILLS; ++i)
if (array[i] > 0)
{
- long result = (long)array[i] * (long)scale;
- const long rest = result % total;
+ int64_t result = (int64_t)array[i] * (int64_t)scale;
+ const int64_t rest = result % total;
if (rest)
- rests.push_back(std::pair<skill_type,long>(skill_type(i),rest));
+ rests.push_back(std::pair<skill_type, int64_t>(skill_type(i), rest));
array[i] = (int)(result / total);
scaled_total += array[i];
}
@@ -539,7 +539,7 @@ static void _scale_array(FixedVector<T, SIZE> &array, int scale, bool exact)
// We ensure that the percentage always add up to 100 by increasing the
// training for skills which had the higher rest from the above scaling.
std::sort(rests.begin(), rests.end(), _cmp_rest);
- std::vector<std::pair<skill_type,long> >::iterator it = rests.begin();
+ std::vector<std::pair<skill_type, int64_t> >::iterator it = rests.begin();
while (scaled_total < scale && it != rests.end())
{
++array[it->first];