Skip to content

Commit

Permalink
Merge pull request #7 from sebamarynissen/feature/plop
Browse files Browse the repository at this point in the history
Allow growified residentials to be redeveloped
  • Loading branch information
sebamarynissen committed Jul 13, 2020
2 parents ee7bee8 + c7812c2 commit 257b380
Show file tree
Hide file tree
Showing 33 changed files with 2,749 additions and 511 deletions.
22 changes: 19 additions & 3 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,32 @@ exports.growify = async function(opts) {
opts = Object.assign(Object.create(baseOptions), opts);
let dbpf = open(opts.dbpf);

// Get the SimGrid with the ZoneData information because that needs to be
// updated as well.
const ZoneData = 0x41800000;
let grid = dbpf.getSimGrid(FileType.SimGridSint8, ZoneData);

// Helper function that will update the zoneType in the SimGrid as well
// when growifying.
function setType(lot, zoneType) {
lot.zoneType = zoneType;
for (let x = lot.minX; x <= lot.maxX; x++) {
for (let z = lot.minZ; z <= lot.maxZ; z++) {
grid.set(x, z, zoneType);
}
}
}

let rCount = 0, iCount = 0, aCount = 0;
for (let lot of dbpf.lotFile) {
if (opts.residential && lot.isPloppedResidential) {
lot.zoneType = opts.residential;
setType(lot, opts.residential);
rCount++;
} else if (opts.industrial && lot.isPloppedIndustrial) {
lot.zoneType = opts.industrial;
setType(lot, opts.industrial);
iCount++;
} else if (opts.agricultural && lot.isPloppedAgricultural) {
lot.zoneType = opts.agricultural;
setType(lot, opts.agricultural);
aCount++;
}
}
Expand Down
17 changes: 10 additions & 7 deletions lib/building.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@ const Type = require('./type');
// Represents a single building from the building file.
const Building = class Building extends Type(FileType.BuildingFile) {

// ## constructor()
constructor() {
// ## constructor(opts)
constructor(opts) {
super();
this.crc = 0x00000000;
this.mem = 0x00000000;
this.major = 0x0002;
this.minor = 0x0004;
this.zotWord = 0x0;
this.unknown1 = 0x00;
this.appearance = 0x04;
this.appearance = 0b00000101;
this.xMinTract = 0x00;
this.zMinTract = 0x00;
this.xMaxTract = 0x00;
this.zMaxTract = 0x00;
this.xTractSize = 0x0002;
this.zTractSize = 0x0002;
this.sgprops = [];
this.unknown2 = 0x01;
this.unknown2 = 0x00;
this.IID1 = this.IID = this.TID = this.GID = 0x00000000;
this.minZ = this.minY = this.minX = 0;
this.maxZ = this.maxY = this.maxX = 0;
this.orientation = 0x00;
this.scaffold = 0;
this.scaffold = 0x01;
Object.assign(this, opts);
}

// ## move(dx, dy, dz)
Expand Down Expand Up @@ -100,11 +101,13 @@ const Building = class Building extends Type(FileType.BuildingFile) {
prop.parse(rs);
}

this.unknown2 = rs.byte();
// There seems to be an error in the Wiki. The unknown byte should
// come **after** the IID1, otherwise they're incorrect.
this.GID = rs.dword();
this.TID = rs.dword();
this.IID = rs.dword();
this.IID1 = rs.dword();
this.unknown2 = rs.byte();
this.minX = rs.float();
this.minY = rs.float();
this.minZ = rs.float();
Expand Down Expand Up @@ -158,11 +161,11 @@ const Building = class Building extends Type(FileType.BuildingFile) {
// Serialize the fixed remainder.
let two = Buffer.allocUnsafe(46);
ws = new WriteStream(two);
ws.byte(this.unknown2);
ws.dword(this.GID);
ws.dword(this.TID);
ws.dword(this.IID);
ws.dword(this.IID1);
ws.byte(this.unknown2);
ws.float(this.minX);
ws.float(this.minY);
ws.float(this.minZ);
Expand Down
Loading

0 comments on commit 257b380

Please sign in to comment.