Ticket #4012: placer_fix2016-6-28.diff
File placer_fix2016-6-28.diff, 3.8 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/maps/random/rmgen/library.js
6 6 const HEIGHT_UNITS_PER_METRE = 92; 7 7 const MIN_MAP_SIZE = 128; 8 8 const MAX_MAP_SIZE = 512; 9 const MAP_BORDER_WIDTH = 3; 9 10 const FALLBACK_CIV = "athen"; 10 11 /** 11 12 * Constants needed for heightmap_manipulation.js … … 283 284 284 285 function placeObject(x, z, type, player, angle) 285 286 { 286 if (g_Map.validT(x, z, 3))287 if (g_Map.validT(x, z, MAP_BORDER_WIDTH)) 287 288 g_Map.addObject(new Entity(type, player, x, z, angle)); 288 289 } 289 290 -
binaries/data/mods/public/maps/random/rmgen/placer.js
453 453 { 454 454 failCount++; 455 455 if (failCount > maxFailCount) 456 {457 456 return undefined; 458 }459 457 } 460 458 } 461 459 } … … 555 553 { 556 554 failCount++; 557 555 if (failCount > maxFailCount) 558 {559 556 return undefined; 560 }561 557 } 562 558 } 563 559 } … … 602 598 else 603 599 { 604 600 for (var j = 0; j < objs.length; ++j) 605 {606 601 resultObjs.push(objs[j]); 607 }608 602 } 609 603 } 610 604 … … 612 606 length = resultObjs.length; 613 607 for (var i=0; i < length; i++) 614 608 { 615 if (g_Map.validT(r ound(resultObjs[i].position.x/CELL_SIZE), round(resultObjs[i].position.z/CELL_SIZE), 3))609 if (g_Map.validT(resultObjs[i].position.x / CELL_SIZE, resultObjs[i].position.z / CELL_SIZE, MAP_BORDER_WIDTH)) 616 610 g_Map.addObject(resultObjs[i]); 617 611 612 // Convert position to integer number of tiles 618 613 if (this.tileClass !== undefined) 619 { // Convert position to integer number of tiles620 614 this.tileClass.add(Math.floor(resultObjs[i].position.x/CELL_SIZE), Math.floor(resultObjs[i].position.z/CELL_SIZE)); 621 }622 615 } 623 616 624 617 return true; … … 653 646 var placer = this.elements[randInt(this.elements.length)]; 654 647 655 648 var objs = placer.place(this.x, this.z, player, this.avoidSelf, constraint); 649 // Failure 656 650 if (objs === undefined) 657 { // Failure651 { 658 652 return false; 659 653 } 660 654 else 661 655 { 662 656 for (var j = 0; j < objs.length; ++j) 663 {664 657 resultObjs.push(objs[j]); 665 }666 658 } 667 659 668 660 // Add placed objects to map … … 671 663 { 672 664 g_Map.addObject(resultObjs[i]); 673 665 666 // Convert position to integer number of tiles 674 667 if (this.tileClass !== undefined) 675 { // Convert position to integer number of tiles676 668 this.tileClass.add(Math.floor(resultObjs[i].position.x/CELL_SIZE), Math.floor(resultObjs[i].position.z/CELL_SIZE)); 677 }678 669 } 679 670 680 671 return true; -
binaries/data/mods/public/maps/random/rmgen/terrain.js
31 31 function SimpleTerrain(texture, treeType) 32 32 { 33 33 if (texture === undefined) 34 {35 34 throw("SimpleTerrain: texture not defined"); 36 }37 35 38 36 this.texture = texture; 39 37 this.treeType = treeType; … … 43 41 SimpleTerrain.prototype.constructor = SimpleTerrain; 44 42 SimpleTerrain.prototype.placeNew = function(x, z) 45 43 { 46 if (this.treeType !== undefined && g_Map.validT(round(x), round(z), 3)) 47 { 44 if (this.treeType !== undefined && g_Map.validT(round(x), round(z), MAP_BORDER_WIDTH)) 48 45 g_Map.terrainObjects[x][z] = new Entity(this.treeType, 0, x+0.5, z+0.5, randFloat()*TWO_PI); 49 }50 46 51 47 g_Map.texture[x][z] = g_Map.getTextureID(this.texture); 52 48 }; … … 63 59 function RandomTerrain(terrains) 64 60 { 65 61 if (!(terrains instanceof Array) || !terrains.length) 66 {67 62 throw("RandomTerrain: Invalid terrains array"); 68 }69 63 70 64 this.terrains = terrains; 71 65 }