home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


[MODDING] Your first Sauerbraten MOD, Tutorial 1

by liquido on 11/15/2007 17:05, 77 messages, last message: 06/29/2010 07:30, 69325 views, last view: 06/26/2024 10:33, closed on 06/29/2010 09:29

[MODDING] Your first Sauerbraten MOD, Guide 1
---------------------------------------------
by liquido (jose.tapadas@yahoo.com)

(btw: i'm new to this forum :) ]

»»» [1]: INTRO:
===============

After googlin', searching and looking on the documentation I've noticed that there is a lot of spread information and nothing that a noob (must like me) could get as a platform to start coding for this great game engine, so I decided to write this guide so a modder-to-be could have some base to start on.
ATTENTION: Basic C/C++ knowledge required (if you don't know much don't worry!)

»»» [2]: THE TOOLS:
===================

Well as you know the Sauer is coded in C/C++ so in order to change something on it we need:

1. A C/C++ compiler:
Assuming you are using windows I recommend MinGW - Minimalist GNU for Windows, which has the Linux GNU tools all included on a win32 package
2. A C/C++ IDE (in order to help you browse through the code of Sauer and your mod.
3. Sauerbraten source code and engine (http://sauerbraten.org/)

To get all of this CodeBlocks has a package with all included:

Code::Blocks IDE, with MINGW compiler, Filesize: 13,597,181 Bytes | Version: 1.0rc2
download »» http://prdownloads.sourceforge.net/codeblocks/codeblocks-1.0rc2_mingw.exe?download

Now you need to configure the compiler so you can access it from any location and not only the MiniGW dir, so open Control Panel > System > Enviroment Variables search for "PATH" choose edit and add on the end of it ";C:\Program Files\CodeBlocks\bin".

»»» [3]: YOUR FIRST COMPILED SAUER:
===================================

On Sauer folder we have a well organized dir-structure so, with a little bit of inspection you can easily figure that we have a bi(nary) folder (with the game executable) and a src (source code folder). On this folder we wanna focus on 3 folders engine, fpsgame, rpggame.
It's not hard to figure that "engine" contains the Sauer game-engine (which contains the game physics, graphical rendering, etc..), fpsgame and rpggame contains both the fps and rpg game modes (or MOD's) which are included on Sauerbraten package.
Lets prepare a modding workspace on our engine, start by creating a new folder called "modgame" and copy into it all of the contents of the folder "fpsgame". We are going to mod the fps mode of Sauerbraten. Go inside your new folder and open all the .CPP and .H files with CodeBlocks. Go to "Search > Replace" and replace "fps" for "mod" on ALL FILES of that folder (when i say ALL I say ALL or it won't work!), save your progress and close CodeBlocks.
Still inside "modgame" rename "fps.cpp", "fpsserver.h" and "fpsrender.h" to "mod.cpp", "modserver.h" and "modrender.h".
Go back to the ..\src\ and go into mingw folder. Now create a copy of the "lib" folder and rename it to "lib.mingw", copy this folder into the ..\src\ folder. Copy the "MakeFile.mingw" into ..\src\ and "make.mingw.bat" into your Sauerbraten main dir (i.e. C:\Program Files\Sauerbraten).
Let's take a breath here to explain things:

* as you have noticed we are creating a new gamemode called "mod", based on the fps gamemode included on Sauer.
* on Sauer, fps and rpg modes, the gamemode binary is coded on "gamemode.cpp" (fps.cpp and rpg.cpp) and all the features are divided in something we call module coding, modules, weapons features on weapons.h, client features on client.h, all of them included on fps.cpp or rpg.cpp.
* if you are into the oo programming you will find interesting that all of the entities, actions and stuff on Sauer are divided into C/C++ classes which makes it very simple to develop.
* if you are not realy into OOP just forget (for now) the * above.
* the make file is something very usefull when programming very large projects with multiple files and compiler flags so it's a script who makes it for us.

We have created a mod workbench based on the fps game mode so lets include it on our makefile as a group ou files to compile, open the MakeFile.mingw and add just before of:

rpggame/rpg.o

the line:

modgame/mod.o \

To remove a compiling error on Sauerbraten scroll up and remove the line which adds:

engine/crypto.o \

(a feature removed from the cube time)

Save the MakeFile and close it. You are now ready to compile your mod and Sauer.
Run the "make.mingw.bat" and you should see somthing like this:

------------

C:\Program Files\Sauerbraten>cd src

C:\Program Files\Sauerbraten\src>mingw32-make all -fMakefile.mingw
g++ -O3 -fomit-frame-pointer -Wall -fsigned-char -Ienet/include -Iinclude -Ishar
ed -Iengine -Ifpsgame -o ../bin/sauerbraten-mingw.exe shared/tools.o shared/geom
.o engine/3dgui.o engine/bih.o engine/client.o engine/command.o engine/console.o
engine/cubeloader.o engine/grass.o engine/lightmap.o engine/main.o engine/mater
ial.o engine/menus.o engine/normal.o engine/octa.o engine/octaedit.o engine/octa
render.o engine/physics.o engine/rendergl.o engine/rendermodel.o engine/renderpa
rticles.o engine/rendersky.o engine/rendertext.o engine/renderva.o engine/server
.o engine/serverbrowser.o engine/shader.o engine/sound.o engine/texture.o engine
/water.o engine/world.o engine/worldio.o fpsgame/fps.o modgame/mod.o rpggame/rpg
.o -Lenet -Llib.mingw -lstdc++ -lenet -lmingw32 -lSDLmain -lSDL -lSDL_image -lSD
L_mixer -mwindows -lfmod -lz -lopengl32 -lglu32 -lws2_32 -lwinmm
strip ../bin/sauerbraten-mingw.exe

C:\Program Files\Sauerbraten\src>PAUSE
Press any key to continue . . .

-------------

Which means that everything went right!
Create a .BAT file called "mod.bat" on Sauer's main folder with the line :

bin\sauerbraten-mingw.exe -gmod

Save it.
This -gmod tells Sauer to run the game "mod".
Run it and....voila, your first mod!
Not very exciting because it's exacly the same that the fps mode but just have patience, you have compiled your first early-stage pseudo mod!

»»» [3]: YOUR FIRST MOD:
========================

Ok, lets do a actual MOD to the game.
Go to your mod's source folder (\src\modgame) and find a file called "weapon.h", open it!
As you can see from the first comment line:

// weapon.h: all shooting and effects code, projectile management

So this is the file where you find all the event handling, modeling and mumbojumbo when we are talking about weaponery stuff on Sauer. Search for the function:

void shoot(modent *d, vec &targ)

As you imagine this is the function which handles what to do when you fire your weapon on your game, so let's do some little moding.
On Sauer (and on most game engines, quake, source, doom, you name it!) we have something called entities which is basically everything that is interactive within the game, being it monsters, pick-ups, lights and even yourself the player, and on this shoot function we pass modent *d, which is a pointer to the entity who shoot's the weapon (so *d = (points) to ourselves for what we are concearned) and the vector &targ to the target of our shooting craziness. So lets mess up..cof...mod a little bit, scroll down until you find the line:

if(d->gunselect) d->ammo[d->gunselect]--;

Which is pretty much self explainatory, you d (ourselves) shoot go to the weapon ammo slot and dec. (--) by one ammo piece. Change it to:

if(d->gunselect) d->ammo[d->gunselect]++;

And this obviously will increase the ammo everytime you fire.
Save "weapon.h", run the "make.mingw.bat", then run your "mod.bat" and start shooting...free ammo on every trigger press!
I know this is very basic but it's a very important step on your journey as a modder ;)
Congratulations your first (micro) Sauerbraten MOD is complete.

Cumps, liquido... ;]

[keywords: mod, modding, Sauerbraten, tutorial, coding, develop, guide, noob, compile]

Go to first 20 messagesGo to previous 20 messages    Board Index    Go to next 20 messagesGo to last 20 messages

#28: Re: ..

by SheeEttin on 11/19/2007 00:18, refers to #27

One's derived from the other (C++ from C), and they're pretty similar, as far as I know (from my mainly non-coder standpoint)...

reply to this message

#29: ..

by yvfc_cebtenzzre on 11/19/2007 00:42

The only similarity worth noting is that they both have the letter C.

Otherwise, it is completely silly to say C/C++.

reply to this message

#30: Re: learn your material before arguing about it

by tentus_ on 11/19/2007 00:56, refers to #29

Ok, think for a minute. C++ comes from C, Stroustrup wrote it as basically C combined with Simula. It's original name was "C with Classes" for goodness sake. Why are you making such a big deal about something you don't know about?

Hell, Stroustrup himself said that C++ is like saying a double superlative in Newspeak, for those who have read 1984 and know what Newspeak is. If you follow through with that statement, the C++ name means "most C like".

Just... gah. What a silly discussion.

reply to this message

#31: Re: ..

by MovingTarget on 11/19/2007 01:10, refers to #29

Dude, like SheeEttin said, one's derived from the other. C++ has object-oriented stuff, while C doesn't. That's one of the only major differences.

reply to this message

#32: ..

by yvfc_cebtenzzre on 11/19/2007 08:11

tentus:

I do know what I'm talking about - what proof do you have that I don't?

C++ is not C, so people should stop referring to C/C++.

reply to this message

#33: Re: ..

by tentus_ on 11/19/2007 08:56, refers to #32

"The only similarity worth noting is that they both have the letter C."

Yeah. That's a well-educated statement there.

I agree that people should not treat them as interchangeable, but this is way more fuss than the distinction is worth. Particularly since the distinction does not apply to the comments you were reacting to- they could have easily said Java/C++ and their comments would mean the same thing.

reply to this message

#34: ..

by Grinch (has lost his cookie) on 11/19/2007 09:16

We're nitpicking, but the tutorial does seem to use "C/C++" as if it's one language. C and C++ are two different languages, and are strictly incompatible with each other. Sauerbraten is written in C++, not C/C++.

reply to this message

#35: Re: ..

by Grinch (has lost his cookie) on 11/19/2007 12:09, refers to #35

afaik Sauerbraten is compiled entirely in C++. The ENet library is written in C, but can be considered separate from Sauer. You don't say Sauer was written in C/C++ because a dependent library was written in C.

reply to this message

#36: ..

by yvfc_cebtenzzre on 11/19/2007 12:36

yes

Sauerbraten is compiled entirely in C++. The ENet library is written in C, but can be considered separate from Sauer. You don't say Sauer was written in C/C++ because a dependent library was written in C.

reply to this message

#37: vcpp Project import

by Osbios on 11/19/2007 16:42

At last C++ has some of the same stupid problems like C. ;)


Something nice to know about the Code::Blocks IDE is the project import function:

Project->import->MS Visual Studio project

Then chose ../Sauerbraten/src/vcpp/cube.vcproj

Now you can use and save the Project in native Code::Blocks format!

Have fun!

reply to this message

#38: Re: vcpp Project import

by MovingTarget on 11/19/2007 17:41, refers to #37

Why import the visual studio project? You can open the code::blocks project from sauerbraten/src/mingw/sauerbraten.cbp

reply to this message

#39: >.<

by Osbios on 11/19/2007 18:53

Or that way. >.<
thx

reply to this message

#40: commonsense

by a.baby.rabbit on 11/27/2007 11:06

Of course, eventually you will want the world to see how cool your mod is...

Pause a second, you don't want to be caught cheating against unmodified clients, or abusing the masterserver - so avoid bad vibes and start reading:

http://cube.wikispaces.com/Modding+Guide

reply to this message

#41: Great tutorial, but I am stuck!?

by screenracer on 03/08/2008 07:41

I (think) that I have followed this tutorial correctly, downloading CodeBlocks and editing all of the files. But when I try to run the batch file, this is what I get:

----------------------
C:\\Program Files\\Sauerbraten>cd src

C:\\Program Files\\Sauerbraten\\src>mingw32-make all -fMakefile.mingw
\'mingw32-make\' is not recognized as an internal or external command,
operable program or batch file.

C:\\Program Files\\Sauerbraten\\src>PAUSE
Press any key to continue . . .
-----------------------

BTW, my Makefile.mingw did not have \"engine/crypto.o \\\" in it already?

I know you say that all the cpp and h files in the modgame folder must be edited to replace FPS with MOD. In most lines that works, but for example even the link in assassin.h file:

void removeplayer(fpsent *d)

Just checking :)

