Halve the amount of ammo rounding up

Discuss anything ZDoom-related that doesn't fall into one of the other categories.

Halve the amount of ammo rounding up

Postby Kzer-Za » Thu Nov 05, 2020 1:28 am

I have tried changing skill definition settings in Gameinfo, i.e. AmmoFactor and DropAmmoFactor. I set them to 0.5, but the problem is that odd amounts are rounded down. I would prefer them be rounded up, or at least for the amount of ammo to never be less than 1.

I can live with getting 2 ammo (instead of 3) from 5-ammo piles (like ethereal arrows packs or flame orbs dropped by Ophidians), but many flame orbs in Heretic come from 1-ammo "piles". And these get rounded down to 0. This is too extreme, that is why I have this question: is there a simple way to halve all ammo piles in the game, but rounding up instead of down, or, at least, make it impossible for any ammo pile to contain less than 1 ammo.

PS I have tried setting the factor to 0.6 but this on one hand leads to 10-ammo piles to contain 6 ammo while on the other still rounds 1-ammo piles to 0.
Kzer-Za
 
Joined: 20 Aug 2017

Re: Halve the amount of ammo rounding up

Postby SanyaWaffles » Thu Nov 05, 2020 1:46 am

Have you tried 0.55 or 0.56?
User avatar
SanyaWaffles
Wouldn't be an epic gamer if I didn't commit a few war crimes.
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Halve the amount of ammo rounding up

Postby Kzer-Za » Thu Nov 05, 2020 1:47 am

Yes, it rounds 1 ammo to 0.
Kzer-Za
 
Joined: 20 Aug 2017

Re: Halve the amount of ammo rounding up

Postby SanyaWaffles » Thu Nov 05, 2020 2:18 am

If 0.6 doesn't work, then I dunno what will that doesn't involve ZScript.
User avatar
SanyaWaffles
Wouldn't be an epic gamer if I didn't commit a few war crimes.
 
Joined: 25 Apr 2013
Location: Eastern Ohio
Discord: SanyaWaffles#5095
Twitch ID: sanyawaffles
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Halve the amount of ammo rounding up

Postby Kzer-Za » Thu Nov 05, 2020 3:37 am

Then what would be the simplest way of using ZScript for the said purpose? I guess, overriding WorldThingSpawned?

I have tried for starters printing the amount of ammo in the pile:

Code: Select allExpand view
   override void WorldThingSpawned(Worldevent event)
   {
      if (event.thing)
      {
         event.thing.bNOFORWARDFALL = true; // nevermind that, it is for a different purpose entirely
         
         if (event.thing is "Ammo")
         {
            Console.Printf(event.thing.Inventory.Amount.." Ammo spawned");
         }
...


However, when I try to launch the game I get

Code: Select allExpand view
Unknown identifier 'Inventory'


How can I get and change the amount of ammo in the pile? I thought it was "Inventory.Amount".
Kzer-Za
 
Joined: 20 Aug 2017

Re: Halve the amount of ammo rounding up

Postby Gez » Thu Nov 05, 2020 6:00 am

You have to cast event.thing to the Ammo type. I think the way to do that in ZScript would be:

Code: Select allExpand view
if (event.thing)
{
    let ammoThing = Ammo(event.thing);
    if (ammoThing) // will be null if event.thing was not Ammo and therefore couldn't be cast, so this also replaces the event.thing is "Ammo" check
    {
        Console.Printf(ammoThing.Inventory.Amount.." ammo spawned");
    }
}
Gez
 
 
 
Joined: 06 Jul 2007

Re: Halve the amount of ammo rounding up

Postby Kzer-Za » Thu Nov 05, 2020 7:14 am

Strange, after I cast the type to Ammo it still gives me

Code: Select allExpand view
Unknown identifier 'Inventory'
Kzer-Za
 
Joined: 20 Aug 2017

Re: Halve the amount of ammo rounding up

Postby Jarewill » Thu Nov 05, 2020 7:18 am

Try just doing:
Code: Select allExpand view
ammoThing.Amount
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: Halve the amount of ammo rounding up

Postby Kzer-Za » Thu Nov 05, 2020 7:22 am

Ah, thanks, that worked!
Kzer-Za
 
Joined: 20 Aug 2017

Re: Halve the amount of ammo rounding up

Postby Kzer-Za » Thu Nov 05, 2020 8:02 am

Just in case anyone is gonna be doing the same thing: as it turns out, the settings AmmoFactor and DropAmmoFactor do not affect the amount of ammo spawned, they are applied the moment the player picks up the ammo pile. So for the amount to act as being rounded up you need to increase it (the odd amount) by one:

Code: Select allExpand view
         if (event.thing is "Ammo")
         {
            let ammoThing = Ammo(event.thing);
            if ((ammoThing.Amount % 2) == 1)
               ammoThing.Amount += 1;
         }
Kzer-Za
 
Joined: 20 Aug 2017

Re: Halve the amount of ammo rounding up

Postby Apeirogon » Thu Nov 05, 2020 12:06 pm

There are ceil function, which "Rounds x upward to the next closest integral value. Result is still floating point."
https://zdoom.org/wiki/DECORATE_expressions

So, untested,
Code: Select allExpand view
            let ammoThing = Ammo(event.thing);
            ammoThing.Amount = int(ceil(ammoThing.Amount% 2) );
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Halve the amount of ammo rounding up

Postby Gez » Thu Nov 05, 2020 2:54 pm

Kzer-Za wrote:Just in case anyone is gonna be doing the same thing: as it turns out, the settings AmmoFactor and DropAmmoFactor do not affect the amount of ammo spawned, they are applied the moment the player picks up the ammo pile. So for the amount to act as being rounded up you need to increase it (the odd amount) by one:

You could probably just increase them all by one without bothering to do a modulo test. Because say you have 4, it increases to 5, then when halved to 2.5 it rounds down to 2.
Gez
 
 
 
Joined: 06 Jul 2007

Re: Halve the amount of ammo rounding up

Postby Kzer-Za » Fri Nov 06, 2020 2:54 am

Gez wrote:You could probably just increase them all by one without bothering to do a modulo test. Because say you have 4, it increases to 5, then when halved to 2.5 it rounds down to 2.


Oh, right, I didn't think about it! Thanks! :)
Kzer-Za
 
Joined: 20 Aug 2017


Return to General

Who is online

Users browsing this forum: Chris and 4 guests