News | Forum | People | FAQ | Links | Search | Register | Log in
Coding Help
This is a counterpart to the "Mapping Help" thread. If you need help with QuakeC coding, or questions about how to do some engine modification, this is the place for you! We've got a few coders here on the forum and hopefully someone knows the answer.
First | Previous | Next | Last
.MAP-file Parser 
Has anyone here made a parser for the .MAP-format for games like the Quake and the Quake 2? I've looked into making one myself to allow for wanton random generation of maps (or parts of maps/prefabs). It would be like an upgraded Oblige but with more focus on generating interesting architecture with decent texturing.

The .MAP-file format is pretty elegant TBQHWYFAMs and I don't think it would be a too taxing task to do. 
There's Someone @ QuakeOne.com 
working on something like that. Forgot who and the name of his mod. You might wanna check the works-in-progress section there. 
Who? Where? 
I'm sorry but I can't seem to find it... 
Don’t Remember 
Been a while since I saw that. If I stumble upon it I'll let you know. 
Trying To Compile Latest FTEQW 
fteqw-code/engine/client/r_surf.c:3299:16: error: ‘com_resourcemutex’ undeclared (first use in this function)
Sys_LockMutex(com_resourcemutex); 
#2371 
cd fteqw-code/engine && rm config.h && make m-rel && release/fteqw -basedir whatever

If that doesn't do it then you're going to need to give more info, like what OS you're trying to compile it for/on. Stuff like that matters when it involves threading. 
 
Still problems. Ubuntu 16.04 64-bit. 
 
revision 5134 compiles fine for me on 64bit ubuntu 16.04.

try make clean
revert stuff listed by 'svn status' (or just delete everything listed).
and try 'svn up' to make sure you've actually got the current version (and replace anything you may have deleted above).

other than that, I've no idea - it should just be a case of checking out, switching to the engine dir, and running 'make m-rel'. 
QC And Resetting. 
Is there any way to preserve an entity through a "reset" command?

I have an entity called "settings_pig". I'm using him to shuttle settings across saves. It works fine for this, but I need some settings to persist after a reset. Is there any way to do this?

I've been using the temp1 cvar, but I can only use that for a little bit of information. Any thoughts? 
Ignore Previous Question... 
I found a (hacky) solution... I can encode more data than I thought into temp1 
 
Settings shouldn't persist across a reset.

Type "coop 1; map e1m1" in the console if you want things to remain unchanged after death.

