[GUIDE] How to add a new building in 14 steps. (Basic)

Part I: Basic implementation of the building.
Some initial notes:
- I tried this with another building first, but for the purpose of this guide I'll use HugoJackson18's castle which is available to all of you. Get it here: https://drive.google.com/file/d/0B6-HjHGVgDRmR2oxczhaTW5tNUE/view
- You will also need a texteditor, I use sublime text, but you could use notepad ++ as well.
- We'll keep it simple, and just add the building to the mission nation, so it can be placed ingame in the editor.
- We will use the blockhouse as a reference to copy files from. This will speed up the implementation of the building greatly.
- It is best that you use the same name everywhere for the building, it will be less confusing, and you'll make less mistakes. So, let's name this building "miscas".

The 14 basic steps:
1. Extract the castle.osm and castl_diffuse.dds from the .rar you downloaded. Rename both, to miscas.osm and miscas.dds

2. Put miscas.osm into Cossacks 3\data\actors\buildings\mis\

3. Put miscas.dds into Cossacks 3\data\materials\buildings\mis\

4. Copy Cossacks 3\data\actors\buildings\mis\misblg.actor and paste it in the same folder. Rename it to miscas.actor

5. Open Cossacks 3\data\actors\buildings\mis\miscas.actor. Replace all the lines where it says "LoadFromFile = .\data\actors\buildings\mis\misblg." with 'miscas'. Pay attention here, since we don't have a 'death stage' for this building (yet) ensure you replace following 2 lines properly:

Copy it, paste it just before section.end at the bottom and change misblg to miscas. Save.

11. Open data\scripts\lib\units.script. Find following line: "//if (mis) then". The mission nation buildings are right below it. Find the following line and add the 'miscas' to it so it looks like this:

Code:

case objprop.sid of
'misblg', 'misblg2', 'miscas' : begin

You could ofcourse also copy the entire 'misblg' section, paste it under it and make adjustments to the building properties here ( HP, price, etc) . Let's not bother with that for now.

12. Open data\scripts\lib\country.script and find '// MEMBERS'.
The mission nation is right below it. Copy the line with 'misblg' and paste it under it. Change the name to miscas.

14. Now we have done the bare minimum to get a new building ingame, it should be placeable in the editor. So test if you did everything right. Go into the editor, look for the 'originals' nation and if you did everything right, your new building should be there:

Additional notes:
- I urge everyone to take a copy of your \Steam\steamapps\common\Cossacks 3 folder, and copy it on your desktop. Work on this copy, so an update from a patch doesn't overwrite your files or when you derp you don't have to reinstall files.

- Take advantage of the external editor , rather than using the internal editor. If you mess up, you will get a blackscreen with the ingame editor, and you will be none the wiser what happened. If you use the external editor, the debug log will tell you that something has gone wrong, and usually what has gone wrong. Sometimes it will even tell you in which file and which line there is something wrong.
I made at least 3 mistakes while doing this , in one occassion I simply forgot to save my changes, and without the debug screen, you could spend an hour trying to figure it out.

- Yes, the building is rotated wrong, and many many more things will be needed to get this building setup properly, but this was just a very basic guide on how to get the new building ingame. Build points will have to be setup, collision mask, collision box, smokepoints, text description, building properties, decals and then later assign it to a proper nation, add it to the peasants building menu,....but that will be for another part of the guide.

- @HugoJackson: Could you make a deathstage and a buildstage for this building? Then it can be covered in the next part of the guide how to set those up properly, maybe even go over attachments, such as a little flag on the tower, scaffolds, etc...

- Take advantage of the external editor , rather than using the internal editor. If you mess up, you will get a blackscreen with the ingame editor, and you will be none the wiser what happened. If you use the external editor, the debug log will tell you that something has gone wrong, and usually what has gone wrong. Sometimes it will even tell you in which file and which line there is something wrong.
I made at least 3 mistakes while doing this , in one occassion I simply forgot to save my changes, and without the debug screen, you could spend an hour trying to figure it out.

Click to expand...

Could you mention how you managed to spawn a building into the external editor? I've been trying to do some stuff relating to replacing mounted infantry, but the ingame editor sometimes blackscreens out. If the external editor works, I might actually be able to figure out what I'm missing/not doing correctly.

Could you mention how you managed to spawn a building into the external editor? I've been trying to do some stuff relating to replacing mounted infantry, but the ingame editor sometimes blackscreens out. If the external editor works, I might actually be able to figure out what I'm missing/not doing correctly.

Click to expand...

2 steps:
1. Go to Advanced - Player -> Add a player, and select "Race" buildings, or leave to 'units' if you want to spawn units.
2. Go to Layer - Players (CTRL+ALT+U)-> Click on buildings/units depending on what race you chose in previous step. A tree will open will all the units or buildings. Then simply place on the map. To 'stop' placing, press the spacebar.

I will definitely try to make at least one buildstage and one death stage for it tomorrow night. It was in my plans, but not in my priority. Definitely is now!

Also those screenshots made me realise a few problems.
- First of all, it has the wrong rotation for the reason that when I tried it by replacing the Austrian Temple, it was rotated this way so I had to adjust. There must be something in the file where you can set the default rotation for a building because when importing the Austrian temple into my 3d application, there was both rotated the correct way.
- Secondly, something is happening with the normals on the tower. I will have to fix that.

On the TO DO list:
- at least one build stage (have to look at how the other buildings buildstages are made but I suspect they are quite unique models altogether rather than just a modification of the final one)
- one deathstage
- building Icon

- First of all, it has the wrong rotation for the reason that when I tried it by replacing the Austrian Temple, it was rotated this way so I had to adjust. There must be something in the file where you can set the default rotation for a building because when importing the Austrian temple into my 3d application, there was both rotated the correct way.

