Commit graph

584 commits

Author SHA1 Message Date
Edoardo Lolletti
3aecb316f0 Don't send the code in MSG_SPSUMMONING if the card is facedown
Prevents leaking of private knowledge
2025-08-10 12:10:03 +02:00
Edoardo Lolletti
4ab85de875
Move Group's lifetime management to Lua (#166)
No longer manage a Group's lifetime explicitly in native code, but instead leverage Lua's garbage collector to handle it's lifetime.
In this change, Groups will be stored internally in the core inside a weak table, so that they will still be reference-able when needed, but if no reference were to exist in Lua code, they will be subject to garbage collection.
Whenever a Group is used by native code, its wrapped by a owned_lua template class, this is akin to std::shared_ptr--It reference counts the usages of that group internally in the core, including managing it in the Lua registry index when in use, so that it won't be collected.
With this approach, the exponential memory usage growth caused by long running procedures due to the creation hundredths of thousands of groups per iteration, is mitigated, since the temporary groups will be reaped more frequently, as opposed to the old approach of them being cleared only after the topmost Lua function had finished executing.
For now a single GC step is triggered whenever the total number of groups is more than 2048--an arbitrary value that seems to work well enough, but which can be changed/optimized after proper profiling.
A major upgrade with this approach is the removal of the concept of Groups "kept alive" and having to "explicitly delete" them to make them outlive a Lua function execution, since they will now follow Lua's variables lifetime properly.
2025-05-30 23:20:22 +02:00
Edoardo Lolletti
2d72976984 Import https://github.com/Fluorohydride/ygopro-core/pull/752 2025-05-17 11:48:30 +02:00
Edoardo Lolletti
9cd09364ca Fix EFFECT_TOSS_COIN_REPLACE and EFFECT_TOSS_DICE_REPLACE not letting results be set
The results array wasn't being resized to allow for it to be then populated by SetCoinResult/SetDiceResult
2025-04-27 22:27:38 +02:00
Edoardo Lolletti
158aebe758 Add duel flag DUEL_NORMAL_SUMMON_FACEUP_DEF 2025-04-17 21:57:02 +02:00
Edoardo Lolletti
9ba58cb794 Fix typo in trap monster adjust
If the first player had no free zones, the cards in the `returns` vector from any previous selection were added to the cards to be sent to the grave
2025-04-13 16:02:00 +02:00
Edoardo Lolletti
c57be7a4d4 Add string for cards added to the hand by a currently resolving effect 2025-04-13 15:38:52 +02:00
Edoardo Lolletti
a3ee9a10ab Reset the various "turn" actions statuses when a card banished temporairly returns to field regardless of the turn number 2025-04-13 15:23:34 +02:00
Edoardo Lolletti
66a4bf3a8e Import https://github.com/Fluorohydride/ygopro-core/pull/586 2024-08-08 17:02:24 +02:00
Edoardo Lolletti
df012a6733 Address variable shadowing warning 2024-06-13 16:44:36 +02:00
Edoardo Lolletti
7668b0940d Minor update to Processors::SpellSetGroup
Remove pointer reusing and store the set_cards directly in the struct
2024-06-13 14:39:19 +02:00
Edoardo Lolletti
7a81311598 Fix EFFECT_FORCE_NORMAL_SUMMON_POSITION
It got erroneously added in the variant rework, and was in an incomplete state, fixup what is possible for the moment
2024-05-30 17:29:07 +02:00
Edoardo Lolletti
a388095e1f Wrap luaL calls so that the lua stack has always at least 5 elements
Functions from the auxiliary library, assume the stack has always at least 5 empty slots, add macro ensure_luaL_stack to wrap every such call so that the stack is checked for enough free space beforehand. This will make mandatory to use the latest version of visual studio 2017 as minimum for windows (it was already being required for c++17 support regardless), as it needs the conformant c++ preprocessor option to be used.
2024-04-13 10:36:47 +02:00
Edoardo Lolletti
e4fc37a4ca Minor updates 2024-04-02 14:02:23 +02:00
Edoardo Lolletti
67c623d8bb Missing update from f4fcb53ad5 2024-04-01 20:45:35 +02:00
Edoardo Lolletti
f4fcb53ad5 Fix other logic update errors in SelectRelease/tribute 2024-04-01 12:58:53 +02:00
Edoardo Lolletti
bde406b38b Fix indestructable effects not being sorted in a deterministic way 2024-04-01 00:07:30 +02:00
Edoardo Lolletti
ae4f284934 Fix call to std::set_difference in selectrelease using the wrong comparator
It was being called on a range sorted with `card_sort` but without passing that specific comparator function, thus triggering undefined behaviour that could potentially lead to a crash
2024-04-01 00:07:30 +02:00
Edoardo Lolletti
0366e0088a Remove no longer needed (card*)nullptr in raise_event
There's no function ambiguity anymore
2024-03-08 11:12:46 +01:00
Edoardo Lolletti
ffe3ba695b Make field::raise_event take card_set by value 2024-03-08 11:03:06 +01:00
Edoardo Lolletti
7482a91975 Fix mid chain spsummon rule group 2024-03-03 10:41:25 +01:00
Edoardo Lolletti
62c2c5dbe2 Make Process::step unsigned
Avoid having to deal with UB while relying on signed integer overflow, add new value Processors::restart to be used in place of the -1 when "looping" a process (a value that when incremented by 1 will properly overflow to 0)
2024-02-11 13:38:26 +01:00
Edoardo Lolletti
acaa99beb9 Use clang-tidy to update instances where 0 was used instead of nullptr 2024-01-13 16:30:50 +01:00
Edoardo Lolletti
e97a1c2f94
Restructure the processor handling to use a variant object (#149)
Rewrite the whole ``process`` function of the processor to use instead tag dispatching on variant objects.
Each single processor message got rewritten as a struct, inheriting from a base templated Process struct, containing only the required data for that process, rather than using the generic structure that ended up needing to spam bitwise operations to pack as many arguments in a byte as possible. This makes things easier to follow and streamlines the addition of new processes:
 - Define its struct with the parameters it expects by also providing a constructor
   - If the process requires an answer, inherit it from ``Process<true>``, if it requires no answer, inherit it from ``Process<false>``
 - Add such struct to the ``processors`` variant type
 - Declare and implement its corresponding ``bool process(Processors::NewProcess& arg);`` function
2024-01-08 20:46:41 +01:00
Edoardo Lolletti
9790b552a0 Address various warnings raised by clang's -Weverything
They were mostly extra breaks/extra semicolons
2024-01-05 15:50:25 +01:00
Edoardo Lolletti
ff41aec90a Update header inclusion 2024-01-05 13:03:46 +01:00
Edoardo Lolletti
8b4bd4ac53 Update field functions to properly take bool and not uint8_t 2024-01-03 14:29:48 +01:00
Edoardo Lolletti
da45f91460 Update copyright for 2024 2024-01-03 01:21:08 +01:00
Edoardo Lolletti
6dc321de75 Make LuaParamType an enum class 2023-12-08 19:55:50 +01:00
Edoardo Lolletti
816fe64199 Update emplace_back/back construct usage
Use c++17's return value on emplace_back
2023-11-26 17:47:47 +01:00
Edoardo Lolletti
f89c5da422 Update get_card_or_group to return a pair group/card
To then be unpacked with c++ 17's structured binding
2023-11-26 17:47:46 +01:00
Naim
7ac33a959f
Update tribute related functions to support "Ritual Beast Ulti-Reirautari" (#150)
* Update Card.IsReleasable to accept a second, optional parameter for the reason. Update GetReleaseGroup, GetReleaseGroupCount the same way as well, with the new parameter being the 4th. Defaulting it to REASON_COST will prevent massive script changes (cards that tribute by effect already use Card.IsReleasableByEffect).

* Update EFFECT_CANNOT_RELEASE to pass the reason and the reason effect a 4th and 5th parameters to its target function

* Pass the reason down the line until get_release_list, check_release_list,is_player_can_release and card::is_releasable_by_nonsummon, updating internal function calls accordingly

---------

Co-authored-by: Edoardo Lolletti <edoardo762@gmail.com>
2023-11-12 17:04:20 +01:00
Edoardo Lolletti
5a696fb0ee Replace some begin/rbegin usage with front/back 2023-08-11 11:55:44 +02:00
Naim
eb0947dcdf
Fix field::negate_chain (#147)
It was setting the statuses STATUS_LEAVE_CONFIRMED and STATUS_ACTIVATE_DISABLED only after checking if the card was in the szone, not accounting for instances where in the same chain the card left the field and got put back in on there before negating the effect. Now only set those statuese if the card is still related to the chain.
2023-08-07 17:14:13 +02:00
Edoardo Lolletti
247a25aac7 Put the number of heads and tails in the event value of EVENT_TOSS_COIN 2023-07-21 22:59:47 +02:00
Edoardo Lolletti
7ca72ebc2b Simplify a bit the logic in tosscoin/tossdice 2023-07-21 22:55:27 +02:00
Edoardo Lolletti
5d2b4b6a85 Fix merge errors 2023-07-02 18:40:30 +02:00
Naim
0135dd1758
Update for the handling of position changes via effects (#145)
* Update the handling of changing positions via effects

Currently, EFFECT_CANNOT_CHANGE_POS_E prevents the affected cards from changing to any position. This changes that behavior to use that effect's value to acquire the positions the card(s) cannot be changed to. If no value is provided, no position change is allowed

---------

Co-authored-by: Edoardo Lolletti <edoardo762@gmail.com>
2023-07-02 17:47:13 +02:00
Naim
360312c551
Make Duel.NegateActivation and Duel.NegateEffect use the proper effect handler (#142)
Import https://github.com/Fluorohydride/ygopro-core/pull/462.
Fixes effect immunities not being properly handled in the case of effects applied via ``EFFECT_TYPE_XMATERIAL``.
2023-05-31 17:59:14 +02:00
Edoardo Lolletti
589bf823c3 Fix crash with GLOBALFLAG_DECK_REVERSE_CHECK enabled
There was an integer underflow that made the deck array be accessed out of bounds if GLOBALFLAG_DECK_REVERSE_CHECK was enabled and the deck emptied
2023-03-25 13:17:28 +01:00
Edoardo Lolletti
e73fb449a8 Silence downcast warnings 2023-02-07 16:43:27 +01:00
Edoardo Lolletti
79455ed275 Duel.Overlay: use the same reasons to send the materials as other places in the core 2022-11-06 11:08:17 +01:00
Edoardo Lolletti
fee290d713 "Detach" overlay materials of monsters overlaid with duel.overlay with reason_lost_target 2022-11-06 11:01:36 +01:00
Edoardo Lolletti
4f4e783766 Duel.Overlay add parameter to automatically send xyz materials of the monsters to be attached to the grave
Implement it natively rather than via lua, correctly handle the scenario where one of the xyz monsters to be overlaid has an effect to banish any card sent to the grave and it would be still applying if duel.sendtograve was called manually from the script
2022-11-05 16:48:29 +01:00
Edoardo Lolletti
29a7a057f1 Minor update to the way the summon info are stored
Decouple the summon location from the summon type, also keep track of the sequence and if the card was in a pzone, this allows to use symbolic locations in Card.IsSummonLocation as wel
2022-10-30 11:08:18 +01:00
Edoardo Lolletti
cc60c9b993 Wrong check in move_to_field 2022-10-28 13:35:33 +02:00
Edoardo Lolletti
7b5a52c6cc Add new symbolic locations
LOCATION_STZONE (the Spell & Trap zone, so excluding mr3 pzones and field zone), LOCATION_MMZONE and LOCATION_EMZONE. Usable in GetMatchingCard, GetFieldGroup, etc
2022-10-28 13:00:48 +02:00
Edoardo Lolletti
94fe632ed8 Fix handling of EFFECT_TOSS_COIN_CHOOSE and EFFECT_TOSS_DICE_CHOOSE
They weren't resizing the result vector, thus making the subsequent call to setCoin/Dice result error out
2022-10-21 18:57:45 +02:00
Edoardo Lolletti
595b9af5f4 Update handling of dice rolls and coins tosses
Remove the arbitrairy cal to a max of 5 values for the results, add strict checks to Duel.SetCoinResult and Duel.SetDiceResult to ensure you set the exact amount of values and no more, also make Duel.GetCoinResult and Duel.GetDiceResult return the actual number of values rather than the fixes 5 values
2022-10-13 16:12:52 +02:00
Edoardo Lolletti
c4785633ba Remove undefined behaviour from ProgressiveBuffer class
Add a separate ``set`` function and use memcpy to store/retrieve the data in the buffer, removes the raw cast to a reference that could have also lead to aligment issues.
2022-09-17 15:19:38 +02:00