Question, you point out after you make your naming changes in the cpp & h files, that you only save. So that is what I did, saved the file. Or should I save and compile?

Thank you in advanced for helping out this lost artist :)

reply to this message

#42: update - my error was not setting in the settings step

by screenracer on 03/08/2008 20:09

I was stuck on this step:

Now you need to configure the compiler so you can access it from any location and not only the MiniGW dir, so open Control Panel > System > Enviroment Variables search for "PATH" choose edit and add on the end of it ";C:\Program Files\CodeBlocks\bin".

I couldn't find it, so I did some google digging. I just missed it, to clarify the location on my computer, it was:

Control Panel > System > Advanced tab, then click the Environment Variables button.

reply to this message

#43: Re: update - my error was not setting in the settings step

by MovingTarget on 03/08/2008 22:10, refers to #42

Or, for a more convenient way, right click on My Computer, click properties, advanced, env vars.

reply to this message

#44: ..

by IllvilJa on 03/10/2008 19:18

Hm... are weapon stats and stuff hardcoded into .h files? One very useful mod (or actually, useful patch to the official Sauerbraten distribution) would be to let the engine read the weapon stats and stuff from configuration files.

That way modders can have their fun without recompiling the sauerbraten engine. They can even run their mods with the distributed Sauerbraten binary!

