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, 67687 views, last view: 05/18/2024 18:34, 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

#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

#48: Re: ..

by 9382938475 on 03/11/2008 14:38, refers to #47

Your weapon mod won't get added. It's very simple to do ( actually would make for a nice beginner mod tut to get acquainted with the cubescript macros ), so there's a reason why it's not there.

Modders shouldn't be concerning themselves with making changes to the standard distro anyway. Treat it as concretely as you would the quake or source engines. The number 2 path to failure is thinking of the standard distro as malleable.

My advice is to go back and read step 3 of the OP. Make a copy of the fps folder, and work on you mod in there. Stop worrying about changing stuff in the other dirs, and just have fun ripping stuff out, or adding stuff in.

reply to this message

#49: Re: ..

by 9382938475 on 03/11/2008 14:49, refers to #47

also don't work with CVS.

work with the latest release. That way you'll have a nice stable build to work with.

When the next release comes, you can simply copy your mod folder to the 'new branch' so to speak. It might not work completely, since there might be some changes to the iengine/igame api, but at least it'll be nice and clean. It's a lot easier to work with a few new api calls/hooks every 4 months, then it is to try and merge your code with a separate actively edited project.

If you do it that way, it'll be quite simple to have different versions of you r mod for each of the different releases.

reply to this message

#50: Re: ..

by Oh No Ghost! on 03/12/2008 01:23, refers to #47

What's wrong with streamlining the process and making heavier map modifications more accessible? Custom weapons that could be included in the CFG would be much easier to work with than having to mod the source code itself. Not everyone is willing to sort through the myriad of bugs and inconsistencies it takes to get a successful compile on their specific machine. Even less common are those willing to create an entire source mod, that may not work for many other people, for even the slightest alteration to weapons.h.

CFGs, on the other hand, work for everybody who can run sauer, require pretty cursory knowledge of coding, and produce a far better ratio of effort to results.

I don't want to seem like I'm goading you into doing it, IllvilJa, but I definitely support you in this endeavor. I'd wait for a response from Aard or Eihrul.

reply to this message

#51: Re: ..

by MovingTarget on 03/12/2008 01:33, refers to #50

Ahem. Myriad of bugs and inconsistencies? I don't think so. I got Sauer to compile on my VERY FIRST TRY! And why the **** won't your mod work for other people? I've emailed my mods to other people, and it worked for them. Geez, quit trying to make compiling sound harder than it is.

reply to this message

#52: Re: ..

by tman_elite on 03/12/2008 02:02, refers to #51

Compiling doesn't seem to work for me... I'm running on Ubuntu, and I'd put in the results of typing make into the terminal in the src folder, but its hundreds of lines long and I don't understand any of it. It ends in "make: *** [shared/tools.o] Error 1", if that means anything. If you want the whole error I'll post it somewhere.

I saw somewhere that you're supposed to type "make [clean] install" but that doesn't give me anything except "make: *** No rule to make target `[clean]'. Stop."

I would love config-based weapons and monsters. I know it'll probably never be part of the main distribution, but maybe someone should make this as a mod-friendly version of the source.

reply to this message

#53: Re: ..

by MovingTarget on 03/12/2008 02:14, refers to #52

OK... I probably should have mentioned that I'm on Windows. It works out of the box on Windows. I've tried it on multiple machines.

Oh, and when they said type make [clean] install, they meant 'clean' was optional, meaning if you do want 'clean', type make clean install.

reply to this message

#54: Re: ..

by tman_elite on 03/12/2008 02:35, refers to #53

I tried that. It didn't work either...

reply to this message

#55: Re: ..

by MovingTarget on 03/12/2008 02:48, refers to #54

Well, I'm no Linux expert, so ask someone else :P

reply to this message

#56: Re: ..

by SheeEttin on 03/12/2008 20:14, refers to #52

I don't think I've ever had problems with compiling Sauer that I didn't cause (and I check out from CVS pretty frequently). (I'm using Kubuntu.)

So, just go into src/ and type "make". Post the output somewhere like http://paste.biz/ .

reply to this message

#57: Re: ..

by tman_elite on 03/13/2008 20:13, refers to #48

Well I tried it again so I could post the output, and for some reason it was a lot shorter this time...

http://paste.biz/paste-3016.html

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
54038605 visitors requested 71819031 pages
page created in 0.085 seconds using 9 queries
hosted by Boost Digital