sfall-team / sfall

sfall - Engine modifications for Fallout 2
https://sfall-team.github.io/sfall/
GNU General Public License v3.0
348 stars 41 forks source link

More script functions for the car #90

Closed Lexx2k closed 7 years ago

Lexx2k commented 7 years ago

Right now we only have:

It would be good to be able to fetch things like remaining fuel, as well as being able to add new vehicle interface graphics (wmcarmve.frm) without replacing the original.

Refueling the car appears to be hardcoded right now (items for refuel + amount they refuel). This can be workarounded via a custom script and "car_give_gas(x)", but it's not possible to check for how much fuel the vehicle currently has, which can result in the player using up fuel items on a 100% filled car without any effect.

Also interesting would be things like speed of the vehicle (it is modified via ingame "upgrades" right now -- "set_car_upgrade_fuel_cell_regulator" for example), as well as fuel consumption. This way we could add multiple (different) vehicles to the game with a little bit of additional scripting.

FakelsHub commented 7 years ago

but it's not possible to check for how much fuel the vehicle currently has

There is the same function :) gas_amount := call_offset_r0(0x4C4E74);

phobos2077 commented 7 years ago

Don't listen to those hackers, they will teach you bad habits :)

The ideas you talk about are exciting. I think I didn't thought about the idea of having multiple vehicle in the game for a long time. This is however involves more questions to solve:

Lexx2k commented 7 years ago

There is another problem with refueling cars. Example: if (obj_pid(obj_being_used_with) == PID_MICRO_FUSION_CELL) then begin remove_pid_qty(dude_obj, PID_MICRO_FUSION_CELL, 1) car_give_gas(40000); end This works. 1 stack of PID_MICRO_FUSION_CELL is removed and the car gets refueled by 40.000 points. Thing is.... the player can actually have less than 1 full stack of said item in his inventory. In case of the MFCs, a (vanilla) stack has 50 charges-- if you fire a plasma rifle, you reduce it. So if the stack now has 40 charges, the above posted script would still work... but now you've refueled 40.000 points with a 40 instead of 50 charge stack. I don't know of any script command to check for this (so one can reduce the 40k points on the fly). The only other solution I see is adding a check "if MFC < 1 stack then deny refuel", but to be honest, this sucks.

phobos2077 commented 7 years ago

Why is this a problem? You can use get_weapon_ammo_count function for ammo stack (this is just badly named function for getting item charges, also works for Geiger counter, etc.). I think I have a procedure somewhere that can get and set the precise amount of ammo for given critter and PID. Check out the source code for my EcCo mod.

Lexx2k commented 7 years ago

Huh, I didn't even know that one exists. Can't find it in any of my files / sfall folder. Did a quick search and found it now in gl_highlighting.ssl -- is that a new function?

phobos2077 commented 7 years ago

No, it was added by timeslip a long time ago. Also see my previous comment :)

FakelsHub commented 7 years ago

Don't listen to those hackers, they will teach you bad habits

No. I'll teach you to use what does not yet support sfall.

FuncX(get_gas_amount) {
 return call 0x4C4E74;
}

I think it will be so))

Lexx2k commented 7 years ago

Controlling in-game vehicle PID (well, maybe we can just change the art via available scripting function, and in car script check for the current type of "car" and show different descriptions)

This is easily scripted. At the end of the day, the car itself is just a generic scenery object with a script attached that gets created & deleted depending on where the vehicle currently is (car_current_town). The car creation & destruction is defined in scenepid.h, the actual car creation code is in every map script (this is the painful part. Maybe this could be moved to a global script or map enter hook or something.) The car trunk is actually a companion that follows the player around (lel). Explains the old "mysteriously following trunk"-bug from back in the days. It was a fuckup in the "hide trunk if.."-code, which gave players an always accessible, teleporting container. :>

Car startup sound

Same as above, is in zsdrvcar.ssl defined, the script that is attached to the vehicle scenery object.

Something else probably

Biggest issue would be to exchange the car frm file on the worldmap interface, I think. Also we somehow have to define which car is the active one, so not all cars are moving to the same locations, etc. Maybe this can be workarounded with some simple GVARs, I dunno. Also it is necessary to make cars not just look different, but also feel different: Speed, fuel consumption, encounter chance(?), etc. (the Vertibird in the RP could be transformed into a real vehicle, for example)

And yeah, last but not least-- that above mentioned "get amount of current fuel" :p

FakelsHub commented 7 years ago

Interestingly, is it possible to change the picture for the auto (wmcarmve.frm) directly in the game from the script with the write_int () function? And change the value of the index of the picture to another? :-)