Click to expand...

Worry not, rotating is easy. I'm busy writing the second part of the guide and already have it properly rotated:

If you don't rename them, then make sure you use the correct names when implementing.

15. We'll start simple, with a description for the building. I have no interest in translating it to every language ingame, so we'll add the description in the 'en' folder.
Find: Cossacks 3\data\locale\en\units.txt
Open it and add at the bottom of the file:

Next go to Cossacks 3\data\locale\txt_to_lng.bat . Open it (rightclick->open as) and at the bottom add following line:

Code:

..\..\tools\locale\editorlang.exe .\en\units.txt .\en\units.lng c

Save and close.
Now run the batch file by double clicking on it.

If you did everything right in the editor it should show 'Castle' now instead of 'miscas'

16. Lets rotate the building a bit, and rescale it a bit aswell just so you know how. Put the castle model (miscas.osm) from castle_02.zip into your Cossacks 3\data\actors\buildings\mis\ folder because Hugo seems to have rotated the model in the second pack. Just overwrite the existing one.
Next: Go to Cossacks 3\data\objects\buildings\miscas.prop
Open it and at the bottom find following lines and adjust:

17. Lets work a bit on the 'selection box', because this was based on the misblg, which is smaller.
This will also help with the collision so we don't have soldiers strolling on the inner courtyard like this:

Load up the editor (editor.exe) . We'll place the building right here (Add a player in Advanced - Player -> Add a player, and select "Race" buildings.
Then go to Layer - Players (CTRL+ALT+U)-> Click on "buildings". A tree will open will all the buildings. Place the building on the map. Press the spacebar to stop placing.
Now go to View- Universal manipulator, and tick on "Bounding box and CustAABBinSP" in the top section.

When dragging over the building to select it, you will instantly see the blockhouse selection box appear. We have to fix this up to match this new building.
We'll do this manually. Go to Cossacks 3\data\objects\buildings\miscas.prop and add:

It's not perfect but at least the box is larger now and easier to select. You can tweak the numbers more, but I'm sure GSC will release a tool/script to get these values more accurately when the workshop comes .

Note: Don't make the selection box too high, or you'll have situations where a small building behind this building becomes unselectable without rotating the camera. (= Don't include the tower in the box)

18. Let's put a ground texture under the building now (Decal)
Get the ground texture (miscasd.dds) from the castle_02.zip and put it in:Cossacks 3\data\terrain\decals\buildings\

Open Cossacks 3\data\terrain\decals\decals.lib
At the bottom paste following :

It's not perfect, but doing this manually is tedious. I wont add anymore smoke points because of this.
I'm sure gsc will release an editor/Script to add these.Note: You can see these points in the editor, if you select the building, and then go to Scripts-> Smokepointshowpickedbuilding.
In this same file you can add exit points, but since the castle doesnt really have an 'open' door for units to come out, i won't.

More in Part III, because posts apparently can't be longer than 10K characters. (sigh)

24.3 Grab the miscas.dds file from the castle_02.zip we renamed and put it in Cossacks 3\data\materials\buildings\mis\
Note: The textures are weird during buildstages, something Hugojackson needs to work on.

25. Time to try in the editor. It should be fully operational now. It can be built, it can shoot, it can be attacked.

Additional notes:
- Next part of the guide will be about attachments : scaffolds, flags. If there's anything else anyone want explained: Ask!
- There are actually scripts to visually adjust the selection box:

// Go to Script and look at all the AABB options there. Use the hotkeys to resize the box to match the building.
// Hotkeys: CTRL/ALT+F1-F12
// You will want to rotate the building often to see that it matches the walls roughly.
// Sadly no way to save these points apparently or I simply haven't figured out how. If someone feels like figuring this out, please do, it would save a lot of time.

- I Would have added an art depot index in the properties so it would add space for cannons, but the gui is very derpy:

Not impossible to change, but not really related to this guide.

@Hugo:
- I notice a small shift between the last buildstage and the building appearing fully built, it's barely visible but it's there. Are the models exactly in the same spot when exported?

- Maybe we should have an 'open door' in the model to let units come out of the building? Else its gonna be weird to have them come from behind the building if anyone would make the building being able to have units recruitable from it.

- Maybe we should have an 'open door' in the model to let units come out of the building? Else its gonna be weird to have them come from behind the building if anyone would make the building being able to have units recruitable from it.

Click to expand...

I did think about it, I'll just open the door I have. No problem. I might do another version with a gate on the right side at one point, but thats not in my priorities.

And yes, I DO need to fix all the textures for the build stages as I said in my initial post. They are all over the place at the moment but I wanted to have something out in terms of models asap for you to continue.

GREAT JOB on the guide, very detailed and I'm amazed how you found all this info with litteraly no support from the devs. Fantastic

Bonus for those who have scrolled down this far :
When looking at how shotpoints were setup, i noticed this on the blockhouse:

You can clearly see the deadzone's. In the shotpoints section, its not fully covering all the angles. It's setup to 5-85/95-175/185-265/275-355.
So it lacks about 10° on each side where it simply can't shoot.
Knowing this, you'll loose less units when approaching the blockhouse from the corners to kill it.

Bonus for those who have scrolled down this far :
When looking at how shotpoints were setup, i noticed this on the blockhouse:

You can clearly see the deadzone's. In the shotpoints section, its not fully covering all the angles. It's setup to 5-85/95-175/185-265/275-355.
So it lacks about 10° on each side where it simply can't shoot.
Knowing this, you'll loose less units when approaching the blockhouse from the corners to kill it.

Guys maybe i have read wrong but i still don't understand. I added to building option to peasants go inside but can't take them out i mean haven't icon like in mine. So help me pls to add icons: go outside, shoot, stop shoot, etc. How to do this?