The best would of course if the SERVER told the client what the weapon stats and stuff were, so players cannot cheat or confuse the game by modifying the stats on their local client.

reply to this message

#45: Re: ..

by tman_elite on 03/10/2008 19:59, refers to #44

I like this idea. I also think that monster stats should be put in a config file, not the code. You wouldn't have to worry about cheaters with this simply because there are no multiplayer game types with monsters.

reply to this message

#46: Re: ..

by tentus_ on 03/11/2008 01:25, refers to #45

Defining monster stats in an external file makes sense to me. Given the direction that Eisenstern is going, actually, we can probably hope to see CFG defined monster stats sometime in the future.

It'd be nice if we could play around a bit with the monster AI a bit too, make them act in more different ways.

reply to this message

#47: ..

by IllvilJa on 03/11/2008 09:37

If the code defining the weapons (like weapons.h for the FPS game) were refactored as gently as possible in order to get away from hard coded weapon behavior and instead get all weapon stats defined in a array of objects or structs, would the authors/maintainers of Sauerbraten accept that patch?

Once that change is done to the code, it is far less difficult to create a command like "weaponreset" which can be used in the .cfg for a map (or perhaps in a separate .cfg, as the map cfg and weapon cfg might do best when in separate files when creating a mod). Once the weapons are "reset" (erased, forgotten, not used) the modder can add new weapons as he/she needs to, with settings and characteristics adapted to the mod.