Udp: write_int(0x4C2D9B, new_index_frm) - only change index for FRM image, does not work.

phobos2077 commented 7 years ago

@Lexx2k : Did you know that car_give_gas function returns exact amount of fuel that was not used? Example you have 50k/80k of gas. If you call car_give_gas(40000) it will return 10000, which you can use and subtract the correct amount of ammo from your fusion cell pack. Edit: this function can also subtract the amount of fuel, but it has no lower boundary check. So you should take care not to end up with a negative amount of fuel :)

I will still add car_current_gas function of course.

phobos2077 commented 7 years ago

Added function. Now about car behavior on world map - it's all in wmWorldMap function. The question is how to make a useful hook out of this?

The easiest solution is to add hook for wmCarUseGas, but it will only cover fuel consumption. In order to change car speed need to hook a part of wmWorldMap function which is not trivial. Car speed is basically determined by how many times certain function is called every frame (this function is moving party on the map by some fixed distance). And there are checks for car upgrade GVARs that increase speed this way.

Suggestions? I can add 2 hooks:

@FakelsHub:

write_int(0x4C2D9B, new_index_frm) - only change index for FRM image, does not work.

What value did you passed to it? This offset accepts only LST index of the FRM.

Edit: I tested and this approach does work: write_int(0x4C2D9B, 306);

Suggestions? Just add set_car_intface_art function? Will have to reset the value after on mod reset.

FakelsHub commented 7 years ago

Использовал индекс 535 продублировав фрм, и при выходе на глобальную карту(используя авто) не выходило на нее - гг оставался бегать как бы на лок.карте затирая ее черным фоном :-) Upd: Да точно работает, это я по запарке переименовал frm с 9 буквами в его имени. :)

phobos2077 commented 7 years ago

Let's wait for suggestions from @Lexx2k (as he probably the only one who will ever use this, given how fallout modding is "popular" nowadays :D ) and then we can start making car shops and long awaited motorcycle for FO2 :)

(я джва года.. нет, больше, ждал такой фичи, почему-то в детстве считал что в игре можно раздобыть мотоцикл :) )

Lexx2k commented 7 years ago

There is also Mutants Rising that has a chance to take it in. Also maybe MIBs Mega Mod or maybe we actually do get another RP update some day. :>

I didn't know "car_give_gas" returns a value. How exactly do I fetch that? (remember, I am a shit scripter) If it works and we can calculate fuel with it, we would "just" have to make a macro for it and everyone can use it anyway without having to write their own code all the time, no?

"set_car_intface_art(x)" sounds good and I think that'd be totally fine. I'm not sure about the wmCarUseGas hook stuff, but I don't think it is the end of the world to have a vehicle always be at least as fast as walk speed.

phobos2077 commented 7 years ago

How exactly do I fetch that?

You don't need to do anything fancy. car_give_gas is a macro for metarule vanilla opcode which returns integer. Just use it like any function.

FakelsHub commented 7 years ago

со сменой транспортного средства все не так радужно как кажется, особенно с car_current_town одновременно 2 разных транспорта не получится иметь, потому как нет функции set_car_town.

phobos2077 commented 7 years ago

потому как нет функции set_car_current_town.

Как это нет? На месте вроде функция.

Просто при смене транспорта надо будет скриптами запоминать где оставили предыдущий и все.

FakelsHub commented 7 years ago

Как это нет? На месте вроде функция.

А это sfall function - я че то забыл про нее.

phobos2077 commented 7 years ago

0x81b6 - void set_car_current_town(int town)

RTFM :)

phobos2077 commented 7 years ago

@Lexx2k : Added set_car_intface_art function as well as new hook script. Please review and tell if there is anything missing for car customization.

Lexx2k commented 7 years ago

How exactly do I use it? Just e.g. "set_car_intface_art(123)" ? I've updated my .h files and I can compile, but ingame nothing happens. Is a new dll file required as well? Keep in mind, I'm not a programmer, I don't know shit. :> PS: I'm also too stupid to get the current amount of gas. Whatever I try, it's always 0, so I'm pretty sure I do something very wrong.

phobos2077 commented 7 years ago

Yes of course you need to recompile sfall DLL from latest develop. Or grab this build: https://yadi.sk/d/ri3ZD50L3H2ZmU

Lexx2k commented 7 years ago

Thanks! I was just running some tests and everything appears to work perfect. I can refuel the vehicle correctly now (without wasting ammo charges), and I can apply a custom worldmap icon.

phobos2077 commented 7 years ago

I'm closing the issue as all planned work is done. Until something is reported not working or not properly customizable.