summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan O'Rear <stefanor@cox.net>2010-01-05 00:28:18 -0800
committerStefan O'Rear <stefanor@cox.net>2010-01-05 00:28:18 -0800
commit150e49039869a03a1788e8c005a9b6abccd4b8f3 (patch)
treed15d801ff0959805f5f68c36c8c0606ceefc3012
parentb7392f433201f7051bd3ee5c19911ecf047ede9b (diff)
downloadcrawl-ref-150e49039869a03a1788e8c005a9b6abccd4b8f3.tar.gz
crawl-ref-150e49039869a03a1788e8c005a9b6abccd4b8f3.zip
Fix marshalling of beholders and unrandarts (#338)
Beholders were getting saved as signed bytes, so any mermaid with a monster index higher than 127 would come out as a negative number, crashes ensuing. Only the first 50 unrandart existance entries were getting saved, allowing roughly 1/3 of the unrandarts to be created multiple times.
-rw-r--r--crawl-ref/source/tags.cc23
-rw-r--r--crawl-ref/source/tags.h1
2 files changed, 17 insertions, 7 deletions
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 8309c17566..816edcf061 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -1113,9 +1113,9 @@ static void tag_construct_you(writer &th)
// be recalculated on game start.
// List of currently beholding monsters (usually empty).
- marshallByte(th, you.beholders.size());
+ marshallShort(th, you.beholders.size());
for (unsigned int k = 0; k < you.beholders.size(); k++)
- marshallByte(th, you.beholders[k]);
+ marshallShort(th, you.beholders[k]);
marshallByte(th, you.piety_hysteresis);
@@ -1165,8 +1165,8 @@ static void tag_construct_you_items(writer &th)
marshallByte(th, static_cast<char>(identy[i][j]));
// how many unique items?
- marshallByte(th, 50);
- for (j = 0; j < 50; ++j)
+ marshallByte(th, MAX_UNRANDARTS);
+ for (j = 0; j < MAX_UNRANDARTS; ++j)
marshallByte(th,you.unique_items[j]);
marshallByte(th, NUM_FIXED_BOOKS);
@@ -1547,9 +1547,18 @@ static void tag_read_you(reader &th, char minorVersion)
you.water_in_sight = -1;
// List of currently beholding monsters (usually empty).
- count_c = unmarshallByte(th);
- for (i = 0; i < count_c; i++)
- you.beholders.push_back(unmarshallByte(th));
+ if (minorVersion >= TAG_MINOR_BEHELD16)
+ {
+ count_c = unmarshallShort(th);
+ for (i = 0; i < count_c; i++)
+ you.beholders.push_back(unmarshallShort(th));
+ }
+ else
+ {
+ count_c = unmarshallByte(th);
+ for (i = 0; i < count_c; i++)
+ you.beholders.push_back(unmarshallByte(th));
+ }
you.piety_hysteresis = unmarshallByte(th);
diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h
index dd04e1df0e..d694e14aae 100644
--- a/crawl-ref/source/tags.h
+++ b/crawl-ref/source/tags.h
@@ -47,6 +47,7 @@ enum tag_major_version
enum tag_minor_version
{
TAG_MINOR_RESET = 0, // Minor tags were reset
+ TAG_MINOR_BEHELD16 = 1, // Use correct type sizes for beholders
TAG_MINOR_VERSION = 1 // Current version. (Keep equal to max.)
};