The reason I ask if this change would stand a chance of being accepted as a patch (if the code were well written enough, of course) is that I don't mind looking into "unhardcoding" the weapons.h file if the changes make it into the official Sauerbraten release. If such a change, regardless the quality of the code, would never be accepted into the official sauerbraten for some (not necessarely bad) reason, I have to reconsider the effort of the refactoring.

(This is not asked to be confrontative, sorry if it sounds like it. I just want to ensure that my limited time is used as wisely as possible, yielding as much value not only for me but also for others using the product).

If such refactoring would be appreciated by the Sauerbraten authors/maintainers, what version of the weapons.h file should then be refactored. I suspect that the answer is "use the latest CVS version..." which of course is just common sense but there are a few advantages as well picking the weapons.h from the latest official assassin release for refactoring.

Ok. Sorry for being a bit long here. I'm in the (slow-motion) process of creating a No-Fi (as opposed to Lo-Fi or Hi-Fi) total conversion mod where the players use tanks instead of humanoids. In true extreme development spirit, I'm trying to create the very smallest possible total conversion with as little intrusion into the Sauerbraten code as well as into my limited free time budget. But I realized that I cannot really have the standard set of weapons (or hudguns) in a tank game. My preferences s actually to have 1 kind of ammo as a start (but given that I have to make changes to the C/C++ code might actually be a hint that the "one ammo" decision causes more work than using the default stuff...)

(BTW: I'm trying to avoid the standard path to failure: to have big ambitions with a mod. So, instead I try to create a mod on the tank theme so brain-dead simple that only an idiot would have problem to implement it. Necessary, as I WILL have problems with it ;-) )

reply to this message

Go to first 20 messagesGo to previous 20 messages    Board Index    Go to next 20 messagesGo to last 20 messages


Thread closed!

This thread has been closed, which is why you can't post any more messages in it.


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
55269728 visitors requested 73123125 pages
page created in 0.064 seconds using 10 queries
hosted by Boost Digital