Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RDY] Rework hordes hearing signal calculation #19222

Merged
merged 19 commits into from Nov 19, 2016

Conversation

Projects
None yet
4 participants
@Firestorm01X2
Copy link
Contributor

commented Nov 9, 2016

Currently wander spawn (aka hordes) is hardcore mode for hardcore players. Actually even players who play Cataclysm for long time and who want to increase difficulty tend to avoid wander spawn.

The main reason of that - horde can hear gunshot from insane distance and have tricky and unfinished spawn and moving algorithms.

This PR tries to fix insane hearing distance and rework hearing formula for hordes.

Here what we have new:

  • New method of calculation that calculates overmap distance hearing for hordes "naturally". Just like if normal volume in tiles reach it. With certain modification;
  • New formula that normalizes hearing sounds to overmap without coefficient. It can be easily tweaked further. Actually it scales sound interval like [X1,Y1] to overmap interval [X2,Y2] (http://stackoverflow.com/questions/929103/convert-a-number-range-to-another-range-maintaining-ratio) (not in use now. may be useful in future) (removed from code for now. upper is better);
  • Reduced hearing for hordes. Now city hordes should not hear you if you are deep in wilderness;
  • Hordes will hear only really loud sound that can leave reality bubble;
  • Hordes can actually hear you underground and above ground. However if you stay under ground then ground cover sound partially. The lower you are - less sound you produce for hordes.

Discussion is here:
http://smf.cataclysmdda.com/index.php?topic=13632.0

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 9, 2016

Currently sound interval like [0,180] scaled to [0,8];

[61,200]=>[4,9]
Min cap volume 61
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 10, 2016

How much loudnsess at max player can produce? 200 or even potentially more?

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Nov 10, 2016

Excessive defines make the code harder to read. They don't help here at all.

If you want all of it to be easy to read, configure and reuse, just wrap the "volume transformation" into a function that takes base noise and outputs range.

Extra code placed in funtions.
Added alternate simple solution.
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 11, 2016

Wraped extra code in functions.
Also alternate simple solution added. Just divide volume/30+1 .30 - is overmap tile (almost). Pretty straightforward and logical solution. This way is connected with normal volume calculation.
New method still in place. But maybe more simplier and natural method should be preffered?

int min_vol_for_hordes = 61;
int max_vol_for_hordes = 200;
int min_sig_power_for_hordes = 4;
int max_sig_power_for_hordes = 8;

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Nov 11, 2016

Contributor

Those names are giant, which makes it pretty hard to read the function.
It would be better if you shortened them to shortest readable name and added a comment if it's ambiguous.

For example min_signal, max_vol, vol_signal_coeff etc.

void sounds::process_sounds()
{
std::vector<centroid> sound_clusters = cluster_sounds( recent_sounds );
std::vector<centroid> sound_clusters = cluster_sounds( recent_sounds );

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Nov 11, 2016

Contributor

Looks like your IDE changed spaces here to tabs.
You'll need to change all tabs to 4 spaces each. Most IDEs support automatic tab->spaces.

int max_sig_power_for_hordes = 8;
//Lower the level- lower the sound
int vol_hordes=( (g->get_levz() < 0 ) ? vol/(per_level_down_vol_reduce_coef_for_hordes*std::abs(g->get_levz())) : vol);
//debugmsg( "vol_hordes %d g->get_levz() %d ",vol_hordes, g->get_levz());

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Nov 11, 2016

Contributor

It may be a good idea to leave it in, but not as debugmsg, but add_msg( m_debug, ... ).
add_msg( m_debug only prints messages when in debug mode.

Removed tabs
Refactored vars name
Limit to horde hearing correcly set to reality bubble (22*3)
Changes simple version of alghoritm to match overmap tile size
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 11, 2016

  • Removed tabs
  • Refactored vars name
  • Limit to horde hearing correctly set to reality bubble (22*3)
  • Changes simple version of algorithm to match overmap tile size

Now there are 2 versions of calculation algorithm.

One- with normalization. Easily tweakable to any requirement. It just rescales volume to overmap tiles using min-max normalization. May be good for further balancing.

Second- simple and clear. It is just divide sound volume to overmap size in player tiles. So volume/22 gives as horde signal. Sound levels are manageable. Shotgun shot should be heard from 8 overmap tiles. It is almost natural way to calculate horde signal.

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 11, 2016

What is the max volume that potentially can be produced ingame?

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2016

Limit to horde hearing correctly set to reality bubble (22*3)

It's 24 per overmap tile. However reality bubble isn't exactly 3 overmap tiles, it's between 5 and 6 submaps (2.5 to 3 overmap tiles), because it isn't actually centered on the player, but on the submap containing the player.

What is the max volume that potentially can be produced ingame?

There is no real limit. Unless I'm missing something, ANFO charge explosion should produce 4500 units of sound volume.

Now there are 2 versions of calculation algorithm.

The simple one looks good enough. We don't need precision here, but readability is always a plus.

{
int min_vol_cap = 67;//Hordes can't hear volume lower than this
int per_level_down_coef= 2;//Coeffficient for volume reduction undeground
int coef_for_hordes = 22;//Divider coefficent for hordes

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Nov 11, 2016

Contributor

Those two lower comments don't really add much.

Would be better like

int undeground_div = 2; // Underground noise is divided by this times number of z-levels below 0
int overmap_tile_size = 2 * SEEX; // Signal is in overmap tiles, volume in map tiles
@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2016

That underground noise thing needs to get the z-level of noise source, not global z-level.

To do that, you should pass it to the signal function from process_sounds. Currently it will stop signaling hordes if the player gets underground, even if the noise sources (NPC with a shotgun, turrets etc.) are on the surface.

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2016

Needs some styling:

  • Spaces within parentheses: if( x ), not if( x), if(x) or if(x )
  • Tabs to spaces (there are still some tabs in the diff)
  • Spaces around operators: int x = a, not int x=a
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 12, 2016

Also is sound unit (vol in my case) in tiles exactly?
An abot that explosion of 4500 - top capped is needed in this case.

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Nov 12, 2016

Also is sound unit (vol in my case) in tiles exactly?

Yes.

An abot that explosion of 4500 - top capped is needed in this case.

Cap around 150 would be fine. Alternatively, a soft cap, with everything above the cap going through some hardcore stepdown, like: if( sig > 8 ) sig = 8 + log( sig - 8 ).

* z-level now getting from sound position
* Added soft cap to get_signal_for_hordes_simple function
* Divider in get_signal_for_hordes_simple  now equal to tiles in overmap tiles 2 * SEEX
* Refactored code
* Added bunch of coefficients to correct signal value
* Both funtions balanced to:
      glock 19 shot - 5  overmaptiles
      autoshotgun shot  - 6  overmaptiles
      amininuke explosive  - 11-12  overmaptiles
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 12, 2016

Both functions now balanced to:
glock 19 shot - 5 overmaptiles,
autoshotgun shot - 6 overmaptiles,
mininuke explosive - 11-12 overmaptiles.

@pisskop

This comment has been minimized.

Copy link
Contributor

commented Nov 12, 2016

Since the thread was used as justification of this, Im weighing in.

5 tiles for s pistol is ridiculously small. thats a 5 minute walk. Ive suggests the rule of thumb "sound/6" as a guide. Thats double [10 tiles] for the pistol, and easily conservative in what it would draw.

there should be no 'max range' for signal promulgation. If its loud enough the entire overmap should respond. The is no reason to think the zombie up the same city block as you cant hear a pistol fired.

The claim for this PR is that using guns or explosives outside of cities is untenable, but unless Ive been playing a different game thats not an issue. Primarily because there are no nearby locations to spawn hordes.

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 12, 2016

Ok. Let's set my special coefficient to zero.

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 12, 2016

"sound/6"

Gives you 27 overmap tiles with glock 19 and JHP ammo. It sounds at 160.
Before that PR it was sound/5.

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 12, 2016

Now (last is mininuke. sig_power- disnance for horde in overmap tiles):
2016-11-12 21-54-18
2016-11-12 21-55-26
2016-11-12 21-56-10_m

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 12, 2016

Also you can see that actual sound from glock and autoshotgun almost similar.
So generally the most important question - from what distance horde should be able to hear gunshot?

Now there is also soft cap on 8 overmap tiles. Signal for horde louder than 8 overmap tiles will be reduced significantly using logarithmic function.

@hmstanley

This comment has been minimized.

Copy link

commented Nov 12, 2016

Somewhat of an off topic question, Firestorm, what font are you using in game? I'd like to implement it.

Firestorm01X2 added some commits Nov 15, 2016

Adding balancing coefs to hordes signal calculation simple function
Renaming some variables
Adding some comments
Now signal for hordes calculating in submaps (1 overmap = 2 subpamps)
Increased reaction coefficient for hordes to match new signal values
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 15, 2016

Looks like I figured that out. rl_dist returns result in submaps. 1 overmap = 2 submaps (or at least approximately). So now I calculate singal spower in submaps.
Currently hordes react to shot from 6-7 tiles. Also it is matching rule: if you see horde - than it may then it will hear your shoot.

Also added balance coefficients for "Simple" function. It will help to balance it later.

@pisskop

This comment has been minimized.

Copy link
Contributor

commented Nov 16, 2016

Guns dont really need a rework per se.

A mile is probably equatable to 12 tiles or so.

What should be fixed is how hordes draw hordes to themselves -but only within the reality bubble i.e your location

horde signal roll changed. Now horde can hear sound that just reach i…
…t not only that overlap it

Slightly refactored code
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 16, 2016

Tests show that with 7 overmap tiles you can still draw horde from city while shooting in starting shelter. It is even without no signal modifying at all - without reducing it or increasing it with coefficients . It is surprisingly good results. Almost like someone planning extension of reality bubble.

Renaming methods
Balancing coefs for standadrt method now floats as it should be
@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 16, 2016

Take notes that int get_signal_for_hordes_using_normalization is not in use now.
I use int get_signal_for_hordes( const centroid &centr ). Other method may be useful for future balancing.

Ok. I think that it is done.

pisskop, look at the:
int get_signal_for_hordes( const centroid &centr )
in sounds.cpp
There are coefficients for balancing. You can easily tweak them in your PR. To achieve 10 overmap tiles for pistol shot. Just set:
float sig_coef = 1.3;
instead of 1.

Do not forget that now we calculate signal in submaps not overmaps. 1 overmap = 2 submaps (approximately?). Signal rounded to higher number.

Ready.

@Firestorm01X2 Firestorm01X2 changed the title [CR] [WIP] Rework hordes hearing signal calculation [RDY] Rework hordes hearing signal calculation Nov 16, 2016

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 17, 2016

Removed unused method. Signal value connected with horde interest value. So signal is not so independent.

Also I can implement that altrnative method later but only if it will be needed. For now usual method of calculation produce fluid results.

Ready.

const int roll = rng( 0, mg.interest );
add_msg( m_debug, "horde roll % d_inter %d dist %d", roll, d_inter, dist);

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Nov 17, 2016

Contributor

That format string looks wrong.

//Capping minimum horde hearing signal
sig_power = ( ( sig_power < min_sig_cap ) ? min_sig_cap : sig_power );
//Capping extremely high signal to hordes
sig_power = ( ( sig_power > max_sig_cap ) ? max_sig_cap : sig_power );

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Nov 17, 2016

Contributor

It's clearer with std::min and std::max, like sig_power = std::min( sig_power, max_sig_cap ).

Also, the comment above suggests that the cap is soft (ie. that sig can sometimes go above it). Does it still do that? If not, the comment should be changed.

const int max_sig_cap = 26;//Signal for hordes beyond this cap will be reduced heavily
//Balancing coefs:
const float sig_coef = 1;// To make player life easier - make it less than one. To make harder - more than one
const float sig_modifier = 0;// To make player life easier - make it less than zero. To make harder - more than zero

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Nov 17, 2016

Contributor

This doesn't look useful for anything.

EDIT: Same for the line above it. Modifiers like that are trivial to add later, no need to keep them around.

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Nov 17, 2016

And again: formatting. Spaces in ifs and no tabs.

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 17, 2016

Now it is really ready.

@Coolthulhu Coolthulhu self-assigned this Nov 19, 2016

@Coolthulhu Coolthulhu merged commit fc22123 into CleverRaven:master Nov 19, 2016

@pisskop

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2016

this means most basements and science migoa wont be heard by hordes.

does this affect player hearing or hearing spam

@Firestorm01X2

This comment has been minimized.

Copy link
Contributor Author

commented Nov 19, 2016

this means most basements and science migoa wont be heard by hordes.

About basements - before this PR hordes won't be able to hear sound from basement at all or from any level, different from surface.

@Coolthulhu

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2016

About basements - before this PR hordes won't be able to hear sound from basement at all or from any level, different from surface at all.

Actually worse than that - old horde hearing would mean that hordes could hear a mi-go in the lab just fine, but only as long as the player stayed on 0 z-level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.