World of Banished

MODS Garage => Tips and Help => Topic started by: gl4d0s on October 26, 2017, 11:50:23 AM

Title: Terrain Help
Post by: gl4d0s on October 26, 2017, 11:50:23 AM
Hello, new modder here. Can someone explain how to add textures to a terrain type? Or send me an example?

I'm trying to add textures to a desert terrain I created.

I tried copying "Terrain.rsc", changing the contents to point to my new image files, and naming it DesertTerrain.rsc. Then changed this line in my "Game/Terrain/Desert.rsc":

WeakMaterialInstance _terrainMaterial = "Terrain/DesertTerrain.rsc";

But I get this error when I try to start a new game:

Assert: _resource != NULL || _path.GetLength() == 0 Error, shouldn't be dereferencing a weak pointer that is NULL!

C:\Projects\Buildy\code\Runtime\Object/ExternalPtr.h(194)

Callstack:
Application-x64-profile.exe(0x0000000043fa1c35)
Application-x64-profile.exe(0x0000000043f980cb)
Application-x64-profile.exe(0x0000000043f74209)
Runtime-x64-profile.dll(0x0000000086215181)
Runtime-x64-profile.dll(0x00000000861de48c)
MSVCR110.dll(0x0000000090f13fef)
MSVCR110.dll(0x0000000090f14196)
KERNEL32.DLL(0x00000000a10313d2)
ntdll.dll(0x00000000a17554f4)


I can't figure out what I'm doing wrong. Please help.
Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 12:29:27 PM
first you need to call this inside your MyModRescource.rsc file:

"Game/Terrain/TerrainList.rsc",


then inside a copy of the TerrainList.rsc you explain the new terrain type you want to add like:

ExternalList resource
{
External _resources
[
"Game/Terrain/Valleys.rsc",
"Game/Terrain/Mountains.rsc",
"Game/Terrain/MyOwnDesert.rsc",
]
}


then you go back to your MyModRecesource.rsc file and you add:

"Game/Terrain/MyOwnDesert.rsc",
"Terrain/MyOwnDesertTerrain.rsc",


now you do your Game/Terrain/MyOwnDesert.rsc like:

TerrainGenerator resource
{
StringTable _stringTable = "UI/MyOwnModStringTable.rsc"; // the name of your stringtable
String _text = "DesertMap"; // the name you gave to your new desert map
bool _exposed = true;

// materials
WeakMaterialInstance _terrainMaterial = "Terrain/MyOwnDesertTerrain.rsc";
WeakMaterialInstance _riverMaterial = "Terrain/River.rsc";
WeakMaterialInstance _lakeMaterial = "Terrain/Lake.rsc";

// size of the map
Feature _features
[
// ------ small ---------
{
int _mapSize = 256;
... (and put all your own numbers for small/med/large with the numbers of river/lake/mountains/etc...)
....


and then you go to make your Terrain/MyOwnDesertTerrain.rsc and define your 4 textures the game needs:

MaterialInstance resource
{
Material _material = "Material\Terrain\TerrainMaterial.rsc";
Texture _textures
[
{
String _name = "grass";
ImageBuffer _texture = "Terrain\MyOwnDesertTerrainGrassTexture.rsc";
}
{
String _name = "dirt";
ImageBuffer _texture = "Terrain\MyOwnDesertTerrainDirtTexture.rsc";
}
{
String _name = "rock";
ImageBuffer _texture = "Terrain\MyOwnDesertTerrainRockTexture.rsc";
}
{
String _name = "snow";
ImageBuffer _texture = "Terrain\TerrainSnowTexture.rsc";
}
]
}


then you define each type of textures and linking them each to a 1024x1024 .png ( like this example of the MyOwnDesertTerrainGrass one )

ImageBuffer resource : "Texture/TerrainTexture.rsc"
{
String _imageName = "Terrain\MyOwnDesertTerrainGrass.png";
}
Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 12:31:00 PM
of course dont forget to fill the entries in your stringtable and decide the words you will be using at the screen to read your new option you just added.


// ------------ My New Terrain ---------------------------
{ String _name = "DesertMap"; String _text = "Desert"; }
Title: Re: Terrain Help
Post by: gl4d0s on October 26, 2017, 02:56:12 PM
I started over and tried my best to copy everything you said, but I still get the same error when I start a new game with my desert terrain.

JTerrainsResource.rsc:


ExternalList resource
{
External _resources

[
"Game/Terrain/TerrainList.rsc",
"Game/Terrain/JValleys.rsc",
"Game/Terrain/JMountains.rsc",
"Game/Terrain/JPlains.rsc",
"Game/Terrain/JMarsh.rsc",
"Game/Terrain/JDesert.rsc",
"Game/Terrain/JJungle.rsc",
"Terrain/JDesertTerrain.rsc"
]
}


Game/Terrain/JDesert.rsc

TerrainGenerator resource
{
StringTable _stringTable = "Dialog/JStringTable.rsc:terrainType";
String _text = "JDesert";
bool _exposed = true;

// materials
WeakMaterialInstance _terrainMaterial = "Terrain/JDesertTerrain.rsc";
WeakMaterialInstance _riverMaterial = "Terrain/River.rsc";
WeakMaterialInstance _lakeMaterial = "Terrain/Lake.rsc";

// size of the map
Feature _features
[


// ------ tiny ---------
{
int _mapSize = 192;

// number of flat areas
int _flatAreaCount = 100;

// size of flat areas
int _minFlatAreaSize = 20;
int _maxFlatAreaSize = 30;

// number of areas to avoid
int _avoidAreaCount = 4;

// size of avoidance areas
int _minAvoidSize = 20;
int _maxAvoidSize = 30;

// how many close nodes to connect to
int _flatAreaConnections = 3;

// rivers
int _streamCount = 0;

// erosion
int _erosion = 4000000;

// number of lakes
int _minLakeCount = 0;
int _maxLakeCount = 0;

// lake size
int _minLakeSize = 20;
int _maxLakeSize = 30;

// number of parts per lake
int _lakePartCount = 40;

// part sizes
int _minLakePartSize = 6;
int _maxLakePartSize = 12;
}

// ------ small ---------
{
int _mapSize = 256;

// number of flat areas
int _flatAreaCount = 100;

// size of flat areas
int _minFlatAreaSize = 20;
int _maxFlatAreaSize = 30;

// number of areas to avoid
int _avoidAreaCount = 4;

// size of avoidance areas
int _minAvoidSize = 20;
int _maxAvoidSize = 30;

// how many close nodes to connect to
int _flatAreaConnections = 3;

// rivers
int _streamCount = 0;

// erosion
int _erosion = 4000000;

// number of lakes
int _minLakeCount = 0;
int _maxLakeCount = 0;

// lake size
int _minLakeSize = 20;
int _maxLakeSize = 30;

// number of parts per lake
int _lakePartCount = 40;

// part sizes
int _minLakePartSize = 6;
int _maxLakePartSize = 12;
}

// ------ medium ---------
{
int _mapSize = 384;

// number of flat areas
int _flatAreaCount = 250;

// size of flat areas
int _minFlatAreaSize = 20;
int _maxFlatAreaSize = 30;

// number of areas to avoid
int _avoidAreaCount = 8;

// size of avoidance areas
int _minAvoidSize = 20;
int _maxAvoidSize = 30;

// how many close nodes to connect to
int _flatAreaConnections = 4;

// rivers
int _streamCount = 0;

// erosion
int _erosion = 8000000;

// number of lakes
int _minLakeCount = 0;
int _maxLakeCount = 0;

// lake size
int _minLakeSize = 30;
int _maxLakeSize = 50;

// number of parts per lake
int _lakePartCount = 50;

// part sizes
int _minLakePartSize = 6;
int _maxLakePartSize = 12;
}

// ------ large ---------
{
int _mapSize = 512;

// number of flat areas
int _flatAreaCount = 400;

// size of flat areas
int _minFlatAreaSize = 20;
int _maxFlatAreaSize = 30;

// number of areas to avoid
int _avoidAreaCount = 16;

// size of avoidance areas
int _minAvoidSize = 20;
int _maxAvoidSize = 30;

// how many close nodes to connect to
int _flatAreaConnections = 4;

// rivers
int _streamCount = 0;

// erosion
int _erosion = 16000000;

// number of lakes
int _minLakeCount = 0;
int _maxLakeCount = 0;

// lake size
int _minLakeSize = 30;
int _maxLakeSize = 60;

// number of parts per lake
int _lakePartCount = 70;

// part sizes
int _minLakePartSize = 6;
int _maxLakePartSize = 12;
}
]
}


Terrain/JDesertTerrain.rsc
MaterialInstance resource
{
Material _material = "Material\Terrain\TerrainMaterial.rsc";
Texture _textures
[
{
String _name = "grass";
ImageBuffer _texture = "Terrain\JDesertGrassTexture.rsc";
}
{
String _name = "dirt";
ImageBuffer _texture = "Terrain\JDesertDirtTexture.rsc";
}
{
String _name = "rock";
ImageBuffer _texture = "Terrain\JDesertRockTexture.rsc";
}
{
String _name = "snow";
ImageBuffer _texture = "Terrain\JDesertSnowTexture.rsc";
}
]
}


All textures are 1024px pngs. I still don't know what I'm missing. If you need to see more of my code, just let me know.
Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 03:21:14 PM
you started 6 new game/terrain in your resource file .... but i only see "Terrain/JDesertTerrain.rsc" in your resource file
you need 1 for each. you started jvalleys... jmountains...jplains...jmarsh...jdesert which is ok... jjungle... you are probably crashing another place even if you get the same error message.

Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 03:36:27 PM
so your resource file should be:

ExternalList resource
{
External _resources

[
"Game/Terrain/TerrainList.rsc",
"Game/Terrain/JValleys.rsc",
"Game/Terrain/JMountains.rsc",
"Game/Terrain/JPlains.rsc",
"Game/Terrain/JMarsh.rsc",
"Game/Terrain/JDesert.rsc",
"Game/Terrain/JJungle.rsc",
"Terrain/JValleysTerrain.rsc"
"Terrain/JMountainsTerrain.rsc"
"Terrain/JPlainsTerrain.rsc"
"Terrain/JMarshTerrain.rsc"
"Terrain/JDesertTerrain.rsc"
"Terrain/JJungleTerrain.rsc"
]
}


your terrainList should be like:

ExternalList resource
{
External _resources
[
"Game/Terrain/Valleys.rsc",
"Game/Terrain/Mountains.rsc",
"Game/Terrain/JValleys.rsc",
"Game/Terrain/JMountains.rsc",
"Game/Terrain/JPlains.rsc",
"Game/Terrain/JMarsh.rsc",
"Game/Terrain/JDesert.rsc",
"Game/Terrain/JJungle.rsc",
]
}


you should have a Game/Terrain/JValleys.rsc, Game/Terrain/JMountains.rsc, Game/Terrain/JPlains.rsc, Game/Terrain/JMarsh.rsc, Game/Terrain/JJungle.rsc files similar to your Game/Terrain/JDesert.rsc you described but with their own names and their own numbers.


your Game/Terrain/JValleys.rsc should also point to the Game/Terrain/JValleysTerrain.rsc
your Game/Terrain/JMountains.rsc should also point to the Game/Terrain/JMountainsTerrain.rsc
your Game/Terrain/JPlains.rsc should also point to the Game/Terrain/JPlainsTerrain.rsc
your Game/Terrain/JMarsh.rsc should also point to the Game/Terrain/JMarshTerrain.rsc
your Game/Terrain/JDesert.rsc should also point to the Game/Terrain/JDesertTerrain.rsc
your Game/Terrain/JJungle.rsc should also point to the Game/Terrain/JJungleTerrain.rsc


then you should have a Terrain/JValleysTerrain.rsc, Terrain/JMountainsTerrain.rsc, Terrain/JPlainsTerrain.rsc, Terrain/JMarshTerrain.rsc, Terrain/JJungleTerrain.rsc files similar to your  Terrain/JDesertTerrain.rsc you also described. i saw you changed the snow one in the JDesertTerrain.rsc ... (you can keep the original snow texture unless you really want to make a new snow one). they each should point to differents grass/dirt/rock textures as you need for different kind of map.


and your Dialog/JStringTable.rsc:terrainType should set the screentext for each 6 different ones.
Title: Re: Terrain Help
Post by: gl4d0s on October 26, 2017, 05:17:53 PM
I only want custom textures for the desert one right now.

All the other terrains and my new map size show up and work fine. It's only the desert one that gives an error and only when this line is changed:

WeakMaterialInstance _terrainMaterial = "Terrain/Terrain.rsc";

I went ahead and tried creating a separate mod that added the desert terrain only and it still popped that same error.

I tried just making a copy of Terrain.rsc without actually changing anything about it except renaming it to JDesertTerrain.rsc and got the same error again.

I see someone else had this issue with no solution:
http://shiningrocksoftware.com/forum/discussion/4169/terrain-rsc-is-hardcoded-can039t-make-new-terrain-types

But I know there has to be some work around because Colonial Charter has unique textures for certain terrain types.

Any chance you have a working source for a basic terrain texture mod I could play with?

Thanks again.

Title: Re: Terrain Help
Post by: gl4d0s on October 26, 2017, 05:47:36 PM
Here's my test with just adding a desert terrain type only. Maybe it'll be easier to spot and tell me where I'm going wrong.

Edit: Just noticed I forgot to remove the tiny map size from the test terrain files. Just know that the main mod does add it to stringtable properly. Fixing that didn't make the error go away though.  :(
Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 06:53:58 PM
sorry i ve got an hockey game tonight.... my Boston Bruins won tonight over SanJose Sharks woooohooo ^^

something is missing from your zip file :
a folder called Texture and within a file named TerrainTexture.rsc


go in your modkit resource folder, spot the folder named Texture and inside copy the file named TerrainTexture.rsc. go in your mod folder. create a folder named Texture and paste it there.
try to recompile.

EDIT:
oh also in your terrain/jdesertTerrain.rsc file.... there is a typo in your last .zip
at the end of your snow line there is a double " and a double ;
Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 07:07:14 PM
i just deleted everything and redid again.

unzipped your mod folder, added a folder texture + the TerrainTexture.rsc. i corrected the typo at snow ... compiled... great, start a game : screenshot
Title: Re: Terrain Help
Post by: gl4d0s on October 26, 2017, 08:29:15 PM
Thank you! For some reason I'm still seeing that error on my end.

It's silly but can you reupload that zip with the changes you made. lol
Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 08:37:36 PM
sure and use my .bat
Title: Re: Terrain Help
Post by: gl4d0s on October 26, 2017, 09:04:16 PM
Yep, that did it. Thanks again!
Title: Re: Terrain Help
Post by: RedKetchup on October 26, 2017, 09:19:52 PM
happy to hear it works for you :)
any other questions.... dont hesitate :)