Commit Graph
59 Commits
Author SHA1 Message Date
Goober5000andClaude Fable 5.1 37b0b6ea82 Standardize isValid across the Lua API by making the types auto-generate it (#7761)
* Automatically generate the isValid() Lua API function for handle types

If an ADE object's stored type has an isValid() member, ade_obj now registers an isValid function for it automatically.  An explicit ADE_FUNC(isValid, ...) declared after the ADE_OBJ replaces the generated one, so types with special semantics (e.g. sound) keep their own.  The 67 hand-written functions that merely delegated to the member are removed, and 26 types that previously exposed no isValid() gain one.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* Add ADE_OBJ_VALIDATOR for index-based Lua handles

Int-index handles (shipclass, weaponclass, team, etc.) can now declare their validity predicate with a single ADE_OBJ_VALIDATOR or ADE_OBJ_VALIDATOR_RANGE line after the ADE_OBJ.  The registered validator drives the generated isValid() function and is also honored by ade_set_args when the mod table asks for nil instead of invalid objects, which previously never applied to these handles.  The 19 hand-written range-check functions are replaced, and loadout_ship, default_primary, default_secondary, and support_rearm_pool_team gain isValid().  Add a validator to HudGauge while we're at it.

Also fully qualify the scripting namespace in LuaConvert.h so its templates can be instantiated from the unit tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
2026-09-08 10:50:53 -04:00
Goober5000andClaude Opus 4.7 49a9141073 Convert team_data to sparse loadout entry vectors
team_data was the last persistence-adjacent structure sized by MAX_SHIP_CLASSES: four parallel ship arrays plus four parallel weapon arrays (one slot per mission-file loadout line, holding a class or a sexp variable name, and a count or a sexp variable name) with manual num_*_choices counters, plus a dense per-class weapon_required flag array.  Convert all of it to the sparse-container family:

  ship_list / ship_list_variables / ship_count / ship_count_variables
    -> SCP_vector<loadout_entry> ship_choices
  weaponry_pool / weaponry_count / weaponry_pool_variable /
  weaponry_amount_variable
    -> SCP_vector<loadout_entry> weapon_choices
  bool weapon_required[MAX_WEAPON_TYPES]
    -> SCP_set<int> required_weapons

where loadout_entry is {class_index, count, class_variable, count_variable}, with empty variable strings meaning the value was given literally.  num_ship_choices / num_weapon_choices become .size().

Intentional behavior fixes, all previously latent memory errors or
data bugs:

 * is_ship_assignable stored an alt ship CLASS in a variable used as a
   loadout list INDEX when default_to_this_class was false, then
   swapped to ship_list[class] - garbage for any mission where the two
   domains diverge.  It now swaps to the alt class itself, per the
   evident intent.

 * The default-ship fallback read ship_list[0] even when a team had
   zero ship choices; it now leaves default_ship at -1, and
   ss_fixup_team_data guards its append of the default ship accordingly.

 * FRED2's dumpstats indexed Ships[] with a ship class when printing
   loadout entries; it now prints the entry's class or variable name
   directly.

 * Team parse now clears the previous mission's entries explicitly
   rather than relying on overwrite-in-place.

This clears the largest remaining cluster of MAX_SHIP_CLASSES references on the way to lifting the ship class limit.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-08-27 00:58:20 -04:00
Goober5000andClaude Opus 4.7 30d81a83fb store campaign allowed-class lists in sets
Convert the allowed-ships and allowed-weapons lists to sets, rather than naive vectors that stored a true/false for every class.  Since these are ordered sets, iteration occurs in the same sequence as iteration of `Ship_info` or `Weapon_info`.  Associated data structures such as `Granted_ships` and `Granted_weapons` are converted as well.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-08-04 22:14:58 -04:00
Mike Nelson bbf527bae3 grant lua access to closeup values (#7342) 2026-04-08 10:32:32 -04:00
Mike Nelson f2e8df4c69 Lua access to puncture flag status (#7323)
* lua access to puncture flag status

* disallow setting flag

* and don't grab the value even

* fix
2026-03-29 12:07:01 -04:00
Mike Nelson 5c2e5a261b Stop select model rendering destroyed subsystems (#7225) 2026-02-26 10:10:26 -05:00
Goober5000 b4d9c3e9c4 make ship and weapon class display names SCP_string
All other display names are `SCP_string`, so make these `SCP_string` as well to be consistent and to allow arbitrary-length display names.

Also fix a few infelicities with German translation and the script API.
2026-01-05 23:13:35 -05:00
Mike Nelson 1ffcaafc89 Allow customizing the fs2 selection effect (#6868)
* allow customizing the fs2 selection effect

* undo color color shift
2025-08-13 07:26:55 -04:00
Mike Nelson 4d39287de1 LuaLS meta file generation (scripting.lua) (#6516) 2025-06-08 11:29:30 -04:00
Goober5000 343d9a36d4 std::unique_ptr refactoring
Use `std::unique_ptr` rather than `vm_malloc` and `vm_free` to handle optional strings in ship classes.  This makes the code more robust and increases memory safety.  This also allows several string variables to be consolidated in the ship class and weapon class script APIs.

Also add new `stuff_string()` overloads and a new `F_TRIMMED` string parsing type to handle the new fields and the string trimming done inside `stuff_malloc_string()`.
2025-03-04 22:52:53 -05:00
Goober5000 ca624f86e2 a few pstypes changes and refinements
Several changes related to the volumetrics model fix:
1. Update the `model_load()` prototype with better parameter names, including a new `ErrorType` enum defined in pstypes.h
2. Update the `MIN`, `MAX`, and `CLAMP` macros, all of which were susceptible to performance issues because they duplicated their tokens.  This could cause functions or calculations to be re-run unnecessarily.  Since the codebase is now on C++17, `std::clamp()` can be used.
3. Update the rest of the codebase to fix any associated issues.
2025-01-30 21:35:03 -05:00
BMagnu 82236ccd9f Merge pull request #6465 from BMagnu/particle_cleanup
The definitive Particle Effect rework
2025-01-30 17:20:42 +09:00
Mike Nelson 4f503ec419 fix countermeasure virtvars (#6553) 2025-01-28 17:14:52 -05:00
Birk Magnussen e955a7f1be Merge branch 'master' into particle_cleanup 2024-12-10 23:41:07 +01:00
Goober5000 2b84233b91 Merge pull request #6439 from Goober5000/weapon_script_enhancements
add scripting support for weapon class "turret names"
2024-12-02 12:39:51 -05:00
Goober5000 854b9abc89 fix distinction between lasers and beams
Many beams are lumped into the #Primary Weapons section of weapons.tbl, which will mark them as WP_LASER.  Fix the few instances of code that are intended for beams that may have omitted most beams by mistake.

Randomization of weapon impact particle radius is also affected, but since this affects existing visual effects, it was not changed.
2024-11-26 14:10:26 -05:00
Goober5000 df6de0e0b8 enhance help text for script functions that do weapon category checks 2024-11-26 12:51:50 -05:00
Goober5000 089c870ad8 add scripting support for weapon class "turret names"
A recent-ish FSO feature, `$Turret Name:`, allows turrets to be displayed differently on the HUD depending on the weapon they carry.  It is useful for scripts to be aware of this, so this PR adds a `TurretName` virtvar for weapon classes, as well as a `NameOnHUD` virtvar for subsystems.  The `NameOnHUD` virtvar shares exactly the same code as the HUD uses, so any future HUD modifications will be reflected in scripting as well.  This required a small amount of refactoring: changing `get_turret_subsys_name()` to return a value rather than stuffing a string, renaming it to `ship_subsys_get_name_on_hud()`, and moving it to ship.cpp.
2024-11-25 16:35:00 -05:00
Mike Nelson 1a1bd84290 Grant lua access to countermeasure parameters (#6345)
* grant lua access to countermeasure parameters

* you win this round, Clang

* and Wookie wins the next round
2024-11-05 08:29:02 -05:00
BMagnu 97dbd2fa83 Removal of effects, pt. 2 2024-09-24 17:23:00 +02:00
Asteroth 649d458e83 fix spelling 2024-09-23 15:16:35 -04:00
Asteroth 40e334fc94 Disambiguate shockwave cases 2024-09-23 03:16:45 -04:00
Goober5000 62180212f5 derp
Counting is A-1 SUPAR.
2024-09-21 18:06:35 -04:00
Goober5000 24555ac739 add functions for getting swarm info and corkscrew info
Apparently virtvars can only return one value.  This deprecates the virtvars and adds function equivalents for getting weapon class swarm info and corkscrew info.  Fixes a bug reported by Woolie Wool in Discord.
2024-09-17 14:07:26 -04:00
Naomi Coffman ce6a6b447e Fix WeaponClass.SwarmInfo 2024-08-19 14:01:53 -04:00
Mike Nelson d9f9996c2d expose shockwave damage (#6245) 2024-07-13 09:29:48 -04:00
mjn-mixael 67ebeb438e custom strings for ships and weapons 2024-06-10 09:43:20 -05:00
Asteroth 1bd65192ba Allow for more field of fire cooldown shenanigans (#6086)
* allow for more fof cd shenanigans

* review fix

* switch to per frame management

* unused variable

* review tweaks
2024-04-20 23:33:24 -04:00
mjn-mixael a0f4c4d2b3 documentation error 2024-02-05 16:20:33 -06:00
mjn-mixael 63990c54a9 unhardcode zoom value 2024-02-05 16:14:07 -06:00
Sébastien Noel f149c36b44 Fix a few typos (#5598) 2023-10-24 20:33:45 -04:00
Goober5000 e132fcf74c Merge pull request #5585 from Goober5000/beam_api_stuff
additional beam-related features for Lua
2023-10-15 12:41:05 -04:00
Goober5000 8b8daece46 additional beam-related features for Lua
1. Add a `vanish()` function for beam objects, to be consistent with other object types
2. Add a `BeamFree` virtvar, analogous to `TurretLocked`
3. Add timestamp variants of TurretLocked and BeamFree to be consistent with sexps
4. Add `BeamLife`, `BeamWarmup`, and `BeamWarmdown` virtvars so scripts can access table properties
5. Add "On Beam Death", "On Beam Warmup", and "On Beam Warmdown" hooks
6. Clarify some existing documentation and patch a couple things
2023-09-06 00:28:07 -04:00
Goober5000 210a9a8309 add AllowedInCampaign virtvar
These can be used to set whether a ship or weapon is allowed in loadouts, without necessarily waiting for the mission to be accepted.
2023-08-21 16:32:56 -04:00
mjn-mixael fd6b670a04 flags to see if a ship or weapon is player allowed 2023-05-31 11:37:59 -05:00
mjn-mixael c6a1639a82 scpui methods required for handling closeup briefing icon stuff 2023-01-07 01:48:39 -06:00
mjn-mixael a662f8168c consolidation of tech rendering methods 2022-12-21 20:45:40 -06:00
Asteroth 924013b521 add burst shots and delay to scripts (#4847) 2022-11-06 23:59:34 +09:00
MjnMixael 50cd91bd86 Damage, swarm, corkscrew info virtvars (#4798)
* Add access to damage type, swarm, and corkscrew data

* Also return if the weapons have the appropriate flags

* Return nil for invalid handle and clarify documentation
2022-10-19 21:51:22 +09:00
Fabian Woltermann 9e56ba43a5 Merge pull request #4783 from MjnMixael/render_no_lighting
Allow option to choose to render with no lighting
2022-10-17 19:30:40 +02:00
mjn-mixael 32b059ae07 fix documentation 2022-10-17 08:09:26 -05:00
mjn-mixael 1af0a1082b int to bool 2022-10-17 08:04:02 -05:00
MjnMixael 09a307b17d Virtvar to access the energy a weapon consumes (#4784)
* Virtvar to access the energy a weapon consumes

* quick fix
2022-10-15 09:54:44 -04:00
mjn-mixael 7a5a54d009 Allow option to choose to render with no lighting 2022-10-14 09:00:35 -05:00
MjnMixael d323421817 Use a local int for model storage in renderTechModel (#4779)
* Use a local int for model storage here

* null -> nullptr
2022-10-13 17:06:03 +00:00
MjnMixael d902c7612b Api to render the 3d selection effect (#4737)
* Api to render the 3d selection effect

* Missing include

* documentation

* error message for effect type

* documentation
2022-10-03 08:25:15 +09:00
MjnMixael 419c56d012 check if weapon is required by current mission (#4731) 2022-10-02 20:23:36 +09:00
MjnMixael 3d700589c5 Give Lua access to the select anims and images (#4687) 2022-09-22 05:31:24 +09:00
mjn-mixael 762d855e99 Implement renderTechModel() and renderTechModel2() for weapons 2022-08-26 12:21:40 -05:00
Kiloku 0548b2fa2f Custom data in tables, tackling #3699 (#3707)
* Add custom data to ship tables

* add index check to shipclass.cpp

* fix hasCustomData name to use the proper casing

* Add custom data to weapon tables

* Add validity checks and remove superfluous empty check

* Attempt to appease clang-tidy

* Use F_RAW as recommended by @BMagnu

* Creates a function to parse maps and uses it in ship.cpp and weapons.cpp

* another attempt to appease clang-tidy

* Remove superfluous using

* Small style and grammar fixes

* Accidentally forgot this change. Rename 'delimiter' to 'end_marker'
2021-10-10 18:26:54 +09:00