You can even save the games (as long as you don't change maxplayers from 1 to a higher number). 
Random Question 
random()'s purported result is 0-1.

In ID1 the ai_melee function does:
ldmg = (random() + random() + random()) * 3;

Soooo...this means that you could receive 0 damage from a knight slash??? Granted low probability due to having 3 of the random()'s and ai_melee being used on multiple anim frames. 
Random Question 
random()'s purported result is 0-1.

In ID1 the ai_melee function does:
ldmg = (random() + random() + random()) * 3;

Soooo...this means that you could receive 0 damage from a knight slash??? Granted low probability due to having 3 of the random()'s and ai_melee being used on multiple anim frames. 
How Random 
its worse than that.
the vanilla qcc had a bug that caused any operator with function calls each side to discard one side and use the other for BOTH terms.
so (random()+random()+random()) really just ends up as (random()*3).
(for anyone weak at statistical maths, adding 3 different randoms gives a value biased towards 0.5*3 instead of an even distribution, assuming no qcc bugs)
which is of course more likely to return extreme values like 0 or 1.

whether random() can actually return 0 3 times in a row depends upon the implementation. Some of the simpler ones just use a lookup table and might not have 3 such entries in a row. others might work more on a bit rotation basis and similarly be unable to return the same thing 3 times in a row. true randomness is basically impossible on current hardware, especially if you've no access beyond the userland.

side note: returning 1 is more problematic, at least if you use arrays. array[random()*array.length] = error! you can bias it, but then the last element is less likely which is undesirable too.
so dp+fte never return 1 from random(). they do return 0 though.

other side note: you can die even with health > 0!.. death occurs at health<1 (instead of health<=0). stat truncation results in interesting quirks otherwise. 
Well, Probably Not 
Remember that random is really a pseudo-random number generator - a fixed stream of numbers which looks random from one to the next and starts in an unpredictable place. It will once in a blue moon throw out an actual zero, this is the cause of the frozen monster glitch. However, I suspect that the PRNG being used here won't actually have a stream of numbers long enough for three zeroes in a row to ever occur.

Technical details: one of the important details in a PRNG is the "period", how long a string of numbers it produces before it loops back round. While a good quality PRNG like Mersenne Twister has a period with 19936 digits (in binary), that was developed in 1997, a year after Quake came out. Doubt anybody's gone to the effort of upgrading Quake's PRNG in the meantime.

Although I can't be bothered to check what Quake does uses (or gets from the default C libraries) I'd guess it's got a period of 2³². If this was used to generate 23 bit numbers (size of the mantissa in floating point) I would estimate the chance of a particular number appearing twice in a row anywhere within the sequence at 2³² / (2²³ * 2²³ ) = 2⁻¹⁴. So while we'd expect some numbers to occur in pairs, there's no guarantee 0 would be one.

And that's just pairs, when we go up to triples we're looking at something 2²³ times less likely, which is actually exceedingly unlikely to even happen once in the 2³². In other words, chances are the RNG in Quake will never output any single number three times in a row. 
I Like How... 
..I take 4 paragraphs to say what spike can cover in just 1 
Randumb 
and usually its me that writes the essays...

one thing I feel I have to point out is that quake uses the libc's rand() function, masked by 65535.
entropy is not spread evenly, and most spread the randomness on its high bits.
so that's bad.

I ended up writing my own rand() function to avoid shitty random numbers provided by emscripten's rand... quake's particle system uses a few of the low bits, and emscripten's was just far far too predictable, instead of a random mix of directions half of the particles in each puff went the exact same direction!

its also worth noting that a real random number generator should be happy to return the exact same value repeatedly some times, but generally humans actually want their random number generators to be LESS random. So rand()&0xffff being 0 three times in a row is actually quite unlikely with such a screwed up human-friendly generator.

either way, if its any value < 1 then the player might not notice, so yeah, 0 vs any damage value <1, not that much difference really.

(is that better, Preach?) 
Fun Fact... 
In order to implement seeds in my (progs only) monster randomizer I ended up using random number tables. Doom style. 
Ceil 
The damage function uses ceil to round up the damage so most of the time any values less than 1 get rounded to one. Since it is nigh impossoble to get 0, 0, 0 (using latest FTEQCC so I expect to have all 3 random()s), and 0, 0, >0 is more likely, I would expect the damage range for an ai_melee call to be 1-9 instead of 0-9. 
 
(talking out my buttcheeks)
What if one just loaded up the knight's animation frames then determined the length of the longest animation swing, like where the night's sword was FULLY extended. Then that that distance and do a trace from the player to the night. If the distance is greater than the distance of the sword then damage = 0. If the distance is within range then full damage. If the animation frame is between fully extended and the wind-up then take a % of damage based on which frame the knight's attack was in. Like if there are 4 frames between backswing to full extension, then determine the distance, (and if in range), base the damage on closeness and attack frame. this would be consistent and still random by player movement.
Does this make sense? just gibberjabbin over here... :) 
 
*edit: "Then that that distance " = Then take that distance 
Crandom 
What does crandom() do? Do I get cranberry sauce numbers from it? 
Ah Never Mind 
Found it:
return 2*(random() - 0.5);

Now I want cranberries. 
Teleporting Monsters 
As promised about 8 weeks ago, I've finally got round to reposting my teleporting monster flag code which was lost when Inside3d went down.

