Skip to content

Commit

Permalink
Fix to reading in larger BASE coordinate values
Browse files Browse the repository at this point in the history
Have increase the size of the bit mask to 0x7f, this works for 64 and 128 maps.
  • Loading branch information
screamingchicken authored Jul 30, 2021
1 parent 059709c commit 06a73cd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions CnCTDRAMapEditor/TiberianDawn/GamePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,9 @@ private IEnumerable<string> LoadINI(INI ini)
if (buildingType != null)
{
var coord = int.Parse(tokens[1]);
var location = new Point((coord >> 8) & 0x3F, (coord >> 24) & 0x3F);
// Megamap support - bitwise AND needs to be larger
// var location = new Point((coord >> 8) & 0x3F, (coord >> 24) & 0x3F);
var location = new Point((coord >> 8) & 0x7F, (coord >> 24) & 0x7F);
if (Map.Buildings.OfType<Building>().Where(x => x.Location == location).FirstOrDefault().Occupier is Building building)
{
building.BasePriority = priority;
Expand Down Expand Up @@ -842,7 +844,7 @@ private void LoadBinary(BinaryReader reader)
{
/*
** Format for this is e.g. 0F 00
** Cell number = every cell gets 2 bytes in the bin file
** Cell number = not required as every cell gets 2 bytes in the bin file
** Template = 0x0F
** Icon = 0x00
*/
Expand Down Expand Up @@ -1086,7 +1088,9 @@ private void SaveINI(INI ini, FileType fileType)

baseSection[key] = string.Format("{0},{1}",
building.Type.Name.ToUpper(),
((location.Y & 0x3F) << 24) | ((location.X & 0x3F) << 8)
// Megamap support - bitwise AND needs to be larger
// ((location.Y & 0x3F) << 24) | ((location.X & 0x3F) << 8)
((location.Y & 0x7F) << 24) | ((location.X & 0x7F) << 8)
);
}
baseSection["Count"] = baseBuildings.Length.ToString();
Expand Down

0 comments on commit 06a73cd

Please sign in to comment.