https://tomeofpreach.wordpress.com/2017/10/08/teleporting-monsters-flag/

I couldn't resist a spot of refining and fixing it. There's a single line fix here which took several days of bug hunting to work out when it affected Quoth, so benefit of accumulated wisdom I guess. The code's also a lot more self-contained - apart from the three entry points which call the new function, there's only one (optional) change to existing code which needs to be made. That should make it very easy to customise and extend... 
Thanks Preach 
When and if I make time to get into QuakeC this sound dandy. 
 
Hope this is the right place to ask.

GLHexen 2 has an annoying long standing issue when upscaling the HUD with -conwidth, some HUD elements are tiled and the seams become visible, like so:

https://i.imgur.com/aff3Auj.png

Any idea how can this be fixed? I mostly want to submit a patch for the Hammer of Thyrion source port, I've contacted the author and he's definitely interested in fixing this, but he's no idea what's causing this. We've tried changing GL_CLAMP to GL_CLAMP_TO_EDGE, and it helps with some images, but the others still have those thin lines. I've noticed that FTE seems to have this fixed, how was this done? 
#2393 
clamp-to-edge is good, but it doesn't affect anything when you're atlasing the texture. In such cases, the atlas should just have the border pixels doubled such that it gets the same value instead of averaging in the texel from the neighbouring image.
beware of mipmaps - eg the smallest mipmap is a 1*1 image that averages the ENTIRE texture instead of just the interesting part. you can use a few mip layers by aligning and capping the mip levels (on desktop gl anyway). or just prescale and avoid mips entirely (with 1 pixel borders).
alternatively you can pinch texture coords inwards by half a texel instead of padding with borders, but beware that the half-texel depends upon the mip level that will be used, so that's still messy.
(sidenote: gles supports npot textures only with clamp-to-edge and no mipmapping)

the other thing to do, especially for the hud images themselves, is to use premultiplied alpha (aka: rgb*=a [or equivalent] before uploading, then draw with blendfunc one,one_minus_src_alpha, you'll need glColor4f(rgb*a,a) for variable transparency). This avoids all discolouration on the edges between opaque/transparent texels, how this works should be well documented elsewhere but basically premultiplied alpha is awesome - USE IT!

also, if you're in contact with the author, can you get him to respond to my bsp2 patch (ideally by merging part of it)?
he doesn't really need to bump all the limits that my patch bumped, so long as the clipnodes are no longer so horribly limited... 
Ambient Sounds From A Point 
If I was to make a mod to create ambient sound entities that could play custom sounds from a point, how would I go about this?

Also what's the best program to use for this kind of thing?

Can custom ambient sounds be done with Quoth? if so, how? 
@ HexenMapper 
Here's a link to a version of the Quoth .fgd(JACK/Worldcraft editing game file) that lists custom ambient sounds.

https://gist.github.com/ItEndsWithTens/200c881f2522af324767be1433c4391e

So it's a simple as placing an entity and then setting the keys for your custom sound, location of course being the most important one.

As far as adding your own custom sounds to a mod, simply look at a mod that has the QC source available(Not Quoth). Though Preach my have a tutorial covering this on his site. Arcane Dimensions is a good current example, so if you play that you already have the QC files to examine.

Download and use FTEQCC GUI, then you can search for "custom sound" to see how it is implemented.

HTH's,
-damage_ 
 
thanks damage_inc, I'll have a look into this 
@hexenmapper 
If the goal is simply to have custom sounds play on a map, why not just make the map for Quoth or AD. Load the fgd into your editor and you are set, the custom sound entities are documented in the readme files for these mods. This will save you from having to create a new progs just for this one thing. Also it will allow you to use all of the other entities from Quoth or AD. 
@Hexenmapper 
You could also use the qc or progs from "extras4" - it has some nice features and custom sounds as well.

In mid 2002 nostalgia and boredom drove me to write some interesting QuakeC hacks. The result is this "Extras" mod, which aims to provide extra stuff for Quake mappers. It features honest to goodness func_water, and func_ladder entities, as well as an insanely customizable emitter/effector based particle system, and advanced trains and switches. So if you ever wanted to dynamically flood a level, or attach water volumes and/or switches to trains, this is the mod for you! Example maps and some snazzy new animated sprites and sound effects are also included.

http://quake.chaoticbox.com/downloads/extras_r4.zip 
For The Curious 
1. Download qc source.
2. Add the following to misc.qc:

void ambient_generic () = {
if (self.noise1 == "") { remove (self); return; } // check that we have a sound
precache_sound (self.noise1); // load sound in memory
ambientsound (self.origin, self.noise1, 0.5, ATTN_STATIC); // start ambient loop with volume 0.5
};

3. Compile using fteqccgui.exe
4. Place the resulting progs.dat in your mod directory (e.g. C:/QUAKE/mymod/progs.dat)
5. Run your map with -game mymod in the commandline. 
Cheers 
Thanks for the info - I think I can attempt to put something like this together! 
Qmaster 
I followed your example and have a progs.dat, but how do I add a sound entity into a map? which entity and keys should I use

And where should I place any new sounds inside my mod directory? 
Adding The Entity 
1. Add any point entity.
2. Rename it to ambient_generic
3. Add key|value of noise1|"folder/sound.wav" without the quotes and of course going to the directory under C:/QUAKE/mymod/sounds/folder/sound.wav or wherever your sound is. Don't include the "sounds" folder.
4. Compile and you will have your ambient. 
Lightstyles 
In world.qc, the different lightstyles are defined using 'a' thru 'z' for brightness in a string. I have questions about limits and compiler:

1. What is the character limit for the string?

2. Is there a limit on different lightstyles?

3. Does the compiler create a different saved lightmap for each letter a,b,c, etc?

4. Are lightstyles hardcoded into the compiler?

5. Does anyone know of a mod that makes their own lightsyles, e.g. Spastic Lightning or a Flash and Fade, etc.? 
 
1. Max string length is MAX_STYLESTRING = 64 which looks like it includes a null terminator, so 63 characters
2. MAX_LIGHTSTYLES = 64
3. No, the compiler bakes (and writes to the bsp) lighting at 100% brightness, which is level "m", I think. Whatever level QC requests is generated by scaling the 100% brightness lightmap to the requested brightness.

Each face can have up to 4 different lightmaps baked for it (bsp format limit), and each lightmap is linked to a lightstyle number.

more detail: the engine looks up the current brightness levels (a-z) of the (up to) 4 lightmaps that were baked for that face. Each of the baked lightmaps is scaled to the right brightness, they're added together, and the result is used as the lightmap for that frame.

4. No. There's not much hardcoded in the light compiler except it knows if a light has "targetname" set, it allocates one of the 64 style numbers for that targetname. It knows if a light has "style" set to use that as the style number for when that light hits faces.

5. Hmm.. I'm not sure. "The Middle Evil" had a lightning effect. ne_ruins might do some tricks with lightstyles, I forget?

The system could be pushed further with a bit of QC, e.g. switchable lights could be extended so they can be animated while on. Could have fade in/out transitions. 
#2404 
1: 63 chars (more depending on engine). chars outside the a-z range still have meaning but may result in numerical overflows (at least in surface caches), so avoid capitals etc.
there is an extension that allows styles of the form of "=0.5" to set a specific value with greater precision (1 is about equivalent to m - quake has overbrights), which allows for smoother style changes.
fte has an additional extension that allows you to pass an extra arg for rgb values.
the style strings are dynamic state, the qc is free to change them whenever it wants. however its the engine's choice which char it uses from the string at any particular time so if you want fancy qc-based animations its best to stick to a single char per lightstyle string (or the = thing, if your target engine supports it).

2: the bsp format (including bsp2) is limited to 255 different light styles (0-254, 255=no more). Many engines still limit to 0-63 however (higher requires saved game changes).

3: the map compiler is unaware of the style strings themselves. triggered lights will automatically be assigned a (shared-by-matching-targetname) style index.

4: styles 32+ will typically be used for triggered lights. lower indexes can freely be (re)defined by the QC mod, but existing mods will expect the same style strings that they were made for, so beware of that if you try changing the existing styles.

5: my recommendation would be to create some new trigger_lightstyle entity or something that allows you to (re)define the styles from the map itself, because awesomesauce. Bonus points if it can be triggered to enable/disable/recolour/etc all lights with the same style. Note that this should probably not be baked into the individual lights. 
Dynamic Strings 
If you want to be able to programmatically change the lighting strings you can use the basic idea from the following tutorials (a long and involved series of posts)

https://tomeofpreach.wordpress.com/2013/03/28/text-manipulation-in-quake-i-the-basics/

The crucial change you need to make is to use

float SVC_LIGHTSTYLE = 12;

as the header byte instead of SVC_CENTERPRINT when you send the characters. This may be overkill but it's nice to know there's a way to do it if you need. If you just want a way to translate a float into a light level it's a fairly compact way to do it without some kind of 26 line long if statement.

This trick will be employed in an upcoming project I'm working on... 
 
a mod that makes their own lightsyles

I remember JPL's "FortDriant" used a recompiled light index for making a long stairway of repulsing light on a long range of 32.

Don't know if its included in the map. 
Thanks Guys! 
 
 
Rubicon 2 has custom light styles 
 
i've done this
void () execute_changelevel =
{
local entity tmp;
local float bcount;

intermission_running = 1;
intermission_exittime = (time + 5);
lightstyle(0, "f");// R00k: -added- dim light on intermission

oddly I assume the world uses lightstyle 0 looking in the misc.qc for the lights i cant find any reference for the actual numerical value, yet in world.qc, lightstyle (0,"m"); etc.. 
 
wait ya, .style entity field is a lightstyle thus the world entity inits with self.style = 0; 
Zero Style 
It's basically that, except it's the style field on the light entities which matters, not the style of the world entity. When you don't set a style, the field defaults to 0 - even in the light compiler. 
 
okay so basically all default lights use lighstyle 0 which is why altering
that to a lower value makes it look like nighttime? i set
that for intermissions and on any map it dims the screen
so the scoreboard shows up better ;) pr_lightstyle calls the svc_ to broadcast to all connected clients. 
Cell Shading On Makaqu 
so I wanted to implement cell shading in my game, and I'm using the makaqu engine because it has cell shading support but more importantly it can be compiled for the dreamcast (I'm making a game for it). When I asked the developer how to implement the cell shading he told me to edit defs.qc and add the line:

float EF_CELSHADING = 16384;

and add this to the model script:
self.effects = self.effects | EF_CELSHADING;

problem is, when I compile it using fteqccgui and place it in my mod pak it still doesn't have cell shaded graphics. I want to add the effect to the player model and the dog, so how would I do this? 
Request For Details 
and add this to the model script:
self.effects = self.effects | EF_CELSHADING;


Can you give us a bit more of the context surrounding this line of code, like which function you've added it to? It wants to be in the function which is setting the model of the entity you want cell-shading on. 
1 post not shown on this page because it was spam
First | Previous | Next | Last
Post A Reply:
Name:
Title:
Body:
message
question
exclamation
idea
flame
noflame
error
skull
beer
moon
pent
rocket
sheep
pacman
pig
cheese
worldcraft
gauntlet
crate
pitfall
pimp
smile
cool
sad
frown
oi
yay
tongue
evil
wink
neutral
q1
q2
q3
ut
hl
cs
doom
dkt
serious
cube
Website copyright © 2002-2017 John Fitzgibbons. All posts are copyright their respective authors.