From 7a1d7635843390e004505456056fb88cc0e09237 Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Sat, 23 Sep 2017 18:12:07 +0200 Subject: [PATCH] take 2: format 904 of 1280 files - this time it compiles --- qcsrc/client/announcer.qc | 105 +- qcsrc/client/bgmscript.qc | 109 +- qcsrc/client/bgmscript.qh | 12 +- qcsrc/client/commands/cl_cmd.qh | 7 +- qcsrc/client/csqc_constants.qh | 178 +-- qcsrc/client/csqcmodel_hooks.qh | 16 +- qcsrc/client/hud/hud.qc | 405 +++--- qcsrc/client/hud/hud_config.qc | 758 +++++----- qcsrc/client/hud/hud_config.qh | 2 +- qcsrc/client/hud/panel/centerprint.qc | 250 ++-- qcsrc/client/hud/panel/chat.qc | 53 +- qcsrc/client/hud/panel/engineinfo.qc | 39 +- qcsrc/client/hud/panel/healtharmor.qc | 217 ++- qcsrc/client/hud/panel/notify.qc | 82 +- qcsrc/client/hud/panel/physics.qc | 303 ++-- qcsrc/client/hud/panel/powerups.qc | 120 +- qcsrc/client/hud/panel/pressedkeys.qc | 30 +- qcsrc/client/hud/panel/timer.qc | 47 +- qcsrc/client/hud/panel/vote.qc | 100 +- qcsrc/client/main.qh | 24 +- qcsrc/client/mapvoting.qc | 477 +++--- qcsrc/client/mutators/events.qh | 50 +- qcsrc/client/player_skeleton.qc | 121 +- qcsrc/client/player_skeleton.qh | 10 +- qcsrc/client/shownames.qc | 115 +- qcsrc/client/shownames.qh | 10 +- qcsrc/client/teamradar.qh | 24 +- qcsrc/client/wall.qc | 147 +- qcsrc/client/wall.qh | 10 +- qcsrc/common/anim.qc | 27 +- qcsrc/common/animdecide.qc | 262 ++-- qcsrc/common/animdecide.qh | 13 +- qcsrc/common/campaign_file.qc | 76 +- qcsrc/common/campaign_setup.qc | 12 +- qcsrc/common/command/command.qh | 2 +- qcsrc/common/command/generic.qc | 348 ++--- qcsrc/common/command/generic.qh | 2 +- qcsrc/common/command/markup.qc | 198 ++- qcsrc/common/command/reg.qh | 7 +- qcsrc/common/command/rpn.qc | 386 +++-- qcsrc/common/csqcmodel_settings.qh | 68 +- qcsrc/common/deathtypes/all.qh | 31 +- qcsrc/common/debug.qh | 261 ++-- qcsrc/common/effects/all.qc | 25 +- qcsrc/common/effects/all.qh | 2 +- qcsrc/common/effects/effect.qh | 10 +- qcsrc/common/effects/effectinfo.qc | 576 ++++---- qcsrc/common/effects/qc/casings.qc | 247 ++-- qcsrc/common/effects/qc/globalsound.qc | 721 +++++---- qcsrc/common/effects/qc/globalsound.qh | 46 +- qcsrc/common/effects/qc/lightningarc.qc | 137 +- qcsrc/common/effects/qc/modeleffects.qc | 57 +- qcsrc/common/effects/qc/rubble.qh | 13 +- .../gamemodes/gamemode/nexball/nexball.qh | 6 +- .../gamemodes/gamemode/nexball/sv_weapon.qc | 124 +- .../gamemodes/gamemode/onslaught/onslaught.qh | 10 +- .../gamemode/onslaught/sv_onslaught.qh | 10 +- qcsrc/common/gamemodes/sv_rules.qc | 88 +- qcsrc/common/gamemodes/sv_rules.qh | 17 +- qcsrc/common/impulses/all.qh | 12 +- qcsrc/common/items/all.qc | 16 +- qcsrc/common/items/item.qh | 80 +- qcsrc/common/items/item/ammo.qh | 120 +- qcsrc/common/items/item/armor.qh | 158 +- qcsrc/common/items/item/health.qh | 158 +- qcsrc/common/items/item/jetpack.qh | 77 +- qcsrc/common/items/item/pickup.qc | 5 +- qcsrc/common/items/item/pickup.qh | 66 +- qcsrc/common/items/item/powerup.qh | 80 +- qcsrc/common/minigames/cl_minigames.qh | 60 +- qcsrc/common/minigames/cl_minigames_hud.qc | 433 +++--- qcsrc/common/minigames/minigames.qc | 49 +- qcsrc/common/minigames/minigames.qh | 92 +- qcsrc/common/minigames/sv_minigames.qh | 21 +- qcsrc/common/models/all.qh | 14 +- qcsrc/common/monsters/monster/zombie.qc | 127 +- qcsrc/common/monsters/monster/zombie.qh | 12 +- qcsrc/common/monsters/sv_spawn.qc | 55 +- qcsrc/common/monsters/sv_spawn.qh | 2 +- qcsrc/common/mutators/events.qh | 84 +- .../mutator/bloodloss/sv_bloodloss.qc | 28 +- .../mutator/breakablehook/sv_breakablehook.qc | 14 +- qcsrc/common/mutators/mutator/buffs/buffs.qh | 48 +- .../common/mutators/mutator/buffs/cl_buffs.qc | 21 +- .../common/mutators/mutator/buffs/sv_buffs.qc | 690 ++++----- .../common/mutators/mutator/buffs/sv_buffs.qh | 2 +- .../mutators/mutator/bugrigs/bugrigs.qc | 183 ++- .../mutator/campcheck/sv_campcheck.qc | 85 +- .../mutators/mutator/cloaked/sv_cloaked.qc | 8 +- .../mutator/damagetext/sv_damagetext.qc | 89 +- .../mutator/damagetext/ui_damagetext.qc | 105 +- .../mutators/mutator/doublejump/doublejump.qc | 13 +- .../mutators/mutator/globalforces/_mod.qh | 2 +- .../mutator/globalforces/sv_globalforces.qc | 39 +- qcsrc/common/mutators/mutator/hook/sv_hook.qc | 56 +- .../common/mutators/mutator/instagib/items.qh | 91 +- .../mutators/mutator/instagib/sv_instagib.qc | 304 ++-- .../invincibleproj/sv_invincibleproj.qc | 3 +- .../mutators/mutator/itemstime/itemstime.qc | 615 ++++---- .../mutator/melee_only/sv_melee_only.qc | 3 +- .../mutators/mutator/midair/sv_midair.qc | 24 +- .../mutators/mutator/multijump/multijump.qc | 96 +- qcsrc/common/mutators/mutator/nades/nades.qh | 46 +- qcsrc/common/mutators/mutator/nades/net.qc | 15 +- .../mutators/mutator/new_toys/sv_new_toys.qc | 49 +- .../physical_items/sv_physical_items.qc | 50 +- .../mutators/mutator/pinata/sv_pinata.qc | 17 +- .../random_gravity/sv_random_gravity.qc | 19 +- .../mutator/rocketflying/sv_rocketflying.qc | 3 +- .../mutator/rocketminsta/sv_rocketminsta.qc | 26 +- .../mutators/mutator/sandbox/sv_sandbox.qc | 450 +++--- .../mutators/mutator/sandbox/sv_sandbox.qh | 5 +- .../mutator/superspec/sv_superspec.qc | 288 ++-- .../mutator/touchexplode/sv_touchexplode.qc | 41 +- .../mutators/mutator/vampire/sv_vampire.qc | 13 +- .../mutator/vampirehook/sv_vampirehook.qc | 41 +- .../mutators/mutator/walljump/walljump.qc | 76 +- .../common/mutators/mutator/waypoints/all.qh | 31 +- .../mutator/waypoints/waypointsprites.qh | 76 +- .../sv_weaponarena_random.qc | 10 +- qcsrc/common/net_notice.qc | 97 +- qcsrc/common/notifications/all.qc | 1282 ++++++++--------- qcsrc/common/physics/movelib.qc | 220 +-- qcsrc/common/physics/movelib.qh | 10 +- qcsrc/common/physics/movetypes/follow.qc | 7 +- qcsrc/common/physics/movetypes/step.qc | 10 +- qcsrc/common/physics/movetypes/toss.qc | 86 +- qcsrc/common/physics/movetypes/walk.qc | 87 +- qcsrc/common/sounds/all.qh | 12 +- qcsrc/common/sounds/sound.qh | 36 +- qcsrc/common/state.qh | 2 +- qcsrc/common/triggers/func/bobbing.qc | 34 +- qcsrc/common/triggers/func/conveyor.qc | 47 +- qcsrc/common/triggers/func/conveyor.qh | 5 +- qcsrc/common/triggers/func/door.qc | 397 +++-- qcsrc/common/triggers/func/door_rotating.qc | 50 +- qcsrc/common/triggers/func/door_secret.qc | 115 +- qcsrc/common/triggers/func/fourier.qc | 37 +- qcsrc/common/triggers/func/pendulum.qc | 29 +- qcsrc/common/triggers/func/plat.qc | 53 +- qcsrc/common/triggers/func/pointparticles.qc | 250 ++-- qcsrc/common/triggers/func/rainsnow.qc | 51 +- qcsrc/common/triggers/func/rotating.qc | 66 +- qcsrc/common/triggers/func/train.qc | 155 +- qcsrc/common/triggers/func/vectormamamam.qc | 95 +- qcsrc/common/triggers/include.qc | 1 - qcsrc/common/triggers/misc/corner.qc | 14 +- qcsrc/common/triggers/misc/follow.qc | 38 +- qcsrc/common/triggers/misc/laser.qc | 272 ++-- qcsrc/common/triggers/platforms.qc | 144 +- qcsrc/common/triggers/subs.qc | 127 +- qcsrc/common/triggers/subs.qh | 42 +- qcsrc/common/triggers/target/changelevel.qc | 21 +- qcsrc/common/triggers/target/kill.qc | 13 +- qcsrc/common/triggers/target/levelwarp.qc | 13 +- qcsrc/common/triggers/target/location.qc | 18 +- qcsrc/common/triggers/target/music.qc | 148 +- qcsrc/common/triggers/target/music.qh | 4 +- qcsrc/common/triggers/target/spawn.qc | 168 +-- qcsrc/common/triggers/target/speaker.qc | 117 +- qcsrc/common/triggers/target/voicescript.qc | 54 +- qcsrc/common/triggers/trigger/counter.qc | 28 +- qcsrc/common/triggers/trigger/delay.qc | 13 +- qcsrc/common/triggers/trigger/disablerelay.qc | 13 +- qcsrc/common/triggers/trigger/flipflop.qc | 16 +- qcsrc/common/triggers/trigger/gamestart.qc | 7 +- qcsrc/common/triggers/trigger/gravity.qc | 59 +- qcsrc/common/triggers/trigger/heal.qc | 39 +- qcsrc/common/triggers/trigger/hurt.qc | 72 +- qcsrc/common/triggers/trigger/impulse.qc | 95 +- qcsrc/common/triggers/trigger/keylock.qc | 85 +- qcsrc/common/triggers/trigger/keylock.qh | 2 +- qcsrc/common/triggers/trigger/magicear.qc | 123 +- qcsrc/common/triggers/trigger/monoflop.qc | 14 +- .../common/triggers/trigger/multivibrator.qc | 32 +- .../triggers/trigger/relay_activators.qc | 20 +- qcsrc/common/triggers/trigger/relay_if.qc | 8 +- qcsrc/common/triggers/trigger/secret.qc | 27 +- qcsrc/common/triggers/trigger/swamp.qc | 44 +- qcsrc/common/triggers/trigger/swamp.qh | 8 +- qcsrc/common/triggers/trigger/viewloc.qc | 69 +- qcsrc/common/triggers/triggers.qc | 148 +- qcsrc/common/triggers/triggers.qh | 14 +- qcsrc/common/turrets/all.qh | 85 +- qcsrc/common/turrets/checkpoint.qc | 46 +- qcsrc/common/turrets/config.qc | 24 +- qcsrc/common/turrets/config.qh | 7 +- qcsrc/common/turrets/sv_turrets.qh | 70 +- qcsrc/common/turrets/targettrigger.qc | 22 +- qcsrc/common/turrets/turret/ewheel.qc | 337 +++-- qcsrc/common/turrets/turret/ewheel.qh | 4 +- qcsrc/common/turrets/turret/ewheel_weapon.qc | 57 +- qcsrc/common/turrets/turret/flac.qc | 15 +- qcsrc/common/turrets/turret/flac.qh | 2 +- qcsrc/common/turrets/turret/flac_weapon.qc | 77 +- qcsrc/common/turrets/turret/fusionreactor.qc | 74 +- qcsrc/common/turrets/turret/hellion.qc | 25 +- qcsrc/common/turrets/turret/hellion.qh | 2 +- qcsrc/common/turrets/turret/hellion_weapon.qc | 143 +- qcsrc/common/turrets/turret/hk.qc | 55 +- qcsrc/common/turrets/turret/hk.qh | 4 +- qcsrc/common/turrets/turret/hk_weapon.qc | 474 +++--- qcsrc/common/turrets/turret/machinegun.qc | 17 +- qcsrc/common/turrets/turret/machinegun.qh | 2 +- .../turrets/turret/machinegun_weapon.qc | 31 +- qcsrc/common/turrets/turret/mlrs.qc | 30 +- qcsrc/common/turrets/turret/mlrs.qh | 2 +- qcsrc/common/turrets/turret/mlrs_weapon.qc | 37 +- qcsrc/common/turrets/turret/phaser.qc | 51 +- qcsrc/common/turrets/turret/phaser.qh | 2 +- qcsrc/common/turrets/turret/phaser_weapon.qc | 132 +- qcsrc/common/turrets/turret/plasma.qh | 2 +- qcsrc/common/turrets/turret/plasma_dual.qh | 2 +- qcsrc/common/turrets/turret/plasma_weapon.qc | 30 +- qcsrc/common/turrets/turret/tesla.qc | 145 +- qcsrc/common/turrets/turret/tesla.qh | 2 +- qcsrc/common/turrets/turret/tesla_weapon.qc | 121 +- qcsrc/common/turrets/turret/walker.qc | 994 +++++++------ qcsrc/common/turrets/turret/walker.qh | 4 +- qcsrc/common/turrets/turret/walker_weapon.qc | 34 +- qcsrc/common/turrets/util.qc | 74 +- qcsrc/common/vehicles/cl_vehicles.qc | 172 +-- qcsrc/common/vehicles/sv_vehicles.qh | 25 +- qcsrc/common/vehicles/vehicle/bumblebee.qc | 883 ++++++------ qcsrc/common/vehicles/vehicle/bumblebee.qh | 6 +- qcsrc/common/vehicles/vehicle/racer.qc | 453 +++--- qcsrc/common/vehicles/vehicle/racer.qh | 4 +- qcsrc/common/vehicles/vehicle/racer_weapon.qc | 274 ++-- qcsrc/common/vehicles/vehicle/raptor.qc | 799 +++++----- qcsrc/common/vehicles/vehicle/raptor.qh | 4 +- .../common/vehicles/vehicle/raptor_weapons.qc | 386 ++--- qcsrc/common/vehicles/vehicle/spiderbot.qc | 478 +++--- qcsrc/common/vehicles/vehicle/spiderbot.qh | 4 +- .../vehicles/vehicle/spiderbot_weapons.qc | 417 +++--- qcsrc/common/viewloc.qc | 96 +- qcsrc/common/weapons/calculations.qc | 130 +- qcsrc/common/weapons/calculations.qh | 2 +- qcsrc/common/weapons/config.qc | 22 +- qcsrc/common/weapons/config.qh | 25 +- qcsrc/common/weapons/weapon/fireball.qc | 265 ++-- qcsrc/common/weapons/weapon/hook.qc | 360 +++-- qcsrc/common/weapons/weapon/shockwave.qc | 413 +++--- qcsrc/common/weapons/weapon/tuba.qh | 46 +- qcsrc/ecs/lib.qh | 47 +- qcsrc/ecs/systems/cl_physics.qc | 5 +- qcsrc/ecs/systems/sv_physics.qc | 28 +- qcsrc/lib/accumulate.qh | 59 +- qcsrc/lib/angle.qc | 38 +- qcsrc/lib/bits.qh | 46 +- qcsrc/lib/bool.qh | 9 +- qcsrc/lib/color.qh | 69 +- qcsrc/lib/counting.qh | 56 +- qcsrc/lib/csqcmodel/cl_model.qc | 134 +- qcsrc/lib/csqcmodel/cl_model.qh | 6 +- qcsrc/lib/csqcmodel/cl_player.qc | 129 +- qcsrc/lib/csqcmodel/cl_player.qh | 4 +- qcsrc/lib/csqcmodel/common.qh | 3 +- qcsrc/lib/csqcmodel/settings.qh | 16 +- qcsrc/lib/csqcmodel/sv_model.qc | 38 +- qcsrc/lib/csqcmodel/sv_model.qh | 6 +- qcsrc/lib/cvar.qh | 21 +- qcsrc/lib/defer.qh | 52 +- qcsrc/lib/enumclass.qh | 6 +- qcsrc/lib/file.qh | 2 +- qcsrc/lib/i18n.qh | 31 +- qcsrc/lib/iter.qh | 136 +- qcsrc/lib/json.qc | 507 ++++--- qcsrc/lib/linkedlist.qh | 13 +- qcsrc/lib/log.qh | 24 +- qcsrc/lib/map.qh | 59 +- qcsrc/lib/markdown.qh | 5 +- qcsrc/lib/matrix/command.qc | 87 +- qcsrc/lib/matrix/matrix.qc | 313 ++-- qcsrc/lib/nil.qh | 4 +- qcsrc/lib/noise.qh | 10 +- qcsrc/lib/p2mathlib.qc | 5 +- qcsrc/lib/p99.qh | 106 +- qcsrc/lib/random.qc | 85 +- qcsrc/lib/random.qh | 8 +- qcsrc/lib/registry.qh | 109 +- qcsrc/lib/replicate.qh | 66 +- qcsrc/lib/sort.qh | 42 +- qcsrc/lib/sortlist.qh | 4 +- qcsrc/lib/static.qh | 25 +- qcsrc/lib/string.qh | 114 +- qcsrc/lib/test.qc | 16 +- qcsrc/lib/test.qh | 41 +- qcsrc/lib/urllib.qc | 157 +- qcsrc/lib/urllib.qh | 2 +- qcsrc/lib/warpzone/anglestransform.qc | 47 +- qcsrc/lib/warpzone/anglestransform.qh | 30 +- qcsrc/lib/warpzone/client.qc | 122 +- qcsrc/lib/warpzone/common.qc | 337 ++--- qcsrc/lib/warpzone/common.qh | 55 +- qcsrc/lib/warpzone/mathlib.qc | 58 +- qcsrc/lib/warpzone/mathlib.qh | 56 +- qcsrc/lib/warpzone/server.qc | 459 +++--- qcsrc/lib/warpzone/server.qh | 7 +- qcsrc/lib/warpzone/util_server.qc | 33 +- qcsrc/lib/yenc.qh | 10 +- qcsrc/menu/anim/animation.qc | 167 ++- qcsrc/menu/anim/animhost.qc | 169 +-- qcsrc/menu/anim/easing.qc | 93 +- qcsrc/menu/anim/keyframe.qc | 142 +- qcsrc/menu/gamesettings.qh | 4 +- qcsrc/menu/item/borderimage.qc | 136 +- qcsrc/menu/item/checkbox.qc | 69 +- qcsrc/menu/item/checkbox.qh | 2 +- qcsrc/menu/item/dialog.qc | 234 ++- qcsrc/menu/item/dialog.qh | 2 +- qcsrc/menu/item/label.qc | 259 ++-- qcsrc/menu/item/modalcontroller.qc | 423 +++--- qcsrc/menu/item/radiobutton.qc | 38 +- qcsrc/menu/item/tab.qh | 2 +- qcsrc/menu/item/textslider.qc | 119 +- qcsrc/menu/menu.qc | 550 +++---- qcsrc/menu/skin.qh | 20 +- qcsrc/menu/xonotic/button.qc | 7 +- qcsrc/menu/xonotic/campaign.qc | 136 +- qcsrc/menu/xonotic/charmap.qc | 27 +- qcsrc/menu/xonotic/checkbox.qc | 32 +- qcsrc/menu/xonotic/checkbox_slider_invalid.qc | 16 +- qcsrc/menu/xonotic/checkbox_string.qc | 14 +- qcsrc/menu/xonotic/colorbutton.qc | 70 +- qcsrc/menu/xonotic/commandbutton.qc | 7 +- qcsrc/menu/xonotic/commandbutton.qh | 6 +- qcsrc/menu/xonotic/credits.qc | 746 +++++----- qcsrc/menu/xonotic/crosshairpicker.qc | 12 +- qcsrc/menu/xonotic/crosshairpreview.qc | 12 +- qcsrc/menu/xonotic/cvarlist.qc | 116 +- qcsrc/menu/xonotic/datasource.qc | 72 +- qcsrc/menu/xonotic/datasource.qh | 55 +- qcsrc/menu/xonotic/demolist.qc | 97 +- qcsrc/menu/xonotic/demolist.qh | 2 +- qcsrc/menu/xonotic/dialog_credits.qc | 8 +- qcsrc/menu/xonotic/dialog_firstrun.qc | 60 +- qcsrc/menu/xonotic/dialog_hudpanel_ammo.qc | 26 +- .../xonotic/dialog_hudpanel_centerprint.qc | 32 +- qcsrc/menu/xonotic/dialog_hudpanel_chat.qc | 18 +- .../xonotic/dialog_hudpanel_engineinfo.qc | 6 +- .../xonotic/dialog_hudpanel_healtharmor.qc | 40 +- .../xonotic/dialog_hudpanel_infomessages.qc | 6 +- .../menu/xonotic/dialog_hudpanel_itemstime.qc | 32 +- .../xonotic/dialog_hudpanel_notification.qc | 22 +- qcsrc/menu/xonotic/dialog_hudpanel_physics.qc | 94 +- .../menu/xonotic/dialog_hudpanel_powerups.qc | 36 +- .../xonotic/dialog_hudpanel_pressedkeys.qc | 16 +- .../menu/xonotic/dialog_hudpanel_quickmenu.qc | 10 +- qcsrc/menu/xonotic/dialog_hudpanel_radar.qc | 58 +- qcsrc/menu/xonotic/dialog_hudpanel_score.qc | 12 +- qcsrc/menu/xonotic/dialog_hudpanel_timer.qc | 6 +- qcsrc/menu/xonotic/dialog_hudpanel_vote.qc | 4 +- qcsrc/menu/xonotic/dialog_hudpanel_weapons.qc | 101 +- qcsrc/menu/xonotic/dialog_hudsetup_exit.qc | 243 ++-- qcsrc/menu/xonotic/dialog_multiplayer.qc | 10 +- .../menu/xonotic/dialog_multiplayer_create.qh | 2 +- .../dialog_multiplayer_create_mapinfo.qc | 70 +- .../dialog_multiplayer_create_mutators.qc | 301 ++-- qcsrc/menu/xonotic/dialog_multiplayer_join.qc | 94 +- .../xonotic/dialog_multiplayer_media_demo.qc | 57 +- ...log_multiplayer_media_demo_startconfirm.qc | 16 +- ...alog_multiplayer_media_demo_timeconfirm.qc | 16 +- .../dialog_multiplayer_media_musicplayer.qc | 91 +- .../dialog_multiplayer_media_screenshot.qc | 64 +- ...log_multiplayer_media_screenshot_viewer.qc | 116 +- .../xonotic/dialog_multiplayer_profile.qc | 186 +-- .../xonotic/dialog_multiplayer_profile.qh | 2 +- qcsrc/menu/xonotic/dialog_quit.qc | 10 +- qcsrc/menu/xonotic/dialog_sandboxtools.qc | 106 +- qcsrc/menu/xonotic/dialog_settings.qc | 16 +- qcsrc/menu/xonotic/dialog_settings_audio.qc | 268 ++-- qcsrc/menu/xonotic/dialog_settings_audio.qh | 2 +- qcsrc/menu/xonotic/dialog_settings_effects.qc | 343 ++--- qcsrc/menu/xonotic/dialog_settings_effects.qh | 2 +- .../xonotic/dialog_settings_game_crosshair.qc | 223 +-- .../menu/xonotic/dialog_settings_game_hud.qc | 184 ++- .../dialog_settings_game_hudconfirm.qc | 21 +- .../xonotic/dialog_settings_game_messages.qc | 117 +- .../menu/xonotic/dialog_settings_game_view.qc | 139 +- .../xonotic/dialog_settings_game_weapons.qc | 80 +- qcsrc/menu/xonotic/dialog_settings_input.qc | 129 +- qcsrc/menu/xonotic/dialog_settings_input.qh | 2 +- .../xonotic/dialog_settings_input_userbind.qc | 30 +- qcsrc/menu/xonotic/dialog_settings_misc.qc | 218 +-- .../xonotic/dialog_settings_misc_cvars.qc | 87 +- .../xonotic/dialog_settings_misc_reset.qc | 12 +- qcsrc/menu/xonotic/dialog_settings_user.qc | 60 +- .../dialog_settings_user_languagewarning.qc | 10 +- qcsrc/menu/xonotic/dialog_settings_video.qc | 203 ++- qcsrc/menu/xonotic/dialog_settings_video.qh | 2 +- qcsrc/menu/xonotic/dialog_singleplayer.qc | 76 +- .../xonotic/dialog_singleplayer_winner.qc | 8 +- qcsrc/menu/xonotic/dialog_teamselect.qc | 26 +- qcsrc/menu/xonotic/dialog_uid2name.qc | 10 +- qcsrc/menu/xonotic/gametypelist.qc | 45 +- qcsrc/menu/xonotic/hudskinlist.qc | 101 +- qcsrc/menu/xonotic/inputbox.qc | 31 +- qcsrc/menu/xonotic/inputbox.qh | 2 +- qcsrc/menu/xonotic/languagelist.qc | 44 +- qcsrc/menu/xonotic/languagelist.qh | 4 +- qcsrc/menu/xonotic/maplist.qc | 208 ++- qcsrc/menu/xonotic/nexposee.qc | 3 +- qcsrc/menu/xonotic/playerlist.qc | 42 +- qcsrc/menu/xonotic/playlist.qc | 116 +- qcsrc/menu/xonotic/radiobutton.qc | 68 +- qcsrc/menu/xonotic/screenshotlist.qc | 129 +- qcsrc/menu/xonotic/serverlist.qc | 669 +++++---- qcsrc/menu/xonotic/serverlist.qh | 18 +- qcsrc/menu/xonotic/skinlist.qc | 47 +- qcsrc/menu/xonotic/slider.qc | 24 +- qcsrc/menu/xonotic/slider_decibels.qc | 44 +- qcsrc/menu/xonotic/slider_particles.qc | 9 +- qcsrc/menu/xonotic/slider_picmip.qc | 14 +- qcsrc/menu/xonotic/slider_picmip.qh | 2 +- qcsrc/menu/xonotic/slider_resolution.qc | 129 +- qcsrc/menu/xonotic/slider_sbfadetime.qc | 5 +- qcsrc/menu/xonotic/soundlist.qc | 42 +- qcsrc/menu/xonotic/statslist.qc | 119 +- qcsrc/menu/xonotic/statslist.qh | 2 +- qcsrc/menu/xonotic/tabcontroller.qc | 5 +- qcsrc/menu/xonotic/textslider.qc | 56 +- qcsrc/menu/xonotic/textslider.qh | 2 +- qcsrc/menu/xonotic/util.qh | 4 +- qcsrc/menu/xonotic/weaponarenacheckbox.qc | 11 +- qcsrc/menu/xonotic/weaponslist.qc | 40 +- qcsrc/server-testcase/framework.qc | 7 +- qcsrc/server/antilag.qc | 72 +- qcsrc/server/bot/default/aim.qc | 282 ++-- qcsrc/server/bot/default/aim.qh | 5 +- qcsrc/server/bot/default/scripting.qc | 602 ++++---- qcsrc/server/bot/default/scripting.qh | 70 +- qcsrc/server/campaign.qc | 121 +- qcsrc/server/cheats.qh | 2 +- qcsrc/server/client.qh | 416 +++--- qcsrc/server/command/banning.qc | 88 +- qcsrc/server/command/banning.qh | 4 +- qcsrc/server/command/common.qc | 298 ++-- qcsrc/server/command/common.qh | 91 +- qcsrc/server/command/getreplies.qc | 158 +- qcsrc/server/command/radarmap.qc | 164 +-- qcsrc/server/command/reg.qh | 10 +- qcsrc/server/compat/halflife.qc | 2 +- qcsrc/server/compat/quake.qc | 58 +- qcsrc/server/compat/quake2.qc | 16 +- qcsrc/server/compat/quake3.qc | 213 ++- qcsrc/server/compat/wop.qc | 120 +- qcsrc/server/g_damage.qh | 76 +- qcsrc/server/g_hook.qc | 206 ++- qcsrc/server/g_hook.qh | 2 +- qcsrc/server/g_lights.qc | 53 +- qcsrc/server/g_subs.qc | 222 ++- qcsrc/server/g_subs.qh | 50 +- qcsrc/server/g_world.qh | 8 +- qcsrc/server/ipban.qc | 333 +++-- qcsrc/server/item_key.qc | 139 +- qcsrc/server/item_key.qh | 4 +- qcsrc/server/mapvoting.qc | 501 ++++--- qcsrc/server/mutators/loader.qc | 19 +- .../mutators/mutator/gamemode_assault.qh | 14 +- qcsrc/server/mutators/mutator/gamemode_ca.qh | 20 +- qcsrc/server/mutators/mutator/gamemode_ctf.qh | 86 +- qcsrc/server/mutators/mutator/gamemode_cts.qh | 6 +- .../mutators/mutator/gamemode_deathmatch.qh | 2 +- .../mutators/mutator/gamemode_domination.qh | 14 +- .../mutators/mutator/gamemode_freezetag.qh | 8 +- .../mutators/mutator/gamemode_invasion.qh | 6 +- .../mutators/mutator/gamemode_keepaway.qh | 12 +- .../mutators/mutator/gamemode_keyhunt.qh | 10 +- qcsrc/server/mutators/mutator/gamemode_lms.qc | 188 +-- qcsrc/server/mutators/mutator/gamemode_lms.qh | 16 +- .../server/mutators/mutator/gamemode_race.qh | 2 +- qcsrc/server/pathlib/costs.qc | 132 +- qcsrc/server/pathlib/debug.qc | 155 +- qcsrc/server/pathlib/expandnode.qc | 385 +++-- qcsrc/server/pathlib/main.qc | 904 ++++++------ qcsrc/server/pathlib/main.qh | 2 +- qcsrc/server/pathlib/movenode.qc | 238 +-- qcsrc/server/pathlib/path_waypoint.qc | 316 ++-- qcsrc/server/pathlib/pathlib.qh | 30 +- qcsrc/server/pathlib/utility.qc | 362 ++--- qcsrc/server/pathlib/utility.qh | 2 +- qcsrc/server/playerdemo.qc | 68 +- qcsrc/server/round_handler.qc | 50 +- qcsrc/server/round_handler.qh | 6 +- qcsrc/server/steerlib.qc | 715 +++++---- qcsrc/server/steerlib.qh | 7 +- qcsrc/server/sys-pre.qh | 44 +- qcsrc/server/teamplay.qh | 24 +- qcsrc/server/tests.qc | 66 +- qcsrc/server/weapons/common.qc | 79 +- qcsrc/server/weapons/common.qh | 2 +- qcsrc/server/weapons/hitplot.qc | 60 +- qcsrc/server/weapons/selection.qc | 233 +-- qcsrc/server/weapons/selection.qh | 2 +- qcsrc/server/weapons/tracing.qh | 36 +- qcsrc/server/weapons/weaponstats.qc | 56 +- qcsrc/server/weapons/weaponstats.qh | 2 +- 497 files changed, 24750 insertions(+), 25070 deletions(-) diff --git a/qcsrc/client/announcer.qc b/qcsrc/client/announcer.qc index 87c8dcc4e..bc82508c7 100644 --- a/qcsrc/client/announcer.qc +++ b/qcsrc/client/announcer.qc @@ -21,45 +21,41 @@ void Announcer_Countdown(entity this) { float starttime = STAT(GAMESTARTTIME); float roundstarttime = STAT(ROUNDSTARTTIME); - if(roundstarttime == -1) - { + if (roundstarttime == -1) { Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTOP); delete(this); announcer_countdown = NULL; return; } - if(roundstarttime >= starttime) + if (roundstarttime >= starttime) { starttime = roundstarttime; - if(starttime <= time && roundstarttime != starttime) // game start time has passed + } + if (starttime <= time && roundstarttime != starttime) { // game start time has passed announcer_5min = announcer_1min = false; // reset maptime announcers now as well - + } float countdown = (starttime - time); float countdown_rounded = floor(0.5 + countdown); - if(countdown <= 0) // countdown has finished, starttime is now - { + if (countdown <= 0) { // countdown has finished, starttime is now Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_BEGIN); Local_Notification(MSG_MULTI, MULTI_COUNTDOWN_BEGIN); delete(this); announcer_countdown = NULL; return; - } - else // countdown is still going - { - // if concomitant countdown to round start overrides countdown to game start - if(roundstarttime == starttime) - { + } else { // countdown is still going + // if concomitant countdown to round start overrides countdown to game start + if (roundstarttime == starttime) { Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_ROUNDSTART, countdown_rounded); Notification annce_num = Announcer_PickNumber(CNT_ROUNDSTART, countdown_rounded); - if(annce_num != NULL) + if (annce_num != NULL) { Local_Notification(MSG_ANNCE, annce_num); - } - else - { + } + } else { Local_Notification(MSG_CENTER, CENTER_COUNTDOWN_GAMESTART, countdown_rounded); Notification annce_num = Announcer_PickNumber(CNT_GAMESTART, countdown_rounded); - if(annce_num != NULL) + if (annce_num != NULL) { Local_Notification(MSG_ANNCE, annce_num); + } } this.nextthink = (starttime - (countdown - 1)); @@ -73,20 +69,18 @@ void Announcer_Countdown(entity this) * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT * and STAT_FRAGLIMIT to be auto-sent) */ - float previous_game_starttime; +float previous_game_starttime; void Announcer_Gamestart() { float startTime = STAT(GAMESTARTTIME); float roundstarttime = STAT(ROUNDSTARTTIME); - if(roundstarttime > startTime) + if (roundstarttime > startTime) { startTime = roundstarttime; - if(intermission) - { - if(announcer_countdown) - { + } + if (intermission) { + if (announcer_countdown) { centerprint_kill(ORDINAL(CPID_ROUND)); - if(announcer_countdown) - { + if (announcer_countdown) { delete(announcer_countdown); announcer_countdown = NULL; } @@ -94,58 +88,61 @@ void Announcer_Gamestart() return; } - if(previous_game_starttime != startTime) - { - if(time < startTime) - { - if (!announcer_countdown) - { + if (previous_game_starttime != startTime) { + if (time < startTime) { + if (!announcer_countdown) { announcer_countdown = new(announcer_countdown); setthink(announcer_countdown, Announcer_Countdown); } - if(time + 5.0 < startTime) // if connecting to server while restart was active don't always play prepareforbattle - if(time > announcer_countdown.nextthink) // don't play it again if countdown was already going - Local_Notification(MSG_ANNCE, ANNCE_PREPARE); + if (time + 5.0 < startTime) { // if connecting to server while restart was active don't always play prepareforbattle + if (time > announcer_countdown.nextthink) { // don't play it again if countdown was already going + Local_Notification(MSG_ANNCE, ANNCE_PREPARE); + } + } - announcer_countdown.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime + announcer_countdown.nextthink = startTime - floor(startTime - time); // synchronize nextthink to startTime } } previous_game_starttime = startTime; } -#define ANNOUNCER_CHECKMINUTE(minute) MACRO_BEGIN \ - if(announcer_##minute##min) { \ - if(timeleft > minute * 60) \ - announcer_##minute##min = false; \ - } else { \ - if(timeleft < minute * 60 && timeleft > minute * 60 - 1) { \ - announcer_##minute##min = true; \ - Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \ +#define ANNOUNCER_CHECKMINUTE(minute) \ + MACRO_BEGIN \ + if (announcer_##minute##min) { \ + if (timeleft > minute * 60) { \ + announcer_##minute##min = false; \ + } \ + } else { \ + if (timeleft < minute * 60 && timeleft > minute * 60 - 1) { \ + announcer_##minute##min = true; \ + Local_Notification(MSG_ANNCE, ANNCE_REMAINING_MIN_##minute); \ + } \ } \ - } \ -MACRO_END + MACRO_END void Announcer_Time() { float timeleft; - if(warmup_stage) - { + if (warmup_stage) { float warmup_timelimit = STAT(WARMUP_TIMELIMIT); - if(warmup_timelimit > 0) + if (warmup_timelimit > 0) { timeleft = max(0, warmup_timelimit - time); - else + } else { timeleft = 0; - } - else + } + } else { timeleft = max(0, STAT(TIMELIMIT) * 60 + STAT(GAMESTARTTIME) - time); + } - if(autocvar_cl_announcer_maptime >= 2) + if (autocvar_cl_announcer_maptime >= 2) { ANNOUNCER_CHECKMINUTE(5); + } - if((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3)) + if ((autocvar_cl_announcer_maptime == 1) || (autocvar_cl_announcer_maptime == 3)) { ANNOUNCER_CHECKMINUTE(1); + } } void Announcer() diff --git a/qcsrc/client/bgmscript.qc b/qcsrc/client/bgmscript.qc index 2db9e54cf..36be15ac9 100644 --- a/qcsrc/client/bgmscript.qc +++ b/qcsrc/client/bgmscript.qc @@ -11,12 +11,12 @@ float bgmscriptbuf; float bgmscriptbufsize; float bgmscriptbufloaded; -class(BGMScript) .float bgmscriptline; -class(BGMScript) .float bgmscriptline0; -class(BGMScript) .float bgmscriptvolume; -class(BGMScript) .float bgmscripttime; -class(BGMScript) .float bgmscriptstate; -class(BGMScript) .float bgmscriptstatetime; +class(BGMScript).float bgmscriptline; +class(BGMScript).float bgmscriptline0; +class(BGMScript).float bgmscriptvolume; +class(BGMScript).float bgmscripttime; +class(BGMScript).float bgmscriptstate; +class(BGMScript).float bgmscriptstatetime; float GetAttackDecaySustainAmplitude(float a, float d, float s, float t) { @@ -25,16 +25,21 @@ float GetAttackDecaySustainAmplitude(float a, float d, float s, float t) // decay: from 1 to s, in time d // sustain: s - if(t < 0) + if (t < 0) { return 0; + } - if(a) - if(t <= a) + if (a) { + if (t <= a) { return t / a; + } + } - if(d) - if(t <= a + d) + if (d) { + if (t <= a + d) { return ((t - a) / d) * (s - 1) + 1; + } + } return s; } @@ -43,19 +48,21 @@ float GetReleaseAmplitude(float d, float s, float r, float t) { float decayval, releaseval; - if(!r) + if (!r) { return 0; + } - if(t > r) + if (t > r) { return 0; + } releaseval = s * (1 - t / r); - if(t < -d) + if (t < -d) { return 1; + } - if(t < 0 && t >= -d) - { + if (t < 0 && t >= -d) { // pre-time decay // value is s at time 0 // 1 at time -d @@ -75,16 +82,17 @@ float GetReleaseTime(float d, float s, float r, float amp) { float decaytime, releasetime; - if(!s) + if (!s) { return 0; + } // if amp > s, we may be in the attack or in the prolonged decay curve releasetime = (1 - amp / s) * r; - if(amp > s) - { - if(s == 1) // gracefully handle division by zero here + if (amp > s) { + if (s == 1) { // gracefully handle division by zero here return 0; + } // pre-time decay // value is s at time 0 @@ -104,11 +112,11 @@ void BGMScript_Init() bgmscriptbufloaded = 1; s = strcat("maps/", mi_shortname, ".bgs"); fh = fopen(s, FILE_READ); - if(fh < 0) + if (fh < 0) { return; + } bgmscriptbuf = buf_create(); - while((s = fgets(fh))) - { + while ((s = fgets(fh))) { bufstr_set(bgmscriptbuf, bgmscriptbufsize, s); ++bgmscriptbufsize; } @@ -119,10 +127,10 @@ void BGMScript_InitEntity(entity e) { float l; string m; - if(e.bgmscript != "") - { - if(!bgmscriptbufloaded) + if (e.bgmscript != "") { + if (!bgmscriptbufloaded) { BGMScript_Init(); + } float i; @@ -130,14 +138,13 @@ void BGMScript_InitEntity(entity e) l = strlen(m); e.bgmscriptline0 = -1; - for(i = 0; i < bgmscriptbufsize; ++i) - { - if(substring(bufstr_get(bgmscriptbuf, i), 0, l) == m) + for (i = 0; i < bgmscriptbufsize; ++i) { + if (substring(bufstr_get(bgmscriptbuf, i), 0, l) == m) { break; + } } e.bgmscriptline = e.bgmscriptline0 = i; - if(i >= bgmscriptbufsize) - { + if (i >= bgmscriptbufsize) { LOG_INFOF("ERROR: bgmscript does not define %s", e.bgmscript); strunzone(e.bgmscript); e.bgmscript = string_null; @@ -147,10 +154,9 @@ void BGMScript_InitEntity(entity e) float GetCurrentAmplitude(entity e, float trel) { - if(e.bgmscriptstate) + if (e.bgmscriptstate) { return GetAttackDecaySustainAmplitude(e.bgmscriptattack, e.bgmscriptdecay, e.bgmscriptsustain, trel) * e.bgmscriptvolume; - else - { + } else { #ifdef CONSTANT_SPEED_DECAY return GetReleaseAmplitude(e.bgmscriptdecay, e.bgmscriptsustain * e.bgmscriptvolume, e.bgmscriptrelease, trel); #else @@ -161,10 +167,9 @@ float GetCurrentAmplitude(entity e, float trel) float GetTimeForAmplitude(entity e, float amp) { - if(e.bgmscriptstate) + if (e.bgmscriptstate) { return GetAttackTime(e.bgmscriptattack, amp / e.bgmscriptvolume); - else - { + } else { #ifdef CONSTANT_SPEED_DECAY return GetReleaseTime(e.bgmscriptdecay, e.bgmscriptsustain * e.bgmscriptvolume, e.bgmscriptrelease, amp); #else @@ -177,19 +182,21 @@ float doBGMScript(entity e) { float amp, vel; - if(e.bgmscript == "") + if (e.bgmscript == "") { return 1; + } - if(autocvar_bgmvolume <= 0) + if (autocvar_bgmvolume <= 0) { return -1; + } e.just_toggled = false; - if(bgmtime < 0) + if (bgmtime < 0) { return -1; + } - if(bgmtime < e.bgmscripttime) - { + if (bgmtime < e.bgmscripttime) { amp = GetCurrentAmplitude(e, e.bgmscripttime - e.bgmscriptstatetime + drawframetime); e.bgmscriptline = e.bgmscriptline0; @@ -202,16 +209,12 @@ float doBGMScript(entity e) } // find the CURRENT line - for (;;) - { + for ( ; ; ) { tokenize_console(bufstr_get(bgmscriptbuf, e.bgmscriptline)); - if(stof(argv(1)) >= bgmtime || argv(0) != e.bgmscript) - { + if (stof(argv(1)) >= bgmtime || argv(0) != e.bgmscript) { e.bgmscripttime = bgmtime; return GetCurrentAmplitude(e, bgmtime - e.bgmscriptstatetime); - } - else if(bgmtime >= stof(argv(1))) - { + } else if (bgmtime >= stof(argv(1))) { e.bgmscriptline += 1; e.bgmscripttime = stof(argv(1)); @@ -219,16 +222,14 @@ float doBGMScript(entity e) // time code reached! vel = stof(argv(2)); - if(vel > 0) - { + if (vel > 0) { e.just_toggled = e.bgmscriptstate = true; e.bgmscriptvolume = vel; - } - else + } else { e.just_toggled = e.bgmscriptstate = false; + } e.bgmscriptstatetime = e.bgmscripttime - GetTimeForAmplitude(e, amp); } } } - diff --git a/qcsrc/client/bgmscript.qh b/qcsrc/client/bgmscript.qh index 18b0d5ee4..2ab3364c8 100644 --- a/qcsrc/client/bgmscript.qh +++ b/qcsrc/client/bgmscript.qh @@ -1,13 +1,13 @@ #pragma once entityclass(BGMScript); -class(BGMScript) .string bgmscript; -class(BGMScript) .float bgmscriptattack; -class(BGMScript) .float bgmscriptdecay; -class(BGMScript) .float bgmscriptsustain; -class(BGMScript) .float bgmscriptrelease; +class(BGMScript).string bgmscript; +class(BGMScript).float bgmscriptattack; +class(BGMScript).float bgmscriptdecay; +class(BGMScript).float bgmscriptsustain; +class(BGMScript).float bgmscriptrelease; -class(BGMScript) .float just_toggled; +class(BGMScript).float just_toggled; #ifdef CSQC void BGMScript_InitEntity(entity e); diff --git a/qcsrc/client/commands/cl_cmd.qh b/qcsrc/client/commands/cl_cmd.qh index f1be4315f..2fc5bf1ed 100644 --- a/qcsrc/client/commands/cl_cmd.qh +++ b/qcsrc/client/commands/cl_cmd.qh @@ -14,11 +14,12 @@ REGISTRY_SORT(CLIENT_COMMANDS) #define CLIENT_COMMAND(id, description) \ CLASS(clientcommand_##id, Command) \ ATTRIB(clientcommand_##id, m_name, string, #id); \ - ATTRIB(clientcommand_##id, m_description, string, description); \ + ATTRIB(clientcommand_##id, m_description, string, description); \ ENDCLASS(clientcommand_##id) \ - REGISTER(CLIENT_COMMANDS, CMD_CL, id, m_id, NEW(clientcommand_##id)); \ + REGISTER(CLIENT_COMMANDS, CMD_CL, id, m_id, NEW(clientcommand_##id)); \ METHOD(clientcommand_##id, m_invokecmd, void(clientcommand_##id this, int request, entity caller, int arguments, string command)) -STATIC_INIT(CLIENT_COMMANDS_aliases) { +STATIC_INIT(CLIENT_COMMANDS_aliases) +{ FOREACH(CLIENT_COMMANDS, true, localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_cl"))); } diff --git a/qcsrc/client/csqc_constants.qh b/qcsrc/client/csqc_constants.qh index d8906b12b..4889003d8 100644 --- a/qcsrc/client/csqc_constants.qh +++ b/qcsrc/client/csqc_constants.qh @@ -1,106 +1,106 @@ #pragma once // Mask Constants (set .drawmask on entities; use R_AddEntities to add all entities based on mask) -const int MASK_ENGINE = BIT(0); -const int MASK_ENGINEVIEWMODELS = BIT(1); -const int MASK_NORMAL = BIT(2); +const int MASK_ENGINE = BIT(0); +const int MASK_ENGINEVIEWMODELS = BIT(1); +const int MASK_NORMAL = BIT(2); // Renderflag Constants (used for CSQC entities) -const int RF_VIEWMODEL = BIT(0); -const int RF_EXTERNALMODEL = BIT(1); -const int RF_DEPTHHACK = BIT(2); -const int RF_ADDITIVE = BIT(3); -const int RF_USEAXIS = BIT(4); +const int RF_VIEWMODEL = BIT(0); +const int RF_EXTERNALMODEL = BIT(1); +const int RF_DEPTHHACK = BIT(2); +const int RF_ADDITIVE = BIT(3); +const int RF_USEAXIS = BIT(4); // Viewflag Constants (use with R_SetView) -const int VF_MIN = 1; //(vector) -const int VF_MIN_X = 2; //(float) -const int VF_MIN_Y = 3; //(float) -const int VF_SIZE = 4; //(vector) (viewport size) -const int VF_SIZE_Y = 5; //(float) -const int VF_SIZE_X = 6; //(float) -const int VF_VIEWPORT = 7; //(vector, vector) -const int VF_FOV = 8; //(vector) -const int VF_FOVX = 9; //(float) -const int VF_FOVY = 10; //(float) -const int VF_ORIGIN = 11; //(vector) -const int VF_ORIGIN_X = 12; //(float) -const int VF_ORIGIN_Y = 13; //(float) -const int VF_ORIGIN_Z = 14; //(float) -const int VF_ANGLES = 15; //(vector) -const int VF_ANGLES_X = 16; //(float) -const int VF_ANGLES_Y = 17; //(float) -const int VF_ANGLES_Z = 18; //(float) -const int VF_DRAWWORLD = 19; //(float) -const int VF_DRAWENGINEHUD = 20; //(float) -const int VF_DRAWCROSSHAIR = 21; //(float) -const int VF_PERSPECTIVE = 200; //(float) - -const int VF_CL_VIEWANGLES = 33; //(vector) -const int VF_CL_VIEWANGLES_X = 34; //(float) -const int VF_CL_VIEWANGLES_Y = 35; //(float) -const int VF_CL_VIEWANGLES_Z = 36; //(float) +const int VF_MIN = 1; // (vector) +const int VF_MIN_X = 2; // (float) +const int VF_MIN_Y = 3; // (float) +const int VF_SIZE = 4; // (vector) (viewport size) +const int VF_SIZE_Y = 5; // (float) +const int VF_SIZE_X = 6; // (float) +const int VF_VIEWPORT = 7; // (vector, vector) +const int VF_FOV = 8; // (vector) +const int VF_FOVX = 9; // (float) +const int VF_FOVY = 10; // (float) +const int VF_ORIGIN = 11; // (vector) +const int VF_ORIGIN_X = 12; // (float) +const int VF_ORIGIN_Y = 13; // (float) +const int VF_ORIGIN_Z = 14; // (float) +const int VF_ANGLES = 15; // (vector) +const int VF_ANGLES_X = 16; // (float) +const int VF_ANGLES_Y = 17; // (float) +const int VF_ANGLES_Z = 18; // (float) +const int VF_DRAWWORLD = 19; // (float) +const int VF_DRAWENGINEHUD = 20; // (float) +const int VF_DRAWCROSSHAIR = 21; // (float) +const int VF_PERSPECTIVE = 200; // (float) + +const int VF_CL_VIEWANGLES = 33; // (vector) +const int VF_CL_VIEWANGLES_X = 34; // (float) +const int VF_CL_VIEWANGLES_Y = 35; // (float) +const int VF_CL_VIEWANGLES_Z = 36; // (float) // Quake-style Point Contents -const int CONTENT_EMPTY = -1; -const int CONTENT_SOLID = -2; -const int CONTENT_WATER = -3; -const int CONTENT_SLIME = -4; -const int CONTENT_LAVA = -5; -const int CONTENT_SKY = -6; +const int CONTENT_EMPTY = -1; +const int CONTENT_SOLID = -2; +const int CONTENT_WATER = -3; +const int CONTENT_SLIME = -4; +const int CONTENT_LAVA = -5; +const int CONTENT_SKY = -6; // Vector / Hull Constants -const vector VEC_1 = '1 1 1'; -const vector VEC_0 = '0 0 0'; -const vector VEC_M1 = '-1 -1 -1'; +const vector VEC_1 = '1 1 1'; +const vector VEC_0 = '0 0 0'; +const vector VEC_M1 = '-1 -1 -1'; -const vector VEC_HULL_MIN = '-16 -16 -24'; -const vector VEC_HULL_MAX = '16 16 32'; +const vector VEC_HULL_MIN = '-16 -16 -24'; +const vector VEC_HULL_MAX = '16 16 32'; // Effect Constants -const int EF_NODRAW = BIT(4); -const int EF_ADDITIVE = BIT(5); -const int EF_BLUE = BIT(6); -const int EF_RED = BIT(7); -const int EF_FULLBRIGHT = BIT(9); -const int EF_FLAME = BIT(10); -const int EF_STARDUST = BIT(11); -const int EF_NOSHADOW = BIT(12); -const int EF_NODEPTHTEST = BIT(13); +const int EF_NODRAW = BIT(4); +const int EF_ADDITIVE = BIT(5); +const int EF_BLUE = BIT(6); +const int EF_RED = BIT(7); +const int EF_FULLBRIGHT = BIT(9); +const int EF_FLAME = BIT(10); +const int EF_STARDUST = BIT(11); +const int EF_NOSHADOW = BIT(12); +const int EF_NODEPTHTEST = BIT(13); // Quake Player Flag Constants -const int PFL_ONGROUND = BIT(0); -const int PFL_CROUCH = BIT(1); -const int PFL_DEAD = BIT(2); -const int PFL_GIBBED = BIT(3); +const int PFL_ONGROUND = BIT(0); +const int PFL_CROUCH = BIT(1); +const int PFL_DEAD = BIT(2); +const int PFL_GIBBED = BIT(3); // Quake Temporary Entity Constants -const int TE_SPIKE = 0; -const int TE_SUPERSPIKE = 1; -const int TE_GUNSHOT = 2; -const int TE_EXPLOSION = 3; -const int TE_TAREXPLOSION = 4; -const int TE_LIGHTNING1 = 5; -const int TE_LIGHTNING2 = 6; -const int TE_WIZSPIKE = 7; -const int TE_KNIGHTSPIKE = 8; -const int TE_LIGHTNING3 = 9; -const int TE_LAVASPLASH = 10; -const int TE_TELEPORT = 11; -const int TE_EXPLOSION2 = 12; +const int TE_SPIKE = 0; +const int TE_SUPERSPIKE = 1; +const int TE_GUNSHOT = 2; +const int TE_EXPLOSION = 3; +const int TE_TAREXPLOSION = 4; +const int TE_LIGHTNING1 = 5; +const int TE_LIGHTNING2 = 6; +const int TE_WIZSPIKE = 7; +const int TE_KNIGHTSPIKE = 8; +const int TE_LIGHTNING3 = 9; +const int TE_LAVASPLASH = 10; +const int TE_TELEPORT = 11; +const int TE_EXPLOSION2 = 12; // Darkplaces Additions -const int TE_EXPLOSIONRGB = 53; -const int TE_GUNSHOTQUAD = 57; -const int TE_EXPLOSIONQUAD = 70; +const int TE_EXPLOSIONRGB = 53; +const int TE_GUNSHOTQUAD = 57; +const int TE_EXPLOSIONQUAD = 70; // Math Constants -const int EXTRA_LOW = -99999999; -const int EXTRA_HIGH = 99999999; +const int EXTRA_LOW = -99999999; +const int EXTRA_HIGH = 99999999; // Frik File Constants -const int FILE_READ = 0; -const int FILE_APPEND = 1; -const int FILE_WRITE = 2; +const int FILE_READ = 0; +const int FILE_APPEND = 1; +const int FILE_WRITE = 2; // Button values used by input_buttons const int BUTTON_ATTACK = BIT(0); @@ -123,16 +123,16 @@ const int BUTTON_14 = BIT(16); const int BUTTON_15 = BIT(17); const int BUTTON_16 = BIT(18); -const int SOLID_NOT = 0; // no interaction with other objects -const int SOLID_TRIGGER = 1; // touch on edge, but not blocking -const int SOLID_BBOX = 2; // touch on edge, block -const int SOLID_SLIDEBOX = 3; // touch on edge, but not an onground -const int SOLID_BSP = 4; // bsp clip, touch on edge, block -const int SOLID_CORPSE = 5; // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters) +const int SOLID_NOT = 0; // no interaction with other objects +const int SOLID_TRIGGER = 1; // touch on edge, but not blocking +const int SOLID_BBOX = 2; // touch on edge, block +const int SOLID_SLIDEBOX = 3; // touch on edge, but not an onground +const int SOLID_BSP = 4; // bsp clip, touch on edge, block +const int SOLID_CORPSE = 5; // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters) -const int MOVE_NORMAL = 0; // same as false -const int MOVE_NOMONSTERS = 1; // same as true -const int MOVE_MISSILE = 2; // save as movement with .move_movetype == MOVETYPE_FLYMISSILE +const int MOVE_NORMAL = 0; // same as false +const int MOVE_NOMONSTERS = 1; // same as true +const int MOVE_MISSILE = 2; // save as movement with .move_movetype == MOVETYPE_FLYMISSILE const int MOVE_HITMODEL = 4; const int MOVE_WORLDONLY = 3; diff --git a/qcsrc/client/csqcmodel_hooks.qh b/qcsrc/client/csqcmodel_hooks.qh index 56a3fb4a5..735b59131 100644 --- a/qcsrc/client/csqcmodel_hooks.qh +++ b/qcsrc/client/csqcmodel_hooks.qh @@ -10,14 +10,14 @@ const int EF_DYNAMICMODELLIGHT = BIT(17); const int EF_RESTARTANIM_BIT = BIT(20); const int EF_TELEPORT_BIT = BIT(21); -const int MF_ROCKET = BIT(0); // leave a trail -const int MF_GRENADE = BIT(1); // leave a trail -const int MF_GIB = BIT(2); // leave a trail -const int MF_ROTATE = BIT(3); // rotate (bonus items) -const int MF_TRACER = BIT(4); // green split trail -const int MF_ZOMGIB = BIT(5); // small blood trail -const int MF_TRACER2 = BIT(6); // orange split trail -const int MF_TRACER3 = BIT(7); // purple trail +const int MF_ROCKET = BIT(0); // leave a trail +const int MF_GRENADE = BIT(1); // leave a trail +const int MF_GIB = BIT(2); // leave a trail +const int MF_ROTATE = BIT(3); // rotate (bonus items) +const int MF_TRACER = BIT(4); // green split trail +const int MF_ZOMGIB = BIT(5); // small blood trail +const int MF_TRACER2 = BIT(6); // orange split trail +const int MF_TRACER3 = BIT(7); // purple trail .int csqcmodel_effects; .int csqcmodel_modelflags; diff --git a/qcsrc/client/hud/hud.qc b/qcsrc/client/hud/hud.qc index 9bcdd3d66..b34757743 100644 --- a/qcsrc/client/hud/hud.qc +++ b/qcsrc/client/hud/hud.qc @@ -25,91 +25,85 @@ Misc HUD functions ================== */ -vector HUD_Get_Num_Color (float hp, float maxvalue) +vector HUD_Get_Num_Color(float hp, float maxvalue) { float blinkingamt; vector color; - if(hp >= maxvalue) { - color.x = sin(2*M_PI*time); + if (hp >= maxvalue) { + color.x = sin(2 * M_PI * time); color.y = 1; - color.z = sin(2*M_PI*time); - } - else if(hp > maxvalue * 0.75) { - color.x = 0.4 - (hp-150)*0.02 * 0.4; //red value between 0.4 -> 0 - color.y = 0.9 + (hp-150)*0.02 * 0.1; // green value between 0.9 -> 1 + color.z = sin(2 * M_PI * time); + } else if (hp > maxvalue * 0.75) { + color.x = 0.4 - (hp - 150) * 0.02 * 0.4; // red value between 0.4 -> 0 + color.y = 0.9 + (hp - 150) * 0.02 * 0.1; // green value between 0.9 -> 1 color.z = 0; - } - else if(hp > maxvalue * 0.5) { - color.x = 1 - (hp-100)*0.02 * 0.6; //red value between 1 -> 0.4 - color.y = 1 - (hp-100)*0.02 * 0.1; // green value between 1 -> 0.9 - color.z = 1 - (hp-100)*0.02; // blue value between 1 -> 0 - } - else if(hp > maxvalue * 0.25) { + } else if (hp > maxvalue * 0.5) { + color.x = 1 - (hp - 100) * 0.02 * 0.6; // red value between 1 -> 0.4 + color.y = 1 - (hp - 100) * 0.02 * 0.1; // green value between 1 -> 0.9 + color.z = 1 - (hp - 100) * 0.02; // blue value between 1 -> 0 + } else if (hp > maxvalue * 0.25) { color.x = 1; color.y = 1; - color.z = 0.2 + (hp-50)*0.02 * 0.8; // blue value between 0.2 -> 1 - } - else if(hp > maxvalue * 0.1) { + color.z = 0.2 + (hp - 50) * 0.02 * 0.8; // blue value between 0.2 -> 1 + } else if (hp > maxvalue * 0.1) { color.x = 1; - color.y = (hp-20)*90/27/100; // green value between 0 -> 1 - color.z = (hp-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2 - } - else { + color.y = (hp - 20) * 90 / 27 / 100; // green value between 0 -> 1 + color.z = (hp - 20) * 90 / 27 / 100 * 0.2; // blue value between 0 -> 0.2 + } else { color.x = 1; color.y = 0; color.z = 0; } - blinkingamt = (1 - hp/maxvalue/0.25); - if(blinkingamt > 0) - { - color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time); - color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time); - color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time); + blinkingamt = (1 - hp / maxvalue / 0.25); + if (blinkingamt > 0) { + color.x = color.x - color.x * blinkingamt * sin(2 * M_PI * time); + color.y = color.y - color.y * blinkingamt * sin(2 * M_PI * time); + color.z = color.z - color.z * blinkingamt * sin(2 * M_PI * time); } return color; } float HUD_GetRowCount(int item_count, vector size, float item_aspect) { - TC(int, item_count); + TC(int, item_count); float aspect = size_y / size_x; return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count); } vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect) { - TC(int, item_count); + TC(int, item_count); float columns, rows; float ratio, best_ratio = 0; float best_columns = 1, best_rows = 1; bool vertical = (psize.x / psize.y >= item_aspect); - if(vertical) - { + if (vertical) { psize = eX * psize.y + eY * psize.x; item_aspect = 1 / item_aspect; } rows = ceil(sqrt(item_count)); - columns = ceil(item_count/rows); - while(columns >= 1) - { - ratio = (psize.x/columns) / (psize.y/rows); - if(ratio > item_aspect) + columns = ceil(item_count / rows); + while (columns >= 1) { + ratio = (psize.x / columns) / (psize.y / rows); + if (ratio > item_aspect) { ratio = item_aspect * item_aspect / ratio; + } - if(ratio <= best_ratio) + if (ratio <= best_ratio) { break; // ratio starts decreasing by now, skip next configurations - + } best_columns = columns; best_rows = rows; best_ratio = ratio; - if(columns == 1) + if (columns == 1) { break; + } --columns; - rows = ceil(item_count/columns); + rows = ceil(item_count / columns); } return (vertical) ? vec2(best_rows, best_columns) : vec2(best_columns, best_rows); @@ -124,8 +118,7 @@ HUD panels void HUD_Panel_LoadCvars() { // NOTE: in hud_configure mode cvars must be reloaded every frame - if (panel.update_time <= time) - { + if (panel.update_time <= time) { panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); HUD_Panel_ScalePosSize(); @@ -136,8 +129,7 @@ void HUD_Panel_LoadCvars() panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); HUD_Panel_GetBg(); - if (panel.current_panel_bg != "0") - { + if (panel.current_panel_bg != "0") { HUD_Panel_GetBgAlpha(); HUD_Panel_GetBorder(); } @@ -147,10 +139,9 @@ void HUD_Panel_LoadCvars() HUD_Panel_GetPadding(); panel.current_panel_bg_alpha = panel_bg_alpha; panel.current_panel_fg_alpha = panel_fg_alpha; - if (hud_configure_menu_open == 2 && panel == highlightedPanel) + if (hud_configure_menu_open == 2 && panel == highlightedPanel) { HUD_Panel_UpdatePosSize_ForMenu(); - else - { + } else { panel_bg_alpha *= hud_fade_alpha * panel_fade_alpha; panel_fg_alpha *= hud_fade_alpha * panel_fade_alpha; } @@ -174,44 +165,45 @@ void HUD_Panel_LoadCvars() panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha * panel_fade_alpha; } -//basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu +// basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag) { - TC(bool, vertical); TC(int, drawflag); - if(!length_ratio || !theAlpha) + TC(bool, vertical); + TC(int, drawflag); + if (!length_ratio || !theAlpha) { return; - if(length_ratio > 1) + } + if (length_ratio > 1) { length_ratio = 1; - if (baralign == 3) - { - if(length_ratio < -1) - length_ratio = -1; } - else if(length_ratio < 0) + if (baralign == 3) { + if (length_ratio < -1) { + length_ratio = -1; + } + } else if (length_ratio < 0) { return; + } theOrigin = HUD_Shift(theOrigin); theSize = HUD_Scale(theSize); vector square; vector width, height; - if(vertical) { + if (vertical) { pic = strcat(hud_skin_path, "/", pic, "_vertical"); - if(precache_pic(pic) == "") { + if (precache_pic(pic) == "") { pic = "gfx/hud/default/progressbar_vertical"; } - if (baralign == 1) // bottom align + if (baralign == 1) { // bottom align theOrigin.y += (1 - length_ratio) * theSize.y; - else if (baralign == 2) // center align - theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y; - else if (baralign == 3) // center align, positive values down, negative up - { + } else if (baralign == 2) { // center align + theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y; + } else if (baralign == 3) { // center align, positive values down, negative up theSize.y *= 0.5; - if (length_ratio > 0) + if (length_ratio > 0) { theOrigin.y += theSize.y; - else - { + } else { theOrigin.y += (1 + length_ratio) * theSize.y; length_ratio = -length_ratio; } @@ -221,17 +213,14 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo vector bH; width = eX * theSize.x; height = eY * theSize.y; - if(theSize.y <= theSize.x * 2) - { + if (theSize.y <= theSize.x * 2) { // button not high enough // draw just upper and lower part then square = eY * theSize.y * 0.5; bH = eY * (0.25 * theSize.y / (theSize.x * 2)); drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag); drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag); - } - else - { + } else { square = eY * theSize.x; drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag); drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag); @@ -239,21 +228,19 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo } } else { pic = strcat(hud_skin_path, "/", pic); - if(precache_pic(pic) == "") { + if (precache_pic(pic) == "") { pic = "gfx/hud/default/progressbar"; } - if (baralign == 1) // right align + if (baralign == 1) { // right align theOrigin.x += (1 - length_ratio) * theSize.x; - else if (baralign == 2) // center align - theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x; - else if (baralign == 3) // center align, positive values on the right, negative on the left - { + } else if (baralign == 2) { // center align + theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x; + } else if (baralign == 3) { // center align, positive values on the right, negative on the left theSize.x *= 0.5; - if (length_ratio > 0) + if (length_ratio > 0) { theOrigin.x += theSize.x; - else - { + } else { theOrigin.x += (1 + length_ratio) * theSize.x; length_ratio = -length_ratio; } @@ -263,17 +250,14 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo vector bW; width = eX * theSize.x; height = eY * theSize.y; - if(theSize.x <= theSize.y * 2) - { + if (theSize.x <= theSize.y * 2) { // button not wide enough // draw just left and right part then square = eX * theSize.x * 0.5; bW = eX * (0.25 * theSize.x / (theSize.y * 2)); drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag); drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag); - } - else - { + } else { square = eX * theSize.y; drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag); drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag); @@ -284,57 +268,53 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag) { - TC(int, drawflag); - if(!theAlpha) + TC(int, drawflag); + if (!theAlpha) { return; + } pos = HUD_Shift(pos); mySize = HUD_Scale(mySize); string pic; pic = strcat(hud_skin_path, "/num_leading"); - if(precache_pic(pic) == "") { + if (precache_pic(pic) == "") { pic = "gfx/hud/default/num_leading"; } drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag); - if(mySize.x/mySize.y > 2) + if (mySize.x / mySize.y > 2) { drawsubpic(pos + eX * mySize.y, eX * (mySize.x - 2 * mySize.y) + eY * mySize.y, pic, '0.25 0 0', '0.5 1 0', color, theAlpha, drawflag); + } drawsubpic(pos + eX * mySize.x - eX * min(mySize.x * 0.5, mySize.y), eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0.75 0 0', '0.25 1 0', color, theAlpha, drawflag); } void DrawNumIcon_expanding(vector myPos, vector mySize, float theTime, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp) { - TC(bool, vertical); TC(int, icon_right_align); + TC(bool, vertical); + TC(int, icon_right_align); vector newPos = '0 0 0', newSize = '0 0 0'; vector picpos, numpos; - if (vertical) - { - if(mySize.y/mySize.x > 2) - { + if (vertical) { + if (mySize.y / mySize.x > 2) { newSize.y = 2 * mySize.x; newSize.x = mySize.x; newPos.y = myPos.y + (mySize.y - newSize.y) / 2; newPos.x = myPos.x; - } - else - { - newSize.x = 1/2 * mySize.y; + } else { + newSize.x = 1 / 2 * mySize.y; newSize.y = mySize.y; newPos.x = myPos.x + (mySize.x - newSize.x) / 2; newPos.y = myPos.y; } - if(icon_right_align) - { + if (icon_right_align) { numpos = newPos; picpos = newPos + eY * newSize.x; - } - else - { + } else { picpos = newPos; numpos = newPos + eY * newSize.x; } @@ -349,30 +329,24 @@ void DrawNumIcon_expanding(vector myPos, vector mySize, float theTime, string ic return; } - if(mySize.x/mySize.y > 3) - { + if (mySize.x / mySize.y > 3) { newSize.x = 3 * mySize.y; newSize.y = mySize.y; newPos.x = myPos.x + (mySize.x - newSize.x) / 2; newPos.y = myPos.y; - } - else - { - newSize.y = 1/3 * mySize.x; + } else { + newSize.y = 1 / 3 * mySize.x; newSize.x = mySize.x; newPos.y = myPos.y + (mySize.y - newSize.y) / 2; newPos.x = myPos.x; } - if(icon_right_align) // right align - { + if (icon_right_align) { // right align numpos = newPos; picpos = newPos + eX * 2 * newSize.y; - } - else // left align - { + } else { // left align numpos = newPos + eX * newSize.y; picpos = newPos; } @@ -385,7 +359,8 @@ void DrawNumIcon_expanding(vector myPos, vector mySize, float theTime, string ic void DrawNumIcon(vector myPos, vector mySize, float theTime, string icon, bool vertical, int icon_right_align, vector color, float theAlpha) { - TC(bool, vertical); TC(int, icon_right_align); + TC(bool, vertical); + TC(int, icon_right_align); DrawNumIcon_expanding(myPos, mySize, theTime, icon, vertical, icon_right_align, color, theAlpha, 0); } @@ -399,12 +374,12 @@ void CSQC_BUMBLE_GUN_HUD(); void HUD_Vehicle() { - if(autocvar__hud_configure) return; - if(intermission == 2) return; + if (autocvar__hud_configure) { return; } + if (intermission == 2) { return; } - if(hud == HUD_BUMBLEBEE_GUN) + if (hud == HUD_BUMBLEBEE_GUN) { CSQC_BUMBLE_GUN_HUD(); - else { + } else { Vehicle info = Vehicles_from(hud); info.vr_hud(info); } @@ -413,10 +388,10 @@ void HUD_Vehicle() void HUD_Panel_Draw(entity panent) { panel = panent; - if (autocvar__hud_configure) - { - if (!(panel.panel_configflags & PANEL_CONFIG_MAIN)) + if (autocvar__hud_configure) { + if (!(panel.panel_configflags & PANEL_CONFIG_MAIN)) { return; + } panel_fade_alpha = 1; Hud_Panel_GetPanelEnabled(); panel.panel_draw(); @@ -424,28 +399,26 @@ void HUD_Panel_Draw(entity panent) } bool draw_allowed = false; - if (active_minigame && HUD_MinigameMenu_IsOpened()) - { - if (panel.panel_showflags & PANEL_SHOW_MINIGAME) + if (active_minigame && HUD_MinigameMenu_IsOpened()) { + if (panel.panel_showflags & PANEL_SHOW_MINIGAME) { draw_allowed = true; - } - else if(intermission == 2) - { - if(panel.panel_showflags & PANEL_SHOW_MAPVOTE) + } + } else if (intermission == 2) { + if (panel.panel_showflags & PANEL_SHOW_MAPVOTE) { draw_allowed = true; - } - else if (panel.panel_showflags & PANEL_SHOW_MAINGAME) + } + } else if (panel.panel_showflags & PANEL_SHOW_MAINGAME) { draw_allowed = true; + } - if (draw_allowed) - { - if (panel.panel_showflags & PANEL_SHOW_WITH_SB) + if (draw_allowed) { + if (panel.panel_showflags & PANEL_SHOW_WITH_SB) { panel_fade_alpha = 1; - else - { + } else { panel_fade_alpha = 1 - scoreboard_fade_alpha; - if(!panel_fade_alpha) + if (!panel_fade_alpha) { return; + } } panel.panel_draw(); } @@ -454,30 +427,33 @@ void HUD_Panel_Draw(entity panent) void HUD_Reset() { // reset gametype specific icons - if(gametype.m_modicons_reset) + if (gametype.m_modicons_reset) { gametype.m_modicons_reset(); + } } float autocvar_hud_dynamic_shake = 1; float autocvar_hud_dynamic_shake_damage_max = 130; float autocvar_hud_dynamic_shake_damage_min = 10; float autocvar_hud_dynamic_shake_scale = 0.2; -float hud_dynamic_shake_x[10] = {0, 1, -0.7, 0.5, -0.3, 0.2, -0.1, 0.1, 0.0, 0}; -float hud_dynamic_shake_y[10] = {0, 0.4, 0.8, -0.2, -0.6, 0.0, 0.3, 0.1, -0.1, 0}; +float hud_dynamic_shake_x[10] = { 0, 1, -0.7, 0.5, -0.3, 0.2, -0.1, 0.1, 0.0, 0 }; +float hud_dynamic_shake_y[10] = { 0, 0.4, 0.8, -0.2, -0.6, 0.0, 0.3, 0.1, -0.1, 0 }; bool Hud_Shake_Update() { - if(time - hud_dynamic_shake_time < 0) + if (time - hud_dynamic_shake_time < 0) { return false; + } float anim_speed = 17 + 9 * hud_dynamic_shake_factor; float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed; int i = floor(elapsed_time); - if(i >= 9) + if (i >= 9) { return false; + } float f = elapsed_time - i; - hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1]; - hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1]; + hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i + 1]; + hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i + 1]; hud_dynamic_shake_realofs.z = 0; hud_dynamic_shake_realofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale; hud_dynamic_shake_realofs.x = bound(-0.1, hud_dynamic_shake_realofs.x, 0.1) * vid_conwidth; @@ -493,8 +469,7 @@ void Hud_Dynamic_Frame() hud_scale_current = '1 1 0'; hud_shift_current = '0 0 0'; - if (autocvar_hud_dynamic_follow) - { + if (autocvar_hud_dynamic_follow) { entity view = CSQCModel_server2csqc(player_localentnum - 1); calc_followmodel_ofs(view); ofs = -cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale; @@ -502,9 +477,9 @@ void Hud_Dynamic_Frame() ofs.y *= autocvar_hud_dynamic_follow_scale_xyz.x; ofs.z *= autocvar_hud_dynamic_follow_scale_xyz.y; - if (fabs(ofs.x) < 0.001) ofs.x = 0; - if (fabs(ofs.y) < 0.001) ofs.y = 0; - if (fabs(ofs.z) < 0.001) ofs.z = 0; + if (fabs(ofs.x) < 0.001) { ofs.x = 0; } + if (fabs(ofs.y) < 0.001) { ofs.y = 0; } + if (fabs(ofs.z) < 0.001) { ofs.z = 0; } ofs.x = bound(-0.1, ofs.x, 0.1); ofs.y = bound(-0.1, ofs.y, 0.1); ofs.z = bound(-0.1, ofs.z, 0.1); @@ -517,40 +492,36 @@ void Hud_Dynamic_Frame() hud_scale_current.y = hud_scale_current.x; } - if(autocvar_hud_dynamic_shake > 0) - { + if (autocvar_hud_dynamic_shake > 0) { static float old_health = 0; float health = max(-1, STAT(HEALTH)); - if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame - { + if (hud_dynamic_shake_factor == -1) { // don't allow the effect for this frame hud_dynamic_shake_factor = 0; old_health = health; - } - else - { + } else { float new_hud_dynamic_shake_factor = 0; if (old_health - health >= autocvar_hud_dynamic_shake_damage_min && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min - && old_health > 0 && !intermission) - { + && old_health > 0 && !intermission) { float m = max(autocvar_hud_dynamic_shake_damage_min, 1); new_hud_dynamic_shake_factor = (old_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m); - if(new_hud_dynamic_shake_factor >= 1) + if (new_hud_dynamic_shake_factor >= 1) { new_hud_dynamic_shake_factor = 1; - if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor) - { + } + if (new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor) { hud_dynamic_shake_factor = new_hud_dynamic_shake_factor; hud_dynamic_shake_time = time; } } old_health = health; - if(hud_dynamic_shake_factor) - if(!Hud_Shake_Update()) + if (hud_dynamic_shake_factor) { + if (!Hud_Shake_Update()) { hud_dynamic_shake_factor = 0; + } + } } - if(hud_dynamic_shake_factor > 0) - { + if (hud_dynamic_shake_factor > 0) { hud_shift_current.x += hud_dynamic_shake_realofs.x; hud_shift_current.y += hud_dynamic_shake_realofs.y; } @@ -565,63 +536,63 @@ void Hud_Dynamic_Frame() void HUD_Main() { int i; - if(hud_configure_menu_open == 1) + if (hud_configure_menu_open == 1) { hud_fade_alpha = 1; - else + } else { hud_fade_alpha = 1 - autocvar__menu_alpha; + } HUD_Configure_Frame(); - if(scoreboard_fade_alpha == 1) - if(autocvar__menu_alpha == 1) + if (scoreboard_fade_alpha == 1) { + if (autocvar__menu_alpha == 1) { return; + } + } // Drawing stuff - if (hud_skin_prev != autocvar_hud_skin) - { - if (hud_skin_path) + if (hud_skin_prev != autocvar_hud_skin) { + if (hud_skin_path) { strunzone(hud_skin_path); + } hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin)); - if (hud_skin_prev) + if (hud_skin_prev) { strunzone(hud_skin_prev); + } hud_skin_prev = strzone(autocvar_hud_skin); } // draw the dock - if(autocvar_hud_dock != "" && autocvar_hud_dock != "0") - { + if (autocvar_hud_dock != "" && autocvar_hud_dock != "0") { int f; vector color; float hud_dock_color_team = autocvar_hud_dock_color_team; - if((teamplay) && hud_dock_color_team) { - if(autocvar__hud_configure && myteam == NUM_SPECTATOR) + if ((teamplay) && hud_dock_color_team) { + if (autocvar__hud_configure && myteam == NUM_SPECTATOR) { color = '1 0 0' * hud_dock_color_team; - else + } else { color = myteamcolors * hud_dock_color_team; - } - else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) { + } + } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) { color = '1 0 0' * hud_dock_color_team; - } - else - { + } else { string hud_dock_color = autocvar_hud_dock_color; - if(hud_dock_color == "shirt") { + if (hud_dock_color == "shirt") { f = entcs_GetClientColors(current_player); color = colormapPaletteColor(floor(f / 16), 0); - } - else if(hud_dock_color == "pants") { + } else if (hud_dock_color == "pants") { f = entcs_GetClientColors(current_player); color = colormapPaletteColor(f % 16, 1); - } - else + } else { color = stov(hud_dock_color); + } } string pic; pic = strcat(hud_skin_path, "/", autocvar_hud_dock); - if(precache_pic(pic) == "") { + if (precache_pic(pic) == "") { pic = strcat(hud_skin_path, "/dock_medium"); - if(precache_pic(pic) == "") { + if (precache_pic(pic) == "") { pic = "gfx/hud/default/dock_medium"; } } @@ -629,66 +600,76 @@ void HUD_Main() } // cache the panel order into the panel_order array - if(autocvar__hud_panelorder != hud_panelorder_prev) { - for(i = 0; i < hud_panels_COUNT; ++i) + if (autocvar__hud_panelorder != hud_panelorder_prev) { + for (i = 0; i < hud_panels_COUNT; ++i) { panel_order[i] = -1; + } string s = ""; int p_num; bool warning = false; int argc = tokenize_console(autocvar__hud_panelorder); - if (argc > hud_panels_COUNT) + if (argc > hud_panels_COUNT) { warning = true; - //first detect wrong/missing panel numbers - for(i = 0; i < hud_panels_COUNT; ++i) { + } + // first detect wrong/missing panel numbers + for (i = 0; i < hud_panels_COUNT; ++i) { p_num = stoi(argv(i)); - if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number? - if (panel_order[p_num] == -1) //found for the first time? + if (p_num >= 0 && p_num < hud_panels_COUNT) { // correct panel number? + if (panel_order[p_num] == -1) { // found for the first time? s = strcat(s, ftos(p_num), " "); - panel_order[p_num] = 1; //mark as found - } - else + } + panel_order[p_num] = 1; // mark as found + } else { warning = true; + } } - for(i = 0; i < hud_panels_COUNT; ++i) { + for (i = 0; i < hud_panels_COUNT; ++i) { if (panel_order[i] == -1) { warning = true; - s = strcat(s, ftos(i), " "); //add missing panel number + s = strcat(s, ftos(i), " "); // add missing panel number } } - if (warning) + if (warning) { LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder"); + } cvar_set("_hud_panelorder", s); - if(hud_panelorder_prev) + if (hud_panelorder_prev) { strunzone(hud_panelorder_prev); + } hud_panelorder_prev = strzone(s); - //now properly set panel_order + // now properly set panel_order tokenize_console(s); - for(i = 0; i < hud_panels_COUNT; ++i) { + for (i = 0; i < hud_panels_COUNT; ++i) { panel_order[i] = stof(argv(i)); } } hud_draw_maximized = 0; // draw panels in the order specified by panel_order array - for(i = hud_panels_COUNT - 1; i >= 0; --i) + for (i = hud_panels_COUNT - 1; i >= 0; --i) { HUD_Panel_Draw(hud_panels_from(panel_order[i])); + } HUD_Vehicle(); hud_draw_maximized = 1; // panels that may be maximized must check this var // draw maximized panels on top - if(hud_panel_radar_maximized) + if (hud_panel_radar_maximized) { HUD_Panel_Draw(HUD_PANEL(RADAR)); - if(autocvar__con_chat_maximized) + } + if (autocvar__con_chat_maximized) { HUD_Panel_Draw(HUD_PANEL(CHAT)); - if(hud_panel_quickmenu) + } + if (hud_panel_quickmenu) { HUD_Panel_Draw(HUD_PANEL(QUICKMENU)); + } HUD_Panel_Draw(HUD_PANEL(SCOREBOARD)); - if (intermission == 2) + if (intermission == 2) { HUD_Reset(); + } HUD_Configure_PostDraw(); diff --git a/qcsrc/client/hud/hud_config.qc b/qcsrc/client/hud/hud_config.qc index ec07ee409..91dd84900 100644 --- a/qcsrc/client/hud/hud_config.qc +++ b/qcsrc/client/hud/hud_config.qc @@ -16,8 +16,7 @@ void HUD_Panel_ExportCfg(string cfgname) string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg"); string str = ""; fh = fopen(filename, FILE_WRITE); - if(fh >= 0) - { + if (fh >= 0) { HUD_Write("//title \n"); HUD_Write("//author \n"); HUD_Write("\n"); @@ -61,8 +60,7 @@ void HUD_Panel_ExportCfg(string cfgname) HUD_Write("\n"); // common cvars for all panels - for (int i = 0; i < hud_panels_COUNT; ++i) - { + for (int i = 0; i < hud_panels_COUNT; ++i) { panel = hud_panels_from(i); HUD_Write_PanelCvar("_pos"); @@ -73,7 +71,7 @@ void HUD_Panel_ExportCfg(string cfgname) HUD_Write_PanelCvar("_bg_alpha"); HUD_Write_PanelCvar("_bg_border"); HUD_Write_PanelCvar("_bg_padding"); - switch(panel) { + switch (panel) { case HUD_PANEL_WEAPONS: HUD_Write_Cvar("hud_panel_weapons_accuracy"); HUD_Write_Cvar("hud_panel_weapons_label"); @@ -241,15 +239,14 @@ void HUD_Panel_ExportCfg(string cfgname) LOG_INFOF(_("^2Successfully exported to %s! (Note: It's saved in data/data/)"), filename); fclose(fh); - } - else + } else { LOG_INFOF(_("^1Couldn't write to %s"), filename); + } } void HUD_Configure_Exit_Force() { - if (hud_configure_menu_open) - { + if (hud_configure_menu_open) { hud_configure_menu_open = 0; localcmd("togglemenu\n"); } @@ -264,23 +261,27 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize) int i; for (i = 0; i < hud_panels_COUNT; ++i) { panel = hud_panels_from(i); - if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; - if(panel == highlightedPanel) continue; + if (!(panel.panel_configflags & PANEL_CONFIG_MAIN)) { continue; } + if (panel == highlightedPanel) { continue; } HUD_Panel_UpdatePosSize(); - if(!panel_enabled) continue; + if (!panel_enabled) { continue; } panel_pos -= '1 1 0' * panel_bg_border; panel_size += '2 2 0' * panel_bg_border; - if(myPos.y + mySize.y < panel_pos.y) + if (myPos.y + mySize.y < panel_pos.y) { continue; - if(myPos.y > panel_pos.y + panel_size.y) + } + if (myPos.y > panel_pos.y + panel_size.y) { continue; + } - if(myPos.x + mySize.x < panel_pos.x) + if (myPos.x + mySize.x < panel_pos.x) { continue; - if(myPos.x > panel_pos.x + panel_size.x) + } + if (myPos.x > panel_pos.x + panel_size.x) { continue; + } // OK, there IS a collision. @@ -290,36 +291,33 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize) targCenter.x = panel_pos.x + 0.5 * panel_size.x; targCenter.y = panel_pos.y + 0.5 * panel_size.y; - if(myCenter.x < targCenter.x && myCenter.y < targCenter.y) // top left (of the target panel) - { - if(myPos.x + mySize.x - panel_pos.x < myPos.y + mySize.y - panel_pos.y) // push it to the side + if (myCenter.x < targCenter.x && myCenter.y < targCenter.y) { // top left (of the target panel) + if (myPos.x + mySize.x - panel_pos.x < myPos.y + mySize.y - panel_pos.y) { // push it to the side myTarget.x = panel_pos.x - mySize.x; - else // push it upwards + } else { // push it upwards myTarget.y = panel_pos.y - mySize.y; - } - else if(myCenter.x > targCenter.x && myCenter.y < targCenter.y) // top right - { - if(panel_pos.x + panel_size.x - myPos.x < myPos.y + mySize.y - panel_pos.y) // push it to the side + } + } else if (myCenter.x > targCenter.x && myCenter.y < targCenter.y) { // top right + if (panel_pos.x + panel_size.x - myPos.x < myPos.y + mySize.y - panel_pos.y) { // push it to the side myTarget.x = panel_pos.x + panel_size.x; - else // push it upwards + } else { // push it upwards myTarget.y = panel_pos.y - mySize.y; - } - else if(myCenter.x < targCenter.x && myCenter.y > targCenter.y) // bottom left - { - if(myPos.x + mySize.x - panel_pos.x < panel_pos.y + panel_size.y - myPos.y) // push it to the side + } + } else if (myCenter.x < targCenter.x && myCenter.y > targCenter.y) { // bottom left + if (myPos.x + mySize.x - panel_pos.x < panel_pos.y + panel_size.y - myPos.y) { // push it to the side myTarget.x = panel_pos.x - mySize.x; - else // push it downwards + } else { // push it downwards myTarget.y = panel_pos.y + panel_size.y; - } - else if(myCenter.x > targCenter.x && myCenter.y > targCenter.y) // bottom right - { - if(panel_pos.x + panel_size.x - myPos.x < panel_pos.y + panel_size.y - myPos.y) // push it to the side + } + } else if (myCenter.x > targCenter.x && myCenter.y > targCenter.y) { // bottom right + if (panel_pos.x + panel_size.x - myPos.x < panel_pos.y + panel_size.y - myPos.y) { // push it to the side myTarget.x = panel_pos.x + panel_size.x; - else // push it downwards + } else { // push it downwards myTarget.y = panel_pos.y + panel_size.y; + } } - //if(cvar("hud_configure_checkcollisions_debug")) - //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL); + // if(cvar("hud_configure_checkcollisions_debug")) + // drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL); } return myTarget; @@ -332,39 +330,40 @@ void HUD_Panel_SetPos(vector pos) vector mySize; mySize = panel_size; - //if(cvar("hud_configure_checkcollisions_debug")) - //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL); + // if(cvar("hud_configure_checkcollisions_debug")) + // drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL); - if(autocvar_hud_configure_grid) - { - pos.x = floor((pos.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x; - pos.y = floor((pos.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y; + if (autocvar_hud_configure_grid) { + pos.x = floor((pos.x / vid_conwidth) / hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x; + pos.y = floor((pos.y / vid_conheight) / hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y; } - if(hud_configure_checkcollisions) + if (hud_configure_checkcollisions) { pos = HUD_Panel_CheckMove(pos, mySize); + } pos.x = bound(0, pos.x, vid_conwidth - mySize.x); pos.y = bound(0, pos.y, vid_conheight - mySize.y); string s; - s = strcat(ftos(pos.x/vid_conwidth), " ", ftos(pos.y/vid_conheight)); + s = strcat(ftos(pos.x / vid_conwidth), " ", ftos(pos.y / vid_conheight)); cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_pos"), s); } // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector -vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { +vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) +{ vector targEndPos; vector dist; - float ratio = mySize.x/mySize.y; + float ratio = mySize.x / mySize.y; int i; for (i = 0; i < hud_panels_COUNT; ++i) { panel = hud_panels_from(i); - if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; - if(panel == highlightedPanel) continue; + if (!(panel.panel_configflags & PANEL_CONFIG_MAIN)) { continue; } + if (panel == highlightedPanel) { continue; } HUD_Panel_UpdatePosSize(); - if(!panel_enabled) continue; + if (!panel_enabled) { continue; } panel_pos -= '1 1 0' * panel_bg_border; panel_size += '2 2 0' * panel_bg_border; @@ -372,20 +371,24 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { targEndPos = panel_pos + panel_size; // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour! - if(resizeorigin.x > panel_pos.x && resizeorigin.x < targEndPos.x && resizeorigin.y > panel_pos.y && resizeorigin.y < targEndPos.y) + if (resizeorigin.x > panel_pos.x && resizeorigin.x < targEndPos.x && resizeorigin.y > panel_pos.y && resizeorigin.y < targEndPos.y) { continue; + } - if (resizeCorner == 1) - { + if (resizeCorner == 1) { // check if this panel is on our way - if (resizeorigin.x <= panel_pos.x) + if (resizeorigin.x <= panel_pos.x) { continue; - if (resizeorigin.y <= panel_pos.y) + } + if (resizeorigin.y <= panel_pos.y) { continue; - if (targEndPos.x <= resizeorigin.x - mySize.x) + } + if (targEndPos.x <= resizeorigin.x - mySize.x) { continue; - if (targEndPos.y <= resizeorigin.y - mySize.y) + } + if (targEndPos.y <= resizeorigin.y - mySize.y) { continue; + } // there is a collision: // detect which side of the panel we are facing is actually limiting the resizing @@ -395,67 +398,77 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel dist.x = resizeorigin.x - targEndPos.x; dist.y = resizeorigin.y - targEndPos.y; - if (dist.y <= 0 || dist.x / dist.y > ratio) + if (dist.y <= 0 || dist.x / dist.y > ratio) { mySize.x = min(mySize.x, dist.x); - else + } else { mySize.y = min(mySize.y, dist.y); - } - else if (resizeCorner == 2) - { - if (resizeorigin.x >= targEndPos.x) + } + } else if (resizeCorner == 2) { + if (resizeorigin.x >= targEndPos.x) { continue; - if (resizeorigin.y <= panel_pos.y) + } + if (resizeorigin.y <= panel_pos.y) { continue; - if (panel_pos.x >= resizeorigin.x + mySize.x) + } + if (panel_pos.x >= resizeorigin.x + mySize.x) { continue; - if (targEndPos.y <= resizeorigin.y - mySize.y) + } + if (targEndPos.y <= resizeorigin.y - mySize.y) { continue; + } dist.x = panel_pos.x - resizeorigin.x; dist.y = resizeorigin.y - targEndPos.y; - if (dist.y <= 0 || dist.x / dist.y > ratio) + if (dist.y <= 0 || dist.x / dist.y > ratio) { mySize.x = min(mySize.x, dist.x); - else + } else { mySize.y = min(mySize.y, dist.y); - } - else if (resizeCorner == 3) - { - if (resizeorigin.x <= panel_pos.x) + } + } else if (resizeCorner == 3) { + if (resizeorigin.x <= panel_pos.x) { continue; - if (resizeorigin.y >= targEndPos.y) + } + if (resizeorigin.y >= targEndPos.y) { continue; - if (targEndPos.x <= resizeorigin.x - mySize.x) + } + if (targEndPos.x <= resizeorigin.x - mySize.x) { continue; - if (panel_pos.y >= resizeorigin.y + mySize.y) + } + if (panel_pos.y >= resizeorigin.y + mySize.y) { continue; + } dist.x = resizeorigin.x - targEndPos.x; dist.y = panel_pos.y - resizeorigin.y; - if (dist.y <= 0 || dist.x / dist.y > ratio) + if (dist.y <= 0 || dist.x / dist.y > ratio) { mySize.x = min(mySize.x, dist.x); - else + } else { mySize.y = min(mySize.y, dist.y); - } - else if (resizeCorner == 4) - { - if (resizeorigin.x >= targEndPos.x) + } + } else if (resizeCorner == 4) { + if (resizeorigin.x >= targEndPos.x) { continue; - if (resizeorigin.y >= targEndPos.y) + } + if (resizeorigin.y >= targEndPos.y) { continue; - if (panel_pos.x >= resizeorigin.x + mySize.x) + } + if (panel_pos.x >= resizeorigin.x + mySize.x) { continue; - if (panel_pos.y >= resizeorigin.y + mySize.y) + } + if (panel_pos.y >= resizeorigin.y + mySize.y) { continue; + } dist.x = panel_pos.x - resizeorigin.x; dist.y = panel_pos.y - resizeorigin.y; - if (dist.y <= 0 || dist.x / dist.y > ratio) + if (dist.y <= 0 || dist.x / dist.y > ratio) { mySize.x = min(mySize.x, dist.x); - else + } else { mySize.y = min(mySize.y, dist.y); + } } - //if(cvar("hud_configure_checkcollisions_debug")) - //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL); + // if(cvar("hud_configure_checkcollisions_debug")) + // drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL); } return mySize; @@ -472,8 +485,7 @@ void HUD_Panel_SetPosSize(vector mySize) mySize.x = max(0.025 * vid_conwidth, mySize.x); mySize.y = max(0.025 * vid_conheight, mySize.y); - if(highlightedPanel == HUD_PANEL(CHAT)) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small. - { + if (highlightedPanel == HUD_PANEL(CHAT)) { // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small. mySize.x = max(17 * autocvar_con_chatsize, mySize.x); mySize.y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize.y); } @@ -482,13 +494,13 @@ void HUD_Panel_SetPosSize(vector mySize) // -----------------+ // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?) - if(resizeCorner == 1) { + if (resizeCorner == 1) { myPos.x = resizeorigin.x - mySize.x; myPos.y = resizeorigin.y - mySize.y; - } else if(resizeCorner == 2) { + } else if (resizeCorner == 2) { myPos.x = resizeorigin.x; myPos.y = resizeorigin.y - mySize.y; - } else if(resizeCorner == 3) { + } else if (resizeCorner == 3) { myPos.x = resizeorigin.x - mySize.x; myPos.y = resizeorigin.y; } else { // resizeCorner == 4 @@ -497,42 +509,46 @@ void HUD_Panel_SetPosSize(vector mySize) } // left/top screen edges - if(myPos.x < 0) + if (myPos.x < 0) { mySize.x = mySize.x + myPos.x; - if(myPos.y < 0) + } + if (myPos.y < 0) { mySize.y = mySize.y + myPos.y; + } // bottom/right screen edges - if(myPos.x + mySize.x > vid_conwidth) + if (myPos.x + mySize.x > vid_conwidth) { mySize.x = vid_conwidth - myPos.x; - if(myPos.y + mySize.y > vid_conheight) + } + if (myPos.y + mySize.y > vid_conheight) { mySize.y = vid_conheight - myPos.y; + } - //if(cvar("hud_configure_checkcollisions_debug")) - //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL); + // if(cvar("hud_configure_checkcollisions_debug")) + // drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL); // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken - if(autocvar_hud_configure_grid) - { - mySize.x = floor((mySize.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x; - mySize.y = floor((mySize.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y; + if (autocvar_hud_configure_grid) { + mySize.x = floor((mySize.x / vid_conwidth) / hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x; + mySize.y = floor((mySize.y / vid_conheight) / hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y; } - if(hud_configure_checkcollisions) + if (hud_configure_checkcollisions) { mySize = HUD_Panel_CheckResize(mySize, resizeorigin); + } // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then) mySize.x = max(0.025 * vid_conwidth, mySize.x); mySize.y = max(0.025 * vid_conheight, mySize.y); // do another pos check, as size might have changed by now - if(resizeCorner == 1) { + if (resizeCorner == 1) { myPos.x = resizeorigin.x - mySize.x; myPos.y = resizeorigin.y - mySize.y; - } else if(resizeCorner == 2) { + } else if (resizeCorner == 2) { myPos.x = resizeorigin.x; myPos.y = resizeorigin.y - mySize.y; - } else if(resizeCorner == 3) { + } else if (resizeCorner == 3) { myPos.x = resizeorigin.x - mySize.x; myPos.y = resizeorigin.y; } else { // resizeCorner == 4 @@ -540,14 +556,14 @@ void HUD_Panel_SetPosSize(vector mySize) myPos.y = resizeorigin.y; } - //if(cvar("hud_configure_checkcollisions_debug")) - //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL); + // if(cvar("hud_configure_checkcollisions_debug")) + // drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL); string s; - s = strcat(ftos(mySize.x/vid_conwidth), " ", ftos(mySize.y/vid_conheight)); + s = strcat(ftos(mySize.x / vid_conwidth), " ", ftos(mySize.y / vid_conheight)); cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_size"), s); - s = strcat(ftos(myPos.x/vid_conwidth), " ", ftos(myPos.y/vid_conheight)); + s = strcat(ftos(myPos.x / vid_conwidth), " ", ftos(myPos.y / vid_conheight)); cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_pos"), s); } @@ -555,39 +571,38 @@ float pressed_key_time; vector highlightedPanel_initial_pos, highlightedPanel_initial_size; void HUD_Panel_Arrow_Action(float nPrimary) { - if(!highlightedPanel) + if (!highlightedPanel) { return; + } hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions); float step; - if(autocvar_hud_configure_grid) - { - if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW) - { - if (hudShiftState & S_SHIFT) + if (autocvar_hud_configure_grid) { + if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW) { + if (hudShiftState & S_SHIFT) { step = hud_configure_realGridSize.y; - else + } else { step = 2 * hud_configure_realGridSize.y; - } - else - { - if (hudShiftState & S_SHIFT) + } + } else { + if (hudShiftState & S_SHIFT) { step = hud_configure_realGridSize.x; - else + } else { step = 2 * hud_configure_realGridSize.x; + } } - } - else - { - if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW) + } else { + if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW) { step = vid_conheight; - else + } else { step = vid_conwidth; - if (hudShiftState & S_SHIFT) + } + if (hudShiftState & S_SHIFT) { step = (step / 256); // more precision - else + } else { step = (step / 64) * (1 + 2 * (time - pressed_key_time)); + } } panel = highlightedPanel; @@ -596,16 +611,16 @@ void HUD_Panel_Arrow_Action(float nPrimary) highlightedPanel_initial_pos = panel_pos; highlightedPanel_initial_size = panel_size; - if (hudShiftState & S_ALT) // resize - { - if(nPrimary == K_UPARROW) + if (hudShiftState & S_ALT) { // resize + if (nPrimary == K_UPARROW) { resizeCorner = 1; - else if(nPrimary == K_RIGHTARROW) + } else if (nPrimary == K_RIGHTARROW) { resizeCorner = 2; - else if(nPrimary == K_LEFTARROW) + } else if (nPrimary == K_LEFTARROW) { resizeCorner = 3; - else // if(nPrimary == K_DOWNARROW) + } else { // if(nPrimary == K_DOWNARROW) resizeCorner = 4; + } // ctrl+arrow reduces the size, instead of increasing it // Note that ctrl disables collisions check too, but it's fine @@ -618,32 +633,31 @@ void HUD_Panel_Arrow_Action(float nPrimary) vector mySize; mySize = panel_size; panel_click_resizeorigin = panel_pos; - if(resizeCorner == 1) { + if (resizeCorner == 1) { panel_click_resizeorigin += mySize; mySize.y += step; - } else if(resizeCorner == 2) { + } else if (resizeCorner == 2) { panel_click_resizeorigin.y += mySize.y; mySize.x += step; - } else if(resizeCorner == 3) { + } else if (resizeCorner == 3) { panel_click_resizeorigin.x += mySize.x; mySize.x += step; } else { // resizeCorner == 4 mySize.y += step; } HUD_Panel_SetPosSize(mySize); - } - else // move - { + } else { // move vector pos; pos = panel_pos; - if(nPrimary == K_UPARROW) + if (nPrimary == K_UPARROW) { pos.y -= step; - else if(nPrimary == K_DOWNARROW) + } else if (nPrimary == K_DOWNARROW) { pos.y += step; - else if(nPrimary == K_LEFTARROW) + } else if (nPrimary == K_LEFTARROW) { pos.x -= step; - else // if(nPrimary == K_RIGHTARROW) + } else { // if(nPrimary == K_RIGHTARROW) pos.x += step; + } HUD_Panel_SetPos(pos); } @@ -651,8 +665,7 @@ void HUD_Panel_Arrow_Action(float nPrimary) panel = highlightedPanel; HUD_Panel_UpdatePosSize(); - if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size) - { + if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size) { // backup! panel_pos_backup = highlightedPanel_initial_pos; panel_size_backup = highlightedPanel_initial_size; @@ -668,21 +681,23 @@ float tab_backward; void HUD_Panel_FirstInDrawQ(float id); void reset_tab_panels() { - for (int i = 0; i < hud_panels_COUNT; ++i) + for (int i = 0; i < hud_panels_COUNT; ++i) { tab_panels[i] = NULL; + } } float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) { string s; - if(bInputType == 2) + if (bInputType == 2) { return false; + } - if(!autocvar__hud_configure) + if (!autocvar__hud_configure) { return false; + } - if(bInputType == 3) - { + if (bInputType == 3) { mousepos.x = nPrimary; mousepos.y = nSecondary; return true; @@ -690,8 +705,7 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) // block any input while a menu dialog is fading // don't block mousepos read as it leads to cursor jumps in the interaction with the menu - if(autocvar__menu_alpha) - { + if (autocvar__menu_alpha) { hudShiftState = 0; mouseClicked = 0; return true; @@ -703,30 +717,26 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) bool hit_con_bind = false; int i; - for (i = 0; i < keys; ++i) - { - if(nPrimary == stof(argv(i))) + for (i = 0; i < keys; ++i) { + if (nPrimary == stof(argv(i))) { hit_con_bind = true; + } } - if(bInputType == 0) { - if(nPrimary == K_ALT) hudShiftState |= S_ALT; - if(nPrimary == K_CTRL) hudShiftState |= S_CTRL; - if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT; - } - else if(bInputType == 1) { - if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT); - if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL); - if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT); + if (bInputType == 0) { + if (nPrimary == K_ALT) { hudShiftState |= S_ALT; } + if (nPrimary == K_CTRL) { hudShiftState |= S_CTRL; } + if (nPrimary == K_SHIFT) { hudShiftState |= S_SHIFT; } + } else if (bInputType == 1) { + if (nPrimary == K_ALT) { hudShiftState -= (hudShiftState & S_ALT); } + if (nPrimary == K_CTRL) { hudShiftState -= (hudShiftState & S_CTRL); } + if (nPrimary == K_SHIFT) { hudShiftState -= (hudShiftState & S_SHIFT); } } - if(nPrimary == K_CTRL) - { - if (bInputType == 1) //ctrl has been released - { - if (tab_panel) - { - //switch to selected panel + if (nPrimary == K_CTRL) { + if (bInputType == 1) { // ctrl has been released + if (tab_panel) { + // switch to selected panel highlightedPanel = tab_panel; highlightedAction = 0; HUD_Panel_FirstInDrawQ(highlightedPanel.panel_id); @@ -736,38 +746,35 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) } } - if(nPrimary == K_MOUSE1) - { - if(bInputType == 0) // key pressed + if (nPrimary == K_MOUSE1) { + if (bInputType == 0) { // key pressed mouseClicked |= S_MOUSE1; - else if(bInputType == 1) // key released + } else if (bInputType == 1) { // key released mouseClicked -= (mouseClicked & S_MOUSE1); - } - else if(nPrimary == K_MOUSE2) - { - if(bInputType == 0) // key pressed + } + } else if (nPrimary == K_MOUSE2) { + if (bInputType == 0) { // key pressed mouseClicked |= S_MOUSE2; - else if(bInputType == 1) // key released + } else if (bInputType == 1) { // key released mouseClicked -= (mouseClicked & S_MOUSE2); - } - else if(nPrimary == K_ESCAPE) - { - if (bInputType == 1) + } + } else if (nPrimary == K_ESCAPE) { + if (bInputType == 1) { return true; + } hud_configure_menu_open = 1; localcmd("menu_showhudexit\n"); - } - else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL) - { - if (bInputType == 1) + } else if (nPrimary == K_BACKSPACE && hudShiftState & S_CTRL) { + if (bInputType == 1) { return true; - if (!hud_configure_menu_open) + } + if (!hud_configure_menu_open) { cvar_set("_hud_configure", "0"); - } - else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // switch panel - { - if (bInputType == 1 || mouseClicked) + } + } else if (nPrimary == K_TAB && hudShiftState & S_CTRL) { // switch panel + if (bInputType == 1 || mouseClicked) { return true; + } // FIXME minor bug: if a panel is highlighted, has the same pos_x and // lays in the same level of another panel then the next consecutive @@ -775,22 +782,19 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) entity starting_panel; entity old_tab_panel = tab_panel; - if (!tab_panel) //first press of TAB - { - if (highlightedPanel) - { + if (!tab_panel) { // first press of TAB + if (highlightedPanel) { panel = highlightedPanel; HUD_Panel_UpdatePosSize(); - } - else + } else { panel_pos = '0 0 0'; + } starting_panel = highlightedPanel; - tab_panel_pos = panel_pos; //to compute level - } - else - { - if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed? + tab_panel_pos = panel_pos; // to compute level + } else { + if (((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT))) { // tab direction changed? reset_tab_panels(); + } starting_panel = tab_panel; } tab_backward = (hudShiftState & S_SHIFT); @@ -799,52 +803,48 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) vector candidate_pos = '0 0 0'; const float LEVELS_NUM = 4; float level_height = vid_conheight / LEVELS_NUM; -LABEL(find_tab_panel) - level = floor(tab_panel_pos.y / level_height) * level_height; //starting level + LABEL(find_tab_panel) + level = floor(tab_panel_pos.y / level_height) * level_height; // starting level candidate_pos.x = (!tab_backward) ? vid_conwidth : 0; start_posX = tab_panel_pos.x; tab_panel = NULL; - k=0; - while(++k) - { - for(i = 0; i < hud_panels_COUNT; ++i) - { + k = 0; + while (++k) { + for (i = 0; i < hud_panels_COUNT; ++i) { panel = hud_panels_from(i); - if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) + if (!(panel.panel_configflags & PANEL_CONFIG_MAIN)) { continue; - if (panel == tab_panels[i] || panel == starting_panel) + } + if (panel == tab_panels[i] || panel == starting_panel) { continue; + } HUD_Panel_UpdatePosSize(); - if (panel_pos.y >= level && (panel_pos.y - level) < level_height) - if ( ( !tab_backward && panel_pos.x >= start_posX && (panel_pos.x < candidate_pos.x || (panel_pos.x == candidate_pos.x && panel_pos.y <= candidate_pos.y)) ) - || ( tab_backward && panel_pos.x <= start_posX && (panel_pos.x > candidate_pos.x || (panel_pos.x == candidate_pos.x && panel_pos.y >= candidate_pos.y)) ) ) - { - tab_panel = panel; - tab_panel_pos = candidate_pos = panel_pos; + if (panel_pos.y >= level && (panel_pos.y - level) < level_height) { + if ((!tab_backward && panel_pos.x >= start_posX && (panel_pos.x < candidate_pos.x || (panel_pos.x == candidate_pos.x && panel_pos.y <= candidate_pos.y))) + || (tab_backward && panel_pos.x <= start_posX && (panel_pos.x > candidate_pos.x || (panel_pos.x == candidate_pos.x && panel_pos.y >= candidate_pos.y)))) { + tab_panel = panel; + tab_panel_pos = candidate_pos = panel_pos; + } } } - if (tab_panel) + if (tab_panel) { break; - if (k == LEVELS_NUM) //tab_panel not found - { + } + if (k == LEVELS_NUM) { // tab_panel not found reset_tab_panels(); - if (!old_tab_panel) - { + if (!old_tab_panel) { tab_panel = NULL; return true; } starting_panel = old_tab_panel; old_tab_panel = NULL; - goto find_tab_panel; //u must find tab_panel! + goto find_tab_panel; // u must find tab_panel! } - if (!tab_backward) - { + if (!tab_backward) { level = (level + level_height) % vid_conheight; start_posX = 0; candidate_pos.x = vid_conwidth; - } - else - { + } else { level = (level - level_height) % vid_conheight; start_posX = vid_conwidth; candidate_pos.x = 0; @@ -852,103 +852,98 @@ LABEL(find_tab_panel) } tab_panels[tab_panel.panel_id] = tab_panel; - } - else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock - { - if (bInputType == 1 || mouseClicked) + } else if (nPrimary == K_SPACE && hudShiftState & S_CTRL) { // enable/disable highlighted panel or dock + if (bInputType == 1 || mouseClicked) { return true; + } - if (highlightedPanel) - { - if(panel.panel_configflags & PANEL_CONFIG_CANBEOFF) + if (highlightedPanel) { + if (panel.panel_configflags & PANEL_CONFIG_CANBEOFF) { cvar_set(strcat("hud_panel_", highlightedPanel.panel_name), ftos(!cvar(strcat("hud_panel_", highlightedPanel.panel_name)))); - } - else + } + } else { cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : ""); - } - else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size - { - if (bInputType == 1 || mouseClicked) + } + } else if (nPrimary == 'c' && hudShiftState & S_CTRL) { // copy highlighted panel size + if (bInputType == 1 || mouseClicked) { return true; + } - if (highlightedPanel) - { + if (highlightedPanel) { panel = highlightedPanel; HUD_Panel_UpdatePosSize(); panel_size_copied = panel_size; } - } - else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel - { - if (bInputType == 1 || mouseClicked) + } else if (nPrimary == 'v' && hudShiftState & S_CTRL) { // past copied size on the highlighted panel + if (bInputType == 1 || mouseClicked) { return true; + } - if (panel_size_copied == '0 0 0' || !highlightedPanel) + if (panel_size_copied == '0 0 0' || !highlightedPanel) { return true; + } panel = highlightedPanel; HUD_Panel_UpdatePosSize(); // reduce size if it'd go beyond screen boundaries vector tmp_size = panel_size_copied; - if (panel_pos.x + panel_size_copied.x > vid_conwidth) + if (panel_pos.x + panel_size_copied.x > vid_conwidth) { tmp_size.x = vid_conwidth - panel_pos.x; - if (panel_pos.y + panel_size_copied.y > vid_conheight) + } + if (panel_pos.y + panel_size_copied.y > vid_conheight) { tmp_size.y = vid_conheight - panel_pos.y; + } - if (panel_size == tmp_size) + if (panel_size == tmp_size) { return true; + } // backup first! panel_pos_backup = panel_pos; panel_size_backup = panel_size; highlightedPanel_backup = highlightedPanel; - s = strcat(ftos(tmp_size.x/vid_conwidth), " ", ftos(tmp_size.y/vid_conheight)); + s = strcat(ftos(tmp_size.x / vid_conwidth), " ", ftos(tmp_size.y / vid_conheight)); cvar_set(strcat("hud_panel_", highlightedPanel.panel_name, "_size"), s); - } - else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action - { - if (bInputType == 1 || mouseClicked) + } else if (nPrimary == 'z' && hudShiftState & S_CTRL) { // undo last action + if (bInputType == 1 || mouseClicked) { return true; - //restore previous values - if (highlightedPanel_backup) - { - s = strcat(ftos(panel_pos_backup.x/vid_conwidth), " ", ftos(panel_pos_backup.y/vid_conheight)); + } + // restore previous values + if (highlightedPanel_backup) { + s = strcat(ftos(panel_pos_backup.x / vid_conwidth), " ", ftos(panel_pos_backup.y / vid_conheight)); cvar_set(strcat("hud_panel_", highlightedPanel_backup.panel_name, "_pos"), s); - s = strcat(ftos(panel_size_backup.x/vid_conwidth), " ", ftos(panel_size_backup.y/vid_conheight)); + s = strcat(ftos(panel_size_backup.x / vid_conwidth), " ", ftos(panel_size_backup.y / vid_conheight)); cvar_set(strcat("hud_panel_", highlightedPanel_backup.panel_name, "_size"), s); highlightedPanel_backup = NULL; } - } - else if(nPrimary == 's' && hudShiftState & S_CTRL) // save config - { - if (bInputType == 1 || mouseClicked) + } else if (nPrimary == 's' && hudShiftState & S_CTRL) { // save config + if (bInputType == 1 || mouseClicked) { return true; + } localcmd("hud save myconfig\n"); - } - else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW) - { - if (bInputType == 1) - { + } else if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW) { + if (bInputType == 1) { pressed_key_time = 0; return true; - } - else if (pressed_key_time == 0) + } else if (pressed_key_time == 0) { pressed_key_time = time; + } - if (!mouseClicked) - HUD_Panel_Arrow_Action(nPrimary); //move or resize panel - } - else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER) - { - if (bInputType == 1) + if (!mouseClicked) { + HUD_Panel_Arrow_Action(nPrimary); // move or resize panel + } + } else if (nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER) { + if (bInputType == 1) { return true; - if (highlightedPanel) + } + if (highlightedPanel) { HUD_Panel_EnableMenu(); - } - else if(hit_con_bind || nPrimary == K_PAUSE) + } + } else if (hit_con_bind || nPrimary == K_PAUSE) { return false; + } return true; } @@ -956,40 +951,34 @@ LABEL(find_tab_panel) float HUD_Panel_Check_Mouse_Pos(float allow_move) { int i, j = 0; - while(j < hud_panels_COUNT) - { + while (j < hud_panels_COUNT) { i = panel_order[j]; j += 1; panel = hud_panels_from(i); - if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; + if (!(panel.panel_configflags & PANEL_CONFIG_MAIN)) { continue; } HUD_Panel_UpdatePosSize(); float border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize // move - if(allow_move && mousepos.x > panel_pos.x && mousepos.y > panel_pos.y && mousepos.x < panel_pos.x + panel_size.x && mousepos.y < panel_pos.y + panel_size.y) - { + if (allow_move && mousepos.x > panel_pos.x && mousepos.y > panel_pos.y && mousepos.x < panel_pos.x + panel_size.x && mousepos.y < panel_pos.y + panel_size.y) { return 1; } // resize from topleft border - else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) - { + else if (mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) { return 2; } // resize from topright border - else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) - { + else if (mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) { return 3; } // resize from bottomleft border - else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + panel_size.y + border) - { + else if (mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + panel_size.y + border) { return 3; } // resize from bottomright border - else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + panel_size.y + border) - { + else if (mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + panel_size.y + border) { return 2; } } @@ -1002,35 +991,33 @@ void HUD_Panel_FirstInDrawQ(float id) int i; int place = -1; // find out where in the array our current id is, save into place - for(i = 0; i < hud_panels_COUNT; ++i) - { - if(panel_order[i] == id) - { + for (i = 0; i < hud_panels_COUNT; ++i) { + if (panel_order[i] == id) { place = i; break; } } // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar) - if(place == -1) + if (place == -1) { place = hud_panels_COUNT - 1; + } // move all ids up by one step in the array until "place" - for(i = place; i > 0; --i) - { - panel_order[i] = panel_order[i-1]; + for (i = place; i > 0; --i) { + panel_order[i] = panel_order[i - 1]; } // now save the new top id panel_order[0] = id; // let's save them into the cvar by some strcat trickery string s = ""; - for(i = 0; i < hud_panels_COUNT; ++i) - { + for (i = 0; i < hud_panels_COUNT; ++i) { s = strcat(s, ftos(panel_order[i]), " "); } cvar_set("_hud_panelorder", s); - if(hud_panelorder_prev) + if (hud_panelorder_prev) { strunzone(hud_panelorder_prev); + } hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here } @@ -1038,21 +1025,20 @@ void HUD_Panel_Highlight(float allow_move) { int i, j = 0; - while(j < hud_panels_COUNT) - { + while (j < hud_panels_COUNT) { i = panel_order[j]; j += 1; panel = hud_panels_from(i); - if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) + if (!(panel.panel_configflags & PANEL_CONFIG_MAIN)) { continue; + } HUD_Panel_UpdatePosSize(); float border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize // move - if(allow_move && mousepos.x > panel_pos.x && mousepos.y > panel_pos.y && mousepos.x < panel_pos.x + panel_size.x && mousepos.y < panel_pos.y + panel_size.y) - { + if (allow_move && mousepos.x > panel_pos.x && mousepos.y > panel_pos.y && mousepos.x < panel_pos.x + panel_size.x && mousepos.y < panel_pos.y + panel_size.y) { highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 1; @@ -1060,8 +1046,7 @@ void HUD_Panel_Highlight(float allow_move) return; } // resize from topleft border - else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) - { + else if (mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) { highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; @@ -1071,8 +1056,7 @@ void HUD_Panel_Highlight(float allow_move) return; } // resize from topright border - else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) - { + else if (mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) { highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; @@ -1083,8 +1067,7 @@ void HUD_Panel_Highlight(float allow_move) return; } // resize from bottomleft border - else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + panel_size.y + border) - { + else if (mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + panel_size.y + border) { highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; @@ -1095,8 +1078,7 @@ void HUD_Panel_Highlight(float allow_move) return; } // resize from bottomright border - else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + panel_size.y + border) - { + else if (mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + panel_size.y + border) { highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; @@ -1118,81 +1100,70 @@ void HUD_Panel_EnableMenu() float mouse_over_panel; void HUD_Panel_Mouse() { - if(autocvar__menu_alpha == 1) + if (autocvar__menu_alpha == 1) { return; + } - if (!autocvar_hud_cursormode) + if (!autocvar_hud_cursormode) { update_mousepos(); + } - if(mouseClicked) - { - if(prevMouseClicked == 0) - { - if (tab_panel) - { - //stop ctrl-tab selection + if (mouseClicked) { + if (prevMouseClicked == 0) { + if (tab_panel) { + // stop ctrl-tab selection tab_panel = NULL; reset_tab_panels(); } HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin - // and calls HUD_Panel_UpdatePosSize() for the highlighted panel - if (highlightedPanel) - { + // and calls HUD_Panel_UpdatePosSize() for the highlighted panel + if (highlightedPanel) { highlightedPanel_initial_pos = panel_pos; highlightedPanel_initial_size = panel_size; } // doubleclick check - if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel && prevMouseClickedPos == mousepos) - { + if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel && prevMouseClickedPos == mousepos) { mouseClicked = 0; // to prevent spam, I guess. HUD_Panel_EnableMenu(); - } - else - { - if (mouseClicked & S_MOUSE1) - { + } else { + if (mouseClicked & S_MOUSE1) { prevMouseClickedTime = time; prevMouseClickedPos = mousepos; } mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1); } - } - else - { + } else { panel = highlightedPanel; HUD_Panel_UpdatePosSize(); } - if (highlightedPanel) - { + if (highlightedPanel) { drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL); - if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size) - { + if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size) { hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions); // backup! panel_pos_backup = highlightedPanel_initial_pos; panel_size_backup = highlightedPanel_initial_size; highlightedPanel_backup = highlightedPanel; - } - else + } else { // in case the clicked panel is inside another panel and we aren't // moving it, avoid the immediate "fix" of its position/size // (often unwanted and hateful) by disabling collisions check hud_configure_checkcollisions = false; + } } - if(highlightedAction == 1) + if (highlightedAction == 1) { HUD_Panel_SetPos(mousepos - panel_click_distance); - else if(highlightedAction == 2) - { + } else if (highlightedAction == 2) { vector mySize = '0 0 0'; - if(resizeCorner == 1) { + if (resizeCorner == 1) { mySize.x = panel_click_resizeorigin.x - (mousepos.x - panel_click_distance.x); mySize.y = panel_click_resizeorigin.y - (mousepos.y - panel_click_distance.y); - } else if(resizeCorner == 2) { + } else if (resizeCorner == 2) { mySize.x = mousepos.x + panel_click_distance.x - panel_click_resizeorigin.x; mySize.y = panel_click_distance.y + panel_click_resizeorigin.y - mousepos.y; - } else if(resizeCorner == 3) { + } else if (resizeCorner == 3) { mySize.x = panel_click_resizeorigin.x + panel_click_distance.x - mousepos.x; mySize.y = mousepos.y + panel_click_distance.y - panel_click_resizeorigin.y; } else { // resizeCorner == 4 @@ -1201,37 +1172,38 @@ void HUD_Panel_Mouse() } HUD_Panel_SetPosSize(mySize); } - } - else - { - if(prevMouseClicked) + } else { + if (prevMouseClicked) { highlightedAction = 0; - if(hud_configure_menu_open == 2) + } + if (hud_configure_menu_open == 2) { mouse_over_panel = 0; - else + } else { mouse_over_panel = HUD_Panel_Check_Mouse_Pos(true); - if (mouse_over_panel && !tab_panel) + } + if (mouse_over_panel && !tab_panel) { drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL); + } } // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel float cursor_alpha = 1 - autocvar__menu_alpha; - if(!mouse_over_panel) + if (!mouse_over_panel) { draw_cursor_normal(mousepos, '1 1 1', cursor_alpha); - else if(mouse_over_panel == 1) + } else if (mouse_over_panel == 1) { draw_cursor(mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha); - else if(mouse_over_panel == 2) + } else if (mouse_over_panel == 2) { draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize", '1 1 1', cursor_alpha); - else + } else { draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize2", '1 1 1', cursor_alpha); + } prevMouseClicked = mouseClicked; } void HUD_Configure_DrawGrid() { float i; - if(autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha) - { + if (autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha) { hud_configure_gridSize.x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2); hud_configure_gridSize.y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2); hud_configure_realGridSize.x = hud_configure_gridSize.x * vid_conwidth; @@ -1239,12 +1211,14 @@ void HUD_Configure_DrawGrid() vector s; // x-axis s = vec2(1, vid_conheight); - for(i = 1; i < 1/hud_configure_gridSize.x; ++i) + for (i = 1; i < 1 / hud_configure_gridSize.x; ++i) { drawfill(eX * i * hud_configure_realGridSize.x, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL); + } // y-axis s = vec2(vid_conwidth, 1); - for(i = 1; i < 1/hud_configure_gridSize.y; ++i) + for (i = 1; i < 1 / hud_configure_gridSize.y; ++i) { drawfill(eY * i * hud_configure_realGridSize.y, s, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL); + } } } @@ -1252,39 +1226,38 @@ float _menu_alpha_prev; void HUD_Configure_Frame() { int i; - if(autocvar__hud_configure) - { - if(isdemo() || intermission == 2 || scoreboard_active) - { + if (autocvar__hud_configure) { + if (isdemo() || intermission == 2 || scoreboard_active) { HUD_Configure_Exit_Force(); return; } - if(!hud_configure_prev) - { - if(autocvar_hud_cursormode) + if (!hud_configure_prev) { + if (autocvar_hud_cursormode) { setcursormode(1); + } hudShiftState = 0; - for(i = hud_panels_COUNT - 1; i >= 0; --i) + for (i = hud_panels_COUNT - 1; i >= 0; --i) { hud_panels_from(panel_order[i]).update_time = time; + } } // NOTE this check is necessary because _menu_alpha isn't updated the frame the menu gets enabled - if(autocvar__menu_alpha != _menu_alpha_prev) - { - if(autocvar__menu_alpha == 0) + if (autocvar__menu_alpha != _menu_alpha_prev) { + if (autocvar__menu_alpha == 0) { hud_configure_menu_open = 0; + } _menu_alpha_prev = autocvar__menu_alpha; } HUD_Configure_DrawGrid(); - } - else if(hud_configure_prev) - { - if(hud_configure_menu_open) + } else if (hud_configure_prev) { + if (hud_configure_menu_open) { hud_configure_menu_open = 0; - if(autocvar_hud_cursormode) + } + if (autocvar_hud_cursormode) { setcursormode(0); + } hud_dynamic_shake_factor = -1; } } @@ -1305,16 +1278,13 @@ void HUD_Panel_HlBorder(float myBorder, vector color, float theAlpha) void HUD_Configure_PostDraw() { - if(autocvar__hud_configure) - { - if(tab_panel) - { + if (autocvar__hud_configure) { + if (tab_panel) { panel = tab_panel; HUD_Panel_UpdatePosSize(); drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL); } - if(highlightedPanel) - { + if (highlightedPanel) { panel = highlightedPanel; HUD_Panel_UpdatePosSize(); HUD_Panel_HlBorder(panel_bg_border * hlBorderSize, '0 0.5 1', 0.4 * (1 - autocvar__menu_alpha)); diff --git a/qcsrc/client/hud/hud_config.qh b/qcsrc/client/hud/hud_config.qh index 6ab64f6ae..6561b48fd 100644 --- a/qcsrc/client/hud/hud_config.qh +++ b/qcsrc/client/hud/hud_config.qh @@ -4,7 +4,7 @@ const int S_MOUSE1 = 1; const int S_MOUSE2 = 2; const int S_MOUSE3 = 4; int mouseClicked; -int prevMouseClicked; // previous state +int prevMouseClicked; // previous state float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks diff --git a/qcsrc/client/hud/panel/centerprint.qc b/qcsrc/client/hud/panel/centerprint.qc index a92bdc692..7b28f9914 100644 --- a/qcsrc/client/hud/panel/centerprint.qc +++ b/qcsrc/client/hud/panel/centerprint.qc @@ -20,74 +20,80 @@ bool centerprint_showing; void centerprint_generic(int new_id, string strMessage, float duration, int countdown_num) { - TC(int, new_id); TC(int, countdown_num); - //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num); + TC(int, new_id); + TC(int, countdown_num); + // printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num); int i, j; - if(strMessage == "" && new_id == 0) + if (strMessage == "" && new_id == 0) { return; + } // strip trailing newlines j = strlen(strMessage) - 1; - while(substring(strMessage, j, 1) == "\n" && j >= 0) + while (substring(strMessage, j, 1) == "\n" && j >= 0) { --j; - if (j < strlen(strMessage) - 1) + } + if (j < strlen(strMessage) - 1) { strMessage = substring(strMessage, 0, j + 1); + } - if(strMessage == "" && new_id == 0) + if (strMessage == "" && new_id == 0) { return; + } // strip leading newlines j = 0; - while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage)) + while (substring(strMessage, j, 1) == "\n" && j < strlen(strMessage)) { ++j; - if (j > 0) + } + if (j > 0) { strMessage = substring(strMessage, j, strlen(strMessage) - j); + } - if(strMessage == "" && new_id == 0) + if (strMessage == "" && new_id == 0) { return; + } - if (!centerprint_showing) + if (!centerprint_showing) { centerprint_showing = true; + } - for (i=0, j=cpm_index; i hud_configure_cp_generation_time) - { - if(highlightedPanel == HUD_PANEL(CENTERPRINT)) - { + if (time > hud_configure_cp_generation_time) { + if (highlightedPanel == HUD_PANEL(CENTERPRINT)) { float r; r = random(); - if (r > 0.8) - centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10); - else if (r > 0.55) + if (r > 0.8) { + centerprint_generic(floor(r * 1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10); + } else if (r > 0.55) { centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0); - else + } else { centerprint_hud(sprintf("Message at time %s", seconds_tostring(time))); - hud_configure_cp_generation_time = time + 1 + random()*4; - } - else - { + } + hud_configure_cp_generation_time = time + 1 + random() * 4; + } else { centerprint_generic(0, sprintf("Centerprint message", seconds_tostring(time)), 10, 0); - hud_configure_cp_generation_time = time + 10 - random()*3; + hud_configure_cp_generation_time = time + 10 - random() * 3; } } } HUD_Panel_LoadCvars(); - if ( HUD_Radar_Clickable() ) - { - if (hud_panel_radar_bottom >= 0.96 * vid_conheight) + if (HUD_Radar_Clickable()) { + if (hud_panel_radar_bottom >= 0.96 * vid_conheight) { return; + } panel_pos.x = 0.5 * (vid_conwidth - panel_size.x); panel_pos.y = hud_panel_radar_bottom; panel_size.y = min(panel_size.y, vid_conheight - hud_panel_radar_bottom); - } - else if(!autocvar__hud_configure && scoreboard_fade_alpha) - { + } else if (!autocvar__hud_configure && scoreboard_fade_alpha) { // move the panel below the scoreboard - if (scoreboard_bottom >= 0.96 * vid_conheight) + if (scoreboard_bottom >= 0.96 * vid_conheight) { return; + } vector target_pos = vec2(0.5 * (vid_conwidth - panel_size.x), scoreboard_bottom); - if(target_pos.y > panel_pos.y) - { + if (target_pos.y > panel_pos.y) { panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha); panel_size.y = min(panel_size.y, vid_conheight - scoreboard_bottom); } } - if (autocvar_hud_panel_centerprint_dynamichud) + if (autocvar_hud_panel_centerprint_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if (!centerprint_showing) + if (!centerprint_showing) { return; + } - if(panel_bg_padding) - { + if (panel_bg_padding) { panel_pos += '1 1 0' * panel_bg_padding; panel_size -= '2 2 0' * panel_bg_padding; } @@ -201,9 +200,9 @@ void HUD_CenterPrint () // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES); // height = panel_size_y/entries; // fontsize = '1 1 0' * height; - height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale; + height = vid_conheight / 50 * autocvar_hud_panel_centerprint_fontscale; fontsize = '1 1 0' * height; - entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES); + entries = bound(1, floor(panel_size.y / height), CENTERPRINT_MAX_ENTRIES); int i, j, k, n, g; float a, sz, align, current_msg_posY = 0, msg_size; @@ -212,58 +211,61 @@ void HUD_CenterPrint () bool all_messages_expired = true; pos = panel_pos; - if (autocvar_hud_panel_centerprint_flip) + if (autocvar_hud_panel_centerprint_flip) { pos.y += panel_size.y; + } align = bound(0, autocvar_hud_panel_centerprint_align, 1); - for (g=0, i=0, j=cpm_index; i 0) + if (centerprint_time[j] > 0) { centerprint_expire_time[j] += centerprint_time[j]; + } } - if (centerprint_expire_time[j] <= time) - { - if (centerprint_countdown_num[j] && centerprint_time[j] > 0) - { + if (centerprint_expire_time[j] <= time) { + if (centerprint_countdown_num[j] && centerprint_time[j] > 0) { centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1; - if (centerprint_countdown_num[j] == 0) + if (centerprint_countdown_num[j] == 0) { continue; + } centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j]; - } - else if(centerprint_time[j] != -1) + } else if (centerprint_time[j] != -1) { continue; + } } all_messages_expired = false; // fade the centerprint_hud in/out - if(centerprint_time[j] < 0) // Expired but forced. Expire time is the fade-in time. + if (centerprint_time[j] < 0) { // Expired but forced. Expire time is the fade-in time. a = (time - centerprint_expire_time[j]) / max(0.0001, autocvar_hud_panel_centerprint_fade_in); - else if(centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time) // Regularily printed. Not fading out yet. + } else if (centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time) { // Regularily printed. Not fading out yet. a = (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in); - else // Expiring soon, so fade it out. + } else { // Expiring soon, so fade it out. a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out); + } - if(centerprint_msgID[j] == CPID_TIMEIN) + if (centerprint_msgID[j] == CPID_TIMEIN) { a = 1; + } // while counting down show it anyway in order to hold the current message position - if (a <= 0.5/255.0 && centerprint_countdown_num[j] == 0) // Guaranteed invisible - don't show. + if (a <= 0.5 / 255.0 && centerprint_countdown_num[j] == 0) { // Guaranteed invisible - don't show. continue; - if (a > 1) + } + if (a > 1) { a = 1; + } // set the size from fading in/out before subsequent fading sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize); // also fade it based on positioning - if(autocvar_hud_panel_centerprint_fade_subsequent) - { + if (autocvar_hud_panel_centerprint_fade_subsequent) { // pass one: all messages after the first have half alpha a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passone_minalpha, (1 - (g / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passone))), 1); // pass two: after that, gradually lower alpha even more for each message @@ -275,80 +277,74 @@ void HUD_CenterPrint () sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize)); drawfontscale = hud_scale * sz; - if (centerprint_countdown_num[j]) + if (centerprint_countdown_num[j]) { n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n"); - else + } else { n = tokenizebyseparator(centerprint_messages[j], "\n"); + } - if (autocvar_hud_panel_centerprint_flip) - { + if (autocvar_hud_panel_centerprint_flip) { // check if the message can be entirely shown - for(k = 0; k < n; ++k) - { + for (k = 0; k < n; ++k) { getWrappedLine_remaining = argv(k); - while(getWrappedLine_remaining) - { + while (getWrappedLine_remaining) { ts = getWrappedLine(panel_size.x * hud_scale.x * sz, fontsize, stringwidth_colors); - if (ts != "") + if (ts != "") { pos.y -= fontsize.y; - else - pos.y -= fontsize.y * CENTERPRINT_SPACING/2; + } else { + pos.y -= fontsize.y * CENTERPRINT_SPACING / 2; + } } } current_msg_posY = pos.y; // save starting pos (first line) of the current message } msg_size = pos.y; - for(k = 0; k < n; ++k) - { + for (k = 0; k < n; ++k) { getWrappedLine_remaining = argv(k); - while(getWrappedLine_remaining) - { + while (getWrappedLine_remaining) { ts = getWrappedLine(panel_size.x * hud_scale.x * sz, fontsize, stringwidth_colors); - if (ts != "") - { - if (align) + if (ts != "") { + if (align) { pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize) * sz) * align; - if (a > 0.5/255.0) // Otherwise guaranteed invisible - don't show. This is checked a second time after some multiplications with other factors were done so temporary changes of these cannot cause flicker. + } + if (a > 0.5 / 255.0) { // Otherwise guaranteed invisible - don't show. This is checked a second time after some multiplications with other factors were done so temporary changes of these cannot cause flicker. drawcolorcodedstring(pos + eY * 0.5 * (1 - sz * hud_scale.x) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL); + } pos.y += fontsize.y; + } else { + pos.y += fontsize.y * CENTERPRINT_SPACING / 2; } - else - pos.y += fontsize.y * CENTERPRINT_SPACING/2; } } ++g; // move next position number up msg_size = pos.y - msg_size; - if (autocvar_hud_panel_centerprint_flip) - { + if (autocvar_hud_panel_centerprint_flip) { pos.y = current_msg_posY - CENTERPRINT_SPACING * fontsize.y; - if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages + if (a < 1 && centerprint_msgID[j] == 0) { // messages with id can be replaced just after they are faded out, so never move over them the next messages pos.y += (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz)); + } - if (pos.y < panel_pos.y) // check if the next message can be shown - { + if (pos.y < panel_pos.y) { // check if the next message can be shown drawfontscale = hud_scale; return; } - } - else - { + } else { pos.y += CENTERPRINT_SPACING * fontsize.y; - if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages + if (a < 1 && centerprint_msgID[j] == 0) { // messages with id can be replaced just after they are faded out, so never move over them the next messages pos.y -= (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz)); + } - if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown - { + if (pos.y > panel_pos.y + panel_size.y - fontsize.y) { // check if the next message can be shown drawfontscale = hud_scale; return; } } } drawfontscale = hud_scale; - if (all_messages_expired) - { + if (all_messages_expired) { centerprint_showing = false; reset_centerprint_messages(); } diff --git a/qcsrc/client/hud/panel/chat.qc b/qcsrc/client/hud/panel/chat.qc index 74d4b6d0f..e5dd27529 100644 --- a/qcsrc/client/hud/panel/chat.qc +++ b/qcsrc/client/hud/panel/chat.qc @@ -8,20 +8,16 @@ void HUD_Chat() { - if(!autocvar__hud_configure) - { - if (!autocvar_hud_panel_chat) - { - if (!autocvar_con_chatrect) + if (!autocvar__hud_configure) { + if (!autocvar_hud_panel_chat) { + if (!autocvar_con_chatrect) { cvar_set("con_chatrect", "0"); + } return; } - if(autocvar__con_chat_maximized) - { - if(!hud_draw_maximized) return; - } - else if(chat_panel_modified) - { + if (autocvar__con_chat_maximized) { + if (!hud_draw_maximized) { return; } + } else if (chat_panel_modified) { panel.update_time = time; // forces reload of panel attributes chat_panel_modified = false; } @@ -29,8 +25,7 @@ void HUD_Chat() HUD_Panel_LoadCvars(); - if(intermission == 2) - { + if (intermission == 2) { // reserve some more space to the mapvote panel // by resizing and moving chat panel to the bottom panel_size.y = min(panel_size.y, vid_conheight * 0.2); @@ -38,18 +33,18 @@ void HUD_Chat() chat_posy = panel_pos.y; chat_sizey = panel_size.y; } - if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized - { + if (autocvar__con_chat_maximized && !autocvar__hud_configure) { // draw at full screen height if maximized panel_pos.y = panel_bg_border; panel_size.y = vid_conheight - panel_bg_border * 2; - if(panel.current_panel_bg == "0") // force a border when maximized - { + if (panel.current_panel_bg == "0") { // force a border when maximized string panel_bg; panel_bg = strcat(hud_skin_path, "/border_default"); - if(precache_pic(panel_bg) == "") + if (precache_pic(panel_bg) == "") { panel_bg = "gfx/hud/default/border_default"; - if(panel.current_panel_bg) + } + if (panel.current_panel_bg) { strunzone(panel.current_panel_bg); + } panel.current_panel_bg = strzone(panel_bg); chat_panel_modified = true; } @@ -64,28 +59,26 @@ void HUD_Chat() HUD_Scale_Disable(); HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } - if (!autocvar_con_chatrect) + if (!autocvar_con_chatrect) { cvar_set("con_chatrect", "1"); + } - cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth)); - cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight)); + cvar_set("con_chatrect_x", ftos(pos.x / vid_conwidth)); + cvar_set("con_chatrect_y", ftos(pos.y / vid_conheight)); - cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth)); - cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5))); + cvar_set("con_chatwidth", ftos(mySize.x / vid_conwidth)); + cvar_set("con_chat", ftos(floor(mySize.y / autocvar_con_chatsize - 0.5))); - if(autocvar__hud_configure) - { + if (autocvar__hud_configure) { vector chatsize = '1 1 0' * autocvar_con_chatsize; cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such string str = textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors); - for(int i = 0; i < autocvar_con_chat; ++i) - { + for (int i = 0; i < autocvar_con_chat; ++i) { // engine displays chat text at full alpha drawcolorcodedstring(pos, str, chatsize, 1, DRAWFLAG_NORMAL); pos.y += chatsize.y; diff --git a/qcsrc/client/hud/panel/engineinfo.qc b/qcsrc/client/hud/panel/engineinfo.qc index ed7966c16..c735e3017 100644 --- a/qcsrc/client/hud/panel/engineinfo.qc +++ b/qcsrc/client/hud/panel/engineinfo.qc @@ -17,9 +17,8 @@ float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_we float autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold; void HUD_EngineInfo() { - if(!autocvar__hud_configure) - { - if(!autocvar_hud_panel_engineinfo) return; + if (!autocvar__hud_configure) { + if (!autocvar_hud_panel_engineinfo) { return; } } HUD_Panel_LoadCvars(); @@ -27,47 +26,43 @@ void HUD_EngineInfo() pos = panel_pos; mySize = panel_size; - if (autocvar_hud_panel_engineinfo_dynamichud) + if (autocvar_hud_panel_engineinfo_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } float currentTime = gettime(GETTIME_REALTIME); - if(autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage) - { + if (autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage) { float currentframetime = currentTime - prevfps_time; - frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P + frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime) / 4; // average three frametimes into framecounter for slightly more stable fps readings :P frametimeavg2 = frametimeavg1; frametimeavg1 = frametimeavg; float weight; weight = autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight; - if(currentframetime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter. - { - if(fabs(prevfps - (1/frametimeavg)) > prevfps * autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold) // if there was a big jump in fps, just force prevfps at current (1/currentframetime) to make big updates instant - prevfps = (1/currentframetime); - prevfps = (1 - weight) * prevfps + weight * (1/frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average" + if (currentframetime > 0.0001) { // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter. + if (fabs(prevfps - (1 / frametimeavg)) > prevfps * autocvar_hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold) { // if there was a big jump in fps, just force prevfps at current (1/currentframetime) to make big updates instant + prevfps = (1 / currentframetime); + } + prevfps = (1 - weight) * prevfps + weight * (1 / frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average" } prevfps_time = currentTime; - } - else - { + } else { framecounter += 1; - if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time) - { - prevfps = framecounter/(currentTime - prevfps_time); + if (currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time) { + prevfps = framecounter / (currentTime - prevfps_time); framecounter = 0; prevfps_time = currentTime; } } vector color; - color = HUD_Get_Num_Color (prevfps, 100); + color = HUD_Get_Num_Color(prevfps, 100); drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL); } diff --git a/qcsrc/client/hud/panel/healtharmor.qc b/qcsrc/client/hud/panel/healtharmor.qc index 4c08ef900..7125ca132 100644 --- a/qcsrc/client/hud/panel/healtharmor.qc +++ b/qcsrc/client/hud/panel/healtharmor.qc @@ -10,27 +10,26 @@ void HUD_HealthArmor() { int armor, health, fuel; - if(!autocvar__hud_configure) - { - if((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1)) + if (!autocvar__hud_configure) { + if ((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1)) { return; - if(hud != HUD_NORMAL) return; + } + if (hud != HUD_NORMAL) { return; } health = STAT(HEALTH); - if(health <= 0) - { + if (health <= 0) { health = 0; prev_health = -1; - if(autocvar_hud_panel_healtharmor_hide_ondeath) + if (autocvar_hud_panel_healtharmor_hide_ondeath) { return; + } } armor = STAT(ARMOR); // code to check for spectatee_status changes is in ENT_CLIENT_CLIENTDATA // prev_p_health and prev_health can be set to -1 there - if (prev_p_health == -1) - { + if (prev_p_health == -1) { // no effect health_beforedamage = 0; armor_beforedamage = 0; @@ -42,19 +41,15 @@ void HUD_HealthArmor() old_p_armor = armor; prev_p_health = health; prev_p_armor = armor; - } - else if (prev_health == -1) - { - //start the load effect + } else if (prev_health == -1) { + // start the load effect health_damagetime = 0; armor_damagetime = 0; prev_health = 0; prev_armor = 0; } fuel = STAT(FUEL); - } - else - { + } else { health = 150; armor = 75; fuel = 20; @@ -68,13 +63,13 @@ void HUD_HealthArmor() pos = panel_pos; mySize = panel_size; - if (autocvar_hud_panel_healtharmor_dynamichud) + if (autocvar_hud_panel_healtharmor_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } @@ -84,8 +79,7 @@ void HUD_HealthArmor() int maxhealth = autocvar_hud_panel_healtharmor_maxhealth; int maxarmor = autocvar_hud_panel_healtharmor_maxarmor; - if(autocvar_hud_panel_healtharmor_combined) // combined health and armor display - { + if (autocvar_hud_panel_healtharmor_combined) { // combined health and armor display vector v; v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id); @@ -93,62 +87,59 @@ void HUD_HealthArmor() float maxtotal = maxhealth + maxarmor; string biggercount; - if(v.z) // NOT fully armored - { + if (v.z) { // NOT fully armored biggercount = "health"; - if(autocvar_hud_panel_healtharmor_progressbar) - HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, hp/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - if(armor && autocvar_hud_panel_healtharmor_text) + if (autocvar_hud_panel_healtharmor_progressbar) { + HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, hp / maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + if (armor && autocvar_hud_panel_healtharmor_text) { drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "armor", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha * armor / health, DRAWFLAG_NORMAL); - } - else - { + } + } else { biggercount = "armor"; - if(autocvar_hud_panel_healtharmor_progressbar) - HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, hp/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - if(health && autocvar_hud_panel_healtharmor_text) + if (autocvar_hud_panel_healtharmor_progressbar) { + HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, hp / maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + if (health && autocvar_hud_panel_healtharmor_text) { drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "health", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + } } - if(autocvar_hud_panel_healtharmor_text) + if (autocvar_hud_panel_healtharmor_text) { DrawNumIcon(pos, mySize, hp, biggercount, 0, iconalign, HUD_Get_Num_Color(hp, maxtotal), 1); + } - if(fuel) - HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); - } - else - { - float panel_ar = mySize.x/mySize.y; + if (fuel) { + HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel / 100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); + } + } else { + float panel_ar = mySize.x / mySize.y; bool is_vertical = (panel_ar < 1); vector health_offset = '0 0 0', armor_offset = '0 0 0'; - if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1)) - { + if (panel_ar >= 4 || (panel_ar >= 1 / 4 && panel_ar < 1)) { mySize.x *= 0.5; - if (autocvar_hud_panel_healtharmor_flip) + if (autocvar_hud_panel_healtharmor_flip) { health_offset.x = mySize.x; - else + } else { armor_offset.x = mySize.x; - } - else - { + } + } else { mySize.y *= 0.5; - if (autocvar_hud_panel_healtharmor_flip) + if (autocvar_hud_panel_healtharmor_flip) { health_offset.y = mySize.y; - else + } else { armor_offset.y = mySize.y; + } } bool health_baralign, armor_baralign, fuel_baralign; bool health_iconalign, armor_iconalign; - if (autocvar_hud_panel_healtharmor_flip) - { + if (autocvar_hud_panel_healtharmor_flip) { armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1); health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1); fuel_baralign = health_baralign; armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1); health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1); - } - else - { + } else { health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1); armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1); fuel_baralign = armor_baralign; @@ -156,119 +147,111 @@ void HUD_HealthArmor() armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1); } - //if(health) + // if(health) { - if(autocvar_hud_panel_healtharmor_progressbar) - { + if (autocvar_hud_panel_healtharmor_progressbar) { float p_health, pain_health_alpha; p_health = health; pain_health_alpha = 1; - if (autocvar_hud_panel_healtharmor_progressbar_gfx) - { - if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0) - { - if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth) - { - if (time - old_p_healthtime < 1) + if (autocvar_hud_panel_healtharmor_progressbar_gfx) { + if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0) { + if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth) { + if (time - old_p_healthtime < 1) { old_p_health = prev_p_health; - else + } else { old_p_health = prev_health; + } old_p_healthtime = time; } - if (time - old_p_healthtime < 1) - { + if (time - old_p_healthtime < 1) { p_health += (old_p_health - health) * (1 - (time - old_p_healthtime)); prev_p_health = p_health; } } - if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0) - { - if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) - { - if (time - health_damagetime >= 1) + if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0) { + if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) { + if (time - health_damagetime >= 1) { health_beforedamage = prev_health; + } health_damagetime = time; } - if (time - health_damagetime < 1) - { - float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime); - HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL); + if (time - health_damagetime < 1) { + float health_damagealpha = 1 - (time - health_damagetime) * (time - health_damagetime); + HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage / maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL); } } prev_health = health; - if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth) - { + if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth) { float BLINK_FACTOR = 0.15; float BLINK_BASE = 0.85; float BLINK_FREQ = 9; pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); } } - HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health / maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL); } - if(autocvar_hud_panel_healtharmor_text) + if (autocvar_hud_panel_healtharmor_text) { DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1); + } } - //if(armor) + // if(armor) { float p_armor = armor; - if(autocvar_hud_panel_healtharmor_progressbar) - { - if (autocvar_hud_panel_healtharmor_progressbar_gfx) - { - if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0) - { - if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth) - { - if (time - old_p_armortime < 1) + if (autocvar_hud_panel_healtharmor_progressbar) { + if (autocvar_hud_panel_healtharmor_progressbar_gfx) { + if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0) { + if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth) { + if (time - old_p_armortime < 1) { old_p_armor = prev_p_armor; - else + } else { old_p_armor = prev_armor; + } old_p_armortime = time; } - if (time - old_p_armortime < 1) - { + if (time - old_p_armortime < 1) { p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime)); prev_p_armor = p_armor; } } - if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0) - { - if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) - { - if (time - armor_damagetime >= 1) + if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0) { + if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) { + if (time - armor_damagetime >= 1) { armor_beforedamage = prev_armor; + } armor_damagetime = time; } - if (time - armor_damagetime < 1) - { - float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime); - HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL); + if (time - armor_damagetime < 1) { + float armor_damagealpha = 1 - (time - armor_damagetime) * (time - armor_damagetime); + HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage / maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL); } } prev_armor = armor; } - if(p_armor) - HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + if (p_armor) { + HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor / maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + } + if (!autocvar_hud_panel_healtharmor_progressbar || p_armor) { + if (autocvar_hud_panel_healtharmor_text) { + DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1); + } } - if(!autocvar_hud_panel_healtharmor_progressbar || p_armor) - if(autocvar_hud_panel_healtharmor_text) - DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1); } - if(fuel) - { - if (is_vertical) - mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits - else + if (fuel) { + if (is_vertical) { + mySize.x *= 0.2 / 2; // if vertical always halve x to not cover too much numbers with 3 digits + } else { mySize.y *= 0.2; - if (panel_ar >= 4) - mySize.x *= 2; //restore full panel size - else if (panel_ar < 1/4) - mySize.y *= 2; //restore full panel size - HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); + } + if (panel_ar >= 4) { + mySize.x *= 2; // restore full panel size + } else if (panel_ar < 1 / 4) { + mySize.y *= 2; // restore full panel size + } + HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel / 100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL); } } diff --git a/qcsrc/client/hud/panel/notify.qc b/qcsrc/client/hud/panel/notify.qc index 82690bee7..c37719724 100644 --- a/qcsrc/client/hud/panel/notify.qc +++ b/qcsrc/client/hud/panel/notify.qc @@ -7,33 +7,35 @@ void HUD_Notify_Push(string icon, string attacker, string victim) { - if (icon == "") + if (icon == "") { return; + } ++notify_count; --notify_index; - if (notify_index == -1) - notify_index = NOTIFY_MAX_ENTRIES-1; + if (notify_index == -1) { + notify_index = NOTIFY_MAX_ENTRIES - 1; + } // Free old strings - if (notify_attackers[notify_index]) + if (notify_attackers[notify_index]) { strunzone(notify_attackers[notify_index]); + } - if (notify_victims[notify_index]) + if (notify_victims[notify_index]) { strunzone(notify_victims[notify_index]); + } - if (notify_icons[notify_index]) + if (notify_icons[notify_index]) { strunzone(notify_icons[notify_index]); + } // Allocate new strings - if (victim != "") - { + if (victim != "") { notify_attackers[notify_index] = strzone(attacker); notify_victims[notify_index] = strzone(victim); - } - else - { + } else { // In case of a notification without a victim, the attacker // is displayed on the victim's side. Instead of special // treatment later on, we can simply switch them here. @@ -47,28 +49,32 @@ void HUD_Notify_Push(string icon, string attacker, string victim) void HUD_Notify() { - if (!autocvar__hud_configure) - if (!autocvar_hud_panel_notify) + if (!autocvar__hud_configure) { + if (!autocvar_hud_panel_notify) { return; + } + } HUD_Panel_LoadCvars(); - if (autocvar_hud_panel_notify_dynamichud) + if (autocvar_hud_panel_notify_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if (!autocvar__hud_configure) - if (notify_count == 0) + if (!autocvar__hud_configure) { + if (notify_count == 0) { return; + } + } vector pos, size; pos = panel_pos; size = panel_size; - if (panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; size -= '2 2 0' * panel_bg_padding; } @@ -95,53 +101,46 @@ void HUD_Notify() int i, j, count, step, limit; float alpha; - if (autocvar_hud_panel_notify_flip) - { + if (autocvar_hud_panel_notify_flip) { // Order items from the top down i = 0; step = +1; limit = entry_count; - } - else - { + } else { // Order items from the bottom up i = entry_count - 1; step = -1; limit = -1; } - for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count) - { - if(autocvar__hud_configure) - { + for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count) { + if (autocvar__hud_configure) { attacker = sprintf(_("Player %d"), count + 1); victim = sprintf(_("Player %d"), count + 2); icon = Weapons_from(min(WEP_FIRST + count * 2, WEP_LAST)).model2; alpha = bound(0, 1.2 - count / entry_count, 1); - } - else - { - if (j == NOTIFY_MAX_ENTRIES) + } else { + if (j == NOTIFY_MAX_ENTRIES) { j = 0; + } - if (notify_times[j] + fade_start > time) + if (notify_times[j] + fade_start > time) { alpha = 1; - else if (fade_time != 0) - { + } else if (fade_time != 0) { alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1); - if (alpha == 0) + if (alpha == 0) { break; - } - else + } + } else { break; + } attacker = notify_attackers[j]; victim = notify_victims[j]; icon = notify_icons[j]; } - if (icon != "" && victim != "") - { + if (icon != "" && victim != "") { vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y)); icon_pos = pos + icon_left + eY * i * entry_height; @@ -151,8 +150,7 @@ void HUD_Notify() victim_pos = pos + victim_left + name_top; drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL); - if (attacker != "") - { + if (attacker != "") { attacker = textShortenToWidth(ColorTranslateRGB(attacker), name_maxwidth, font_size, stringwidth_colors); attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top; drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL); diff --git a/qcsrc/client/hud/panel/physics.qc b/qcsrc/client/hud/panel/physics.qc index f58b442bc..400249eb5 100644 --- a/qcsrc/client/hud/panel/physics.qc +++ b/qcsrc/client/hud/panel/physics.qc @@ -14,71 +14,72 @@ float acc_prevtime, acc_avg, top_speed, top_speed_time; float physics_update_time, discrete_speed, discrete_acceleration; void HUD_Physics() { - if(!autocvar__hud_configure) - { - if(!autocvar_hud_panel_physics) return; - if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return; - if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return; + if (!autocvar__hud_configure) { + if (!autocvar_hud_panel_physics) { return; } + if (spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) { return; } + if (autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) { return; } } HUD_Panel_LoadCvars(); draw_beginBoldFont(); - if (autocvar_hud_panel_physics_dynamichud) + if (autocvar_hud_panel_physics_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { panel_pos += '1 1 0' * panel_bg_padding; panel_size -= '2 2 0' * panel_bg_padding; } float acceleration_progressbar_scale = 0; - if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1) + if (autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1) { acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale; + } float text_scale; - if (autocvar_hud_panel_physics_text_scale <= 0) + if (autocvar_hud_panel_physics_text_scale <= 0) { text_scale = 1; - else + } else { text_scale = min(autocvar_hud_panel_physics_text_scale, 1); + } - //compute speed + // compute speed float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit); vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel); - float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 ); - if (autocvar__hud_configure) - speed = floor( max_speed * 0.65 + 0.5 ); - else if(autocvar_hud_panel_physics_speed_vertical) - speed = floor( vlen(vel) * conversion_factor + 0.5 ); - else - speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 ); + float max_speed = floor(autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5); + if (autocvar__hud_configure) { + speed = floor(max_speed * 0.65 + 0.5); + } else if (autocvar_hud_panel_physics_speed_vertical) { + speed = floor(vlen(vel) * conversion_factor + 0.5); + } else { + speed = floor(vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5); + } - //compute acceleration + // compute acceleration float acceleration, f; - if (autocvar__hud_configure) + if (autocvar__hud_configure) { acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3; - else - { + } else { // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2 f = time - acc_prevtime; - if(autocvar_hud_panel_physics_acceleration_vertical) + if (autocvar_hud_panel_physics_acceleration_vertical) { acceleration = (vlen(vel) - vlen(acc_prevspeed)); - else + } else { acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z)); + } acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665); acc_prevspeed = vel; acc_prevtime = time; - if(autocvar_hud_panel_physics_acceleration_movingaverage) - { + if (autocvar_hud_panel_physics_acceleration_movingaverage) { f = bound(0, f * 10, 1); acc_avg = acc_avg * (1 - f) + acceleration * f; acceleration = acc_avg; @@ -86,79 +87,78 @@ void HUD_Physics() } const int acc_decimals = 2; - if(time > physics_update_time) - { + if (time > physics_update_time) { // workaround for ftos_decimals returning a negative 0 - if(discrete_acceleration > -1 / POW(10, acc_decimals) && discrete_acceleration < 0) + if (discrete_acceleration > -1 / POW(10, acc_decimals) && discrete_acceleration < 0) { discrete_acceleration = 0; + } discrete_acceleration = acceleration; discrete_speed = speed; physics_update_time += autocvar_hud_panel_physics_update_interval; - if(physics_update_time < time) + if (physics_update_time < time) { physics_update_time = time + autocvar_hud_panel_physics_update_interval; + } } - //compute layout - float panel_ar = panel_size.x/panel_size.y; + // compute layout + float panel_ar = panel_size.x / panel_size.y; vector speed_offset = '0 0 0', acceleration_offset = '0 0 0'; - if (panel_ar >= 5 && !acceleration_progressbar_scale) - { + if (panel_ar >= 5 && !acceleration_progressbar_scale) { panel_size.x *= 0.5; - if (autocvar_hud_panel_physics_flip) + if (autocvar_hud_panel_physics_flip) { speed_offset.x = panel_size.x; - else + } else { acceleration_offset.x = panel_size.x; - } - else - { + } + } else { panel_size.y *= 0.5; - if (autocvar_hud_panel_physics_flip) + if (autocvar_hud_panel_physics_flip) { speed_offset.y = panel_size.y; - else + } else { acceleration_offset.y = panel_size.y; + } } int speed_baralign, acceleration_baralign; - if (autocvar_hud_panel_physics_baralign == 1) + if (autocvar_hud_panel_physics_baralign == 1) { acceleration_baralign = speed_baralign = 1; - else if(autocvar_hud_panel_physics_baralign == 4) + } else if (autocvar_hud_panel_physics_baralign == 4) { acceleration_baralign = speed_baralign = 2; - else if (autocvar_hud_panel_physics_flip) - { + } else if (autocvar_hud_panel_physics_flip) { acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2); speed_baralign = (autocvar_hud_panel_physics_baralign == 3); - } - else - { + } else { speed_baralign = (autocvar_hud_panel_physics_baralign == 2); acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3); } - if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0) - acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration - - //draw speed - if(speed) - if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2) - HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0) { + acceleration_baralign = 3; // override hud_panel_physics_baralign value for acceleration + } + // draw speed + if (speed) { + if (autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2) { + HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed / max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + } vector tmp_offset = '0 0 0', tmp_size = '0 0 0'; - if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2) - { + if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2) { tmp_size.x = panel_size.x * 0.75; tmp_size.y = panel_size.y * text_scale; - if (speed_baralign) + if (speed_baralign) { tmp_offset.x = panel_size.x - tmp_size.x; - //else - //tmp_offset_x = 0; + } + // else + // tmp_offset_x = 0; tmp_offset.y = (panel_size.y - tmp_size.y) / 2; drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(discrete_speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); - //draw speed unit - if (speed_baralign) + // draw speed unit + if (speed_baralign) { tmp_offset.x = 0; - else + } else { tmp_offset.x = tmp_size.x; - if (autocvar_hud_panel_physics_speed_unit_show) - { - //tmp_offset_y = 0; + } + if (autocvar_hud_panel_physics_speed_unit_show) { + // tmp_offset_y = 0; tmp_size.x = panel_size.x * (1 - 0.75); tmp_size.y = panel_size.y * 0.4 * text_scale; tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2; @@ -166,104 +166,97 @@ void HUD_Physics() } } - //compute and draw top speed - if (autocvar_hud_panel_physics_topspeed) - if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2) - { - if (autocvar__hud_configure) - { - top_speed = floor( max_speed * 0.75 + 0.5 ); - f = 1; - } - else - { - if (speed >= top_speed) - { - top_speed = speed; - top_speed_time = time; - } - if (top_speed != 0) - { - f = max(1, autocvar_hud_panel_physics_topspeed_time); - // divide by f to make it start from 1 - f = cos( ((time - top_speed_time) / f) * PI/2 ); - } - else //hide top speed 0, it would be stupid - f = 0; - } - if (f > 0) - { - //top speed progressbar peak - if(speed < top_speed) - if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2) - { - float peak_offsetX; - vector peak_size = '0 0 0'; - if (speed_baralign == 0) - peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x; - else if (speed_baralign == 1) - peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x; - else // if (speed_baralign == 2) - peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5; - peak_size.x = floor(panel_size.x * 0.01 + 1.5); - peak_size.y = panel_size.y; - if (speed_baralign == 2) // draw two peaks, on both sides - { - drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x + peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x - peak_offsetX + peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } - else - drawfill(panel_pos + speed_offset + eX * (peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + // compute and draw top speed + if (autocvar_hud_panel_physics_topspeed) { + if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2) { + if (autocvar__hud_configure) { + top_speed = floor(max_speed * 0.75 + 0.5); + f = 1; + } else { + if (speed >= top_speed) { + top_speed = speed; + top_speed_time = time; + } + if (top_speed != 0) { + f = max(1, autocvar_hud_panel_physics_topspeed_time); + // divide by f to make it start from 1 + f = cos(((time - top_speed_time) / f) * PI / 2); + } else { // hide top speed 0, it would be stupid + f = 0; + } } + if (f > 0) { + // top speed progressbar peak + if (speed < top_speed) { + if (autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2) { + float peak_offsetX; + vector peak_size = '0 0 0'; + if (speed_baralign == 0) { + peak_offsetX = min(top_speed, max_speed) / max_speed * panel_size.x; + } else if (speed_baralign == 1) { + peak_offsetX = (1 - min(top_speed, max_speed) / max_speed) * panel_size.x; + } else { // if (speed_baralign == 2) + peak_offsetX = min(top_speed, max_speed) / max_speed * panel_size.x * 0.5; + } + peak_size.x = floor(panel_size.x * 0.01 + 1.5); + peak_size.y = panel_size.y; + if (speed_baralign == 2) { // draw two peaks, on both sides + drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x + peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x - peak_offsetX + peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } else { + drawfill(panel_pos + speed_offset + eX * (peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + } + } - //top speed - tmp_offset.y = panel_size.y * 0.4; - tmp_size.x = panel_size.x * (1 - 0.75); - tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale; - tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2; - drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL); + // top speed + tmp_offset.y = panel_size.y * 0.4; + tmp_size.x = panel_size.x * (1 - 0.75); + tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale; + tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2; + drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL); + } else { + top_speed = 0; + } } - else - top_speed = 0; } - //draw acceleration - if(acceleration) - if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3) - { - vector progressbar_color; - if(acceleration < 0) - progressbar_color = autocvar_hud_progressbar_acceleration_neg_color; - else - progressbar_color = autocvar_hud_progressbar_acceleration_color; + // draw acceleration + if (acceleration) { + if (autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3) { + vector progressbar_color; + if (acceleration < 0) { + progressbar_color = autocvar_hud_progressbar_acceleration_neg_color; + } else { + progressbar_color = autocvar_hud_progressbar_acceleration_color; + } - f = acceleration/autocvar_hud_panel_physics_acceleration_max; - if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear) - f = (f >= 0 ? sqrt(f) : -sqrt(-f)); + f = acceleration / autocvar_hud_panel_physics_acceleration_max; + if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear) { + f = (f >= 0 ? sqrt(f) : -sqrt(-f)); + } - if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds - { - tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY; + if (acceleration_progressbar_scale) { // allow progressbar to go out of panel bounds + tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY; - if (acceleration_baralign == 1) - tmp_offset.x = panel_size.x - tmp_size.x; - else if (acceleration_baralign == 2 || acceleration_baralign == 3) - tmp_offset.x = (panel_size.x - tmp_size.x) / 2; - else - tmp_offset.x = 0; - tmp_offset.y = 0; - } - else - { - tmp_size = panel_size; - tmp_offset = '0 0 0'; - } + if (acceleration_baralign == 1) { + tmp_offset.x = panel_size.x - tmp_size.x; + } else if (acceleration_baralign == 2 || acceleration_baralign == 3) { + tmp_offset.x = (panel_size.x - tmp_size.x) / 2; + } else { + tmp_offset.x = 0; + } + tmp_offset.y = 0; + } else { + tmp_size = panel_size; + tmp_offset = '0 0 0'; + } - HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset + tmp_offset, tmp_size, "accelbar", f, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset + tmp_offset, tmp_size, "accelbar", f, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } } - if(autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3) - { + if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3) { tmp_size.x = panel_size.x; tmp_size.y = panel_size.y * text_scale; tmp_offset.x = 0; diff --git a/qcsrc/client/hud/panel/powerups.qc b/qcsrc/client/hud/panel/powerups.qc index dd574cf9b..d79e1bf5f 100644 --- a/qcsrc/client/hud/panel/powerups.qc +++ b/qcsrc/client/hud/panel/powerups.qc @@ -20,21 +20,25 @@ int powerupItemsCount; void resetPowerupItems() { entity item; - for(item = powerupItems; item; item = item.chain) + for (item = powerupItems; item; item = item.chain) { item.count = 0; + } powerupItemsCount = 0; } void addPowerupItem(string name, string icon, vector color, float currentTime, float lifeTime) { - if(!powerupItems) + if (!powerupItems) { powerupItems = spawn(); + } entity item; - for(item = powerupItems; item.count; item = item.chain) - if(!item.chain) + for (item = powerupItems; item.count; item = item.chain) { + if (!item.chain) { item.chain = spawn(); + } + } item.message = name; item.netname = icon; @@ -47,17 +51,23 @@ void addPowerupItem(string name, string icon, vector color, float currentTime, f int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical) { - TC(int, align); TC(int, column); TC(int, row); TC(int, columns); TC(int, rows); TC(bool, isVertical); - if(align < 2) + TC(int, align); + TC(int, column); + TC(int, row); + TC(int, columns); + TC(int, rows); + TC(bool, isVertical); + if (align < 2) { return align; + } bool isTop = isVertical && rows > 1 && row == 0; - bool isBottom = isVertical && rows > 1 && row == rows-1; + bool isBottom = isVertical && rows > 1 && row == rows - 1; bool isLeft = !isVertical && columns > 1 && column == 0; - bool isRight = !isVertical && columns > 1 && column == columns-1; + bool isRight = !isVertical && columns > 1 && column == columns - 1; - if(isTop || isLeft) return (align == 2) ? 1 : 0; - if(isBottom || isRight) return (align == 2) ? 0 : 1; + if (isTop || isLeft) { return (align == 2) ? 1 : 0; } + if (isBottom || isRight) { return (align == 2) ? 0 : 1; } return 2; } @@ -69,27 +79,28 @@ void HUD_Powerups() float strengthTime, shieldTime, superTime; // Initialize items - if(!autocvar__hud_configure) - { - if((!autocvar_hud_panel_powerups) || (spectatee_status == -1)) + if (!autocvar__hud_configure) { + if ((!autocvar_hud_panel_powerups) || (spectatee_status == -1)) { return; - if(STAT(HEALTH) <= 0 && autocvar_hud_panel_powerups_hide_ondeath) + } + if (STAT(HEALTH) <= 0 && autocvar_hud_panel_powerups_hide_ondeath) { return; - //if(!(allItems & (ITEM_Strength.m_itemid | ITEM_Shield.m_itemid | IT_SUPERWEAPON)) && !allBuffs) return; + } + // if(!(allItems & (ITEM_Strength.m_itemid | ITEM_Shield.m_itemid | IT_SUPERWEAPON)) && !allBuffs) return; strengthTime = bound(0, STAT(STRENGTH_FINISHED) - time, 99); shieldTime = bound(0, STAT(INVINCIBLE_FINISHED) - time, 99); superTime = bound(0, STAT(SUPERWEAPONS_FINISHED) - time, 99); - if(allItems & IT_UNLIMITED_SUPERWEAPONS) + if (allItems & IT_UNLIMITED_SUPERWEAPONS) { superTime = 99; + } // Prevent stuff to show up on mismatch that will be fixed next frame - if(!(allItems & IT_SUPERWEAPON)) + if (!(allItems & IT_SUPERWEAPON)) { superTime = 0; - } - else - { + } + } else { strengthTime = 15; shieldTime = 27; superTime = 13; @@ -99,25 +110,30 @@ void HUD_Powerups() // Add items to linked list resetPowerupItems(); - if(strengthTime) + if (strengthTime) { addPowerupItem("Strength", "strength", autocvar_hud_progressbar_strength_color, strengthTime, 30); - if(shieldTime) + } + if (shieldTime) { addPowerupItem("Shield", "shield", autocvar_hud_progressbar_shield_color, shieldTime, 30); - if(superTime) + } + if (superTime) { addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30); + } MUTATOR_CALLHOOK(HUD_Powerups_add); - if(!powerupItemsCount) + if (!powerupItemsCount) { return; + } // Draw panel background HUD_Panel_LoadCvars(); - if (autocvar_hud_panel_powerups_dynamichud) + if (autocvar_hud_panel_powerups_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); // Set drawing area @@ -125,8 +141,7 @@ void HUD_Powerups() vector size = panel_size; bool isVertical = size.y > size.x; - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; size -= '2 2 0' * panel_bg_padding; } @@ -138,31 +153,24 @@ void HUD_Powerups() int rows = 0, r; int i = 1; - do - { + do { c = floor(powerupItemsCount / i); r = ceil(powerupItemsCount / c); - a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r); + a = isVertical ? (size.y / r) / (size.x / c) : (size.x / c) / (size.y / r); - if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect)) - { + if (i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect)) { aspect = a; columns = c; rows = r; } - } - while(++i <= powerupItemsCount); + } while (++i <= powerupItemsCount); // Prevent single items from getting too wide - if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT) - { - if(isVertical) - { + if (powerupItemsCount == 1 && aspect > DESIRED_ASPECT) { + if (isVertical) { size.y *= 0.5; pos.y += size.y * 0.5; - } - else - { + } else { size.x *= 0.5; pos.x += size.x * 0.5; } @@ -179,43 +187,37 @@ void HUD_Powerups() int row = 0; draw_beginBoldFont(); - for(entity item = powerupItems; item.count; item = item.chain) - { + for (entity item = powerupItems; item.count; item = item.chain) { itemPos = vec2(pos.x + column * itemSize.x, pos.y + row * itemSize.y); // Draw progressbar - if(autocvar_hud_panel_powerups_progressbar) - { + if (autocvar_hud_panel_powerups_progressbar) { align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical); HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } // Draw icon and text - if(autocvar_hud_panel_powerups_text) - { + if (autocvar_hud_panel_powerups_text) { align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical); fullSeconds = ceil(item.count); textColor = '0.6 0.6 0.6' + (item.colormod * 0.4); - if(item.count > 1) + if (item.count > 1) { DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha); - if(item.count <= 5) + } + if (item.count <= 5) { DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1)); + } } // Determine next section - if(isVertical) - { - if(++column >= columns) - { + if (isVertical) { + if (++column >= columns) { column = 0; ++row; } - } - else - { - if(++row >= rows) - { + } else { + if (++row >= rows) { row = 0; ++column; } diff --git a/qcsrc/client/hud/panel/pressedkeys.qc b/qcsrc/client/hud/panel/pressedkeys.qc index b4da1dd7d..23cee51f6 100644 --- a/qcsrc/client/hud/panel/pressedkeys.qc +++ b/qcsrc/client/hud/panel/pressedkeys.qc @@ -8,10 +8,9 @@ void HUD_PressedKeys() { - if(!autocvar__hud_configure) - { - if(!autocvar_hud_panel_pressedkeys) return; - if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return; + if (!autocvar__hud_configure) { + if (!autocvar_hud_panel_pressedkeys) { return; } + if (spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) { return; } } HUD_Panel_LoadCvars(); @@ -19,32 +18,28 @@ void HUD_PressedKeys() pos = panel_pos; mySize = panel_size; - if (autocvar_hud_panel_pressedkeys_dynamichud) + if (autocvar_hud_panel_pressedkeys_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } // force custom aspect float aspect = autocvar_hud_panel_pressedkeys_aspect; - if(aspect) - { + if (aspect) { vector newSize = '0 0 0'; - if(mySize.x/mySize.y > aspect) - { + if (mySize.x / mySize.y > aspect) { newSize.x = aspect * mySize.y; newSize.y = mySize.y; pos.x = pos.x + (mySize.x - newSize.x) / 2; - } - else - { - newSize.y = 1/aspect * mySize.x; + } else { + newSize.y = 1 / aspect * mySize.x; newSize.x = mySize.x; pos.y = pos.y + (mySize.y - newSize.y) / 2; @@ -55,8 +50,7 @@ void HUD_PressedKeys() vector keysize = vec2(mySize.x / 3, mySize.y / (3 - !autocvar_hud_panel_pressedkeys_attack)); int pressedkeys = STAT(PRESSED_KEYS); - if(autocvar_hud_panel_pressedkeys_attack) - { + if (autocvar_hud_panel_pressedkeys_attack) { drawpic_aspect_skin(pos + eX * keysize.x * 0.5, ((pressedkeys & KEY_ATCK) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); drawpic_aspect_skin(pos + eX * keysize.x * 1.5, ((pressedkeys & KEY_ATCK2) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); pos.y += keysize.y; diff --git a/qcsrc/client/hud/panel/timer.qc b/qcsrc/client/hud/panel/timer.qc index 0dcbb70db..d9fa90669 100644 --- a/qcsrc/client/hud/panel/timer.qc +++ b/qcsrc/client/hud/panel/timer.qc @@ -8,9 +8,8 @@ void HUD_Timer() { - if(!autocvar__hud_configure) - { - if(!autocvar_hud_panel_timer) return; + if (!autocvar__hud_configure) { + if (!autocvar_hud_panel_timer) { return; } } HUD_Panel_LoadCvars(); @@ -21,13 +20,13 @@ void HUD_Timer() pos = panel_pos; mySize = panel_size; - if (autocvar_hud_panel_timer_dynamichud) + if (autocvar_hud_panel_timer_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } @@ -43,36 +42,38 @@ void HUD_Timer() minutesLeft = floor(timeleft / 60); float warmup_timeleft = 0; - if(warmup_stage) - { + if (warmup_stage) { float warmup_timelimit = STAT(WARMUP_TIMELIMIT); - if(warmup_timelimit > 0) + if (warmup_timelimit > 0) { warmup_timeleft = max(0, warmup_timelimit - time); - else if(warmup_timelimit == 0) + } else if (warmup_timelimit == 0) { warmup_timeleft = timeleft; + } warmup_timeleft = ceil(warmup_timeleft); } vector timer_color; - if(intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0) - timer_color = '1 1 1'; //white - else if(minutesLeft >= 1) - timer_color = '1 1 0'; //yellow - else - timer_color = '1 0 0'; //red - + if (intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0) { + timer_color = '1 1 1'; // white + } else if (minutesLeft >= 1) { + timer_color = '1 1 0'; // yellow + } else { + timer_color = '1 0 0'; // red + } if (intermission_time) { timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME)))); } else if (autocvar_hud_panel_timer_increment || (!warmup_stage && timelimit == 0) || (warmup_stage && warmup_timeleft <= 0)) { - if (time < STAT(GAMESTARTTIME)) - timer = seconds_tostring(0); //while restart is still active, show 00:00 - else + if (time < STAT(GAMESTARTTIME)) { + timer = seconds_tostring(0); // while restart is still active, show 00:00 + } else { timer = seconds_tostring(floor(time - STAT(GAMESTARTTIME))); + } } else { - if(warmup_stage) + if (warmup_stage) { timer = seconds_tostring(warmup_timeleft); - else + } else { timer = seconds_tostring(timeleft); + } } drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL); diff --git a/qcsrc/client/hud/panel/vote.qc b/qcsrc/client/hud/panel/vote.qc index 15e18e8f4..90161b9a1 100644 --- a/qcsrc/client/hud/panel/vote.qc +++ b/qcsrc/client/hud/panel/vote.qc @@ -9,42 +9,40 @@ void HUD_Vote() { - if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS))) - { + if (autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS))) { // this dialog gets overriden by the uid2name menu dialog, if it exists // TODO remove this client side uid2name dialog in the next release - if(!autocvar__menu_alpha) + if (!autocvar__menu_alpha) { uid2name_dialog = 0; + } - if (!uid2name_dialog) + if (!uid2name_dialog) { localcmd("menu_cmd directmenu Uid2Name\n"); + } vote_active = 1; - if (autocvar__hud_configure) - { + if (autocvar__hud_configure) { vote_yescount = 0; vote_nocount = 0; LOG_INFO(_("^1You must answer before entering hud configure mode")); cvar_set("_hud_configure", "0"); } - if(vote_called_vote) + if (vote_called_vote) { strunzone(vote_called_vote); + } vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats")); uid2name_dialog = 1; } - if(!autocvar__hud_configure) - { - if(!autocvar_hud_panel_vote) return; + if (!autocvar__hud_configure) { + if (!autocvar_hud_panel_vote) { return; } /* if(cvar("hud_panel_vote_test")) { - if(vote_called_vote) strunzone(vote_called_vote); vote_called_vote = strzone("^1test the vote panel"); - vote_active = true; vote_yescount = 3; vote_nocount = 2; vote_needed = 4; + if(vote_called_vote) strunzone(vote_called_vote); vote_called_vote = strzone("^1test the vote panel"); + vote_active = true; vote_yescount = 3; vote_nocount = 2; vote_needed = 4; } else vote_active = false; */ - } - else - { + } else { vote_yescount = 3; vote_nocount = 2; vote_needed = 4; @@ -52,31 +50,33 @@ void HUD_Vote() string s; float a; - if(vote_active != vote_prev) { + if (vote_active != vote_prev) { vote_change = time; vote_prev = vote_active; } - if(vote_active || autocvar__hud_configure) + if (vote_active || autocvar__hud_configure) { vote_alpha = bound(0, (time - vote_change) * 2, 1); - else + } else { vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1); + } a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1); - if(a <= 0) + if (a <= 0) { return; - //panel_fade_alpha *= a; + } + // panel_fade_alpha *= a; // nothing can hide this panel, not even the menu float hud_fade_alpha_save = hud_fade_alpha; - if(uid2name_dialog && autocvar__menu_alpha) + if (uid2name_dialog && autocvar__menu_alpha) { hud_fade_alpha = 0; - else + } else { hud_fade_alpha = a; + } HUD_Panel_LoadCvars(); hud_fade_alpha = hud_fade_alpha_save; - if(uid2name_dialog) - { + if (uid2name_dialog) { panel_pos = vec2(0.3 * vid_conwidth, 0.1 * vid_conheight); panel_size = vec2(0.4 * vid_conwidth, 0.3 * vid_conheight); } @@ -85,30 +85,27 @@ void HUD_Vote() pos = panel_pos; mySize = panel_size; - if (autocvar_hud_panel_vote_dynamichud) + if (autocvar_hud_panel_vote_dynamichud) { HUD_Scale_Enable(); - else + } else { HUD_Scale_Disable(); + } HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } // always force 3:1 aspect vector newSize = '0 0 0'; - if(mySize.x/mySize.y > 3) - { + if (mySize.x / mySize.y > 3) { newSize.x = 3 * mySize.y; newSize.y = mySize.y; pos.x = pos.x + (mySize.x - newSize.x) / 2; - } - else - { - newSize.y = 1/3 * mySize.x; + } else { + newSize.y = 1 / 3 * mySize.x; newSize.x = mySize.x; pos.y = pos.y + (mySize.y - newSize.y) / 2; @@ -116,45 +113,44 @@ void HUD_Vote() mySize = newSize; s = _("A vote has been called for:"); - if(uid2name_dialog) + if (uid2name_dialog) { s = _("Allow servers to store and display your name?"); - drawstring_aspect(pos, s, vec2(mySize.x, (2/8) * mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); - s = textShortenToWidth(ColorTranslateRGB(vote_called_vote), mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors); - if(autocvar__hud_configure) + } + drawstring_aspect(pos, s, vec2(mySize.x, (2 / 8) * mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + s = textShortenToWidth(ColorTranslateRGB(vote_called_vote), mySize.x, '1 1 0' * mySize.y * (1 / 8), stringwidth_colors); + if (autocvar__hud_configure) { s = _("^1Configure the HUD"); - drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, vec2(mySize.x, (1.75/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL); + } + drawcolorcodedstring_aspect(pos + eY * (2 / 8) * mySize.y, s, vec2(mySize.x, (1.75 / 8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL); // print the yes/no counts s = sprintf("^2%s ^7(%d)", getcommandkey_forcename(_("Yes"), "vyes"), vote_yescount); - drawcolorcodedstring_aspect(pos + eY * (4/8) * mySize.y, s, vec2(0.5 * mySize.x, (1.5/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL); + drawcolorcodedstring_aspect(pos + eY * (4 / 8) * mySize.y, s, vec2(0.5 * mySize.x, (1.5 / 8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL); s = sprintf("^1%s ^7(%d)", getcommandkey_forcename(_("No"), "vno"), vote_nocount); - drawcolorcodedstring_aspect(pos + vec2(0.5 * mySize.x, (4/8) * mySize.y), s, vec2(0.5 * mySize.x, (1.5/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL); + drawcolorcodedstring_aspect(pos + vec2(0.5 * mySize.x, (4 / 8) * mySize.y), s, vec2(0.5 * mySize.x, (1.5 / 8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL); - pos.y += (5/8) * mySize.y; - vector tmp_size = vec2(mySize.x, (3/8) * mySize.y); + pos.y += (5 / 8) * mySize.y; + vector tmp_size = vec2(mySize.x, (3 / 8) * mySize.y); // draw the progress bar backgrounds drawpic_skin(pos, "voteprogress_back", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); // draw the highlights - if(vote_highlighted == 1) { + if (vote_highlighted == 1) { drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y); drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); - } - else if(vote_highlighted == -1) { + } else if (vote_highlighted == -1) { drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y); drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); } // draw the progress bars - if(vote_yescount && vote_needed) - { - drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y); + if (vote_yescount && vote_needed) { + drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount / vote_needed), mySize.y); drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); } - if(vote_nocount && vote_needed) - { - drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y); + if (vote_nocount && vote_needed) { + drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount / vote_needed), pos.y, mySize.x * 0.5, mySize.y); drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); } diff --git a/qcsrc/client/main.qh b/qcsrc/client/main.qh index a2f4d18bb..39cd86361 100644 --- a/qcsrc/client/main.qh +++ b/qcsrc/client/main.qh @@ -36,18 +36,30 @@ entity teamslots[17]; // 17 teams (including "spectator team") .void(entity) draw; IntrusiveList g_drawables; -STATIC_INIT(g_drawables) { g_drawables = IL_NEW(); } +STATIC_INIT(g_drawables) +{ + g_drawables = IL_NEW(); +} .void(entity) draw2d; IntrusiveList g_drawables_2d; -STATIC_INIT(g_drawables_2d) { g_drawables_2d = IL_NEW(); } +STATIC_INIT(g_drawables_2d) +{ + g_drawables_2d = IL_NEW(); +} .void(entity) entremove; float drawframetime; vector view_origin, view_forward, view_right, view_up; IntrusiveList g_radarlinks; -STATIC_INIT(g_radarlinks) { g_radarlinks = IL_NEW(); } +STATIC_INIT(g_radarlinks) +{ + g_radarlinks = IL_NEW(); +} IntrusiveList g_radaricons; -STATIC_INIT(g_radaricons) { g_radaricons = IL_NEW(); } +STATIC_INIT(g_radaricons) +{ + g_radaricons = IL_NEW(); +} bool button_zoom; bool spectatorbutton_zoom; @@ -74,7 +86,7 @@ float current_zoomfraction; float cs_project_is_b0rked; float vid_width, vid_height, vid_pixelheight; -float camera_active; // Demo camera is active if set to true +float camera_active; // Demo camera is active if set to true float chase_active_backup; float camera_roll; vector camera_direction; @@ -88,7 +100,7 @@ const float ALPHA_MIN_VISIBLE = 0.003; float armorblockpercent; float damagepush_speedfactor; -//hooks +// hooks int calledhooks; const int HOOK_START = 1; const int HOOK_END = 2; diff --git a/qcsrc/client/mapvoting.qc b/qcsrc/client/mapvoting.qc index 87b6d585b..dcca466c6 100644 --- a/qcsrc/client/mapvoting.qc +++ b/qcsrc/client/mapvoting.qc @@ -43,20 +43,20 @@ int n_ssdirs; string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, vector fontsize) { - TC(int, id); + TC(int, id); string pre, post; - pre = sprintf("%d. ", id+1); - if(mv_detail) - { - if(_count == 1) + pre = sprintf("%d. ", id + 1); + if (mv_detail) { + if (_count == 1) { post = _(" (1 vote)"); - else if(_count >= 0 && (mv_flags[id] & GTV_AVAILABLE)) + } else if (_count >= 0 && (mv_flags[id] & GTV_AVAILABLE)) { post = sprintf(_(" (%d votes)"), _count); - else + } else { post = ""; - } - else + } + } else { post = ""; + } maxwidth -= stringwidth(pre, false, fontsize) + stringwidth(post, false, fontsize); map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors); return strcat(pre, map, post); @@ -64,28 +64,31 @@ string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, v vector MapVote_RGB(int id) { - TC(int, id); - if(!(mv_flags[id] & GTV_AVAILABLE)) + TC(int, id); + if (!(mv_flags[id] & GTV_AVAILABLE)) { return '1 1 1'; - if(id == mv_ownvote) + } + if (id == mv_ownvote) { return '0 1 0'; - else if (id == mv_selection) + } else if (id == mv_selection) { return '1 1 0'; - else + } else { return '1 1 1'; + } } void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string gtype, string pic, float _count, int id) { - TC(int, id); + TC(int, id); // Find the correct alpha float alpha; - if(!(mv_flags_start[id] & GTV_AVAILABLE)) - alpha = 0.2; // The gametype isn't supported by the map - else if ( !(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha) + if (!(mv_flags_start[id] & GTV_AVAILABLE)) { + alpha = 0.2; // The gametype isn't supported by the map + } else if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha) { alpha = mv_top2_alpha; // Fade away if not one of the top 2 choice - else - alpha = 1; // Normal, full alpha + } else { + alpha = 1; // Normal, full alpha + } alpha *= panel_fg_alpha; // Bounding box details @@ -102,15 +105,13 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g rect_size.y = maxh + rect_margin; // Highlight selected item - if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE)) - { + if (id == mv_selection && (mv_flags[id] & GTV_AVAILABLE)) { drawfill(rect_pos, rect_size, '1 1 1', 0.1 * panel_fg_alpha, DRAWFLAG_NORMAL); } // Highlight current vote vector rgb = MapVote_RGB(id); - if(id == mv_ownvote) - { + if (id == mv_ownvote) { drawfill(rect_pos, rect_size, rgb, 0.1 * alpha, DRAWFLAG_NORMAL); drawborderlines(autocvar_hud_panel_mapvote_highlight_border, rect_pos, rect_size, rgb, alpha, DRAWFLAG_NORMAL); } @@ -123,8 +124,9 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g // Evaluate the image size vector image_size = '1 1 0' * gtv_text_size.x * 3; - if ( maxh < image_size.y ) + if (maxh < image_size.y) { image_size = '1 1 0' * maxh; + } image_size *= 0.8; float desc_padding = gtv_text_size.x * 0.6; pos.x += image_size.x + desc_padding; @@ -139,20 +141,16 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g entity last = title; entity next = NULL; float nlines = 0; - if( thelabel != "") - { - float i,n = tokenizebyseparator(thelabel, "\n"); - for(i = 0; i < n && maxh > (nlines+1)*gtv_text_size_small.y; ++i) - { + if (thelabel != "") { + float i, n = tokenizebyseparator(thelabel, "\n"); + for (i = 0; i < n && maxh > (nlines + 1) * gtv_text_size_small.y; ++i) { getWrappedLine_remaining = argv(i); - while(getWrappedLine_remaining && maxh > (nlines+1)*gtv_text_size_small.y) - { + while (getWrappedLine_remaining && maxh > (nlines + 1) * gtv_text_size_small.y) { ts = getWrappedLine(tsize, gtv_text_size_small, stringwidth_colors); - if (ts != "") - { + if (ts != "") { next = spawn(); next.message = ts; - next.origin = pos-offset; + next.origin = pos - offset; last.chain = next; last = next; pos.y += gtv_text_size_small.y; @@ -163,21 +161,22 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g } // Center the contents in the bounding box - maxh -= max(nlines*gtv_text_size_small.y,image_size.y); - if ( maxh > 0 ) - offset.y += maxh/2; + maxh -= max(nlines * gtv_text_size_small.y, image_size.y); + if (maxh > 0) { + offset.y += maxh / 2; + } // Draw the title drawstring(offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL); // Draw the icon - if(pic != "") - drawpic('0 1 0'*title_gap+'0.5 0 0'*desc_padding+offset, pic, image_size, '1 1 1', alpha, DRAWFLAG_NORMAL); + if (pic != "") { + drawpic('0 1 0' * title_gap + '0.5 0 0' * desc_padding + offset, pic, image_size, '1 1 1', alpha, DRAWFLAG_NORMAL); + } // Draw the description - for ( last = title.chain; last ; ) - { - drawstring(last.origin+offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL); + for (last = title.chain; last; ) { + drawstring(last.origin + offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL); next = last; last = last.chain; delete(next); @@ -189,7 +188,7 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float _count, int id) { - TC(int, id); + TC(int, id); vector img_size = '0 0 0'; string label; float text_size; @@ -206,7 +205,7 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin rect_size.x = tsize + rect_margin; rect_size.y = isize + rect_margin; - float img_ar = 4/3; + float img_ar = 4 / 3; img_size.x = min(tsize, isize * img_ar); img_size.y = img_size.x / img_ar; img_size.y -= hud_fontsize.y; @@ -229,42 +228,41 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin pos.x += (tsize - img_size.x) / 2; float theAlpha; - if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha) + if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha) { theAlpha = mv_top2_alpha; - else + } else { theAlpha = 1; + } theAlpha *= panel_fg_alpha; // Highlight selected item - if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE)) + if (id == mv_selection && (mv_flags[id] & GTV_AVAILABLE)) { drawfill(rect_pos, rect_size, '1 1 1', 0.1 * panel_fg_alpha, DRAWFLAG_NORMAL); + } // Highlight current vote vector rgb = MapVote_RGB(id); - if(id == mv_ownvote) - { + if (id == mv_ownvote) { drawfill(rect_pos, rect_size, rgb, 0.1 * theAlpha, DRAWFLAG_NORMAL); drawborderlines(autocvar_hud_panel_mapvote_highlight_border, rect_pos, rect_size, rgb, theAlpha, DRAWFLAG_NORMAL); } drawstring(text_pos, label, hud_fontsize, rgb, theAlpha, DRAWFLAG_NORMAL); - if(pic == "") - { + if (pic == "") { drawfill(pos, img_size, '.5 .5 .5', .7 * theAlpha, DRAWFLAG_NORMAL); - } - else - { - if(drawgetimagesize(pic) == '0 0 0') + } else { + if (drawgetimagesize(pic) == '0 0 0') { drawpic(pos, draw_UseSkinFor("nopreview_map"), img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL); - else + } else { drawpic(pos, pic, img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL); + } } } void MapVote_DrawAbstain(vector pos, float isize, float tsize, float _count, int id) { - TC(int, id); + TC(int, id); vector rgb; float text_size; string label; @@ -275,48 +273,49 @@ void MapVote_DrawAbstain(vector pos, float isize, float tsize, float _count, int text_size = stringwidth(label, false, hud_fontsize); - pos.x -= text_size*0.5; + pos.x -= text_size * 0.5; drawstring(pos, label, hud_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL); } vector MapVote_GridVec(vector gridspec, int i, int m) { - TC(int, i); TC(int, m); + TC(int, i); + TC(int, m); int r = i % m; - return - '1 0 0' * (gridspec.x * r) - + - '0 1 0' * (gridspec.y * (i - r) / m); + return '1 0 0' * (gridspec.x * r) + + + '0 1 0' * (gridspec.y * (i - r) / m); } float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns) { - float c, r; mv_mouse_selection = -1; - for (r = 0; r < rows; ++r) - for (c = 0; c < columns; ++c) - { - if (mousepos.x >= topleft.x + cellsize.x * c && - mousepos.x <= topleft.x + cellsize.x * (c + 1) && - mousepos.y >= topleft.y + cellsize.y * r && - mousepos.y <= topleft.y + cellsize.y * (r + 1)) - { + for (r = 0; r < rows; ++r) { + for (c = 0; c < columns; ++c) { + if (mousepos.x >= topleft.x + cellsize.x * c + && mousepos.x <= topleft.x + cellsize.x * (c + 1) + && mousepos.y >= topleft.y + cellsize.y * r + && mousepos.y <= topleft.y + cellsize.y * (r + 1)) { mv_mouse_selection = r * columns + c; break; } } + } - if (mv_mouse_selection >= mv_num_maps) + if (mv_mouse_selection >= mv_num_maps) { mv_mouse_selection = -1; + } - if (mv_abstain && mv_mouse_selection < 0) + if (mv_abstain && mv_mouse_selection < 0) { mv_mouse_selection = mv_num_maps; + } - if ( mv_selection_keyboard ) + if (mv_selection_keyboard) { return mv_selection; + } return mv_mouse_selection; } @@ -332,30 +331,32 @@ void MapVote_Draw() float rows; vector dist = '0 0 0'; - //if(intermission != 2) return; - if(!mv_active) + // if(intermission != 2) return; + if (!mv_active) { return; + } HUD_Panel_LoadCvars(); - if (!autocvar_hud_cursormode) - { + if (!autocvar_hud_cursormode) { vector mpos = mousepos; update_mousepos(); - if (mpos.x != mousepos.x || mpos.y != mousepos.y) + if (mpos.x != mousepos.x || mpos.y != mousepos.y) { mv_selection_keyboard = 0; + } } - center = (vid_conwidth - 1)/2; + center = (vid_conwidth - 1) / 2; xmin = vid_conwidth * 0.08; xmax = vid_conwidth - xmin; ymin = 20; ymax = vid_conheight - ymin; - if(chat_posy + chat_sizey / 2 < vid_conheight / 2) + if (chat_posy + chat_sizey / 2 < vid_conheight / 2) { ymin += chat_sizey; - else + } else { ymax -= chat_sizey; + } hud_fontsize = HUD_GetFontsize("hud_fontsize"); @@ -370,8 +371,7 @@ void MapVote_Draw() drawstring(pos, map, hud_fontsize * 2, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); pos.y += hud_fontsize.y * 2; - if( mapvote_chosenmap != "" ) - { + if (mapvote_chosenmap != "") { pos.y += hud_fontsize.y * 0.25; pos.x = center - stringwidth(mapvote_chosenmap, false, hud_fontsize * 1.5) * 0.5; drawstring(pos, mapvote_chosenmap, hud_fontsize * 1.5, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); @@ -393,14 +393,13 @@ void MapVote_Draw() pos.x = xmin; ymin = pos.y; float abstain_spacing = panel_bg_border + hud_fontsize.y; - if(mv_abstain) - { + if (mv_abstain) { mv_num_maps -= 1; ymax -= abstain_spacing; } // higher than the image itself ratio for mapvote items to reserve space for long map names - int item_aspect = (gametypevote) ? 3/1 : 5/3; + int item_aspect = (gametypevote) ? 3 / 1 : 5 / 3; vector table_size = HUD_GetTableSize_BestItemAR(mv_num_maps, vec2(xmax - xmin, ymax - ymin), item_aspect); mv_columns = table_size.x; rows = table_size.y; @@ -410,23 +409,22 @@ void MapVote_Draw() // reduce size of too wide items tmp = vid_conwidth / 3; // max width - if(dist.x > tmp) - { + if (dist.x > tmp) { dist.x = tmp; dist.y = min(dist.y, dist.x / item_aspect); } tmp = vid_conheight / 3; // max height - if(dist.y > tmp) - { + if (dist.y > tmp) { dist.y = tmp; dist.x = min(dist.x, dist.y * item_aspect); } // reduce size to fix aspect ratio - if(dist.x / dist.y > item_aspect) + if (dist.x / dist.y > item_aspect) { dist.x = dist.y * item_aspect; - else + } else { dist.y = dist.x / item_aspect; + } // adjust table pos and size according to the new size float offset; @@ -443,8 +441,7 @@ void MapVote_Draw() panel_size.y = ymax - ymin; HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { // FIXME item AR gets slightly changed here... // it's rather hard to avoid it at this point dist.x -= 2 * panel_bg_padding / mv_columns; @@ -457,33 +454,36 @@ void MapVote_Draw() mv_selection = MapVote_Selection(pos, dist, rows, mv_columns); - if (mv_top2_time) - mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time)*(time - mv_top2_time)); + if (mv_top2_time) { + mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time) * (time - mv_top2_time)); + } - void (vector, float, float, string, string, float, float) DrawItem; + void(vector, float, float, string, string, float, float) DrawItem; - if(gametypevote) + if (gametypevote) { DrawItem = GameTypeVote_DrawGameTypeItem; - else + } else { DrawItem = MapVote_DrawMapItem; + } - for(i = 0; i < mv_num_maps; ++i) - { + for (i = 0; i < mv_num_maps; ++i) { tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up map = mv_maps[i]; - if(mv_preview[i]) + if (mv_preview[i]) { DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), dist.y, dist.x, map, mv_pics[i], tmp, i); - else + } else { DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), dist.y, dist.x, map, "", tmp, i); + } } - if(mv_abstain) + if (mv_abstain) { ++mv_num_maps; + } - if(mv_abstain && i < mv_num_maps) { + if (mv_abstain && i < mv_num_maps) { tmp = mv_votes[i]; pos.y = ymax + abstain_spacing; - pos.x = (xmax+xmin)*0.5; + pos.x = (xmax + xmin) * 0.5; MapVote_DrawAbstain(pos, dist.x, xmax - xmin, tmp, i); } @@ -492,27 +492,27 @@ void MapVote_Draw() void Cmd_MapVote_MapDownload(int argc) { - TC(int, argc); + TC(int, argc); entity pak; - if(argc != 2 || !mv_pk3list) - { + if (argc != 2 || !mv_pk3list) { LOG_INFO(_("mv_mapdownload: ^3You're not supposed to use this command on your own!")); return; } int id = stof(argv(1)); - for(pak = mv_pk3list; pak; pak = pak.chain) - if(pak.sv_entnum == id) + for (pak = mv_pk3list; pak; pak = pak.chain) { + if (pak.sv_entnum == id) { break; + } + } - if(!pak || pak.sv_entnum != id) { + if (!pak || pak.sv_entnum != id) { LOG_INFO(_("^1Error:^7 Couldn't find pak index.")); return; } - if(PreviewExists(pak.message)) - { + if (PreviewExists(pak.message)) { mv_preview[id] = true; return; } else { @@ -523,7 +523,7 @@ void Cmd_MapVote_MapDownload(int argc) void MapVote_CheckPK3(string pic, string pk3, int id) { - TC(int, id); + TC(int, id); entity pak; pak = spawn(); pak.netname = pk3; @@ -533,25 +533,22 @@ void MapVote_CheckPK3(string pic, string pk3, int id) pak.chain = mv_pk3list; mv_pk3list = pak; - if(pk3 != "") - { + if (pk3 != "") { localcmd(strcat("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", ftos(id), "\n")); - } - else - { + } else { Cmd_MapVote_MapDownload(tokenize_console(strcat("mv_download ", ftos(id)))); } } void MapVote_CheckPic(string pic, string pk3, int id) { - TC(int, id); + TC(int, id); // never try to retrieve a pic for the "don't care" 'map' - if(mv_abstain && id == mv_num_maps - 1) + if (mv_abstain && id == mv_num_maps - 1) { return; + } - if(PreviewExists(pic)) - { + if (PreviewExists(pic)) { mv_preview[id] = true; return; } @@ -561,34 +558,33 @@ void MapVote_CheckPic(string pic, string pk3, int id) void MapVote_ReadMask() { int i; - if ( mv_num_maps < 24 ) - { + if (mv_num_maps < 24) { int mask; - if(mv_num_maps < 8) + if (mv_num_maps < 8) { mask = ReadByte(); - else if(mv_num_maps < 16) + } else if (mv_num_maps < 16) { mask = ReadShort(); - else + } else { mask = ReadLong(); + } - for(i = 0; i < mv_num_maps; ++i) - { - if (mask & BIT(i)) + for (i = 0; i < mv_num_maps; ++i) { + if (mask & BIT(i)) { mv_flags[i] |= GTV_AVAILABLE; - else + } else { mv_flags[i] &= ~GTV_AVAILABLE; + } } - } - else - { - for(i = 0; i < mv_num_maps; ++i ) + } else { + for (i = 0; i < mv_num_maps; ++i) { mv_flags[i] = ReadByte(); + } } } void MapVote_ReadOption(int i) { - TC(int, i); + TC(int, i); string map = strzone(ReadString()); string pk3 = strzone(ReadString()); int j = bound(0, ReadByte(), n_ssdirs - 1); @@ -605,7 +601,7 @@ void MapVote_ReadOption(int i) void GameTypeVote_ReadOption(int i) { - TC(int, i); + TC(int, i); string gt = strzone(ReadString()); mv_maps[i] = gt; @@ -613,31 +609,26 @@ void GameTypeVote_ReadOption(int i) string basetype = ""; - if ( mv_flags[i] & GTV_CUSTOM ) - { + if (mv_flags[i] & GTV_CUSTOM) { string name = ReadString(); - if ( strlen(name) < 1 ) + if (strlen(name) < 1) { name = gt; + } mv_pk3[i] = strzone(name); mv_desc[i] = strzone(ReadString()); basetype = strzone(ReadString()); - } - else - { + } else { Gametype type = MapInfo_Type_FromString(gt); mv_pk3[i] = strzone(MapInfo_Type_ToText(type)); mv_desc[i] = MapInfo_Type_Description(type); } string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, gt); - if(precache_pic(mv_picpath) == "") - { + if (precache_pic(mv_picpath) == "") { mv_picpath = strcat("gfx/menu/default/gametype_", gt); - if(precache_pic(mv_picpath) == "") - { + if (precache_pic(mv_picpath) == "") { mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, basetype); - if(precache_pic(mv_picpath) == "") - { + if (precache_pic(mv_picpath) == "") { mv_picpath = strcat("gfx/menu/default/gametype_", basetype); } } @@ -650,26 +641,27 @@ void GameTypeVote_ReadOption(int i) void MapVote_Init() { mv_active = 1; - if(autocvar_hud_cursormode) setcursormode(1); - else mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight; + if (autocvar_hud_cursormode) { setcursormode(1); } else { mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight; } mv_selection = -1; mv_selection_keyboard = 0; string s; - for(n_ssdirs = 0; ; ++n_ssdirs) - { + for (n_ssdirs = 0; ; ++n_ssdirs) { s = ReadString(); - if(s == "") + if (s == "") { break; - if(n_ssdirs < NUM_SSDIRS) + } + if (n_ssdirs < NUM_SSDIRS) { ssdirs[n_ssdirs] = s; + } } n_ssdirs = min(n_ssdirs, NUM_SSDIRS); mv_num_maps = min(MAPVOTE_COUNT, ReadByte()); mv_abstain = ReadByte(); - if(mv_abstain) + if (mv_abstain) { mv_abstain = 1; // must be 1 for bool-true, makes stuff easier + } mv_detail = ReadByte(); mv_ownvote = -1; @@ -677,144 +669,160 @@ void MapVote_Init() gametypevote = ReadByte(); - if(gametypevote) - { + if (gametypevote) { mapvote_chosenmap = strzone(ReadString()); - if ( gametypevote == 2 ) + if (gametypevote == 2) { gametypevote = 0; + } - gtv_text_size = hud_fontsize*1.4; - gtv_text_size_small = hud_fontsize*1.1; + gtv_text_size = hud_fontsize * 1.4; + gtv_text_size_small = hud_fontsize * 1.1; } MapVote_ReadMask(); int i; - for(i = 0; i < mv_num_maps; ++i ) + for (i = 0; i < mv_num_maps; ++i) { mv_flags_start[i] = mv_flags[i]; + } // Assume mv_pk3list is NULL, there should only be 1 mapvote per round mv_pk3list = NULL; // I'm still paranoid! - for(i = 0; i < mv_num_maps; ++i) - { + for (i = 0; i < mv_num_maps; ++i) { mv_votes[i] = 0; - if ( gametypevote ) + if (gametypevote) { GameTypeVote_ReadOption(i); - else + } else { MapVote_ReadOption(i); + } } - for(i = 0; i < n_ssdirs; ++i) + for (i = 0; i < n_ssdirs; ++i) { ssdirs[n_ssdirs] = string_null; + } n_ssdirs = 0; } void MapVote_SendChoice(int index) { - TC(int, index); - localcmd(strcat("\nimpulse ", ftos(index+1), "\n")); + TC(int, index); + localcmd(strcat("\nimpulse ", ftos(index + 1), "\n")); } int MapVote_MoveLeft(int pos) { - TC(int, pos); + TC(int, pos); int imp; - if ( pos < 0 ) + if (pos < 0) { imp = mv_num_maps - 1; - else + } else { imp = pos < 1 ? mv_num_maps - 1 : pos - 1; - if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) + } + if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote) { imp = MapVote_MoveLeft(imp); + } return imp; } int MapVote_MoveRight(int pos) { - TC(int, pos); + TC(int, pos); int imp; - if ( pos < 0 ) + if (pos < 0) { imp = 0; - else + } else { imp = pos >= mv_num_maps - 1 ? 0 : pos + 1; - if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) + } + if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote) { imp = MapVote_MoveRight(imp); + } return imp; } int MapVote_MoveUp(int pos) { - TC(int, pos); + TC(int, pos); int imp; - if ( pos < 0 ) + if (pos < 0) { imp = mv_num_maps - 1; - else - { + } else { imp = pos - mv_columns; - if ( imp < 0 ) - { - imp = floor(mv_num_maps/mv_columns)*mv_columns + pos % mv_columns; - if ( imp >= mv_num_maps ) + if (imp < 0) { + imp = floor(mv_num_maps / mv_columns) * mv_columns + pos % mv_columns; + if (imp >= mv_num_maps) { imp -= mv_columns; + } } } - if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) + if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote) { imp = MapVote_MoveUp(imp); + } return imp; } int MapVote_MoveDown(int pos) { - TC(int, pos); + TC(int, pos); int imp; - if ( pos < 0 ) + if (pos < 0) { imp = 0; - else - { + } else { imp = pos + mv_columns; - if ( imp >= mv_num_maps ) + if (imp >= mv_num_maps) { imp = imp % mv_columns; + } } - if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) + if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote) { imp = MapVote_MoveDown(imp); + } return imp; } float MapVote_InputEvent(int bInputType, float nPrimary, float nSecondary) { - TC(int, bInputType); + TC(int, bInputType); float imp; - if (!mv_active) + if (!mv_active) { return false; + } - if(bInputType == 3) - { + if (bInputType == 3) { mousepos.x = nPrimary; mousepos.y = nSecondary; mv_selection_keyboard = 0; return true; } - if (bInputType != 0) + if (bInputType != 0) { return false; + } - if ('0' <= nPrimary && nPrimary <= '9') - { + if ('0' <= nPrimary && nPrimary <= '9') { imp = nPrimary - '0'; - if (imp == 0) imp = 10; + if (imp == 0) { imp = 10; } localcmd(strcat("\nimpulse ", ftos(imp), "\n")); return true; } - switch(nPrimary) - { - case K_KP_1: localcmd("\nimpulse 1\n"); return true; - case K_KP_2: localcmd("\nimpulse 2\n"); return true; - case K_KP_3: localcmd("\nimpulse 3\n"); return true; - case K_KP_4: localcmd("\nimpulse 4\n"); return true; - case K_KP_5: localcmd("\nimpulse 5\n"); return true; - case K_KP_6: localcmd("\nimpulse 6\n"); return true; - case K_KP_7: localcmd("\nimpulse 7\n"); return true; - case K_KP_8: localcmd("\nimpulse 8\n"); return true; - case K_KP_9: localcmd("\nimpulse 9\n"); return true; - case K_KP_0: localcmd("\nimpulse 10\n"); return true; + switch (nPrimary) { + case K_KP_1: localcmd("\nimpulse 1\n"); + return true; + case K_KP_2: localcmd("\nimpulse 2\n"); + return true; + case K_KP_3: localcmd("\nimpulse 3\n"); + return true; + case K_KP_4: localcmd("\nimpulse 4\n"); + return true; + case K_KP_5: localcmd("\nimpulse 5\n"); + return true; + case K_KP_6: localcmd("\nimpulse 6\n"); + return true; + case K_KP_7: localcmd("\nimpulse 7\n"); + return true; + case K_KP_8: localcmd("\nimpulse 8\n"); + return true; + case K_KP_9: localcmd("\nimpulse 9\n"); + return true; + case K_KP_0: localcmd("\nimpulse 10\n"); + return true; case K_RIGHTARROW: mv_selection_keyboard = 1; @@ -835,17 +843,16 @@ float MapVote_InputEvent(int bInputType, float nPrimary, float nSecondary) case K_KP_ENTER: case K_ENTER: case K_SPACE: - if ( mv_selection_keyboard ) + if (mv_selection_keyboard) { MapVote_SendChoice(mv_selection); + } return true; } - if (nPrimary == K_MOUSE1) - { + if (nPrimary == K_MOUSE1) { mv_selection_keyboard = 0; mv_selection = mv_mouse_selection; - if (mv_selection >= 0) - { + if (mv_selection >= 0) { imp = min(mv_selection + 1, mv_num_maps); localcmd(strcat("\nimpulse ", ftos(imp), "\n")); return true; @@ -864,20 +871,19 @@ void MapVote_UpdateMask() void MapVote_UpdateVotes() { int i; - for(i = 0; i < mv_num_maps; ++i) - { - if(mv_flags[i] & GTV_AVAILABLE) - { - if(mv_detail) + for (i = 0; i < mv_num_maps; ++i) { + if (mv_flags[i] & GTV_AVAILABLE) { + if (mv_detail) { mv_votes[i] = ReadByte(); - else + } else { mv_votes[i] = 0; - } - else + } + } else { mv_votes[i] = -1; + } } - mv_ownvote = ReadByte()-1; + mv_ownvote = ReadByte() - 1; } NET_HANDLE(ENT_CLIENT_MAPVOTE, bool isnew) @@ -886,14 +892,17 @@ NET_HANDLE(ENT_CLIENT_MAPVOTE, bool isnew) int sf = ReadByte(); return = true; - if(sf & 1) + if (sf & 1) { MapVote_Init(); + } - if(sf & 2) + if (sf & 2) { MapVote_UpdateMask(); + } - if(sf & 4) + if (sf & 4) { MapVote_UpdateVotes(); + } } NET_HANDLE(TE_CSQC_PICTURE, bool isNew) diff --git a/qcsrc/client/mutators/events.qh b/qcsrc/client/mutators/events.qh index 24d634ce8..b8fd46722 100644 --- a/qcsrc/client/mutators/events.qh +++ b/qcsrc/client/mutators/events.qh @@ -24,9 +24,9 @@ * } */ #define EV_CSQC_ConsoleCommand(i, o) \ - /** command name */ i(string, MUTATOR_ARGV_0_string) \ - /** argc (also, argv() can be used) */ i(int, MUTATOR_ARGV_1_int) \ - /** whole command, use only if you really have to */ i(string, MUTATOR_ARGV_2_string) \ + /** command name */ i(string, MUTATOR_ARGV_0_string) \ + /** argc (also, argv() can be used) */ i(int, MUTATOR_ARGV_1_int) \ + /** whole command, use only if you really have to */ i(string, MUTATOR_ARGV_2_string) \ /**/ MUTATOR_HOOKABLE(CSQC_ConsoleCommand, EV_CSQC_ConsoleCommand); @@ -77,8 +77,8 @@ MUTATOR_HOOKABLE(ClearModelParams, EV_NO_ARGS); /** Called when getting the global parameters for a model */ #define EV_GetModelParams(i, o) \ - /** input */ i(string, MUTATOR_ARGV_0_string) \ - /** command */ i(string, MUTATOR_ARGV_1_string) \ + /** input */ i(string, MUTATOR_ARGV_0_string) \ + /** command */ i(string, MUTATOR_ARGV_1_string) \ /**/ MUTATOR_HOOKABLE(GetModelParams, EV_GetModelParams); @@ -98,7 +98,7 @@ MUTATOR_HOOKABLE(WantEventchase, EV_WantEventchase); MUTATOR_HOOKABLE(CustomizeEventchase, EV_CustomizeEventchase); #define EV_AnnouncerOption(i, o) \ - /** announcer string */ i(string, MUTATOR_ARGV_0_string) \ + /** announcer string */ i(string, MUTATOR_ARGV_0_string) \ /** announcer string */ o(string, MUTATOR_ARGV_0_string) \ /**/ MUTATOR_HOOKABLE(AnnouncerOption, EV_AnnouncerOption); @@ -115,15 +115,15 @@ MUTATOR_HOOKABLE(HUD_Powerups_add, EV_NO_ARGS); /** Return true to not draw any vortex beam */ #define EV_Particles_VortexBeam(i, o) \ - /** beam shot origin */ i(vector, MUTATOR_ARGV_0_vector) \ + /** beam shot origin */ i(vector, MUTATOR_ARGV_0_vector) \ /** beam end position */ i(vector, MUTATOR_ARGV_1_vector) \ /**/ MUTATOR_HOOKABLE(Particles_VortexBeam, EV_Particles_VortexBeam); /** Return true to not draw any impact effect */ #define EV_Weapon_ImpactEffect(i, o) \ - /** weapon */ i(entity, MUTATOR_ARGV_0_entity) \ - /** damage entity */ i(entity, MUTATOR_ARGV_1_entity) \ + /** weapon */ i(entity, MUTATOR_ARGV_0_entity) \ + /** damage entity */ i(entity, MUTATOR_ARGV_1_entity) \ /**/ MUTATOR_HOOKABLE(Weapon_ImpactEffect, EV_Weapon_ImpactEffect); @@ -136,18 +136,18 @@ MUTATOR_HOOKABLE(HUD_Command, EV_HUD_Command); /** Draw the grapple hook, allows changing hook texture and colour */ #define EV_DrawGrapplingHook(i, o) \ - /** hook */ i(entity, MUTATOR_ARGV_0_entity) \ - /** texture */ i(string, MUTATOR_ARGV_1_string) \ - /***/ o(string, MUTATOR_ARGV_1_string) \ - /** colour */ i(vector, MUTATOR_ARGV_2_vector) \ - /***/ o(vector, MUTATOR_ARGV_2_vector) \ - /** team */ i(float, MUTATOR_ARGV_3_float) \ + /** hook */ i(entity, MUTATOR_ARGV_0_entity) \ + /** texture */ i(string, MUTATOR_ARGV_1_string) \ + /***/ o(string, MUTATOR_ARGV_1_string) \ + /** colour */ i(vector, MUTATOR_ARGV_2_vector) \ + /***/ o(vector, MUTATOR_ARGV_2_vector) \ + /** team */ i(float, MUTATOR_ARGV_3_float) \ /**/ MUTATOR_HOOKABLE(DrawGrapplingHook, EV_DrawGrapplingHook); /** Called when an entity is updated (either by SVQC networking or PVS) */ #define EV_Ent_Update(i, o) \ - /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ + /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ /** is new to client */ i(bool, MUTATOR_ARGV_1_bool) \ /**/ MUTATOR_HOOKABLE(Ent_Update, EV_Ent_Update); @@ -160,20 +160,20 @@ MUTATOR_HOOKABLE(DrawScoreboard, EV_NO_ARGS); /** Called when drawing info messages, allows adding new info messages */ #define EV_DrawInfoMessages(i, o) \ - /** pos */ i(vector, MUTATOR_ARGV_0_vector) \ - /** mySize */ i(vector, MUTATOR_ARGV_1_vector) \ + /** pos */ i(vector, MUTATOR_ARGV_0_vector) \ + /** mySize */ i(vector, MUTATOR_ARGV_1_vector) \ /**/ MUTATOR_HOOKABLE(DrawInfoMessages, EV_DrawInfoMessages); /** Called when drawing info messages, allows adding new info messages */ #define EV_HUD_WriteCvars(i, o) \ - /** file */ i(float, MUTATOR_ARGV_0_float) \ + /** file */ i(float, MUTATOR_ARGV_0_float) \ /**/ MUTATOR_HOOKABLE(HUD_WriteCvars, EV_HUD_WriteCvars); /** Called when the view model is being animated (setorigin is called after the hook, so you only need to modify origin here if desired) */ #define EV_DrawViewModel(i, o) \ - /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ + /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ /**/ MUTATOR_HOOKABLE(DrawViewModel, EV_DrawViewModel); @@ -182,15 +182,15 @@ MUTATOR_HOOKABLE(HUD_Contents, EV_NO_ARGS); /** Return true to disable player model/color forcing */ #define EV_ForcePlayermodels_Skip(i, o) \ - /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ - /** is local */ i(bool, MUTATOR_ARGV_1_bool) \ + /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ + /** is local */ i(bool, MUTATOR_ARGV_1_bool) \ /**/ MUTATOR_HOOKABLE(ForcePlayermodels_Skip, EV_ForcePlayermodels_Skip); /** Called when damage info is received on the client, useful for playing explosion effects */ #define EV_DamageInfo(i, o) \ - /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ - /** death type */ i(int, MUTATOR_ARGV_1_int) \ - /** hit origin */ i(vector, MUTATOR_ARGV_2_vector) \ + /** entity id */ i(entity, MUTATOR_ARGV_0_entity) \ + /** death type */ i(int, MUTATOR_ARGV_1_int) \ + /** hit origin */ i(vector, MUTATOR_ARGV_2_vector) \ /**/ MUTATOR_HOOKABLE(DamageInfo, EV_DamageInfo); diff --git a/qcsrc/client/player_skeleton.qc b/qcsrc/client/player_skeleton.qc index 55e54d8ac..cb8fce0e9 100644 --- a/qcsrc/client/player_skeleton.qc +++ b/qcsrc/client/player_skeleton.qc @@ -8,57 +8,61 @@ .float v_angle_save_x; -class(Skeleton) .float skeleton_info_modelindex; -class(Skeleton) .float skeleton_info_skin; +class(Skeleton).float skeleton_info_modelindex; +class(Skeleton).float skeleton_info_skin; const int BONETYPE_LOWER = 0; const int BONETYPE_UPPER = 1; const int MAX_BONES = 128; -class(Skeleton) .float skeleton_bonetype[MAX_BONES]; -class(Skeleton) .float skeleton_numbones; +class(Skeleton).float skeleton_bonetype[MAX_BONES]; +class(Skeleton).float skeleton_numbones; void skeleton_loadinfo(entity e) { int i; - if(e.skeleton_info_modelindex == e.modelindex && e.skeleton_info_skin == e.skin) + if (e.skeleton_info_modelindex == e.modelindex && e.skeleton_info_skin == e.skin) { return; + } e.bone_upperbody = 0; e.bone_weapon = gettagindex(e, "weapon"); - if(!e.bone_weapon) + if (!e.bone_weapon) { e.bone_weapon = gettagindex(e, "tag_weapon"); - if(!e.bone_weapon) + } + if (!e.bone_weapon) { e.bone_weapon = gettagindex(e, "bip01 r hand"); + } MUTATOR_CALLHOOK(Skeleton_CheckBones, e); - for(i = 0; i < MAX_AIM_BONES; ++i) - { + for (i = 0; i < MAX_AIM_BONES; ++i) { e.(bone_aim[i]) = 0; e.(bone_aimweight[i]) = 0; } e.fixbone = 0; - if(get_model_parameters(e.model, e.skin)) - { - if(get_model_parameters_bone_upperbody) + if (get_model_parameters(e.model, e.skin)) { + if (get_model_parameters_bone_upperbody) { e.bone_upperbody = gettagindex(e, get_model_parameters_bone_upperbody); - if(e.bone_upperbody) + } + if (e.bone_upperbody) { e.fixbone = get_model_parameters_fixbone; - if(get_model_parameters_bone_weapon) + } + if (get_model_parameters_bone_weapon) { e.bone_weapon = gettagindex(e, get_model_parameters_bone_weapon); + } MUTATOR_CALLHOOK(Skeleton_CheckModel, e); - for(i = 0; i < MAX_AIM_BONES; ++i) - { - if(get_model_parameters_bone_aim[i]) + for (i = 0; i < MAX_AIM_BONES; ++i) { + if (get_model_parameters_bone_aim[i]) { e.(bone_aim[i]) = gettagindex(e, get_model_parameters_bone_aim[i]); - if(e.bone_aim[i]) + } + if (e.bone_aim[i]) { e.(bone_aimweight[i]) = get_model_parameters_bone_aimweight[i]; + } } - } - else + } else { LOG_TRACE("No model parameters for ", e.model); - //dprint(e.model, " uses ", ftos(e.bone_upperbody), " ", ftos(e.fixbone), "\n"); + } + // dprint(e.model, " uses ", ftos(e.bone_upperbody), " ", ftos(e.fixbone), "\n"); get_model_parameters(string_null, 0); e.skeleton_info_modelindex = e.modelindex; e.skeleton_info_skin = e.skin; - if(e.skeletonindex) - { + if (e.skeletonindex) { skel_delete(e.skeletonindex); e.skeletonindex = 0; } @@ -69,21 +73,22 @@ void skeleton_markbones(entity e) float s = e.skeletonindex; float n = (e.skeleton_numbones = skel_get_numbones(s)); int i; - for(i = 1; i <= n; ++i) - { + for (i = 1; i <= n; ++i) { float t = BONETYPE_LOWER; int p = skel_get_boneparent(s, i); - if(p > 0) - t = e.(skeleton_bonetype[p-1]); - if(i == e.bone_upperbody) + if (p > 0) { + t = e.(skeleton_bonetype[p - 1]); + } + if (i == e.bone_upperbody) { t = BONETYPE_UPPER; - e.(skeleton_bonetype[i-1]) = t; + } + e.(skeleton_bonetype[i - 1]) = t; } } void skel_set_boneabs(float s, int bone, vector absorg) { - TC(int, bone); + TC(int, bone); vector absang = fixedvectoangles2(v_forward, v_up); vector parentorg = skel_get_boneabs(s, skel_get_boneparent(s, bone)); @@ -104,8 +109,7 @@ void skel_set_boneabs(float s, int bone, vector absorg) void free_skeleton_from_frames(entity e) { - if(e.skeletonindex) - { + if (e.skeletonindex) { skel_delete(e.skeletonindex); e.skeletonindex = 0; } @@ -113,24 +117,23 @@ void free_skeleton_from_frames(entity e) void skeleton_from_frames(entity e, bool is_dead) { - TC(bool, is_dead); + TC(bool, is_dead); float m = e.modelindex; - if(!e.skeletonindex) - { + if (!e.skeletonindex) { e.skeletonindex = skel_create(m); skeleton_markbones(e); } float s = e.skeletonindex; - if(!s) + if (!s) { return; + } float n = e.skeleton_numbones; float savelerpfrac = e.lerpfrac; float savelerpfrac3 = e.lerpfrac3; float savelerpfrac4 = e.lerpfrac4; vector fixbone_oldangles = '0 0 0'; - if(e.fixbone) - { + if (e.fixbone) { // make all bones BONETYPE_UPPER e.lerpfrac = 0; e.lerpfrac3 = savelerpfrac3 * 2; @@ -142,60 +145,50 @@ void skeleton_from_frames(entity e, bool is_dead) fixbone_oldangles = fixedvectoangles2(v_forward, v_up); } int bone; - for(bone = 0; bone < n; ) - { + for (bone = 0; bone < n; ) { float firstbone = bone; float bonetype = e.skeleton_bonetype[bone]; - for(++bone; (bone < n) && (e.skeleton_bonetype[bone] == bonetype); ++bone) - ; - if(bonetype == BONETYPE_UPPER) - { + for (++bone; (bone < n) && (e.skeleton_bonetype[bone] == bonetype); ++bone) {} + if (bonetype == BONETYPE_UPPER) { // only show frames 1+3 (upper body) e.lerpfrac = 0; e.lerpfrac3 = savelerpfrac3 * 2; e.lerpfrac4 = 0; - } - else - { + } else { // only show frames 2+4 (lower body) e.lerpfrac = savelerpfrac * 2; e.lerpfrac3 = 0; e.lerpfrac4 = savelerpfrac4 * 2; } - //printf("Run: bone %d to %d, type %d\n", firstbone + 1, bone, bonetype); - //printf("frame %d %d %d %d lerpfrac * %d %d %d\n", e.frame, e.frame2, e.frame3, e.frame4, e.lerpfrac, e.lerpfrac3, e.lerpfrac4); + // printf("Run: bone %d to %d, type %d\n", firstbone + 1, bone, bonetype); + // printf("frame %d %d %d %d lerpfrac * %d %d %d\n", e.frame, e.frame2, e.frame3, e.frame4, e.lerpfrac, e.lerpfrac3, e.lerpfrac4); skel_build(s, e, m, 0, firstbone + 1, bone); } e.lerpfrac = savelerpfrac; e.lerpfrac3 = savelerpfrac3; e.lerpfrac4 = savelerpfrac4; - if(e.fixbone) - { + if (e.fixbone) { // FIX IT vector org = skel_get_boneabs(s, e.bone_upperbody); fixedmakevectors(fixbone_oldangles); skel_set_boneabs(s, e.bone_upperbody, org); } - if(!is_dead) - { - if(e == csqcplayer) - { - if(e.move_movetype == MOVETYPE_NONE) - { - if(!e.v_angle_save_x) + if (!is_dead) { + if (e == csqcplayer) { + if (e.move_movetype == MOVETYPE_NONE) { + if (!e.v_angle_save_x) { e.v_angle_save_x = input_angles.x; + } e.v_angle_x = e.v_angle_save_x; - } - else + } else { e.v_angle_x = input_angles.x; + } } int i; - for(i = 0; i < MAX_AIM_BONES; ++i) - { - if(e.(bone_aim[i])) - { + for (i = 0; i < MAX_AIM_BONES; ++i) { + if (e.(bone_aim[i])) { vector aim = '1 0 0' * bound(-90, e.v_angle_x, 90) * e.(bone_aimweight[i]); vector org = skel_get_boneabs(s, e.(bone_aim[i])); vector ang_cur = fixedvectoangles2(v_forward, v_up); diff --git a/qcsrc/client/player_skeleton.qh b/qcsrc/client/player_skeleton.qh index 8c5969b09..28c0514e6 100644 --- a/qcsrc/client/player_skeleton.qh +++ b/qcsrc/client/player_skeleton.qh @@ -7,8 +7,8 @@ void skeleton_from_frames(entity e, float is_dead); void skeleton_loadinfo(entity e); entityclass(Skeleton); -class(Skeleton) .float bone_upperbody; -class(Skeleton) .int bone_weapon; -class(Skeleton) .float bone_aim[MAX_AIM_BONES]; -class(Skeleton) .float bone_aimweight[MAX_AIM_BONES]; -class(Skeleton) .float fixbone; +class(Skeleton).float bone_upperbody; +class(Skeleton).int bone_weapon; +class(Skeleton).float bone_aim[MAX_AIM_BONES]; +class(Skeleton).float bone_aimweight[MAX_AIM_BONES]; +class(Skeleton).float fixbone; diff --git a/qcsrc/client/shownames.qc b/qcsrc/client/shownames.qc index 8a7d225bf..ae1847263 100644 --- a/qcsrc/client/shownames.qc +++ b/qcsrc/client/shownames.qc @@ -25,8 +25,7 @@ LinkedList shownames_ent; STATIC_INIT(shownames_ent) { shownames_ent = LL_NEW(); - for (int i = 0; i < maxclients; ++i) - { + for (int i = 0; i < maxclients; ++i) { entity e = new_pure(shownames_tag); e.sv_entnum = i + 1; LL_PUSH(shownames_ent, e); @@ -37,105 +36,88 @@ const float SHOWNAMES_FADESPEED = 4; const float SHOWNAMES_FADEDELAY = 0.4; void Draw_ShowNames(entity this) { - if (this.sv_entnum == (current_player + 1)) // self or spectatee - if (!(autocvar_hud_shownames_self && autocvar_chase_active)) return; - if (!this.sameteam && !autocvar_hud_shownames_enemies) return; + if (this.sv_entnum == (current_player + 1)) { // self or spectatee + if (!(autocvar_hud_shownames_self && autocvar_chase_active)) { return; } } + if (!this.sameteam && !autocvar_hud_shownames_enemies) { return; } bool hit; - if (!autocvar_hud_shownames_crosshairdistance && this.sameteam) - { + if (!autocvar_hud_shownames_crosshairdistance && this.sameteam) { hit = true; - } - else - { + } else { traceline(view_origin, this.origin, MOVE_NORMAL, this); hit = !(trace_fraction < 1 && (trace_networkentity != this.sv_entnum && trace_ent.entnum != this.sv_entnum)); } // handle tag fading int overlap = -1; vector o = project_3d_to_2d(this.origin + eZ * autocvar_hud_shownames_offset); - if (autocvar_hud_shownames_crosshairdistance) - { + if (autocvar_hud_shownames_crosshairdistance) { float d = autocvar_hud_shownames_crosshairdistance; float w = o.x - vid_conwidth / 2; float h = o.y - vid_conheight / 2; - if (d * d > w * w + h * h) this.pointtime = time; - if (this.pointtime + autocvar_hud_shownames_crosshairdistance_time <= time) + if (d * d > w * w + h * h) { this.pointtime = time; } + if (this.pointtime + autocvar_hud_shownames_crosshairdistance_time <= time) { overlap = 1; - else if(!autocvar_hud_shownames_crosshairdistance_antioverlap) + } else if (!autocvar_hud_shownames_crosshairdistance_antioverlap) { overlap = 0; + } } - if (overlap == -1 && autocvar_hud_shownames_antioverlap) - { + if (overlap == -1 && autocvar_hud_shownames_antioverlap) { // fade tag out if another tag that is closer to you overlaps entity entcs = NULL; LL_EACH(shownames_ent, it != this, { entcs = entcs_receiver(i); - if (!(entcs && entcs.has_sv_origin)) + if (!(entcs && entcs.has_sv_origin)) { continue; + } vector eo = project_3d_to_2d(it.origin); - if (eo.z < 0 || eo.x < 0 || eo.y < 0 || eo.x > vid_conwidth || eo.y > vid_conheight) continue; + if (eo.z < 0 || eo.x < 0 || eo.y < 0 || eo.x > vid_conwidth || eo.y > vid_conheight) { continue; } eo.z = 0; if (vdist((vec2(o) - eo), <, autocvar_hud_shownames_antioverlap_distance) - && vlen2(it.origin - view_origin) < vlen2(this.origin - view_origin)) - { + && vlen2(it.origin - view_origin) < vlen2(this.origin - view_origin)) { overlap = 1; break; } }); } bool onscreen = (o.z >= 0 && o.x >= 0 && o.y >= 0 && o.x <= vid_conwidth && o.y <= vid_conheight); - if (!this.fadedelay) this.fadedelay = time + SHOWNAMES_FADEDELAY; - if (this.csqcmodel_isdead) // dead player, fade out slowly - { + if (!this.fadedelay) { this.fadedelay = time + SHOWNAMES_FADEDELAY; } + if (this.csqcmodel_isdead) { // dead player, fade out slowly this.alpha = max(0, this.alpha - SHOWNAMES_FADESPEED * 0.25 * frametime); - } - else if (!onscreen || (!this.sameteam && !hit)) // out of view, fade out - { + } else if (!onscreen || (!this.sameteam && !hit)) { // out of view, fade out this.alpha = max(0, this.alpha - SHOWNAMES_FADESPEED * frametime); - this.fadedelay = 0; // reset fade in delay, enemy has left the view - } - else if (overlap > 0) // tag overlap detected, fade out - { + this.fadedelay = 0; // reset fade in delay, enemy has left the view + } else if (overlap > 0) { // tag overlap detected, fade out this.alpha = max(0, this.alpha - SHOWNAMES_FADESPEED * frametime); - } - else if (this.sameteam) // fade in for team mates - { + } else if (this.sameteam) { // fade in for team mates this.alpha = min(1, this.alpha + SHOWNAMES_FADESPEED * frametime); - } - else if (time > this.fadedelay) // fade in for enemies - { + } else if (time > this.fadedelay) { // fade in for enemies this.alpha = min(1, this.alpha + SHOWNAMES_FADESPEED * frametime); } float a = autocvar_hud_shownames_alpha * this.alpha; // multiply by player alpha - if (!this.sameteam || (this.sv_entnum == player_localentnum)) - { + if (!this.sameteam || (this.sv_entnum == player_localentnum)) { float f = entcs_GetAlpha(this.sv_entnum - 1); - if (f == 0) f = 1; - if (f < 0) f = 0; + if (f == 0) { f = 1; } + if (f < 0) { f = 0; } // FIXME: alpha is negative when dead, breaking death fade - if (!this.csqcmodel_isdead) a *= f; + if (!this.csqcmodel_isdead) { a *= f; } } - if (a < ALPHA_MIN_VISIBLE && gametype != MAPINFO_TYPE_CTS) return; - if (vdist(this.origin - view_origin, >=, max_shot_distance)) return; + if (a < ALPHA_MIN_VISIBLE && gametype != MAPINFO_TYPE_CTS) { return; } + if (vdist(this.origin - view_origin, >=, max_shot_distance)) { return; } float dist = vlen(this.origin - view_origin); - if (autocvar_hud_shownames_maxdistance) - { - if (dist >= autocvar_hud_shownames_maxdistance) return; + if (autocvar_hud_shownames_maxdistance) { + if (dist >= autocvar_hud_shownames_maxdistance) { return; } float f = autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance; a *= (f - max(0, dist - autocvar_hud_shownames_mindistance)) / f; } - if (!a) return; + if (!a) { return; } float resize = 1; - if (autocvar_hud_shownames_resize) // limit resize so its never smaller than 0.5... gets unreadable - { + if (autocvar_hud_shownames_resize) { // limit resize so its never smaller than 0.5... gets unreadable float f = autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance; resize = 0.5 + 0.5 * (f - max(0, dist - autocvar_hud_shownames_mindistance)) / f; } // draw the sprite image - if (o.z >= 0) - { + if (o.z >= 0) { o.z = 0; vector mySize = (vec2(autocvar_hud_shownames_aspect, 1)) * autocvar_hud_shownames_fontsize; vector myPos = o - vec2(0.5 * mySize.x, mySize.y); @@ -147,18 +129,15 @@ void Draw_ShowNames(entity this) // this is where the origin of the string vector namepos = myPos; float namewidth = mySize.x; - if (autocvar_hud_shownames_status && this.sameteam) - { + if (autocvar_hud_shownames_status && this.sameteam) { vector pos = namepos + eY * autocvar_hud_shownames_fontsize * resize; vector sz = vec2(0.5 * mySize.x, resize * autocvar_hud_shownames_statusbar_height); - if (this.healthvalue > 0) - { + if (this.healthvalue > 0) { HUD_Panel_DrawProgressBar(pos, sz, "nametag_statusbar", this.healthvalue / autocvar_hud_panel_healtharmor_maxhealth, false, 1, '1 0 0', a, DRAWFLAG_NORMAL); } - if (this.armorvalue > 0) - { + if (this.armorvalue > 0) { HUD_Panel_DrawProgressBar(pos + eX * 0.5 * mySize.x, sz, "nametag_statusbar", this.armorvalue / autocvar_hud_panel_healtharmor_maxarmor, false, 0, '0 1 0', a, DRAWFLAG_NORMAL); @@ -166,11 +145,11 @@ void Draw_ShowNames(entity this) } string s = entcs_GetName(this.sv_entnum - 1); if ((autocvar_hud_shownames_decolorize == 1 && teamplay) - || autocvar_hud_shownames_decolorize == 2) s = playername(s, entcs_GetTeam(this.sv_entnum - 1)); + || autocvar_hud_shownames_decolorize == 2) { s = playername(s, entcs_GetTeam(this.sv_entnum - 1)); } drawfontscale = '1 1 0' * resize; s = textShortenToWidth(s, namewidth, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors); float width = stringwidth(s, true, '1 1 0' * autocvar_hud_shownames_fontsize); - if (width != namewidth) namepos.x += (namewidth - width) / 2; + if (width != namewidth) { namepos.x += (namewidth - width) / 2; } drawcolorcodedstring(namepos, s, '1 1 0' * autocvar_hud_shownames_fontsize, a, DRAWFLAG_NORMAL); drawfontscale = '1 1 0'; } @@ -178,32 +157,28 @@ void Draw_ShowNames(entity this) void Draw_ShowNames_All() { - if (!autocvar_hud_shownames) return; + if (!autocvar_hud_shownames) { return; } LL_EACH(shownames_ent, true, { entity entcs = entcs_receiver(i); - if (!entcs) - { + if (!entcs) { make_pure(it); continue; } make_impure(it); assert(getthink(entcs), eprint(entcs)); getthink(entcs)(entcs); - if (!entcs.has_origin) continue; - if (entcs.m_entcs_private) - { + if (!entcs.has_origin) { continue; } + if (entcs.m_entcs_private) { it.healthvalue = entcs.healthvalue; it.armorvalue = entcs.armorvalue; it.sameteam = true; - } - else - { + } else { it.healthvalue = 0; it.armorvalue = 0; it.sameteam = false; } bool dead = entcs_IsDead(i) || entcs_IsSpectating(i); - if (!it.csqcmodel_isdead) setorigin(it, entcs.origin); + if (!it.csqcmodel_isdead) { setorigin(it, entcs.origin); } it.csqcmodel_isdead = dead; Draw_ShowNames(it); }); diff --git a/qcsrc/client/shownames.qh b/qcsrc/client/shownames.qh index 24f6568d2..db919a851 100644 --- a/qcsrc/client/shownames.qh +++ b/qcsrc/client/shownames.qh @@ -1,10 +1,10 @@ #pragma once entityclass(ShowNames); -class(ShowNames) .float healthvalue; -class(ShowNames) .float armorvalue; -class(ShowNames) .float sameteam; -class(ShowNames) .float fadedelay; -class(ShowNames) .float pointtime; +class(ShowNames).float healthvalue; +class(ShowNames).float armorvalue; +class(ShowNames).float sameteam; +class(ShowNames).float fadedelay; +class(ShowNames).float pointtime; void Draw_ShowNames_All(); diff --git a/qcsrc/client/teamradar.qh b/qcsrc/client/teamradar.qh index 251c1a53f..91a43753a 100644 --- a/qcsrc/client/teamradar.qh +++ b/qcsrc/client/teamradar.qh @@ -4,20 +4,20 @@ const int MAX_TEAMRADAR_TIMES = 32; entityclass(TeamRadar); // to make entities have dots on the team radar -class(TeamRadar) .float teamradar_icon; -class(TeamRadar) .float teamradar_times[MAX_TEAMRADAR_TIMES]; -class(TeamRadar) .int teamradar_time_index; -class(TeamRadar) .vector teamradar_color; - -float teamradar_angle; // player yaw angle -vector teamradar_origin3d_in_texcoord; // player origin -vector teamradar_origin2d; // 2D origin -vector teamradar_size2d; // 2D size +class(TeamRadar).float teamradar_icon; +class(TeamRadar).float teamradar_times[MAX_TEAMRADAR_TIMES]; +class(TeamRadar).int teamradar_time_index; +class(TeamRadar).vector teamradar_color; + +float teamradar_angle; // player yaw angle +vector teamradar_origin3d_in_texcoord; // player origin +vector teamradar_origin2d; // 2D origin +vector teamradar_size2d; // 2D size vector teamradar_extraclip_mins, teamradar_extraclip_maxs; // for non-centered radar display -float teamradar_size; // 2D scale factor +float teamradar_size; // 2D scale factor float v_flipped; -float hud_panel_radar_scale; // window size = ...qu +float hud_panel_radar_scale; // window size = ...qu float hud_panel_radar_foreground_alpha; float hud_panel_radar_rotation; vector hud_panel_radar_size; @@ -32,7 +32,7 @@ vector teamradar_3dcoord_to_texcoord(vector in); vector teamradar_texcoord_to_2dcoord(vector in); -vector teamradar_texcoord_to_3dcoord(vector in,float oz); +vector teamradar_texcoord_to_3dcoord(vector in, float oz); void draw_teamradar_background(float fg); diff --git a/qcsrc/client/wall.qc b/qcsrc/client/wall.qc index a0d66d719..07800d0e1 100644 --- a/qcsrc/client/wall.qc +++ b/qcsrc/client/wall.qc @@ -13,77 +13,70 @@ void Ent_Wall_PreDraw(entity this) { - if (this.inactive) - { + if (this.inactive) { this.alpha = 0; - } - else - { + } else { vector org = getpropertyvec(VF_ORIGIN); - if(!checkpvs(org, this)) + if (!checkpvs(org, this)) { this.alpha = 0; - else if(this.fade_start || this.fade_end) { + } else if (this.fade_start || this.fade_end) { vector offset = '0 0 0'; offset_z = this.fade_vertical_offset; float player_dist = vlen(org - this.origin - 0.5 * (this.mins + this.maxs) + offset); - if (this.fade_end == this.fade_start) - { - if (player_dist >= this.fade_start) + if (this.fade_end == this.fade_start) { + if (player_dist >= this.fade_start) { this.alpha = 0; - else + } else { this.alpha = 1; - } - else - { + } + } else { this.alpha = (this.alpha_min + this.alpha_max * bound(0, - (this.fade_end - player_dist) - / (this.fade_end - this.fade_start), 1)) / 100.0; + (this.fade_end - player_dist) + / (this.fade_end - this.fade_start), 1)) / 100.0; } - } - else - { + } else { this.alpha = 1; } } - if(this.alpha <= 0) + if (this.alpha <= 0) { this.drawmask = 0; - else + } else { this.drawmask = MASK_NORMAL; + } } void Ent_Wall_Draw(entity this) { float f; - var .vector fld; + var.vector fld; - if(this.bgmscriptangular) + if (this.bgmscriptangular) { fld = angles; - else + } else { fld = origin; + } this.(fld) = this.saved; - if(this.lodmodelindex1) - { - if(autocvar_cl_modeldetailreduction <= 0) - { - if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2) + if (this.lodmodelindex1) { + if (autocvar_cl_modeldetailreduction <= 0) { + if (this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2) { this.modelindex = this.lodmodelindex2; - else if(autocvar_cl_modeldetailreduction <= -1) + } else if (autocvar_cl_modeldetailreduction <= -1) { this.modelindex = this.lodmodelindex1; - else + } else { this.modelindex = this.lodmodelindex0; - } - else - { + } + } else { float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin); f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction; f *= 1.0 / bound(0.01, view_quality, 1); - if(this.lodmodelindex2 && f > this.loddistance2) + if (this.lodmodelindex2 && f > this.loddistance2) { this.modelindex = this.lodmodelindex2; - else if(f > this.loddistance1) + } else if (f > this.loddistance1) { this.modelindex = this.lodmodelindex1; - else + } else { this.modelindex = this.lodmodelindex0; + } } } @@ -92,121 +85,113 @@ void Ent_Wall_Draw(entity this) this.saved = this.(fld); f = doBGMScript(this); - if(f >= 0) - { - if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip) + if (f >= 0) { + if (this.lip < 0) { // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip) this.alpha = 1 + this.lip * f; - else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip) + } else { // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip) this.alpha = 1 - this.lip * (1 - f); + } this.(fld) = this.(fld) + this.movedir * f; - } - else + } else { this.alpha = 1; + } - if(this.alpha >= ALPHA_MIN_VISIBLE) + if (this.alpha >= ALPHA_MIN_VISIBLE) { this.drawmask = MASK_NORMAL; - else + } else { this.drawmask = 0; + } } void Ent_Wall_Remove(entity this) { - if(this.bgmscript) + if (this.bgmscript) { strunzone(this.bgmscript); + } this.bgmscript = string_null; } NET_HANDLE(ENT_CLIENT_WALL, bool isnew) { int f; - var .vector fld; + var.vector fld; InterpolateOrigin_Undo(this); this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN; - if(this.bgmscriptangular) + if (this.bgmscriptangular) { fld = angles; - else + } else { fld = origin; + } this.(fld) = this.saved; f = ReadByte(); - if(f & 1) - { - if(f & 0x40) + if (f & 1) { + if (f & 0x40) { this.colormap = ReadShort(); - else + } else { this.colormap = 0; + } this.skin = ReadByte(); } - if(f & 2) - { + if (f & 2) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); setorigin(this, this.origin); } - if(f & 4) - { - if(f & 0x10) - { + if (f & 4) { + if (f & 0x10) { this.angles_x = ReadAngle(); this.angles_y = ReadAngle(); this.angles_z = ReadAngle(); - } - else + } else { this.angles = '0 0 0'; + } } - if(f & 8) - { - if(f & 0x80) - { + if (f & 8) { + if (f & 0x80) { this.lodmodelindex0 = ReadShort(); this.loddistance1 = ReadShort(); this.lodmodelindex1 = ReadShort(); this.loddistance2 = ReadShort(); this.lodmodelindex2 = ReadShort(); - } - else - { + } else { this.modelindex = ReadShort(); this.loddistance1 = 0; this.loddistance2 = 0; } this.solid = ReadByte(); this.scale = ReadShort() / 256.0; - if(f & 0x20) - { + if (f & 0x20) { this.mins_x = ReadCoord(); this.mins_y = ReadCoord(); this.mins_z = ReadCoord(); this.maxs_x = ReadCoord(); this.maxs_y = ReadCoord(); this.maxs_z = ReadCoord(); - } - else + } else { this.mins = this.maxs = '0 0 0'; + } setsize(this, this.mins, this.maxs); - if(this.bgmscript) + if (this.bgmscript) { strunzone(this.bgmscript); + } this.bgmscript = ReadString(); - if(substring(this.bgmscript, 0, 1) == "<") - { + if (substring(this.bgmscript, 0, 1) == "<") { this.bgmscript = strzone(substring(this.bgmscript, 1, -1)); this.bgmscriptangular = 1; - } - else - { + } else { this.bgmscript = strzone(this.bgmscript); this.bgmscriptangular = 0; } - if(this.bgmscript != "") - { + if (this.bgmscript != "") { this.bgmscriptattack = ReadByte() / 64.0; this.bgmscriptdecay = ReadByte() / 64.0; this.bgmscriptsustain = ReadByte() / 255.0; @@ -233,6 +218,6 @@ NET_HANDLE(ENT_CLIENT_WALL, bool isnew) this.entremove = Ent_Wall_Remove; this.draw = Ent_Wall_Draw; - if (isnew) IL_PUSH(g_drawables, this); + if (isnew) { IL_PUSH(g_drawables, this); } setpredraw(this, Ent_Wall_PreDraw); } diff --git a/qcsrc/client/wall.qh b/qcsrc/client/wall.qh index 11aebd0ed..b13991abe 100644 --- a/qcsrc/client/wall.qh +++ b/qcsrc/client/wall.qh @@ -1,11 +1,11 @@ #pragma once entityclass(Wall); -class(Wall) .float lip; -class(Wall) .float bgmscriptangular; -class(Wall) .int lodmodelindex0, lodmodelindex1, lodmodelindex2; -class(Wall) .float loddistance1, loddistance2; -class(Wall) .vector saved; +class(Wall).float lip; +class(Wall).float bgmscriptangular; +class(Wall).int lodmodelindex0, lodmodelindex1, lodmodelindex2; +class(Wall).float loddistance1, loddistance2; +class(Wall).vector saved; // Needed for interactive clientwalls .float inactive; // Clientwall disappears when inactive diff --git a/qcsrc/common/anim.qc b/qcsrc/common/anim.qc index 6a4dbe50f..8236976d5 100644 --- a/qcsrc/common/anim.qc +++ b/qcsrc/common/anim.qc @@ -5,24 +5,23 @@ */ void anim_set(entity e, vector anim, bool looping, bool override, bool restart) { - if (!anim) return; // no animation was given to us! We can't use this. - - if (anim.x == e.animstate_startframe) - { - if (anim.y == e.animstate_numframes) - { - if (anim.z == e.animstate_framerate) - { - if (!restart) return; - if (anim.y == 1) // ZYM animation + if (!anim) { + return; // no animation was given to us! We can't use this. + } + if (anim.x == e.animstate_startframe) { + if (anim.y == e.animstate_numframes) { + if (anim.z == e.animstate_framerate) { + if (!restart) { return; } + if (anim.y == 1) { // ZYM animation BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT); + } } } } e.animstate_startframe = anim.x; e.animstate_numframes = anim.y; e.animstate_framerate = anim.z; - e.animstate_starttime = time - 0.1 * frametime; // shift it a little bit into the past to prevent float inaccuracy hiccups + e.animstate_starttime = time - 0.1 * frametime; // shift it a little bit into the past to prevent float inaccuracy hiccups e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate; e.animstate_looping = looping; e.animstate_override = override; @@ -35,10 +34,8 @@ void anim_set(entity e, vector anim, bool looping, bool override, bool restart) */ void anim_update(entity e) { - if (time >= e.animstate_endtime) - { - if (e.animstate_looping) - { + if (time >= e.animstate_endtime) { + if (e.animstate_looping) { e.animstate_starttime = e.animstate_endtime; e.animstate_endtime = e.animstate_starttime + e.animstate_numframes / e.animstate_framerate; } diff --git a/qcsrc/common/animdecide.qc b/qcsrc/common/animdecide.qc index b53a9ba0e..61a6765f4 100644 --- a/qcsrc/common/animdecide.qc +++ b/qcsrc/common/animdecide.qc @@ -3,19 +3,19 @@ #include #if defined(SVQC) - #include "util.qh" - #include "../server/defs.qh" + #include "util.qh" + #include "../server/defs.qh" #endif bool monsters_animoverride(entity this) { Monster monster_id = NULL; FOREACH(Monsters, it != MON_Null && it.m_model.model_str() == this.model, { - monster_id = it; - break; + monster_id = it; + break; }); - if(!monster_id) { return false; } + if (!monster_id) { return false; } monster_id.mr_anim(monster_id, this); @@ -50,13 +50,13 @@ bool monsters_animoverride(entity this) void animdecide_load_if_needed(entity e) { int mdlidx = e.modelindex; - if (mdlidx == e.animdecide_modelindex) return; + if (mdlidx == e.animdecide_modelindex) { return; } e.animdecide_modelindex = mdlidx; - if(substring(e.model, 0, 16) == "models/monsters/") - { - if(monsters_animoverride(e)) + if (substring(e.model, 0, 16) == "models/monsters/") { + if (monsters_animoverride(e)) { return; + } } #define ANIM_VEC(a, frames, rate) anim_vec(ANIM_##a, mdlidx, frames, rate) @@ -81,7 +81,7 @@ void animdecide_load_if_needed(entity e) e.anim_forwardright = animfixfps(e, ANIM_VEC(forwardright, 1, 1), ANIM_VEC(straferight, 1, 1)); e.anim_forwardleft = animfixfps(e, ANIM_VEC(forwardleft, 1, 1), ANIM_VEC(strafeleft, 1, 1)); e.anim_backright = animfixfps(e, ANIM_VEC(backright, 1, 1), ANIM_VEC(straferight, 1, 1)); - e.anim_backleft = animfixfps(e, ANIM_VEC(backleft , 1, 1), ANIM_VEC(strafeleft, 1, 1)); + e.anim_backleft = animfixfps(e, ANIM_VEC(backleft, 1, 1), ANIM_VEC(strafeleft, 1, 1)); e.anim_melee = animfixfps(e, ANIM_VEC(melee, 1, 1), ANIM_VEC(shoot, 1, 1)); e.anim_duckwalkbackwards = animfixfps(e, ANIM_VEC(duckwalkbackwards, 1, 1), ANIM_VEC(duckwalk, 1, 1)); e.anim_duckwalkstrafeleft = animfixfps(e, ANIM_VEC(duckwalkstrafeleft, 1, 1), ANIM_VEC(duckwalk, 1, 1)); @@ -89,7 +89,7 @@ void animdecide_load_if_needed(entity e) e.anim_duckwalkforwardright = animfixfps(e, ANIM_VEC(duckwalkforwardright, 1, 1), ANIM_VEC(duckwalk, 1, 1)); e.anim_duckwalkforwardleft = animfixfps(e, ANIM_VEC(duckwalkforwardleft, 1, 1), ANIM_VEC(duckwalk, 1, 1)); e.anim_duckwalkbackright = animfixfps(e, ANIM_VEC(duckwalkbackright, 1, 1), ANIM_VEC(duckwalk, 1, 1)); - e.anim_duckwalkbackleft = animfixfps(e, ANIM_VEC(duckwalkbackleft , 1, 1), ANIM_VEC(duckwalk, 1, 1)); + e.anim_duckwalkbackleft = animfixfps(e, ANIM_VEC(duckwalkbackleft, 1, 1), ANIM_VEC(duckwalk, 1, 1)); #undef ANIM_VEC @@ -106,39 +106,42 @@ const float ANIMPRIO_DEAD = 3; vector animdecide_getupperanim(entity e) { // death etc. - if(e.anim_state & ANIMSTATE_FROZEN) + if (e.anim_state & ANIMSTATE_FROZEN) { return vec3(e.anim_idle.x, e.anim_time, ANIMPRIO_DEAD); - if(e.anim_state & ANIMSTATE_DEAD1) + } + if (e.anim_state & ANIMSTATE_DEAD1) { return vec3(e.anim_die1_x, e.anim_time, ANIMPRIO_DEAD); - if(e.anim_state & ANIMSTATE_DEAD2) + } + if (e.anim_state & ANIMSTATE_DEAD2) { return vec3(e.anim_die2_x, e.anim_time, ANIMPRIO_DEAD); + } // is there an action? vector outframe = '-1 0 0'; float t, a; - if(e.anim_upper_time >= e.anim_upper_implicit_time) - { + if (e.anim_upper_time >= e.anim_upper_implicit_time) { a = e.anim_upper_action; t = e.anim_upper_time; - } - else - { + } else { a = e.anim_upper_implicit_action; t = e.anim_upper_implicit_time; } - switch(a) - { - case ANIMACTION_DRAW: outframe = e.anim_draw; break; - case ANIMACTION_PAIN1: outframe = e.anim_pain1; break; - case ANIMACTION_PAIN2: outframe = e.anim_pain2; break; - case ANIMACTION_SHOOT: outframe = e.anim_shoot; break; - case ANIMACTION_TAUNT: outframe = e.anim_taunt; break; - case ANIMACTION_MELEE: outframe = e.anim_melee; break; + switch (a) { + case ANIMACTION_DRAW: outframe = e.anim_draw; + break; + case ANIMACTION_PAIN1: outframe = e.anim_pain1; + break; + case ANIMACTION_PAIN2: outframe = e.anim_pain2; + break; + case ANIMACTION_SHOOT: outframe = e.anim_shoot; + break; + case ANIMACTION_TAUNT: outframe = e.anim_taunt; + break; + case ANIMACTION_MELEE: outframe = e.anim_melee; + break; } - if(outframe.x >= 0) - { - if(time <= t + outframe.y / outframe.z) - { + if (outframe.x >= 0) { + if (time <= t + outframe.y / outframe.z) { // animation is running! return vec3(outframe.x, t, ANIMPRIO_ACTIVE); } @@ -152,92 +155,89 @@ vector animdecide_getupperanim(entity e) vector animdecide_getloweranim(entity e) { // death etc. - if(e.anim_state & ANIMSTATE_FOLLOW) + if (e.anim_state & ANIMSTATE_FOLLOW) { return vec3(((e.anim_state & ANIMSTATE_DUCK) ? e.anim_duckidle_x : e.anim_idle_x), e.anim_time, ANIMPRIO_DEAD); // dead priority so it's above all - if(e.anim_state & ANIMSTATE_FROZEN) + } + if (e.anim_state & ANIMSTATE_FROZEN) { return vec3(e.anim_idle.x, e.anim_time, ANIMPRIO_DEAD); - if(e.anim_state & ANIMSTATE_DEAD1) + } + if (e.anim_state & ANIMSTATE_DEAD1) { return vec3(e.anim_die1_x, e.anim_time, ANIMPRIO_DEAD); - if(e.anim_state & ANIMSTATE_DEAD2) + } + if (e.anim_state & ANIMSTATE_DEAD2) { return vec3(e.anim_die2_x, e.anim_time, ANIMPRIO_DEAD); + } // is there an action? vector outframe = '-1 0 0'; float t, a; - if(e.anim_lower_time >= e.anim_lower_implicit_time) - { + if (e.anim_lower_time >= e.anim_lower_implicit_time) { a = e.anim_lower_action; t = e.anim_lower_time; - } - else - { + } else { a = e.anim_lower_implicit_action; t = e.anim_lower_implicit_time; } - switch(a) - { - case ANIMACTION_JUMP: if(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) { if(e.anim_state & ANIMSTATE_DUCK) outframe = e.anim_duckjump; else outframe = e.anim_jump; } break; + switch (a) { + case ANIMACTION_JUMP: if (e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) { if (e.anim_state & ANIMSTATE_DUCK) { outframe = e.anim_duckjump; } else { outframe = e.anim_jump; } } break; } - if(outframe.x >= 0) - { - if(time <= t + outframe.y / outframe.z) - { + if (outframe.x >= 0) { + if (time <= t + outframe.y / outframe.z) { // animation is running! return vec3(outframe.x, t, ANIMPRIO_ACTIVE); } } // or, decide the anim by state t = max(e.anim_time, e.anim_implicit_time); - if(e.anim_state & ANIMSTATE_DUCK) - { - if(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) + if (e.anim_state & ANIMSTATE_DUCK) { + if (e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) { return vec3(e.anim_duckjump.x, 0, ANIMPRIO_CROUCH); // play the END of the jump anim - else switch(e.anim_implicit_state & (ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT | ANIMIMPLICITSTATE_RIGHT)) - { - case ANIMIMPLICITSTATE_FORWARD: - return vec3(e.anim_duckwalk.x, t, ANIMPRIO_CROUCH); - case ANIMIMPLICITSTATE_BACKWARDS: - return vec3(e.anim_duckwalkbackwards.x, t, ANIMPRIO_CROUCH); - case ANIMIMPLICITSTATE_RIGHT: - return vec3(e.anim_duckwalkstraferight.x, t, ANIMPRIO_CROUCH); - case ANIMIMPLICITSTATE_LEFT: - return vec3(e.anim_duckwalkstrafeleft.x, t, ANIMPRIO_CROUCH); - case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_RIGHT: - return vec3(e.anim_duckwalkforwardright.x, t, ANIMPRIO_CROUCH); - case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_LEFT: - return vec3(e.anim_duckwalkforwardleft.x, t, ANIMPRIO_CROUCH); - case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_RIGHT: - return vec3(e.anim_duckwalkbackright.x, t, ANIMPRIO_CROUCH); - case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT: - return vec3(e.anim_duckwalkbackleft.x, t, ANIMPRIO_CROUCH); - default: - return vec3(e.anim_duckidle.x, t, ANIMPRIO_CROUCH); + } else { + switch (e.anim_implicit_state & (ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT | ANIMIMPLICITSTATE_RIGHT)) { + case ANIMIMPLICITSTATE_FORWARD: + return vec3(e.anim_duckwalk.x, t, ANIMPRIO_CROUCH); + case ANIMIMPLICITSTATE_BACKWARDS: + return vec3(e.anim_duckwalkbackwards.x, t, ANIMPRIO_CROUCH); + case ANIMIMPLICITSTATE_RIGHT: + return vec3(e.anim_duckwalkstraferight.x, t, ANIMPRIO_CROUCH); + case ANIMIMPLICITSTATE_LEFT: + return vec3(e.anim_duckwalkstrafeleft.x, t, ANIMPRIO_CROUCH); + case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_RIGHT: + return vec3(e.anim_duckwalkforwardright.x, t, ANIMPRIO_CROUCH); + case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_LEFT: + return vec3(e.anim_duckwalkforwardleft.x, t, ANIMPRIO_CROUCH); + case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_RIGHT: + return vec3(e.anim_duckwalkbackright.x, t, ANIMPRIO_CROUCH); + case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT: + return vec3(e.anim_duckwalkbackleft.x, t, ANIMPRIO_CROUCH); + default: + return vec3(e.anim_duckidle.x, t, ANIMPRIO_CROUCH); + } } - } - else - { - if(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) + } else { + if (e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) { return vec3(e.anim_jump.x, 0, ANIMPRIO_ACTIVE); // play the END of the jump anim - else switch(e.anim_implicit_state & (ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT | ANIMIMPLICITSTATE_RIGHT)) - { - case ANIMIMPLICITSTATE_FORWARD: - return vec3(e.anim_run.x, t, ANIMPRIO_ACTIVE); - case ANIMIMPLICITSTATE_BACKWARDS: - return vec3(e.anim_runbackwards.x, t, ANIMPRIO_ACTIVE); - case ANIMIMPLICITSTATE_RIGHT: - return vec3(e.anim_straferight.x, t, ANIMPRIO_ACTIVE); - case ANIMIMPLICITSTATE_LEFT: - return vec3(e.anim_strafeleft.x, t, ANIMPRIO_ACTIVE); - case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_RIGHT: - return vec3(e.anim_forwardright.x, t, ANIMPRIO_ACTIVE); - case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_LEFT: - return vec3(e.anim_forwardleft.x, t, ANIMPRIO_ACTIVE); - case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_RIGHT: - return vec3(e.anim_backright.x, t, ANIMPRIO_ACTIVE); - case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT: - return vec3(e.anim_backleft.x, t, ANIMPRIO_ACTIVE); - default: - return vec3(e.anim_idle.x, t, ANIMPRIO_IDLE); + } else { + switch (e.anim_implicit_state & (ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT | ANIMIMPLICITSTATE_RIGHT)) { + case ANIMIMPLICITSTATE_FORWARD: + return vec3(e.anim_run.x, t, ANIMPRIO_ACTIVE); + case ANIMIMPLICITSTATE_BACKWARDS: + return vec3(e.anim_runbackwards.x, t, ANIMPRIO_ACTIVE); + case ANIMIMPLICITSTATE_RIGHT: + return vec3(e.anim_straferight.x, t, ANIMPRIO_ACTIVE); + case ANIMIMPLICITSTATE_LEFT: + return vec3(e.anim_strafeleft.x, t, ANIMPRIO_ACTIVE); + case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_RIGHT: + return vec3(e.anim_forwardright.x, t, ANIMPRIO_ACTIVE); + case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_LEFT: + return vec3(e.anim_forwardleft.x, t, ANIMPRIO_ACTIVE); + case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_RIGHT: + return vec3(e.anim_backright.x, t, ANIMPRIO_ACTIVE); + case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT: + return vec3(e.anim_backleft.x, t, ANIMPRIO_ACTIVE); + default: + return vec3(e.anim_idle.x, t, ANIMPRIO_IDLE); + } } } // can't get here @@ -264,30 +264,32 @@ void animdecide_setimplicitstate(entity e, float onground) // it slightly less likely to "hit two keys at once", so let's do this // here too - if(vdist(v, >, 10)) - { - if(v.x > fabs(v.y) * 0.5) + if (vdist(v, >, 10)) { + if (v.x > fabs(v.y) * 0.5) { s |= ANIMIMPLICITSTATE_FORWARD; - if(v.x < -fabs(v.y) * 0.5) + } + if (v.x < -fabs(v.y) * 0.5) { s |= ANIMIMPLICITSTATE_BACKWARDS; - if(v.y > fabs(v.x) * 0.5) + } + if (v.y > fabs(v.x) * 0.5) { s |= ANIMIMPLICITSTATE_RIGHT; - if(v.y < -fabs(v.x) * 0.5) + } + if (v.y < -fabs(v.x) * 0.5) { s |= ANIMIMPLICITSTATE_LEFT; + } } - if(!onground) + if (!onground) { s |= ANIMIMPLICITSTATE_INAIR; + } // detect some kinds of otherwise misdetected jumps (ground to air transition) // NOTE: currently, in CSQC this is the only jump detection, as the explicit jump action is never called! - if(!(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) && (s & ANIMIMPLICITSTATE_INAIR)) - { + if (!(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) && (s & ANIMIMPLICITSTATE_INAIR)) { e.anim_lower_implicit_action = ANIMACTION_JUMP; e.anim_lower_implicit_time = time; } - if(s != e.anim_implicit_state) - { + if (s != e.anim_implicit_state) { e.anim_implicit_state = s; e.anim_implicit_time = time; } @@ -299,28 +301,29 @@ void animdecide_setframes(entity e, float support_blending, .float fld_frame, .f // _z: priority vector upper = animdecide_getupperanim(e); vector lower = animdecide_getloweranim(e); - //print("UPPER: ", vtos(upper), ", LOWER: ", vtos(lower), "\n"); - if(support_blending) - { - if(upper.z && !lower.z) + // print("UPPER: ", vtos(upper), ", LOWER: ", vtos(lower), "\n"); + if (support_blending) { + if (upper.z && !lower.z) { lower = upper; - else if(lower.z && !upper.z) + } else if (lower.z && !upper.z) { upper = lower; - if(e.frame1time != upper.y || e.frame2time != lower.y) + } + if (e.frame1time != upper.y || e.frame2time != lower.y) { BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT); + } e.(fld_frame) = upper.x; e.(fld_frame1time) = upper.y; e.(fld_frame2) = lower.x; e.(fld_frame2time) = lower.y; - } - else - { - if(upper.z > lower.z) + } else { + if (upper.z > lower.z) { lower = upper; - else if(lower.z > upper.z) + } else if (lower.z > upper.z) { upper = lower; - if(e.frame1time != upper.y) + } + if (e.frame1time != upper.y) { BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT); + } e.(fld_frame) = upper.x; e.(fld_frame1time) = upper.y; } @@ -328,27 +331,30 @@ void animdecide_setframes(entity e, float support_blending, .float fld_frame, .f void animdecide_setstate(entity e, int newstate, float restart) { - if(!restart) - if(newstate == e.anim_state) + if (!restart) { + if (newstate == e.anim_state) { return; + } + } e.anim_state = newstate; e.anim_time = time; } void animdecide_setaction(entity e, float action, float restart) { - if(action < 0) - { - if(!restart) - if(action == e.anim_lower_action) + if (action < 0) { + if (!restart) { + if (action == e.anim_lower_action) { return; + } + } e.anim_lower_action = action; e.anim_lower_time = time; - } - else - { - if(!restart) - if(action == e.anim_upper_action) + } else { + if (!restart) { + if (action == e.anim_upper_action) { return; + } + } e.anim_upper_action = action; e.anim_upper_time = time; } diff --git a/qcsrc/common/animdecide.qh b/qcsrc/common/animdecide.qh index 16feb948c..7cc9330ee 100644 --- a/qcsrc/common/animdecide.qh +++ b/qcsrc/common/animdecide.qh @@ -13,7 +13,7 @@ CLASS(Animation, Object) { FOREACH_WORD(this.m_framenames, true, { int f = frameforname(mdlidx, it); - if (f != -1) return f; + if (f != -1) { return f; } }); #ifdef CSQC LOG_DEBUGF("Missing animation for %s: %s", modelnameforindex(mdlidx), this.registered_id); @@ -29,7 +29,8 @@ REGISTER_REGISTRY(Animations) #define ReadAnimation() ReadRegistered(Animations) #define REGISTER_ANIMATION(id, framenames) \ .vector anim_##id; \ - REGISTER(Animations, ANIM_##id, m_id, NEW(Animation)) { \ + REGISTER(Animations, ANIM_##id, m_id, NEW(Animation)) \ + { \ this.m_framenames = framenames; \ } @@ -121,9 +122,9 @@ REGISTER_ANIMATION(duckwalkbackleft, "duckwalkbackleft duckbackwardleft groupifi // explicit anim states (networked) void animdecide_setstate(entity e, int newstate, float restart); -const int ANIMSTATE_DEAD1 = BIT(0); // base frames: die1 -const int ANIMSTATE_DEAD2 = BIT(1); // base frames: die2 -const int ANIMSTATE_DUCK = BIT(2); // turns walk into duckwalk, jump into duckjump, etc. +const int ANIMSTATE_DEAD1 = BIT(0); // base frames: die1 +const int ANIMSTATE_DEAD2 = BIT(1); // base frames: die2 +const int ANIMSTATE_DUCK = BIT(2); // turns walk into duckwalk, jump into duckjump, etc. const int ANIMSTATE_FROZEN = BIT(3); // force idle const int ANIMSTATE_FOLLOW = BIT(4); // also force idle @@ -138,7 +139,7 @@ const int ANIMIMPLICITSTATE_JUMPRELEASED = BIT(5); // explicit actions (networked); negative values are for lower body void animdecide_setaction(entity e, float action, float restart); const int ANIMACTION_JUMP = -1; // jump -const int ANIMACTION_DRAW = 1; // draw +const int ANIMACTION_DRAW = 1; // draw const int ANIMACTION_PAIN1 = 2; // pain const int ANIMACTION_PAIN2 = 3; // pain const int ANIMACTION_SHOOT = 4; // shoot diff --git a/qcsrc/common/campaign_file.qc b/qcsrc/common/campaign_file.qc index d3efe77e8..93752ba5b 100644 --- a/qcsrc/common/campaign_file.qc +++ b/qcsrc/common/campaign_file.qc @@ -2,8 +2,8 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include "util.qh" - #include "campaign_common.qh" + #include "util.qh" + #include "campaign_common.qh" #endif // CampaignFileLoad(offset, n) @@ -19,8 +19,9 @@ float CampaignFile_Load(int offset, float n) string l, a; string fn; - if(n > CAMPAIGN_MAX_ENTRIES) + if (n > CAMPAIGN_MAX_ENTRIES) { n = CAMPAIGN_MAX_ENTRIES; + } campaign_offset = offset; campaign_entries = 0; @@ -28,51 +29,64 @@ float CampaignFile_Load(int offset, float n) fn = language_filename(strcat("maps/campaign", campaign_name, ".txt")); fh = fopen(fn, FILE_READ); - if(fh >= 0) - { - for(lineno = 0; (l = fgets(fh)); ) - { - if(strlen(l) == 0) + if (fh >= 0) { + for (lineno = 0; (l = fgets(fh)); ) { + if (strlen(l) == 0) { continue; // empty line - if(substring(l, 0, 11) == "//campaign:") + } + if (substring(l, 0, 11) == "//campaign:") { campaign_title = substring(l, 11, strlen(l) - 11); - if(substring(l, 0, 2) == "//") + } + if (substring(l, 0, 2) == "//") { continue; // comment - if(substring(l, 0, 12) == "\"//campaign:") + } + if (substring(l, 0, 12) == "\"//campaign:") { campaign_title = substring(l, 12, strlen(l) - 13); - if(substring(l, 0, 3) == "\"//") - continue; // comment - if(lineno >= offset) - { + } + if (substring(l, 0, 3) == "\"//") { + continue; // comment + } + if (lineno >= offset) { entlen = tokenize(l); // using insane tokenizer for CSV #define CAMPAIGN_GETARG \ a = argv(++i); \ - if(a == ",") \ + if (a == ",") { \ a = ""; \ - else \ + } else \ ++i // What you're seeing here is what people will do when your compiler supports // C-style macros but no line continuations. i = -1; // starts at -1 so I don't need postincrement; that is, i points to BEFORE the current arg! - CAMPAIGN_GETARG; campaign_gametype[campaign_entries] = strzone(a); - CAMPAIGN_GETARG; campaign_mapname[campaign_entries] = strzone(a); - CAMPAIGN_GETARG; campaign_bots[campaign_entries] = stof(a); - CAMPAIGN_GETARG; campaign_botskill[campaign_entries] = stof(a); - CAMPAIGN_GETARG; campaign_fraglimit[campaign_entries] = stof(a); - CAMPAIGN_GETARG; campaign_timelimit[campaign_entries] = stof(a); - CAMPAIGN_GETARG; campaign_mutators[campaign_entries] = strzone(a); - CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a); - CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a)); + CAMPAIGN_GETARG; + campaign_gametype[campaign_entries] = strzone(a); + CAMPAIGN_GETARG; + campaign_mapname[campaign_entries] = strzone(a); + CAMPAIGN_GETARG; + campaign_bots[campaign_entries] = stof(a); + CAMPAIGN_GETARG; + campaign_botskill[campaign_entries] = stof(a); + CAMPAIGN_GETARG; + campaign_fraglimit[campaign_entries] = stof(a); + CAMPAIGN_GETARG; + campaign_timelimit[campaign_entries] = stof(a); + CAMPAIGN_GETARG; + campaign_mutators[campaign_entries] = strzone(a); + CAMPAIGN_GETARG; + campaign_shortdesc[campaign_entries] = strzone(a); + CAMPAIGN_GETARG; + campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a)); - if(i > entlen) + if (i > entlen) { error("syntax error in campaign file: line has not enough fields"); + } campaign_entries = campaign_entries + 1; - if(campaign_entries >= n) + if (campaign_entries >= n) { break; + } } lineno = lineno + 1; } @@ -86,11 +100,9 @@ float CampaignFile_Load(int offset, float n) void CampaignFile_Unload() { - if(campaign_title) - { + if (campaign_title) { strunzone(campaign_title); - for(int i = 0; i < campaign_entries; ++i) - { + for (int i = 0; i < campaign_entries; ++i) { strunzone(campaign_gametype[i]); strunzone(campaign_mapname[i]); strunzone(campaign_mutators[i]); diff --git a/qcsrc/common/campaign_setup.qc b/qcsrc/common/campaign_setup.qc index 258d47f45..4ec28aa71 100644 --- a/qcsrc/common/campaign_setup.qc +++ b/qcsrc/common/campaign_setup.qc @@ -2,19 +2,19 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include "campaign_common.qh" - #include "mapinfo.qh" + #include "campaign_common.qh" + #include "mapinfo.qh" #endif void CampaignSetup(int n) { localcmd("set g_campaign 1\n"); localcmd("set _campaign_name \""); - localcmd(campaign_name); - localcmd("\"\n"); + localcmd(campaign_name); + localcmd("\"\n"); localcmd("set _campaign_index "); - localcmd(ftos(campaign_offset + n)); - localcmd("\n"); + localcmd(ftos(campaign_offset + n)); + localcmd("\n"); localcmd("disconnect\nmaxplayers 16\n"); MapInfo_LoadMap(campaign_mapname[n], 1); } diff --git a/qcsrc/common/command/command.qh b/qcsrc/common/command/command.qh index 349d492da..26308b89d 100644 --- a/qcsrc/common/command/command.qh +++ b/qcsrc/common/command/command.qh @@ -8,6 +8,6 @@ CLASS(Command, Object) ATTRIB(Command, m_description, string); METHOD(Command, m_invokecmd, void(Command this, int request, entity caller, int arguments, string command)) { - TC(Command, this); + TC(Command, this); } ENDCLASS(Command) diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index c58a3df75..e963fe4c6 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -33,23 +33,25 @@ void Curl_URI_Get_Callback(int id, float status, string data) int i = id - URI_GET_CURL; float do_exec = curl_uri_get_exec[i]; string do_cvar = curl_uri_get_cvar[i]; - if(status != 0) - { + if (status != 0) { LOG_TRACEF("error: status is %d", status); - if(do_cvar) + if (do_cvar) { strunzone(do_cvar); + } return; } - if(do_exec) + if (do_exec) { localcmd(data); - if(do_cvar) - { + } + if (do_cvar) { cvar_set(do_cvar, data); strunzone(do_cvar); } - if(!do_exec) - if (!do_cvar) + if (!do_exec) { + if (!do_cvar) { LOG_INFO(data); + } + } } @@ -59,21 +61,16 @@ void Curl_URI_Get_Callback(int id, float status, string data) void GenericCommand_addtolist(float request, float argc) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc >= 2) - { + if (argc >= 2) { string original_cvar = argv(1); string tmp_string = argv(2); - if(cvar_string(original_cvar) == "") // cvar was empty - { + if (cvar_string(original_cvar) == "") { // cvar was empty cvar_set(original_cvar, tmp_string); - } - else // add it to the end of the list if the list doesn't already have it - { + } else { // add it to the end of the list if the list doesn't already have it FOREACH_WORD(cvar_string(original_cvar), it == tmp_string, { return; // already in the list @@ -99,29 +96,24 @@ void GenericCommand_addtolist(float request, float argc) void GenericCommand_qc_curl(float request, float argc) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { bool do_exec = false; string do_cvar = string_null; float key = -1; int i; - for(i = 1; i+1 < argc; ++i) - { - if(argv(i) == "--cvar" && i+2 < argc) - { + for (i = 1; i + 1 < argc; ++i) { + if (argv(i) == "--cvar" && i + 2 < argc) { ++i; do_cvar = strzone(argv(i)); continue; } - if(argv(i) == "--exec") - { + if (argv(i) == "--exec") { do_exec = true; continue; } - if(argv(i) == "--key" && i+2 < argc) - { + if (argv(i) == "--key" && i + 2 < argc) { ++i; key = stof(argv(i)); continue; @@ -135,25 +127,27 @@ void GenericCommand_qc_curl(float request, float argc) ++i; float buf = buf_create(); int j; - for(j = 0; i+1 < argc; i += 2) - bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1)))); - if(i < argc) + for (j = 0; i + 1 < argc; i += 2) { + bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i + 1)))); + } + if (i < argc) { bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i)))); + } float r; - if(j == 0) // no args: GET + if (j == 0) { // no args: GET r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key); - else // with args: POST + } else { // with args: POST r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key); + } - if(r) - { + if (r) { curl_uri_get_exec[curl_uri_get_pos] = do_exec; curl_uri_get_cvar[curl_uri_get_pos] = do_cvar; curl_uri_get_pos = (curl_uri_get_pos + 1) % (URI_GET_CURL_END - URI_GET_CURL + 1); - } - else + } else { LOG_INFO(_("error creating curl handle")); + } buf_del(buf); @@ -171,33 +165,31 @@ void GenericCommand_qc_curl(float request, float argc) GENERIC_COMMAND(dumpcommands, "Dump all commands on the program to *_cmd_dump.txt") { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { float fh; string filename = strcat(GetProgramCommandPrefix(), "_dump.txt"); fh = fopen(filename, FILE_WRITE); - if(fh >= 0) - { + if (fh >= 0) { #ifdef SVQC - CMD_Write("dump of server console commands:\n"); - GameCommand_macro_write_aliases(fh); + CMD_Write("dump of server console commands:\n"); + GameCommand_macro_write_aliases(fh); - CMD_Write("\ndump of networked client only commands:\n"); - ClientCommand_macro_write_aliases(fh); + CMD_Write("\ndump of networked client only commands:\n"); + ClientCommand_macro_write_aliases(fh); - CMD_Write("\ndump of common commands:\n"); - CommonCommand_macro_write_aliases(fh); + CMD_Write("\ndump of common commands:\n"); + CommonCommand_macro_write_aliases(fh); - CMD_Write("\ndump of ban commands:\n"); - BanCommand_macro_write_aliases(fh); + CMD_Write("\ndump of ban commands:\n"); + BanCommand_macro_write_aliases(fh); #endif #ifdef CSQC - CMD_Write("dump of client commands:\n"); - LocalCommand_macro_write_aliases(fh); + CMD_Write("dump of client commands:\n"); + LocalCommand_macro_write_aliases(fh); #endif CMD_Write("\ndump of generic commands:\n"); @@ -206,9 +198,7 @@ GENERIC_COMMAND(dumpcommands, "Dump all commands on the program to *_cmd_dump.tx LOG_INFO("Completed dump of aliases in ^2data/data/", GetProgramCommandPrefix(), "_dump.txt^7."); fclose(fh); - } - else - { + } else { LOG_INFO("^1Error: ^7Could not dump to file!"); } return; @@ -226,33 +216,30 @@ GENERIC_COMMAND(dumpcommands, "Dump all commands on the program to *_cmd_dump.tx void GenericCommand_maplist(float request, float argc) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { string tmp_string; float i; - switch(argv(1)) - { + switch (argv(1)) { case "add": // appends new maps to the maplist { - if(argc == 3) - { - if (!fexists(strcat("maps/", argv(2), ".bsp"))) - { + if (argc == 3) { + if (!fexists(strcat("maps/", argv(2), ".bsp"))) { LOG_INFO("maplist: ERROR: ", argv(2), " does not exist!"); break; } - if(cvar_string("g_maplist") == "") + if (cvar_string("g_maplist") == "") { cvar_set("g_maplist", argv(2)); - else + } else { cvar_set("g_maplist", strcat(argv(2), " ", cvar_string("g_maplist"))); + } return; } - break; // go to usage + break; // go to usage } case "cleanup": // scans maplist and only adds back the ones which are really usable @@ -267,21 +254,22 @@ void GenericCommand_maplist(float request, float argc) case "remove": // scans maplist and only adds back whatever maps were not provided in argv(2) { - if(argc == 3) - { + if (argc == 3) { argc = tokenizebyseparator(cvar_string("g_maplist"), " "); tmp_string = ""; - for(i = 0; i < argc; ++i) - if(argv(i) != argv(2)) + for (i = 0; i < argc; ++i) { + if (argv(i) != argv(2)) { tmp_string = strcat(tmp_string, " ", argv(i)); + } + } tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1); cvar_set("g_maplist", tmp_string); return; } - break; // go to usage + break; // go to usage } case "shuffle": // randomly shuffle the maplist @@ -309,8 +297,7 @@ void GenericCommand_maplist(float request, float argc) void GenericCommand_nextframe(float request, float arguments, string command) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { queue_to_execute_next_frame(substring(command, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); @@ -329,12 +316,10 @@ void GenericCommand_nextframe(float request, float arguments, string command) void GenericCommand_removefromlist(float request, float argc) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc == 3) - { + if (argc == 3) { string original_cvar = argv(1); string removal = argv(2); @@ -364,27 +349,36 @@ void GenericCommand_removefromlist(float request, float argc) void GenericCommand_restartnotifs(float request) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { #ifdef GAMEQC - int NOTIF_ANNCE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_ANNCE, { ++NOTIF_ANNCE_COUNT; }); - int NOTIF_INFO_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_INFO, { ++NOTIF_INFO_COUNT; }); - int NOTIF_CENTER_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CENTER, { ++NOTIF_CENTER_COUNT; }); - int NOTIF_MULTI_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_MULTI, { ++NOTIF_MULTI_COUNT; }); - int NOTIF_CHOICE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CHOICE, { ++NOTIF_CHOICE_COUNT; }); + int NOTIF_ANNCE_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_ANNCE, { ++NOTIF_ANNCE_COUNT; + }); + int NOTIF_INFO_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_INFO, { ++NOTIF_INFO_COUNT; + }); + int NOTIF_CENTER_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_CENTER, { ++NOTIF_CENTER_COUNT; + }); + int NOTIF_MULTI_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_MULTI, { ++NOTIF_MULTI_COUNT; + }); + int NOTIF_CHOICE_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_CHOICE, { ++NOTIF_CHOICE_COUNT; + }); LOG_INFOF( - ( - "Restart_Notifications(): Restarting %d notifications... " - "Counts: MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d" - ), ( - NOTIF_ANNCE_COUNT + - NOTIF_INFO_COUNT + - NOTIF_CENTER_COUNT + - NOTIF_MULTI_COUNT + - NOTIF_CHOICE_COUNT + "Restart_Notifications(): Restarting %d notifications... " + "Counts: MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d" + ), + ( + NOTIF_ANNCE_COUNT + + NOTIF_INFO_COUNT + + NOTIF_CENTER_COUNT + + NOTIF_MULTI_COUNT + + NOTIF_CHOICE_COUNT ), NOTIF_ANNCE_COUNT, NOTIF_INFO_COUNT, @@ -412,17 +406,16 @@ void GenericCommand_restartnotifs(float request) void GenericCommand_settemp(float request, float argc) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc >= 3) - { + if (argc >= 3) { float f = cvar_settemp(argv(1), argv(2)); - if(f == 1) + if (f == 1) { LOG_TRACE("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily."); - else if(f == -1) + } else if (f == -1) { LOG_TRACE("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\"."); + } // else cvar_settemp itself errors out return; @@ -443,16 +436,16 @@ void GenericCommand_settemp(float request, float argc) void GenericCommand_settemp_restore(float request, float argc) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { float i = cvar_settemp_restore(); - if(i) + if (i) { LOG_TRACE("Restored ", ftos(i), " temporary cvar settings to their original values."); - else + } else { LOG_TRACE("Nothing to restore."); + } return; } @@ -470,18 +463,17 @@ void GenericCommand_settemp_restore(float request, float argc) void GenericCommand_runtest(float request, float argc) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc > 1) - { + if (argc > 1) { float i; - for(i = 1; i < argc; ++i) + for (i = 1; i < argc; ++i) { TEST_Run(argv(i)); - } - else + } + } else { RUN_ALL_TESTS(); + } return; } @@ -498,36 +490,66 @@ void GenericCommand_runtest(float request, float argc) ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION! void GenericCommand_(float request) { - switch(request) - { - case CMD_REQUEST_COMMAND: - { - - return; - } - - default: - case CMD_REQUEST_USAGE: - { - print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " ")); - print(" No arguments required.\n"); - return; - } - } + switch(request) + { + case CMD_REQUEST_COMMAND: + { + + return; + } + + default: + case CMD_REQUEST_USAGE: + { + print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " ")); + print(" No arguments required.\n"); + return; + } + } } */ // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) -GENERIC_COMMAND(addtolist, "Add a string to a cvar") { GenericCommand_addtolist(request, arguments); } -GENERIC_COMMAND(maplist, "Automatic control of maplist") { GenericCommand_maplist(request, arguments); } -GENERIC_COMMAND(nextframe, "Execute the given command next frame of this VM") { GenericCommand_nextframe(request, arguments, command); } -GENERIC_COMMAND(qc_curl, "Queries a URL") { GenericCommand_qc_curl(request, arguments); } -GENERIC_COMMAND(removefromlist, "Remove a string from a cvar") { GenericCommand_removefromlist(request, arguments); } -GENERIC_COMMAND(restartnotifs, "Re-initialize all notifications") { GenericCommand_restartnotifs(request); } -GENERIC_COMMAND(rpn, "RPN calculator") { GenericCommand_rpn(request, arguments, command); } -GENERIC_COMMAND(settemp, "Temporarily set a value to a cvar which is restored later") { GenericCommand_settemp(request, arguments); } -GENERIC_COMMAND(settemp_restore, "Restore all cvars set by settemp command") { GenericCommand_settemp_restore(request, arguments); } -GENERIC_COMMAND(runtest, "Run unit tests") { GenericCommand_runtest(request, arguments); } +GENERIC_COMMAND(addtolist, "Add a string to a cvar") +{ + GenericCommand_addtolist(request, arguments); +} +GENERIC_COMMAND(maplist, "Automatic control of maplist") +{ + GenericCommand_maplist(request, arguments); +} +GENERIC_COMMAND(nextframe, "Execute the given command next frame of this VM") +{ + GenericCommand_nextframe(request, arguments, command); +} +GENERIC_COMMAND(qc_curl, "Queries a URL") +{ + GenericCommand_qc_curl(request, arguments); +} +GENERIC_COMMAND(removefromlist, "Remove a string from a cvar") +{ + GenericCommand_removefromlist(request, arguments); +} +GENERIC_COMMAND(restartnotifs, "Re-initialize all notifications") +{ + GenericCommand_restartnotifs(request); +} +GENERIC_COMMAND(rpn, "RPN calculator") +{ + GenericCommand_rpn(request, arguments, command); +} +GENERIC_COMMAND(settemp, "Temporarily set a value to a cvar which is restored later") +{ + GenericCommand_settemp(request, arguments); +} +GENERIC_COMMAND(settemp_restore, "Restore all cvars set by settemp command") +{ + GenericCommand_settemp_restore(request, arguments); +} +GENERIC_COMMAND(runtest, "Run unit tests") +{ + GenericCommand_runtest(request, arguments); +} void GenericCommand_macro_help() { @@ -577,81 +599,77 @@ float GenericCommand(string command) // argv: 0 - 1 - 2 - 3 // cmd vote - master - login - password - if(GenericCommand_macro_command(argc, command)) // continue as usual and scan for normal commands - { + if (GenericCommand_macro_command(argc, command)) { // continue as usual and scan for normal commands return true; // handled by one of the above GenericCommand_* functions - } - else if(argc >= 3 && argv(0) == "red") - { + } else if (argc >= 3 && argv(0) == "red") { s = substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)); localcmd(strcat(argv(1), " ", GenericCommand_markup(s))); return true; - } - else if(argc >= 3 && crc16(0, argv(0)) == 38566 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 59830) - { + } else if (argc >= 3 && crc16(0, argv(0)) == 38566 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 59830) { // other test case s = strconv(2, 0, 0, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2))); n = floor(random() * 6 + 2); s2 = ""; - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { s2 = strcat(s2, "AH"); } - if(random() < 0.1) + if (random() < 0.1) { s2 = strcat(substring(s2, 1, strlen(s2) - 1), "A"); + } - if(s == "") + if (s == "") { s = s2; - else - if(random() < 0.8) + } else { + if (random() < 0.8) { s = strcat(s, " ", s2); - else + } else { s = strcat(s2, " ", s); + } + } s2 = substring(s, strlen(s) - 2, 2); - if(s2 == "AH" || s2 == "AY") + if (s2 == "AH" || s2 == "AY") { s = strcat(s, "))"); - else + } else { s = strcat(s, " ))"); + } - if(random() < 0.1) + if (random() < 0.1) { s = substring(s, 0, strlen(s) - 1); + } - if(random() < 0.1) + if (random() < 0.1) { s = strconv(1, 0, 0, s); + } localcmd(strcat(argv(1), " ", s)); return true; - } - else if(argc >= 3 && crc16(0, argv(0)) == 3826 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 55790) - { + } else if (argc >= 3 && crc16(0, argv(0)) == 3826 && crc16(0, strcat(argv(0), argv(0), argv(0))) == 55790) { // test case for terencehill's color codes s = strdecolorize(substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2))); s2 = ""; n = strlen(s); - j = ((6 * max(1, floor(strlen(s)/32 + random() * 2 - 1))) / n) * (1 - 2 * (random() > 0.5)); + j = ((6 * max(1, floor(strlen(s) / 32 + random() * 2 - 1))) / n) * (1 - 2 * (random() > 0.5)); f = random() * 6; - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { c = substring(s, i, 1); - if(c == ";") + if (c == ";") { c = ":"; - else if(c == "^") - { + } else if (c == "^") { c = "^^"; - if(substring(s, i+1, 1) == "^") + if (substring(s, i + 1, 1) == "^") { ++i; + } } - if(c != " ") - { + if (c != " ") { rgb = hsl_to_rgb('1 0 0' * (j * i + f) + '0 1 .5'); c = strcat(rgb_to_hexcolor(rgb), c); } diff --git a/qcsrc/common/command/generic.qh b/qcsrc/common/command/generic.qh index b39c79901..bcad0d020 100644 --- a/qcsrc/common/command/generic.qh +++ b/qcsrc/common/command/generic.qh @@ -31,7 +31,7 @@ float GenericCommand(string command); // used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file #define CMD_Write(s) fputs(fh, s) -#define CMD_Write_Alias(execute,command,description) CMD_Write(sprintf("alias %-20s \"%-13s %-20s ${* ?}\" // %s\n", command, execute, command, description)) +#define CMD_Write_Alias(execute, command, description) CMD_Write(sprintf("alias %-20s \"%-13s %-20s ${* ?}\" // %s\n", command, execute, command, description)) void GenericCommand_macro_write_aliases(float fh); void Curl_URI_Get_Callback(int id, float status, string data); diff --git a/qcsrc/common/command/markup.qc b/qcsrc/common/command/markup.qc index 95a3b53c5..441dcdca5 100644 --- a/qcsrc/common/command/markup.qc +++ b/qcsrc/common/command/markup.qc @@ -8,51 +8,134 @@ void GenericCommand_markup_init() { - if (markup_init) + if (markup_init) { return; + } markup_init = true; int i = 0; - markup_from[i] = "&alien"; markup_to[i] = "\x12"; ++i; - markup_from[i] = "&:-)"; markup_to[i] = "\x13"; ++i; - markup_from[i] = "&:-("; markup_to[i] = "\x14"; ++i; - markup_from[i] = "&x-P"; markup_to[i] = "\x15"; ++i; - markup_from[i] = "&:-/"; markup_to[i] = "\x16"; ++i; - markup_from[i] = "&:-D"; markup_to[i] = "\x17"; ++i; - markup_from[i] = "&<<"; markup_to[i] = "\x18"; ++i; - markup_from[i] = "&>>"; markup_to[i] = "\x19"; ++i; - markup_from[i] = "&dot"; markup_to[i] = "\x1a"; ++i; - markup_from[i] = "&^_"; markup_to[i] = "\x1b"; ++i; - markup_from[i] = "&ysplat"; markup_to[i] = "\x1c"; ++i; - markup_from[i] = "&-]"; markup_to[i] = "\x1d"; ++i; - markup_from[i] = "&--"; markup_to[i] = "\x1e"; ++i; - markup_from[i] = "&[-"; markup_to[i] = "\x1f"; ++i; - markup_from[i] = "&s<"; markup_to[i] = "\x2c"; ++i; - markup_from[i] = "&s>"; markup_to[i] = "\x2e"; ++i; - markup_from[i] = "&<-"; markup_to[i] = "\x7f"; ++i; - markup_from[i] = "&[="; markup_to[i] = "\x80"; ++i; - markup_from[i] = "&=="; markup_to[i] = "\x81"; ++i; - markup_from[i] = "&=]"; markup_to[i] = "\x82"; ++i; - markup_from[i] = "&r!"; markup_to[i] = "\x84"; ++i; - markup_from[i] = "&|o|"; markup_to[i] = "\x85"; ++i; - markup_from[i] = "&|u|"; markup_to[i] = "\x86"; ++i; - markup_from[i] = "&|i|"; markup_to[i] = "\x87"; ++i; - markup_from[i] = "&|c|"; markup_to[i] = "\x88"; ++i; - markup_from[i] = "&[c]"; markup_to[i] = "\x89"; ++i; - markup_from[i] = "&[n]"; markup_to[i] = "\x8a"; ++i; - markup_from[i] = "&[]"; markup_to[i] = "\x8b"; ++i; - markup_from[i] = "&r?"; markup_to[i] = "\x8c"; ++i; - markup_from[i] = "&|>"; markup_to[i] = "\x8d"; ++i; - markup_from[i] = "&splat0"; markup_to[i] = "\x8e"; ++i; - markup_from[i] = "&splat1"; markup_to[i] = "\x8f"; ++i; - markup_from[i] = "&[["; markup_to[i] = "\x90"; ++i; - markup_from[i] = "&]]"; markup_to[i] = "\x91"; ++i; - markup_from[i] = "&splat2"; markup_to[i] = "\x9a"; ++i; - markup_from[i] = "&)("; markup_to[i] = "\x9b"; ++i; - markup_from[i] = "&splat3"; markup_to[i] = "\x9c"; ++i; - markup_from[i] = "&(."; markup_to[i] = "\x9d"; ++i; - markup_from[i] = "&.."; markup_to[i] = "\x9e"; ++i; - markup_from[i] = "&.)"; markup_to[i] = "\x9f"; ++i; - markup_from[i] = "&<|"; markup_to[i] = "\xff"; ++i; + markup_from[i] = "&alien"; + markup_to[i] = "\x12"; + ++i; + markup_from[i] = "&:-)"; + markup_to[i] = "\x13"; + ++i; + markup_from[i] = "&:-("; + markup_to[i] = "\x14"; + ++i; + markup_from[i] = "&x-P"; + markup_to[i] = "\x15"; + ++i; + markup_from[i] = "&:-/"; + markup_to[i] = "\x16"; + ++i; + markup_from[i] = "&:-D"; + markup_to[i] = "\x17"; + ++i; + markup_from[i] = "&<<"; + markup_to[i] = "\x18"; + ++i; + markup_from[i] = "&>>"; + markup_to[i] = "\x19"; + ++i; + markup_from[i] = "&dot"; + markup_to[i] = "\x1a"; + ++i; + markup_from[i] = "&^_"; + markup_to[i] = "\x1b"; + ++i; + markup_from[i] = "&ysplat"; + markup_to[i] = "\x1c"; + ++i; + markup_from[i] = "&-]"; + markup_to[i] = "\x1d"; + ++i; + markup_from[i] = "&--"; + markup_to[i] = "\x1e"; + ++i; + markup_from[i] = "&[-"; + markup_to[i] = "\x1f"; + ++i; + markup_from[i] = "&s<"; + markup_to[i] = "\x2c"; + ++i; + markup_from[i] = "&s>"; + markup_to[i] = "\x2e"; + ++i; + markup_from[i] = "&<-"; + markup_to[i] = "\x7f"; + ++i; + markup_from[i] = "&[="; + markup_to[i] = "\x80"; + ++i; + markup_from[i] = "&=="; + markup_to[i] = "\x81"; + ++i; + markup_from[i] = "&=]"; + markup_to[i] = "\x82"; + ++i; + markup_from[i] = "&r!"; + markup_to[i] = "\x84"; + ++i; + markup_from[i] = "&|o|"; + markup_to[i] = "\x85"; + ++i; + markup_from[i] = "&|u|"; + markup_to[i] = "\x86"; + ++i; + markup_from[i] = "&|i|"; + markup_to[i] = "\x87"; + ++i; + markup_from[i] = "&|c|"; + markup_to[i] = "\x88"; + ++i; + markup_from[i] = "&[c]"; + markup_to[i] = "\x89"; + ++i; + markup_from[i] = "&[n]"; + markup_to[i] = "\x8a"; + ++i; + markup_from[i] = "&[]"; + markup_to[i] = "\x8b"; + ++i; + markup_from[i] = "&r?"; + markup_to[i] = "\x8c"; + ++i; + markup_from[i] = "&|>"; + markup_to[i] = "\x8d"; + ++i; + markup_from[i] = "&splat0"; + markup_to[i] = "\x8e"; + ++i; + markup_from[i] = "&splat1"; + markup_to[i] = "\x8f"; + ++i; + markup_from[i] = "&[["; + markup_to[i] = "\x90"; + ++i; + markup_from[i] = "&]]"; + markup_to[i] = "\x91"; + ++i; + markup_from[i] = "&splat2"; + markup_to[i] = "\x9a"; + ++i; + markup_from[i] = "&)("; + markup_to[i] = "\x9b"; + ++i; + markup_from[i] = "&splat3"; + markup_to[i] = "\x9c"; + ++i; + markup_from[i] = "&(."; + markup_to[i] = "\x9d"; + ++i; + markup_from[i] = "&.."; + markup_to[i] = "\x9e"; + ++i; + markup_from[i] = "&.)"; + markup_to[i] = "\x9f"; + ++i; + markup_from[i] = "&<|"; + markup_to[i] = "\xff"; + ++i; } string GenericCommand_markup(string s2) @@ -66,46 +149,35 @@ string GenericCommand_markup(string s2) red = 0; ccase = 0; - for(i = 0; i < strlen(s2); ++i) - { - for(j = 0; j < NUM_MARKUPS; ++j) - { + for (i = 0; i < strlen(s2); ++i) { + for (j = 0; j < NUM_MARKUPS; ++j) { s3 = substring(s2, i, strlen(markup_from[j])); - if (s3 == markup_from[j]) - { + if (s3 == markup_from[j]) { s = strcat(s, markup_to[j]); i += strlen(markup_from[j]) - 1; break; } } - if(j == NUM_MARKUPS) - { - if(substring(s2, i, 2) == "&&") - { + if (j == NUM_MARKUPS) { + if (substring(s2, i, 2) == "&&") { s = strcat(s, strconv(ccase, red, red, "&")); ++i; - } - else if(substring(s2, i, 2) == "&d") - { + } else if (substring(s2, i, 2) == "&d") { red = 2; ccase = 0; ++i; - } - else if(substring(s2, i, 2) == "&a") - { + } else if (substring(s2, i, 2) == "&a") { red = 2; ccase = 2; ++i; - } - else if(substring(s2, i, 2) == "&n") - { + } else if (substring(s2, i, 2) == "&n") { red = 0; ccase = 0; ++i; - } - else + } else { s = strcat(s, strconv(ccase, red, red, substring(s2, i, 1))); + } } } diff --git a/qcsrc/common/command/reg.qh b/qcsrc/common/command/reg.qh index 9868e2490..f19578ae1 100644 --- a/qcsrc/common/command/reg.qh +++ b/qcsrc/common/command/reg.qh @@ -9,11 +9,12 @@ REGISTRY_SORT(GENERIC_COMMANDS) #define GENERIC_COMMAND(id, description) \ CLASS(genericcommand_##id, Command) \ ATTRIB(genericcommand_##id, m_name, string, #id); \ - ATTRIB(genericcommand_##id, m_description, string, description); \ + ATTRIB(genericcommand_##id, m_description, string, description); \ ENDCLASS(genericcommand_##id) \ - REGISTER(GENERIC_COMMANDS, CMD_G, id, m_id, NEW(genericcommand_##id)); \ + REGISTER(GENERIC_COMMANDS, CMD_G, id, m_id, NEW(genericcommand_##id)); \ METHOD(genericcommand_##id, m_invokecmd, void(genericcommand_##id this, int request, entity caller, int arguments, string command)) -STATIC_INIT(GENERIC_COMMANDS_aliases) { +STATIC_INIT(GENERIC_COMMANDS_aliases) +{ FOREACH(GENERIC_COMMANDS, true, localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svmenu"))); } diff --git a/qcsrc/common/command/rpn.qc b/qcsrc/common/command/rpn.qc index c02b7cf5a..c457af08e 100644 --- a/qcsrc/common/command/rpn.qc +++ b/qcsrc/common/command/rpn.qc @@ -9,7 +9,7 @@ string rpn_pop() { - if(rpn_sp > 0) { + if (rpn_sp > 0) { --rpn_sp; return rpn_stack[rpn_sp]; } else { @@ -20,7 +20,7 @@ string rpn_pop() } void rpn_push(string s) { - if(rpn_sp < MAX_RPN_STACK) { + if (rpn_sp < MAX_RPN_STACK) { rpn_stack[rpn_sp] = s; ++rpn_sp; } else { @@ -30,7 +30,7 @@ void rpn_push(string s) } string rpn_get() { - if(rpn_sp > 0) { + if (rpn_sp > 0) { return rpn_stack[rpn_sp - 1]; } else { LOG_INFO("rpn: empty stack"); @@ -40,7 +40,7 @@ string rpn_get() } void rpn_set(string s) { - if(rpn_sp > 0) { + if (rpn_sp > 0) { rpn_stack[rpn_sp - 1] = s; } else { LOG_INFO("rpn: empty stack"); @@ -55,372 +55,350 @@ void rpn_setf(float f) { return rpn_set(sprintf("%.9g", f)); } void GenericCommand_rpn(float request, float argc, string command) { - switch(request) - { + switch (request) { case CMD_REQUEST_COMMAND: { float i, j, f, f2, f3, rpnpos; - //vector rgb; + // vector rgb; string s, s2, rpncmd; - if(!rpn_db) - { + if (!rpn_db) { rpn_db = db_create(); db_put(rpn_db, "stack.pointer", "0"); db_put(rpn_db, "stack.pos", "-1"); } - if(argc >= 2) - { + if (argc >= 2) { rpn_sp = 0; rpn_error = false; - for(rpnpos = 1; rpnpos < argc; ++rpnpos) - { + for (rpnpos = 1; rpnpos < argc; ++rpnpos) { rpncmd = argv(rpnpos); f = strlen(rpncmd); - if(rpncmd == "") { - } else if(stof(substring(rpncmd, 0, 1)) > 0) { + if (rpncmd == "") {} else if (stof(substring(rpncmd, 0, 1)) > 0) { rpn_push(rpncmd); - } else if(substring(rpncmd, 0, 1) == "0") { + } else if (substring(rpncmd, 0, 1) == "0") { rpn_push(rpncmd); - } else if(f >= 2 && substring(rpncmd, 0, 1) == "+") { + } else if (f >= 2 && substring(rpncmd, 0, 1) == "+") { rpn_push(rpncmd); - } else if(f >= 2 && substring(rpncmd, 0, 1) == "-") { + } else if (f >= 2 && substring(rpncmd, 0, 1) == "-") { rpn_push(rpncmd); - } else if(f >= 2 && substring(rpncmd, 0, 1) == "/") { + } else if (f >= 2 && substring(rpncmd, 0, 1) == "/") { rpn_push(substring(rpncmd, 1, strlen(rpncmd) - 1)); - } else if(rpncmd == "clear") { + } else if (rpncmd == "clear") { rpn_sp = 0; - } else if(rpncmd == "def" || rpncmd == "=") { + } else if (rpncmd == "def" || rpncmd == "=") { s = rpn_pop(); s2 = rpn_pop(); - if(s2 != "") - { + if (s2 != "") { #ifdef MENUQC registercvar(s2, "", 0); #else registercvar(s2, ""); #endif - if(!rpn_error) // don't change cvars if a stack error had happened! + if (!rpn_error) { // don't change cvars if a stack error had happened! cvar_set(s2, s); - } - else - { + } + } else { LOG_INFO("rpn: empty cvar name for 'def'"); rpn_error = true; } - } else if(rpncmd == "defs" || rpncmd == "@") { + } else if (rpncmd == "defs" || rpncmd == "@") { s = ""; i = rpn_popf(); j = (i == 0); - while(rpn_sp > 1 && (j || i > 0)) - { + while (rpn_sp > 1 && (j || i > 0)) { s = strcat("/", rpn_pop(), " ", s); --i; } s2 = rpn_pop(); - if(s2 != "") - { + if (s2 != "") { #ifdef MENUQC registercvar(s2, "", 0); #else registercvar(s2, ""); #endif - if(!rpn_error) // don't change cvars if a stack error had happened! + if (!rpn_error) { // don't change cvars if a stack error had happened! cvar_set(s2, s); - } - else - { + } + } else { LOG_INFO("rpn: empty cvar name for 'defs'"); rpn_error = true; } - } else if(rpncmd == "load") { + } else if (rpncmd == "load") { rpn_set(cvar_string(rpn_get())); - } else if(rpncmd == "exch") { + } else if (rpncmd == "exch") { s = rpn_pop(); s2 = rpn_get(); rpn_set(s); rpn_push(s2); - } else if(rpncmd == "dup") { + } else if (rpncmd == "dup") { rpn_push(rpn_get()); - } else if(rpncmd == "pop") { + } else if (rpncmd == "pop") { rpn_pop(); - } else if(rpncmd == "add" || rpncmd == "+") { + } else if (rpncmd == "add" || rpncmd == "+") { f = rpn_popf(); rpn_setf(rpn_getf() + f); - } else if(rpncmd == "sub" || rpncmd == "-") { + } else if (rpncmd == "sub" || rpncmd == "-") { f = rpn_popf(); rpn_setf(rpn_getf() - f); - } else if(rpncmd == "mul" || rpncmd == "*") { + } else if (rpncmd == "mul" || rpncmd == "*") { f = rpn_popf(); rpn_setf(rpn_getf() * f); - } else if(rpncmd == "div" || rpncmd == "/") { + } else if (rpncmd == "div" || rpncmd == "/") { f = rpn_popf(); rpn_setf(rpn_getf() / f); - } else if(rpncmd == "mod" || rpncmd == "%") { + } else if (rpncmd == "mod" || rpncmd == "%") { f = rpn_popf(); f2 = rpn_getf(); rpn_setf(f2 - f * floor(f2 / f)); - } else if(rpncmd == "pow" || rpncmd == "**") { + } else if (rpncmd == "pow" || rpncmd == "**") { f = rpn_popf(); rpn_setf(POW(rpn_getf(), f)); - } else if(rpncmd == "bitand" || rpncmd == "&") { + } else if (rpncmd == "bitand" || rpncmd == "&") { f = rpn_popf(); rpn_setf(rpn_getf() & f); - } else if(rpncmd == "bitor" || rpncmd == "|") { + } else if (rpncmd == "bitor" || rpncmd == "|") { f = rpn_popf(); rpn_setf(rpn_getf() | f); - } else if(rpncmd == "bitxor" || rpncmd == "^") { + } else if (rpncmd == "bitxor" || rpncmd == "^") { f = rpn_popf(); rpn_setf(rpn_getf() ^ f); - } else if(rpncmd == "and" || rpncmd == "&&") { + } else if (rpncmd == "and" || rpncmd == "&&") { f = rpn_popf(); rpn_setf(rpn_getf() && f); - } else if(rpncmd == "or" || rpncmd == "||") { + } else if (rpncmd == "or" || rpncmd == "||") { f = rpn_popf(); rpn_setf(rpn_getf() || f); - } else if(rpncmd == "xor" || rpncmd == "^^") { + } else if (rpncmd == "xor" || rpncmd == "^^") { f = rpn_popf(); rpn_setf(!rpn_getf() != !f); - } else if(rpncmd == "bitnot") { + } else if (rpncmd == "bitnot") { rpn_setf(~rpn_popf()); - } else if(rpncmd == "not") { + } else if (rpncmd == "not") { rpn_setf(!rpn_popf()); - } else if(rpncmd == "abs") { + } else if (rpncmd == "abs") { rpn_setf(fabs(rpn_getf())); - } else if(rpncmd == "sgn") { + } else if (rpncmd == "sgn") { f = rpn_getf(); - if(f < 0) + if (f < 0) { rpn_set("-1"); - else if(f > 0) + } else if (f > 0) { rpn_set("1"); - else + } else { rpn_set("0"); - } else if(rpncmd == "neg" || rpncmd == "~") { + } + } else if (rpncmd == "neg" || rpncmd == "~") { rpn_setf(-rpn_getf()); - } else if(rpncmd == "floor" || rpncmd == "f") { + } else if (rpncmd == "floor" || rpncmd == "f") { rpn_setf(floor(rpn_getf())); - } else if(rpncmd == "ceil" || rpncmd == "c") { + } else if (rpncmd == "ceil" || rpncmd == "c") { rpn_setf(ceil(rpn_getf())); - } else if(rpncmd == "exp") { + } else if (rpncmd == "exp") { rpn_setf(exp(rpn_getf())); - } else if(rpncmd == "log") { + } else if (rpncmd == "log") { rpn_setf(exp(rpn_getf())); - } else if(rpncmd == "sin") { + } else if (rpncmd == "sin") { rpn_setf(sin(rpn_getf())); - } else if(rpncmd == "cos") { + } else if (rpncmd == "cos") { rpn_setf(cos(rpn_getf())); - } else if(rpncmd == "max") { + } else if (rpncmd == "max") { f = rpn_popf(); f2 = rpn_getf(); rpn_setf(max(f2, f)); - } else if(rpncmd == "min") { + } else if (rpncmd == "min") { f = rpn_popf(); f2 = rpn_getf(); rpn_setf(min(f2, f)); - } else if(rpncmd == "bound") { + } else if (rpncmd == "bound") { f = rpn_popf(); f2 = rpn_popf(); f3 = rpn_getf(); rpn_setf(bound(f3, f2, f)); - } else if(rpncmd == "when") { + } else if (rpncmd == "when") { f = rpn_popf(); s = rpn_pop(); s2 = rpn_get(); - if(f) + if (f) { rpn_set(s2); - else + } else { rpn_set(s); - } else if(rpncmd == ">" || rpncmd == "gt") { + } + } else if (rpncmd == ">" || rpncmd == "gt") { f = rpn_popf(); rpn_setf(rpn_getf() > f); - } else if(rpncmd == "<" || rpncmd == "lt") { + } else if (rpncmd == "<" || rpncmd == "lt") { f = rpn_popf(); rpn_setf(rpn_getf() < f); - } else if(rpncmd == "==" || rpncmd == "eq") { + } else if (rpncmd == "==" || rpncmd == "eq") { f = rpn_popf(); rpn_setf(rpn_getf() == f); - } else if(rpncmd == ">=" || rpncmd == "ge") { + } else if (rpncmd == ">=" || rpncmd == "ge") { f = rpn_popf(); rpn_setf(rpn_getf() >= f); - } else if(rpncmd == "<=" || rpncmd == "le") { + } else if (rpncmd == "<=" || rpncmd == "le") { f = rpn_popf(); rpn_setf(rpn_getf() <= f); - } else if(rpncmd == "!=" || rpncmd == "ne") { + } else if (rpncmd == "!=" || rpncmd == "ne") { f = rpn_popf(); rpn_setf(rpn_getf() != f); - } else if(rpncmd == "rand") { + } else if (rpncmd == "rand") { rpn_setf(ceil(random() * rpn_getf()) - 1); - } else if(rpncmd == "crc16") { + } else if (rpncmd == "crc16") { rpn_setf(crc16(false, rpn_get())); - } else if(rpncmd == "put") { + } else if (rpncmd == "put") { s2 = rpn_pop(); - if (!rpn_error) - { + if (!rpn_error) { s = rpn_pop(); - if (!rpn_error) + if (!rpn_error) { db_put(rpn_db, s, s2); + } } - } else if(rpncmd == "get") { + } else if (rpncmd == "get") { s = rpn_pop(); - if (!rpn_error) + if (!rpn_error) { rpn_push(db_get(rpn_db, s)); - } else if(rpncmd == "dbpush") { + } + } else if (rpncmd == "dbpush") { s = rpn_pop(); - if(!rpn_error) - { + if (!rpn_error) { i = stof(db_get(rpn_db, "stack.pointer")); - db_put(rpn_db, "stack.pointer", ftos(i+1)); + db_put(rpn_db, "stack.pointer", ftos(i + 1)); db_put(rpn_db, strcat("stack.", ftos(i)), s); - if(!i) + if (!i) { db_put(rpn_db, "stack.pos", "0"); + } } - } else if(rpncmd == "dbpop") { + } else if (rpncmd == "dbpop") { i = stof(db_get(rpn_db, "stack.pointer")); - if(i) - { - s = ftos(i-1); + if (i) { + s = ftos(i - 1); db_put(rpn_db, "stack.pointer", s); rpn_push(db_get(rpn_db, strcat("stack.", s))); j = stof(db_get(rpn_db, "stack.pos")); - if(j >= i) - db_put(rpn_db, "stack.pos", ftos(i-2)); + if (j >= i) { + db_put(rpn_db, "stack.pos", ftos(i - 2)); + } } else { rpn_error = 1; LOG_INFO("rpn: database underflow"); } - } else if(rpncmd == "dbget") { - + } else if (rpncmd == "dbget") { i = stof(db_get(rpn_db, "stack.pointer")); - if(i) - { - rpn_push(db_get(rpn_db, strcat("stack.", ftos(i-1)))); + if (i) { + rpn_push(db_get(rpn_db, strcat("stack.", ftos(i - 1)))); } else { rpn_error = 1; LOG_INFO("rpn: database empty"); } - } else if(rpncmd == "dblen") { + } else if (rpncmd == "dblen") { rpn_push(db_get(rpn_db, "stack.pointer")); - } else if(rpncmd == "dbclr") { + } else if (rpncmd == "dbclr") { db_close(rpn_db); rpn_db = db_create(); db_put(rpn_db, "stack.pointer", "0"); db_put(rpn_db, "stack.pos", "-1"); - } else if(rpncmd == "dbsave") { + } else if (rpncmd == "dbsave") { s = rpn_pop(); - if(!rpn_error) + if (!rpn_error) { db_save(rpn_db, s); - } else if(rpncmd == "dbload") { + } + } else if (rpncmd == "dbload") { s = rpn_pop(); - if(!rpn_error) - { + if (!rpn_error) { db_close(rpn_db); rpn_db = db_load(s); } - } else if(rpncmd == "dbins") { + } else if (rpncmd == "dbins") { s = rpn_pop(); - if(!rpn_error) - //if(rpn_sp > 0) - { + if (!rpn_error) { + // if(rpn_sp > 0) j = stof(db_get(rpn_db, "stack.pointer")); i = stof(db_get(rpn_db, "stack.pos")); - if(i < 0) - { + if (i < 0) { i = 0; db_put(rpn_db, "stack.pos", "0"); } - db_put(rpn_db, "stack.pointer", ftos(j+1)); - for(--j; j >= i; --j) - { - db_put(rpn_db, strcat("stack.", ftos(j+1)), - db_get(rpn_db, (strcat("stack.", ftos(j)))) - ); + db_put(rpn_db, "stack.pointer", ftos(j + 1)); + for (--j; j >= i; --j) { + db_put(rpn_db, strcat("stack.", ftos(j + 1)), + db_get(rpn_db, (strcat("stack.", ftos(j)))) + ); } db_put(rpn_db, strcat("stack.", ftos(i)), s); } - } else if(rpncmd == "dbext") { + } else if (rpncmd == "dbext") { j = stof(db_get(rpn_db, "stack.pointer")); i = stof(db_get(rpn_db, "stack.pos")); - if(!j) - { + if (!j) { rpn_error = true; LOG_INFO("rpn: empty database"); } else { --j; rpn_push(db_get(rpn_db, strcat("stack.", ftos(i)))); db_put(rpn_db, "stack.pointer", ftos(j)); - if(i == j) - { - db_put(rpn_db, "stack.pos", ftos(j-1)); + if (i == j) { + db_put(rpn_db, "stack.pos", ftos(j - 1)); } else { - while(i < j) - { + while (i < j) { db_put(rpn_db, strcat("stack.", ftos(i)), - db_get(rpn_db, (strcat("stack.", ftos(i+1)))) - ); + db_get(rpn_db, (strcat("stack.", ftos(i + 1)))) + ); ++i; } } } - } else if(rpncmd == "dbread") { + } else if (rpncmd == "dbread") { s = db_get(rpn_db, "stack.pos"); - if(stof(s) >= 0) - { + if (stof(s) >= 0) { rpn_push(db_get(rpn_db, strcat("stack.", s))); } else { rpn_error = 1; LOG_INFO("rpn: empty database"); } - } else if(rpncmd == "dbat") { + } else if (rpncmd == "dbat") { rpn_push(db_get(rpn_db, "stack.pos")); - } else if(rpncmd == "dbmov") { + } else if (rpncmd == "dbmov") { j = stof(db_get(rpn_db, "stack.pointer")); i = stof(db_get(rpn_db, "stack.pos")); i += rpn_popf(); - if(!rpn_error) - { - if(i < 0 || i >= j) - { + if (!rpn_error) { + if (i < 0 || i >= j) { LOG_INFO("rpn: database cursor out of bounds"); rpn_error = true; } - if(!rpn_error) - { + if (!rpn_error) { db_put(rpn_db, "stack.pos", ftos(i)); } } - } else if(rpncmd == "dbgoto") { + } else if (rpncmd == "dbgoto") { s = rpn_pop(); j = stof(db_get(rpn_db, "stack.pointer")); - if(!j) - { + if (!j) { rpn_error = true; LOG_INFO("rpn: empty database, cannot move cursor"); } - if(!rpn_error) - { - if(s == "end") - i = stof(db_get(rpn_db, "stack.pointer"))-1; - else if(s == "beg") + if (!rpn_error) { + if (s == "end") { + i = stof(db_get(rpn_db, "stack.pointer")) - 1; + } else if (s == "beg") { i = 0; - else + } else { i = stof(s); + } j = stof(db_get(rpn_db, "stack.pointer")); - if(i < 0 || i >= j) - { + if (i < 0 || i >= j) { LOG_INFO("rpn: database cursor destination out of bounds"); rpn_error = true; } - if(!rpn_error) - { + if (!rpn_error) { db_put(rpn_db, "stack.pos", ftos(i)); } } - } else if(rpncmd == "union") { + } else if (rpncmd == "union") { // s s2 union s2 = rpn_pop(); s = rpn_get(); @@ -430,20 +408,24 @@ void GenericCommand_rpn(float request, float argc, string command) // tokens f..f2 represent s2 // UNION: add all tokens to s that are in s2 but not in s s = ""; - for(i = 0; i < f; ++i) + for (i = 0; i < f; ++i) { s = strcat(s, " ", argv(i)); - for(i = f; i < f2; ++i) { - for(j = 0; j < f; ++j) - if(argv(i) == argv(j)) + } + for (i = f; i < f2; ++i) { + for (j = 0; j < f; ++j) { + if (argv(i) == argv(j)) { goto skip_union; + } + } s = strcat(s, " ", argv(i)); -LABEL(skip_union) + LABEL(skip_union) } - if(substring(s, 0, 1) == " ") + if (substring(s, 0, 1) == " ") { s = substring(s, 1, 99999); + } rpn_set(s); tokenize_console(command); - } else if(rpncmd == "intersection") { + } else if (rpncmd == "intersection") { // s s2 intersection s2 = rpn_pop(); s = rpn_get(); @@ -453,19 +435,20 @@ LABEL(skip_union) // tokens f..f2 represent s2 // INTERSECTION: keep only the tokens from s that are also in s2 s = ""; - for(i = 0; i < f; ++i) { - for(j = f; j < f2; ++j) - if(argv(i) == argv(j)) - { + for (i = 0; i < f; ++i) { + for (j = f; j < f2; ++j) { + if (argv(i) == argv(j)) { s = strcat(s, " ", argv(i)); break; } + } } - if(substring(s, 0, 1) == " ") + if (substring(s, 0, 1) == " ") { s = substring(s, 1, 99999); + } rpn_set(s); tokenize_console(command); - } else if(rpncmd == "difference") { + } else if (rpncmd == "difference") { // s s2 difference s2 = rpn_pop(); s = rpn_get(); @@ -475,71 +458,76 @@ LABEL(skip_union) // tokens f..f2 represent s2 // DIFFERENCE: keep only the tokens from s that are not in s2 s = ""; - for(i = 0; i < f; ++i) { - for(j = f; j < f2; ++j) - if(argv(i) == argv(j)) + for (i = 0; i < f; ++i) { + for (j = f; j < f2; ++j) { + if (argv(i) == argv(j)) { goto skip_difference; + } + } s = strcat(s, " ", argv(i)); -LABEL(skip_difference) + LABEL(skip_difference) } - if(substring(s, 0, 1) == " ") + if (substring(s, 0, 1) == " ") { s = substring(s, 1, 99999); + } rpn_set(s); tokenize_console(command); - } else if(rpncmd == "shuffle") { + } else if (rpncmd == "shuffle") { // s shuffle s = rpn_get(); f = tokenize_console(s); - for(i = 0; i < f - 1; ++i) { + for (i = 0; i < f - 1; ++i) { // move a random item from i..f-1 to position i s = ""; f2 = floor(random() * (f - i) + i); - for(j = 0; j < i; ++j) + for (j = 0; j < i; ++j) { s = strcat(s, " ", argv(j)); + } s = strcat(s, " ", argv(f2)); - for(j = i; j < f; ++j) - if(j != f2) + for (j = i; j < f; ++j) { + if (j != f2) { s = strcat(s, " ", argv(j)); + } + } f = tokenize_console(s); } - if(substring(s, 0, 1) == " ") + if (substring(s, 0, 1) == " ") { s = substring(s, 1, 99999); + } rpn_set(s); tokenize_console(command); - } else if(rpncmd == "fexists_assert") { + } else if (rpncmd == "fexists_assert") { s = rpn_pop(); - if(!rpn_error) - { - if (!fexists(s)) - { + if (!rpn_error) { + if (!fexists(s)) { LOG_INFO("rpn: ERROR: ", s, " does not exist!"); rpn_error = true; } } - } else if(rpncmd == "fexists") { + } else if (rpncmd == "fexists") { s = rpn_get(); - if(!rpn_error) - { - if (fexists(s)) + if (!rpn_error) { + if (fexists(s)) { rpn_setf(1); - else + } else { rpn_setf(0); + } } - } else if(rpncmd == "localtime") { + } else if (rpncmd == "localtime") { rpn_set(strftime(true, rpn_get())); - } else if(rpncmd == "gmtime") { + } else if (rpncmd == "gmtime") { rpn_set(strftime(false, rpn_get())); - } else if(rpncmd == "time") { + } else if (rpncmd == "time") { rpn_pushf(time); - } else if(rpncmd == "digest") { + } else if (rpncmd == "digest") { s = rpn_pop(); rpn_set(digest_hex(s, rpn_get())); - } else if(rpncmd == "sprintf1s") { + } else if (rpncmd == "sprintf1s") { s = rpn_pop(); rpn_set(sprintf(s, rpn_get())); - } else if(rpncmd == "eval") { + } else if (rpncmd == "eval") { s = rpn_pop(); command = strcat(s, substring(command, argv_end_index(rpnpos), -1)); argc = tokenize_console(command); @@ -547,11 +535,11 @@ LABEL(skip_difference) } else { rpn_push(cvar_string(rpncmd)); } - if(rpn_error) + if (rpn_error) { break; + } } - while(rpn_sp > 0) - { + while (rpn_sp > 0) { s = rpn_pop(); LOG_INFO("rpn: still on stack: ", s); } diff --git a/qcsrc/common/csqcmodel_settings.qh b/qcsrc/common/csqcmodel_settings.qh index 125ef6bf3..12c367b2f 100644 --- a/qcsrc/common/csqcmodel_settings.qh +++ b/qcsrc/common/csqcmodel_settings.qh @@ -1,29 +1,29 @@ #pragma once // define this if svqc code wants to use .frame2 and .lerpfrac -//#define CSQCMODEL_HAVE_TWO_FRAMES +// #define CSQCMODEL_HAVE_TWO_FRAMES // don't define this ever -//#define CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW +// #define CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW // server decides crouching, this lags, but so be it -//#define CSQCMODEL_SERVERSIDE_CROUCH +// #define CSQCMODEL_SERVERSIDE_CROUCH // a hack for Xonotic #ifdef CSQC -# define TAG_ENTITY_NAME tag_networkentity -# define TAG_ENTITY_TYPE float +#define TAG_ENTITY_NAME tag_networkentity +#define TAG_ENTITY_TYPE float .float tag_networkentity; -# define TAG_VIEWLOC_NAME tag_networkviewloc -# define TAG_VIEWLOC_TYPE int +#define TAG_VIEWLOC_NAME tag_networkviewloc +#define TAG_VIEWLOC_TYPE int .float tag_networkviewloc; #else -# define TAG_ENTITY_NAME tag_entity -# define TAG_ENTITY_TYPE entity +#define TAG_ENTITY_NAME tag_entity +#define TAG_ENTITY_TYPE entity -# define TAG_VIEWLOC_NAME viewloc -# define TAG_VIEWLOC_TYPE entity +#define TAG_VIEWLOC_NAME viewloc +#define TAG_VIEWLOC_TYPE entity #endif // add properties you want networked to CSQC here @@ -36,23 +36,23 @@ CSQCMODEL_PROPERTY(BIT(5), float, ReadApproxPastTime, WriteApproxPastTime, death_time) \ CSQCMODEL_PROPERTY(BIT(6), float, ReadByte, WriteByte, solid) \ CSQCMODEL_IF(!isplayer) \ - CSQCMODEL_PROPERTY(BIT(7), TAG_ENTITY_TYPE, ReadShort, WriteEntity, TAG_ENTITY_NAME) \ - CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, glowmod_x, 254, -1, 254) \ - CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, glowmod_y, 254, -1, 254) \ - CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, glowmod_z, 254, -1, 254) \ - CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, colormod_x, 254, -1, 254) \ - CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, colormod_y, 254, -1, 254) \ - CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, colormod_z, 254, -1, 254) \ + CSQCMODEL_PROPERTY(BIT(7), TAG_ENTITY_TYPE, ReadShort, WriteEntity, TAG_ENTITY_NAME) \ + CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, glowmod_x, 254, -1, 254) \ + CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, glowmod_y, 254, -1, 254) \ + CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, glowmod_z, 254, -1, 254) \ + CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, colormod_x, 254, -1, 254) \ + CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, colormod_y, 254, -1, 254) \ + CSQCMODEL_PROPERTY_SCALED(BIT(8), float, ReadByte, WriteByte, colormod_z, 254, -1, 254) \ CSQCMODEL_ENDIF \ CSQCMODEL_IF(isplayer) \ - CSQCMODEL_PROPERTY(BIT(7), int, ReadByte, WriteByte, anim_state) \ - CSQCMODEL_PROPERTY(BIT(7), float, ReadApproxPastTime, WriteApproxPastTime, anim_time) \ - CSQCMODEL_IF(!islocalplayer) \ - CSQCMODEL_PROPERTY(BIT(8), float, ReadChar, WriteChar, anim_lower_action) \ - CSQCMODEL_PROPERTY(BIT(8), float, ReadApproxPastTime, WriteApproxPastTime, anim_lower_time) \ - CSQCMODEL_ENDIF \ - CSQCMODEL_PROPERTY(BIT(9), float, ReadChar, WriteChar, anim_upper_action) \ - CSQCMODEL_PROPERTY(BIT(9), float, ReadApproxPastTime, WriteApproxPastTime, anim_upper_time) \ + CSQCMODEL_PROPERTY(BIT(7), int, ReadByte, WriteByte, anim_state) \ + CSQCMODEL_PROPERTY(BIT(7), float, ReadApproxPastTime, WriteApproxPastTime, anim_time) \ + CSQCMODEL_IF(!islocalplayer) \ + CSQCMODEL_PROPERTY(BIT(8), float, ReadChar, WriteChar, anim_lower_action) \ + CSQCMODEL_PROPERTY(BIT(8), float, ReadApproxPastTime, WriteApproxPastTime, anim_lower_time) \ + CSQCMODEL_ENDIF \ + CSQCMODEL_PROPERTY(BIT(9), float, ReadChar, WriteChar, anim_upper_action) \ + CSQCMODEL_PROPERTY(BIT(9), float, ReadApproxPastTime, WriteApproxPastTime, anim_upper_time) \ CSQCMODEL_ENDIF \ CSQCMODEL_PROPERTY(BIT(10), float, ReadAngle, WriteAngle, v_angle_x) \ CSQCMODEL_PROPERTY(BIT(11), int, ReadByte, WriteByte, traileffect) \ @@ -73,16 +73,16 @@ #endif // mod must define: -//vector PL_MIN = ...; -//vector PL_MAX = ...; -//vector PL_VIEW_OFS = ...; -//vector PL_CROUCH_MIN = ...; -//vector PL_CROUCH_MAX = ...; -//vector PL_CROUCH_VIEW_OFS = ...; +// vector PL_MIN = ...; +// vector PL_MAX = ...; +// vector PL_VIEW_OFS = ...; +// vector PL_CROUCH_MIN = ...; +// vector PL_CROUCH_MAX = ...; +// vector PL_CROUCH_VIEW_OFS = ...; #ifdef SVQC -# define CSQCMODEL_AUTOINIT(e) CSQCModel_LinkEntity(e) -# define CSQCMODEL_AUTOUPDATE(e) CSQCModel_CheckUpdate(e) +#define CSQCMODEL_AUTOINIT(e) CSQCModel_LinkEntity(e) +#define CSQCMODEL_AUTOUPDATE(e) CSQCModel_CheckUpdate(e) #endif #define CSQCMODEL_EF_RESPAWNGHOST EF_SELECTABLE diff --git a/qcsrc/common/deathtypes/all.qh b/qcsrc/common/deathtypes/all.qh index 0466c230a..abe1765bd 100644 --- a/qcsrc/common/deathtypes/all.qh +++ b/qcsrc/common/deathtypes/all.qh @@ -14,13 +14,14 @@ REGISTRY_CHECK(Deathtypes) int dt_identity(int i) { return i; } #define REGISTER_DEATHTYPE(id, msg_death, msg_death_by, extra) \ - REGISTER(Deathtypes, DEATH, id, m_id, new_pure(deathtype)) { \ - this.m_id += DT_FIRST; \ - this.nent_name = #id; \ - this.death_msgextra = extra; \ - this.death_msgself = msg_death; \ - this.death_msgmurder = msg_death_by; \ - } + REGISTER(Deathtypes, DEATH, id, m_id, new_pure(deathtype)) \ + { \ + this.m_id += DT_FIRST; \ + this.nent_name = #id; \ + this.death_msgextra = extra; \ + this.death_msgself = msg_death; \ + this.death_msgmurder = msg_death_by; \ + } const int DEATH_WEAPONMASK = BITS(8); const int HITTYPE_SECONDARY = BITS(1) << 8; @@ -34,14 +35,14 @@ const int DEATH_HITTYPEMASK = HITTYPE_SECONDARY | HITTYPE_SPLASH | HITTYPE_BOUNC // normal deaths begin const int DT_FIRST = BIT(13); -#define DEATH_ISSPECIAL(t) (t >= DT_FIRST) -#define DEATH_IS(t, dt) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)) == dt) -#define DEATH_ENT(t) (DEATH_ISSPECIAL(t) ? (Deathtypes_from(t - DT_FIRST)) : NULL) -#define DEATH_ISVEHICLE(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "vehicle") -#define DEATH_ISTURRET(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "turret") -#define DEATH_ISMONSTER(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "monster") -#define DEATH_WEAPONOF(t) (DEATH_ISSPECIAL(t) ? WEP_Null : Weapons_from((t) & DEATH_WEAPONMASK)) -#define DEATH_ISWEAPON(t, w) (DEATH_WEAPONOF(t) == (w)) +#define DEATH_ISSPECIAL(t) (t >= DT_FIRST) +#define DEATH_IS(t, dt) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)) == dt) +#define DEATH_ENT(t) (DEATH_ISSPECIAL(t) ? (Deathtypes_from(t - DT_FIRST)) : NULL) +#define DEATH_ISVEHICLE(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "vehicle") +#define DEATH_ISTURRET(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "turret") +#define DEATH_ISMONSTER(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "monster") +#define DEATH_WEAPONOF(t) (DEATH_ISSPECIAL(t) ? WEP_Null : Weapons_from((t) & DEATH_WEAPONMASK)) +#define DEATH_ISWEAPON(t, w) (DEATH_WEAPONOF(t) == (w)) string Deathtype_Name(int deathtype); diff --git a/qcsrc/common/debug.qh b/qcsrc/common/debug.qh index 0200883b8..1efdc722b 100644 --- a/qcsrc/common/debug.qh +++ b/qcsrc/common/debug.qh @@ -11,40 +11,44 @@ REGISTER_NET_TEMP(net_debug) #endif #ifdef CSQC - NET_HANDLE(net_debug, bool isNew) - { - Net_Accept(net_debug); - this.sv_entnum = ReadShort(); - if (ReadByte()) make_pure(this); - this.origin_x = ReadCoord(); - this.origin_y = ReadCoord(); - this.origin_z = ReadCoord(); - setorigin(this, this.origin); - this.debug = true; // identify server entities by this - this.classname = strzone(ReadString()); - this.sourceLoc = strzone(ReadString()); - return true; - } +NET_HANDLE(net_debug, bool isNew) +{ + Net_Accept(net_debug); + this.sv_entnum = ReadShort(); + if (ReadByte()) { make_pure(this); } + this.origin_x = ReadCoord(); + this.origin_y = ReadCoord(); + this.origin_z = ReadCoord(); + setorigin(this, this.origin); + this.debug = true; // identify server entities by this + this.classname = strzone(ReadString()); + this.sourceLoc = strzone(ReadString()); + return true; +} #endif #ifdef SVQC - bool debug_send(entity this, entity to, int sf) - { - int channel = MSG_ONE; - msg_entity = to; - WriteHeader(channel, net_debug); - WriteShort(channel, etof(this)); - WriteByte(channel, is_pure(this)); - vector o = this.origin; - if (o == '0 0 0') // brushes - o = (this.absmin + this.absmax) / 2; - if (this.tag_entity) - o += this.tag_entity.origin; - WriteCoord(channel, o.x); WriteCoord(channel, o.y); WriteCoord(channel, o.z); - WriteString(channel, this.classname); - WriteString(channel, this.sourceLoc); - return true; +bool debug_send(entity this, entity to, int sf) +{ + int channel = MSG_ONE; + msg_entity = to; + WriteHeader(channel, net_debug); + WriteShort(channel, etof(this)); + WriteByte(channel, is_pure(this)); + vector o = this.origin; + if (o == '0 0 0') { // brushes + o = (this.absmin + this.absmax) / 2; + } + if (this.tag_entity) { + o += this.tag_entity.origin; } + WriteCoord(channel, o.x); + WriteCoord(channel, o.y); + WriteCoord(channel, o.z); + WriteString(channel, this.classname); + WriteString(channel, this.sourceLoc); + return true; +} #endif #if ENABLE_DEBUGDRAW @@ -62,39 +66,34 @@ bool autocvar_debugdraw; #endif #ifdef CSQC - string autocvar_debugdraw_filter, autocvar_debugdraw_filterout; - .int debugdraw_last; - vector project_3d_to_2d(vector vec); - void Debug_Draw() - { - if (!autocvar_debugdraw) return; - static int debugdraw_frame; - ++debugdraw_frame; - const int sz = 8; - FOREACH_ENTITY(true, { - if (it.debugdraw_last == debugdraw_frame) continue; - int ofs = 0; - FOREACH_ENTITY_RADIUS(it.origin, 100, it.debugdraw_last != debugdraw_frame, { - it.debugdraw_last = debugdraw_frame; - vector rgb = (it.debug) ? '0 0 1' : '1 0 0'; - if (autocvar_debugdraw_filterout != "" && strhasword(autocvar_debugdraw_filterout, it.classname)) continue; - if (autocvar_debugdraw_filter != "" && !strhasword(autocvar_debugdraw_filter, it.classname)) continue; - if (autocvar_debugdraw == 3) - { - if (!it.entnum) continue; - } - if (autocvar_debugdraw == 4) - { - if (it.origin) continue; - } - if (autocvar_debugdraw == 5) - { - if (!it.debug) continue; - } - else if (autocvar_debugdraw > 5) - { - bool flag = true; - do { +string autocvar_debugdraw_filter, autocvar_debugdraw_filterout; +.int debugdraw_last; +vector project_3d_to_2d(vector vec); +void Debug_Draw() +{ + if (!autocvar_debugdraw) { return; } + static int debugdraw_frame; + ++debugdraw_frame; + const int sz = 8; + FOREACH_ENTITY(true, { + if (it.debugdraw_last == debugdraw_frame) { continue; } + int ofs = 0; + FOREACH_ENTITY_RADIUS(it.origin, 100, it.debugdraw_last != debugdraw_frame, { + it.debugdraw_last = debugdraw_frame; + vector rgb = (it.debug) ? '0 0 1' : '1 0 0'; + if (autocvar_debugdraw_filterout != "" && strhasword(autocvar_debugdraw_filterout, it.classname)) { continue; } + if (autocvar_debugdraw_filter != "" && !strhasword(autocvar_debugdraw_filter, it.classname)) { continue; } + if (autocvar_debugdraw == 3) { + if (!it.entnum) { continue; } + } + if (autocvar_debugdraw == 4) { + if (it.origin) { continue; } + } + if (autocvar_debugdraw == 5) { + if (!it.debug) { continue; } + } else if (autocvar_debugdraw > 5) { + bool flag = true; + do { // if (it.modelindex) break; // if (it.absmin) break; // if (it.absmax) break; @@ -102,7 +101,7 @@ bool autocvar_debugdraw; // if (it.drawmask) break; // if (it.predraw) break; // if (it.move_movetype) break; - if (it.solid) break; + if (it.solid) { break; } // if (it.origin) break; // if (it.oldorigin) break; // if (it.velocity) break; @@ -127,68 +126,64 @@ bool autocvar_debugdraw; // if (it.flags) break; // if (it.colormap) break; // if (it.owner) break; - flag = false; - } while (0); - if (!flag) continue; - } - else if (is_pure(it)) - { - if (autocvar_debugdraw < 2) continue; - rgb.y = 1; - } - vector o = it.origin; - if (it.tag_entity) - o += it.tag_entity.origin; - vector pos = project_3d_to_2d(o); - if (pos.z < 0) continue; - pos.z = 0; - pos.y += ofs * sz; - drawcolorcodedstring2_builtin(pos, - sprintf("%d: '%s'@%s", (it.debug ? it.sv_entnum : etof(it)), - it.classname, it.sourceLoc), - sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL); - ++ofs; - }); + flag = false; + } while (0); + if (!flag) { continue; } + } else if (is_pure(it)) { + if (autocvar_debugdraw < 2) { continue; } + rgb.y = 1; + } + vector o = it.origin; + if (it.tag_entity) { + o += it.tag_entity.origin; + } + vector pos = project_3d_to_2d(o); + if (pos.z < 0) { continue; } + pos.z = 0; + pos.y += ofs * sz; + drawcolorcodedstring2_builtin(pos, + sprintf("%d: '%s'@%s", (it.debug ? it.sv_entnum : etof(it)), + it.classname, it.sourceLoc), + sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL); + ++ofs; }); - } + }); +} #endif #ifdef SVQC - COMMON_COMMAND(debugdraw_sv, "Dump all server entities") - { - switch (request) +COMMON_COMMAND(debugdraw_sv, "Dump all server entities") +{ + switch (request) { + case CMD_REQUEST_COMMAND: { - case CMD_REQUEST_COMMAND: - { - if (!autocvar_debugdraw) return; - int n = 1000; - int rem = n; - for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; ) - { - if (autocvar_debugdraw < 2 && is_pure(e)) continue; - debug_send(e, caller, 0); - e.debug = true; - --rem; - } - LOG_INFOF("%d server entities sent", n - rem); - return; + if (!autocvar_debugdraw) { return; } + int n = 1000; + int rem = n; + for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; ) { + if (autocvar_debugdraw < 2 && is_pure(e)) { continue; } + debug_send(e, caller, 0); + e.debug = true; + --rem; } + LOG_INFOF("%d server entities sent", n - rem); + return; + } - default: - case CMD_REQUEST_USAGE: - { - LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " debugdraw_sv"); - return; - } + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " debugdraw_sv"); + return; } } +} #endif #endif GENERIC_COMMAND(bufstr_get, "Examine a string buffer object") { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { int bufhandle = stof(argv(1)); @@ -209,8 +204,7 @@ GENERIC_COMMAND(bufstr_get, "Examine a string buffer object") GENERIC_COMMAND(version, "Print the current version") { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { LOG_INFO(WATERMARK); @@ -230,8 +224,7 @@ void(float bufhandle, string pattern, string antipattern) buf_cvarlist = #517; #endif GENERIC_COMMAND(cvar_localchanges, "Print locally changed cvars") { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { string s = ""; @@ -242,8 +235,9 @@ GENERIC_COMMAND(cvar_localchanges, "Print locally changed cvars") string k = bufstr_get(h, i); string v = cvar_string(k); string d = cvar_defstring(k); - if (v == d) + if (v == d) { continue; + } s = strcat(s, k, " \"", v, "\" // \"", d, "\"\n"); } buf_del(h); @@ -273,25 +267,27 @@ MUTATOR_HOOKFUNCTION(trace, SV_StartFrame) FOREACH_CLIENT(true, { bool skip = false; bool btn = PHYS_INPUT_BUTTON_HOOK(it); - if (btn == it.debug_trace_button) skip = true; + if (btn == it.debug_trace_button) { skip = true; } it.debug_trace_button = btn; - if (!btn || skip) continue; + if (!btn || skip) { continue; } FOREACH_ENTITY(true, { - it.solid_prev = it.solid; + it.solid_prev = it.solid; it.solid = SOLID_BBOX; }); - vector forward = '0 0 0'; vector right = '0 0 0'; vector up = '0 0 0'; + vector forward = '0 0 0'; + vector right = '0 0 0'; + vector up = '0 0 0'; MAKEVECTORS(makevectors, it.v_angle, forward, right, up); vector pos = it.origin + it.view_ofs; traceline(pos, pos + forward * max_shot_distance, MOVE_NORMAL, it); FOREACH_ENTITY(true, { - it.solid = it.solid_prev; - it.solid_prev = 0; + it.solid = it.solid_prev; + it.solid_prev = 0; }); entity e = trace_ent; int i = etof(e); STAT(TRACE_ENT, it) = i; - if (!e) continue; + if (!e) { continue; } setorigin(e, e.origin + '0 0 100'); stuffcmd(it, sprintf("prvm_edict server %d\n", i)); }); @@ -302,7 +298,7 @@ entity TRACE_ENT; void Trace_draw2d(entity this) { int e = STAT(TRACE_ENT); - if (!e) return; + if (!e) { return; } vector pos = '0 0 0'; pos.y += vid_conheight / 2; drawstring(pos, sprintf("prvm_edict server %d", e), '10 10 0', '1 1 1', 1, DRAWFLAG_NORMAL); @@ -319,8 +315,7 @@ STATIC_INIT(TRACE_ENT) GENERIC_COMMAND(find, "Search through entities for matching classname") { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { int entcnt = 0; @@ -329,15 +324,16 @@ GENERIC_COMMAND(find, "Search through entities for matching classname") LOG_INFOF("%i (%s)", it, it.classname); ++entcnt; }); - if(entcnt) + if (entcnt) { LOG_INFOF("Found %d entities", entcnt); + } return; } default: { LOG_INFO("Incorrect parameters for ^2find^7"); - } + } case CMD_REQUEST_USAGE: { LOG_INFO("Usage:^3 " GetProgramCommandPrefix() " find classname"); @@ -349,12 +345,11 @@ GENERIC_COMMAND(find, "Search through entities for matching classname") GENERIC_COMMAND(findat, "Search through entities for matching origin") { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - vector match = stov(argv(1)); - FOREACH_ENTITY_ORDERED(it.origin == match, LOG_INFOF("%i (%s)", it, it.classname)); + vector match = stov(argv(1)); + FOREACH_ENTITY_ORDERED(it.origin == match, LOG_INFOF("%i (%s)", it, it.classname)); return; } diff --git a/qcsrc/common/effects/all.qc b/qcsrc/common/effects/all.qc index af41054e3..a1f9d67de 100644 --- a/qcsrc/common/effects/all.qc +++ b/qcsrc/common/effects/all.qc @@ -17,20 +17,21 @@ NET_HANDLE(net_effect, bool isNew) v_z = ReadCoord(); bool use_vel = ReadByte(); - if(use_vel) - { + if (use_vel) { vel_x = ReadCoord(); vel_y = ReadCoord(); vel_z = ReadCoord(); } - if(!eff_trail) + if (!eff_trail) { eff_cnt = ReadByte(); + } - if(eff_trail) + if (eff_trail) { WarpZone_TrailParticles(NULL, particleeffectnum(eff), v, vel); - else + } else { pointparticles(eff, v, vel, eff_cnt); + } return true; } #endif @@ -49,26 +50,24 @@ bool Net_Write_Effect(entity this, entity client, int sf) WriteCoord(channel, this.eent_net_location_z); // attempt to save a tiny bit more bandwidth by not sending velocity if it isn't set - if(this.eent_net_velocity) - { + if (this.eent_net_velocity) { WriteByte(channel, true); WriteCoord(channel, this.eent_net_velocity_x); WriteCoord(channel, this.eent_net_velocity_y); WriteCoord(channel, this.eent_net_velocity_z); - } - else { WriteByte(channel, false); } + } else { WriteByte(channel, false); } - if(!this.eent_eff_trail) { WriteByte(channel, this.eent_net_count); } + if (!this.eent_eff_trail) { WriteByte(channel, this.eent_net_count); } return true; } void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt) { - if(!eff) { return; } - if(!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count! + if (!eff) { return; } + if (!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count! entity net_eff = new_pure(net_effect); net_eff.owner = eff; - //net_eff.eent_broadcast = broadcast; + // net_eff.eent_broadcast = broadcast; net_eff.m_id = eff.m_id; net_eff.eent_net_velocity = eff_vel; net_eff.eent_net_location = eff_loc; diff --git a/qcsrc/common/effects/all.qh b/qcsrc/common/effects/all.qh index 758161837..105d2c452 100644 --- a/qcsrc/common/effects/all.qh +++ b/qcsrc/common/effects/all.qh @@ -12,7 +12,7 @@ REGISTRY(Effects, BITS(8)) REGISTER_REGISTRY(Effects) REGISTRY_CHECK(Effects) #define EFFECT(istrail, name, realname) \ - REGISTER(Effects, EFFECT, name, m_id, Create_Effect_Entity(realname, istrail)); + REGISTER(Effects, EFFECT, name, m_id, Create_Effect_Entity(realname, istrail)); EFFECT(0, Null, string_null) #include "all.inc" diff --git a/qcsrc/common/effects/effect.qh b/qcsrc/common/effects/effect.qh index 7802f0a91..51df007aa 100644 --- a/qcsrc/common/effects/effect.qh +++ b/qcsrc/common/effects/effect.qh @@ -5,15 +5,15 @@ #if defined(SVQC) #define pointparticles(effect, org, vel, howmany) \ - Send_Effect(effect, org, vel, howmany) + Send_Effect(effect, org, vel, howmany) #define trailparticles(e, effect, org, vel) \ - ((!e) ? Send_Effect(effect, org, vel, 0) \ - : __trailparticles(e, particleeffectnum(effect), org, vel)) + ((!e) ? Send_Effect(effect, org, vel, 0) \ + : __trailparticles(e, particleeffectnum(effect), org, vel)) #elif defined(CSQC) #define pointparticles(effect, org, vel, howmany) \ - __pointparticles(particleeffectnum(effect), org, vel, howmany) + __pointparticles(particleeffectnum(effect), org, vel, howmany) #define trailparticles(e, effect, org, vel) \ - __trailparticles(e, particleeffectnum(effect), org, vel) + __trailparticles(e, particleeffectnum(effect), org, vel) #endif .int m_id; diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index 89f2bc42a..298a48032 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -1,325 +1,295 @@ #include "effectinfo.qh" #define EFFECTINFO_PARSER(on, MY) \ - on(type, MY(type) \ - ,{ demand(n == 1 && "type"); MY(type) = strzone(argv(1)); \ - }, sprintf(" %s", (MY(type)) \ - )) \ - on(airfriction, MY(airfriction) \ - ,{ demand(n == 1 && "airfriction"); MY(airfriction) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(airfriction)) \ - )) \ - on(alpha, MY(alpha_min) || MY(alpha_max) || MY(alpha_fade) \ - ,{ demand(n == 3 && "alpha"); MY(alpha_min) = stof(argv(1)); MY(alpha_max) = stof(argv(2)); MY(alpha_fade) = stof(argv(3)); \ - }, sprintf(" %s %s %s", ftos(MY(alpha_min)), ftos(MY(alpha_max)), ftos(MY(alpha_fade)) \ - )) \ - on(blend, MY(blend) \ - ,{ demand(n == 1 && "blend"); MY(blend) = strzone(argv(1)); \ - }, sprintf(" %s", (MY(blend)) \ - )) \ - on(bounce, MY(bounce) \ - ,{ demand(n == 1 && "bounce"); MY(bounce) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(bounce)) \ - )) \ - on(color, MY(color_min) || MY(color_max) \ - ,{ demand(n == 2 && "color"); MY(color_min) = strzone(argv(1)); MY(color_max) = strzone(argv(2)); \ - }, sprintf(" %s %s", (MY(color_min)), (MY(color_max)) \ - )) \ - on(countabsolute, MY(countabsolute) \ - ,{ demand(n == 1 && "countabsolute"); MY(countabsolute) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(countabsolute)) \ - )) \ - on(count, MY(count) \ - ,{ demand(n == 1 && "count"); MY(count) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(count)) \ - )) \ - on(gravity, MY(gravity) \ - ,{ demand(n == 1 && "gravity"); MY(gravity) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(gravity)) \ - )) \ - on(lightcolor, MY(lightcolor) \ - ,{ demand(n == 3 && "lightcolor"); MY(lightcolor) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); \ - }, sprintf(" %v", (MY(lightcolor)) \ - )) \ - on(lightradiusfade, MY(lightradiusfade) \ - ,{ demand(n == 1 && "lightradiusfade"); MY(lightradiusfade) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(lightradiusfade)) \ - )) \ - on(lightradius, MY(lightradius) \ - ,{ demand(n == 1 && "lightradius"); MY(lightradius) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(lightradius)) \ - )) \ - on(lighttime, MY(lighttime) \ - ,{ demand(n == 1 && "lighttime"); MY(lighttime) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(lighttime)) \ - )) \ - on(liquidfriction, MY(liquidfriction) \ - ,{ demand(n == 1 && "liquidfriction"); MY(liquidfriction) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(liquidfriction)) \ - )) \ - on(notunderwater, MY(notunderwater) \ - ,{ demand(n == 0 && "notunderwater"); MY(notunderwater) = true; \ - }, "" \ - ) \ - on(orientation, MY(orientation) \ - ,{ demand(n == 1 && "orientation"); MY(orientation) = strzone(argv(1)); \ - }, sprintf(" %s", (MY(orientation)) \ - )) \ - on(originjitter, MY(originjitter) \ - ,{ demand(n == 3 && "originjitter"); MY(originjitter) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); \ - }, sprintf(" %v", (MY(originjitter)) \ - )) \ - on(originoffset, MY(originoffset) \ - ,{ demand(n == 3 && "originoffset"); MY(originoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); \ - }, sprintf(" %v", (MY(originoffset)) \ - )) \ - on(relativeoriginoffset, MY(relativeoriginoffset) \ - ,{ demand(n == 3 && "relativeoriginoffset"); MY(relativeoriginoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); \ - }, sprintf(" %v", (MY(relativeoriginoffset)) \ - )) \ - on(relativevelocityoffset, MY(relativevelocityoffset) \ - ,{ demand(n == 3 && "relativevelocityoffset"); MY(relativevelocityoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); \ - }, sprintf(" %v", (MY(relativevelocityoffset)) \ - )) \ - on(rotate, MY(startangle_min) || MY(startangle_max) || MY(spin_min) || MY(spin_max) \ - ,{ demand(n == 4 && "rotate"); MY(startangle_min) = stof(argv(1)); MY(startangle_max) = stof(argv(2)); MY(spin_min) = stof(argv(3)); MY(spin_max) = stof(argv(4)); \ - }, sprintf(" %s %s %s %s", ftos(MY(startangle_min)), ftos(MY(startangle_max)), ftos(MY(spin_min)), ftos(MY(spin_max)) \ - )) \ - on(sizeincrease, MY(sizeincrease) \ - ,{ demand(n == 1 && "sizeincrease"); MY(sizeincrease) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(sizeincrease)) \ - )) \ - on(size, MY(size_min) || MY(size_max) \ - ,{ demand(n == 2 && "size"); MY(size_min) = stof(argv(1)); MY(size_max) = stof(argv(2)); \ - }, sprintf(" %s %s", ftos(MY(size_min)), ftos(MY(size_max)) \ - )) \ - on(staincolor, MY(staincolor_min) || MY(staincolor_max) \ - ,{ demand(n == 2 && "staincolor"); MY(staincolor_min) = strzone(argv(1)); MY(staincolor_max) = strzone(argv(2)); \ - }, sprintf(" %s %s", (MY(staincolor_min)), (MY(staincolor_max)) \ - )) \ - on(stainsize, MY(stainsize_min) || MY(stainsize_max) \ - ,{ demand(n == 2 && "stainsize"); MY(stainsize_min) = stof(argv(1)); MY(stainsize_max) = stof(argv(2)); \ - }, sprintf(" %s %s", ftos(MY(stainsize_min)), ftos(MY(stainsize_max)) \ - )) \ - on(staintex, MY(staintex_min) || MY(staintex_max) \ - ,{ demand(n == 2 && "staintex"); MY(staintex_min) = stof(argv(1)); MY(staintex_max) = stof(argv(2)); \ - }, sprintf(" %s %s", ftos(MY(staintex_min)), ftos(MY(staintex_max)) \ - )) \ - on(stretchfactor, MY(stretchfactor) \ - ,{ demand(n == 1 && "stretchfactor"); MY(stretchfactor) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(stretchfactor)) \ - )) \ - on(tex, MY(tex_min) || MY(tex_max) \ - ,{ demand(n == 2 && "tex"); MY(tex_min) = stof(argv(1)); MY(tex_max) = stof(argv(2)); \ - }, sprintf(" %s %s", ftos(MY(tex_min)), ftos(MY(tex_max)) \ - )) \ - on(time, MY(time_min) || MY(time_max) \ - ,{ demand(n == 2 && "time"); MY(time_min) = stof(argv(1)); MY(time_max) = stof(argv(2)); \ - }, sprintf(" %s %s", ftos(MY(time_min)), ftos(MY(time_max)) \ - )) \ - on(trailspacing, MY(trailspacing) \ - ,{ demand(n == 1 && "trailspacing"); MY(trailspacing) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(trailspacing)) \ - )) \ - on(underwater, MY(underwater) \ - ,{ demand(n == 0 && "underwater"); MY(underwater) = true; \ - }, "" \ - ) \ - on(velocityjitter, MY(velocityjitter) \ - ,{ demand(n == 3 && "velocityjitter"); MY(velocityjitter) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); \ - }, sprintf(" %v", (MY(velocityjitter)) \ - )) \ - on(velocitymultiplier, MY(velocitymultiplier) \ - ,{ demand(n == 1 && "velocitymultiplier"); MY(velocitymultiplier) = stof(argv(1)); \ - }, sprintf(" %s", ftos(MY(velocitymultiplier)) \ - )) \ - on(velocityoffset, MY(velocityoffset) \ - ,{ demand(n == 3 && "velocityoffset"); MY(velocityoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); \ - }, sprintf(" %v", (MY(velocityoffset)) \ - )) \ - /**/ + on(type, MY(type) \ + , { demand(n == 1 && "type"); MY(type) = strzone(argv(1)); }, sprintf(" %s", (MY(type)) \ + )) \ + on(airfriction, MY(airfriction) \ + , { demand(n == 1 && "airfriction"); MY(airfriction) = stof(argv(1)); }, sprintf(" %s", ftos(MY(airfriction)) \ + )) \ + on(alpha, MY(alpha_min) || MY(alpha_max) || MY(alpha_fade) \ + , { demand(n == 3 && "alpha"); MY(alpha_min) = stof(argv(1)); MY(alpha_max) = stof(argv(2)); MY(alpha_fade) = stof(argv(3)); }, sprintf(" %s %s %s", ftos(MY(alpha_min)), ftos(MY(alpha_max)), ftos(MY(alpha_fade)) \ + )) \ + on(blend, MY(blend) \ + , { demand(n == 1 && "blend"); MY(blend) = strzone(argv(1)); }, sprintf(" %s", (MY(blend)) \ + )) \ + on(bounce, MY(bounce) \ + , { demand(n == 1 && "bounce"); MY(bounce) = stof(argv(1)); }, sprintf(" %s", ftos(MY(bounce)) \ + )) \ + on(color, MY(color_min) || MY(color_max) \ + , { demand(n == 2 && "color"); MY(color_min) = strzone(argv(1)); MY(color_max) = strzone(argv(2)); }, sprintf(" %s %s", (MY(color_min)), (MY(color_max)) \ + )) \ + on(countabsolute, MY(countabsolute) \ + , { demand(n == 1 && "countabsolute"); MY(countabsolute) = stof(argv(1)); }, sprintf(" %s", ftos(MY(countabsolute)) \ + )) \ + on(count, MY(count) \ + , { demand(n == 1 && "count"); MY(count) = stof(argv(1)); }, sprintf(" %s", ftos(MY(count)) \ + )) \ + on(gravity, MY(gravity) \ + , { demand(n == 1 && "gravity"); MY(gravity) = stof(argv(1)); }, sprintf(" %s", ftos(MY(gravity)) \ + )) \ + on(lightcolor, MY(lightcolor) \ + , { demand(n == 3 && "lightcolor"); MY(lightcolor) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); }, sprintf(" %v", (MY(lightcolor)) \ + )) \ + on(lightradiusfade, MY(lightradiusfade) \ + , { demand(n == 1 && "lightradiusfade"); MY(lightradiusfade) = stof(argv(1)); }, sprintf(" %s", ftos(MY(lightradiusfade)) \ + )) \ + on(lightradius, MY(lightradius) \ + , { demand(n == 1 && "lightradius"); MY(lightradius) = stof(argv(1)); }, sprintf(" %s", ftos(MY(lightradius)) \ + )) \ + on(lighttime, MY(lighttime) \ + , { demand(n == 1 && "lighttime"); MY(lighttime) = stof(argv(1)); }, sprintf(" %s", ftos(MY(lighttime)) \ + )) \ + on(liquidfriction, MY(liquidfriction) \ + , { demand(n == 1 && "liquidfriction"); MY(liquidfriction) = stof(argv(1)); }, sprintf(" %s", ftos(MY(liquidfriction)) \ + )) \ + on(notunderwater, MY(notunderwater) \ + , { demand(n == 0 && "notunderwater"); MY(notunderwater) = true; }, "" \ + ) \ + on(orientation, MY(orientation) \ + , { demand(n == 1 && "orientation"); MY(orientation) = strzone(argv(1)); }, sprintf(" %s", (MY(orientation)) \ + )) \ + on(originjitter, MY(originjitter) \ + , { demand(n == 3 && "originjitter"); MY(originjitter) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); }, sprintf(" %v", (MY(originjitter)) \ + )) \ + on(originoffset, MY(originoffset) \ + , { demand(n == 3 && "originoffset"); MY(originoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); }, sprintf(" %v", (MY(originoffset)) \ + )) \ + on(relativeoriginoffset, MY(relativeoriginoffset) \ + , { demand(n == 3 && "relativeoriginoffset"); MY(relativeoriginoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); }, sprintf(" %v", (MY(relativeoriginoffset)) \ + )) \ + on(relativevelocityoffset, MY(relativevelocityoffset) \ + , { demand(n == 3 && "relativevelocityoffset"); MY(relativevelocityoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); }, sprintf(" %v", (MY(relativevelocityoffset)) \ + )) \ + on(rotate, MY(startangle_min) || MY(startangle_max) || MY(spin_min) || MY(spin_max) \ + , { demand(n == 4 && "rotate"); MY(startangle_min) = stof(argv(1)); MY(startangle_max) = stof(argv(2)); MY(spin_min) = stof(argv(3)); MY(spin_max) = stof(argv(4)); }, sprintf(" %s %s %s %s", ftos(MY(startangle_min)), ftos(MY(startangle_max)), ftos(MY(spin_min)), ftos(MY(spin_max)) \ + )) \ + on(sizeincrease, MY(sizeincrease) \ + , { demand(n == 1 && "sizeincrease"); MY(sizeincrease) = stof(argv(1)); }, sprintf(" %s", ftos(MY(sizeincrease)) \ + )) \ + on(size, MY(size_min) || MY(size_max) \ + , { demand(n == 2 && "size"); MY(size_min) = stof(argv(1)); MY(size_max) = stof(argv(2)); }, sprintf(" %s %s", ftos(MY(size_min)), ftos(MY(size_max)) \ + )) \ + on(staincolor, MY(staincolor_min) || MY(staincolor_max) \ + , { demand(n == 2 && "staincolor"); MY(staincolor_min) = strzone(argv(1)); MY(staincolor_max) = strzone(argv(2)); }, sprintf(" %s %s", (MY(staincolor_min)), (MY(staincolor_max)) \ + )) \ + on(stainsize, MY(stainsize_min) || MY(stainsize_max) \ + , { demand(n == 2 && "stainsize"); MY(stainsize_min) = stof(argv(1)); MY(stainsize_max) = stof(argv(2)); }, sprintf(" %s %s", ftos(MY(stainsize_min)), ftos(MY(stainsize_max)) \ + )) \ + on(staintex, MY(staintex_min) || MY(staintex_max) \ + , { demand(n == 2 && "staintex"); MY(staintex_min) = stof(argv(1)); MY(staintex_max) = stof(argv(2)); }, sprintf(" %s %s", ftos(MY(staintex_min)), ftos(MY(staintex_max)) \ + )) \ + on(stretchfactor, MY(stretchfactor) \ + , { demand(n == 1 && "stretchfactor"); MY(stretchfactor) = stof(argv(1)); }, sprintf(" %s", ftos(MY(stretchfactor)) \ + )) \ + on(tex, MY(tex_min) || MY(tex_max) \ + , { demand(n == 2 && "tex"); MY(tex_min) = stof(argv(1)); MY(tex_max) = stof(argv(2)); }, sprintf(" %s %s", ftos(MY(tex_min)), ftos(MY(tex_max)) \ + )) \ + on(time, MY(time_min) || MY(time_max) \ + , { demand(n == 2 && "time"); MY(time_min) = stof(argv(1)); MY(time_max) = stof(argv(2)); }, sprintf(" %s %s", ftos(MY(time_min)), ftos(MY(time_max)) \ + )) \ + on(trailspacing, MY(trailspacing) \ + , { demand(n == 1 && "trailspacing"); MY(trailspacing) = stof(argv(1)); }, sprintf(" %s", ftos(MY(trailspacing)) \ + )) \ + on(underwater, MY(underwater) \ + , { demand(n == 0 && "underwater"); MY(underwater) = true; }, "" \ + ) \ + on(velocityjitter, MY(velocityjitter) \ + , { demand(n == 3 && "velocityjitter"); MY(velocityjitter) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); }, sprintf(" %v", (MY(velocityjitter)) \ + )) \ + on(velocitymultiplier, MY(velocitymultiplier) \ + , { demand(n == 1 && "velocitymultiplier"); MY(velocitymultiplier) = stof(argv(1)); }, sprintf(" %s", ftos(MY(velocitymultiplier)) \ + )) \ + on(velocityoffset, MY(velocityoffset) \ + , { demand(n == 3 && "velocityoffset"); MY(velocityoffset) = vec3(stof(argv(1)), stof(argv(2)), stof(argv(3))); }, sprintf(" %v", (MY(velocityoffset)) \ + )) \ + /**/ CLASS(EffectInfo, Object) - ATTRIB(EffectInfo, effectinfo_name, string); - CONSTRUCTOR(EffectInfo, string s) { - CONSTRUCT(EffectInfo); - this.effectinfo_name = s; - } + ATTRIB(EffectInfo, effectinfo_name, string); + CONSTRUCTOR(EffectInfo, string s) + { + CONSTRUCT(EffectInfo); + this.effectinfo_name = s; + } - #define FIELDS(MY) \ - MY(airfriction, float, 0) \ - MY(alpha_min, float, 0) \ - MY(alpha_max, float, 0) \ - MY(alpha_fade, float, 0) \ - MY(blend, string, string_null) \ - MY(bounce, float, 0) \ - MY(color_min, string, string_null) \ - MY(color_max, string, string_null) \ - MY(countabsolute, float, 0) \ - MY(count, float, 0) \ - MY(gravity, float, 0) \ - MY(lightcolor, vector, '0 0 0') \ - MY(lightradiusfade, float, 0) \ - MY(lightradius, float, 0) \ - MY(lighttime, float, 0) \ - MY(liquidfriction, float, 0) \ - MY(notunderwater, bool, false) \ - MY(orientation, string, string_null) \ - MY(originjitter, vector, '0 0 0') \ - MY(originoffset, vector, '0 0 0') \ - MY(relativeoriginoffset, vector, '0 0 0') \ - MY(relativevelocityoffset, vector, '0 0 0') \ - MY(startangle_min, float, 0) \ - MY(startangle_max, float, 0) \ - MY(spin_min, float, 0) \ - MY(spin_max, float, 0) \ - MY(sizeincrease, float, 0) \ - MY(size_min, float, 0) \ - MY(size_max, float, 0) \ - MY(staincolor_min, string, string_null) \ - MY(staincolor_max, string, string_null) \ - MY(stainsize_min, float, 0) \ - MY(stainsize_max, float, 0) \ - MY(staintex_min, float, 0) \ - MY(staintex_max, float, 0) \ - MY(stretchfactor, float, 0) \ - MY(tex_min, float, 0) \ - MY(tex_max, float, 0) \ - MY(time_min, float, 0) \ - MY(time_max, float, 0) \ - MY(trailspacing, float, 0) \ - MY(type, string, string_null) \ - MY(underwater, bool, false) \ - MY(velocityjitter, vector, '0 0 0') \ - MY(velocitymultiplier, float, 0) \ - MY(velocityoffset, vector, '0 0 0') \ - /**/ + #define FIELDS(MY) \ + MY(airfriction, float, 0) \ + MY(alpha_min, float, 0) \ + MY(alpha_max, float, 0) \ + MY(alpha_fade, float, 0) \ + MY(blend, string, string_null) \ + MY(bounce, float, 0) \ + MY(color_min, string, string_null) \ + MY(color_max, string, string_null) \ + MY(countabsolute, float, 0) \ + MY(count, float, 0) \ + MY(gravity, float, 0) \ + MY(lightcolor, vector, '0 0 0') \ + MY(lightradiusfade, float, 0) \ + MY(lightradius, float, 0) \ + MY(lighttime, float, 0) \ + MY(liquidfriction, float, 0) \ + MY(notunderwater, bool, false) \ + MY(orientation, string, string_null) \ + MY(originjitter, vector, '0 0 0') \ + MY(originoffset, vector, '0 0 0') \ + MY(relativeoriginoffset, vector, '0 0 0') \ + MY(relativevelocityoffset, vector, '0 0 0') \ + MY(startangle_min, float, 0) \ + MY(startangle_max, float, 0) \ + MY(spin_min, float, 0) \ + MY(spin_max, float, 0) \ + MY(sizeincrease, float, 0) \ + MY(size_min, float, 0) \ + MY(size_max, float, 0) \ + MY(staincolor_min, string, string_null) \ + MY(staincolor_max, string, string_null) \ + MY(stainsize_min, float, 0) \ + MY(stainsize_max, float, 0) \ + MY(staintex_min, float, 0) \ + MY(staintex_max, float, 0) \ + MY(stretchfactor, float, 0) \ + MY(tex_min, float, 0) \ + MY(tex_max, float, 0) \ + MY(time_min, float, 0) \ + MY(time_max, float, 0) \ + MY(trailspacing, float, 0) \ + MY(type, string, string_null) \ + MY(underwater, bool, false) \ + MY(velocityjitter, vector, '0 0 0') \ + MY(velocitymultiplier, float, 0) \ + MY(velocityoffset, vector, '0 0 0') \ + /**/ - #define MY(f, type, val) ATTRIB(EffectInfo, effectinfo_##f, type, val); - FIELDS(MY) - #undef MY + #define MY(f, type, val) ATTRIB(EffectInfo, effectinfo_##f, type, val); + FIELDS(MY) + #undef MY - METHOD(EffectInfo, describe, string(EffectInfo this)) - { - TC(EffectInfo, this); - string s = sprintf("SUB(%s) {\n", this.effectinfo_name); - #define str_bool(it) (it ? "true" : "false") - #define str_float(it) ftos(it) - #define str_vector(it) vtos(it) - #define str_string(it) strcat("\"", it, "\"") - #define p(f, type, default) if (this.effectinfo_##f) { s = strcat(s, "\t", "MY("#f") = ", str_##type(this.effectinfo_##f), ";\n"); } - FIELDS(p) - #undef p - return strcat(s, "}\n"); - } + METHOD(EffectInfo, describe, string(EffectInfo this)) + { + TC(EffectInfo, this); + string s = sprintf("SUB(%s) {\n", this.effectinfo_name); + #define str_bool(it) (it ? "true" : "false") + #define str_float(it) ftos(it) + #define str_vector(it) vtos(it) + #define str_string(it) strcat("\"", it, "\"") + #define p(f, type, default) if (this.effectinfo_##f) { s = strcat(s, "\t", "MY(" #f ") = ", str_##type(this.effectinfo_##f), ";\n"); } + FIELDS(p) + #undef p + return strcat(s, "}\n"); + } - METHOD(EffectInfo, dump, string(EffectInfo this)) - { - TC(EffectInfo, this); - string s = sprintf("effect %s\n", this.effectinfo_name); - #define MY(f) this.effectinfo_##f - #define p(k, isset, parse, unparse) if (isset) { s = strcat(s, "\t", #k, unparse, "\n"); } - EFFECTINFO_PARSER(p, MY) - #undef p - #undef MY - return s; - } + METHOD(EffectInfo, dump, string(EffectInfo this)) + { + TC(EffectInfo, this); + string s = sprintf("effect %s\n", this.effectinfo_name); + #define MY(f) this.effectinfo_##f + #define p(k, isset, parse, unparse) if (isset) { s = strcat(s, "\t", #k, unparse, "\n"); } + EFFECTINFO_PARSER(p, MY) + #undef p + #undef MY + return s; + } - #undef FIELDS + #undef FIELDS ENDCLASS(EffectInfo) CLASS(EffectInfoGroup, Object) - ATTRIBARRAY(EffectInfoGroup, children, EffectInfo, 16); - ATTRIB(EffectInfoGroup, children_count, int, 0); + ATTRIBARRAY(EffectInfoGroup, children, EffectInfo, 16); + ATTRIB(EffectInfoGroup, children_count, int, 0); ENDCLASS(EffectInfoGroup) void effectinfo_read() { - int fh = fopen("effectinfo.txt", FILE_READ); - EffectInfo info = NULL; - for (string line; (line = fgets(fh)); ) { - int n = tokenize_console(line); - if (n == 0) continue; - n--; - string k = argv(0); - if (k == "effect") { - demand(n == 1); - info = NEW(EffectInfo, strzone(argv(1))); - continue; - } - demand(info != NULL); - switch (k) { - #define MY(f) info.effectinfo_##f - #define p(k, isset, parse, unparse) case #k: parse break; - EFFECTINFO_PARSER(p, MY) - #undef p - #undef MY - default: - LOG_WARNF("Unknown property '%s'", k); - break; - } - } - fclose(fh); + int fh = fopen("effectinfo.txt", FILE_READ); + EffectInfo info = NULL; + for (string line; (line = fgets(fh)); ) { + int n = tokenize_console(line); + if (n == 0) { continue; } + n--; + string k = argv(0); + if (k == "effect") { + demand(n == 1); + info = NEW(EffectInfo, strzone(argv(1))); + continue; + } + demand(info != NULL); + switch (k) { + #define MY(f) info.effectinfo_##f + #define p(k, isset, parse, unparse) case #k: parse break; + EFFECTINFO_PARSER(p, MY) + #undef p + #undef MY + default: + LOG_WARNF("Unknown property '%s'", k); + break; + } + } + fclose(fh); } void effectinfo_dump(int fh, bool alsoprint) { - #define WRITE(s) MACRO_BEGIN \ - fputs(fh, s); \ - if (alsoprint) LOG_INFO(s); \ - MACRO_END - WRITE("// ********************************************** //\n"); - WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n"); - WRITE("// ** ** //\n"); - WRITE("// ** This file is automatically generated by ** //\n"); - WRITE("// ** code with the command 'dumpeffectinfo'. ** //\n"); - WRITE("// ** ** //\n"); - WRITE("// ** If you modify an effect, please ** //\n"); - WRITE("// ** regenerate this file with that command. ** //\n"); - WRITE("// ** ** //\n"); - WRITE("// ********************************************** //\n"); - WRITE("\n"); + #define WRITE(s) \ + MACRO_BEGIN \ + fputs(fh, s); \ + if (alsoprint) { LOG_INFO(s); } \ + MACRO_END + WRITE("// ********************************************** //\n"); + WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n"); + WRITE("// ** ** //\n"); + WRITE("// ** This file is automatically generated by ** //\n"); + WRITE("// ** code with the command 'dumpeffectinfo'. ** //\n"); + WRITE("// ** ** //\n"); + WRITE("// ** If you modify an effect, please ** //\n"); + WRITE("// ** regenerate this file with that command. ** //\n"); + WRITE("// ** ** //\n"); + WRITE("// ********************************************** //\n"); + WRITE("\n"); - for (EffectInfo it = NULL; (it = findfloat(it, instanceOfEffectInfo, true)); ) { - if (it.classname == "vtbl") continue; - string s = it.dump(it); - WRITE(s); - } - #undef WRITE + for (EffectInfo it = NULL; (it = findfloat(it, instanceOfEffectInfo, true)); ) { + if (it.classname == "vtbl") { continue; } + string s = it.dump(it); + WRITE(s); + } + #undef WRITE } GENERIC_COMMAND(dumpeffectinfo, "Dump all effectinfo to effectinfo_dump.txt") { - switch (request) { - case CMD_REQUEST_COMMAND: { - string filename = argv(1); + switch (request) { + case CMD_REQUEST_COMMAND: + { + string filename = argv(1); bool alsoprint = false; - if (filename == "") { - filename = "effectinfo_dump.txt"; - alsoprint = false; - } else if (filename == "-") { - filename = "effectinfo_dump.txt"; - alsoprint = true; - } - int fh = fopen(filename, FILE_WRITE); - if (fh >= 0) { - effectinfo_dump(fh, alsoprint); - LOG_INFOF("Dumping effectinfo... File located at ^2data/data/%s^7.", filename); + if (filename == "") { + filename = "effectinfo_dump.txt"; + alsoprint = false; + } else if (filename == "-") { + filename = "effectinfo_dump.txt"; + alsoprint = true; + } + int fh = fopen(filename, FILE_WRITE); + if (fh >= 0) { + effectinfo_dump(fh, alsoprint); + LOG_INFOF("Dumping effectinfo... File located at ^2data/data/%s^7.", filename); LOG_INFOF("Reload with ^2cl_particles_reloadeffects data/%s^7.", filename); - fclose(fh); - } else { - LOG_WARNF("Could not open file '%s'!", filename); - } - return; - } - default: - case CMD_REQUEST_USAGE: { - LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " dumpeffectinfo [filename]"); - LOG_INFO(" Where 'filename' is the file to write (default is effectinfo_dump.txt),"); - LOG_INFO(" if supplied with '-' output to console as well as default,"); - LOG_INFO(" if left blank, it will only write to default."); - return; - } - } + fclose(fh); + } else { + LOG_WARNF("Could not open file '%s'!", filename); + } + return; + } + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " dumpeffectinfo [filename]"); + LOG_INFO(" Where 'filename' is the file to write (default is effectinfo_dump.txt),"); + LOG_INFO(" if supplied with '-' output to console as well as default,"); + LOG_INFO(" if left blank, it will only write to default."); + return; + } + } } @@ -327,16 +297,20 @@ REGISTRY(EffectInfos, BITS(9)) #define EffectInfos_from(i) _EffectInfos_from(i, NULL) REGISTER_REGISTRY(EffectInfos) #define EFFECTINFO(name) \ - [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { } \ - REGISTER(EffectInfos, EFFECTINFO, name, m_id, NEW(EffectInfoGroup)) { \ - effectinfo_##name(this, NULL); \ - } + [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) {} \ + REGISTER(EffectInfos, EFFECTINFO, name, m_id, NEW(EffectInfoGroup)) \ + { \ + effectinfo_##name(this, NULL); \ + } #define MY(f) this.effectinfo_##f #define DEF(name) EFFECTINFO(name) #define SUB(name) \ - [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { parent = EFFECTINFO_##name; parent.children[parent.children_count++] = this = NEW(EffectInfo, #name); } \ - [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) + [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) \ + { \ + parent = EFFECTINFO_##name; parent.children[parent.children_count++] = this = NEW(EffectInfo, #name); \ + } \ + [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) #include "effectinfo.inc" #undef MY #undef DEF diff --git a/qcsrc/common/effects/qc/casings.qc b/qcsrc/common/effects/qc/casings.qc index 60f963302..f133be8d8 100644 --- a/qcsrc/common/effects/qc/casings.qc +++ b/qcsrc/common/effects/qc/casings.qc @@ -12,164 +12,161 @@ REGISTER_NET_TEMP(casings) #ifdef SVQC void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity) { - entity wep = casingowner.(weaponentity); - vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up; - - if (!sound_allowed(MSG_BROADCAST, casingowner)) - casingtype |= 0x80; - - WriteHeader(MSG_ALL, casings); - WriteByte(MSG_ALL, casingtype); - WriteCoord(MSG_ALL, org.x); - WriteCoord(MSG_ALL, org.y); - WriteCoord(MSG_ALL, org.z); - WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity - WriteByte(MSG_ALL, ang.x * 256 / 360); - WriteByte(MSG_ALL, ang.y * 256 / 360); - WriteByte(MSG_ALL, ang.z * 256 / 360); + entity wep = casingowner.(weaponentity); + vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up; + + if (!sound_allowed(MSG_BROADCAST, casingowner)) { + casingtype |= 0x80; + } + + WriteHeader(MSG_ALL, casings); + WriteByte(MSG_ALL, casingtype); + WriteCoord(MSG_ALL, org.x); + WriteCoord(MSG_ALL, org.y); + WriteCoord(MSG_ALL, org.z); + WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity + WriteByte(MSG_ALL, ang.x * 256 / 360); + WriteByte(MSG_ALL, ang.y * 256 / 360); + WriteByte(MSG_ALL, ang.z * 256 / 360); } #endif #ifdef CSQC entityclass(Casing); -class(Casing) .float alpha; -class(Casing) .bool silent; -class(Casing) .int state; -class(Casing) .float cnt; +class(Casing).float alpha; +class(Casing).bool silent; +class(Casing).int state; +class(Casing).float cnt; void Casing_Delete(entity this) { - delete(this); + delete(this); } void Casing_Draw(entity this) { - if (IS_ONGROUND(this)) - { - this.angles_x = 0; - this.angles_z = 0; - //UNSET_ONGROUND(this); - } - - Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy); - if (wasfreed(this)) - return; // deleted by touch function - - this.renderflags = 0; - this.alpha = bound(0, this.cnt - time, 1); - - if (this.alpha < ALPHA_MIN_VISIBLE) - { - Casing_Delete(this); - this.drawmask = 0; - } + if (IS_ONGROUND(this)) { + this.angles_x = 0; + this.angles_z = 0; + // UNSET_ONGROUND(this); + } + + Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy); + if (wasfreed(this)) { + return; // deleted by touch function + } + this.renderflags = 0; + this.alpha = bound(0, this.cnt - time, 1); + + if (this.alpha < ALPHA_MIN_VISIBLE) { + Casing_Delete(this); + this.drawmask = 0; + } } SOUND(BRASS1, W_Sound("brass1")); SOUND(BRASS2, W_Sound("brass2")); SOUND(BRASS3, W_Sound("brass3")); -Sound SND_BRASS_RANDOM() { - return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3)); +Sound SND_BRASS_RANDOM() +{ + return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3)); } SOUND(CASINGS1, W_Sound("casings1")); SOUND(CASINGS2, W_Sound("casings2")); SOUND(CASINGS3, W_Sound("casings3")); -Sound SND_CASINGS_RANDOM() { - return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3)); +Sound SND_CASINGS_RANDOM() +{ + return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3)); } void Casing_Touch(entity this, entity toucher) { - if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) - { - Casing_Delete(this); - return; - } - - if (!this.silent) - if (!trace_ent || trace_ent.solid == SOLID_BSP) - { - if(vdist(this.velocity, >, 50)) - { - if (time >= this.nextthink) - { - Sound s; - switch (this.state) - { - case 1: - s = SND_CASINGS_RANDOM(); - break; - default: - s = SND_BRASS_RANDOM(); - break; - } - - sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE); - } - } - } - - this.nextthink = time + 0.2; + if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) { + Casing_Delete(this); + return; + } + + if (!this.silent) { + if (!trace_ent || trace_ent.solid == SOLID_BSP) { + if (vdist(this.velocity, >, 50)) { + if (time >= this.nextthink) { + Sound s; + switch (this.state) { + case 1: + s = SND_CASINGS_RANDOM(); + break; + default: + s = SND_BRASS_RANDOM(); + break; + } + + sound(this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE); + } + } + } + } + + this.nextthink = time + 0.2; } void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce) { - if (thisforce.z < 0) - thisforce.z = 0; - this.velocity = this.velocity + thisforce + '0 0 100'; - UNSET_ONGROUND(this); + if (thisforce.z < 0) { + thisforce.z = 0; + } + this.velocity = this.velocity + thisforce + '0 0 100'; + UNSET_ONGROUND(this); } NET_HANDLE(casings, bool isNew) { - int _state = ReadByte(); - vector org; - org_x = ReadCoord(); - org_y = ReadCoord(); - org_z = ReadCoord(); - vector vel = decompressShortVector(ReadShort()); - vector ang; - ang_x = ReadByte() * 360 / 256; - ang_y = ReadByte() * 360 / 256; - ang_z = ReadByte() * 360 / 256; - return = true; - - if (!autocvar_cl_casings) return; - - Casing casing = RubbleNew("casing"); - casing.silent = (_state & 0x80); - casing.state = (_state & 0x7F); - casing.origin = org; - setorigin(casing, casing.origin); - casing.velocity = vel; - casing.angles = ang; - casing.drawmask = MASK_NORMAL; - - casing.draw = Casing_Draw; - if (isNew) IL_PUSH(g_drawables, casing); - casing.velocity = casing.velocity + 2 * prandomvec(); - casing.avelocity = '0 250 0' + 100 * prandomvec(); - set_movetype(casing, MOVETYPE_BOUNCE); - settouch(casing, Casing_Touch); - casing.move_time = time; - casing.event_damage = Casing_Damage; - casing.solid = SOLID_TRIGGER; - - switch (casing.state) - { - case 1: - setmodel(casing, MDL_CASING_SHELL); - casing.cnt = time + autocvar_cl_casings_shell_time; - break; - default: - setmodel(casing, MDL_CASING_BULLET); - casing.cnt = time + autocvar_cl_casings_bronze_time; - break; - } - - setsize(casing, '0 0 -1', '0 0 -1'); - - RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete); + int _state = ReadByte(); + vector org; + org_x = ReadCoord(); + org_y = ReadCoord(); + org_z = ReadCoord(); + vector vel = decompressShortVector(ReadShort()); + vector ang; + ang_x = ReadByte() * 360 / 256; + ang_y = ReadByte() * 360 / 256; + ang_z = ReadByte() * 360 / 256; + return = true; + + if (!autocvar_cl_casings) { return; } + + Casing casing = RubbleNew("casing"); + casing.silent = (_state & 0x80); + casing.state = (_state & 0x7F); + casing.origin = org; + setorigin(casing, casing.origin); + casing.velocity = vel; + casing.angles = ang; + casing.drawmask = MASK_NORMAL; + + casing.draw = Casing_Draw; + if (isNew) { IL_PUSH(g_drawables, casing); } + casing.velocity = casing.velocity + 2 * prandomvec(); + casing.avelocity = '0 250 0' + 100 * prandomvec(); + set_movetype(casing, MOVETYPE_BOUNCE); + settouch(casing, Casing_Touch); + casing.move_time = time; + casing.event_damage = Casing_Damage; + casing.solid = SOLID_TRIGGER; + + switch (casing.state) { + case 1: + setmodel(casing, MDL_CASING_SHELL); + casing.cnt = time + autocvar_cl_casings_shell_time; + break; + default: + setmodel(casing, MDL_CASING_BULLET); + casing.cnt = time + autocvar_cl_casings_bronze_time; + break; + } + + setsize(casing, '0 0 -1', '0 0 -1'); + + RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete); } #endif diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index 911e79bf2..bcc43b9ac 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -8,428 +8,405 @@ #include #endif - REGISTER_NET_TEMP(globalsound) - REGISTER_NET_TEMP(playersound) +REGISTER_NET_TEMP(globalsound) +REGISTER_NET_TEMP(playersound) - string GlobalSound_sample(string pair, float r); +string GlobalSound_sample(string pair, float r); #ifdef SVQC - /** - * @param from the source entity, its position is sent - * @param gs the global sound def - * @param r a random number in 0..1 - */ - void globalsound(int channel, entity from, entity gs, float r, int chan, float _vol, float _atten) - { - //assert(IS_PLAYER(from), eprint(from)); - if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return; - if (!autocvar_g_debug_globalsounds) { - string sample = GlobalSound_sample(gs.m_globalsoundstr, r); - switch (channel) { - case MSG_ONE: - soundto(channel, from, chan, sample, _vol, _atten); - break; - case MSG_ALL: - _sound(from, chan, sample, _vol, _atten); - break; - } - return; - } - WriteHeader(channel, globalsound); - WriteByte(channel, gs.m_id); - WriteByte(channel, r * 255); - WriteByte(channel, etof(from)); - WriteByte(channel, chan); - WriteByte(channel, floor(_vol * 255)); - WriteByte(channel, floor(_atten * 64)); - entcs_force_origin(from); - vector o = from.origin + 0.5 * (from.mins + from.maxs); - WriteCoord(channel, o.x); - WriteCoord(channel, o.y); - WriteCoord(channel, o.z); +/** + * @param from the source entity, its position is sent + * @param gs the global sound def + * @param r a random number in 0..1 + */ +void globalsound(int channel, entity from, entity gs, float r, int chan, float _vol, float _atten) +{ + // assert(IS_PLAYER(from), eprint(from)); + if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) { return; } + if (!autocvar_g_debug_globalsounds) { + string sample = GlobalSound_sample(gs.m_globalsoundstr, r); + switch (channel) { + case MSG_ONE: + soundto(channel, from, chan, sample, _vol, _atten); + break; + case MSG_ALL: + _sound(from, chan, sample, _vol, _atten); + break; } + return; + } + WriteHeader(channel, globalsound); + WriteByte(channel, gs.m_id); + WriteByte(channel, r * 255); + WriteByte(channel, etof(from)); + WriteByte(channel, chan); + WriteByte(channel, floor(_vol * 255)); + WriteByte(channel, floor(_atten * 64)); + entcs_force_origin(from); + vector o = from.origin + 0.5 * (from.mins + from.maxs); + WriteCoord(channel, o.x); + WriteCoord(channel, o.y); + WriteCoord(channel, o.z); +} - /** - * @param from the source entity, its position is sent - * @param ps the player sound def - * @param r a random number in 0..1 - */ - void playersound(int channel, entity from, entity ps, float r, int chan, float _vol, float _atten) - { - //assert(IS_PLAYER(from), eprint(from)); - if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return; - if (!autocvar_g_debug_globalsounds) { - //UpdatePlayerSounds(from); - string s = from.(ps.m_playersoundfld); - string sample = GlobalSound_sample(s, r); - switch (channel) { - case MSG_ONE: - soundto(channel, from, chan, sample, _vol, _atten); - break; - case MSG_ALL: - _sound(from, chan, sample, _vol, _atten); - break; - } - return; - } - WriteHeader(channel, playersound); - WriteByte(channel, ps.m_id); - WriteByte(channel, r * 255); - WriteByte(channel, etof(from)); - WriteByte(channel, chan); - WriteByte(channel, floor(_vol * 255)); - WriteByte(channel, floor(_atten * 64)); - entcs_force_origin(from); - vector o = from.origin + 0.5 * (from.mins + from.maxs); - WriteCoord(channel, o.x); - WriteCoord(channel, o.y); - WriteCoord(channel, o.z); +/** +* @param from the source entity, its position is sent +* @param ps the player sound def +* @param r a random number in 0..1 +*/ +void playersound(int channel, entity from, entity ps, float r, int chan, float _vol, float _atten) +{ + // assert(IS_PLAYER(from), eprint(from)); + if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) { return; } + if (!autocvar_g_debug_globalsounds) { + // UpdatePlayerSounds(from); + string s = from.(ps.m_playersoundfld); + string sample = GlobalSound_sample(s, r); + switch (channel) { + case MSG_ONE: + soundto(channel, from, chan, sample, _vol, _atten); + break; + case MSG_ALL: + _sound(from, chan, sample, _vol, _atten); + break; } + return; + } + WriteHeader(channel, playersound); + WriteByte(channel, ps.m_id); + WriteByte(channel, r * 255); + WriteByte(channel, etof(from)); + WriteByte(channel, chan); + WriteByte(channel, floor(_vol * 255)); + WriteByte(channel, floor(_atten * 64)); + entcs_force_origin(from); + vector o = from.origin + 0.5 * (from.mins + from.maxs); + WriteCoord(channel, o.x); + WriteCoord(channel, o.y); + WriteCoord(channel, o.z); +} #endif #ifdef CSQC - NET_HANDLE(globalsound, bool isnew) - { - entity gs = GlobalSounds_from(ReadByte()); - float r = ReadByte() / 255; - string sample = GlobalSound_sample(gs.m_globalsoundstr, r); - int who = ReadByte(); - entity e = entcs_receiver(who - 1); - int chan = ReadSByte(); - float vol = ReadByte() / 255; - float atten = ReadByte() / 64; - vector o; - o.x = ReadCoord(); - o.y = ReadCoord(); - o.z = ReadCoord(); - // TODO: is this really what we want to be doing? Footsteps that follow the player at head height? - if (who == player_currententnum) e = findfloat(NULL, entnum, who); // play at camera position for full volume - else if (e) e.origin = o; - if (e) - { - sound7(e, chan, sample, vol, atten, 0, 0); - } - else - { - // Can this happen? - LOG_WARNF("Missing entcs data for player %d", who); - sound8(e, o, chan, sample, vol, atten, 0, 0); - } - return true; - } +NET_HANDLE(globalsound, bool isnew) +{ + entity gs = GlobalSounds_from(ReadByte()); + float r = ReadByte() / 255; + string sample = GlobalSound_sample(gs.m_globalsoundstr, r); + int who = ReadByte(); + entity e = entcs_receiver(who - 1); + int chan = ReadSByte(); + float vol = ReadByte() / 255; + float atten = ReadByte() / 64; + vector o; + o.x = ReadCoord(); + o.y = ReadCoord(); + o.z = ReadCoord(); + // TODO: is this really what we want to be doing? Footsteps that follow the player at head height? + if (who == player_currententnum) { + e = findfloat(NULL, entnum, who); // play at camera position for full volume + } else if (e) { + e.origin = o; + } + if (e) { + sound7(e, chan, sample, vol, atten, 0, 0); + } else { + // Can this happen? + LOG_WARNF("Missing entcs data for player %d", who); + sound8(e, o, chan, sample, vol, atten, 0, 0); + } + return true; +} - NET_HANDLE(playersound, bool isnew) - { - entity ps = PlayerSounds_from(ReadByte()); - float r = ReadByte() / 255; - int who = ReadByte(); - entity e = entcs_receiver(who - 1); - UpdatePlayerSounds(e); - string s = e.(ps.m_playersoundfld); - string sample = GlobalSound_sample(s, r); - int chan = ReadSByte(); - float vol = ReadByte() / 255; - float atten = ReadByte() / 64; - vector o; - o.x = ReadCoord(); - o.y = ReadCoord(); - o.z = ReadCoord(); - if (who == player_currententnum) e = findfloat(NULL, entnum, who); // play at camera position for full volume - else if (e) e.origin = o; - if (e) - { - // TODO: for non-visible players, origin should probably continue to be updated as long as the sound is playing - sound7(e, chan, sample, vol, atten, 0, 0); - } - else - { - // Can this happen? - LOG_WARNF("Missing entcs data for player %d", who); - sound8(e, o, chan, sample, vol, atten, 0, 0); - } - return true; - } +NET_HANDLE(playersound, bool isnew) +{ + entity ps = PlayerSounds_from(ReadByte()); + float r = ReadByte() / 255; + int who = ReadByte(); + entity e = entcs_receiver(who - 1); + UpdatePlayerSounds(e); + string s = e.(ps.m_playersoundfld); + string sample = GlobalSound_sample(s, r); + int chan = ReadSByte(); + float vol = ReadByte() / 255; + float atten = ReadByte() / 64; + vector o; + o.x = ReadCoord(); + o.y = ReadCoord(); + o.z = ReadCoord(); + if (who == player_currententnum) { + e = findfloat(NULL, entnum, who); // play at camera position for full volume + } else if (e) { + e.origin = o; + } + if (e) { + // TODO: for non-visible players, origin should probably continue to be updated as long as the sound is playing + sound7(e, chan, sample, vol, atten, 0, 0); + } else { + // Can this happen? + LOG_WARNF("Missing entcs data for player %d", who); + sound8(e, o, chan, sample, vol, atten, 0, 0); + } + return true; +} #endif - string GlobalSound_sample(string pair, float r) +string GlobalSound_sample(string pair, float r) +{ + int n; { - int n; - { - string s = cdr(pair); - if (s) n = stof(s); - else n = 0; - } - string sample = car(pair); - if (n > 0) sample = sprintf("%s%d.wav", sample, floor(r * n + 1)); // randomization - else sample = sprintf("%s.wav", sample); - return sample; + string s = cdr(pair); + if (s) { n = stof(s); } else { n = 0; } } + string sample = car(pair); + if (n > 0) { + sample = sprintf("%s%d.wav", sample, floor(r * n + 1)); // randomization + } else { sample = sprintf("%s.wav", sample); } + return sample; +} - void PrecacheGlobalSound(string sample) +void PrecacheGlobalSound(string sample) +{ + int n; { - int n; - { - string s = cdr(sample); - if (s) n = stof(s); - else n = 0; - } - sample = car(sample); - if (n > 0) - { - for (int i = 1; i <= n; ++i) - precache_sound(sprintf("%s%d.wav", sample, i)); - } - else - { - precache_sound(sprintf("%s.wav", sample)); + string s = cdr(sample); + if (s) { n = stof(s); } else { n = 0; } + } + sample = car(sample); + if (n > 0) { + for (int i = 1; i <= n; ++i) { + precache_sound(sprintf("%s%d.wav", sample, i)); } + } else { + precache_sound(sprintf("%s.wav", sample)); } +} - entity GetVoiceMessage(string type) - { - FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, return it); - return NULL; - } +entity GetVoiceMessage(string type) +{ + FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == true, return it); + return NULL; +} - entity GetPlayerSound(string type) - { - FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == false, return it); - return NULL; - } +entity GetPlayerSound(string type) +{ + FOREACH(PlayerSounds, it.m_playersoundstr == type && it.instanceOfVoiceMessage == false, return it); + return NULL; +} - .string _GetPlayerSoundSampleField(string type, bool voice) - { - GetPlayerSoundSampleField_notFound = false; - entity e = voice ? GetVoiceMessage(type) : GetPlayerSound(type); - if (e) return e.m_playersoundfld; - GetPlayerSoundSampleField_notFound = true; - return playersound_taunt.m_playersoundfld; - } +.string _GetPlayerSoundSampleField(string type, bool voice) +{ + GetPlayerSoundSampleField_notFound = false; + entity e = voice ? GetVoiceMessage(type) : GetPlayerSound(type); + if (e) { return e.m_playersoundfld; } + GetPlayerSoundSampleField_notFound = true; + return playersound_taunt.m_playersoundfld; +} - .string GetVoiceMessageSampleField(string type) - { - return _GetPlayerSoundSampleField(type, true); - } +.string GetVoiceMessageSampleField(string type) +{ + return _GetPlayerSoundSampleField(type, true); +} - void PrecachePlayerSounds(string f) - { - int fh = fopen(f, FILE_READ); - if (fh < 0) - { - LOG_WARNF("Player sound file not found: %s", f); - return; - } - for (string s; (s = fgets(fh)); ) - { - int n = tokenize_console(s); - if (n != 3) - { - if (n != 0) LOG_WARNF("Invalid sound info line: %s", s); - continue; - } - string file = argv(1); - string variants = argv(2); - PrecacheGlobalSound(strcat(file, " ", variants)); +void PrecachePlayerSounds(string f) +{ + int fh = fopen(f, FILE_READ); + if (fh < 0) { + LOG_WARNF("Player sound file not found: %s", f); + return; + } + for (string s; (s = fgets(fh)); ) { + int n = tokenize_console(s); + if (n != 3) { + if (n != 0) { LOG_WARNF("Invalid sound info line: %s", s); } + continue; } - fclose(fh); + string file = argv(1); + string variants = argv(2); + PrecacheGlobalSound(strcat(file, " ", variants)); } + fclose(fh); +} - //#ifdef CSQC +// #ifdef CSQC - .string GetPlayerSoundSampleField(string type) - { - return _GetPlayerSoundSampleField(type, false); - } +.string GetPlayerSoundSampleField(string type) +{ + return _GetPlayerSoundSampleField(type, false); +} - void ClearPlayerSounds(entity this) - { - FOREACH(PlayerSounds, true, { - .string fld = it.m_playersoundfld; - if (this.(fld)) - { - strunzone(this.(fld)); - this.(fld) = string_null; - } - }); +void ClearPlayerSounds(entity this) +{ + FOREACH(PlayerSounds, true, { + .string fld = it.m_playersoundfld; + if (this.(fld)) { + strunzone(this.(fld)); + this.(fld) = string_null; } + }); +} - bool LoadPlayerSounds(entity this, string f, bool strict) - { - int fh = fopen(f, FILE_READ); - if (fh < 0) - { - if (strict) LOG_WARNF("Player sound file not found: %s", f); - return false; - } - for (string s; (s = fgets(fh)); ) - { - int n = tokenize_console(s); - if (n != 3) - { - if (n != 0) LOG_WARNF("Invalid sound info line: %s", s); - continue; - } - string key = argv(0); - var.string field = GetPlayerSoundSampleField(key); - if (GetPlayerSoundSampleField_notFound) field = GetVoiceMessageSampleField(key); - if (GetPlayerSoundSampleField_notFound) - { - LOG_TRACEF("Invalid sound info field: %s", key); - continue; - } - string file = argv(1); - string variants = argv(2); - if (this.(field)) strunzone(this.(field)); - this.(field) = strzone(strcat(file, " ", variants)); - } - fclose(fh); - return true; +bool LoadPlayerSounds(entity this, string f, bool strict) +{ + int fh = fopen(f, FILE_READ); + if (fh < 0) { + if (strict) { LOG_WARNF("Player sound file not found: %s", f); } + return false; + } + for (string s; (s = fgets(fh)); ) { + int n = tokenize_console(s); + if (n != 3) { + if (n != 0) { LOG_WARNF("Invalid sound info line: %s", s); } + continue; } + string key = argv(0); + var.string field = GetPlayerSoundSampleField(key); + if (GetPlayerSoundSampleField_notFound) { field = GetVoiceMessageSampleField(key); } + if (GetPlayerSoundSampleField_notFound) { + LOG_TRACEF("Invalid sound info field: %s", key); + continue; + } + string file = argv(1); + string variants = argv(2); + if (this.(field)) { strunzone(this.(field)); } + this.(field) = strzone(strcat(file, " ", variants)); + } + fclose(fh); + return true; +} - .string model_for_playersound; - .int skin_for_playersound; +.string model_for_playersound; +.int skin_for_playersound; - bool autocvar_g_debug_defaultsounds; +bool autocvar_g_debug_defaultsounds; - void UpdatePlayerSounds(entity this) - { - if (this.model == this.model_for_playersound && this.skin == this.skin_for_playersound) return; - if (this.model_for_playersound) strunzone(this.model_for_playersound); - this.model_for_playersound = strzone(this.model); - this.skin_for_playersound = this.skin; - ClearPlayerSounds(this); - LoadPlayerSounds(this, "sound/player/default.sounds", true); - if (this.model == "null" +void UpdatePlayerSounds(entity this) +{ + if (this.model == this.model_for_playersound && this.skin == this.skin_for_playersound) { return; } + if (this.model_for_playersound) { strunzone(this.model_for_playersound); } + this.model_for_playersound = strzone(this.model); + this.skin_for_playersound = this.skin; + ClearPlayerSounds(this); + LoadPlayerSounds(this, "sound/player/default.sounds", true); + if (this.model == "null" #ifdef SVQC - && autocvar_g_debug_globalsounds + && autocvar_g_debug_globalsounds #endif - ) return; - if (autocvar_g_debug_defaultsounds) return; - if (LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) return; - LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true); - } + ) { return; } + if (autocvar_g_debug_defaultsounds) { return; } + if (LoadPlayerSounds(this, get_model_datafilename(this.model, this.skin, "sounds"), false)) { return; } + LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true); +} - //#endif +// #endif #ifdef SVQC - void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, float vol, int voicetype, bool fake) +void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, float vol, int voicetype, bool fake) +{ + if (gs == NULL && ps == NULL && sample == "") { return; } + if (this.classname == "body") { return; } + float r = random(); + if (sample != "") { sample = GlobalSound_sample(sample, r); } + switch (voicetype) { + case VOICETYPE_LASTATTACKER_ONLY: + case VOICETYPE_LASTATTACKER: { - if (gs == NULL && ps == NULL && sample == "") return; - if(this.classname == "body") return; - float r = random(); - if (sample != "") sample = GlobalSound_sample(sample, r); - switch (voicetype) - { - case VOICETYPE_LASTATTACKER_ONLY: - case VOICETYPE_LASTATTACKER: - { - if (!fake) - { - if (!this.pusher) break; - msg_entity = this.pusher; - if (IS_REAL_CLIENT(msg_entity)) - { - float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); - else soundto(MSG_ONE, this, chan, sample, vol, atten); - } - } - if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break; - msg_entity = this; - if (IS_REAL_CLIENT(msg_entity)) - { - if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASE, ATTEN_NONE); - else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASE, ATTEN_NONE); - else soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE); - } - break; + if (!fake) { + if (!this.pusher) { break; } + msg_entity = this.pusher; + if (IS_REAL_CLIENT(msg_entity)) { + float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; + if (gs) { globalsound(MSG_ONE, this, gs, r, chan, vol, atten); } else if (ps) { + playersound(MSG_ONE, this, ps, r, chan, vol, atten); + } else { soundto(MSG_ONE, this, chan, sample, vol, atten); } } - case VOICETYPE_TEAMRADIO: - { + } + if (voicetype == VOICETYPE_LASTATTACKER_ONLY) { break; } + msg_entity = this; + if (IS_REAL_CLIENT(msg_entity)) { + if (gs) { globalsound(MSG_ONE, this, gs, r, chan, VOL_BASE, ATTEN_NONE); } else if (ps) { + playersound(MSG_ONE, this, ps, r, chan, VOL_BASE, ATTEN_NONE); + } else { soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE); } + } + break; + } + case VOICETYPE_TEAMRADIO: + { #define X() \ - MACRO_BEGIN \ - float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \ - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); \ - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); \ - else soundto(MSG_ONE, this, chan, sample, vol, atten); \ - MACRO_END + MACRO_BEGIN \ + float atten = (CS(msg_entity).cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \ + if (gs) { globalsound(MSG_ONE, this, gs, r, chan, vol, atten); } else if (ps) { \ + playersound(MSG_ONE, this, ps, r, chan, vol, atten); \ + } else { soundto(MSG_ONE, this, chan, sample, vol, atten); } \ + MACRO_END - if (fake) { msg_entity = this; X(); } - else - { - FOREACH_CLIENT(IS_REAL_CLIENT(it) && SAME_TEAM(it, this), { - msg_entity = it; - X(); - }); - } + if (fake) { msg_entity = this; X(); } else { + FOREACH_CLIENT(IS_REAL_CLIENT(it) && SAME_TEAM(it, this), { + msg_entity = it; + X(); + }); + } #undef X - break; - } - case VOICETYPE_AUTOTAUNT: - case VOICETYPE_TAUNT: - { - if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) { break; }else {} - else if (IS_PLAYER(this) && !IS_DEAD(this)) animdecide_setaction(this, ANIMACTION_TAUNT, - true); - if (!sv_taunt) break; - if (autocvar_sv_gentle) break; - float tauntrand = 0; - if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random(); + break; + } + case VOICETYPE_AUTOTAUNT: + case VOICETYPE_TAUNT: + { + if (voicetype == VOICETYPE_AUTOTAUNT) { if (!sv_autotaunt) { break; } else {} } else if (IS_PLAYER(this) && !IS_DEAD(this)) { + animdecide_setaction(this, ANIMACTION_TAUNT, + true); + } + if (!sv_taunt) { break; } + if (autocvar_sv_gentle) { break; } + float tauntrand = 0; + if (voicetype == VOICETYPE_AUTOTAUNT) { tauntrand = random(); } #define X() \ - MACRO_BEGIN \ - if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < CS(msg_entity).cvar_cl_autotaunt) \ - { \ - float atten = (CS(msg_entity).cvar_cl_voice_directional >= 1) \ - ? bound(ATTEN_MIN, CS(msg_entity).cvar_cl_voice_directional_taunt_attenuation, \ - ATTEN_MAX) \ - : ATTEN_NONE; \ - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, atten); \ - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, atten); \ - else soundto(MSG_ONE, this, chan, sample, vol, atten); \ - } \ - MACRO_END - if (fake) - { - msg_entity = this; - X(); - } - else - { - FOREACH_CLIENT(IS_REAL_CLIENT(it), { - msg_entity = it; - X(); - }); - } + MACRO_BEGIN \ + if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < CS(msg_entity).cvar_cl_autotaunt) { \ + float atten = (CS(msg_entity).cvar_cl_voice_directional >= 1) \ + ? bound(ATTEN_MIN, CS(msg_entity).cvar_cl_voice_directional_taunt_attenuation, \ + ATTEN_MAX) \ + : ATTEN_NONE; \ + if (gs) { globalsound(MSG_ONE, this, gs, r, chan, vol, atten); } else if (ps) { \ + playersound(MSG_ONE, this, ps, r, chan, vol, atten); \ + } else { soundto(MSG_ONE, this, chan, sample, vol, atten); } \ + } \ + MACRO_END + if (fake) { + msg_entity = this; + X(); + } else { + FOREACH_CLIENT(IS_REAL_CLIENT(it), { + msg_entity = it; + X(); + }); + } #undef X - break; - } - case VOICETYPE_PLAYERSOUND: - { - msg_entity = this; - if (fake) - { - if (gs) globalsound(MSG_ONE, this, gs, r, chan, vol, ATTEN_NORM); - else if (ps) playersound(MSG_ONE, this, ps, r, chan, vol, ATTEN_NORM); - else soundto(MSG_ONE, this, chan, sample, vol, ATTEN_NORM); - } - else - { - if (gs) globalsound(MSG_ALL, this, gs, r, chan, vol, ATTEN_NORM); - else if (ps) playersound(MSG_ALL, this, ps, r, chan, vol, ATTEN_NORM); - else _sound(this, chan, sample, vol, ATTEN_NORM); - } - break; - } - default: - { - backtrace("Invalid voice type!"); - break; - } + break; + } + case VOICETYPE_PLAYERSOUND: + { + msg_entity = this; + if (fake) { + if (gs) { globalsound(MSG_ONE, this, gs, r, chan, vol, ATTEN_NORM); } else if (ps) { + playersound(MSG_ONE, this, ps, r, chan, vol, ATTEN_NORM); + } else { soundto(MSG_ONE, this, chan, sample, vol, ATTEN_NORM); } + } else { + if (gs) { globalsound(MSG_ALL, this, gs, r, chan, vol, ATTEN_NORM); } else if (ps) { + playersound(MSG_ALL, this, ps, r, chan, vol, ATTEN_NORM); + } else { _sound(this, chan, sample, vol, ATTEN_NORM); } } + break; + } + default: + { + backtrace("Invalid voice type!"); + break; } + } +} #endif diff --git a/qcsrc/common/effects/qc/globalsound.qh b/qcsrc/common/effects/qc/globalsound.qh index 77dd4479f..76beb1e18 100644 --- a/qcsrc/common/effects/qc/globalsound.qh +++ b/qcsrc/common/effects/qc/globalsound.qh @@ -1,8 +1,8 @@ #pragma once #ifdef SVQC - /** Use new sound handling. TODO: use when sounds play correctly on clients */ - bool autocvar_g_debug_globalsounds = false; +/** Use new sound handling. TODO: use when sounds play correctly on clients */ +bool autocvar_g_debug_globalsounds = false; #endif // player sounds, voice messages @@ -110,39 +110,39 @@ REGISTER_GLOBALSOUND(FALL_METAL, "misc/metalhitground 4") bool GetPlayerSoundSampleField_notFound; void PrecachePlayerSounds(string f); -//#ifdef CSQC - .string GetVoiceMessageSampleField(string type); - .string GetPlayerSoundSampleField(string type); - void ClearPlayerSounds(entity this); - float LoadPlayerSounds(entity this, string f, bool strict); - void UpdatePlayerSounds(entity this); -//#endif +// #ifdef CSQC +.string GetVoiceMessageSampleField(string type); +.string GetPlayerSoundSampleField(string type); +void ClearPlayerSounds(entity this); +float LoadPlayerSounds(entity this, string f, bool strict); +void UpdatePlayerSounds(entity this); +// #endif entity GetVoiceMessage(string type); #ifdef SVQC - void _GlobalSound(entity this, entity gs, entity ps, string sample, float chan, float vol, float voicetype, bool fake); +void _GlobalSound(entity this, entity gs, entity ps, string sample, float chan, float vol, float voicetype, bool fake); #define GlobalSound(this, def, chan, vol, voicetype) _GlobalSound(this, def, NULL, string_null, chan, vol, voicetype, false) #define GlobalSound_string(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, NULL, def, chan, vol, voicetype, false) #define PlayerSound(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, def, string_null, chan, vol, voicetype, false) #define VoiceMessage(this, def, msg) \ - MACRO_BEGIN \ - entity VM = def; \ - int voicetype = VM.m_playersoundvt; \ - bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \ - int flood = Say(this, ownteam, NULL, msg, true); \ - bool fake; \ - if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \ - else if (flood > 0) fake = false; \ - else break; \ - _GlobalSound(this, NULL, VM, string_null, CH_VOICE, VOL_BASEVOICE, voicetype, fake); \ - MACRO_END + MACRO_BEGIN \ + entity VM = def; \ + int voicetype = VM.m_playersoundvt; \ + bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \ + int flood = Say(this, ownteam, NULL, msg, true); \ + bool fake; \ + if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) { fake = true; } else if (flood > 0) { \ + fake = false; \ + } else { break; } \ + _GlobalSound(this, NULL, VM, string_null, CH_VOICE, VOL_BASEVOICE, voicetype, fake); \ + MACRO_END #endif string allvoicesamples; STATIC_INIT(allvoicesamples) { - FOREACH(PlayerSounds, it.instanceOfVoiceMessage, allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr)); - allvoicesamples = strzone(substring(allvoicesamples, 1, -1)); + FOREACH(PlayerSounds, it.instanceOfVoiceMessage, allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr)); + allvoicesamples = strzone(substring(allvoicesamples, 1, -1)); } diff --git a/qcsrc/common/effects/qc/lightningarc.qc b/qcsrc/common/effects/qc/lightningarc.qc index 6388575b7..9eeae6101 100644 --- a/qcsrc/common/effects/qc/lightningarc.qc +++ b/qcsrc/common/effects/qc/lightningarc.qc @@ -4,17 +4,17 @@ REGISTER_NET_TEMP(TE_CSQC_ARC) #if defined(SVQC) - void te_csqc_lightningarc(vector from, vector to) - { - WriteHeader(MSG_BROADCAST, TE_CSQC_ARC); - - WriteCoord(MSG_BROADCAST, from.x); - WriteCoord(MSG_BROADCAST, from.y); - WriteCoord(MSG_BROADCAST, from.z); - WriteCoord(MSG_BROADCAST, to.x); - WriteCoord(MSG_BROADCAST, to.y); - WriteCoord(MSG_BROADCAST, to.z); - } +void te_csqc_lightningarc(vector from, vector to) +{ + WriteHeader(MSG_BROADCAST, TE_CSQC_ARC); + + WriteCoord(MSG_BROADCAST, from.x); + WriteCoord(MSG_BROADCAST, from.y); + WriteCoord(MSG_BROADCAST, from.z); + WriteCoord(MSG_BROADCAST, to.x); + WriteCoord(MSG_BROADCAST, to.y); + WriteCoord(MSG_BROADCAST, to.z); +} #elif defined(CSQC) @@ -47,72 +47,63 @@ void b_make(vector s,vector e, string t,float l,float z) } */ - void cl_effects_lightningarc(vector from, vector to, float seglength, float drifts, float drifte, - float branchfactor, float branchfactor_add) - { - float length = vlen(from - to); - if (length < 1) return; - - // Use at most 16 te_lightning1 segments, as these eat up beam list segments. - // TODO: Change this to R_BeginPolygon code, then we no longer have this limit. - int steps = min(16, floor(length / seglength)); - if (steps < 1) - { - te_lightning1(NULL, from, to); - return; - } +void cl_effects_lightningarc(vector from, vector to, float seglength, float drifts, float drifte, float branchfactor, float branchfactor_add) +{ + float length = vlen(from - to); + if (length < 1) { return; } + + // Use at most 16 te_lightning1 segments, as these eat up beam list segments. + // TODO: Change this to R_BeginPolygon code, then we no longer have this limit. + int steps = min(16, floor(length / seglength)); + if (steps < 1) { + te_lightning1(NULL, from, to); + return; + } - float steplength = length / steps; - vector direction = normalize(to - from); - vector pos_l = from; - if (length > seglength) - { - for (int i = 1; i < steps; i += 1) - { - float drift = drifts * (1 - (i / steps)) + drifte * (i / steps); - vector dirnew = normalize(direction * (1 - drift) + randomvec() * drift); - vector pos = pos_l + dirnew * steplength; - te_lightning1(NULL, pos_l, pos); - // WTF endless recursion if branchfactor is 1.0 (possibly due to adding branchfactor_add). FIXME - // if(random() < branchfactor) - // cl_effects_lightningarc(pos, pos + (dirnew * length * 0.25),seglength,drifts,drifte,min(branchfactor + branchfactor_add,1),branchfactor_add); - - pos_l = pos; - } - te_lightning1(NULL, pos_l, to); - } - else - { - te_lightning1(NULL, from, to); + float steplength = length / steps; + vector direction = normalize(to - from); + vector pos_l = from; + if (length > seglength) { + for (int i = 1; i < steps; i += 1) { + float drift = drifts * (1 - (i / steps)) + drifte * (i / steps); + vector dirnew = normalize(direction * (1 - drift) + randomvec() * drift); + vector pos = pos_l + dirnew * steplength; + te_lightning1(NULL, pos_l, pos); + // WTF endless recursion if branchfactor is 1.0 (possibly due to adding branchfactor_add). FIXME + // if(random() < branchfactor) + // cl_effects_lightningarc(pos, pos + (dirnew * length * 0.25),seglength,drifts,drifte,min(branchfactor + branchfactor_add,1),branchfactor_add); + + pos_l = pos; } + te_lightning1(NULL, pos_l, to); + } else { + te_lightning1(NULL, from, to); } +} - NET_HANDLE(TE_CSQC_ARC, bool isNew) - { - vector from; - from.x = ReadCoord(); - from.y = ReadCoord(); - from.z = ReadCoord(); - vector to; - to.x = ReadCoord(); - to.y = ReadCoord(); - to.z = ReadCoord(); - return = true; - - if (autocvar_cl_effects_lightningarc_simple) - { - te_lightning1(NULL, from, to); - } - else - { - float seglength = autocvar_cl_effects_lightningarc_segmentlength; - float drifts = autocvar_cl_effects_lightningarc_drift_start; - float drifte = autocvar_cl_effects_lightningarc_drift_end; - float branchfactor = autocvar_cl_effects_lightningarc_branchfactor_start; - float branchfactor_add = autocvar_cl_effects_lightningarc_branchfactor_add; - - cl_effects_lightningarc(from, to, seglength, drifts, drifte, branchfactor, branchfactor_add); - } +NET_HANDLE(TE_CSQC_ARC, bool isNew) +{ + vector from; + from.x = ReadCoord(); + from.y = ReadCoord(); + from.z = ReadCoord(); + vector to; + to.x = ReadCoord(); + to.y = ReadCoord(); + to.z = ReadCoord(); + return = true; + + if (autocvar_cl_effects_lightningarc_simple) { + te_lightning1(NULL, from, to); + } else { + float seglength = autocvar_cl_effects_lightningarc_segmentlength; + float drifts = autocvar_cl_effects_lightningarc_drift_start; + float drifte = autocvar_cl_effects_lightningarc_drift_end; + float branchfactor = autocvar_cl_effects_lightningarc_branchfactor_start; + float branchfactor_add = autocvar_cl_effects_lightningarc_branchfactor_add; + + cl_effects_lightningarc(from, to, seglength, drifts, drifte, branchfactor, branchfactor_add); } +} #endif diff --git a/qcsrc/common/effects/qc/modeleffects.qc b/qcsrc/common/effects/qc/modeleffects.qc index 1b70daee2..31488abd7 100644 --- a/qcsrc/common/effects/qc/modeleffects.qc +++ b/qcsrc/common/effects/qc/modeleffects.qc @@ -12,12 +12,15 @@ bool modeleffect_SendEntity(entity this, entity to, int sf) WriteHeader(MSG_ENTITY, ENT_CLIENT_MODELEFFECT); f = 0; - if(this.velocity != '0 0 0') + if (this.velocity != '0 0 0') { f |= 1; - if(this.angles != '0 0 0') + } + if (this.angles != '0 0 0') { f |= 2; - if(this.avelocity != '0 0 0') + } + if (this.avelocity != '0 0 0') { f |= 4; + } WriteByte(MSG_ENTITY, f); WriteShort(MSG_ENTITY, this.modelindex); @@ -26,20 +29,17 @@ bool modeleffect_SendEntity(entity this, entity to, int sf) WriteCoord(MSG_ENTITY, this.origin.x); WriteCoord(MSG_ENTITY, this.origin.y); WriteCoord(MSG_ENTITY, this.origin.z); - if(f & 1) - { + if (f & 1) { WriteCoord(MSG_ENTITY, this.velocity.x); WriteCoord(MSG_ENTITY, this.velocity.y); WriteCoord(MSG_ENTITY, this.velocity.z); } - if(f & 2) - { + if (f & 2) { WriteCoord(MSG_ENTITY, this.angles.x); WriteCoord(MSG_ENTITY, this.angles.y); WriteCoord(MSG_ENTITY, this.angles.z); } - if(f & 4) - { + if (f & 4) { WriteCoord(MSG_ENTITY, this.avelocity.x); WriteCoord(MSG_ENTITY, this.avelocity.y); WriteCoord(MSG_ENTITY, this.avelocity.z); @@ -66,14 +66,16 @@ void modeleffect_spawn(string m, float s, float f, vector o, vector v, vector an e.teleport_time = t1; e.fade_time = t2; e.skin = s; - if(s0 >= 0) + if (s0 >= 0) { e.scale = s0 / max6(-e.mins.x, -e.mins.y, -e.mins.z, e.maxs.x, e.maxs.y, e.maxs.z); - else + } else { e.scale = -s0; - if(s2 >= 0) + } + if (s2 >= 0) { e.scale2 = s2 / max6(-e.mins.x, -e.mins.y, -e.mins.z, e.maxs.x, e.maxs.y, e.maxs.z); - else + } else { e.scale2 = -s2; + } float sz = max(e.scale, e.scale2); setsize(e, e.mins * sz, e.maxs * sz); Net_LinkEntity(e, false, 0.1, modeleffect_SendEntity); @@ -84,10 +86,10 @@ void modeleffect_spawn(string m, float s, float f, vector o, vector v, vector an #ifdef CSQC entityclass(ModelEffect); -class(ModelEffect) .float frame1time; -class(ModelEffect) .float lifetime, fadetime; -class(ModelEffect) .float teleport_time; -class(ModelEffect) .float scale1, scale2; +class(ModelEffect).float frame1time; +class(ModelEffect).float lifetime, fadetime; +class(ModelEffect).float teleport_time; +class(ModelEffect).float scale1, scale2; .float cnt; .float scale; @@ -99,14 +101,12 @@ void ModelEffect_Draw(entity this) setorigin(this, this.origin + frametime * this.velocity); this.scale = this.scale1 + (this.scale2 - this.scale1) * (time - this.teleport_time) / (this.lifetime + this.fadetime - this.teleport_time); this.alpha = this.cnt * bound(0, 1 - (time - this.lifetime) / this.fadetime, 1); - if(this.alpha < ALPHA_MIN_VISIBLE) - { + if (this.alpha < ALPHA_MIN_VISIBLE) { delete(this); return; } this.drawmask = MASK_NORMAL; - if(this.scale <= 0) - { + if (this.scale <= 0) { this.drawmask = 0; return; } @@ -128,20 +128,17 @@ NET_HANDLE(ENT_CLIENT_MODELEFFECT, bool isnew) e.origin_y = ReadCoord(); e.origin_z = ReadCoord(); setorigin(e, e.origin); - if(f & 1) - { + if (f & 1) { e.velocity_x = ReadCoord(); e.velocity_y = ReadCoord(); e.velocity_z = ReadCoord(); } - if(f & 2) - { + if (f & 2) { e.angles_x = ReadAngle(); e.angles_y = ReadAngle(); e.angles_z = ReadAngle(); } - if(f & 4) - { + if (f & 4) { e.avelocity_x = ReadAngle(); e.avelocity_y = ReadAngle(); e.avelocity_z = ReadAngle(); @@ -154,9 +151,11 @@ NET_HANDLE(ENT_CLIENT_MODELEFFECT, bool isnew) e.cnt = ReadByte() / 255.0; // actually alpha e.draw = ModelEffect_Draw; - if (isnew) IL_PUSH(g_drawables, e); + if (isnew) { IL_PUSH(g_drawables, e); } - if (!isnew) delete(e); // yes, this IS stupid, but I don't need to duplicate all the read* stuff then + if (!isnew) { + delete(e); // yes, this IS stupid, but I don't need to duplicate all the read* stuff then + } return true; } #endif diff --git a/qcsrc/common/effects/qc/rubble.qh b/qcsrc/common/effects/qc/rubble.qh index dd3785b68..318909b59 100644 --- a/qcsrc/common/effects/qc/rubble.qh +++ b/qcsrc/common/effects/qc/rubble.qh @@ -6,14 +6,16 @@ entityclass(Rubble); class(Rubble).float creationtime; IntrusiveList g_rubble; -STATIC_INIT(g_rubble) { g_rubble = IL_NEW(); } +STATIC_INIT(g_rubble) +{ + g_rubble = IL_NEW(); +} void RubbleLimit(string cname, int limit, void(entity) deleteproc) { // remove rubble of the same type if it's at the limit // remove multiple rubble if the limit has been decreased - while (1) - { + while (1) { // walk the list and count the entities, find the oldest // initialize our search with the first entity int c = 0; @@ -23,15 +25,14 @@ void RubbleLimit(string cname, int limit, void(entity) deleteproc) IL_EACH(g_rubble, it.classname == cname, { ++c; - if(!oldest || oldesttime > it.creationtime) - { + if (!oldest || oldesttime > it.creationtime) { oldest = it; oldesttime = it.creationtime; } }); // stop if there are less than the limit already - if (c <= limit) break; + if (c <= limit) { break; } // delete this oldest one and search again deleteproc(oldest); diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qh b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qh index 53797d2bc..5edfe184d 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qh +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qh @@ -1,16 +1,16 @@ #pragma once #ifdef SVQC -//EF_BRIGHTFIELD|EF_BRIGHTLIGHT|EF_DIMLIGHT|EF_BLUE|EF_RED|EF_FLAME +// EF_BRIGHTFIELD|EF_BRIGHTLIGHT|EF_DIMLIGHT|EF_BLUE|EF_RED|EF_FLAME const float BALL_EFFECTMASK = 1229; const vector BALL_MINS = '-16 -16 -16'; // The model is 24*24*24 const vector BALL_MAXS = '16 16 16'; const vector BALL_ATTACHORG = '3 0 16'; const float BALL_FOOT = 1; const float BALL_BASKET = 2; -//spawnflags +// spawnflags const float GOAL_TOUCHPLAYER = 1; -//goal types +// goal types const float GOAL_FAULT = -1; const float GOAL_OUT = -2; diff --git a/qcsrc/common/gamemodes/gamemode/nexball/sv_weapon.qc b/qcsrc/common/gamemodes/gamemode/nexball/sv_weapon.qc index 705ac6d54..cd6a53a32 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/sv_weapon.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/sv_weapon.qc @@ -6,68 +6,67 @@ vector trigger_push_calculatevelocity(vector org, entity tgt, float ht); METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire)) { - TC(BallStealer, thiswep); - if(fire & 1) - if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire)) - if(autocvar_g_nexball_basketball_meter) - { - if(actor.ballcarried && !actor.metertime) - actor.metertime = time; - else - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready); - } - else - { - W_Nexball_Attack(actor, weaponentity, -1); - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready); - } - if(fire & 2) - if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire)) - { - W_Nexball_Attack2(actor, weaponentity); - weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready); - } - - if(!(fire & 1) && actor.metertime && actor.ballcarried) - { - W_Nexball_Attack(actor, weaponentity, time - actor.metertime); - // DropBall or stealing will set metertime back to 0 - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready); - } + TC(BallStealer, thiswep); + if (fire & 1) { + if (weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire)) { + if (autocvar_g_nexball_basketball_meter) { + if (actor.ballcarried && !actor.metertime) { + actor.metertime = time; + } else { + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready); + } + } else { + W_Nexball_Attack(actor, weaponentity, -1); + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready); + } + } + } + if (fire & 2) { + if (weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire)) { + W_Nexball_Attack2(actor, weaponentity); + weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready); + } + } + + if (!(fire & 1) && actor.metertime && actor.ballcarried) { + W_Nexball_Attack(actor, weaponentity, time - actor.metertime); + // DropBall or stealing will set metertime back to 0 + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready); + } } METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor, .entity weaponentity)) { - TC(BallStealer, this); - //weapon_setup(WEP_PORTO.m_id); + TC(BallStealer, this); + // weapon_setup(WEP_PORTO.m_id); } METHOD(BallStealer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity)) { - TC(BallStealer, this); + TC(BallStealer, this); } METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor, .entity weaponentity)) { - TC(BallStealer, this); - return true; + TC(BallStealer, this); + return true; } METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor, .entity weaponentity)) { - TC(BallStealer, this); - return true; + TC(BallStealer, this); + return true; } void W_Nexball_Think(entity this) { - //dprint("W_Nexball_Think\n"); - //vector new_dir = steerlib_arrive(this.enemy.origin, 2500); + // dprint("W_Nexball_Think\n"); + // vector new_dir = steerlib_arrive(this.enemy.origin, 2500); vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin); vector old_dir = normalize(this.velocity); float _speed = vlen(this.velocity); vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed; - //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate + // vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate this.velocity = new_vel; @@ -78,22 +77,19 @@ void W_Nexball_Touch(entity this, entity toucher) { entity ball, attacker; attacker = this.owner; - //this.think = func_null; - //this.enemy = NULL; + // this.think = func_null; + // this.enemy = NULL; PROJECTILE_TOUCH(this, toucher); - if(attacker.team != toucher.team || autocvar_g_nexball_basketball_teamsteal) - if((ball = toucher.ballcarried) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (IS_PLAYER(attacker))) - { + if (attacker.team != toucher.team || autocvar_g_nexball_basketball_teamsteal) { + if ((ball = toucher.ballcarried) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (IS_PLAYER(attacker))) { toucher.velocity = toucher.velocity + normalize(this.velocity) * toucher.damageforcescale * autocvar_g_balance_nexball_secondary_force; UNSET_ONGROUND(toucher); - if(!attacker.ballcarried) - { + if (!attacker.ballcarried) { LogNB("stole", attacker); _sound(toucher, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM); - if(SAME_TEAM(attacker, toucher) && time > CS(attacker).teamkill_complain) - { + if (SAME_TEAM(attacker, toucher) && time > CS(attacker).teamkill_complain) { CS(attacker).teamkill_complain = time + 5; CS(attacker).teamkill_soundtime = time + 0.4; CS(attacker).teamkill_soundsource = toucher; @@ -102,6 +98,7 @@ void W_Nexball_Touch(entity this, entity toucher) GiveBall(attacker, toucher.ballcarried); } } + } delete(this); } @@ -109,42 +106,42 @@ void W_Nexball_Attack(entity actor, .entity weaponentity, float t) { entity ball; float mul, mi, ma; - if(!(ball = actor.ballcarried)) + if (!(ball = actor.ballcarried)) { return; + } W_SetupShot(actor, weaponentity, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0); tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, NULL); - if(trace_startsolid) - { - if(actor.metertime) + if (trace_startsolid) { + if (actor.metertime) { actor.metertime = 0; // Shot failed, hide the power meter + } return; } - //Calculate multiplier - if(t < 0) + // Calculate multiplier + if (t < 0) { mul = 1; - else - { + } else { mi = autocvar_g_nexball_basketball_meter_minpower; ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion - //One triangle wave period with 1 as max + // One triangle wave period with 1 as max mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period; - if(mul > 1) + if (mul > 1) { mul = 2 - mul; + } mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power } DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor, actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false)); - //TODO: use the speed_up cvar too ?? + // TODO: use the speed_up cvar too ?? } void W_Nexball_Attack2(entity actor, .entity weaponentity) { - if(actor.ballcarried.enemy) - { + if (actor.ballcarried.enemy) { entity _ball = actor.ballcarried; W_SetupShot(actor, weaponentity, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0); DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32)); @@ -153,8 +150,9 @@ void W_Nexball_Attack2(entity actor, .entity weaponentity) return; } - if(!autocvar_g_nexball_tackling) + if (!autocvar_g_nexball_tackling) { return; + } W_SetupShot(actor, weaponentity, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0); entity missile = new(ballstealer); @@ -164,7 +162,7 @@ void W_Nexball_Attack2(entity actor, .entity weaponentity) set_movetype(missile, MOVETYPE_FLY); PROJECTILE_MAKETRIGGER(missile); - //setmodel(missile, "models/elaser.mdl"); // precision set below + // setmodel(missile, "models/elaser.mdl"); // precision set below setsize(missile, '0 0 0', '0 0 0'); setorigin(missile, w_shotorg); @@ -172,7 +170,7 @@ void W_Nexball_Attack2(entity actor, .entity weaponentity) missile.angles = vectoangles(missile.velocity); settouch(missile, W_Nexball_Touch); setthink(missile, SUB_Remove); - missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead? + missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; // FIXME: use a distance instead? missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION; missile.flags = FL_PROJECTILE; diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qh b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qh index c863e2f71..bfd26c2d2 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qh +++ b/qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qh @@ -5,10 +5,16 @@ REGISTER_NET_LINKED(ENT_CLIENT_CONTROLPOINT_ICON) #ifdef SVQC IntrusiveList g_onsshields; -STATIC_INIT(g_onsshields) { g_onsshields = IL_NEW(); } +STATIC_INIT(g_onsshields) +{ + g_onsshields = IL_NEW(); +} #endif #ifdef CSQC IntrusiveList g_onsgenerators; -STATIC_INIT(g_onsgenerators) { g_onsgenerators = IL_NEW(); } +STATIC_INIT(g_onsgenerators) +{ + g_onsgenerators = IL_NEW(); +} #endif diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh index 5c7fd4697..96fff9cd0 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh @@ -5,7 +5,7 @@ void ons_Initialize(); REGISTER_MUTATOR(ons, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { GameRules_teams(true); @@ -73,10 +73,10 @@ bool ons_ControlPoint_Attackable(entity cp, int teamnumber); float ons_captureshield_force; // push force of the shield // bot player logic -const int HAVOCBOT_ONS_ROLE_NONE = 0; -const int HAVOCBOT_ONS_ROLE_DEFENSE = 2; -const int HAVOCBOT_ONS_ROLE_ASSISTANT = 4; -const int HAVOCBOT_ONS_ROLE_OFFENSE = 8; +const int HAVOCBOT_ONS_ROLE_NONE = 0; +const int HAVOCBOT_ONS_ROLE_DEFENSE = 2; +const int HAVOCBOT_ONS_ROLE_ASSISTANT = 4; +const int HAVOCBOT_ONS_ROLE_OFFENSE = 8; .entity havocbot_ons_target; diff --git a/qcsrc/common/gamemodes/sv_rules.qc b/qcsrc/common/gamemodes/sv_rules.qc index a4a4bcd19..77bec71bb 100644 --- a/qcsrc/common/gamemodes/sv_rules.qc +++ b/qcsrc/common/gamemodes/sv_rules.qc @@ -4,109 +4,109 @@ void GameRules_teams(bool value) { - if (value) { - serverflags |= SERVERFLAG_TEAMPLAY; - teamplay = 1; - cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies. - GameRules_spawning_teams(true); - } else { - serverflags &= ~SERVERFLAG_TEAMPLAY; - teamplay = 0; - cvar_set("teamplay", "0"); // DP needs this for sending proper getstatus replies. - GameRules_spawning_teams(false); - } + if (value) { + serverflags |= SERVERFLAG_TEAMPLAY; + teamplay = 1; + cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies. + GameRules_spawning_teams(true); + } else { + serverflags &= ~SERVERFLAG_TEAMPLAY; + teamplay = 0; + cvar_set("teamplay", "0"); // DP needs this for sending proper getstatus replies. + GameRules_spawning_teams(false); + } } void GameRules_spawning_teams(bool value) { - have_team_spawns = value ? -1 : 0; + have_team_spawns = value ? -1 : 0; } bool _GameRules_score_enabled = true; void GameRules_score_enabled(bool value) { - _GameRules_score_enabled = value; + _GameRules_score_enabled = value; } bool GameRules_limit_score_initialized; void GameRules_limit_score(int limit) { - if (GameRules_limit_score_initialized) return; - if (autocvar_g_campaign) return; - if (limit < 0) return; - cvar_set("fraglimit", ftos(limit)); - GameRules_limit_score_initialized = true; + if (GameRules_limit_score_initialized) { return; } + if (autocvar_g_campaign) { return; } + if (limit < 0) { return; } + cvar_set("fraglimit", ftos(limit)); + GameRules_limit_score_initialized = true; } bool GameRules_limit_lead_initialized; void GameRules_limit_lead(int limit) { - if (GameRules_limit_lead_initialized) return; - if (autocvar_g_campaign) return; - if (limit < 0) return; - cvar_set("leadlimit", ftos(limit)); - GameRules_limit_lead_initialized = true; + if (GameRules_limit_lead_initialized) { return; } + if (autocvar_g_campaign) { return; } + if (limit < 0) { return; } + cvar_set("leadlimit", ftos(limit)); + GameRules_limit_lead_initialized = true; } bool GameRules_limit_time_initialized; void GameRules_limit_time(int limit) { - if (GameRules_limit_time_initialized) return; - if (autocvar_g_campaign) return; - if (limit < 0) return; - cvar_set("timelimit", ftos(limit)); - GameRules_limit_time_initialized = true; + if (GameRules_limit_time_initialized) { return; } + if (autocvar_g_campaign) { return; } + if (limit < 0) { return; } + cvar_set("timelimit", ftos(limit)); + GameRules_limit_time_initialized = true; } bool GameRules_limit_time_qualifying_initialized; void GameRules_limit_time_qualifying(int limit) { - if (GameRules_limit_time_qualifying_initialized) return; - if (autocvar_g_campaign) return; - if (limit < 0) return; - cvar_set("g_race_qualifying_timelimit", ftos(limit)); - GameRules_limit_time_qualifying_initialized = true; + if (GameRules_limit_time_qualifying_initialized) { return; } + if (autocvar_g_campaign) { return; } + if (limit < 0) { return; } + cvar_set("g_race_qualifying_timelimit", ftos(limit)); + GameRules_limit_time_qualifying_initialized = true; } void GameRules_limit_fallbacks() { - GameRules_limit_score(autocvar_fraglimit_override); - GameRules_limit_lead(autocvar_leadlimit_override); - GameRules_limit_time(autocvar_timelimit_override); + GameRules_limit_score(autocvar_fraglimit_override); + GameRules_limit_lead(autocvar_leadlimit_override); + GameRules_limit_time(autocvar_timelimit_override); } void _GameRules_scoring_begin(int teams, float spprio, float stprio) { - ScoreRules_basics(teams, spprio, stprio, _GameRules_score_enabled); + ScoreRules_basics(teams, spprio, stprio, _GameRules_score_enabled); } void _GameRules_scoring_field(entity i, string label, int scoreflags) { - ScoreInfo_SetLabel_PlayerScore(i, label, scoreflags); + ScoreInfo_SetLabel_PlayerScore(i, label, scoreflags); } void _GameRules_scoring_field_team(float i, string label, int scoreflags) { - ScoreInfo_SetLabel_TeamScore(i, label, scoreflags); + ScoreInfo_SetLabel_TeamScore(i, label, scoreflags); } void _GameRules_scoring_end() { - ScoreRules_basics_end(); + ScoreRules_basics_end(); } .bool m_GameRules_scoring_vip; void GameRules_scoring_vip(entity player, bool value) { - player.m_GameRules_scoring_vip = value; + player.m_GameRules_scoring_vip = value; } bool GameRules_scoring_is_vip(entity player) { - return player.m_GameRules_scoring_vip; + return player.m_GameRules_scoring_vip; } float _GameRules_scoring_add(entity client, entity sp, float value) { - return PlayerScore_Add(client, sp, value); + return PlayerScore_Add(client, sp, value); } float _GameRules_scoring_add_team(entity client, entity sp, int st, float value) { - return PlayerTeamScore_Add(client, sp, st, value); + return PlayerTeamScore_Add(client, sp, st, value); } diff --git a/qcsrc/common/gamemodes/sv_rules.qh b/qcsrc/common/gamemodes/sv_rules.qh index 7a4e44cfb..bb6b66160 100644 --- a/qcsrc/common/gamemodes/sv_rules.qh +++ b/qcsrc/common/gamemodes/sv_rules.qh @@ -28,14 +28,15 @@ void GameRules_limit_fallbacks(); * @param spprio player score priority (if frags aren't enabled) * @param stprio team score priority (if frags aren't enabled) */ -#define GameRules_scoring(teams, spprio, stprio, fields) MACRO_BEGIN \ - _GameRules_scoring_begin((teams), (spprio), (stprio)); \ - noref void(entity, string, float) field = _GameRules_scoring_field; \ - /* todo: just have the one `field` function */ \ - noref void(int, string, float) field_team = _GameRules_scoring_field_team; \ - LAMBDA(fields); \ - _GameRules_scoring_end(); \ -MACRO_END +#define GameRules_scoring(teams, spprio, stprio, fields) \ + MACRO_BEGIN \ + _GameRules_scoring_begin((teams), (spprio), (stprio)); \ + noref void(entity, string, float) field = _GameRules_scoring_field; \ + /* todo: just have the one `field` function */ \ + noref void(int, string, float) field_team = _GameRules_scoring_field_team; \ + LAMBDA(fields); \ + _GameRules_scoring_end(); \ + MACRO_END void _GameRules_scoring_begin(int teams, float spprio, float stprio); void _GameRules_scoring_field(entity i, string label, int scoreflags); diff --git a/qcsrc/common/impulses/all.qh b/qcsrc/common/impulses/all.qh index 45a8f1323..4e3318838 100644 --- a/qcsrc/common/impulses/all.qh +++ b/qcsrc/common/impulses/all.qh @@ -12,7 +12,7 @@ REGISTRY_CHECK(IMPULSES) .void(entity this) impulse_handle; #if defined(CSQC) -#define IMPULSE_ALIAS(alias, id) localcmd("\nalias " #alias " \"", id ,"\"\n") +#define IMPULSE_ALIAS(alias, id) localcmd("\nalias " #alias " \"", id, "\"\n") #else #define IMPULSE_ALIAS(alias, id) #endif @@ -28,12 +28,16 @@ REGISTRY_CHECK(IMPULSES) #define LEGACY_IMPULSE_ID(alias, id) LEGACY_IMPULSE(alias, id, sprintf("impulse %d", IMP_##alias.impulse)) #define LEGACY_IMPULSE(alias, id, new) \ - STATIC_INIT(legacy_##alias) { \ + STATIC_INIT(legacy_##alias) \ + { \ string s = new; \ - if (s == #alias) LOG_FATALF("LEGACY_IMPULSE: would define a recursive alias for '%s', use LEGACY_IMPULSE_ID instead", s); \ + if (s == #alias) { LOG_FATALF("LEGACY_IMPULSE: would define a recursive alias for '%s', use LEGACY_IMPULSE_ID instead", s); } \ IMPULSE_ALIAS(alias, s); \ } \ - SHUTDOWN(legacy_##alias) { IMPULSE_ALIAS(alias, "impulse " #id); } + SHUTDOWN(legacy_##alias) \ + { \ + IMPULSE_ALIAS(alias, "impulse " #id); \ + } #define X(slot, imp) \ REGISTER_IMPULSE(weapon_group_##slot, imp) \ diff --git a/qcsrc/common/items/all.qc b/qcsrc/common/items/all.qc index 0a26a75b5..779d266dc 100644 --- a/qcsrc/common/items/all.qc +++ b/qcsrc/common/items/all.qc @@ -2,26 +2,26 @@ void Dump_Items() { - FOREACH(Items, true, ITEM_HANDLE(Show, it)); + FOREACH(Items, true, ITEM_HANDLE(Show, it)); } string Item_Model(string item_mdl) { - string output = strcat("models/items/", item_mdl); + string output = strcat("models/items/", item_mdl); #ifdef SVQC - MUTATOR_CALLHOOK(ItemModel, item_mdl, output); - output = M_ARGV(1, string); + MUTATOR_CALLHOOK(ItemModel, item_mdl, output); + output = M_ARGV(1, string); #endif - return output; + return output; } string Item_Sound(string it_snd) { string output = strcat("misc/", it_snd); #ifdef SVQC - MUTATOR_CALLHOOK(ItemSound, it_snd, output); - return M_ARGV(1, string); + MUTATOR_CALLHOOK(ItemSound, it_snd, output); + return M_ARGV(1, string); #else - return output; + return output; #endif } diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index c302ae402..114fb7d2c 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -6,41 +6,41 @@ #include #endif -const int IT_UNLIMITED_WEAPON_AMMO = BIT(0); // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup. -const int IT_UNLIMITED_SUPERWEAPONS = BIT(1); // when this bit is set, superweapons don't expire. Checkpoints can give this powerup. +const int IT_UNLIMITED_WEAPON_AMMO = BIT(0); // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup. +const int IT_UNLIMITED_SUPERWEAPONS = BIT(1); // when this bit is set, superweapons don't expire. Checkpoints can give this powerup. -const int IT_JETPACK = BIT(2); // actual item -const int IT_USING_JETPACK = BIT(3); // confirmation that button is pressed -const int IT_FUEL_REGEN = BIT(4); // fuel regeneration trigger +const int IT_JETPACK = BIT(2); // actual item +const int IT_USING_JETPACK = BIT(3); // confirmation that button is pressed +const int IT_FUEL_REGEN = BIT(4); // fuel regeneration trigger -const int IT_FUEL = BIT(5); +const int IT_FUEL = BIT(5); const int IT_SHELLS = BIT(6); const int IT_NAILS = BIT(7); const int IT_ROCKETS = BIT(8); const int IT_CELLS = BIT(9); -const int IT_PLASMA = BIT(10); +const int IT_PLASMA = BIT(10); -const int IT_5HP = BIT(11); -const int IT_25HP = BIT(12); -const int IT_HEALTH = BIT(13); +const int IT_5HP = BIT(11); +const int IT_25HP = BIT(12); +const int IT_HEALTH = BIT(13); -const int IT_ARMOR_SHARD = BIT(14); -const int IT_ARMOR = BIT(15); +const int IT_ARMOR_SHARD = BIT(14); +const int IT_ARMOR = BIT(15); -const int IT_KEY1 = BIT(16); -const int IT_KEY2 = BIT(17); +const int IT_KEY1 = BIT(16); +const int IT_KEY2 = BIT(17); -const int IT_CTF_SHIELDED = BIT(18); // set for the flag shield +const int IT_CTF_SHIELDED = BIT(18); // set for the flag shield // special colorblend meaning in engine -const int IT_INVISIBILITY = BIT(19); -const int IT_INVINCIBLE = BIT(20); -const int IT_SUPERWEAPON = BIT(21); // suit -const int IT_STRENGTH = BIT(22); +const int IT_INVISIBILITY = BIT(19); +const int IT_INVINCIBLE = BIT(20); +const int IT_SUPERWEAPON = BIT(21); // suit +const int IT_STRENGTH = BIT(22); // item masks -const int IT_UNLIMITED_AMMO = IT_UNLIMITED_WEAPON_AMMO | IT_UNLIMITED_SUPERWEAPONS; -const int IT_PICKUPMASK = IT_UNLIMITED_AMMO | IT_JETPACK | IT_FUEL_REGEN; // strength and invincible are handled separately +const int IT_UNLIMITED_AMMO = IT_UNLIMITED_WEAPON_AMMO | IT_UNLIMITED_SUPERWEAPONS; +const int IT_PICKUPMASK = IT_UNLIMITED_AMMO | IT_JETPACK | IT_FUEL_REGEN; // strength and invincible are handled separately #ifdef SVQC .float strength_finished = _STAT(STRENGTH_FINISHED); @@ -49,25 +49,25 @@ const int IT_PICKUPMASK = IT_UNLIMITED_AMMO | IT_JETPACK | IT_FU #define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__) CLASS(GameItem, Object) - ATTRIB(GameItem, m_id, int, 0); - ATTRIB(GameItem, m_name, string); - ATTRIB(GameItem, m_icon, string); - ATTRIB(GameItem, m_color, vector, '1 1 1'); - ATTRIB(GameItem, m_waypoint, string); - ATTRIB(GameItem, m_waypointblink, int, 1); + ATTRIB(GameItem, m_id, int, 0); + ATTRIB(GameItem, m_name, string); + ATTRIB(GameItem, m_icon, string); + ATTRIB(GameItem, m_color, vector, '1 1 1'); + ATTRIB(GameItem, m_waypoint, string); + ATTRIB(GameItem, m_waypointblink, int, 1); #ifdef GAMEQC - ATTRIB(GameItem, m_glow, bool, false); - ATTRIB(GameItem, m_respawnsound, Sound, SND_ITEMRESPAWN); + ATTRIB(GameItem, m_glow, bool, false); + ATTRIB(GameItem, m_respawnsound, Sound, SND_ITEMRESPAWN); #endif - METHOD(GameItem, display, void(GameItem this, void(string name, string icon) returns)) - { - TC(GameItem, this); - returns(this.m_name, this.m_icon ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.m_icon) : string_null); - } - METHOD(GameItem, show, void(GameItem this)) - { - TC(GameItem, this); - LOG_INFO("A game item"); - } - void ITEM_HANDLE(Show, GameItem this) { this.show(this); } + METHOD(GameItem, display, void(GameItem this, void(string name, string icon) returns)) + { + TC(GameItem, this); + returns(this.m_name, this.m_icon ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.m_icon) : string_null); + } + METHOD(GameItem, show, void(GameItem this)) + { + TC(GameItem, this); + LOG_INFO("A game item"); + } + void ITEM_HANDLE(Show, GameItem this) { this.show(this); } ENDCLASS(GameItem) diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index 209639285..89f05a830 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -7,15 +7,15 @@ PROPERTY(float, g_pickup_ammo_anyway); CLASS(Ammo, Pickup) #ifdef SVQC - ATTRIB(Ammo, m_pickupevalfunc, float(entity player, entity item), ammo_pickupevalfunc); - ATTRIB(Ammo, m_respawntime, float(), GET(g_pickup_respawntime_ammo)); - ATTRIB(Ammo, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_ammo)); - ATTRIB(Ammo, m_pickupanyway, float(), GET(g_pickup_ammo_anyway)); + ATTRIB(Ammo, m_pickupevalfunc, float(entity player, entity item), ammo_pickupevalfunc); + ATTRIB(Ammo, m_respawntime, float(), GET(g_pickup_respawntime_ammo)); + ATTRIB(Ammo, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_ammo)); + ATTRIB(Ammo, m_pickupanyway, float(), GET(g_pickup_ammo_anyway)); #endif ENDCLASS(Ammo) #ifdef SVQC - #include + #include #endif #ifdef GAMEQC @@ -26,21 +26,23 @@ MODEL(Bullets_ITEM, Item_Model("a_bullets.mdl")); PROPERTY(int, g_pickup_nails); void ammo_bullets_init(entity item) { - if(!item.ammo_nails) - item.ammo_nails = g_pickup_nails; + if (!item.ammo_nails) { + item.ammo_nails = g_pickup_nails; + } } #endif -REGISTER_ITEM(Bullets, Ammo) { +REGISTER_ITEM(Bullets, Ammo) +{ #ifdef GAMEQC - this.m_model = MDL_Bullets_ITEM; + this.m_model = MDL_Bullets_ITEM; #endif - this.netname = "bullets"; - this.m_name = "bullets"; - this.m_icon = "ammo_bullets"; + this.netname = "bullets"; + this.m_name = "bullets"; + this.m_icon = "ammo_bullets"; #ifdef SVQC - this.m_botvalue = 1500; - this.m_itemid = IT_NAILS; - this.m_iteminit = ammo_bullets_init; + this.m_botvalue = 1500; + this.m_itemid = IT_NAILS; + this.m_iteminit = ammo_bullets_init; #endif } @@ -52,21 +54,23 @@ MODEL(Cells_ITEM, Item_Model("a_cells.md3")); PROPERTY(int, g_pickup_cells); void ammo_cells_init(entity item) { - if(!item.ammo_cells) - item.ammo_cells = g_pickup_cells; + if (!item.ammo_cells) { + item.ammo_cells = g_pickup_cells; + } } #endif -REGISTER_ITEM(Cells, Ammo) { +REGISTER_ITEM(Cells, Ammo) +{ #ifdef GAMEQC - this.m_model = MDL_Cells_ITEM; + this.m_model = MDL_Cells_ITEM; #endif - this.netname = "cells"; - this.m_name = "cells"; - this.m_icon = "ammo_cells"; + this.netname = "cells"; + this.m_name = "cells"; + this.m_icon = "ammo_cells"; #ifdef SVQC - this.m_botvalue = 1500; - this.m_itemid = IT_CELLS; - this.m_iteminit = ammo_cells_init; + this.m_botvalue = 1500; + this.m_itemid = IT_CELLS; + this.m_iteminit = ammo_cells_init; #endif } @@ -78,21 +82,23 @@ MODEL(Plasma_ITEM, Item_Model("a_cells.md3")); PROPERTY(int, g_pickup_plasma); void ammo_plasma_init(entity item) { - if(!item.ammo_plasma) - item.ammo_plasma = g_pickup_plasma; + if (!item.ammo_plasma) { + item.ammo_plasma = g_pickup_plasma; + } } #endif -REGISTER_ITEM(Plasma, Ammo) { +REGISTER_ITEM(Plasma, Ammo) +{ #ifdef GAMEQC - this.m_model = MDL_Plasma_ITEM; + this.m_model = MDL_Plasma_ITEM; #endif - this.netname = "plasma"; - this.m_name = "plasma"; - this.m_icon = "ammo_plasma"; + this.netname = "plasma"; + this.m_name = "plasma"; + this.m_icon = "ammo_plasma"; #ifdef SVQC - this.m_botvalue = 1500; - this.m_itemid = IT_PLASMA; - this.m_iteminit = ammo_plasma_init; + this.m_botvalue = 1500; + this.m_itemid = IT_PLASMA; + this.m_iteminit = ammo_plasma_init; #endif } @@ -104,21 +110,23 @@ MODEL(Rockets_ITEM, Item_Model("a_rockets.md3")); PROPERTY(int, g_pickup_rockets); void ammo_rockets_init(entity item) { - if(!item.ammo_rockets) - item.ammo_rockets = g_pickup_rockets; + if (!item.ammo_rockets) { + item.ammo_rockets = g_pickup_rockets; + } } #endif -REGISTER_ITEM(Rockets, Ammo) { +REGISTER_ITEM(Rockets, Ammo) +{ #ifdef GAMEQC - this.m_model = MDL_Rockets_ITEM; + this.m_model = MDL_Rockets_ITEM; #endif - this.netname = "rockets"; - this.m_name = "rockets"; - this.m_icon = "ammo_rockets"; + this.netname = "rockets"; + this.m_name = "rockets"; + this.m_icon = "ammo_rockets"; #ifdef SVQC - this.m_botvalue = 1500; - this.m_itemid = IT_ROCKETS; - this.m_iteminit = ammo_rockets_init; + this.m_botvalue = 1500; + this.m_itemid = IT_ROCKETS; + this.m_iteminit = ammo_rockets_init; #endif } @@ -130,20 +138,22 @@ MODEL(Shells_ITEM, Item_Model("a_shells.md3")); PROPERTY(int, g_pickup_shells); void ammo_shells_init(entity item) { - if(!item.ammo_shells) - item.ammo_shells = g_pickup_shells; + if (!item.ammo_shells) { + item.ammo_shells = g_pickup_shells; + } } #endif -REGISTER_ITEM(Shells, Ammo) { +REGISTER_ITEM(Shells, Ammo) +{ #ifdef GAMEQC - this.m_model = MDL_Shells_ITEM; + this.m_model = MDL_Shells_ITEM; #endif - this.netname = "shells"; - this.m_name = "shells"; - this.m_icon = "ammo_shells"; + this.netname = "shells"; + this.m_name = "shells"; + this.m_icon = "ammo_shells"; #ifdef SVQC - this.m_botvalue = 1000; - this.m_itemid = IT_SHELLS; - this.m_iteminit = ammo_shells_init; + this.m_botvalue = 1000; + this.m_itemid = IT_SHELLS; + this.m_iteminit = ammo_shells_init; #endif } diff --git a/qcsrc/common/items/item/armor.qh b/qcsrc/common/items/item/armor.qh index 0258cf881..d80f8a75e 100644 --- a/qcsrc/common/items/item/armor.qh +++ b/qcsrc/common/items/item/armor.qh @@ -3,15 +3,15 @@ #include "pickup.qh" CLASS(Armor, Pickup) #ifdef SVQC - ATTRIB(Armor, m_mins, vector, '-16 -16 0'); - ATTRIB(Armor, m_maxs, vector, '16 16 48'); - ATTRIB(Armor, m_pickupevalfunc, float(entity player, entity item), healtharmor_pickupevalfunc); - ATTRIB(Armor, m_botvalue, int, 5000); + ATTRIB(Armor, m_mins, vector, '-16 -16 0'); + ATTRIB(Armor, m_maxs, vector, '16 16 48'); + ATTRIB(Armor, m_pickupevalfunc, float(entity player, entity item), healtharmor_pickupevalfunc); + ATTRIB(Armor, m_botvalue, int, 5000); #endif ENDCLASS(Armor) #ifdef SVQC - #include + #include #endif #ifdef GAMEQC @@ -24,27 +24,30 @@ PROPERTY(int, g_pickup_armorsmall); PROPERTY(int, g_pickup_armorsmall_max); void item_armorsmall_init(entity item) { - if(!item.max_armorvalue) - item.max_armorvalue = g_pickup_armorsmall_max; - if(!item.armorvalue) - item.armorvalue = g_pickup_armorsmall; + if (!item.max_armorvalue) { + item.max_armorvalue = g_pickup_armorsmall_max; + } + if (!item.armorvalue) { + item.armorvalue = g_pickup_armorsmall; + } } #endif -REGISTER_ITEM(ArmorSmall, Armor) { +REGISTER_ITEM(ArmorSmall, Armor) +{ #ifdef GAMEQC - this.m_model = MDL_ArmorSmall_ITEM; - this.m_sound = SND_ArmorSmall; + this.m_model = MDL_ArmorSmall_ITEM; + this.m_sound = SND_ArmorSmall; #endif - this.netname = "armor_small"; - this.m_name = "5 Armor"; - this.m_icon = "armor"; + this.netname = "armor_small"; + this.m_name = "5 Armor"; + this.m_icon = "armor"; #ifdef SVQC - this.m_itemid = IT_ARMOR_SHARD; - this.m_respawntime = GET(g_pickup_respawntime_short); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); - this.m_pickupanyway = GET(g_pickup_armorsmall_anyway); - this.m_iteminit = item_armorsmall_init; + this.m_itemid = IT_ARMOR_SHARD; + this.m_respawntime = GET(g_pickup_respawntime_short); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); + this.m_pickupanyway = GET(g_pickup_armorsmall_anyway); + this.m_iteminit = item_armorsmall_init; #endif } @@ -58,27 +61,30 @@ PROPERTY(int, g_pickup_armormedium); PROPERTY(int, g_pickup_armormedium_max); void item_armormedium_init(entity item) { - if(!item.max_armorvalue) - item.max_armorvalue = g_pickup_armormedium_max; - if(!item.armorvalue) - item.armorvalue = g_pickup_armormedium; + if (!item.max_armorvalue) { + item.max_armorvalue = g_pickup_armormedium_max; + } + if (!item.armorvalue) { + item.armorvalue = g_pickup_armormedium; + } } #endif -REGISTER_ITEM(ArmorMedium, Armor) { +REGISTER_ITEM(ArmorMedium, Armor) +{ #ifdef GAMEQC - this.m_model = MDL_ArmorMedium_ITEM; - this.m_sound = SND_ArmorMedium; + this.m_model = MDL_ArmorMedium_ITEM; + this.m_sound = SND_ArmorMedium; #endif - this.netname = "armor_medium"; - this.m_name = "25 Armor"; - this.m_icon = "armor"; + this.netname = "armor_medium"; + this.m_name = "25 Armor"; + this.m_icon = "armor"; #ifdef SVQC - this.m_itemid = IT_ARMOR; - this.m_respawntime = GET(g_pickup_respawntime_medium); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_medium); - this.m_pickupanyway = GET(g_pickup_armormedium_anyway); - this.m_iteminit = item_armormedium_init; + this.m_itemid = IT_ARMOR; + this.m_respawntime = GET(g_pickup_respawntime_medium); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_medium); + this.m_pickupanyway = GET(g_pickup_armormedium_anyway); + this.m_iteminit = item_armormedium_init; #endif } @@ -92,29 +98,32 @@ PROPERTY(int, g_pickup_armorbig); PROPERTY(int, g_pickup_armorbig_max); void item_armorbig_init(entity item) { - if(!item.max_armorvalue) - item.max_armorvalue = g_pickup_armorbig_max; - if(!item.armorvalue) - item.armorvalue = g_pickup_armorbig; + if (!item.max_armorvalue) { + item.max_armorvalue = g_pickup_armorbig_max; + } + if (!item.armorvalue) { + item.armorvalue = g_pickup_armorbig; + } } #endif -REGISTER_ITEM(ArmorBig, Armor) { +REGISTER_ITEM(ArmorBig, Armor) +{ #ifdef GAMEQC - this.m_model = MDL_ArmorBig_ITEM; - this.m_sound = SND_ArmorBig; -#endif - this.netname = "armor_big"; - this.m_name = "50 Armor"; - this.m_icon = "armor"; - this.m_color = '0 1 0'; - this.m_waypoint = _("Big armor"); + this.m_model = MDL_ArmorBig_ITEM; + this.m_sound = SND_ArmorBig; +#endif + this.netname = "armor_big"; + this.m_name = "50 Armor"; + this.m_icon = "armor"; + this.m_color = '0 1 0'; + this.m_waypoint = _("Big armor"); #ifdef SVQC - this.m_itemid = IT_ARMOR; - this.m_respawntime = GET(g_pickup_respawntime_long); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); - this.m_pickupanyway = GET(g_pickup_armorbig_anyway); - this.m_iteminit = item_armorbig_init; + this.m_itemid = IT_ARMOR; + this.m_respawntime = GET(g_pickup_respawntime_long); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); + this.m_pickupanyway = GET(g_pickup_armorbig_anyway); + this.m_iteminit = item_armorbig_init; #endif } @@ -128,30 +137,33 @@ PROPERTY(int, g_pickup_armormega); PROPERTY(int, g_pickup_armormega_max); void item_armormega_init(entity item) { - if(!item.max_armorvalue) - item.max_armorvalue = g_pickup_armormega_max; - if(!item.armorvalue) - item.armorvalue = g_pickup_armormega; + if (!item.max_armorvalue) { + item.max_armorvalue = g_pickup_armormega_max; + } + if (!item.armorvalue) { + item.armorvalue = g_pickup_armormega; + } } #endif -REGISTER_ITEM(ArmorMega, Armor) { +REGISTER_ITEM(ArmorMega, Armor) +{ #ifdef GAMEQC - this.m_model = MDL_ArmorMega_ITEM; - this.m_sound = SND_ArmorMega; -#endif - this.netname = "armor_mega"; - this.m_name = "100 Armor"; - this.m_icon = "item_large_armor"; - this.m_color = '0 1 0'; - this.m_waypoint = _("Mega armor"); - this.m_waypointblink = 2; + this.m_model = MDL_ArmorMega_ITEM; + this.m_sound = SND_ArmorMega; +#endif + this.netname = "armor_mega"; + this.m_name = "100 Armor"; + this.m_icon = "item_large_armor"; + this.m_color = '0 1 0'; + this.m_waypoint = _("Mega armor"); + this.m_waypointblink = 2; #ifdef SVQC - this.m_maxs = '16 16 70'; - this.m_itemid = IT_ARMOR; - this.m_respawntime = GET(g_pickup_respawntime_long); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); - this.m_pickupanyway = GET(g_pickup_armormega_anyway); - this.m_iteminit = item_armormega_init; + this.m_maxs = '16 16 70'; + this.m_itemid = IT_ARMOR; + this.m_respawntime = GET(g_pickup_respawntime_long); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); + this.m_pickupanyway = GET(g_pickup_armormega_anyway); + this.m_iteminit = item_armormega_init; #endif } diff --git a/qcsrc/common/items/item/health.qh b/qcsrc/common/items/item/health.qh index cad5a376e..b2b2bbc29 100644 --- a/qcsrc/common/items/item/health.qh +++ b/qcsrc/common/items/item/health.qh @@ -3,15 +3,15 @@ #include "pickup.qh" CLASS(Health, Pickup) #ifdef SVQC - ATTRIB(Health, m_mins, vector, '-16 -16 0'); - ATTRIB(Health, m_maxs, vector, '16 16 48'); - ATTRIB(Health, m_pickupevalfunc, float(entity player, entity item), healtharmor_pickupevalfunc); - ATTRIB(Health, m_botvalue, int, 5000); + ATTRIB(Health, m_mins, vector, '-16 -16 0'); + ATTRIB(Health, m_maxs, vector, '16 16 48'); + ATTRIB(Health, m_pickupevalfunc, float(entity player, entity item), healtharmor_pickupevalfunc); + ATTRIB(Health, m_botvalue, int, 5000); #endif ENDCLASS(Health) #ifdef SVQC - #include + #include #endif #ifdef GAMEQC @@ -24,27 +24,30 @@ PROPERTY(int, g_pickup_healthsmall); PROPERTY(int, g_pickup_healthsmall_max); void item_healthsmall_init(entity item) { - if(!item.max_health) - item.max_health = g_pickup_healthsmall_max; - if(!item.health) - item.health = g_pickup_healthsmall; + if (!item.max_health) { + item.max_health = g_pickup_healthsmall_max; + } + if (!item.health) { + item.health = g_pickup_healthsmall; + } } #endif -REGISTER_ITEM(HealthSmall, Health) { +REGISTER_ITEM(HealthSmall, Health) +{ #ifdef GAMEQC - this.m_model = MDL_HealthSmall_ITEM; - this.m_sound = SND_HealthSmall; + this.m_model = MDL_HealthSmall_ITEM; + this.m_sound = SND_HealthSmall; #endif - this.netname = "health_small"; - this.m_name = "5 Health"; - this.m_icon = "health"; + this.netname = "health_small"; + this.m_name = "5 Health"; + this.m_icon = "health"; #ifdef SVQC - this.m_itemid = IT_5HP; - this.m_respawntime = GET(g_pickup_respawntime_short); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); - this.m_pickupanyway = GET(g_pickup_healthsmall_anyway); - this.m_iteminit = item_healthsmall_init; + this.m_itemid = IT_5HP; + this.m_respawntime = GET(g_pickup_respawntime_short); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); + this.m_pickupanyway = GET(g_pickup_healthsmall_anyway); + this.m_iteminit = item_healthsmall_init; #endif } @@ -58,27 +61,30 @@ PROPERTY(int, g_pickup_healthmedium); PROPERTY(int, g_pickup_healthmedium_max); void item_healthmedium_init(entity item) { - if(!item.max_health) - item.max_health = g_pickup_healthmedium_max; - if(!item.health) - item.health = g_pickup_healthmedium; + if (!item.max_health) { + item.max_health = g_pickup_healthmedium_max; + } + if (!item.health) { + item.health = g_pickup_healthmedium; + } } #endif -REGISTER_ITEM(HealthMedium, Health) { +REGISTER_ITEM(HealthMedium, Health) +{ #ifdef GAMEQC - this.m_model = MDL_HealthMedium_ITEM; - this.m_sound = SND_HealthMedium; + this.m_model = MDL_HealthMedium_ITEM; + this.m_sound = SND_HealthMedium; #endif - this.netname = "health_medium"; - this.m_name = "25 Health"; - this.m_icon = "health"; + this.netname = "health_medium"; + this.m_name = "25 Health"; + this.m_icon = "health"; #ifdef SVQC - this.m_itemid = IT_25HP; - this.m_respawntime = GET(g_pickup_respawntime_short); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); - this.m_pickupanyway = GET(g_pickup_healthmedium_anyway); - this.m_iteminit = item_healthmedium_init; + this.m_itemid = IT_25HP; + this.m_respawntime = GET(g_pickup_respawntime_short); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); + this.m_pickupanyway = GET(g_pickup_healthmedium_anyway); + this.m_iteminit = item_healthmedium_init; #endif } @@ -92,29 +98,32 @@ PROPERTY(int, g_pickup_healthbig); PROPERTY(int, g_pickup_healthbig_max); void item_healthbig_init(entity item) { - if(!item.max_health) - item.max_health = g_pickup_healthbig_max; - if(!item.health) - item.health = g_pickup_healthbig; + if (!item.max_health) { + item.max_health = g_pickup_healthbig_max; + } + if (!item.health) { + item.health = g_pickup_healthbig; + } } #endif -REGISTER_ITEM(HealthBig, Health) { +REGISTER_ITEM(HealthBig, Health) +{ #ifdef GAMEQC - this.m_model = MDL_HealthBig_ITEM; - this.m_sound = SND_HealthBig; -#endif - this.netname = "health_big"; - this.m_name = "50 Health"; - this.m_icon = "health"; - this.m_color = '1 0 0'; - this.m_waypoint = _("Big health"); + this.m_model = MDL_HealthBig_ITEM; + this.m_sound = SND_HealthBig; +#endif + this.netname = "health_big"; + this.m_name = "50 Health"; + this.m_icon = "health"; + this.m_color = '1 0 0'; + this.m_waypoint = _("Big health"); #ifdef SVQC - this.m_itemid = IT_25HP; - this.m_respawntime = GET(g_pickup_respawntime_medium); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_medium); - this.m_pickupanyway = GET(g_pickup_healthbig_anyway); - this.m_iteminit = item_healthbig_init; + this.m_itemid = IT_25HP; + this.m_respawntime = GET(g_pickup_respawntime_medium); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_medium); + this.m_pickupanyway = GET(g_pickup_healthbig_anyway); + this.m_iteminit = item_healthbig_init; #endif } @@ -128,30 +137,33 @@ PROPERTY(int, g_pickup_healthmega); PROPERTY(int, g_pickup_healthmega_max); void item_healthmega_init(entity item) { - if(!item.max_health) - item.max_health = g_pickup_healthmega_max; - if(!item.health) - item.health = g_pickup_healthmega; + if (!item.max_health) { + item.max_health = g_pickup_healthmega_max; + } + if (!item.health) { + item.health = g_pickup_healthmega; + } } #endif -REGISTER_ITEM(HealthMega, Health) { +REGISTER_ITEM(HealthMega, Health) +{ #ifdef GAMEQC - this.m_model = MDL_HealthMega_ITEM; - this.m_sound = SND_HealthMega; -#endif - this.netname = "health_mega"; - this.m_name = "100 Health"; - this.m_icon = "item_mega_health"; - this.m_color = '1 0 0'; - this.m_waypoint = _("Mega health"); - this.m_waypointblink = 2; + this.m_model = MDL_HealthMega_ITEM; + this.m_sound = SND_HealthMega; +#endif + this.netname = "health_mega"; + this.m_name = "100 Health"; + this.m_icon = "item_mega_health"; + this.m_color = '1 0 0'; + this.m_waypoint = _("Mega health"); + this.m_waypointblink = 2; #ifdef SVQC - this.m_maxs = '16 16 70'; - this.m_itemid = IT_HEALTH; - this.m_respawntime = GET(g_pickup_respawntime_long); - this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); - this.m_pickupanyway = GET(g_pickup_healthmega_anyway); - this.m_iteminit = item_healthmega_init; + this.m_maxs = '16 16 70'; + this.m_itemid = IT_HEALTH; + this.m_respawntime = GET(g_pickup_respawntime_long); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); + this.m_pickupanyway = GET(g_pickup_healthmega_anyway); + this.m_iteminit = item_healthmega_init; #endif } diff --git a/qcsrc/common/items/item/jetpack.qh b/qcsrc/common/items/item/jetpack.qh index a6d1c8dae..b1a67d0ca 100644 --- a/qcsrc/common/items/item/jetpack.qh +++ b/qcsrc/common/items/item/jetpack.qh @@ -1,7 +1,7 @@ #pragma once #ifdef SVQC - #include + #include #endif #include "ammo.qh" @@ -19,25 +19,27 @@ MODEL(Jetpack_ITEM, Item_Model("g_jetpack.md3")); PROPERTY(int, g_pickup_fuel_jetpack); void powerup_jetpack_init(entity item) { - if(!item.ammo_fuel) - item.ammo_fuel = g_pickup_fuel_jetpack; + if (!item.ammo_fuel) { + item.ammo_fuel = g_pickup_fuel_jetpack; + } } #endif -REGISTER_ITEM(Jetpack, Powerup) { +REGISTER_ITEM(Jetpack, Powerup) +{ #ifdef GAMEQC - this.m_model = MDL_Jetpack_ITEM; - this.m_itemid = IT_JETPACK; + this.m_model = MDL_Jetpack_ITEM; + this.m_itemid = IT_JETPACK; #endif - this.netname = "jetpack"; - this.m_name = "Jet pack"; - this.m_icon = "jetpack"; - this.m_color = '0.5 0.5 0.5'; - this.m_waypoint = _("Jet Pack"); - this.m_waypointblink = 2; + this.netname = "jetpack"; + this.m_name = "Jet pack"; + this.m_icon = "jetpack"; + this.m_color = '0.5 0.5 0.5'; + this.m_waypoint = _("Jet Pack"); + this.m_waypointblink = 2; #ifdef SVQC - this.m_botvalue = 3000; - this.m_pickupevalfunc = ammo_pickupevalfunc; - this.m_iteminit = powerup_jetpack_init; + this.m_botvalue = 3000; + this.m_pickupevalfunc = ammo_pickupevalfunc; + this.m_iteminit = powerup_jetpack_init; #endif } @@ -49,21 +51,23 @@ MODEL(JetpackFuel_ITEM, Item_Model("g_fuel.md3")); PROPERTY(int, g_pickup_fuel); void ammo_fuel_init(entity item) { - if(!item.ammo_fuel) - item.ammo_fuel = g_pickup_fuel; + if (!item.ammo_fuel) { + item.ammo_fuel = g_pickup_fuel; + } } #endif -REGISTER_ITEM(JetpackFuel, Ammo) { +REGISTER_ITEM(JetpackFuel, Ammo) +{ #ifdef GAMEQC - this.m_model = MDL_JetpackFuel_ITEM; + this.m_model = MDL_JetpackFuel_ITEM; #endif - this.netname = "fuel"; - this.m_name = "Fuel"; - this.m_icon = "ammo_fuel"; + this.netname = "fuel"; + this.m_name = "Fuel"; + this.m_icon = "ammo_fuel"; #ifdef SVQC - this.m_botvalue = 2000; - this.m_itemid = IT_FUEL; - this.m_iteminit = ammo_fuel_init; + this.m_botvalue = 2000; + this.m_itemid = IT_FUEL; + this.m_iteminit = ammo_fuel_init; #endif } @@ -71,19 +75,20 @@ REGISTER_ITEM(JetpackFuel, Ammo) { MODEL(JetpackRegen_ITEM, Item_Model("g_fuelregen.md3")); #endif -REGISTER_ITEM(JetpackRegen, Powerup) { +REGISTER_ITEM(JetpackRegen, Powerup) +{ #ifdef GAMEQC - this.m_model = MDL_JetpackRegen_ITEM; + this.m_model = MDL_JetpackRegen_ITEM; #endif - this.netname = "fuel_regen"; - this.m_name = "Fuel regenerator"; - this.m_icon = "fuelregen"; - this.m_color = '1 0.5 0'; - this.m_waypoint = _("Fuel regen"); - this.m_waypointblink = 2; + this.netname = "fuel_regen"; + this.m_name = "Fuel regenerator"; + this.m_icon = "fuelregen"; + this.m_color = '1 0.5 0'; + this.m_waypoint = _("Fuel regen"); + this.m_waypointblink = 2; #ifdef SVQC - this.m_botvalue = 3000; - this.m_itemid = IT_FUEL_REGEN; - this.m_pickupevalfunc = ammo_pickupevalfunc; + this.m_botvalue = 3000; + this.m_itemid = IT_FUEL_REGEN; + this.m_pickupevalfunc = ammo_pickupevalfunc; #endif } diff --git a/qcsrc/common/items/item/pickup.qc b/qcsrc/common/items/item/pickup.qc index fc958709e..d6ccc4427 100644 --- a/qcsrc/common/items/item/pickup.qc +++ b/qcsrc/common/items/item/pickup.qc @@ -1,7 +1,8 @@ #include "pickup.qh" #ifdef SVQC -bool ITEM_HANDLE(Pickup, entity this, entity item, entity player) { - return this.giveTo(this, item, player); +bool ITEM_HANDLE(Pickup, entity this, entity item, entity player) +{ + return this.giveTo(this, item, player); } #endif diff --git a/qcsrc/common/items/item/pickup.qh b/qcsrc/common/items/item/pickup.qh index 39cf78cc3..26a766977 100644 --- a/qcsrc/common/items/item/pickup.qh +++ b/qcsrc/common/items/item/pickup.qh @@ -29,40 +29,40 @@ PROPERTY(float, g_pickup_respawntimejitter_powerup) CLASS(Pickup, GameItem) #ifdef GAMEQC - ATTRIB(Pickup, m_model, Model); - ATTRIB(Pickup, m_sound, Sound, SND_ITEMPICKUP); + ATTRIB(Pickup, m_model, Model); + ATTRIB(Pickup, m_sound, Sound, SND_ITEMPICKUP); #endif - ATTRIB(Pickup, netname, string); - ATTRIB(Pickup, m_name, string); - METHOD(Pickup, show, void(Pickup this)) - { - TC(Pickup, this); - LOG_INFOF("%s: %s", etos(this), this.m_name); - } - ATTRIB(Pickup, m_itemid, int, 0); + ATTRIB(Pickup, netname, string); + ATTRIB(Pickup, m_name, string); + METHOD(Pickup, show, void(Pickup this)) + { + TC(Pickup, this); + LOG_INFOF("%s: %s", etos(this), this.m_name); + } + ATTRIB(Pickup, m_itemid, int, 0); #ifdef SVQC - ATTRIB(Pickup, m_mins, vector, '-16 -16 0'); - ATTRIB(Pickup, m_maxs, vector, '16 16 32'); - ATTRIB(Pickup, m_botvalue, int, 0); - ATTRIB(Pickup, m_itemflags, int, 0); - float generic_pickupevalfunc(entity player, entity item); - ATTRIB(Pickup, m_pickupevalfunc, float(entity player, entity item), generic_pickupevalfunc); - ATTRIB(Pickup, m_respawntime, float()); - ATTRIB(Pickup, m_respawntimejitter, float()); - ATTRIB(Pickup, m_pickupanyway, float()); - ATTRIB(Pickup, m_iteminit, void(entity item)); - float Item_GiveTo(entity item, entity player); - METHOD(Pickup, giveTo, bool(Pickup this, entity item, entity player)) - { - TC(Pickup, this); - bool b = Item_GiveTo(item, player); - if (b) { - LOG_DEBUGF("entity %i picked up %s", player, this.m_name); - player.inventory.inv_items[this.m_id]++; - Inventory_update(player); - } - return b; - } - bool ITEM_HANDLE(Pickup, Pickup this, entity item, entity player); + ATTRIB(Pickup, m_mins, vector, '-16 -16 0'); + ATTRIB(Pickup, m_maxs, vector, '16 16 32'); + ATTRIB(Pickup, m_botvalue, int, 0); + ATTRIB(Pickup, m_itemflags, int, 0); + float generic_pickupevalfunc(entity player, entity item); + ATTRIB(Pickup, m_pickupevalfunc, float(entity player, entity item), generic_pickupevalfunc); + ATTRIB(Pickup, m_respawntime, float()); + ATTRIB(Pickup, m_respawntimejitter, float()); + ATTRIB(Pickup, m_pickupanyway, float()); + ATTRIB(Pickup, m_iteminit, void(entity item)); + float Item_GiveTo(entity item, entity player); + METHOD(Pickup, giveTo, bool(Pickup this, entity item, entity player)) + { + TC(Pickup, this); + bool b = Item_GiveTo(item, player); + if (b) { + LOG_DEBUGF("entity %i picked up %s", player, this.m_name); + player.inventory.inv_items[this.m_id]++; + Inventory_update(player); + } + return b; + } + bool ITEM_HANDLE(Pickup, Pickup this, entity item, entity player); #endif ENDCLASS(Pickup) diff --git a/qcsrc/common/items/item/powerup.qh b/qcsrc/common/items/item/powerup.qh index 41b658c2f..b4a14830d 100644 --- a/qcsrc/common/items/item/powerup.qh +++ b/qcsrc/common/items/item/powerup.qh @@ -1,19 +1,19 @@ #pragma once #ifdef SVQC - // For FL_POWERUP - #include +// For FL_POWERUP + #include #endif #include "pickup.qh" CLASS(Powerup, Pickup) #ifdef SVQC - ATTRIB(Powerup, m_mins, vector, '-16 -16 0'); - ATTRIB(Powerup, m_maxs, vector, '16 16 80'); - ATTRIB(Powerup, m_botvalue, int, 20000); - ATTRIB(Powerup, m_itemflags, int, FL_POWERUP); - ATTRIB(Powerup, m_respawntime, float(), GET(g_pickup_respawntime_powerup)); - ATTRIB(Powerup, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_powerup)); + ATTRIB(Powerup, m_mins, vector, '-16 -16 0'); + ATTRIB(Powerup, m_maxs, vector, '16 16 80'); + ATTRIB(Powerup, m_botvalue, int, 20000); + ATTRIB(Powerup, m_itemflags, int, FL_POWERUP); + ATTRIB(Powerup, m_respawntime, float(), GET(g_pickup_respawntime_powerup)); + ATTRIB(Powerup, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_powerup)); #endif ENDCLASS(Powerup) @@ -26,26 +26,28 @@ SOUND(Strength, Item_Sound("powerup")); float autocvar_g_balance_powerup_strength_time; void powerup_strength_init(entity item) { - if(!item.strength_finished) - item.strength_finished = autocvar_g_balance_powerup_strength_time; + if (!item.strength_finished) { + item.strength_finished = autocvar_g_balance_powerup_strength_time; + } } #endif -REGISTER_ITEM(Strength, Powerup) { +REGISTER_ITEM(Strength, Powerup) +{ #ifdef GAMEQC - this.m_model = MDL_Strength_ITEM; - this.m_sound = SND_Strength; - this.m_glow = true; - this.m_respawnsound = SND_STRENGTH_RESPAWN; + this.m_model = MDL_Strength_ITEM; + this.m_sound = SND_Strength; + this.m_glow = true; + this.m_respawnsound = SND_STRENGTH_RESPAWN; #endif - this.netname = "strength"; - this.m_name = "Strength Powerup"; - this.m_icon = "strength"; - this.m_color = '0 0 1'; - this.m_waypoint = _("Strength"); - this.m_waypointblink = 2; - this.m_itemid = IT_STRENGTH; + this.netname = "strength"; + this.m_name = "Strength Powerup"; + this.m_icon = "strength"; + this.m_color = '0 0 1'; + this.m_waypoint = _("Strength"); + this.m_waypointblink = 2; + this.m_itemid = IT_STRENGTH; #ifdef SVQC - this.m_iteminit = powerup_strength_init; + this.m_iteminit = powerup_strength_init; #endif } @@ -58,25 +60,27 @@ SOUND(Shield, Item_Sound("powerup_shield")); float autocvar_g_balance_powerup_invincible_time; void powerup_shield_init(entity item) { - if(!item.invincible_finished) - item.invincible_finished = autocvar_g_balance_powerup_invincible_time; + if (!item.invincible_finished) { + item.invincible_finished = autocvar_g_balance_powerup_invincible_time; + } } #endif -REGISTER_ITEM(Shield, Powerup) { +REGISTER_ITEM(Shield, Powerup) +{ #ifdef GAMEQC - this.m_model = MDL_Shield_ITEM; - this.m_sound = SND_Shield; - this.m_glow = true; - this.m_respawnsound = SND_SHIELD_RESPAWN; + this.m_model = MDL_Shield_ITEM; + this.m_sound = SND_Shield; + this.m_glow = true; + this.m_respawnsound = SND_SHIELD_RESPAWN; #endif - this.netname = "invincible"; - this.m_name = "Shield"; - this.m_icon = "shield"; - this.m_color = '1 0 1'; - this.m_waypoint = _("Shield"); - this.m_waypointblink = 2; - this.m_itemid = IT_INVINCIBLE; + this.netname = "invincible"; + this.m_name = "Shield"; + this.m_icon = "shield"; + this.m_color = '1 0 1'; + this.m_waypoint = _("Shield"); + this.m_waypointblink = 2; + this.m_itemid = IT_INVINCIBLE; #ifdef SVQC - this.m_iteminit = powerup_shield_init; + this.m_iteminit = powerup_shield_init; #endif } diff --git a/qcsrc/common/minigames/cl_minigames.qh b/qcsrc/common/minigames/cl_minigames.qh index a0f6195d1..a5f782ee1 100644 --- a/qcsrc/common/minigames/cl_minigames.qh +++ b/qcsrc/common/minigames/cl_minigames.qh @@ -3,18 +3,14 @@ // Get a square in the center of the avaliable area // \note macro to pass by reference pos and mySize #define minigame_hud_fitsqare(pos, mySize) \ - if ( mySize##_x > mySize##_y ) \ - { \ - pos##_x += (mySize##_x-mySize##_y)/2; \ + if (mySize##_x > mySize##_y) { \ + pos##_x += (mySize##_x - mySize##_y) / 2; \ mySize##_x = mySize##_y; \ - } \ - else \ - { \ - pos##_y += (mySize##_y-mySize##_x)/2; \ + } else { \ + pos##_y += (mySize##_y - mySize##_x) / 2; \ mySize##_x = mySize##_x; \ } \ - if(panel_bg_padding) \ - { \ + if (panel_bg_padding) { \ pos += '1 1 0' * panel_bg_padding; \ mySize -= '2 2 0' * panel_bg_padding; \ } @@ -45,26 +41,21 @@ bool minigame_hud_mouse_in(vector pos, vector sz); // Like drawstring, but wrapping words to fit maxwidth // returns the size of the drawn area // align selects the string alignment (0 = left, 0.5 = center, 1 = right) -vector minigame_drawstring_wrapped( float maxwidth, vector pos, string text, - vector fontsize, vector color, float theAlpha, int drawflags, float align ); +vector minigame_drawstring_wrapped(float maxwidth, vector pos, string text, vector fontsize, vector color, float theAlpha, int drawflags, float align); // Like drawcolorcodedstring, but wrapping words to fit maxwidth // returns the size of the drawn area // align selects the string alignment (0 = left, 0.5 = center, 1 = right) -vector minigame_drawcolorcodedstring_wrapped( float maxwidth, vector pos, - string text, vector fontsize, float theAlpha, int drawflags, float align ); +vector minigame_drawcolorcodedstring_wrapped(float maxwidth, vector pos, string text, vector fontsize, float theAlpha, int drawflags, float align); // Like drawstring but truncates the text to fit maxwidth -void minigame_drawstring_trunc(float maxwidth, vector pos, string text, - vector fontsize, vector color, float theAlpha, int drawflags ); +void minigame_drawstring_trunc(float maxwidth, vector pos, string text, vector fontsize, vector color, float theAlpha, int drawflags); // Like drawcolorcodedstring but truncates the text to fit maxwidth -void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text, - vector fontsize, float theAlpha, int drawflags ); +void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text, vector fontsize, float theAlpha, int drawflags); // like drawpic but pos represent the center rather than the topleft corner -void minigame_drawpic_centered( vector pos, string texture, vector sz, - vector color, float thealpha, int drawflags ); +void minigame_drawpic_centered(vector pos, string texture, vector sz, vector color, float thealpha, int drawflags); // Get full path of a minigame texture string minigame_texture(string name); @@ -85,8 +76,8 @@ entity active_minigame; entity minigame_self; // Execute a minigame command -#define minigame_cmd(...) minigame_cmd_workaround(0,__VA_ARGS__) -void minigame_cmd_workaround(float dummy, string...cmdargc); +#define minigame_cmd(...) minigame_cmd_workaround(0, __VA_ARGS__) +void minigame_cmd_workaround(float dummy, string ... cmdargc); // Prompt the player to play in the current minigame // (ie: it's their turn and they should get back to the minigame) @@ -100,24 +91,25 @@ void HUD_MinigameMenu_CustomEntry(entity parent, string message, string event_ar #define FOREACH_MINIGAME_ENTITY(entityvar) \ - entityvar=NULL; \ - while( (entityvar = findentity(entityvar,owner,active_minigame)) ) + entityvar = NULL; \ + while ((entityvar = findentity(entityvar, owner, active_minigame))) REGISTRY(Minigames, BITS(4)) #define Minigames_from(i) _Minigames_from(i, NULL) REGISTER_REGISTRY(Minigames) REGISTRY_CHECK(Minigames) -#define REGISTER_MINIGAME(name,nicename) \ - REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \ - void name##_hud_board(vector, vector); \ - void name##_hud_status(vector, vector); \ - int name##_client_event(entity, string, ...); \ - REGISTER_INIT(MINIGAME_##name) { \ - this.netname = strzone(strtolower(#name)); \ - this.message = nicename; \ - this.minigame_hud_board = name##_hud_board; \ +#define REGISTER_MINIGAME(name, nicename) \ + REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \ + void name##_hud_board(vector, vector); \ + void name##_hud_status(vector, vector); \ + int name##_client_event(entity, string, ...); \ + REGISTER_INIT(MINIGAME_##name) \ + { \ + this.netname = strzone(strtolower( #name)); \ + this.message = nicename; \ + this.minigame_hud_board = name##_hud_board; \ this.minigame_hud_status = name##_hud_status; \ this.minigame_event = name##_client_event; \ - } \ - REGISTER_INIT(MINIGAME_##name) + } \ + REGISTER_INIT(MINIGAME_##name) diff --git a/qcsrc/common/minigames/cl_minigames_hud.qc b/qcsrc/common/minigames/cl_minigames_hud.qc index 2049dc9ea..3b7e39e2b 100644 --- a/qcsrc/common/minigames/cl_minigames_hud.qc +++ b/qcsrc/common/minigames/cl_minigames_hud.qc @@ -15,8 +15,8 @@ bool HUD_mouse_over(entity somepanel) { vector pos = stov(cvar_string(strcat("hud_panel_", somepanel.panel_name, "_pos"))); vector sz = stov(cvar_string(strcat("hud_panel_", somepanel.panel_name, "_size"))); - return mousepos_x >= pos_x*vid_conwidth && mousepos_x <= (pos_x+sz_x)*vid_conwidth && - mousepos_y >= pos_y*vid_conheight && mousepos_y <= (pos_y+sz_y)*vid_conheight ; + return mousepos_x >= pos_x * vid_conwidth && mousepos_x <= (pos_x + sz_x) * vid_conwidth + && mousepos_y >= pos_y * vid_conheight && mousepos_y <= (pos_y + sz_y) * vid_conheight; } // ==================================================================== @@ -24,17 +24,19 @@ bool HUD_mouse_over(entity somepanel) // ==================================================================== // Draws the minigame game board -void HUD_MinigameBoard () +void HUD_MinigameBoard() { entity hud_minigame = NULL; - if(!autocvar__hud_configure) + if (!autocvar__hud_configure) { hud_minigame = active_minigame.descriptor; - else + } else { hud_minigame = minigame_get_descriptor("nmm"); + } - if ( !hud_minigame ) + if (!hud_minigame) { return; + } HUD_Panel_LoadCvars(); @@ -43,24 +45,26 @@ void HUD_MinigameBoard () pos = panel_pos; mySize = panel_size; - hud_minigame.minigame_hud_board(pos,mySize); + hud_minigame.minigame_hud_board(pos, mySize); } // ==================================================================== // Minigame Status // ==================================================================== // Draws the minigame status panel -void HUD_MinigameStatus () +void HUD_MinigameStatus() { entity hud_minigame = NULL; - if(!autocvar__hud_configure) + if (!autocvar__hud_configure) { hud_minigame = active_minigame.descriptor; - else + } else { hud_minigame = minigame_get_descriptor("nmm"); + } - if ( !hud_minigame ) + if (!hud_minigame) { return; + } HUD_Panel_LoadCvars(); @@ -69,14 +73,13 @@ void HUD_MinigameStatus () pos = panel_pos; mySize = panel_size; - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } HUD_Scale_Disable(); - hud_minigame.minigame_hud_status(pos,mySize); + hud_minigame.minigame_hud_status(pos, mySize); } // ==================================================================== @@ -91,8 +94,7 @@ entity HUD_MinigameMenu_last_entry; // Minigame menu options: insert entry after the given location void HUD_MinigameMenu_InsertEntry(entity newentry, entity prev) { - if ( !HUD_MinigameMenu_entries ) - { + if (!HUD_MinigameMenu_entries) { HUD_MinigameMenu_entries = newentry; HUD_MinigameMenu_last_entry = newentry; return; @@ -100,12 +102,12 @@ void HUD_MinigameMenu_InsertEntry(entity newentry, entity prev) newentry.list_prev = prev; newentry.list_next = prev.list_next; - if ( prev.list_next ) + if (prev.list_next) { prev.list_next.list_prev = newentry; - else + } else { HUD_MinigameMenu_last_entry = newentry; + } prev.list_next = newentry; - } @@ -115,40 +117,41 @@ entity HUD_MinigameMenu_activeitem; // Click the given item void HUD_MinigameMenu_Click(entity menuitem) { - if ( menuitem ) - { + if (menuitem) { menuitem.use(menuitem, NULL, NULL); } } // Minigame menu options: Remove the given entry // Precondition: the given entry is actually in the list -void HUD_MinigameMenu_EraseEntry ( entity e ) +void HUD_MinigameMenu_EraseEntry(entity e) { // remove child items (if any) - if ( e.flags & 2 ) - { + if (e.flags & 2) { HUD_MinigameMenu_Click(e); } - if ( e.list_prev ) + if (e.list_prev) { e.list_prev.list_next = e.list_next; - else + } else { HUD_MinigameMenu_entries = e.list_next; + } - if ( e.list_next ) + if (e.list_next) { e.list_next.list_prev = e.list_prev; - else + } else { HUD_MinigameMenu_last_entry = e.list_prev; + } - if ( HUD_MinigameMenu_activeitem == e ) + if (HUD_MinigameMenu_activeitem == e) { HUD_MinigameMenu_activeitem = NULL; + } delete(e); } // Minigame menu options: create entry -entity HUD_MinigameMenu_SpawnEntry(string s, vector offset, vector fontsize, vector color,void(entity, entity, entity) click) +entity HUD_MinigameMenu_SpawnEntry(string s, vector offset, vector fontsize, vector color, void(entity, entity, entity) click) { entity entry = spawn(); entry.message = s; @@ -164,10 +167,10 @@ entity HUD_MinigameMenu_SpawnEntry(string s, vector offset, vector fontsize, vec // Spawn a child entry of a collapsable entry entity HUD_MinigameMenu_SpawnSubEntry(string s, void(entity, entity, entity) click, entity parent) { - vector item_fontsize = hud_fontsize*1.25; + vector item_fontsize = hud_fontsize * 1.25; vector item_offset = '1 0 0' * item_fontsize_x; entity item = HUD_MinigameMenu_SpawnEntry( - s,item_offset,item_fontsize,'0.8 0.8 0.8', click ); + s, item_offset, item_fontsize, '0.8 0.8 0.8', click); item.owner = parent; return item; } @@ -183,30 +186,29 @@ void HUD_MinigameMenu_ClickCreate_Entry(entity this, entity actor, entity trigge bool HUD_MinigameMenu_Click_ExpandCollapse(entity this) { entity e; - if ( this.flags & 2 ) - { - if ( HUD_MinigameMenu_activeitem && - HUD_MinigameMenu_activeitem.owner == this ) + if (this.flags & 2) { + if (HUD_MinigameMenu_activeitem + && HUD_MinigameMenu_activeitem.owner == this) { HUD_MinigameMenu_activeitem = NULL; + } this.flags &= ~2; - for ( e = this.list_next; e != NULL && e.owner == this; e = this.list_next ) - { - if ( e.flags & 2 ) + for (e = this.list_next; e != NULL && e.owner == this; e = this.list_next) { + if (e.flags & 2) { HUD_MinigameMenu_Click(e); + } this.list_next = e.list_next; delete(e); } - if ( this.list_next ) + if (this.list_next) { this.list_next.list_prev = this; - else + } else { HUD_MinigameMenu_last_entry = this; - } - else - { - for ( e = HUD_MinigameMenu_entries; e != NULL; e = e.list_next ) - { - if ( e.flags & 2 && e.origin_x == this.origin_x) + } + } else { + for (e = HUD_MinigameMenu_entries; e != NULL; e = e.list_next) { + if (e.flags & 2 && e.origin_x == this.origin_x) { HUD_MinigameMenu_Click(e); + } } this.flags |= 2; @@ -219,15 +221,14 @@ bool HUD_MinigameMenu_Click_ExpandCollapse(entity this) // Click action for the Create menu void HUD_MinigameMenu_ClickCreate(entity this, entity actor, entity trigger) { - if ( HUD_MinigameMenu_Click_ExpandCollapse(this) ) - { + if (HUD_MinigameMenu_Click_ExpandCollapse(this)) { entity curr; entity prev = this; FOREACH(Minigames, true, { curr = HUD_MinigameMenu_SpawnSubEntry(it.message, HUD_MinigameMenu_ClickCreate_Entry, this); curr.netname = it.netname; - curr.model = strzone(minigame_texture(strcat(it.netname,"/icon"))); - HUD_MinigameMenu_InsertEntry( curr, prev ); + curr.model = strzone(minigame_texture(strcat(it.netname, "/icon"))); + HUD_MinigameMenu_InsertEntry(curr, prev); prev = curr; }); } @@ -236,27 +237,24 @@ void HUD_MinigameMenu_ClickCreate(entity this, entity actor, entity trigger) // Click action for Join sub-entries void HUD_MinigameMenu_ClickJoin_Entry(entity this, entity actor, entity trigger) { - minigame_cmd("join ",this.netname); + minigame_cmd("join ", this.netname); HUD_MinigameMenu_EraseEntry(this); } // Click action for the Join menu void HUD_MinigameMenu_ClickJoin(entity this, entity actor, entity trigger) { - if ( HUD_MinigameMenu_Click_ExpandCollapse(this) ) - { + if (HUD_MinigameMenu_Click_ExpandCollapse(this)) { entity e = NULL; entity curr; entity prev = this; - while( (e = find(e,classname,"minigame")) ) - { - if ( e != active_minigame ) - { + while ((e = find(e, classname, "minigame"))) { + if (e != active_minigame) { curr = HUD_MinigameMenu_SpawnSubEntry( - e.netname, HUD_MinigameMenu_ClickJoin_Entry, this ); + e.netname, HUD_MinigameMenu_ClickJoin_Entry, this); curr.netname = e.netname; - curr.model = strzone(minigame_texture(strcat(e.descriptor.netname,"/icon"))); - HUD_MinigameMenu_InsertEntry( curr, prev ); + curr.model = strzone(minigame_texture(strcat(e.descriptor.netname, "/icon"))); + HUD_MinigameMenu_InsertEntry(curr, prev); prev = curr; } } @@ -266,7 +264,7 @@ void HUD_MinigameMenu_ClickJoin(entity this, entity actor, entity trigger) /*// Temporary placeholder for un-implemented Click actions void HUD_MinigameMenu_ClickNoop() { - dprint("Placeholder for ",this.message,"\n"); + dprint("Placeholder for ",this.message,"\n"); }*/ // Click action for Quit @@ -279,28 +277,25 @@ void HUD_MinigameMenu_ClickQuit(entity this, entity actor, entity trigger) // Click action for Invite sub-entries void HUD_MinigameMenu_ClickInvite_Entry(entity this, entity actor, entity trigger) { - minigame_cmd("invite #",this.netname); + minigame_cmd("invite #", this.netname); } // Click action for the Invite menu void HUD_MinigameMenu_ClickInvite(entity this, entity actor, entity trigger) { - if ( HUD_MinigameMenu_Click_ExpandCollapse(this) ) - { + if (HUD_MinigameMenu_Click_ExpandCollapse(this)) { entity e; entity prev = this; - for(int i = 0; i < maxclients; ++i) - { - if ( player_localnum != i && playerslots[i] && entcs_GetName(i) != "" && - !findfloat(NULL,minigame_playerslot,i+1) && playerslots[i].ping ) - { + for (int i = 0; i < maxclients; ++i) { + if (player_localnum != i && playerslots[i] && entcs_GetName(i) != "" + && !findfloat(NULL, minigame_playerslot, i + 1) && playerslots[i].ping) { e = HUD_MinigameMenu_SpawnSubEntry( strzone(entcs_GetName(i)), HUD_MinigameMenu_ClickInvite_Entry, - this ); + this); e.flags |= 1; - e.netname = strzone(ftos(i+1)); + e.netname = strzone(ftos(i + 1)); e.origin_x *= 2; - HUD_MinigameMenu_InsertEntry(e,prev); + HUD_MinigameMenu_InsertEntry(e, prev); prev = e; } } @@ -309,31 +304,31 @@ void HUD_MinigameMenu_ClickInvite(entity this, entity actor, entity trigger) void HUD_MinigameMenu_ClickCustomEntry(entity this, entity actor, entity trigger) { - if ( active_minigame ) - active_minigame.minigame_event(active_minigame,"menu_click",this.netname); + if (active_minigame) { + active_minigame.minigame_event(active_minigame, "menu_click", this.netname); + } } // Adds a game-specific entry to the menu void HUD_MinigameMenu_CustomEntry(entity parent, string menumessage, string event_arg) { entity e = HUD_MinigameMenu_SpawnSubEntry( - menumessage, HUD_MinigameMenu_ClickCustomEntry, parent ); + menumessage, HUD_MinigameMenu_ClickCustomEntry, parent); e.netname = event_arg; HUD_MinigameMenu_InsertEntry(e, parent); - //dprint("CustomEntry ",ftos(num_for_edict(parent))," ",menumessage," ",event_arg,"\n"); + // dprint("CustomEntry ",ftos(num_for_edict(parent))," ",menumessage," ",event_arg,"\n"); } // Click action for the Current Game menu void HUD_MinigameMenu_ClickCurrentGame(entity this, entity actor, entity trigger) { - if ( HUD_MinigameMenu_Click_ExpandCollapse(this) ) - { - HUD_MinigameMenu_InsertEntry( HUD_MinigameMenu_SpawnSubEntry( - _("Quit"), HUD_MinigameMenu_ClickQuit, this ), this); + if (HUD_MinigameMenu_Click_ExpandCollapse(this)) { + HUD_MinigameMenu_InsertEntry(HUD_MinigameMenu_SpawnSubEntry( + _("Quit"), HUD_MinigameMenu_ClickQuit, this), this); - active_minigame.minigame_event(active_minigame,"menu_show",this); + active_minigame.minigame_event(active_minigame, "menu_show", this); - HUD_MinigameMenu_InsertEntry( HUD_MinigameMenu_SpawnSubEntry( + HUD_MinigameMenu_InsertEntry(HUD_MinigameMenu_SpawnSubEntry( _("Invite"), HUD_MinigameMenu_ClickInvite, this), this); } } @@ -346,20 +341,20 @@ bool HUD_MinigameMenu_IsOpened() // Close the minigame menu panel void HUD_MinigameMenu_Close(entity this, entity actor, entity trigger) { - if ( HUD_MinigameMenu_IsOpened() ) - { + if (HUD_MinigameMenu_IsOpened()) { entity e, p; - for ( e = HUD_MinigameMenu_entries; e != NULL; e = p ) - { + for (e = HUD_MinigameMenu_entries; e != NULL; e = p) { p = e.list_next; delete(e); } HUD_MinigameMenu_entries = NULL; HUD_MinigameMenu_last_entry = NULL; HUD_MinigameMenu_activeitem = NULL; - if(autocvar_hud_cursormode) - if ( !autocvar__hud_configure ) - setcursormode(0); + if (autocvar_hud_cursormode) { + if (!autocvar__hud_configure) { + setcursormode(0); + } + } } } @@ -367,61 +362,59 @@ void HUD_MinigameMenu_Close(entity this, entity actor, entity trigger) void HUD_MinigameMenu_CurrentButton() { entity e; - if ( active_minigame ) - { - for ( e = HUD_MinigameMenu_last_entry; e != NULL; e = e.list_prev ) - if ( e.classname == "hud_minigamemenu_exit" ) - { + if (active_minigame) { + for (e = HUD_MinigameMenu_last_entry; e != NULL; e = e.list_prev) { + if (e.classname == "hud_minigamemenu_exit") { HUD_MinigameMenu_EraseEntry(e); break; } + } entity currb = HUD_MinigameMenu_SpawnEntry( - _("Current Game"), '0 0 0', hud_fontsize*1.5,'0.7 0.84 1', HUD_MinigameMenu_ClickCurrentGame ); + _("Current Game"), '0 0 0', hud_fontsize * 1.5, '0.7 0.84 1', HUD_MinigameMenu_ClickCurrentGame); currb.classname = "hud_minigamemenu_current"; - currb.model = strzone(minigame_texture(strcat(active_minigame.descriptor.netname,"/icon"))); - HUD_MinigameMenu_InsertEntry(currb,HUD_MinigameMenu_last_entry); + currb.model = strzone(minigame_texture(strcat(active_minigame.descriptor.netname, "/icon"))); + HUD_MinigameMenu_InsertEntry(currb, HUD_MinigameMenu_last_entry); HUD_MinigameMenu_Click(currb); - } - else - { + } else { entity p; - for ( e = HUD_MinigameMenu_last_entry; e != NULL; e = p.list_prev ) - { + for (e = HUD_MinigameMenu_last_entry; e != NULL; e = p.list_prev) { p = e; - if ( e.classname == "hud_minigamemenu_current" ) - { + if (e.classname == "hud_minigamemenu_current") { p = e.list_next; - if ( !p ) + if (!p) { p = HUD_MinigameMenu_last_entry; + } HUD_MinigameMenu_EraseEntry(e); break; } } - for ( e = HUD_MinigameMenu_last_entry; e != NULL; e = e.list_prev ) - if ( e.classname == "hud_minigamemenu_exit" ) + for (e = HUD_MinigameMenu_last_entry; e != NULL; e = e.list_prev) { + if (e.classname == "hud_minigamemenu_exit") { return; + } + } entity exit = HUD_MinigameMenu_SpawnEntry( - _("Exit Menu"),'0 0 0',hud_fontsize*1.5,'0.7 0.84 1', HUD_MinigameMenu_Close); + _("Exit Menu"), '0 0 0', hud_fontsize * 1.5, '0.7 0.84 1', HUD_MinigameMenu_Close); exit.classname = "hud_minigamemenu_exit"; - HUD_MinigameMenu_InsertEntry ( exit, HUD_MinigameMenu_last_entry ); + HUD_MinigameMenu_InsertEntry(exit, HUD_MinigameMenu_last_entry); } } // Open the minigame menu panel void HUD_MinigameMenu_Open() { - if ( !HUD_MinigameMenu_IsOpened() ) - { - HUD_MinigameMenu_InsertEntry( HUD_MinigameMenu_SpawnEntry( - _("Create"), '0 0 0', hud_fontsize*1.5,'0.7 0.84 1', HUD_MinigameMenu_ClickCreate), - HUD_MinigameMenu_last_entry ); - HUD_MinigameMenu_InsertEntry ( HUD_MinigameMenu_SpawnEntry( - _("Join"),'0 0 0',hud_fontsize*1.5,'0.7 0.84 1', HUD_MinigameMenu_ClickJoin), - HUD_MinigameMenu_last_entry ); + if (!HUD_MinigameMenu_IsOpened()) { + HUD_MinigameMenu_InsertEntry(HUD_MinigameMenu_SpawnEntry( + _("Create"), '0 0 0', hud_fontsize * 1.5, '0.7 0.84 1', HUD_MinigameMenu_ClickCreate), + HUD_MinigameMenu_last_entry); + HUD_MinigameMenu_InsertEntry(HUD_MinigameMenu_SpawnEntry( + _("Join"), '0 0 0', hud_fontsize * 1.5, '0.7 0.84 1', HUD_MinigameMenu_ClickJoin), + HUD_MinigameMenu_last_entry); HUD_MinigameMenu_CurrentButton(); HUD_MinigameMenu_activeitem = NULL; - if(autocvar_hud_cursormode) + if (autocvar_hud_cursormode) { setcursormode(1); + } } } @@ -432,25 +425,23 @@ void HUD_MinigameMenu_MouseInput() HUD_Panel_LoadCvars(); - if(panel_bg_padding) - { + if (panel_bg_padding) { panel_pos += '1 1 0' * panel_bg_padding; panel_size -= '2 2 0' * panel_bg_padding; } entity e; - panel_pos_y += hud_fontsize_y*2; + panel_pos_y += hud_fontsize_y * 2; HUD_MinigameMenu_activeitem = NULL; vector sz; - for ( e = HUD_MinigameMenu_entries; e != NULL; e = e.list_next ) - { - sz = eX*panel_size_x + eY*e.size_y; - if ( e.model ) + for (e = HUD_MinigameMenu_entries; e != NULL; e = e.list_next) { + sz = eX * panel_size_x + eY * e.size_y; + if (e.model) { sz_y = 22; - if ( !HUD_MinigameMenu_activeitem && mousepos_y >= panel_pos_y && mousepos_y <= panel_pos_y + sz_y ) - { + } + if (!HUD_MinigameMenu_activeitem && mousepos_y >= panel_pos_y && mousepos_y <= panel_pos_y + sz_y) { HUD_MinigameMenu_activeitem = e; } panel_pos_y += sz_y; @@ -460,71 +451,71 @@ void HUD_MinigameMenu_MouseInput() // Draw a menu entry void HUD_MinigameMenu_DrawEntry(vector pos, string s, vector fontsize, vector color) { - minigame_drawstring_trunc(panel_size_x-pos_x+panel_pos_x, pos, s, - fontsize, color, panel_fg_alpha, DRAWFLAG_NORMAL); + minigame_drawstring_trunc(panel_size_x - pos_x + panel_pos_x, pos, s, + fontsize, color, panel_fg_alpha, DRAWFLAG_NORMAL); } // Draw a color-coded menu void HUD_MinigameMenu_DrawColoredEntry(vector pos, string s, vector fontsize) { - minigame_drawcolorcodedstring_trunc(panel_size_x-pos_x+panel_pos_x, pos, s, - fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); + minigame_drawcolorcodedstring_trunc(panel_size_x - pos_x + panel_pos_x, pos, s, + fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); } // Minigame menu panel UI -void HUD_MinigameMenu () +void HUD_MinigameMenu() { - if ( !HUD_MinigameMenu_IsOpened() ) + if (!HUD_MinigameMenu_IsOpened()) { return; + } HUD_Panel_LoadCvars(); HUD_Scale_Disable(); HUD_Panel_DrawBg(); - if(panel_bg_padding) - { + if (panel_bg_padding) { panel_pos += '1 1 0' * panel_bg_padding; panel_size -= '2 2 0' * panel_bg_padding; } - HUD_MinigameMenu_DrawEntry(panel_pos,_("Minigames"),hud_fontsize*2,'0.25 0.47 0.72'); - panel_pos_y += hud_fontsize_y*2; + HUD_MinigameMenu_DrawEntry(panel_pos, _("Minigames"), hud_fontsize * 2, '0.25 0.47 0.72'); + panel_pos_y += hud_fontsize_y * 2; vector color; vector offset; float itemh; vector imgsz = '22 22 0'; // NOTE: if changed, edit where HUD_MinigameMenu_activeitem is selected - for ( entity e = HUD_MinigameMenu_entries; e != NULL; e = e.list_next ) - { + for (entity e = HUD_MinigameMenu_entries; e != NULL; e = e.list_next) { color = e.colormod; offset = e.origin; itemh = e.size_y; - if ( e.model ) + if (e.model) { itemh = imgsz_y; + } - if ( e.flags & 2 ) - { - drawfill(panel_pos, eX*panel_size_x + eY*itemh, e.colormod, - panel_fg_alpha, DRAWFLAG_NORMAL); + if (e.flags & 2) { + drawfill(panel_pos, eX * panel_size_x + eY * itemh, e.colormod, + panel_fg_alpha, DRAWFLAG_NORMAL); color = '0 0 0'; } - if ( e.model ) - { - drawpic( panel_pos+offset, e.model, imgsz, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL ); + if (e.model) { + drawpic(panel_pos + offset, e.model, imgsz, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); offset_x += imgsz_x; - offset_y = (imgsz_y-e.size_y) / 2; + offset_y = (imgsz_y - e.size_y) / 2; } - if ( e.flags & 1 ) - HUD_MinigameMenu_DrawColoredEntry(panel_pos+offset,e.message,e.size); - else - HUD_MinigameMenu_DrawEntry(panel_pos+offset,e.message,e.size,color); + if (e.flags & 1) { + HUD_MinigameMenu_DrawColoredEntry(panel_pos + offset, e.message, e.size); + } else { + HUD_MinigameMenu_DrawEntry(panel_pos + offset, e.message, e.size, color); + } - if ( e == HUD_MinigameMenu_activeitem ) - drawfill(panel_pos, eX*panel_size_x + eY*itemh,'1 1 1', 0.25, DRAWFLAG_ADDITIVE); + if (e == HUD_MinigameMenu_activeitem) { + drawfill(panel_pos, eX * panel_size_x + eY * itemh, '1 1 1', 0.25, DRAWFLAG_ADDITIVE); + } panel_pos_y += itemh; } @@ -538,13 +529,15 @@ void HUD_MinigameHelp() { string help_message; - if(!autocvar__hud_configure) + if (!autocvar__hud_configure) { help_message = active_minigame.message; - else + } else { help_message = "Minigame message"; + } - if ( !help_message ) + if (!help_message) { return; + } HUD_Panel_LoadCvars(); @@ -553,14 +546,13 @@ void HUD_MinigameHelp() pos = panel_pos; mySize = panel_size; - if(panel_bg_padding) - { + if (panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } - minigame_drawcolorcodedstring_wrapped( mySize_x, pos, help_message, - hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5 ); + minigame_drawcolorcodedstring_wrapped(mySize_x, pos, help_message, + hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5); } // ==================================================================== @@ -568,106 +560,91 @@ void HUD_MinigameHelp() // ==================================================================== float HUD_Minigame_InputEvent(float bInputType, float nPrimary, float nSecondary) { - - if( !HUD_MinigameMenu_IsOpened() || autocvar__hud_configure ) + if (!HUD_MinigameMenu_IsOpened() || autocvar__hud_configure) { return false; + } - if(bInputType == 3) - { + if (bInputType == 3) { mousepos_x = nPrimary; mousepos_y = nSecondary; - if ( active_minigame && HUD_mouse_over(HUD_PANEL(MINIGAMEBOARD)) ) - active_minigame.minigame_event(active_minigame,"mouse_moved",mousepos); - return true; - - } - else - { - if(bInputType == 0) { - if(nPrimary == K_ALT) hudShiftState |= S_ALT; - if(nPrimary == K_CTRL) hudShiftState |= S_CTRL; - if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT; - if(nPrimary == K_MOUSE1) mouseClicked |= S_MOUSE1; - if(nPrimary == K_MOUSE2) mouseClicked |= S_MOUSE2; + if (active_minigame && HUD_mouse_over(HUD_PANEL(MINIGAMEBOARD))) { + active_minigame.minigame_event(active_minigame, "mouse_moved", mousepos); } - else if(bInputType == 1) { - if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT); - if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL); - if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT); - if(nPrimary == K_MOUSE1) mouseClicked -= (mouseClicked & S_MOUSE1); - if(nPrimary == K_MOUSE2) mouseClicked -= (mouseClicked & S_MOUSE2); + return true; + } else { + if (bInputType == 0) { + if (nPrimary == K_ALT) { hudShiftState |= S_ALT; } + if (nPrimary == K_CTRL) { hudShiftState |= S_CTRL; } + if (nPrimary == K_SHIFT) { hudShiftState |= S_SHIFT; } + if (nPrimary == K_MOUSE1) { mouseClicked |= S_MOUSE1; } + if (nPrimary == K_MOUSE2) { mouseClicked |= S_MOUSE2; } + } else if (bInputType == 1) { + if (nPrimary == K_ALT) { hudShiftState -= (hudShiftState & S_ALT); } + if (nPrimary == K_CTRL) { hudShiftState -= (hudShiftState & S_CTRL); } + if (nPrimary == K_SHIFT) { hudShiftState -= (hudShiftState & S_SHIFT); } + if (nPrimary == K_MOUSE1) { mouseClicked -= (mouseClicked & S_MOUSE1); } + if (nPrimary == K_MOUSE2) { mouseClicked -= (mouseClicked & S_MOUSE2); } } // allow some binds string con_keys = findkeysforcommand("toggleconsole", 0); int keys = tokenize(con_keys); // findkeysforcommand returns data for this int i; - for (i = 0; i < keys; ++i) - { - if(nPrimary == stof(argv(i))) + for (i = 0; i < keys; ++i) { + if (nPrimary == stof(argv(i))) { return false; + } } - if ( active_minigame && ( bInputType == 0 || bInputType == 1 ) ) - { + if (active_minigame && (bInputType == 0 || bInputType == 1)) { string device = ""; string action = bInputType == 0 ? "pressed" : "released"; - if ( nPrimary >= K_MOUSE1 && nPrimary <= K_MOUSE16 ) - { - if ( HUD_mouse_over(HUD_PANEL(MINIGAMEBOARD)) ) + if (nPrimary >= K_MOUSE1 && nPrimary <= K_MOUSE16) { + if (HUD_mouse_over(HUD_PANEL(MINIGAMEBOARD))) { device = "mouse"; - } - else + } + } else { device = "key"; + } - if ( device && active_minigame.minigame_event( - active_minigame,strcat(device,"_",action),nPrimary) ) + if (device && active_minigame.minigame_event( + active_minigame, strcat(device, "_", action), nPrimary)) { return true; + } /// TODO: bInputType == 2? } - if ( bInputType == 0 ) - { - if ( nPrimary == K_MOUSE1 && HUD_MinigameMenu_activeitem && - HUD_mouse_over(HUD_PANEL(MINIGAMEMENU)) ) - { + if (bInputType == 0) { + if (nPrimary == K_MOUSE1 && HUD_MinigameMenu_activeitem + && HUD_mouse_over(HUD_PANEL(MINIGAMEMENU))) { HUD_MinigameMenu_Click(HUD_MinigameMenu_activeitem); return true; } - if ( nPrimary == K_UPARROW || nPrimary == K_KP_UPARROW ) - { - if ( HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_prev ) + if (nPrimary == K_UPARROW || nPrimary == K_KP_UPARROW) { + if (HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_prev) { HUD_MinigameMenu_activeitem = HUD_MinigameMenu_activeitem.list_prev; - else + } else { HUD_MinigameMenu_activeitem = HUD_MinigameMenu_last_entry; + } return true; - } - else if ( nPrimary == K_DOWNARROW || nPrimary == K_KP_DOWNARROW ) - { - if ( HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_next ) + } else if (nPrimary == K_DOWNARROW || nPrimary == K_KP_DOWNARROW) { + if (HUD_MinigameMenu_activeitem && HUD_MinigameMenu_activeitem.list_next) { HUD_MinigameMenu_activeitem = HUD_MinigameMenu_activeitem.list_next; - else + } else { HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; + } return true; - } - else if ( nPrimary == K_HOME || nPrimary == K_KP_HOME ) - { + } else if (nPrimary == K_HOME || nPrimary == K_KP_HOME) { HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; return true; - } - else if ( nPrimary == K_END || nPrimary == K_KP_END ) - { + } else if (nPrimary == K_END || nPrimary == K_KP_END) { HUD_MinigameMenu_activeitem = HUD_MinigameMenu_entries; return true; - } - else if ( nPrimary == K_KP_ENTER || nPrimary == K_ENTER || nPrimary == K_SPACE ) - { + } else if (nPrimary == K_KP_ENTER || nPrimary == K_ENTER || nPrimary == K_SPACE) { HUD_MinigameMenu_Click(HUD_MinigameMenu_activeitem); return true; - } - else if ( nPrimary == K_ESCAPE ) - { + } else if (nPrimary == K_ESCAPE) { HUD_MinigameMenu_Close(NULL, NULL, NULL); return true; } @@ -675,19 +652,21 @@ float HUD_Minigame_InputEvent(float bInputType, float nPrimary, float nSecondary } return false; - } void HUD_Minigame_Mouse() { - if( !HUD_MinigameMenu_IsOpened() || autocvar__hud_configure || mv_active ) + if (!HUD_MinigameMenu_IsOpened() || autocvar__hud_configure || mv_active) { return; + } - if (!autocvar_hud_cursormode) + if (!autocvar_hud_cursormode) { update_mousepos(); + } - if ( HUD_MinigameMenu_IsOpened() && HUD_mouse_over(HUD_PANEL(MINIGAMEMENU)) ) + if (HUD_MinigameMenu_IsOpened() && HUD_mouse_over(HUD_PANEL(MINIGAMEMENU))) { HUD_MinigameMenu_MouseInput(); + } draw_cursor_normal(mousepos, '1 1 1', panel_fg_alpha); } diff --git a/qcsrc/common/minigames/minigames.qc b/qcsrc/common/minigames/minigames.qc index 6d14b2582..5b8323174 100644 --- a/qcsrc/common/minigames/minigames.qc +++ b/qcsrc/common/minigames/minigames.qc @@ -11,7 +11,7 @@ entity minigame_get_descriptor(string id) // Get letter index of a tile name int minigame_tile_letter(string id) { - return str2chr(substring(id,0,1),0)-'a'; + return str2chr(substring(id, 0, 1), 0) - 'a'; } // Get number index of a tile name @@ -20,7 +20,7 @@ int minigame_tile_letter(string id) // you may want to do number_of_rows - what_this_function_returns or something int minigame_tile_number(string id) { - return stof(substring(id,1,-1)) -1 ; + return stof(substring(id, 1, -1)) - 1; } // Get relative position of the center of a given tile @@ -33,7 +33,7 @@ vector minigame_tile_pos(string id, int rows, int columns) // Get a tile name from indices string minigame_tile_buildname(int letter, int number) { - return strcat(chr2str('a'+letter),ftos(number+1)); + return strcat(chr2str('a' + letter), ftos(number + 1)); } // Get the id of a tile relative to the given one @@ -41,23 +41,25 @@ string minigame_relative_tile(string start_id, int dx, int dy, int rows, int col { int letter = minigame_tile_letter(start_id); int number = minigame_tile_number(start_id); - letter = (letter+dx) % columns; - number = (number+dy) % rows; - if ( letter < 0 ) + letter = (letter + dx) % columns; + number = (number + dy) % rows; + if (letter < 0) { letter = columns + letter; - if ( number < 0 ) + } + if (number < 0) { number = rows + number; + } return minigame_tile_buildname(letter, number); } // Get tile name from a relative position (matches the tile covering a square area) string minigame_tile_name(vector pos, int rows, int columns) { - if ( pos_x < 0 || pos_x > 1 || pos_y < 0 || pos_y > 1 ) + if (pos_x < 0 || pos_x > 1 || pos_y < 0 || pos_y > 1) { return ""; // no tile - + } int letter = floor(pos_x * columns); - int number = floor((1-pos_y) * rows); + int number = floor((1 - pos_y) * rows); return minigame_tile_buildname(letter, number); } @@ -78,7 +80,7 @@ int minigame_prev_team(int curr_team, int n_teams) void minigame_server_sendflags(entity ent, int mgflags) { #ifdef SVQC - ent.SendFlags |= mgflags; + ent.SendFlags |= mgflags; #endif } @@ -91,8 +93,8 @@ entity msle_spawn(entity minigame_session, string class_name) e.owner = minigame_session; e.minigame_autoclean = 1; #ifdef SVQC - setcefc(e, minigame_CheckSend); - Net_LinkEntity(e, false, 0, minigame_SendEntity); + setcefc(e, minigame_CheckSend); + Net_LinkEntity(e, false, 0, minigame_SendEntity); #endif return e; } @@ -100,10 +102,10 @@ entity msle_spawn(entity minigame_session, string class_name) const int msle_base_id = 2; int msle_id(string class_name) { - if ( class_name == "minigame" ) return 1; - if ( class_name == "minigame_player" ) return 2; + if (class_name == "minigame") { return 1; } + if (class_name == "minigame_player") { return 2; } int i = msle_base_id; -#define MSLE(Name, Fields) i++; if ( class_name == #Name ) return i; +#define MSLE(Name, Fields) i++; if (class_name == #Name) { return i; } MINIGAME_SIMPLELINKED_ENTITIES #undef MSLE return 0; @@ -111,10 +113,10 @@ int msle_id(string class_name) string msle_classname(int id) { - if ( id == 1 ) return "minigame"; - if ( id == 2 ) return "minigame_player"; + if (id == 1) { return "minigame"; } + if (id == 2) { return "minigame_player"; } int i = msle_base_id; -#define MSLE(Name, Fields) i++; if ( id == i ) return #Name; +#define MSLE(Name, Fields) i++; if (id == i) { return #Name; } MINIGAME_SIMPLELINKED_ENTITIES #undef MSLE return ""; @@ -125,13 +127,14 @@ int minigame_count_players(entity minigame) int pl_num = 0; entity e; #ifdef SVQC - for(e = minigame.minigame_players; e; e = e.list_next) + for (e = minigame.minigame_players; e; e = e.list_next) #elif defined(CSQC) e = NULL; - while( (e = findentity(e,owner,minigame)) ) - if ( e.classname == "minigame_player" ) + while ((e = findentity(e, owner, minigame))) + if (e.classname == "minigame_player") #endif - pl_num++; + { pl_num++; + } return pl_num; } diff --git a/qcsrc/common/minigames/minigames.qh b/qcsrc/common/minigames/minigames.qh index 284001a0a..1d3356bdb 100644 --- a/qcsrc/common/minigames/minigames.qh +++ b/qcsrc/common/minigames/minigames.qh @@ -46,55 +46,55 @@ int minigame_count_players(entity minigame); /// For minigame sessions/descriptors: execute the given event /// Client events: -/// mouse_moved(vector mouse_pos) +/// mouse_moved(vector mouse_pos) /// return 1 to handle input, 0 to discard -/// mouse_pressed/released(int K_Keycode) +/// mouse_pressed/released(int K_Keycode) /// return 1 to handle input, 0 to discard -/// note: see dpdefs/keycodes.qc for values -/// key_pressed/released(int K_Keycode) -/// return 1 to handle input, 0 to discard -/// note: see dpdefs/keycodes.qc for values -/// activate() -/// executed when the minigame is activated for the current client -/// deactivate() -/// executed when the minigame is deactivated for the current client -/// network_receive(entity received,int flags) -/// executed each time a networked entity is received -/// note: when this is called self == ...(0,entity) -/// You can use the MINIG_SF_ constants to check the send flags -/// IMPORTANT: always read in client everything you send from the server! -/// menu_show(entity parent_menu_item) -/// executed when the Current Game menu is shown, used to add custom entries -/// Call HUD_MinigameMenu_CustomEntry to do so (pass ...(0,entity) as first argument) -/// menu_click(string arg) -/// executed when a custom menu entry is clicked +/// note: see dpdefs/keycodes.qc for values +/// key_pressed/released(int K_Keycode) +/// return 1 to handle input, 0 to discard +/// note: see dpdefs/keycodes.qc for values +/// activate() +/// executed when the minigame is activated for the current client +/// deactivate() +/// executed when the minigame is deactivated for the current client +/// network_receive(entity received,int flags) +/// executed each time a networked entity is received +/// note: when this is called self == ...(0,entity) +/// You can use the MINIG_SF_ constants to check the send flags +/// IMPORTANT: always read in client everything you send from the server! +/// menu_show(entity parent_menu_item) +/// executed when the Current Game menu is shown, used to add custom entries +/// Call HUD_MinigameMenu_CustomEntry to do so (pass ...(0,entity) as first argument) +/// menu_click(string arg) +/// executed when a custom menu entry is clicked /// Server events: -/// start() -/// executed when the minigame session is starting -/// end() -/// executed when the minigame session is shutting down -/// join(entity player) -/// executed when a player wants to join the session -/// return the player team number to accept the new player, 0 to discard -/// part(entity player) -/// executed when a player is going to leave the session -/// network_send(entity sent,int flags) -/// executed each time a networked entity is sent -/// note: when this is called self == ...(0,entity) -/// You can use the MINIG_SF_ constants to check the send flags -/// IMPORTANT: always read in client everything you send from the server! -/// cmd(entity minigame_player, int argc, string command) -/// self = client entity triggering this -/// argv(n) = console token -/// argc: number of console tokens -/// command: full command string -/// triggered when a player does "cmd minigame ..." with some unrecognized command -/// return 1 if the minigame has handled the command -/// impulse(entity minigame_player,int impulse) -/// self = client entity triggering this -/// triggered when a player does "impulse ..." -/// return 1 if the minigame has handled the impulse -.int(entity,string,...) minigame_event; +/// start() +/// executed when the minigame session is starting +/// end() +/// executed when the minigame session is shutting down +/// join(entity player) +/// executed when a player wants to join the session +/// return the player team number to accept the new player, 0 to discard +/// part(entity player) +/// executed when a player is going to leave the session +/// network_send(entity sent,int flags) +/// executed each time a networked entity is sent +/// note: when this is called self == ...(0,entity) +/// You can use the MINIG_SF_ constants to check the send flags +/// IMPORTANT: always read in client everything you send from the server! +/// cmd(entity minigame_player, int argc, string command) +/// self = client entity triggering this +/// argv(n) = console token +/// argc: number of console tokens +/// command: full command string +/// triggered when a player does "cmd minigame ..." with some unrecognized command +/// return 1 if the minigame has handled the command +/// impulse(entity minigame_player,int impulse) +/// self = client entity triggering this +/// triggered when a player does "impulse ..." +/// return 1 if the minigame has handled the impulse +.int(entity, string, ...) minigame_event; // For run-time gameplay entities: Whether to be removed when the game is deactivated .bool minigame_autoclean; diff --git a/qcsrc/common/minigames/sv_minigames.qh b/qcsrc/common/minigames/sv_minigames.qh index b5015a1f4..3bfb70c2a 100644 --- a/qcsrc/common/minigames/sv_minigames.qh +++ b/qcsrc/common/minigames/sv_minigames.qh @@ -2,11 +2,11 @@ /// Create a new minigame session /// \return minigame session entity -entity start_minigame(entity player, string minigame ); +entity start_minigame(entity player, string minigame); /// Join an existing minigame session /// \return minigame session entity -entity join_minigame(entity player, string game_id ); +entity join_minigame(entity player, string game_id); /// Invite a player to join in a minigame /// \return Error string @@ -49,12 +49,13 @@ REGISTRY(Minigames, BITS(4)) #define Minigames_from(i) _Minigames_from(i, NULL) REGISTER_REGISTRY(Minigames) REGISTRY_CHECK(Minigames) -#define REGISTER_MINIGAME(name,nicename) \ - REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \ - int name##_server_event(entity, string, ...); \ - REGISTER_INIT(MINIGAME_##name) { \ - this.netname = strzone(strtolower(#name)); \ - this.message = nicename; \ +#define REGISTER_MINIGAME(name, nicename) \ + REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \ + int name##_server_event(entity, string, ...); \ + REGISTER_INIT(MINIGAME_##name) \ + { \ + this.netname = strzone(strtolower( #name)); \ + this.message = nicename; \ this.minigame_event = name##_server_event; \ - } \ - REGISTER_INIT(MINIGAME_##name) + } \ + REGISTER_INIT(MINIGAME_##name) diff --git a/qcsrc/common/models/all.qh b/qcsrc/common/models/all.qh index ce9862941..4e5ae2560 100644 --- a/qcsrc/common/models/all.qh +++ b/qcsrc/common/models/all.qh @@ -7,16 +7,20 @@ REGISTRY(Models, BITS(9)) REGISTER_REGISTRY(Models) #define MODEL(name, path) \ - string MDL_##name##_get() { return path; } \ - REGISTER(Models, MDL, name, m_id, NEW(Model, MDL_##name##_get)) + string MDL_##name##_get() \ + { \ + return path; \ + } \ + REGISTER(Models, MDL, name, m_id, NEW(Model, MDL_##name##_get)) STATIC_INIT(NULLMDL) { - precache_model("null"); + precache_model("null"); } -PRECACHE(Models) { - FOREACH(Models, true, it.model_precache(it)); +PRECACHE(Models) +{ + FOREACH(Models, true, it.model_precache(it)); } MODEL(Null, "null"); diff --git a/qcsrc/common/monsters/monster/zombie.qc b/qcsrc/common/monsters/monster/zombie.qc index d5011c7f3..f11cdc76d 100644 --- a/qcsrc/common/monsters/monster/zombie.qc +++ b/qcsrc/common/monsters/monster/zombie.qc @@ -51,13 +51,13 @@ const float zombie_anim_spawn = 30; void M_Zombie_Attack_Leap_Touch(entity this, entity toucher) { - if (this.health <= 0) + if (this.health <= 0) { return; + } vector angles_face; - if(toucher.takedamage) - { + if (toucher.takedamage) { angles_face = vectoangles(this.moveto - this.origin); angles_face = normalize(angles_face) * (autocvar_g_monster_zombie_attack_leap_force); Damage(toucher, this, this, (autocvar_g_monster_zombie_attack_leap_damage) * MONSTER_SKILLMOD(this), DEATH_MONSTER_ZOMBIE_JUMP.m_id, toucher.origin, angles_face); @@ -65,8 +65,7 @@ void M_Zombie_Attack_Leap_Touch(entity this, entity toucher) this.state = 0; } - if (trace_dphitcontents) - { + if (trace_dphitcontents) { this.state = 0; settouch(this, Monster_Touch); } @@ -74,8 +73,9 @@ void M_Zombie_Attack_Leap_Touch(entity this, entity toucher) void M_Zombie_Defend_Block_End(entity this) { - if(this.health <= 0) + if (this.health <= 0) { return; + } setanim(this, this.anim_blockend, false, true, true); this.armorvalue = autocvar_g_monsters_armor_blockpercent; @@ -96,22 +96,23 @@ bool M_Zombie_Defend_Block(entity this) bool M_Zombie_Attack(int attack_type, entity actor, entity targ, .entity weaponentity) { - switch(attack_type) - { + switch (attack_type) { case MONSTER_ATTACK_MELEE: { - if(random() < 0.3 && actor.health < 75 && actor.enemy.health > 10) + if (random() < 0.3 && actor.health < 75 && actor.enemy.health > 10) { return M_Zombie_Defend_Block(actor); + } float anim_chance = random(); vector chosen_anim; - if(anim_chance < 0.33) + if (anim_chance < 0.33) { chosen_anim = actor.anim_melee1; - else if(anim_chance < 0.66) + } else if (anim_chance < 0.66) { chosen_anim = actor.anim_melee2; - else + } else { chosen_anim = actor.anim_melee3; + } return Monster_Attack_Melee(actor, actor.enemy, (autocvar_g_monster_zombie_attack_melee_damage), chosen_anim, actor.attack_range, (autocvar_g_monster_zombie_attack_melee_delay), DEATH_MONSTER_ZOMBIE_MELEE.m_id, true); } @@ -125,82 +126,86 @@ bool M_Zombie_Attack(int attack_type, entity actor, entity targ, .entity weapone return false; } -spawnfunc(monster_zombie) { Monster_Spawn(this, true, MON_ZOMBIE.monsterid); } +spawnfunc(monster_zombie) +{ + Monster_Spawn(this, true, MON_ZOMBIE.monsterid); +} #endif // SVQC #ifdef SVQC METHOD(Zombie, mr_think, bool(Zombie this, entity actor)) { - TC(Zombie, this); - if(time >= actor.spawn_time) - actor.damageforcescale = autocvar_g_monster_zombie_damageforcescale; - return true; + TC(Zombie, this); + if (time >= actor.spawn_time) { + actor.damageforcescale = autocvar_g_monster_zombie_damageforcescale; + } + return true; } METHOD(Zombie, mr_pain, float(Zombie this, entity actor, float damage_take, entity attacker, float deathtype)) { - TC(Zombie, this); - actor.pain_finished = time + 0.34; - setanim(actor, ((random() > 0.5) ? actor.anim_pain1 : actor.anim_pain2), true, true, false); - return damage_take; + TC(Zombie, this); + actor.pain_finished = time + 0.34; + setanim(actor, ((random() > 0.5) ? actor.anim_pain1 : actor.anim_pain2), true, true, false); + return damage_take; } METHOD(Zombie, mr_death, bool(Zombie this, entity actor)) { - TC(Zombie, this); - actor.armorvalue = autocvar_g_monsters_armor_blockpercent; + TC(Zombie, this); + actor.armorvalue = autocvar_g_monsters_armor_blockpercent; - setanim(actor, ((random() > 0.5) ? actor.anim_die1 : actor.anim_die2), false, true, true); - return true; + setanim(actor, ((random() > 0.5) ? actor.anim_die1 : actor.anim_die2), false, true, true); + return true; } #endif #ifdef GAMEQC METHOD(Zombie, mr_anim, bool(Zombie this, entity actor)) { - TC(Zombie, this); - vector none = '0 0 0'; - actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds - actor.anim_die2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds - actor.anim_spawn = animfixfps(actor, '30 1 3', none); - actor.anim_walk = animfixfps(actor, '27 1 1', none); - actor.anim_idle = animfixfps(actor, '19 1 1', none); - actor.anim_pain1 = animfixfps(actor, '20 1 2', none); // 0.5 seconds - actor.anim_pain2 = animfixfps(actor, '22 1 2', none); // 0.5 seconds - actor.anim_melee1 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate - actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate - actor.anim_melee3 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate - actor.anim_shoot = animfixfps(actor, '0 1 5', none); // analyze models and set framerate - actor.anim_run = animfixfps(actor, '27 1 1', none); - actor.anim_blockstart = animfixfps(actor, '8 1 1', none); - actor.anim_blockend = animfixfps(actor, '7 1 1', none); - return true; + TC(Zombie, this); + vector none = '0 0 0'; + actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds + actor.anim_die2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds + actor.anim_spawn = animfixfps(actor, '30 1 3', none); + actor.anim_walk = animfixfps(actor, '27 1 1', none); + actor.anim_idle = animfixfps(actor, '19 1 1', none); + actor.anim_pain1 = animfixfps(actor, '20 1 2', none); // 0.5 seconds + actor.anim_pain2 = animfixfps(actor, '22 1 2', none); // 0.5 seconds + actor.anim_melee1 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate + actor.anim_melee2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate + actor.anim_melee3 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate + actor.anim_shoot = animfixfps(actor, '0 1 5', none); // analyze models and set framerate + actor.anim_run = animfixfps(actor, '27 1 1', none); + actor.anim_blockstart = animfixfps(actor, '8 1 1', none); + actor.anim_blockend = animfixfps(actor, '7 1 1', none); + return true; } #endif #ifdef SVQC METHOD(Zombie, mr_setup, bool(Zombie this, entity actor)) { - TC(Zombie, this); - if(!actor.health) actor.health = (autocvar_g_monster_zombie_health); - if(!actor.speed) { actor.speed = (autocvar_g_monster_zombie_speed_walk); } - if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_zombie_speed_run); } - if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_zombie_speed_stop); } - - if(actor.spawnflags & MONSTERFLAG_NORESPAWN) - actor.spawnflags &= ~MONSTERFLAG_NORESPAWN; // zombies always respawn - - actor.spawnflags &= ~MONSTERFLAG_APPEAR; // once it's appeared, it will respawn quickly, we don't want it to appear + TC(Zombie, this); + if (!actor.health) { actor.health = (autocvar_g_monster_zombie_health); } + if (!actor.speed) { actor.speed = (autocvar_g_monster_zombie_speed_walk); } + if (!actor.speed2) { actor.speed2 = (autocvar_g_monster_zombie_speed_run); } + if (!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_zombie_speed_stop); } + + if (actor.spawnflags & MONSTERFLAG_NORESPAWN) { + actor.spawnflags &= ~MONSTERFLAG_NORESPAWN; // zombies always respawn + } + actor.spawnflags &= ~MONSTERFLAG_APPEAR; // once it's appeared, it will respawn quickly, we don't want it to appear - actor.spawnflags |= MONSTER_RESPAWN_DEATHPOINT; + actor.spawnflags |= MONSTER_RESPAWN_DEATHPOINT; - actor.monster_loot = ITEM_HealthMedium; - actor.monster_attackfunc = M_Zombie_Attack; - actor.spawnshieldtime = actor.spawn_time; - actor.respawntime = 0.2; - actor.damageforcescale = 0.0001; // no push while spawning + actor.monster_loot = ITEM_HealthMedium; + actor.monster_attackfunc = M_Zombie_Attack; + actor.spawnshieldtime = actor.spawn_time; + actor.respawntime = 0.2; + actor.damageforcescale = 0.0001; // no push while spawning - setanim(actor, actor.anim_spawn, false, true, true); - actor.spawn_time = actor.animstate_endtime; + setanim(actor, actor.anim_spawn, false, true, true); + actor.spawn_time = actor.animstate_endtime; - return true; + return true; } #endif diff --git a/qcsrc/common/monsters/monster/zombie.qh b/qcsrc/common/monsters/monster/zombie.qh index 1572a95ea..ca958f6f1 100644 --- a/qcsrc/common/monsters/monster/zombie.qh +++ b/qcsrc/common/monsters/monster/zombie.qh @@ -7,14 +7,14 @@ MODEL(MON_ZOMBIE, M_Model("zombie.dpm")); #endif CLASS(Zombie, Monster) - ATTRIB(Zombie, spawnflags, int, MONSTER_TYPE_UNDEAD | MON_FLAG_MELEE | MON_FLAG_RIDE); - ATTRIB(Zombie, m_mins, vector, '-18 -18 -25'); - ATTRIB(Zombie, m_maxs, vector, '18 18 47'); + ATTRIB(Zombie, spawnflags, int, MONSTER_TYPE_UNDEAD | MON_FLAG_MELEE | MON_FLAG_RIDE); + ATTRIB(Zombie, m_mins, vector, '-18 -18 -25'); + ATTRIB(Zombie, m_maxs, vector, '18 18 47'); #ifdef GAMEQC - ATTRIB(Zombie, m_model, Model, MDL_MON_ZOMBIE); + ATTRIB(Zombie, m_model, Model, MDL_MON_ZOMBIE); #endif - ATTRIB(Zombie, netname, string, "zombie"); - ATTRIB(Zombie, monster_name, string, _("Zombie")); + ATTRIB(Zombie, netname, string, "zombie"); + ATTRIB(Zombie, monster_name, string, _("Zombie")); ENDCLASS(Zombie) REGISTER_MONSTER(ZOMBIE, NEW(Zombie)); diff --git a/qcsrc/common/monsters/sv_spawn.qc b/qcsrc/common/monsters/sv_spawn.qc index d6989ad31..a13fe0eda 100644 --- a/qcsrc/common/monsters/sv_spawn.qc +++ b/qcsrc/common/monsters/sv_spawn.qc @@ -2,24 +2,23 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include "../util.qh" - #include "all.qh" - #include "sv_monsters.qh" - #include - #include + #include "../util.qh" + #include "all.qh" + #include "sv_monsters.qh" + #include + #include #endif -entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag) +entity spawnmonster(entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag) { e.spawnflags = MONSTERFLAG_SPAWNED; - if(!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; } - //if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; } + if (!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; } + // if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; } setorigin(e, orig); bool allow_any = boolean(monster == "anyrandom"); - if(monster == "random" || allow_any) - { + if (monster == "random" || allow_any) { RandomSelection_Init(); FOREACH(Monsters, it != MON_Null && (allow_any || (!(it.spawnflags & MONSTER_TYPE_PASSIVE) && !(it.spawnflags & MON_FLAG_HIDDEN))), { @@ -27,51 +26,45 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, }); monster_id = RandomSelection_chosen_ent.monsterid; - } - else if(monster != "") - { + } else if (monster != "") { bool found = false; FOREACH(Monsters, it != MON_Null, { - if(it.netname == monster) - { + if (it.netname == monster) { found = true; monster_id = it.monsterid; // we have the monster, old monster id is no longer required break; } }); - if(!found && !monster_id) - { - if(removeifinvalid) - { + if (!found && !monster_id) { + if (removeifinvalid) { delete(e); return NULL; // no good - } - else + } else { monster_id = MON_FIRST; + } } } e.realowner = spawnedby; - if(moveflag) + if (moveflag) { e.monster_moveflags = moveflag; + } - if(IS_PLAYER(spawnedby)) - { - if(teamplay && autocvar_g_monsters_teams) + if (IS_PLAYER(spawnedby)) { + if (teamplay && autocvar_g_monsters_teams) { e.team = spawnedby.team; // colors handled in spawn code - - if(autocvar_g_monsters_owners) - e.monster_follow = own; // using .owner makes the monster non-solid for its master - + } + if (autocvar_g_monsters_owners) { + e.monster_follow = own; // using .owner makes the monster non-solid for its master + } e.angles_y = spawnedby.angles_y; } // Monster_Spawn checks if monster is valid - if(!Monster_Spawn(e, false, monster_id)) - { + if (!Monster_Spawn(e, false, monster_id)) { delete(e); return NULL; // remove even if told not to, as we didn't spawn any kind of monster } diff --git a/qcsrc/common/monsters/sv_spawn.qh b/qcsrc/common/monsters/sv_spawn.qh index 983676db8..062db6e3f 100644 --- a/qcsrc/common/monsters/sv_spawn.qh +++ b/qcsrc/common/monsters/sv_spawn.qh @@ -1,3 +1,3 @@ #pragma once -entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag); +entity spawnmonster(entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag); diff --git a/qcsrc/common/mutators/events.qh b/qcsrc/common/mutators/events.qh index 107a82030..0a57d52b1 100644 --- a/qcsrc/common/mutators/events.qh +++ b/qcsrc/common/mutators/events.qh @@ -5,13 +5,13 @@ #pragma noref 1 #define MUTATOR_TYPES(_, x) \ - _(x, bool) \ - _(x, int) \ - _(x, entity) \ - _(x, float) \ - _(x, vector) \ - _(x, string) \ - /**/ + _(x, bool) \ + _(x, int) \ + _(x, entity) \ + _(x, float) \ + _(x, vector) \ + _(x, string) \ + /**/ // TODO: migrate to arrays some day when no other globals are used #define M_ARGV(x, type) MUTATOR_ARGV_##x##_##type @@ -36,23 +36,23 @@ MUTATOR_TYPES(MUTATOR_NEWGLOBAL, 10) /** appends ":mutatorname" to argument for logging */ #define EV_BuildMutatorsString(i, o) \ - /** mutator string */ i(string, MUTATOR_ARGV_0_string) \ - /**/ o(string, MUTATOR_ARGV_0_string) \ - /**/ + /** mutator string */ i(string, MUTATOR_ARGV_0_string) \ + /**/ o(string, MUTATOR_ARGV_0_string) \ + /**/ MUTATOR_HOOKABLE(BuildMutatorsString, EV_BuildMutatorsString); /** appends ", Mutator name" to ret_string for display */ #define EV_BuildMutatorsPrettyString(i, o) \ - /** mutator string */ i(string, MUTATOR_ARGV_0_string) \ - /**/ o(string, MUTATOR_ARGV_0_string) \ - /**/ + /** mutator string */ i(string, MUTATOR_ARGV_0_string) \ + /**/ o(string, MUTATOR_ARGV_0_string) \ + /**/ MUTATOR_HOOKABLE(BuildMutatorsPrettyString, EV_BuildMutatorsPrettyString); /** appends mutator string for displaying extra gameplay tips */ #define EV_BuildGameplayTipsString(i, o) \ - /** tips string */ i(string, MUTATOR_ARGV_0_string) \ - /**/ o(string, MUTATOR_ARGV_0_string) \ - /**/ + /** tips string */ i(string, MUTATOR_ARGV_0_string) \ + /**/ o(string, MUTATOR_ARGV_0_string) \ + /**/ MUTATOR_HOOKABLE(BuildGameplayTipsString, EV_BuildGameplayTipsString); #define EV_IsFlying(i, o) \ @@ -61,11 +61,11 @@ MUTATOR_HOOKABLE(BuildGameplayTipsString, EV_BuildGameplayTipsString); MUTATOR_HOOKABLE(IsFlying, EV_IsFlying); #define EV_WP_Format(i, o) \ - /**/ i(entity, MUTATOR_ARGV_0_entity) \ - /**/ i(string, MUTATOR_ARGV_1_string) \ - /**/ o(vector, MUTATOR_ARGV_2_vector) \ - /**/ o(string, MUTATOR_ARGV_3_string) \ - /**/ + /**/ i(entity, MUTATOR_ARGV_0_entity) \ + /**/ i(string, MUTATOR_ARGV_1_string) \ + /**/ o(vector, MUTATOR_ARGV_2_vector) \ + /**/ o(string, MUTATOR_ARGV_3_string) \ + /**/ MUTATOR_HOOKABLE(WP_Format, EV_WP_Format); /** @@ -73,41 +73,41 @@ MUTATOR_HOOKABLE(WP_Format, EV_WP_Format); * is run AFTER bot code and idle checking on the server */ #define EV_PlayerPhysics(i, o) \ - /** player */ i(entity, MUTATOR_ARGV_0_entity) \ - /** ticrate*/ i(float, MUTATOR_ARGV_1_float) \ - /**/ + /** player */ i(entity, MUTATOR_ARGV_0_entity) \ + /** ticrate*/ i(float, MUTATOR_ARGV_1_float) \ + /**/ MUTATOR_HOOKABLE(PlayerPhysics, EV_PlayerPhysics); /** called when a player presses the jump key */ #define EV_PlayerJump(i, o) \ - /** player */ i(entity, MUTATOR_ARGV_0_entity) \ - /** jump height */ i(float, MUTATOR_ARGV_1_float) \ - /**/ o(float, MUTATOR_ARGV_1_float) \ - /** multijump */ i(bool, MUTATOR_ARGV_2_bool) \ - /**/ o(bool, MUTATOR_ARGV_2_bool) \ - /**/ + /** player */ i(entity, MUTATOR_ARGV_0_entity) \ + /** jump height */ i(float, MUTATOR_ARGV_1_float) \ + /**/ o(float, MUTATOR_ARGV_1_float) \ + /** multijump */ i(bool, MUTATOR_ARGV_2_bool) \ + /**/ o(bool, MUTATOR_ARGV_2_bool) \ + /**/ MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump); /** called during player physics, allows adjusting the movement type used */ #define EV_PM_Physics(i, o) \ - /** player */ i(entity, MUTATOR_ARGV_0_entity) \ - /** maxspeed_mod */ i(float, MUTATOR_ARGV_1_float) \ - /** tick rate */ i(float, MUTATOR_ARGV_2_float) \ - /**/ + /** player */ i(entity, MUTATOR_ARGV_0_entity) \ + /** maxspeed_mod */ i(float, MUTATOR_ARGV_1_float) \ + /** tick rate */ i(float, MUTATOR_ARGV_2_float) \ + /**/ MUTATOR_HOOKABLE(PM_Physics, EV_PM_Physics); /** called when a weapon sound is about to be played, allows custom paths etc. */ #define EV_WeaponSound(i, o) \ - /** sound */ i(string, MUTATOR_ARGV_0_string) \ - /** output */ i(string, MUTATOR_ARGV_1_string) \ - /**/ o(string, MUTATOR_ARGV_1_string) \ - /**/ + /** sound */ i(string, MUTATOR_ARGV_0_string) \ + /** output */ i(string, MUTATOR_ARGV_1_string) \ + /**/ o(string, MUTATOR_ARGV_1_string) \ + /**/ MUTATOR_HOOKABLE(WeaponSound, EV_WeaponSound); /** called when a weapon model is about to be set, allows custom paths etc. */ #define EV_WeaponModel(i, o) \ - /** model */ i(string, MUTATOR_ARGV_0_string) \ - /** output */ i(string, MUTATOR_ARGV_1_string) \ - /**/ o(string, MUTATOR_ARGV_1_string) \ - /**/ + /** model */ i(string, MUTATOR_ARGV_0_string) \ + /** output */ i(string, MUTATOR_ARGV_1_string) \ + /**/ o(string, MUTATOR_ARGV_1_string) \ + /**/ MUTATOR_HOOKABLE(WeaponModel, EV_WeaponModel); diff --git a/qcsrc/common/mutators/mutator/bloodloss/sv_bloodloss.qc b/qcsrc/common/mutators/mutator/bloodloss/sv_bloodloss.qc index 1164e0ade..b19a4f5e3 100644 --- a/qcsrc/common/mutators/mutator/bloodloss/sv_bloodloss.qc +++ b/qcsrc/common/mutators/mutator/bloodloss/sv_bloodloss.qc @@ -9,18 +9,19 @@ MUTATOR_HOOKFUNCTION(bloodloss, PlayerPreThink) { entity player = M_ARGV(0, entity); - if(IS_PLAYER(player)) - if(GetResourceAmount(player, RESOURCE_HEALTH) <= autocvar_g_bloodloss && !IS_DEAD(player)) - { - PHYS_INPUT_BUTTON_CROUCH(player) = true; - - if(time >= player.bloodloss_timer) - { - if(player.vehicle) - vehicles_exit(player.vehicle, VHEF_RELEASE); - if(player.event_damage) - player.event_damage(player, player, player, 1, DEATH_ROT.m_id, player.origin, '0 0 0'); - player.bloodloss_timer = time + 0.5 + random() * 0.5; + if (IS_PLAYER(player)) { + if (GetResourceAmount(player, RESOURCE_HEALTH) <= autocvar_g_bloodloss && !IS_DEAD(player)) { + PHYS_INPUT_BUTTON_CROUCH(player) = true; + + if (time >= player.bloodloss_timer) { + if (player.vehicle) { + vehicles_exit(player.vehicle, VHEF_RELEASE); + } + if (player.event_damage) { + player.event_damage(player, player, player, 1, DEATH_ROT.m_id, player.origin, '0 0 0'); + } + player.bloodloss_timer = time + 0.5 + random() * 0.5; + } } } } @@ -29,8 +30,9 @@ MUTATOR_HOOKFUNCTION(bloodloss, PlayerJump) { entity player = M_ARGV(0, entity); - if(GetResourceAmount(player, RESOURCE_HEALTH) <= autocvar_g_bloodloss) + if (GetResourceAmount(player, RESOURCE_HEALTH) <= autocvar_g_bloodloss) { return true; + } } MUTATOR_HOOKFUNCTION(bloodloss, BuildMutatorsString) diff --git a/qcsrc/common/mutators/mutator/breakablehook/sv_breakablehook.qc b/qcsrc/common/mutators/mutator/breakablehook/sv_breakablehook.qc index ee1ca94b5..30f6283eb 100644 --- a/qcsrc/common/mutators/mutator/breakablehook/sv_breakablehook.qc +++ b/qcsrc/common/mutators/mutator/breakablehook/sv_breakablehook.qc @@ -13,16 +13,14 @@ MUTATOR_HOOKFUNCTION(breakablehook, Damage_Calculate) entity frag_attacker = M_ARGV(1, entity); entity frag_target = M_ARGV(2, entity); - if(frag_target.classname == "grapplinghook") - { - if((!autocvar_g_breakablehook) - || (!autocvar_g_breakablehook_owner && frag_attacker == frag_target.realowner) - ) { M_ARGV(4, float) = 0; } + if (frag_target.classname == "grapplinghook") { + if ((!autocvar_g_breakablehook) + || (!autocvar_g_breakablehook_owner && frag_attacker == frag_target.realowner) + ) { M_ARGV(4, float) = 0; } // hurt the owner of the hook - if(DIFF_TEAM(frag_attacker, frag_target.realowner)) - { - Damage (frag_target.realowner, frag_attacker, frag_attacker, 5, WEP_HOOK.m_id | HITTYPE_SPLASH, frag_target.realowner.origin, '0 0 0'); + if (DIFF_TEAM(frag_attacker, frag_target.realowner)) { + Damage(frag_target.realowner, frag_attacker, frag_attacker, 5, WEP_HOOK.m_id | HITTYPE_SPLASH, frag_target.realowner.origin, '0 0 0'); RemoveHook(frag_target); return; // dead } diff --git a/qcsrc/common/mutators/mutator/buffs/buffs.qh b/qcsrc/common/mutators/mutator/buffs/buffs.qh index 81a638ea7..a352ba54a 100644 --- a/qcsrc/common/mutators/mutator/buffs/buffs.qh +++ b/qcsrc/common/mutators/mutator/buffs/buffs.qh @@ -14,7 +14,7 @@ REGISTER_REGISTRY(Buffs) REGISTRY_CHECK(Buffs) #define REGISTER_BUFF(id) \ - REGISTER(Buffs, BUFF_##id, m_id, NEW(Buff)) + REGISTER(Buffs, BUFF_##id, m_id, NEW(Buff)) #include CLASS(Buff, Pickup) @@ -25,39 +25,49 @@ CLASS(Buff, Pickup) ATTRIB(Buff, m_prettyName, string, "Buff"); ATTRIB(Buff, m_skin, int, 0); ATTRIB(Buff, m_sprite, string, ""); - METHOD(Buff, display, void(entity this, void(string name, string icon) returns)) { + METHOD(Buff, display, void(entity this, void(string name, string icon) returns)) + { returns(this.m_prettyName, sprintf("/gfx/hud/%s/buff_%s", cvar_string("menu_skin"), this.m_name)); } #ifdef SVQC METHOD(Buff, m_time, float(Buff this)) - { return cvar(strcat("g_buffs_", this.netname, "_time")); } + { + return cvar(strcat("g_buffs_", this.netname, "_time")); + } #endif ENDCLASS(Buff) -STATIC_INIT(REGISTER_BUFFS) { - FOREACH(Buffs, true, { - it.netname = it.m_name; \ - it.m_itemid = BIT(it.m_id - 1); \ - it.m_sprite = strzone(strcat("buff-", it.m_name)); \ - }); +STATIC_INIT(REGISTER_BUFFS) +{ + FOREACH(Buffs, true, { + it.netname = it.m_name; \ + it.m_itemid = BIT(it.m_id - 1); \ + it.m_sprite = strzone(strcat("buff-", it.m_name)); \ + }); } #ifdef SVQC - // .int buffs = _STAT(BUFFS); - void buff_Init(entity ent); - void buff_Init_Compat(entity ent, entity replacement); - #define BUFF_SPAWNFUNC(e, b, t) spawnfunc(item_buff_##e) { \ +// .int buffs = _STAT(BUFFS); +void buff_Init(entity ent); +void buff_Init_Compat(entity ent, entity replacement); + #define BUFF_SPAWNFUNC(e, b, t) \ + spawnfunc(item_buff_##e) \ + { \ this.buffs = b.m_itemid; \ this.team = t; \ buff_Init(this); \ } #define BUFF_SPAWNFUNCS(e, b) \ - BUFF_SPAWNFUNC(e, b, 0) \ - BUFF_SPAWNFUNC(e##_team1, b, NUM_TEAM_1) \ - BUFF_SPAWNFUNC(e##_team2, b, NUM_TEAM_2) \ - BUFF_SPAWNFUNC(e##_team3, b, NUM_TEAM_3) \ - BUFF_SPAWNFUNC(e##_team4, b, NUM_TEAM_4) - #define BUFF_SPAWNFUNC_Q3TA_COMPAT(o, r) spawnfunc(item_##o) { buff_Init_Compat(this, r); } + BUFF_SPAWNFUNC(e, b, 0) \ + BUFF_SPAWNFUNC(e##_team1, b, NUM_TEAM_1) \ + BUFF_SPAWNFUNC(e##_team2, b, NUM_TEAM_2) \ + BUFF_SPAWNFUNC(e##_team3, b, NUM_TEAM_3) \ + BUFF_SPAWNFUNC(e##_team4, b, NUM_TEAM_4) + #define BUFF_SPAWNFUNC_Q3TA_COMPAT(o, r) \ + spawnfunc(item_##o) \ + { \ + buff_Init_Compat(this, r); \ + } #else #define BUFF_SPAWNFUNC(e, b, t) #define BUFF_SPAWNFUNCS(e, b) diff --git a/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc b/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc index a46a92d0a..73c1d34ed 100644 --- a/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc +++ b/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc @@ -3,20 +3,19 @@ REGISTER_MUTATOR(cl_buffs, true); MUTATOR_HOOKFUNCTION(cl_buffs, HUD_Powerups_add) { - int allBuffs = STAT(BUFFS); - FOREACH(Buffs, it.m_itemid & allBuffs, { + int allBuffs = STAT(BUFFS); + FOREACH(Buffs, it.m_itemid & allBuffs, { addPowerupItem(it.m_prettyName, strcat("buff_", it.m_name), it.m_color, bound(0, STAT(BUFF_TIME) - time, 99), 60); }); } MUTATOR_HOOKFUNCTION(cl_buffs, WP_Format) { - entity this = M_ARGV(0, entity); - string s = M_ARGV(1, string); - if (s == WP_Buff.netname || s == RADARICON_Buff.netname) - { - Buff b = Buffs_from(this.wp_extra); - M_ARGV(2, vector) = b.m_color; - M_ARGV(3, string) = b.m_prettyName; - return true; - } + entity this = M_ARGV(0, entity); + string s = M_ARGV(1, string); + if (s == WP_Buff.netname || s == RADARICON_Buff.netname) { + Buff b = Buffs_from(this.wp_extra); + M_ARGV(2, vector) = b.m_color; + M_ARGV(3, string) = b.m_prettyName; + return true; + } } diff --git a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc index e039a96b9..d9a966e0b 100644 --- a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc +++ b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc @@ -12,8 +12,9 @@ REGISTER_MUTATOR(buffs, autocvar_g_buffs) { MUTATOR_ONADD { - if(autocvar_g_buffs > 0) + if (autocvar_g_buffs > 0) { InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET); + } } } @@ -26,20 +27,19 @@ bool buffs_BuffModel_Customize(entity this, entity client) myowner = this.owner; same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner)); - if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0) + if (myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0) { return false; + } - if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player)) + if (MUTATOR_CALLHOOK(BuffModel_Customize, this, player)) { return false; + } - if(player == myowner || (IS_SPEC(client) && client.enemy == myowner)) - { + if (player == myowner || (IS_SPEC(client) && client.enemy == myowner)) { // somewhat hide the model, but keep the glow this.effects = 0; this.alpha = -1; - } - else - { + } else { this.effects = EF_FULLBRIGHT | EF_LOWPRECISION; this.alpha = 1; } @@ -62,16 +62,15 @@ void buffs_BuffModel_Spawn(entity player) vector buff_GlowColor(entity buff) { - //if(buff.team) { return Team_ColorRGB(buff.team); } + // if(buff.team) { return Team_ColorRGB(buff.team); } return buff.m_color; } void buff_Effect(entity player, string eff) { - if(!autocvar_g_buffs_effects) { return; } + if (!autocvar_g_buffs_effects) { return; } - if(time >= player.buff_effect_delay) - { + if (time >= player.buff_effect_delay) { Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1); player.buff_effect_delay = time + 0.05; // prevent spam } @@ -80,11 +79,11 @@ void buff_Effect(entity player, string eff) // buff item bool buff_Waypoint_visible_for_player(entity this, entity player, entity view) { - if(!this.owner.buff_active && !this.owner.buff_activetime) + if (!this.owner.buff_active && !this.owner.buff_activetime) { return false; + } - if (view.buffs) - { + if (view.buffs) { return CS(view).cvar_cl_buffs_autoreplace == false || view.buffs != this.owner.buffs; } @@ -104,8 +103,9 @@ void buff_SetCooldown(entity this, float cd) { cd = max(0, cd); - if(!this.buff_waypoint) + if (!this.buff_waypoint) { buff_Waypoint_Spawn(this); + } WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd); this.buff_activetime = cd; @@ -114,14 +114,13 @@ void buff_SetCooldown(entity this, float cd) void buff_Respawn(entity this) { - if(game_stopped) return; + if (game_stopped) { return; } vector oldbufforigin = this.origin; this.velocity = '0 0 200'; - if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, - ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256)) - { + if (!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, + ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256)) { entity spot = SelectSpawnPoint(this, true); setorigin(this, spot.origin); this.velocity = ((randomvec() * 100) + '0 0 200'); @@ -136,8 +135,9 @@ void buff_Respawn(entity this) makevectors(this.angles); this.angles = '0 0 0'; - if(autocvar_g_buffs_random_lifetime > 0) + if (autocvar_g_buffs_random_lifetime > 0) { this.lifetime = time + autocvar_g_buffs_random_lifetime; + } Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1); Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1); @@ -149,46 +149,43 @@ void buff_Respawn(entity this) void buff_Touch(entity this, entity toucher) { - if(game_stopped) return; + if (game_stopped) { return; } - if(ITEM_TOUCH_NEEDKILL()) - { + if (ITEM_TOUCH_NEEDKILL()) { buff_Respawn(this); return; } - if(!this.buff_active) + if (!this.buff_active) { return; + } - if(MUTATOR_CALLHOOK(BuffTouch, this, toucher)) + if (MUTATOR_CALLHOOK(BuffTouch, this, toucher)) { return; + } toucher = M_ARGV(1, entity); - if(!IS_PLAYER(toucher)) + if (!IS_PLAYER(toucher)) { return; // incase mutator changed toucher - - if((this.team && DIFF_TEAM(toucher, this)) - || (STAT(FROZEN, toucher)) - || (toucher.vehicle) - || (time < PS(toucher).buff_shield) - ) - { + } + if ((this.team && DIFF_TEAM(toucher, this)) + || (STAT(FROZEN, toucher)) + || (toucher.vehicle) + || (time < PS(toucher).buff_shield) + ) { // can't touch this return; } - if (toucher.buffs) - { - if (CS(toucher).cvar_cl_buffs_autoreplace && toucher.buffs != this.buffs) - { + if (toucher.buffs) { + if (CS(toucher).cvar_cl_buffs_autoreplace && toucher.buffs != this.buffs) { int buffid = buff_FirstFromFlags(toucher.buffs).m_id; - //Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_DROP, toucher.buffs); + // Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_DROP, toucher.buffs); Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid); toucher.buffs = 0; - //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM); - } - else { return; } // do nothing + // sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM); + } else { return; } // do nothing } this.owner = toucher; @@ -205,12 +202,15 @@ void buff_Touch(entity this, entity toucher) float buff_Available(entity buff) { - if (buff == BUFF_Null) + if (buff == BUFF_Null) { return false; - if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only")))) + } + if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only")))) { return false; - if (buff == BUFF_VAMPIRE && cvar("g_vampire")) + } + if (buff == BUFF_VAMPIRE && cvar("g_vampire")) { return false; + } return cvar(strcat("g_buffs_", buff.m_name)); } @@ -231,8 +231,7 @@ void buff_NewType(entity ent) void buff_Think(entity this) { - if(this.buffs != this.oldbuffs) - { + if (this.buffs != this.oldbuffs) { entity buff = buff_FirstFromFlags(this.buffs); this.color = buff.m_color; this.glowmod = buff_GlowColor(buff); @@ -241,99 +240,103 @@ void buff_Think(entity this) setmodel(this, MDL_BUFF); setsize(this, BUFF_MIN, BUFF_MAX); - if(this.buff_waypoint) - { - //WaypointSprite_Disown(this.buff_waypoint, 1); + if (this.buff_waypoint) { + // WaypointSprite_Disown(this.buff_waypoint, 1); WaypointSprite_Kill(this.buff_waypoint); buff_Waypoint_Spawn(this); - if(this.buff_activetime) + if (this.buff_activetime) { WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime); + } } this.oldbuffs = this.buffs; } - if(!game_stopped) - if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime) - if(!this.buff_activetime_updated) - { - buff_SetCooldown(this, this.buff_activetime); - this.buff_activetime_updated = true; + if (!game_stopped) { + if ((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime) { + if (!this.buff_activetime_updated) { + buff_SetCooldown(this, this.buff_activetime); + this.buff_activetime_updated = true; + } + } } - if(!this.buff_active && !this.buff_activetime) - if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle || !(this.owner.buffs & this.buffs) || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway)) - { - buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime); - this.owner = NULL; - if(autocvar_g_buffs_randomize) - buff_NewType(this); + if (!this.buff_active && !this.buff_activetime) { + if (!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle || !(this.owner.buffs & this.buffs) || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway)) { + buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime); + this.owner = NULL; + if (autocvar_g_buffs_randomize) { + buff_NewType(this); + } - if(autocvar_g_buffs_random_location || (this.spawnflags & 64)) - buff_Respawn(this); + if (autocvar_g_buffs_random_location || (this.spawnflags & 64)) { + buff_Respawn(this); + } + } } - if(this.buff_activetime) - if(!game_stopped) - if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime) - { - this.buff_activetime = max(0, this.buff_activetime - frametime); + if (this.buff_activetime) { + if (!game_stopped) { + if ((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime) { + this.buff_activetime = max(0, this.buff_activetime - frametime); - if(!this.buff_activetime) - { - this.buff_active = true; - sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM); - Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1); + if (!this.buff_activetime) { + this.buff_active = true; + sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM); + Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1); + } + } } } - if(this.buff_active) - { - if(this.team && !this.buff_waypoint) + if (this.buff_active) { + if (this.team && !this.buff_waypoint) { buff_Waypoint_Spawn(this); + } - if(this.lifetime) - if(time >= this.lifetime) - buff_Respawn(this); + if (this.lifetime) { + if (time >= this.lifetime) { + buff_Respawn(this); + } + } } this.nextthink = time; - //this.angles_y = time * 110.1; + // this.angles_y = time * 110.1; } void buff_Waypoint_Reset(entity this) { WaypointSprite_Kill(this.buff_waypoint); - if(this.buff_activetime) { buff_Waypoint_Spawn(this); } + if (this.buff_activetime) { buff_Waypoint_Spawn(this); } } void buff_Reset(entity this) { - if(autocvar_g_buffs_randomize) + if (autocvar_g_buffs_randomize) { buff_NewType(this); + } this.owner = NULL; buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate); buff_Waypoint_Reset(this); this.buff_activetime_updated = false; - if(autocvar_g_buffs_random_location || (this.spawnflags & 64)) + if (autocvar_g_buffs_random_location || (this.spawnflags & 64)) { buff_Respawn(this); + } } bool buff_Customize(entity this, entity client) { entity player = WaypointSprite_getviewentity(client); - if(!this.buff_active || (this.team && DIFF_TEAM(player, this))) - { + if (!this.buff_active || (this.team && DIFF_TEAM(player, this))) { this.alpha = 0.3; - if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); } + if (this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); } this.pflags = 0; - } - else - { + } else { this.alpha = 1; - if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; } + if (!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; } this.light_lev = 220 + 36 * sin(time); this.pflags = PFLAGS_FULLDYNAMIC; } @@ -342,14 +345,15 @@ bool buff_Customize(entity this, entity client) void buff_Init(entity this) { - if(!cvar("g_buffs")) { delete(this); return; } + if (!cvar("g_buffs")) { delete(this); return; } - if(!teamplay && this.team) { this.team = 0; } + if (!teamplay && this.team) { this.team = 0; } entity buff = buff_FirstFromFlags(this.buffs); - if(!this.buffs || !buff_Available(buff)) + if (!this.buffs || !buff_Available(buff)) { buff_NewType(this); + } this.classname = "item_buff"; this.solid = SOLID_TRIGGER; @@ -369,32 +373,35 @@ void buff_Init(entity this) this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW; this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY; setcefc(this, buff_Customize); - //this.gravity = 100; + // this.gravity = 100; this.color = buff.m_color; this.glowmod = buff_GlowColor(this); buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time)); this.buff_active = !this.buff_activetime; this.pflags = PFLAGS_FULLDYNAMIC; - if(this.spawnflags & 1) + if (this.spawnflags & 1) { this.noalign = true; + } - if(this.noalign) + if (this.noalign) { set_movetype(this, MOVETYPE_NONE); // reset by random location - + } setmodel(this, MDL_BUFF); setsize(this, BUFF_MIN, BUFF_MAX); - if(cvar("g_buffs_random_location") || (this.spawnflags & 64)) + if (cvar("g_buffs_random_location") || (this.spawnflags & 64)) { buff_Respawn(this); + } } void buff_Init_Compat(entity ent, entity replacement) { - if (ent.spawnflags & 2) + if (ent.spawnflags & 2) { ent.team = NUM_TEAM_1; - else if (ent.spawnflags & 4) + } else if (ent.spawnflags & 4) { ent.team = NUM_TEAM_2; + } ent.buffs = replacement.m_itemid; @@ -412,11 +419,11 @@ void buff_SpawnReplacement(entity ent, entity old) void buff_Vengeance_DelayedDamage(entity this) { - if(this.enemy) + if (this.enemy) { Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, this.enemy.origin, '0 0 0'); + } delete(this); - return; } // note: only really useful in teamplay @@ -424,13 +431,11 @@ void buff_Medic_Heal(entity this) { FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range), { - if (!SAME_TEAM(it, this)) - { + if (!SAME_TEAM(it, this)) { continue; } float hp = GetResourceAmount(it, RESOURCE_HEALTH); - if(hp >= autocvar_g_balance_health_regenstable) - { + if (hp >= autocvar_g_balance_health_regenstable) { continue; } Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1); @@ -452,104 +457,133 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate) float frag_damage = M_ARGV(4, float); vector frag_force = M_ARGV(6, vector); - if(frag_deathtype == DEATH_BUFF.m_id) { return; } + if (frag_deathtype == DEATH_BUFF.m_id) { return; } - if(frag_target.buffs & BUFF_RESISTANCE.m_itemid) - { + if (frag_target.buffs & BUFF_RESISTANCE.m_itemid) { float reduced = frag_damage * autocvar_g_buffs_resistance_blockpercent; frag_damage = bound(0, frag_damage - reduced, frag_damage); } - if(frag_target.buffs & BUFF_SPEED.m_itemid) - if(frag_target != frag_attacker) - frag_damage *= autocvar_g_buffs_speed_damage_take; - - if(frag_target.buffs & BUFF_MEDIC.m_itemid) - if((GetResourceAmount(frag_target, RESOURCE_HEALTH) - frag_damage) <= 0) - if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) - if(frag_attacker) - if(random() <= autocvar_g_buffs_medic_survive_chance) - frag_damage = max(5, GetResourceAmount(frag_target, RESOURCE_HEALTH) - autocvar_g_buffs_medic_survive_health); + if (frag_target.buffs & BUFF_SPEED.m_itemid) { + if (frag_target != frag_attacker) { + frag_damage *= autocvar_g_buffs_speed_damage_take; + } + } - if(frag_target.buffs & BUFF_JUMP.m_itemid) - if(frag_deathtype == DEATH_FALL.m_id) - frag_damage = 0; + if (frag_target.buffs & BUFF_MEDIC.m_itemid) { + if ((GetResourceAmount(frag_target, RESOURCE_HEALTH) - frag_damage) <= 0) { + if (!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) { + if (frag_attacker) { + if (random() <= autocvar_g_buffs_medic_survive_chance) { + frag_damage = max(5, GetResourceAmount(frag_target, RESOURCE_HEALTH) - autocvar_g_buffs_medic_survive_health); + } + } + } + } + } - if(frag_target.buffs & BUFF_VENGEANCE.m_itemid) - if(frag_attacker) - if(frag_attacker != frag_target) - if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) - { - entity dmgent = spawn(); + if (frag_target.buffs & BUFF_JUMP.m_itemid) { + if (frag_deathtype == DEATH_FALL.m_id) { + frag_damage = 0; + } + } - dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier; - dmgent.enemy = frag_attacker; - dmgent.owner = frag_target; - setthink(dmgent, buff_Vengeance_DelayedDamage); - dmgent.nextthink = time + 0.1; + if (frag_target.buffs & BUFF_VENGEANCE.m_itemid) { + if (frag_attacker) { + if (frag_attacker != frag_target) { + if (!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) { + entity dmgent = spawn(); + + dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier; + dmgent.enemy = frag_attacker; + dmgent.owner = frag_target; + setthink(dmgent, buff_Vengeance_DelayedDamage); + dmgent.nextthink = time + 0.1; + } + } + } } - if(frag_target.buffs & BUFF_BASH.m_itemid) - if(frag_attacker != frag_target) - frag_force = '0 0 0'; + if (frag_target.buffs & BUFF_BASH.m_itemid) { + if (frag_attacker != frag_target) { + frag_force = '0 0 0'; + } + } - if(frag_attacker.buffs & BUFF_BASH.m_itemid) - if(frag_force) - if(frag_attacker == frag_target) - frag_force *= autocvar_g_buffs_bash_force_self; - else - frag_force *= autocvar_g_buffs_bash_force; + if (frag_attacker.buffs & BUFF_BASH.m_itemid) { + if (frag_force) { + if (frag_attacker == frag_target) { + frag_force *= autocvar_g_buffs_bash_force_self; + } else { + frag_force *= autocvar_g_buffs_bash_force; + } + } + } - if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid) - if(frag_target != frag_attacker) - frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime; + if (frag_attacker.buffs & BUFF_DISABILITY.m_itemid) { + if (frag_target != frag_attacker) { + frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime; + } + } - if(frag_target.buffs & BUFF_INFERNO.m_itemid) - { - if(frag_deathtype == DEATH_FIRE.m_id) + if (frag_target.buffs & BUFF_INFERNO.m_itemid) { + if (frag_deathtype == DEATH_FIRE.m_id) { frag_damage = 0; - if(frag_deathtype == DEATH_LAVA.m_id) + } + if (frag_deathtype == DEATH_LAVA.m_id) { frag_damage *= 0.5; // TODO: cvarize? + } } - if(frag_attacker.buffs & BUFF_LUCK.m_itemid) - if(frag_attacker != frag_target) - if(autocvar_g_buffs_luck_damagemultiplier > 0) - if(random() <= autocvar_g_buffs_luck_chance) - frag_damage *= autocvar_g_buffs_luck_damagemultiplier; + if (frag_attacker.buffs & BUFF_LUCK.m_itemid) { + if (frag_attacker != frag_target) { + if (autocvar_g_buffs_luck_damagemultiplier > 0) { + if (random() <= autocvar_g_buffs_luck_chance) { + frag_damage *= autocvar_g_buffs_luck_damagemultiplier; + } + } + } + } - if(frag_attacker.buffs & BUFF_INFERNO.m_itemid) - if(frag_target != frag_attacker) { - float btime = buff_Inferno_CalculateTime( - frag_damage, - 0, - autocvar_g_buffs_inferno_burntime_min_time, - autocvar_g_buffs_inferno_burntime_target_damage, - autocvar_g_buffs_inferno_burntime_target_time, - autocvar_g_buffs_inferno_burntime_factor - ); - Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id); + if (frag_attacker.buffs & BUFF_INFERNO.m_itemid) { + if (frag_target != frag_attacker) { + float btime = buff_Inferno_CalculateTime( + frag_damage, + 0, + autocvar_g_buffs_inferno_burntime_min_time, + autocvar_g_buffs_inferno_burntime_target_damage, + autocvar_g_buffs_inferno_burntime_target_time, + autocvar_g_buffs_inferno_burntime_factor + ); + Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id); + } } // this... is ridiculous (TODO: fix!) - if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid) - if(!frag_target.vehicle) - if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) - if(!IS_DEAD(frag_target)) - if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target)) - if(frag_attacker != frag_target) - if(!STAT(FROZEN, frag_target)) - if(frag_target.takedamage) - if(DIFF_TEAM(frag_attacker, frag_target)) - { - float amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, - GetResourceAmount(frag_target, RESOURCE_HEALTH)); - GiveResourceWithLimit(frag_attacker, RESOURCE_HEALTH, amount, g_pickup_healthsmall_max); - if (frag_target.armorvalue) - { - amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, - GetResourceAmount(frag_target, RESOURCE_ARMOR)); - GiveResourceWithLimit(frag_attacker, RESOURCE_ARMOR, amount, g_pickup_armorsmall_max); + if (frag_attacker.buffs & BUFF_VAMPIRE.m_itemid) { + if (!frag_target.vehicle) { + if (!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) { + if (!IS_DEAD(frag_target)) { + if (IS_PLAYER(frag_target) || IS_MONSTER(frag_target)) { + if (frag_attacker != frag_target) { + if (!STAT(FROZEN, frag_target)) { + if (frag_target.takedamage) { + if (DIFF_TEAM(frag_attacker, frag_target)) { + float amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, + GetResourceAmount(frag_target, RESOURCE_HEALTH)); + GiveResourceWithLimit(frag_attacker, RESOURCE_HEALTH, amount, g_pickup_healthsmall_max); + if (frag_target.armorvalue) { + amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, + GetResourceAmount(frag_target, RESOURCE_ARMOR)); + GiveResourceWithLimit(frag_attacker, RESOURCE_ARMOR, amount, g_pickup_armorsmall_max); + } + } + } + } + } + } + } + } } } @@ -574,11 +608,13 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats) entity player = M_ARGV(0, entity); // these automatically reset, no need to worry - if(player.buffs & BUFF_SPEED.m_itemid) + if (player.buffs & BUFF_SPEED.m_itemid) { STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed; + } - if(time < player.buff_disability_time) + if (time < player.buff_disability_time) { STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed; + } } MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics) @@ -586,16 +622,16 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics) entity player = M_ARGV(0, entity); // these automatically reset, no need to worry - if(player.buffs & BUFF_JUMP.m_itemid) + if (player.buffs & BUFF_JUMP.m_itemid) { STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height; + } } MUTATOR_HOOKFUNCTION(buffs, MonsterMove) { entity mon = M_ARGV(0, entity); - if(time < mon.buff_disability_time) - { + if (time < mon.buff_disability_time) { M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed } @@ -605,14 +641,12 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerDies) { entity frag_target = M_ARGV(2, entity); - if(frag_target.buffs) - { + if (frag_target.buffs) { int buffid = buff_FirstFromFlags(frag_target.buffs).m_id; Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid); frag_target.buffs = 0; - if(frag_target.buff_model) - { + if (frag_target.buff_model) { delete(frag_target.buff_model); frag_target.buff_model = NULL; } @@ -621,19 +655,18 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerDies) MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST) { - if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return; + if (MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) { return; } entity player = M_ARGV(0, entity); - if(player.buffs) - { + if (player.buffs) { int buffid = buff_FirstFromFlags(player.buffs).m_id; Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid); player.buffs = 0; PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); - //player.buff_time = 0; // already notified + // player.buff_time = 0; // already notified sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM); return true; } @@ -641,28 +674,25 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST) MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon) { - if(MUTATOR_RETURNVALUE || game_stopped) return; + if (MUTATOR_RETURNVALUE || game_stopped) { return; } entity player = M_ARGV(0, entity); - if(player.buffs & BUFF_SWAPPER.m_itemid) - { + if (player.buffs & BUFF_SWAPPER.m_itemid) { float best_distance = autocvar_g_buffs_swapper_range; entity closest = NULL; FOREACH_CLIENT(IS_PLAYER(it), { - if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle) - if(DIFF_TEAM(it, player)) - { - float test = vlen2(player.origin - it.origin); - if(test <= best_distance * best_distance) - { - best_distance = sqrt(test); - closest = it; + if (!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle) { + if (DIFF_TEAM(it, player)) { + float test = vlen2(player.origin - it.origin); + if (test <= best_distance * best_distance) { + best_distance = sqrt(test); + closest = it; + } } } }); - if(closest) - { + if (closest) { vector my_org, my_vel, my_ang, their_org, their_vel, their_ang; my_org = player.origin; @@ -710,8 +740,7 @@ MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon) bool buffs_RemovePlayer(entity player) { - if(player.buff_model) - { + if (player.buff_model) { delete(player.buff_model); player.buff_model = NULL; } @@ -722,8 +751,16 @@ bool buffs_RemovePlayer(entity player) return false; } -MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); } -MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); } +MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) +{ + entity player = M_ARGV(0, entity); + return buffs_RemovePlayer(player); +} +MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) +{ + entity player = M_ARGV(0, entity); + return buffs_RemovePlayer(player); +} MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint) { @@ -734,27 +771,29 @@ MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint) // if you have the invisibility powerup, sprites ALWAYS are restricted to your team // but only apply this to real players, not to spectators - if((wp.owner.flags & FL_CLIENT) && (wp.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == player)) - if(DIFF_TEAM(wp.owner, e)) - return true; + if ((wp.owner.flags & FL_CLIENT) && (wp.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == player)) { + if (DIFF_TEAM(wp.owner, e)) { + return true; + } + } } MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST) { - if(autocvar_g_buffs < 0) + if (autocvar_g_buffs < 0) { return; // no auto replacing of entities in this mode - + } entity ent = M_ARGV(0, entity); - if(autocvar_g_buffs_replace_powerups) - switch(ent.classname) - { - case "item_strength": - case "item_invincible": - { - entity e = spawn(); - buff_SpawnReplacement(e, ent); - return true; + if (autocvar_g_buffs_replace_powerups) { + switch (ent.classname) { + case "item_strength": + case "item_invincible": + { + entity e = spawn(); + buff_SpawnReplacement(e, ent); + return true; + } } } } @@ -763,22 +802,26 @@ MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor) { entity player = M_ARGV(1, entity); - if(player.buffs & BUFF_SPEED.m_itemid) + if (player.buffs & BUFF_SPEED.m_itemid) { M_ARGV(0, float) *= autocvar_g_buffs_speed_rate; + } - if(time < player.buff_disability_time) + if (time < player.buff_disability_time) { M_ARGV(0, float) *= autocvar_g_buffs_disability_rate; + } } MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor) { entity player = M_ARGV(1, entity); - if(player.buffs & BUFF_SPEED.m_itemid) + if (player.buffs & BUFF_SPEED.m_itemid) { M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed; + } - if(time < player.buff_disability_time) + if (time < player.buff_disability_time) { M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed; + } } .bool buff_flight_crouchheld; @@ -787,24 +830,22 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) { entity player = M_ARGV(0, entity); - if(game_stopped || IS_DEAD(player) || frametime || !IS_PLAYER(player)) return; + if (game_stopped || IS_DEAD(player) || frametime || !IS_PLAYER(player)) { return; } - if(player.buffs & BUFF_FLIGHT.m_itemid) - { - if(!PHYS_INPUT_BUTTON_CROUCH(player)) + if (player.buffs & BUFF_FLIGHT.m_itemid) { + if (!PHYS_INPUT_BUTTON_CROUCH(player)) { player.buff_flight_crouchheld = false; - else if(!player.buff_flight_crouchheld) - { + } else if (!player.buff_flight_crouchheld) { player.buff_flight_crouchheld = true; player.gravity *= -1; } } - if(time < player.buff_disability_time) - if(time >= player.buff_disability_effect_time) - { - Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1); - player.buff_disability_effect_time = time + 0.5; + if (time < player.buff_disability_time) { + if (time >= player.buff_disability_effect_time) { + Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1); + player.buff_disability_effect_time = time + 0.5; + } } // handle buff lost status @@ -812,75 +853,70 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) // 2: notify carrier as well int buff_lost = 0; - if(player.buff_time && player.buffs) - if(time >= player.buff_time) - { - player.buff_time = 0; - buff_lost = 2; + if (player.buff_time && player.buffs) { + if (time >= player.buff_time) { + player.buff_time = 0; + buff_lost = 2; + } } - if(STAT(FROZEN, player)) { buff_lost = 1; } + if (STAT(FROZEN, player)) { buff_lost = 1; } - if(buff_lost) - { - if(player.buffs) - { + if (buff_lost) { + if (player.buffs) { int buffid = buff_FirstFromFlags(player.buffs).m_id; - if(buff_lost == 2) - { + if (buff_lost == 2) { Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message? sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM); - } - else + } else { Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid); + } player.buffs = 0; PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small } } - if(player.buffs & BUFF_MAGNET.m_itemid) - { + if (player.buffs & BUFF_MAGNET.m_itemid) { vector pickup_size; IL_EACH(g_items, it.itemdef, { - if(it.buffs) + if (it.buffs) { pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff; - else + } else { pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item; + } - if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax)) - { - if(gettouch(it)) + if (boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax)) { + if (gettouch(it)) { gettouch(it)(it, player); + } } }); } - if(player.buffs & BUFF_AMMO.m_itemid) - { - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + if (player.buffs & BUFF_AMMO.m_itemid) { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - if(player.(weaponentity).clip_size) + if (player.(weaponentity).clip_size) { player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size; + } } } - if((player.buffs & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid)) + if ((player.buffs & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid)) { player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO) - - if(player.buffs & BUFF_MEDIC.m_itemid) - if(time >= player.buff_medic_healtime) - { - buff_Medic_Heal(player); - player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay; + } + if (player.buffs & BUFF_MEDIC.m_itemid) { + if (time >= player.buff_medic_healtime) { + buff_Medic_Heal(player); + player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay; + } } -#define BUFF_ONADD(b) if ( (player.buffs & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid)) +#define BUFF_ONADD(b) if ((player.buffs & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid)) #define BUFF_ONREM(b) if (!(player.buffs & (b).m_itemid) && (player.oldbuffs & (b).m_itemid)) - if(player.buffs != player.oldbuffs) - { + if (player.buffs != player.oldbuffs) { entity buff = buff_FirstFromFlags(player.buffs); float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0; player.buff_time = (bufftime) ? time + bufftime : 0; @@ -890,88 +926,89 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_WEAPON_AMMO); player.items |= IT_UNLIMITED_WEAPON_AMMO; - if(player.buffs & BUFF_AMMO.m_itemid) - { - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + if (player.buffs & BUFF_AMMO.m_itemid) { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - if(player.(weaponentity).clip_load) + if (player.(weaponentity).clip_load) { player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load; - if(player.(weaponentity).clip_size) + } + if (player.(weaponentity).clip_size) { player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size; + } } } } BUFF_ONREM(BUFF_AMMO) { - if(player.buff_ammo_prev_infitems) + if (player.buff_ammo_prev_infitems) { player.items |= IT_UNLIMITED_WEAPON_AMMO; - else + } else { player.items &= ~IT_UNLIMITED_WEAPON_AMMO; + } - if(player.buffs & BUFF_AMMO.m_itemid) - { - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + if (player.buffs & BUFF_AMMO.m_itemid) { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - if(player.(weaponentity).buff_ammo_prev_clipload) + if (player.(weaponentity).buff_ammo_prev_clipload) { player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload; + } } } } BUFF_ONADD(BUFF_INVISIBLE) { - if(time < player.strength_finished && g_instagib) + if (time < player.strength_finished && g_instagib) { player.buff_invisible_prev_alpha = default_player_alpha; // we don't want to save the powerup's alpha, as player may lose the powerup while holding the buff - else + } else { player.buff_invisible_prev_alpha = player.alpha; + } player.alpha = autocvar_g_buffs_invisible_alpha; } BUFF_ONREM(BUFF_INVISIBLE) { - if(time < player.strength_finished && g_instagib) + if (time < player.strength_finished && g_instagib) { player.alpha = autocvar_g_instagib_invis_alpha; - else + } else { player.alpha = player.buff_invisible_prev_alpha; + } } BUFF_ONADD(BUFF_FLIGHT) { player.buff_flight_oldgravity = player.gravity; - if(!player.gravity) + if (!player.gravity) { player.gravity = 1; + } } BUFF_ONREM(BUFF_FLIGHT) - player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity); + player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity); player.oldbuffs = player.buffs; - if(player.buffs) - { - if(!player.buff_model) + if (player.buffs) { + if (!player.buff_model) { buffs_BuffModel_Spawn(player); + } player.buff_model.color = buff.m_color; player.buff_model.glowmod = buff_GlowColor(player.buff_model); player.buff_model.skin = buff.m_skin; player.effects |= EF_NOSHADOW; - } - else - { - if(player.buff_model) + } else { + if (player.buff_model) { delete(player.buff_model); + } player.buff_model = NULL; player.effects &= ~(EF_NOSHADOW); } } - if(player.buff_model) - { + if (player.buff_model) { player.buff_model.effects = player.effects; player.buff_model.effects |= EF_LOWPRECISION; player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance @@ -996,43 +1033,44 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerRegen) { entity player = M_ARGV(0, entity); - if(player.buffs & BUFF_MEDIC.m_itemid) - { - M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod + if (player.buffs & BUFF_MEDIC.m_itemid) { + M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod - M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod + M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod } - if(player.buffs & BUFF_SPEED.m_itemid) + if (player.buffs & BUFF_SPEED.m_itemid) { M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod + } } REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace"); MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString) { - if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled + if (autocvar_g_buffs > 0) { // only report as a mutator if they're enabled M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs"); + } } MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString) { - if(autocvar_g_buffs > 0) + if (autocvar_g_buffs > 0) { M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs"); + } } void buffs_DelayedInit(entity this) { - if(autocvar_g_buffs_spawn_count > 0) - if(find(NULL, classname, "item_buff") == NULL) - { - float i; - for(i = 0; i < autocvar_g_buffs_spawn_count; ++i) - { - entity e = spawn(); - e.spawnflags |= 64; // always randomize - e.velocity = randomvec() * 250; // this gets reset anyway if random location works - buff_Init(e); + if (autocvar_g_buffs_spawn_count > 0) { + if (find(NULL, classname, "item_buff") == NULL) { + float i; + for (i = 0; i < autocvar_g_buffs_spawn_count; ++i) { + entity e = spawn(); + e.spawnflags |= 64; // always randomize + e.velocity = randomvec() * 250; // this gets reset anyway if random location works + buff_Init(e); + } } } } diff --git a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qh b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qh index 4d9f107af..d5b863045 100644 --- a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qh +++ b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qh @@ -72,7 +72,7 @@ float autocvar_g_buffs_luck_damagemultiplier = 3; .float buff_activetime; .float buff_activetime_updated; .entity buff_waypoint; -.int oldbuffs; // for updating effects +.int oldbuffs; // for updating effects .float buff_shield; // delay for players to keep them from spamming buff pickups .entity buff_model; // controls effects (TODO: make csqc) diff --git a/qcsrc/common/mutators/mutator/bugrigs/bugrigs.qc b/qcsrc/common/mutators/mutator/bugrigs/bugrigs.qc index 83d8be101..0b076ed82 100644 --- a/qcsrc/common/mutators/mutator/bugrigs/bugrigs.qc +++ b/qcsrc/common/mutators/mutator/bugrigs/bugrigs.qc @@ -24,21 +24,21 @@ REGISTER_MUTATOR(bugrigs, true); #endif -#define PHYS_BUGRIGS(s) STAT(BUGRIGS, s) -#define PHYS_BUGRIGS_ACCEL(s) STAT(BUGRIGS_ACCEL, s) -#define PHYS_BUGRIGS_AIR_STEERING(s) STAT(BUGRIGS_AIR_STEERING, s) -#define PHYS_BUGRIGS_ANGLE_SMOOTHING(s) STAT(BUGRIGS_ANGLE_SMOOTHING, s) -#define PHYS_BUGRIGS_CAR_JUMPING(s) STAT(BUGRIGS_CAR_JUMPING, s) -#define PHYS_BUGRIGS_FRICTION_AIR(s) STAT(BUGRIGS_FRICTION_AIR, s) -#define PHYS_BUGRIGS_FRICTION_BRAKE(s) STAT(BUGRIGS_FRICTION_BRAKE, s) -#define PHYS_BUGRIGS_FRICTION_FLOOR(s) STAT(BUGRIGS_FRICTION_FLOOR, s) -#define PHYS_BUGRIGS_PLANAR_MOVEMENT(s) STAT(BUGRIGS_PLANAR_MOVEMENT, s) -#define PHYS_BUGRIGS_REVERSE_SPEEDING(s) STAT(BUGRIGS_REVERSE_SPEEDING, s) -#define PHYS_BUGRIGS_REVERSE_SPINNING(s) STAT(BUGRIGS_REVERSE_SPINNING, s) -#define PHYS_BUGRIGS_REVERSE_STOPPING(s) STAT(BUGRIGS_REVERSE_STOPPING, s) -#define PHYS_BUGRIGS_SPEED_POW(s) STAT(BUGRIGS_SPEED_POW, s) -#define PHYS_BUGRIGS_SPEED_REF(s) STAT(BUGRIGS_SPEED_REF, s) -#define PHYS_BUGRIGS_STEER(s) STAT(BUGRIGS_STEER, s) +#define PHYS_BUGRIGS(s) STAT(BUGRIGS, s) +#define PHYS_BUGRIGS_ACCEL(s) STAT(BUGRIGS_ACCEL, s) +#define PHYS_BUGRIGS_AIR_STEERING(s) STAT(BUGRIGS_AIR_STEERING, s) +#define PHYS_BUGRIGS_ANGLE_SMOOTHING(s) STAT(BUGRIGS_ANGLE_SMOOTHING, s) +#define PHYS_BUGRIGS_CAR_JUMPING(s) STAT(BUGRIGS_CAR_JUMPING, s) +#define PHYS_BUGRIGS_FRICTION_AIR(s) STAT(BUGRIGS_FRICTION_AIR, s) +#define PHYS_BUGRIGS_FRICTION_BRAKE(s) STAT(BUGRIGS_FRICTION_BRAKE, s) +#define PHYS_BUGRIGS_FRICTION_FLOOR(s) STAT(BUGRIGS_FRICTION_FLOOR, s) +#define PHYS_BUGRIGS_PLANAR_MOVEMENT(s) STAT(BUGRIGS_PLANAR_MOVEMENT, s) +#define PHYS_BUGRIGS_REVERSE_SPEEDING(s) STAT(BUGRIGS_REVERSE_SPEEDING, s) +#define PHYS_BUGRIGS_REVERSE_SPINNING(s) STAT(BUGRIGS_REVERSE_SPINNING, s) +#define PHYS_BUGRIGS_REVERSE_STOPPING(s) STAT(BUGRIGS_REVERSE_STOPPING, s) +#define PHYS_BUGRIGS_SPEED_POW(s) STAT(BUGRIGS_SPEED_POW, s) +#define PHYS_BUGRIGS_SPEED_REF(s) STAT(BUGRIGS_SPEED_REF, s) +#define PHYS_BUGRIGS_STEER(s) STAT(BUGRIGS_STEER, s) #if defined(SVQC) @@ -65,8 +65,7 @@ void bugrigs_SetVars() float racecar_angle(float forward, float down) { - if (forward < 0) - { + if (forward < 0) { forward = -forward; down = -down; } @@ -75,10 +74,11 @@ float racecar_angle(float forward, float down) float angle_mult = forward / (800 + forward); - if (ret > 180) + if (ret > 180) { return ret * angle_mult + 360 * (1 - angle_mult); - else + } else { return ret * angle_mult; + } } void RaceCarPhysics(entity this, float dt) @@ -92,16 +92,15 @@ void RaceCarPhysics(entity this, float dt) float accel = bound(-1, PHYS_CS(this).movement.x / PHYS_MAXSPEED(this), 1); float steer = bound(-1, PHYS_CS(this).movement.y / PHYS_MAXSPEED(this), 1); - if (PHYS_BUGRIGS_REVERSE_SPEEDING(this)) - { - if (accel < 0) - { + if (PHYS_BUGRIGS_REVERSE_SPEEDING(this)) { + if (accel < 0) { // back accel is DIGITAL // to prevent speedhack - if (accel < -0.5) + if (accel < -0.5) { accel = -1; - else + } else { accel = 0; + } } } @@ -109,66 +108,58 @@ void RaceCarPhysics(entity this, float dt) this.angles_z = 0; makevectors(this.angles); // new forward direction! - if (IS_ONGROUND(this) || PHYS_BUGRIGS_AIR_STEERING(this)) - { + if (IS_ONGROUND(this) || PHYS_BUGRIGS_AIR_STEERING(this)) { float myspeed = this.velocity * v_forward; float upspeed = this.velocity * v_up; // responsiveness factor for steering and acceleration float f = 1 / (1 + POW((max(-myspeed, myspeed) / PHYS_BUGRIGS_SPEED_REF(this)), PHYS_BUGRIGS_SPEED_POW(this))); - //MAXIMA: f(v) := 1 / (1 + (v / PHYS_BUGRIGS_SPEED_REF(this)) ^ PHYS_BUGRIGS_SPEED_POW(this)); + // MAXIMA: f(v) := 1 / (1 + (v / PHYS_BUGRIGS_SPEED_REF(this)) ^ PHYS_BUGRIGS_SPEED_POW(this)); float steerfactor; - if (myspeed < 0 && PHYS_BUGRIGS_REVERSE_SPINNING(this)) + if (myspeed < 0 && PHYS_BUGRIGS_REVERSE_SPINNING(this)) { steerfactor = -myspeed * PHYS_BUGRIGS_STEER(this); - else + } else { steerfactor = -myspeed * f * PHYS_BUGRIGS_STEER(this); + } float accelfactor; - if (myspeed < 0 && PHYS_BUGRIGS_REVERSE_SPEEDING(this)) + if (myspeed < 0 && PHYS_BUGRIGS_REVERSE_SPEEDING(this)) { accelfactor = PHYS_BUGRIGS_ACCEL(this); - else + } else { accelfactor = f * PHYS_BUGRIGS_ACCEL(this); - //MAXIMA: accel(v) := f(v) * PHYS_BUGRIGS_ACCEL(this); + } + // MAXIMA: accel(v) := f(v) * PHYS_BUGRIGS_ACCEL(this); - if (accel < 0) - { - if (myspeed > 0) - { + if (accel < 0) { + if (myspeed > 0) { myspeed = max(0, myspeed - dt * (PHYS_BUGRIGS_FRICTION_FLOOR(this) - PHYS_BUGRIGS_FRICTION_BRAKE(this) * accel)); - } - else - { - if (!PHYS_BUGRIGS_REVERSE_SPEEDING(this)) + } else { + if (!PHYS_BUGRIGS_REVERSE_SPEEDING(this)) { myspeed = min(0, myspeed + dt * PHYS_BUGRIGS_FRICTION_FLOOR(this)); + } } - } - else - { - if (myspeed >= 0) - { + } else { + if (myspeed >= 0) { myspeed = max(0, myspeed - dt * PHYS_BUGRIGS_FRICTION_FLOOR(this)); - } - else - { - if (PHYS_BUGRIGS_REVERSE_STOPPING(this)) + } else { + if (PHYS_BUGRIGS_REVERSE_STOPPING(this)) { myspeed = 0; - else + } else { myspeed = min(0, myspeed + dt * (PHYS_BUGRIGS_FRICTION_FLOOR(this) + PHYS_BUGRIGS_FRICTION_BRAKE(this) * accel)); + } } } // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec - //MAXIMA: friction(v) := PHYS_BUGRIGS_FRICTION_FLOOR(this); + // MAXIMA: friction(v) := PHYS_BUGRIGS_FRICTION_FLOOR(this); this.angles_y += steer * dt * steerfactor; // apply steering - makevectors(this.angles); // new forward direction! + makevectors(this.angles); // new forward direction! myspeed += accel * accelfactor * dt; rigvel = myspeed * v_forward + '0 0 1' * upspeed; - } - else - { + } else { float myspeed = vlen(this.velocity); // responsiveness factor for steering and acceleration @@ -177,26 +168,26 @@ void RaceCarPhysics(entity this, float dt) this.angles_y += steer * dt * steerfactor; // apply steering rigvel = this.velocity; - makevectors(this.angles); // new forward direction! + makevectors(this.angles); // new forward direction! } rigvel *= max(0, 1 - vlen(rigvel) * PHYS_BUGRIGS_FRICTION_AIR(this) * dt); - //MAXIMA: airfriction(v) := v * v * PHYS_BUGRIGS_FRICTION_AIR(this); - //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v); - //MAXIMA: solve(total_acceleration(v) = 0, v); + // MAXIMA: airfriction(v) := v * v * PHYS_BUGRIGS_FRICTION_AIR(this); + // MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v); + // MAXIMA: solve(total_acceleration(v) = 0, v); - if (PHYS_BUGRIGS_PLANAR_MOVEMENT(this)) - { + if (PHYS_BUGRIGS_PLANAR_MOVEMENT(this)) { vector rigvel_xy, neworigin, up; float mt; rigvel_z -= dt * PHYS_GRAVITY(this); // 4x gravity plays better rigvel_xy = vec2(rigvel); - if (PHYS_BUGRIGS_CAR_JUMPING(this)) + if (PHYS_BUGRIGS_CAR_JUMPING(this)) { mt = MOVE_NORMAL; - else + } else { mt = MOVE_NOMONSTERS; + } tracebox(this.origin, this.mins, this.maxs, this.origin + '0 0 1024', mt, this); up = trace_endpos - this.origin; @@ -208,37 +199,31 @@ void RaceCarPhysics(entity this, float dt) // align to surface tracebox(trace_endpos, this.mins, this.maxs, trace_endpos - up + '0 0 1' * rigvel_z * dt, mt, this); - if (trace_fraction < 0.5) - { + if (trace_fraction < 0.5) { trace_fraction = 1; neworigin = this.origin; - } - else + } else { neworigin = trace_endpos; + } - if (trace_fraction < 1) - { + if (trace_fraction < 1) { // now set angles_x so that the car points parallel to the surface this.angles = vectoangles( - '1 0 0' * v_forward.x * trace_plane_normal.z - + - '0 1 0' * v_forward.y * trace_plane_normal.z - + - '0 0 1' * -(v_forward.x * trace_plane_normal.x + v_forward.y * trace_plane_normal.y) - ); + '1 0 0' * v_forward.x * trace_plane_normal.z + + + '0 1 0' * v_forward.y * trace_plane_normal.z + + + '0 0 1' * -(v_forward.x * trace_plane_normal.x + v_forward.y * trace_plane_normal.y) + ); SET_ONGROUND(this); - } - else - { + } else { // now set angles_x so that the car points forward, but is tilted in velocity direction UNSET_ONGROUND(this); } this.velocity = (neworigin - this.origin) * (1.0 / dt); set_movetype(this, MOVETYPE_NOCLIP); - } - else - { + } else { rigvel_z -= dt * PHYS_GRAVITY(this); // 4x gravity plays better this.velocity = rigvel; set_movetype(this, MOVETYPE_FLY); @@ -246,19 +231,16 @@ void RaceCarPhysics(entity this, float dt) trace_fraction = 1; tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 4', MOVE_NORMAL, this); - if (trace_fraction != 1) - { + if (trace_fraction != 1) { this.angles = vectoangles2( - '1 0 0' * v_forward.x * trace_plane_normal.z - + - '0 1 0' * v_forward.y * trace_plane_normal.z - + - '0 0 1' * -(v_forward.x * trace_plane_normal.x + v_forward.y * trace_plane_normal.y), - trace_plane_normal - ); - } - else - { + '1 0 0' * v_forward.x * trace_plane_normal.z + + + '0 1 0' * v_forward.y * trace_plane_normal.z + + + '0 0 1' * -(v_forward.x * trace_plane_normal.x + v_forward.y * trace_plane_normal.y), + trace_plane_normal + ); + } else { vector vel_local; vel_local.x = v_forward * this.velocity; @@ -273,8 +255,9 @@ void RaceCarPhysics(entity this, float dt) vector vf1, vu1, smoothangles; makevectors(this.angles); float f = bound(0, dt * PHYS_BUGRIGS_ANGLE_SMOOTHING(this), 1); - if (f == 0) + if (f == 0) { f = 1; + } vf1 = v_forward * f; vu1 = v_up * f; makevectors(angles_save); @@ -290,10 +273,10 @@ void RaceCarPhysics(entity this, float dt) #endif MUTATOR_HOOKFUNCTION(bugrigs, PM_Physics) { - entity player = M_ARGV(0, entity); - float dt = M_ARGV(2, float); + entity player = M_ARGV(0, entity); + float dt = M_ARGV(2, float); - if(!PHYS_BUGRIGS(player) || !IS_PLAYER(player)) { return; } + if (!PHYS_BUGRIGS(player) || !IS_PLAYER(player)) { return; } #ifdef SVQC player.angles = player.bugrigs_prevangles; @@ -305,7 +288,7 @@ MUTATOR_HOOKFUNCTION(bugrigs, PM_Physics) MUTATOR_HOOKFUNCTION(bugrigs, PlayerPhysics) { - if(!PHYS_BUGRIGS(M_ARGV(0, entity))) { return; } + if (!PHYS_BUGRIGS(M_ARGV(0, entity))) { return; } #ifdef SVQC entity player = M_ARGV(0, entity); player.bugrigs_prevangles = player.angles; @@ -316,7 +299,7 @@ MUTATOR_HOOKFUNCTION(bugrigs, PlayerPhysics) MUTATOR_HOOKFUNCTION(bugrigs, ClientConnect) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); stuffcmd(player, "cl_cmd settemp chase_active 1\n"); } diff --git a/qcsrc/common/mutators/mutator/campcheck/sv_campcheck.qc b/qcsrc/common/mutators/mutator/campcheck/sv_campcheck.qc index 987645aaa..4226f97e1 100644 --- a/qcsrc/common/mutators/mutator/campcheck/sv_campcheck.qc +++ b/qcsrc/common/mutators/mutator/campcheck/sv_campcheck.qc @@ -24,12 +24,13 @@ MUTATOR_HOOKFUNCTION(campcheck, Damage_Calculate) entity frag_attacker = M_ARGV(1, entity); entity frag_target = M_ARGV(2, entity); - if(IS_PLAYER(frag_target)) - if(IS_PLAYER(frag_attacker)) - if(frag_attacker != frag_target) - { - frag_target.campcheck_traveled_distance = autocvar_g_campcheck_distance; - frag_attacker.campcheck_traveled_distance = autocvar_g_campcheck_distance; + if (IS_PLAYER(frag_target)) { + if (IS_PLAYER(frag_attacker)) { + if (frag_attacker != frag_target) { + frag_target.campcheck_traveled_distance = autocvar_g_campcheck_distance; + frag_attacker.campcheck_traveled_distance = autocvar_g_campcheck_distance; + } + } } } @@ -38,45 +39,49 @@ MUTATOR_HOOKFUNCTION(campcheck, PlayerPreThink) entity player = M_ARGV(0, entity); bool checked = false; - if(autocvar_g_campcheck_interval) - if(!game_stopped && !warmup_stage && time >= game_starttime) - if(IS_PLAYER(player)) - if(!IS_DEAD(player)) - if(!STAT(FROZEN, player)) - if(!PHYS_INPUT_BUTTON_CHAT(player)) - if(IS_REAL_CLIENT(player)) // bots may camp, but that's no reason to constantly kill them - if(!forbidWeaponUse(player)) - { - // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement) - vector dist = vec2(player.campcheck_prevorigin - player.origin); - player.campcheck_traveled_distance += fabs(vlen(dist)); - - if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime) || (round_handler_IsActive() && !round_handler_IsRoundStarted())) - { - player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2; - player.campcheck_traveled_distance = 0; - } - - if(time > player.campcheck_nextcheck) - { - if(player.campcheck_traveled_distance < autocvar_g_campcheck_distance) - { - Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CAMPCHECK); - if(player.vehicle) - Damage(player.vehicle, NULL, NULL, autocvar_g_campcheck_damage * 2, DEATH_CAMP.m_id, player.vehicle.origin, '0 0 0'); - else - Damage(player, NULL, NULL, bound(0, autocvar_g_campcheck_damage, GetResourceAmount(player, RESOURCE_HEALTH) + GetResourceAmount(player, RESOURCE_ARMOR) * autocvar_g_balance_armor_blockpercent + 5), DEATH_CAMP.m_id, player.origin, '0 0 0'); + if (autocvar_g_campcheck_interval) { + if (!game_stopped && !warmup_stage && time >= game_starttime) { + if (IS_PLAYER(player)) { + if (!IS_DEAD(player)) { + if (!STAT(FROZEN, player)) { + if (!PHYS_INPUT_BUTTON_CHAT(player)) { + if (IS_REAL_CLIENT(player)) { // bots may camp, but that's no reason to constantly kill them + if (!forbidWeaponUse(player)) { + // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement) + vector dist = vec2(player.campcheck_prevorigin - player.origin); + player.campcheck_traveled_distance += fabs(vlen(dist)); + + if ((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime) || (round_handler_IsActive() && !round_handler_IsRoundStarted())) { + player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2; + player.campcheck_traveled_distance = 0; + } + + if (time > player.campcheck_nextcheck) { + if (player.campcheck_traveled_distance < autocvar_g_campcheck_distance) { + Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CAMPCHECK); + if (player.vehicle) { + Damage(player.vehicle, NULL, NULL, autocvar_g_campcheck_damage * 2, DEATH_CAMP.m_id, player.vehicle.origin, '0 0 0'); + } else { + Damage(player, NULL, NULL, bound(0, autocvar_g_campcheck_damage, GetResourceAmount(player, RESOURCE_HEALTH) + GetResourceAmount(player, RESOURCE_ARMOR) * autocvar_g_balance_armor_blockpercent + 5), DEATH_CAMP.m_id, player.origin, '0 0 0'); + } + } + player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; + player.campcheck_traveled_distance = 0; + } + + checked = true; + } + } + } + } + } } - player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; - player.campcheck_traveled_distance = 0; } - - checked = true; } - if(!checked) + if (!checked) { player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; // one of the above checks failed, so keep the timer up to date - + } player.campcheck_prevorigin = player.origin; } diff --git a/qcsrc/common/mutators/mutator/cloaked/sv_cloaked.qc b/qcsrc/common/mutators/mutator/cloaked/sv_cloaked.qc index a1fe27a87..fdac00a64 100644 --- a/qcsrc/common/mutators/mutator/cloaked/sv_cloaked.qc +++ b/qcsrc/common/mutators/mutator/cloaked/sv_cloaked.qc @@ -7,12 +7,12 @@ float autocvar_g_balance_cloaked_alpha; MUTATOR_HOOKFUNCTION(cloaked, SetDefaultAlpha) { - default_player_alpha = autocvar_g_balance_cloaked_alpha; - default_weapon_alpha = default_player_alpha; - return true; + default_player_alpha = autocvar_g_balance_cloaked_alpha; + default_weapon_alpha = default_player_alpha; + return true; } MUTATOR_HOOKFUNCTION(cloaked, BuildMutatorsPrettyString) { - if (!g_cts) M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Cloaked"); + if (!g_cts) { M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Cloaked"); } } diff --git a/qcsrc/common/mutators/mutator/damagetext/sv_damagetext.qc b/qcsrc/common/mutators/mutator/damagetext/sv_damagetext.qc index 4a18cc930..62e44bdc7 100644 --- a/qcsrc/common/mutators/mutator/damagetext/sv_damagetext.qc +++ b/qcsrc/common/mutators/mutator/damagetext/sv_damagetext.qc @@ -4,54 +4,51 @@ AUTOCVAR(sv_damagetext, int, 2, "<= 0: disabled, >= 1: visible to spectators, >= REGISTER_MUTATOR(damagetext, true); -#define SV_DAMAGETEXT_DISABLED() (autocvar_sv_damagetext <= 0 || autocvar_g_instagib) +#define SV_DAMAGETEXT_DISABLED() (autocvar_sv_damagetext <= 0 || autocvar_g_instagib) #define SV_DAMAGETEXT_SPECTATORS_ONLY() (autocvar_sv_damagetext >= 1) -#define SV_DAMAGETEXT_PLAYERS() (autocvar_sv_damagetext >= 2) -#define SV_DAMAGETEXT_ALL() (autocvar_sv_damagetext >= 3) -MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) { - if (SV_DAMAGETEXT_DISABLED()) return; - const entity attacker = M_ARGV(0, entity); - const entity hit = M_ARGV(1, entity); if (hit == attacker) return; - const float health = M_ARGV(2, float); - const float armor = M_ARGV(3, float); - const int deathtype = M_ARGV(5, int); - const float potential_damage = M_ARGV(6, float); - FOREACH_CLIENT(IS_REAL_CLIENT(it), { - if ( - (SV_DAMAGETEXT_ALL()) || - (SV_DAMAGETEXT_PLAYERS() && it == attacker) || - (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(it) && it.enemy == attacker) || - (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_OBSERVER(it)) - ) { - int flags = 0; - if (SAME_TEAM(hit, attacker)) flags |= DTFLAG_SAMETEAM; - if (health >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_HEALTH; - if (armor >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_ARMOR; - if (potential_damage >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_POTENTIAL; - if (!armor) flags |= DTFLAG_NO_ARMOR; - if (almost_equals_eps(armor + health, potential_damage, 5)) flags |= DTFLAG_NO_POTENTIAL; +#define SV_DAMAGETEXT_PLAYERS() (autocvar_sv_damagetext >= 2) +#define SV_DAMAGETEXT_ALL() (autocvar_sv_damagetext >= 3) +MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) +{ + if (SV_DAMAGETEXT_DISABLED()) { return; } + const entity attacker = M_ARGV(0, entity); + const entity hit = M_ARGV(1, entity); + if (hit == attacker) { return; } + const float health = M_ARGV(2, float); + const float armor = M_ARGV(3, float); + const int deathtype = M_ARGV(5, int); + const float potential_damage = M_ARGV(6, float); + FOREACH_CLIENT(IS_REAL_CLIENT(it), { + if ( + (SV_DAMAGETEXT_ALL()) + || (SV_DAMAGETEXT_PLAYERS() && it == attacker) + || (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(it) && it.enemy == attacker) + || (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_OBSERVER(it)) + ) { + int flags = 0; + if (SAME_TEAM(hit, attacker)) { flags |= DTFLAG_SAMETEAM; } + if (health >= DAMAGETEXT_SHORT_LIMIT) { flags |= DTFLAG_BIG_HEALTH; } + if (armor >= DAMAGETEXT_SHORT_LIMIT) { flags |= DTFLAG_BIG_ARMOR; } + if (potential_damage >= DAMAGETEXT_SHORT_LIMIT) { flags |= DTFLAG_BIG_POTENTIAL; } + if (!armor) { flags |= DTFLAG_NO_ARMOR; } + if (almost_equals_eps(armor + health, potential_damage, 5)) { flags |= DTFLAG_NO_POTENTIAL; } - msg_entity = it; - WriteHeader(MSG_ONE, damagetext); - WriteByte(MSG_ONE, etof(hit)); - WriteInt24_t(MSG_ONE, deathtype); - WriteByte(MSG_ONE, flags); + msg_entity = it; + WriteHeader(MSG_ONE, damagetext); + WriteByte(MSG_ONE, etof(hit)); + WriteInt24_t(MSG_ONE, deathtype); + WriteByte(MSG_ONE, flags); - // we need to send a few decimal places to minimize errors when accumulating damage - // sending them multiplied saves bandwidth compared to using WriteCoord, - // however if the multiplied damage would be too much for (signed) short, we send an int24 - if (flags & DTFLAG_BIG_HEALTH) WriteInt24_t(MSG_ONE, health * DAMAGETEXT_PRECISION_MULTIPLIER); - else WriteShort(MSG_ONE, health * DAMAGETEXT_PRECISION_MULTIPLIER); - if (!(flags & DTFLAG_NO_ARMOR)) - { - if (flags & DTFLAG_BIG_ARMOR) WriteInt24_t(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER); - else WriteShort(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER); - } - if (!(flags & DTFLAG_NO_POTENTIAL)) - { - if (flags & DTFLAG_BIG_POTENTIAL) WriteInt24_t(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER); - else WriteShort(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER); + // we need to send a few decimal places to minimize errors when accumulating damage + // sending them multiplied saves bandwidth compared to using WriteCoord, + // however if the multiplied damage would be too much for (signed) short, we send an int24 + if (flags & DTFLAG_BIG_HEALTH) { WriteInt24_t(MSG_ONE, health * DAMAGETEXT_PRECISION_MULTIPLIER); } else { WriteShort(MSG_ONE, health * DAMAGETEXT_PRECISION_MULTIPLIER); } + if (!(flags & DTFLAG_NO_ARMOR)) { + if (flags & DTFLAG_BIG_ARMOR) { WriteInt24_t(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER); } else { WriteShort(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER); } } - } - }); + if (!(flags & DTFLAG_NO_POTENTIAL)) { + if (flags & DTFLAG_BIG_POTENTIAL) { WriteInt24_t(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER); } else { WriteShort(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER); } + } + } + }); } diff --git a/qcsrc/common/mutators/mutator/damagetext/ui_damagetext.qc b/qcsrc/common/mutators/mutator/damagetext/ui_damagetext.qc index 78834ce63..7b7ae8095 100644 --- a/qcsrc/common/mutators/mutator/damagetext/ui_damagetext.qc +++ b/qcsrc/common/mutators/mutator/damagetext/ui_damagetext.qc @@ -4,53 +4,60 @@ #include CLASS(XonoticDamageTextSettings, XonoticTab) - REGISTER_SETTINGS(damagetext, NEW(XonoticDamageTextSettings)); - ATTRIB(XonoticDamageTextSettings, title, string, _("Damage text")); - ATTRIB(XonoticDamageTextSettings, intendedWidth, float, 0.9); - ATTRIB(XonoticDamageTextSettings, rows, float, 15.5); - ATTRIB(XonoticDamageTextSettings, columns, float, 5); - INIT(XonoticDamageTextSettings) { this.configureDialog(this); } - METHOD(XonoticDamageTextSettings, showNotify, void(entity this)) { loadAllCvars(this); } - METHOD(XonoticDamageTextSettings, fill, void(entity this)) - { - entity e; - this.gotoRC(this, 0, 1); this.setFirstColumn(this, this.currentColumn); - this.TD(this, 1, 3, makeXonoticCheckBox(0, "cl_damagetext", _("Draw damage numbers"))); - this.TR(this); - this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Font size minimum:"))); - setDependent(e, "cl_damagetext", 1, 1); - this.TD(this, 1, 2, e = makeXonoticSlider(0, 50, 1, "cl_damagetext_size_min")); - setDependent(e, "cl_damagetext", 1, 1); - this.TR(this); - this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Font size maximum:"))); - setDependent(e, "cl_damagetext", 1, 1); - this.TD(this, 1, 2, e = makeXonoticSlider(0, 50, 1, "cl_damagetext_size_max")); - setDependent(e, "cl_damagetext", 1, 1); - this.TR(this); - this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Accumulate range:"))); - setDependent(e, "cl_damagetext", 1, 1); - this.TD(this, 1, 2, e = makeXonoticSlider(0, 500, 1, "cl_damagetext_accumulate_range")); - setDependent(e, "cl_damagetext", 1, 1); - this.TR(this); - this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Lifetime:"))); - setDependent(e, "cl_damagetext", 1, 1); - this.TD(this, 1, 2, e = makeXonoticSlider(0, 10, 1, "cl_damagetext_alpha_lifetime")); - setDependent(e, "cl_damagetext", 1, 1); - this.TR(this); - this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color:"))); - setDependent(e, "cl_damagetext", 1, 1); - this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_color", "cl_damagetext_color")); - setDependent(e, "cl_damagetext", 1, 1); - this.TR(this); - this.TR(this); - // friendly fire - this.TD(this, 1, 3, e = makeXonoticCheckBox(0, "cl_damagetext_friendlyfire", _("Draw damage numbers for friendly fire"))); - setDependent(e, "cl_damagetext", 1, 1); - this.TR(this); - this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color:"))); - setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1); - this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_friendlyfire_color", "cl_damagetext_friendlyfire_color")); - setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1); - this.TR(this); - } + REGISTER_SETTINGS(damagetext, NEW(XonoticDamageTextSettings)); + ATTRIB(XonoticDamageTextSettings, title, string, _("Damage text")); + ATTRIB(XonoticDamageTextSettings, intendedWidth, float, 0.9); + ATTRIB(XonoticDamageTextSettings, rows, float, 15.5); + ATTRIB(XonoticDamageTextSettings, columns, float, 5); + INIT(XonoticDamageTextSettings) + { + this.configureDialog(this); + } + METHOD(XonoticDamageTextSettings, showNotify, void(entity this)) + { + loadAllCvars(this); + } + METHOD(XonoticDamageTextSettings, fill, void(entity this)) + { + entity e; + this.gotoRC(this, 0, 1); + this.setFirstColumn(this, this.currentColumn); + this.TD(this, 1, 3, makeXonoticCheckBox(0, "cl_damagetext", _("Draw damage numbers"))); + this.TR(this); + this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Font size minimum:"))); + setDependent(e, "cl_damagetext", 1, 1); + this.TD(this, 1, 2, e = makeXonoticSlider(0, 50, 1, "cl_damagetext_size_min")); + setDependent(e, "cl_damagetext", 1, 1); + this.TR(this); + this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Font size maximum:"))); + setDependent(e, "cl_damagetext", 1, 1); + this.TD(this, 1, 2, e = makeXonoticSlider(0, 50, 1, "cl_damagetext_size_max")); + setDependent(e, "cl_damagetext", 1, 1); + this.TR(this); + this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Accumulate range:"))); + setDependent(e, "cl_damagetext", 1, 1); + this.TD(this, 1, 2, e = makeXonoticSlider(0, 500, 1, "cl_damagetext_accumulate_range")); + setDependent(e, "cl_damagetext", 1, 1); + this.TR(this); + this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Lifetime:"))); + setDependent(e, "cl_damagetext", 1, 1); + this.TD(this, 1, 2, e = makeXonoticSlider(0, 10, 1, "cl_damagetext_alpha_lifetime")); + setDependent(e, "cl_damagetext", 1, 1); + this.TR(this); + this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color:"))); + setDependent(e, "cl_damagetext", 1, 1); + this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_color", "cl_damagetext_color")); + setDependent(e, "cl_damagetext", 1, 1); + this.TR(this); + this.TR(this); + // friendly fire + this.TD(this, 1, 3, e = makeXonoticCheckBox(0, "cl_damagetext_friendlyfire", _("Draw damage numbers for friendly fire"))); + setDependent(e, "cl_damagetext", 1, 1); + this.TR(this); + this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color:"))); + setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1); + this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_friendlyfire_color", "cl_damagetext_friendlyfire_color")); + setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1); + this.TR(this); + } ENDCLASS(XonoticDamageTextSettings) diff --git a/qcsrc/common/mutators/mutator/doublejump/doublejump.qc b/qcsrc/common/mutators/mutator/doublejump/doublejump.qc index cc60ccc1f..c81fd3e83 100644 --- a/qcsrc/common/mutators/mutator/doublejump/doublejump.qc +++ b/qcsrc/common/mutators/mutator/doublejump/doublejump.qc @@ -12,24 +12,23 @@ REGISTER_MUTATOR(doublejump, autocvar_sv_doublejump); REGISTER_MUTATOR(doublejump, true); #endif -#define PHYS_DOUBLEJUMP(s) STAT(DOUBLEJUMP, s) +#define PHYS_DOUBLEJUMP(s) STAT(DOUBLEJUMP, s) MUTATOR_HOOKFUNCTION(doublejump, PlayerJump) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); - if (PHYS_DOUBLEJUMP(player)) - { + if (PHYS_DOUBLEJUMP(player)) { tracebox(player.origin + '0 0 0.01', player.mins, player.maxs, player.origin - '0 0 0.01', MOVE_NORMAL, player); - if (trace_fraction < 1 && trace_plane_normal_z > 0.7) - { + if (trace_fraction < 1 && trace_plane_normal_z > 0.7) { M_ARGV(2, bool) = true; // we MUST clip velocity here! float f = player.velocity * trace_plane_normal; - if (f < 0) + if (f < 0) { player.velocity -= f * trace_plane_normal; + } } } } diff --git a/qcsrc/common/mutators/mutator/globalforces/_mod.qh b/qcsrc/common/mutators/mutator/globalforces/_mod.qh index c31ee5cfc..2d606899e 100644 --- a/qcsrc/common/mutators/mutator/globalforces/_mod.qh +++ b/qcsrc/common/mutators/mutator/globalforces/_mod.qh @@ -1,4 +1,4 @@ // generated file; do not modify #ifdef SVQC - #include + #include #endif diff --git a/qcsrc/common/mutators/mutator/globalforces/sv_globalforces.qc b/qcsrc/common/mutators/mutator/globalforces/sv_globalforces.qc index 3e9cd0d51..e35cb1b08 100644 --- a/qcsrc/common/mutators/mutator/globalforces/sv_globalforces.qc +++ b/qcsrc/common/mutators/mutator/globalforces/sv_globalforces.qc @@ -6,26 +6,29 @@ AUTOCVAR(g_globalforces_self, float, 1, "Global forces: knockback self scale"); AUTOCVAR(g_globalforces_range, float, 1000, "Global forces: max range of effect"); REGISTER_MUTATOR(mutator_globalforces, autocvar_g_globalforces); -MUTATOR_HOOKFUNCTION(mutator_globalforces, BuildMutatorsString) { - M_ARGV(0, string) = strcat(M_ARGV(0, string), ":GlobalForces"); +MUTATOR_HOOKFUNCTION(mutator_globalforces, BuildMutatorsString) +{ + M_ARGV(0, string) = strcat(M_ARGV(0, string), ":GlobalForces"); } -MUTATOR_HOOKFUNCTION(mutator_globalforces, BuildMutatorsPrettyString) { - M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Global forces"); +MUTATOR_HOOKFUNCTION(mutator_globalforces, BuildMutatorsPrettyString) +{ + M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Global forces"); } -MUTATOR_HOOKFUNCTION(mutator_globalforces, PlayerDamage_SplitHealthArmor) { - entity frag_attacker = M_ARGV(1, entity); - entity frag_target = M_ARGV(2, entity); - if (autocvar_g_globalforces_noself && frag_target == frag_attacker) return; - vector damage_force = M_ARGV(3, vector) * autocvar_g_globalforces; - FOREACH_CLIENT(IS_PLAYER(it) && it != frag_target, { - if (autocvar_g_globalforces_range) { - if (vdist(it.origin - frag_target.origin, >, autocvar_g_globalforces_range)) { - continue; - } - } - float f = (it == frag_attacker) ? autocvar_g_globalforces_self : 1; - it.velocity += damage_explosion_calcpush(f * it.damageforcescale * damage_force, it.velocity, autocvar_g_balance_damagepush_speedfactor); - }); +MUTATOR_HOOKFUNCTION(mutator_globalforces, PlayerDamage_SplitHealthArmor) +{ + entity frag_attacker = M_ARGV(1, entity); + entity frag_target = M_ARGV(2, entity); + if (autocvar_g_globalforces_noself && frag_target == frag_attacker) { return; } + vector damage_force = M_ARGV(3, vector) * autocvar_g_globalforces; + FOREACH_CLIENT(IS_PLAYER(it) && it != frag_target, { + if (autocvar_g_globalforces_range) { + if (vdist(it.origin - frag_target.origin, >, autocvar_g_globalforces_range)) { + continue; + } + } + float f = (it == frag_attacker) ? autocvar_g_globalforces_self : 1; + it.velocity += damage_explosion_calcpush(f * it.damageforcescale * damage_force, it.velocity, autocvar_g_balance_damagepush_speedfactor); + }); } diff --git a/qcsrc/common/mutators/mutator/hook/sv_hook.qc b/qcsrc/common/mutators/mutator/hook/sv_hook.qc index c39678119..77e5f9b35 100644 --- a/qcsrc/common/mutators/mutator/hook/sv_hook.qc +++ b/qcsrc/common/mutators/mutator/hook/sv_hook.qc @@ -1,62 +1,64 @@ #include "sv_hook.qh" // can't use the autocvar as it doesn't work in the campaign -//AUTOCVAR(g_grappling_hook, bool, false, "let players spawn with the grappling hook which allows them to pull themselves up"); +// AUTOCVAR(g_grappling_hook, bool, false, "let players spawn with the grappling hook which allows them to pull themselves up"); #ifdef SVQC AUTOCVAR(g_grappling_hook_useammo, bool, false, "Use ammunition with the off-hand grappling hook"); -REGISTER_MUTATOR(hook, expr_evaluate(cvar_string("g_grappling_hook"))) { - MUTATOR_ONADD { - g_grappling_hook = true; - if(!autocvar_g_grappling_hook_useammo) - WEP_HOOK.ammo_factor = 0; - } - MUTATOR_ONROLLBACK_OR_REMOVE { - g_grappling_hook = false; - if(!autocvar_g_grappling_hook_useammo) - WEP_HOOK.ammo_factor = 1; // we don't need to change it - } - - return false; +REGISTER_MUTATOR(hook, expr_evaluate(cvar_string("g_grappling_hook"))) +{ + MUTATOR_ONADD { + g_grappling_hook = true; + if (!autocvar_g_grappling_hook_useammo) { + WEP_HOOK.ammo_factor = 0; + } + } + MUTATOR_ONROLLBACK_OR_REMOVE { + g_grappling_hook = false; + if (!autocvar_g_grappling_hook_useammo) { + WEP_HOOK.ammo_factor = 1; // we don't need to change it + } + } + + return false; } MUTATOR_HOOKFUNCTION(hook, BuildMutatorsString) { - M_ARGV(0, string) = strcat(M_ARGV(0, string), ":grappling_hook"); + M_ARGV(0, string) = strcat(M_ARGV(0, string), ":grappling_hook"); } MUTATOR_HOOKFUNCTION(hook, BuildMutatorsPrettyString) { - M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Hook"); + M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Hook"); } MUTATOR_HOOKFUNCTION(hook, BuildGameplayTipsString) { - M_ARGV(0, string) = strcat(M_ARGV(0, string), "\n\n^3grappling hook^8 is enabled, press 'e' to use it\n"); + M_ARGV(0, string) = strcat(M_ARGV(0, string), "\n\n^3grappling hook^8 is enabled, press 'e' to use it\n"); } MUTATOR_HOOKFUNCTION(hook, SetStartItems) { - if(autocvar_g_grappling_hook_useammo) - { - start_items |= ITEM_JetpackRegen.m_itemid; - start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable")); - warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable")); - } + if (autocvar_g_grappling_hook_useammo) { + start_items |= ITEM_JetpackRegen.m_itemid; + start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable")); + warmup_start_ammo_fuel = max(warmup_start_ammo_fuel, cvar("g_balance_fuel_rotstable")); + } } MUTATOR_HOOKFUNCTION(hook, PlayerSpawn) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); - player.offhand = OFFHAND_HOOK; + player.offhand = OFFHAND_HOOK; } MUTATOR_HOOKFUNCTION(hook, FilterItem) { - entity item = M_ARGV(0, entity); + entity item = M_ARGV(0, entity); - return item.weapon == WEP_HOOK.m_id; + return item.weapon == WEP_HOOK.m_id; } #endif diff --git a/qcsrc/common/mutators/mutator/instagib/items.qh b/qcsrc/common/mutators/mutator/instagib/items.qh index e80f36e1a..4fa46f211 100644 --- a/qcsrc/common/mutators/mutator/instagib/items.qh +++ b/qcsrc/common/mutators/mutator/instagib/items.qh @@ -18,24 +18,26 @@ SOUND(VaporizerCells, Item_Sound("itempickup")); int autocvar_g_instagib_ammo_drop; void ammo_vaporizercells_init(entity item) { - if(!item.ammo_cells) - item.ammo_cells = autocvar_g_instagib_ammo_drop; + if (!item.ammo_cells) { + item.ammo_cells = autocvar_g_instagib_ammo_drop; + } } #endif -REGISTER_ITEM(VaporizerCells, Ammo) { +REGISTER_ITEM(VaporizerCells, Ammo) +{ #ifdef GAMEQC - this.m_model = MDL_VaporizerCells_ITEM; - this.m_sound = SND_VaporizerCells; + this.m_model = MDL_VaporizerCells_ITEM; + this.m_sound = SND_VaporizerCells; #endif - this.netname = "minst_cells"; - this.m_name = "Vaporizer Ammo"; - this.m_icon = "ammo_supercells"; + this.netname = "minst_cells"; + this.m_name = "Vaporizer Ammo"; + this.m_icon = "ammo_supercells"; #ifdef SVQC - this.m_botvalue = 2000; - this.m_itemid = IT_CELLS; - this.m_respawntime = GET(instagib_respawntime_ammo); - this.m_respawntimejitter = GET(instagib_respawntimejitter_ammo); - this.m_iteminit = ammo_vaporizercells_init; + this.m_botvalue = 2000; + this.m_itemid = IT_CELLS; + this.m_respawntime = GET(instagib_respawntime_ammo); + this.m_respawntimejitter = GET(instagib_respawntimejitter_ammo); + this.m_iteminit = ammo_vaporizercells_init; #endif } @@ -44,18 +46,19 @@ MODEL(ExtraLife_ITEM, Item_Model("g_h100.md3")); SOUND(ExtraLife, Item_Sound("megahealth")); #endif -REGISTER_ITEM(ExtraLife, Powerup) { +REGISTER_ITEM(ExtraLife, Powerup) +{ #ifdef GAMEQC - this.m_model = MDL_ExtraLife_ITEM; - this.m_sound = SND_ExtraLife; + this.m_model = MDL_ExtraLife_ITEM; + this.m_sound = SND_ExtraLife; #endif - this.netname = "health_mega"; - this.m_name = "Extra life"; - this.m_icon = "item_mega_health"; - this.m_color = '1 0 0'; - this.m_waypoint = _("Extra life"); - this.m_waypointblink = 2; - this.m_itemid = IT_NAILS; + this.netname = "health_mega"; + this.m_name = "Extra life"; + this.m_icon = "item_mega_health"; + this.m_color = '1 0 0'; + this.m_waypoint = _("Extra life"); + this.m_waypointblink = 2; + this.m_itemid = IT_NAILS; } #ifdef GAMEQC @@ -63,18 +66,19 @@ MODEL(Invisibility_ITEM, Item_Model("g_strength.md3")); SOUND(Invisibility, Item_Sound("powerup")); #endif -REGISTER_ITEM(Invisibility, Powerup) { +REGISTER_ITEM(Invisibility, Powerup) +{ #ifdef GAMEQC - this.m_model = MDL_Invisibility_ITEM; - this.m_sound = SND_Invisibility; + this.m_model = MDL_Invisibility_ITEM; + this.m_sound = SND_Invisibility; #endif - this.netname = "strength"; - this.m_name = "Invisibility"; - this.m_icon = "strength"; - this.m_color = '0 0 1'; - this.m_waypoint = _("Invisibility"); - this.m_waypointblink = 2; - this.m_itemid = IT_STRENGTH; + this.netname = "strength"; + this.m_name = "Invisibility"; + this.m_icon = "strength"; + this.m_color = '0 0 1'; + this.m_waypoint = _("Invisibility"); + this.m_waypointblink = 2; + this.m_itemid = IT_STRENGTH; } #ifdef GAMEQC @@ -82,16 +86,17 @@ MODEL(Speed_ITEM, Item_Model("g_invincible.md3")); SOUND(Speed, Item_Sound("powerup_shield")); #endif -REGISTER_ITEM(Speed, Powerup) { +REGISTER_ITEM(Speed, Powerup) +{ #ifdef GAMEQC - this.m_model = MDL_Speed_ITEM; - this.m_sound = SND_Speed; + this.m_model = MDL_Speed_ITEM; + this.m_sound = SND_Speed; #endif - this.netname = "invincible"; - this.m_name = "Speed"; - this.m_icon = "shield"; - this.m_color = '1 0 1'; - this.m_waypoint = _("Speed"); - this.m_waypointblink = 2; - this.m_itemid = IT_INVINCIBLE; + this.netname = "invincible"; + this.m_name = "Speed"; + this.m_icon = "shield"; + this.m_color = '1 0 1'; + this.m_waypoint = _("Speed"); + this.m_waypointblink = 2; + this.m_itemid = IT_INVINCIBLE; } diff --git a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc index 1561dc10d..8b52589e2 100644 --- a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc +++ b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc @@ -5,7 +5,7 @@ bool autocvar_g_instagib_blaster_keepdamage = false; bool autocvar_g_instagib_blaster_keepforce = false; bool autocvar_g_instagib_mirrordamage; bool autocvar_g_instagib_friendlypush = true; -//int autocvar_g_instagib_ammo_drop; +// int autocvar_g_instagib_ammo_drop; bool autocvar_g_instagib_ammo_convert_cells; bool autocvar_g_instagib_ammo_convert_rockets; bool autocvar_g_instagib_ammo_convert_shells; @@ -46,87 +46,64 @@ void instagib_speed(entity this) .float instagib_needammo; void instagib_stop_countdown(entity e) { - if (!e.instagib_needammo) + if (!e.instagib_needammo) { return; + } Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO); e.instagib_needammo = false; } void instagib_ammocheck(entity this) { - if(time < this.instagib_nextthink) + if (time < this.instagib_nextthink) { return; - if(!IS_PLAYER(this)) + } + if (!IS_PLAYER(this)) { return; // not a player - - if(IS_DEAD(this) || game_stopped) + } + if (IS_DEAD(this) || game_stopped) { instagib_stop_countdown(this); - else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE)) + } else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE)) { instagib_stop_countdown(this); - else if(autocvar_g_rm && autocvar_g_rm_laser) - { - if(!this.instagib_needammo) - { + } else if (autocvar_g_rm && autocvar_g_rm_laser) { + if (!this.instagib_needammo) { Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE); this.instagib_needammo = true; } - } - else - { + } else { float hp = GetResourceAmount(this, RESOURCE_HEALTH); this.instagib_needammo = true; - if (hp <= 5) - { + if (hp <= 5) { Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED); - } - else if (hp <= 10) - { + } else if (hp <= 10) { Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1); - } - else if (hp <= 20) - { + } else if (hp <= 20) { Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2); - } - else if (hp <= 30) - { + } else if (hp <= 30) { Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3); - } - else if (hp <= 40) - { + } else if (hp <= 40) { Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4); - } - else if (hp <= 50) - { + } else if (hp <= 50) { Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5); - } - else if (hp <= 60) - { + } else if (hp <= 60) { Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6); - } - else if (hp <= 70) - { + } else if (hp <= 70) { Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7); - } - else if (hp <= 80) - { + } else if (hp <= 80) { Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8); - } - else if (hp <= 90) - { + } else if (hp <= 90) { Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO); Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9); - } - else - { + } else { Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO); Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0'); } @@ -136,7 +113,8 @@ void instagib_ammocheck(entity this) MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd) { - FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); }); + FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); + }); } MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem) @@ -151,16 +129,18 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn) entity mon = M_ARGV(0, entity); // always refill ammo - if(mon.monsterid == MON_MAGE.monsterid) + if (mon.monsterid == MON_MAGE.monsterid) { mon.skin = 1; + } } MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack) { entity targ = M_ARGV(1, entity); - if (targ.items & ITEM_Invisibility.m_itemid) + if (targ.items & ITEM_Invisibility.m_itemid) { return true; + } } MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver) @@ -194,24 +174,20 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups) { entity player = M_ARGV(0, entity); - if (!(player.effects & EF_FULLBRIGHT)) + if (!(player.effects & EF_FULLBRIGHT)) { player.effects |= EF_FULLBRIGHT; + } - if (player.items & ITEM_Invisibility.m_itemid) - { + if (player.items & ITEM_Invisibility.m_itemid) { play_countdown(player, player.strength_finished, SND_POWEROFF); - if (time > player.strength_finished) - { + if (time > player.strength_finished) { player.alpha = default_player_alpha; player.exteriorweaponentity.alpha = default_weapon_alpha; player.items &= ~ITEM_Invisibility.m_itemid; Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY); } - } - else - { - if (time < player.strength_finished) - { + } else { + if (time < player.strength_finished) { player.alpha = autocvar_g_instagib_invis_alpha; player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha; player.items |= ITEM_Invisibility.m_itemid; @@ -220,19 +196,14 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups) } } - if (player.items & ITEM_Speed.m_itemid) - { + if (player.items & ITEM_Speed.m_itemid) { play_countdown(player, player.invincible_finished, SND_POWEROFF); - if (time > player.invincible_finished) - { + if (time > player.invincible_finished) { player.items &= ~ITEM_Speed.m_itemid; Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED); } - } - else - { - if (time < player.invincible_finished) - { + } else { + if (time < player.invincible_finished) { player.items |= ITEM_Speed.m_itemid; Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname); Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED); @@ -246,14 +217,15 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics) { entity player = M_ARGV(0, entity); - if(player.items & ITEM_Speed.m_itemid) + if (player.items & ITEM_Speed.m_itemid) { player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed; + } } MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor) { M_ARGV(4, float) = M_ARGV(7, float); // take = damage - M_ARGV(5, float) = 0; // save + M_ARGV(5, float) = 0; // save } MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon) @@ -271,82 +243,82 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate) float frag_mirrordamage = M_ARGV(5, float); vector frag_force = M_ARGV(6, vector); - if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker)) + if (autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker)) { frag_damage = 0; + } - if(IS_PLAYER(frag_target)) - { - if(frag_deathtype == DEATH_FALL.m_id) + if (IS_PLAYER(frag_target)) { + if (frag_deathtype == DEATH_FALL.m_id) { frag_damage = 0; // never count fall damage - - if(!autocvar_g_instagib_damagedbycontents) - switch(DEATH_ENT(frag_deathtype)) - { - case DEATH_DROWN: - case DEATH_SLIME: - case DEATH_LAVA: - frag_damage = 0; - break; } + if (!autocvar_g_instagib_damagedbycontents) { + switch (DEATH_ENT(frag_deathtype)) { + case DEATH_DROWN: + case DEATH_SLIME: + case DEATH_LAVA: + frag_damage = 0; + break; + } + } + + if (IS_PLAYER(frag_attacker)) { + if (DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER)) { + if (!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker)) { + frag_force = '0 0 0'; + } - if(IS_PLAYER(frag_attacker)) - if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER)) - { - if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker)) - frag_force = '0 0 0'; - - float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR); - if(armor) - { - armor -= 1; - SetResourceAmount(frag_target, RESOURCE_ARMOR, armor); - frag_damage = 0; - frag_target.damage_dealt += 1; - frag_attacker.damage_dealt += 1; - Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor); + float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR); + if (armor) { + armor -= 1; + SetResourceAmount(frag_target, RESOURCE_ARMOR, armor); + frag_damage = 0; + frag_target.damage_dealt += 1; + frag_attacker.damage_dealt += 1; + Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor); + } } } - if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER)) - { - if(frag_deathtype & HITTYPE_SECONDARY) - { - if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target) - { + if (IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER)) { + if (frag_deathtype & HITTYPE_SECONDARY) { + if (!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target) { frag_damage = 0; - if(!autocvar_g_instagib_mirrordamage) + if (!autocvar_g_instagib_mirrordamage) { frag_mirrordamage = 0; // never do mirror damage on enemies + } } - if(frag_target != frag_attacker) - { - if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); } - if(!autocvar_g_instagib_blaster_keepforce) + if (frag_target != frag_attacker) { + if (frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); } + if (!autocvar_g_instagib_blaster_keepforce) { frag_force = '0 0 0'; + } } } } } - if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring - if(IS_PLAYER(frag_attacker)) - if(frag_mirrordamage > 0) - { - // just lose extra LIVES, don't kill the player for mirror damage - float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR); - if(armor > 0) - { - armor -= 1; - SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor); - Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor); - frag_attacker.damage_dealt += frag_mirrordamage; + if (!autocvar_g_instagib_mirrordamage) { // only apply the taking lives hack if we don't want to support real damage mirroring + if (IS_PLAYER(frag_attacker)) { + if (frag_mirrordamage > 0) { + // just lose extra LIVES, don't kill the player for mirror damage + float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR); + if (armor > 0) { + armor -= 1; + SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor); + Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor); + frag_attacker.damage_dealt += frag_mirrordamage; + } + frag_mirrordamage = 0; + } } - frag_mirrordamage = 0; } - if(frag_target.alpha && frag_target.alpha < 1) - if(IS_PLAYER(frag_target)) - yoda = 1; + if (frag_target.alpha && frag_target.alpha < 1) { + if (IS_PLAYER(frag_target)) { + yoda = 1; + } + } M_ARGV(4, float) = frag_damage; M_ARGV(5, float) = frag_mirrordamage; @@ -363,7 +335,7 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems) start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start"); start_ammo_plasma = warmup_start_ammo_plasma = 0; start_ammo_rockets = warmup_start_ammo_rockets = 0; - //start_ammo_fuel = warmup_start_ammo_fuel = 0; + // start_ammo_fuel = warmup_start_ammo_fuel = 0; start_weapons = warmup_start_weapons = WEPSET(VAPORIZER); start_items |= IT_UNLIMITED_SUPERWEAPONS; @@ -390,60 +362,50 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem) { entity item = M_ARGV(0, entity); - if(item.classname == "item_cells") - { - if(autocvar_g_instagib_ammo_convert_cells) - { + if (item.classname == "item_cells") { + if (autocvar_g_instagib_ammo_convert_cells) { replace_with_insta_cells(item); } return true; - } - else if(item.classname == "item_rockets") - { - if(autocvar_g_instagib_ammo_convert_rockets) - { + } else if (item.classname == "item_rockets") { + if (autocvar_g_instagib_ammo_convert_rockets) { replace_with_insta_cells(item); } return true; - } - else if(item.classname == "item_shells") - { - if(autocvar_g_instagib_ammo_convert_shells) - { + } else if (item.classname == "item_shells") { + if (autocvar_g_instagib_ammo_convert_shells) { replace_with_insta_cells(item); } return true; - } - else if(item.classname == "item_bullets") - { - if(autocvar_g_instagib_ammo_convert_bullets) - { + } else if (item.classname == "item_bullets") { + if (autocvar_g_instagib_ammo_convert_bullets) { replace_with_insta_cells(item); } return true; } - if(item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon") - { + if (item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon") { SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop); return false; } - if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id) - { + if (item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id) { replace_with_insta_cells(item); return true; } - if(item.flags & FL_POWERUP) + if (item.flags & FL_POWERUP) { return false; + } float cells = GetResourceAmount(item, RESOURCE_CELLS); - if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells") + if (cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells") { SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop); + } - if(cells && !item.weapon) + if (cells && !item.weapon) { return false; + } return true; } @@ -457,17 +419,20 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint) // if you have the invisibility powerup, sprites ALWAYS are restricted to your team // but only apply this to real players, not to spectators - if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player)) - if(DIFF_TEAM(wp.owner, e)) - return true; + if ((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player)) { + if (DIFF_TEAM(wp.owner, e)) { + return true; + } + } } MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies) { float frag_deathtype = M_ARGV(3, float); - if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER)) + if (DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER)) { M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death + } } MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch) @@ -475,26 +440,25 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch) entity item = M_ARGV(0, entity); entity toucher = M_ARGV(1, entity); - if(GetResourceAmount(item, RESOURCE_CELLS)) - { + if (GetResourceAmount(item, RESOURCE_CELLS)) { // play some cool sounds ;) float hp = GetResourceAmount(toucher, RESOURCE_HEALTH); - if (IS_CLIENT(toucher)) - { - if(hp <= 5) + if (IS_CLIENT(toucher)) { + if (hp <= 5) { Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND); - else if(hp < 50) + } else if (hp < 50) { Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY); + } } - if(hp < 100) + if (hp < 100) { SetResourceAmount(toucher, RESOURCE_HEALTH, 100); + } return MUT_ITEMTOUCH_CONTINUE; } - if(item.itemdef == ITEM_ExtraLife) - { + if (item.itemdef == ITEM_ExtraLife) { GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives); Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES); return MUT_ITEMTOUCH_PICKUP; @@ -508,18 +472,20 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn) if (!autocvar_g_powerups) { return; } entity ent = M_ARGV(0, entity); // Can't use .itemdef here - if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega")) + if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega")) { return; + } entity e = spawn(); float r = random(); - if (r < 0.3) + if (r < 0.3) { setthink(e, instagib_invisibility); - else if (r < 0.6) + } else if (r < 0.6) { setthink(e, instagib_extralife); - else + } else { setthink(e, instagib_speed); + } e.nextthink = time + 0.1; e.spawnflags = ent.spawnflags; diff --git a/qcsrc/common/mutators/mutator/invincibleproj/sv_invincibleproj.qc b/qcsrc/common/mutators/mutator/invincibleproj/sv_invincibleproj.qc index e68c687bd..40dcf55a9 100644 --- a/qcsrc/common/mutators/mutator/invincibleproj/sv_invincibleproj.qc +++ b/qcsrc/common/mutators/mutator/invincibleproj/sv_invincibleproj.qc @@ -7,8 +7,7 @@ MUTATOR_HOOKFUNCTION(invincibleprojectiles, EditProjectile) { entity proj = M_ARGV(1, entity); - if(proj.health) - { + if (proj.health) { // disable health which in effect disables damage calculations proj.health = 0; } diff --git a/qcsrc/common/mutators/mutator/itemstime/itemstime.qc b/qcsrc/common/mutators/mutator/itemstime/itemstime.qc index c2402ef46..245e62f47 100644 --- a/qcsrc/common/mutators/mutator/itemstime/itemstime.qc +++ b/qcsrc/common/mutators/mutator/itemstime/itemstime.qc @@ -5,12 +5,13 @@ REGISTER_MUTATOR(itemstime, true); REGISTER_NET_TEMP(itemstime) #ifdef SVQC -void IT_Write(entity e, int i, float f) { - if (!IS_REAL_CLIENT(e)) return; - msg_entity = e; - WriteHeader(MSG_ONE, itemstime); - WriteByte(MSG_ONE, i); - WriteFloat(MSG_ONE, f); +void IT_Write(entity e, int i, float f) +{ + if (!IS_REAL_CLIENT(e)) { return; } + msg_entity = e; + WriteHeader(MSG_ONE, itemstime); + WriteByte(MSG_ONE, i); + WriteFloat(MSG_ONE, f); } #endif @@ -20,24 +21,25 @@ float ItemsTime_time[Items_MAX + 1]; float ItemsTime_availableTime[Items_MAX + 1]; NET_HANDLE(itemstime, bool isNew) { - int i = ReadByte(); - float f = ReadFloat(); - return = true; - ItemsTime_time[i] = f; + int i = ReadByte(); + float f = ReadFloat(); + return = true; + ItemsTime_time[i] = f; } #endif #ifdef CSQC void Item_ItemsTime_Init() { - FOREACH(Items, true, { - ItemsTime_time[it.m_id] = -1; - }); - ItemsTime_time[Items_MAX] = -1; + FOREACH(Items, true, { + ItemsTime_time[it.m_id] = -1; + }); + ItemsTime_time[Items_MAX] = -1; } -STATIC_INIT(ItemsTime_Init) { - Item_ItemsTime_Init(); +STATIC_INIT(ItemsTime_Init) +{ + Item_ItemsTime_Init(); } int autocvar_hud_panel_itemstime = 2; @@ -58,18 +60,18 @@ int autocvar_hud_panel_itemstime_text = 1; bool Item_ItemsTime_SpectatorOnly(GameItem it) { - return (false - || it == ITEM_ArmorMega || (it == ITEM_ArmorBig && !hud_panel_itemstime_hidebig) - || it == ITEM_HealthMega || (it == ITEM_HealthBig && !hud_panel_itemstime_hidebig) - ); + return false + || it == ITEM_ArmorMega || (it == ITEM_ArmorBig && !hud_panel_itemstime_hidebig) + || it == ITEM_HealthMega || (it == ITEM_HealthBig && !hud_panel_itemstime_hidebig) + ; } bool Item_ItemsTime_Allow(GameItem it) { - return (false - || it.instanceOfPowerup - || Item_ItemsTime_SpectatorOnly(it) - ); + return false + || it.instanceOfPowerup + || Item_ItemsTime_SpectatorOnly(it) + ; } #ifdef SVQC @@ -79,116 +81,123 @@ float it_times[Items_MAX + 1]; void Item_ItemsTime_Init() { - FOREACH(Items, Item_ItemsTime_Allow(it), { - it_times[it.m_id] = -1; - }); - it_times[Items_MAX] = -1; + FOREACH(Items, Item_ItemsTime_Allow(it), { + it_times[it.m_id] = -1; + }); + it_times[Items_MAX] = -1; } -STATIC_INIT(ItemsTime_Init) { - // items time - Item_ItemsTime_Init(); +STATIC_INIT(ItemsTime_Init) +{ + // items time + Item_ItemsTime_Init(); } void Item_ItemsTime_ResetTimes() { - FOREACH(Items, Item_ItemsTime_Allow(it), { - it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0; - }); - it_times[Items_MAX] = (it_times[Items_MAX] == -1) ? -1 : 0; + FOREACH(Items, Item_ItemsTime_Allow(it), { + it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0; + }); + it_times[Items_MAX] = (it_times[Items_MAX] == -1) ? -1 : 0; } void Item_ItemsTime_ResetTimesForPlayer(entity e) { - FOREACH(Items, Item_ItemsTime_Allow(it), { - IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0); - }); - IT_Write(e, Items_MAX, (it_times[Items_MAX] == -1) ? -1 : 0); + FOREACH(Items, Item_ItemsTime_Allow(it), { + IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0); + }); + IT_Write(e, Items_MAX, (it_times[Items_MAX] == -1) ? -1 : 0); } void Item_ItemsTime_SetTimesForPlayer(entity e) { - FOREACH(Items, Item_ItemsTime_Allow(it), { - IT_Write(e, it.m_id, it_times[it.m_id]); - }); - IT_Write(e, Items_MAX, it_times[Items_MAX]); + FOREACH(Items, Item_ItemsTime_Allow(it), { + IT_Write(e, it.m_id, it_times[it.m_id]); + }); + IT_Write(e, Items_MAX, it_times[Items_MAX]); } void Item_ItemsTime_SetTime(entity e, float t) { - if (!autocvar_sv_itemstime) - return; + if (!autocvar_sv_itemstime) { + return; + } - GameItem item = e.itemdef; - if (item.instanceOfGameItem) - { - if (!item.instanceOfWeaponPickup) + GameItem item = e.itemdef; + if (item.instanceOfGameItem) { + if (!item.instanceOfWeaponPickup) { it_times[item.m_id] = t; - else if (e.weapons & WEPSET_SUPERWEAPONS) + } else if (e.weapons & WEPSET_SUPERWEAPONS) { it_times[Items_MAX] = t; - } + } + } } void Item_ItemsTime_SetTimesForAllPlayers() { - FOREACH_CLIENT(IS_REAL_CLIENT(it) && (warmup_stage || !IS_PLAYER(it) || autocvar_sv_itemstime == 2), { Item_ItemsTime_SetTimesForPlayer(it); }); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && (warmup_stage || !IS_PLAYER(it) || autocvar_sv_itemstime == 2), { Item_ItemsTime_SetTimesForPlayer(it); + }); } float Item_ItemsTime_UpdateTime(entity e, float t) { - bool isavailable = (t == 0); - IL_EACH(g_items, it != e, - { - if(!(it.itemdef == e.itemdef || ((e.weapons & WEPSET_SUPERWEAPONS) && (it.weapons & WEPSET_SUPERWEAPONS)))) - continue; - if (it.scheduledrespawntime <= time) - isavailable = true; - else if (t == 0 || it.scheduledrespawntime < t) - t = it.scheduledrespawntime; - }); - if (isavailable) - t = -t; // let know the client there's another available item - return t; + bool isavailable = (t == 0); + IL_EACH(g_items, it != e, + { + if (!(it.itemdef == e.itemdef || ((e.weapons & WEPSET_SUPERWEAPONS) && (it.weapons & WEPSET_SUPERWEAPONS)))) { + continue; + } + if (it.scheduledrespawntime <= time) { + isavailable = true; + } else if (t == 0 || it.scheduledrespawntime < t) { + t = it.scheduledrespawntime; + } + }); + if (isavailable) { + t = -t; // let know the client there's another available item + } + return t; } MUTATOR_HOOKFUNCTION(itemstime, reset_map_global) { - Item_ItemsTime_ResetTimes(); - // ALL the times need to be reset before .reset()ing each item - // since Item_Reset schedules respawn of superweapons and powerups - IL_EACH(g_items, it.reset, - { - Item_ItemsTime_SetTime(it, 0); - }); - Item_ItemsTime_SetTimesForAllPlayers(); + Item_ItemsTime_ResetTimes(); + // ALL the times need to be reset before .reset() ing each item + // since Item_Reset schedules respawn of superweapons and powerups + IL_EACH(g_items, it.reset, + { + Item_ItemsTime_SetTime(it, 0); + }); + Item_ItemsTime_SetTimesForAllPlayers(); } MUTATOR_HOOKFUNCTION(itemstime, MakePlayerObserver) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); - Item_ItemsTime_SetTimesForPlayer(player); + Item_ItemsTime_SetTimesForPlayer(player); } MUTATOR_HOOKFUNCTION(itemstime, ClientConnect, CBC_ORDER_LAST) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); - if(IS_PLAYER(player)) - { + if (IS_PLAYER(player)) { // client became player on connection skipping putObserverInServer step - if (IS_REAL_CLIENT(player)) - if (warmup_stage || autocvar_sv_itemstime == 2) - Item_ItemsTime_SetTimesForPlayer(player); + if (IS_REAL_CLIENT(player)) { + if (warmup_stage || autocvar_sv_itemstime == 2) { + Item_ItemsTime_SetTimesForPlayer(player); + } + } } } MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn) { - if (warmup_stage || autocvar_sv_itemstime == 2) return; - entity player = M_ARGV(0, entity); + if (warmup_stage || autocvar_sv_itemstime == 2) { return; } + entity player = M_ARGV(0, entity); - Item_ItemsTime_ResetTimesForPlayer(player); + Item_ItemsTime_ResetTimesForPlayer(player); } #endif @@ -197,246 +206,226 @@ MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn) void DrawItemsTimeItem(vector myPos, vector mySize, float ar, string item_icon, float item_time, bool item_available, float item_availableTime) { - float t = 0; - vector color = '0 0 0'; - float picalpha; - - if (autocvar_hud_panel_itemstime_hidespawned == 2) - picalpha = 1; - else if (item_available) - { - float BLINK_FACTOR = 0.15; - float BLINK_BASE = 0.85; - float BLINK_FREQ = 5; - picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); - } - else - picalpha = 0.5; - t = floor(item_time - time + 0.999); - if (t < 5) - color = '0.7 0 0'; - else if (t < 10) - color = '0.7 0.7 0'; - else - color = '1 1 1'; - - vector picpos, numpos; - if (autocvar_hud_panel_itemstime_iconalign) - { - numpos = myPos; - picpos = myPos + eX * (ar - 1) * mySize_y; - } - else - { - numpos = myPos + eX * mySize_y; - picpos = myPos; - } - - if (t > 0 && autocvar_hud_panel_itemstime_progressbar) - { - vector p_pos, p_size; - if (autocvar_hud_panel_itemstime_progressbar_reduced) - { - p_pos = numpos; - p_size = vec2(((ar - 1)/ar) * mySize.x, mySize.y); - } - else - { - p_pos = myPos; - p_size = mySize; - } - HUD_Panel_DrawProgressBar(p_pos, p_size, autocvar_hud_panel_itemstime_progressbar_name, t/autocvar_hud_panel_itemstime_progressbar_maxtime, 0, autocvar_hud_panel_itemstime_iconalign, color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); - } - - if(autocvar_hud_panel_itemstime_text) - { - if(t > 0) - drawstring_aspect(numpos, ftos(t), vec2(((ar - 1)/ar) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL); - else if(precache_pic("gfx/hud/default/checkmark")) // COMPAT: check if this image exists, as 0.8.1 clients lack it - drawpic_aspect_skin(numpos, "checkmark", vec2((ar - 1) * mySize.y, mySize.y), '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL); - else // legacy code, if the image is missing just center the icon - picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2; - } - if (item_availableTime) - drawpic_aspect_skin_expanding(picpos, item_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime); - drawpic_aspect_skin(picpos, item_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL); + float t = 0; + vector color = '0 0 0'; + float picalpha; + + if (autocvar_hud_panel_itemstime_hidespawned == 2) { + picalpha = 1; + } else if (item_available) { + float BLINK_FACTOR = 0.15; + float BLINK_BASE = 0.85; + float BLINK_FREQ = 5; + picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); + } else { + picalpha = 0.5; + } + t = floor(item_time - time + 0.999); + if (t < 5) { + color = '0.7 0 0'; + } else if (t < 10) { + color = '0.7 0.7 0'; + } else { + color = '1 1 1'; + } + + vector picpos, numpos; + if (autocvar_hud_panel_itemstime_iconalign) { + numpos = myPos; + picpos = myPos + eX * (ar - 1) * mySize_y; + } else { + numpos = myPos + eX * mySize_y; + picpos = myPos; + } + + if (t > 0 && autocvar_hud_panel_itemstime_progressbar) { + vector p_pos, p_size; + if (autocvar_hud_panel_itemstime_progressbar_reduced) { + p_pos = numpos; + p_size = vec2(((ar - 1) / ar) * mySize.x, mySize.y); + } else { + p_pos = myPos; + p_size = mySize; + } + HUD_Panel_DrawProgressBar(p_pos, p_size, autocvar_hud_panel_itemstime_progressbar_name, t / autocvar_hud_panel_itemstime_progressbar_maxtime, 0, autocvar_hud_panel_itemstime_iconalign, color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + + if (autocvar_hud_panel_itemstime_text) { + if (t > 0) { + drawstring_aspect(numpos, ftos(t), vec2(((ar - 1) / ar) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL); + } else if (precache_pic("gfx/hud/default/checkmark")) { // COMPAT: check if this image exists, as 0.8.1 clients lack it + drawpic_aspect_skin(numpos, "checkmark", vec2((ar - 1) * mySize.y, mySize.y), '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL); + } else { // legacy code, if the image is missing just center the icon + picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2; + } + } + if (item_availableTime) { + drawpic_aspect_skin_expanding(picpos, item_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime); + } + drawpic_aspect_skin(picpos, item_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL); } float Item_ItemsTime_GetTime(int item) { - if(autocvar__hud_configure) - { - switch(item) - { - case ITEM_ArmorMega.m_id: return time + 0; - case ITEM_HealthMega.m_id: return time + 8; - case ITEM_Strength.m_id: return time + 0; - case ITEM_Shield.m_id: return time + 4; - } - - return -1; // don't show others - } - else - return ItemsTime_time[item]; + if (autocvar__hud_configure) { + switch (item) { + case ITEM_ArmorMega.m_id: return time + 0; + case ITEM_HealthMega.m_id: return time + 8; + case ITEM_Strength.m_id: return time + 0; + case ITEM_Shield.m_id: return time + 4; + } + + return -1; // don't show others + } else { + return ItemsTime_time[item]; + } } void HUD_ItemsTime() { - if (!autocvar__hud_configure) - { - if (!( - (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0) - || (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage || STAT(ITEMSTIME) == 2)) - )) { return; } - } - - int count = 0; - if (autocvar_hud_panel_itemstime_hidespawned == 1) - { - FOREACH(Items, Item_ItemsTime_Allow(it), { - count += (Item_ItemsTime_GetTime(it.m_id) > time || -Item_ItemsTime_GetTime(it.m_id) > time); - }); - count += (Item_ItemsTime_GetTime(Items_MAX) > time || -Item_ItemsTime_GetTime(Items_MAX) > time); - } - else if (autocvar_hud_panel_itemstime_hidespawned == 2) - { - FOREACH(Items, Item_ItemsTime_Allow(it), { - count += (Item_ItemsTime_GetTime(it.m_id) > time); - }); - count += (Item_ItemsTime_GetTime(Items_MAX) > time); - } - else - { - FOREACH(Items, Item_ItemsTime_Allow(it), { - count += (Item_ItemsTime_GetTime(it.m_id) != -1); - }); - count += (Item_ItemsTime_GetTime(Items_MAX) != -1); - } - if (count == 0) - return; - - HUD_Panel_LoadCvars(); - - vector pos, mySize; - pos = panel_pos; - mySize = panel_size; - - if (panel_bg_padding) - { - pos += '1 1 0' * panel_bg_padding; - mySize -= '2 2 0' * panel_bg_padding; - } - - float rows, columns; - float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1; - rows = HUD_GetRowCount(count, mySize, ar); - columns = ceil(count/rows); - - vector itemstime_size = vec2(mySize.x / columns, mySize.y / rows); - - vector offset = '0 0 0'; - float newSize; - if (autocvar_hud_panel_itemstime_dynamicsize) - { - if (autocvar__hud_configure) - if (hud_configure_menu_open != 2) - HUD_Panel_DrawBg(); // also draw the bg of the entire panel - - // reduce panel to avoid spacing items - if (itemstime_size.x / itemstime_size.y < ar) - { - newSize = rows * itemstime_size.x / ar; - pos.y += (mySize.y - newSize) / 2; - mySize.y = newSize; - itemstime_size.y = mySize.y / rows; - } - else - { - newSize = columns * itemstime_size.y * ar; - pos.x += (mySize.x - newSize) / 2; - mySize.x = newSize; - itemstime_size.x = mySize.x / columns; - } - panel_pos = pos - '1 1 0' * panel_bg_padding; - panel_size = mySize + '2 2 0' * panel_bg_padding; - } - else - { - if (itemstime_size.x/itemstime_size.y > ar) - { - newSize = ar * itemstime_size.y; - offset.x = itemstime_size.x - newSize; - pos.x += offset.x/2; - itemstime_size.x = newSize; - } - else - { - newSize = 1/ar * itemstime_size.x; - offset.y = itemstime_size.y - newSize; - pos.y += offset.y/2; - itemstime_size.y = newSize; - } - } - - HUD_Scale_Enable(); - HUD_Panel_DrawBg(); - - float row = 0, column = 0; - bool item_available; - int id = 0; - string icon = ""; - FOREACH(Items, Item_ItemsTime_Allow(it) && Item_ItemsTime_GetTime(it.m_id) != -1, { - id = it.m_id; - icon = it.m_icon; - -LABEL(iteration) - float item_time = Item_ItemsTime_GetTime(id); - if (item_time < -1) - { - item_available = true; - item_time = -item_time; - } - else - item_available = (item_time <= time); - - if (Item_ItemsTime_GetTime(id) >= 0) - { - if (time <= Item_ItemsTime_GetTime(id)) - ItemsTime_availableTime[id] = 0; - else if (ItemsTime_availableTime[id] == 0) - ItemsTime_availableTime[id] = time; - } - else if (ItemsTime_availableTime[id] == 0) - ItemsTime_availableTime[id] = time; - - float f = (time - ItemsTime_availableTime[id]) * 2; - f = (f > 1) ? 0 : bound(0, f, 1); - - if (autocvar_hud_panel_itemstime_hidespawned == 1) - if (!(Item_ItemsTime_GetTime(id) > time || -Item_ItemsTime_GetTime(id) > time)) - continue; - - if (autocvar_hud_panel_itemstime_hidespawned == 2) - if (!(Item_ItemsTime_GetTime(id) > time)) - continue; - - DrawItemsTimeItem(pos + vec2(column * (itemstime_size.x + offset.x), row * (itemstime_size.y + offset.y)), itemstime_size, ar, icon, item_time, item_available, f); - ++row; - if (row >= rows) - { - row = 0; - column = column + 1; - } - if(id == Items_MAX) // can happen only in the last fake iteration - break; - }); - // add another fake iteration for superweapons time - if(id < Items_MAX && Item_ItemsTime_GetTime(Items_MAX) != -1) - { + if (!autocvar__hud_configure) { + if (!( + (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0) + || (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage || STAT(ITEMSTIME) == 2)) + )) { return; } + } + + int count = 0; + if (autocvar_hud_panel_itemstime_hidespawned == 1) { + FOREACH(Items, Item_ItemsTime_Allow(it), { + count += (Item_ItemsTime_GetTime(it.m_id) > time || -Item_ItemsTime_GetTime(it.m_id) > time); + }); + count += (Item_ItemsTime_GetTime(Items_MAX) > time || -Item_ItemsTime_GetTime(Items_MAX) > time); + } else if (autocvar_hud_panel_itemstime_hidespawned == 2) { + FOREACH(Items, Item_ItemsTime_Allow(it), { + count += (Item_ItemsTime_GetTime(it.m_id) > time); + }); + count += (Item_ItemsTime_GetTime(Items_MAX) > time); + } else { + FOREACH(Items, Item_ItemsTime_Allow(it), { + count += (Item_ItemsTime_GetTime(it.m_id) != -1); + }); + count += (Item_ItemsTime_GetTime(Items_MAX) != -1); + } + if (count == 0) { + return; + } + + HUD_Panel_LoadCvars(); + + vector pos, mySize; + pos = panel_pos; + mySize = panel_size; + + if (panel_bg_padding) { + pos += '1 1 0' * panel_bg_padding; + mySize -= '2 2 0' * panel_bg_padding; + } + + float rows, columns; + float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1; + rows = HUD_GetRowCount(count, mySize, ar); + columns = ceil(count / rows); + + vector itemstime_size = vec2(mySize.x / columns, mySize.y / rows); + + vector offset = '0 0 0'; + float newSize; + if (autocvar_hud_panel_itemstime_dynamicsize) { + if (autocvar__hud_configure) { + if (hud_configure_menu_open != 2) { + HUD_Panel_DrawBg(); // also draw the bg of the entire panel + } + } + // reduce panel to avoid spacing items + if (itemstime_size.x / itemstime_size.y < ar) { + newSize = rows * itemstime_size.x / ar; + pos.y += (mySize.y - newSize) / 2; + mySize.y = newSize; + itemstime_size.y = mySize.y / rows; + } else { + newSize = columns * itemstime_size.y * ar; + pos.x += (mySize.x - newSize) / 2; + mySize.x = newSize; + itemstime_size.x = mySize.x / columns; + } + panel_pos = pos - '1 1 0' * panel_bg_padding; + panel_size = mySize + '2 2 0' * panel_bg_padding; + } else { + if (itemstime_size.x / itemstime_size.y > ar) { + newSize = ar * itemstime_size.y; + offset.x = itemstime_size.x - newSize; + pos.x += offset.x / 2; + itemstime_size.x = newSize; + } else { + newSize = 1 / ar * itemstime_size.x; + offset.y = itemstime_size.y - newSize; + pos.y += offset.y / 2; + itemstime_size.y = newSize; + } + } + + HUD_Scale_Enable(); + HUD_Panel_DrawBg(); + + float row = 0, column = 0; + bool item_available; + int id = 0; + string icon = ""; + FOREACH(Items, Item_ItemsTime_Allow(it) && Item_ItemsTime_GetTime(it.m_id) != -1, { + id = it.m_id; + icon = it.m_icon; + + LABEL(iteration) + float item_time = Item_ItemsTime_GetTime(id); + if (item_time < -1) { + item_available = true; + item_time = -item_time; + } else { + item_available = (item_time <= time); + } + + if (Item_ItemsTime_GetTime(id) >= 0) { + if (time <= Item_ItemsTime_GetTime(id)) { + ItemsTime_availableTime[id] = 0; + } else if (ItemsTime_availableTime[id] == 0) { + ItemsTime_availableTime[id] = time; + } + } else if (ItemsTime_availableTime[id] == 0) { + ItemsTime_availableTime[id] = time; + } + + float f = (time - ItemsTime_availableTime[id]) * 2; + f = (f > 1) ? 0 : bound(0, f, 1); + + if (autocvar_hud_panel_itemstime_hidespawned == 1) { + if (!(Item_ItemsTime_GetTime(id) > time || -Item_ItemsTime_GetTime(id) > time)) { + continue; + } + } + + if (autocvar_hud_panel_itemstime_hidespawned == 2) { + if (!(Item_ItemsTime_GetTime(id) > time)) { + continue; + } + } + + DrawItemsTimeItem(pos + vec2(column * (itemstime_size.x + offset.x), row * (itemstime_size.y + offset.y)), itemstime_size, ar, icon, item_time, item_available, f); + ++row; + if (row >= rows) { + row = 0; + column = column + 1; + } + if (id == Items_MAX) { // can happen only in the last fake iteration + break; + } + }); + // add another fake iteration for superweapons time + if (id < Items_MAX && Item_ItemsTime_GetTime(Items_MAX) != -1) { id = Items_MAX; icon = "superweapons"; goto iteration; - } + } } #endif diff --git a/qcsrc/common/mutators/mutator/melee_only/sv_melee_only.qc b/qcsrc/common/mutators/mutator/melee_only/sv_melee_only.qc index ac06a8f77..5bab34295 100644 --- a/qcsrc/common/mutators/mutator/melee_only/sv_melee_only.qc +++ b/qcsrc/common/mutators/mutator/melee_only/sv_melee_only.qc @@ -24,8 +24,7 @@ MUTATOR_HOOKFUNCTION(melee_only, FilterItem) { entity item = M_ARGV(0, entity); - switch (item.itemdef) - { + switch (item.itemdef) { case ITEM_HealthSmall: case ITEM_ArmorSmall: return false; diff --git a/qcsrc/common/mutators/mutator/midair/sv_midair.qc b/qcsrc/common/mutators/mutator/midair/sv_midair.qc index 54b3673c6..f5c9f5d5e 100644 --- a/qcsrc/common/mutators/mutator/midair/sv_midair.qc +++ b/qcsrc/common/mutators/mutator/midair/sv_midair.qc @@ -12,21 +12,24 @@ MUTATOR_HOOKFUNCTION(midair, Damage_Calculate) entity frag_attacker = M_ARGV(1, entity); entity frag_target = M_ARGV(2, entity); - if(IS_PLAYER(frag_attacker)) - if(IS_PLAYER(frag_target)) - if(time < frag_target.midair_shieldtime) - M_ARGV(4, float) = 0; + if (IS_PLAYER(frag_attacker)) { + if (IS_PLAYER(frag_target)) { + if (time < frag_target.midair_shieldtime) { + M_ARGV(4, float) = 0; + } + } + } } MUTATOR_HOOKFUNCTION(midair, PlayerPowerups) { entity player = M_ARGV(0, entity); - if(time >= game_starttime) - if(IS_ONGROUND(player)) - { - player.effects |= (EF_ADDITIVE | EF_FULLBRIGHT); - player.midair_shieldtime = max(player.midair_shieldtime, time + autocvar_g_midair_shieldtime); + if (time >= game_starttime) { + if (IS_ONGROUND(player)) { + player.effects |= (EF_ADDITIVE | EF_FULLBRIGHT); + player.midair_shieldtime = max(player.midair_shieldtime, time + autocvar_g_midair_shieldtime); + } } } @@ -34,8 +37,9 @@ MUTATOR_HOOKFUNCTION(midair, PlayerSpawn) { entity player = M_ARGV(0, entity); - if(IS_BOT_CLIENT(player)) + if (IS_BOT_CLIENT(player)) { player.bot_moveskill = 0; // disable bunnyhopping + } } MUTATOR_HOOKFUNCTION(midair, BuildMutatorsString) diff --git a/qcsrc/common/mutators/mutator/multijump/multijump.qc b/qcsrc/common/mutators/mutator/multijump/multijump.qc index 081a1fdb6..9911aebb2 100644 --- a/qcsrc/common/mutators/mutator/multijump/multijump.qc +++ b/qcsrc/common/mutators/mutator/multijump/multijump.qc @@ -14,98 +14,94 @@ REGISTER_MUTATOR(multijump, autocvar_g_multijump); REGISTER_MUTATOR(multijump, true); #endif -#define PHYS_MULTIJUMP(s) STAT(MULTIJUMP, s) -#define PHYS_MULTIJUMP_SPEED(s) STAT(MULTIJUMP_SPEED, s) -#define PHYS_MULTIJUMP_ADD(s) STAT(MULTIJUMP_ADD, s) -#define PHYS_MULTIJUMP_MAXSPEED(s) STAT(MULTIJUMP_MAXSPEED, s) -#define PHYS_MULTIJUMP_DODGING(s) STAT(MULTIJUMP_DODGING, s) -#define PHYS_MULTIJUMP_COUNT(s) STAT(MULTIJUMP_COUNT, s) +#define PHYS_MULTIJUMP(s) STAT(MULTIJUMP, s) +#define PHYS_MULTIJUMP_SPEED(s) STAT(MULTIJUMP_SPEED, s) +#define PHYS_MULTIJUMP_ADD(s) STAT(MULTIJUMP_ADD, s) +#define PHYS_MULTIJUMP_MAXSPEED(s) STAT(MULTIJUMP_MAXSPEED, s) +#define PHYS_MULTIJUMP_DODGING(s) STAT(MULTIJUMP_DODGING, s) +#define PHYS_MULTIJUMP_COUNT(s) STAT(MULTIJUMP_COUNT, s) .bool multijump_ready; #ifdef CSQC bool autocvar_cl_multijump = true; - #define PHYS_MULTIJUMP_CLIENT(s) autocvar_cl_multijump + #define PHYS_MULTIJUMP_CLIENT(s) autocvar_cl_multijump #elif defined(SVQC) .bool cvar_cl_multijump; - #define PHYS_MULTIJUMP_CLIENT(s) CS(s).cvar_cl_multijump + #define PHYS_MULTIJUMP_CLIENT(s) CS(s).cvar_cl_multijump #endif MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); #ifdef CSQC player.multijump_count = PHYS_MULTIJUMP_COUNT(player); #endif - if(!PHYS_MULTIJUMP(player)) { return; } + if (!PHYS_MULTIJUMP(player)) { return; } - if(IS_ONGROUND(player)) + if (IS_ONGROUND(player)) { player.multijump_count = 0; + } } MUTATOR_HOOKFUNCTION(multijump, PlayerJump) { entity player = M_ARGV(0, entity); - if(!PHYS_MULTIJUMP(player)) { return; } + if (!PHYS_MULTIJUMP(player)) { return; } int client_multijump = PHYS_MULTIJUMP_CLIENT(player); - if(client_multijump > 1) - return; // nope - - if (!IS_JUMP_HELD(player) && !IS_ONGROUND(player) && client_multijump) // jump button pressed this frame and we are in midair - player.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again - else + if (client_multijump > 1) { + return; // nope + } + if (!IS_JUMP_HELD(player) && !IS_ONGROUND(player) && client_multijump) { // jump button pressed this frame and we are in midair + player.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again + } else { player.multijump_ready = false; + } int phys_multijump = PHYS_MULTIJUMP(player); - if(!M_ARGV(2, bool) && player.multijump_ready && (PHYS_MULTIJUMP_COUNT(player) < phys_multijump || phys_multijump == -1) && player.velocity_z > PHYS_MULTIJUMP_SPEED(player) && - (!PHYS_MULTIJUMP_MAXSPEED(player) || vdist(player.velocity, <=, PHYS_MULTIJUMP_MAXSPEED(player)))) - { - if (PHYS_MULTIJUMP(player)) - { - if (!PHYS_MULTIJUMP_ADD(player)) // in this case we make the z velocity == jumpvelocity - { - if (player.velocity_z < PHYS_JUMPVELOCITY(player)) - { + if (!M_ARGV(2, bool) && player.multijump_ready && (PHYS_MULTIJUMP_COUNT(player) < phys_multijump || phys_multijump == -1) && player.velocity_z > PHYS_MULTIJUMP_SPEED(player) + && (!PHYS_MULTIJUMP_MAXSPEED(player) || vdist(player.velocity, <=, PHYS_MULTIJUMP_MAXSPEED(player)))) { + if (PHYS_MULTIJUMP(player)) { + if (!PHYS_MULTIJUMP_ADD(player)) { // in this case we make the z velocity == jumpvelocity + if (player.velocity_z < PHYS_JUMPVELOCITY(player)) { M_ARGV(2, bool) = true; player.velocity_z = 0; } - } - else + } else { M_ARGV(2, bool) = true; + } - if(M_ARGV(2, bool)) - { - if(PHYS_MULTIJUMP_DODGING(player)) - if(PHYS_CS(player).movement_x != 0 || PHYS_CS(player).movement_y != 0) // don't remove all speed if player isnt pressing any movement keys - { - float curspeed; - vector wishvel, wishdir; + if (M_ARGV(2, bool)) { + if (PHYS_MULTIJUMP_DODGING(player)) { + if (PHYS_CS(player).movement_x != 0 || PHYS_CS(player).movement_y != 0) { // don't remove all speed if player isnt pressing any movement keys + float curspeed; + vector wishvel, wishdir; /*#ifdef SVQC - curspeed = max( - vlen(vec2(player.velocity)), // current xy speed - vlen(vec2(antilag_takebackavgvelocity(player, max(player.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs - ); + curspeed = max( + vlen(vec2(player.velocity)), // current xy speed + vlen(vec2(antilag_takebackavgvelocity(player, max(player.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs + ); #elif defined(CSQC)*/ - curspeed = vlen(vec2(player.velocity)); -//#endif + curspeed = vlen(vec2(player.velocity)); +// #endif - makevectors(player.v_angle_y * '0 1 0'); - wishvel = v_forward * PHYS_CS(player).movement_x + v_right * PHYS_CS(player).movement_y; - wishdir = normalize(wishvel); + makevectors(player.v_angle_y * '0 1 0'); + wishvel = v_forward * PHYS_CS(player).movement_x + v_right * PHYS_CS(player).movement_y; + wishdir = normalize(wishvel); - player.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump - player.velocity_y = wishdir_y * curspeed; - // keep velocity_z unchanged! + player.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump + player.velocity_y = wishdir_y * curspeed; + // keep velocity_z unchanged! + } } - if (PHYS_MULTIJUMP(player) > 0) - { + if (PHYS_MULTIJUMP(player) > 0) { player.multijump_count += 1; } } diff --git a/qcsrc/common/mutators/mutator/nades/nades.qh b/qcsrc/common/mutators/mutator/nades/nades.qh index 3618fd418..1c12a5767 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qh +++ b/qcsrc/common/mutators/mutator/nades/nades.qh @@ -27,28 +27,28 @@ REGISTRY_CHECK(Nades) #define REGISTER_NADE(id) REGISTER(Nades, NADE_TYPE, id, m_id, NEW(Nade)) CLASS(Nade, Object) - ATTRIB(Nade, m_id, int, 0); - ATTRIB(Nade, m_color, vector, '0 0 0'); - ATTRIB(Nade, m_name, string, _("Grenade")); - ATTRIB(Nade, m_icon, string, "nade_normal"); - ATTRIBARRAY(Nade, m_projectile, int, 2); - ATTRIBARRAY(Nade, m_trail, entity, 2); - METHOD(Nade, display, void(entity this, void(string name, string icon) returns)) { - returns(this.m_name, sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.m_icon)); - } + ATTRIB(Nade, m_id, int, 0); + ATTRIB(Nade, m_color, vector, '0 0 0'); + ATTRIB(Nade, m_name, string, _("Grenade")); + ATTRIB(Nade, m_icon, string, "nade_normal"); + ATTRIBARRAY(Nade, m_projectile, int, 2); + ATTRIBARRAY(Nade, m_trail, entity, 2); + METHOD(Nade, display, void(entity this, void(string name, string icon) returns)) + { + returns(this.m_name, sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.m_icon)); + } ENDCLASS(Nade) REGISTER_NADE(Null); Nade Nade_FromProjectile(int proj) { - FOREACH(Nades, true, { - for (int j = 0; j < 2; j++) - { - if (it.m_projectile[j] == proj) return it; - } - }); - return NADE_TYPE_Null; + FOREACH(Nades, true, { + for (int j = 0; j < 2; j++) { + if (it.m_projectile[j] == proj) { return it; } + } + }); + return NADE_TYPE_Null; } #ifdef GAMEQC @@ -91,13 +91,13 @@ void nades_GiveBonus(entity player, float score); * called to adjust nade damage and force on hit */ #define EV_Nade_Damage(i, o) \ - /** nade */ i(entity, MUTATOR_ARGV_0_entity) \ - /** weapon */ i(entity, MUTATOR_ARGV_1_entity) \ - /** force */ i(vector, MUTATOR_ARGV_2_vector) \ - /**/ o(vector, MUTATOR_ARGV_2_vector) \ - /** damage */ i(float, MUTATOR_ARGV_3_float) \ - /**/ o(float, MUTATOR_ARGV_3_float) \ - /**/ + /** nade */ i(entity, MUTATOR_ARGV_0_entity) \ + /** weapon */ i(entity, MUTATOR_ARGV_1_entity) \ + /** force */ i(vector, MUTATOR_ARGV_2_vector) \ + /**/ o(vector, MUTATOR_ARGV_2_vector) \ + /** damage */ i(float, MUTATOR_ARGV_3_float) \ + /**/ o(float, MUTATOR_ARGV_3_float) \ + /**/ MUTATOR_HOOKABLE(Nade_Damage, EV_Nade_Damage); #endif diff --git a/qcsrc/common/mutators/mutator/nades/net.qc b/qcsrc/common/mutators/mutator/nades/net.qc index 498d878d2..e50e0228b 100644 --- a/qcsrc/common/mutators/mutator/nades/net.qc +++ b/qcsrc/common/mutators/mutator/nades/net.qc @@ -10,11 +10,12 @@ void orb_draw(entity this) { float dt = time - this.move_time; this.move_time = time; - if(dt <= 0) + if (dt <= 0) { return; + } this.alpha = (this.ltime - time) / this.orb_lifetime; - this.scale = min((1 - this.alpha)*this.orb_lifetime*4,1)*this.orb_radius; + this.scale = min((1 - this.alpha) * this.orb_lifetime * 4, 1) * this.orb_radius; this.angles = this.angles + dt * this.avelocity; } @@ -27,8 +28,8 @@ void orb_setup(entity e) float model_radius = e.maxs.x; vector size = '1 1 1' * e.orb_radius / 2; - setsize(e,-size,size); - e.orb_radius = e.orb_radius/model_radius*0.6; + setsize(e, -size, size); + e.orb_radius = e.orb_radius / model_radius * 0.6; e.draw = orb_draw; IL_PUSH(g_drawables, e); @@ -59,7 +60,7 @@ NET_HANDLE(Nade_Orb, bool isNew) this.colormod_z = ReadCoord(); this.orb_lifetime = ReadByte(); this.orb_radius = ReadShort(); - this.ltime = time + ReadByte()/10.0; + this.ltime = time + ReadByte() / 10.0; // this.ltime = time + this.orb_lifetime; orb_setup(this); } @@ -83,10 +84,10 @@ bool orb_send(entity this, entity to, int sf) WriteCoord(channel, this.colormod.z); WriteByte(channel, this.orb_lifetime); - //WriteByte(MSG_ENTITY, this.ltime - time + 1); + // WriteByte(MSG_ENTITY, this.ltime - time + 1); WriteShort(channel, this.orb_radius); // round time delta to a 1/10th of a second - WriteByte(channel, (this.ltime - time)*10.0+0.5); + WriteByte(channel, (this.ltime - time) * 10.0 + 0.5); } return true; } diff --git a/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc b/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc index af364995a..3e9a0d201 100644 --- a/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc +++ b/qcsrc/common/mutators/mutator/new_toys/sv_new_toys.qc @@ -3,8 +3,8 @@ /* CORE laser vortex lg rl cry gl elec hagar fireb hook - vaporizer porto - tuba + vaporizer porto + tuba NEW rifle hlac minel seeker IDEAS OPEN flak OPEN FUN FUN FUN FUN @@ -76,21 +76,24 @@ REGISTER_MUTATOR(nt, expr_evaluate(autocvar_g_new_toys) && !cvar("g_instagib") & { MUTATOR_ONADD { - if(time > 1) // game loads at time 1 + if (time > 1) { // game loads at time 1 error("This cannot be added at runtime\n"); + } // mark the guns as ok to use by e.g. impulse 99 FOREACH(Weapons, it != WEP_Null, { - if(nt_IsNewToy(it.m_id)) + if (nt_IsNewToy(it.m_id)) { it.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED; + } }); } MUTATOR_ONROLLBACK_OR_REMOVE { FOREACH(Weapons, it != WEP_Null, { - if(nt_IsNewToy(it.m_id)) + if (nt_IsNewToy(it.m_id)) { it.spawnflags |= WEP_FLAG_MUTATORBLOCKED; + } }); } @@ -113,8 +116,7 @@ const float NT_AUTOREPLACE_RANDOM = 2; bool nt_IsNewToy(int w) { - switch(w) - { + switch (w) { case WEP_SEEKER.m_id: case WEP_MINE_LAYER.m_id: case WEP_HLAC.m_id: @@ -128,26 +130,28 @@ bool nt_IsNewToy(int w) string nt_GetFullReplacement(string w) { - switch(w) - { + switch (w) { case "hagar": return "seeker"; case "devastator": return "minelayer"; case "machinegun": return "hlac"; case "vortex": return "rifle"; - //case "shotgun": return "shockwave"; + // case "shotgun": return "shockwave"; default: return string_null; } } string nt_GetReplacement(string w, float m) { - if(m == NT_AUTOREPLACE_NEVER) + if (m == NT_AUTOREPLACE_NEVER) { return w; + } string s = nt_GetFullReplacement(w); - if (!s) + if (!s) { return w; - if(m == NT_AUTOREPLACE_RANDOM) + } + if (m == NT_AUTOREPLACE_RANDOM) { s = strcat(w, " ", s); + } return s; } @@ -171,15 +175,15 @@ MUTATOR_HOOKFUNCTION(nt, SetStartItems) seti = it.m_wepset; n = tokenize_console(nt_GetReplacement(it.netname, autocvar_g_new_toys_autoreplace)); - for(j = 0; j < n; ++j) + for (j = 0; j < n; ++j) { FOREACH(Weapons, it != WEP_Null, { - if(it.netname == argv(j)) - { + if (it.netname == argv(j)) { WepSet setk = it.m_wepset; - if(start_weapons & seti) newdefault |= setk; - if(warmup_start_weapons & seti) warmup_newdefault |= setk; + if (start_weapons & seti) { newdefault |= setk; } + if (warmup_start_weapons & seti) { warmup_newdefault |= setk; } } }); + } }); newdefault &= start_weapons_defaultmask; @@ -198,13 +202,10 @@ MUTATOR_HOOKFUNCTION(nt, SetWeaponreplace) string ret_string = M_ARGV(2, string); // otherwise, we do replace - if(wep.new_toys) - { + if (wep.new_toys) { // map defined replacement: ret_string = wep.new_toys; - } - else - { + } else { // auto replacement: ret_string = nt_GetReplacement(wepinfo.netname, autocvar_g_new_toys_autoreplace); } @@ -219,7 +220,7 @@ MUTATOR_HOOKFUNCTION(nt, FilterItem) { entity item = M_ARGV(0, entity); - if(nt_IsNewToy(item.weapon) && autocvar_g_new_toys_use_pickupsound) { + if (nt_IsNewToy(item.weapon) && autocvar_g_new_toys_use_pickupsound) { item.item_pickupsound = string_null; item.item_pickupsound_ent = SND_WEAPONPICKUP_NEW_TOYS; } diff --git a/qcsrc/common/mutators/mutator/physical_items/sv_physical_items.qc b/qcsrc/common/mutators/mutator/physical_items/sv_physical_items.qc index 38cd7474b..cd3964512 100644 --- a/qcsrc/common/mutators/mutator/physical_items/sv_physical_items.qc +++ b/qcsrc/common/mutators/mutator/physical_items/sv_physical_items.qc @@ -9,8 +9,7 @@ REGISTER_MUTATOR(physical_items, autocvar_g_physical_items) // check if we have a physics engine MUTATOR_ONADD { - if (!(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE"))) - { + if (!(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE"))) { LOG_TRACE("Warning: Physical items are enabled but no physics engine can be used. Reverting to old items."); return -1; } @@ -38,26 +37,21 @@ void physical_item_think(entity this) this.alpha = this.owner.alpha; // apply fading and ghosting - if(!this.cnt) // map item, not dropped - { + if (!this.cnt) { // map item, not dropped // copy ghost item properties this.colormap = this.owner.colormap; this.colormod = this.owner.colormod; this.glowmod = this.owner.glowmod; // if the item is not spawned, make sure the invisible / ghost item returns to its origin and stays there - if(autocvar_g_physical_items_reset) - { - if(this.owner.wait > time) // awaiting respawn - { + if (autocvar_g_physical_items_reset) { + if (this.owner.wait > time) { // awaiting respawn setorigin(this, this.spawn_origin); this.angles = this.spawn_angles; this.solid = SOLID_NOT; this.alpha = -1; set_movetype(this, MOVETYPE_NONE); - } - else - { + } else { this.alpha = 1; this.solid = SOLID_CORPSE; set_movetype(this, MOVETYPE_PHYSICS); @@ -65,27 +59,28 @@ void physical_item_think(entity this) } } - if(!this.owner.modelindex) + if (!this.owner.modelindex) { delete(this); // the real item is gone, remove this + } } void physical_item_touch(entity this, entity toucher) { - if(!this.cnt) // not for dropped items - if (ITEM_TOUCH_NEEDKILL()) - { - setorigin(this, this.spawn_origin); - this.angles = this.spawn_angles; + if (!this.cnt) { // not for dropped items + if (ITEM_TOUCH_NEEDKILL()) { + setorigin(this, this.spawn_origin); + this.angles = this.spawn_angles; + } } } void physical_item_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) { - if(!this.cnt) // not for dropped items - if(ITEM_DAMAGE_NEEDKILL(deathtype)) - { - setorigin(this, this.spawn_origin); - this.angles = this.spawn_angles; + if (!this.cnt) { // not for dropped items + if (ITEM_DAMAGE_NEEDKILL(deathtype)) { + setorigin(this, this.spawn_origin); + this.angles = this.spawn_angles; + } } } @@ -93,10 +88,12 @@ MUTATOR_HOOKFUNCTION(physical_items, Item_Spawn) { entity item = M_ARGV(0, entity); - if(item.owner == NULL && autocvar_g_physical_items <= 1) + if (item.owner == NULL && autocvar_g_physical_items <= 1) { return; - if (item.spawnflags & 1) // floating item + } + if (item.spawnflags & 1) { // floating item return; + } // The actual item can't be physical and trigger at the same time, so make it invisible and use a second entity for physics. // Ugly hack, but unless SOLID_TRIGGER is gotten to work with MOVETYPE_PHYSICS in the engine it can't be fixed. @@ -124,8 +121,7 @@ MUTATOR_HOOKFUNCTION(physical_items, Item_Spawn) settouch(wep, physical_item_touch); wep.event_damage = physical_item_damage; - if(!wep.cnt) - { + if (!wep.cnt) { // fix the spawn origin setorigin(wep, wep.origin + '0 0 1'); droptofloor(wep); @@ -136,6 +132,6 @@ MUTATOR_HOOKFUNCTION(physical_items, Item_Spawn) item.effects |= EF_NODRAW; // hide the original weapon set_movetype(item, MOVETYPE_FOLLOW); - item.aiment = wep; // attach the original weapon + item.aiment = wep; // attach the original weapon setSendEntity(item, func_null); } diff --git a/qcsrc/common/mutators/mutator/pinata/sv_pinata.qc b/qcsrc/common/mutators/mutator/pinata/sv_pinata.qc index 1084ff778..bba5d447a 100644 --- a/qcsrc/common/mutators/mutator/pinata/sv_pinata.qc +++ b/qcsrc/common/mutators/mutator/pinata/sv_pinata.qc @@ -7,18 +7,21 @@ MUTATOR_HOOKFUNCTION(pinata, PlayerDies) { entity frag_target = M_ARGV(2, entity); - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - if(frag_target.(weaponentity).m_weapon == WEP_Null) + if (frag_target.(weaponentity).m_weapon == WEP_Null) { continue; + } FOREACH(Weapons, it != WEP_Null, { - if(frag_target.weapons & WepSet_FromWeapon(it)) - if(frag_target.(weaponentity).m_weapon != it) - if(W_IsWeaponThrowable(frag_target, it.m_id)) - W_ThrowNewWeapon(frag_target, it.m_id, false, CENTER_OR_VIEWOFS(frag_target), randomvec() * 175 + '0 0 325', weaponentity); + if (frag_target.weapons & WepSet_FromWeapon(it)) { + if (frag_target.(weaponentity).m_weapon != it) { + if (W_IsWeaponThrowable(frag_target, it.m_id)) { + W_ThrowNewWeapon(frag_target, it.m_id, false, CENTER_OR_VIEWOFS(frag_target), randomvec() * 175 + '0 0 325', weaponentity); + } + } + } }); } diff --git a/qcsrc/common/mutators/mutator/random_gravity/sv_random_gravity.qc b/qcsrc/common/mutators/mutator/random_gravity/sv_random_gravity.qc index db361850d..75483eb6a 100644 --- a/qcsrc/common/mutators/mutator/random_gravity/sv_random_gravity.qc +++ b/qcsrc/common/mutators/mutator/random_gravity/sv_random_gravity.qc @@ -24,15 +24,16 @@ float gravity_delay; MUTATOR_HOOKFUNCTION(random_gravity, SV_StartFrame) { - if(game_stopped || !cvar("g_random_gravity")) return false; - if(time < gravity_delay) return false; - if(time < game_starttime) return false; - if(round_handler_IsActive() && !round_handler_IsRoundStarted()) return false; - - if(random() >= autocvar_g_random_gravity_negative_chance) - cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() - random() * -autocvar_g_random_gravity_negative, autocvar_g_random_gravity_max))); - else - cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() * autocvar_g_random_gravity_positive, autocvar_g_random_gravity_max))); + if (game_stopped || !cvar("g_random_gravity")) { return false; } + if (time < gravity_delay) { return false; } + if (time < game_starttime) { return false; } + if (round_handler_IsActive() && !round_handler_IsRoundStarted()) { return false; } + + if (random() >= autocvar_g_random_gravity_negative_chance) { + cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() - random() * -autocvar_g_random_gravity_negative, autocvar_g_random_gravity_max))); + } else { + cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() * autocvar_g_random_gravity_positive, autocvar_g_random_gravity_max))); + } gravity_delay = time + autocvar_g_random_gravity_delay; diff --git a/qcsrc/common/mutators/mutator/rocketflying/sv_rocketflying.qc b/qcsrc/common/mutators/mutator/rocketflying/sv_rocketflying.qc index d3c1922b9..4bcec727f 100644 --- a/qcsrc/common/mutators/mutator/rocketflying/sv_rocketflying.qc +++ b/qcsrc/common/mutators/mutator/rocketflying/sv_rocketflying.qc @@ -7,8 +7,7 @@ MUTATOR_HOOKFUNCTION(rocketflying, EditProjectile) { entity proj = M_ARGV(1, entity); - if(proj.classname == "rocket" || proj.classname == "mine") - { + if (proj.classname == "rocket" || proj.classname == "mine") { // kill detonate delay of rockets proj.spawnshieldtime = time; } diff --git a/qcsrc/common/mutators/mutator/rocketminsta/sv_rocketminsta.qc b/qcsrc/common/mutators/mutator/rocketminsta/sv_rocketminsta.qc index 7edef9813..bcfcb4652 100644 --- a/qcsrc/common/mutators/mutator/rocketminsta/sv_rocketminsta.qc +++ b/qcsrc/common/mutators/mutator/rocketminsta/sv_rocketminsta.qc @@ -8,21 +8,26 @@ REGISTER_MUTATOR(rm, cvar("g_instagib")); MUTATOR_HOOKFUNCTION(rm, Damage_Calculate) { // we do it this way, so rm can be toggled during the match - if(!autocvar_g_rm) { return; } + if (!autocvar_g_rm) { return; } entity frag_attacker = M_ARGV(1, entity); entity frag_target = M_ARGV(2, entity); float frag_deathtype = M_ARGV(3, float); float frag_damage = M_ARGV(4, float); - if(DEATH_ISWEAPON(frag_deathtype, WEP_DEVASTATOR)) - if(frag_attacker == frag_target || frag_target.classname == "nade") - frag_damage = 0; + if (DEATH_ISWEAPON(frag_deathtype, WEP_DEVASTATOR)) { + if (frag_attacker == frag_target || frag_target.classname == "nade") { + frag_damage = 0; + } + } - if(autocvar_g_rm_laser) - if(DEATH_ISWEAPON(frag_deathtype, WEP_ELECTRO)) - if(frag_attacker == frag_target || (round_handler_IsActive() && !round_handler_IsRoundStarted())) - frag_damage = 0; + if (autocvar_g_rm_laser) { + if (DEATH_ISWEAPON(frag_deathtype, WEP_ELECTRO)) { + if (frag_attacker == frag_target || (round_handler_IsActive() && !round_handler_IsRoundStarted())) { + frag_damage = 0; + } + } + } M_ARGV(4, float) = frag_damage; } @@ -30,10 +35,11 @@ MUTATOR_HOOKFUNCTION(rm, Damage_Calculate) MUTATOR_HOOKFUNCTION(rm, PlayerDies) { // we do it this way, so rm can be toggled during the match - if(!autocvar_g_rm) { return; } + if (!autocvar_g_rm) { return; } float frag_deathtype = M_ARGV(3, float); - if(DEATH_ISWEAPON(frag_deathtype, WEP_DEVASTATOR) || DEATH_ISWEAPON(frag_deathtype, WEP_ELECTRO)) + if (DEATH_ISWEAPON(frag_deathtype, WEP_DEVASTATOR) || DEATH_ISWEAPON(frag_deathtype, WEP_ELECTRO)) { M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death + } } diff --git a/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc b/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc index d121cf109..75cffc825 100644 --- a/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc +++ b/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc @@ -24,8 +24,9 @@ REGISTER_MUTATOR(sandbox, expr_evaluate(autocvar_g_sandbox)) MUTATOR_ONADD { autosave_time = time + autocvar_g_sandbox_storage_autosave; // don't save the first server frame - if(autocvar_g_sandbox_storage_autoload) + if (autocvar_g_sandbox_storage_autoload) { sandbox_Database_Load(); + } } } @@ -40,45 +41,48 @@ void sandbox_ObjectFunction_Touch(entity this, entity toucher) { // apply material impact effects - if(!this.material) + if (!this.material) { return; - if(this.touch_timer > time) + } + if (this.touch_timer > time) { return; // don't execute each frame + } this.touch_timer = time + 0.1; // make particle count and sound volume depend on impact speed float intensity; intensity = vlen(this.velocity) + vlen(toucher.velocity); - if(intensity) // avoid divisions by 0 - intensity /= 2; // average the two velocities - if (!(intensity >= autocvar_g_sandbox_object_material_velocity_min)) - return; // impact not strong enough to do anything + if (intensity) { // avoid divisions by 0 + intensity /= 2; // average the two velocities + } + if (!(intensity >= autocvar_g_sandbox_object_material_velocity_min)) { + return; // impact not strong enough to do anything + } // now offset intensity and apply it to the effects intensity -= autocvar_g_sandbox_object_material_velocity_min; // start from minimum velocity, not actual velocity intensity = bound(0, intensity * autocvar_g_sandbox_object_material_velocity_factor, 1); - _sound(this, CH_TRIGGER, strcat("object/impact_", this.material, "_", ftos(ceil(random() * 5)) , ".wav"), VOL_BASE * intensity, ATTEN_NORM); + _sound(this, CH_TRIGGER, strcat("object/impact_", this.material, "_", ftos(ceil(random() * 5)), ".wav"), VOL_BASE * intensity, ATTEN_NORM); Send_Effect_(strcat("impact_", this.material), this.origin, '0 0 0', ceil(intensity * 10)); // allow a count from 1 to 10 } void sandbox_ObjectFunction_Think(entity this) { // decide if and how this object can be grabbed - if(autocvar_g_sandbox_readonly) + if (autocvar_g_sandbox_readonly) { this.grab = 0; // no grabbing - else if(autocvar_g_sandbox_editor_free < 2 && this.crypto_idfp) + } else if (autocvar_g_sandbox_editor_free < 2 && this.crypto_idfp) { this.grab = 1; // owner only - else + } else { this.grab = 3; // anyone - + } // Object owner is stored via player UID, but we also need the owner as an entity (if the player is available on the server). // Therefore, scan for all players, and update the owner as long as the player is present. We must always do this, // since if the owning player disconnects, the object's owner should also be reset. // bots can't have objects FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { - if(this.crypto_idfp == it.crypto_idfp) - { + if (this.crypto_idfp == it.crypto_idfp) { this.realowner = it; break; } @@ -98,26 +102,30 @@ entity sandbox_ObjectEdit_Get(entity this, float permissions) // Attached objects are SOLID_NOT and do not get traced. crosshair_trace_plusvisibletriggers(this); - if(vdist(this.origin - trace_ent.origin, >, autocvar_g_sandbox_editor_distance_edit)) - return NULL; // out of trace range - if(trace_ent.classname != "object") - return NULL; // entity is not an object - if(!permissions) + if (vdist(this.origin - trace_ent.origin, >, autocvar_g_sandbox_editor_distance_edit)) { + return NULL; // out of trace range + } + if (trace_ent.classname != "object") { + return NULL; // entity is not an object + } + if (!permissions) { return trace_ent; // don't check permissions, anyone can edit this object - if(trace_ent.crypto_idfp == "") + } + if (trace_ent.crypto_idfp == "") { return trace_ent; // the player who spawned this object did not have an UID, so anyone can edit it - if (!(trace_ent.realowner != this && autocvar_g_sandbox_editor_free < 2)) + } + if (!(trace_ent.realowner != this && autocvar_g_sandbox_editor_free < 2)) { return trace_ent; // object does not belong to the player, and players can only edit their own objects on this server + } return NULL; } void sandbox_ObjectEdit_Scale(entity e, float f) { e.scale = f; - if(e.scale) - { + if (e.scale) { e.scale = bound(autocvar_g_sandbox_object_scale_min, e.scale, autocvar_g_sandbox_object_scale_max); - _setmodel(e, e.model); // reset mins and maxs based on mesh + _setmodel(e, e.model); // reset mins and maxs based on mesh setsize(e, e.mins * e.scale, e.maxs * e.scale); // adapt bounding box size to model size } } @@ -130,7 +138,7 @@ void sandbox_ObjectAttach_Set(entity e, entity parent, string s) // we can't attach to an attachment, for obvious reasons sandbox_ObjectAttach_Remove(e); - e.old_solid = e.solid; // persist solidity + e.old_solid = e.solid; // persist solidity e.old_movetype = e.move_movetype; // persist physics set_movetype(e, MOVETYPE_FOLLOW); e.solid = SOLID_NOT; @@ -152,9 +160,9 @@ void sandbox_ObjectAttach_Remove(entity e) // objects change origin and angles when detached, so apply previous position setorigin(it, org); - it.angles = e.angles; // don't allow detached objects to spin or roll + it.angles = e.angles; // don't allow detached objects to spin or roll - it.solid = it.old_solid; // restore persisted solidity + it.solid = it.old_solid; // restore persisted solidity set_movetype(it, it.old_movetype); // restore persisted physics it.takedamage = DAMAGE_AIM; }); @@ -176,20 +184,20 @@ entity sandbox_ObjectSpawn(entity this, float database) settouch(e, sandbox_ObjectFunction_Touch); setthink(e, sandbox_ObjectFunction_Think); e.nextthink = time; - //e.effects |= EF_SELECTABLE; // don't do this all the time, maybe just when editing objects? + // e.effects |= EF_SELECTABLE; // don't do this all the time, maybe just when editing objects? - if(!database) - { + if (!database) { // set the object's owner via player UID // if the player does not have an UID, the owner cannot be stored and his objects may be edited by anyone - if(this.crypto_idfp != "") + if (this.crypto_idfp != "") { e.crypto_idfp = strzone(this.crypto_idfp); - else + } else { print_to(this, "^1SANDBOX - WARNING: ^7You spawned an object, but lack a player UID. ^1Your objects are not secured and can be edited by any player!"); + } // set public object information - e.netname = strzone(this.netname); // name of the owner - e.message = strzone(strftime(true, "%d-%m-%Y %H:%M:%S")); // creation time + e.netname = strzone(this.netname); // name of the owner + e.message = strzone(strftime(true, "%d-%m-%Y %H:%M:%S")); // creation time e.message2 = strzone(strftime(true, "%d-%m-%Y %H:%M:%S")); // last editing time // set origin and direction based on player position and view angle @@ -210,13 +218,14 @@ void sandbox_ObjectRemove(entity e) sandbox_ObjectAttach_Remove(e); // detach child objects // if the object being removed has been selected for attachment by a player, unset it - FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.object_attach == e, { it.object_attach = NULL; }); - - if(e.material) { strunzone(e.material); e.material = string_null; } - if(e.crypto_idfp) { strunzone(e.crypto_idfp); e.crypto_idfp = string_null; } - if(e.netname) { strunzone(e.netname); e.netname = string_null; } - if(e.message) { strunzone(e.message); e.message = string_null; } - if(e.message2) { strunzone(e.message2); e.message2 = string_null; } + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.object_attach == e, { it.object_attach = NULL; + }); + + if (e.material) { strunzone(e.material); e.material = string_null; } + if (e.crypto_idfp) { strunzone(e.crypto_idfp); e.crypto_idfp = string_null; } + if (e.netname) { strunzone(e.netname); e.netname = string_null; } + if (e.message) { strunzone(e.message); e.message = string_null; } + if (e.message2) { strunzone(e.message2); e.message2 = string_null; } delete(e); e = NULL; @@ -232,44 +241,38 @@ string sandbox_ObjectPort_Save(entity e, bool database) // order doesn't really matter, as we're writing the file fresh IL_EACH(g_sandbox_objects, it == e || it.owner == e, LAMBDA( - // the main object needs to be first in the array [0] with attached objects following + // the main object needs to be first in the array [0] with attached objects following int slot, physics, solidity; - if(it == e) // this is the main object, place it first - { - slot = 0; - solidity = it.solid; // applied solidity is normal solidity for children - physics = it.move_movetype; // applied physics are normal physics for parents - } - else if(it.owner == e) // child object, list them in order - { - o += 1; // children start from 1 - slot = o; - solidity = it.old_solid; // persisted solidity is normal solidity for children - physics = it.old_movetype; // persisted physics are normal physics for children - gettaginfo(it.owner, it.tag_index); // get the name of the tag our object is attached to, used further below - } - else - continue; + if (it == e) { // this is the main object, place it first + slot = 0; + solidity = it.solid; // applied solidity is normal solidity for children + physics = it.move_movetype; // applied physics are normal physics for parents + } else if (it.owner == e) { // child object, list them in order + o += 1; // children start from 1 + slot = o; + solidity = it.old_solid; // persisted solidity is normal solidity for children + physics = it.old_movetype; // persisted physics are normal physics for children + gettaginfo(it.owner, it.tag_index); // get the name of the tag our object is attached to, used further below + } else { + continue; + } - // ---------------- OBJECT PROPERTY STORAGE: SAVE ---------------- - if(slot) - { - // properties stored only for child objects - if(gettaginfo_name) - port_string[slot] = strcat(port_string[slot], "\"", gettaginfo_name, "\" "); - else - port_string[slot] = strcat(port_string[slot], "\"\" "); // none + // ---------------- OBJECT PROPERTY STORAGE: SAVE ---------------- + if (slot) { + // properties stored only for child objects + if (gettaginfo_name) { + port_string[slot] = strcat(port_string[slot], "\"", gettaginfo_name, "\" "); + } else { + port_string[slot] = strcat(port_string[slot], "\"\" "); // none } - else - { - // properties stored only for parent objects - if(database) - { - port_string[slot] = strcat(port_string[slot], sprintf("\"%.9v\"", it.origin), " "); - port_string[slot] = strcat(port_string[slot], sprintf("\"%.9v\"", it.angles), " "); - } + } else { + // properties stored only for parent objects + if (database) { + port_string[slot] = strcat(port_string[slot], sprintf("\"%.9v\"", it.origin), " "); + port_string[slot] = strcat(port_string[slot], sprintf("\"%.9v\"", it.angles), " "); } - // properties stored for all objects + } + // properties stored for all objects port_string[slot] = strcat(port_string[slot], "\"", it.model, "\" "); port_string[slot] = strcat(port_string[slot], ftos(it.skin), " "); port_string[slot] = strcat(port_string[slot], ftos(it.alpha), " "); @@ -280,29 +283,30 @@ string sandbox_ObjectPort_Save(entity e, bool database) port_string[slot] = strcat(port_string[slot], ftos(solidity), " "); port_string[slot] = strcat(port_string[slot], ftos(physics), " "); port_string[slot] = strcat(port_string[slot], ftos(it.damageforcescale), " "); - if(it.material) - port_string[slot] = strcat(port_string[slot], "\"", it.material, "\" "); - else + if (it.material) { + port_string[slot] = strcat(port_string[slot], "\"", it.material, "\" "); + } else { + port_string[slot] = strcat(port_string[slot], "\"\" "); // none + } + if (database) { + // properties stored only for the database + if (it.crypto_idfp) { + port_string[slot] = strcat(port_string[slot], "\"", it.crypto_idfp, "\" "); + } else { port_string[slot] = strcat(port_string[slot], "\"\" "); // none - if(database) - { - // properties stored only for the database - if(it.crypto_idfp) - port_string[slot] = strcat(port_string[slot], "\"", it.crypto_idfp, "\" "); - else - port_string[slot] = strcat(port_string[slot], "\"\" "); // none - port_string[slot] = strcat(port_string[slot], "\"", e.netname, "\" "); - port_string[slot] = strcat(port_string[slot], "\"", e.message, "\" "); - port_string[slot] = strcat(port_string[slot], "\"", e.message2, "\" "); } - )); + port_string[slot] = strcat(port_string[slot], "\"", e.netname, "\" "); + port_string[slot] = strcat(port_string[slot], "\"", e.message, "\" "); + port_string[slot] = strcat(port_string[slot], "\"", e.message2, "\" "); + } + )); // now apply the array to a simple string, with the ; symbol separating objects string s = ""; - for(int j = 0; j <= MAX_STORAGE_ATTACHMENTS; ++j) - { - if(port_string[j]) + for (int j = 0; j <= MAX_STORAGE_ATTACHMENTS; ++j) { + if (port_string[j]) { s = strcat(s, port_string[j], "; "); + } port_string[j] = string_null; // fully clear the string } @@ -317,12 +321,12 @@ entity sandbox_ObjectPort_Load(entity this, string s, float database) // separate objects between the ; symbols n = tokenizebyseparator(s, "; "); - for(i = 0; i < n; ++i) + for (i = 0; i < n; ++i) { port_string[i] = argv(i); + } // now separate and apply the properties of each object - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { float argv_num; string tagname = string_null; argv_num = 0; @@ -330,51 +334,62 @@ entity sandbox_ObjectPort_Load(entity this, string s, float database) e = sandbox_ObjectSpawn(this, database); // ---------------- OBJECT PROPERTY STORAGE: LOAD ---------------- - if(i) - { + if (i) { // properties stored only for child objects - if(argv(argv_num) != "") tagname = argv(argv_num); else tagname = string_null; ++argv_num; - } - else - { + if (argv(argv_num) != "") { tagname = argv(argv_num); } else { tagname = string_null; } ++argv_num; + } else { // properties stored only for parent objects - if(database) - { - setorigin(e, stov(argv(argv_num))); ++argv_num; - e.angles = stov(argv(argv_num)); ++argv_num; + if (database) { + setorigin(e, stov(argv(argv_num))); + ++argv_num; + e.angles = stov(argv(argv_num)); + ++argv_num; } parent = e; // mark parent objects as such } // properties stored for all objects - _setmodel(e, argv(argv_num)); ++argv_num; - e.skin = stof(argv(argv_num)); ++argv_num; - e.alpha = stof(argv(argv_num)); ++argv_num; - e.colormod = stov(argv(argv_num)); ++argv_num; - e.glowmod = stov(argv(argv_num)); ++argv_num; - e.frame = stof(argv(argv_num)); ++argv_num; - sandbox_ObjectEdit_Scale(e, stof(argv(argv_num))); ++argv_num; - e.solid = e.old_solid = stof(argv(argv_num)); ++argv_num; - e.old_movetype = stof(argv(argv_num)); ++argv_num; + _setmodel(e, argv(argv_num)); + ++argv_num; + e.skin = stof(argv(argv_num)); + ++argv_num; + e.alpha = stof(argv(argv_num)); + ++argv_num; + e.colormod = stov(argv(argv_num)); + ++argv_num; + e.glowmod = stov(argv(argv_num)); + ++argv_num; + e.frame = stof(argv(argv_num)); + ++argv_num; + sandbox_ObjectEdit_Scale(e, stof(argv(argv_num))); + ++argv_num; + e.solid = e.old_solid = stof(argv(argv_num)); + ++argv_num; + e.old_movetype = stof(argv(argv_num)); + ++argv_num; set_movetype(e, e.old_movetype); - e.damageforcescale = stof(argv(argv_num)); ++argv_num; - if(e.material) strunzone(e.material); if(argv(argv_num) != "") e.material = strzone(argv(argv_num)); else e.material = string_null; ++argv_num; - if(database) - { + e.damageforcescale = stof(argv(argv_num)); + ++argv_num; + if (e.material) { strunzone(e.material); } if (argv(argv_num) != "") { e.material = strzone(argv(argv_num)); } else { e.material = string_null; } ++argv_num; + if (database) { // properties stored only for the database - if(e.crypto_idfp) strunzone(e.crypto_idfp); if(argv(argv_num) != "") e.crypto_idfp = strzone(argv(argv_num)); else e.crypto_idfp = string_null; ++argv_num; - if(e.netname) strunzone(e.netname); e.netname = strzone(argv(argv_num)); ++argv_num; - if(e.message) strunzone(e.message); e.message = strzone(argv(argv_num)); ++argv_num; - if(e.message2) strunzone(e.message2); e.message2 = strzone(argv(argv_num)); ++argv_num; + if (e.crypto_idfp) { strunzone(e.crypto_idfp); } if (argv(argv_num) != "") { e.crypto_idfp = strzone(argv(argv_num)); } else { e.crypto_idfp = string_null; } ++argv_num; + if (e.netname) { strunzone(e.netname); } e.netname = strzone(argv(argv_num)); + ++argv_num; + if (e.message) { strunzone(e.message); } e.message = strzone(argv(argv_num)); + ++argv_num; + if (e.message2) { strunzone(e.message2); } e.message2 = strzone(argv(argv_num)); + ++argv_num; } // attach last - if(i) + if (i) { sandbox_ObjectAttach_Set(e, parent, tagname); + } } - for(i = 0; i <= MAX_STORAGE_ATTACHMENTS; ++i) + for (i = 0; i <= MAX_STORAGE_ATTACHMENTS; ++i) { port_string[i] = string_null; // fully clear the string - + } return e; } @@ -405,63 +420,61 @@ void sandbox_Database_Load() file_name = strcat("sandbox/storage_", autocvar_g_sandbox_storage_name, "_", GetMapname(), ".txt"); file_get = fopen(file_name, FILE_READ); - if(file_get < 0) - { - if(autocvar_g_sandbox_info > 0) + if (file_get < 0) { + if (autocvar_g_sandbox_info > 0) { LOG_INFO("^3SANDBOX - SERVER: ^7could not find storage file ^3", file_name, "^7, no objects were loaded"); - } - else - { - for (;;) - { + } + } else { + for ( ; ; ) { file_read = fgets(file_get); - if(file_read == "") + if (file_read == "") { break; - if(substring(file_read, 0, 2) == "//") + } + if (substring(file_read, 0, 2) == "//") { continue; - if(substring(file_read, 0, 1) == "#") + } + if (substring(file_read, 0, 1) == "#") { continue; + } entity e; e = sandbox_ObjectPort_Load(NULL, file_read, true); - if(e.material) - { + if (e.material) { // since objects are being loaded for the first time, precache material sounds for each - for (i = 1; i <= 5; i++) // 5 sounds in total + for (i = 1; i <= 5; i++) { // 5 sounds in total precache_sound(strcat("object/impact_", e.material, "_", ftos(i), ".wav")); + } } } - if(autocvar_g_sandbox_info > 0) + if (autocvar_g_sandbox_info > 0) { LOG_INFO("^3SANDBOX - SERVER: ^7successfully loaded storage file ^3", file_name); + } } fclose(file_get); } MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) { - if(MUTATOR_RETURNVALUE) // command was already handled? + if (MUTATOR_RETURNVALUE) { // command was already handled? return; + } entity player = M_ARGV(0, entity); string cmd_name = M_ARGV(1, string); int cmd_argc = M_ARGV(2, int); - if(cmd_name == "g_sandbox") - { - if(autocvar_g_sandbox_readonly) - { + if (cmd_name == "g_sandbox") { + if (autocvar_g_sandbox_readonly) { print_to(player, "^2SANDBOX - INFO: ^7Sandbox mode is active, but in read-only mode. Sandbox commands cannot be used"); return true; } - if(cmd_argc < 2) - { + if (cmd_argc < 2) { print_to(player, "^2SANDBOX - INFO: ^7Sandbox mode is active. For usage information, type 'sandbox help'"); return true; } - switch(argv(1)) - { + switch (argv(1)) { entity e; int j; string s; @@ -499,24 +512,20 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) // ---------------- COMMAND: OBJECT, SPAWN ---------------- case "object_spawn": - if(time < player.object_flood) - { + if (time < player.object_flood) { print_to(player, strcat("^1SANDBOX - WARNING: ^7Flood protection active. Please wait ^3", ftos(player.object_flood - time), " ^7seconds beofore spawning another object")); return true; } player.object_flood = time + autocvar_g_sandbox_editor_flood; - if(object_count >= autocvar_g_sandbox_editor_maxobjects) - { + if (object_count >= autocvar_g_sandbox_editor_maxobjects) { print_to(player, strcat("^1SANDBOX - WARNING: ^7Cannot spawn any more objects. Up to ^3", ftos(autocvar_g_sandbox_editor_maxobjects), " ^7objects may exist at a time")); return true; } - if(cmd_argc < 3) - { + if (cmd_argc < 3) { print_to(player, "^1SANDBOX - WARNING: ^7Attempted to spawn an object without specifying a model. Please specify the path to your model file after the 'object_spawn' command"); return true; } - if (!(fexists(argv(2)))) - { + if (!(fexists(argv(2)))) { print_to(player, "^1SANDBOX - WARNING: ^7Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct"); return true; } @@ -524,17 +533,18 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) e = sandbox_ObjectSpawn(player, false); _setmodel(e, argv(2)); - if(autocvar_g_sandbox_info > 0) + if (autocvar_g_sandbox_info > 0) { LOG_INFO("^3SANDBOX - SERVER: ^7", player.netname, " spawned an object at origin ^3", vtos(e.origin)); + } return true; // ---------------- COMMAND: OBJECT, REMOVE ---------------- case "object_remove": e = sandbox_ObjectEdit_Get(player, true); - if(e != NULL) - { - if(autocvar_g_sandbox_info > 0) + if (e != NULL) { + if (autocvar_g_sandbox_info > 0) { LOG_INFO("^3SANDBOX - SERVER: ^7", player.netname, " removed an object at origin ^3", vtos(e.origin)); + } sandbox_ObjectRemove(e); return true; } @@ -544,13 +554,11 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) // ---------------- COMMAND: OBJECT, DUPLICATE ---------------- case "object_duplicate": - switch(argv(2)) - { + switch (argv(2)) { case "copy": // copies customizable properties of the selected object to the clipboard cvar e = sandbox_ObjectEdit_Get(player, autocvar_g_sandbox_editor_free); // can we copy objects we can't edit? - if(e != NULL) - { + if (e != NULL) { s = sandbox_ObjectPort_Save(e, false); s = strreplace("\"", "\\\"", s); stuffcmd(player, strcat("set ", argv(3), " \"", s, "\"")); @@ -563,40 +571,36 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) case "paste": // spawns a new object using the properties in the player's clipboard cvar - if(time < player.object_flood) - { + if (time < player.object_flood) { print_to(player, strcat("^1SANDBOX - WARNING: ^7Flood protection active. Please wait ^3", ftos(player.object_flood - time), " ^7seconds beofore spawning another object")); return true; } player.object_flood = time + autocvar_g_sandbox_editor_flood; - if(argv(3) == "") // no object in clipboard - { + if (argv(3) == "") { // no object in clipboard print_to(player, "^1SANDBOX - WARNING: ^7No object in clipboard. You must copy an object before you can paste it"); return true; } - if(object_count >= autocvar_g_sandbox_editor_maxobjects) - { + if (object_count >= autocvar_g_sandbox_editor_maxobjects) { print_to(player, strcat("^1SANDBOX - WARNING: ^7Cannot spawn any more objects. Up to ^3", ftos(autocvar_g_sandbox_editor_maxobjects), " ^7objects may exist at a time")); return true; } e = sandbox_ObjectPort_Load(player, argv(3), false); print_to(player, "^2SANDBOX - INFO: ^7Object pasted successfully"); - if(autocvar_g_sandbox_info > 0) + if (autocvar_g_sandbox_info > 0) { LOG_INFO("^3SANDBOX - SERVER: ^7", player.netname, " pasted an object at origin ^3", vtos(e.origin)); + } return true; } return true; // ---------------- COMMAND: OBJECT, ATTACH ---------------- case "object_attach": - switch(argv(2)) - { + switch (argv(2)) { case "get": // select e as the object as meant to be attached e = sandbox_ObjectEdit_Get(player, true); - if(e != NULL) - { + if (e != NULL) { player.object_attach = e; print_to(player, "^2SANDBOX - INFO: ^7Object selected for attachment"); return true; @@ -604,21 +608,20 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) print_to(player, "^1SANDBOX - WARNING: ^7Object could not be selected for attachment. Make sure you are facing an object that you have edit rights over"); return true; case "set": - if(player.object_attach == NULL) - { + if (player.object_attach == NULL) { print_to(player, "^1SANDBOX - WARNING: ^7No object selected for attachment. Please select an object to be attached first."); return true; } // attaches the previously selected object to e e = sandbox_ObjectEdit_Get(player, true); - if(e != NULL) - { + if (e != NULL) { sandbox_ObjectAttach_Set(player.object_attach, e, argv(3)); player.object_attach = NULL; // object was attached, no longer keep it scheduled for attachment print_to(player, "^2SANDBOX - INFO: ^7Object attached successfully"); - if(autocvar_g_sandbox_info > 1) + if (autocvar_g_sandbox_info > 1) { LOG_INFO("^3SANDBOX - SERVER: ^7", player.netname, " attached objects at origin ^3", vtos(e.origin)); + } return true; } print_to(player, "^1SANDBOX - WARNING: ^7Object could not be attached to the parent. Make sure you are facing an object that you have edit rights over"); @@ -626,12 +629,12 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) case "remove": // removes e if it was attached e = sandbox_ObjectEdit_Get(player, true); - if(e != NULL) - { + if (e != NULL) { sandbox_ObjectAttach_Remove(e); print_to(player, "^2SANDBOX - INFO: ^7Child objects detached successfully"); - if(autocvar_g_sandbox_info > 1) + if (autocvar_g_sandbox_info > 1) { LOG_INFO("^3SANDBOX - SERVER: ^7", player.netname, " detached objects at origin ^3", vtos(e.origin)); + } return true; } print_to(player, "^1SANDBOX - WARNING: ^7Child objects could not be detached. Make sure you are facing an object that you have edit rights over"); @@ -641,17 +644,14 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) // ---------------- COMMAND: OBJECT, EDIT ---------------- case "object_edit": - if(argv(2) == "") - { + if (argv(2) == "") { print_to(player, "^1SANDBOX - WARNING: ^7Too few parameters. You must specify a property to edit"); return true; } e = sandbox_ObjectEdit_Get(player, true); - if(e != NULL) - { - switch(argv(2)) - { + if (e != NULL) { + switch (argv(2)) { case "skin": e.skin = stof(argv(3)); break; @@ -671,8 +671,7 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) sandbox_ObjectEdit_Scale(e, stof(argv(3))); break; case "solidity": - switch(argv(3)) - { + switch (argv(3)) { case "0": // non-solid e.solid = SOLID_TRIGGER; break; @@ -683,8 +682,7 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) break; } case "physics": - switch(argv(3)) - { + switch (argv(3)) { case "0": // static set_movetype(e, MOVETYPE_NONE); break; @@ -702,15 +700,15 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) e.damageforcescale = stof(argv(3)); break; case "material": - if(e.material) strunzone(e.material); - if(argv(3)) - { - for (j = 1; j <= 5; j++) // precache material sounds, 5 in total + if (e.material) { strunzone(e.material); } + if (argv(3)) { + for (j = 1; j <= 5; j++) { // precache material sounds, 5 in total precache_sound(strcat("object/impact_", argv(3), "_", ftos(j), ".wav")); + } e.material = strzone(argv(3)); - } - else + } else { e.material = string_null; // no material + } break; default: print_to(player, "^1SANDBOX - WARNING: ^7Invalid object property. For usage information, type 'sandbox help'"); @@ -718,11 +716,12 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) } // update last editing time - if(e.message2) strunzone(e.message2); + if (e.message2) { strunzone(e.message2); } e.message2 = strzone(strftime(true, "%d-%m-%Y %H:%M:%S")); - if(autocvar_g_sandbox_info > 1) + if (autocvar_g_sandbox_info > 1) { LOG_INFO("^3SANDBOX - SERVER: ^7", player.netname, " edited property ^3", argv(2), " ^7of an object at origin ^3", vtos(e.origin)); + } return true; } @@ -732,31 +731,27 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) // ---------------- COMMAND: OBJECT, CLAIM ---------------- case "object_claim": // if the player can edit an object but is not its owner, this can be used to claim that object - if(player.crypto_idfp == "") - { + if (player.crypto_idfp == "") { print_to(player, "^1SANDBOX - WARNING: ^7You do not have a player UID, and cannot claim objects"); return true; } e = sandbox_ObjectEdit_Get(player, true); - if(e != NULL) - { + if (e != NULL) { // update the owner's name // Do this before checking if you're already the owner and skipping if such, so we // also update the player's nickname if he changed it (but has the same player UID) - if(e.netname != player.netname) - { - if(e.netname) strunzone(e.netname); + if (e.netname != player.netname) { + if (e.netname) { strunzone(e.netname); } e.netname = strzone(player.netname); print_to(player, "^2SANDBOX - INFO: ^7Object owner name updated"); } - if(e.crypto_idfp == player.crypto_idfp) - { + if (e.crypto_idfp == player.crypto_idfp) { print_to(player, "^2SANDBOX - INFO: ^7Object is already yours, nothing to claim"); return true; } - if(e.crypto_idfp) strunzone(e.crypto_idfp); + if (e.crypto_idfp) { strunzone(e.crypto_idfp); } e.crypto_idfp = strzone(player.crypto_idfp); print_to(player, "^2SANDBOX - INFO: ^7Object claimed successfully"); @@ -768,17 +763,15 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) case "object_info": // prints public information about the object to the player e = sandbox_ObjectEdit_Get(player, false); - if(e != NULL) - { - switch(argv(2)) - { + if (e != NULL) { + switch (argv(2)) { case "object": print_to(player, strcat("^2SANDBOX - INFO: ^7Object is owned by \"^7", e.netname, "^7\", created \"^3", e.message, "^7\", last edited \"^3", e.message2, "^7\"")); return true; case "mesh": s = ""; FOR_EACH_TAG(e) - s = strcat(s, "^7\"^5", gettaginfo_name, "^7\", "); + s = strcat(s, "^7\"^5", gettaginfo_name, "^7\", "); print_to(player, strcat("^2SANDBOX - INFO: ^7Object mesh is \"^3", e.model, "^7\" at animation frame ^3", ftos(e.frame), " ^7containing the following tags: ", s)); return true; case "attachments": @@ -786,16 +779,17 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) s = ""; j = 0; IL_EACH(g_sandbox_objects, it.owner == e, - { - ++j; // start from 1 - gettaginfo(e, it.tag_index); - s = strcat(s, "^1attachment ", ftos(j), "^7 has mesh \"^3", it.model, "^7\" at animation frame ^3", ftos(it.frame)); - s = strcat(s, "^7 and is attached to bone \"^5", gettaginfo_name, "^7\", "); - }); - if(j) // object contains attachments + { + ++j; // start from 1 + gettaginfo(e, it.tag_index); + s = strcat(s, "^1attachment ", ftos(j), "^7 has mesh \"^3", it.model, "^7\" at animation frame ^3", ftos(it.frame)); + s = strcat(s, "^7 and is attached to bone \"^5", gettaginfo_name, "^7\", "); + }); + if (j) { // object contains attachments print_to(player, strcat("^2SANDBOX - INFO: ^7Object contains the following ^1", ftos(j), "^7 attachment(s): ", s)); - else + } else { print_to(player, "^2SANDBOX - INFO: ^7Object contains no attachments"); + } return true; } } @@ -812,10 +806,12 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) MUTATOR_HOOKFUNCTION(sandbox, SV_StartFrame) { - if(!autocvar_g_sandbox_storage_autosave) + if (!autocvar_g_sandbox_storage_autosave) { return; - if(time < autosave_time) + } + if (time < autosave_time) { return; + } autosave_time = time + autocvar_g_sandbox_storage_autosave; sandbox_Database_Save(); diff --git a/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qh b/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qh index f6a0afdf4..0f88af689 100644 --- a/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qh +++ b/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qh @@ -1,4 +1,7 @@ #pragma once IntrusiveList g_sandbox_objects; -STATIC_INIT(g_sandbox_objects) { g_sandbox_objects = IL_NEW(); } +STATIC_INIT(g_sandbox_objects) +{ + g_sandbox_objects = IL_NEW(); +} diff --git a/qcsrc/common/mutators/mutator/superspec/sv_superspec.qc b/qcsrc/common/mutators/mutator/superspec/sv_superspec.qc index eb2008235..ae345f27b 100644 --- a/qcsrc/common/mutators/mutator/superspec/sv_superspec.qc +++ b/qcsrc/common/mutators/mutator/superspec/sv_superspec.qc @@ -6,16 +6,16 @@ REGISTER_MUTATOR(superspec, expr_evaluate(autocvar_g_superspectate)); #define _SSMAGIX "SUPERSPEC_OPTIONSFILE_V1" #define _ISLOCAL(ent) ((edict_num(1) == (ent)) ? true : false) -const float ASF_STRENGTH = BIT(0); -const float ASF_SHIELD = BIT(1); -const float ASF_MEGA_AR = BIT(2); -const float ASF_MEGA_HP = BIT(3); -const float ASF_FLAG_GRAB = BIT(4); -const float ASF_OBSERVER_ONLY = BIT(5); -const float ASF_SHOWWHAT = BIT(6); -const float ASF_SSIM = BIT(7); -const float ASF_FOLLOWKILLER = BIT(8); -const float ASF_ALL = 0xFFFFFF; +const float ASF_STRENGTH = BIT(0); +const float ASF_SHIELD = BIT(1); +const float ASF_MEGA_AR = BIT(2); +const float ASF_MEGA_HP = BIT(3); +const float ASF_FLAG_GRAB = BIT(4); +const float ASF_OBSERVER_ONLY = BIT(5); +const float ASF_SHOWWHAT = BIT(6); +const float ASF_SSIM = BIT(7); +const float ASF_FOLLOWKILLER = BIT(8); +const float ASF_ALL = 0xFFFFFF; .float autospec_flags; const float SSF_SILENT = 1; @@ -23,12 +23,13 @@ const float SSF_VERBOSE = 2; const float SSF_ITEMMSG = 4; .float superspec_flags; -.string superspec_itemfilter; //"classname1 classname2 ..." +.string superspec_itemfilter; // "classname1 classname2 ..." bool superspec_Spectate(entity this, entity targ) { - if(Spectate(this, targ) == 1) - TRANSMUTE(Spectator, this); + if (Spectate(this, targ) == 1) { + TRANSMUTE(Spectator, this); + } return true; } @@ -38,21 +39,18 @@ void superspec_save_client_conf(entity this) string fn = "superspec-local.options"; float fh; - if (!_ISLOCAL(this)) - { - if(this.crypto_idfp == "") + if (!_ISLOCAL(this)) { + if (this.crypto_idfp == "") { return; + } fn = sprintf("superspec-%s.options", uri_escape(this.crypto_idfp)); } fh = fopen(fn, FILE_WRITE); - if(fh < 0) - { + if (fh < 0) { LOG_TRACE("^1ERROR: ^7 superspec can not open ", fn, " for writing."); - } - else - { + } else { fputs(fh, _SSMAGIX); fputs(fh, "\n"); fputs(fh, ftos(this.autospec_flags)); @@ -69,12 +67,15 @@ void superspec_msg(string _center_title, string _con_title, entity _to, string _ { sprint(_to, strcat(_con_title, _msg)); - if(_to.superspec_flags & SSF_SILENT) + if (_to.superspec_flags & SSF_SILENT) { return; + } - if(_spamlevel > 1) - if (!(_to.superspec_flags & SSF_VERBOSE)) + if (_spamlevel > 1) { + if (!(_to.superspec_flags & SSF_VERBOSE)) { return; + } + } centerprint(_to, strcat(_center_title, _msg)); } @@ -83,17 +84,19 @@ float superspec_filteritem(entity _for, entity _item) { float i; - if(_for.superspec_itemfilter == "") + if (_for.superspec_itemfilter == "") { return true; + } - if(_for.superspec_itemfilter == "") + if (_for.superspec_itemfilter == "") { return true; + } float l = tokenize_console(_for.superspec_itemfilter); - for(i = 0; i < l; ++i) - { - if(argv(i) == _item.classname) + for (i = 0; i < l; ++i) { + if (argv(i) == _item.classname) { return true; + } } return false; @@ -105,40 +108,37 @@ MUTATOR_HOOKFUNCTION(superspec, ItemTouch) entity toucher = M_ARGV(1, entity); FOREACH_CLIENT(true, { - if(!IS_SPEC(it) && !IS_OBSERVER(it)) + if (!IS_SPEC(it) && !IS_OBSERVER(it)) { continue; - if(it.superspec_flags & SSF_ITEMMSG) - if(superspec_filteritem(it, item)) - { - if(it.superspec_flags & SSF_VERBOSE) + } + if (it.superspec_flags & SSF_ITEMMSG) { + if (superspec_filteritem(it, item)) { + if (it.superspec_flags & SSF_VERBOSE) { superspec_msg("", "", it, sprintf("Player %s^7 just picked up ^3%s\n", toucher.netname, item.netname), 1); - else + } else { superspec_msg("", "", it, sprintf("Player %s^7 just picked up ^3%s\n^8(%s^8)\n", toucher.netname, item.netname, item.classname), 1); - if((it.autospec_flags & ASF_SSIM) && it.enemy != toucher) - { + } + if ((it.autospec_flags & ASF_SSIM) && it.enemy != toucher) { superspec_Spectate(it, toucher); return MUT_ITEMTOUCH_CONTINUE; } } + } - if((it.autospec_flags & ASF_SHIELD && item.invincible_finished) || - (it.autospec_flags & ASF_STRENGTH && item.strength_finished) || - (it.autospec_flags & ASF_MEGA_AR && item.itemdef == ITEM_ArmorMega) || - (it.autospec_flags & ASF_MEGA_HP && item.itemdef == ITEM_HealthMega) || - (it.autospec_flags & ASF_FLAG_GRAB && item.classname == "item_flag_team")) - { - - if((it.enemy != toucher) || IS_OBSERVER(it)) - { - if(it.autospec_flags & ASF_OBSERVER_ONLY && !IS_OBSERVER(it)) - { - if(it.superspec_flags & SSF_VERBOSE) + if ((it.autospec_flags & ASF_SHIELD && item.invincible_finished) + || (it.autospec_flags & ASF_STRENGTH && item.strength_finished) + || (it.autospec_flags & ASF_MEGA_AR && item.itemdef == ITEM_ArmorMega) + || (it.autospec_flags & ASF_MEGA_HP && item.itemdef == ITEM_HealthMega) + || (it.autospec_flags & ASF_FLAG_GRAB && item.classname == "item_flag_team")) { + if ((it.enemy != toucher) || IS_OBSERVER(it)) { + if (it.autospec_flags & ASF_OBSERVER_ONLY && !IS_OBSERVER(it)) { + if (it.superspec_flags & SSF_VERBOSE) { superspec_msg("", "", it, sprintf("^8Ignored that ^7%s^8 grabbed %s^8 since the observer_only option is ON\n", toucher.netname, item.netname), 2); - } - else - { - if(it.autospec_flags & ASF_SHOWWHAT) + } + } else { + if (it.autospec_flags & ASF_SHOWWHAT) { superspec_msg("", "", it, sprintf("^7Following %s^7 due to picking up %s\n", toucher.netname, item.netname), 2); + } superspec_Spectate(it, toucher); } @@ -151,59 +151,55 @@ MUTATOR_HOOKFUNCTION(superspec, ItemTouch) MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand) { -#define OPTIONINFO(flag,var,test,text,long,short) \ - var = strcat(var, ((flag & test) ? "^2[ON] ^7" : "^1[OFF] ^7")); \ - var = strcat(var, text," ^7(^3 ", long, "^7 | ^3", short, " ^7)\n") +#define OPTIONINFO(flag, var, test, text, long, short) \ + var = strcat(var, ((flag & test) ? "^2[ON] ^7" : "^1[OFF] ^7")); \ + var = strcat(var, text, " ^7(^3 ", long, "^7 | ^3", short, " ^7)\n") - if(MUTATOR_RETURNVALUE) // command was already handled? + if (MUTATOR_RETURNVALUE) { // command was already handled? return; + } entity player = M_ARGV(0, entity); string cmd_name = M_ARGV(1, string); int cmd_argc = M_ARGV(2, int); - if(IS_PLAYER(player)) + if (IS_PLAYER(player)) { return; + } - if(cmd_name == "superspec_itemfilter") - { - if(argv(1) == "help") - { + if (cmd_name == "superspec_itemfilter") { + if (argv(1) == "help") { string _aspeco; _aspeco = "^7 superspec_itemfilter ^3\"item_classname1 item_classname2\"^7 only show thise items when ^2superspec ^3item_message^7 is on\n"; _aspeco = strcat(_aspeco, "^3 clear^7 Remove the filter (show all pickups)\n"); _aspeco = strcat(_aspeco, "^3 show ^7 Display current filter\n"); superspec_msg("^3superspec_itemfilter help:\n\n\n", "\n^3superspec_itemfilter help:\n", player, _aspeco, 1); - } - else if(argv(1) == "clear") - { - if(player.superspec_itemfilter != "") + } else if (argv(1) == "clear") { + if (player.superspec_itemfilter != "") { strunzone(player.superspec_itemfilter); + } player.superspec_itemfilter = ""; - } - else if(argv(1) == "show" || argv(1) == "") - { - if(player.superspec_itemfilter == "") - { + } else if (argv(1) == "show" || argv(1) == "") { + if (player.superspec_itemfilter == "") { superspec_msg("^3superspec_itemfilter^7 is ^1not^7 set", "\n^3superspec_itemfilter^7 is ^1not^7 set\n", player, "", 1); return true; } float i; float l = tokenize_console(player.superspec_itemfilter); string _msg = ""; - for(i = 0; i < l; ++i) + for (i = 0; i < l; ++i) { _msg = strcat(_msg, "^3#", ftos(i), " ^7", argv(i), "\n"); - //_msg = sprintf("^3#%d^7 %s\n%s", i, _msg, argv(i)); + } + // _msg = sprintf("^3#%d^7 %s\n%s", i, _msg, argv(i)); - _msg = strcat(_msg,"\n"); + _msg = strcat(_msg, "\n"); superspec_msg("^3superspec_itemfilter is:\n\n\n", "\n^3superspec_itemfilter is:\n", player, _msg, 1); - } - else - { - if(player.superspec_itemfilter != "") + } else { + if (player.superspec_itemfilter != "") { strunzone(player.superspec_itemfilter); + } player.superspec_itemfilter = strzone(argv(1)); } @@ -211,15 +207,12 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand) return true; } - if(cmd_name == "superspec") - { + if (cmd_name == "superspec") { string _aspeco; - if(cmd_argc > 1) - { + if (cmd_argc > 1) { float i, _bits = 0, _start = 1; - if(argv(1) == "help") - { + if (argv(1) == "help") { _aspeco = "use cmd superspec [option] [on|off] to set options\n\n"; _aspeco = strcat(_aspeco, "^3 silent ^7(short^5 si^7) supresses ALL messages from superspectate.\n"); _aspeco = strcat(_aspeco, "^3 verbose ^7(short^5 ve^7) makes superspectate print some additional information.\n"); @@ -229,31 +222,25 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand) return true; } - if(argv(1) == "clear") - { + if (argv(1) == "clear") { player.superspec_flags = 0; _start = 2; } - for(i = _start; i < cmd_argc; ++i) - { - if(argv(i) == "on" || argv(i) == "1") - { + for (i = _start; i < cmd_argc; ++i) { + if (argv(i) == "on" || argv(i) == "1") { player.superspec_flags |= _bits; _bits = 0; - } - else if(argv(i) == "off" || argv(i) == "0") - { - if(_start == 1) + } else if (argv(i) == "off" || argv(i) == "0") { + if (_start == 1) { player.superspec_flags &= ~_bits; + } _bits = 0; - } - else - { - if((argv(i) == "silent") || (argv(i) == "si")) _bits |= SSF_SILENT ; - if((argv(i) == "verbose") || (argv(i) == "ve")) _bits |= SSF_VERBOSE; - if((argv(i) == "item_message") || (argv(i) == "im")) _bits |= SSF_ITEMMSG; + } else { + if ((argv(i) == "silent") || (argv(i) == "si")) { _bits |= SSF_SILENT; } + if ((argv(i) == "verbose") || (argv(i) == "ve")) { _bits |= SSF_VERBOSE; } + if ((argv(i) == "item_message") || (argv(i) == "im")) { _bits |= SSF_ITEMMSG; } } } } @@ -270,13 +257,10 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand) ///////////////////// - if(cmd_name == "autospec") - { + if (cmd_name == "autospec") { string _aspeco; - if(cmd_argc > 1) - { - if(argv(1) == "help") - { + if (cmd_argc > 1) { + if (argv(1) == "help") { _aspeco = "use cmd autospec [option] [on|off] to set options\n\n"; _aspeco = strcat(_aspeco, "^3 strength ^7(short^5 st^7) for automatic spectate on strength powerup\n"); _aspeco = strcat(_aspeco, "^3 shield ^7(short^5 sh^7) for automatic spectate on shield powerup\n"); @@ -293,38 +277,32 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand) } float i, _bits = 0, _start = 1; - if(argv(1) == "clear") - { + if (argv(1) == "clear") { player.autospec_flags = 0; _start = 2; } - for(i = _start; i < cmd_argc; ++i) - { - if(argv(i) == "on" || argv(i) == "1") - { + for (i = _start; i < cmd_argc; ++i) { + if (argv(i) == "on" || argv(i) == "1") { player.autospec_flags |= _bits; _bits = 0; - } - else if(argv(i) == "off" || argv(i) == "0") - { - if(_start == 1) + } else if (argv(i) == "off" || argv(i) == "0") { + if (_start == 1) { player.autospec_flags &= ~_bits; + } _bits = 0; - } - else - { - if((argv(i) == "strength") || (argv(i) == "st")) _bits |= ASF_STRENGTH; - if((argv(i) == "shield") || (argv(i) == "sh")) _bits |= ASF_SHIELD; - if((argv(i) == "mega_health") || (argv(i) == "mh")) _bits |= ASF_MEGA_HP; - if((argv(i) == "mega_armor") || (argv(i) == "ma")) _bits |= ASF_MEGA_AR; - if((argv(i) == "flag_grab") || (argv(i) == "fg")) _bits |= ASF_FLAG_GRAB; - if((argv(i) == "observer_only") || (argv(i) == "oo")) _bits |= ASF_OBSERVER_ONLY; - if((argv(i) == "show_what") || (argv(i) == "sw")) _bits |= ASF_SHOWWHAT; - if((argv(i) == "item_msg") || (argv(i) == "im")) _bits |= ASF_SSIM; - if((argv(i) == "followkiller") || (argv(i) == "fk")) _bits |= ASF_FOLLOWKILLER; - if((argv(i) == "all") || (argv(i) == "aa")) _bits |= ASF_ALL; + } else { + if ((argv(i) == "strength") || (argv(i) == "st")) { _bits |= ASF_STRENGTH; } + if ((argv(i) == "shield") || (argv(i) == "sh")) { _bits |= ASF_SHIELD; } + if ((argv(i) == "mega_health") || (argv(i) == "mh")) { _bits |= ASF_MEGA_HP; } + if ((argv(i) == "mega_armor") || (argv(i) == "ma")) { _bits |= ASF_MEGA_AR; } + if ((argv(i) == "flag_grab") || (argv(i) == "fg")) { _bits |= ASF_FLAG_GRAB; } + if ((argv(i) == "observer_only") || (argv(i) == "oo")) { _bits |= ASF_OBSERVER_ONLY; } + if ((argv(i) == "show_what") || (argv(i) == "sw")) { _bits |= ASF_SHOWWHAT; } + if ((argv(i) == "item_msg") || (argv(i) == "im")) { _bits |= ASF_SSIM; } + if ((argv(i) == "followkiller") || (argv(i) == "fk")) { _bits |= ASF_FOLLOWKILLER; } + if ((argv(i) == "all") || (argv(i) == "aa")) { _bits |= ASF_ALL; } } } } @@ -334,7 +312,7 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand) OPTIONINFO(player.autospec_flags, _aspeco, ASF_SHIELD, "Shield", "shield", "sh"); OPTIONINFO(player.autospec_flags, _aspeco, ASF_MEGA_HP, "Mega Health", "mega_health", "mh"); OPTIONINFO(player.autospec_flags, _aspeco, ASF_MEGA_AR, "Mega Armor", "mega_armor", "ma"); - OPTIONINFO(player.autospec_flags, _aspeco, ASF_FLAG_GRAB, "Flag grab", "flag_grab","fg"); + OPTIONINFO(player.autospec_flags, _aspeco, ASF_FLAG_GRAB, "Flag grab", "flag_grab", "fg"); OPTIONINFO(player.autospec_flags, _aspeco, ASF_OBSERVER_ONLY, "Only switch if observer", "observer_only", "oo"); OPTIONINFO(player.autospec_flags, _aspeco, ASF_SHOWWHAT, "Show what item triggered spectate", "show_what", "sw"); OPTIONINFO(player.autospec_flags, _aspeco, ASF_SSIM, "Switch on superspec item message", "item_msg", "im"); @@ -344,25 +322,25 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand) return true; } - if(cmd_name == "followpowerup") - { - FOREACH_CLIENT(IS_PLAYER(it) && (it.strength_finished > time || it.invincible_finished > time), { return superspec_Spectate(player, it); }); + if (cmd_name == "followpowerup") { + FOREACH_CLIENT(IS_PLAYER(it) && (it.strength_finished > time || it.invincible_finished > time), { return superspec_Spectate(player, it); + }); superspec_msg("", "", player, "No active powerup\n", 1); return true; } - if(cmd_name == "followstrength") - { - FOREACH_CLIENT(IS_PLAYER(it) && it.strength_finished > time, { return superspec_Spectate(player, it); }); + if (cmd_name == "followstrength") { + FOREACH_CLIENT(IS_PLAYER(it) && it.strength_finished > time, { return superspec_Spectate(player, it); + }); superspec_msg("", "", player, "No active Strength\n", 1); return true; } - if(cmd_name == "followshield") - { - FOREACH_CLIENT(IS_PLAYER(it) && it.invincible_finished > time, { return superspec_Spectate(player, it); }); + if (cmd_name == "followshield") { + FOREACH_CLIENT(IS_PLAYER(it) && it.invincible_finished > time, { return superspec_Spectate(player, it); + }); superspec_msg("", "", player, "No active Shield\n", 1); return true; @@ -382,8 +360,9 @@ MUTATOR_HOOKFUNCTION(superspec, BuildMutatorsPrettyString) void superspec_hello(entity this) { - if(this.enemy.crypto_idfp == "") + if (this.enemy.crypto_idfp == "") { Send_Notification(NOTIF_ONE_ONLY, this.enemy, MSG_INFO, INFO_SUPERSPEC_MISSING_UID); + } delete(this); } @@ -392,8 +371,9 @@ MUTATOR_HOOKFUNCTION(superspec, ClientConnect) { entity player = M_ARGV(0, entity); - if(!IS_REAL_CLIENT(player)) + if (!IS_REAL_CLIENT(player)) { return; + } string fn = "superspec-local.options"; float fh; @@ -406,28 +386,22 @@ MUTATOR_HOOKFUNCTION(superspec, ClientConnect) setthink(_hello, superspec_hello); _hello.nextthink = time + 5; - if (!_ISLOCAL(player)) - { - if(player.crypto_idfp == "") + if (!_ISLOCAL(player)) { + if (player.crypto_idfp == "") { return; + } fn = sprintf("superspec-%s.options", uri_escape(player.crypto_idfp)); } fh = fopen(fn, FILE_READ); - if(fh < 0) - { + if (fh < 0) { LOG_TRACE("^1ERROR: ^7 superspec can not open ", fn, " for reading."); - } - else - { + } else { string _magic = fgets(fh); - if(_magic != _SSMAGIX) - { + if (_magic != _SSMAGIX) { LOG_TRACE("^1ERROR^7 While reading superspec options file: unknown magic"); - } - else - { + } else { player.autospec_flags = stof(fgets(fh)); player.superspec_flags = stof(fgets(fh)); player.superspec_itemfilter = strzone(fgets(fh)); @@ -442,10 +416,10 @@ MUTATOR_HOOKFUNCTION(superspec, PlayerDies) entity frag_target = M_ARGV(2, entity); FOREACH_CLIENT(IS_SPEC(it), { - if(it.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && it.enemy == frag_target) - { - if(it.autospec_flags & ASF_SHOWWHAT) + if (it.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && it.enemy == frag_target) { + if (it.autospec_flags & ASF_SHOWWHAT) { superspec_msg("", "", it, sprintf("^7Following %s^7 due to followkiller\n", frag_attacker.netname), 2); + } superspec_Spectate(it, frag_attacker); } diff --git a/qcsrc/common/mutators/mutator/touchexplode/sv_touchexplode.qc b/qcsrc/common/mutators/mutator/touchexplode/sv_touchexplode.qc index a1b38fb6e..6e683d70c 100644 --- a/qcsrc/common/mutators/mutator/touchexplode/sv_touchexplode.qc +++ b/qcsrc/common/mutators/mutator/touchexplode/sv_touchexplode.qc @@ -28,21 +28,30 @@ MUTATOR_HOOKFUNCTION(touchexplode, PlayerPreThink) { entity player = M_ARGV(0, entity); - if(time > player.touchexplode_time) - if(!game_stopped) - if(!STAT(FROZEN, player)) - if(IS_PLAYER(player)) - if(!IS_DEAD(player)) - if(!IS_INDEPENDENT_PLAYER(player)) - FOREACH_CLIENT(IS_PLAYER(it) && it != player, { - if(time > it.touchexplode_time) - if(!STAT(FROZEN, it)) - if(!IS_DEAD(it)) - if (!IS_INDEPENDENT_PLAYER(it)) - if(boxesoverlap(player.absmin, player.absmax, it.absmin, it.absmax)) - { - PlayerTouchExplode(player, it); - player.touchexplode_time = it.touchexplode_time = time + 0.2; + if (time > player.touchexplode_time) { + if (!game_stopped) { + if (!STAT(FROZEN, player)) { + if (IS_PLAYER(player)) { + if (!IS_DEAD(player)) { + if (!IS_INDEPENDENT_PLAYER(player)) { + FOREACH_CLIENT(IS_PLAYER(it) && it != player, { + if (time > it.touchexplode_time) { + if (!STAT(FROZEN, it)) { + if (!IS_DEAD(it)) { + if (!IS_INDEPENDENT_PLAYER(it)) { + if (boxesoverlap(player.absmin, player.absmax, it.absmin, it.absmax)) { + PlayerTouchExplode(player, it); + player.touchexplode_time = it.touchexplode_time = time + 0.2; + } + } + } + } + } + }); + } + } + } } - }); + } + } } diff --git a/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc b/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc index 199b4e202..4b25227ae 100644 --- a/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc +++ b/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc @@ -9,12 +9,13 @@ MUTATOR_HOOKFUNCTION(vampire, PlayerDamage_SplitHealthArmor) entity frag_target = M_ARGV(2, entity); float damage_take = M_ARGV(4, float); - if(time >= frag_target.spawnshieldtime) - if(frag_target != frag_attacker) - if(!IS_DEAD(frag_target)) - { - GiveResource(frag_attacker, RESOURCE_HEALTH, - bound(0, damage_take, frag_target.health)); + if (time >= frag_target.spawnshieldtime) { + if (frag_target != frag_attacker) { + if (!IS_DEAD(frag_target)) { + GiveResource(frag_attacker, RESOURCE_HEALTH, + bound(0, damage_take, frag_target.health)); + } + } } } diff --git a/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc b/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc index ce9e27065..0bfc8dfc9 100644 --- a/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc +++ b/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc @@ -16,23 +16,30 @@ MUTATOR_HOOKFUNCTION(vh, GrappleHookThink) entity dmgent = ((SAME_TEAM(thehook.owner, thehook.aiment) && autocvar_g_vampirehook_teamheal) ? thehook.owner : thehook.aiment); - if(IS_PLAYER(thehook.aiment)) - if(thehook.last_dmg < time) - if(!STAT(FROZEN, thehook.aiment)) - if(time >= game_starttime) - if(DIFF_TEAM(thehook.owner, thehook.aiment) || autocvar_g_vampirehook_teamheal) - if(thehook.aiment.health > 0) - if(autocvar_g_vampirehook_damage) - { - thehook.last_dmg = time + autocvar_g_vampirehook_damagerate; - thehook.owner.damage_dealt += autocvar_g_vampirehook_damage; - Damage(dmgent, thehook, thehook.owner, autocvar_g_vampirehook_damage, WEP_HOOK.m_id, thehook.origin, '0 0 0'); - if(SAME_TEAM(thehook.owner, thehook.aiment)) - thehook.aiment.health = min(thehook.aiment.health + autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); - else - thehook.owner.health = min(thehook.owner.health + autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); + if (IS_PLAYER(thehook.aiment)) { + if (thehook.last_dmg < time) { + if (!STAT(FROZEN, thehook.aiment)) { + if (time >= game_starttime) { + if (DIFF_TEAM(thehook.owner, thehook.aiment) || autocvar_g_vampirehook_teamheal) { + if (thehook.aiment.health > 0) { + if (autocvar_g_vampirehook_damage) { + thehook.last_dmg = time + autocvar_g_vampirehook_damagerate; + thehook.owner.damage_dealt += autocvar_g_vampirehook_damage; + Damage(dmgent, thehook, thehook.owner, autocvar_g_vampirehook_damage, WEP_HOOK.m_id, thehook.origin, '0 0 0'); + if (SAME_TEAM(thehook.owner, thehook.aiment)) { + thehook.aiment.health = min(thehook.aiment.health + autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); + } else { + thehook.owner.health = min(thehook.owner.health + autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); + } - if(dmgent == thehook.owner) - dmgent.health -= autocvar_g_vampirehook_damage; // FIXME: friendly fire?! + if (dmgent == thehook.owner) { + dmgent.health -= autocvar_g_vampirehook_damage; // FIXME: friendly fire?! + } + } + } + } + } + } + } } } diff --git a/qcsrc/common/mutators/mutator/walljump/walljump.qc b/qcsrc/common/mutators/mutator/walljump/walljump.qc index c462a7e2b..c633f385b 100644 --- a/qcsrc/common/mutators/mutator/walljump/walljump.qc +++ b/qcsrc/common/mutators/mutator/walljump/walljump.qc @@ -7,19 +7,21 @@ REGISTER_MUTATOR(walljump, true); REGISTER_MUTATOR(walljump, autocvar_g_walljump); #endif -#define PHYS_WALLJUMP(s) STAT(WALLJUMP, s) -#define PHYS_WALLJUMP_VELOCITY_Z_FACTOR(s) STAT(WALLJUMP_VELOCITY_Z_FACTOR, s) -#define PHYS_WALLJUMP_VELOCITY_XY_FACTOR(s) STAT(WALLJUMP_VELOCITY_XY_FACTOR, s) -#define PHYS_WALLJUMP_DELAY(s) STAT(WALLJUMP_DELAY, s) -#define PHYS_WALLJUMP_FORCE(s) STAT(WALLJUMP_FORCE, s) +#define PHYS_WALLJUMP(s) STAT(WALLJUMP, s) +#define PHYS_WALLJUMP_VELOCITY_Z_FACTOR(s) STAT(WALLJUMP_VELOCITY_Z_FACTOR, s) +#define PHYS_WALLJUMP_VELOCITY_XY_FACTOR(s) STAT(WALLJUMP_VELOCITY_XY_FACTOR, s) +#define PHYS_WALLJUMP_DELAY(s) STAT(WALLJUMP_DELAY, s) +#define PHYS_WALLJUMP_FORCE(s) STAT(WALLJUMP_FORCE, s) vector PlayerTouchWall(entity this) { #define TRACE(newvec) \ - tracebox (start, this.mins, this.maxs, (newvec), true, this); \ - if (trace_fraction < 1 && vdist(this.origin - trace_endpos, <, dist) && trace_plane_normal_z < max_normal) \ - if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)) \ - return trace_plane_normal; + tracebox(start, this.mins, this.maxs, (newvec), true, this); \ + if (trace_fraction < 1 && vdist(this.origin - trace_endpos, <, dist) && trace_plane_normal_z < max_normal) { \ + if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)) { \ + return trace_plane_normal; \ + } \ + } float dist = 10, max_normal = 0.2, scaler = 100; vector start = this.origin; @@ -35,37 +37,41 @@ MUTATOR_HOOKFUNCTION(walljump, PlayerJump) { entity player = M_ARGV(0, entity); - if(PHYS_WALLJUMP(player)) - if(time - STAT(LASTWJ, player) > PHYS_WALLJUMP_DELAY(player)) // can't do this on client, as it's too stupid to obey counters - if(!IS_ONGROUND(player)) - if(player.move_movetype != MOVETYPE_NONE && player.move_movetype != MOVETYPE_FOLLOW && player.move_movetype != MOVETYPE_FLY && player.move_movetype != MOVETYPE_NOCLIP) - if(!IS_JUMP_HELD(player)) - if(!STAT(FROZEN, player)) - if(!IS_DEAD(player)) - { - vector plane_normal = PlayerTouchWall(player); + if (PHYS_WALLJUMP(player)) { + if (time - STAT(LASTWJ, player) > PHYS_WALLJUMP_DELAY(player)) { // can't do this on client, as it's too stupid to obey counters + if (!IS_ONGROUND(player)) { + if (player.move_movetype != MOVETYPE_NONE && player.move_movetype != MOVETYPE_FOLLOW && player.move_movetype != MOVETYPE_FLY && player.move_movetype != MOVETYPE_NOCLIP) { + if (!IS_JUMP_HELD(player)) { + if (!STAT(FROZEN, player)) { + if (!IS_DEAD(player)) { + vector plane_normal = PlayerTouchWall(player); - if(plane_normal != '0 0 0') - { - float wj_force = PHYS_WALLJUMP_FORCE(player); - float wj_xy_factor = PHYS_WALLJUMP_VELOCITY_XY_FACTOR(player); - float wj_z_factor = PHYS_WALLJUMP_VELOCITY_Z_FACTOR(player); - player.velocity_x += plane_normal_x * wj_force; - player.velocity_x /= wj_xy_factor; - player.velocity_y += plane_normal_y * wj_force; - player.velocity_y /= wj_xy_factor; - player.velocity_z = PHYS_JUMPVELOCITY(player) * wj_z_factor; - if(PHYS_INPUT_BUTTON_CROUCH(player)) player.velocity_z *= -1; + if (plane_normal != '0 0 0') { + float wj_force = PHYS_WALLJUMP_FORCE(player); + float wj_xy_factor = PHYS_WALLJUMP_VELOCITY_XY_FACTOR(player); + float wj_z_factor = PHYS_WALLJUMP_VELOCITY_Z_FACTOR(player); + player.velocity_x += plane_normal_x * wj_force; + player.velocity_x /= wj_xy_factor; + player.velocity_y += plane_normal_y * wj_force; + player.velocity_y /= wj_xy_factor; + player.velocity_z = PHYS_JUMPVELOCITY(player) * wj_z_factor; + if (PHYS_INPUT_BUTTON_CROUCH(player)) { player.velocity_z *= -1; } #ifdef SVQC - STAT(LASTWJ, player) = time; - player.oldvelocity = player.velocity; - Send_Effect(EFFECT_SMOKE_RING, trace_endpos, plane_normal, 5); - PlayerSound(player, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND); - animdecide_setaction(player, ANIMACTION_JUMP, true); + STAT(LASTWJ, player) = time; + player.oldvelocity = player.velocity; + Send_Effect(EFFECT_SMOKE_RING, trace_endpos, plane_normal, 5); + PlayerSound(player, playersound_jump, CH_PLAYER, VOL_BASE, VOICETYPE_PLAYERSOUND); + animdecide_setaction(player, ANIMACTION_JUMP, true); #endif - M_ARGV(2, bool) = true; // multijump + M_ARGV(2, bool) = true; // multijump + } + } + } + } + } + } } } } diff --git a/qcsrc/common/mutators/mutator/waypoints/all.qh b/qcsrc/common/mutators/mutator/waypoints/all.qh index 77c431200..699b4a959 100644 --- a/qcsrc/common/mutators/mutator/waypoints/all.qh +++ b/qcsrc/common/mutators/mutator/waypoints/all.qh @@ -11,18 +11,19 @@ REGISTRY_CHECK(Waypoints) #define REGISTER_WAYPOINT_(id, init) REGISTER(Waypoints, WP, id, m_id, init) CLASS(Waypoint, Object) - ATTRIB(Waypoint, m_id, int, 0); - ATTRIB(Waypoint, netname, string); - ATTRIB(Waypoint, m_name, string); - ATTRIB(Waypoint, m_color, vector, '1 1 1'); - ATTRIB(Waypoint, m_blink, int, 1); - CONSTRUCTOR(Waypoint, string _netname, string _name, vector _color, int _blink) { - CONSTRUCT(Waypoint); - this.netname = _netname; - this.m_name = _name; - this.m_color = _color; - this.m_blink = _blink; - } + ATTRIB(Waypoint, m_id, int, 0); + ATTRIB(Waypoint, netname, string); + ATTRIB(Waypoint, m_name, string); + ATTRIB(Waypoint, m_color, vector, '1 1 1'); + ATTRIB(Waypoint, m_blink, int, 1); + CONSTRUCTOR(Waypoint, string _netname, string _name, vector _color, int _blink) + { + CONSTRUCT(Waypoint); + this.netname = _netname; + this.m_name = _name; + this.m_color = _color; + this.m_blink = _blink; + } ENDCLASS(Waypoint) #define REGISTER_WAYPOINT(id, text, color, blink) REGISTER_WAYPOINT_(id, NEW(Waypoint, #id, text, color, blink)) @@ -33,7 +34,11 @@ REGISTER_REGISTRY(RadarIcons) REGISTRY_CHECK(RadarIcons) .int m_radaricon; -#define REGISTER_RADARICON(id, num) REGISTER(RadarIcons, RADARICON, id, m_id, new_pure(RadarIcon)) { this.m_radaricon = num; this.netname = #id; } +#define REGISTER_RADARICON(id, num) \ + REGISTER(RadarIcons, RADARICON, id, m_id, new_pure(RadarIcon)) \ + { \ + this.m_radaricon = num; this.netname = #id; \ + } REGISTER_WAYPOINT(Null, "", '0 0 0', 1); diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh index 6a8d57157..2079ed4b4 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh @@ -11,21 +11,21 @@ const int SPRITERULE_SPECTATOR = 2; #ifdef CSQC entityclass(WaypointSprite); -class(WaypointSprite) .float helpme; -class(WaypointSprite) .float rule; -class(WaypointSprite) .string netname; // primary picture -class(WaypointSprite) .string netname2; // secondary picture -class(WaypointSprite) .string netname3; // tertiary picture -class(WaypointSprite) .int team; // team that gets netname2 -class(WaypointSprite) .float lifetime; -class(WaypointSprite) .float fadetime; -class(WaypointSprite) .float maxdistance; -class(WaypointSprite) .int hideflags; -class(WaypointSprite) .float spawntime; -class(WaypointSprite) .float health; -class(WaypointSprite) .float build_started; -class(WaypointSprite) .float build_starthealth; -class(WaypointSprite) .float build_finished; +class(WaypointSprite).float helpme; +class(WaypointSprite).float rule; +class(WaypointSprite).string netname; // primary picture +class(WaypointSprite).string netname2; // secondary picture +class(WaypointSprite).string netname3; // tertiary picture +class(WaypointSprite).int team; // team that gets netname2 +class(WaypointSprite).float lifetime; +class(WaypointSprite).float fadetime; +class(WaypointSprite).float maxdistance; +class(WaypointSprite).int hideflags; +class(WaypointSprite).float spawntime; +class(WaypointSprite).float health; +class(WaypointSprite).float build_started; +class(WaypointSprite).float build_starthealth; +class(WaypointSprite).float build_finished; float autocvar_g_waypointsprite_alpha; float autocvar_g_waypointsprite_crosshairfadealpha; @@ -179,54 +179,32 @@ bool WaypointSprite_SendEntity(entity this, entity to, float sendflags); void WaypointSprite_Reset(entity this); -entity WaypointSprite_Spawn( - entity spr, // sprite - float lifetime, float maxdistance, // lifetime, max distance - entity ref, vector ofs, // position - entity showto, float t, // show to whom? Use a flag to indicate a team - entity own, .entity ownfield, // remove when own gets killed - float hideable, // true when it should be controlled by cl_hidewaypoints - entity icon // initial icon +entity WaypointSprite_Spawn(entity spr, // sprite + float lifetime, float maxdistance, // lifetime, max distance + entity ref, vector ofs, // position + entity showto, float t, // show to whom? Use a flag to indicate a team + entity own, .entity ownfield, // remove when own gets killed + float hideable, // true when it should be controlled by cl_hidewaypoints + entity icon // initial icon ); -entity WaypointSprite_SpawnFixed( - entity spr, - vector ofs, - entity own, - .entity ownfield, - entity icon // initial icon +entity WaypointSprite_SpawnFixed(entity spr, vector ofs, entity own, .entity ownfield, entity icon // initial icon ); .entity waypointsprite_deployed_fixed; -entity WaypointSprite_DeployFixed( - entity spr, - float limited_range, - entity player, - vector ofs, - entity icon // initial icon +entity WaypointSprite_DeployFixed(entity spr, float limited_range, entity player, vector ofs, entity icon // initial icon ); .entity waypointsprite_deployed_personal; -entity WaypointSprite_DeployPersonal( - entity spr, - entity player, - vector ofs, - entity icon // initial icon +entity WaypointSprite_DeployPersonal(entity spr, entity player, vector ofs, entity icon // initial icon ); .entity waypointsprite_attached; .entity waypointsprite_attachedforcarrier; -entity WaypointSprite_Attach( - entity spr, - entity player, - float limited_range, - entity icon // initial icon +entity WaypointSprite_Attach(entity spr, entity player, float limited_range, entity icon // initial icon ); -entity WaypointSprite_AttachCarrier( - entity spr, - entity carrier, - entity icon // initial icon +entity WaypointSprite_AttachCarrier(entity spr, entity carrier, entity icon // initial icon ); void WaypointSprite_DetachCarrier(entity carrier); diff --git a/qcsrc/common/mutators/mutator/weaponarena_random/sv_weaponarena_random.qc b/qcsrc/common/mutators/mutator/weaponarena_random/sv_weaponarena_random.qc index 7ac4504ec..8cd47d3eb 100644 --- a/qcsrc/common/mutators/mutator/weaponarena_random/sv_weaponarena_random.qc +++ b/qcsrc/common/mutators/mutator/weaponarena_random/sv_weaponarena_random.qc @@ -5,10 +5,10 @@ REGISTER_MUTATOR(weaponarena_random, true); MUTATOR_HOOKFUNCTION(weaponarena_random, PlayerSpawn) { - if (!g_weaponarena_random) return; - entity player = M_ARGV(0, entity); + if (!g_weaponarena_random) { return; } + entity player = M_ARGV(0, entity); - if (g_weaponarena_random_with_blaster) player.weapons &= ~WEPSET(BLASTER); - W_RandomWeapons(player, g_weaponarena_random); - if (g_weaponarena_random_with_blaster) player.weapons |= WEPSET(BLASTER); + if (g_weaponarena_random_with_blaster) { player.weapons &= ~WEPSET(BLASTER); } + W_RandomWeapons(player, g_weaponarena_random); + if (g_weaponarena_random_with_blaster) { player.weapons |= WEPSET(BLASTER); } } diff --git a/qcsrc/common/net_notice.qc b/qcsrc/common/net_notice.qc index 6f6a17c40..4b2f81110 100644 --- a/qcsrc/common/net_notice.qc +++ b/qcsrc/common/net_notice.qc @@ -5,17 +5,18 @@ REGISTER_NET_TEMP(TE_CSQC_SVNOTICE) #ifdef SVQC void sv_notice_join_think(entity this) { - int argc = tokenizebyseparator(autocvar_sv_join_notices, "|"); - if (argc <= 0) return; - for (int i = 0; i < argc; ++i) - sv_notice_to(this, argv(i), autocvar_sv_join_notices_time, false); + int argc = tokenizebyseparator(autocvar_sv_join_notices, "|"); + if (argc <= 0) { return; } + for (int i = 0; i < argc; ++i) { + sv_notice_to(this, argv(i), autocvar_sv_join_notices_time, false); + } } void sv_notice_join(entity _to) { - // to-do: make sv_join_notices support per-entry times - if (autocvar_sv_join_notices == "") return; - defer(_to, 1, sv_notice_join_think); + // to-do: make sv_join_notices support per-entry times + if (autocvar_sv_join_notices == "") { return; } + defer(_to, 1, sv_notice_join_think); } void sv_notice_to(entity _to, string _notice, float _howlong, float _modal) @@ -29,7 +30,7 @@ void sv_notice_to(entity _to, string _notice, float _howlong, float _modal) void sv_notice_toall(string _notice, float _howlong, float _modal) { - FOREACH_CLIENT(IS_REAL_CLIENT(it), sv_notice_to(it, _notice, _howlong, _modal)); + FOREACH_CLIENT(IS_REAL_CLIENT(it), sv_notice_to(it, _notice, _howlong, _modal)); } #endif // SVQC @@ -43,59 +44,61 @@ NET_HANDLE(TE_CSQC_SVNOTICE, bool isNew) entity cl_notices; void cl_notice_read() { - entity _notice = new_pure(sv_notice); - _notice.netname = strzone(ReadString()); - _notice.alpha = ReadLong() + time; - _notice.skin = ReadByte(); - if(!cl_notices) - cl_notices = LL_NEW(); - LL_PUSH(cl_notices, _notice); + entity _notice = new_pure(sv_notice); + _notice.netname = strzone(ReadString()); + _notice.alpha = ReadLong() + time; + _notice.skin = ReadByte(); + if (!cl_notices) { + cl_notices = LL_NEW(); + } + LL_PUSH(cl_notices, _notice); } void cl_notice_run() { - if (!cl_notices) + if (!cl_notices) { return; + } - bool flag = false; - LL_EACH(cl_notices, it.alpha > time, { flag = true; break; }); - if (!flag) - { + bool flag = false; + LL_EACH(cl_notices, it.alpha > time, { flag = true; + break; + }); + if (!flag) { LL_DELETE(cl_notices); return; } - const int M1 = 30; - const int M2 = 10; + const int M1 = 30; + const int M2 = 10; - vector v1 = '1 1 0' * M1; - vector v2 = '0 0 0'; - v2.x = vid_conwidth - (2 * M1); - v2.y = vid_conheight - (2 * M1); - drawfill(v1, v2, '0 0 0', 0.5, DRAWFLAG_NORMAL); + vector v1 = '1 1 0' * M1; + vector v2 = '0 0 0'; + v2.x = vid_conwidth - (2 * M1); + v2.y = vid_conheight - (2 * M1); + drawfill(v1, v2, '0 0 0', 0.5, DRAWFLAG_NORMAL); - v1 = '1 1 0' * (M1 + M2); - v2.x = vid_conwidth - (2 * (M1 + M2)); - v2.y = vid_conheight - (2 * (M1 + M2)); - drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL); + v1 = '1 1 0' * (M1 + M2); + v2.x = vid_conwidth - (2 * (M1 + M2)); + v2.y = vid_conheight - (2 * (M1 + M2)); + drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL); - vector v3 = v1 + '10 10 0'; - #define OUT(s, z) MACRO_BEGIN drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3.y += z + 4; MACRO_END + vector v3 = v1 + '10 10 0'; + #define OUT(s, z) MACRO_BEGIN drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3.y += z + 4; MACRO_END - float cur_time = 0; - float time_width = 48; - OUT(_("^1Server notices:"), 32); - LL_EACH(cl_notices, it.alpha > time, { - if(it.alpha - cur_time > 0.1) - { - cur_time = it.alpha; - string s = sprintf("^3%d", ceil(cur_time - time)); - drawcolorcodedstring(v3 + eX * 0.5 * (time_width - stringwidth(s, true, '1 1 0' * 16)), s, '1 1 0' * 16, 1, DRAWFLAG_NORMAL); - v3.x = v1.x + 10 + time_width; - } - OUT(it.netname, 16); - }); - #undef OUT + float cur_time = 0; + float time_width = 48; + OUT(_("^1Server notices:"), 32); + LL_EACH(cl_notices, it.alpha > time, { + if (it.alpha - cur_time > 0.1) { + cur_time = it.alpha; + string s = sprintf("^3%d", ceil(cur_time - time)); + drawcolorcodedstring(v3 + eX * 0.5 * (time_width - stringwidth(s, true, '1 1 0' * 16)), s, '1 1 0' * 16, 1, DRAWFLAG_NORMAL); + v3.x = v1.x + 10 + time_width; + } + OUT(it.netname, 16); + }); + #undef OUT } #endif // CSQC diff --git a/qcsrc/common/notifications/all.qc b/qcsrc/common/notifications/all.qc index 5cce35885..73b8b2494 100644 --- a/qcsrc/common/notifications/all.qc +++ b/qcsrc/common/notifications/all.qc @@ -18,12 +18,10 @@ // ================================================ #ifdef SVQC -string Notification_CheckArgs( - NOTIF broadcast, entity client) +string Notification_CheckArgs(NOTIF broadcast, entity client) { // check supplied broadcast and target for errors - switch (broadcast) - { + switch (broadcast) { case NOTIF_ONE: case NOTIF_ONE_ONLY: { @@ -79,56 +77,55 @@ string Notification_CheckArgs( bool Notification_ShouldSend(NOTIF broadcast, entity to_client, entity other_client) { - switch (broadcast) - { + switch (broadcast) { case NOTIF_ONE: - return ( + return (to_client == other_client) || (IS_SPEC(to_client) && (to_client.enemy == other_client)) - ); + ; case NOTIF_ONE_ONLY: - return (to_client == other_client); + return to_client == other_client; case NOTIF_TEAM: - return ( + return (to_client.team == other_client.team) || ( - IS_SPEC(to_client) - && - (to_client.enemy.team == other_client.team) + IS_SPEC(to_client) + && + (to_client.enemy.team == other_client.team) ) - ); + ; case NOTIF_TEAM_EXCEPT: - return ( + return (to_client != other_client) && ( - (to_client.team == other_client.team) - || + (to_client.team == other_client.team) + || + ( + IS_SPEC(to_client) + && ( - IS_SPEC(to_client) + (to_client.enemy != other_client) && - ( - (to_client.enemy != other_client) - && - (to_client.enemy.team == other_client.team) - ) + (to_client.enemy.team == other_client.team) ) ) - ); + ) + ; case NOTIF_ALL: return true; case NOTIF_ALL_EXCEPT: - return ( + return (to_client != other_client) && !( - IS_SPEC(to_client) - && - (to_client.enemy == other_client) + IS_SPEC(to_client) + && + (to_client.enemy == other_client) ) - ); + ; default: return false; } @@ -143,13 +140,13 @@ bool Notification_ShouldSend(NOTIF broadcast, entity to_client, entity other_cli // used by restartnotifs command to initialize notifications void Destroy_Notification_Entity(entity notif) { - if (notif.nent_name != "") strunzone(notif.nent_name); - if (notif.nent_snd != "") strunzone(notif.nent_snd); - if (notif.nent_args != "") strunzone(notif.nent_args); - if (notif.nent_hudargs != "") strunzone(notif.nent_hudargs); - if (notif.nent_icon != "") strunzone(notif.nent_icon); - if (notif.nent_durcnt != "") strunzone(notif.nent_durcnt); - if (notif.nent_string != "") strunzone(notif.nent_string); + if (notif.nent_name != "") { strunzone(notif.nent_name); } + if (notif.nent_snd != "") { strunzone(notif.nent_snd); } + if (notif.nent_args != "") { strunzone(notif.nent_args); } + if (notif.nent_hudargs != "") { strunzone(notif.nent_hudargs); } + if (notif.nent_icon != "") { strunzone(notif.nent_icon); } + if (notif.nent_durcnt != "") { strunzone(notif.nent_durcnt); } + if (notif.nent_string != "") { strunzone(notif.nent_string); } delete(notif); } @@ -163,23 +160,16 @@ void Destroy_All_Notifications() #endif // kill all real notification entities - FOREACH(Notifications, true, { Destroy_Notification_Entity(it); }); + FOREACH(Notifications, true, { Destroy_Notification_Entity(it); + }); } -string Process_Notif_Line( - MSG typeId, - bool chat, - string input, - string notiftype, - string notifname, - string stringtype) +string Process_Notif_Line(MSG typeId, bool chat, string input, string notiftype, string notifname, string stringtype) { #ifdef CSQC - if(typeId == MSG_INFO) - { - if((chat && autocvar_notification_allow_chatboxprint) - || (autocvar_notification_allow_chatboxprint == 2)) - { + if (typeId == MSG_INFO) { + if ((chat && autocvar_notification_allow_chatboxprint) + || (autocvar_notification_allow_chatboxprint == 2)) { // pass 1: add ETX char at beginning of line input = strcat("\{3}", input); @@ -188,15 +178,14 @@ string Process_Notif_Line( input = strreplace("\n", "\n\{3}", input); // pass 3: strip trailing ETX char - if(substring(input, (strlen(input) - 1), 1) == "\{3}") - { input = substring(input, 0, (strlen(input) - 1)); } + if (substring(input, (strlen(input) - 1), 1) == "\{3}") + { input = substring(input, 0, (strlen(input) - 1)); } } } #endif // done to both MSG_INFO and MSG_CENTER - if(substring(input, (strlen(input) - 1), 1) == "\n") - { + if (substring(input, (strlen(input) - 1), 1) == "\n") { LOG_INFOF( ( "^1TRAILING NEW LINE AT END OF NOTIFICATION: " @@ -213,25 +202,19 @@ string Process_Notif_Line( return input; } -string Process_Notif_Args( - float arg_type, - string args, - string notiftype, - string notifname) +string Process_Notif_Args(float arg_type, string args, string notiftype, string notifname) { string selected, remaining = args; float sel_num = 0; - for (;(remaining != "");) - { - selected = car(remaining); remaining = cdr(remaining); + for ( ; (remaining != ""); ) { + selected = car(remaining); + remaining = cdr(remaining); - switch(arg_type) - { + switch (arg_type) { case 1: // normal args { - if(sel_num == NOTIF_MAX_ARGS) - { + if (sel_num == NOTIF_MAX_ARGS) { LOG_INFOF( ( "^1NOTIFICATION HAS TOO MANY ARGUMENTS: " @@ -245,15 +228,24 @@ string Process_Notif_Args( break; } - switch(strtolower(selected)) - { - #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE_ARG_CS_SV(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE_ARG_CS(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE_ARG_SV(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE_ARG_DC(selected,result) - #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result) + switch (strtolower(selected)) { + #define ARG_CASE_ARG_CS_SV_HA(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE_ARG_CS_SV_DC(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE_ARG_CS_SV(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE_ARG_CS(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE_ARG_SV(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE_ARG_DC(selected, result) + #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) NOTIF_ARGUMENT_LIST #undef ARG_CASE #undef ARG_CASE_ARG_DC @@ -281,8 +273,7 @@ string Process_Notif_Args( } case 2: // hudargs { - if(sel_num == NOTIF_MAX_HUDARGS) - { + if (sel_num == NOTIF_MAX_HUDARGS) { LOG_INFOF( ( "^1NOTIFICATION HAS TOO MANY ARGUMENTS: " @@ -296,15 +287,16 @@ string Process_Notif_Args( break; } - switch(strtolower(selected)) - { - #define ARG_CASE_ARG_CS_SV_HA(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE_ARG_CS_SV_DC(selected,result) - #define ARG_CASE_ARG_CS_SV(selected,result) - #define ARG_CASE_ARG_CS(selected,result) - #define ARG_CASE_ARG_SV(selected,result) - #define ARG_CASE_ARG_DC(selected,result) - #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result) + switch (strtolower(selected)) { + #define ARG_CASE_ARG_CS_SV_HA(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE_ARG_CS_SV_DC(selected, result) + #define ARG_CASE_ARG_CS_SV(selected, result) + #define ARG_CASE_ARG_CS(selected, result) + #define ARG_CASE_ARG_SV(selected, result) + #define ARG_CASE_ARG_DC(selected, result) + #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) NOTIF_ARGUMENT_LIST #undef ARG_CASE #undef ARG_CASE_ARG_DC @@ -332,8 +324,7 @@ string Process_Notif_Args( } case 3: // durcnt { - if(sel_num == NOTIF_MAX_DURCNT) - { + if (sel_num == NOTIF_MAX_DURCNT) { LOG_INFOF( ( "^1NOTIFICATION HAS TOO MANY ARGUMENTS: " @@ -347,15 +338,18 @@ string Process_Notif_Args( break; } - switch(strtolower(selected)) - { - #define ARG_CASE_ARG_CS_SV_HA(selected,result) - #define ARG_CASE_ARG_CS_SV_DC(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE_ARG_CS_SV(selected,result) - #define ARG_CASE_ARG_CS(selected,result) - #define ARG_CASE_ARG_SV(selected,result) - #define ARG_CASE_ARG_DC(selected,result) case selected: { ++sel_num; break; } - #define ARG_CASE(prog,selected,result) ARG_CASE_##prog(selected,result) + switch (strtolower(selected)) { + #define ARG_CASE_ARG_CS_SV_HA(selected, result) + #define ARG_CASE_ARG_CS_SV_DC(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE_ARG_CS_SV(selected, result) + #define ARG_CASE_ARG_CS(selected, result) + #define ARG_CASE_ARG_SV(selected, result) + #define ARG_CASE_ARG_DC(selected, result) \ + case selected: \ + { ++sel_num; break; } + #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) NOTIF_ARGUMENT_LIST #undef ARG_CASE #undef ARG_CASE_ARG_DC @@ -366,9 +360,7 @@ string Process_Notif_Args( #undef ARG_CASE_ARG_CS_SV_HA default: { - if(ftos(stof(selected)) != "") { ++sel_num; } - else - { + if (ftos(stof(selected)) != "") { ++sel_num; } else { LOG_INFOF( ( "^1NOTIFICATION WITH UNKNOWN TOKEN IN ARGUMENT STRING: " @@ -390,12 +382,7 @@ string Process_Notif_Args( return args; } -void Create_Notification_Entity(entity notif, - float var_default, - float var_cvar, - MSG typeId, - string namestring, - int teamnum) +void Create_Notification_Entity(entity notif, float var_default, float var_cvar, MSG typeId, string namestring, int teamnum) { // ===================== // Global Entity Setup @@ -409,8 +396,7 @@ void Create_Notification_Entity(entity notif, // Other pre-notif-setup requisites notif_error = false; - switch (typeId) - { + switch (typeId) { case MSG_ANNCE: case MSG_INFO: case MSG_CENTER: @@ -419,248 +405,117 @@ void Create_Notification_Entity(entity notif, break; default: LOG_INFOF( - ( - "^1NOTIFICATION WITH IMPROPER TYPE: " - "^7net_type = %d, net_name = %s." - ), - typeId, - namestring + ( + "^1NOTIFICATION WITH IMPROPER TYPE: " + "^7net_type = %d, net_name = %s." + ), + typeId, + namestring ); notif_error = true; break; } // now check to see if any errors happened - if (notif_error) - { + if (notif_error) { notif.nent_enabled = false; // disable the notification so it can't cause trouble - notif_global_error = true; // throw the red flag that an error happened on init + notif_global_error = true; // throw the red flag that an error happened on init } } #define AnnouncerFilename(snd) sprintf("announcer/%s/%s.wav", AnnouncerOption(), snd) -void Create_Notification_Entity_Annce(entity notif, - float var_cvar, - string namestring, - /* MSG_ANNCE */ - float channel, - string snd, - float vol, - float position) - { - // Set MSG_ANNCE information and handle precaching +void Create_Notification_Entity_Annce(entity notif, float var_cvar, string namestring, + /* MSG_ANNCE */ + float channel, string snd, float vol, float position) +{ + // Set MSG_ANNCE information and handle precaching #ifdef CSQC - MSG typeId = MSG_ANNCE; - if (!(GENTLE && (var_cvar == 1))) - { - if(snd != "") - { - if(notif.nent_enabled) - { - precache_sound(AnnouncerFilename(snd)); - notif.nent_channel = channel; - notif.nent_snd = strzone(snd); - notif.nent_vol = vol; - notif.nent_position = position; - } - } - else - { - string typestring = Get_Notif_TypeName(typeId); - LOG_INFOF( - ( - "^1NOTIFICATION WITH NO SOUND: " - "^7net_type = %s, net_name = %s." - ), - typestring, - namestring - ); - notif_error = true; - } + MSG typeId = MSG_ANNCE; + if (!(GENTLE && (var_cvar == 1))) { + if (snd != "") { + if (notif.nent_enabled) { + precache_sound(AnnouncerFilename(snd)); + notif.nent_channel = channel; + notif.nent_snd = strzone(snd); + notif.nent_vol = vol; + notif.nent_position = position; } - else { notif.nent_enabled = false; } + } else { + string typestring = Get_Notif_TypeName(typeId); + LOG_INFOF( + ( + "^1NOTIFICATION WITH NO SOUND: " + "^7net_type = %s, net_name = %s." + ), + typestring, + namestring + ); + notif_error = true; + } + } else { notif.nent_enabled = false; } #else - notif.nent_enabled = false; + notif.nent_enabled = false; #endif +} - } - -void Create_Notification_Entity_InfoCenter(entity notif, - float var_cvar, - string namestring, - int strnum, - int flnum, - /* MSG_INFO & MSG_CENTER */ - string args, - string hudargs, - string icon, - CPID cpid, - string durcnt, - string normal, - string gentle) - { - MSG typeId = notif.nent_type; - // Set MSG_INFO and MSG_CENTER string/float counts - notif.nent_stringcount = strnum; - notif.nent_floatcount = flnum; +void Create_Notification_Entity_InfoCenter(entity notif, float var_cvar, string namestring, int strnum, int flnum, + /* MSG_INFO & MSG_CENTER */ + string args, string hudargs, string icon, CPID cpid, string durcnt, string normal, string gentle) +{ + MSG typeId = notif.nent_type; + // Set MSG_INFO and MSG_CENTER string/float counts + notif.nent_stringcount = strnum; + notif.nent_floatcount = flnum; - // Only initialize arguments if we're either a client or on a dedicated server + // Only initialize arguments if we're either a client or on a dedicated server #ifdef SVQC - float should_process_args = server_is_dedicated; + float should_process_args = server_is_dedicated; #else - float should_process_args = true; + float should_process_args = true; #endif - string typestring = Get_Notif_TypeName(typeId); - if(should_process_args) - { - // ======================== - // Process Main Arguments - // ======================== - if(strnum + flnum) - { - if(args != "") - { - notif.nent_args = strzone( - Process_Notif_Args(1, args, typestring, namestring)); - } - else if((hudargs == "") && (durcnt =="")) - { - LOG_INFOF( - ( - "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: " - "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d" - ), - typestring, - namestring, - strnum, - flnum - ); - notif_error = true; - } - } - else if(args != "") - { - notif.nent_args = strzone( - Process_Notif_Args(1, args, typestring, namestring)); - } + string typestring = Get_Notif_TypeName(typeId); + if (should_process_args) { + // ======================== + // Process Main Arguments + // ======================== + if (strnum + flnum) { + if (args != "") { + notif.nent_args = strzone( + Process_Notif_Args(1, args, typestring, namestring)); + } else if ((hudargs == "") && (durcnt == "")) { + LOG_INFOF( + ( + "^1NOTIFICATION HAS ARG COUNTS BUT NO ARGS OR HUDARGS OR DURCNT: " + "^7net_type = %s, net_name = %s, strnum = %d, flnum = %d" + ), + typestring, + namestring, + strnum, + flnum + ); + notif_error = true; + } + } else if (args != "") { + notif.nent_args = strzone( + Process_Notif_Args(1, args, typestring, namestring)); + } - // ======================================= - // Process HUD and Centerprint Arguments - // Only processed on CSQC, as these - // args are only for HUD features. - // ======================================= + // ======================================= + // Process HUD and Centerprint Arguments + // Only processed on CSQC, as these + // args are only for HUD features. + // ======================================= #ifdef CSQC - if(hudargs != "") - { - notif.nent_hudargs = strzone( - Process_Notif_Args(2, hudargs, typestring, namestring)); + if (hudargs != "") { + notif.nent_hudargs = strzone( + Process_Notif_Args(2, hudargs, typestring, namestring)); - if(icon != "") { notif.nent_icon = strzone(icon); } - else - { - LOG_INFOF( - ( - "^1NOTIFICATION HAS HUDARGS BUT NO ICON: " - "^7net_type = %s, net_name = %s." - ), - typestring, - namestring - ); - notif_error = true; - } - } - else if(icon != "") - { - LOG_WARNF( - ( - "^1NOTIFICATION HAS ICON BUT NO HUDARGS: " - "^7net_type = %s, net_name = %s.\n" - ), - typestring, - namestring - ); - notif_error = true; - } - - if (durcnt != "") - { - notif.nent_durcnt = strzone(Process_Notif_Args(3, durcnt, typestring, namestring)); - - if (cpid == CPID_Null && durcnt != "0 0") - { - LOG_WARNF( - ( - "Notification has durcnt but no cpid: " - "net_type = %s, net_name = %s." - ), - typestring, - namestring - ); - notif_error = true; - } - } - notif.nent_cpid = cpid; - #endif - - - // ====================== - // Process Notif String - // ====================== - #define SET_NOTIF_STRING(string,stringname) MACRO_BEGIN \ - notif.nent_string = strzone(CCR( \ - Process_Notif_Line( \ - typeId, \ - (var_cvar > 1), \ - string, \ - typestring, \ - namestring, \ - stringname \ - )) \ - ); \ - MACRO_END - - if(GENTLE) - { - if(gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); } - else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); } - } - else if(normal != "") { SET_NOTIF_STRING(normal, "NORMAL"); } - #undef SET_NOTIF_STRING - - // Check to make sure a string was chosen - if(notif.nent_string == "") - { - LOG_INFOF( - ( - "^1EMPTY NOTIFICATION: " - "^7net_type = %s, net_name = %s." - ), - typestring, - namestring - ); - notif_error = true; - } - } - } - -void Create_Notification_Entity_Multi(entity notif, - float var_cvar, - string namestring, - /* MSG_MULTI */ - Notification anncename, - Notification infoname, - Notification centername) - { - MSG typeId = MSG_MULTI; - // Set MSG_MULTI string/float counts - if (!anncename && !infoname && !centername) - { - string typestring = Get_Notif_TypeName(typeId); + if (icon != "") { notif.nent_icon = strzone(icon); } else { LOG_INFOF( ( - "^1NOTIFICATION WITH NO SUBCALLS: " + "^1NOTIFICATION HAS HUDARGS BUT NO ICON: " "^7net_type = %s, net_name = %s." ), typestring, @@ -668,89 +523,166 @@ void Create_Notification_Entity_Multi(entity notif, ); notif_error = true; } - else - { - // announcements don't actually need any arguments, so lets not even count them. - if (anncename) { notif.nent_msgannce = anncename; } - - float infoname_stringcount = 0, infoname_floatcount = 0; - float centername_stringcount = 0, centername_floatcount = 0; - - if (infoname) - { - notif.nent_msginfo = infoname; - infoname_stringcount = notif.nent_msginfo.nent_stringcount; - infoname_floatcount = notif.nent_msginfo.nent_floatcount; - } - - if (centername) - { - notif.nent_msgcenter = centername; - centername_stringcount = notif.nent_msgcenter.nent_stringcount; - centername_floatcount = notif.nent_msgcenter.nent_floatcount; - } - - // set the requirements of THIS notification to the totals of its subcalls - notif.nent_stringcount = max(infoname_stringcount, centername_stringcount); - notif.nent_floatcount = max(infoname_floatcount, centername_floatcount); - } + } else if (icon != "") { + LOG_WARNF( + ( + "^1NOTIFICATION HAS ICON BUT NO HUDARGS: " + "^7net_type = %s, net_name = %s.\n" + ), + typestring, + namestring + ); + notif_error = true; } -void Create_Notification_Entity_Choice(entity notif, - float var_cvar, - string namestring, - /* MSG_CHOICE */ - float challow_def, - float challow_var, - MSG chtype, - Notification optiona, - Notification optionb) - { - MSG typeId = MSG_CHOICE; - if (chtype == MSG_Null || !optiona || !optionb) - { - string typestring = Get_Notif_TypeName(typeId); - LOG_INFOF( + if (durcnt != "") { + notif.nent_durcnt = strzone(Process_Notif_Args(3, durcnt, typestring, namestring)); + + if (cpid == CPID_Null && durcnt != "0 0") { + LOG_WARNF( ( - "^1NOTIFICATION IS MISSING CHOICE PARAMS: " - "^7net_type = %s, net_name = %s." + "Notification has durcnt but no cpid: " + "net_type = %s, net_name = %s." ), typestring, namestring ); notif_error = true; } - else - { - notif.nent_optiona = optiona; - notif.nent_optionb = optionb; - notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed - notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed - notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount); - notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount); - - /*#ifdef NOTIFICATIONS_DEBUG - Debug_Notification(sprintf( - "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n", - notif.nent_name, - sprintf( - "^ optiona: %s %s : %d %d", - Get_Notif_TypeName(notif.nent_optiona.nent_type), - notif.nent_optiona.nent_name, - notif.nent_optiona.nent_stringcount, - notif.nent_optiona.nent_floatcount - ), - sprintf( - "^ optionb: %s %s : %d %d", - Get_Notif_TypeName(notif.nent_optionb.nent_type), - notif.nent_optionb.nent_name, - notif.nent_optionb.nent_stringcount, - notif.nent_optionb.nent_floatcount - ) - )); - #endif*/ + } + notif.nent_cpid = cpid; + #endif + + + // ====================== + // Process Notif String + // ====================== + #define SET_NOTIF_STRING(string, stringname) \ + MACRO_BEGIN \ + notif.nent_string = strzone(CCR( \ + Process_Notif_Line( \ + typeId, \ + (var_cvar > 1), \ + string, \ + typestring, \ + namestring, \ + stringname \ + )) \ + ); \ + MACRO_END + + if (GENTLE) { + if (gentle != "") { SET_NOTIF_STRING(gentle, "GENTLE"); } else if (normal != "") { + SET_NOTIF_STRING(normal, "NORMAL"); } + } else if (normal != "") { + SET_NOTIF_STRING(normal, "NORMAL"); } + #undef SET_NOTIF_STRING + + // Check to make sure a string was chosen + if (notif.nent_string == "") { + LOG_INFOF( + ( + "^1EMPTY NOTIFICATION: " + "^7net_type = %s, net_name = %s." + ), + typestring, + namestring + ); + notif_error = true; + } + } +} + +void Create_Notification_Entity_Multi(entity notif, float var_cvar, string namestring, + /* MSG_MULTI */ + Notification anncename, Notification infoname, Notification centername) +{ + MSG typeId = MSG_MULTI; + // Set MSG_MULTI string/float counts + if (!anncename && !infoname && !centername) { + string typestring = Get_Notif_TypeName(typeId); + LOG_INFOF( + ( + "^1NOTIFICATION WITH NO SUBCALLS: " + "^7net_type = %s, net_name = %s." + ), + typestring, + namestring + ); + notif_error = true; + } else { + // announcements don't actually need any arguments, so lets not even count them. + if (anncename) { notif.nent_msgannce = anncename; } + + float infoname_stringcount = 0, infoname_floatcount = 0; + float centername_stringcount = 0, centername_floatcount = 0; + + if (infoname) { + notif.nent_msginfo = infoname; + infoname_stringcount = notif.nent_msginfo.nent_stringcount; + infoname_floatcount = notif.nent_msginfo.nent_floatcount; + } + + if (centername) { + notif.nent_msgcenter = centername; + centername_stringcount = notif.nent_msgcenter.nent_stringcount; + centername_floatcount = notif.nent_msgcenter.nent_floatcount; + } + + // set the requirements of THIS notification to the totals of its subcalls + notif.nent_stringcount = max(infoname_stringcount, centername_stringcount); + notif.nent_floatcount = max(infoname_floatcount, centername_floatcount); + } +} + +void Create_Notification_Entity_Choice(entity notif, float var_cvar, string namestring, + /* MSG_CHOICE */ + float challow_def, float challow_var, MSG chtype, Notification optiona, Notification optionb) +{ + MSG typeId = MSG_CHOICE; + if (chtype == MSG_Null || !optiona || !optionb) { + string typestring = Get_Notif_TypeName(typeId); + LOG_INFOF( + ( + "^1NOTIFICATION IS MISSING CHOICE PARAMS: " + "^7net_type = %s, net_name = %s." + ), + typestring, + namestring + ); + notif_error = true; + } else { + notif.nent_optiona = optiona; + notif.nent_optionb = optionb; + notif.nent_challow_def = challow_def; // 0: never allowed, 1: allowed in warmup, 2: always allowed + notif.nent_challow_var = challow_var; // 0: never allowed, 1: allowed in warmup, 2: always allowed + notif.nent_stringcount = max(notif.nent_optiona.nent_stringcount, notif.nent_optionb.nent_stringcount); + notif.nent_floatcount = max(notif.nent_optiona.nent_floatcount, notif.nent_optionb.nent_floatcount); + + /*#ifdef NOTIFICATIONS_DEBUG + Debug_Notification(sprintf( + "Create_Notification_Entity(...): MSG_CHOICE: %s\n%s\n%s\n", + notif.nent_name, + sprintf( + "^ optiona: %s %s : %d %d", + Get_Notif_TypeName(notif.nent_optiona.nent_type), + notif.nent_optiona.nent_name, + notif.nent_optiona.nent_stringcount, + notif.nent_optiona.nent_floatcount + ), + sprintf( + "^ optionb: %s %s : %d %d", + Get_Notif_TypeName(notif.nent_optionb.nent_type), + notif.nent_optionb.nent_name, + notif.nent_optionb.nent_stringcount, + notif.nent_optionb.nent_floatcount + ) + )); + #endif*/ + } +} // =============== @@ -763,12 +695,12 @@ void Notification_GetCvars(entity this) { FOREACH(Notifications, it.nent_type == MSG_CHOICE, { GetCvars_handleFloat( - this, - CS(this), - get_cvars_s, - get_cvars_f, - msg_choice_choices[it.nent_choice_idx], - sprintf("notification_%s", Get_Notif_CvarName(it)) + this, + CS(this), + get_cvars_s, + get_cvars_f, + msg_choice_choices[it.nent_choice_idx], + sprintf("notification_%s", Get_Notif_CvarName(it)) ); }); } @@ -777,34 +709,38 @@ void Notification_GetCvars(entity this) /** used to output notifications.cfg file */ void Dump_Notifications(int fh, bool alsoprint) { - #define NOTIF_WRITE(a) MACRO_BEGIN \ + #define NOTIF_WRITE(a) \ + MACRO_BEGIN \ fputs(fh, a); \ - if (alsoprint) LOG_INFO(a); \ + if (alsoprint) { LOG_INFO(a); } \ MACRO_END - #define NOTIF_WRITE_ENTITY(e, description) MACRO_BEGIN \ + #define NOTIF_WRITE_ENTITY(e, description) \ + MACRO_BEGIN \ string notif_msg = sprintf( \ - "seta notification_%s \"%d\" \"%s\"\n", \ - Get_Notif_CvarName(e), e.nent_default, description \ - ); \ + "seta notification_%s \"%d\" \"%s\"\n", \ + Get_Notif_CvarName(e), e.nent_default, description \ + ); \ NOTIF_WRITE(notif_msg); \ MACRO_END - #define NOTIF_WRITE_ENTITY_CHOICE(e, descriptiona, descriptionb) MACRO_BEGIN \ + #define NOTIF_WRITE_ENTITY_CHOICE(e, descriptiona, descriptionb) \ + MACRO_BEGIN \ string notif_msg = sprintf( \ - "seta notification_%s \"%d\" \"%s\"\n" \ - "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \ - Get_Notif_CvarName(e), e.nent_default, descriptiona, \ - Get_Notif_CvarName(e), e.nent_challow_def, descriptionb \ - ); \ + "seta notification_%s \"%d\" \"%s\"\n" \ + "seta notification_%s_ALLOWED \"%d\" \"%s\"\n", \ + Get_Notif_CvarName(e), e.nent_default, descriptiona, \ + Get_Notif_CvarName(e), e.nent_challow_def, descriptionb \ + ); \ NOTIF_WRITE(notif_msg); \ MACRO_END - #define NOTIF_WRITE_HARDCODED(cvar, default, description) MACRO_BEGIN \ + #define NOTIF_WRITE_HARDCODED(cvar, default, description) \ + MACRO_BEGIN \ string notif_msg = sprintf( \ - "seta notification_%s \"%s\" \"%s\"\n", \ - cvar, default, description \ - ); \ + "seta notification_%s \"%s\" \"%s\"\n", \ + cvar, default, description \ + ); \ NOTIF_WRITE(notif_msg); \ MACRO_END @@ -830,45 +766,55 @@ void Dump_Notifications(int fh, bool alsoprint) // This is not necessary, and does not matter if they vary between config versions, // it is just a semi-helpful tool for those who want to manually change their user settings. - int NOTIF_ANNCE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_ANNCE, { ++NOTIF_ANNCE_COUNT; }); + int NOTIF_ANNCE_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_ANNCE, { ++NOTIF_ANNCE_COUNT; + }); NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT)); FOREACH(Notifications, it.nent_type == MSG_ANNCE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, - "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled" + "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled" ); }); - int NOTIF_INFO_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_INFO, { ++NOTIF_INFO_COUNT; }); + int NOTIF_INFO_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_INFO, { ++NOTIF_INFO_COUNT; + }); NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT)); FOREACH(Notifications, it.nent_type == MSG_INFO && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, - "0 = off, 1 = print to console, " - "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)" + "0 = off, 1 = print to console, " + "2 = print to console and chatbox (if notification_allow_chatboxprint is enabled)" ); }); - int NOTIF_CENTER_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CENTER, { ++NOTIF_CENTER_COUNT; }); + int NOTIF_CENTER_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_CENTER, { ++NOTIF_CENTER_COUNT; + }); NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT)); FOREACH(Notifications, it.nent_type == MSG_CENTER && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, - "0 = off, 1 = centerprint" + "0 = off, 1 = centerprint" ); }); - int NOTIF_MULTI_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_MULTI, { ++NOTIF_MULTI_COUNT; }); + int NOTIF_MULTI_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_MULTI, { ++NOTIF_MULTI_COUNT; + }); NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT)); FOREACH(Notifications, it.nent_type == MSG_MULTI && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY(it, - "Enable this multiple notification" + "Enable this multiple notification" ); }); - int NOTIF_CHOICE_COUNT = 0; FOREACH(Notifications, it.nent_type == MSG_CHOICE, { ++NOTIF_CHOICE_COUNT; }); + int NOTIF_CHOICE_COUNT = 0; + FOREACH(Notifications, it.nent_type == MSG_CHOICE, { ++NOTIF_CHOICE_COUNT; + }); NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT)); FOREACH(Notifications, it.nent_type == MSG_CHOICE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), { NOTIF_WRITE_ENTITY_CHOICE(it, - "Choice for this notification 0 = off, 1 = default message, 2 = verbose message", - "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always" + "Choice for this notification 0 = off, 1 = default message, 2 = verbose message", + "Allow choice for this notification 0 = off, 1 = only in warmup mode, 2 = always" ); }); @@ -965,18 +911,18 @@ void Dump_Notifications(int fh, bool alsoprint) "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n" ), ( - NOTIF_ANNCE_COUNT + - NOTIF_INFO_COUNT + - NOTIF_CENTER_COUNT + - NOTIF_MULTI_COUNT + - NOTIF_CHOICE_COUNT + NOTIF_ANNCE_COUNT + + NOTIF_INFO_COUNT + + NOTIF_CENTER_COUNT + + NOTIF_MULTI_COUNT + + NOTIF_CHOICE_COUNT ), NOTIF_ANNCE_COUNT, NOTIF_INFO_COUNT, NOTIF_CENTER_COUNT, NOTIF_MULTI_COUNT, NOTIF_CHOICE_COUNT - )); + )); #undef NOTIF_WRITE_HARDCODED #undef NOTIF_WRITE_ENTITY #undef NOTIF_WRITE @@ -987,10 +933,7 @@ void Dump_Notifications(int fh, bool alsoprint) // Frontend Notification Pushing // =============================== -string Local_Notification_sprintf( - string input, string args, - string s1, string s2, string s3, string s4, - int f1, float f2, float f3, float f4) +string Local_Notification_sprintf(string input, string args, string s1, string s2, string s3, string s4, int f1, float f2, float f3, float f4) { #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf( @@ -999,30 +942,41 @@ string Local_Notification_sprintf( args, MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)), sprintf("%d, %d, %d, %d", f1, f2, f3, f4) - )); + )); #endif - for (int sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; } + for (int sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { + arg_slot[sel_num] = ""; + } - for (int sel_num = 0; (args != ""); ) - { - string selected = car(args); args = cdr(args); + for (int sel_num = 0; (args != ""); ) { + string selected = car(args); + args = cdr(args); NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf"); string tmp_s; // used by NOTIF_ARGUMENT_LIST - switch (strtolower(selected)) - { - #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; } - #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; } - #define ARG_CASE_ARG_CS_SV(selected, result) case selected: { arg_slot[sel_num++] = result; break; } + switch (strtolower(selected)) { + #define ARG_CASE_ARG_CS_SV_HA(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } + #define ARG_CASE_ARG_CS_SV_DC(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } + #define ARG_CASE_ARG_CS_SV(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } #ifdef CSQC - #define ARG_CASE_ARG_CS(selected, result) case selected: { arg_slot[sel_num++] = result; break; } + #define ARG_CASE_ARG_CS(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } #define ARG_CASE_ARG_SV(selected, result) #else #define ARG_CASE_ARG_CS(selected, result) - #define ARG_CASE_ARG_SV(selected, result) case selected: { arg_slot[sel_num++] = result; break; } + #define ARG_CASE_ARG_SV(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } #endif #define ARG_CASE_ARG_DC(selected, result) - #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) + #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) NOTIF_ARGUMENT_LIST #undef ARG_CASE #undef ARG_CASE_ARG_DC @@ -1049,8 +1003,7 @@ string Local_Notification_sprintf( #ifdef CSQC void Local_Notification_sound(int soundchannel, string soundfile, float soundvolume, float soundposition) { - if ((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam))) - { + if ((soundfile != prev_soundfile) || (time >= (prev_soundtime + autocvar_cl_announcer_antispam))) { #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf( "Local_Notification_sound(%f, '%s', %f, %f);\n", @@ -1058,17 +1011,15 @@ void Local_Notification_sound(int soundchannel, string soundfile, float soundvol AnnouncerFilename(soundfile), soundvolume, soundposition - )); + )); #endif _sound(NULL, soundchannel, AnnouncerFilename(soundfile), soundvolume, soundposition); - if (prev_soundfile) strunzone(prev_soundfile); + if (prev_soundfile) { strunzone(prev_soundfile); } prev_soundfile = strzone(soundfile); prev_soundtime = time; - } - else - { + } else { #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf( ( @@ -1082,31 +1033,30 @@ void Local_Notification_sound(int soundchannel, string soundfile, float soundvol prev_soundfile, (time - prev_soundtime), autocvar_cl_announcer_antispam - )); + )); #endif } } -void Local_Notification_HUD_Notify_Push( - string icon, string hudargs, - string s1, string s2, string s3, string s4, - float f1, float f2, float f3, float f4) +void Local_Notification_HUD_Notify_Push(string icon, string hudargs, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4) { - arg_slot[0] = ""; arg_slot[1] = ""; + arg_slot[0] = ""; + arg_slot[1] = ""; - for (int sel_num = 0; (hudargs != ""); ) - { - string selected = car(hudargs); hudargs = cdr(hudargs); + for (int sel_num = 0; (hudargs != ""); ) { + string selected = car(hudargs); + hudargs = cdr(hudargs); NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push"); - switch (strtolower(selected)) - { - #define ARG_CASE_ARG_CS_SV_HA(selected, result) case selected: { arg_slot[sel_num++] = result; break; } + switch (strtolower(selected)) { + #define ARG_CASE_ARG_CS_SV_HA(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } #define ARG_CASE_ARG_CS_SV_DC(selected, result) #define ARG_CASE_ARG_CS_SV(selected, result) #define ARG_CASE_ARG_CS(selected, result) #define ARG_CASE_ARG_SV(selected, result) #define ARG_CASE_ARG_DC(selected, result) - #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) + #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) NOTIF_ARGUMENT_LIST #undef ARG_CASE #undef ARG_CASE_ARG_DC @@ -1126,30 +1076,32 @@ void Local_Notification_HUD_Notify_Push( MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)), sprintf("%d, %d, %d, %d", f1, f2, f3, f4), MakeConsoleSafe(sprintf("'%s^7', '%s^7'", stof(arg_slot[0]), stof(arg_slot[1]))) - )); + )); #endif HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]); } -void Local_Notification_centerprint_generic( - string input, string durcnt, - CPID cpid, float f1, float f2) +void Local_Notification_centerprint_generic(string input, string durcnt, CPID cpid, float f1, float f2) { - arg_slot[0] = ""; arg_slot[1] = ""; + arg_slot[0] = ""; + arg_slot[1] = ""; - for (int sel_num = 0; (durcnt != ""); ) - { - string selected = car(durcnt); durcnt = cdr(durcnt); + for (int sel_num = 0; (durcnt != ""); ) { + string selected = car(durcnt); + durcnt = cdr(durcnt); NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic"); - switch (strtolower(selected)) - { + switch (strtolower(selected)) { #define ARG_CASE_ARG_CS_SV_HA(selected, result) - #define ARG_CASE_ARG_CS_SV_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; } + #define ARG_CASE_ARG_CS_SV_DC(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } #define ARG_CASE_ARG_CS_SV(selected, result) #define ARG_CASE_ARG_CS(selected, result) #define ARG_CASE_ARG_SV(selected, result) - #define ARG_CASE_ARG_DC(selected, result) case selected: { arg_slot[sel_num++] = result; break; } - #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected,result) + #define ARG_CASE_ARG_DC(selected, result) \ + case selected: \ + { arg_slot[sel_num++] = result; break; } + #define ARG_CASE(prog, selected, result) ARG_CASE_##prog(selected, result) NOTIF_ARGUMENT_LIST #undef ARG_CASE #undef ARG_CASE_ARG_DC @@ -1160,8 +1112,7 @@ void Local_Notification_centerprint_generic( #undef ARG_CASE_ARG_CS_SV_HA default: { - if (/* wtf */ ftos(stof(selected)) != "") { arg_slot[sel_num++] = selected; } - else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") } + if ( /* wtf */ ftos(stof(selected)) != "") { arg_slot[sel_num++] = selected; } else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") } break; } } @@ -1174,49 +1125,47 @@ void Local_Notification_centerprint_generic( f1, f2, stof(arg_slot[0]), stof(arg_slot[1]) - )); + )); #endif centerprint_generic(ORDINAL(cpid), input, stof(arg_slot[0]), stof(arg_slot[1])); } #endif -void Local_Notification(MSG net_type, Notification net_name, ...count) +void Local_Notification(MSG net_type, Notification net_name, ... count) { // retreive entity of this notification entity notif = net_name; - if (!notif) - { + if (!notif) { #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf( "Local_Notification(%s, NULL, ...);\n", Get_Notif_TypeName(net_type) - )); + )); #endif LOG_WARNF("Incorrect usage of Local_Notification: %s", "Null notification"); return; } // check if the notification is enabled - if (!notif.nent_enabled) - { + if (!notif.nent_enabled) { #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf( "Local_Notification(%s, %s, ...): Entity was disabled...\n", Get_Notif_TypeName(net_type), notif.nent_name - )); + )); #endif return; } - string s1 = CCR((notif.nent_stringcount > 0) ? ...(0, string) : ""); - string s2 = CCR((notif.nent_stringcount > 1) ? ...(1, string) : ""); - string s3 = CCR((notif.nent_stringcount > 2) ? ...(2, string) : ""); - string s4 = CCR((notif.nent_stringcount > 3) ? ...(3, string) : ""); - float f1 = ((notif.nent_floatcount > 0) ? ...((notif.nent_stringcount + 0), float) : 0); - float f2 = ((notif.nent_floatcount > 1) ? ...((notif.nent_stringcount + 1), float) : 0); - float f3 = ((notif.nent_floatcount > 2) ? ...((notif.nent_stringcount + 2), float) : 0); - float f4 = ((notif.nent_floatcount > 3) ? ...((notif.nent_stringcount + 3), float) : 0); + string s1 = CCR((notif.nent_stringcount > 0) ? ... (0, string) : ""); + string s2 = CCR((notif.nent_stringcount > 1) ? ... (1, string) : ""); + string s3 = CCR((notif.nent_stringcount > 2) ? ... (2, string) : ""); + string s4 = CCR((notif.nent_stringcount > 3) ? ... (3, string) : ""); + float f1 = ((notif.nent_floatcount > 0) ? ... ((notif.nent_stringcount + 0), float) : 0); + float f2 = ((notif.nent_floatcount > 1) ? ... ((notif.nent_stringcount + 1), float) : 0); + float f3 = ((notif.nent_floatcount > 2) ? ... ((notif.nent_stringcount + 2), float) : 0); + float f4 = ((notif.nent_floatcount > 3) ? ... ((notif.nent_stringcount + 3), float) : 0); #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf( @@ -1225,11 +1174,10 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) notif.nent_name, MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)), sprintf("%d, %d, %d, %d", f1, f2, f3, f4) - )); + )); #endif - if ((notif.nent_stringcount + notif.nent_floatcount) != count) - { + if ((notif.nent_stringcount + notif.nent_floatcount) != count) { backtrace(sprintf( ( "Arguments mismatch for Local_Notification(%s, %s, ...)! " @@ -1241,12 +1189,11 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) notif.nent_stringcount, notif.nent_floatcount, count - )); + )); return; } - switch (net_type) - { + switch (net_type) { case MSG_ANNCE: { #ifdef CSQC @@ -1261,18 +1208,16 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) { print( Local_Notification_sprintf( - notif.nent_string, - notif.nent_args, - s1, s2, s3, s4, - f1, f2, f3, f4) + notif.nent_string, + notif.nent_args, + s1, s2, s3, s4, + f1, f2, f3, f4) ); #ifdef CSQC - if (notif.nent_icon != "") - { - if (notif.nent_iconargs != "") - { + if (notif.nent_icon != "") { + if (notif.nent_iconargs != "") { string s = Local_Notification_sprintf( - notif.nent_icon,notif.nent_iconargs, + notif.nent_icon, notif.nent_iconargs, s1, s2, s3, s4, f1, f2, f3, f4); // remove the trailing newline notif.nent_icon = strzone(substring(s, 0, -1)); @@ -1292,10 +1237,10 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) { Local_Notification_centerprint_generic( Local_Notification_sprintf( - notif.nent_string, - notif.nent_args, - s1, s2, s3, s4, - f1, f2, f3, f4), + notif.nent_string, + notif.nent_args, + s1, s2, s3, s4, + f1, f2, f3, f4), notif.nent_durcnt, notif.nent_cpid, f1, f2); @@ -1305,8 +1250,7 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) case MSG_MULTI: { - if (notif.nent_msginfo && notif.nent_msginfo.nent_enabled) - { + if (notif.nent_msginfo && notif.nent_msginfo.nent_enabled) { Local_Notification_WOVA( MSG_INFO, notif.nent_msginfo, @@ -1316,8 +1260,7 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) f1, f2, f3, f4); } #ifdef CSQC - if (notif.nent_msgannce && notif.nent_msgannce.nent_enabled) - { + if (notif.nent_msgannce && notif.nent_msgannce.nent_enabled) { Local_Notification_WOVA( MSG_ANNCE, notif.nent_msgannce, @@ -1325,8 +1268,7 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) "", "", "", "", 0, 0, 0, 0); } - if (notif.nent_msgcenter && notif.nent_msgcenter.nent_enabled) - { + if (notif.nent_msgcenter && notif.nent_msgcenter.nent_enabled) { Local_Notification_WOVA( MSG_CENTER, notif.nent_msgcenter, @@ -1343,10 +1285,10 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) { entity found_choice = notif.nent_optiona; if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) { - switch (cvar(sprintf("notification_%s", Get_Notif_CvarName(notif)))) - { + switch (cvar(sprintf("notification_%s", Get_Notif_CvarName(notif)))) { case 1: break; - case 2: found_choice = notif.nent_optionb; break; + case 2: found_choice = notif.nent_optionb; + break; default: return; // not enabled anyway } } @@ -1363,15 +1305,11 @@ void Local_Notification(MSG net_type, Notification net_name, ...count) } // WOVA = Without Variable Arguments -void Local_Notification_WOVA( - MSG net_type, Notification net_name, - float stringcount, float floatcount, - string s1, string s2, string s3, string s4, - float f1, float f2, float f3, float f4) +void Local_Notification_WOVA(MSG net_type, Notification net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4) { #define VARITEM(stringc, floatc, args) \ - if ((stringcount == stringc) && (floatcount == floatc)) \ - { Local_Notification(net_type, net_name, args); return; } + if ((stringcount == stringc) && (floatcount == floatc)) \ + { Local_Notification(net_type, net_name, args); return; } EIGHT_VARS_TO_VARARGS_VARLIST #undef VARITEM Local_Notification(net_type, net_name); // some notifications don't have any arguments at all @@ -1391,32 +1329,31 @@ NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new) make_pure(this); MSG net_type = ENUMCAST(MSG, ReadByte()); int net_name = ReadShort(); - return = true; - - if (net_type == MSG_CENTER_KILL) - { - if (!is_new) return; - // killing - #ifdef NOTIFICATIONS_DEBUG - Debug_Notification(sprintf( - "Read_Notification(%d) at %f: net_type = %s, cpid = %d\n", - is_new, - time, - Get_Notif_TypeName(net_type), - net_name - )); - #endif - int _net_name = net_name; - CPID net_name = ENUMCAST(CPID, _net_name); - if (net_name == CPID_Null) { - // kill all - reset_centerprint_messages(); - } else { - // kill group - centerprint_generic(ORDINAL(net_name), "", 0, 0); - } - return; - } + return = true; + + if (net_type == MSG_CENTER_KILL) { + if (!is_new) { return; } + // killing + #ifdef NOTIFICATIONS_DEBUG + Debug_Notification(sprintf( + "Read_Notification(%d) at %f: net_type = %s, cpid = %d\n", + is_new, + time, + Get_Notif_TypeName(net_type), + net_name + )); + #endif + int _net_name = net_name; + CPID net_name = ENUMCAST(CPID, _net_name); + if (net_name == CPID_Null) { + // kill all + reset_centerprint_messages(); + } else { + // kill group + centerprint_generic(ORDINAL(net_name), "", 0, 0); + } + return; + } Notification notif = Get_Notif_Ent(net_type, net_name); @@ -1428,30 +1365,30 @@ NET_HANDLE(ENT_CLIENT_NOTIFICATION, bool is_new) Get_Notif_TypeName(net_type), notif.registered_id, net_name - )); + )); #endif - if (!notif) { - backtrace("Read_Notification: Could not find notification entity!\n"); - return false; - } - - string s1 = ((notif.nent_stringcount > 0) ? ReadString() : ""); - string s2 = ((notif.nent_stringcount > 1) ? ReadString() : ""); - string s3 = ((notif.nent_stringcount > 2) ? ReadString() : ""); - string s4 = ((notif.nent_stringcount > 3) ? ReadString() : ""); - float f1 = ((notif.nent_floatcount > 0) ? ReadLong() : 0); - float f2 = ((notif.nent_floatcount > 1) ? ReadLong() : 0); - float f3 = ((notif.nent_floatcount > 2) ? ReadLong() : 0); - float f4 = ((notif.nent_floatcount > 3) ? ReadLong() : 0); - - if (!is_new) return; - Local_Notification_WOVA( - net_type, notif, - notif.nent_stringcount, - notif.nent_floatcount, - s1, s2, s3, s4, - f1, f2, f3, f4); + if (!notif) { + backtrace("Read_Notification: Could not find notification entity!\n"); + return false; + } + + string s1 = ((notif.nent_stringcount > 0) ? ReadString() : ""); + string s2 = ((notif.nent_stringcount > 1) ? ReadString() : ""); + string s3 = ((notif.nent_stringcount > 2) ? ReadString() : ""); + string s4 = ((notif.nent_stringcount > 3) ? ReadString() : ""); + float f1 = ((notif.nent_floatcount > 0) ? ReadLong() : 0); + float f2 = ((notif.nent_floatcount > 1) ? ReadLong() : 0); + float f3 = ((notif.nent_floatcount > 2) ? ReadLong() : 0); + float f4 = ((notif.nent_floatcount > 3) ? ReadLong() : 0); + + if (!is_new) { return; } + Local_Notification_WOVA( + net_type, notif, + notif.nent_stringcount, + notif.nent_floatcount, + s1, s2, s3, s4, + f1, f2, f3, f4); } #endif @@ -1465,25 +1402,32 @@ void Net_Notification_Remove(entity this) ((this.nent_net_name == -1) ? "Killed" : "Removed"), Get_Notif_TypeName(this.nent_net_type), this.owner.nent_name - )); + )); #endif - for (int i = 0; i < this.nent_stringcount; ++i) { if (this.nent_strings[i]) strunzone(this.nent_strings[i]); } + for (int i = 0; i < this.nent_stringcount; ++i) { + if (this.nent_strings[i]) { + strunzone(this.nent_strings[i]); + } + } delete(this); } bool Net_Write_Notification(entity this, entity client, int sf) { - if (!Notification_ShouldSend(this.nent_broadcast, client, this.nent_client)) return false; + if (!Notification_ShouldSend(this.nent_broadcast, client, this.nent_client)) { return false; } WriteHeader(MSG_ENTITY, ENT_CLIENT_NOTIFICATION); WriteByte(MSG_ENTITY, ORDINAL(this.nent_net_type)); WriteShort(MSG_ENTITY, this.nent_net_name); - for (int i = 0; i < this.nent_stringcount; ++i) { WriteString(MSG_ENTITY, this.nent_strings[i]); } - for (int i = 0; i < this.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, this.nent_floats[i]); } + for (int i = 0; i < this.nent_stringcount; ++i) { + WriteString(MSG_ENTITY, this.nent_strings[i]); + } + for (int i = 0; i < this.nent_floatcount; ++i) { + WriteLong(MSG_ENTITY, this.nent_floats[i]); + } return true; } -void Kill_Notification( - NOTIF broadcast, entity client, +void Kill_Notification(NOTIF broadcast, entity client, /** message group, MSG_Null for all */ MSG net_type, /** cpid group, CPID_Null for all */ @@ -1496,7 +1440,7 @@ void Kill_Notification( client.netname, (net_type ? Get_Notif_TypeName(net_type) : "0"), net_cpid - )); + )); #endif string checkargs = Notification_CheckArgs(broadcast, client); @@ -1511,53 +1455,48 @@ void Kill_Notification( IL_EACH(g_notifications, (it.owner.nent_type == net_type || net_type == MSG_Null) && (it.owner.nent_cpid == net_cpid || net_cpid == CPID_Null), - { - it.nent_net_name = -1; - it.nextthink = time; - } + { + it.nent_net_name = -1; + it.nextthink = time; + } ); } -void Send_Notification( - NOTIF broadcast, entity client, - MSG net_type, Notification net_name, - ...count) +void Send_Notification(NOTIF broadcast, entity client, MSG net_type, Notification net_name, ... count) { - if (broadcast != NOTIF_ALL && broadcast != NOTIF_ALL_EXCEPT && !IS_REAL_CLIENT(client)) return; + if (broadcast != NOTIF_ALL && broadcast != NOTIF_ALL_EXCEPT && !IS_REAL_CLIENT(client)) { return; } entity notif = net_name; string parms = sprintf("%s, '%s', %s, %s", Get_Notif_BroadcastName(broadcast), client.classname, Get_Notif_TypeName(net_type), net_name.registered_id - ); + ); #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf("Send_Notification(%s, ...%d);\n", parms, count)); #endif - if (!notif) - { + if (!notif) { LOG_WARN("Send_Notification: Could not find notification entity!"); return; } // check supplied broadcast, target, type, and name for errors string checkargs = Notification_CheckArgs(broadcast, client); - if (!net_name) { checkargs = sprintf("No notification provided! %s", checkargs); } - if (checkargs != "") - { + if (!net_name) { checkargs = sprintf("No notification provided! %s", checkargs); } + if (checkargs != "") { LOG_WARNF("Incorrect usage of Send_Notification: %s", checkargs); return; } - string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : ""); - string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : ""); - string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : ""); - string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : ""); - float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0); - float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0); - float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0); - float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0); + string s1 = ((0 < notif.nent_stringcount) ? ... (0, string) : ""); + string s2 = ((1 < notif.nent_stringcount) ? ... (1, string) : ""); + string s3 = ((2 < notif.nent_stringcount) ? ... (2, string) : ""); + string s4 = ((3 < notif.nent_stringcount) ? ... (3, string) : ""); + float f1 = ((0 < notif.nent_floatcount) ? ... ((notif.nent_stringcount + 0), float) : 0); + float f2 = ((1 < notif.nent_floatcount) ? ... ((notif.nent_stringcount + 1), float) : 0); + float f3 = ((2 < notif.nent_floatcount) ? ... ((notif.nent_stringcount + 2), float) : 0); + float f4 = ((3 < notif.nent_floatcount) ? ... ((notif.nent_stringcount + 3), float) : 0); #ifdef NOTIFICATIONS_DEBUG Debug_Notification(sprintf( @@ -1565,11 +1504,10 @@ void Send_Notification( parms, MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)), sprintf("%d, %d, %d, %d", f1, f2, f3, f4) - )); + )); #endif - if ((notif.nent_stringcount + notif.nent_floatcount) != count) - { + if ((notif.nent_stringcount + notif.nent_floatcount) != count) { LOG_WARNF( "Argument mismatch for Send_Notification(%s, ...)! " "stringcount(%d) + floatcount(%d) != count(%d)\n" @@ -1585,8 +1523,7 @@ void Send_Notification( if (server_is_dedicated && (broadcast == NOTIF_ALL || broadcast == NOTIF_ALL_EXCEPT) && !(net_type == MSG_ANNCE || net_type == MSG_CENTER) - ) - { + ) { Local_Notification_WOVA( net_type, net_name, notif.nent_stringcount, @@ -1595,8 +1532,7 @@ void Send_Notification( f1, f2, f3, f4); } - if (net_type == MSG_CHOICE) - { + if (net_type == MSG_CHOICE) { // THIS GETS TRICKY... now we have to cycle through each possible player (checking broadcast) // and then do an individual NOTIF_ONE_ONLY recursive call for each one depending on their option... // It's slow, but it's better than the alternatives: @@ -1604,34 +1540,33 @@ void Send_Notification( // 2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose) entity found_choice; - #define RECURSE_FROM_CHOICE(ent,action) MACRO_BEGIN \ - if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) { \ - switch (CS(ent).msg_choice_choices[net_name.nent_choice_idx]) \ - { \ - case 1: found_choice = notif.nent_optiona; break; \ - case 2: found_choice = notif.nent_optionb; break; \ - default: action; \ - } \ - } else { \ - found_choice = notif.nent_optiona; \ + #define RECURSE_FROM_CHOICE(ent, action) \ + MACRO_BEGIN \ + if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) { \ + switch (CS(ent).msg_choice_choices[net_name.nent_choice_idx]) { \ + case 1: found_choice = notif.nent_optiona; break; \ + case 2: found_choice = notif.nent_optionb; break; \ + default: action; \ } \ - Send_Notification_WOVA( \ - NOTIF_ONE_ONLY, \ - ent, \ - found_choice.nent_type, \ - found_choice, \ - found_choice.nent_stringcount, \ - found_choice.nent_floatcount, \ - s1, s2, s3, s4, \ - f1, f2, f3, f4); \ - MACRO_END - - switch (broadcast) - { + } else { \ + found_choice = notif.nent_optiona; \ + } \ + Send_Notification_WOVA( \ + NOTIF_ONE_ONLY, \ + ent, \ + found_choice.nent_type, \ + found_choice, \ + found_choice.nent_stringcount, \ + found_choice.nent_floatcount, \ + s1, s2, s3, s4, \ + f1, f2, f3, f4); \ + MACRO_END + + switch (broadcast) { case NOTIF_ONE_ONLY: // we can potentially save processing power with this broadcast method { if (IS_REAL_CLIENT(client)) { - RECURSE_FROM_CHOICE(client, return); + RECURSE_FROM_CHOICE(client, return ); } break; } @@ -1643,9 +1578,7 @@ void Send_Notification( break; } } - } - else - { + } else { entity net_notif = new_pure(net_notification); IL_PUSH(g_notifications, net_notif); net_notif.owner = notif; @@ -1657,10 +1590,10 @@ void Send_Notification( net_notif.nent_floatcount = notif.nent_floatcount; for (int i = 0; i < net_notif.nent_stringcount; ++i) { - net_notif.nent_strings[i] = strzone(...(i, string)); + net_notif.nent_strings[i] = strzone(... (i, string)); } for (int i = 0; i < net_notif.nent_floatcount; ++i) { - net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); + net_notif.nent_floats[i] = ... ((net_notif.nent_stringcount + i), float); } setthink(net_notif, Net_Notification_Remove); @@ -1673,45 +1606,36 @@ void Send_Notification( } // WOVA = Without Variable Arguments -void Send_Notification_WOVA( - NOTIF broadcast, entity client, - MSG net_type, Notification net_name, - float stringcount, float floatcount, - string s1, string s2, string s3, string s4, - float f1, float f2, float f3, float f4) +void Send_Notification_WOVA(NOTIF broadcast, entity client, MSG net_type, Notification net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4) { #ifdef NOTIFICATIONS_DEBUG entity notif = net_name; Debug_Notification(sprintf( "Send_Notification_WOVA(%s, %d, %d, %s, %s);\n", sprintf( - "%s, '%s', %s, %s", - Get_Notif_BroadcastName(broadcast), - client.classname, - Get_Notif_TypeName(net_type), - notif.nent_name + "%s, '%s', %s, %s", + Get_Notif_BroadcastName(broadcast), + client.classname, + Get_Notif_TypeName(net_type), + notif.nent_name ), stringcount, floatcount, MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)), sprintf("%d, %d, %d, %d", f1, f2, f3, f4) - )); + )); #endif #define VARITEM(stringc, floatc, args) \ - if ((stringcount == stringc) && (floatcount == floatc)) \ - { Send_Notification(broadcast, client, net_type, net_name, args); return; } + if ((stringcount == stringc) && (floatcount == floatc)) \ + { Send_Notification(broadcast, client, net_type, net_name, args); return; } EIGHT_VARS_TO_VARARGS_VARLIST #undef VARITEM Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all } // WOCOVA = Without Counts Or Variable Arguments -void Send_Notification_WOCOVA( - NOTIF broadcast, entity client, - MSG net_type, Notification net_name, - string s1, string s2, string s3, string s4, - float f1, float f2, float f3, float f4) +void Send_Notification_WOCOVA(NOTIF broadcast, entity client, MSG net_type, Notification net_name, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4) { entity notif = net_name; @@ -1719,20 +1643,20 @@ void Send_Notification_WOCOVA( Debug_Notification(sprintf( "Send_Notification_WOCOVA(%s, %s, %s);\n", sprintf( - "%s, '%s', %s, %s", - Get_Notif_BroadcastName(broadcast), - client.classname, - Get_Notif_TypeName(net_type), - notif.nent_name + "%s, '%s', %s, %s", + Get_Notif_BroadcastName(broadcast), + client.classname, + Get_Notif_TypeName(net_type), + notif.nent_name ), MakeConsoleSafe(sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4)), sprintf("%d, %d, %d, %d", f1, f2, f3, f4) - )); + )); #endif #define VARITEM(stringc, floatc, args) \ - if ((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \ - { Send_Notification(broadcast, client, net_type, net_name, args); return; } + if ((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \ + { Send_Notification(broadcast, client, net_type, net_name, args); return; } EIGHT_VARS_TO_VARARGS_VARLIST #undef VARITEM Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all diff --git a/qcsrc/common/physics/movelib.qc b/qcsrc/common/physics/movelib.qc index e66e3c9a9..1c041c796 100644 --- a/qcsrc/common/physics/movelib.qc +++ b/qcsrc/common/physics/movelib.qc @@ -9,29 +9,29 @@ **/ vector movelib_dragvec(entity this, float drag, float exp_) { - float lspeed,ldrag; + float lspeed, ldrag; - lspeed = vlen(this.velocity); - ldrag = lspeed * drag; - ldrag = ldrag * (drag * exp_); - ldrag = 1 - (ldrag / lspeed); + lspeed = vlen(this.velocity); + ldrag = lspeed * drag; + ldrag = ldrag * (drag * exp_); + ldrag = 1 - (ldrag / lspeed); - return this.velocity * ldrag; + return this.velocity * ldrag; } /** Simulate drag this.velocity *= movelib_dragflt(somespeed,0.01,0.7); **/ -float movelib_dragflt(float fspeed,float drag,float exp_) +float movelib_dragflt(float fspeed, float drag, float exp_) { - float ldrag; + float ldrag; - ldrag = fspeed * drag; - ldrag = ldrag * ldrag * exp_; - ldrag = 1 - (ldrag / fspeed); + ldrag = fspeed * drag; + ldrag = ldrag * ldrag * exp_; + ldrag = 1 - (ldrag / fspeed); - return ldrag; + return ldrag; } /** @@ -39,68 +39,69 @@ float movelib_dragflt(float fspeed,float drag,float exp_) Basicaly, this allows you to simulate loss of steering with higher speed. this.velocity = movelib_inertmove_byspeed(this.velocity,newvel,1000,0.1,0.9); **/ -vector movelib_inertmove_byspeed(entity this, vector vel_new, float vel_max,float newmin,float oldmax) +vector movelib_inertmove_byspeed(entity this, vector vel_new, float vel_max, float newmin, float oldmax) { - float influense; + float influense; - influense = vlen(this.velocity) * (1 / vel_max); + influense = vlen(this.velocity) * (1 / vel_max); - influense = bound(newmin,influense,oldmax); + influense = bound(newmin, influense, oldmax); - return (vel_new * (1 - influense)) + (this.velocity * influense); + return (vel_new * (1 - influense)) + (this.velocity * influense); } -vector movelib_inertmove(entity this, vector new_vel,float new_bias) +vector movelib_inertmove(entity this, vector new_vel, float new_bias) { - return new_vel * new_bias + this.velocity * (1-new_bias); + return new_vel * new_bias + this.velocity * (1 - new_bias); } -void movelib_move(entity this, vector force,float max_velocity,float drag,float theMass,float breakforce) +void movelib_move(entity this, vector force, float max_velocity, float drag, float theMass, float breakforce) { - float deltatime; - float acceleration; - float mspeed; - vector breakvec; - - deltatime = time - this.movelib_lastupdate; - if (deltatime > 0.15) deltatime = 0; - this.movelib_lastupdate = time; - if (!deltatime) return; - - mspeed = vlen(this.velocity); - - if (theMass) - acceleration = vlen(force) / theMass; - else - acceleration = vlen(force); - - if (IS_ONGROUND(this)) - { - if (breakforce) - { - breakvec = (normalize(this.velocity) * (breakforce / theMass) * deltatime); - this.velocity = this.velocity - breakvec; - } - - this.velocity = this.velocity + force * (acceleration * deltatime); - } - - if (drag) - this.velocity = movelib_dragvec(this, drag, 1); - - if (this.waterlevel > 1) - { - this.velocity = this.velocity + force * (acceleration * deltatime); - this.velocity = this.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime; - } - else - this.velocity = this.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime; - - mspeed = vlen(this.velocity); - - if (max_velocity) - if (mspeed > max_velocity) - this.velocity = normalize(this.velocity) * (mspeed - 50);//* max_velocity; + float deltatime; + float acceleration; + float mspeed; + vector breakvec; + + deltatime = time - this.movelib_lastupdate; + if (deltatime > 0.15) { deltatime = 0; } + this.movelib_lastupdate = time; + if (!deltatime) { return; } + + mspeed = vlen(this.velocity); + + if (theMass) { + acceleration = vlen(force) / theMass; + } else { + acceleration = vlen(force); + } + + if (IS_ONGROUND(this)) { + if (breakforce) { + breakvec = (normalize(this.velocity) * (breakforce / theMass) * deltatime); + this.velocity = this.velocity - breakvec; + } + + this.velocity = this.velocity + force * (acceleration * deltatime); + } + + if (drag) { + this.velocity = movelib_dragvec(this, drag, 1); + } + + if (this.waterlevel > 1) { + this.velocity = this.velocity + force * (acceleration * deltatime); + this.velocity = this.velocity + '0 0 0.05' * autocvar_sv_gravity * deltatime; + } else { + this.velocity = this.velocity + '0 0 -1' * autocvar_sv_gravity * deltatime; + } + + mspeed = vlen(this.velocity); + + if (max_velocity) { + if (mspeed > max_velocity) { + this.velocity = normalize(this.velocity) * (mspeed - 50); // * max_velocity; + } + } } /* @@ -165,15 +166,15 @@ void movelib_update(entity this, vector dir,float force) void movelib_brake_simple(entity this, float force) { - float mspeed; - vector mdir; - float vz; - - mspeed = max(0,vlen(this.velocity) - force); - mdir = normalize(this.velocity); - vz = this.velocity.z; - this.velocity = mdir * mspeed; - this.velocity_z = vz; + float mspeed; + vector mdir; + float vz; + + mspeed = max(0, vlen(this.velocity) - force); + mdir = normalize(this.velocity); + vz = this.velocity.z; + this.velocity = mdir * mspeed; + this.velocity_z = vz; } /** @@ -184,54 +185,53 @@ Yed need to set v_up and v_forward (generally by calling makevectors) before cal void movelib_groundalign4point(entity this, float spring_length, float spring_up, float blendrate, float _max) { - vector a, b, c, d, e, r, push_angle, ahead, side; + vector a, b, c, d, e, r, push_angle, ahead, side; - push_angle.y = 0; - r = (this.absmax + this.absmin) * 0.5 + (v_up * spring_up); - e = v_up * spring_length; + push_angle.y = 0; + r = (this.absmax + this.absmin) * 0.5 + (v_up * spring_up); + e = v_up * spring_length; - // Put springs slightly inside bbox - ahead = v_forward * (this.maxs.x * 0.8); - side = v_right * (this.maxs.y * 0.8); + // Put springs slightly inside bbox + ahead = v_forward * (this.maxs.x * 0.8); + side = v_right * (this.maxs.y * 0.8); - a = r + ahead + side; - b = r + ahead - side; - c = r - ahead + side; - d = r - ahead - side; + a = r + ahead + side; + b = r + ahead - side; + c = r - ahead + side; + d = r - ahead - side; - traceline(a, a - e,MOVE_NORMAL,this); - a.z = (1 - trace_fraction); - r = trace_endpos; + traceline(a, a - e, MOVE_NORMAL, this); + a.z = (1 - trace_fraction); + r = trace_endpos; - traceline(b, b - e,MOVE_NORMAL,this); - b.z = (1 - trace_fraction); - r += trace_endpos; + traceline(b, b - e, MOVE_NORMAL, this); + b.z = (1 - trace_fraction); + r += trace_endpos; - traceline(c, c - e,MOVE_NORMAL,this); - c.z = (1 - trace_fraction); - r += trace_endpos; + traceline(c, c - e, MOVE_NORMAL, this); + c.z = (1 - trace_fraction); + r += trace_endpos; - traceline(d, d - e,MOVE_NORMAL,this); - d.z = (1 - trace_fraction); - r += trace_endpos; + traceline(d, d - e, MOVE_NORMAL, this); + d.z = (1 - trace_fraction); + r += trace_endpos; - a.x = r.z; - r = this.origin; - r.z = r.z; + a.x = r.z; + r = this.origin; + r.z = r.z; - push_angle.x = (a.z - c.z) * _max; - push_angle.x += (b.z - d.z) * _max; + push_angle.x = (a.z - c.z) * _max; + push_angle.x += (b.z - d.z) * _max; - push_angle.z = (b.z - a.z) * _max; - push_angle.z += (d.z - c.z) * _max; + push_angle.z = (b.z - a.z) * _max; + push_angle.z += (d.z - c.z) * _max; - //this.angles_x += push_angle_x * 0.95; - //this.angles_z += push_angle_z * 0.95; + // this.angles_x += push_angle_x * 0.95; + // this.angles_z += push_angle_z * 0.95; - this.angles_x = ((1-blendrate) * this.angles.x) + (push_angle.x * blendrate); - this.angles_z = ((1-blendrate) * this.angles.z) + (push_angle.z * blendrate); + this.angles_x = ((1 - blendrate) * this.angles.x) + (push_angle.x * blendrate); + this.angles_z = ((1 - blendrate) * this.angles.z) + (push_angle.z * blendrate); - //a = this.origin; - setorigin(this, r); + // a = this.origin; + setorigin(this, r); } - diff --git a/qcsrc/common/physics/movelib.qh b/qcsrc/common/physics/movelib.qh index e0659a40c..1bcab7921 100644 --- a/qcsrc/common/physics/movelib.qh +++ b/qcsrc/common/physics/movelib.qh @@ -13,7 +13,7 @@ vector movelib_dragvec(entity this, float drag, float exp_); Simulate drag this.velocity *= movelib_dragflt(somespeed,0.01,0.7); **/ -float movelib_dragflt(float fspeed,float drag,float exp_); +float movelib_dragflt(float fspeed, float drag, float exp_); /** Do a inertia simulation based on velocity. @@ -33,11 +33,11 @@ void movelib_move_simple(vector newdir,float velo,float blendrate) this.velocity = this.velocity * (1 - blendrate) + (newdir * blendrate) * velo; } */ -#define movelib_move_simple(e,newdir,velo,blendrate) \ - e.velocity = e.velocity * (1 - blendrate) + (newdir * blendrate) * velo +#define movelib_move_simple(e, newdir, velo, blendrate) \ + e.velocity = e.velocity * (1 - blendrate) + (newdir * blendrate) * velo -#define movelib_move_simple_gravity(e,newdir,velo,blendrate) \ - if(IS_ONGROUND(e)) movelib_move_simple(e,newdir,velo,blendrate) +#define movelib_move_simple_gravity(e, newdir, velo, blendrate) \ + if (IS_ONGROUND(e)) movelib_move_simple(e, newdir, velo, blendrate) void movelib_brake_simple(entity this, float force); diff --git a/qcsrc/common/physics/movetypes/follow.qc b/qcsrc/common/physics/movetypes/follow.qc index 300906905..b98144dc8 100644 --- a/qcsrc/common/physics/movetypes/follow.qc +++ b/qcsrc/common/physics/movetypes/follow.qc @@ -3,12 +3,9 @@ void _Movetype_Physics_Follow(entity this) // SV_Physics_Follow { entity e = this.aiment; - if(e.angles == this.punchangle) - { + if (e.angles == this.punchangle) { this.origin = e.origin + this.view_ofs; - } - else - { + } else { vector ang, v; ang_x = -this.punchangle_x; ang_y = this.punchangle_y; diff --git a/qcsrc/common/physics/movetypes/step.qc b/qcsrc/common/physics/movetypes/step.qc index a41269f79..91cc36474 100644 --- a/qcsrc/common/physics/movetypes/step.qc +++ b/qcsrc/common/physics/movetypes/step.qc @@ -1,18 +1,14 @@ #include "step.qh" void _Movetype_Physics_Step(entity this, float dt) // SV_Physics_Step { - if(IS_ONGROUND(this)) - { - if(this.velocity_z >= (1.0 / 32.0) && UPWARD_VELOCITY_CLEARS_ONGROUND(this)) - { + if (IS_ONGROUND(this)) { + if (this.velocity_z >= (1.0 / 32.0) && UPWARD_VELOCITY_CLEARS_ONGROUND(this)) { UNSET_ONGROUND(this); _Movetype_CheckVelocity(this); _Movetype_FlyMove(this, dt, true, '0 0 0', 0); _Movetype_LinkEdict(this, true); } - } - else - { + } else { _Movetype_CheckVelocity(this); _Movetype_FlyMove(this, dt, true, '0 0 0', 0); _Movetype_LinkEdict(this, true); diff --git a/qcsrc/common/physics/movetypes/toss.qc b/qcsrc/common/physics/movetypes/toss.qc index 71e7fa9d0..8c18264b2 100644 --- a/qcsrc/common/physics/movetypes/toss.qc +++ b/qcsrc/common/physics/movetypes/toss.qc @@ -1,19 +1,13 @@ #include "toss.qh" -void _Movetype_Physics_Toss(entity this, float dt) // SV_Physics_Toss +void _Movetype_Physics_Toss(entity this, float dt) // SV_Physics_Toss { - if (IS_ONGROUND(this)) - { - if (this.velocity.z >= 1 / 32 && UPWARD_VELOCITY_CLEARS_ONGROUND(this)) - { + if (IS_ONGROUND(this)) { + if (this.velocity.z >= 1 / 32 && UPWARD_VELOCITY_CLEARS_ONGROUND(this)) { UNSET_ONGROUND(this); - } - else if (!this.groundentity) - { + } else if (!this.groundentity) { return; - } - else if (this.move_suspendedinair && wasfreed(this.groundentity)) - { + } else if (this.move_suspendedinair && wasfreed(this.groundentity)) { this.groundentity = NULL; return; } @@ -25,15 +19,14 @@ void _Movetype_Physics_Toss(entity this, float dt) // SV_Physics_Toss /*if (this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) { - this.move_didgravity = 1; - this.velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1) - * dt - * (this.gravity ? this.gravity : 1) - * PHYS_GRAVITY(this); + this.move_didgravity = 1; + this.velocity_z -= (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1) + * dt + * (this.gravity ? this.gravity : 1) + * PHYS_GRAVITY(this); }*/ - if (this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) - { + if (this.move_movetype == MOVETYPE_BOUNCE || this.move_movetype == MOVETYPE_TOSS) { this.move_didgravity = true; this.velocity_z -= (((this.gravity) ? this.gravity : 1) * PHYS_GRAVITY(this) * dt); } @@ -41,80 +34,75 @@ void _Movetype_Physics_Toss(entity this, float dt) // SV_Physics_Toss this.angles = this.angles + this.avelocity * dt; float movetime = dt; - for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; ++bump) - { + for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; ++bump) { vector move = this.velocity * movetime; _Movetype_PushEntity(this, move, true); - if (wasfreed(this)) + if (wasfreed(this)) { return; + } - if (trace_startsolid) - { + if (trace_startsolid) { _Movetype_UnstickEntity(this); _Movetype_PushEntity(this, move, false); - if (wasfreed(this)) + if (wasfreed(this)) { return; + } } - if (trace_fraction == 1) + if (trace_fraction == 1) { break; + } movetime *= 1 - min(1, trace_fraction); - if (this.move_movetype == MOVETYPE_BOUNCEMISSILE) - { + if (this.move_movetype == MOVETYPE_BOUNCEMISSILE) { this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 2.0); UNSET_ONGROUND(this); - } - else if (this.move_movetype == MOVETYPE_BOUNCE) - { - float bouncefac = this.bouncefactor; if (!bouncefac) bouncefac = 0.5; - float bstop = this.bouncestop; if (!bstop) bstop = 60 / 800; + } else if (this.move_movetype == MOVETYPE_BOUNCE) { + float bouncefac = this.bouncefactor; + if (!bouncefac) { bouncefac = 0.5; } + float bstop = this.bouncestop; + if (!bstop) { bstop = 60 / 800; } bstop *= (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this); this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1 + bouncefac); float d = trace_plane_normal * this.velocity; - if (trace_plane_normal.z > 0.7 && d < bstop && d > -bstop) - { + if (trace_plane_normal.z > 0.7 && d < bstop && d > -bstop) { SET_ONGROUND(this); this.groundentity = trace_ent; this.velocity = '0 0 0'; this.avelocity = '0 0 0'; - } - else - { + } else { UNSET_ONGROUND(this); } - } - else - { + } else { this.velocity = _Movetype_ClipVelocity(this.velocity, trace_plane_normal, 1.0); - if (trace_plane_normal.z > 0.7) - { + if (trace_plane_normal.z > 0.7) { SET_ONGROUND(this); this.groundentity = trace_ent; - if (trace_ent.solid == SOLID_BSP) + if (trace_ent.solid == SOLID_BSP) { this.move_suspendedinair = true; + } this.velocity = '0 0 0'; this.avelocity = '0 0 0'; - } - else - { + } else { UNSET_ONGROUND(this); } } // DP revision 8905 (just, WHY...) - if (this.move_movetype == MOVETYPE_BOUNCEMISSILE) + if (this.move_movetype == MOVETYPE_BOUNCEMISSILE) { break; + } // DP revision 8918 (WHY...) - if (IS_ONGROUND(this)) + if (IS_ONGROUND(this)) { break; + } } - //if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE && this.move_didgravity > 0 && !IS_ONGROUND(this)) + // if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE && this.move_didgravity > 0 && !IS_ONGROUND(this)) // this.velocity_z -= 0.5 * dt * (this.gravity ? this.gravity : 1) * PHYS_GRAVITY(this); _Movetype_CheckWaterTransition(this); diff --git a/qcsrc/common/physics/movetypes/walk.qc b/qcsrc/common/physics/movetypes/walk.qc index c20e82e83..398901ad3 100644 --- a/qcsrc/common/physics/movetypes/walk.qc +++ b/qcsrc/common/physics/movetypes/walk.qc @@ -1,14 +1,16 @@ #include "walk.qh" -void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove +void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove { vector stepnormal = '0 0 0'; // if frametime is 0 (due to client sending the same timestamp twice), don't move - if (dt <= 0) + if (dt <= 0) { return; + } - if (GAMEPLAYFIX_UNSTICKPLAYERS(this)) + if (GAMEPLAYFIX_UNSTICKPLAYERS(this)) { _Movetype_UnstickEntity(this); + } bool applygravity = (!_Movetype_CheckWater(this) && this.move_movetype == MOVETYPE_WALK && !(this.flags & FL_WATERJUMP)); @@ -22,41 +24,45 @@ void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove int clip = _Movetype_FlyMove(this, dt, applygravity, stepnormal, GAMEPLAYFIX_STEPMULTIPLETIMES(this) ? PHYS_STEPHEIGHT(this) : 0); - if (GAMEPLAYFIX_DOWNTRACEONGROUND(this) && !(clip & 1)) - { + if (GAMEPLAYFIX_DOWNTRACEONGROUND(this) && !(clip & 1)) { // only try this if there was no floor in the way in the trace (no, // this check seems to be not REALLY necessary, because if clip & 1, // our trace will hit that thing too) vector upmove = this.origin + '0 0 1'; vector downmove = this.origin - '0 0 1'; int type; - if (this.move_movetype == MOVETYPE_FLYMISSILE) + if (this.move_movetype == MOVETYPE_FLYMISSILE) { type = MOVE_MISSILE; - else if (this.move_movetype == MOVETYPE_FLY_WORLDONLY) + } else if (this.move_movetype == MOVETYPE_FLY_WORLDONLY) { type = MOVE_WORLDONLY; - else if (this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT) + } else if (this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT) { type = MOVE_NOMONSTERS; - else type = MOVE_NORMAL; + } else { type = MOVE_NORMAL; } tracebox(upmove, this.mins, this.maxs, downmove, type, this); - if (trace_fraction < 1 && trace_plane_normal.z > 0.7) - clip |= 1; // but we HAVE found a floor + if (trace_fraction < 1 && trace_plane_normal.z > 0.7) { + clip |= 1; // but we HAVE found a floor + } } // if the move did not hit the ground at any point, we're not on ground - if (!(clip & 1)) + if (!(clip & 1)) { UNSET_ONGROUND(this); + } _Movetype_CheckVelocity(this); _Movetype_LinkEdict(this, true); - if (clip & 8) // teleport + if (clip & 8) { // teleport return; + } - if (this.flags & FL_WATERJUMP) + if (this.flags & FL_WATERJUMP) { return; + } - if (PHYS_NOSTEP(this)) + if (PHYS_NOSTEP(this)) { return; + } vector originalorigin = this.origin; vector originalvelocity = this.velocity; @@ -65,22 +71,24 @@ void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove entity originalmove_groundentity = this.groundentity; // if move didn't block on a step, return - if (clip & 2) - { + if (clip & 2) { // if move was not trying to move into the step, return - if (fabs(start_velocity.x) < 0.03125 && fabs(start_velocity.y) < 0.03125) + if (fabs(start_velocity.x) < 0.03125 && fabs(start_velocity.y) < 0.03125) { return; + } - if (this.move_movetype != MOVETYPE_FLY) - { + if (this.move_movetype != MOVETYPE_FLY) { // return if gibbed by a trigger - if (this.move_movetype != MOVETYPE_WALK) + if (this.move_movetype != MOVETYPE_WALK) { return; + } // return if attempting to jump while airborn (unless sv_jumpstep) - if (!PHYS_JUMPSTEP(this)) - if (!oldonground && this.waterlevel == 0) + if (!PHYS_JUMPSTEP(this)) { + if (!oldonground && this.waterlevel == 0) { return; + } + } } // try moving up and forward to go up a step @@ -91,10 +99,10 @@ void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove // move up vector upmove = '0 0 1' * PHYS_STEPHEIGHT(this); _Movetype_PushEntity(this, upmove, true); - if(wasfreed(this)) + if (wasfreed(this)) { return; - if(trace_startsolid) - { + } + if (trace_startsolid) { // we got teleported when upstepping... must abort the move return; } @@ -103,8 +111,7 @@ void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove this.velocity_z = 0; clip = _Movetype_FlyMove(this, dt, applygravity, stepnormal, 0); this.velocity_z += start_velocity.z; - if (clip & 8) - { + if (clip & 8) { // we got teleported when upstepping... must abort the move // note that z velocity handling may not be what QC expects here, but we cannot help it return; @@ -116,9 +123,8 @@ void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove // check for stuckness, possibly due to the limited precision of floats // in the clipping hulls if (clip - && fabs(originalorigin.y - this.origin.y) < 0.03125 - && fabs(originalorigin.x - this.origin.x) < 0.03125) - { + && fabs(originalorigin.y - this.origin.y) < 0.03125 + && fabs(originalorigin.x - this.origin.x) < 0.03125) { // Con_Printf("wall\n"); // stepping up didn't make any progress, revert to original move this.origin = originalorigin; @@ -134,34 +140,31 @@ void _Movetype_Physics_Walk(entity this, float dt) // SV_WalkMove // Con_Printf("step - "); // extra friction based on view angle - if ((clip & 2) && PHYS_WALLFRICTION(this)) + if ((clip & 2) && PHYS_WALLFRICTION(this)) { _Movetype_WallFriction(this, stepnormal); + } } // don't do the down move if stepdown is disabled, moving upward, not in water, or the move started offground or ended onground - else if (!GAMEPLAYFIX_STEPDOWN(this) || this.waterlevel >= 3 || start_velocity.z >= (1.0 / 32.0) || !oldonground || IS_ONGROUND(this)) - { + else if (!GAMEPLAYFIX_STEPDOWN(this) || this.waterlevel >= 3 || start_velocity.z >= (1.0 / 32.0) || !oldonground || IS_ONGROUND(this)) { return; } // move down vector downmove = '0 0 1' * (-PHYS_STEPHEIGHT(this) + start_velocity.z * dt); _Movetype_PushEntity(this, downmove, true); - if(wasfreed(this)) + if (wasfreed(this)) { return; + } - if(trace_startsolid) - { + if (trace_startsolid) { // we got teleported when downstepping... must abort the move return; } - if (trace_fraction < 1 && trace_plane_normal.z > 0.7) - { + if (trace_fraction < 1 && trace_plane_normal.z > 0.7) { // this has been disabled so that you can't jump when you are stepping // up while already jumping (also known as the Quake2 double jump bug) - } - else - { + } else { // Con_Printf("slope\n"); // if the push down didn't end up on good ground, use the move without // the step up. This happens near wall / slope combinations, and can diff --git a/qcsrc/common/sounds/all.qh b/qcsrc/common/sounds/all.qh index b7b296341..748e59b22 100644 --- a/qcsrc/common/sounds/all.qh +++ b/qcsrc/common/sounds/all.qh @@ -7,14 +7,18 @@ REGISTRY(Sounds, BITS(9)) REGISTER_REGISTRY(Sounds) #define SOUND(name, path) \ - string SND_##name##_get() { return path; } \ - REGISTER(Sounds, SND, name, m_id, NEW(Sound, SND_##name##_get)) + string SND_##name##_get() \ + { \ + return path; \ + } \ + REGISTER(Sounds, SND, name, m_id, NEW(Sound, SND_##name##_get)) /** @deprecated Used in places where a string is required for legacy reasons, prefer using SND_id constants instead */ #define SND(id) Sound_fixpath(SND_##id) -PRECACHE(Sounds) { - FOREACH(Sounds, true, it.sound_precache(it)); +PRECACHE(Sounds) +{ + FOREACH(Sounds, true, it.sound_precache(it)); } SOUND(Null, "misc/null"); diff --git a/qcsrc/common/sounds/sound.qh b/qcsrc/common/sounds/sound.qh index 0ff10a9ae..de75c742f 100644 --- a/qcsrc/common/sounds/sound.qh +++ b/qcsrc/common/sounds/sound.qh @@ -40,11 +40,12 @@ const float VOL_MUFFLED = 0.35; // Otherwise, channels 8 to 15 would be blocked for a weird QW feature. #ifdef SVQC #define _sound(e, c, s, v, a) \ - MACRO_BEGIN \ - entity __e = e; \ - if (sound_allowed(MSG_BROADCAST, __e)) \ - sound7(__e, c, s, v, a, 0, 0); \ - MACRO_END + MACRO_BEGIN \ + entity __e = e; \ + if (sound_allowed(MSG_BROADCAST, __e)) { \ + sound7(__e, c, s, v, a, 0, 0); \ + } \ + MACRO_END #else #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0) #endif @@ -68,9 +69,7 @@ const float VOL_MUFFLED = 0.35; int __chan = chan; \ string __samp = samp; \ bool auto = false; \ - if (__chan > 0) __e = e; \ - else \ - { \ + if (__chan > 0) { __e = e; } else { \ auto = true; \ __chan = fabs(__chan); \ entity tmp = __e = new(csqc_autochannel); \ @@ -83,8 +82,7 @@ const float VOL_MUFFLED = 0.35; setorigin(__e, o); \ setsize(__e, '0 0 0', '0 0 0'); \ sound7(__e, __chan, __samp, vol, atten, speed, sf); \ - if (!auto) \ - { \ + if (!auto) { \ setorigin(__e, old_origin); \ setsize(__e, old_mins, old_maxs); \ } \ @@ -101,16 +99,16 @@ CLASS(Sound, Object) #define Sound_fixpath(this) _Sound_fixpath((this).sound_str()) string _Sound_fixpath(string base) { - if (base == "") return string_null; + if (base == "") { return string_null; } #ifdef SVQC - return strcat(base, ".wav"); // let the client engine decide + return strcat(base, ".wav"); // let the client engine decide #else #define extensions(x) \ - x(wav) \ - x(ogg) \ - x(flac) \ - /**/ - #define tryext(ext) { string s = strcat(base, "." #ext); if (fexists(strcat("sound/", s))) return s; } + x(wav) \ + x(ogg) \ + x(flac) \ + /**/ + #define tryext(ext) { string s = strcat(base, "." #ext); if (fexists(strcat("sound/", s))) { return s; } } extensions(tryext); LOG_WARNF("Missing sound: \"%s\"", strcat("sound/", base)); #undef tryext @@ -120,9 +118,9 @@ CLASS(Sound, Object) } METHOD(Sound, sound_precache, void(Sound this)) { - TC(Sound, this); + TC(Sound, this); string s = Sound_fixpath(this); - if (!s) return; + if (!s) { return; } profile(sprintf("precache_sound(\"%s\")", s)); precache_sound(s); } diff --git a/qcsrc/common/state.qh b/qcsrc/common/state.qh index 42fc450c4..2d94705b9 100644 --- a/qcsrc/common/state.qh +++ b/qcsrc/common/state.qh @@ -44,7 +44,7 @@ ENDCLASS(ClientState) #if NDEBUG #define CS(this) (this._cs) #else - ClientState CS(Client this) { TC(Client, this); assert(this._cs); return this._cs; } +ClientState CS(Client this) { TC(Client, this); assert(this._cs); return this._cs; } #endif void ClientState_attach(entity this); diff --git a/qcsrc/common/triggers/func/bobbing.qc b/qcsrc/common/triggers/func/bobbing.qc index ff8841a57..12aa29946 100644 --- a/qcsrc/common/triggers/func/bobbing.qc +++ b/qcsrc/common/triggers/func/bobbing.qc @@ -6,8 +6,7 @@ void func_bobbing_controller_think(entity this) vector v; this.nextthink = time + 0.1; - if(this.owner.active != ACTIVE_ACTIVE) - { + if (this.owner.active != ACTIVE_ACTIVE) { this.owner.velocity = '0 0 0'; return; } @@ -15,9 +14,10 @@ void func_bobbing_controller_think(entity this) // calculate sinewave using makevectors makevectors((this.nextthink * this.owner.cnt + this.owner.phase * 360) * '0 1 0'); v = this.owner.destvec + this.owner.movedir * v_forward_y; - if(this.owner.classname == "func_bobbing") // don't brake stuff if the func_bobbing was killtarget'ed + if (this.owner.classname == "func_bobbing") { // don't brake stuff if the func_bobbing was killtarget'ed // * 10 so it will arrive in 0.1 sec this.owner.velocity = (v - this.owner.origin) * 10; + } } /*QUAKED spawnfunc_func_bobbing (0 .5 .8) ? X_AXIS Y_AXIS @@ -32,15 +32,16 @@ dmgtime : See above. spawnfunc(func_bobbing) { entity controller; - if (this.noise != "") - { + if (this.noise != "") { precache_sound(this.noise); soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE); } - if (!this.speed) + if (!this.speed) { this.speed = 4; - if (!this.height) + } + if (!this.height) { this.height = 32; + } // center of bobbing motion this.destvec = this.origin; // time scale to get degrees @@ -50,24 +51,29 @@ spawnfunc(func_bobbing) // damage when blocked setblocked(this, generic_plat_blocked); - if(this.dmg && (this.message == "")) + if (this.dmg && (this.message == "")) { this.message = " was squished"; - if(this.dmg && (this.message2 == "")) + } + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; - if(this.dmg && (!this.dmgtime)) + } + if (this.dmg && (!this.dmgtime)) { this.dmgtime = 0.25; + } this.dmgtime2 = time; // how far to bob - if (this.spawnflags & 1) // X + if (this.spawnflags & 1) { // X this.movedir = '1 0 0' * this.height; - else if (this.spawnflags & 2) // Y + } else if (this.spawnflags & 2) { // Y this.movedir = '0 1 0' * this.height; - else // Z + } else { // Z this.movedir = '0 0 1' * this.height; + } - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } // wait for targets to spawn controller = new(func_bobbing_controller); diff --git a/qcsrc/common/triggers/func/conveyor.qc b/qcsrc/common/triggers/func/conveyor.qc index 960ee2150..163e8b958 100644 --- a/qcsrc/common/triggers/func/conveyor.qc +++ b/qcsrc/common/triggers/func/conveyor.qc @@ -7,7 +7,7 @@ void conveyor_think(entity this) // TODO: check if this is what is causing the glitchiness when switching between them float dt = time - this.move_time; this.move_time = time; - if(dt <= 0) { return; } + if (dt <= 0) { return; } #endif // set myself as current conveyor where possible @@ -17,31 +17,30 @@ void conveyor_think(entity this) IL_REMOVE(g_conveyed, it); }); - if(this.state) - { + if (this.state) { FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.conveyor.state && isPushable(it), { vector emin = it.absmin; vector emax = it.absmax; - if(this.solid == SOLID_BSP) - { + if (this.solid == SOLID_BSP) { emin -= '1 1 1'; emax += '1 1 1'; } - if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick - if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate - { - if(!it.conveyor) + if (boxesoverlap(emin, emax, this.absmin, this.absmax)) { // quick + if (WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) { // accurate + if (!it.conveyor) { IL_PUSH(g_conveyed, it); + } it.conveyor = this; } + } }); IL_EACH(g_conveyed, it.conveyor == this, { - if(IS_CLIENT(it)) // doing it via velocity has quite some advantages + if (IS_CLIENT(it)) { // doing it via velocity has quite some advantages continue; // done in SV_PlayerPhysics continue; - + } setorigin(it, it.origin + this.movedir * PHYS_INPUT_FRAMETIME); move_out_of_solid(it); #ifdef SVQC @@ -51,7 +50,7 @@ void conveyor_think(entity this) // stupid conveyor code tracebox(it.origin, it.mins, it.maxs, it.origin + this.movedir * sys_frametime, MOVE_NORMAL, it); if(trace_fraction > 0) - setorigin(it, trace_endpos); + setorigin(it, trace_endpos); */ }); } @@ -82,8 +81,7 @@ bool conveyor_send(entity this, entity to, int sf) WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR); WriteByte(MSG_ENTITY, sf); - if(sf & 1) - { + if (sf & 1) { WriteByte(MSG_ENTITY, this.warpzone_isboxy); WriteCoord(MSG_ENTITY, this.origin_x); WriteCoord(MSG_ENTITY, this.origin_y); @@ -107,26 +105,26 @@ bool conveyor_send(entity this, entity to, int sf) WriteString(MSG_ENTITY, this.target); } - if(sf & 2) + if (sf & 2) { WriteByte(MSG_ENTITY, this.state); + } return true; } void conveyor_init(entity this) { - if (!this.speed) this.speed = 200; + if (!this.speed) { this.speed = 200; } this.movedir *= this.speed; setthink(this, conveyor_think); this.nextthink = time; - if(THIS_TARGETED) - { + if (THIS_TARGETED) { this.use = conveyor_use; this.reset = conveyor_reset; this.reset(this); - } - else + } else { this.state = 1; + } FixSize(this); @@ -156,8 +154,9 @@ void conveyor_draw(entity this) { conveyor_think(this); } void conveyor_init(entity this, bool isnew) { - if(isnew) + if (isnew) { IL_PUSH(g_drawables, this); + } this.draw = conveyor_draw; this.drawmask = MASK_NORMAL; @@ -171,8 +170,7 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew) { int sf = ReadByte(); - if(sf & 1) - { + if (sf & 1) { this.warpzone_isboxy = ReadByte(); this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); @@ -200,8 +198,9 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew) conveyor_init(this, isnew); } - if(sf & 2) + if (sf & 2) { this.state = ReadByte(); + } return true; } diff --git a/qcsrc/common/triggers/func/conveyor.qh b/qcsrc/common/triggers/func/conveyor.qh index c12b52d2d..ce4db5f8d 100644 --- a/qcsrc/common/triggers/func/conveyor.qh +++ b/qcsrc/common/triggers/func/conveyor.qh @@ -1,4 +1,7 @@ #pragma once IntrusiveList g_conveyed; -STATIC_INIT(g_conveyed) { g_conveyed = IL_NEW(); } +STATIC_INIT(g_conveyed) +{ + g_conveyed = IL_NEW(); +} diff --git a/qcsrc/common/triggers/func/door.qc b/qcsrc/common/triggers/func/door.qc index 1f9b6239e..3c8521fa8 100644 --- a/qcsrc/common/triggers/func/door.qc +++ b/qcsrc/common/triggers/func/door.qc @@ -28,58 +28,51 @@ void door_rotating_go_up(entity this, entity oth); void door_blocked(entity this, entity blocker) { - if((this.spawnflags & 8) + if ((this.spawnflags & 8) #ifdef SVQC && (blocker.takedamage != DAMAGE_NO) #elif defined(CSQC) && !IS_DEAD(blocker) #endif - ) - { // KIll Kill Kill!! + ) { // KIll Kill Kill!! #ifdef SVQC - Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + Damage(blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); #endif - } - else - { + } else { #ifdef SVQC - if((this.dmg) && (blocker.takedamage == DAMAGE_YES)) // Shall we bite? - Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + if ((this.dmg) && (blocker.takedamage == DAMAGE_YES)) { // Shall we bite? + Damage(blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + } #endif - // don't change direction for dead or dying stuff - if(IS_DEAD(blocker) + // don't change direction for dead or dying stuff + if (IS_DEAD(blocker) #ifdef SVQC && (blocker.takedamage == DAMAGE_NO) #endif - ) - { - if (this.wait >= 0) - { - if (this.state == STATE_DOWN) - if (this.classname == "door") - { - door_go_up (this); - } else - { - door_rotating_go_up(this, blocker); - } - else - if (this.classname == "door") - { - door_go_down (this); - } else - { - door_rotating_go_down (this); - } + ) { + if (this.wait >= 0) { + if (this.state == STATE_DOWN) { + if (this.classname == "door") { + door_go_up(this); + } else { + door_rotating_go_up(this, blocker); + } + } else { + if (this.classname == "door") { + door_go_down(this); + } else { + door_rotating_go_down(this); + } + } } } #ifdef SVQC - else - { - //gib dying stuff just to make sure - if((this.dmg) && (blocker.takedamage != DAMAGE_NO)) // Shall we bite? - Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + else { + // gib dying stuff just to make sure + if ((this.dmg) && (blocker.takedamage != DAMAGE_NO)) { // Shall we bite? + Damage(blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + } } #endif } @@ -87,16 +80,16 @@ void door_blocked(entity this, entity blocker) void door_hit_top(entity this) { - if (this.noise1 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + if (this.noise1 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + } this.state = STATE_TOP; - if (this.spawnflags & DOOR_TOGGLE) - return; // don't come down automatically - if (this.classname == "door") - { + if (this.spawnflags & DOOR_TOGGLE) { + return; // don't come down automatically + } + if (this.classname == "door") { setthink(this, door_go_down); - } else - { + } else { setthink(this, door_rotating_go_down); } this.nextthink = this.ltime + this.wait; @@ -104,40 +97,41 @@ void door_hit_top(entity this) void door_hit_bottom(entity this) { - if (this.noise1 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + if (this.noise1 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + } this.state = STATE_BOTTOM; } void door_go_down(entity this) { - if (this.noise2 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); - if (this.max_health) - { + if (this.noise2 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } + if (this.max_health) { this.takedamage = DAMAGE_YES; this.health = this.max_health; } this.state = STATE_DOWN; - SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, door_hit_bottom); + SUB_CalcMove(this, this.pos1, TSPEED_LINEAR, this.speed, door_hit_bottom); } void door_go_up(entity this) { - if (this.state == STATE_UP) - return; // already going up - - if (this.state == STATE_TOP) - { // reset top wait time + if (this.state == STATE_UP) { + return; // already going up + } + if (this.state == STATE_TOP) { // reset top wait time this.nextthink = this.ltime + this.wait; return; } - if (this.noise2 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + if (this.noise2 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } this.state = STATE_UP; - SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, door_hit_top); + SUB_CalcMove(this, this.pos2, TSPEED_LINEAR, this.speed, door_hit_top); string oldmessage; oldmessage = this.message; @@ -157,17 +151,20 @@ ACTIVATION FUNCTIONS bool door_check_keys(entity door, entity player) { - if(door.owner) + if (door.owner) { door = door.owner; + } // no key needed - if(!door.itemkeys) + if (!door.itemkeys) { return true; + } // this door require a key // only a player can have a key - if(!IS_PLAYER(player)) + if (!IS_PLAYER(player)) { return false; + } entity store = player; #ifdef SVQC @@ -176,8 +173,7 @@ bool door_check_keys(entity door, entity player) int valid = (door.itemkeys & store.itemkeys); door.itemkeys &= ~valid; // only some of the needed keys were given - if(!door.itemkeys) - { + if (!door.itemkeys) { #ifdef SVQC play2(player, SND(TALK)); Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_UNLOCKED); @@ -185,11 +181,9 @@ bool door_check_keys(entity door, entity player) return true; } - if(!valid) - { + if (!valid) { #ifdef SVQC - if(player.key_door_messagetime <= time) - { + if (player.key_door_messagetime <= time) { play2(player, door.noise3); Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(door.itemkeys)); player.key_door_messagetime = time + 2; @@ -200,8 +194,7 @@ bool door_check_keys(entity door, entity player) // door needs keys the player doesn't have #ifdef SVQC - if(player.key_door_messagetime <= time) - { + if (player.key_door_messagetime <= time) { play2(player, door.noise3); Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(door.itemkeys)); player.key_door_messagetime = time + 2; @@ -213,13 +206,12 @@ bool door_check_keys(entity door, entity player) void door_fire(entity this, entity actor, entity trigger) { - if (this.owner != this) - objerror (this, "door_fire: this.owner != this"); + if (this.owner != this) { + objerror(this, "door_fire: this.owner != this"); + } - if (this.spawnflags & DOOR_TOGGLE) - { - if (this.state == STATE_UP || this.state == STATE_TOP) - { + if (this.spawnflags & DOOR_TOGGLE) { + if (this.state == STATE_UP || this.state == STATE_TOP) { entity e = this; do { if (e.classname == "door") { @@ -240,14 +232,13 @@ void door_fire(entity this, entity actor, entity trigger) door_go_up(e); } else { // if the BIDIR spawnflag (==2) is set and the trigger has set trigger_reverse, reverse the opening direction - if ((e.spawnflags & 2) && trigger.trigger_reverse!=0 && e.lip != 666 && e.state == STATE_BOTTOM) { + if ((e.spawnflags & 2) && trigger.trigger_reverse != 0 && e.lip != 666 && e.state == STATE_BOTTOM) { e.lip = 666; // e.lip is used to remember reverse opening direction for door_rotating e.pos2 = '0 0 0' - e.pos2; } // if BIDIR_IN_DOWN (==8) is set, prevent the door from reoping during closing if it is triggered from the wrong side if (!((e.spawnflags & 2) && (e.spawnflags & 8) && e.state == STATE_DOWN - && (((e.lip == 666) && (trigger.trigger_reverse == 0)) || ((e.lip != 666) && (trigger.trigger_reverse != 0))))) - { + && (((e.lip == 666) && (trigger.trigger_reverse == 0)) || ((e.lip != 666) && (trigger.trigger_reverse != 0))))) { door_rotating_go_up(e, trigger); } } @@ -257,29 +248,30 @@ void door_fire(entity this, entity actor, entity trigger) void door_use(entity this, entity actor, entity trigger) { - //dprint("door_use (model: ");dprint(this.model);dprint(")\n"); + // dprint("door_use (model: ");dprint(this.model);dprint(")\n"); - if (this.owner) + if (this.owner) { door_fire(this.owner, actor, trigger); + } } void door_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) { - if(this.spawnflags & DOOR_NOSPLASH) - if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH)) + if (this.spawnflags & DOOR_NOSPLASH) { + if (!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH)) { return; + } + } this.health = this.health - damage; - if (this.itemkeys) - { + if (this.itemkeys) { // don't allow opening doors through damage if keys are required return; } - if (this.health <= 0) - { + if (this.health <= 0) { this.owner.health = this.owner.max_health; - this.owner.takedamage = DAMAGE_NO; // wil be reset upon return + this.owner.takedamage = DAMAGE_NO; // wil be reset upon return door_use(this.owner, NULL, NULL); } } @@ -296,18 +288,20 @@ Prints messages void door_touch(entity this, entity toucher) { - if (!IS_PLAYER(toucher)) + if (!IS_PLAYER(toucher)) { return; - if (this.owner.door_finished > time) + } + if (this.owner.door_finished > time) { return; + } this.owner.door_finished = time + 2; #ifdef SVQC - if (!(this.owner.dmg) && (this.owner.message != "")) - { - if (IS_CLIENT(toucher)) + if (!(this.owner.dmg) && (this.owner.message != "")) { + if (IS_CLIENT(toucher)) { centerprint(toucher, this.owner.message); + } play2(toucher, this.owner.noise); } #endif @@ -315,36 +309,33 @@ void door_touch(entity this, entity toucher) void door_generic_plat_blocked(entity this, entity blocker) { - if((this.spawnflags & 8) && (blocker.takedamage != DAMAGE_NO)) { // Kill Kill Kill!! + if ((this.spawnflags & 8) && (blocker.takedamage != DAMAGE_NO)) { // Kill Kill Kill!! #ifdef SVQC - Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + Damage(blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); #endif - } - else - { - + } else { #ifdef SVQC - if((this.dmg) && (blocker.takedamage == DAMAGE_YES)) // Shall we bite? - Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + if ((this.dmg) && (blocker.takedamage == DAMAGE_YES)) { // Shall we bite? + Damage(blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + } #endif - //Dont chamge direction for dead or dying stuff - if(IS_DEAD(blocker) && (blocker.takedamage == DAMAGE_NO)) - { - if (this.wait >= 0) - { - if (this.state == STATE_DOWN) - door_rotating_go_up (this, blocker); - else - door_rotating_go_down (this); + // Dont chamge direction for dead or dying stuff + if (IS_DEAD(blocker) && (blocker.takedamage == DAMAGE_NO)) { + if (this.wait >= 0) { + if (this.state == STATE_DOWN) { + door_rotating_go_up(this, blocker); + } else { + door_rotating_go_down(this); + } } } #ifdef SVQC - else - { - //gib dying stuff just to make sure - if((this.dmg) && (blocker.takedamage != DAMAGE_NO)) // Shall we bite? - Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + else { + // gib dying stuff just to make sure + if ((this.dmg) && (blocker.takedamage != DAMAGE_NO)) { // Shall we bite? + Damage(blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + } } #endif } @@ -352,21 +343,23 @@ void door_generic_plat_blocked(entity this, entity blocker) void door_rotating_hit_top(entity this) { - if (this.noise1 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + if (this.noise1 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + } this.state = STATE_TOP; - if (this.spawnflags & DOOR_TOGGLE) - return; // don't come down automatically + if (this.spawnflags & DOOR_TOGGLE) { + return; // don't come down automatically + } setthink(this, door_rotating_go_down); this.nextthink = this.ltime + this.wait; } void door_rotating_hit_bottom(entity this) { - if (this.noise1 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); - if (this.lip==666) // this.lip is used to remember reverse opening direction for door_rotating - { + if (this.noise1 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + } + if (this.lip == 666) { // this.lip is used to remember reverse opening direction for door_rotating this.pos2 = '0 0 0' - this.pos2; this.lip = 0; } @@ -375,32 +368,32 @@ void door_rotating_hit_bottom(entity this) void door_rotating_go_down(entity this) { - if (this.noise2 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); - if (this.max_health) - { + if (this.noise2 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } + if (this.max_health) { this.takedamage = DAMAGE_YES; this.health = this.max_health; } this.state = STATE_DOWN; - SUB_CalcAngleMove (this, this.pos1, TSPEED_LINEAR, this.speed, door_rotating_hit_bottom); + SUB_CalcAngleMove(this, this.pos1, TSPEED_LINEAR, this.speed, door_rotating_hit_bottom); } void door_rotating_go_up(entity this, entity oth) { - if (this.state == STATE_UP) - return; // already going up - - if (this.state == STATE_TOP) - { // reset top wait time + if (this.state == STATE_UP) { + return; // already going up + } + if (this.state == STATE_TOP) { // reset top wait time this.nextthink = this.ltime + this.wait; return; } - if (this.noise2 != "") - _sound (this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + if (this.noise2 != "") { + _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } this.state = STATE_UP; - SUB_CalcAngleMove (this, this.pos2, TSPEED_LINEAR, this.speed, door_rotating_hit_top); + SUB_CalcAngleMove(this, this.pos2, TSPEED_LINEAR, this.speed, door_rotating_hit_top); string oldmessage; oldmessage = this.message; @@ -420,22 +413,22 @@ Spawned if a door lacks a real activator void door_trigger_touch(entity this, entity toucher) { - if (toucher.health < 1){ + if (toucher.health < 1) { #ifdef SVQC - if (!((toucher.iscreature || (toucher.flags & FL_PROJECTILE)) && !IS_DEAD(toucher))){ + if (!((toucher.iscreature || (toucher.flags & FL_PROJECTILE)) && !IS_DEAD(toucher))) { #elif defined(CSQC) - if(!((IS_CLIENT(toucher) || toucher.classname == "csqcprojectile") && !IS_DEAD(toucher))){ + if (!((IS_CLIENT(toucher) || toucher.classname == "csqcprojectile") && !IS_DEAD(toucher))) { #endif return; } } - if (time < this.door_finished){ + if (time < this.door_finished) { return; } // check if door is locked - if (!door_check_keys(this, toucher)){ + if (!door_check_keys(this, toucher)) { return; } @@ -446,8 +439,8 @@ void door_trigger_touch(entity this, entity toucher) void door_spawnfield(entity this, vector fmins, vector fmaxs) { - entity trigger; - vector t1 = fmins, t2 = fmaxs; + entity trigger; + vector t1 = fmins, t2 = fmaxs; trigger = new(doortriggerfield); set_movetype(trigger, MOVETYPE_NONE); @@ -457,7 +450,7 @@ void door_spawnfield(entity this, vector fmins, vector fmaxs) settouch(trigger, door_trigger_touch); #endif - setsize (trigger, t1 - '60 60 8', t2 + '60 60 8'); + setsize(trigger, t1 - '60 60 8', t2 + '60 60 8'); } @@ -471,21 +464,19 @@ LinkDoors entity LinkDoors_nextent(entity cur, entity near, entity pass) { - while((cur = find(cur, classname, pass.classname)) && ((cur.spawnflags & 4) || cur.enemy)) - { - } + while ((cur = find(cur, classname, pass.classname)) && ((cur.spawnflags & 4) || cur.enemy)) {} return cur; } bool LinkDoors_isconnected(entity e1, entity e2, entity pass) { float DELTA = 4; - if((e1.absmin_x > e2.absmax_x + DELTA) - || (e1.absmin_y > e2.absmax_y + DELTA) - || (e1.absmin_z > e2.absmax_z + DELTA) - || (e2.absmin_x > e1.absmax_x + DELTA) - || (e2.absmin_y > e1.absmax_y + DELTA) - || (e2.absmin_z > e1.absmax_z + DELTA) + if ((e1.absmin_x > e2.absmax_x + DELTA) + || (e1.absmin_y > e2.absmax_y + DELTA) + || (e1.absmin_z > e2.absmax_z + DELTA) + || (e2.absmin_x > e1.absmax_x + DELTA) + || (e2.absmin_y > e1.absmax_y + DELTA) + || (e2.absmin_z > e1.absmax_z + DELTA) ) { return false; } return true; } @@ -495,42 +486,42 @@ void door_link(); #endif void LinkDoors(entity this) { - entity t; - vector cmins, cmaxs; + entity t; + vector cmins, cmaxs; #ifdef SVQC door_link(); #endif - if (this.enemy){ - return; // already linked by another door + if (this.enemy) { + return; // already linked by another door } - if (this.spawnflags & 4) - { + if (this.spawnflags & 4) { this.owner = this.enemy = this; - if (this.health) + if (this.health) { return; - if(THIS_TARGETED) + } + if (THIS_TARGETED) { return; - if (this.items) + } + if (this.items) { return; + } door_spawnfield(this, this.absmin, this.absmax); - return; // don't want to link this door + return; // don't want to link this door } FindConnectedComponent(this, enemy, LinkDoors_nextent, LinkDoors_isconnected, this); // set owner, and make a loop of the chain LOG_TRACE("LinkDoors: linking doors:"); - for(t = this; ; t = t.enemy) - { + for (t = this; ; t = t.enemy) { LOG_TRACE(" ", etos(t)); t.owner = this; - if(t.enemy == NULL) - { + if (t.enemy == NULL) { t.enemy = this; break; } @@ -540,48 +531,47 @@ void LinkDoors(entity this) // collect health, targetname, message, size cmins = this.absmin; cmaxs = this.absmax; - for(t = this; ; t = t.enemy) - { - if(t.health && !this.health){ + for (t = this; ; t = t.enemy) { + if (t.health && !this.health) { this.health = t.health; } - if((t.targetname != "") && (this.targetname == "")){ + if ((t.targetname != "") && (this.targetname == "")) { this.targetname = t.targetname; } - if((t.message != "") && (this.message == "")){ + if ((t.message != "") && (this.message == "")) { this.message = t.message; } - if (t.absmin_x < cmins_x){ + if (t.absmin_x < cmins_x) { cmins_x = t.absmin_x; } - if (t.absmin_y < cmins_y){ + if (t.absmin_y < cmins_y) { cmins_y = t.absmin_y; } - if (t.absmin_z < cmins_z){ + if (t.absmin_z < cmins_z) { cmins_z = t.absmin_z; } - if (t.absmax_x > cmaxs_x){ + if (t.absmax_x > cmaxs_x) { cmaxs_x = t.absmax_x; } - if (t.absmax_y > cmaxs_y){ + if (t.absmax_y > cmaxs_y) { cmaxs_y = t.absmax_y; } - if (t.absmax_z > cmaxs_z){ + if (t.absmax_z > cmaxs_z) { cmaxs_z = t.absmax_z; } - if(t.enemy == this){ + if (t.enemy == this) { break; } } // distribute health, targetname, message - for(t = this; t; t = t.enemy) - { + for (t = this; t; t = t.enemy) { t.health = this.health; t.targetname = this.targetname; t.message = this.message; - if(t.enemy == this) + if (t.enemy == this) { break; + } } // shootable, or triggered doors just needed the owner/enemy links, @@ -590,7 +580,7 @@ void LinkDoors(entity this) if (this.health) { return; } - if(THIS_TARGETED) { + if (THIS_TARGETED) { return; } if (this.items) { @@ -637,8 +627,7 @@ float door_send(entity this, entity to, float sf) WriteHeader(MSG_ENTITY, ENT_CLIENT_DOOR); WriteByte(MSG_ENTITY, sf); - if(sf & SF_TRIGGER_INIT) - { + if (sf & SF_TRIGGER_INIT) { WriteString(MSG_ENTITY, this.classname); WriteByte(MSG_ENTITY, this.spawnflags); @@ -664,13 +653,11 @@ float door_send(entity this, entity to, float sf) WriteCoord(MSG_ENTITY, this.ltime); } - if(sf & SF_TRIGGER_RESET) - { + if (sf & SF_TRIGGER_RESET) { // client makes use of this, we do not } - if(sf & SF_TRIGGER_UPDATE) - { + if (sf & SF_TRIGGER_UPDATE) { WriteCoord(MSG_ENTITY, this.origin_x); WriteCoord(MSG_ENTITY, this.origin_y); WriteCoord(MSG_ENTITY, this.origin_z); @@ -689,8 +676,8 @@ float door_send(entity this, entity to, float sf) void door_link() { // set size now, as everything is loaded - //FixSize(this); - //Net_LinkEntity(this, false, 0, door_send); + // FixSize(this); + // Net_LinkEntity(this, false, 0, door_send); } #endif @@ -740,10 +727,10 @@ spawnfunc(func_door) this.effects |= EF_LOWPRECISION; this.classname = "door"; - if(this.noise == "") { + if (this.noise == "") { this.noise = "misc/talk.wav"; } - if(this.noise3 == "") { + if (this.noise3 == "") { this.noise3 = "misc/talk.wav"; } precache_sound(this.noise); @@ -752,10 +739,10 @@ spawnfunc(func_door) setblocked(this, door_blocked); this.use = door_use; - if(this.dmg && (this.message == "")) { + if (this.dmg && (this.message == "")) { this.message = "was squished"; } - if(this.dmg && (this.message2 == "")) { + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; } @@ -764,8 +751,8 @@ spawnfunc(func_door) this.noise1 = "plats/medplat2.wav"; } - if(this.noise1 && this.noise1 != "") { precache_sound(this.noise1); } - if(this.noise2 && this.noise2 != "") { precache_sound(this.noise2); } + if (this.noise1 && this.noise1 != "") { precache_sound(this.noise1); } + if (this.noise2 && this.noise2 != "") { precache_sound(this.noise2); } if (!this.speed) { this.speed = 100; @@ -778,9 +765,9 @@ spawnfunc(func_door) } this.pos1 = this.origin; - this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip); + this.pos2 = this.pos1 + this.movedir * (fabs(this.movedir * this.size) - this.lip); - if(this.spawnflags & DOOR_NONSOLID) { + if (this.spawnflags & DOOR_NONSOLID) { this.solid = SOLID_NOT; } @@ -816,8 +803,7 @@ NET_HANDLE(ENT_CLIENT_DOOR, bool isnew) { int sf = ReadByte(); - if(sf & SF_TRIGGER_INIT) - { + if (sf & SF_TRIGGER_INIT) { this.classname = strzone(ReadString()); this.spawnflags = ReadByte(); @@ -855,20 +841,19 @@ NET_HANDLE(ENT_CLIENT_DOOR, bool isnew) LinkDoors(this); - if(this.spawnflags & DOOR_START_OPEN) + if (this.spawnflags & DOOR_START_OPEN) { door_init_startopen(this); + } this.move_time = time; set_movetype(this, MOVETYPE_PUSH); } - if(sf & SF_TRIGGER_RESET) - { + if (sf & SF_TRIGGER_RESET) { door_reset(this); } - if(sf & SF_TRIGGER_UPDATE) - { + if (sf & SF_TRIGGER_UPDATE) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); diff --git a/qcsrc/common/triggers/func/door_rotating.qc b/qcsrc/common/triggers/func/door_rotating.qc index 2c72dc9cf..97aa4ec44 100644 --- a/qcsrc/common/triggers/func/door_rotating.qc +++ b/qcsrc/common/triggers/func/door_rotating.qc @@ -47,54 +47,59 @@ void door_rotating_init_startopen(entity this) spawnfunc(func_door_rotating) { - - //if (!this.deathtype) // map makers can override this + // if (!this.deathtype) // map makers can override this // this.deathtype = " got in the way"; // I abuse "movedir" for denoting the axis for now - if (this.spawnflags & 64) // X (untested) + if (this.spawnflags & 64) { // X (untested) this.movedir = '0 0 1'; - else if (this.spawnflags & 128) // Y (untested) + } else if (this.spawnflags & 128) { // Y (untested) this.movedir = '1 0 0'; - else // Z + } else { // Z this.movedir = '0 1 0'; + } - if (this.angles_y==0) this.angles_y = 90; + if (this.angles_y == 0) { this.angles_y = 90; } this.movedir = this.movedir * this.angles_y; this.angles = '0 0 0'; this.max_health = this.health; this.avelocity = this.movedir; - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } this.velocity = '0 0 0'; - //this.effects |= EF_LOWPRECISION; + // this.effects |= EF_LOWPRECISION; this.classname = "door_rotating"; setblocked(this, door_blocked); this.use = door_use; - if(this.spawnflags & 8) - this.dmg = 10000; + if (this.spawnflags & 8) { + this.dmg = 10000; + } - if(this.dmg && (this.message == "")) + if (this.dmg && (this.message == "")) { this.message = "was squished"; - if(this.dmg && (this.message2 == "")) + } + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; + } - if (this.sounds > 0) - { - precache_sound ("plats/medplat1.wav"); - precache_sound ("plats/medplat2.wav"); + if (this.sounds > 0) { + precache_sound("plats/medplat1.wav"); + precache_sound("plats/medplat2.wav"); this.noise2 = "plats/medplat1.wav"; this.noise1 = "plats/medplat2.wav"; } - if (!this.speed) + if (!this.speed) { this.speed = 50; - if (!this.wait) + } + if (!this.wait) { this.wait = 1; + } this.lip = 0; // this.lip is used to remember reverse opening direction for door_rotating this.pos1 = '0 0 0'; @@ -102,19 +107,20 @@ spawnfunc(func_door_rotating) // DOOR_START_OPEN is to allow an entity to be lighted in the closed position // but spawn in the open position - if (this.spawnflags & DOOR_START_OPEN) + if (this.spawnflags & DOOR_START_OPEN) { InitializeEntity(this, door_rotating_init_startopen, INITPRIO_SETLOCATION); + } this.state = STATE_BOTTOM; - if (this.health) - { + if (this.health) { this.takedamage = DAMAGE_YES; this.event_damage = door_damage; } - if (this.items) + if (this.items) { this.wait = -1; + } settouch(this, door_touch); diff --git a/qcsrc/common/triggers/func/door_secret.qc b/qcsrc/common/triggers/func/door_secret.qc index 671f7048a..02a3f346d 100644 --- a/qcsrc/common/triggers/func/door_secret.qc +++ b/qcsrc/common/triggers/func/door_secret.qc @@ -8,11 +8,11 @@ void fd_secret_move5(entity this); void fd_secret_move6(entity this); void fd_secret_done(entity this); -const float SECRET_OPEN_ONCE = 1; // stays open -const float SECRET_1ST_LEFT = 2; // 1st move is left of arrow -const float SECRET_1ST_DOWN = 4; // 1st move is down from arrow -const float SECRET_NO_SHOOT = 8; // only opened by trigger -const float SECRET_YES_SHOOT = 16; // shootable even if targeted +const float SECRET_OPEN_ONCE = 1; // stays open +const float SECRET_1ST_LEFT = 2; // 1st move is left of arrow +const float SECRET_1ST_DOWN = 4; // 1st move is down from arrow +const float SECRET_NO_SHOOT = 8; // only opened by trigger +const float SECRET_YES_SHOOT = 16; // shootable even if targeted void fd_secret_use(entity this, entity actor, entity trigger) { @@ -20,50 +20,56 @@ void fd_secret_use(entity this, entity actor, entity trigger) string message_save; this.health = 10000; - if(!this.bot_attack) + if (!this.bot_attack) { IL_PUSH(g_bot_targets, this); + } this.bot_attack = true; // exit if still moving around... - if (this.origin != this.oldorigin) + if (this.origin != this.oldorigin) { return; + } message_save = this.message; - this.message = ""; // no more message - SUB_UseTargets(this, actor, trigger); // fire all targets / killtargets + this.message = ""; // no more message + SUB_UseTargets(this, actor, trigger); // fire all targets / killtargets this.message = message_save; this.velocity = '0 0 0'; // Make a sound, wait a little... - if (this.noise1 != "") + if (this.noise1 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + } this.nextthink = this.ltime + 0.1; - temp = 1 - (this.spawnflags & SECRET_1ST_LEFT); // 1 or -1 + temp = 1 - (this.spawnflags & SECRET_1ST_LEFT); // 1 or -1 makevectors(this.mangle); - if (!this.t_width) - { - if (this.spawnflags & SECRET_1ST_DOWN) + if (!this.t_width) { + if (this.spawnflags & SECRET_1ST_DOWN) { this.t_width = fabs(v_up * this.size); - else + } else { this.t_width = fabs(v_right * this.size); + } } - if (!this.t_length) + if (!this.t_length) { this.t_length = fabs(v_forward * this.size); + } - if (this.spawnflags & SECRET_1ST_DOWN) + if (this.spawnflags & SECRET_1ST_DOWN) { this.dest1 = this.origin - v_up * this.t_width; - else + } else { this.dest1 = this.origin + v_right * (this.t_width * temp); + } this.dest2 = this.dest1 + v_forward * this.t_length; SUB_CalcMove(this, this.dest1, TSPEED_LINEAR, this.speed, fd_secret_move1); - if (this.noise2 != "") + if (this.noise2 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } } void fd_secret_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) @@ -76,25 +82,27 @@ void fd_secret_move1(entity this) { this.nextthink = this.ltime + 1.0; setthink(this, fd_secret_move2); - if (this.noise3 != "") + if (this.noise3 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise3, VOL_BASE, ATTEN_NORM); + } } // Start moving sideways w/sound... void fd_secret_move2(entity this) { - if (this.noise2 != "") + if (this.noise2 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } SUB_CalcMove(this, this.dest2, TSPEED_LINEAR, this.speed, fd_secret_move3); } // Wait here until time to go back... void fd_secret_move3(entity this) { - if (this.noise3 != "") + if (this.noise3 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise3, VOL_BASE, ATTEN_NORM); - if (!(this.spawnflags & SECRET_OPEN_ONCE)) - { + } + if (!(this.spawnflags & SECRET_OPEN_ONCE)) { this.nextthink = this.ltime + this.wait; setthink(this, fd_secret_move4); } @@ -103,8 +111,9 @@ void fd_secret_move3(entity this) // Move backward... void fd_secret_move4(entity this) { - if (this.noise2 != "") + if (this.noise2 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } SUB_CalcMove(this, this.dest1, TSPEED_LINEAR, this.speed, fd_secret_move5); } @@ -113,37 +122,40 @@ void fd_secret_move5(entity this) { this.nextthink = this.ltime + 1.0; setthink(this, fd_secret_move6); - if (this.noise3 != "") + if (this.noise3 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise3, VOL_BASE, ATTEN_NORM); + } } void fd_secret_move6(entity this) { - if (this.noise2 != "") + if (this.noise2 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise2, VOL_BASE, ATTEN_NORM); + } SUB_CalcMove(this, this.oldorigin, TSPEED_LINEAR, this.speed, fd_secret_done); } void fd_secret_done(entity this) { - if (this.spawnflags&SECRET_YES_SHOOT) - { + if (this.spawnflags & SECRET_YES_SHOOT) { this.health = 10000; this.takedamage = DAMAGE_YES; - //this.th_pain = fd_secret_use; + // this.th_pain = fd_secret_use; } - if (this.noise3 != "") + if (this.noise3 != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise3, VOL_BASE, ATTEN_NORM); + } } .float door_finished; void secret_blocked(entity this, entity blocker) { - if (time < this.door_finished) + if (time < this.door_finished) { return; + } this.door_finished = time + 0.5; - //T_Damage (other, this, this, this.dmg, this.dmg, this.deathtype, DT_IMPACT, (this.absmin + this.absmax) * 0.5, '0 0 0', Obituary_Generic); + // T_Damage (other, this, this, this.dmg, this.dmg, this.deathtype, DT_IMPACT, (this.absmin + this.absmax) * 0.5, '0 0 0', Obituary_Generic); } /* @@ -155,25 +167,26 @@ Prints messages */ void secret_touch(entity this, entity toucher) { - if (!toucher.iscreature) + if (!toucher.iscreature) { return; - if (this.door_finished > time) + } + if (this.door_finished > time) { return; + } this.door_finished = time + 2; - if (this.message) - { - if (IS_CLIENT(toucher)) + if (this.message) { + if (IS_CLIENT(toucher)) { centerprint(toucher, this.message); + } play2(toucher, this.noise); } } void secret_reset(entity this) { - if (this.spawnflags & SECRET_YES_SHOOT) - { + if (this.spawnflags & SECRET_YES_SHOOT) { this.health = 10000; this.takedamage = DAMAGE_YES; } @@ -202,39 +215,37 @@ If a secret door has a targetname, it will only be opened by it's botton or trig spawnfunc(func_door_secret) { /*if (!this.deathtype) // map makers can override this - this.deathtype = " got in the way";*/ + this.deathtype = " got in the way";*/ - if (!this.dmg) this.dmg = 2; + if (!this.dmg) { this.dmg = 2; } // Magic formula... this.mangle = this.angles; this.angles = '0 0 0'; this.classname = "door"; - if (!InitMovingBrushTrigger(this)) return; + if (!InitMovingBrushTrigger(this)) { return; } this.effects |= EF_LOWPRECISION; - if (this.noise == "") this.noise = "misc/talk.wav"; + if (this.noise == "") { this.noise = "misc/talk.wav"; } precache_sound(this.noise); settouch(this, secret_touch); setblocked(this, secret_blocked); this.speed = 50; this.use = fd_secret_use; - if(THIS_TARGETED) - { - } - else + if (THIS_TARGETED) {} else { this.spawnflags |= SECRET_YES_SHOOT; + } - if (this.spawnflags & SECRET_YES_SHOOT) - { + if (this.spawnflags & SECRET_YES_SHOOT) { this.health = 10000; this.takedamage = DAMAGE_YES; this.event_damage = fd_secret_damage; } this.oldorigin = this.origin; - if (!this.wait) this.wait = 5; // seconds before closing - + if (!this.wait) { + this.wait = 5; // seconds before closing + } this.reset = secret_reset; this.reset(this); } diff --git a/qcsrc/common/triggers/func/fourier.qc b/qcsrc/common/triggers/func/fourier.qc index 28e0f0f7c..5f82f98c7 100644 --- a/qcsrc/common/triggers/func/fourier.qc +++ b/qcsrc/common/triggers/func/fourier.qc @@ -17,8 +17,7 @@ void func_fourier_controller_think(entity this) float n, i, t; this.nextthink = time + 0.1; - if(this.owner.active != ACTIVE_ACTIVE) - { + if (this.owner.active != ACTIVE_ACTIVE) { this.owner.velocity = '0 0 0'; return; } @@ -29,47 +28,53 @@ void func_fourier_controller_think(entity this) v = this.owner.destvec; - for(i = 0; i < n; ++i) - { - makevectors((t * stof(argv(i*5)) + stof(argv(i*5+1)) * 360) * '0 1 0'); - v = v + ('1 0 0' * stof(argv(i*5+2)) + '0 1 0' * stof(argv(i*5+3)) + '0 0 1' * stof(argv(i*5+4))) * this.owner.height * v_forward_y; + for (i = 0; i < n; ++i) { + makevectors((t * stof(argv(i * 5)) + stof(argv(i * 5 + 1)) * 360) * '0 1 0'); + v = v + ('1 0 0' * stof(argv(i * 5 + 2)) + '0 1 0' * stof(argv(i * 5 + 3)) + '0 0 1' * stof(argv(i * 5 + 4))) * this.owner.height * v_forward_y; } - if(this.owner.classname == "func_fourier") // don't brake stuff if the func_fourier was killtarget'ed + if (this.owner.classname == "func_fourier") { // don't brake stuff if the func_fourier was killtarget'ed // * 10 so it will arrive in 0.1 sec this.owner.velocity = (v - this.owner.origin) * 10; + } } spawnfunc(func_fourier) { entity controller; - if (this.noise != "") - { + if (this.noise != "") { precache_sound(this.noise); soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE); } - if (!this.speed) + if (!this.speed) { this.speed = 4; - if (!this.height) + } + if (!this.height) { this.height = 32; + } this.destvec = this.origin; this.cnt = 360 / this.speed; setblocked(this, generic_plat_blocked); - if(this.dmg && (this.message == "")) + if (this.dmg && (this.message == "")) { this.message = " was squished"; - if(this.dmg && (this.message2 == "")) + } + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; - if(this.dmg && (!this.dmgtime)) + } + if (this.dmg && (!this.dmgtime)) { this.dmgtime = 0.25; + } this.dmgtime2 = time; - if(this.netname == "") + if (this.netname == "") { this.netname = "1 0 0 0 1"; + } - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } this.active = ACTIVE_ACTIVE; diff --git a/qcsrc/common/triggers/func/pendulum.qc b/qcsrc/common/triggers/func/pendulum.qc index a59f7a93b..8b8d13e6e 100644 --- a/qcsrc/common/triggers/func/pendulum.qc +++ b/qcsrc/common/triggers/func/pendulum.qc @@ -6,8 +6,7 @@ void func_pendulum_controller_think(entity this) float v; this.nextthink = time + 0.1; - if (!(this.owner.active == ACTIVE_ACTIVE)) - { + if (!(this.owner.active == ACTIVE_ACTIVE)) { this.owner.avelocity_x = 0; return; } @@ -15,8 +14,7 @@ void func_pendulum_controller_think(entity this) // calculate sinewave using makevectors makevectors((this.nextthink * this.owner.freq + this.owner.phase) * '0 360 0'); v = this.owner.speed * v_forward_y + this.cnt; - if(this.owner.classname == "func_pendulum") // don't brake stuff if the func_bobbing was killtarget'ed - { + if (this.owner.classname == "func_pendulum") { // don't brake stuff if the func_bobbing was killtarget'ed // * 10 so it will arrive in 0.1 sec this.owner.avelocity_z = (remainder(v - this.owner.angles_z, 360)) * 10; } @@ -25,8 +23,7 @@ void func_pendulum_controller_think(entity this) spawnfunc(func_pendulum) { entity controller; - if (this.noise != "") - { + if (this.noise != "") { precache_sound(this.noise); soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE); } @@ -35,26 +32,30 @@ spawnfunc(func_pendulum) // keys: angle, speed, phase, noise, freq - if(!this.speed) + if (!this.speed) { this.speed = 30; + } // not initializing this.dmg to 2, to allow damageless pendulum - if(this.dmg && (this.message == "")) + if (this.dmg && (this.message == "")) { this.message = " was squished"; - if(this.dmg && (this.message2 == "")) + } + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; - if(this.dmg && (!this.dmgtime)) + } + if (this.dmg && (!this.dmgtime)) { this.dmgtime = 0.25; + } this.dmgtime2 = time; setblocked(this, generic_plat_blocked); this.avelocity_z = 0.0000001; - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } - if(!this.freq) - { + if (!this.freq) { // find pendulum length (same formula as Q3A) this.freq = 1 / (M_PI * 2) * sqrt(autocvar_sv_gravity / (3 * max(8, fabs(this.mins_z)))); } @@ -70,7 +71,7 @@ spawnfunc(func_pendulum) this.nextthink = this.ltime + 999999999; setthink(this, SUB_NullThink); // for PushMove - //this.effects |= EF_LOWPRECISION; + // this.effects |= EF_LOWPRECISION; // TODO make a reset function for this one } diff --git a/qcsrc/common/triggers/func/plat.qc b/qcsrc/common/triggers/func/plat.qc index 36b4eefff..550c64296 100644 --- a/qcsrc/common/triggers/func/plat.qc +++ b/qcsrc/common/triggers/func/plat.qc @@ -15,8 +15,7 @@ float plat_send(entity this, entity to, float sf) WriteHeader(MSG_ENTITY, ENT_CLIENT_PLAT); WriteByte(MSG_ENTITY, sf); - if(sf & SF_TRIGGER_INIT) - { + if (sf & SF_TRIGGER_INIT) { WriteByte(MSG_ENTITY, this.platmovetype_start); WriteByte(MSG_ENTITY, this.platmovetype_turn); WriteByte(MSG_ENTITY, this.platmovetype_end); @@ -49,8 +48,7 @@ float plat_send(entity this, entity to, float sf) WriteShort(MSG_ENTITY, this.dmg); } - if(sf & SF_TRIGGER_RESET) - { + if (sf & SF_TRIGGER_RESET) { // used on client } @@ -59,52 +57,53 @@ float plat_send(entity this, entity to, float sf) void plat_link(entity this) { - //Net_LinkEntity(this, 0, false, plat_send); + // Net_LinkEntity(this, 0, false, plat_send); } spawnfunc(func_plat) { - if (this.sounds == 0) this.sounds = 2; + if (this.sounds == 0) { this.sounds = 2; } - if (this.spawnflags & 4) this.dmg = 10000; + if (this.spawnflags & 4) { this.dmg = 10000; } - if (this.dmg && (this.message == "")) this.message = "was squished"; - if (this.dmg && (this.message2 == "")) this.message2 = "was squished by"; + if (this.dmg && (this.message == "")) { this.message = "was squished"; } + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; } - if (this.sounds == 1) - { + if (this.sounds == 1) { this.noise = "plats/plat1.wav"; this.noise1 = "plats/plat2.wav"; } - if (this.sounds == 2) - { + if (this.sounds == 2) { this.noise = "plats/medplat1.wav"; this.noise1 = "plats/medplat2.wav"; } - if (this.sound1) + if (this.sound1) { this.noise = this.sound1; - if (this.sound2) + } + if (this.sound2) { this.noise1 = this.sound2; + } - if(this.noise && this.noise != "") { precache_sound(this.noise); } - if(this.noise1 && this.noise1 != "") { precache_sound(this.noise1); } + if (this.noise && this.noise != "") { precache_sound(this.noise); } + if (this.noise1 && this.noise1 != "") { precache_sound(this.noise1); } this.mangle = this.angles; this.angles = '0 0 0'; this.classname = "plat"; - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } this.effects |= EF_LOWPRECISION; - setsize (this, this.mins , this.maxs); + setsize(this, this.mins, this.maxs); setblocked(this, plat_crush); - if (!this.speed) this.speed = 150; - if (!this.lip) this.lip = 16; - if (!this.height) this.height = this.size.z - this.lip; + if (!this.speed) { this.speed = 150; } + if (!this.lip) { this.lip = 16; } + if (!this.height) { this.height = this.size.z - this.lip; } this.pos1 = this.origin; this.pos2 = this.origin; @@ -119,15 +118,14 @@ spawnfunc(func_plat) void plat_draw(entity this) { Movetype_Physics_NoMatchServer(this); - //Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy); + // Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy); } NET_HANDLE(ENT_CLIENT_PLAT, bool isnew) { float sf = ReadByte(); - if(sf & SF_TRIGGER_INIT) - { + if (sf & SF_TRIGGER_INIT) { this.platmovetype_start = ReadByte(); this.platmovetype_turn = ReadByte(); this.platmovetype_end = ReadByte(); @@ -165,7 +163,7 @@ NET_HANDLE(ENT_CLIENT_PLAT, bool isnew) set_movetype(this, MOVETYPE_PUSH); this.drawmask = MASK_NORMAL; this.draw = plat_draw; - if (isnew) IL_PUSH(g_drawables, this); + if (isnew) { IL_PUSH(g_drawables, this); } this.use = plat_use; this.entremove = trigger_remove_generic; @@ -177,8 +175,7 @@ NET_HANDLE(ENT_CLIENT_PLAT, bool isnew) plat_spawn_inside_trigger(this); } - if(sf & SF_TRIGGER_RESET) - { + if (sf & SF_TRIGGER_RESET) { plat_reset(this); this.move_time = time; diff --git a/qcsrc/common/triggers/func/pointparticles.qc b/qcsrc/common/triggers/func/pointparticles.qc index 3676550d6..e4a59c1b1 100644 --- a/qcsrc/common/triggers/func/pointparticles.qc +++ b/qcsrc/common/triggers/func/pointparticles.qc @@ -10,36 +10,35 @@ bool pointparticles_SendEntity(entity this, entity to, float fl) // optional features to save space fl = fl & 0x0F; - if(this.spawnflags & 2) + if (this.spawnflags & 2) { fl |= 0x10; // absolute count on toggle-on - if(this.movedir != '0 0 0' || this.velocity != '0 0 0') + } + if (this.movedir != '0 0 0' || this.velocity != '0 0 0') { fl |= 0x20; // 4 bytes - saves CPU - if(this.waterlevel || this.count != 1) + } + if (this.waterlevel || this.count != 1) { fl |= 0x40; // 4 bytes - obscure features almost never used - if(this.mins != '0 0 0' || this.maxs != '0 0 0') + } + if (this.mins != '0 0 0' || this.maxs != '0 0 0') { fl |= 0x80; // 14 bytes - saves lots of space - + } WriteByte(MSG_ENTITY, fl); - if(fl & 2) - { - if(this.state) + if (fl & 2) { + if (this.state) { WriteCoord(MSG_ENTITY, this.impulse); - else + } else { WriteCoord(MSG_ENTITY, 0); // off + } } - if(fl & 4) - { + if (fl & 4) { WriteCoord(MSG_ENTITY, this.origin_x); WriteCoord(MSG_ENTITY, this.origin_y); WriteCoord(MSG_ENTITY, this.origin_z); } - if(fl & 1) - { - if(this.model != "null") - { + if (fl & 1) { + if (this.model != "null") { WriteShort(MSG_ENTITY, this.modelindex); - if(fl & 0x80) - { + if (fl & 0x80) { WriteCoord(MSG_ENTITY, this.mins_x); WriteCoord(MSG_ENTITY, this.mins_y); WriteCoord(MSG_ENTITY, this.mins_z); @@ -47,12 +46,9 @@ bool pointparticles_SendEntity(entity this, entity to, float fl) WriteCoord(MSG_ENTITY, this.maxs_y); WriteCoord(MSG_ENTITY, this.maxs_z); } - } - else - { + } else { WriteShort(MSG_ENTITY, 0); - if(fl & 0x80) - { + if (fl & 0x80) { WriteCoord(MSG_ENTITY, this.maxs_x); WriteCoord(MSG_ENTITY, this.maxs_y); WriteCoord(MSG_ENTITY, this.maxs_z); @@ -60,25 +56,21 @@ bool pointparticles_SendEntity(entity this, entity to, float fl) } WriteShort(MSG_ENTITY, this.cnt); WriteString(MSG_ENTITY, this.mdl); - if(fl & 0x20) - { + if (fl & 0x20) { WriteShort(MSG_ENTITY, compressShortVector(this.velocity)); WriteShort(MSG_ENTITY, compressShortVector(this.movedir)); } - if(fl & 0x40) - { + if (fl & 0x40) { WriteShort(MSG_ENTITY, this.waterlevel * 16.0); WriteByte(MSG_ENTITY, this.count * 16.0); } WriteString(MSG_ENTITY, this.noise); - if(this.noise != "") - { + if (this.noise != "") { WriteByte(MSG_ENTITY, floor(this.atten * 64)); WriteByte(MSG_ENTITY, floor(this.volume * 255)); } WriteString(MSG_ENTITY, this.bgmscript); - if(this.bgmscript != "") - { + if (this.bgmscript != "") { WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64)); WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64)); WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255)); @@ -96,8 +88,7 @@ void pointparticles_use(entity this, entity actor, entity trigger) void pointparticles_think(entity this) { - if(this.origin != this.oldorigin) - { + if (this.origin != this.oldorigin) { this.SendFlags |= 4; this.oldorigin = this.origin; } @@ -106,44 +97,46 @@ void pointparticles_think(entity this) void pointparticles_reset(entity this) { - if(this.spawnflags & 1) + if (this.spawnflags & 1) { this.state = 1; - else + } else { this.state = 0; + } } spawnfunc(func_pointparticles) { - if(this.model != "") { precache_model(this.model); _setmodel(this, this.model); } - if(this.noise != "") precache_sound(this.noise); - if(this.mdl != "") this.cnt = 0; // use a good handler - - if(!this.bgmscriptsustain) this.bgmscriptsustain = 1; - else if(this.bgmscriptsustain < 0) this.bgmscriptsustain = 0; + if (this.model != "") { precache_model(this.model); _setmodel(this, this.model); } + if (this.noise != "") { precache_sound(this.noise); } + if (this.mdl != "") { + this.cnt = 0; // use a good handler + } + if (!this.bgmscriptsustain) { this.bgmscriptsustain = 1; } else if (this.bgmscriptsustain < 0) { + this.bgmscriptsustain = 0; + } - if(!this.atten) this.atten = ATTEN_NORM; - else if(this.atten < 0) this.atten = 0; - if(!this.volume) this.volume = 1; - if(!this.count) this.count = 1; - if(!this.impulse) this.impulse = 1; + if (!this.atten) { this.atten = ATTEN_NORM; } else if (this.atten < 0) { + this.atten = 0; + } + if (!this.volume) { this.volume = 1; } + if (!this.count) { this.count = 1; } + if (!this.impulse) { this.impulse = 1; } - if(!this.modelindex) - { + if (!this.modelindex) { setorigin(this, this.origin + this.mins); setsize(this, '0 0 0', this.maxs - this.mins); } - //if(!this.cnt) this.cnt = _particleeffectnum(this.mdl); + // if(!this.cnt) this.cnt = _particleeffectnum(this.mdl); Net_LinkEntity(this, (this.spawnflags & 4), 0, pointparticles_SendEntity); - if(THIS_TARGETED) - { + if (THIS_TARGETED) { this.use = pointparticles_use; this.reset = pointparticles_reset; this.reset(this); - } - else + } else { this.state = 1; + } setthink(this, pointparticles_think); this.nextthink = time; } @@ -151,13 +144,13 @@ spawnfunc(func_pointparticles) spawnfunc(func_sparks) { // this.cnt is the amount of sparks that one burst will spawn - if(this.cnt < 1) { + if (this.cnt < 1) { this.cnt = 25.0; // nice default value } // this.wait is the probability that a sparkthink will spawn a spark shower // range: 0 - 1, but 0 makes little sense, so... - if(this.wait < 0.05) { + if (this.wait < 0.05) { this.wait = 0.25; // nice default value } @@ -168,7 +161,7 @@ spawnfunc(func_sparks) this.mdl = "TE_SPARK"; this.impulse = 10 * this.wait; // by default 2.5/sec this.wait = 0; - this.cnt = 0; // use mdl + this.cnt = 0; // use mdl spawnfunc_func_pointparticles(this); } @@ -177,17 +170,17 @@ spawnfunc(func_sparks) .int dphitcontentsmask; entityclass(PointParticles); -class(PointParticles) .int cnt; // effect number -class(PointParticles) .vector velocity; // particle velocity -class(PointParticles) .float waterlevel; // direction jitter -class(PointParticles) .int count; // count multiplier -class(PointParticles) .int impulse; // density -class(PointParticles) .string noise; // sound -class(PointParticles) .float atten; -class(PointParticles) .float volume; -class(PointParticles) .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle -class(PointParticles) .vector movedir; // trace direction -class(PointParticles) .float glow_color; // palette index +class(PointParticles).int cnt; // effect number +class(PointParticles).vector velocity; // particle velocity +class(PointParticles).float waterlevel; // direction jitter +class(PointParticles).int count; // count multiplier +class(PointParticles).int impulse; // density +class(PointParticles).string noise; // sound +class(PointParticles).float atten; +class(PointParticles).float volume; +class(PointParticles).float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle +class(PointParticles).vector movedir; // trace direction +class(PointParticles).float glow_color; // palette index void Draw_PointParticles(entity this) { @@ -198,60 +191,55 @@ void Draw_PointParticles(entity this) o = this.origin; sz = this.maxs - this.mins; n = doBGMScript(this); - if(this.absolute == 2) - { - if(n >= 0) + if (this.absolute == 2) { + if (n >= 0) { n = this.just_toggled ? this.impulse : 0; - else + } else { n = this.impulse * drawframetime; - } - else - { + } + } else { n *= this.impulse * drawframetime; - if(this.just_toggled) - if(n < 1) + if (this.just_toggled) { + if (n < 1) { n = 1; + } + } } - if(n == 0) + if (n == 0) { return; + } fail = 0; - for(i = random(); i <= n && fail <= 64*n; ++i) - { + for (i = random(); i <= n && fail <= 64 * n; ++i) { p = o + this.mins; p.x += random() * sz.x; p.y += random() * sz.y; p.z += random() * sz.z; - if(WarpZoneLib_BoxTouchesBrush(p, p, this, NULL)) - { - if(this.movedir != '0 0 0') - { + if (WarpZoneLib_BoxTouchesBrush(p, p, this, NULL)) { + if (this.movedir != '0 0 0') { traceline(p, p + normalize(this.movedir) * 4096, 0, NULL); p = trace_endpos; int eff_num; - if(this.cnt) + if (this.cnt) { eff_num = this.cnt; - else + } else { eff_num = _particleeffectnum(this.mdl); + } __pointparticles(eff_num, p, trace_plane_normal * vlen(this.movedir) + this.velocity + randomvec() * this.waterlevel, this.count); - } - else - { + } else { int eff_num; - if(this.cnt) + if (this.cnt) { eff_num = this.cnt; - else + } else { eff_num = _particleeffectnum(this.mdl); + } __pointparticles(eff_num, p, this.velocity + randomvec() * this.waterlevel, this.count); } - if(this.noise != "") - { + if (this.noise != "") { setorigin(this, p); _sound(this, CH_AMBIENT, this.noise, VOL_BASE * this.volume, this.atten); } this.just_toggled = 0; - } - else if(this.absolute) - { + } else if (this.absolute) { ++fail; --i; } @@ -261,14 +249,17 @@ void Draw_PointParticles(entity this) void Ent_PointParticles_Remove(entity this) { - if(this.noise) + if (this.noise) { strunzone(this.noise); + } this.noise = string_null; - if(this.bgmscript) + if (this.bgmscript) { strunzone(this.bgmscript); + } this.bgmscript = string_null; - if(this.mdl) + if (this.mdl) { strunzone(this.mdl); + } this.mdl = string_null; } @@ -277,81 +268,67 @@ NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew) float i; vector v; int f = ReadByte(); - if(f & 2) - { + if (f & 2) { i = ReadCoord(); // density (<0: point, >0: volume) - if(i && !this.impulse && (this.cnt || this.mdl)) // this.cnt check is so it only happens if the ent already existed + if (i && !this.impulse && (this.cnt || this.mdl)) { // this.cnt check is so it only happens if the ent already existed this.just_toggled = 1; + } this.impulse = i; } - if(f & 4) - { + if (f & 4) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); } - if(f & 1) - { + if (f & 1) { this.modelindex = ReadShort(); - if(f & 0x80) - { - if(this.modelindex) - { + if (f & 0x80) { + if (this.modelindex) { this.mins_x = ReadCoord(); this.mins_y = ReadCoord(); this.mins_z = ReadCoord(); this.maxs_x = ReadCoord(); this.maxs_y = ReadCoord(); this.maxs_z = ReadCoord(); - } - else - { + } else { this.mins = '0 0 0'; this.maxs_x = ReadCoord(); this.maxs_y = ReadCoord(); this.maxs_z = ReadCoord(); } - } - else - { + } else { this.mins = this.maxs = '0 0 0'; } - this.cnt = ReadShort(); // effect number + this.cnt = ReadShort(); // effect number this.mdl = strzone(ReadString()); // effect string - if(f & 0x20) - { + if (f & 0x20) { this.velocity = decompressShortVector(ReadShort()); this.movedir = decompressShortVector(ReadShort()); - } - else - { + } else { this.velocity = this.movedir = '0 0 0'; } - if(f & 0x40) - { + if (f & 0x40) { this.waterlevel = ReadShort() / 16.0; this.count = ReadByte() / 16.0; - } - else - { + } else { this.waterlevel = 0; this.count = 1; } - if(this.noise) + if (this.noise) { strunzone(this.noise); - if(this.bgmscript) + } + if (this.bgmscript) { strunzone(this.bgmscript); + } this.noise = strzone(ReadString()); - if(this.noise != "") - { + if (this.noise != "") { this.atten = ReadByte() / 64.0; this.volume = ReadByte() / 255.0; } this.bgmscript = strzone(ReadString()); - if(this.bgmscript != "") - { + if (this.bgmscript != "") { this.bgmscriptattack = ReadByte() / 64.0; this.bgmscriptdecay = ReadByte() / 64.0; this.bgmscriptsustain = ReadByte() / 255.0; @@ -362,24 +339,23 @@ NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew) return = true; - if(f & 2) - { + if (f & 2) { this.absolute = (this.impulse >= 0); - if(!this.absolute) - { + if (!this.absolute) { v = this.maxs - this.mins; this.impulse *= -v.x * v.y * v.z / 262144; // relative: particles per 64^3 cube } } - if(f & 0x10) + if (f & 0x10) { this.absolute = 2; + } setorigin(this, this.origin); setsize(this, this.mins, this.maxs); this.solid = SOLID_NOT; this.draw = Draw_PointParticles; - if (isnew) IL_PUSH(g_drawables, this); + if (isnew) { IL_PUSH(g_drawables, this); } this.entremove = Ent_PointParticles_Remove; } #endif diff --git a/qcsrc/common/triggers/func/rainsnow.qc b/qcsrc/common/triggers/func/rainsnow.qc index c8b4e2924..519d583d6 100644 --- a/qcsrc/common/triggers/func/rainsnow.qc +++ b/qcsrc/common/triggers/func/rainsnow.qc @@ -33,21 +33,26 @@ spawnfunc(func_rain) { this.dest = this.velocity; this.velocity = '0 0 0'; - if (!this.dest) + if (!this.dest) { this.dest = '0 0 -700'; + } this.angles = '0 0 0'; set_movetype(this, MOVETYPE_NONE); this.solid = SOLID_NOT; SetBrushEntityModel(this); - if (!this.cnt) + if (!this.cnt) { this.cnt = 12; - if (!this.count) + } + if (!this.count) { this.count = 2000; + } this.count = 0.01 * this.count * (this.size_x / 1024) * (this.size_y / 1024); - if (this.count < 1) + if (this.count < 1) { this.count = 1; - if(this.count > 65535) + } + if (this.count > 65535) { this.count = 65535; + } this.state = 1; // 1 is rain, 0 is snow this.Version = 1; @@ -71,21 +76,26 @@ spawnfunc(func_snow) { this.dest = this.velocity; this.velocity = '0 0 0'; - if (!this.dest) + if (!this.dest) { this.dest = '0 0 -300'; + } this.angles = '0 0 0'; set_movetype(this, MOVETYPE_NONE); this.solid = SOLID_NOT; SetBrushEntityModel(this); - if (!this.cnt) + if (!this.cnt) { this.cnt = 12; - if (!this.count) + } + if (!this.count) { this.count = 2000; + } this.count = 0.01 * this.count * (this.size_x / 1024) * (this.size_y / 1024); - if (this.count < 1) + if (this.count < 1) { this.count = 1; - if(this.count > 65535) + } + if (this.count > 65535) { this.count = 65535; + } this.state = 0; // 1 is rain, 0 is snow this.Version = 1; @@ -99,18 +109,20 @@ void Draw_Rain(entity this) { vector maxdist = '1 1 0' * autocvar_cl_rainsnow_maxdrawdist; maxdist.z = 5; - if(boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5')) - //if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist)) - te_particlerain(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color); + if (boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5')) { + // if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist)) + te_particlerain(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color); + } } void Draw_Snow(entity this) { vector maxdist = '1 1 0' * autocvar_cl_rainsnow_maxdrawdist; maxdist.z = 5; - if(boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5')) - //if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist)) - te_particlesnow(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color); + if (boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5')) { + // if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist)) + te_particlesnow(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color); + } } NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew) @@ -135,10 +147,11 @@ NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew) setorigin(this, this.origin); setsize(this, this.mins, this.maxs); this.solid = SOLID_NOT; - if (isnew) IL_PUSH(g_drawables, this); - if(this.impulse) + if (isnew) { IL_PUSH(g_drawables, this); } + if (this.impulse) { this.draw = Draw_Rain; - else + } else { this.draw = Draw_Snow; + } } #endif diff --git a/qcsrc/common/triggers/func/rotating.qc b/qcsrc/common/triggers/func/rotating.qc index 6268dcfeb..ec45f4ab9 100644 --- a/qcsrc/common/triggers/func/rotating.qc +++ b/qcsrc/common/triggers/func/rotating.qc @@ -4,33 +4,31 @@ const int FUNC_ROTATING_STARTOFF = BIT(4); void func_rotating_setactive(entity this, int astate) { - if (astate == ACTIVE_TOGGLE) - { - if(this.active == ACTIVE_ACTIVE) + if (astate == ACTIVE_TOGGLE) { + if (this.active == ACTIVE_ACTIVE) { this.active = ACTIVE_NOT; - else + } else { this.active = ACTIVE_ACTIVE; - } - else + } + } else { this.active = astate; + } - if(this.active == ACTIVE_NOT) + if (this.active == ACTIVE_NOT) { this.avelocity = '0 0 0'; - else + } else { this.avelocity = this.pos1; + } } void func_rotating_reset(entity this) { // TODO: reset angles as well? - if(this.spawnflags & FUNC_ROTATING_STARTOFF) - { + if (this.spawnflags & FUNC_ROTATING_STARTOFF) { this.avelocity = '0 0 0'; this.active = ACTIVE_NOT; - } - else - { + } else { this.avelocity = this.pos1; this.active = ACTIVE_ACTIVE; } @@ -46,53 +44,59 @@ dmgtime : See above. spawnfunc(func_rotating) { - if (this.noise != "") - { + if (this.noise != "") { precache_sound(this.noise); ambientsound(this.origin, this.noise, VOL_BASE, ATTEN_IDLE); } this.setactive = func_rotating_setactive; - if (!this.speed) + if (!this.speed) { this.speed = 100; + } // FIXME: test if this turns the right way, then remove this comment (negate as needed) - if (this.spawnflags & BIT(2)) // X (untested) + if (this.spawnflags & BIT(2)) { // X (untested) this.avelocity = '0 0 1' * this.speed; + } // FIXME: test if this turns the right way, then remove this comment (negate as needed) - else if (this.spawnflags & BIT(3)) // Y (untested) + else if (this.spawnflags & BIT(3)) { // Y (untested) this.avelocity = '1 0 0' * this.speed; + } // FIXME: test if this turns the right way, then remove this comment (negate as needed) - else // Z + else { // Z this.avelocity = '0 1 0' * this.speed; + } this.pos1 = this.avelocity; // do this after setting pos1, so we can safely reactivate the func_rotating - if(this.spawnflags & FUNC_ROTATING_STARTOFF) - { + if (this.spawnflags & FUNC_ROTATING_STARTOFF) { this.avelocity = '0 0 0'; this.active = ACTIVE_NOT; - } - else + } else { this.active = ACTIVE_ACTIVE; + } - if(this.dmg && (this.message == "")) - this.message = " was squished"; - if(this.dmg && (this.message2 == "")) + if (this.dmg && (this.message == "")) { + this.message = " was squished"; + } + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; + } - if(this.dmg && (!this.dmgtime)) - this.dmgtime = 0.25; + if (this.dmg && (!this.dmgtime)) { + this.dmgtime = 0.25; + } - this.dmgtime2 = time; + this.dmgtime2 = time; - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } // no EF_LOWPRECISION here, as rounding angles is bad - setblocked(this, generic_plat_blocked); + setblocked(this, generic_plat_blocked); // wait for targets to spawn this.nextthink = this.ltime + 999999999; diff --git a/qcsrc/common/triggers/func/train.qc b/qcsrc/common/triggers/func/train.qc index c5a6e3d03..1e26bc1a0 100644 --- a/qcsrc/common/triggers/func/train.qc +++ b/qcsrc/common/triggers/func/train.qc @@ -11,53 +11,51 @@ void train_wait(entity this) this.enemy = NULL; // if turning is enabled, the train will turn toward the next point while waiting - if(this.platmovetype_turn && !this.train_wait_turning) - { + if (this.platmovetype_turn && !this.train_wait_turning) { entity targ, cp; vector ang; targ = this.future_target; - if((this.spawnflags & 1) && targ.curvetarget) + if ((this.spawnflags & 1) && targ.curvetarget) { cp = find(NULL, targetname, targ.curvetarget); - else + } else { cp = NULL; + } - if(cp) // bezier curves movement - ang = cp.origin - (this.origin - this.view_ofs); // use the origin of the control point of the next path_corner - else // linear movement + if (cp) { // bezier curves movement + ang = cp.origin - (this.origin - this.view_ofs); // use the origin of the control point of the next path_corner + } else { // linear movement ang = targ.origin - (this.origin - this.view_ofs); // use the origin of the next path_corner + } ang = vectoangles(ang); - ang_x = -ang_x; // flip up / down orientation + ang_x = -ang_x; // flip up / down orientation - if(this.wait > 0) // slow turning + if (this.wait > 0) { // slow turning SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.ltime - time + this.wait, train_wait); - else // instant turning + } else { // instant turning SUB_CalcAngleMove(this, ang, TSPEED_TIME, 0.0000001, train_wait); + } this.train_wait_turning = true; return; } #ifdef SVQC - if(this.noise != "") + if (this.noise != "") { stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway + } #endif #ifdef SVQC entity tg = this.future_target; - if(tg.spawnflags & 4) - { + if (tg.spawnflags & 4) { this.use = train_use; setthink(this, func_null); this.nextthink = 0; - } - else + } else #endif - if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning - { + if (this.wait < 0 || this.train_wait_turning) { // no waiting or we already waited while turning this.train_wait_turning = false; train_next(this); - } - else - { + } else { setthink(this, train_next); this.nextthink = this.ltime + this.wait; } @@ -65,17 +63,13 @@ void train_wait(entity this) entity train_next_find(entity this) { - if(this.target_random) - { + if (this.target_random) { RandomSelection_Init(); - for(entity t = NULL; (t = find(t, targetname, this.target));) - { + for (entity t = NULL; (t = find(t, targetname, this.target)); ) { RandomSelection_AddEnt(t, 1, 0); } return RandomSelection_chosen_ent; - } - else - { + } else { return find(NULL, targetname, this.target); } } @@ -91,50 +85,47 @@ void train_next(entity this) this.target_random = targ.target_random; this.future_target = train_next_find(targ); - if (this.spawnflags & 1) - { - if(targ.curvetarget) - { + if (this.spawnflags & 1) { + if (targ.curvetarget) { cp = find(NULL, targetname, targ.curvetarget); // get its second target (the control point) - cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination + cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination } } - if (this.target == "") + if (this.target == "") { objerror(this, "train_next: no next target"); + } this.wait = targ.wait; - if (!this.wait) + if (!this.wait) { this.wait = 0.1; + } - if(targ.platmovetype) - { + if (targ.platmovetype) { // this path_corner contains a movetype overrider, apply it this.platmovetype_start = targ.platmovetype_start; this.platmovetype_end = targ.platmovetype_end; - } - else - { + } else { // this path_corner doesn't contain a movetype overrider, use the train's defaults this.platmovetype_start = this.platmovetype_start_default; this.platmovetype_end = this.platmovetype_end_default; } - if (targ.speed) - { - if (cp) + if (targ.speed) { + if (cp) { SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait); - else + } else { SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait); - } - else - { - if (cp) + } + } else { + if (cp) { SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait); - else + } else { SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait); + } } - if(this.noise != "") + if (this.noise != "") { _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE); + } } REGISTER_NET_LINKED(ENT_CLIENT_TRAIN) @@ -145,8 +136,7 @@ float train_send(entity this, entity to, float sf) WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN); WriteByte(MSG_ENTITY, sf); - if(sf & SF_TRIGGER_INIT) - { + if (sf & SF_TRIGGER_INIT) { WriteString(MSG_ENTITY, this.platmovetype); WriteByte(MSG_ENTITY, this.platmovetype_turn); WriteByte(MSG_ENTITY, this.spawnflags); @@ -186,8 +176,7 @@ float train_send(entity this, entity to, float sf) WriteByte(MSG_ENTITY, this.dmgtime); } - if(sf & SF_TRIGGER_RESET) - { + if (sf & SF_TRIGGER_RESET) { // used on client } @@ -196,7 +185,7 @@ float train_send(entity this, entity to, float sf) void train_link(entity this) { - //Net_LinkEntity(this, 0, false, train_send); + // Net_LinkEntity(this, 0, false, train_send); } void train_use(entity this, entity actor, entity trigger) @@ -204,8 +193,9 @@ void train_use(entity this, entity actor, entity trigger) this.nextthink = this.ltime + 1; setthink(this, train_next); this.use = func_null; // not again - if(trigger.target2 && trigger.target2 != "") + if (trigger.target2 && trigger.target2 != "") { this.future_target = find(NULL, targetname, trigger.target2); + } } void func_train_find(entity this) @@ -215,12 +205,12 @@ void func_train_find(entity this) this.target_random = targ.target_random; // save the future target for later this.future_target = train_next_find(targ); - if (this.target == "") + if (this.target == "") { objerror(this, "func_train_find: no next target"); + } setorigin(this, targ.origin - this.view_ofs); - if(!(this.spawnflags & 4)) - { + if (!(this.spawnflags & 4)) { this.nextthink = this.ltime + 1; setthink(this, train_next); } @@ -238,43 +228,51 @@ target : targetname of first spawnfunc_path_corner (starts here) #ifdef SVQC spawnfunc(func_train) { - if (this.noise != "") + if (this.noise != "") { precache_sound(this.noise); + } - if (this.target == "") + if (this.target == "") { objerror(this, "func_train without a target"); - if (!this.speed) + } + if (!this.speed) { this.speed = 100; + } - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } this.effects |= EF_LOWPRECISION; - if(this.spawnflags & 4) + if (this.spawnflags & 4) { this.use = train_use; + } - if (this.spawnflags & 2) - { + if (this.spawnflags & 2) { this.platmovetype_turn = true; this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now - } - else + } else { this.view_ofs = this.mins; + } // wait for targets to spawn InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET); setblocked(this, generic_plat_blocked); - if(this.dmg && (this.message == "")) + if (this.dmg && (this.message == "")) { this.message = " was squished"; - if(this.dmg && (this.message2 == "")) + } + if (this.dmg && (this.message2 == "")) { this.message2 = "was squished by"; - if(this.dmg && (!this.dmgtime)) + } + if (this.dmg && (!this.dmgtime)) { this.dmgtime = 0.25; + } this.dmgtime2 = time; - if(!set_platmovetype(this, this.platmovetype)) + if (!set_platmovetype(this, this.platmovetype)) { return; + } this.platmovetype_start_default = this.platmovetype_start; this.platmovetype_end_default = this.platmovetype_end; @@ -283,7 +281,7 @@ spawnfunc(func_train) #elif defined(CSQC) void train_draw(entity this) { - //Movetype_Physics_NoMatchServer(); + // Movetype_Physics_NoMatchServer(); Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy); } @@ -291,8 +289,7 @@ NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew) { float sf = ReadByte(); - if(sf & SF_TRIGGER_INIT) - { + if (sf & SF_TRIGGER_INIT) { this.platmovetype = strzone(ReadString()); this.platmovetype_turn = ReadByte(); this.spawnflags = ReadByte(); @@ -337,17 +334,16 @@ NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew) set_movetype(this, MOVETYPE_PUSH); this.drawmask = MASK_NORMAL; this.draw = train_draw; - if (isnew) IL_PUSH(g_drawables, this); + if (isnew) { IL_PUSH(g_drawables, this); } this.entremove = trigger_remove_generic; - if(set_platmovetype(this, this.platmovetype)) - { + if (set_platmovetype(this, this.platmovetype)) { this.platmovetype_start_default = this.platmovetype_start; this.platmovetype_end_default = this.platmovetype_end; } // everything is set up by the time the train is linked, we shouldn't need this - //func_train_find(); + // func_train_find(); // but we will need these train_next(this); @@ -356,8 +352,7 @@ NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew) this.move_time = time; } - if(sf & SF_TRIGGER_RESET) - { + if (sf & SF_TRIGGER_RESET) { // TODO: make a reset function for trains } diff --git a/qcsrc/common/triggers/func/vectormamamam.qc b/qcsrc/common/triggers/func/vectormamamam.qc index 951a740a2..78aecf15f 100644 --- a/qcsrc/common/triggers/func/vectormamamam.qc +++ b/qcsrc/common/triggers/func/vectormamamam.qc @@ -16,43 +16,43 @@ vector func_vectormamamam_origin(entity o, float t) v = '0 0 0'; e = o.wp00; - if(e) - { + if (e) { p = e.origin + t * e.velocity; - if(f & 1) + if (f & 1) { v = v + (p * o.targetnormal) * o.targetnormal * o.targetfactor; - else + } else { v = v + (p - (p * o.targetnormal) * o.targetnormal) * o.targetfactor; + } } e = o.wp01; - if(e) - { + if (e) { p = e.origin + t * e.velocity; - if(f & 2) + if (f & 2) { v = v + (p * o.target2normal) * o.target2normal * o.target2factor; - else + } else { v = v + (p - (p * o.target2normal) * o.target2normal) * o.target2factor; + } } e = o.wp02; - if(e) - { + if (e) { p = e.origin + t * e.velocity; - if(f & 4) + if (f & 4) { v = v + (p * o.target3normal) * o.target3normal * o.target3factor; - else + } else { v = v + (p - (p * o.target3normal) * o.target3normal) * o.target3factor; + } } e = o.wp03; - if(e) - { + if (e) { p = e.origin + t * e.velocity; - if(f & 8) + if (f & 8) { v = v + (p * o.target4normal) * o.target4normal * o.target4factor; - else + } else { v = v + (p - (p * o.target4normal) * o.target4normal) * o.target4factor; + } } return v; @@ -62,32 +62,37 @@ void func_vectormamamam_controller_think(entity this) { this.nextthink = time + 0.1; - if(this.owner.active != ACTIVE_ACTIVE) - { + if (this.owner.active != ACTIVE_ACTIVE) { this.owner.velocity = '0 0 0'; return; } - if(this.owner.classname == "func_vectormamamam") // don't brake stuff if the func_vectormamamam was killtarget'ed + if (this.owner.classname == "func_vectormamamam") { // don't brake stuff if the func_vectormamamam was killtarget'ed this.owner.velocity = (this.owner.destvec + func_vectormamamam_origin(this.owner, 0.1) - this.owner.origin) * 10; + } } void func_vectormamamam_findtarget(entity this) { - if(this.target != "") + if (this.target != "") { this.wp00 = find(NULL, targetname, this.target); + } - if(this.target2 != "") + if (this.target2 != "") { this.wp01 = find(NULL, targetname, this.target2); + } - if(this.target3 != "") + if (this.target3 != "") { this.wp02 = find(NULL, targetname, this.target3); + } - if(this.target4 != "") + if (this.target4 != "") { this.wp03 = find(NULL, targetname, this.target4); + } - if(!this.wp00 && !this.wp01 && !this.wp02 && !this.wp03) + if (!this.wp00 && !this.wp01 && !this.wp02 && !this.wp03) { objerror(this, "No reference entity found, so there is nothing to move. Aborting."); + } this.destvec = this.origin - func_vectormamamam_origin(this, 0); @@ -100,50 +105,62 @@ void func_vectormamamam_findtarget(entity this) spawnfunc(func_vectormamamam) { - if (this.noise != "") - { + if (this.noise != "") { precache_sound(this.noise); soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE); } - if(!this.targetfactor) + if (!this.targetfactor) { this.targetfactor = 1; + } - if(!this.target2factor) + if (!this.target2factor) { this.target2factor = 1; + } - if(!this.target3factor) + if (!this.target3factor) { this.target3factor = 1; + } - if(!this.target4factor) + if (!this.target4factor) { this.target4factor = 1; + } - if(this.targetnormal) + if (this.targetnormal) { this.targetnormal = normalize(this.targetnormal); + } - if(this.target2normal) + if (this.target2normal) { this.target2normal = normalize(this.target2normal); + } - if(this.target3normal) + if (this.target3normal) { this.target3normal = normalize(this.target3normal); + } - if(this.target4normal) + if (this.target4normal) { this.target4normal = normalize(this.target4normal); + } setblocked(this, generic_plat_blocked); - if(this.dmg && (this.message == "")) + if (this.dmg && (this.message == "")) { this.message = " was squished"; - if(this.dmg && (this.message == "")) + } + if (this.dmg && (this.message == "")) { this.message2 = "was squished by"; - if(this.dmg && (!this.dmgtime)) + } + if (this.dmg && (!this.dmgtime)) { this.dmgtime = 0.25; + } this.dmgtime2 = time; - if(this.netname == "") + if (this.netname == "") { this.netname = "1 0 0 0 1"; + } - if (!InitMovingBrushTrigger(this)) + if (!InitMovingBrushTrigger(this)) { return; + } // wait for targets to spawn this.nextthink = this.ltime + 999999999; diff --git a/qcsrc/common/triggers/include.qc b/qcsrc/common/triggers/include.qc index 59da1f217..4235c735c 100644 --- a/qcsrc/common/triggers/include.qc +++ b/qcsrc/common/triggers/include.qc @@ -17,4 +17,3 @@ // trigger #include "trigger/include.qc" - diff --git a/qcsrc/common/triggers/misc/corner.qc b/qcsrc/common/triggers/misc/corner.qc index dcc44710f..73d23c76c 100644 --- a/qcsrc/common/triggers/misc/corner.qc +++ b/qcsrc/common/triggers/misc/corner.qc @@ -26,7 +26,7 @@ bool corner_send(entity this, entity to, int sf) void corner_link(entity this) { - //Net_LinkEntity(this, false, 0, corner_send); + // Net_LinkEntity(this, false, 0, corner_send); } spawnfunc(path_corner) @@ -41,22 +41,22 @@ spawnfunc(path_corner) void corner_remove(entity this) { - if(this.target) { strunzone(this.target); } + if (this.target) { strunzone(this.target); } this.target = string_null; - if(this.target2) { strunzone(this.target2); } + if (this.target2) { strunzone(this.target2); } this.target2 = string_null; - if(this.target3) { strunzone(this.target3); } + if (this.target3) { strunzone(this.target3); } this.target3 = string_null; - if(this.target4) { strunzone(this.target4); } + if (this.target4) { strunzone(this.target4); } this.target4 = string_null; - if(this.targetname) { strunzone(this.targetname); } + if (this.targetname) { strunzone(this.targetname); } this.targetname = string_null; - if(this.platmovetype) { strunzone(this.platmovetype); } + if (this.platmovetype) { strunzone(this.platmovetype); } this.platmovetype = string_null; } diff --git a/qcsrc/common/triggers/misc/follow.qc b/qcsrc/common/triggers/misc/follow.qc index 63db2c18f..da7bd1c49 100644 --- a/qcsrc/common/triggers/misc/follow.qc +++ b/qcsrc/common/triggers/misc/follow.qc @@ -7,55 +7,43 @@ void follow_init(entity this) entity src, dst; src = NULL; dst = NULL; - if(this.killtarget != "") + if (this.killtarget != "") { src = find(NULL, targetname, this.killtarget); - if(this.target != "") + } + if (this.target != "") { dst = find(NULL, targetname, this.target); + } - if(!src && !dst) - { + if (!src && !dst) { objerror(this, "follow: could not find target/killtarget"); return; } - if(this.jointtype) - { + if (this.jointtype) { // already done :P entity must stay this.aiment = src; this.enemy = dst; - } - else if(!src || !dst) - { + } else if (!src || !dst) { objerror(this, "follow: could not find target/killtarget"); return; - } - else if(this.spawnflags & 1) - { + } else if (this.spawnflags & 1) { // attach - if(this.spawnflags & 2) - { + if (this.spawnflags & 2) { setattachment(dst, src, this.message); - } - else - { + } else { attach_sameorigin(dst, src, this.message); } dst.solid = SOLID_NOT; // solid doesn't work with attachment delete(this); - } - else - { - if(this.spawnflags & 2) - { + } else { + if (this.spawnflags & 2) { set_movetype(dst, MOVETYPE_FOLLOW); dst.aiment = src; // dst.punchangle = '0 0 0'; // keep unchanged dst.view_ofs = dst.origin; dst.v_angle = dst.angles; - } - else - { + } else { follow_sameorigin(dst, src); } diff --git a/qcsrc/common/triggers/misc/laser.qc b/qcsrc/common/triggers/misc/laser.qc index e4fd43c1a..90e6c3608 100644 --- a/qcsrc/common/triggers/misc/laser.qc +++ b/qcsrc/common/triggers/misc/laser.qc @@ -14,37 +14,27 @@ REGISTER_NET_LINKED(ENT_CLIENT_LASER) void misc_laser_aim(entity this) { vector a; - if(this.enemy) - { - if(this.spawnflags & 2) - { - if(this.enemy.origin != this.mangle) - { + if (this.enemy) { + if (this.spawnflags & 2) { + if (this.enemy.origin != this.mangle) { this.mangle = this.enemy.origin; this.SendFlags |= 2; } - } - else - { + } else { a = vectoangles(this.enemy.origin - this.origin); a_x = -a_x; - if(a != this.mangle) - { + if (a != this.mangle) { this.mangle = a; this.SendFlags |= 2; } } - } - else - { - if(this.angles != this.mangle) - { + } else { + if (this.angles != this.mangle) { this.mangle = this.angles; this.SendFlags |= 2; } } - if(this.origin != this.oldorigin) - { + if (this.origin != this.oldorigin) { this.SendFlags |= 1; this.oldorigin = this.origin; } @@ -52,8 +42,9 @@ void misc_laser_aim(entity this) void misc_laser_init(entity this) { - if(this.target != "") + if (this.target != "") { this.enemy = find(NULL, targetname, this.target); + } } .entity pusher; @@ -65,46 +56,38 @@ void misc_laser_think(entity this) this.nextthink = time; - if(!this.state) + if (!this.state) { return; + } misc_laser_aim(this); - if(this.enemy) - { + if (this.enemy) { o = this.enemy.origin; - if (!(this.spawnflags & 2)) + if (!(this.spawnflags & 2)) { o = this.origin + normalize(o - this.origin) * 32768; - } - else - { + } + } else { makevectors(this.mangle); o = this.origin + v_forward * 32768; } - if(this.dmg || this.enemy.target != "") - { + if (this.dmg || this.enemy.target != "") { traceline(this.origin, o, MOVE_NORMAL, this); } hitent = trace_ent; hitloc = trace_endpos; - if(this.enemy.target != "") // DETECTOR laser - { - if(trace_ent.iscreature) - { + if (this.enemy.target != "") { // DETECTOR laser + if (trace_ent.iscreature) { this.pusher = hitent; - if(!this.count) - { + if (!this.count) { this.count = 1; SUB_UseTargets(this.enemy, this.enemy.pusher, NULL); } - } - else - { - if(this.count) - { + } else { + if (this.count) { this.count = 0; SUB_UseTargets(this.enemy, this.enemy.pusher, NULL); @@ -112,13 +95,15 @@ void misc_laser_think(entity this) } } - if(this.dmg) - { - if(this.team) - if(((this.spawnflags & 8) == 0) == (this.team != hitent.team)) + if (this.dmg) { + if (this.team) { + if (((this.spawnflags & 8) == 0) == (this.team != hitent.team)) { return; - if(hitent.takedamage) + } + } + if (hitent.takedamage) { Damage(hitent, this, this, ((this.dmg < 0) ? 100000 : (this.dmg * frametime)), DEATH_HURTTRIGGER.m_id, hitloc, '0 0 0'); + } } } @@ -126,52 +111,52 @@ bool laser_SendEntity(entity this, entity to, float fl) { WriteHeader(MSG_ENTITY, ENT_CLIENT_LASER); fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser - if(this.spawnflags & 2) + if (this.spawnflags & 2) { fl |= 0x80; - if(this.alpha) + } + if (this.alpha) { fl |= 0x40; - if(this.scale != 1 || this.modelscale != 1) + } + if (this.scale != 1 || this.modelscale != 1) { fl |= 0x20; - if(this.spawnflags & 4) + } + if (this.spawnflags & 4) { fl |= 0x10; + } WriteByte(MSG_ENTITY, fl); - if(fl & 1) - { + if (fl & 1) { WriteCoord(MSG_ENTITY, this.origin_x); WriteCoord(MSG_ENTITY, this.origin_y); WriteCoord(MSG_ENTITY, this.origin_z); } - if(fl & 8) - { + if (fl & 8) { WriteByte(MSG_ENTITY, this.colormod_x * 255.0); WriteByte(MSG_ENTITY, this.colormod_y * 255.0); WriteByte(MSG_ENTITY, this.colormod_z * 255.0); - if(fl & 0x40) + if (fl & 0x40) { WriteByte(MSG_ENTITY, this.alpha * 255.0); - if(fl & 0x20) - { + } + if (fl & 0x20) { WriteByte(MSG_ENTITY, bound(0, this.scale * 16.0, 255)); WriteByte(MSG_ENTITY, bound(0, this.modelscale * 16.0, 255)); } - if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off + if ((fl & 0x80) || !(fl & 0x10)) { // effect doesn't need sending if the laser is infinite and has collision testing turned off WriteShort(MSG_ENTITY, this.cnt + 1); + } } - if(fl & 2) - { - if(fl & 0x80) - { + if (fl & 2) { + if (fl & 0x80) { WriteCoord(MSG_ENTITY, this.enemy.origin_x); WriteCoord(MSG_ENTITY, this.enemy.origin_y); WriteCoord(MSG_ENTITY, this.enemy.origin_z); - } - else - { + } else { WriteAngle(MSG_ENTITY, this.mangle_x); WriteAngle(MSG_ENTITY, this.mangle_y); } } - if(fl & 4) + if (fl & 4) { WriteByte(MSG_ENTITY, this.state); + } return 1; } @@ -196,43 +181,46 @@ void laser_use(entity this, entity actor, entity trigger) void laser_reset(entity this) { - if(this.spawnflags & 1) + if (this.spawnflags & 1) { this.state = 1; - else + } else { this.state = 0; + } } spawnfunc(misc_laser) { - if(this.mdl) - { - if(this.mdl == "none") + if (this.mdl) { + if (this.mdl == "none") { this.cnt = -1; - else - { + } else { this.cnt = _particleeffectnum(this.mdl); - if(this.cnt < 0 && this.dmg) - this.cnt = particleeffectnum(EFFECT_LASER_DEADLY); + if (this.cnt < 0 && this.dmg) { + this.cnt = particleeffectnum(EFFECT_LASER_DEADLY); + } } - } - else if(!this.cnt) - { - if(this.dmg) + } else if (!this.cnt) { + if (this.dmg) { this.cnt = particleeffectnum(EFFECT_LASER_DEADLY); - else + } else { this.cnt = -1; + } } - if(this.cnt < 0) + if (this.cnt < 0) { this.cnt = -1; + } - if(this.colormod == '0 0 0') - if(!this.alpha) + if (this.colormod == '0 0 0') { + if (!this.alpha) { this.colormod = '1 0 0'; - if(this.message == "") this.message = "saw the light"; - if (this.message2 == "") this.message2 = "was pushed into a laser by"; - if(!this.scale) this.scale = 1; - if(!this.modelscale) this.modelscale = 1; - else if(this.modelscale < 0) this.modelscale = 0; + } + } + if (this.message == "") { this.message = "saw the light"; } + if (this.message2 == "") { this.message2 = "was pushed into a laser by"; } + if (!this.scale) { this.scale = 1; } + if (!this.modelscale) { this.modelscale = 1; } else if (this.modelscale < 0) { + this.modelscale = 0; + } setthink(this, misc_laser_think); this.nextthink = time; InitializeEntity(this, misc_laser_init, INITPRIO_FINDTARGET); @@ -241,14 +229,13 @@ spawnfunc(misc_laser) Net_LinkEntity(this, false, 0, laser_SendEntity); - if(THIS_TARGETED) - { + if (THIS_TARGETED) { this.reset = laser_reset; this.reset(this); this.use = laser_use; - } - else + } else { this.state = 1; + } } #elif defined(CSQC) @@ -256,63 +243,55 @@ spawnfunc(misc_laser) // it has color 'colormod' // and stops when something is in the way entityclass(Laser); -class(Laser) .int cnt; // end effect -class(Laser) .vector colormod; -class(Laser) .int state; // on-off -class(Laser) .int count; // flags for the laser -class(Laser) .vector velocity; -class(Laser) .float alpha; -class(Laser) .float scale; // scaling factor of the thickness -class(Laser) .float modelscale; // scaling factor of the dlight +class(Laser).int cnt; // end effect +class(Laser).vector colormod; +class(Laser).int state; // on-off +class(Laser).int count; // flags for the laser +class(Laser).vector velocity; +class(Laser).float alpha; +class(Laser).float scale; // scaling factor of the thickness +class(Laser).float modelscale; // scaling factor of the dlight void Draw_Laser(entity this) { - if(!this.state) + if (!this.state) { return; + } InterpolateOrigin_Do(this); - if(this.count & 0x80) - { - if(this.count & 0x10) - { + if (this.count & 0x80) { + if (this.count & 0x10) { trace_endpos = this.velocity; trace_dphitq3surfaceflags = 0; - } - else + } else { traceline(this.origin, this.velocity, 0, this); - } - else - { - if(this.count & 0x10) - { + } + } else { + if (this.count & 0x10) { makevectors(this.angles); trace_endpos = this.origin + v_forward * 1048576; trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY; - } - else - { + } else { makevectors(this.angles); traceline(this.origin, this.origin + v_forward * 32768, 0, this); - if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) + if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) { trace_endpos = this.origin + v_forward * 1048576; + } } } - if(this.scale != 0) - { - if(this.alpha) - { + if (this.scale != 0) { + if (this.alpha) { Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, this.alpha, DRAWFLAG_NORMAL, view_origin); - } - else - { + } else { Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin); } } - if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT))) - { - if(this.cnt >= 0) + if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT))) { + if (this.cnt >= 0) { __pointparticles(this.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000); - if(this.colormod != '0 0 0' && this.modelscale != 0) + } + if (this.colormod != '0 0 0' && this.modelscale != 0) { adddynamiclight(trace_endpos + trace_plane_normal * 1, this.modelscale, this.colormod * 5); + } } } @@ -324,60 +303,57 @@ NET_HANDLE(ENT_CLIENT_LASER, bool isnew) int f = ReadByte(); this.count = (f & 0xF0); - if(this.count & 0x80) + if (this.count & 0x80) { this.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN; - else + } else { this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN; + } - if(f & 1) - { + if (f & 1) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); setorigin(this, this.origin); } - if(f & 8) - { + if (f & 8) { this.colormod_x = ReadByte() / 255.0; this.colormod_y = ReadByte() / 255.0; this.colormod_z = ReadByte() / 255.0; - if(f & 0x40) + if (f & 0x40) { this.alpha = ReadByte() / 255.0; - else + } else { this.alpha = 0; + } this.scale = 2; this.modelscale = 50; - if(f & 0x20) - { - this.scale *= ReadByte() / 16.0; // beam radius + if (f & 0x20) { + this.scale *= ReadByte() / 16.0; // beam radius this.modelscale *= ReadByte() / 16.0; // dlight radius } - if((f & 0x80) || !(f & 0x10)) - this.cnt = ReadShort() - 1; // effect number - else + if ((f & 0x80) || !(f & 0x10)) { + this.cnt = ReadShort() - 1; // effect number + } else { this.cnt = 0; + } } - if(f & 2) - { - if(f & 0x80) - { + if (f & 2) { + if (f & 0x80) { this.velocity_x = ReadCoord(); this.velocity_y = ReadCoord(); this.velocity_z = ReadCoord(); - } - else - { + } else { this.angles_x = ReadAngle(); this.angles_y = ReadAngle(); } } - if(f & 4) + if (f & 4) { this.state = ReadByte(); + } return = true; InterpolateOrigin_Note(this); this.draw = Draw_Laser; - if (isnew) IL_PUSH(g_drawables, this); + if (isnew) { IL_PUSH(g_drawables, this); } } #endif diff --git a/qcsrc/common/triggers/platforms.qc b/qcsrc/common/triggers/platforms.qc index 703f1d05c..48bc843e3 100644 --- a/qcsrc/common/triggers/platforms.qc +++ b/qcsrc/common/triggers/platforms.qc @@ -2,17 +2,16 @@ void generic_plat_blocked(entity this, entity blocker) { #ifdef SVQC - if(this.dmg && blocker.takedamage != DAMAGE_NO) - { - if(this.dmgtime2 < time) - { - Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + if (this.dmg && blocker.takedamage != DAMAGE_NO) { + if (this.dmgtime2 < time) { + Damage(blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); this.dmgtime2 = time + this.dmgtime; } // Gib dead/dying stuff - if(IS_DEAD(blocker)) - Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + if (IS_DEAD(blocker)) { + Damage(blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + } } #endif } @@ -31,27 +30,27 @@ void plat_spawn_inside_trigger(entity this) tmin = this.absmin + '25 25 0'; tmax = this.absmax - '25 25 -8'; tmin_z = tmax_z - (this.pos1_z - this.pos2_z + 8); - if (this.spawnflags & PLAT_LOW_TRIGGER) + if (this.spawnflags & PLAT_LOW_TRIGGER) { tmax_z = tmin_z + 8; + } - if (this.size_x <= 50) - { + if (this.size_x <= 50) { tmin_x = (this.mins_x + this.maxs_x) / 2; tmax_x = tmin_x + 1; } - if (this.size_y <= 50) - { + if (this.size_y <= 50) { tmin_y = (this.mins_y + this.maxs_y) / 2; tmax_y = tmin_y + 1; } - if(tmin_x < tmax_x) - if(tmin_y < tmax_y) - if(tmin_z < tmax_z) - { - setsize (trigger, tmin, tmax); + if (tmin_x < tmax_x) { + if (tmin_y < tmax_y) { + if (tmin_z < tmax_z) { + setsize(trigger, tmin, tmax); return; } + } + } // otherwise, something is fishy... delete(trigger); @@ -60,7 +59,7 @@ void plat_spawn_inside_trigger(entity this) void plat_hit_top(entity this) { - _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + _sound(this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); this.state = 1; setthink(this, plat_go_down); @@ -69,107 +68,115 @@ void plat_hit_top(entity this) void plat_hit_bottom(entity this) { - _sound (this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); + _sound(this, CH_TRIGGER_SINGLE, this.noise1, VOL_BASE, ATTEN_NORM); this.state = 2; } void plat_go_down(entity this) { - _sound (this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM); + _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM); this.state = 3; - SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, plat_hit_bottom); + SUB_CalcMove(this, this.pos2, TSPEED_LINEAR, this.speed, plat_hit_bottom); } void plat_go_up(entity this) { - _sound (this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM); + _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_NORM); this.state = 4; - SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, plat_hit_top); + SUB_CalcMove(this, this.pos1, TSPEED_LINEAR, this.speed, plat_hit_top); } void plat_center_touch(entity this, entity toucher) { #ifdef SVQC - if (!toucher.iscreature) + if (!toucher.iscreature) { return; + } - if (toucher.health <= 0) + if (toucher.health <= 0) { return; + } #elif defined(CSQC) - if (!IS_PLAYER(toucher)) + if (!IS_PLAYER(toucher)) { return; - if(IS_DEAD(toucher)) + } + if (IS_DEAD(toucher)) { return; + } #endif if (this.enemy.state == 2) { plat_go_up(this.enemy); - } else if (this.enemy.state == 1) + } else if (this.enemy.state == 1) { this.enemy.nextthink = this.enemy.ltime + 1; + } } void plat_outside_touch(entity this, entity toucher) { #ifdef SVQC - if (!toucher.iscreature) + if (!toucher.iscreature) { return; + } - if (toucher.health <= 0) + if (toucher.health <= 0) { return; + } #elif defined(CSQC) - if (!IS_PLAYER(toucher)) + if (!IS_PLAYER(toucher)) { return; + } #endif if (this.enemy.state == 1) { - entity e = this.enemy; + entity e = this.enemy; plat_go_down(e); - } + } } void plat_trigger_use(entity this, entity actor, entity trigger) { - if (getthink(this)) - return; // already activated + if (getthink(this)) { + return; // already activated + } plat_go_down(this); } void plat_crush(entity this, entity blocker) { - if((this.spawnflags & 4) && (blocker.takedamage != DAMAGE_NO)) - { // KIll Kill Kill!! + if ((this.spawnflags & 4) && (blocker.takedamage != DAMAGE_NO)) { // KIll Kill Kill!! #ifdef SVQC - Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + Damage(blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); #endif - } - else - { + } else { #ifdef SVQC - if((this.dmg) && (blocker.takedamage != DAMAGE_NO)) - { // Shall we bite? - Damage (blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + if ((this.dmg) && (blocker.takedamage != DAMAGE_NO)) { // Shall we bite? + Damage(blocker, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); // Gib dead/dying stuff - if(IS_DEAD(blocker)) - Damage (blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + if (IS_DEAD(blocker)) { + Damage(blocker, this, this, 10000, DEATH_HURTTRIGGER.m_id, blocker.origin, '0 0 0'); + } } #endif - if (this.state == 4) - plat_go_down (this); - else if (this.state == 3) - plat_go_up (this); - // when in other states, then the plat_crush event came delayed after - // plat state already had changed - // this isn't a bug per se! + if (this.state == 4) { + plat_go_down(this); + } else if (this.state == 3) { + plat_go_up(this); + } + // when in other states, then the plat_crush event came delayed after + // plat state already had changed + // this isn't a bug per se! } } void plat_use(entity this, entity actor, entity trigger) { this.use = func_null; - if (this.state != 4) - objerror (this, "plat_use: not in up state"); + if (this.state != 4) { + objerror(this, "plat_use: not in up state"); + } plat_go_down(this); } @@ -177,14 +184,11 @@ void plat_use(entity this, entity actor, entity trigger) void plat_reset(entity this) { - if(THIS_TARGETED) - { + if (THIS_TARGETED) { setorigin(this, this.pos1); this.state = 4; this.use = plat_use; - } - else - { + } else { setorigin(this, this.pos2); this.state = 2; this.use = plat_trigger_use; @@ -201,22 +205,24 @@ bool set_platmovetype(entity e, string s) // sets platmovetype_start and platmovetype_end based on a string consisting of two values int n = tokenize_console(s); - if(n > 0) + if (n > 0) { e.platmovetype_start = stof(argv(0)); - else + } else { e.platmovetype_start = 0; + } - if(n > 1) + if (n > 1) { e.platmovetype_end = stof(argv(1)); - else + } else { e.platmovetype_end = e.platmovetype_start; + } - if(n > 2) - if(argv(2) == "force") + if (n > 2) { + if (argv(2) == "force") { return true; // no checking, return immediately - - if(!cubic_speedfunc_is_sane(e.platmovetype_start, e.platmovetype_end)) - { + } + } + if (!cubic_speedfunc_is_sane(e.platmovetype_start, e.platmovetype_end)) { objerror(e, "Invalid platform move type; platform would go in reverse, which is not allowed."); return false; } diff --git a/qcsrc/common/triggers/subs.qc b/qcsrc/common/triggers/subs.qc index 5b6182e0a..81b84a510 100644 --- a/qcsrc/common/triggers/subs.qc +++ b/qcsrc/common/triggers/subs.qc @@ -1,5 +1,5 @@ #include "subs.qh" -void SUB_NullThink(entity this) { } +void SUB_NullThink(entity this) {} void SUB_CalcMoveDone(entity this); void SUB_CalcAngleMoveDone(entity this); @@ -12,11 +12,12 @@ Applies some friction to this ================== */ .float friction; -void SUB_Friction (entity this) +void SUB_Friction(entity this) { this.nextthink = time; - if(IS_ONGROUND(this)) + if (IS_ONGROUND(this)) { this.velocity = this.velocity * (1 - frametime * this.friction); + } } /* @@ -26,10 +27,9 @@ SUB_VanishOrRemove Makes client invisible or removes non-client ================== */ -void SUB_VanishOrRemove (entity ent) +void SUB_VanishOrRemove(entity ent) { - if (IS_CLIENT(ent)) - { + if (IS_CLIENT(ent)) { // vanish ent.alpha = -1; ent.effects = 0; @@ -37,25 +37,25 @@ void SUB_VanishOrRemove (entity ent) ent.glow_size = 0; ent.pflags = 0; #endif - } - else - { + } else { // remove delete(ent); } } -void SUB_SetFade_Think (entity this) +void SUB_SetFade_Think(entity this) { - if(this.alpha == 0) + if (this.alpha == 0) { this.alpha = 1; + } setthink(this, SUB_SetFade_Think); this.nextthink = time; this.alpha -= frametime * this.fade_rate; - if (this.alpha < 0.01) + if (this.alpha < 0.01) { SUB_VanishOrRemove(this); - else + } else { this.nextthink = time; + } } /* @@ -65,9 +65,9 @@ SUB_SetFade Fade 'ent' out when time >= 'when' ================== */ -void SUB_SetFade (entity ent, float when, float fading_time) +void SUB_SetFade(entity ent, float when, float fading_time) { - ent.fade_rate = 1/fading_time; + ent.fade_rate = 1 / fading_time; setthink(ent, SUB_SetFade_Think); ent.nextthink = when; } @@ -84,15 +84,16 @@ void SUB_CalcMoveDone(entity this) { // After moving, set origin to exact final destination - setorigin (this, this.finaldest); + setorigin(this, this.finaldest); this.velocity = '0 0 0'; this.nextthink = -1; - if (this.think1 && this.think1 != SUB_CalcMoveDone) - this.think1 (this); + if (this.think1 && this.think1 != SUB_CalcMoveDone) { + this.think1(this); + } } .float platmovetype_turn; -void SUB_CalcMove_controller_think (entity this) +void SUB_CalcMove_controller_think(entity this) { float traveltime; float phasepos; @@ -104,8 +105,7 @@ void SUB_CalcMove_controller_think (entity this) vector nextpos; delta = this.destvec; delta2 = this.destvec2; - if(time < this.animstate_endtime) - { + if (time < this.animstate_endtime) { nexttick = time + PHYS_INPUT_FRAMETIME; traveltime = this.animstate_endtime - this.animstate_starttime; @@ -114,8 +114,7 @@ void SUB_CalcMove_controller_think (entity this) nextpos = this.origin + (delta * phasepos) + (delta2 * phasepos * phasepos); // derivative: delta + 2 * delta2 * phasepos (e.g. for angle positioning) - if(this.owner.platmovetype_turn) - { + if (this.owner.platmovetype_turn) { vector destangle; destangle = delta + 2 * delta2 * phasepos; destangle = vectoangles(destangle); @@ -131,17 +130,16 @@ void SUB_CalcMove_controller_think (entity this) angloc = angloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame this.owner.avelocity = angloc; } - if(nexttick < this.animstate_endtime) + if (nexttick < this.animstate_endtime) { veloc = nextpos - this.owner.origin; - else + } else { veloc = this.finaldest - this.owner.origin; + } veloc = veloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame this.owner.velocity = veloc; this.nextthink = nexttick; - } - else - { + } else { // derivative: delta + 2 * delta2 (e.g. for angle positioning) entity own = this.owner; setthink(own, this.think1); @@ -150,7 +148,7 @@ void SUB_CalcMove_controller_think (entity this) } } -void SUB_CalcMove_controller_setbezier (entity controller, vector org, vector control, vector destin) +void SUB_CalcMove_controller_setbezier(entity controller, vector org, vector control, vector destin) { // 0 * (1-t) * (1-t) + 2 * control * t * (1-t) + destin * t * t // 2 * control * t - 2 * control * t * t + destin * t * t @@ -160,12 +158,12 @@ void SUB_CalcMove_controller_setbezier (entity controller, vector org, vector co control -= org; destin -= org; - controller.destvec = 2 * control; // control point + controller.destvec = 2 * control; // control point controller.destvec2 = destin - 2 * control; // quadratic part required to reach end point // also: initial d/dphasepos origin = 2 * control, final speed = 2 * (destin - control) } -void SUB_CalcMove_controller_setlinear (entity controller, vector org, vector destin) +void SUB_CalcMove_controller_setlinear(entity controller, vector org, vector destin) { // 0 * (1-t) * (1-t) + 2 * control * t * (1-t) + destin * t * t // 2 * control * t - 2 * control * t * t + destin * t * t @@ -184,20 +182,20 @@ float TSPEED_START = 1; float TSPEED_END = 2; // TODO average too? -void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func) +void SUB_CalcMove_Bezier(entity this, vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func) { - float traveltime; + float traveltime; entity controller; - if (!tspeed) - objerror (this, "No speed is defined!"); + if (!tspeed) { + objerror(this, "No speed is defined!"); + } this.think1 = func; this.finaldest = tdest; setthink(this, SUB_CalcMoveDone); - switch(tspeedtype) - { + switch (tspeedtype) { default: case TSPEED_START: traveltime = 2 * vlen(tcontrol - this.origin) / tspeed; @@ -213,8 +211,7 @@ void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspe break; } - if (traveltime < 0.1) // useless anim - { + if (traveltime < 0.1) { // useless anim this.velocity = '0 0 0'; this.nextthink = this.ltime + 0.1; return; @@ -240,20 +237,20 @@ void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspe getthink(controller)(controller); } -void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func) +void SUB_CalcMove(entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func) { - vector delta; - float traveltime; + vector delta; + float traveltime; - if (!tspeed) - objerror (this, "No speed is defined!"); + if (!tspeed) { + objerror(this, "No speed is defined!"); + } this.think1 = func; this.finaldest = tdest; setthink(this, SUB_CalcMoveDone); - if (tdest == this.origin) - { + if (tdest == this.origin) { this.velocity = '0 0 0'; this.nextthink = this.ltime + 0.1; return; @@ -261,13 +258,12 @@ void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, vo delta = tdest - this.origin; - switch(tspeedtype) - { + switch (tspeedtype) { default: case TSPEED_START: case TSPEED_END: case TSPEED_LINEAR: - traveltime = vlen (delta) / tspeed; + traveltime = vlen(delta) / tspeed; break; case TSPEED_TIME: traveltime = tspeed; @@ -277,10 +273,9 @@ void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, vo // Very short animations don't really show off the effect // of controlled animation, so let's just use linear movement. // Alternatively entities can choose to specify non-controlled movement. - // The only currently implemented alternative movement is linear (value 1) - if (traveltime < 0.15 || (this.platmovetype_start == 1 && this.platmovetype_end == 1)) // is this correct? - { - this.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division + // The only currently implemented alternative movement is linear (value 1) + if (traveltime < 0.15 || (this.platmovetype_start == 1 && this.platmovetype_end == 1)) { // is this correct? + this.velocity = delta * (1 / traveltime); // QuakeC doesn't allow vector/float division this.nextthink = this.ltime + traveltime; return; } @@ -289,7 +284,7 @@ void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, vo SUB_CalcMove_Bezier(this, (this.origin + tdest) * 0.5, tdest, tspeedtype, tspeed, func); } -void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func) +void SUB_CalcMoveEnt(entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func) { SUB_CalcMove(ent, tdest, tspeedtype, tspeed, func); } @@ -310,15 +305,17 @@ void SUB_CalcAngleMoveDone(entity this) this.angles = this.finalangle; this.avelocity = '0 0 0'; this.nextthink = -1; - if (this.think1 && this.think1 != SUB_CalcAngleMoveDone) // avoid endless loops - this.think1 (this); + if (this.think1 && this.think1 != SUB_CalcAngleMoveDone) { // avoid endless loops + this.think1(this); + } } // FIXME: I fixed this function only for rotation around the main axes -void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func) +void SUB_CalcAngleMove(entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func) { - if (!tspeed) - objerror (this, "No speed is defined!"); + if (!tspeed) { + objerror(this, "No speed is defined!"); + } // take the shortest distance for the angles this.angles_x -= 360 * floor((this.angles_x - destangle_x) / 360 + 0.5); @@ -327,13 +324,12 @@ void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float t vector delta = destangle - this.angles; float traveltime; - switch(tspeedtype) - { + switch (tspeedtype) { default: case TSPEED_START: case TSPEED_END: case TSPEED_LINEAR: - traveltime = vlen (delta) / tspeed; + traveltime = vlen(delta) / tspeed; break; case TSPEED_TIME: traveltime = tspeed; @@ -344,8 +340,7 @@ void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float t this.finalangle = destangle; setthink(this, SUB_CalcAngleMoveDone); - if (traveltime < 0.1) - { + if (traveltime < 0.1) { this.avelocity = '0 0 0'; this.nextthink = this.ltime + 0.1; return; @@ -355,7 +350,7 @@ void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float t this.nextthink = this.ltime + traveltime; } -void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func) +void SUB_CalcAngleMoveEnt(entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func) { - SUB_CalcAngleMove (ent, destangle, tspeedtype, tspeed, func); + SUB_CalcAngleMove(ent, destangle, tspeedtype, tspeed, func); } diff --git a/qcsrc/common/triggers/subs.qh b/qcsrc/common/triggers/subs.qh index 1b3bc5e69..e9ee8476a 100644 --- a/qcsrc/common/triggers/subs.qh +++ b/qcsrc/common/triggers/subs.qh @@ -1,30 +1,30 @@ #pragma once -void SUB_SetFade (entity ent, float when, float fading_time); -void SUB_VanishOrRemove (entity ent); +void SUB_SetFade(entity ent, float when, float fading_time); +void SUB_VanishOrRemove(entity ent); -.vector finaldest, finalangle; //plat.qc stuff +.vector finaldest, finalangle; // plat.qc stuff .void(entity this) think1; .float state; -.float t_length, t_width; +.float t_length, t_width; .vector destvec; .vector destvec2; -.float delay; -.float wait; -.float lip; -.float speed; -.float sounds; +.float delay; +.float wait; +.float lip; +.float speed; +.float sounds; .string platmovetype; .float platmovetype_start, platmovetype_end; -//entity activator; +// entity activator; .string killtarget; -.vector pos1, pos2; -.vector mangle; +.vector pos1, pos2; +.vector mangle; .string target2; .string target3; @@ -44,16 +44,16 @@ void SUB_VanishOrRemove (entity ent); #ifdef CSQC // this stuff is defined in the server side engine VM, so we must define it separately here .float takedamage; -const float DAMAGE_NO = 0; -const float DAMAGE_YES = 1; -const float DAMAGE_AIM = 2; +const float DAMAGE_NO = 0; +const float DAMAGE_YES = 1; +const float DAMAGE_AIM = 2; -float STATE_TOP = 0; -float STATE_BOTTOM = 1; -float STATE_UP = 2; -float STATE_DOWN = 3; +float STATE_TOP = 0; +float STATE_BOTTOM = 1; +float STATE_UP = 2; +float STATE_DOWN = 3; -.string noise, noise1, noise2, noise3; // contains names of wavs to play +.string noise, noise1, noise2, noise3; // contains names of wavs to play -.float max_health; // players maximum health is stored here +.float max_health; // players maximum health is stored here #endif diff --git a/qcsrc/common/triggers/target/changelevel.qc b/qcsrc/common/triggers/target/changelevel.qc index 6c006d42a..5540f936a 100644 --- a/qcsrc/common/triggers/target/changelevel.qc +++ b/qcsrc/common/triggers/target/changelevel.qc @@ -5,10 +5,9 @@ void target_changelevel_use(entity this, entity actor, entity trigger) { - if(this.spawnflags & 2) - { + if (this.spawnflags & 2) { // simply don't react if a non-player triggers it - if(!IS_PLAYER(actor)) { return; } + if (!IS_PLAYER(actor)) { return; } actor.chlevel_targ = this; @@ -17,26 +16,30 @@ void target_changelevel_use(entity this, entity actor, entity trigger) // let's not count bots FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { ++realplnum; - if(it.chlevel_targ == this) + if (it.chlevel_targ == this) { ++plnum; + } }); - if(plnum < ceil(realplnum * min(1, this.count))) // 70% of players + if (plnum < ceil(realplnum * min(1, this.count))) { // 70% of players return; + } } - if(this.gametype != "") + if (this.gametype != "") { MapInfo_SwitchGameType(MapInfo_Type_FromString(this.gametype)); + } - if (this.chmap == "") + if (this.chmap == "") { localcmd("endmatch\n"); - else + } else { localcmd(strcat("changelevel ", this.chmap, "\n")); + } } spawnfunc(target_changelevel) { this.use = target_changelevel_use; - if(!this.count) { this.count = 0.7; } + if (!this.count) { this.count = 0.7; } } #endif diff --git a/qcsrc/common/triggers/target/kill.qc b/qcsrc/common/triggers/target/kill.qc index a821ac139..41ce8fde5 100644 --- a/qcsrc/common/triggers/target/kill.qc +++ b/qcsrc/common/triggers/target/kill.qc @@ -4,23 +4,26 @@ void target_kill_use(entity this, entity actor, entity trigger) { - if(actor.takedamage == DAMAGE_NO) + if (actor.takedamage == DAMAGE_NO) { return; + } - if(!actor.iscreature && !actor.damagedbytriggers) + if (!actor.iscreature && !actor.damagedbytriggers) { return; + } Damage(actor, this, trigger, 1000, DEATH_HURTTRIGGER.m_id, actor.origin, '0 0 0'); } spawnfunc(target_kill) { - this.classname = "target_kill"; + this.classname = "target_kill"; - if (this.message == "") + if (this.message == "") { this.message = "was in the wrong place"; + } - this.use = target_kill_use; + this.use = target_kill_use; } #endif diff --git a/qcsrc/common/triggers/target/levelwarp.qc b/qcsrc/common/triggers/target/levelwarp.qc index 6cef53d6e..2db4d1c9f 100644 --- a/qcsrc/common/triggers/target/levelwarp.qc +++ b/qcsrc/common/triggers/target/levelwarp.qc @@ -3,13 +3,14 @@ #ifdef SVQC void target_levelwarp_use(entity this, entity actor, entity trigger) { - if(!autocvar_g_campaign) - return; // only in campaign - - if(this.cnt) + if (!autocvar_g_campaign) { + return; // only in campaign + } + if (this.cnt) { CampaignLevelWarp(this.cnt - 1); // specific level - else - CampaignLevelWarp(-1); // next level + } else { + CampaignLevelWarp(-1); // next level + } } spawnfunc(target_levelwarp) diff --git a/qcsrc/common/triggers/target/location.qc b/qcsrc/common/triggers/target/location.qc index 5774f45f9..618832bd2 100644 --- a/qcsrc/common/triggers/target/location.qc +++ b/qcsrc/common/triggers/target/location.qc @@ -4,22 +4,22 @@ void target_push_init(entity this); spawnfunc(target_location) { - this.classname = "target_location"; - // location name in netname - // eventually support: count, teamgame selectors, line of sight? + this.classname = "target_location"; + // location name in netname + // eventually support: count, teamgame selectors, line of sight? - target_push_init(this); + target_push_init(this); - IL_PUSH(g_locations, this); + IL_PUSH(g_locations, this); } spawnfunc(info_location) { - this.classname = "target_location"; - this.message = this.netname; + this.classname = "target_location"; + this.message = this.netname; - target_push_init(this); + target_push_init(this); - IL_PUSH(g_locations, this); + IL_PUSH(g_locations, this); } #endif diff --git a/qcsrc/common/triggers/target/music.qc b/qcsrc/common/triggers/target/music.qc index 1f8cb00cb..1e0bc9b0d 100644 --- a/qcsrc/common/triggers/target/music.qc +++ b/qcsrc/common/triggers/target/music.qc @@ -2,10 +2,10 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include - #include - #include - #include + #include + #include + #include + #include #endif REGISTER_NET_TEMP(TE_CSQC_TARGET_MUSIC) @@ -14,7 +14,10 @@ REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_MUSIC) #ifdef SVQC IntrusiveList g_targetmusic_list; -STATIC_INIT(g_targetmusic_list) { g_targetmusic_list = IL_NEW(); } +STATIC_INIT(g_targetmusic_list) +{ + g_targetmusic_list = IL_NEW(); +} // values: // volume @@ -37,25 +40,26 @@ void target_music_sendto(entity this, int to, bool is) } void target_music_reset(entity this) { - if (this.targetname == "") target_music_sendto(this, MSG_ALL, 1); + if (this.targetname == "") { target_music_sendto(this, MSG_ALL, 1); } } void target_music_kill() { IL_EACH(g_targetmusic_list, true, { it.volume = 0; - if (it.targetname == "") - target_music_sendto(it, MSG_ALL, 1); - else - target_music_sendto(it, MSG_ALL, 0); + if (it.targetname == "") { + target_music_sendto(it, MSG_ALL, 1); + } else { + target_music_sendto(it, MSG_ALL, 0); + } }); } void target_music_use(entity this, entity actor, entity trigger) { - if(!actor) + if (!actor) { return; - if(IS_REAL_CLIENT(actor)) - { + } + if (IS_REAL_CLIENT(actor)) { msg_entity = actor; target_music_sendto(this, MSG_ONE, 1); } @@ -68,22 +72,25 @@ spawnfunc(target_music) { this.use = target_music_use; this.reset = target_music_reset; - if(!this.volume) + if (!this.volume) { this.volume = 1; + } IL_PUSH(g_targetmusic_list, this); - if(this.targetname == "") + if (this.targetname == "") { target_music_sendto(this, MSG_INIT, 1); - else + } else { target_music_sendto(this, MSG_INIT, 0); + } } void TargetMusic_RestoreGame() { IL_EACH(g_targetmusic_list, true, { - if(it.targetname == "") + if (it.targetname == "") { target_music_sendto(it, MSG_INIT, 1); - else + } else { target_music_sendto(it, MSG_INIT, 0); + } }); } // values: @@ -98,19 +105,17 @@ bool trigger_music_SendEntity(entity this, entity to, float sf) { WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC); sf &= ~0x80; - if(this.cnt) + if (this.cnt) { sf |= 0x80; + } WriteByte(MSG_ENTITY, sf); - if(sf & 4) - { + if (sf & 4) { WriteCoord(MSG_ENTITY, this.origin.x); WriteCoord(MSG_ENTITY, this.origin.y); WriteCoord(MSG_ENTITY, this.origin.z); } - if(sf & 1) - { - if(this.model != "null") - { + if (sf & 1) { + if (this.model != "null") { WriteShort(MSG_ENTITY, this.modelindex); WriteCoord(MSG_ENTITY, this.mins.x); WriteCoord(MSG_ENTITY, this.mins.y); @@ -118,9 +123,7 @@ bool trigger_music_SendEntity(entity this, entity to, float sf) WriteCoord(MSG_ENTITY, this.maxs.x); WriteCoord(MSG_ENTITY, this.maxs.y); WriteCoord(MSG_ENTITY, this.maxs.z); - } - else - { + } else { WriteShort(MSG_ENTITY, 0); WriteCoord(MSG_ENTITY, this.maxs.x); WriteCoord(MSG_ENTITY, this.maxs.y); @@ -145,10 +148,9 @@ void trigger_music_use(entity this, entity actor, entity trigger) } spawnfunc(trigger_music) { - if(this.model != "") _setmodel(this, this.model); - if(!this.volume) this.volume = 1; - if(!this.modelindex) - { + if (this.model != "") { _setmodel(this, this.model); } + if (!this.volume) { this.volume = 1; } + if (!this.modelindex) { setorigin(this, this.origin + this.mins); setsize(this, '0 0 0', this.maxs - this.mins); } @@ -171,27 +173,24 @@ void TargetMusic_Advance() { // run AFTER all the thinks! entity best = music_default; - if (music_target && time < music_target.lifetime) best = music_target; - if (music_trigger) best = music_trigger; + if (music_target && time < music_target.lifetime) { best = music_target; } + if (music_trigger) { best = music_trigger; } LL_EACH(TargetMusic_list, it.noise, { const float vol0 = (getsoundtime(it, CH_BGM_SINGLE) >= 0) ? it.lastvol : -1; - if (it == best) - { - // increase volume + if (it == best) { + // increase volume it.state = (it.fade_time > 0) ? bound(0, it.state + frametime / it.fade_time, 1) : 1; - } - else - { - // decrease volume + } else { + // decrease volume it.state = (it.fade_rate > 0) ? bound(0, it.state - frametime / it.fade_rate, 1) : 0; } const float vol = it.state * it.volume * autocvar_bgmvolume; - if (vol != vol0) - { - if(vol0 < 0) + if (vol != vol0) { + if (vol0 < 0) { _sound(it, CH_BGM_SINGLE, it.noise, vol, ATTEN_NONE); // restart - else + } else { _sound(it, CH_BGM_SINGLE, "", vol, ATTEN_NONE); + } it.lastvol = vol; } }); @@ -215,21 +214,21 @@ void Net_TargetMusic() const string noi = ReadString(); entity e = NULL; - LL_EACH(TargetMusic_list, it.count == id, { e = it; break; }); - if (!e) - { + LL_EACH(TargetMusic_list, it.count == id, { e = it; + break; + }); + if (!e) { LL_PUSH(TargetMusic_list, e = new_pure(TargetMusic)); e.count = id; } - if(e.noise != noi) - { - if(e.noise) + if (e.noise != noi) { + if (e.noise) { strunzone(e.noise); + } e.noise = strzone(noi); precache_sound(e.noise); _sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE); - if(getsoundtime(e, CH_BGM_SINGLE) < 0) - { + if (getsoundtime(e, CH_BGM_SINGLE) < 0) { LOG_TRACEF("Cannot initialize sound %s", e.noise); strunzone(e.noise); e.noise = string_null; @@ -238,21 +237,16 @@ void Net_TargetMusic() e.volume = vol; e.fade_time = fai; e.fade_rate = fao; - if(vol > 0) - { - if(tim == 0) - { + if (vol > 0) { + if (tim == 0) { music_default = e; - if(!music_disabled) - { + if (!music_disabled) { e.state = 2; cvar_settemp("music_playlist_index", "-1"); // don't use playlists - localcmd("cd stop\n"); // just in case + localcmd("cd stop\n"); // just in case music_disabled = 1; } - } - else - { + } else { music_target = e; e.lifetime = time + tim; } @@ -261,8 +255,7 @@ void Net_TargetMusic() void Ent_TriggerMusic_Think(entity this) { - if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, this, NULL)) - { + if (WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, this, NULL)) { music_trigger = this; } this.nextthink = time; @@ -270,34 +263,30 @@ void Ent_TriggerMusic_Think(entity this) void Ent_TriggerMusic_Remove(entity this) { - if(this.noise) + if (this.noise) { strunzone(this.noise); + } this.noise = string_null; } NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew) { int f = ReadByte(); - if(f & 4) - { + if (f & 4) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); } - if(f & 1) - { + if (f & 1) { this.modelindex = ReadShort(); - if(this.modelindex) - { + if (this.modelindex) { this.mins_x = ReadCoord(); this.mins_y = ReadCoord(); this.mins_z = ReadCoord(); this.maxs_x = ReadCoord(); this.maxs_y = ReadCoord(); this.maxs_z = ReadCoord(); - } - else - { + } else { this.mins = '0 0 0'; this.maxs_x = ReadCoord(); this.maxs_y = ReadCoord(); @@ -308,15 +297,14 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew) this.fade_time = ReadByte() / 16.0; this.fade_rate = ReadByte() / 16.0; string s = this.noise; - if(this.noise) + if (this.noise) { strunzone(this.noise); + } this.noise = strzone(ReadString()); - if(this.noise != s) - { + if (this.noise != s) { precache_sound(this.noise); _sound(this, CH_BGM_SINGLE, this.noise, 0, ATTEN_NONE); - if(getsoundtime(this, CH_BGM_SINGLE) < 0) - { + if (getsoundtime(this, CH_BGM_SINGLE) < 0) { LOG_TRACEF("Cannot initialize sound %s", this.noise); strunzone(this.noise); this.noise = string_null; diff --git a/qcsrc/common/triggers/target/music.qh b/qcsrc/common/triggers/target/music.qh index 80b3684a4..b54effc5d 100644 --- a/qcsrc/common/triggers/target/music.qh +++ b/qcsrc/common/triggers/target/music.qh @@ -10,8 +10,8 @@ entity music_trigger; // FIXME also control bgmvolume here, to not require a target_music for the default track. entityclass(TargetMusic); -class(TargetMusic) .int state; -class(TargetMusic) .float lastvol; +class(TargetMusic).int state; +class(TargetMusic).float lastvol; void TargetMusic_Advance(); diff --git a/qcsrc/common/triggers/target/spawn.qc b/qcsrc/common/triggers/target/spawn.qc index 1464da955..f61f3b3b8 100644 --- a/qcsrc/common/triggers/target/spawn.qc +++ b/qcsrc/common/triggers/target/spawn.qc @@ -2,8 +2,8 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include - #include + #include + #include #endif #ifdef SVQC @@ -41,144 +41,106 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti n = tokenize_console(msg); - for(i = 0; i < n-1; i += 2) - { + for (i = 0; i < n - 1; i += 2) { key = argv(i); - value = argv(i+1); - if(key == "$") - { + value = argv(i + 1); + if (key == "$") { data.x = -1; data.y = FIELD_STRING; - } - else - { + } else { data = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", key))); - if(data.y == 0) // undefined field, i.e., invalid type - { + if (data.y == 0) { // undefined field, i.e., invalid type LOG_INFO("target_spawn: invalid/unknown entity key ", key, " specified, ignored!"); continue; } } - if(substring(value, 0, 1) == "$") - { + if (substring(value, 0, 1) == "$") { value = substring(value, 1, strlen(value) - 1); - if(substring(value, 0, 1) == "$") - { + if (substring(value, 0, 1) == "$") { // deferred replacement // do nothing // useful for creating target_spawns with this! - } - else - { + } else { // replace me! valuefieldpos = strstrofs(value, "+", 0); valueoffset = ""; - if(valuefieldpos != -1) - { + if (valuefieldpos != -1) { valueoffset = substring(value, valuefieldpos + 1, strlen(value) - valuefieldpos - 1); value = substring(value, 0, valuefieldpos); } valuefieldpos = strstrofs(valueoffset, "+", 0); valueoffsetrandom = ""; - if(valuefieldpos != -1) - { + if (valuefieldpos != -1) { valueoffsetrandom = substring(valueoffset, valuefieldpos + 1, strlen(valueoffset) - valuefieldpos - 1); valueoffset = substring(valueoffset, 0, valuefieldpos); } valuefieldpos = strstrofs(value, ".", 0); valuefield = ""; - if(valuefieldpos != -1) - { + if (valuefieldpos != -1) { valuefield = substring(value, valuefieldpos + 1, strlen(value) - valuefieldpos - 1); value = substring(value, 0, valuefieldpos); } - if(value == "self") - { + if (value == "self") { valueent = this; value = ""; - } - else if(value == "activator") - { + } else if (value == "activator") { valueent = act; value = ""; - } - else if(value == "other") - { + } else if (value == "other") { valueent = trigger; value = ""; - } - else if(value == "pusher") - { - if(time < act.pushltime) + } else if (value == "pusher") { + if (time < act.pushltime) { valueent = act.pusher; - else + } else { valueent = NULL; + } value = ""; - } - else if(value == "target") - { + } else if (value == "target") { valueent = e; value = ""; - } - else if(value == "killtarget") - { + } else if (value == "killtarget") { valueent = kt; value = ""; - } - else if(value == "target2") - { + } else if (value == "target2") { valueent = t2; value = ""; - } - else if(value == "target3") - { + } else if (value == "target3") { valueent = t3; value = ""; - } - else if(value == "target4") - { + } else if (value == "target4") { valueent = t4; value = ""; - } - else if(value == "time") - { + } else if (value == "time") { valueent = NULL; value = ftos(time); - } - else - { + } else { LOG_INFO("target_spawn: invalid/unknown variable replacement ", value, " specified, ignored!"); continue; } - if(valuefield == "") - { - if(value == "") + if (valuefield == "") { + if (value == "") { value = ftos(etof(valueent)); - } - else - { - if(value != "") - { + } + } else { + if (value != "") { LOG_INFO("target_spawn: try to get a field of a non-entity, ignored!"); continue; } data2 = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", valuefield))); - if(data2_y == 0) // undefined field, i.e., invalid type - { + if (data2_y == 0) { // undefined field, i.e., invalid type LOG_INFO("target_spawn: invalid/unknown entity key replacement ", valuefield, " specified, ignored!"); continue; } value = getentityfieldstring(data2_x, valueent); } - if(valueoffset != "") - { - switch(data.y) - { + if (valueoffset != "") { + switch (data.y) { case FIELD_STRING: value = strcat(value, valueoffset); break; @@ -194,10 +156,8 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti } } - if(valueoffsetrandom != "") - { - switch(data.y) - { + if (valueoffsetrandom != "") { + switch (data.y) { case FIELD_FLOAT: value = ftos(stof(value) + random() * stof(valueoffsetrandom)); break; @@ -212,21 +172,20 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti } } } - if(key == "$") - { - if(substring(value, 0, 1) == "_") + if (key == "$") { + if (substring(value, 0, 1) == "_") { value = strcat("target_spawn_helper", value); + } putentityfieldstring(target_spawn_spawnfunc_field, e, value); e.target_spawn_spawnfunc(e); // We called an external function, so we have to re-tokenize msg. n = tokenize_console(msg); - } - else - { - if(data.y == FIELD_VECTOR) + } else { + if (data.y == FIELD_VECTOR) { value = strreplace("'", "", value); // why?!? + } putentityfieldstring(data.x, e, value); } } @@ -254,39 +213,37 @@ bool target_spawn_cancreate(entity this) entity e; c = this.count; - if(c == 0) // no limit? + if (c == 0) { // no limit? return true; + } ++c; // increase count to not include MYSELF - for(e = NULL; (e = findfloat(e, target_spawn_id, this.target_spawn_id)); --c) - ; + for (e = NULL; (e = findfloat(e, target_spawn_id, this.target_spawn_id)); --c) {} // if c now is 0, we have AT LEAST the given count (maybe more), so don't spawn any more - if(c == 0) + if (c == 0) { return false; + } return true; } void target_spawn_use(entity this, entity actor, entity trigger) { - if(this.target == "") - { + if (this.target == "") { // spawn new entity - if(!target_spawn_cancreate(this)) + if (!target_spawn_cancreate(this)) { return; + } entity e = spawn(); e.spawnfunc_checked = true; target_spawn_useon(e, this, actor, trigger); e.target_spawn_id = this.target_spawn_id; - } - else if(this.target == "*activator") - { + } else if (this.target == "*activator") { // edit entity - if(actor) + if (actor) { target_spawn_useon(actor, this, actor, trigger); - } - else - { + } + } else { // edit entity FOREACH_ENTITY_STRING(targetname, this.target, { @@ -298,31 +255,30 @@ void target_spawn_use(entity this, entity actor, entity trigger) void target_spawn_spawnfirst(entity this) { entity act = this.target_spawn_activator; - if(this.spawnflags & 2) + if (this.spawnflags & 2) { target_spawn_use(this, act, NULL); + } } void initialize_field_db() { - if(!target_spawn_initialized) - { + if (!target_spawn_initialized) { float n, i; string fn; vector prev, next; float ft; n = numentityfields(); - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { fn = entityfieldname(i); ft = entityfieldtype(i); next = i * '1 0 0' + ft * '0 1 0' + '0 0 1'; prev = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", fn))); - if(prev.y == 0) - { + if (prev.y == 0) { db_put(TemporaryDB, strcat("/target_spawn/field/", fn), vtos(next)); - if(fn == "target_spawn_spawnfunc") + if (fn == "target_spawn_spawnfunc") { target_spawn_spawnfunc_field = i; + } } } diff --git a/qcsrc/common/triggers/target/speaker.qc b/qcsrc/common/triggers/target/speaker.qc index 355ba16c9..91716406c 100644 --- a/qcsrc/common/triggers/target/speaker.qc +++ b/qcsrc/common/triggers/target/speaker.qc @@ -4,58 +4,58 @@ void target_speaker_use_off(entity this, entity actor, entity trigger); void target_speaker_use_activator(entity this, entity actor, entity trigger) { - if (!IS_REAL_CLIENT(actor)) + if (!IS_REAL_CLIENT(actor)) { return; + } string snd; - if(substring(this.noise, 0, 1) == "*") - { - var .string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1)); - if(GetPlayerSoundSampleField_notFound) + if (substring(this.noise, 0, 1) == "*") { + var.string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1)); + if (GetPlayerSoundSampleField_notFound) { snd = SND(Null); - else if(actor.(sample) == "") + } else if (actor.(sample) == "") { snd = SND(Null); - else - { + } else { tokenize_console(actor.(sample)); float n; n = stof(argv(1)); - if(n > 0) + if (n > 0) { snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization - else - snd = strcat(argv(0), ".wav"); // randomization + } else { + snd = strcat(argv(0), ".wav"); // randomization + } } - } - else + } else { snd = this.noise; + } msg_entity = actor; soundto(MSG_ONE, this, CH_TRIGGER, snd, VOL_BASE * this.volume, this.atten); } void target_speaker_use_on(entity this, entity actor, entity trigger) { string snd; - if(substring(this.noise, 0, 1) == "*") - { - var .string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1)); - if(GetPlayerSoundSampleField_notFound) + if (substring(this.noise, 0, 1) == "*") { + var.string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1)); + if (GetPlayerSoundSampleField_notFound) { snd = SND(Null); - else if(actor.(sample) == "") + } else if (actor.(sample) == "") { snd = SND(Null); - else - { + } else { tokenize_console(actor.(sample)); float n; n = stof(argv(1)); - if(n > 0) + if (n > 0) { snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization - else - snd = strcat(argv(0), ".wav"); // randomization + } else { + snd = strcat(argv(0), ".wav"); // randomization + } } - } - else + } else { snd = this.noise; + } _sound(this, CH_TRIGGER_SINGLE, snd, VOL_BASE * this.volume, this.atten); - if(this.spawnflags & 3) + if (this.spawnflags & 3) { this.use = target_speaker_use_off; + } } void target_speaker_use_off(entity this, entity actor, entity trigger) { @@ -64,15 +64,14 @@ void target_speaker_use_off(entity this, entity actor, entity trigger) } void target_speaker_reset(entity this) { - if(this.spawnflags & 1) // LOOPED_ON - { - if(this.use == target_speaker_use_on) + if (this.spawnflags & 1) { // LOOPED_ON + if (this.use == target_speaker_use_on) { target_speaker_use_on(this, NULL, NULL); - } - else if(this.spawnflags & 2) - { - if(this.use == target_speaker_use_off) + } + } else if (this.spawnflags & 2) { + if (this.use == target_speaker_use_off) { target_speaker_use_off(this, NULL, NULL); + } } } @@ -80,52 +79,44 @@ spawnfunc(target_speaker) { // TODO: "*" prefix to sound file name // TODO: wait and random (just, HOW? random is not a field) - if(this.noise) - precache_sound (this.noise); + if (this.noise) { + precache_sound(this.noise); + } - if(!this.atten && !(this.spawnflags & 4)) - { - if(THIS_TARGETED) + if (!this.atten && !(this.spawnflags & 4)) { + if (THIS_TARGETED) { this.atten = ATTEN_NORM; - else + } else { this.atten = ATTEN_STATIC; - } - else if(this.atten < 0) + } + } else if (this.atten < 0) { this.atten = 0; + } - if(!this.volume) + if (!this.volume) { this.volume = 1; + } - if(THIS_TARGETED) - { - if(this.spawnflags & 8) // ACTIVATOR + if (THIS_TARGETED) { + if (this.spawnflags & 8) { // ACTIVATOR this.use = target_speaker_use_activator; - else if(this.spawnflags & 1) // LOOPED_ON - { + } else if (this.spawnflags & 1) { // LOOPED_ON target_speaker_use_on(this, NULL, NULL); this.reset = target_speaker_reset; - } - else if(this.spawnflags & 2) // LOOPED_OFF - { + } else if (this.spawnflags & 2) { // LOOPED_OFF this.use = target_speaker_use_on; this.reset = target_speaker_reset; - } - else + } else { this.use = target_speaker_use_on; - } - else if(this.spawnflags & 1) // LOOPED_ON - { - ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten); + } + } else if (this.spawnflags & 1) { // LOOPED_ON + ambientsound(this.origin, this.noise, VOL_BASE * this.volume, this.atten); delete(this); - } - else if(this.spawnflags & 2) // LOOPED_OFF - { + } else if (this.spawnflags & 2) { // LOOPED_OFF objerror(this, "This sound entity can never be activated"); - } - else - { + } else { // Quake/Nexuiz fallback - ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten); + ambientsound(this.origin, this.noise, VOL_BASE * this.volume, this.atten); delete(this); } } diff --git a/qcsrc/common/triggers/target/voicescript.qc b/qcsrc/common/triggers/target/voicescript.qc index 6dfb568a8..bb836a92e 100644 --- a/qcsrc/common/triggers/target/voicescript.qc +++ b/qcsrc/common/triggers/target/voicescript.qc @@ -1,9 +1,9 @@ #include "voicescript.qh" #ifdef SVQC -.entity voicescript; // attached voice script -.float voicescript_index; // index of next voice, or -1 to use the randomized ones +.entity voicescript; // attached voice script +.float voicescript_index; // index of next voice, or -1 to use the randomized ones .float voicescript_nextthink; // time to play next voice -.float voicescript_voiceend; // time when this voice ends +.float voicescript_voiceend; // time when this voice ends void target_voicescript_clear(entity pl) { @@ -12,8 +12,7 @@ void target_voicescript_clear(entity pl) void target_voicescript_use(entity this, entity actor, entity trigger) { - if(actor.voicescript != this) - { + if (actor.voicescript != this) { actor.voicescript = this; actor.voicescript_index = 0; actor.voicescript_nextthink = time + this.delay; @@ -26,48 +25,45 @@ void target_voicescript_next(entity pl) float i, n, dt; vs = pl.voicescript; - if(!vs) + if (!vs) { return; - if(vs.message == "") + } + if (vs.message == "") { return; - if (!IS_PLAYER(pl)) + } + if (!IS_PLAYER(pl)) { return; - if(game_stopped) + } + if (game_stopped) { return; + } - if(time >= pl.voicescript_voiceend) - { - if(time >= pl.voicescript_nextthink) - { + if (time >= pl.voicescript_voiceend) { + if (time >= pl.voicescript_nextthink) { // get the next voice... n = tokenize_console(vs.message); - if(pl.voicescript_index < vs.cnt) + if (pl.voicescript_index < vs.cnt) { i = pl.voicescript_index * 2; - else if(n > vs.cnt * 2) + } else if (n > vs.cnt * 2) { i = ((pl.voicescript_index - vs.cnt) % ((n - vs.cnt * 2 - 1) / 2)) * 2 + vs.cnt * 2 + 1; - else + } else { i = -1; + } - if(i >= 0) - { + if (i >= 0) { play2(pl, strcat(vs.netname, "/", argv(i), ".wav")); dt = stof(argv(i + 1)); - if(dt >= 0) - { + if (dt >= 0) { pl.voicescript_voiceend = time + dt; pl.voicescript_nextthink = pl.voicescript_voiceend + vs.wait * (0.5 + random()); - } - else - { + } else { pl.voicescript_voiceend = time - dt; pl.voicescript_nextthink = pl.voicescript_voiceend; } pl.voicescript_index += 1; - } - else - { + } else { pl.voicescript = NULL; // stop trying then } } @@ -89,10 +85,8 @@ spawnfunc(target_voicescript) n = tokenize_console(this.message); this.cnt = n / 2; - for(i = 0; i+1 < n; i += 2) - { - if(argv(i) == "*") - { + for (i = 0; i + 1 < n; i += 2) { + if (argv(i) == "*") { this.cnt = i / 2; ++i; } diff --git a/qcsrc/common/triggers/trigger/counter.qc b/qcsrc/common/triggers/trigger/counter.qc index 8246aed7c..0e028e620 100644 --- a/qcsrc/common/triggers/trigger/counter.qc +++ b/qcsrc/common/triggers/trigger/counter.qc @@ -3,24 +3,25 @@ void counter_use(entity this, entity actor, entity trigger) { this.count -= 1; - if (this.count < 0) + if (this.count < 0) { return; + } - if (this.count == 0) - { - if(IS_PLAYER(actor) && (this.spawnflags & SPAWNFLAG_NOMESSAGE) == 0) + if (this.count == 0) { + if (IS_PLAYER(actor) && (this.spawnflags & SPAWNFLAG_NOMESSAGE) == 0) { Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COMPLETED); + } this.enemy = actor; multi_trigger(this); - } - else - { - if(IS_PLAYER(actor) && (this.spawnflags & SPAWNFLAG_NOMESSAGE) == 0) - if(this.count >= 4) - Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER); - else - Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER_FEWMORE, this.count); + } else { + if (IS_PLAYER(actor) && (this.spawnflags & SPAWNFLAG_NOMESSAGE) == 0) { + if (this.count >= 4) { + Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER); + } else { + Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER_FEWMORE, this.count); + } + } } } @@ -40,8 +41,9 @@ After the counter has been triggered "count" times (default 2), it will fire all spawnfunc(trigger_counter) { this.wait = -1; - if (!this.count) + if (!this.count) { this.count = 2; + } this.cnt = this.count; this.use = counter_use; diff --git a/qcsrc/common/triggers/trigger/delay.qc b/qcsrc/common/triggers/trigger/delay.qc index dc1a781f8..9410737ab 100644 --- a/qcsrc/common/triggers/trigger/delay.qc +++ b/qcsrc/common/triggers/trigger/delay.qc @@ -2,8 +2,8 @@ #ifdef SVQC void delay_use(entity this, entity actor, entity trigger) { - setthink(this, SUB_UseTargets_self); - this.nextthink = time + this.wait; + setthink(this, SUB_UseTargets_self); + this.nextthink = time + this.wait; } void delay_reset(entity this) @@ -14,10 +14,11 @@ void delay_reset(entity this) spawnfunc(trigger_delay) { - if(!this.wait) - this.wait = 1; + if (!this.wait) { + this.wait = 1; + } - this.use = delay_use; - this.reset = delay_reset; + this.use = delay_use; + this.reset = delay_reset; } #endif diff --git a/qcsrc/common/triggers/trigger/disablerelay.qc b/qcsrc/common/triggers/trigger/disablerelay.qc index eee61c993..5c915557e 100644 --- a/qcsrc/common/triggers/trigger/disablerelay.qc +++ b/qcsrc/common/triggers/trigger/disablerelay.qc @@ -4,22 +4,19 @@ void trigger_disablerelay_use(entity this, entity actor, entity trigger) { int a = 0, b = 0; - for(entity e = NULL; (e = find(e, targetname, this.target)); ) - { - if(e.use == SUB_UseTargets) - { + for (entity e = NULL; (e = find(e, targetname, this.target)); ) { + if (e.use == SUB_UseTargets) { e.use = SUB_DontUseTargets; ++a; - } - else if(e.use == SUB_DontUseTargets) - { + } else if (e.use == SUB_DontUseTargets) { e.use = SUB_UseTargets; ++b; } } - if((!a) == (!b)) + if ((!a) == (!b)) { LOG_INFO("Invalid use of trigger_disablerelay: ", ftos(a), " relays were on, ", ftos(b), " relays were off!"); + } } spawnfunc(trigger_disablerelay) diff --git a/qcsrc/common/triggers/trigger/flipflop.qc b/qcsrc/common/triggers/trigger/flipflop.qc index af212ff5a..3d6ca77a9 100644 --- a/qcsrc/common/triggers/trigger/flipflop.qc +++ b/qcsrc/common/triggers/trigger/flipflop.qc @@ -5,17 +5,19 @@ */ void flipflop_use(entity this, entity actor, entity trigger) { - this.state = !this.state; - if(this.state) - SUB_UseTargets(this, actor, trigger); + this.state = !this.state; + if (this.state) { + SUB_UseTargets(this, actor, trigger); + } } spawnfunc(trigger_flipflop) { - if(this.spawnflags & 1) - this.state = 1; - this.use = flipflop_use; - this.reset = spawnfunc_trigger_flipflop; // perfect resetter + if (this.spawnflags & 1) { + this.state = 1; + } + this.use = flipflop_use; + this.reset = spawnfunc_trigger_flipflop; // perfect resetter } #endif diff --git a/qcsrc/common/triggers/trigger/gamestart.qc b/qcsrc/common/triggers/trigger/gamestart.qc index 72d76d183..9cf149bf4 100644 --- a/qcsrc/common/triggers/trigger/gamestart.qc +++ b/qcsrc/common/triggers/trigger/gamestart.qc @@ -16,13 +16,12 @@ spawnfunc(trigger_gamestart) this.use = gamestart_use; this.reset2 = spawnfunc_trigger_gamestart; - if(this.wait) - { + if (this.wait) { setthink(this, adaptor_think2use); this.nextthink = game_starttime + this.wait; - } - else + } else { InitializeEntity(this, gamestart_use_this, INITPRIO_FINDTARGET); + } } #endif diff --git a/qcsrc/common/triggers/trigger/gravity.qc b/qcsrc/common/triggers/trigger/gravity.qc index 4112dbdb1..b6824ec2c 100644 --- a/qcsrc/common/triggers/trigger/gravity.qc +++ b/qcsrc/common/triggers/trigger/gravity.qc @@ -3,14 +3,13 @@ .entity trigger_gravity_check; void trigger_gravity_remove(entity own) { - if(own.trigger_gravity_check.owner == own) - { + if (own.trigger_gravity_check.owner == own) { UpdateCSQCProjectile(own); own.gravity = own.trigger_gravity_check.gravity; delete(own.trigger_gravity_check); - } - else + } else { backtrace("Removing a trigger_gravity_check with no valid owner"); + } own.trigger_gravity_check = NULL; } void trigger_gravity_check_think(entity this) @@ -18,16 +17,14 @@ void trigger_gravity_check_think(entity this) // This spawns when a player enters the gravity zone and checks if he left. // Each frame, this.count is set to 2 by trigger_gravity_touch() and decreased by 1 here. // It the player has left the gravity trigger, this will be allowed to reach 0 and indicate that. - if(this.count <= 0) - { - if(this.owner.trigger_gravity_check == this) + if (this.count <= 0) { + if (this.owner.trigger_gravity_check == this) { trigger_gravity_remove(this.owner); - else + } else { delete(this); + } return; - } - else - { + } else { this.count -= 1; this.nextthink = time; } @@ -42,29 +39,28 @@ void trigger_gravity_touch(entity this, entity toucher) { float g; - if(this.state != true) + if (this.state != true) { return; + } EXACTTRIGGER_TOUCH(this, toucher); g = this.gravity; - if (!(this.spawnflags & 1)) - { - if(toucher.trigger_gravity_check) - { - if(this == toucher.trigger_gravity_check.enemy) - { + if (!(this.spawnflags & 1)) { + if (toucher.trigger_gravity_check) { + if (this == toucher.trigger_gravity_check.enemy) { // same? toucher.trigger_gravity_check.count = 2; // gravity one more frame... return; } // compare prio - if(this.cnt > toucher.trigger_gravity_check.enemy.cnt) + if (this.cnt > toucher.trigger_gravity_check.enemy.cnt) { trigger_gravity_remove(toucher); - else + } else { return; + } } toucher.trigger_gravity_check = spawn(); toucher.trigger_gravity_check.enemy = this; @@ -73,35 +69,38 @@ void trigger_gravity_touch(entity this, entity toucher) setthink(toucher.trigger_gravity_check, trigger_gravity_check_think); toucher.trigger_gravity_check.nextthink = time; toucher.trigger_gravity_check.count = 2; - if(toucher.gravity) + if (toucher.gravity) { g *= toucher.gravity; + } } - if (toucher.gravity != g) - { + if (toucher.gravity != g) { toucher.gravity = g; - if(this.noise != "") - _sound (toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM); + if (this.noise != "") { + _sound(toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM); + } UpdateCSQCProjectile(this.owner); } } spawnfunc(trigger_gravity) { - if(this.gravity == 1) + if (this.gravity == 1) { return; + } EXACTTRIGGER_INIT; settouch(this, trigger_gravity_touch); - if(this.noise != "") + if (this.noise != "") { precache_sound(this.noise); + } this.state = true; - if(THIS_TARGETED) - { + if (THIS_TARGETED) { this.use = trigger_gravity_use; - if(this.spawnflags & 2) + if (this.spawnflags & 2) { this.state = false; + } } } #endif diff --git a/qcsrc/common/triggers/trigger/heal.qc b/qcsrc/common/triggers/trigger/heal.qc index e7b309062..f01108d61 100644 --- a/qcsrc/common/triggers/trigger/heal.qc +++ b/qcsrc/common/triggers/trigger/heal.qc @@ -3,24 +3,24 @@ .float triggerhealtime; void trigger_heal_touch(entity this, entity toucher) { - if (this.active != ACTIVE_ACTIVE) + if (this.active != ACTIVE_ACTIVE) { return; + } // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu) - if (toucher.iscreature) - { - if (toucher.takedamage) - if (!IS_DEAD(toucher)) - if (toucher.triggerhealtime < time) - { - EXACTTRIGGER_TOUCH(this, toucher); - toucher.triggerhealtime = time + 1; + if (toucher.iscreature) { + if (toucher.takedamage) { + if (!IS_DEAD(toucher)) { + if (toucher.triggerhealtime < time) { + EXACTTRIGGER_TOUCH(this, toucher); + toucher.triggerhealtime = time + 1; - if (toucher.health < this.max_health) - { - toucher.health = min(toucher.health + this.health, this.max_health); - toucher.pauserothealth_finished = max(toucher.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot); - _sound (toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM); + if (toucher.health < this.max_health) { + toucher.health = min(toucher.health + this.health, this.max_health); + toucher.pauserothealth_finished = max(toucher.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot); + _sound(toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM); + } + } } } } @@ -32,12 +32,15 @@ spawnfunc(trigger_heal) EXACTTRIGGER_INIT; settouch(this, trigger_heal_touch); - if (!this.health) + if (!this.health) { this.health = 10; - if (!this.max_health) - this.max_health = 200; //Max health topoff for field - if(this.noise == "") + } + if (!this.max_health) { + this.max_health = 200; // Max health topoff for field + } + if (this.noise == "") { this.noise = "misc/mediumhealth.wav"; + } precache_sound(this.noise); } #endif diff --git a/qcsrc/common/triggers/trigger/hurt.qc b/qcsrc/common/triggers/trigger/hurt.qc index d0ba4ebd1..999280066 100644 --- a/qcsrc/common/triggers/trigger/hurt.qc +++ b/qcsrc/common/triggers/trigger/hurt.qc @@ -2,52 +2,49 @@ #ifdef SVQC void trigger_hurt_use(entity this, entity actor, entity trigger) { - if(IS_PLAYER(actor)) + if (IS_PLAYER(actor)) { this.enemy = actor; - else + } else { this.enemy = NULL; // let's just destroy it, if taking over is too much work + } } .float triggerhurttime; void trigger_hurt_touch(entity this, entity toucher) { - if (this.active != ACTIVE_ACTIVE) + if (this.active != ACTIVE_ACTIVE) { return; + } - if(this.team) - if(((this.spawnflags & 4) == 0) == (this.team != toucher.team)) + if (this.team) { + if (((this.spawnflags & 4) == 0) == (this.team != toucher.team)) { return; + } + } // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu) - if (toucher.iscreature) - { - if (toucher.takedamage) - if (toucher.triggerhurttime < time) - { - EXACTTRIGGER_TOUCH(this, toucher); - toucher.triggerhurttime = time + 1; + if (toucher.iscreature) { + if (toucher.takedamage) { + if (toucher.triggerhurttime < time) { + EXACTTRIGGER_TOUCH(this, toucher); + toucher.triggerhurttime = time + 1; - entity own; - own = this.enemy; - if (!IS_PLAYER(own)) - { - own = this; - this.enemy = NULL; // I still hate you all - } + entity own; + own = this.enemy; + if (!IS_PLAYER(own)) { + own = this; + this.enemy = NULL; // I still hate you all + } - Damage (toucher, this, own, this.dmg, DEATH_HURTTRIGGER.m_id, toucher.origin, '0 0 0'); + Damage(toucher, this, own, this.dmg, DEATH_HURTTRIGGER.m_id, toucher.origin, '0 0 0'); + } } - } - else if(toucher.damagedbytriggers) - { - if(toucher.takedamage) - { + } else if (toucher.damagedbytriggers) { + if (toucher.takedamage) { EXACTTRIGGER_TOUCH(this, toucher); Damage(toucher, this, this, this.dmg, DEATH_HURTTRIGGER.m_id, toucher.origin, '0 0 0'); } } - - return; } /*QUAKED spawnfunc_trigger_hurt (.5 .5 .5) ? @@ -65,18 +62,23 @@ spawnfunc(trigger_hurt) settouch(this, trigger_hurt_touch); this.use = trigger_hurt_use; this.enemy = world; // I hate you all - if (!this.dmg) + if (!this.dmg) { this.dmg = 1000; - if (this.message == "") + } + if (this.message == "") { this.message = "was in the wrong place"; - if (this.message2 == "") + } + if (this.message2 == "") { this.message2 = "was thrown into a world of hurt by"; + } // this.message = "someone like %s always gets wrongplaced"; - if(!trigger_hurt_first) + if (!trigger_hurt_first) { trigger_hurt_first = this; - if(trigger_hurt_last) + } + if (trigger_hurt_last) { trigger_hurt_last.trigger_hurt_next = this; + } trigger_hurt_last = this; } @@ -84,9 +86,11 @@ float tracebox_hits_trigger_hurt(vector start, vector mi, vector ma, vector end) { entity th; - for(th = trigger_hurt_first; th; th = th.trigger_hurt_next) - if(tracebox_hits_box(start, mi, ma, end, th.absmin, th.absmax)) + for (th = trigger_hurt_first; th; th = th.trigger_hurt_next) { + if (tracebox_hits_box(start, mi, ma, end, th.absmin, th.absmax)) { return true; + } + } return false; } diff --git a/qcsrc/common/triggers/trigger/impulse.qc b/qcsrc/common/triggers/trigger/impulse.qc index 62793e470..a1e438506 100644 --- a/qcsrc/common/triggers/trigger/impulse.qc +++ b/qcsrc/common/triggers/trigger/impulse.qc @@ -6,17 +6,18 @@ void trigger_impulse_touch1(entity this, entity toucher) float pushdeltatime; float str; - if (this.active != ACTIVE_ACTIVE) + if (this.active != ACTIVE_ACTIVE) { return; + } - if (!isPushable(toucher)) + if (!isPushable(toucher)) { return; + } EXACTTRIGGER_TOUCH(this, toucher); targ = find(NULL, targetname, this.target); - if(!targ) - { + if (!targ) { objerror(this, "trigger_force without a (valid) .target!\n"); delete(this); return; @@ -24,29 +25,28 @@ void trigger_impulse_touch1(entity this, entity toucher) str = min(this.radius, vlen(this.origin - toucher.origin)); - if(this.falloff == 1) + if (this.falloff == 1) { str = (str / this.radius) * this.strength; - else if(this.falloff == 2) + } else if (this.falloff == 2) { str = (1 - (str / this.radius)) * this.strength; - else + } else { str = this.strength; + } pushdeltatime = time - toucher.lastpushtime; - if (pushdeltatime > 0.15) pushdeltatime = 0; + if (pushdeltatime > 0.15) { pushdeltatime = 0; } toucher.lastpushtime = time; - if(!pushdeltatime) return; + if (!pushdeltatime) { return; } - if(this.spawnflags & 64) - { + if (this.spawnflags & 64) { float addspeed = str - toucher.velocity * normalize(targ.origin - this.origin); - if (addspeed > 0) - { + if (addspeed > 0) { float accelspeed = min(8 * pushdeltatime * str, addspeed); toucher.velocity += accelspeed * normalize(targ.origin - this.origin); } - } - else + } else { toucher.velocity = toucher.velocity + normalize(targ.origin - this.origin) * str * pushdeltatime; + } UNSET_ONGROUND(toucher); @@ -60,18 +60,20 @@ void trigger_impulse_touch2(entity this, entity toucher) { float pushdeltatime; - if (this.active != ACTIVE_ACTIVE) + if (this.active != ACTIVE_ACTIVE) { return; + } - if (!isPushable(toucher)) + if (!isPushable(toucher)) { return; + } EXACTTRIGGER_TOUCH(this, toucher); pushdeltatime = time - toucher.lastpushtime; - if (pushdeltatime > 0.15) pushdeltatime = 0; + if (pushdeltatime > 0.15) { pushdeltatime = 0; } toucher.lastpushtime = time; - if(!pushdeltatime) return; + if (!pushdeltatime) { return; } // div0: ticrate independent, 1 = identity (not 20) toucher.velocity = toucher.velocity * POW(this.strength, pushdeltatime); @@ -87,29 +89,32 @@ void trigger_impulse_touch3(entity this, entity toucher) float pushdeltatime; float str; - if (this.active != ACTIVE_ACTIVE) + if (this.active != ACTIVE_ACTIVE) { return; + } - if (!isPushable(toucher)) + if (!isPushable(toucher)) { return; + } EXACTTRIGGER_TOUCH(this, toucher); pushdeltatime = time - toucher.lastpushtime; - if (pushdeltatime > 0.15) pushdeltatime = 0; + if (pushdeltatime > 0.15) { pushdeltatime = 0; } toucher.lastpushtime = time; - if(!pushdeltatime) return; + if (!pushdeltatime) { return; } - setsize(this, '-1 -1 -1' * this.radius,'1 1 1' * this.radius); + setsize(this, '-1 -1 -1' * this.radius, '1 1 1' * this.radius); str = min(this.radius, vlen(this.origin - toucher.origin)); - if(this.falloff == 1) + if (this.falloff == 1) { str = (1 - str / this.radius) * this.strength; // 1 in the inside - else if(this.falloff == 2) - str = (str / this.radius) * this.strength; // 0 in the inside - else + } else if (this.falloff == 2) { + str = (str / this.radius) * this.strength; // 0 in the inside + } else { str = this.strength; + } toucher.velocity = toucher.velocity + normalize(toucher.origin - this.origin) * str * pushdeltatime; @@ -123,11 +128,11 @@ REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_IMPULSE) /*QUAKED spawnfunc_trigger_impulse (.5 .5 .5) ? -------- KEYS -------- target : If this is set, this points to the spawnfunc_target_position to which the player will get pushed. - If not, this trigger acts like a damper/accelerator field. + If not, this trigger acts like a damper/accelerator field. strength : This is how mutch force to add in the direction of .target each second - when .target is set. If not, this is hoe mutch to slow down/accelerate - someting cought inside this trigger. (1=no change, 0,5 half speed rougthly each tic, 2 = doubble) + when .target is set. If not, this is hoe mutch to slow down/accelerate + someting cought inside this trigger. (1=no change, 0,5 half speed rougthly each tic, 2 = doubble) radius : If set, act as a spherical device rather then a liniar one. @@ -164,23 +169,17 @@ spawnfunc(trigger_impulse) trigger_init(this); - if(this.radius) - { - if(!this.strength) this.strength = 2000 * autocvar_g_triggerimpulse_radial_multiplier; + if (this.radius) { + if (!this.strength) { this.strength = 2000 * autocvar_g_triggerimpulse_radial_multiplier; } setorigin(this, this.origin); - setsize(this, '-1 -1 -1' * this.radius,'1 1 1' * this.radius); + setsize(this, '-1 -1 -1' * this.radius, '1 1 1' * this.radius); settouch(this, trigger_impulse_touch3); - } - else - { - if(this.target) - { - if(!this.strength) this.strength = 950 * autocvar_g_triggerimpulse_directional_multiplier; + } else { + if (this.target) { + if (!this.strength) { this.strength = 950 * autocvar_g_triggerimpulse_directional_multiplier; } settouch(this, trigger_impulse_touch1); - } - else - { - if(!this.strength) this.strength = 0.9; + } else { + if (!this.strength) { this.strength = 0.9; } this.strength = POW(this.strength, autocvar_g_triggerimpulse_accel_power) * autocvar_g_triggerimpulse_accel_multiplier; settouch(this, trigger_impulse_touch2); } @@ -205,8 +204,8 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_IMPULSE, bool isnew) this.entremove = trigger_remove_generic; this.move_time = time; - if (this.radius) { settouch(this, trigger_impulse_touch3); } - else if (this.target) { settouch(this, trigger_impulse_touch1); } - else { settouch(this, trigger_impulse_touch2); } + if (this.radius) { settouch(this, trigger_impulse_touch3); } else if (this.target) { + settouch(this, trigger_impulse_touch1); + } else { settouch(this, trigger_impulse_touch2); } } #endif diff --git a/qcsrc/common/triggers/trigger/keylock.qc b/qcsrc/common/triggers/trigger/keylock.qc index bf20d1e97..cff0ad9a9 100644 --- a/qcsrc/common/triggers/trigger/keylock.qc +++ b/qcsrc/common/triggers/trigger/keylock.qc @@ -4,9 +4,11 @@ */ void trigger_keylock_trigger(entity this, entity actor, string s) { - for(entity t = NULL; (t = find(t, targetname, s)); ) - if(t.use) + for (entity t = NULL; (t = find(t, targetname, s)); ) { + if (t.use) { t.use(t, actor, this); + } + } } /** @@ -15,8 +17,9 @@ void trigger_keylock_trigger(entity this, entity actor, string s) void trigger_keylock_kill(string s) { entity t; - for(t = NULL; (t = find(t, targetname, s)); ) + for (t = NULL; (t = find(t, targetname, s)); ) { delete(t); + } } void trigger_keylock_touch(entity this, entity toucher) @@ -25,26 +28,24 @@ void trigger_keylock_touch(entity this, entity toucher) bool started_delay = false; // only player may trigger the lock - if(!IS_PLAYER(toucher)) + if (!IS_PLAYER(toucher)) { return; + } // check silver key - if(this.itemkeys) + if (this.itemkeys) { key_used = item_keys_usekey(this, toucher); + } - if(this.itemkeys) - { + if (this.itemkeys) { #ifdef SVQC // at least one of the keys is missing - if(key_used) - { + if (key_used) { // one or more keys were given, but others are still missing! play2(toucher, this.noise1); Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(this.itemkeys)); toucher.key_door_messagetime = time + 2; - } - else if(toucher.key_door_messagetime <= time) - { + } else if (toucher.key_door_messagetime <= time) { // no keys were given play2(toucher, this.noise2); Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(this.itemkeys)); @@ -53,31 +54,30 @@ void trigger_keylock_touch(entity this, entity toucher) #endif // trigger target2 - if(this.delay <= time || started_delay == true) - if(this.target2) - { - trigger_keylock_trigger(this, toucher, this.target2); - started_delay = true; - this.delay = time + this.wait; + if (this.delay <= time || started_delay == true) { + if (this.target2) { + trigger_keylock_trigger(this, toucher, this.target2); + started_delay = true; + this.delay = time + this.wait; + } } - } - else - { + } else { #ifdef SVQC // all keys were given! play2(toucher, this.noise); centerprint(toucher, this.message); #endif - if(this.target) + if (this.target) { trigger_keylock_trigger(this, toucher, this.target); + } - if(this.killtarget) + if (this.killtarget) { trigger_keylock_kill(this.killtarget); + } delete(this); } - } REGISTER_NET_LINKED(ENT_CLIENT_KEYLOCK) @@ -98,7 +98,7 @@ bool trigger_keylock_send(entity this, entity to, int sf) void trigger_keylock_link(entity this) { // uncomment to network keylocks - //Net_LinkEntity(this, false, 0, trigger_keylock_send); + // Net_LinkEntity(this, false, 0, trigger_keylock_send); } /*QUAKED trigger_keylock (.0 .5 .8) ? @@ -122,33 +122,36 @@ message2 and noise2 will be resent to the player every 2 seconds while he is in */ spawnfunc(trigger_keylock) { - if(!this.itemkeys) { delete(this); return; } + if (!this.itemkeys) { delete(this); return; } // set unlocked message - if(this.message == "") + if (this.message == "") { this.message = "Unlocked!"; + } // set default unlock noise - if(this.noise == "") - { - if(this.sounds == 1) + if (this.noise == "") { + if (this.sounds == 1) { this.noise = "misc/secret.wav"; - else if(this.sounds == 2) + } else if (this.sounds == 2) { this.noise = strzone(SND(TALK)); - else //if (this.sounds == 3) { + } else { // if (this.sounds == 3) { this.noise = "misc/trigger1.wav"; + } } // set default use key sound - if(this.noise1 == "") + if (this.noise1 == "") { this.noise1 = "misc/decreasevalue.wav"; + } // set closed sourd - if(this.noise2 == "") + if (this.noise2 == "") { this.noise2 = SND(TALK); + } // delay between triggering message2 and trigger2 - if(!this.wait) { this.wait = 5; } + if (!this.wait) { this.wait = 5; } // precache sounds precache_sound(this.noise); @@ -164,22 +167,22 @@ spawnfunc(trigger_keylock) #elif defined(CSQC) void keylock_remove(entity this) { - if(this.target) { strunzone(this.target); } + if (this.target) { strunzone(this.target); } this.target = string_null; - if(this.target2) { strunzone(this.target2); } + if (this.target2) { strunzone(this.target2); } this.target2 = string_null; - if(this.target3) { strunzone(this.target3); } + if (this.target3) { strunzone(this.target3); } this.target3 = string_null; - if(this.target4) { strunzone(this.target4); } + if (this.target4) { strunzone(this.target4); } this.target4 = string_null; - if(this.killtarget) { strunzone(this.killtarget); } + if (this.killtarget) { strunzone(this.killtarget); } this.killtarget = string_null; - if(this.targetname) { strunzone(this.targetname); } + if (this.targetname) { strunzone(this.targetname); } this.targetname = string_null; } diff --git a/qcsrc/common/triggers/trigger/keylock.qh b/qcsrc/common/triggers/trigger/keylock.qh index 904c3fa3d..0944f3d52 100644 --- a/qcsrc/common/triggers/trigger/keylock.qh +++ b/qcsrc/common/triggers/trigger/keylock.qh @@ -4,7 +4,7 @@ bool item_keys_usekey(entity l, entity p) { int valid = (l.itemkeys & p.itemkeys); // TODO: itemkeys isn't networked or anything! - l.itemkeys &= ~valid; // only some of the needed keys were given + l.itemkeys &= ~valid; // only some of the needed keys were given return valid != 0; } #endif diff --git a/qcsrc/common/triggers/trigger/magicear.qc b/qcsrc/common/triggers/trigger/magicear.qc index 354ed1bfe..0da480fdd 100644 --- a/qcsrc/common/triggers/trigger/magicear.qc +++ b/qcsrc/common/triggers/trigger/magicear.qc @@ -13,136 +13,136 @@ string trigger_magicear_processmessage(entity ear, entity source, float teamsay, dotrigger = ((IS_PLAYER(source)) && (!IS_DEAD(source)) && ((ear.radius == 0) || (vdist(source.origin - ear.origin, <=, ear.radius)))); domatch = ((ear.spawnflags & 32) || dotrigger); - if (!domatch) + if (!domatch) { return msgin; + } - if (!msgin) - { + if (!msgin) { // we are in TUBA mode! - if (!(ear.spawnflags & 256)) + if (!(ear.spawnflags & 256)) { return msgin; + } - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - if(!W_Tuba_HasPlayed(source, weaponentity, ear.message, ear.movedir_x, !(ear.spawnflags & 512), ear.movedir_y, ear.movedir_z)) + if (!W_Tuba_HasPlayed(source, weaponentity, ear.message, ear.movedir_x, !(ear.spawnflags & 512), ear.movedir_y, ear.movedir_z)) { return msgin; + } } magicear_matched = true; - if(dotrigger) - { + if (dotrigger) { savemessage = ear.message; ear.message = string_null; SUB_UseTargets(ear, source, NULL); ear.message = savemessage; } - if(ear.netname != "") + if (ear.netname != "") { return ear.netname; + } return msgin; } - if(ear.spawnflags & 256) // ENOTUBA + if (ear.spawnflags & 256) { // ENOTUBA return msgin; + } - if(privatesay) - { - if(ear.spawnflags & 4) + if (privatesay) { + if (ear.spawnflags & 4) { return msgin; - } - else - { - if(!teamsay) - if(ear.spawnflags & 1) + } + } else { + if (!teamsay) { + if (ear.spawnflags & 1) { return msgin; - if(teamsay > 0) - if(ear.spawnflags & 2) + } + } + if (teamsay > 0) { + if (ear.spawnflags & 2) { return msgin; - if(teamsay < 0) - if(ear.spawnflags & 8) + } + } + if (teamsay < 0) { + if (ear.spawnflags & 8) { return msgin; + } + } } matchstart = -1; l = strlen(ear.message); - if(ear.spawnflags & 128) + if (ear.spawnflags & 128) { msg = msgin; - else + } else { msg = strdecolorize(msgin); + } - if(substring(ear.message, 0, 1) == "*") - { - if(substring(ear.message, -1, 1) == "*") - { + if (substring(ear.message, 0, 1) == "*") { + if (substring(ear.message, -1, 1) == "*") { // two wildcards // as we need multi-replacement here... s = substring(ear.message, 1, -2); l -= 2; - if(strstrofs(msg, s, 0) >= 0) + if (strstrofs(msg, s, 0) >= 0) { matchstart = -2; // we use strreplace on s - } - else - { + } + } else { // match at start s = substring(ear.message, 1, -1); l -= 1; - if(substring(msg, -l, l) == s) + if (substring(msg, -l, l) == s) { matchstart = strlen(msg) - l; + } } - } - else - { - if(substring(ear.message, -1, 1) == "*") - { + } else { + if (substring(ear.message, -1, 1) == "*") { // match at end s = substring(ear.message, 0, -2); l -= 1; - if(substring(msg, 0, l) == s) + if (substring(msg, 0, l) == s) { matchstart = 0; - } - else - { + } + } else { // full match s = ear.message; - if(msg == ear.message) + if (msg == ear.message) { matchstart = 0; + } } } - if(matchstart == -1) // no match + if (matchstart == -1) { // no match return msgin; + } magicear_matched = true; - if(dotrigger) - { + if (dotrigger) { savemessage = ear.message; ear.message = string_null; SUB_UseTargets(ear, source, NULL); ear.message = savemessage; } - if(ear.spawnflags & 16) - { + if (ear.spawnflags & 16) { return ear.netname; - } - else if(ear.netname != "") - { - if(matchstart < 0) + } else if (ear.netname != "") { + if (matchstart < 0) { return strreplace(s, ear.netname, msg); - else + } else { return strcat( substring(msg, 0, matchstart), ear.netname, substring(msg, matchstart + l, -1) ); - } - else + } + } else { return msgin; + } } entity magicears; @@ -150,12 +150,13 @@ string trigger_magicear_processmessage_forallears(entity source, float teamsay, { entity ear; string msgout; - for(ear = magicears; ear; ear = ear.enemy) - { + for (ear = magicears; ear; ear = ear.enemy) { msgout = trigger_magicear_processmessage(ear, source, teamsay, privatesay, msgin); - if(!(ear.spawnflags & 64)) - if(magicear_matched) - return msgout; + if (!(ear.spawnflags & 64)) { + if (magicear_matched) { + return msgout; + } + } msgin = msgout; } return msgin; diff --git a/qcsrc/common/triggers/trigger/monoflop.qc b/qcsrc/common/triggers/trigger/monoflop.qc index a67baca16..79b4228e4 100644 --- a/qcsrc/common/triggers/trigger/monoflop.qc +++ b/qcsrc/common/triggers/trigger/monoflop.qc @@ -7,15 +7,17 @@ void monoflop_use(entity this, entity actor, entity trigger) { this.nextthink = time + this.wait; this.enemy = actor; - if(this.state) + if (this.state) { return; + } this.state = 1; SUB_UseTargets(this, actor, trigger); } void monoflop_fixed_use(entity this, entity actor, entity trigger) { - if(this.state) + if (this.state) { return; + } this.nextthink = time + this.wait; this.state = 1; this.enemy = actor; @@ -36,12 +38,14 @@ void monoflop_reset(entity this) spawnfunc(trigger_monoflop) { - if(!this.wait) + if (!this.wait) { this.wait = 1; - if(this.spawnflags & 1) + } + if (this.spawnflags & 1) { this.use = monoflop_fixed_use; - else + } else { this.use = monoflop_use; + } setthink(this, monoflop_think); this.state = 0; this.reset = monoflop_reset; diff --git a/qcsrc/common/triggers/trigger/multivibrator.qc b/qcsrc/common/triggers/trigger/multivibrator.qc index 6bf0557f2..77cc3838b 100644 --- a/qcsrc/common/triggers/trigger/multivibrator.qc +++ b/qcsrc/common/triggers/trigger/multivibrator.qc @@ -9,14 +9,16 @@ void multivibrator_send(entity this) newstate = (time < cyclestart + this.wait); - if(this.state != newstate) + if (this.state != newstate) { SUB_UseTargets(this, this, NULL); + } this.state = newstate; - if(this.state) + if (this.state) { this.nextthink = cyclestart + this.wait + 0.01; - else + } else { this.nextthink = cyclestart + this.wait + this.respawntime + 0.01; + } } void multivibrator_send_think(entity this) @@ -26,14 +28,10 @@ void multivibrator_send_think(entity this) void multivibrator_toggle(entity this, entity actor, entity trigger) { - if(this.nextthink == 0) - { + if (this.nextthink == 0) { multivibrator_send(this); - } - else - { - if(this.state) - { + } else { + if (this.state) { SUB_UseTargets(this, actor, trigger); this.state = 0; } @@ -43,10 +41,11 @@ void multivibrator_toggle(entity this, entity actor, entity trigger) void multivibrator_reset(entity this) { - if(!(this.spawnflags & 1)) + if (!(this.spawnflags & 1)) { this.nextthink = 0; // wait for a trigger event - else + } else { this.nextthink = max(1, time); + } } /*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ON @@ -62,17 +61,20 @@ START_ON: assume it is already turned on (when targeted) */ spawnfunc(trigger_multivibrator) { - if(!this.wait) + if (!this.wait) { this.wait = 1; - if(!this.respawntime) + } + if (!this.respawntime) { this.respawntime = this.wait; + } this.state = 0; this.use = multivibrator_toggle; setthink(this, multivibrator_send_think); this.nextthink = max(1, time); - if(THIS_TARGETED) + if (THIS_TARGETED) { multivibrator_reset(this); + } } #endif diff --git a/qcsrc/common/triggers/trigger/relay_activators.qc b/qcsrc/common/triggers/trigger/relay_activators.qc index d713a0583..e64768ccf 100644 --- a/qcsrc/common/triggers/trigger/relay_activators.qc +++ b/qcsrc/common/triggers/trigger/relay_activators.qc @@ -2,20 +2,20 @@ #ifdef SVQC void relay_activators_use(entity this, entity actor, entity trigger) { - for(entity trg = NULL; (trg = find(trg, targetname, this.target)); ) - { - if (trg.setactive) + for (entity trg = NULL; (trg = find(trg, targetname, this.target)); ) { + if (trg.setactive) { trg.setactive(trg, this.cnt); - else - { - //bprint("Not using setactive\n"); - if(this.cnt == ACTIVE_TOGGLE) - if(trg.active == ACTIVE_ACTIVE) + } else { + // bprint("Not using setactive\n"); + if (this.cnt == ACTIVE_TOGGLE) { + if (trg.active == ACTIVE_ACTIVE) { trg.active = ACTIVE_NOT; - else + } else { trg.active = ACTIVE_ACTIVE; - else + } + } else { trg.active = this.cnt; + } } } } diff --git a/qcsrc/common/triggers/trigger/relay_if.qc b/qcsrc/common/triggers/trigger/relay_if.qc index 728252c70..dae6d5d90 100644 --- a/qcsrc/common/triggers/trigger/relay_if.qc +++ b/qcsrc/common/triggers/trigger/relay_if.qc @@ -4,13 +4,15 @@ void trigger_relay_if_use(entity this, entity actor, entity trigger) { int n = this.count; - // TODO make this generic AND faster than nextent()ing through all, if somehow possible + // TODO make this generic AND faster than nextent() ing through all, if somehow possible n = (cvar_string(this.netname) == cvar_string(this.message)); - if(this.spawnflags & 1) + if (this.spawnflags & 1) { n = !n; + } - if(n) + if (n) { SUB_UseTargets(this, actor, trigger); + } } spawnfunc(trigger_relay_if) diff --git a/qcsrc/common/triggers/trigger/secret.qc b/qcsrc/common/triggers/trigger/secret.qc index c3c2c7474..a322c4524 100644 --- a/qcsrc/common/triggers/trigger/secret.qc +++ b/qcsrc/common/triggers/trigger/secret.qc @@ -2,8 +2,8 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include - #include + #include + #include #endif #ifdef SVQC @@ -20,13 +20,14 @@ void secrets_setstatus(entity this) void trigger_secret_touch(entity this, entity toucher) { // only a player can trigger this - if (!IS_PLAYER(toucher)) + if (!IS_PLAYER(toucher)) { return; + } // update secrets found counter secrets_found += 1; - //print("Secret found: ", ftos(secret_counter.cnt), "/"); - //print(ftos(secret_counter.count), "\n"); + // print("Secret found: ", ftos(secret_counter.cnt), "/"); + // print(ftos(secret_counter.count), "\n"); // centerprint message (multi_touch() doesn't always call centerprint()) centerprint(toucher, this.message); @@ -36,7 +37,7 @@ void trigger_secret_touch(entity this, entity toucher) multi_touch(this, toucher); // we can't just delete(this) here, because this is a touch function // called while C code is looping through area links... - //delete(this); + // delete(this); } /*QUAKED trigger_secret (.5 .5 .5) ? @@ -60,14 +61,16 @@ spawnfunc(trigger_secret) secrets_total += 1; // add default message - if (this.message == "") + if (this.message == "") { this.message = "You found a secret!"; + } // set default sound - if (this.noise == "") - if (!this.sounds) - this.sounds = 1; // misc/secret.wav - + if (this.noise == "") { + if (!this.sounds) { + this.sounds = 1; // misc/secret.wav + } + } // this entity can't be a target itself!!!! this.targetname = ""; @@ -78,7 +81,7 @@ spawnfunc(trigger_secret) this.delay = 0; // convert this trigger to trigger_once - //this.classname = "trigger_once"; + // this.classname = "trigger_once"; spawnfunc_trigger_once(this); // take over the touch() function, so we can mark secret as found diff --git a/qcsrc/common/triggers/trigger/swamp.qc b/qcsrc/common/triggers/trigger/swamp.qc index 71c5247c7..6d5c1e3d4 100644 --- a/qcsrc/common/triggers/trigger/swamp.qc +++ b/qcsrc/common/triggers/trigger/swamp.qc @@ -2,10 +2,10 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include - #include - #include - #include + #include + #include + #include + #include #endif /* @@ -16,8 +16,8 @@ * 2005 11 29 */ -.float swamp_interval; //Hurt players in swamp with this interval -.float swamp_slowdown; //Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?) +.float swamp_interval; // Hurt players in swamp with this interval +.float swamp_slowdown; // Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?) .entity swampslug; #ifdef SVQC @@ -39,15 +39,14 @@ void swampslug_think(entity this); */ void swampslug_think(entity this) { - //Slowly kill the slug + // Slowly kill the slug this.health = this.health - 1; - //Slug dead? then remove curses. - if(this.health <= 0) - { + // Slug dead? then remove curses. + if (this.health <= 0) { this.owner.in_swamp = 0; delete(this); - //centerprint(this.owner,"Killing slug...\n"); + // centerprint(this.owner,"Killing slug...\n"); return; } @@ -55,7 +54,7 @@ void swampslug_think(entity this) // Or we have exited it very recently. // Do the damage and renew the timer. #ifdef SVQC - Damage (this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, this.owner.origin, '0 0 0'); + Damage(this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, this.owner.origin, '0 0 0'); #endif this.nextthink = time + this.swamp_interval; @@ -65,16 +64,16 @@ void swamp_touch(entity this, entity toucher) { // If whatever thats touching the swamp is not a player // or if its a dead player, just dont care abt it. - if(!IS_PLAYER(toucher) || IS_DEAD(toucher)) + if (!IS_PLAYER(toucher) || IS_DEAD(toucher)) { return; + } EXACTTRIGGER_TOUCH(this, toucher); // Chech if player alredy got a swampslug. - if(toucher.in_swamp != 1) - { + if (toucher.in_swamp != 1) { // If not attach one. - //centerprint(toucher,"Entering swamp!\n"); + // centerprint(toucher,"Entering swamp!\n"); toucher.swampslug = spawn(); toucher.swampslug.health = 2; setthink(toucher.swampslug, swampslug_think); @@ -87,9 +86,9 @@ void swamp_touch(entity this, entity toucher) return; } - //toucher.in_swamp = 1; + // toucher.in_swamp = 1; - //Revitalize players swampslug + // Revitalize players swampslug toucher.swampslug.health = 2; } @@ -125,12 +124,15 @@ spawnfunc(trigger_swamp) settouch(this, swamp_touch); // Setup default keys, if missing - if(this.dmg <= 0) + if (this.dmg <= 0) { this.dmg = 5; - if(this.swamp_interval <= 0) + } + if (this.swamp_interval <= 0) { this.swamp_interval = 1; - if(this.swamp_slowdown <= 0) + } + if (this.swamp_slowdown <= 0) { this.swamp_slowdown = 0.5; + } swamp_link(this); } diff --git a/qcsrc/common/triggers/trigger/swamp.qh b/qcsrc/common/triggers/trigger/swamp.qh index f4df98378..1e576d29f 100644 --- a/qcsrc/common/triggers/trigger/swamp.qh +++ b/qcsrc/common/triggers/trigger/swamp.qh @@ -1,8 +1,8 @@ #pragma once -.float swamp_interval; //Hurt players in swamp with this interval -.float swamp_slowdown; //Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?) +.float swamp_interval; // Hurt players in swamp with this interval +.float swamp_slowdown; // Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?) .entity swampslug; -.float in_swamp; // bool -.entity swampslug; // Uses this to release from swamp ("untouch" fix) +.float in_swamp; // bool +.entity swampslug; // Uses this to release from swamp ("untouch" fix) diff --git a/qcsrc/common/triggers/trigger/viewloc.qc b/qcsrc/common/triggers/trigger/viewloc.qc index ffc04a078..8005e96be 100644 --- a/qcsrc/common/triggers/trigger/viewloc.qc +++ b/qcsrc/common/triggers/trigger/viewloc.qc @@ -2,8 +2,8 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include - #include + #include + #include #endif REGISTER_NET_LINKED(ENT_CLIENT_VIEWLOC) @@ -18,25 +18,28 @@ void viewloc_think(entity this) // we abuse this method, rather than using normal .touch, because touch isn't reliable with multiple clients inside the same trigger, and can't "untouch" entities // set myself as current viewloc where possible - for(e = NULL; (e = findentity(e, viewloc, this)); ) + for (e = NULL; (e = findentity(e, viewloc, this)); ) { e.viewloc = NULL; - - for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain) - if(!e.viewloc) - if(IS_PLAYER(e)) // should we support non-player entities with this? - //if(!IS_DEAD(e)) // death view is handled separately, we can't override this just yet - { - vector emin = e.absmin; - vector emax = e.absmax; - if(this.solid == SOLID_BSP) - { - emin -= '1 1 1'; - emax += '1 1 1'; + } + + for (e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain) { + if (!e.viewloc) { + if (IS_PLAYER(e)) { // should we support non-player entities with this? + // if(!IS_DEAD(e)) // death view is handled separately, we can't override this just yet + vector emin = e.absmin; + vector emax = e.absmax; + if (this.solid == SOLID_BSP) { + emin -= '1 1 1'; + emax += '1 1 1'; + } + if (boxesoverlap(emin, emax, this.absmin, this.absmax)) { // quick + if (WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) { // accurate + e.viewloc = this; } - if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick - if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate - e.viewloc = this; } + } + } + } this.nextthink = time; } @@ -59,24 +62,24 @@ bool trigger_viewloc_send(entity this, entity to, int sf) void viewloc_init(entity this) { entity e; - for(e = NULL; (e = find(e, targetname, this.target)); ) - if(e.classname == "target_viewlocation_start") - { + for (e = NULL; (e = find(e, targetname, this.target)); ) { + if (e.classname == "target_viewlocation_start") { this.enemy = e; break; } - for(e = NULL; (e = find(e, targetname, this.target2)); ) - if(e.classname == "target_viewlocation_end") - { + } + for (e = NULL; (e = find(e, targetname, this.target2)); ) { + if (e.classname == "target_viewlocation_end") { this.goalentity = e; break; } + } - if(!this.enemy) { LOG_INFO("^1FAIL!"); delete(this); return; } + if (!this.enemy) { LOG_INFO("^1FAIL!"); delete(this); return; } - if(!this.goalentity) + if (!this.goalentity) { this.goalentity = this.enemy; // make them match so CSQC knows what to do - + } Net_LinkEntity(this, false, 0, trigger_viewloc_send); setthink(this, viewloc_think); @@ -86,7 +89,7 @@ void viewloc_init(entity this) spawnfunc(trigger_viewlocation) { // we won't check target2 here yet, as it may not even need to exist - if(this.target == "") { LOG_INFO("^1FAIL!"); delete(this); return; } + if (this.target == "") { LOG_INFO("^1FAIL!"); delete(this); return; } EXACTTRIGGER_INIT; InitializeEntity(this, viewloc_init, INITPRIO_FINDTARGET); @@ -112,8 +115,9 @@ bool viewloc_send(entity this, entity to, int sf) .float angle; void viewloc_link(entity this) { - if(this.angle) + if (this.angle) { this.angles_y = this.angle; + } Net_LinkEntity(this, false, 0, viewloc_send); } @@ -131,7 +135,10 @@ spawnfunc(target_viewlocation_end) } // compatibility -spawnfunc(target_viewlocation) { spawnfunc_target_viewlocation_start(this); } +spawnfunc(target_viewlocation) +{ + spawnfunc_target_viewlocation_start(this); +} #elif defined(CSQC) @@ -161,7 +168,7 @@ NET_HANDLE(ENT_CLIENT_VIEWLOC_TRIGGER, bool isnew) this.count = point2; setthink(this, trigger_viewloc_updatelink); - this.nextthink = time + 1; // we need to delay this or else + this.nextthink = time + 1; // we need to delay this or else this.classname = "trigger_viewlocation"; this.drawmask = MASK_NORMAL; // not so concerned, but better keep it alive diff --git a/qcsrc/common/triggers/triggers.qc b/qcsrc/common/triggers/triggers.qc index 2a76d80c4..6ff3acb97 100644 --- a/qcsrc/common/triggers/triggers.qc +++ b/qcsrc/common/triggers/triggers.qc @@ -1,11 +1,11 @@ #include "triggers.qh" -void SUB_DontUseTargets(entity this, entity actor, entity trigger) { } +void SUB_DontUseTargets(entity this, entity actor, entity trigger) {} void SUB_UseTargets(entity this, entity actor, entity trigger); void DelayThink(entity this) { - SUB_UseTargets (this, this.enemy, NULL); + SUB_UseTargets(this, this.enemy, NULL); delete(this); } @@ -28,22 +28,22 @@ void trigger_init(entity this) { string m = this.model; EXACTTRIGGER_INIT; - if(autocvar_g_triggers_debug) - { - if(m != "") - { - precache_model(m); - _setmodel(this, m); // no precision needed + if (autocvar_g_triggers_debug) { + if (m != "") { + precache_model(m); + _setmodel(this, m); // no precision needed } setorigin(this, this.origin); - if(this.scale) + if (this.scale) { setsize(this, this.mins * this.scale, this.maxs * this.scale); - else + } else { setsize(this, this.mins, this.maxs); + } } - if(autocvar_g_triggers_debug) + if (autocvar_g_triggers_debug) { BITSET_ASSIGN(this.effects, EF_NODEPTHTEST); + } } void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendfunc) @@ -55,14 +55,15 @@ void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendf void trigger_common_write(entity this, bool withtarget) { int f = 0; - if(this.warpzone_isboxy) + if (this.warpzone_isboxy) { BITSET_ASSIGN(f, 1); - if(this.origin != '0 0 0') + } + if (this.origin != '0 0 0') { BITSET_ASSIGN(f, 4); + } WriteByte(MSG_ENTITY, f); - if(withtarget) - { + if (withtarget) { WriteString(MSG_ENTITY, this.target); WriteString(MSG_ENTITY, this.target2); WriteString(MSG_ENTITY, this.target3); @@ -71,8 +72,7 @@ void trigger_common_write(entity this, bool withtarget) WriteString(MSG_ENTITY, this.killtarget); } - if(f & 4) - { + if (f & 4) { WriteCoord(MSG_ENTITY, this.origin.x); WriteCoord(MSG_ENTITY, this.origin.y); WriteCoord(MSG_ENTITY, this.origin.z); @@ -103,30 +103,28 @@ void trigger_common_read(entity this, bool withtarget) int f = ReadByte(); this.warpzone_isboxy = (f & 1); - if(withtarget) - { - if(this.target) { strunzone(this.target); } + if (withtarget) { + if (this.target) { strunzone(this.target); } this.target = strzone(ReadString()); - if(this.target2) { strunzone(this.target2); } + if (this.target2) { strunzone(this.target2); } this.target2 = strzone(ReadString()); - if(this.target3) { strunzone(this.target3); } + if (this.target3) { strunzone(this.target3); } this.target3 = strzone(ReadString()); - if(this.target4) { strunzone(this.target4); } + if (this.target4) { strunzone(this.target4); } this.target4 = strzone(ReadString()); - if(this.targetname) { strunzone(this.targetname); } + if (this.targetname) { strunzone(this.targetname); } this.targetname = strzone(ReadString()); - if(this.killtarget) { strunzone(this.killtarget); } + if (this.killtarget) { strunzone(this.killtarget); } this.killtarget = strzone(ReadString()); } - if(f & 4) - { + if (f & 4) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); - } - else + } else { this.origin = '0 0 0'; + } setorigin(this, this.origin); this.modelindex = ReadShort(); @@ -150,22 +148,22 @@ void trigger_common_read(entity this, bool withtarget) void trigger_remove_generic(entity this) { - if(this.target) { strunzone(this.target); } + if (this.target) { strunzone(this.target); } this.target = string_null; - if(this.target2) { strunzone(this.target2); } + if (this.target2) { strunzone(this.target2); } this.target2 = string_null; - if(this.target3) { strunzone(this.target3); } + if (this.target3) { strunzone(this.target3); } this.target3 = string_null; - if(this.target4) { strunzone(this.target4); } + if (this.target4) { strunzone(this.target4); } this.target4 = string_null; - if(this.targetname) { strunzone(this.targetname); } + if (this.targetname) { strunzone(this.targetname); } this.target = string_null; - if(this.killtarget) { strunzone(this.killtarget); } + if (this.killtarget) { strunzone(this.killtarget); } this.killtarget = string_null; } #endif @@ -185,8 +183,8 @@ Centerprints any this.message to the activator. Removes all entities with a targetname that match this.killtarget, and removes them, so some events can remove other triggers. -Search for (string)targetname in all entities that -match (string)this.target and call their .use function +Search for (string) targetname in all entities that +match (string) this.target and call their .use function ============================== */ @@ -196,9 +194,8 @@ void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventRe // // check for a delay // - if (this.delay) - { - // create a temp object to fire at a later time + if (this.delay) { + // create a temp object to fire at a later time entity t = new(DelayedUse); t.nextthink = time + this.delay; setthink(t, DelayThink); @@ -219,23 +216,25 @@ void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventRe // print the message // #ifdef SVQC - if(this) - if(IS_PLAYER(actor) && this.message != "") - if(IS_REAL_CLIENT(actor)) - { - centerprint(actor, this.message); - if (this.noise == "") - play2(actor, SND(TALK)); + if (this) { + if (IS_PLAYER(actor) && this.message != "") { + if (IS_REAL_CLIENT(actor)) { + centerprint(actor, this.message); + if (this.noise == "") { + play2(actor, SND(TALK)); + } + } + } } // // kill the killtagets // s = this.killtarget; - if (s != "") - { - for(entity t = NULL; (t = find(t, targetname, s)); ) + if (s != "") { + for (entity t = NULL; (t = find(t, targetname, s)); ) { delete(t); + } } #endif @@ -243,51 +242,50 @@ void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventRe // fire targets // - if(this.target_random) + if (this.target_random) { RandomSelection_Init(); + } - for(int i = 0; i < 4; ++i) - { - switch(i) - { + for (int i = 0; i < 4; ++i) { + switch (i) { default: - case 0: s = this.target; break; - case 1: s = this.target2; break; - case 2: s = this.target3; break; - case 3: s = this.target4; break; + case 0: s = this.target; + break; + case 1: s = this.target2; + break; + case 2: s = this.target3; + break; + case 3: s = this.target4; + break; } - if (s != "") - { + if (s != "") { // Flag to set func_clientwall state // 1 == deactivate, 2 == activate, 0 == do nothing int aw_flag = this.antiwall_flag; - for(entity t = NULL; (t = find(t, targetname, s)); ) - { - if(t.use && (t.sub_target_used != time || !preventReuse)) - { - if(this.target_random) - { + for (entity t = NULL; (t = find(t, targetname, s)); ) { + if (t.use && (t.sub_target_used != time || !preventReuse)) { + if (this.target_random) { RandomSelection_AddEnt(t, 1, 0); - } - else - { - if (t.classname == "func_clientwall" || t.classname == "func_clientillusionary") + } else { + if (t.classname == "func_clientwall" || t.classname == "func_clientillusionary") { t.antiwall_flag = aw_flag; + } t.use(t, actor, this); - if(preventReuse) + if (preventReuse) { t.sub_target_used = time; + } } } } } } - if(this.target_random && RandomSelection_chosen_ent) - { + if (this.target_random && RandomSelection_chosen_ent) { RandomSelection_chosen_ent.use(RandomSelection_chosen_ent, actor, this); - if(preventReuse) + if (preventReuse) { RandomSelection_chosen_ent.sub_target_used = time; + } } } diff --git a/qcsrc/common/triggers/triggers.qh b/qcsrc/common/triggers/triggers.qh index 56ebb0c38..234bf9fc1 100644 --- a/qcsrc/common/triggers/triggers.qh +++ b/qcsrc/common/triggers/triggers.qh @@ -4,8 +4,8 @@ const float SF_TRIGGER_INIT = 1; const float SF_TRIGGER_UPDATE = 2; const float SF_TRIGGER_RESET = 4; -const float SPAWNFLAG_NOMESSAGE = 1; -const float SPAWNFLAG_NOTOUCH = 1; +const float SPAWNFLAG_NOMESSAGE = 1; +const float SPAWNFLAG_NOTOUCH = 1; .bool pushable; @@ -49,9 +49,9 @@ void trigger_remove_generic(entity this); .string target; .string targetname; -const int ACTIVE_NOT = 0; -const int ACTIVE_ACTIVE = 1; -const int ACTIVE_IDLE = 2; -const int ACTIVE_BUSY = 2; -const int ACTIVE_TOGGLE = 3; +const int ACTIVE_NOT = 0; +const int ACTIVE_ACTIVE = 1; +const int ACTIVE_IDLE = 2; +const int ACTIVE_BUSY = 2; +const int ACTIVE_TOGGLE = 3; #endif diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.qh index e63a931a6..aa234a8c6 100644 --- a/qcsrc/common/turrets/all.qh +++ b/qcsrc/common/turrets/all.qh @@ -14,55 +14,48 @@ REGISTRY_CHECK(Turrets) GENERIC_COMMAND(dumpturrets, "Dump all turrets into turrets_dump.txt") { - switch(request) - { - case CMD_REQUEST_COMMAND: - { - #ifdef SVQC - tur_config_file = -1; - tur_config_alsoprint = -1; - string filename = argv(1); + switch (request) { + case CMD_REQUEST_COMMAND: + { + #ifdef SVQC + tur_config_file = -1; + tur_config_alsoprint = -1; + string filename = argv(1); - if(filename == "") - { - filename = "turrets_dump.cfg"; - tur_config_alsoprint = false; - } - else if(filename == "-") - { - filename = "turrets_dump.cfg"; - tur_config_alsoprint = true; - } - tur_config_file = fopen(filename, FILE_WRITE); + if (filename == "") { + filename = "turrets_dump.cfg"; + tur_config_alsoprint = false; + } else if (filename == "-") { + filename = "turrets_dump.cfg"; + tur_config_alsoprint = true; + } + tur_config_file = fopen(filename, FILE_WRITE); - if(tur_config_file >= 0) - { - Dump_Turret_Settings(); - LOG_INFOF("Dumping turrets... File located in ^2data/data/%s^7.", filename); - fclose(tur_config_file); - tur_config_file = -1; - tur_config_alsoprint = -1; - } - else - { - LOG_INFOF("^1Error: ^7Could not open file '%s'!", filename); - } - #else - LOG_INFO(_("Turrets dump command only works with sv_cmd.")); - #endif - return; - } + if (tur_config_file >= 0) { + Dump_Turret_Settings(); + LOG_INFOF("Dumping turrets... File located in ^2data/data/%s^7.", filename); + fclose(tur_config_file); + tur_config_file = -1; + tur_config_alsoprint = -1; + } else { + LOG_INFOF("^1Error: ^7Could not open file '%s'!", filename); + } + #else + LOG_INFO(_("Turrets dump command only works with sv_cmd.")); + #endif + return; + } - default: - case CMD_REQUEST_USAGE: - { - LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " dumpturrets [filename]"); - LOG_INFO(" Where 'filename' is the file to write (default is turrets_dump.cfg),"); - LOG_INFO(" if supplied with '-' output to console as well as default,"); - LOG_INFO(" if left blank, it will only write to default."); - return; - } - } + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " dumpturrets [filename]"); + LOG_INFO(" Where 'filename' is the file to write (default is turrets_dump.cfg),"); + LOG_INFO(" if supplied with '-' output to console as well as default,"); + LOG_INFO(" if left blank, it will only write to default."); + return; + } + } } diff --git a/qcsrc/common/turrets/checkpoint.qc b/qcsrc/common/turrets/checkpoint.qc index f5ba71477..9083b6b2c 100644 --- a/qcsrc/common/turrets/checkpoint.qc +++ b/qcsrc/common/turrets/checkpoint.qc @@ -7,7 +7,7 @@ **/ -//.entity checkpoint_target; +// .entity checkpoint_target; /* #define checkpoint_cache_who flagcarried @@ -27,16 +27,16 @@ entity path_makeorcache(entity forwho,entity start, entity end) */ void turret_checkpoint_use() -{ -} +{} #if 0 void turret_checkpoint_think(entity this) { - if(this.enemy) - te_lightning1(this,this.origin, this.enemy.origin); + if (this.enemy) { + te_lightning1(this, this.origin, this.enemy.origin); + } - this.nextthink = time + 0.25; + this.nextthink = time + 0.25; } #endif /*QUAKED turret_checkpoint (1 0 1) (-32 -32 -32) (32 32 32) @@ -48,35 +48,35 @@ wait: Pause at this point # seconds. If a loop is of targets are formed, any unit entering this loop will patrol it indefinitly. If the checkpoint chain in not looped, the unit will go "Roaming" when the last point is reached. */ -//float tc_acum; +// float tc_acum; void turret_checkpoint_init(entity this) { - traceline(this.origin + '0 0 16', this.origin - '0 0 1024', MOVE_WORLDONLY, this); - setorigin(this, trace_endpos + '0 0 32'); + traceline(this.origin + '0 0 16', this.origin - '0 0 1024', MOVE_WORLDONLY, this); + setorigin(this, trace_endpos + '0 0 32'); - if(this.target != "") - { - this.enemy = find(NULL, targetname, this.target); - if(this.enemy == NULL) - LOG_TRACE("A turret_checkpoint faild to find its target!"); - } - //setthink(this, turret_checkpoint_think); - //this.nextthink = time + tc_acum + 0.25; - //tc_acum += 0.25; + if (this.target != "") { + this.enemy = find(NULL, targetname, this.target); + if (this.enemy == NULL) { + LOG_TRACE("A turret_checkpoint faild to find its target!"); + } + } + // setthink(this, turret_checkpoint_think); + // this.nextthink = time + tc_acum + 0.25; + // tc_acum += 0.25; } spawnfunc(turret_checkpoint) { - setorigin(this, this.origin); - setthink(this, turret_checkpoint_init); - this.nextthink = time + 0.2; + setorigin(this, this.origin); + setthink(this, turret_checkpoint_init); + this.nextthink = time + 0.2; } // Compat. spawnfunc(walker_checkpoint) { - this.classname = "turret_checkpoint"; - spawnfunc_turret_checkpoint(this); + this.classname = "turret_checkpoint"; + spawnfunc_turret_checkpoint(this); } #endif diff --git a/qcsrc/common/turrets/config.qc b/qcsrc/common/turrets/config.qc index effabeac2..e19e50659 100644 --- a/qcsrc/common/turrets/config.qc +++ b/qcsrc/common/turrets/config.qc @@ -16,13 +16,12 @@ float T_Config_Queue_Compare(float root, float child, entity pass) { float i, r, c; - for(i = 1; i <= 100; ++i) - { + for (i = 1; i <= 100; ++i) { r = str2chr(config_queue[root], i); c = str2chr(config_queue[child], i); - if(r == c) { continue; } - else if(c > r) { return -1; } - else { return 1; } + if (r == c) { continue; } else if (c > r) { + return -1; + } else { return 1; } } return 0; @@ -34,8 +33,9 @@ void Dump_Turret_Settings() FOREACH(Turrets, it != TUR_Null, { // step 1: clear the queue TUR_CONFIG_COUNT = 0; - for(int j = 0; j <= MAX_CONFIG_SETTINGS; ++j) + for (int j = 0; j <= MAX_CONFIG_SETTINGS; ++j) { config_queue[j] = string_null; + } // step 2: build new queue it.tr_config(it); @@ -45,19 +45,21 @@ void Dump_Turret_Settings() // step 4: write queue TUR_CONFIG_WRITETOFILE(sprintf("// {{{ #%d: %s\n", i, it.turret_name)) - for(int j = 0; j <= TUR_CONFIG_COUNT; ++j) + for (int j = 0; j <= TUR_CONFIG_COUNT; ++j) { TUR_CONFIG_WRITETOFILE(config_queue[j]) - TUR_CONFIG_WRITETOFILE("// }}}\n") + TUR_CONFIG_WRITETOFILE("// }}}\n") - // step 5: debug info - LOG_INFOF("#%d: %s: %d settings...", i, it.turret_name, TUR_CONFIG_COUNT); + // step 5: debug info + LOG_INFOF("#%d: %s: %d settings...", i, it.turret_name, TUR_CONFIG_COUNT); + } totalsettings += TUR_CONFIG_COUNT; }); // clear queue now that we're finished TUR_CONFIG_COUNT = 0; - for(int j = 0; j <= MAX_CONFIG_SETTINGS; ++j) + for (int j = 0; j <= MAX_CONFIG_SETTINGS; ++j) { config_queue[j] = string_null; + } // extra information LOG_INFOF("Totals: %d turrets, %d settings", (Turrets_COUNT - 1), totalsettings); diff --git a/qcsrc/common/turrets/config.qh b/qcsrc/common/turrets/config.qh index ac09e9e37..206aa8c31 100644 --- a/qcsrc/common/turrets/config.qh +++ b/qcsrc/common/turrets/config.qh @@ -7,9 +7,10 @@ float tur_config_file; float tur_config_alsoprint; float TUR_CONFIG_COUNT; -#define TUR_CONFIG_WRITETOFILE(a) { \ - fputs(tur_config_file, a); \ - if(tur_config_alsoprint) { LOG_INFO(a); } } +#define TUR_CONFIG_WRITETOFILE(a) \ + { \ + fputs(tur_config_file, a); \ + if (tur_config_alsoprint) { LOG_INFO(a); } } #endif diff --git a/qcsrc/common/turrets/sv_turrets.qh b/qcsrc/common/turrets/sv_turrets.qh index 41a7bd962..9fae21bca 100644 --- a/qcsrc/common/turrets/sv_turrets.qh +++ b/qcsrc/common/turrets/sv_turrets.qh @@ -9,26 +9,26 @@ bool turret_firecheck(entity this); entity turret_select_target(entity this); // turret fields -.float ticrate; // interal ai think rate -.entity tur_head; // top part of the turret -.entity tur_defend; // defend this entity -.vector tur_shotorg; // shot origin -.vector tur_aimpos; // aiming location -.float tur_impacttime; // predicted projectile impact time -.entity tur_impactent; // entity the projectile hit -.float tur_dist_enemy; // distance to enemy -.float tur_dist_aimpos; // distance to aim location +.float ticrate; // interal ai think rate +.entity tur_head; // top part of the turret +.entity tur_defend; // defend this entity +.vector tur_shotorg; // shot origin +.vector tur_aimpos; // aiming location +.float tur_impacttime; // predicted projectile impact time +.entity tur_impactent; // entity the projectile hit +.float tur_dist_enemy; // distance to enemy +.float tur_dist_aimpos; // distance to aim location .float tur_dist_impact_to_aimpos; // distance impact<->aim -.float volly_counter; // decrement counter from .shot_volly to 0 +.float volly_counter; // decrement counter from .shot_volly to 0 -.float shot_refire; // attack refire -.float shot_speed; // projectile speed -.float shot_spread; // inaccuracy -.float shot_dmg; // core damage of projectile -.float shot_radius; // projectile damage radius -.float shot_force; // projectile damage force -.float shot_volly; // smaller than 1 = shoot # times at target -.float shot_volly_refire; // refire after completed volly +.float shot_refire; // attack refire +.float shot_speed; // projectile speed +.float shot_spread; // inaccuracy +.float shot_dmg; // core damage of projectile +.float shot_radius; // projectile damage radius +.float shot_force; // projectile damage force +.float shot_volly; // smaller than 1 = shoot # times at target +.float shot_volly_refire; // refire after completed volly .float target_range; .float target_range_min; @@ -39,7 +39,7 @@ entity turret_select_target(entity this); .float target_select_anglebias; .float target_select_missilebias; .float target_select_playerbias; -.float target_select_time; // last time turret had a valid target +.float target_select_time; // last time turret had a valid target .float target_validate_time; // throttle re-validation of current target .float aim_firetolerance_dist; @@ -47,9 +47,9 @@ entity turret_select_target(entity this); .float aim_maxpitch; .float aim_maxrotate; -.float ammo; // current ammo +.float ammo; // current ammo .float ammo_recharge; // recharge rate -.float ammo_max; // maximum ammo +.float ammo_max; // maximum ammo .vector idle_aim; @@ -70,7 +70,7 @@ entity turret_select_target(entity this); // tracking type .float track_type; -const float TFL_TRACKTYPE_STEPMOTOR = 1; // hard angle increments, ugly for fast turning with best accuracy +const float TFL_TRACKTYPE_STEPMOTOR = 1; // hard angle increments, ugly for fast turning with best accuracy const float TFL_TRACKTYPE_FLUIDPRECISE = 2; // smooth absolute movement, looks OK with fair accuracy const float TFL_TRACKTYPE_FLUIDINERTIA = 3; // simulated inertia ("wobbly" mode), worst accuracy, depends on below flags .float track_accel_pitch; @@ -92,7 +92,7 @@ bool turret_initialize(entity this, Turret tur); /// Function to use for target evaluation. usualy turret_targetscore_generic .float(entity _turret, entity _target) turret_score_target; -.bool(entity this, entity e_target,entity e_sender) turret_addtarget; +.bool(entity this, entity e_target, entity e_sender) turret_addtarget; .entity pathcurrent; @@ -102,22 +102,22 @@ float turret_count; // debugging // Uncomment below to enable various debug output. -//#define TURRET_DEBUG -//#define TURRET_DEBUG_TARGETVALIDATE -//#define TURRET_DEBUG_TARGETSELECT +// #define TURRET_DEBUG +// #define TURRET_DEBUG_TARGETVALIDATE +// #define TURRET_DEBUG_TARGETSELECT #ifdef TURRET_DEBUG .float tur_debug_dmg_t_h; // total damage that hit something (can be more than tur_debug_dmg_t_f since it should count radius damage) .float tur_debug_dmg_t_f; // total damage -.float tur_debug_start; // turret initialization time -.float tur_debug_tmr1; // random timer -.float tur_debug_tmr2; // random timer -.float tur_debug_tmr3; // random timer -.vector tur_debug_rvec; // random vector +.float tur_debug_start; // turret initialization time +.float tur_debug_tmr1; // random timer +.float tur_debug_tmr2; // random timer +.float tur_debug_tmr3; // random timer +.vector tur_debug_rvec; // random vector #endif // aiming vector tvt_thadv; // turret head angle diff vector, updated by a successful call to turret_validate_target -vector tvt_tadv; // turret angle diff vector, updated by a successful call to turret_validate_target -float tvt_thadf; // turret head angle diff float, updated by a successful call to turret_validate_target -float tvt_tadf; // turret angle diff float, updated by a successful call to turret_validate_target -float tvt_dist; // turret distance, updated by a successful call to turret_validate_target +vector tvt_tadv; // turret angle diff vector, updated by a successful call to turret_validate_target +float tvt_thadf; // turret head angle diff float, updated by a successful call to turret_validate_target +float tvt_tadf; // turret angle diff float, updated by a successful call to turret_validate_target +float tvt_dist; // turret distance, updated by a successful call to turret_validate_target diff --git a/qcsrc/common/turrets/targettrigger.qc b/qcsrc/common/turrets/targettrigger.qc index d64616f50..c8887349e 100644 --- a/qcsrc/common/turrets/targettrigger.qc +++ b/qcsrc/common/turrets/targettrigger.qc @@ -7,25 +7,25 @@ void turret_targettrigger_touch(entity this, entity toucher); void turret_targettrigger_touch(entity this, entity toucher) { - if (this.cnt > time) return; - IL_EACH(g_turrets, it.targetname == this.target, - { - if (!(it.turret_flags & TUR_FLAG_RECIEVETARGETS)) continue; - if (!it.turret_addtarget) continue; - it.turret_addtarget(it, toucher, this); - }); - this.cnt = time + 0.5; + if (this.cnt > time) { return; } + IL_EACH(g_turrets, it.targetname == this.target, + { + if (!(it.turret_flags & TUR_FLAG_RECIEVETARGETS)) { continue; } + if (!it.turret_addtarget) { continue; } + it.turret_addtarget(it, toucher, this); + }); + this.cnt = time + 0.5; } /*QUAKED turret_targettrigger (.5 .5 .5) ? */ spawnfunc(turret_targettrigger) { - if(!autocvar_g_turrets) { delete(this); return; } + if (!autocvar_g_turrets) { delete(this); return; } - InitTrigger(this); + InitTrigger(this); - settouch(this, turret_targettrigger_touch); + settouch(this, turret_targettrigger_touch); } #endif diff --git a/qcsrc/common/turrets/turret/ewheel.qc b/qcsrc/common/turrets/turret/ewheel.qc index 5625d23fc..72c2f0f75 100644 --- a/qcsrc/common/turrets/turret/ewheel.qc +++ b/qcsrc/common/turrets/turret/ewheel.qc @@ -16,201 +16,191 @@ const int ewheel_anim_bck_fast = 4; void ewheel_move_path(entity this) { - // Are we close enough to a path node to switch to the next? - if(vdist(this.origin - this.pathcurrent.origin, <, 64)) - { + // Are we close enough to a path node to switch to the next? + if (vdist(this.origin - this.pathcurrent.origin, <, 64)) { #ifdef EWHEEL_FANCYPATH - if (this.pathcurrent.path_next == NULL) - { - // Path endpoint reached - pathlib_deletepath(this.pathcurrent.owner); - this.pathcurrent = NULL; - - if (this.pathgoal) - { - if (this.pathgoal.use) - this.pathgoal.use(this.pathgoal, NULL, NULL); - - if (this.pathgoal.enemy) - { - this.pathcurrent = pathlib_astar(this, this.pathgoal.origin,this.pathgoal.enemy.origin); - this.pathgoal = this.pathgoal.enemy; - } - } - else - this.pathgoal = NULL; - } - else - this.pathcurrent = this.pathcurrent.path_next; + if (this.pathcurrent.path_next == NULL) { + // Path endpoint reached + pathlib_deletepath(this.pathcurrent.owner); + this.pathcurrent = NULL; + + if (this.pathgoal) { + if (this.pathgoal.use) { + this.pathgoal.use(this.pathgoal, NULL, NULL); + } + + if (this.pathgoal.enemy) { + this.pathcurrent = pathlib_astar(this, this.pathgoal.origin, this.pathgoal.enemy.origin); + this.pathgoal = this.pathgoal.enemy; + } + } else { + this.pathgoal = NULL; + } + } else { + this.pathcurrent = this.pathcurrent.path_next; + } #else - this.pathcurrent = this.pathcurrent.enemy; + this.pathcurrent = this.pathcurrent.enemy; #endif - } + } - if (this.pathcurrent) - { + if (this.pathcurrent) { + this.moveto = this.pathcurrent.origin; + this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); - this.moveto = this.pathcurrent.origin; - this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); - - movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4); - } + movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4); + } } void ewheel_move_enemy(entity this) { - int newframe; - - this.steerto = steerlib_arrive(this, this.enemy.origin,this.target_range_optimal); - - this.moveto = this.origin + this.steerto * 128; - - if (this.tur_dist_enemy > this.target_range_optimal) - { - if ( this.tur_head.spawnshieldtime < 1 ) - { - newframe = ewheel_anim_fwd_fast; - movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4); - } - else if (this.tur_head.spawnshieldtime < 2) - { - - newframe = ewheel_anim_fwd_slow; - movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4); - } - else - { - newframe = ewheel_anim_fwd_slow; - movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slower), 0.4); - } - } - else if (this.tur_dist_enemy < this.target_range_optimal * 0.5) - { - newframe = ewheel_anim_bck_slow; - movelib_move_simple(this, v_forward * -1, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4); - } - else - { - newframe = ewheel_anim_stop; - movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop)); - } - - turrets_setframe(this, newframe, false); + int newframe; + + this.steerto = steerlib_arrive(this, this.enemy.origin, this.target_range_optimal); + + this.moveto = this.origin + this.steerto * 128; + + if (this.tur_dist_enemy > this.target_range_optimal) { + if (this.tur_head.spawnshieldtime < 1) { + newframe = ewheel_anim_fwd_fast; + movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4); + } else if (this.tur_head.spawnshieldtime < 2) { + newframe = ewheel_anim_fwd_slow; + movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4); + } else { + newframe = ewheel_anim_fwd_slow; + movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slower), 0.4); + } + } else if (this.tur_dist_enemy < this.target_range_optimal * 0.5) { + newframe = ewheel_anim_bck_slow; + movelib_move_simple(this, v_forward * -1, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4); + } else { + newframe = ewheel_anim_stop; + movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop)); + } + + turrets_setframe(this, newframe, false); } void ewheel_move_idle(entity this) { - if(this.frame != 0) - { - this.SendFlags |= TNSF_ANIM; - this.anim_start_time = time; - } - - this.frame = 0; - if(this.velocity) - movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop)); + if (this.frame != 0) { + this.SendFlags |= TNSF_ANIM; + this.anim_start_time = time; + } + + this.frame = 0; + if (this.velocity) { + movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop)); + } } void ewheel_findtarget(entity this) { - entity e = find(NULL, targetname, this.target); - if (!e) - { - LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!"); - this.target = ""; - } - - if (e.classname != "turret_checkpoint") - LOG_TRACE("Warning: not a turret path"); - else - { - + entity e = find(NULL, targetname, this.target); + if (!e) { + LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!"); + this.target = ""; + } + + if (e.classname != "turret_checkpoint") { + LOG_TRACE("Warning: not a turret path"); + } else { #ifdef EWHEEL_FANCYPATH - this.pathcurrent = pathlib_astar(this, this.origin, e.origin); - this.pathgoal = e; + this.pathcurrent = pathlib_astar(this, this.origin, e.origin); + this.pathgoal = e; #else - this.pathcurrent = e; + this.pathcurrent = e; #endif - } + } } -spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this); } +spawnfunc(turret_ewheel) +{ + if (!turret_initialize(this, TUR_EWHEEL)) { + delete(this); + } +} METHOD(EWheel, tr_think, void(EWheel thistur, entity it)) { - vector wish_angle, real_angle; + vector wish_angle, real_angle; - float vz = it.velocity_z; + float vz = it.velocity_z; - it.angles_x = anglemods(it.angles_x); - it.angles_y = anglemods(it.angles_y); + it.angles_x = anglemods(it.angles_x); + it.angles_y = anglemods(it.angles_y); - fixedmakevectors(it.angles); + fixedmakevectors(it.angles); - wish_angle = normalize(it.steerto); - wish_angle = vectoangles(wish_angle); - real_angle = wish_angle - it.angles; - real_angle = shortangle_vxy(real_angle, it.tur_head.angles); + wish_angle = normalize(it.steerto); + wish_angle = vectoangles(wish_angle); + real_angle = wish_angle - it.angles; + real_angle = shortangle_vxy(real_angle, it.tur_head.angles); - it.tur_head.spawnshieldtime = fabs(real_angle_y); - real_angle_y = bound(-it.tur_head.aim_speed, real_angle_y, it.tur_head.aim_speed); - it.angles_y = (it.angles_y + real_angle_y); + it.tur_head.spawnshieldtime = fabs(real_angle_y); + real_angle_y = bound(-it.tur_head.aim_speed, real_angle_y, it.tur_head.aim_speed); + it.angles_y = (it.angles_y + real_angle_y); - if(it.enemy) - ewheel_move_enemy(it); - else if(it.pathcurrent) - ewheel_move_path(it); - else - ewheel_move_idle(it); + if (it.enemy) { + ewheel_move_enemy(it); + } else if (it.pathcurrent) { + ewheel_move_path(it); + } else { + ewheel_move_idle(it); + } - it.velocity_z = vz; + it.velocity_z = vz; - if(it.velocity) - it.SendFlags |= TNSF_MOVE; + if (it.velocity) { + it.SendFlags |= TNSF_MOVE; + } } METHOD(EWheel, tr_death, void(EWheel this, entity it)) { - it.velocity = '0 0 0'; + it.velocity = '0 0 0'; #ifdef EWHEEL_FANCYPATH - if (it.pathcurrent) - pathlib_deletepath(it.pathcurrent.owner); + if (it.pathcurrent) { + pathlib_deletepath(it.pathcurrent.owner); + } #endif - it.pathcurrent = NULL; + it.pathcurrent = NULL; } METHOD(EWheel, tr_setup, void(EWheel this, entity it)) { - if(it.move_movetype == MOVETYPE_WALK) - { - it.velocity = '0 0 0'; - it.enemy = NULL; - - setorigin(it, it.pos1); - - if (it.target != "") - InitializeEntity(it, ewheel_findtarget, INITPRIO_FINDTARGET); - } - - it.iscreature = true; - it.teleportable = TELEPORT_NORMAL; - if(!it.damagedbycontents) - IL_PUSH(g_damagedbycontents, it); - it.damagedbycontents = true; - set_movetype(it, MOVETYPE_WALK); - it.solid = SOLID_SLIDEBOX; - it.takedamage = DAMAGE_AIM; - it.idle_aim = '0 0 0'; - it.pos1 = it.origin; - it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; - it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; - it.frame = it.tur_head.frame = 1; - it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; - - // Convert from dgr / sec to dgr / tic - it.tur_head.aim_speed = (autocvar_g_turrets_unit_ewheel_turnrate); - it.tur_head.aim_speed = it.tur_head.aim_speed / (1 / it.ticrate); + if (it.move_movetype == MOVETYPE_WALK) { + it.velocity = '0 0 0'; + it.enemy = NULL; + + setorigin(it, it.pos1); + + if (it.target != "") { + InitializeEntity(it, ewheel_findtarget, INITPRIO_FINDTARGET); + } + } + + it.iscreature = true; + it.teleportable = TELEPORT_NORMAL; + if (!it.damagedbycontents) { + IL_PUSH(g_damagedbycontents, it); + } + it.damagedbycontents = true; + set_movetype(it, MOVETYPE_WALK); + it.solid = SOLID_SLIDEBOX; + it.takedamage = DAMAGE_AIM; + it.idle_aim = '0 0 0'; + it.pos1 = it.origin; + it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; + it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; + it.frame = it.tur_head.frame = 1; + it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; + + // Convert from dgr / sec to dgr / tic + it.tur_head.aim_speed = (autocvar_g_turrets_unit_ewheel_turnrate); + it.tur_head.aim_speed = it.tur_head.aim_speed / (1 / it.ticrate); } #endif // SVQC @@ -218,28 +208,31 @@ METHOD(EWheel, tr_setup, void(EWheel this, entity it)) void ewheel_draw(entity this) { - float dt; - - dt = time - this.move_time; - this.move_time = time; - if(dt <= 0) - return; - - fixedmakevectors(this.angles); - setorigin(this, this.origin + this.velocity * dt); - this.tur_head.angles += dt * this.tur_head.avelocity; - - if (this.health < 127) - if(random() < 0.05) - te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); + float dt; + + dt = time - this.move_time; + this.move_time = time; + if (dt <= 0) { + return; + } + + fixedmakevectors(this.angles); + setorigin(this, this.origin + this.velocity * dt); + this.tur_head.angles += dt * this.tur_head.avelocity; + + if (this.health < 127) { + if (random() < 0.05) { + te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); + } + } } - METHOD(EWheel, tr_setup, void(EWheel this, entity it)) - { - it.gravity = 1; - set_movetype(it, MOVETYPE_BOUNCE); - it.move_time = time; - it.draw = ewheel_draw; - } +METHOD(EWheel, tr_setup, void(EWheel this, entity it)) +{ + it.gravity = 1; + set_movetype(it, MOVETYPE_BOUNCE); + it.move_time = time; + it.draw = ewheel_draw; +} #endif // CSQC diff --git a/qcsrc/common/turrets/turret/ewheel.qh b/qcsrc/common/turrets/turret/ewheel.qh index ed1a5a630..af5a3a718 100644 --- a/qcsrc/common/turrets/turret/ewheel.qh +++ b/qcsrc/common/turrets/turret/ewheel.qh @@ -1,6 +1,6 @@ #pragma once -//#define EWHEEL_FANCYPATH +// #define EWHEEL_FANCYPATH #include "ewheel_weapon.qh" @@ -13,6 +13,6 @@ CLASS(EWheel, Turret) /* head_model */ ATTRIB_STRZONE(EWheel, head_model, string, strcat("models/turrets/", "ewheel-gun1.md3")); /* netname */ ATTRIB(EWheel, netname, string, "ewheel"); /* fullname */ ATTRIB(EWheel, turret_name, string, _("eWheel Turret")); - ATTRIB(EWheel, m_weapon, Weapon, WEP_EWHEEL); + ATTRIB(EWheel, m_weapon, Weapon, WEP_EWHEEL); ENDCLASS(EWheel) REGISTER_TURRET(EWHEEL, NEW(EWheel)); diff --git a/qcsrc/common/turrets/turret/ewheel_weapon.qc b/qcsrc/common/turrets/turret/ewheel_weapon.qc index fc22c3086..df73c271f 100644 --- a/qcsrc/common/turrets/turret/ewheel_weapon.qc +++ b/qcsrc/common/turrets/turret/ewheel_weapon.qc @@ -4,33 +4,36 @@ void turret_initparams(entity); SOUND(EWheelAttack_FIRE, W_Sound("electro_fire")); -METHOD(EWheelAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_EWheelAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - - turret_do_updates(actor); - - entity missile = turret_projectile(actor, SND_LASERGUN_FIRE, 1, 0, DEATH_TURRET_EWHEEL.m_id, PROJECTILE_BLASTER, true, true); - missile.missile_flags = MIF_SPLASH; - - Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); - - if (!isPlayer) { - actor.tur_head.frame += 2; - - if (actor.tur_head.frame > 3) - actor.tur_head.frame = 0; - } - } +METHOD(EWheelAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_EWheelAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } + + turret_do_updates(actor); + + entity missile = turret_projectile(actor, SND_LASERGUN_FIRE, 1, 0, DEATH_TURRET_EWHEEL.m_id, PROJECTILE_BLASTER, true, true); + missile.missile_flags = MIF_SPLASH; + + Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); + + if (!isPlayer) { + actor.tur_head.frame += 2; + + if (actor.tur_head.frame > 3) { + actor.tur_head.frame = 0; + } + } + } + } } #endif diff --git a/qcsrc/common/turrets/turret/flac.qc b/qcsrc/common/turrets/turret/flac.qc index 6a81bc2c9..40fbfdbe3 100644 --- a/qcsrc/common/turrets/turret/flac.qc +++ b/qcsrc/common/turrets/turret/flac.qc @@ -2,14 +2,19 @@ #ifdef SVQC -spawnfunc(turret_flac) { if (!turret_initialize(this, TUR_FLAC)) delete(this); } +spawnfunc(turret_flac) +{ + if (!turret_initialize(this, TUR_FLAC)) { + delete(this); + } +} METHOD(Flac, tr_setup, void(Flac this, entity it)) { - it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; - it.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; - it.damage_flags |= TFL_DMG_HEADSHAKE; - it.target_select_flags |= TFL_TARGETSELECT_NOTURRETS | TFL_TARGETSELECT_MISSILESONLY; + it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; + it.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; + it.damage_flags |= TFL_DMG_HEADSHAKE; + it.target_select_flags |= TFL_TARGETSELECT_NOTURRETS | TFL_TARGETSELECT_MISSILESONLY; } #endif diff --git a/qcsrc/common/turrets/turret/flac.qh b/qcsrc/common/turrets/turret/flac.qh index 216dcd71f..34a7997d6 100644 --- a/qcsrc/common/turrets/turret/flac.qh +++ b/qcsrc/common/turrets/turret/flac.qh @@ -11,6 +11,6 @@ CLASS(Flac, Turret) /* head_model */ ATTRIB_STRZONE(Flac, head_model, string, strcat("models/turrets/", "flac.md3")); /* netname */ ATTRIB(Flac, netname, string, "flac"); /* fullname */ ATTRIB(Flac, turret_name, string, _("FLAC Cannon")); - ATTRIB(Flac, m_weapon, Weapon, WEP_FLAC); + ATTRIB(Flac, m_weapon, Weapon, WEP_FLAC); ENDCLASS(Flac) REGISTER_TURRET(FLAC, NEW(Flac)); diff --git a/qcsrc/common/turrets/turret/flac_weapon.qc b/qcsrc/common/turrets/turret/flac_weapon.qc index 10d53aa08..9021b3e2f 100644 --- a/qcsrc/common/turrets/turret/flac_weapon.qc +++ b/qcsrc/common/turrets/turret/flac_weapon.qc @@ -4,50 +4,55 @@ void turret_flac_projectile_think_explode(entity this); SOUND(FlacAttack_FIRE, W_Sound("electro_fire")); -METHOD(FlacAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_FlacAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - actor.tur_impacttime = 10; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - - turret_tag_fire_update(actor); - - entity proj = turret_projectile(actor, SND_HAGAR_FIRE, 5, 0, DEATH_TURRET_FLAC.m_id, PROJECTILE_HAGAR, true, true); - proj.missile_flags = MIF_SPLASH | MIF_PROXY; - setthink(proj, turret_flac_projectile_think_explode); - proj.nextthink = time + actor.tur_impacttime + (random() * 0.01 - random() * 0.01); - Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); - - if (!isPlayer) { - actor.tur_head.frame = actor.tur_head.frame + 1; - if (actor.tur_head.frame >= 4) - actor.tur_head.frame = 0; - } - } +METHOD(FlacAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_FlacAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + actor.tur_impacttime = 10; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } + + turret_tag_fire_update(actor); + + entity proj = turret_projectile(actor, SND_HAGAR_FIRE, 5, 0, DEATH_TURRET_FLAC.m_id, PROJECTILE_HAGAR, true, true); + proj.missile_flags = MIF_SPLASH | MIF_PROXY; + setthink(proj, turret_flac_projectile_think_explode); + proj.nextthink = time + actor.tur_impacttime + (random() * 0.01 - random() * 0.01); + Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); + + if (!isPlayer) { + actor.tur_head.frame = actor.tur_head.frame + 1; + if (actor.tur_head.frame >= 4) { + actor.tur_head.frame = 0; + } + } + } + } } void turret_flac_projectile_think_explode(entity this) { - if(this.enemy != NULL) - if(vdist(this.origin - this.enemy.origin, <, this.owner.shot_radius * 3)) - setorigin(this, this.enemy.origin + randomvec() * this.owner.shot_radius); + if (this.enemy != NULL) { + if (vdist(this.origin - this.enemy.origin, <, this.owner.shot_radius * 3)) { + setorigin(this, this.enemy.origin + randomvec() * this.owner.shot_radius); + } + } #ifdef TURRET_DEBUG - float d = RadiusDamage (this, this.owner, this.owner.shot_dmg, this.owner.shot_dmg, this.owner.shot_radius, this, NULL, this.owner.shot_force, this.totalfrags, NULL); - this.owner.tur_dbg_dmg_t_h = this.owner.tur_dbg_dmg_t_h + d; - this.owner.tur_dbg_dmg_t_f = this.owner.tur_dbg_dmg_t_f + this.owner.shot_dmg; + float d = RadiusDamage(this, this.owner, this.owner.shot_dmg, this.owner.shot_dmg, this.owner.shot_radius, this, NULL, this.owner.shot_force, this.totalfrags, NULL); + this.owner.tur_dbg_dmg_t_h = this.owner.tur_dbg_dmg_t_h + d; + this.owner.tur_dbg_dmg_t_f = this.owner.tur_dbg_dmg_t_f + this.owner.shot_dmg; #else - RadiusDamage (this, this.realowner, this.owner.shot_dmg, this.owner.shot_dmg, this.owner.shot_radius, this, NULL, this.owner.shot_force, this.totalfrags, NULL); + RadiusDamage(this, this.realowner, this.owner.shot_dmg, this.owner.shot_dmg, this.owner.shot_radius, this, NULL, this.owner.shot_force, this.totalfrags, NULL); #endif - delete(this); + delete(this); } #endif diff --git a/qcsrc/common/turrets/turret/fusionreactor.qc b/qcsrc/common/turrets/turret/fusionreactor.qc index 32ac81d58..a30c62ecb 100644 --- a/qcsrc/common/turrets/turret/fusionreactor.qc +++ b/qcsrc/common/turrets/turret/fusionreactor.qc @@ -3,52 +3,60 @@ #ifdef SVQC bool turret_fusionreactor_firecheck(entity this) { - entity targ = this.enemy; - - switch(MUTATOR_CALLHOOK(FusionReactor_ValidTarget, this, targ)) - { - case MUT_FUSREAC_TARG_VALID: { return true; } - case MUT_FUSREAC_TARG_INVALID: { return false; } - } - - if((this.attack_finished_single[0] > time) - || (!targ) - || (IS_DEAD(targ)) - || (this.ammo < this.shot_dmg) - || (targ.ammo >= targ.ammo_max) - || (vdist(targ.origin - this.origin, >, this.target_range)) - || (this.team != targ.team) - || (!(targ.ammo_flags & TFL_AMMO_ENERGY)) - ) { return false; } - - return true; + entity targ = this.enemy; + + switch (MUTATOR_CALLHOOK(FusionReactor_ValidTarget, this, targ)) { + case MUT_FUSREAC_TARG_VALID: + { return true; + } + case MUT_FUSREAC_TARG_INVALID: + { return false; + } + } + + if ((this.attack_finished_single[0] > time) + || (!targ) + || (IS_DEAD(targ)) + || (this.ammo < this.shot_dmg) + || (targ.ammo >= targ.ammo_max) + || (vdist(targ.origin - this.origin, >, this.target_range)) + || (this.team != targ.team) + || (!(targ.ammo_flags & TFL_AMMO_ENERGY)) + ) { return false; } + + return true; } -spawnfunc(turret_fusionreactor) { if (!turret_initialize(this, TUR_FUSIONREACTOR)) delete(this); } +spawnfunc(turret_fusionreactor) +{ + if (!turret_initialize(this, TUR_FUSIONREACTOR)) { + delete(this); + } +} METHOD(FusionReactor, tr_attack, void(FusionReactor this, entity it)) { - it.enemy.ammo = min(it.enemy.ammo + it.shot_dmg,it.enemy.ammo_max); - vector fl_org = 0.5 * (it.enemy.absmin + it.enemy.absmax); - te_smallflash(fl_org); + it.enemy.ammo = min(it.enemy.ammo + it.shot_dmg, it.enemy.ammo_max); + vector fl_org = 0.5 * (it.enemy.absmin + it.enemy.absmax); + te_smallflash(fl_org); } METHOD(FusionReactor, tr_think, void(FusionReactor thistur, entity it)) { - it.tur_head.avelocity = '0 250 0' * (it.ammo / it.ammo_max); + it.tur_head.avelocity = '0 250 0' * (it.ammo / it.ammo_max); } METHOD(FusionReactor, tr_setup, void(FusionReactor this, entity it)) { - it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE; - it.target_select_flags = TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_OWNTEAM | TFL_TARGETSELECT_RANGELIMITS; - it.firecheck_flags = TFL_FIRECHECK_AMMO_OWN | TFL_FIRECHECK_AMMO_OTHER | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_DEAD; - it.shoot_flags = TFL_SHOOT_HITALLVALID; - it.aim_flags = TFL_AIM_NO; - it.track_flags = TFL_TRACK_NO; + it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE; + it.target_select_flags = TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_OWNTEAM | TFL_TARGETSELECT_RANGELIMITS; + it.firecheck_flags = TFL_FIRECHECK_AMMO_OWN | TFL_FIRECHECK_AMMO_OTHER | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_DEAD; + it.shoot_flags = TFL_SHOOT_HITALLVALID; + it.aim_flags = TFL_AIM_NO; + it.track_flags = TFL_TRACK_NO; - it.tur_head.scale = 0.75; - it.tur_head.avelocity = '0 50 0'; + it.tur_head.scale = 0.75; + it.tur_head.avelocity = '0 50 0'; - it.turret_firecheckfunc = turret_fusionreactor_firecheck; + it.turret_firecheckfunc = turret_fusionreactor_firecheck; } #endif diff --git a/qcsrc/common/turrets/turret/hellion.qc b/qcsrc/common/turrets/turret/hellion.qc index 15dc36b3d..5da28639a 100644 --- a/qcsrc/common/turrets/turret/hellion.qc +++ b/qcsrc/common/turrets/turret/hellion.qc @@ -2,22 +2,29 @@ #ifdef SVQC -spawnfunc(turret_hellion) { if (!turret_initialize(this, TUR_HELLION)) delete(this); } +spawnfunc(turret_hellion) +{ + if (!turret_initialize(this, TUR_HELLION)) { + delete(this); + } +} METHOD(Hellion, tr_think, void(Hellion thistur, entity it)) { - if (it.tur_head.frame != 0) - it.tur_head.frame += 1; + if (it.tur_head.frame != 0) { + it.tur_head.frame += 1; + } - if (it.tur_head.frame >= 7) - it.tur_head.frame = 0; + if (it.tur_head.frame >= 7) { + it.tur_head.frame = 0; + } } METHOD(Hellion, tr_setup, void(Hellion this, entity it)) { - it.aim_flags = TFL_AIM_SIMPLE; - it.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK ; - it.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF | TFL_FIRECHECK_AMMO_OWN; - it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; + it.aim_flags = TFL_AIM_SIMPLE; + it.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; + it.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF | TFL_FIRECHECK_AMMO_OWN; + it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; } #endif diff --git a/qcsrc/common/turrets/turret/hellion.qh b/qcsrc/common/turrets/turret/hellion.qh index 216b4c7ec..bb3202f3a 100644 --- a/qcsrc/common/turrets/turret/hellion.qh +++ b/qcsrc/common/turrets/turret/hellion.qh @@ -11,6 +11,6 @@ CLASS(Hellion, Turret) /* head_model */ ATTRIB_STRZONE(Hellion, head_model, string, strcat("models/turrets/", "hellion.md3")); /* netname */ ATTRIB(Hellion, netname, string, "hellion"); /* fullname */ ATTRIB(Hellion, turret_name, string, _("Hellion Missile Turret")); - ATTRIB(Hellion, m_weapon, Weapon, WEP_HELLION); + ATTRIB(Hellion, m_weapon, Weapon, WEP_HELLION); ENDCLASS(Hellion) REGISTER_TURRET(HELLION, NEW(Hellion)); diff --git a/qcsrc/common/turrets/turret/hellion_weapon.qc b/qcsrc/common/turrets/turret/hellion_weapon.qc index a1065dec1..84b905e06 100644 --- a/qcsrc/common/turrets/turret/hellion_weapon.qc +++ b/qcsrc/common/turrets/turret/hellion_weapon.qc @@ -7,97 +7,102 @@ float autocvar_g_turrets_unit_hellion_shot_speed_max; void turret_hellion_missile_think(entity this); SOUND(HellionAttack_FIRE, W_Sound("electro_fire")); -METHOD(HellionAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_HellionAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - actor.shot_radius = 500; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - if (!isPlayer) { - if (actor.tur_head.frame != 0) - actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire")); - else - actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire2")); - } - - entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_HELLION.m_id, PROJECTILE_ROCKET, false, false); - te_explosion (missile.origin); - setthink(missile, turret_hellion_missile_think); - missile.nextthink = time; - missile.max_health = time + 9; - missile.tur_aimpos = randomvec() * 128; - missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT; - if (!isPlayer) actor.tur_head.frame += 1; - } +METHOD(HellionAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_HellionAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + actor.shot_radius = 500; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } + if (!isPlayer) { + if (actor.tur_head.frame != 0) { + actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire")); + } else { + actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire2")); + } + } + + entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_HELLION.m_id, PROJECTILE_ROCKET, false, false); + te_explosion(missile.origin); + setthink(missile, turret_hellion_missile_think); + missile.nextthink = time; + missile.max_health = time + 9; + missile.tur_aimpos = randomvec() * 128; + missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT; + if (!isPlayer) { actor.tur_head.frame += 1; } + } + } } void turret_hellion_missile_think(entity this) { - vector olddir,newdir; - vector pre_pos; - float itime; - - this.nextthink = time + 0.05; + vector olddir, newdir; + vector pre_pos; + float itime; - olddir = normalize(this.velocity); + this.nextthink = time + 0.05; - if(this.max_health < time) - turret_projectile_explode(this); + olddir = normalize(this.velocity); - // Enemy dead? just keep on the current heading then. - if ((this.enemy == NULL) || (IS_DEAD(this.enemy))) - { + if (this.max_health < time) { + turret_projectile_explode(this); + } - // Make sure we dont return to tracking a respawned player - this.enemy = NULL; + // Enemy dead? just keep on the current heading then. + if ((this.enemy == NULL) || (IS_DEAD(this.enemy))) { + // Make sure we dont return to tracking a respawned player + this.enemy = NULL; - // Turn model - this.angles = vectoangles(this.velocity); + // Turn model + this.angles = vectoangles(this.velocity); - if(vdist(this.origin - this.owner.origin, >, (this.owner.shot_radius * 5))) - turret_projectile_explode(this); + if (vdist(this.origin - this.owner.origin, >, (this.owner.shot_radius * 5))) { + turret_projectile_explode(this); + } - // Accelerate - this.velocity = olddir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max)); + // Accelerate + this.velocity = olddir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max)); - UpdateCSQCProjectile(this); + UpdateCSQCProjectile(this); - return; - } + return; + } - // Enemy in range? - if(vdist(this.origin - this.enemy.origin, <, this.owner.shot_radius * 0.2)) - turret_projectile_explode(this); + // Enemy in range? + if (vdist(this.origin - this.enemy.origin, <, this.owner.shot_radius * 0.2)) { + turret_projectile_explode(this); + } - // Predict enemy position - itime = vlen(this.enemy.origin - this.origin) / vlen(this.velocity); - pre_pos = this.enemy.origin + this.enemy.velocity * itime; + // Predict enemy position + itime = vlen(this.enemy.origin - this.origin) / vlen(this.velocity); + pre_pos = this.enemy.origin + this.enemy.velocity * itime; - pre_pos = (pre_pos + this.enemy.origin) * 0.5; + pre_pos = (pre_pos + this.enemy.origin) * 0.5; - // Find out the direction to that place - newdir = normalize(pre_pos - this.origin); + // Find out the direction to that place + newdir = normalize(pre_pos - this.origin); - // Turn - newdir = normalize(olddir + newdir * 0.35); + // Turn + newdir = normalize(olddir + newdir * 0.35); - // Turn model - this.angles = vectoangles(this.velocity); + // Turn model + this.angles = vectoangles(this.velocity); - // Accelerate - this.velocity = newdir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max)); + // Accelerate + this.velocity = newdir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max)); - if (itime < 0.05) - setthink(this, turret_projectile_explode); + if (itime < 0.05) { + setthink(this, turret_projectile_explode); + } - UpdateCSQCProjectile(this); + UpdateCSQCProjectile(this); } #endif diff --git a/qcsrc/common/turrets/turret/hk.qc b/qcsrc/common/turrets/turret/hk.qc index 811e386f5..961fe266f 100644 --- a/qcsrc/common/turrets/turret/hk.qc +++ b/qcsrc/common/turrets/turret/hk.qc @@ -6,42 +6,47 @@ .float atime; #endif -spawnfunc(turret_hk) { if(!turret_initialize(this, TUR_HK)) delete(this); } +spawnfunc(turret_hk) +{ + if (!turret_initialize(this, TUR_HK)) { + delete(this); + } +} METHOD(HunterKiller, tr_think, void(HunterKiller thistur, entity it)) { - if (it.tur_head.frame != 0) - it.tur_head.frame = it.tur_head.frame + 1; + if (it.tur_head.frame != 0) { + it.tur_head.frame = it.tur_head.frame + 1; + } - if (it.tur_head.frame > 5) - it.tur_head.frame = 0; + if (it.tur_head.frame > 5) { + it.tur_head.frame = 0; + } } -bool turret_hk_addtarget(entity this, entity e_target,entity e_sender); +bool turret_hk_addtarget(entity this, entity e_target, entity e_sender); METHOD(HunterKiller, tr_setup, void(HunterKiller this, entity it)) { - it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; - it.aim_flags = TFL_AIM_SIMPLE; - it.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; - it.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF; - it.shoot_flags = TFL_SHOOT_CLEARTARGET; - it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK; - - it.turret_addtarget = turret_hk_addtarget; + it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; + it.aim_flags = TFL_AIM_SIMPLE; + it.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; + it.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF; + it.shoot_flags = TFL_SHOOT_CLEARTARGET; + it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TEAMCHECK; + + it.turret_addtarget = turret_hk_addtarget; } -bool turret_hk_addtarget(entity this, entity e_target,entity e_sender) +bool turret_hk_addtarget(entity this, entity e_target, entity e_sender) { - if (e_target) - { - if (turret_validate_target(this,e_target,this.target_validate_flags) > 0) - { - this.enemy = e_target; - return true; - } - } - - return false; + if (e_target) { + if (turret_validate_target(this, e_target, this.target_validate_flags) > 0) { + this.enemy = e_target; + return true; + } + } + + return false; } #endif // SVQC diff --git a/qcsrc/common/turrets/turret/hk.qh b/qcsrc/common/turrets/turret/hk.qh index 639924fc4..c8e483607 100644 --- a/qcsrc/common/turrets/turret/hk.qh +++ b/qcsrc/common/turrets/turret/hk.qh @@ -1,6 +1,6 @@ #pragma once -//#define TURRET_DEBUG_HK +// #define TURRET_DEBUG_HK #include "hk_weapon.qh" @@ -13,6 +13,6 @@ CLASS(HunterKiller, Turret) /* head_model */ ATTRIB_STRZONE(HunterKiller, head_model, string, strcat("models/turrets/", "hk.md3")); /* netname */ ATTRIB(HunterKiller, netname, string, "hk"); /* fullname */ ATTRIB(HunterKiller, turret_name, string, _("Hunter-Killer Turret")); - ATTRIB(HunterKiller, m_weapon, Weapon, WEP_HK); + ATTRIB(HunterKiller, m_weapon, Weapon, WEP_HK); ENDCLASS(HunterKiller) REGISTER_TURRET(HK, NEW(HunterKiller)); diff --git a/qcsrc/common/turrets/turret/hk_weapon.qc b/qcsrc/common/turrets/turret/hk_weapon.qc index 9a243adaa..7aefd9120 100644 --- a/qcsrc/common/turrets/turret/hk_weapon.qc +++ b/qcsrc/common/turrets/turret/hk_weapon.qc @@ -14,265 +14,267 @@ SOUND(HunterKillerAttack_FIRE, W_Sound("electro_fire")); METHOD(HunterKillerAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_HunterKillerAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_HK.m_id, PROJECTILE_ROCKET, false, false); - te_explosion (missile.origin); - - setthink(missile, turret_hk_missile_think); - missile.nextthink = time + 0.25; - set_movetype(missile, MOVETYPE_BOUNCEMISSILE); - missile.velocity = actor.tur_shotdir_updated * (actor.shot_speed * 0.75); - missile.angles = vectoangles(missile.velocity); - missile.cnt = time + 30; - missile.ticrate = max(autocvar_sys_ticrate, 0.05); - missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI; - - if (!isPlayer) - if (actor.tur_head.frame == 0) - actor.tur_head.frame = actor.tur_head.frame + 1; + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_HunterKillerAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } + entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_HK.m_id, PROJECTILE_ROCKET, false, false); + te_explosion(missile.origin); + + setthink(missile, turret_hk_missile_think); + missile.nextthink = time + 0.25; + set_movetype(missile, MOVETYPE_BOUNCEMISSILE); + missile.velocity = actor.tur_shotdir_updated * (actor.shot_speed * 0.75); + missile.angles = vectoangles(missile.velocity); + missile.cnt = time + 30; + missile.ticrate = max(autocvar_sys_ticrate, 0.05); + missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_AI; + + if (!isPlayer) { + if (actor.tur_head.frame == 0) { + actor.tur_head.frame = actor.tur_head.frame + 1; + } + } + } } } bool hk_is_valid_target(entity this, entity proj, entity targ); void turret_hk_missile_think(entity this) { - vector vu, vd, vf, vl, vr, ve; // Vector (direction) - float fu, fd, ff, fl, fr, fe; // Fraction to solid - vector olddir,wishdir,newdir; // Final direction - float lt_for; // Length of Trace FORwrad - float lt_seek; // Length of Trace SEEK (left, right, up down) - float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward) - float myspeed; - - this.nextthink = time + this.ticrate; - - //if (this.cnt < time) - // turret_hk_missile_explode(); - - if (IS_DEAD(this.enemy)) - this.enemy = NULL; - - // Pick the closest valid target. - if (!this.enemy) - { - // in this case, the lighter check is to validate it first, and check distance if it is valid - IL_EACH(g_damagedbycontents, hk_is_valid_target(this.owner, this, it), - { - if(vdist(it.origin, >, 5000)) - continue; - - if(!this.enemy) - this.enemy = it; - else if(vlen2(this.origin - it.origin) < vlen2(this.origin - this.enemy.origin)) - this.enemy = it; - }); - } - - this.angles = vectoangles(this.velocity); - this.angles_x = this.angles_x * -1; - makevectors(this.angles); - this.angles_x = this.angles_x * -1; - - if (this.enemy) - { - // Close enougth to do decent damage? - if(vdist(this.origin - this.enemy.origin, <=, (this.owner.shot_radius * 0.25))) - { - turret_projectile_explode(this); - return; - } - - // Get data on enemy position - vector pre_pos = this.enemy.origin + - this.enemy.velocity * - min((vlen(this.enemy.origin - this.origin) / vlen(this.velocity)),0.5); - - traceline(this.origin, pre_pos,true,this.enemy); - ve = normalize(pre_pos - this.origin); - fe = trace_fraction; - - } - else - { - ve = '0 0 0'; - fe = 0; - } - - if ((fe != 1) || (this.enemy == NULL) || vdist(this.origin - this.enemy.origin, >, 1000)) - { - myspeed = vlen(this.velocity); - - lt_for = myspeed * 3; - lt_seek = myspeed * 2.95; - - // Trace forward - traceline(this.origin, this.origin + v_forward * lt_for,false,this); - vf = trace_endpos; - ff = trace_fraction; - - // Find angular offset - float ad = vlen(vectoangles(normalize(this.enemy.origin - this.origin)) - this.angles); - - // To close to something, Slow down! - if ( ((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) ) - myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed)); - - // Failry clear, accelerate. - if ( (ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) ) - myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max)); - - // Setup trace pitch - pt_seek = 1 - ff; - pt_seek = bound(0.15,pt_seek,0.8); - if (ff < 0.5) pt_seek = 1; - - // Trace left - traceline(this.origin, this.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek,false,this); - vl = trace_endpos; - fl = trace_fraction; - - // Trace right - traceline(this.origin, this.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek ,false,this); - vr = trace_endpos; - fr = trace_fraction; - - // Trace up - traceline(this.origin, this.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this); - vu = trace_endpos; - fu = trace_fraction; - - // Trace down - traceline(this.origin, this.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek ,false,this); - vd = trace_endpos; - fd = trace_fraction; - - vl = normalize(vl - this.origin); - vr = normalize(vr - this.origin); - vu = normalize(vu - this.origin); - vd = normalize(vd - this.origin); - - // Panic tresh passed, find a single direction and turn as hard as we can - if (pt_seek == 1) - { - wishdir = v_right; - if (fl > fr) wishdir = -1 * v_right; - if (fu > fl) wishdir = v_up; - if (fd > fu) wishdir = -1 * v_up; - } - else - { - // Normalize our trace vectors to make a smooth path - wishdir = normalize( (vl * fl) + (vr * fr) + (vu * fu) + (vd * fd) ); - } - - if (this.enemy) - { - if (fe < 0.1) fe = 0.1; // Make sure we always try to move sligtly towards our target - wishdir = (wishdir * (1 - fe)) + (ve * fe); - } - } - else - { - // Got a clear path to target, speed up fast (if not at full speed) and go straight for it. - myspeed = vlen(this.velocity); - if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) - myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max)); - - wishdir = ve; - } - - if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (this.cnt > time)) - myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2),(autocvar_g_turrets_unit_hk_shot_speed_max)); - - // Ranoutagazfish? - if (this.cnt < time) - { - this.cnt = time + 0.25; - this.nextthink = 0; - set_movetype(this, MOVETYPE_BOUNCE); - return; - } - - // Calculate new heading - olddir = normalize(this.velocity); - newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate)); - - // Set heading & speed - this.velocity = newdir * myspeed; - - // Align model with new heading - this.angles = vectoangles(this.velocity); + vector vu, vd, vf, vl, vr, ve; // Vector (direction) + float fu, fd, ff, fl, fr, fe; // Fraction to solid + vector olddir, wishdir, newdir; // Final direction + float lt_for; // Length of Trace FORwrad + float lt_seek; // Length of Trace SEEK (left, right, up down) + float pt_seek; // Pitch of Trace SEEK (How mutch to angele left, right up, down trace towards v_forward) + float myspeed; + + this.nextthink = time + this.ticrate; + + // if (this.cnt < time) + // turret_hk_missile_explode(); + + if (IS_DEAD(this.enemy)) { + this.enemy = NULL; + } + + // Pick the closest valid target. + if (!this.enemy) { + // in this case, the lighter check is to validate it first, and check distance if it is valid + IL_EACH(g_damagedbycontents, hk_is_valid_target(this.owner, this, it), + { + if (vdist(it.origin, >, 5000)) { + continue; + } + + if (!this.enemy) { + this.enemy = it; + } else if (vlen2(this.origin - it.origin) < vlen2(this.origin - this.enemy.origin)) { + this.enemy = it; + } + }); + } + + this.angles = vectoangles(this.velocity); + this.angles_x = this.angles_x * -1; + makevectors(this.angles); + this.angles_x = this.angles_x * -1; + + if (this.enemy) { + // Close enougth to do decent damage? + if (vdist(this.origin - this.enemy.origin, <=, (this.owner.shot_radius * 0.25))) { + turret_projectile_explode(this); + return; + } + + // Get data on enemy position + vector pre_pos = this.enemy.origin + + this.enemy.velocity + * min((vlen(this.enemy.origin - this.origin) / vlen(this.velocity)), 0.5); + + traceline(this.origin, pre_pos, true, this.enemy); + ve = normalize(pre_pos - this.origin); + fe = trace_fraction; + } else { + ve = '0 0 0'; + fe = 0; + } + + if ((fe != 1) || (this.enemy == NULL) || vdist(this.origin - this.enemy.origin, >, 1000)) { + myspeed = vlen(this.velocity); + + lt_for = myspeed * 3; + lt_seek = myspeed * 2.95; + + // Trace forward + traceline(this.origin, this.origin + v_forward * lt_for, false, this); + vf = trace_endpos; + ff = trace_fraction; + + // Find angular offset + float ad = vlen(vectoangles(normalize(this.enemy.origin - this.origin)) - this.angles); + + // To close to something, Slow down! + if (((ff < 0.7) || (ad > 4)) && (myspeed > (autocvar_g_turrets_unit_hk_shot_speed))) { + myspeed = max(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_decel), (autocvar_g_turrets_unit_hk_shot_speed)); + } + + // Failry clear, accelerate. + if ((ff > 0.7) && (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max))) { + myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel), (autocvar_g_turrets_unit_hk_shot_speed_max)); + } + + // Setup trace pitch + pt_seek = 1 - ff; + pt_seek = bound(0.15, pt_seek, 0.8); + if (ff < 0.5) { pt_seek = 1; } + + // Trace left + traceline(this.origin, this.origin + (-1 * (v_right * pt_seek) + (v_forward * ff)) * lt_seek, false, this); + vl = trace_endpos; + fl = trace_fraction; + + // Trace right + traceline(this.origin, this.origin + ((v_right * pt_seek) + (v_forward * ff)) * lt_seek, false, this); + vr = trace_endpos; + fr = trace_fraction; + + // Trace up + traceline(this.origin, this.origin + ((v_up * pt_seek) + (v_forward * ff)) * lt_seek, false, this); + vu = trace_endpos; + fu = trace_fraction; + + // Trace down + traceline(this.origin, this.origin + (-1 * (v_up * pt_seek) + (v_forward * ff)) * lt_seek, false, this); + vd = trace_endpos; + fd = trace_fraction; + + vl = normalize(vl - this.origin); + vr = normalize(vr - this.origin); + vu = normalize(vu - this.origin); + vd = normalize(vd - this.origin); + + // Panic tresh passed, find a single direction and turn as hard as we can + if (pt_seek == 1) { + wishdir = v_right; + if (fl > fr) { wishdir = -1 * v_right; } + if (fu > fl) { wishdir = v_up; } + if (fd > fu) { wishdir = -1 * v_up; } + } else { + // Normalize our trace vectors to make a smooth path + wishdir = normalize((vl * fl) + (vr * fr) + (vu * fu) + (vd * fd)); + } + + if (this.enemy) { + if (fe < 0.1) { + fe = 0.1; // Make sure we always try to move sligtly towards our target + } + wishdir = (wishdir * (1 - fe)) + (ve * fe); + } + } else { + // Got a clear path to target, speed up fast (if not at full speed) and go straight for it. + myspeed = vlen(this.velocity); + if (myspeed < (autocvar_g_turrets_unit_hk_shot_speed_max)) { + myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2), (autocvar_g_turrets_unit_hk_shot_speed_max)); + } + + wishdir = ve; + } + + if ((myspeed > (autocvar_g_turrets_unit_hk_shot_speed)) && (this.cnt > time)) { + myspeed = min(myspeed * (autocvar_g_turrets_unit_hk_shot_speed_accel2), (autocvar_g_turrets_unit_hk_shot_speed_max)); + } + + // Ranoutagazfish? + if (this.cnt < time) { + this.cnt = time + 0.25; + this.nextthink = 0; + set_movetype(this, MOVETYPE_BOUNCE); + return; + } + + // Calculate new heading + olddir = normalize(this.velocity); + newdir = normalize(olddir + wishdir * (autocvar_g_turrets_unit_hk_shot_speed_turnrate)); + + // Set heading & speed + this.velocity = newdir * myspeed; + + // Align model with new heading + this.angles = vectoangles(this.velocity); #ifdef TURRET_DEBUG_HK - //if(this.atime < time) { - if ((fe <= 0.99)||vdist(this.origin - this.enemy.origin, >, 1000)) - { - te_lightning2(NULL,this.origin, this.origin + vr * lt_seek); - te_lightning2(NULL,this.origin, this.origin + vl * lt_seek); - te_lightning2(NULL,this.origin, this.origin + vu * lt_seek); - te_lightning2(NULL,this.origin, this.origin + vd * lt_seek); - te_lightning2(NULL,this.origin, vf); - } - else - { - te_lightning2(NULL,this.origin, this.enemy.origin); - } - bprint("Speed: ", ftos(rint(myspeed)), "\n"); - bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n"); - bprint("Trace to target:", ftos(rint(fe * 100)), "%\n"); - this.atime = time + 0.2; - //} + // if(this.atime < time) { + if ((fe <= 0.99) || vdist(this.origin - this.enemy.origin, >, 1000)) { + te_lightning2(NULL, this.origin, this.origin + vr * lt_seek); + te_lightning2(NULL, this.origin, this.origin + vl * lt_seek); + te_lightning2(NULL, this.origin, this.origin + vu * lt_seek); + te_lightning2(NULL, this.origin, this.origin + vd * lt_seek); + te_lightning2(NULL, this.origin, vf); + } else { + te_lightning2(NULL, this.origin, this.enemy.origin); + } + bprint("Speed: ", ftos(rint(myspeed)), "\n"); + bprint("Trace to solid: ", ftos(rint(ff * 100)), "%\n"); + bprint("Trace to target:", ftos(rint(fe * 100)), "%\n"); + this.atime = time + 0.2; + // } #endif - UpdateCSQCProjectile(this); + UpdateCSQCProjectile(this); } bool hk_is_valid_target(entity this, entity proj, entity targ) { - if (!targ) - return false; + if (!targ) { + return false; + } - // we know for sure pure entities are bad targets - if(is_pure(targ)) - return false; + // we know for sure pure entities are bad targets + if (is_pure(targ)) { + return false; + } - // If only this was used more.. - if (targ.flags & FL_NOTARGET) - return false; + // If only this was used more.. + if (targ.flags & FL_NOTARGET) { + return false; + } - // Cant touch this - if ((targ.takedamage == DAMAGE_NO) || (targ.health < 0)) - return false; + // Cant touch this + if ((targ.takedamage == DAMAGE_NO) || (targ.health < 0)) { + return false; + } - // player - if (IS_PLAYER(targ)) - { - if (this.target_select_playerbias < 0) - return false; + // player + if (IS_PLAYER(targ)) { + if (this.target_select_playerbias < 0) { + return false; + } - if (IS_DEAD(targ)) - return false; - } + if (IS_DEAD(targ)) { + return false; + } + } - // Missile - if ((targ.flags & FL_PROJECTILE) && (this.target_select_missilebias < 0)) - return false; + // Missile + if ((targ.flags & FL_PROJECTILE) && (this.target_select_missilebias < 0)) { + return false; + } - // Team check - if ((targ.team == this.team) || (this.team == targ.owner.team)) - return false; + // Team check + if ((targ.team == this.team) || (this.team == targ.owner.team)) { + return false; + } - return true; + return true; } #endif diff --git a/qcsrc/common/turrets/turret/machinegun.qc b/qcsrc/common/turrets/turret/machinegun.qc index a2ee1def6..0abc6f328 100644 --- a/qcsrc/common/turrets/turret/machinegun.qc +++ b/qcsrc/common/turrets/turret/machinegun.qc @@ -2,15 +2,20 @@ #ifdef SVQC -spawnfunc(turret_machinegun) { if (!turret_initialize(this, TUR_MACHINEGUN)) delete(this); } +spawnfunc(turret_machinegun) +{ + if (!turret_initialize(this, TUR_MACHINEGUN)) { + delete(this); + } +} METHOD(MachineGunTurret, tr_setup, void(MachineGunTurret this, entity it)) { - it.damage_flags |= TFL_DMG_HEADSHAKE; - it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; - it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; - it.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; - it.turret_flags |= TUR_FLAG_HITSCAN; + it.damage_flags |= TFL_DMG_HEADSHAKE; + it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; + it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; + it.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; + it.turret_flags |= TUR_FLAG_HITSCAN; } #endif // SVQC diff --git a/qcsrc/common/turrets/turret/machinegun.qh b/qcsrc/common/turrets/turret/machinegun.qh index c4a6066b3..0fcecab0d 100644 --- a/qcsrc/common/turrets/turret/machinegun.qh +++ b/qcsrc/common/turrets/turret/machinegun.qh @@ -11,6 +11,6 @@ CLASS(MachineGunTurret, Turret) /* head_model */ ATTRIB_STRZONE(MachineGunTurret, head_model, string, strcat("models/turrets/", "machinegun.md3")); /* netname */ ATTRIB(MachineGunTurret, netname, string, "machinegun"); /* fullname */ ATTRIB(MachineGunTurret, turret_name, string, _("Machinegun Turret")); - ATTRIB(MachineGunTurret, m_weapon, Weapon, WEP_TUR_MACHINEGUN); + ATTRIB(MachineGunTurret, m_weapon, Weapon, WEP_TUR_MACHINEGUN); ENDCLASS(MachineGunTurret) REGISTER_TURRET(MACHINEGUN, NEW(MachineGunTurret)); diff --git a/qcsrc/common/turrets/turret/machinegun_weapon.qc b/qcsrc/common/turrets/turret/machinegun_weapon.qc index 846b52343..7718ccab9 100644 --- a/qcsrc/common/turrets/turret/machinegun_weapon.qc +++ b/qcsrc/common/turrets/turret/machinegun_weapon.qc @@ -6,21 +6,22 @@ void W_MachineGun_MuzzleFlash(entity actor, .entity weaponentity); SOUND(MachineGunTurretAttack_FIRE, W_Sound("electro_fire")); METHOD(MachineGunTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(machinegun, sustained_refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MachineGunTurretAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready); - } - fireBullet (actor, weaponentity, actor.tur_shotorg, actor.tur_shotdir_updated, actor.shot_spread, 0, actor.shot_dmg, actor.shot_force, DEATH_TURRET_MACHINEGUN.m_id, 0); - W_MachineGun_MuzzleFlash(actor, weaponentity); - setattachment(actor.(weaponentity).muzzle_flash, actor.tur_head, "tag_fire"); - } + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(machinegun, sustained_refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MachineGunTurretAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready); + } + fireBullet(actor, weaponentity, actor.tur_shotorg, actor.tur_shotdir_updated, actor.shot_spread, 0, actor.shot_dmg, actor.shot_force, DEATH_TURRET_MACHINEGUN.m_id, 0); + W_MachineGun_MuzzleFlash(actor, weaponentity); + setattachment(actor.(weaponentity).muzzle_flash, actor.tur_head, "tag_fire"); + } + } } #endif diff --git a/qcsrc/common/turrets/turret/mlrs.qc b/qcsrc/common/turrets/turret/mlrs.qc index 2315012b1..e0eb871bd 100644 --- a/qcsrc/common/turrets/turret/mlrs.qc +++ b/qcsrc/common/turrets/turret/mlrs.qc @@ -2,26 +2,30 @@ #ifdef SVQC -spawnfunc(turret_mlrs) { if (!turret_initialize(this, TUR_MLRS)) delete(this); } +spawnfunc(turret_mlrs) +{ + if (!turret_initialize(this, TUR_MLRS)) { + delete(this); + } +} METHOD(MLRSTurret, tr_think, void(MLRSTurret thistur, entity it)) { - // 0 = full, 6 = empty - it.tur_head.frame = bound(0, 6 - floor(0.1 + it.ammo / it.shot_dmg), 6); - if(it.tur_head.frame < 0) - { - LOG_TRACE("ammo:",ftos(it.ammo)); - LOG_TRACE("shot_dmg:",ftos(it.shot_dmg)); - } + // 0 = full, 6 = empty + it.tur_head.frame = bound(0, 6 - floor(0.1 + it.ammo / it.shot_dmg), 6); + if (it.tur_head.frame < 0) { + LOG_TRACE("ammo:", ftos(it.ammo)); + LOG_TRACE("shot_dmg:", ftos(it.shot_dmg)); + } } METHOD(MLRSTurret, tr_setup, void(MLRSTurret this, entity it)) { - it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; - it.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; + it.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE; + it.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE; - it.damage_flags |= TFL_DMG_HEADSHAKE; - it.shoot_flags |= TFL_SHOOT_VOLLYALWAYS; - it.volly_counter = it.shot_volly; + it.damage_flags |= TFL_DMG_HEADSHAKE; + it.shoot_flags |= TFL_SHOOT_VOLLYALWAYS; + it.volly_counter = it.shot_volly; } #endif // SVQC diff --git a/qcsrc/common/turrets/turret/mlrs.qh b/qcsrc/common/turrets/turret/mlrs.qh index 7e0bccf22..7c84c4cd3 100644 --- a/qcsrc/common/turrets/turret/mlrs.qh +++ b/qcsrc/common/turrets/turret/mlrs.qh @@ -11,6 +11,6 @@ CLASS(MLRSTurret, Turret) /* head_model */ ATTRIB_STRZONE(MLRSTurret, head_model, string, strcat("models/turrets/", "mlrs.md3")); /* netname */ ATTRIB(MLRSTurret, netname, string, "mlrs"); /* fullname */ ATTRIB(MLRSTurret, turret_name, string, _("MLRS Turret")); - ATTRIB(MLRSTurret, m_weapon, Weapon, WEP_TUR_MLRS); + ATTRIB(MLRSTurret, m_weapon, Weapon, WEP_TUR_MLRS); ENDCLASS(MLRSTurret) REGISTER_TURRET(MLRS, NEW(MLRSTurret)); diff --git a/qcsrc/common/turrets/turret/mlrs_weapon.qc b/qcsrc/common/turrets/turret/mlrs_weapon.qc index ccf309aaf..7b198fb0d 100644 --- a/qcsrc/common/turrets/turret/mlrs_weapon.qc +++ b/qcsrc/common/turrets/turret/mlrs_weapon.qc @@ -4,24 +4,25 @@ SOUND(MLRSTurretAttack_FIRE, W_Sound("electro_fire")); METHOD(MLRSTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(machinegun, sustained_refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MLRSTurretAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - actor.shot_radius = 500; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready); - } - turret_tag_fire_update(actor); - entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_MLRS.m_id, PROJECTILE_ROCKET, true, true); - missile.nextthink = time + max(actor.tur_impacttime,(actor.shot_radius * 2) / actor.shot_speed); - missile.missile_flags = MIF_SPLASH; - te_explosion (missile.origin); - } + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(machinegun, sustained_refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MLRSTurretAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + actor.shot_radius = 500; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready); + } + turret_tag_fire_update(actor); + entity missile = turret_projectile(actor, SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_MLRS.m_id, PROJECTILE_ROCKET, true, true); + missile.nextthink = time + max(actor.tur_impacttime, (actor.shot_radius * 2) / actor.shot_speed); + missile.missile_flags = MIF_SPLASH; + te_explosion(missile.origin); + } + } } #endif diff --git a/qcsrc/common/turrets/turret/phaser.qc b/qcsrc/common/turrets/turret/phaser.qc index 9c93a6e89..4c2204f42 100644 --- a/qcsrc/common/turrets/turret/phaser.qc +++ b/qcsrc/common/turrets/turret/phaser.qc @@ -2,44 +2,45 @@ #ifdef SVQC -spawnfunc(turret_phaser) { if (!turret_initialize(this, TUR_PHASER)) delete(this); } +spawnfunc(turret_phaser) +{ + if (!turret_initialize(this, TUR_PHASER)) { + delete(this); + } +} .int fireflag; METHOD(PhaserTurret, tr_think, void(PhaserTurret thistur, entity it)) { - if (it.tur_head.frame != 0) - { - if (it.fireflag == 1) - { - if (it.tur_head.frame == 10) - it.tur_head.frame = 1; - else - it.tur_head.frame = it.tur_head.frame +1; - } - else if (it.fireflag == 2 ) - { - it.tur_head.frame = it.tur_head.frame +1; - if (it.tur_head.frame == 15) - { - it.tur_head.frame = 0; - it.fireflag = 0; - } - } - } + if (it.tur_head.frame != 0) { + if (it.fireflag == 1) { + if (it.tur_head.frame == 10) { + it.tur_head.frame = 1; + } else { + it.tur_head.frame = it.tur_head.frame + 1; + } + } else if (it.fireflag == 2) { + it.tur_head.frame = it.tur_head.frame + 1; + if (it.tur_head.frame == 15) { + it.tur_head.frame = 0; + it.fireflag = 0; + } + } + } } bool turret_phaser_firecheck(entity this); METHOD(PhaserTurret, tr_setup, void(PhaserTurret this, entity it)) { - it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; - it.aim_flags = TFL_AIM_LEAD; + it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; + it.aim_flags = TFL_AIM_LEAD; - it.turret_firecheckfunc = turret_phaser_firecheck; + it.turret_firecheckfunc = turret_phaser_firecheck; } bool turret_phaser_firecheck(entity this) { - if (this.fireflag != 0) return false; - return turret_firecheck(this); + if (this.fireflag != 0) { return false; } + return turret_firecheck(this); } #endif diff --git a/qcsrc/common/turrets/turret/phaser.qh b/qcsrc/common/turrets/turret/phaser.qh index 887a11a9e..7a1aabe48 100644 --- a/qcsrc/common/turrets/turret/phaser.qh +++ b/qcsrc/common/turrets/turret/phaser.qh @@ -11,6 +11,6 @@ CLASS(PhaserTurret, Turret) /* head_model */ ATTRIB_STRZONE(PhaserTurret, head_model, string, strcat("models/turrets/", "phaser.md3")); /* netname */ ATTRIB(PhaserTurret, netname, string, "phaser"); /* fullname */ ATTRIB(PhaserTurret, turret_name, string, _("Phaser Cannon")); - ATTRIB(PhaserTurret, m_weapon, Weapon, WEP_PHASER); + ATTRIB(PhaserTurret, m_weapon, Weapon, WEP_PHASER); ENDCLASS(PhaserTurret) REGISTER_TURRET(PHASER, NEW(PhaserTurret)); diff --git a/qcsrc/common/turrets/turret/phaser_weapon.qc b/qcsrc/common/turrets/turret/phaser_weapon.qc index 3fb34fb14..756ad0096 100644 --- a/qcsrc/common/turrets/turret/phaser_weapon.qc +++ b/qcsrc/common/turrets/turret/phaser_weapon.qc @@ -7,84 +7,84 @@ void beam_think(entity this); SOUND(PhaserTurretAttack_FIRE, W_Sound("electro_fire")); METHOD(PhaserTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_PhaserTurretAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - actor.shot_speed = 1; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - entity beam = spawn(); - beam.ticrate = 0.1; //autocvar_sys_ticrate; - setmodel(beam, MDL_TUR_PHASER_BEAM); - beam.effects = EF_LOWPRECISION; - beam.solid = SOLID_NOT; - setthink(beam, beam_think); - beam.cnt = time + actor.shot_speed; - beam.shot_spread = time + 2; - beam.nextthink = time; - beam.owner = actor; - beam.shot_dmg = actor.shot_dmg / (actor.shot_speed / beam.ticrate); - beam.scale = actor.target_range / 256; - set_movetype(beam, MOVETYPE_NONE); - beam.enemy = actor.enemy; - beam.bot_dodge = true; - IL_PUSH(g_bot_dodge, beam); - beam.bot_dodgerating = beam.shot_dmg; - sound (beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM); - actor.fireflag = 1; + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_PhaserTurretAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + actor.shot_speed = 1; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } + entity beam = spawn(); + beam.ticrate = 0.1; // autocvar_sys_ticrate; + setmodel(beam, MDL_TUR_PHASER_BEAM); + beam.effects = EF_LOWPRECISION; + beam.solid = SOLID_NOT; + setthink(beam, beam_think); + beam.cnt = time + actor.shot_speed; + beam.shot_spread = time + 2; + beam.nextthink = time; + beam.owner = actor; + beam.shot_dmg = actor.shot_dmg / (actor.shot_speed / beam.ticrate); + beam.scale = actor.target_range / 256; + set_movetype(beam, MOVETYPE_NONE); + beam.enemy = actor.enemy; + beam.bot_dodge = true; + IL_PUSH(g_bot_dodge, beam); + beam.bot_dodgerating = beam.shot_dmg; + sound(beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM); + actor.fireflag = 1; - beam.attack_finished_single[0] = actor.attack_finished_single[0]; - actor.attack_finished_single[0] = time; // + autocvar_sys_ticrate; + beam.attack_finished_single[0] = actor.attack_finished_single[0]; + actor.attack_finished_single[0] = time; // + autocvar_sys_ticrate; - setattachment(beam,actor.tur_head, "tag_fire"); + setattachment(beam, actor.tur_head, "tag_fire"); - soundat (actor, trace_endpos, CH_SHOTS, SND(NEXIMPACT), VOL_BASE, ATTEN_NORM); - if (!isPlayer) - if (actor.tur_head.frame == 0) - actor.tur_head.frame = 1; - } + soundat(actor, trace_endpos, CH_SHOTS, SND(NEXIMPACT), VOL_BASE, ATTEN_NORM); + if (!isPlayer) { + if (actor.tur_head.frame == 0) { + actor.tur_head.frame = 1; + } + } + } + } } void beam_think(entity this) { - if ((time > this.cnt) || (IS_DEAD(this.owner))) - { - this.owner.attack_finished_single[0] = time + this.owner.shot_refire; - this.owner.fireflag = 2; - this.owner.tur_head.frame = 10; - sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); - delete(this); - return; - } + if ((time > this.cnt) || (IS_DEAD(this.owner))) { + this.owner.attack_finished_single[0] = time + this.owner.shot_refire; + this.owner.fireflag = 2; + this.owner.tur_head.frame = 10; + sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); + delete(this); + return; + } - turret_do_updates(this.owner); + turret_do_updates(this.owner); - if (time - this.shot_spread > 0) - { - this.shot_spread = time + 2; - sound (this, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM); - } + if (time - this.shot_spread > 0) { + this.shot_spread = time + 2; + sound(this, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM); + } - this.nextthink = time + this.ticrate; - - this.owner.attack_finished_single[0] = time + frametime; - FireImoBeam ( this.owner, this.tur_shotorg, - this.tur_shotorg + this.tur_shotdir_updated * this.target_range, - '-1 -1 -1' * this.shot_radius, - '1 1 1' * this.shot_radius, - this.shot_force, - this.shot_dmg, - 0.75, - DEATH_TURRET_PHASER.m_id); - this.scale = vlen(this.owner.tur_shotorg - trace_endpos) / 256; + this.nextthink = time + this.ticrate; + this.owner.attack_finished_single[0] = time + frametime; + FireImoBeam(this.owner, this.tur_shotorg, + this.tur_shotorg + this.tur_shotdir_updated * this.target_range, + '-1 -1 -1' * this.shot_radius, + '1 1 1' * this.shot_radius, + this.shot_force, + this.shot_dmg, + 0.75, + DEATH_TURRET_PHASER.m_id); + this.scale = vlen(this.owner.tur_shotorg - trace_endpos) / 256; } #endif diff --git a/qcsrc/common/turrets/turret/plasma.qh b/qcsrc/common/turrets/turret/plasma.qh index f15ecfc89..6a851ea06 100644 --- a/qcsrc/common/turrets/turret/plasma.qh +++ b/qcsrc/common/turrets/turret/plasma.qh @@ -11,6 +11,6 @@ CLASS(PlasmaTurret, Turret) /* head_model */ ATTRIB_STRZONE(PlasmaTurret, head_model, string, strcat("models/turrets/", "plasma.md3")); /* netname */ ATTRIB(PlasmaTurret, netname, string, "plasma"); /* fullname */ ATTRIB(PlasmaTurret, turret_name, string, _("Plasma Cannon")); - ATTRIB(PlasmaTurret, m_weapon, Weapon, WEP_PLASMA); + ATTRIB(PlasmaTurret, m_weapon, Weapon, WEP_PLASMA); ENDCLASS(PlasmaTurret) REGISTER_TURRET(PLASMA, NEW(PlasmaTurret)); diff --git a/qcsrc/common/turrets/turret/plasma_dual.qh b/qcsrc/common/turrets/turret/plasma_dual.qh index 04436c47f..c1b501c33 100644 --- a/qcsrc/common/turrets/turret/plasma_dual.qh +++ b/qcsrc/common/turrets/turret/plasma_dual.qh @@ -17,6 +17,6 @@ CLASS(DualPlasmaTurret, PlasmaTurret) /* head_model */ ATTRIB_STRZONE(DualPlasmaTurret, head_model, string, strcat("models/turrets/", "plasmad.md3")); /* netname */ ATTRIB(DualPlasmaTurret, netname, string, "plasma_dual"); /* fullname */ ATTRIB(DualPlasmaTurret, turret_name, string, _("Dual Plasma Cannon")); - ATTRIB(DualPlasmaTurret, m_weapon, Weapon, WEP_PLASMA_DUAL); + ATTRIB(DualPlasmaTurret, m_weapon, Weapon, WEP_PLASMA_DUAL); ENDCLASS(DualPlasmaTurret) REGISTER_TURRET(PLASMA_DUAL, NEW(DualPlasmaTurret)); diff --git a/qcsrc/common/turrets/turret/plasma_weapon.qc b/qcsrc/common/turrets/turret/plasma_weapon.qc index 7de7406e2..3d543f629 100644 --- a/qcsrc/common/turrets/turret/plasma_weapon.qc +++ b/qcsrc/common/turrets/turret/plasma_weapon.qc @@ -2,21 +2,23 @@ #ifdef SVQC SOUND(PlasmaAttack_FIRE, W_Sound("electro_fire")); -METHOD(PlasmaAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { +METHOD(PlasmaAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_PlasmaAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - entity missile = turret_projectile(actor, SND_HAGAR_FIRE, 1, 0, DEATH_TURRET_PLASMA.m_id, PROJECTILE_ELECTRO_BEAM, true, true); - missile.missile_flags = MIF_SPLASH; - Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_PlasmaAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } + entity missile = turret_projectile(actor, SND_HAGAR_FIRE, 1, 0, DEATH_TURRET_PLASMA.m_id, PROJECTILE_ELECTRO_BEAM, true, true); + missile.missile_flags = MIF_SPLASH; + Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); + } } } diff --git a/qcsrc/common/turrets/turret/tesla.qc b/qcsrc/common/turrets/turret/tesla.qc index 4c27bc9ac..c513d1744 100644 --- a/qcsrc/common/turrets/turret/tesla.qc +++ b/qcsrc/common/turrets/turret/tesla.qc @@ -2,87 +2,94 @@ #ifdef SVQC -spawnfunc(turret_tesla) { if (!turret_initialize(this, TUR_TESLA)) delete(this); } +spawnfunc(turret_tesla) +{ + if (!turret_initialize(this, TUR_TESLA)) { + delete(this); + } +} METHOD(TeslaCoil, tr_think, void(TeslaCoil thistur, entity it)) { - if(!it.active) - { - it.tur_head.avelocity = '0 0 0'; - return; - } - - if(it.ammo < it.shot_dmg) - { - it.tur_head.avelocity = '0 45 0' * (it.ammo / it.shot_dmg); - } - else - { - it.tur_head.avelocity = '0 180 0' * (it.ammo / it.shot_dmg); - - if(it.attack_finished_single[0] > time) - return; - - float f; - f = (it.ammo / it.ammo_max); - f = f * f; - if(f > random()) - if(random() < 0.1) - te_csqc_lightningarc(it.tur_shotorg,it.tur_shotorg + (randomvec() * 350)); - } + if (!it.active) { + it.tur_head.avelocity = '0 0 0'; + return; + } + + if (it.ammo < it.shot_dmg) { + it.tur_head.avelocity = '0 45 0' * (it.ammo / it.shot_dmg); + } else { + it.tur_head.avelocity = '0 180 0' * (it.ammo / it.shot_dmg); + + if (it.attack_finished_single[0] > time) { + return; + } + + float f; + f = (it.ammo / it.ammo_max); + f = f * f; + if (f > random()) { + if (random() < 0.1) { + te_csqc_lightningarc(it.tur_shotorg, it.tur_shotorg + (randomvec() * 350)); + } + } + } } bool turret_tesla_firecheck(entity this); METHOD(TeslaCoil, tr_setup, void(TeslaCoil this, entity it)) { - it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | - TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; - - it.turret_firecheckfunc = turret_tesla_firecheck; - it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | - TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; - - it.firecheck_flags = TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AMMO_OWN; - it.shoot_flags = TFL_SHOOT_CUSTOM; - it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; - it.aim_flags = TFL_AIM_NO; - it.track_flags = TFL_TRACK_NO; + it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES + | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; + + it.turret_firecheckfunc = turret_tesla_firecheck; + it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES + | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; + + it.firecheck_flags = TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AMMO_OWN; + it.shoot_flags = TFL_SHOOT_CUSTOM; + it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; + it.aim_flags = TFL_AIM_NO; + it.track_flags = TFL_TRACK_NO; } bool turret_tesla_firecheck(entity this) { - // g_turrets_targetscan_maxdelay forces a target re-scan at least this often - float do_target_scan = 0; - - if((this.target_select_time + autocvar_g_turrets_targetscan_maxdelay) < time) - do_target_scan = 1; - - // Old target (if any) invalid? - if(this.target_validate_time < time) - if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0) - { - this.enemy = NULL; - this.target_validate_time = time + 0.5; - do_target_scan = 1; - } - - // But never more often then g_turrets_targetscan_mindelay! - if (this.target_select_time + autocvar_g_turrets_targetscan_mindelay > time) - do_target_scan = 0; - - if(do_target_scan) - { - this.enemy = turret_select_target(this); - this.target_select_time = time; - } - - if(!turret_firecheck(this)) - return false; - - if(this.enemy) - return true; - - return false; + // g_turrets_targetscan_maxdelay forces a target re-scan at least this often + float do_target_scan = 0; + + if ((this.target_select_time + autocvar_g_turrets_targetscan_maxdelay) < time) { + do_target_scan = 1; + } + + // Old target (if any) invalid? + if (this.target_validate_time < time) { + if (turret_validate_target(this, this.enemy, this.target_validate_flags) <= 0) { + this.enemy = NULL; + this.target_validate_time = time + 0.5; + do_target_scan = 1; + } + } + + // But never more often then g_turrets_targetscan_mindelay! + if (this.target_select_time + autocvar_g_turrets_targetscan_mindelay > time) { + do_target_scan = 0; + } + + if (do_target_scan) { + this.enemy = turret_select_target(this); + this.target_select_time = time; + } + + if (!turret_firecheck(this)) { + return false; + } + + if (this.enemy) { + return true; + } + + return false; } #endif diff --git a/qcsrc/common/turrets/turret/tesla.qh b/qcsrc/common/turrets/turret/tesla.qh index ee3192eb9..405f7eeb8 100644 --- a/qcsrc/common/turrets/turret/tesla.qh +++ b/qcsrc/common/turrets/turret/tesla.qh @@ -11,6 +11,6 @@ CLASS(TeslaCoil, Turret) /* head_model */ ATTRIB_STRZONE(TeslaCoil, head_model, string, strcat("models/turrets/", "tesla_head.md3")); /* netname */ ATTRIB(TeslaCoil, netname, string, "tesla"); /* fullname */ ATTRIB(TeslaCoil, turret_name, string, _("Tesla Coil")); - ATTRIB(TeslaCoil, m_weapon, Weapon, WEP_TESLA); + ATTRIB(TeslaCoil, m_weapon, Weapon, WEP_TESLA); ENDCLASS(TeslaCoil) REGISTER_TURRET(TESLA, NEW(TeslaCoil)); diff --git a/qcsrc/common/turrets/turret/tesla_weapon.qc b/qcsrc/common/turrets/turret/tesla_weapon.qc index 88ca4db97..d9ec07c66 100644 --- a/qcsrc/common/turrets/turret/tesla_weapon.qc +++ b/qcsrc/common/turrets/turret/tesla_weapon.qc @@ -4,81 +4,78 @@ entity toast(entity actor, entity from, float range, float damage); SOUND(TeslaCoilTurretAttack_FIRE, W_Sound("electro_fire")); -METHOD(TeslaCoilTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_TeslaCoilTurretAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - - float d = actor.shot_dmg; - float r = actor.target_range; - entity e = spawn(); - setorigin(e, actor.tur_shotorg); +METHOD(TeslaCoilTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_TeslaCoilTurretAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } - actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; + float d = actor.shot_dmg; + float r = actor.target_range; + entity e = spawn(); + setorigin(e, actor.tur_shotorg); - entity t = toast(actor, e,r,d); - delete(e); + actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK; - if (t == NULL) return; + entity t = toast(actor, e, r, d); + delete(e); - actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_TEAMCHECK; + if (t == NULL) { return; } - actor.attack_finished_single[0] = time + actor.shot_refire; - for (int i = 0; i < 10; ++i) { - d *= 0.75; - r *= 0.85; - t = toast(actor, t, r, d); - if (t == NULL) break; + actor.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_MISSILES | TFL_TARGETSELECT_TEAMCHECK; - } + actor.attack_finished_single[0] = time + actor.shot_refire; + for (int i = 0; i < 10; ++i) { + d *= 0.75; + r *= 0.85; + t = toast(actor, t, r, d); + if (t == NULL) { break; } + } - IL_EACH(g_railgunhit, it.railgunhit, - { - it.railgunhit = false; - }); - IL_CLEAR(g_railgunhit); - } + IL_EACH(g_railgunhit, it.railgunhit, + { + it.railgunhit = false; + }); + IL_CLEAR(g_railgunhit); + } + } } entity toast(entity actor, entity from, float range, float damage) { - float dd = range + 1; - entity etarget = NULL; - FOREACH_ENTITY_RADIUS(from.origin, range, it != from && !it.railgunhit, - { - float r = turret_validate_target(actor, it, actor.target_validate_flags); - if(r > 0) - { - traceline(from.origin, 0.5 * (it.absmin + it.absmax), MOVE_WORLDONLY, from); - if(trace_fraction == 1.0) - { - float d = vlen(it.origin - from.origin); - if(d < dd) - { - dd = d; - etarget = it; - } - } - } - }); + float dd = range + 1; + entity etarget = NULL; + FOREACH_ENTITY_RADIUS(from.origin, range, it != from && !it.railgunhit, + { + float r = turret_validate_target(actor, it, actor.target_validate_flags); + if (r > 0) { + traceline(from.origin, 0.5 * (it.absmin + it.absmax), MOVE_WORLDONLY, from); + if (trace_fraction == 1.0) { + float d = vlen(it.origin - from.origin); + if (d < dd) { + dd = d; + etarget = it; + } + } + } + }); - if (etarget) - { - te_csqc_lightningarc(from.origin, etarget.origin); - Damage(etarget, actor, actor, damage, DEATH_TURRET_TESLA.m_id, etarget.origin, '0 0 0'); - etarget.railgunhit = true; - IL_PUSH(g_railgunhit, etarget); - } + if (etarget) { + te_csqc_lightningarc(from.origin, etarget.origin); + Damage(etarget, actor, actor, damage, DEATH_TURRET_TESLA.m_id, etarget.origin, '0 0 0'); + etarget.railgunhit = true; + IL_PUSH(g_railgunhit, etarget); + } - return etarget; + return etarget; } #endif diff --git a/qcsrc/common/turrets/turret/walker.qc b/qcsrc/common/turrets/turret/walker.qc index 415d5dfee..8d48e9544 100644 --- a/qcsrc/common/turrets/turret/walker.qc +++ b/qcsrc/common/turrets/turret/walker.qc @@ -43,569 +43,558 @@ const int ANIM_ROAM = 11; bool walker_firecheck(entity this) { - if (this.animflag == ANIM_MELEE) - return false; + if (this.animflag == ANIM_MELEE) { + return false; + } - return turret_firecheck(this); + return turret_firecheck(this); } void walker_melee_do_dmg(entity this) { - vector where; - entity e; - - makevectors(this.angles); - where = this.origin + v_forward * 128; - - e = findradius(where,32); - while (e) - { - if (turret_validate_target(this, e, this.target_validate_flags)) - if (e != this && e.owner != this) - Damage(e, this, this, (autocvar_g_turrets_unit_walker_melee_damage), DEATH_TURRET_WALK_MELEE.m_id, '0 0 0', v_forward * (autocvar_g_turrets_unit_walker_melee_force)); - - e = e.chain; - } + vector where; + entity e; + + makevectors(this.angles); + where = this.origin + v_forward * 128; + + e = findradius(where, 32); + while (e) { + if (turret_validate_target(this, e, this.target_validate_flags)) { + if (e != this && e.owner != this) { + Damage(e, this, this, (autocvar_g_turrets_unit_walker_melee_damage), DEATH_TURRET_WALK_MELEE.m_id, '0 0 0', v_forward * (autocvar_g_turrets_unit_walker_melee_force)); + } + } + + e = e.chain; + } } void walker_setnoanim(entity this) { - turrets_setframe(this, ANIM_NO, false); - this.animflag = this.frame; + turrets_setframe(this, ANIM_NO, false); + this.animflag = this.frame; } void walker_rocket_explode(entity this) { - RadiusDamage (this, this.owner, (autocvar_g_turrets_unit_walker_rocket_damage), 0, (autocvar_g_turrets_unit_walker_rocket_radius), this, NULL, (autocvar_g_turrets_unit_walker_rocket_force), DEATH_TURRET_WALK_ROCKET.m_id, NULL); - delete(this); + RadiusDamage(this, this.owner, (autocvar_g_turrets_unit_walker_rocket_damage), 0, (autocvar_g_turrets_unit_walker_rocket_radius), this, NULL, (autocvar_g_turrets_unit_walker_rocket_force), DEATH_TURRET_WALK_ROCKET.m_id, NULL); + delete(this); } void walker_rocket_touch(entity this, entity toucher) { - walker_rocket_explode(this); + walker_rocket_explode(this); } void walker_rocket_damage(entity this, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce) { - this.health = this.health - damage; - this.velocity = this.velocity + vforce; + this.health = this.health - damage; + this.velocity = this.velocity + vforce; - if (this.health <= 0) - W_PrepareExplosionByDamage(this, this.owner, walker_rocket_explode); + if (this.health <= 0) { + W_PrepareExplosionByDamage(this, this.owner, walker_rocket_explode); + } } #define WALKER_ROCKET_MOVE(s) movelib_move_simple((s), newdir, (autocvar_g_turrets_unit_walker_rocket_speed), (autocvar_g_turrets_unit_walker_rocket_turnrate)); UpdateCSQCProjectile(s) void walker_rocket_loop(entity this); void walker_rocket_think(entity this) { - vector newdir; - float edist; - float itime; - float m_speed; - - this.nextthink = time; - - edist = vlen(this.enemy.origin - this.origin); - - // Simulate crude guidance - if (this.cnt < time) - { - if (edist < 1000) - this.tur_shotorg = randomvec() * min(edist, 64); - else - this.tur_shotorg = randomvec() * min(edist, 256); - - this.cnt = time + 0.5; - } - - if (edist < 128) - this.tur_shotorg = '0 0 0'; - - if (this.max_health < time) - { - setthink(this, walker_rocket_explode); - this.nextthink = time; - return; - } - - if (this.shot_dmg != 1337 && random() < 0.01) - { - walker_rocket_loop(this); - return; - } - - m_speed = vlen(this.velocity); - - // Enemy dead? just keep on the current heading then. - if (this.enemy == NULL || IS_DEAD(this.enemy)) - this.enemy = NULL; - - if (this.enemy) - { - itime = max(edist / m_speed, 1); - newdir = steerlib_pull(this, this.enemy.origin + this.tur_shotorg); - } - else - newdir = normalize(this.velocity); - - WALKER_ROCKET_MOVE(this); + vector newdir; + float edist; + float itime; + float m_speed; + + this.nextthink = time; + + edist = vlen(this.enemy.origin - this.origin); + + // Simulate crude guidance + if (this.cnt < time) { + if (edist < 1000) { + this.tur_shotorg = randomvec() * min(edist, 64); + } else { + this.tur_shotorg = randomvec() * min(edist, 256); + } + + this.cnt = time + 0.5; + } + + if (edist < 128) { + this.tur_shotorg = '0 0 0'; + } + + if (this.max_health < time) { + setthink(this, walker_rocket_explode); + this.nextthink = time; + return; + } + + if (this.shot_dmg != 1337 && random() < 0.01) { + walker_rocket_loop(this); + return; + } + + m_speed = vlen(this.velocity); + + // Enemy dead? just keep on the current heading then. + if (this.enemy == NULL || IS_DEAD(this.enemy)) { + this.enemy = NULL; + } + + if (this.enemy) { + itime = max(edist / m_speed, 1); + newdir = steerlib_pull(this, this.enemy.origin + this.tur_shotorg); + } else { + newdir = normalize(this.velocity); + } + + WALKER_ROCKET_MOVE(this); } void walker_rocket_loop3(entity this) { - this.nextthink = time; + this.nextthink = time; - if (this.max_health < time) - { - setthink(this, walker_rocket_explode); - return; - } + if (this.max_health < time) { + setthink(this, walker_rocket_explode); + return; + } - if(vdist(this.origin - this.tur_shotorg, <, 100)) - { - setthink(this, walker_rocket_think); - return; - } + if (vdist(this.origin - this.tur_shotorg, <, 100)) { + setthink(this, walker_rocket_think); + return; + } - vector newdir = steerlib_pull(this, this.tur_shotorg); - WALKER_ROCKET_MOVE(this); + vector newdir = steerlib_pull(this, this.tur_shotorg); + WALKER_ROCKET_MOVE(this); - this.angles = vectoangles(this.velocity); + this.angles = vectoangles(this.velocity); } void walker_rocket_loop2(entity this) { - this.nextthink = time; - - if (this.max_health < time) - { - setthink(this, walker_rocket_explode); - return; - } - - if(vdist(this.origin - this.tur_shotorg, <, 100)) - { - this.tur_shotorg = this.origin - '0 0 200'; - setthink(this, walker_rocket_loop3); - return; - } - - vector newdir = steerlib_pull(this, this.tur_shotorg); - WALKER_ROCKET_MOVE(this); + this.nextthink = time; + + if (this.max_health < time) { + setthink(this, walker_rocket_explode); + return; + } + + if (vdist(this.origin - this.tur_shotorg, <, 100)) { + this.tur_shotorg = this.origin - '0 0 200'; + setthink(this, walker_rocket_loop3); + return; + } + + vector newdir = steerlib_pull(this, this.tur_shotorg); + WALKER_ROCKET_MOVE(this); } void walker_rocket_loop(entity this) { - this.nextthink = time; - this.tur_shotorg = this.origin + '0 0 300'; - setthink(this, walker_rocket_loop2); - this.shot_dmg = 1337; + this.nextthink = time; + this.tur_shotorg = this.origin + '0 0 300'; + setthink(this, walker_rocket_loop2); + this.shot_dmg = 1337; } void walker_fire_rocket(entity this, vector org) { - fixedmakevectors(this.angles); - - te_explosion (org); - - entity rocket = new(walker_rocket); - setorigin(rocket, org); - - sound (this, CH_WEAPON_A, SND_HAGAR_FIRE, VOL_BASE, ATTEN_NORM); - setsize (rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot - - rocket.owner = this; - rocket.bot_dodge = true; - rocket.bot_dodgerating = 50; - rocket.takedamage = DAMAGE_YES; - rocket.damageforcescale = 2; - rocket.health = 25; - rocket.tur_shotorg = randomvec() * 512; - rocket.cnt = time + 1; - rocket.enemy = this.enemy; - - if (random() < 0.01) - setthink(rocket, walker_rocket_loop); - else - setthink(rocket, walker_rocket_think); - - rocket.event_damage = walker_rocket_damage; - - rocket.nextthink = time; - set_movetype(rocket, MOVETYPE_FLY); - rocket.velocity = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * (autocvar_g_turrets_unit_walker_rocket_speed); - rocket.angles = vectoangles(rocket.velocity); - settouch(rocket, walker_rocket_touch); - rocket.flags = FL_PROJECTILE; - IL_PUSH(g_projectiles, rocket); - IL_PUSH(g_bot_dodge, rocket); - rocket.solid = SOLID_BBOX; - rocket.max_health = time + 9; - rocket.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT; - - CSQCProjectile(rocket, false, PROJECTILE_ROCKET, false); // no culling, has fly sound + fixedmakevectors(this.angles); + + te_explosion(org); + + entity rocket = new(walker_rocket); + setorigin(rocket, org); + + sound(this, CH_WEAPON_A, SND_HAGAR_FIRE, VOL_BASE, ATTEN_NORM); + setsize(rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot + + rocket.owner = this; + rocket.bot_dodge = true; + rocket.bot_dodgerating = 50; + rocket.takedamage = DAMAGE_YES; + rocket.damageforcescale = 2; + rocket.health = 25; + rocket.tur_shotorg = randomvec() * 512; + rocket.cnt = time + 1; + rocket.enemy = this.enemy; + + if (random() < 0.01) { + setthink(rocket, walker_rocket_loop); + } else { + setthink(rocket, walker_rocket_think); + } + + rocket.event_damage = walker_rocket_damage; + + rocket.nextthink = time; + set_movetype(rocket, MOVETYPE_FLY); + rocket.velocity = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * (autocvar_g_turrets_unit_walker_rocket_speed); + rocket.angles = vectoangles(rocket.velocity); + settouch(rocket, walker_rocket_touch); + rocket.flags = FL_PROJECTILE; + IL_PUSH(g_projectiles, rocket); + IL_PUSH(g_bot_dodge, rocket); + rocket.solid = SOLID_BBOX; + rocket.max_health = time + 9; + rocket.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT; + + CSQCProjectile(rocket, false, PROJECTILE_ROCKET, false); // no culling, has fly sound } .vector enemy_last_loc; .float enemy_last_time; void walker_move_to(entity this, vector _target, float _dist) { - switch (this.waterlevel) - { - case WATERLEVEL_NONE: - if (_dist > 500) - this.animflag = ANIM_RUN; - else - this.animflag = ANIM_WALK; - case WATERLEVEL_WETFEET: - case WATERLEVEL_SWIMMING: - if (this.animflag != ANIM_SWIM) - this.animflag = ANIM_WALK; - else - this.animflag = ANIM_SWIM; - break; - case WATERLEVEL_SUBMERGED: - this.animflag = ANIM_SWIM; - } - - this.moveto = _target; - this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); - - if(this.enemy) - { - this.enemy_last_loc = _target; - this.enemy_last_time = time; - } + switch (this.waterlevel) { + case WATERLEVEL_NONE: + if (_dist > 500) { + this.animflag = ANIM_RUN; + } else { + this.animflag = ANIM_WALK; + } + case WATERLEVEL_WETFEET: + case WATERLEVEL_SWIMMING: + if (this.animflag != ANIM_SWIM) { + this.animflag = ANIM_WALK; + } else { + this.animflag = ANIM_SWIM; + } + break; + case WATERLEVEL_SUBMERGED: + this.animflag = ANIM_SWIM; + } + + this.moveto = _target; + this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); + + if (this.enemy) { + this.enemy_last_loc = _target; + this.enemy_last_time = time; + } } void walker_move_path(entity this) { #ifdef WALKER_FANCYPATHING - // Are we close enougth to a path node to switch to the next? - if(vdist(this.origin - this.pathcurrent.origin, <, 64)) - if (this.pathcurrent.path_next == NULL) - { - // Path endpoint reached - pathlib_deletepath(this.pathcurrent.owner); - this.pathcurrent = NULL; - - if (this.pathgoal) - { - if (this.pathgoal.use) - this.pathgoal.use(this, NULL, NULL); - - if (this.pathgoal.enemy) - { - this.pathcurrent = pathlib_astar(this, this.pathgoal.origin, this.pathgoal.enemy.origin); - this.pathgoal = this.pathgoal.enemy; - } - } - else - this.pathgoal = NULL; - } - else - this.pathcurrent = this.pathcurrent.path_next; - - this.moveto = this.pathcurrent.origin; - this.steerto = steerlib_attract2(this, this.moveto,0.5,500,0.95); - walker_move_to(this, this.moveto, 0); + // Are we close enougth to a path node to switch to the next? + if (vdist(this.origin - this.pathcurrent.origin, <, 64)) { + if (this.pathcurrent.path_next == NULL) { + // Path endpoint reached + pathlib_deletepath(this.pathcurrent.owner); + this.pathcurrent = NULL; + + if (this.pathgoal) { + if (this.pathgoal.use) { + this.pathgoal.use(this, NULL, NULL); + } + + if (this.pathgoal.enemy) { + this.pathcurrent = pathlib_astar(this, this.pathgoal.origin, this.pathgoal.enemy.origin); + this.pathgoal = this.pathgoal.enemy; + } + } else { + this.pathgoal = NULL; + } + } else { + this.pathcurrent = this.pathcurrent.path_next; + } + } + + this.moveto = this.pathcurrent.origin; + this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); + walker_move_to(this, this.moveto, 0); #else - if(vdist(this.origin - this.pathcurrent.origin, <, 64)) - this.pathcurrent = this.pathcurrent.enemy; + if (vdist(this.origin - this.pathcurrent.origin, <, 64)) { + this.pathcurrent = this.pathcurrent.enemy; + } - if(!this.pathcurrent) - return; + if (!this.pathcurrent) { + return; + } - this.moveto = this.pathcurrent.origin; - this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); - walker_move_to(this, this.moveto, 0); + this.moveto = this.pathcurrent.origin; + this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95); + walker_move_to(this, this.moveto, 0); #endif } void walker_findtarget(entity this) { - entity e = find(NULL, targetname, this.target); - if (!e) - { - LOG_TRACE("Initital waypoint for walker does NOT exist, fix your map!"); - this.target = ""; - } - - if (e.classname != "turret_checkpoint") - LOG_TRACE("Warning: not a turrret path"); - else - { + entity e = find(NULL, targetname, this.target); + if (!e) { + LOG_TRACE("Initital waypoint for walker does NOT exist, fix your map!"); + this.target = ""; + } + + if (e.classname != "turret_checkpoint") { + LOG_TRACE("Warning: not a turrret path"); + } else { #ifdef WALKER_FANCYPATHING - this.pathcurrent = pathlib_astar(this, this.origin, e.origin); - this.pathgoal = e; + this.pathcurrent = pathlib_astar(this, this.origin, e.origin); + this.pathgoal = e; #else - this.pathcurrent = e; + this.pathcurrent = e; #endif - } + } - // TODO: this doesn't reset target, so tur_defend will be the checkpoint too! + // TODO: this doesn't reset target, so tur_defend will be the checkpoint too! } -spawnfunc(turret_walker) { if(!turret_initialize(this, TUR_WALKER)) delete(this); } +spawnfunc(turret_walker) +{ + if (!turret_initialize(this, TUR_WALKER)) { + delete(this); + } +} METHOD(WalkerTurret, tr_think, void(WalkerTurret thistur, entity it)) { - fixedmakevectors(it.angles); - - if (it.spawnflags & TSF_NO_PATHBREAK && it.pathcurrent) - walker_move_path(it); - else if (it.enemy == NULL) - { - if(it.pathcurrent) - walker_move_path(it); - else - { - if(it.enemy_last_time != 0) - { - if(vdist(it.origin - it.enemy_last_loc, <, 128) || time - it.enemy_last_time > 10) - it.enemy_last_time = 0; - else - walker_move_to(it, it.enemy_last_loc, 0); - } - else - { - if(it.animflag != ANIM_NO) - { - traceline(it.origin + '0 0 64', it.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, it); - - if(trace_fraction != 1.0) - it.tur_head.idletime = -1337; - else - { - traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, it); - if(trace_fraction == 1.0) - it.tur_head.idletime = -1337; - } - - if(it.tur_head.idletime == -1337) - { - it.moveto = it.origin + randomvec() * 256; - it.tur_head.idletime = 0; - } - - it.moveto = it.moveto * 0.9 + ((it.origin + v_forward * 500) + randomvec() * 400) * 0.1; - it.moveto_z = it.origin_z + 64; - walker_move_to(it, it.moveto, 0); - } - - if(it.idletime < time) - { - if(random() < 0.5 || !(it.spawnflags & TSL_ROAM)) - { - it.idletime = time + 1 + random() * 5; - it.moveto = it.origin; - it.animflag = ANIM_NO; - } - else - { - it.animflag = ANIM_WALK; - it.idletime = time + 4 + random() * 2; - it.moveto = it.origin + randomvec() * 256; - it.tur_head.moveto = it.moveto; - it.tur_head.idletime = 0; - } - } - } - } - } - else - { - if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_melee_range) && it.animflag != ANIM_MELEE) - { - vector wish_angle; - - wish_angle = angleofs(it, it.enemy); - if (it.animflag != ANIM_SWIM) - if (fabs(wish_angle_y) < 15) - { - it.moveto = it.enemy.origin; - it.steerto = steerlib_attract2(it, it.moveto, 0.5, 500, 0.95); - it.animflag = ANIM_MELEE; - } - } - else if (it.tur_head.attack_finished_single[0] < time) - { - if(it.tur_head.shot_volly) - { - it.animflag = ANIM_NO; - - it.tur_head.shot_volly = it.tur_head.shot_volly -1; - if(it.tur_head.shot_volly == 0) - it.tur_head.attack_finished_single[0] = time + (autocvar_g_turrets_unit_walker_rocket_refire); - else - it.tur_head.attack_finished_single[0] = time + 0.2; - - if(it.tur_head.shot_volly > 1) - walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket01"))); - else - walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket02"))); - } - else - { - if (it.tur_dist_enemy > (autocvar_g_turrets_unit_walker_rocket_range_min)) - if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_rocket_range)) - it.tur_head.shot_volly = 4; - } - } - else - { - if (it.animflag != ANIM_MELEE) - walker_move_to(it, it.enemy.origin, it.tur_dist_enemy); - } - } - - { - vector real_angle; - float turny = 0, turnx = 0; - float vz; - - real_angle = vectoangles(it.steerto) - it.angles; - vz = it.velocity_z; - - switch (it.animflag) - { - case ANIM_NO: - movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop)); - break; - - case ANIM_TURN: - turny = (autocvar_g_turrets_unit_walker_turn); - movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop)); - break; - - case ANIM_WALK: - turny = (autocvar_g_turrets_unit_walker_turn_walk); - movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_walk), 0.6); - break; - - case ANIM_RUN: - turny = (autocvar_g_turrets_unit_walker_turn_run); - movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_run), 0.6); - break; - - case ANIM_STRAFE_L: - turny = (autocvar_g_turrets_unit_walker_turn_strafe); - movelib_move_simple(it, v_right * -1, (autocvar_g_turrets_unit_walker_speed_walk), 0.8); - break; - - case ANIM_STRAFE_R: - turny = (autocvar_g_turrets_unit_walker_turn_strafe); - movelib_move_simple(it, v_right, (autocvar_g_turrets_unit_walker_speed_walk), 0.8); - break; - - case ANIM_JUMP: - it.velocity += '0 0 1' * (autocvar_g_turrets_unit_walker_speed_jump); - break; - - case ANIM_LAND: - break; - - case ANIM_PAIN: - if(it.frame != ANIM_PAIN) - defer(it, 0.25, walker_setnoanim); - - break; - - case ANIM_MELEE: - if(it.frame != ANIM_MELEE) - { - defer(it, 0.41, walker_setnoanim); - defer(it, 0.21, walker_melee_do_dmg); - } - - movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop)); - break; - - case ANIM_SWIM: - turny = (autocvar_g_turrets_unit_walker_turn_swim); - turnx = (autocvar_g_turrets_unit_walker_turn_swim); - - it.angles_x += bound(-10, shortangle_f(real_angle_x, it.angles_x), 10); - movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_swim), 0.3); - vz = it.velocity_z + sin(time * 4) * 8; - break; - - case ANIM_ROAM: - turny = (autocvar_g_turrets_unit_walker_turn_walk); - movelib_move_simple(it, v_forward ,(autocvar_g_turrets_unit_walker_speed_roam), 0.5); - break; - } - - if(turny) - { - turny = bound( turny * -1, shortangle_f(real_angle_y, it.angles_y), turny ); - it.angles_y += turny; - } - - if(turnx) - { - turnx = bound( turnx * -1, shortangle_f(real_angle_x, it.angles_x), turnx ); - it.angles_x += turnx; - } - - it.velocity_z = vz; - } - - - if(it.origin != it.oldorigin) - it.SendFlags |= TNSF_MOVE; - - it.oldorigin = it.origin; - turrets_setframe(it, it.animflag, false); + fixedmakevectors(it.angles); + + if (it.spawnflags & TSF_NO_PATHBREAK && it.pathcurrent) { + walker_move_path(it); + } else if (it.enemy == NULL) { + if (it.pathcurrent) { + walker_move_path(it); + } else { + if (it.enemy_last_time != 0) { + if (vdist(it.origin - it.enemy_last_loc, <, 128) || time - it.enemy_last_time > 10) { + it.enemy_last_time = 0; + } else { + walker_move_to(it, it.enemy_last_loc, 0); + } + } else { + if (it.animflag != ANIM_NO) { + traceline(it.origin + '0 0 64', it.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, it); + + if (trace_fraction != 1.0) { + it.tur_head.idletime = -1337; + } else { + traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, it); + if (trace_fraction == 1.0) { + it.tur_head.idletime = -1337; + } + } + + if (it.tur_head.idletime == -1337) { + it.moveto = it.origin + randomvec() * 256; + it.tur_head.idletime = 0; + } + + it.moveto = it.moveto * 0.9 + ((it.origin + v_forward * 500) + randomvec() * 400) * 0.1; + it.moveto_z = it.origin_z + 64; + walker_move_to(it, it.moveto, 0); + } + + if (it.idletime < time) { + if (random() < 0.5 || !(it.spawnflags & TSL_ROAM)) { + it.idletime = time + 1 + random() * 5; + it.moveto = it.origin; + it.animflag = ANIM_NO; + } else { + it.animflag = ANIM_WALK; + it.idletime = time + 4 + random() * 2; + it.moveto = it.origin + randomvec() * 256; + it.tur_head.moveto = it.moveto; + it.tur_head.idletime = 0; + } + } + } + } + } else { + if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_melee_range) && it.animflag != ANIM_MELEE) { + vector wish_angle; + + wish_angle = angleofs(it, it.enemy); + if (it.animflag != ANIM_SWIM) { + if (fabs(wish_angle_y) < 15) { + it.moveto = it.enemy.origin; + it.steerto = steerlib_attract2(it, it.moveto, 0.5, 500, 0.95); + it.animflag = ANIM_MELEE; + } + } + } else if (it.tur_head.attack_finished_single[0] < time) { + if (it.tur_head.shot_volly) { + it.animflag = ANIM_NO; + + it.tur_head.shot_volly = it.tur_head.shot_volly - 1; + if (it.tur_head.shot_volly == 0) { + it.tur_head.attack_finished_single[0] = time + (autocvar_g_turrets_unit_walker_rocket_refire); + } else { + it.tur_head.attack_finished_single[0] = time + 0.2; + } + + if (it.tur_head.shot_volly > 1) { + walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket01"))); + } else { + walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket02"))); + } + } else { + if (it.tur_dist_enemy > (autocvar_g_turrets_unit_walker_rocket_range_min)) { + if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_rocket_range)) { + it.tur_head.shot_volly = 4; + } + } + } + } else { + if (it.animflag != ANIM_MELEE) { + walker_move_to(it, it.enemy.origin, it.tur_dist_enemy); + } + } + } + + { + vector real_angle; + float turny = 0, turnx = 0; + float vz; + + real_angle = vectoangles(it.steerto) - it.angles; + vz = it.velocity_z; + + switch (it.animflag) { + case ANIM_NO: + movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop)); + break; + + case ANIM_TURN: + turny = (autocvar_g_turrets_unit_walker_turn); + movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop)); + break; + + case ANIM_WALK: + turny = (autocvar_g_turrets_unit_walker_turn_walk); + movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_walk), 0.6); + break; + + case ANIM_RUN: + turny = (autocvar_g_turrets_unit_walker_turn_run); + movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_run), 0.6); + break; + + case ANIM_STRAFE_L: + turny = (autocvar_g_turrets_unit_walker_turn_strafe); + movelib_move_simple(it, v_right * -1, (autocvar_g_turrets_unit_walker_speed_walk), 0.8); + break; + + case ANIM_STRAFE_R: + turny = (autocvar_g_turrets_unit_walker_turn_strafe); + movelib_move_simple(it, v_right, (autocvar_g_turrets_unit_walker_speed_walk), 0.8); + break; + + case ANIM_JUMP: + it.velocity += '0 0 1' * (autocvar_g_turrets_unit_walker_speed_jump); + break; + + case ANIM_LAND: + break; + + case ANIM_PAIN: + if (it.frame != ANIM_PAIN) { + defer(it, 0.25, walker_setnoanim); + } + + break; + + case ANIM_MELEE: + if (it.frame != ANIM_MELEE) { + defer(it, 0.41, walker_setnoanim); + defer(it, 0.21, walker_melee_do_dmg); + } + + movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop)); + break; + + case ANIM_SWIM: + turny = (autocvar_g_turrets_unit_walker_turn_swim); + turnx = (autocvar_g_turrets_unit_walker_turn_swim); + + it.angles_x += bound(-10, shortangle_f(real_angle_x, it.angles_x), 10); + movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_swim), 0.3); + vz = it.velocity_z + sin(time * 4) * 8; + break; + + case ANIM_ROAM: + turny = (autocvar_g_turrets_unit_walker_turn_walk); + movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_roam), 0.5); + break; + } + + if (turny) { + turny = bound(turny * -1, shortangle_f(real_angle_y, it.angles_y), turny); + it.angles_y += turny; + } + + if (turnx) { + turnx = bound(turnx * -1, shortangle_f(real_angle_x, it.angles_x), turnx); + it.angles_x += turnx; + } + + it.velocity_z = vz; + } + + + if (it.origin != it.oldorigin) { + it.SendFlags |= TNSF_MOVE; + } + + it.oldorigin = it.origin; + turrets_setframe(it, it.animflag, false); } METHOD(WalkerTurret, tr_death, void(WalkerTurret this, entity it)) { #ifdef WALKER_FANCYPATHING - if (it.pathcurrent) - pathlib_deletepath(it.pathcurrent.owner); + if (it.pathcurrent) { + pathlib_deletepath(it.pathcurrent.owner); + } #endif - it.pathcurrent = NULL; + it.pathcurrent = NULL; } METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it)) { - it.ticrate = 0.05; - - // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn. - if(it.move_movetype == MOVETYPE_WALK) - { - if(it.pos1) - setorigin(it, it.pos1); - if(it.pos2) - it.angles = it.pos2; - } - - it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; - it.aim_flags = TFL_AIM_LEAD; - it.turret_flags |= TUR_FLAG_HITSCAN; - - it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; - it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; - it.iscreature = true; - it.teleportable = TELEPORT_NORMAL; - if(!it.damagedbycontents) - IL_PUSH(g_damagedbycontents, it); - it.damagedbycontents = true; - it.solid = SOLID_SLIDEBOX; - it.takedamage = DAMAGE_AIM; - if(it.move_movetype != MOVETYPE_WALK) - { - setorigin(it, it.origin); - tracebox(it.origin + '0 0 128', it.mins, it.maxs, it.origin - '0 0 10000', MOVE_NORMAL, it); - setorigin(it, trace_endpos + '0 0 4'); - it.pos1 = it.origin; - it.pos2 = it.angles; - } - set_movetype(it, MOVETYPE_WALK); - it.idle_aim = '0 0 0'; - it.turret_firecheckfunc = walker_firecheck; - - if (it.target != "") - InitializeEntity(it, walker_findtarget, INITPRIO_FINDTARGET); + it.ticrate = 0.05; + + // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn. + if (it.move_movetype == MOVETYPE_WALK) { + if (it.pos1) { + setorigin(it, it.pos1); + } + if (it.pos2) { + it.angles = it.pos2; + } + } + + it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE; + it.aim_flags = TFL_AIM_LEAD; + it.turret_flags |= TUR_FLAG_HITSCAN; + + it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; + it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS; + it.iscreature = true; + it.teleportable = TELEPORT_NORMAL; + if (!it.damagedbycontents) { + IL_PUSH(g_damagedbycontents, it); + } + it.damagedbycontents = true; + it.solid = SOLID_SLIDEBOX; + it.takedamage = DAMAGE_AIM; + if (it.move_movetype != MOVETYPE_WALK) { + setorigin(it, it.origin); + tracebox(it.origin + '0 0 128', it.mins, it.maxs, it.origin - '0 0 10000', MOVE_NORMAL, it); + setorigin(it, trace_endpos + '0 0 4'); + it.pos1 = it.origin; + it.pos2 = it.angles; + } + set_movetype(it, MOVETYPE_WALK); + it.idle_aim = '0 0 0'; + it.turret_firecheckfunc = walker_firecheck; + + if (it.target != "") { + InitializeEntity(it, walker_findtarget, INITPRIO_FINDTARGET); + } } #endif // SVQC @@ -615,29 +604,32 @@ METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it)) void walker_draw(entity this) { - float dt; - - dt = time - this.move_time; - this.move_time = time; - if(dt <= 0) - return; - - fixedmakevectors(this.angles); - movelib_groundalign4point(this, 300, 100, 0.25, 45); - setorigin(this, this.origin + this.velocity * dt); - this.tur_head.angles += dt * this.tur_head.avelocity; - - if (this.health < 127) - if(random() < 0.15) - te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); + float dt; + + dt = time - this.move_time; + this.move_time = time; + if (dt <= 0) { + return; + } + + fixedmakevectors(this.angles); + movelib_groundalign4point(this, 300, 100, 0.25, 45); + setorigin(this, this.origin + this.velocity * dt); + this.tur_head.angles += dt * this.tur_head.avelocity; + + if (this.health < 127) { + if (random() < 0.15) { + te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); + } + } } - METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it)) - { - it.gravity = 1; - set_movetype(it, MOVETYPE_BOUNCE); - it.move_time = time; - it.draw = walker_draw; - } +METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it)) +{ + it.gravity = 1; + set_movetype(it, MOVETYPE_BOUNCE); + it.move_time = time; + it.draw = walker_draw; +} #endif // CSQC diff --git a/qcsrc/common/turrets/turret/walker.qh b/qcsrc/common/turrets/turret/walker.qh index 1c923cad7..adec3cf3a 100644 --- a/qcsrc/common/turrets/turret/walker.qh +++ b/qcsrc/common/turrets/turret/walker.qh @@ -1,6 +1,6 @@ #pragma once -//#define WALKER_FANCYPATHING +// #define WALKER_FANCYPATHING #include "walker_weapon.qh" @@ -13,6 +13,6 @@ CLASS(WalkerTurret, Turret) /* head_model */ ATTRIB_STRZONE(WalkerTurret, head_model, string, strcat("models/turrets/", "walker_head_minigun.md3")); /* netname */ ATTRIB(WalkerTurret, netname, string, "walker"); /* fullname */ ATTRIB(WalkerTurret, turret_name, string, _("Walker Turret")); - ATTRIB(WalkerTurret, m_weapon, Weapon, WEP_WALKER); + ATTRIB(WalkerTurret, m_weapon, Weapon, WEP_WALKER); ENDCLASS(WalkerTurret) REGISTER_TURRET(WALKER, NEW(WalkerTurret)); diff --git a/qcsrc/common/turrets/turret/walker_weapon.qc b/qcsrc/common/turrets/turret/walker_weapon.qc index b418ce40d..87157a4c6 100644 --- a/qcsrc/common/turrets/turret/walker_weapon.qc +++ b/qcsrc/common/turrets/turret/walker_weapon.qc @@ -3,22 +3,24 @@ #ifdef SVQC SOUND(WalkerTurretAttack_FIRE, W_Sound("electro_fire")); -METHOD(WalkerTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - if (fire & 1) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { - if (isPlayer) { - turret_initparams(actor); - W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_WalkerTurretAttack_FIRE, CH_WEAPON_B, 0); - actor.tur_shotdir_updated = w_shotdir; - actor.tur_shotorg = w_shotorg; - actor.tur_head = actor; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); - } - sound (actor, CH_WEAPON_A, SND_UZI_FIRE, VOL_BASE, ATTEN_NORM); - fireBullet (actor, weaponentity, actor.tur_shotorg, actor.tur_shotdir_updated, actor.shot_spread, 0, actor.shot_dmg, actor.shot_force, DEATH_TURRET_WALK_GUN.m_id, 0); - Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); - } +METHOD(WalkerTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + if (fire & 1) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) { + if (isPlayer) { + turret_initparams(actor); + W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_WalkerTurretAttack_FIRE, CH_WEAPON_B, 0); + actor.tur_shotdir_updated = w_shotdir; + actor.tur_shotorg = w_shotorg; + actor.tur_head = actor; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready); + } + sound(actor, CH_WEAPON_A, SND_UZI_FIRE, VOL_BASE, ATTEN_NORM); + fireBullet(actor, weaponentity, actor.tur_shotorg, actor.tur_shotdir_updated, actor.shot_spread, 0, actor.shot_dmg, actor.shot_force, DEATH_TURRET_WALK_GUN.m_id, 0); + Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, actor.tur_shotorg, actor.tur_shotdir_updated * 1000, 1); + } + } } #endif diff --git a/qcsrc/common/turrets/util.qc b/qcsrc/common/turrets/util.qc index d4cbb4fb1..0c33b555e 100644 --- a/qcsrc/common/turrets/util.qc +++ b/qcsrc/common/turrets/util.qc @@ -8,8 +8,7 @@ */ float turret_tag_fire_update(entity this) { - if(!this.tur_head) - { + if (!this.tur_head) { LOG_DEBUG("Call to turret_tag_fire_update with this.tur_head missing!"); this.tur_shotorg = '0 0 0'; return false; @@ -24,8 +23,7 @@ float turret_tag_fire_update(entity this) /* * Railgun-like beam, but has thickness and suppots slowing of target */ -void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax, - float bforce, float f_dmg, float f_velfactor, int deathtype) +void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax, float bforce, float f_dmg, float f_velfactor, int deathtype) { vector hitloc, force, endpoint, dir; @@ -39,16 +37,17 @@ void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax // trace multiple times until we hit a wall, each obstacle will be made unsolid. // note down which entities were hit so we can damage them later - while (1) - { + while (1) { tracebox(start, smin, smax, end, false, this); // if it is NULL we can't hurt it so stop now - if (trace_ent == NULL || trace_fraction == 1) + if (trace_ent == NULL || trace_fraction == 1) { break; + } - if (trace_ent.solid == SOLID_BSP) + if (trace_ent.solid == SOLID_BSP) { break; + } // make the entity non-solid so we can hit the next one trace_ent.railgunhit = true; @@ -65,8 +64,7 @@ void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax // find all the entities the railgun hit and restore their solid state ent = findfloat(NULL, railgunhit, true); - while (ent) - { + while (ent) { // restore their solid type ent.solid = ent.railgunhitsolidbackup; ent = findfloat(ent, railgunhit, true); @@ -74,8 +72,7 @@ void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax // find all the entities the railgun hit and hurt them ent = findfloat(NULL, railgunhit, true); - while (ent) - { + while (ent) { // get the details we need to call the damage function hitloc = ent.railgunhitloc; ent.railgunhitloc = '0 0 0'; @@ -83,11 +80,10 @@ void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax ent.railgunhit = false; // apply the damage - if (ent.takedamage) - { - Damage (ent, this, this, f_dmg, deathtype, hitloc, force); + if (ent.takedamage) { + Damage(ent, this, this, f_dmg, deathtype, hitloc, force); ent.velocity = ent.velocity * f_velfactor; - //ent.alpha = 0.25 + random() * 0.75; + // ent.alpha = 0.25 + random() * 0.75; } // advance to the next entity @@ -99,22 +95,23 @@ void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax #ifdef TURRET_DEBUG void marker_think(entity this, ) { - if(this.cnt) - if(this.cnt < time) - { - setthink(this, SUB_Remove); - this.nextthink = time; - return; + if (this.cnt) { + if (this.cnt < time) { + setthink(this, SUB_Remove); + this.nextthink = time; + return; + } } this.frame += 1; - if(this.frame > 29) + if (this.frame > 29) { this.frame = 0; + } this.nextthink = time; } -void mark_error(vector where,float lifetime) +void mark_error(vector where, float lifetime) { entity err = new(error_marker); setmodel(err, MDL_MARKER); @@ -123,11 +120,12 @@ void mark_error(vector where,float lifetime) setthink(err, marker_think); err.nextthink = time; err.skin = 0; - if(lifetime) + if (lifetime) { err.cnt = lifetime + time; + } } -void mark_info(vector where,float lifetime) +void mark_info(vector where, float lifetime) { entity err = spawn(info_marker); setmodel(err, MDL_MARKER); @@ -136,11 +134,12 @@ void mark_info(vector where,float lifetime) setthink(err, marker_think); err.nextthink = time; err.skin = 1; - if(lifetime) + if (lifetime) { err.cnt = lifetime + time; + } } -entity mark_misc(vector where,float lifetime) +entity mark_misc(vector where, float lifetime) { entity err = spawn(mark_misc); setmodel(err, MDL_MARKER); @@ -149,8 +148,9 @@ entity mark_misc(vector where,float lifetime) setthink(err, marker_think); err.nextthink = time; err.skin = 3; - if(lifetime) + if (lifetime) { err.cnt = lifetime + time; + } return err; } @@ -166,9 +166,9 @@ void paint_target(entity onwho, float f_size, vector v_color, float f_time) e = spawn(); setmodel(e, MDL_TUR_C512); // precision set above - e.scale = (f_size/512); - //setsize(e, '0 0 0', '0 0 0'); - //setattachment(e,onwho,""); + e.scale = (f_size / 512); + // setsize(e, '0 0 0', '0 0 0'); + // setattachment(e,onwho,""); setorigin(e, onwho.origin + '0 0 1'); e.alpha = 0.15; set_movetype(e, MOVETYPE_FLY); @@ -176,7 +176,7 @@ void paint_target(entity onwho, float f_size, vector v_color, float f_time) e.velocity = (v_color * 32); // + '0 0 1' * 64; e.colormod = v_color; - SUB_SetFade(e,time,f_time); + SUB_SetFade(e, time, f_time); } void paint_target2(entity onwho, float f_size, vector v_color, float f_time) @@ -185,7 +185,7 @@ void paint_target2(entity onwho, float f_size, vector v_color, float f_time) e = spawn(); setmodel(e, MDL_TUR_C512); // precision set above - e.scale = (f_size/512); + e.scale = (f_size / 512); setsize(e, '0 0 0', '0 0 0'); setorigin(e, onwho.origin + '0 0 1'); @@ -196,7 +196,7 @@ void paint_target2(entity onwho, float f_size, vector v_color, float f_time) e.avelocity_x = -128; e.colormod = v_color; - SUB_SetFade(e,time,f_time); + SUB_SetFade(e, time, f_time); } void paint_target3(vector where, float f_size, vector v_color, float f_time) @@ -204,13 +204,13 @@ void paint_target3(vector where, float f_size, vector v_color, float f_time) entity e; e = spawn(); setmodel(e, MDL_TUR_C512); // precision set above - e.scale = (f_size/512); + e.scale = (f_size / 512); setsize(e, '0 0 0', '0 0 0'); setorigin(e, where + '0 0 1'); set_movetype(e, MOVETYPE_NONE); e.velocity = '0 0 0'; e.colormod = v_color; - SUB_SetFade(e,time,f_time); + SUB_SetFade(e, time, f_time); } #endif diff --git a/qcsrc/common/vehicles/cl_vehicles.qc b/qcsrc/common/vehicles/cl_vehicles.qc index b2f87821e..119918f71 100644 --- a/qcsrc/common/vehicles/cl_vehicles.qc +++ b/qcsrc/common/vehicles/cl_vehicles.qc @@ -21,22 +21,23 @@ float alarm2time; void vehicle_alarm(entity e, int ch, Sound s0und) { - TC(Sound, s0und); - if(!autocvar_cl_vehicles_alarm) + TC(Sound, s0und); + if (!autocvar_cl_vehicles_alarm) { return; + } sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE); } void AuxiliaryXhair_Draw2D(entity this) { - if (scoreboard_active) + if (scoreboard_active) { return; + } vector pos = project_3d_to_2d(this.origin); - if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight)) - { + if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight)) { vector size = draw_getimagesize(this.axh_image) * autocvar_cl_vehicles_crosshair_size; pos.x -= 0.5 * size.x; pos.y -= 0.5 * size.y; @@ -44,46 +45,44 @@ void AuxiliaryXhair_Draw2D(entity this) drawpic(pos, this.axh_image, size, this.colormod, autocvar_crosshair_alpha * this.alpha, this.axh_drawflag); } - if(time - this.cnt > this.axh_fadetime) + if (time - this.cnt > this.axh_fadetime) { this.draw2d = func_null; + } } NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew) { int sf = ReadByte(); - int axh_id = bound(0, ReadByte(), MAX_AXH); + int axh_id = bound(0, ReadByte(), MAX_AXH); entity axh = AuxiliaryXhair[axh_id]; - if(axh == NULL || wasfreed(axh)) - { - axh = new(auxiliary_crosshair); - axh.draw2d = func_null; - axh.drawmask = MASK_NORMAL; - axh.axh_drawflag = DRAWFLAG_ADDITIVE; - axh.axh_fadetime = 0.1; - axh.axh_image = vCROSS_HINT; - axh.alpha = 1; + if (axh == NULL || wasfreed(axh)) { + axh = new(auxiliary_crosshair); + axh.draw2d = func_null; + axh.drawmask = MASK_NORMAL; + axh.axh_drawflag = DRAWFLAG_ADDITIVE; + axh.axh_fadetime = 0.1; + axh.axh_image = vCROSS_HINT; + axh.alpha = 1; AuxiliaryXhair[axh_id] = axh; IL_PUSH(g_drawables_2d, axh); } - if(sf & 2) - { + if (sf & 2) { axh.origin_x = ReadCoord(); axh.origin_y = ReadCoord(); axh.origin_z = ReadCoord(); } - if(sf & 4) - { + if (sf & 4) { axh.colormod_x = ReadByte() / 255; axh.colormod_y = ReadByte() / 255; axh.colormod_z = ReadByte() / 255; } - axh.cnt = time; - axh.draw2d = AuxiliaryXhair_Draw2D; + axh.cnt = time; + axh.draw2d = AuxiliaryXhair_Draw2D; return true; } @@ -94,17 +93,14 @@ NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew) // hud_id == 0 means we exited a vehicle, so stop alarm sound/s // note: HUD_NORMAL is set to 0 currently too, but we'll check both just in case - if(hud_id == 0 || hud_id == HUD_NORMAL) - { + if (hud_id == 0 || hud_id == HUD_NORMAL) { sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE); sound(this, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE); - for(int i = 0; i < MAX_AXH; ++i) - { + for (int i = 0; i < MAX_AXH; ++i) { entity axh = AuxiliaryXhair[i]; - if(axh != NULL && !wasfreed(axh)) - { + if (axh != NULL && !wasfreed(axh)) { AuxiliaryXhair[i] = NULL; delete(axh); } @@ -113,12 +109,12 @@ NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew) } // Init auxiliary crosshairs - for(int i = 0; i < MAX_AXH; ++i) - { + for (int i = 0; i < MAX_AXH; ++i) { entity axh = AuxiliaryXhair[i]; - if(axh != NULL && !wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?) + if (axh != NULL && !wasfreed(axh)) { // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?) delete(axh); + } axh = spawn(); axh.draw2d = func_null; @@ -131,24 +127,16 @@ NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew) IL_PUSH(g_drawables_2d, axh); } - if(hud_id == HUD_BUMBLEBEE_GUN) - { + if (hud_id == HUD_BUMBLEBEE_GUN) { AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun } else { Vehicle info = Vehicles_from(hud_id); - info.vr_setup(info, NULL); + info.vr_setup(info, NULL); } } -void Vehicles_drawHUD( - string vehicle, - string vehicleWeapon1, - string vehicleWeapon2, - string iconAmmo1, - vector colorAmmo1, - string iconAmmo2, - vector colorAmmo2) +void Vehicles_drawHUD(string vehicle, string vehicleWeapon1, string vehicleWeapon2, string iconAmmo1, vector colorAmmo1, string iconAmmo2, vector colorAmmo2) { // Initialize vector tmpSize = '0 0 0'; @@ -171,22 +159,23 @@ void Vehicles_drawHUD( // Frame string frame = strcat(hud_skin_path, "/vehicle_frame"); - if (precache_pic(frame) == "") + if (precache_pic(frame) == "") { frame = "gfx/hud/default/vehicle_frame"; + } vehicleHud_Size = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale; vehicleHud_Pos.x = (vid_conwidth - vehicleHud_Size.x) / 2; vehicleHud_Pos.y = vid_conheight - vehicleHud_Size.y; - if(teamplay && autocvar_hud_panel_bg_color_team) + if (teamplay && autocvar_hud_panel_bg_color_team) { drawpic(vehicleHud_Pos, frame, vehicleHud_Size, myteamcolors * autocvar_hud_panel_bg_color_team, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); - else + } else { drawpic(vehicleHud_Pos, frame, vehicleHud_Size, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); + } - if(!autocvar__vehicles_shownchasemessage && time < vh_notice_time) - { + if (!autocvar__vehicles_shownchasemessage && time < vh_notice_time) { float tmpblinkValue = 0.55 + sin(time * 3) * 0.45; - tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (96/256) - tmpSize.x; + tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (96 / 256) - tmpSize.x; tmpPos.y = vehicleHud_Pos.y; tmpSize = '1 1 1' * hud_fontsize; drawstring(tmpPos, sprintf(_("Press %s"), getcommandkey(_("drop weapon"), "dropweapon")), tmpSize, '1 0 0' + '0 1 1' * tmpblinkValue, hudAlpha, DRAWFLAG_NORMAL); @@ -198,21 +187,24 @@ void Vehicles_drawHUD( tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x / 3; tmpPos.y = vehicleHud_Pos.y; - if(health < 0.25) + if (health < 0.25) { drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL); - else + } else { drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL); + } - if(vehicleWeapon1) + if (vehicleWeapon1) { drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL); - if(vehicleWeapon2) + } + if (vehicleWeapon2) { drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL); + } drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL); // Health bar tmpSize.y = vehicleHud_Size.y / 2; - tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (32/768); + tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (32 / 768); tmpPos.y = vehicleHud_Pos.y; drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y); @@ -225,46 +217,43 @@ void Vehicles_drawHUD( drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL); // Ammo1 bar - tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480/768); + tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480 / 768); tmpPos.y = vehicleHud_Pos.y; - if(ammo1) + if (ammo1) { drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y); - else + } else { drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y); + } drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL); // Ammo2 bar tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2; - if(ammo2) + if (ammo2) { drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y); - else + } else { drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y); + } drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL); drawresetcliparea(); // Health icon - tmpSize.x = vehicleHud_Size.x * (80/768); - tmpSize.y = vehicleHud_Size.y * (80/256); - tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (64/768); - tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256); - - if(health < 0.25) - { - if(alarm1time < time) - { + tmpSize.x = vehicleHud_Size.x * (80 / 768); + tmpSize.y = vehicleHud_Size.y * (80 / 256); + tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (64 / 768); + tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48 / 256); + + if (health < 0.25) { + if (alarm1time < time) { alarm1time = time + 2; vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_VEH_ALARM); } drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); - } - else - { - if(alarm1time) - { + } else { + if (alarm1time) { vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_Null); alarm1time = 0; } @@ -274,19 +263,14 @@ void Vehicles_drawHUD( // Shield icon tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2; - if(shield < 0.25) - { - if(alarm2time < time) - { + if (shield < 0.25) { + if (alarm2time < time) { alarm2time = time + 1; vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_VEH_ALARM_SHIELD); } drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); - } - else - { - if(alarm2time) - { + } else { + if (alarm2time) { vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_Null); alarm2time = 0; } @@ -294,26 +278,26 @@ void Vehicles_drawHUD( } // Ammo1 icon - tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624/768); - tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256); + tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624 / 768); + tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48 / 256); - if(iconAmmo1) - { - if(ammo1) + if (iconAmmo1) { + if (ammo1) { drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL); - else + } else { drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL); + } } // Ammo2 icon tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2; - if(iconAmmo2) - { - if(ammo2) + if (iconAmmo2) { + if (ammo2) { drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL); - else + } else { drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL); + } } } @@ -323,15 +307,15 @@ void Vehicles_drawCrosshair(string crosshair) vector tmpPos = '0 0 0'; // Crosshair - if(crosshair) - { + if (crosshair) { tmpSize = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size; tmpPos.x = (vid_conwidth - tmpSize.x) / 2; tmpPos.y = (vid_conheight - tmpSize.y) / 2; vector wcross_color = '1 1 1'; - if(autocvar_cl_vehicles_crosshair_colorize) + if (autocvar_cl_vehicles_crosshair_colorize) { wcross_color = crosshair_getcolor(NULL, STAT(VEHICLESTAT_HEALTH)); + } drawpic(tmpPos, crosshair, tmpSize, wcross_color, autocvar_crosshair_alpha, DRAWFLAG_NORMAL); } diff --git a/qcsrc/common/vehicles/sv_vehicles.qh b/qcsrc/common/vehicles/sv_vehicles.qh index 22e2e4859..bfa33f836 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qh +++ b/qcsrc/common/vehicles/sv_vehicles.qh @@ -36,7 +36,7 @@ float autocvar_g_vehicles_weapon_damagerate = 2; .entity gun1; .entity gun2; .entity gun3; -.entity vehicle_shieldent; /// Entity to disply the shild effect on damage +.entity vehicle_shieldent; /// Entity to disply the shild effect on damage .entity vehicle; .entity vehicle_viewport; .entity vehicle_hudmodel; @@ -45,13 +45,13 @@ float autocvar_g_vehicles_weapon_damagerate = 2; .entity gunner1; .entity gunner2; -.float vehicle_health = _STAT(VEHICLESTAT_HEALTH); /// If ent is player this is 0..100 indicating precentage of health left on vehicle. If ent is vehile, this is the real health value. -.float vehicle_energy = _STAT(VEHICLESTAT_ENERGY); /// If ent is player this is 0..100 indicating precentage of energy left on vehicle. If ent is vehile, this is the real energy value. -.float vehicle_shield = _STAT(VEHICLESTAT_SHIELD); /// If ent is player this is 0..100 indicating precentage of shield left on vehicle. If ent is vehile, this is the real shield value. +.float vehicle_health = _STAT(VEHICLESTAT_HEALTH); /// If ent is player this is 0..100 indicating precentage of health left on vehicle. If ent is vehile, this is the real health value. +.float vehicle_energy = _STAT(VEHICLESTAT_ENERGY); /// If ent is player this is 0..100 indicating precentage of energy left on vehicle. If ent is vehile, this is the real energy value. +.float vehicle_shield = _STAT(VEHICLESTAT_SHIELD); /// If ent is player this is 0..100 indicating precentage of shield left on vehicle. If ent is vehile, this is the real shield value. -.float vehicle_ammo1 = _STAT(VEHICLESTAT_AMMO1); /// If ent is player this is 0..100 indicating percentage of primary ammo left UNLESS value is already stored in vehicle_energy. If ent is vehile, this is the real ammo1 value. +.float vehicle_ammo1 = _STAT(VEHICLESTAT_AMMO1); /// If ent is player this is 0..100 indicating percentage of primary ammo left UNLESS value is already stored in vehicle_energy. If ent is vehile, this is the real ammo1 value. .float vehicle_reload1 = _STAT(VEHICLESTAT_RELOAD1); /// If ent is player this is 0..100 indicating percentage of primary reload status. If ent is vehile, this is the real reload1 value. -.float vehicle_ammo2 = _STAT(VEHICLESTAT_AMMO2); /// If ent is player this is 0..100 indicating percentage of secondary ammo left. If ent is vehile, this is the real ammo2 value. +.float vehicle_ammo2 = _STAT(VEHICLESTAT_AMMO2); /// If ent is player this is 0..100 indicating percentage of secondary ammo left. If ent is vehile, this is the real ammo2 value. .float vehicle_reload2 = _STAT(VEHICLESTAT_RELOAD2); /// If ent is player this is 0..100 indicating percentage of secondary reload status. If ent is vehile, this is the real reload2 value. .float sound_nexttime; @@ -80,17 +80,17 @@ const int MAX_AXH = 4; .float lock_strength; .float lock_time; .float lock_soundtime; -const float DAMAGE_TARGETDRONE = 10; +const float DAMAGE_TARGETDRONE = 10; // vehicle functions -.void(int _spawnflag) vehicle_spawn; /// Vehicles custom fucntion to be efecuted when vehicle (re)spawns +.void(int _spawnflag) vehicle_spawn; /// Vehicles custom fucntion to be efecuted when vehicle (re) spawns .bool(entity this, int _imp) vehicles_impulse; .int vehicle_weapon2mode = _STAT(VEHICLESTAT_W2MODE); .void(entity this, int exit_flags) vehicle_exit; .bool(entity this, entity player) vehicle_enter; const int VHEF_NORMAL = 0; /// User pressed exit key const int VHEF_EJECT = 1; /// User pressed exit key 3 times fast (not implemented) or vehile is dying -const int VHEF_RELEASE = 2; /// Release ownership, client possibly allready dissconnected / went spec / changed team / used "kill" (not implemented) +const int VHEF_RELEASE = 2; /// Release ownership, client possibly allready dissconnected / went spec / changed team / used "kill" (not implemented) float force_fromtag_power; float force_fromtag_normpower; @@ -99,7 +99,7 @@ vector force_fromtag_origin; float vehicles_exit_running; // macros -#define VEHICLE_UPDATE_PLAYER(ply,vehi,fld,vhname) \ +#define VEHICLE_UPDATE_PLAYER(ply, vehi, fld, vhname) \ ply.vehicle_##fld = (vehi.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100 .float vehicle_enter_delay; // prevent players jumping to and from vehicles instantly @@ -111,6 +111,9 @@ bool vehicles_crushable(entity e); float vehicle_altitude(entity this, float amax); IntrusiveList g_vehicle_returners; -STATIC_INIT(g_vehicle_returners) { g_vehicle_returners = IL_NEW(); } +STATIC_INIT(g_vehicle_returners) +{ + g_vehicle_returners = IL_NEW(); +} #endif diff --git a/qcsrc/common/vehicles/vehicle/bumblebee.qc b/qcsrc/common/vehicles/vehicle/bumblebee.qc index 018e1a17d..9e8d7b38b 100644 --- a/qcsrc/common/vehicles/vehicle/bumblebee.qc +++ b/qcsrc/common/vehicles/vehicle/bumblebee.qc @@ -75,24 +75,21 @@ bool bumblebee_gunner_frame(entity this, float dt) return = true; // this isn't technically a vehicle (yet), let's not do frame functions on it (yet) - //vehicles_frame(gun, player); + // vehicles_frame(gun, player); vehic.solid = SOLID_NOT; - //setorigin(this, vehic.origin); + // setorigin(this, vehic.origin); this.velocity = vehic.velocity; float _in, _out; vehic.angles_x *= -1; makevectors(vehic.angles); vehic.angles_x *= -1; - if(gun == vehic.gun1) - { + if (gun == vehic.gun1) { _in = autocvar_g_vehicle_bumblebee_cannon_turnlimit_in; _out = autocvar_g_vehicle_bumblebee_cannon_turnlimit_out; setorigin(this, vehic.origin + v_up * -16 + v_forward * -16 + v_right * 128); - } - else - { + } else { _in = autocvar_g_vehicle_bumblebee_cannon_turnlimit_out; _out = autocvar_g_vehicle_bumblebee_cannon_turnlimit_in; setorigin(this, vehic.origin + v_up * -16 + v_forward * -16 + v_right * -128); @@ -103,32 +100,33 @@ bool bumblebee_gunner_frame(entity this, float dt) vector _ct = trace_endpos; vector ad; - if(autocvar_g_vehicle_bumblebee_cannon_lock) - { - if(gun.lock_time < time) + if (autocvar_g_vehicle_bumblebee_cannon_lock) { + if (gun.lock_time < time) { gun.enemy = NULL; + } - if(trace_ent) - if(trace_ent.move_movetype) - if(trace_ent.takedamage) - if(!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent)) - { - if(DIFF_TEAM(trace_ent, this)) - { + if (trace_ent) { + if (trace_ent.move_movetype) { + if (trace_ent.takedamage) { + if (!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent)) { + if (DIFF_TEAM(trace_ent, this)) { gun.enemy = trace_ent; gun.lock_time = time + 5; } } + } + } + } } - if(gun.enemy) - { + if (gun.enemy) { float distance, impact_time; vector vf = real_origin(gun.enemy); vector _vel = gun.enemy.velocity; - if(gun.enemy.move_movetype == MOVETYPE_WALK) + if (gun.enemy.move_movetype == MOVETYPE_WALK) { _vel.z *= 0.1; + } ad = vf; @@ -140,38 +138,41 @@ bool bumblebee_gunner_frame(entity this, float dt) UpdateAuxiliaryXhair(this, ad, '1 0 1', 1); vehicle_aimturret(vehic, trace_endpos, gun, "fire", - autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up, - _out * -1, _in, autocvar_g_vehicle_bumblebee_cannon_turnspeed); - - } - else + autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up, + _out * -1, _in, autocvar_g_vehicle_bumblebee_cannon_turnspeed); + } else { vehicle_aimturret(vehic, _ct, gun, "fire", - autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up, - _out * -1, _in, autocvar_g_vehicle_bumblebee_cannon_turnspeed); - - if(!forbidWeaponUse(this)) - if(PHYS_INPUT_BUTTON_ATCK(this)) - if(time > gun.attack_finished_single[0]) - if(gun.vehicle_energy >= autocvar_g_vehicle_bumblebee_cannon_cost) - { - gun.vehicle_energy -= autocvar_g_vehicle_bumblebee_cannon_cost; - bumblebee_fire_cannon(vehic, gun, "fire", this); - gun.delay = time; - gun.attack_finished_single[0] = time + autocvar_g_vehicle_bumblebee_cannon_refire; + autocvar_g_vehicle_bumblebee_cannon_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_cannon_pitchlimit_up, + _out * -1, _in, autocvar_g_vehicle_bumblebee_cannon_turnspeed); + } + + if (!forbidWeaponUse(this)) { + if (PHYS_INPUT_BUTTON_ATCK(this)) { + if (time > gun.attack_finished_single[0]) { + if (gun.vehicle_energy >= autocvar_g_vehicle_bumblebee_cannon_cost) { + gun.vehicle_energy -= autocvar_g_vehicle_bumblebee_cannon_cost; + bumblebee_fire_cannon(vehic, gun, "fire", this); + gun.delay = time; + gun.attack_finished_single[0] = time + autocvar_g_vehicle_bumblebee_cannon_refire; + } } + } + } VEHICLE_UPDATE_PLAYER(this, vehic, health, bumblebee); - if(vehic.vehicle_flags & VHF_HASSHIELD) + if (vehic.vehicle_flags & VHF_HASSHIELD) { VEHICLE_UPDATE_PLAYER(this, vehic, shield, bumblebee); + } ad = gettaginfo(gun, gettagindex(gun, "fire")); traceline(ad, ad + v_forward * max_shot_distance, MOVE_NORMAL, gun); - UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload1) + ('0 1 0' *(1 - this.vehicle_reload1)), 0); + UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload1) + ('0 1 0' * (1 - this.vehicle_reload1)), 0); - if(vehic.owner) - UpdateAuxiliaryXhair(vehic.owner, trace_endpos, ('1 0 0' * this.vehicle_reload1) + ('0 1 0' *(1 - this.vehicle_reload1)), ((this == vehic.gunner1) ? 1 : 2)); + if (vehic.owner) { + UpdateAuxiliaryXhair(vehic.owner, trace_endpos, ('1 0 0' * this.vehicle_reload1) + ('0 1 0' * (1 - this.vehicle_reload1)), ((this == vehic.gunner1) ? 1 : 2)); + } vehic.solid = SOLID_BBOX; PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false; @@ -180,25 +181,26 @@ bool bumblebee_gunner_frame(entity this, float dt) vector bumblebee_gunner_findgoodexit(vector prefer_spot, entity gunner, entity player) { - //vector exitspot; + // vector exitspot; float mysize; tracebox(gunner.origin + '0 0 32', STAT(PL_MIN, player), STAT(PL_MAX, player), prefer_spot, MOVE_NORMAL, player); - if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid) + if (trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid) { return prefer_spot; + } mysize = 1.5 * vlen(STAT(PL_MAX, player) - STAT(PL_MIN, player)); // can't use gunner's size, as they don't have a size float i; vector v, v2; v2 = 0.5 * (gunner.absmin + gunner.absmax); - for(i = 0; i < 100; ++i) - { + for (i = 0; i < 100; ++i) { v = randomvec(); v_z = 0; v = v2 + normalize(v) * mysize; tracebox(v2, STAT(PL_MIN, player), STAT(PL_MAX, player), v, MOVE_NORMAL, player); - if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid) + if (trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid) { return v; + } } return prefer_spot; // this should be considered a fallback?! @@ -210,8 +212,7 @@ void bumblebee_gunner_exit(entity this, int _exitflag) entity gunner = this; entity vehic = gunner.owner; - if(IS_REAL_CLIENT(player)) - { + if (IS_REAL_CLIENT(player)) { msg_entity = player; WriteByte(MSG_ONE, SVC_SETVIEWPORT); WriteEntity(MSG_ONE, player); @@ -234,9 +235,8 @@ void bumblebee_gunner_exit(entity this, int _exitflag) player.view_ofs = STAT(PL_VIEW_OFS, player); player.event_damage = PlayerDamage; player.hud = HUD_NORMAL; - player.teleportable = TELEPORT_NORMAL; - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + player.teleportable = TELEPORT_NORMAL; + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; player.(weaponentity).m_switchweapon = gunner.(weaponentity).m_switchweapon; delete(gunner.(weaponentity)); @@ -245,8 +245,8 @@ void bumblebee_gunner_exit(entity this, int _exitflag) fixedmakevectors(vehic.angles); - if(player == vehic.gunner1) { vehic.gunner1 = NULL; } - if(player == vehic.gunner2) { vehic.gunner2 = NULL; v_right *= -1; } + if (player == vehic.gunner1) { vehic.gunner1 = NULL; } + if (player == vehic.gunner2) { vehic.gunner2 = NULL; v_right *= -1; } vector spot = real_origin(gunner); spot = spot + v_up * 128 + v_forward * 300 + v_right * 150; @@ -270,48 +270,46 @@ bool bumblebee_gunner_enter(entity this, entity player) entity vehic = this; entity gunner = NULL; - if(!vehic.gunner1 && !vehic.gunner2 && ((time >= vehic.gun1.phase) + (time >= vehic.gun2.phase)) == 2) - { + if (!vehic.gunner1 && !vehic.gunner2 && ((time >= vehic.gun1.phase) + (time >= vehic.gun2.phase)) == 2) { // we can have some fun vector v1 = gettaginfo(vehic, gettagindex(vehic, "cannon_right")); vector v2 = gettaginfo(vehic, gettagindex(vehic, "cannon_left")); - if(vlen2(player.origin - v1) < vlen2(player.origin - v2)) - { + if (vlen2(player.origin - v1) < vlen2(player.origin - v2)) { gunner = vehic.gun1; vehic.gunner1 = player; - } - else - { + } else { gunner = vehic.gun2; vehic.gunner2 = player; } - } - else if(!vehic.gunner1 && time >= vehic.gun1.phase) { gunner = vehic.gun1; vehic.gunner1 = player; } - else if(!vehic.gunner2 && time >= vehic.gun2.phase) { gunner = vehic.gun2; vehic.gunner2 = player; } - else { LOG_TRACE("Vehicle is full, fail"); return false; } - - player.vehicle = gunner; - player.angles = vehic.angles; - player.takedamage = DAMAGE_NO; - player.solid = SOLID_NOT; - player.alpha = -1; + } else if (!vehic.gunner1 && time >= vehic.gun1.phase) { + gunner = vehic.gun1; + vehic.gunner1 = player; + } else if (!vehic.gunner2 && time >= vehic.gun2.phase) { + gunner = vehic.gun2; + vehic.gunner2 = player; + } else { LOG_TRACE("Vehicle is full, fail"); return false; } + + player.vehicle = gunner; + player.angles = vehic.angles; + player.takedamage = DAMAGE_NO; + player.solid = SOLID_NOT; + player.alpha = -1; set_movetype(player, MOVETYPE_NOCLIP); - player.event_damage = func_null; - player.view_ofs = '0 0 0'; - player.hud = gunner.hud; - player.teleportable = false; - player.PlayerPhysplug = gunner.PlayerPhysplug; - player.vehicle_ammo1 = vehic.vehicle_ammo1; - player.vehicle_ammo2 = vehic.vehicle_ammo2; - player.vehicle_reload1 = vehic.vehicle_reload1; - player.vehicle_reload2 = vehic.vehicle_reload2; - player.vehicle_energy = vehic.vehicle_energy; + player.event_damage = func_null; + player.view_ofs = '0 0 0'; + player.hud = gunner.hud; + player.teleportable = false; + player.PlayerPhysplug = gunner.PlayerPhysplug; + player.vehicle_ammo1 = vehic.vehicle_ammo1; + player.vehicle_ammo2 = vehic.vehicle_ammo2; + player.vehicle_reload1 = vehic.vehicle_reload1; + player.vehicle_reload2 = vehic.vehicle_reload2; + player.vehicle_energy = vehic.vehicle_energy; UNSET_ONGROUND(player); RemoveGrapplingHooks(player); - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; gunner.(weaponentity) = new(temp_wepent); @@ -320,16 +318,15 @@ bool bumblebee_gunner_enter(entity this, entity player) gunner.vehicle_exit = bumblebee_gunner_exit; gunner.vehicle_hudmodel.viewmodelforclient = player; - if(IS_REAL_CLIENT(player)) - { + if (IS_REAL_CLIENT(player)) { msg_entity = player; - WriteByte(MSG_ONE, SVC_SETVIEWPORT); - WriteEntity(MSG_ONE, gunner.vehicle_viewport); + WriteByte(MSG_ONE, SVC_SETVIEWPORT); + WriteEntity(MSG_ONE, gunner.vehicle_viewport); - WriteByte(MSG_ONE, SVC_SETVIEWANGLES); - WriteAngle(MSG_ONE, gunner.angles_x + vehic.angles_x); // tilt - WriteAngle(MSG_ONE, gunner.angles_y + vehic.angles_y); // yaw - WriteAngle(MSG_ONE, 0); // roll + WriteByte(MSG_ONE, SVC_SETVIEWANGLES); + WriteAngle(MSG_ONE, gunner.angles_x + vehic.angles_x); // tilt + WriteAngle(MSG_ONE, gunner.angles_y + vehic.angles_y); // yaw + WriteAngle(MSG_ONE, 0); // roll } CSQCVehicleSetup(player, player.hud); @@ -341,13 +338,14 @@ bool bumblebee_gunner_enter(entity this, entity player) bool vehicles_valid_pilot(entity this, entity toucher) { - if(IS_BOT_CLIENT(toucher) && !autocvar_g_vehicles_allow_bots) + if (IS_BOT_CLIENT(toucher) && !autocvar_g_vehicles_allow_bots) { return false; + } - if((!IS_PLAYER(toucher)) - || (IS_DEAD(toucher)) - || (toucher.vehicle) - || (DIFF_TEAM(toucher, this)) + if ((!IS_PLAYER(toucher)) + || (IS_DEAD(toucher)) + || (toucher.vehicle) + || (DIFF_TEAM(toucher, this)) ) { return false; } return true; @@ -355,21 +353,21 @@ bool vehicles_valid_pilot(entity this, entity toucher) void bumblebee_touch(entity this, entity toucher) { - if(autocvar_g_vehicles_enter) { return; } + if (autocvar_g_vehicles_enter) { return; } - if(this.gunner1 != NULL && this.gunner2 != NULL) - { + if (this.gunner1 != NULL && this.gunner2 != NULL) { vehicles_touch(this, toucher); return; } - if(vehicles_valid_pilot(this, toucher)) - { + if (vehicles_valid_pilot(this, toucher)) { float phase_time = (time >= this.gun1.phase) + (time >= this.gun2.phase); - if(time >= toucher.vehicle_enter_delay && phase_time) - if(bumblebee_gunner_enter(this, toucher)) - return; + if (time >= toucher.vehicle_enter_delay && phase_time) { + if (bumblebee_gunner_enter(this, toucher)) { + return; + } + } } vehicles_touch(this, toucher); @@ -377,23 +375,27 @@ void bumblebee_touch(entity this, entity toucher) void bumblebee_regen(entity this, float dt) { - if(this.gun1.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time) + if (this.gun1.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time) { this.gun1.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo, - this.gun1.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * dt); + this.gun1.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * dt); + } - if(this.gun2.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time) + if (this.gun2.delay + autocvar_g_vehicle_bumblebee_cannon_ammo_regen_pause < time) { this.gun2.vehicle_energy = min(autocvar_g_vehicle_bumblebee_cannon_ammo, - this.gun2.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * dt); + this.gun2.vehicle_energy + autocvar_g_vehicle_bumblebee_cannon_ammo_regen * dt); + } - if(this.vehicle_flags & VHF_SHIELDREGEN) + if (this.vehicle_flags & VHF_SHIELDREGEN) { vehicles_regen(this, this.dmg_time, vehicle_shield, autocvar_g_vehicle_bumblebee_shield, autocvar_g_vehicle_bumblebee_shield_regen_pause, autocvar_g_vehicle_bumblebee_shield_regen, dt, true); + } - if(this.vehicle_flags & VHF_HEALTHREGEN) + if (this.vehicle_flags & VHF_HEALTHREGEN) { vehicles_regen(this, this.dmg_time, vehicle_health, autocvar_g_vehicle_bumblebee_health, autocvar_g_vehicle_bumblebee_health_regen_pause, autocvar_g_vehicle_bumblebee_health_regen, dt, false); + } - if(this.vehicle_flags & VHF_ENERGYREGEN) + if (this.vehicle_flags & VHF_ENERGYREGEN) { vehicles_regen(this, this.wait, vehicle_energy, autocvar_g_vehicle_bumblebee_energy, autocvar_g_vehicle_bumblebee_energy_regen_pause, autocvar_g_vehicle_bumblebee_energy_regen, dt, false); - + } } bool bumblebee_pilot_frame(entity this, float dt) @@ -401,8 +403,7 @@ bool bumblebee_pilot_frame(entity this, float dt) entity vehic = this.vehicle; return = true; - if(game_stopped) - { + if (game_stopped) { vehic.solid = SOLID_NOT; vehic.takedamage = DAMAGE_NO; set_movetype(vehic, MOVETYPE_NONE); @@ -411,8 +412,7 @@ bool bumblebee_pilot_frame(entity this, float dt) vehicles_frame(vehic, this); - if(IS_DEAD(vehic)) - { + if (IS_DEAD(vehic)) { PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false; return; } @@ -425,24 +425,25 @@ bool bumblebee_pilot_frame(entity this, float dt) vector newvel = vectoangles(normalize(trace_endpos - vehic.origin + '0 0 32')); vang.x *= -1; newvel.x *= -1; - if(newvel.x > 180) newvel.x -= 360; - if(newvel.x < -180) newvel.x += 360; - if(newvel.y > 180) newvel.y -= 360; - if(newvel.y < -180) newvel.y += 360; + if (newvel.x > 180) { newvel.x -= 360; } + if (newvel.x < -180) { newvel.x += 360; } + if (newvel.y > 180) { newvel.y -= 360; } + if (newvel.y < -180) { newvel.y += 360; } float ftmp = shortangle_f(this.v_angle.y - vang.y, vang.y); - if(ftmp > 180) ftmp -= 360; - if(ftmp < -180) ftmp += 360; + if (ftmp > 180) { ftmp -= 360; } + if (ftmp < -180) { ftmp += 360; } vehic.avelocity_y = bound(-autocvar_g_vehicle_bumblebee_turnspeed, ftmp + vehic.avelocity.y * 0.9, autocvar_g_vehicle_bumblebee_turnspeed); // Pitch ftmp = 0; - if(CS(this).movement.x > 0 && vang.x < autocvar_g_vehicle_bumblebee_pitchlimit) + if (CS(this).movement.x > 0 && vang.x < autocvar_g_vehicle_bumblebee_pitchlimit) { ftmp = 4; - else if(CS(this).movement.x < 0 && vang.x > -autocvar_g_vehicle_bumblebee_pitchlimit) + } else if (CS(this).movement.x < 0 && vang.x > -autocvar_g_vehicle_bumblebee_pitchlimit) { ftmp = -8; + } - newvel.x = bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel.x , autocvar_g_vehicle_bumblebee_pitchlimit); + newvel.x = bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel.x, autocvar_g_vehicle_bumblebee_pitchlimit); ftmp = vang.x - bound(-autocvar_g_vehicle_bumblebee_pitchlimit, newvel.x + ftmp, autocvar_g_vehicle_bumblebee_pitchlimit); vehic.avelocity_x = bound(-autocvar_g_vehicle_bumblebee_pitchspeed, ftmp + vehic.avelocity.x * 0.9, autocvar_g_vehicle_bumblebee_pitchspeed); @@ -453,143 +454,135 @@ bool bumblebee_pilot_frame(entity this, float dt) makevectors('0 1 0' * vehic.angles.y); newvel = vehic.velocity * -autocvar_g_vehicle_bumblebee_friction; - if(CS(this).movement.x != 0) - { - if(CS(this).movement.x > 0) + if (CS(this).movement.x != 0) { + if (CS(this).movement.x > 0) { newvel += v_forward * autocvar_g_vehicle_bumblebee_speed_forward; - else if(CS(this).movement.x < 0) + } else if (CS(this).movement.x < 0) { newvel -= v_forward * autocvar_g_vehicle_bumblebee_speed_forward; + } } - if(CS(this).movement.y != 0) - { - if(CS(this).movement.y < 0) + if (CS(this).movement.y != 0) { + if (CS(this).movement.y < 0) { newvel -= v_right * autocvar_g_vehicle_bumblebee_speed_strafe; - else if(CS(this).movement.y > 0) + } else if (CS(this).movement.y > 0) { newvel += v_right * autocvar_g_vehicle_bumblebee_speed_strafe; + } ftmp = newvel * v_right; ftmp *= dt * 0.1; vehic.angles_z = bound(-15, vehic.angles.z + ftmp, 15); - } - else - { + } else { vehic.angles_z *= 0.95; - if(vehic.angles.z >= -1 && vehic.angles.z <= -1) + if (vehic.angles.z >= -1 && vehic.angles.z <= -1) { vehic.angles_z = 0; + } } - if(PHYS_INPUT_BUTTON_CROUCH(this)) + if (PHYS_INPUT_BUTTON_CROUCH(this)) { newvel -= v_up * autocvar_g_vehicle_bumblebee_speed_down; - else if(PHYS_INPUT_BUTTON_JUMP(this)) + } else if (PHYS_INPUT_BUTTON_JUMP(this)) { newvel += v_up * autocvar_g_vehicle_bumblebee_speed_up; + } vehic.velocity += newvel * dt; this.velocity = CS(this).movement = vehic.velocity; - if(autocvar_g_vehicle_bumblebee_healgun_locktime) - { - if(vehic.tur_head.lock_time < time || IS_DEAD(vehic.tur_head.enemy) || STAT(FROZEN, vehic.tur_head.enemy)) + if (autocvar_g_vehicle_bumblebee_healgun_locktime) { + if (vehic.tur_head.lock_time < time || IS_DEAD(vehic.tur_head.enemy) || STAT(FROZEN, vehic.tur_head.enemy)) { vehic.tur_head.enemy = NULL; + } - if(trace_ent) - if(trace_ent.move_movetype) - if(trace_ent.takedamage) - if(!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent)) - { - if(teamplay) - { - if(trace_ent.team == this.team) - { - vehic.tur_head.enemy = trace_ent; - vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime; + if (trace_ent) { + if (trace_ent.move_movetype) { + if (trace_ent.takedamage) { + if (!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent)) { + if (teamplay) { + if (trace_ent.team == this.team) { + vehic.tur_head.enemy = trace_ent; + vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime; + } + } else { + vehic.tur_head.enemy = trace_ent; + vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime; + } + } } } - else - { - vehic.tur_head.enemy = trace_ent; - vehic.tur_head.lock_time = time + autocvar_g_vehicle_bumblebee_healgun_locktime; - } } - if(vehic.tur_head.enemy) - { + if (vehic.tur_head.enemy) { trace_endpos = real_origin(vehic.tur_head.enemy); UpdateAuxiliaryXhair(this, trace_endpos, '0 0.75 0', 0); } } vang = vehicle_aimturret(vehic, trace_endpos, vehic.gun3, "fire", - autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up, - autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides * -1, autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides, autocvar_g_vehicle_bumblebee_raygun_turnspeed); - - if(!forbidWeaponUse(this)) - if((PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this)) && (vehic.vehicle_energy > autocvar_g_vehicle_bumblebee_raygun_dps * PHYS_INPUT_FRAMETIME || autocvar_g_vehicle_bumblebee_raygun == 0)) - { - vehic.gun3.enemy.realowner = this; - vehic.gun3.enemy.effects &= ~EF_NODRAW; - - vehic.gun3.enemy.hook_start = gettaginfo(vehic.gun3, gettagindex(vehic.gun3, "fire")); - vehic.gun3.enemy.SendFlags |= BRG_START; - - traceline(vehic.gun3.enemy.hook_start, vehic.gun3.enemy.hook_start + v_forward * autocvar_g_vehicle_bumblebee_raygun_range, MOVE_NORMAL, vehic); - - if(trace_ent) - { - if(autocvar_g_vehicle_bumblebee_raygun) - { - Damage(trace_ent, vehic, this, autocvar_g_vehicle_bumblebee_raygun_dps * PHYS_INPUT_FRAMETIME, DEATH_GENERIC.m_id, trace_endpos, v_forward * autocvar_g_vehicle_bumblebee_raygun_fps * PHYS_INPUT_FRAMETIME); - vehic.vehicle_energy -= autocvar_g_vehicle_bumblebee_raygun_aps * PHYS_INPUT_FRAMETIME; - } - else - { - if(!IS_DEAD(trace_ent)) - if((teamplay && trace_ent.team == this.team) || !teamplay) - { - - if(IS_VEHICLE(trace_ent)) - { - if(autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.max_health) - trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * dt, trace_ent.tur_head.max_health); - - if(autocvar_g_vehicle_bumblebee_healgun_hps) - trace_ent.vehicle_health = min(trace_ent.vehicle_health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, trace_ent.max_health); - } - else if(IS_CLIENT(trace_ent)) - { - if(trace_ent.health <= autocvar_g_vehicle_bumblebee_healgun_hmax && autocvar_g_vehicle_bumblebee_healgun_hps) - trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, autocvar_g_vehicle_bumblebee_healgun_hmax); + autocvar_g_vehicle_bumblebee_raygun_pitchlimit_down * -1, autocvar_g_vehicle_bumblebee_raygun_pitchlimit_up, + autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides * -1, autocvar_g_vehicle_bumblebee_raygun_turnlimit_sides, autocvar_g_vehicle_bumblebee_raygun_turnspeed); + + if (!forbidWeaponUse(this)) { + if ((PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this)) && (vehic.vehicle_energy > autocvar_g_vehicle_bumblebee_raygun_dps * PHYS_INPUT_FRAMETIME || autocvar_g_vehicle_bumblebee_raygun == 0)) { + vehic.gun3.enemy.realowner = this; + vehic.gun3.enemy.effects &= ~EF_NODRAW; + + vehic.gun3.enemy.hook_start = gettaginfo(vehic.gun3, gettagindex(vehic.gun3, "fire")); + vehic.gun3.enemy.SendFlags |= BRG_START; + + traceline(vehic.gun3.enemy.hook_start, vehic.gun3.enemy.hook_start + v_forward * autocvar_g_vehicle_bumblebee_raygun_range, MOVE_NORMAL, vehic); + + if (trace_ent) { + if (autocvar_g_vehicle_bumblebee_raygun) { + Damage(trace_ent, vehic, this, autocvar_g_vehicle_bumblebee_raygun_dps * PHYS_INPUT_FRAMETIME, DEATH_GENERIC.m_id, trace_endpos, v_forward * autocvar_g_vehicle_bumblebee_raygun_fps * PHYS_INPUT_FRAMETIME); + vehic.vehicle_energy -= autocvar_g_vehicle_bumblebee_raygun_aps * PHYS_INPUT_FRAMETIME; + } else { + if (!IS_DEAD(trace_ent)) { + if ((teamplay && trace_ent.team == this.team) || !teamplay) { + if (IS_VEHICLE(trace_ent)) { + if (autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.max_health) { + trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * dt, trace_ent.tur_head.max_health); + } + + if (autocvar_g_vehicle_bumblebee_healgun_hps) { + trace_ent.vehicle_health = min(trace_ent.vehicle_health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, trace_ent.max_health); + } + } else if (IS_CLIENT(trace_ent)) { + if (trace_ent.health <= autocvar_g_vehicle_bumblebee_healgun_hmax && autocvar_g_vehicle_bumblebee_healgun_hps) { + trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, autocvar_g_vehicle_bumblebee_healgun_hmax); + } + + if (trace_ent.armorvalue <= autocvar_g_vehicle_bumblebee_healgun_amax && autocvar_g_vehicle_bumblebee_healgun_aps) { + trace_ent.armorvalue = min(trace_ent.armorvalue + autocvar_g_vehicle_bumblebee_healgun_aps * dt, autocvar_g_vehicle_bumblebee_healgun_amax); + } - if(trace_ent.armorvalue <= autocvar_g_vehicle_bumblebee_healgun_amax && autocvar_g_vehicle_bumblebee_healgun_aps) - trace_ent.armorvalue = min(trace_ent.armorvalue + autocvar_g_vehicle_bumblebee_healgun_aps * dt, autocvar_g_vehicle_bumblebee_healgun_amax); - - trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, autocvar_g_vehicle_bumblebee_healgun_hmax); - } - else if(IS_TURRET(trace_ent)) - { - if(trace_ent.health <= trace_ent.max_health && autocvar_g_vehicle_bumblebee_healgun_hps) - trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, trace_ent.max_health); - //else ..hmmm what? ammo? - - trace_ent.SendFlags |= TNSF_STATUS; + trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, autocvar_g_vehicle_bumblebee_healgun_hmax); + } else if (IS_TURRET(trace_ent)) { + if (trace_ent.health <= trace_ent.max_health && autocvar_g_vehicle_bumblebee_healgun_hps) { + trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, trace_ent.max_health); + } + // else ..hmmm what? ammo? + + trace_ent.SendFlags |= TNSF_STATUS; + } } } + } } - } - vehic.gun3.enemy.hook_end = trace_endpos; - setorigin(vehic.gun3.enemy, trace_endpos); - vehic.gun3.enemy.SendFlags |= BRG_END; + vehic.gun3.enemy.hook_end = trace_endpos; + setorigin(vehic.gun3.enemy, trace_endpos); + vehic.gun3.enemy.SendFlags |= BRG_END; - vehic.wait = time + 1; + vehic.wait = time + 1; + } else { + vehic.gun3.enemy.effects |= EF_NODRAW; + } } - else - vehic.gun3.enemy.effects |= EF_NODRAW; /*{ - if(vehic.gun3.enemy) - remove(vehic.gun3.enemy); + if(vehic.gun3.enemy) + remove(vehic.gun3.enemy); - vehic.gun3.enemy = NULL; + vehic.gun3.enemy = NULL; } */ @@ -599,8 +592,9 @@ bool bumblebee_pilot_frame(entity this, float dt) this.vehicle_ammo1 = (vehic.gun1.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100; this.vehicle_ammo2 = (vehic.gun2.vehicle_energy / autocvar_g_vehicle_bumblebee_cannon_ammo) * 100; - if(vehic.vehicle_flags & VHF_HASSHIELD) + if (vehic.vehicle_flags & VHF_HASSHIELD) { VEHICLE_UPDATE_PLAYER(this, vehic, shield, bumblebee); + } vehic.angles_x *= -1; makevectors(vehic.angles); @@ -620,8 +614,9 @@ void bumblebee_land(entity this) this.angles_x *= 0.95; this.angles_z *= 0.95; - if(hgt < 16) + if (hgt < 16) { setthink(this, vehicles_think); + } this.nextthink = time; @@ -630,37 +625,38 @@ void bumblebee_land(entity this) void bumblebee_exit(entity this, int eject) { - if(this.owner.vehicleid == VEH_BUMBLEBEE.vehicleid) - { + if (this.owner.vehicleid == VEH_BUMBLEBEE.vehicleid) { bumblebee_gunner_exit(this, eject); return; } settouch(this, vehicles_touch); - if(!IS_DEAD(this)) - { + if (!IS_DEAD(this)) { setthink(this, bumblebee_land); this.nextthink = time; } set_movetype(this, MOVETYPE_TOSS); - if(!this.owner) + if (!this.owner) { return; + } fixedmakevectors(this.angles); vector spot; - if(vdist(this.velocity, >, autocvar_g_vehicle_bumblebee_speed_forward * 0.5)) + if (vdist(this.velocity, >, autocvar_g_vehicle_bumblebee_speed_forward * 0.5)) { spot = this.origin + v_up * 128 + v_forward * 300; - else + } else { spot = this.origin + v_up * 128 - v_forward * 300; + } spot = vehicles_findgoodexit(this, this.owner, spot); // Hide beam - if(this.gun3.enemy || !wasfreed(this.gun3.enemy)) + if (this.gun3.enemy || !wasfreed(this.gun3.enemy)) { this.gun3.enemy.effects |= EF_NODRAW; + } this.owner.velocity = 0.75 * this.vehicle.velocity + normalize(spot - this.vehicle.origin) * 200; this.owner.velocity_z += 10; @@ -673,16 +669,17 @@ void bumblebee_exit(entity this, int eject) void bumblebee_blowup(entity this) { RadiusDamage(this, this.enemy, autocvar_g_vehicle_bumblebee_blowup_coredamage, - autocvar_g_vehicle_bumblebee_blowup_edgedamage, - autocvar_g_vehicle_bumblebee_blowup_radius, this, NULL, - autocvar_g_vehicle_bumblebee_blowup_forceintensity, - DEATH_VH_BUMB_DEATH.m_id, NULL); + autocvar_g_vehicle_bumblebee_blowup_edgedamage, + autocvar_g_vehicle_bumblebee_blowup_radius, this, NULL, + autocvar_g_vehicle_bumblebee_blowup_forceintensity, + DEATH_VH_BUMB_DEATH.m_id, NULL); sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); Send_Effect(EFFECT_EXPLOSION_BIG, (this.origin + '0 0 100') + (randomvec() * 80), '0 0 0', 1); - if(this.owner.deadflag == DEAD_DYING) + if (this.owner.deadflag == DEAD_DYING) { this.owner.deadflag = DEAD_DEAD; + } delete(this); } @@ -694,11 +691,11 @@ void bumblebee_dead_touch(entity this, entity toucher) void bumblebee_diethink(entity this) { - if(time >= this.wait) + if (time >= this.wait) { setthink(this, bumblebee_blowup); + } - if(random() < 0.1) - { + if (random() < 0.1) { sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1); } @@ -708,216 +705,230 @@ void bumblebee_diethink(entity this) spawnfunc(vehicle_bumblebee) { - if(!autocvar_g_vehicle_bumblebee) { delete(this); return; } - if(!vehicle_initialize(this, VEH_BUMBLEBEE, false)) { delete(this); return; } + if (!autocvar_g_vehicle_bumblebee) { delete(this); return; } + if (!vehicle_initialize(this, VEH_BUMBLEBEE, false)) { delete(this); return; } } METHOD(Bumblebee, vr_impact, void(Bumblebee thisveh, entity instance)) { - if(autocvar_g_vehicle_bumblebee_bouncepain) - vehicles_impact(instance, autocvar_g_vehicle_bumblebee_bouncepain_x, autocvar_g_vehicle_bumblebee_bouncepain_y, autocvar_g_vehicle_bumblebee_bouncepain_z); + if (autocvar_g_vehicle_bumblebee_bouncepain) { + vehicles_impact(instance, autocvar_g_vehicle_bumblebee_bouncepain_x, autocvar_g_vehicle_bumblebee_bouncepain_y, autocvar_g_vehicle_bumblebee_bouncepain_z); + } } METHOD(Bumblebee, vr_enter, void(Bumblebee thisveh, entity instance)) { - settouch(instance, bumblebee_touch); - instance.nextthink = 0; - set_movetype(instance, MOVETYPE_BOUNCEMISSILE); + settouch(instance, bumblebee_touch); + instance.nextthink = 0; + set_movetype(instance, MOVETYPE_BOUNCEMISSILE); } METHOD(Bumblebee, vr_gunner_enter, void(Bumblebee thisveh, entity instance, entity actor)) { - if(!instance.gunner1) - if(time >= instance.gun1.phase) - if(instance.gun1.vehicle_enter) - if(instance.gun1.vehicle_enter(instance, actor)) - return; + if (!instance.gunner1) { + if (time >= instance.gun1.phase) { + if (instance.gun1.vehicle_enter) { + if (instance.gun1.vehicle_enter(instance, actor)) { + return; + } + } + } + } - if(!instance.gunner2) - if(time >= instance.gun2.phase) - if(instance.gun2.vehicle_enter) - if(instance.gun2.vehicle_enter(instance, actor)) - return; + if (!instance.gunner2) { + if (time >= instance.gun2.phase) { + if (instance.gun2.vehicle_enter) { + if (instance.gun2.vehicle_enter(instance, actor)) { + return; + } + } + } + } } METHOD(Bumblebee, vr_think, void(Bumblebee thisveh, entity instance)) { - instance.angles_z *= 0.8; - instance.angles_x *= 0.8; - - instance.nextthink = time; - - if(!instance.owner) - { - if(instance.gunner1) - { - entity e = instance.gunner1; - instance.gun1.vehicle_exit(instance.gun1, VHEF_EJECT); - instance.phase = 0; - gettouch(instance)(instance, e); - return; - } - - if(instance.gunner2) - { - entity e = instance.gunner2; - instance.gun2.vehicle_exit(instance.gun2, VHEF_EJECT); - instance.phase = 0; - gettouch(instance)(instance, e); - return; - } - } + instance.angles_z *= 0.8; + instance.angles_x *= 0.8; + + instance.nextthink = time; + + if (!instance.owner) { + if (instance.gunner1) { + entity e = instance.gunner1; + instance.gun1.vehicle_exit(instance.gun1, VHEF_EJECT); + instance.phase = 0; + gettouch(instance)(instance, e); + return; + } + + if (instance.gunner2) { + entity e = instance.gunner2; + instance.gun2.vehicle_exit(instance.gun2, VHEF_EJECT); + instance.phase = 0; + gettouch(instance)(instance, e); + return; + } + } } METHOD(Bumblebee, vr_death, void(Bumblebee thisveh, entity instance)) { CSQCModel_UnlinkEntity(instance); // hide beam - if(instance.gun3.enemy || !wasfreed(instance.gun3.enemy)) + if (instance.gun3.enemy || !wasfreed(instance.gun3.enemy)) { instance.gun3.enemy.effects |= EF_NODRAW; + } - if(instance.gunner1) + if (instance.gunner1) { instance.gun1.vehicle_exit(instance.gun1, VHEF_EJECT); + } - if(instance.gunner2) + if (instance.gunner2) { instance.gun2.vehicle_exit(instance.gun2, VHEF_EJECT); + } instance.vehicle_exit(instance, VHEF_EJECT); - fixedmakevectors(instance.angles); - vehicle_tossgib(instance, instance.gun1, instance.velocity + v_right * 300 + v_up * 100 + randomvec() * 200, "cannon_right", rint(random()), rint(random()), 6, randomvec() * 200); - vehicle_tossgib(instance, instance.gun2, instance.velocity + v_right * -300 + v_up * 100 + randomvec() * 200, "cannon_left", rint(random()), rint(random()), 6, randomvec() * 200); - vehicle_tossgib(instance, instance.gun3, instance.velocity + v_forward * 300 + v_up * -100 + randomvec() * 200, "raygun", rint(random()), rint(random()), 6, randomvec() * 300); - - entity _body = vehicle_tossgib(instance, instance, instance.velocity + randomvec() * 200, "", rint(random()), rint(random()), 6, randomvec() * 100); - - if(random() > 0.5) - settouch(_body, bumblebee_dead_touch); - else - settouch(_body, func_null); - - setthink(_body, bumblebee_diethink); - _body.nextthink = time; - _body.wait = time + 2 + (random() * 8); - _body.owner = instance; - _body.enemy = instance.enemy; - _body.scale = 1.5; - _body.angles = instance.angles; - - Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation(instance.origin, 16), '0 0 0', 1); - - instance.health = 0; - instance.event_damage = func_null; - instance.solid = SOLID_NOT; - instance.takedamage = DAMAGE_NO; - instance.deadflag = DEAD_DYING; - set_movetype(instance, MOVETYPE_NONE); - instance.effects = EF_NODRAW; - instance.colormod = '0 0 0'; - instance.avelocity = '0 0 0'; - instance.velocity = '0 0 0'; - settouch(instance, func_null); - instance.nextthink = 0; - - setorigin(instance, instance.pos1); + fixedmakevectors(instance.angles); + vehicle_tossgib(instance, instance.gun1, instance.velocity + v_right * 300 + v_up * 100 + randomvec() * 200, "cannon_right", rint(random()), rint(random()), 6, randomvec() * 200); + vehicle_tossgib(instance, instance.gun2, instance.velocity + v_right * -300 + v_up * 100 + randomvec() * 200, "cannon_left", rint(random()), rint(random()), 6, randomvec() * 200); + vehicle_tossgib(instance, instance.gun3, instance.velocity + v_forward * 300 + v_up * -100 + randomvec() * 200, "raygun", rint(random()), rint(random()), 6, randomvec() * 300); + + entity _body = vehicle_tossgib(instance, instance, instance.velocity + randomvec() * 200, "", rint(random()), rint(random()), 6, randomvec() * 100); + + if (random() > 0.5) { + settouch(_body, bumblebee_dead_touch); + } else { + settouch(_body, func_null); + } + + setthink(_body, bumblebee_diethink); + _body.nextthink = time; + _body.wait = time + 2 + (random() * 8); + _body.owner = instance; + _body.enemy = instance.enemy; + _body.scale = 1.5; + _body.angles = instance.angles; + + Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation(instance.origin, 16), '0 0 0', 1); + + instance.health = 0; + instance.event_damage = func_null; + instance.solid = SOLID_NOT; + instance.takedamage = DAMAGE_NO; + instance.deadflag = DEAD_DYING; + set_movetype(instance, MOVETYPE_NONE); + instance.effects = EF_NODRAW; + instance.colormod = '0 0 0'; + instance.avelocity = '0 0 0'; + instance.velocity = '0 0 0'; + settouch(instance, func_null); + instance.nextthink = 0; + + setorigin(instance, instance.pos1); } METHOD(Bumblebee, vr_spawn, void(Bumblebee thisveh, entity instance)) { - if(!instance.gun1) - { - // for some reason, autosizing of the shield entity refuses to work for this one so set it up in advance. - instance.vehicle_shieldent = spawn(); - instance.vehicle_shieldent.effects = EF_LOWPRECISION; - setmodel(instance.vehicle_shieldent, MDL_VEH_BUMBLEBEE_SHIELD); - setattachment(instance.vehicle_shieldent, instance, ""); - setorigin(instance.vehicle_shieldent, real_origin(instance) - instance.origin); - instance.vehicle_shieldent.scale = 512 / vlen(instance.maxs - instance.mins); - setthink(instance.vehicle_shieldent, shieldhit_think); - instance.vehicle_shieldent.alpha = -1; - instance.vehicle_shieldent.effects = EF_LOWPRECISION | EF_NODRAW; - - instance.gun1 = new(vehicle_playerslot); - instance.gun2 = new(vehicle_playerslot); - instance.gun3 = new(bumblebee_raygun); - - instance.vehicle_flags |= VHF_MULTISLOT; - - instance.gun1.owner = instance; - instance.gun2.owner = instance; - instance.gun3.owner = instance; - - setmodel(instance.gun1, MDL_VEH_BUMBLEBEE_CANNON_RIGHT); - setmodel(instance.gun2, MDL_VEH_BUMBLEBEE_CANNON_LEFT); - setmodel(instance.gun3, MDL_VEH_BUMBLEBEE_CANNON_CENTER); - - setattachment(instance.gun1, instance, "cannon_right"); - setattachment(instance.gun2, instance, "cannon_left"); - - // Angled bones are no fun, messes up gun-aim; so work arround it. - instance.gun3.pos1 = instance.angles; - instance.angles = '0 0 0'; - vector ofs = gettaginfo(instance, gettagindex(instance, "raygun")); - ofs -= instance.origin; - setattachment(instance.gun3, instance, ""); - setorigin(instance.gun3, ofs); - instance.angles = instance.gun3.pos1; - - vehicle_addplayerslot(instance, instance.gun1, HUD_BUMBLEBEE_GUN, MDL_VEH_BUMBLEBEE_GUNCOCKPIT, bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter); - vehicle_addplayerslot(instance, instance.gun2, HUD_BUMBLEBEE_GUN, MDL_VEH_BUMBLEBEE_GUNCOCKPIT, bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter); - - setorigin(instance.vehicle_hudmodel, '50 0 -5'); // Move cockpit forward - down. - setorigin(instance.vehicle_viewport, '5 0 2'); // Move camera forward up - - //fixme-model-bones - setorigin(instance.gun1.vehicle_hudmodel, '90 -27 -23'); - setorigin(instance.gun1.vehicle_viewport, '-85 0 50'); - //fixme-model-bones - setorigin(instance.gun2.vehicle_hudmodel, '90 27 -23'); - setorigin(instance.gun2.vehicle_viewport, '-85 0 50'); - - instance.scale = 1.5; - - // Raygun beam - if(instance.gun3.enemy == NULL) - { - instance.gun3.enemy = spawn(); - Net_LinkEntity(instance.gun3.enemy, true, 0, bumble_raygun_send); - instance.gun3.enemy.SendFlags = BRG_SETUP; - instance.gun3.enemy.cnt = autocvar_g_vehicle_bumblebee_raygun; - instance.gun3.enemy.effects = EF_NODRAW | EF_LOWPRECISION; - } - } - - if(!autocvar_g_vehicle_bumblebee_swim) - instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK; - - instance.vehicle_health = autocvar_g_vehicle_bumblebee_health; - instance.vehicle_shield = autocvar_g_vehicle_bumblebee_shield; - instance.solid = SOLID_BBOX; - set_movetype(instance, MOVETYPE_TOSS); - instance.damageforcescale = 0.025; - - instance.PlayerPhysplug = bumblebee_pilot_frame; - - setorigin(instance, instance.origin + '0 0 25'); + if (!instance.gun1) { + // for some reason, autosizing of the shield entity refuses to work for this one so set it up in advance. + instance.vehicle_shieldent = spawn(); + instance.vehicle_shieldent.effects = EF_LOWPRECISION; + setmodel(instance.vehicle_shieldent, MDL_VEH_BUMBLEBEE_SHIELD); + setattachment(instance.vehicle_shieldent, instance, ""); + setorigin(instance.vehicle_shieldent, real_origin(instance) - instance.origin); + instance.vehicle_shieldent.scale = 512 / vlen(instance.maxs - instance.mins); + setthink(instance.vehicle_shieldent, shieldhit_think); + instance.vehicle_shieldent.alpha = -1; + instance.vehicle_shieldent.effects = EF_LOWPRECISION | EF_NODRAW; + + instance.gun1 = new(vehicle_playerslot); + instance.gun2 = new(vehicle_playerslot); + instance.gun3 = new(bumblebee_raygun); + + instance.vehicle_flags |= VHF_MULTISLOT; + + instance.gun1.owner = instance; + instance.gun2.owner = instance; + instance.gun3.owner = instance; + + setmodel(instance.gun1, MDL_VEH_BUMBLEBEE_CANNON_RIGHT); + setmodel(instance.gun2, MDL_VEH_BUMBLEBEE_CANNON_LEFT); + setmodel(instance.gun3, MDL_VEH_BUMBLEBEE_CANNON_CENTER); + + setattachment(instance.gun1, instance, "cannon_right"); + setattachment(instance.gun2, instance, "cannon_left"); + + // Angled bones are no fun, messes up gun-aim; so work arround it. + instance.gun3.pos1 = instance.angles; + instance.angles = '0 0 0'; + vector ofs = gettaginfo(instance, gettagindex(instance, "raygun")); + ofs -= instance.origin; + setattachment(instance.gun3, instance, ""); + setorigin(instance.gun3, ofs); + instance.angles = instance.gun3.pos1; + + vehicle_addplayerslot(instance, instance.gun1, HUD_BUMBLEBEE_GUN, MDL_VEH_BUMBLEBEE_GUNCOCKPIT, bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter); + vehicle_addplayerslot(instance, instance.gun2, HUD_BUMBLEBEE_GUN, MDL_VEH_BUMBLEBEE_GUNCOCKPIT, bumblebee_gunner_frame, bumblebee_gunner_exit, bumblebee_gunner_enter); + + setorigin(instance.vehicle_hudmodel, '50 0 -5'); // Move cockpit forward - down. + setorigin(instance.vehicle_viewport, '5 0 2'); // Move camera forward up + + // fixme-model-bones + setorigin(instance.gun1.vehicle_hudmodel, '90 -27 -23'); + setorigin(instance.gun1.vehicle_viewport, '-85 0 50'); + // fixme-model-bones + setorigin(instance.gun2.vehicle_hudmodel, '90 27 -23'); + setorigin(instance.gun2.vehicle_viewport, '-85 0 50'); + + instance.scale = 1.5; + + // Raygun beam + if (instance.gun3.enemy == NULL) { + instance.gun3.enemy = spawn(); + Net_LinkEntity(instance.gun3.enemy, true, 0, bumble_raygun_send); + instance.gun3.enemy.SendFlags = BRG_SETUP; + instance.gun3.enemy.cnt = autocvar_g_vehicle_bumblebee_raygun; + instance.gun3.enemy.effects = EF_NODRAW | EF_LOWPRECISION; + } + } + + if (!autocvar_g_vehicle_bumblebee_swim) { + instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK; + } + + instance.vehicle_health = autocvar_g_vehicle_bumblebee_health; + instance.vehicle_shield = autocvar_g_vehicle_bumblebee_shield; + instance.solid = SOLID_BBOX; + set_movetype(instance, MOVETYPE_TOSS); + instance.damageforcescale = 0.025; + + instance.PlayerPhysplug = bumblebee_pilot_frame; + + setorigin(instance, instance.origin + '0 0 25'); } METHOD(Bumblebee, vr_setup, void(Bumblebee thisveh, entity instance)) { - if(autocvar_g_vehicle_bumblebee_energy) - if(autocvar_g_vehicle_bumblebee_energy_regen) - instance.vehicle_flags |= VHF_ENERGYREGEN; + if (autocvar_g_vehicle_bumblebee_energy) { + if (autocvar_g_vehicle_bumblebee_energy_regen) { + instance.vehicle_flags |= VHF_ENERGYREGEN; + } + } - if(autocvar_g_vehicle_bumblebee_shield) - instance.vehicle_flags |= VHF_HASSHIELD; + if (autocvar_g_vehicle_bumblebee_shield) { + instance.vehicle_flags |= VHF_HASSHIELD; + } - if(autocvar_g_vehicle_bumblebee_shield_regen) - instance.vehicle_flags |= VHF_SHIELDREGEN; + if (autocvar_g_vehicle_bumblebee_shield_regen) { + instance.vehicle_flags |= VHF_SHIELDREGEN; + } - if(autocvar_g_vehicle_bumblebee_health_regen) - instance.vehicle_flags |= VHF_HEALTHREGEN; + if (autocvar_g_vehicle_bumblebee_health_regen) { + instance.vehicle_flags |= VHF_HEALTHREGEN; + } - instance.vehicle_exit = bumblebee_exit; - instance.respawntime = autocvar_g_vehicle_bumblebee_respawntime; - instance.vehicle_health = autocvar_g_vehicle_bumblebee_health; - instance.max_health = instance.vehicle_health; - instance.vehicle_shield = autocvar_g_vehicle_bumblebee_shield; + instance.vehicle_exit = bumblebee_exit; + instance.respawntime = autocvar_g_vehicle_bumblebee_respawntime; + instance.vehicle_health = autocvar_g_vehicle_bumblebee_health; + instance.max_health = instance.vehicle_health; + instance.vehicle_shield = autocvar_g_vehicle_bumblebee_shield; } #endif // SVQC @@ -926,43 +937,41 @@ METHOD(Bumblebee, vr_setup, void(Bumblebee thisveh, entity instance)) void CSQC_BUMBLE_GUN_HUD() { Vehicles_drawHUD("vehicle_gunner", "vehicle_gunner_weapon1", string_null, - "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, - string_null, '0 0 0'); + "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, + string_null, '0 0 0'); } METHOD(Bumblebee, vr_hud, void(Bumblebee thisveh)) { - Vehicles_drawHUD(VEH_BUMBLEBEE.m_icon, "vehicle_bumble_weapon1", "vehicle_bumble_weapon2", - "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, - "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color); - - float hudAlpha = autocvar_hud_panel_fg_alpha; - float blinkValue = 0.55 + sin(time * 7) * 0.45; - vector tmpPos = '0 0 0'; - vector tmpSize = '1 1 1' * hud_fontsize; - tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (520/768); - - if(!AuxiliaryXhair[1].draw2d) - { - tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (96/256) - tmpSize.y; - drawstring(tmpPos, _("No right gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); - } - - if(!AuxiliaryXhair[2].draw2d) - { - tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (160/256); - drawstring(tmpPos, _("No left gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); - } + Vehicles_drawHUD(VEH_BUMBLEBEE.m_icon, "vehicle_bumble_weapon1", "vehicle_bumble_weapon2", + "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, + "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color); + + float hudAlpha = autocvar_hud_panel_fg_alpha; + float blinkValue = 0.55 + sin(time * 7) * 0.45; + vector tmpPos = '0 0 0'; + vector tmpSize = '1 1 1' * hud_fontsize; + tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (520 / 768); + + if (!AuxiliaryXhair[1].draw2d) { + tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (96 / 256) - tmpSize.y; + drawstring(tmpPos, _("No right gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); + } + + if (!AuxiliaryXhair[2].draw2d) { + tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (160 / 256); + drawstring(tmpPos, _("No left gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); + } } METHOD(Bumblebee, vr_crosshair, void(Bumblebee thisveh, entity player)) { - Vehicles_drawCrosshair(vCROSS_HEAL); + Vehicles_drawCrosshair(vCROSS_HEAL); } METHOD(Bumblebee, vr_setup, void(Bumblebee thisveh, entity instance)) { - AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Raygun-locked - AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Gunner1 - AuxiliaryXhair[2].axh_image = vCROSS_BURST; // Gunner2 + AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Raygun-locked + AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Gunner1 + AuxiliaryXhair[2].axh_image = vCROSS_BURST; // Gunner2 } #endif diff --git a/qcsrc/common/vehicles/vehicle/bumblebee.qh b/qcsrc/common/vehicles/vehicle/bumblebee.qh index 4c226f97a..46423b7d8 100644 --- a/qcsrc/common/vehicles/vehicle/bumblebee.qh +++ b/qcsrc/common/vehicles/vehicle/bumblebee.qh @@ -8,8 +8,8 @@ CLASS(Bumblebee, Vehicle) /* maxs */ ATTRIB(Bumblebee, m_maxs, vector, '230 130 130'); /* view offset*/ ATTRIB(Bumblebee, view_ofs, vector, '0 0 300'); /* view dist */ ATTRIB(Bumblebee, height, float, 450); -/* model */ ATTRIB(Bumblebee, mdl, string, "models/vehicles/bumblebee_body.dpm"); -/* model */ ATTRIB(Bumblebee, model, string, "models/vehicles/bumblebee_body.dpm"); +/* model */ATTRIB(Bumblebee, mdl, string, "models/vehicles/bumblebee_body.dpm"); +/* model */ATTRIB(Bumblebee, model, string, "models/vehicles/bumblebee_body.dpm"); /* head_model */ ATTRIB(Bumblebee, head_model, string, ""); /* hud_model */ ATTRIB(Bumblebee, hud_model, string, "models/vehicles/spiderbot_cockpit.dpm"); /* tags */ ATTRIB(Bumblebee, tag_head, string, ""); @@ -22,7 +22,7 @@ ENDCLASS(Bumblebee) REGISTER_VEHICLE(BUMBLEBEE, NEW(Bumblebee)); #ifdef GAMEQC - MODEL(VEH_BUMBLEBEE_GUNCOCKPIT, "models/vehicles/wakizashi_cockpit.dpm"); +MODEL(VEH_BUMBLEBEE_GUNCOCKPIT, "models/vehicles/wakizashi_cockpit.dpm"); #endif #ifdef CSQC diff --git a/qcsrc/common/vehicles/vehicle/racer.qc b/qcsrc/common/vehicles/vehicle/racer.qc index 8dbfae467..06ba84e16 100644 --- a/qcsrc/common/vehicles/vehicle/racer.qc +++ b/qcsrc/common/vehicles/vehicle/racer.qc @@ -33,7 +33,7 @@ float autocvar_g_vehicle_racer_friction = 0.45; float autocvar_g_vehicle_racer_water_time = 5; -//float autocvar_g_vehicle_racer_collision_multiplier = 0.05; +// float autocvar_g_vehicle_racer_collision_multiplier = 0.05; // 0 = hover, != 0 = maglev int autocvar_g_vehicle_racer_hovertype = 0; @@ -85,40 +85,41 @@ void racer_align4point(entity this, float _delta) float fl_push, fr_push, bl_push, br_push; push_vector = racer_force_from_tag(this, "tag_engine_fr", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower); - fr_push = force_fromtag_normpower; - //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); + fr_push = force_fromtag_normpower; + // vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); push_vector += racer_force_from_tag(this, "tag_engine_fl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower); - fl_push = force_fromtag_normpower; - //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); + fl_push = force_fromtag_normpower; + // vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); push_vector += racer_force_from_tag(this, "tag_engine_br", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower); - br_push = force_fromtag_normpower; - //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); + br_push = force_fromtag_normpower; + // vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); push_vector += racer_force_from_tag(this, "tag_engine_bl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower); - bl_push = force_fromtag_normpower; - //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); + bl_push = force_fromtag_normpower; + // vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier); this.velocity += push_vector * _delta; float uforce = autocvar_g_vehicle_racer_upforcedamper; int cont = pointcontents(this.origin - '0 0 64'); - if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME) - { + if (cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME) { uforce = autocvar_g_vehicle_racer_water_upforcedamper; - if(PHYS_INPUT_BUTTON_CROUCH(this.owner) && time < this.air_finished) + if (PHYS_INPUT_BUTTON_CROUCH(this.owner) && time < this.air_finished) { this.velocity_z += 30; - else + } else { this.velocity_z += 200; + } } // Anti ocilation - if(this.velocity_z > 0) + if (this.velocity_z > 0) { this.velocity_z *= 1 - uforce * _delta; + } push_vector_x = (fl_push - bl_push); push_vector_x += (fr_push - br_push); @@ -149,8 +150,7 @@ bool racer_frame(entity this, float dt) entity vehic = this.vehicle; return = true; - if(game_stopped) - { + if (game_stopped) { vehic.solid = SOLID_NOT; vehic.takedamage = DAMAGE_NO; set_movetype(vehic, MOVETYPE_NONE); @@ -161,11 +161,11 @@ bool racer_frame(entity this, float dt) traceline(vehic.origin, vehic.origin + '0 0 1', MOVE_NOMONSTERS, this); int cont = trace_dpstartcontents; - if(!(cont & DPCONTENTS_WATER)) + if (!(cont & DPCONTENTS_WATER)) { vehic.air_finished = time + autocvar_g_vehicle_racer_water_time; + } - if(IS_DEAD(vehic)) - { + if (IS_DEAD(vehic)) { PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false; return; } @@ -192,94 +192,83 @@ bool racer_frame(entity this, float dt) makevectors(vehic.angles); vehic.angles_x *= -1; - //ftmp = vehic.velocity_z; + // ftmp = vehic.velocity_z; vector df = vehic.velocity * -autocvar_g_vehicle_racer_friction; - //vehic.velocity_z = ftmp; - - if(CS(this).movement) - { - if(cont & DPCONTENTS_LIQUIDSMASK) - { - if(CS(this).movement_x) { df += v_forward * ((CS(this).movement_x > 0) ? autocvar_g_vehicle_racer_water_speed_forward : -autocvar_g_vehicle_racer_water_speed_forward); } - if(CS(this).movement_y) { df += v_right * ((CS(this).movement_y > 0) ? autocvar_g_vehicle_racer_water_speed_strafe : -autocvar_g_vehicle_racer_water_speed_strafe); } - } - else - { - if(CS(this).movement_x) { df += v_forward * ((CS(this).movement_x > 0) ? autocvar_g_vehicle_racer_speed_forward : -autocvar_g_vehicle_racer_speed_forward); } - if(CS(this).movement_y) { df += v_right * ((CS(this).movement_y > 0) ? autocvar_g_vehicle_racer_speed_strafe : -autocvar_g_vehicle_racer_speed_strafe); } + // vehic.velocity_z = ftmp; + + if (CS(this).movement) { + if (cont & DPCONTENTS_LIQUIDSMASK) { + if (CS(this).movement_x) { df += v_forward * ((CS(this).movement_x > 0) ? autocvar_g_vehicle_racer_water_speed_forward : -autocvar_g_vehicle_racer_water_speed_forward); } + if (CS(this).movement_y) { df += v_right * ((CS(this).movement_y > 0) ? autocvar_g_vehicle_racer_water_speed_strafe : -autocvar_g_vehicle_racer_water_speed_strafe); } + } else { + if (CS(this).movement_x) { df += v_forward * ((CS(this).movement_x > 0) ? autocvar_g_vehicle_racer_speed_forward : -autocvar_g_vehicle_racer_speed_forward); } + if (CS(this).movement_y) { df += v_right * ((CS(this).movement_y > 0) ? autocvar_g_vehicle_racer_speed_strafe : -autocvar_g_vehicle_racer_speed_strafe); } } #ifdef SVQC - if(vehic.sound_nexttime < time || vehic.sounds != 1) - { + if (vehic.sound_nexttime < time || vehic.sounds != 1) { vehic.sounds = 1; - vehic.sound_nexttime = time + 10.922667; //soundlength("vehicles/racer_move.wav"); - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_MOVE, VOL_VEHICLEENGINE, ATTEN_NORM); + vehic.sound_nexttime = time + 10.922667; // soundlength("vehicles/racer_move.wav"); + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_MOVE, VOL_VEHICLEENGINE, ATTEN_NORM); } #endif } #ifdef SVQC - else - { - if(vehic.sound_nexttime < time || vehic.sounds != 0) - { + else { + if (vehic.sound_nexttime < time || vehic.sounds != 0) { vehic.sounds = 0; - vehic.sound_nexttime = time + 11.888604; //soundlength("vehicles/racer_idle.wav"); - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM); + vehic.sound_nexttime = time + 11.888604; // soundlength("vehicles/racer_idle.wav"); + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM); } } #endif // Afterburn - if (PHYS_INPUT_BUTTON_JUMP(this) && vehic.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * dt)) - { + if (PHYS_INPUT_BUTTON_JUMP(this) && vehic.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * dt)) { #ifdef SVQC - if(time - vehic.wait > 0.2) + if (time - vehic.wait > 0.2) { pointparticles(EFFECT_RACER_BOOSTER, vehic.origin - v_forward * 32, v_forward * vlen(vehic.velocity), 1); + } #endif vehic.wait = time; - if(cont & DPCONTENTS_LIQUIDSMASK) - { + if (cont & DPCONTENTS_LIQUIDSMASK) { vehic.vehicle_energy -= autocvar_g_vehicle_racer_waterburn_cost * dt; df += (v_forward * autocvar_g_vehicle_racer_waterburn_speed); - } - else - { + } else { vehic.vehicle_energy -= autocvar_g_vehicle_racer_afterburn_cost * dt; df += (v_forward * autocvar_g_vehicle_racer_speed_afterburn); } #ifdef SVQC - if(vehic.invincible_finished < time) - { + if (vehic.invincible_finished < time) { traceline(vehic.origin, vehic.origin - '0 0 256', MOVE_NORMAL, vehic); - if(trace_fraction != 1.0) + if (trace_fraction != 1.0) { pointparticles(EFFECT_SMOKE_SMALL, trace_endpos, '0 0 0', 1); + } vehic.invincible_finished = time + 0.1 + (random() * 0.1); } - if(vehic.strength_finished < time) - { - vehic.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav"); - sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RACER_BOOST, VOL_VEHICLEENGINE, ATTEN_NORM); + if (vehic.strength_finished < time) { + vehic.strength_finished = time + 10.922667; // soundlength("vehicles/racer_boost.wav"); + sound(vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RACER_BOOST, VOL_VEHICLEENGINE, ATTEN_NORM); } #endif - } - else - { + } else { vehic.strength_finished = 0; - sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM); + sound(vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM); } - if(cont & DPCONTENTS_LIQUIDSMASK) + if (cont & DPCONTENTS_LIQUIDSMASK) { vehic.racer_watertime = time; + } float dforce = autocvar_g_vehicle_racer_downforce; - if(time - vehic.racer_watertime <= 3) + if (time - vehic.racer_watertime <= 3) { dforce = autocvar_g_vehicle_racer_water_downforce; + } df -= v_up * (vlen(vehic.velocity) * dforce); CS(this).movement = vehic.velocity += df * dt; @@ -288,88 +277,89 @@ bool racer_frame(entity this, float dt) Weapon wep1 = WEP_RACER; .entity weaponentity = weaponentities[0]; // TODO: unhardcode - if (!forbidWeaponUse(this)) - if (PHYS_INPUT_BUTTON_ATCK(this)) - if (wep1.wr_checkammo1(wep1, vehic, weaponentity)) - { - string tagname = (vehic.cnt) - ? (vehic.cnt = 0, "tag_fire1") - : (vehic.cnt = 1, "tag_fire2"); - vector org = gettaginfo(vehic, gettagindex(vehic, tagname)); - w_shotorg = org; - w_shotdir = v_forward; - // Fix z-aim (for chase mode) - crosshair_trace(this); - w_shotdir.z = normalize(trace_endpos - org).z * 0.5; - wep1.wr_think(wep1, vehic, weaponentity, 1); + if (!forbidWeaponUse(this)) { + if (PHYS_INPUT_BUTTON_ATCK(this)) { + if (wep1.wr_checkammo1(wep1, vehic, weaponentity)) { + string tagname = (vehic.cnt) + ? (vehic.cnt = 0, "tag_fire1") + : (vehic.cnt = 1, "tag_fire2"); + vector org = gettaginfo(vehic, gettagindex(vehic, tagname)); + w_shotorg = org; + w_shotdir = v_forward; + // Fix z-aim (for chase mode) + crosshair_trace(this); + w_shotdir.z = normalize(trace_endpos - org).z * 0.5; + wep1.wr_think(wep1, vehic, weaponentity, 1); + } + } } - if(autocvar_g_vehicle_racer_rocket_locktarget) - { - if(time >= vehic.vehicle_last_trace) - { + if (autocvar_g_vehicle_racer_rocket_locktarget) { + if (time >= vehic.vehicle_last_trace) { crosshair_trace(this); vehicles_locktarget(vehic, (1 / autocvar_g_vehicle_racer_rocket_locking_time) * dt, - (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * dt, - autocvar_g_vehicle_racer_rocket_locked_time); + (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * dt, + autocvar_g_vehicle_racer_rocket_locked_time); vehic.vehicle_last_trace = time + autocvar_g_vehicle_racer_thinkrate; } - if(vehic.lock_target) - { - if(vehic.lock_strength == 1) + if (vehic.lock_target) { + if (vehic.lock_strength == 1) { UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '1 0 0', 0); - else if(vehic.lock_strength > 0.5) + } else if (vehic.lock_strength > 0.5) { UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 1 0', 0); - else if(vehic.lock_strength < 0.5) + } else if (vehic.lock_strength < 0.5) { UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 0 1', 0); + } } } - if(!forbidWeaponUse(this)) - if(time > vehic.delay) - if(PHYS_INPUT_BUTTON_ATCK2(this)) - { - vehic.misc_bulletcounter += 1; - vehic.delay = time + 0.3; - - if(vehic.misc_bulletcounter == 1) - { - racer_fire_rocket_aim(this, "tag_rocket_r", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL); - this.vehicle_ammo2 = 50; - } - else if(vehic.misc_bulletcounter == 2) - { - racer_fire_rocket_aim(this, "tag_rocket_l", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL); - vehic.lock_strength = 0; - vehic.lock_target = NULL; - vehic.misc_bulletcounter = 0; - vehic.delay = time + autocvar_g_vehicle_racer_rocket_refire; - vehic.lip = time; - this.vehicle_ammo2 = 0; + if (!forbidWeaponUse(this)) { + if (time > vehic.delay) { + if (PHYS_INPUT_BUTTON_ATCK2(this)) { + vehic.misc_bulletcounter += 1; + vehic.delay = time + 0.3; + + if (vehic.misc_bulletcounter == 1) { + racer_fire_rocket_aim(this, "tag_rocket_r", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL); + this.vehicle_ammo2 = 50; + } else if (vehic.misc_bulletcounter == 2) { + racer_fire_rocket_aim(this, "tag_rocket_l", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL); + vehic.lock_strength = 0; + vehic.lock_target = NULL; + vehic.misc_bulletcounter = 0; + vehic.delay = time + autocvar_g_vehicle_racer_rocket_refire; + vehic.lip = time; + this.vehicle_ammo2 = 0; + } + } else if (vehic.misc_bulletcounter == 0) { + this.vehicle_ammo2 = 100; + } } } - else if(vehic.misc_bulletcounter == 0) - this.vehicle_ammo2 = 100; this.vehicle_reload2 = bound(0, 100 * ((time - vehic.lip) / (vehic.delay - vehic.lip)), 100); - if(vehic.vehicle_flags & VHF_SHIELDREGEN) + if (vehic.vehicle_flags & VHF_SHIELDREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_racer_shield, autocvar_g_vehicle_racer_shield_regen_pause, autocvar_g_vehicle_racer_shield_regen, dt, true); + } - if(vehic.vehicle_flags & VHF_HEALTHREGEN) + if (vehic.vehicle_flags & VHF_HEALTHREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_racer_health, autocvar_g_vehicle_racer_health_regen_pause, autocvar_g_vehicle_racer_health_regen, dt, false); + } - if(vehic.vehicle_flags & VHF_ENERGYREGEN) + if (vehic.vehicle_flags & VHF_ENERGYREGEN) { vehicles_regen(vehic, vehic.wait, vehicle_energy, autocvar_g_vehicle_racer_energy, autocvar_g_vehicle_racer_energy_regen_pause, autocvar_g_vehicle_racer_energy_regen, dt, false); + } VEHICLE_UPDATE_PLAYER(this, vehic, health, racer); VEHICLE_UPDATE_PLAYER(this, vehic, energy, racer); - if(vehic.vehicle_flags & VHF_HASSHIELD) + if (vehic.vehicle_flags & VHF_HASSHIELD) { VEHICLE_UPDATE_PLAYER(this, vehic, shield, racer); + } PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false; #endif @@ -390,18 +380,18 @@ void racer_think(entity this) float forced = autocvar_g_vehicle_racer_upforcedamper; - //int cont = pointcontents(this.origin - '0 0 64'); + // int cont = pointcontents(this.origin - '0 0 64'); traceline(this.origin - '0 0 64', this.origin - '0 0 64', MOVE_NOMONSTERS, this); - //if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME) - if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK) - { + // if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME) + if (trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK) { forced = autocvar_g_vehicle_racer_water_upforcedamper; this.velocity_z += 200; } this.velocity += df * autocvar_g_vehicle_racer_thinkrate; - if(this.velocity_z > 0) + if (this.velocity_z > 0) { this.velocity_z *= 1 - forced * autocvar_g_vehicle_racer_thinkrate; + } this.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * autocvar_g_vehicle_racer_thinkrate); this.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * autocvar_g_vehicle_racer_thinkrate); @@ -416,38 +406,33 @@ void racer_exit(entity this, int eject) setthink(this, racer_think); this.nextthink = time; set_movetype(this, MOVETYPE_BOUNCE); - sound (this.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM); + sound(this.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM); - if(!this.owner) + if (!this.owner) { return; + } makevectors(this.angles); - if(eject) - { + if (eject) { spot = this.origin + v_forward * 100 + '0 0 64'; spot = vehicles_findgoodexit(this, this.owner, spot); setorigin(this.owner, spot); this.owner.velocity = (v_up + v_forward * 0.25) * 750; this.owner.oldvelocity = this.owner.velocity; - } - else - { - if(vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed)) - { + } else { + if (vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed)) { this.owner.velocity = normalize(this.velocity) * autocvar_sv_maxairspeed * 2; this.owner.velocity_z += 200; spot = this.origin + v_forward * 32 + '0 0 32'; spot = vehicles_findgoodexit(this, this.owner, spot); - } - else - { + } else { this.owner.velocity = this.velocity * 0.5; this.owner.velocity_z += 10; spot = this.origin - v_forward * 200 + '0 0 32'; spot = vehicles_findgoodexit(this, this.owner, spot); } this.owner.oldvelocity = this.owner.velocity; - setorigin(this.owner , spot); + setorigin(this.owner, spot); } antilag_clear(this.owner, CS(this.owner)); this.owner = NULL; @@ -458,16 +443,16 @@ void racer_blowup(entity this) this.deadflag = DEAD_DEAD; this.vehicle_exit(this, VHEF_NORMAL); - RadiusDamage (this, this.enemy, autocvar_g_vehicle_racer_blowup_coredamage, - autocvar_g_vehicle_racer_blowup_edgedamage, - autocvar_g_vehicle_racer_blowup_radius, NULL, NULL, - autocvar_g_vehicle_racer_blowup_forceintensity, - DEATH_VH_WAKI_DEATH.m_id, NULL); + RadiusDamage(this, this.enemy, autocvar_g_vehicle_racer_blowup_coredamage, + autocvar_g_vehicle_racer_blowup_edgedamage, + autocvar_g_vehicle_racer_blowup_radius, NULL, NULL, + autocvar_g_vehicle_racer_blowup_forceintensity, + DEATH_VH_WAKI_DEATH.m_id, NULL); this.nextthink = time + autocvar_g_vehicle_racer_respawntime; setthink(this, vehicles_spawn); set_movetype(this, MOVETYPE_NONE); - this.effects = EF_NODRAW; + this.effects = EF_NODRAW; this.solid = SOLID_NOT; this.colormod = '0 0 0'; @@ -481,8 +466,9 @@ void racer_blowup_think(entity this) { this.nextthink = time; - if(time >= this.delay) + if (time >= this.delay) { racer_blowup(this); + } CSQCMODEL_AUTOUPDATE(this); } @@ -491,14 +477,15 @@ void racer_deadtouch(entity this, entity toucher) { this.avelocity_x *= 0.7; this.cnt -= 1; - if(this.cnt <= 0) + if (this.cnt <= 0) { racer_blowup(this); + } } spawnfunc(vehicle_racer) { - if(!autocvar_g_vehicle_racer) { delete(this); return; } - if(!vehicle_initialize(this, VEH_RACER, false)) { delete(this); return; } + if (!autocvar_g_vehicle_racer) { delete(this); return; } + if (!vehicle_initialize(this, VEH_RACER, false)) { delete(this); return; } } #endif // SVQC @@ -506,132 +493,140 @@ spawnfunc(vehicle_racer) METHOD(Racer, vr_impact, void(Racer thisveh, entity instance)) { #ifdef SVQC - if(autocvar_g_vehicle_racer_bouncepain) - vehicles_impact(instance, autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z); + if (autocvar_g_vehicle_racer_bouncepain) { + vehicles_impact(instance, autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z); + } #endif } METHOD(Racer, vr_enter, void(Racer thisveh, entity instance)) { #ifdef SVQC - set_movetype(instance, MOVETYPE_BOUNCE); - instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_racer_health) * 100; - instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_racer_shield) * 100; + set_movetype(instance, MOVETYPE_BOUNCE); + instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_racer_health) * 100; + instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_racer_shield) * 100; - if(instance.owner.flagcarried) - setorigin(instance.owner.flagcarried, '-190 0 96'); + if (instance.owner.flagcarried) { + setorigin(instance.owner.flagcarried, '-190 0 96'); + } #elif defined(CSQC) - set_movetype(instance, MOVETYPE_BOUNCE); + set_movetype(instance, MOVETYPE_BOUNCE); #endif } METHOD(Racer, vr_spawn, void(Racer thisveh, entity instance)) { #ifdef SVQC - if(instance.scale != 0.5) - { - if(autocvar_g_vehicle_racer_hovertype != 0) - racer_force_from_tag = vehicles_force_fromtag_maglev; - else - racer_force_from_tag = vehicles_force_fromtag_hover; - - // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel). - instance.scale = 0.5; - setattachment(instance.vehicle_hudmodel, instance, ""); - setattachment(instance.vehicle_viewport, instance, "tag_viewport"); - - instance.mass = 900; - } - - setthink(instance, racer_think); - instance.nextthink = time; - instance.vehicle_health = autocvar_g_vehicle_racer_health; - instance.vehicle_shield = autocvar_g_vehicle_racer_shield; - - set_movetype(instance, MOVETYPE_TOSS); - instance.solid = SOLID_SLIDEBOX; - instance.delay = time; - instance.scale = 0.5; - - instance.PlayerPhysplug = racer_frame; - - instance.bouncefactor = autocvar_g_vehicle_racer_bouncefactor; - instance.bouncestop = autocvar_g_vehicle_racer_bouncestop; - instance.damageforcescale = 0.5; - instance.vehicle_health = autocvar_g_vehicle_racer_health; - instance.vehicle_shield = autocvar_g_vehicle_racer_shield; + if (instance.scale != 0.5) { + if (autocvar_g_vehicle_racer_hovertype != 0) { + racer_force_from_tag = vehicles_force_fromtag_maglev; + } else { + racer_force_from_tag = vehicles_force_fromtag_hover; + } + + // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel). + instance.scale = 0.5; + setattachment(instance.vehicle_hudmodel, instance, ""); + setattachment(instance.vehicle_viewport, instance, "tag_viewport"); + + instance.mass = 900; + } + + setthink(instance, racer_think); + instance.nextthink = time; + instance.vehicle_health = autocvar_g_vehicle_racer_health; + instance.vehicle_shield = autocvar_g_vehicle_racer_shield; + + set_movetype(instance, MOVETYPE_TOSS); + instance.solid = SOLID_SLIDEBOX; + instance.delay = time; + instance.scale = 0.5; + + instance.PlayerPhysplug = racer_frame; + + instance.bouncefactor = autocvar_g_vehicle_racer_bouncefactor; + instance.bouncestop = autocvar_g_vehicle_racer_bouncestop; + instance.damageforcescale = 0.5; + instance.vehicle_health = autocvar_g_vehicle_racer_health; + instance.vehicle_shield = autocvar_g_vehicle_racer_shield; #endif } METHOD(Racer, vr_death, void(Racer thisveh, entity instance)) { #ifdef SVQC - setSendEntity(instance, func_null); // stop networking this racer (for now) - instance.health = 0; - instance.event_damage = func_null; - instance.solid = SOLID_CORPSE; - instance.takedamage = DAMAGE_NO; - instance.deadflag = DEAD_DYING; - set_movetype(instance, MOVETYPE_BOUNCE); - instance.wait = time; - instance.delay = 2 + time + random() * 3; - instance.cnt = 1 + random() * 2; - settouch(instance, racer_deadtouch); - - Send_Effect(EFFECT_EXPLOSION_MEDIUM, instance.origin, '0 0 0', 1); - - if(random() < 0.5) - instance.avelocity_z = 32; - else - instance.avelocity_z = -32; - - instance.avelocity_x = -vlen(instance.velocity) * 0.2; - instance.velocity += '0 0 700'; - instance.colormod = '-0.5 -0.5 -0.5'; - - setthink(instance, racer_blowup_think); - instance.nextthink = time; + setSendEntity(instance, func_null); // stop networking this racer (for now) + instance.health = 0; + instance.event_damage = func_null; + instance.solid = SOLID_CORPSE; + instance.takedamage = DAMAGE_NO; + instance.deadflag = DEAD_DYING; + set_movetype(instance, MOVETYPE_BOUNCE); + instance.wait = time; + instance.delay = 2 + time + random() * 3; + instance.cnt = 1 + random() * 2; + settouch(instance, racer_deadtouch); + + Send_Effect(EFFECT_EXPLOSION_MEDIUM, instance.origin, '0 0 0', 1); + + if (random() < 0.5) { + instance.avelocity_z = 32; + } else { + instance.avelocity_z = -32; + } + + instance.avelocity_x = -vlen(instance.velocity) * 0.2; + instance.velocity += '0 0 700'; + instance.colormod = '-0.5 -0.5 -0.5'; + + setthink(instance, racer_blowup_think); + instance.nextthink = time; #endif } #ifdef CSQC METHOD(Racer, vr_hud, void(Racer thisveh)) { - Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2", - "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, - "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color); + Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2", + "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, + "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color); } METHOD(Racer, vr_crosshair, void(Racer thisveh, entity player)) { - Vehicles_drawCrosshair(vCROSS_GUIDE); + Vehicles_drawCrosshair(vCROSS_GUIDE); } #endif METHOD(Racer, vr_setup, void(Racer thisveh, entity instance)) { #ifdef SVQC - instance.vehicle_exit = racer_exit; + instance.vehicle_exit = racer_exit; - // we have no need to network energy - if(autocvar_g_vehicle_racer_energy) - if(autocvar_g_vehicle_racer_energy_regen) - instance.vehicle_flags |= VHF_ENERGYREGEN; + // we have no need to network energy + if (autocvar_g_vehicle_racer_energy) { + if (autocvar_g_vehicle_racer_energy_regen) { + instance.vehicle_flags |= VHF_ENERGYREGEN; + } + } - if(autocvar_g_vehicle_racer_shield) - instance.vehicle_flags |= VHF_HASSHIELD; + if (autocvar_g_vehicle_racer_shield) { + instance.vehicle_flags |= VHF_HASSHIELD; + } - if(autocvar_g_vehicle_racer_shield_regen) - instance.vehicle_flags |= VHF_SHIELDREGEN; + if (autocvar_g_vehicle_racer_shield_regen) { + instance.vehicle_flags |= VHF_SHIELDREGEN; + } - if(autocvar_g_vehicle_racer_health_regen) - instance.vehicle_flags |= VHF_HEALTHREGEN; + if (autocvar_g_vehicle_racer_health_regen) { + instance.vehicle_flags |= VHF_HEALTHREGEN; + } - instance.respawntime = autocvar_g_vehicle_racer_respawntime; - instance.vehicle_health = autocvar_g_vehicle_racer_health; - instance.vehicle_shield = autocvar_g_vehicle_racer_shield; - instance.max_health = instance.vehicle_health; + instance.respawntime = autocvar_g_vehicle_racer_respawntime; + instance.vehicle_health = autocvar_g_vehicle_racer_health; + instance.vehicle_shield = autocvar_g_vehicle_racer_shield; + instance.max_health = instance.vehicle_health; #endif #ifdef CSQC - AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket + AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket #endif } diff --git a/qcsrc/common/vehicles/vehicle/racer.qh b/qcsrc/common/vehicles/vehicle/racer.qh index 3c348ae1c..f1c704cf8 100644 --- a/qcsrc/common/vehicles/vehicle/racer.qh +++ b/qcsrc/common/vehicles/vehicle/racer.qh @@ -8,8 +8,8 @@ CLASS(Racer, Vehicle) /* maxs */ ATTRIB(Racer, m_maxs, vector, '120 120 40' * 0.5); /* view offset*/ ATTRIB(Racer, view_ofs, vector, '0 0 50'); /* view dist */ ATTRIB(Racer, height, float, 200); -/* model */ ATTRIB(Racer, mdl, string, "models/vehicles/wakizashi.dpm"); -/* model */ ATTRIB(Racer, model, string, "models/vehicles/wakizashi.dpm"); +/* model */ATTRIB(Racer, mdl, string, "models/vehicles/wakizashi.dpm"); +/* model */ATTRIB(Racer, model, string, "models/vehicles/wakizashi.dpm"); /* head_model */ ATTRIB(Racer, head_model, string, "null"); /* hud_model */ ATTRIB(Racer, hud_model, string, "models/vehicles/wakizashi_cockpit.dpm"); /* tags */ ATTRIB(Racer, tag_head, string, ""); diff --git a/qcsrc/common/vehicles/vehicle/racer_weapon.qc b/qcsrc/common/vehicles/vehicle/racer_weapon.qc index 02015eb8d..97fe333cd 100644 --- a/qcsrc/common/vehicles/vehicle/racer_weapon.qc +++ b/qcsrc/common/vehicles/vehicle/racer_weapon.qc @@ -5,39 +5,41 @@ void racer_fire_rocket(entity player, vector org, vector dir, entity trg); METHOD(RacerAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - entity player = isPlayer ? actor : actor.owner; - entity veh = player.vehicle; - if (fire & 1) - if (weapon_prepareattack(thiswep, player, weaponentity, false, autocvar_g_vehicle_racer_cannon_refire)) { - if (veh) { - veh.vehicle_energy -= autocvar_g_vehicle_racer_cannon_cost; - veh.wait = time; - } - if (isPlayer) W_SetupShot_Dir(player, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0); - vector org = w_shotorg; - vector dir = w_shotdir; - entity bolt = vehicles_projectile(veh, EFFECT_RACER_MUZZLEFLASH.eent_eff_name, SND_LASERGUN_FIRE, - org, normalize(v_forward + randomvec() * autocvar_g_vehicle_racer_cannon_spread) * autocvar_g_vehicle_racer_cannon_speed, - autocvar_g_vehicle_racer_cannon_damage, autocvar_g_vehicle_racer_cannon_radius, autocvar_g_vehicle_racer_cannon_force, 0, - DEATH_VH_WAKI_GUN.m_id, PROJECTILE_WAKICANNON, 0, true, true, player); - bolt.velocity = normalize(dir) * autocvar_g_vehicle_racer_cannon_speed; - weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready); - } - if (fire & 2) - if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) { - if (isPlayer) W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0); - racer_fire_rocket(player, w_shotorg, w_shotdir, NULL); - weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready); - } + bool isPlayer = IS_PLAYER(actor); + entity player = isPlayer ? actor : actor.owner; + entity veh = player.vehicle; + if (fire & 1) { + if (weapon_prepareattack(thiswep, player, weaponentity, false, autocvar_g_vehicle_racer_cannon_refire)) { + if (veh) { + veh.vehicle_energy -= autocvar_g_vehicle_racer_cannon_cost; + veh.wait = time; + } + if (isPlayer) { W_SetupShot_Dir(player, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0); } + vector org = w_shotorg; + vector dir = w_shotdir; + entity bolt = vehicles_projectile(veh, EFFECT_RACER_MUZZLEFLASH.eent_eff_name, SND_LASERGUN_FIRE, + org, normalize(v_forward + randomvec() * autocvar_g_vehicle_racer_cannon_spread) * autocvar_g_vehicle_racer_cannon_speed, + autocvar_g_vehicle_racer_cannon_damage, autocvar_g_vehicle_racer_cannon_radius, autocvar_g_vehicle_racer_cannon_force, 0, + DEATH_VH_WAKI_GUN.m_id, PROJECTILE_WAKICANNON, 0, true, true, player); + bolt.velocity = normalize(dir) * autocvar_g_vehicle_racer_cannon_speed; + weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready); + } + } + if (fire & 2) { + if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) { + if (isPlayer) { W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0); } + racer_fire_rocket(player, w_shotorg, w_shotdir, NULL); + weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready); + } + } } METHOD(RacerAttack, wr_checkammo1, bool(RacerAttack thiswep, entity actor, .entity weaponentity)) { - bool isPlayer = IS_PLAYER(actor); - entity player = isPlayer ? actor : actor.owner; - entity veh = player.vehicle; - return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_racer_cannon_cost; + bool isPlayer = IS_PLAYER(actor); + entity player = isPlayer ? actor : actor.owner; + entity veh = player.vehicle; + return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_racer_cannon_cost; } void racer_rocket_tracker(entity this); @@ -45,125 +47,117 @@ void racer_rocket_groundhugger(entity this); void racer_fire_rocket(entity player, vector org, vector dir, entity trg) { - entity rocket = vehicles_projectile(player.vehicle, EFFECT_RACER_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, - org, dir * autocvar_g_vehicle_racer_rocket_speed, - autocvar_g_vehicle_racer_rocket_damage, autocvar_g_vehicle_racer_rocket_radius, autocvar_g_vehicle_racer_rocket_force, 3, - DEATH_VH_WAKI_ROCKET.m_id, PROJECTILE_WAKIROCKET, 20, false, false, player); - - rocket.lip = autocvar_g_vehicle_racer_rocket_accel * sys_frametime; - rocket.wait = autocvar_g_vehicle_racer_rocket_turnrate; - rocket.nextthink = time; - rocket.enemy = trg; - rocket.cnt = time + 15; - - if(trg) - setthink(rocket, racer_rocket_tracker); - else - setthink(rocket, racer_rocket_groundhugger); + entity rocket = vehicles_projectile(player.vehicle, EFFECT_RACER_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, + org, dir * autocvar_g_vehicle_racer_rocket_speed, + autocvar_g_vehicle_racer_rocket_damage, autocvar_g_vehicle_racer_rocket_radius, autocvar_g_vehicle_racer_rocket_force, 3, + DEATH_VH_WAKI_ROCKET.m_id, PROJECTILE_WAKIROCKET, 20, false, false, player); + + rocket.lip = autocvar_g_vehicle_racer_rocket_accel * sys_frametime; + rocket.wait = autocvar_g_vehicle_racer_rocket_turnrate; + rocket.nextthink = time; + rocket.enemy = trg; + rocket.cnt = time + 15; + + if (trg) { + setthink(rocket, racer_rocket_tracker); + } else { + setthink(rocket, racer_rocket_groundhugger); + } } void racer_rocket_tracker(entity this) { - vector olddir, newdir; - float oldvel, newvel; - - this.nextthink = time; - - if (IS_DEAD(this.owner) || this.cnt < time) - { - this.use(this, NULL, NULL); - return; - } - - if(!this.realowner.vehicle) - { - UpdateCSQCProjectile(this); - return; - } - - olddir = normalize(this.velocity); - oldvel = vlen(this.velocity); - newvel = oldvel + this.lip; - makevectors(vectoangles(olddir)); - - float time_to_impact = min(vlen(this.enemy.origin - this.origin) / vlen(this.velocity), 1); - vector predicted_origin = this.enemy.origin + this.enemy.velocity * time_to_impact; - - traceline(this.origin, this.origin + v_forward * 64 - '0 0 32', MOVE_NORMAL, this); - newdir = normalize(predicted_origin - this.origin); - - //vector - float height_diff = predicted_origin_z - this.origin_z; - - if(vdist(newdir - v_forward, >, autocvar_g_vehicle_racer_rocket_locked_maxangle)) - { - //bprint("Target lost!\n"); - //dprint("OF:", ftos(vlen(newdir - v_forward)), "\n"); - setthink(this, racer_rocket_groundhugger); - return; - } - - if(trace_fraction != 1.0 && trace_ent != this.enemy) - newdir_z += 16 * sys_frametime; - - this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_racer_rocket_turnrate) * newvel; - this.velocity_z -= 800 * sys_frametime; - this.velocity_z += max(height_diff, autocvar_g_vehicle_racer_rocket_climbspeed) * sys_frametime ; - - UpdateCSQCProjectile(this); - return; + vector olddir, newdir; + float oldvel, newvel; + + this.nextthink = time; + + if (IS_DEAD(this.owner) || this.cnt < time) { + this.use(this, NULL, NULL); + return; + } + + if (!this.realowner.vehicle) { + UpdateCSQCProjectile(this); + return; + } + + olddir = normalize(this.velocity); + oldvel = vlen(this.velocity); + newvel = oldvel + this.lip; + makevectors(vectoangles(olddir)); + + float time_to_impact = min(vlen(this.enemy.origin - this.origin) / vlen(this.velocity), 1); + vector predicted_origin = this.enemy.origin + this.enemy.velocity * time_to_impact; + + traceline(this.origin, this.origin + v_forward * 64 - '0 0 32', MOVE_NORMAL, this); + newdir = normalize(predicted_origin - this.origin); + + // vector + float height_diff = predicted_origin_z - this.origin_z; + + if (vdist(newdir - v_forward, >, autocvar_g_vehicle_racer_rocket_locked_maxangle)) { + // bprint("Target lost!\n"); + // dprint("OF:", ftos(vlen(newdir - v_forward)), "\n"); + setthink(this, racer_rocket_groundhugger); + return; + } + + if (trace_fraction != 1.0 && trace_ent != this.enemy) { + newdir_z += 16 * sys_frametime; + } + + this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_racer_rocket_turnrate) * newvel; + this.velocity_z -= 800 * sys_frametime; + this.velocity_z += max(height_diff, autocvar_g_vehicle_racer_rocket_climbspeed) * sys_frametime; + + UpdateCSQCProjectile(this); } void racer_rocket_groundhugger(entity this) { - vector olddir, newdir; - float oldvel, newvel; - - this.nextthink = time; - - if(IS_DEAD(this.owner) || this.cnt < time) - { - this.use(this, NULL, NULL); - return; - } - - if(!this.realowner.vehicle) - { - UpdateCSQCProjectile(this); - return; - } - - olddir = normalize(this.velocity); - oldvel = vlen(this.velocity); - newvel = oldvel + this.lip; - - tracebox(this.origin, this.mins, this.maxs, this.origin + olddir * 64, MOVE_WORLDONLY,this); - if(trace_fraction <= 0.5) - { - // Hitting somethign soon, just speed ahead - this.velocity = olddir * newvel; - UpdateCSQCProjectile(this); - return; - } - - traceline(trace_endpos, trace_endpos - '0 0 64', MOVE_NORMAL, this); - if(trace_fraction != 1.0) - { - newdir = normalize(trace_endpos + '0 0 64' - this.origin) * autocvar_g_vehicle_racer_rocket_turnrate; - this.velocity = normalize(olddir + newdir) * newvel; - } - else - { - this.velocity = olddir * newvel; - this.velocity_z -= 1600 * sys_frametime; // 2x grav looks better for this one - } - - int cont = pointcontents(this.origin - '0 0 32'); - if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME) - this.velocity_z += 200; - - UpdateCSQCProjectile(this); - return; + vector olddir, newdir; + float oldvel, newvel; + + this.nextthink = time; + + if (IS_DEAD(this.owner) || this.cnt < time) { + this.use(this, NULL, NULL); + return; + } + + if (!this.realowner.vehicle) { + UpdateCSQCProjectile(this); + return; + } + + olddir = normalize(this.velocity); + oldvel = vlen(this.velocity); + newvel = oldvel + this.lip; + + tracebox(this.origin, this.mins, this.maxs, this.origin + olddir * 64, MOVE_WORLDONLY, this); + if (trace_fraction <= 0.5) { + // Hitting somethign soon, just speed ahead + this.velocity = olddir * newvel; + UpdateCSQCProjectile(this); + return; + } + + traceline(trace_endpos, trace_endpos - '0 0 64', MOVE_NORMAL, this); + if (trace_fraction != 1.0) { + newdir = normalize(trace_endpos + '0 0 64' - this.origin) * autocvar_g_vehicle_racer_rocket_turnrate; + this.velocity = normalize(olddir + newdir) * newvel; + } else { + this.velocity = olddir * newvel; + this.velocity_z -= 1600 * sys_frametime; // 2x grav looks better for this one + } + + int cont = pointcontents(this.origin - '0 0 32'); + if (cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME) { + this.velocity_z += 200; + } + + UpdateCSQCProjectile(this); } #endif diff --git a/qcsrc/common/vehicles/vehicle/raptor.qc b/qcsrc/common/vehicles/vehicle/raptor.qc index d7ef38abc..5e1f75578 100644 --- a/qcsrc/common/vehicles/vehicle/raptor.qc +++ b/qcsrc/common/vehicles/vehicle/raptor.qc @@ -61,17 +61,17 @@ void raptor_land(entity this) this.angles_x *= 0.95; this.angles_z *= 0.95; - if(hgt < 128 && hgt > 0) + if (hgt < 128 && hgt > 0) { this.frame = (hgt / 128) * 25; + } this.bomb1.gun1.avelocity_y = 90 + ((this.frame / 25) * 2000); this.bomb1.gun2.avelocity_y = -this.bomb1.gun1.avelocity_y; - if(hgt < 16) - { + if (hgt < 16) { set_movetype(this, MOVETYPE_TOSS); setthink(this, vehicles_think); - this.frame = 0; + this.frame = 0; } this.nextthink = time; @@ -85,36 +85,30 @@ void raptor_exit(entity this, int eject) this.tur_head.exteriormodeltoclient = NULL; - if(!IS_DEAD(this)) - { + if (!IS_DEAD(this)) { setthink(this, raptor_land); this.nextthink = time; } - if(!player) + if (!player) { return; + } makevectors(this.angles); vector spot; - if(eject) - { + if (eject) { spot = this.origin + v_forward * 100 + '0 0 64'; spot = vehicles_findgoodexit(this, player, spot); setorigin(player, spot); player.velocity = (v_up + v_forward * 0.25) * 750; player.oldvelocity = player.velocity; - } - else - { - if(vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed)) - { + } else { + if (vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed)) { player.velocity = normalize(this.velocity) * autocvar_sv_maxairspeed * 2; player.velocity_z += 200; spot = this.origin + v_forward * 32 + '0 0 64'; spot = vehicles_findgoodexit(this, player, spot); - } - else - { + } else { player.velocity = this.velocity * 0.5; player.velocity_z += 10; spot = this.origin - v_forward * 200 + '0 0 64'; @@ -133,8 +127,7 @@ bool raptor_frame(entity this, float dt) entity vehic = this.vehicle; return = true; - if(game_stopped) - { + if (game_stopped) { vehic.solid = SOLID_NOT; vehic.takedamage = DAMAGE_NO; set_movetype(vehic, MOVETYPE_NONE); @@ -146,66 +139,63 @@ bool raptor_frame(entity this, float dt) /* ftmp = vlen(vehic.velocity); if(ftmp > autocvar_g_vehicle_raptor_speed_forward) - ftmp = 1; + ftmp = 1; else - ftmp = ftmp / autocvar_g_vehicle_raptor_speed_forward; + ftmp = ftmp / autocvar_g_vehicle_raptor_speed_forward; */ - if(vehic.sound_nexttime < time) - { + if (vehic.sound_nexttime < time) { vehic.sound_nexttime = time + 7.955812; - //sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_FLY, 1 - ftmp, ATTEN_NORM ); - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, 1, ATTEN_NORM); + // sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_FLY, 1 - ftmp, ATTEN_NORM ); + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, 1, ATTEN_NORM); vehic.wait = 0; } /* else if(fabs(ftmp - vehic.wait) > 0.2) { - sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, 1 - ftmp, ATTEN_NORM ); - sound (vehic, CH_TRIGGER_SINGLE, SND_Null, ftmp, ATTEN_NORM); - vehic.wait = ftmp; + sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, 1 - ftmp, ATTEN_NORM ); + sound (vehic, CH_TRIGGER_SINGLE, SND_Null, ftmp, ATTEN_NORM); + vehic.wait = ftmp; } */ - if(IS_DEAD(vehic)) - { + if (IS_DEAD(vehic)) { PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false; return; } crosshair_trace(this); - //if(time - vehic.lastteleporttime < 1) - //{ - if(vehic.angles_z > 50 || vehic.angles_z < -50) - { - if(PHYS_INPUT_BUTTON_JUMP(this)) - { - PHYS_INPUT_BUTTON_CROUCH(this) = true; - PHYS_INPUT_BUTTON_JUMP(this) = false; - } + // if(time - vehic.lastteleporttime < 1) + // { + if (vehic.angles_z > 50 || vehic.angles_z < -50) { + if (PHYS_INPUT_BUTTON_JUMP(this)) { + PHYS_INPUT_BUTTON_CROUCH(this) = true; + PHYS_INPUT_BUTTON_JUMP(this) = false; } - //} + } + // } vector vang; vang = vehic.angles; vector df = vectoangles(normalize(trace_endpos - vehic.origin + '0 0 32')); vang_x *= -1; df_x *= -1; - if(df_x > 180) df_x -= 360; - if(df_x < -180) df_x += 360; - if(df_y > 180) df_y -= 360; - if(df_y < -180) df_y += 360; + if (df_x > 180) { df_x -= 360; } + if (df_x < -180) { df_x += 360; } + if (df_y > 180) { df_y -= 360; } + if (df_y < -180) { df_y += 360; } float ftmp = shortangle_f(this.v_angle_y - vang_y, vang_y); - if(ftmp > 180) ftmp -= 360; if(ftmp < -180) ftmp += 360; + if (ftmp > 180) { ftmp -= 360; } if (ftmp < -180) { ftmp += 360; } vehic.avelocity_y = bound(-autocvar_g_vehicle_raptor_turnspeed, ftmp + vehic.avelocity_y * 0.9, autocvar_g_vehicle_raptor_turnspeed); // Pitch ftmp = 0; - if(CS(this).movement_x > 0 && vang_x < autocvar_g_vehicle_raptor_pitchlimit) ftmp = 5; - else if(CS(this).movement_x < 0 && vang_x > -autocvar_g_vehicle_raptor_pitchlimit) ftmp = -20; + if (CS(this).movement_x > 0 && vang_x < autocvar_g_vehicle_raptor_pitchlimit) { ftmp = 5; } else if (CS(this).movement_x < 0 && vang_x > -autocvar_g_vehicle_raptor_pitchlimit) { + ftmp = -20; + } - df_x = bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x , autocvar_g_vehicle_raptor_pitchlimit); + df_x = bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x, autocvar_g_vehicle_raptor_pitchlimit); ftmp = vang_x - bound(-autocvar_g_vehicle_raptor_pitchlimit, df_x + ftmp, autocvar_g_vehicle_raptor_pitchlimit); vehic.avelocity_x = bound(-autocvar_g_vehicle_raptor_pitchspeed, ftmp + vehic.avelocity_x * 0.9, autocvar_g_vehicle_raptor_pitchspeed); @@ -213,41 +203,42 @@ bool raptor_frame(entity this, float dt) vehic.angles_y = anglemods(vehic.angles_y); vehic.angles_z = anglemods(vehic.angles_z); - if(autocvar_g_vehicle_raptor_movestyle == 1) + if (autocvar_g_vehicle_raptor_movestyle == 1) { makevectors('0 1 0' * vehic.angles_y); - else + } else { makevectors(this.v_angle); + } df = vehic.velocity * -autocvar_g_vehicle_raptor_friction; - if(CS(this).movement_x != 0) - { - if(CS(this).movement_x > 0) + if (CS(this).movement_x != 0) { + if (CS(this).movement_x > 0) { df += v_forward * autocvar_g_vehicle_raptor_speed_forward; - else if(CS(this).movement_x < 0) + } else if (CS(this).movement_x < 0) { df -= v_forward * autocvar_g_vehicle_raptor_speed_forward; + } } - if(CS(this).movement_y != 0) - { - if(CS(this).movement_y < 0) + if (CS(this).movement_y != 0) { + if (CS(this).movement_y < 0) { df -= v_right * autocvar_g_vehicle_raptor_speed_strafe; - else if(CS(this).movement_y > 0) + } else if (CS(this).movement_y > 0) { df += v_right * autocvar_g_vehicle_raptor_speed_strafe; + } - vehic.angles_z = bound(-30,vehic.angles_z + (CS(this).movement_y / autocvar_g_vehicle_raptor_speed_strafe),30); - } - else - { + vehic.angles_z = bound(-30, vehic.angles_z + (CS(this).movement_y / autocvar_g_vehicle_raptor_speed_strafe), 30); + } else { vehic.angles_z *= 0.95; - if(vehic.angles_z >= -1 && vehic.angles_z <= -1) + if (vehic.angles_z >= -1 && vehic.angles_z <= -1) { vehic.angles_z = 0; + } } - if(PHYS_INPUT_BUTTON_CROUCH(this)) + if (PHYS_INPUT_BUTTON_CROUCH(this)) { df -= v_up * autocvar_g_vehicle_raptor_speed_down; - else if (PHYS_INPUT_BUTTON_JUMP(this)) + } else if (PHYS_INPUT_BUTTON_JUMP(this)) { df += v_up * autocvar_g_vehicle_raptor_speed_up; + } vehic.velocity += df * dt; this.velocity = CS(this).movement = vehic.velocity; @@ -258,96 +249,90 @@ bool raptor_frame(entity this, float dt) vector vf, ad; // Target lock & predict - if(autocvar_g_vehicle_raptor_cannon_locktarget == 2) - { - if(vehic.gun1.lock_time < time || IS_DEAD(vehic.gun1.enemy) || STAT(FROZEN, vehic.gun1.enemy)) + if (autocvar_g_vehicle_raptor_cannon_locktarget == 2) { + if (vehic.gun1.lock_time < time || IS_DEAD(vehic.gun1.enemy) || STAT(FROZEN, vehic.gun1.enemy)) { vehic.gun1.enemy = NULL; + } - if(trace_ent) - if(trace_ent.move_movetype) - if(trace_ent.takedamage) - if(!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent)) - { - if(teamplay) - { - if(trace_ent.team != this.team) - { - vehic.gun1.enemy = trace_ent; - vehic.gun1.lock_time = time + 5; + if (trace_ent) { + if (trace_ent.move_movetype) { + if (trace_ent.takedamage) { + if (!IS_DEAD(trace_ent) && !STAT(FROZEN, trace_ent)) { + if (teamplay) { + if (trace_ent.team != this.team) { + vehic.gun1.enemy = trace_ent; + vehic.gun1.lock_time = time + 5; + } + } else { + vehic.gun1.enemy = trace_ent; + vehic.gun1.lock_time = time + 0.5; + } + } } } - else - { - vehic.gun1.enemy = trace_ent; - vehic.gun1.lock_time = time + 0.5; - } } - if(vehic.gun1.enemy) - { + if (vehic.gun1.enemy) { float distance, impact_time; vf = real_origin(vehic.gun1.enemy); UpdateAuxiliaryXhair(this, vf, '1 0 0', 1); vector _vel = vehic.gun1.enemy.velocity; - if(vehic.gun1.enemy.move_movetype == MOVETYPE_WALK) + if (vehic.gun1.enemy.move_movetype == MOVETYPE_WALK) { _vel_z *= 0.1; + } - if(autocvar_g_vehicle_raptor_cannon_predicttarget) - { + if (autocvar_g_vehicle_raptor_cannon_predicttarget) { ad = vf; distance = vlen(ad - this.origin); impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed; ad = vf + _vel * impact_time; trace_endpos = ad; - } - else + } else { trace_endpos = vf; + } } - } - else if(autocvar_g_vehicle_raptor_cannon_locktarget == 1) - { - + } else if (autocvar_g_vehicle_raptor_cannon_locktarget == 1) { vehicles_locktarget(vehic, (1 / autocvar_g_vehicle_raptor_cannon_locking_time) * dt, - (1 / autocvar_g_vehicle_raptor_cannon_locking_releasetime) * dt, - autocvar_g_vehicle_raptor_cannon_locked_time); - - if(vehic.lock_target != NULL) - if(autocvar_g_vehicle_raptor_cannon_predicttarget) - if(vehic.lock_strength == 1) - { - float i, distance, impact_time; - - vf = real_origin(vehic.lock_target); - ad = vf; - for(i = 0; i < 4; ++i) - { - distance = vlen(ad - vehic.origin); - impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed; - ad = vf + vehic.lock_target.velocity * impact_time; + (1 / autocvar_g_vehicle_raptor_cannon_locking_releasetime) * dt, + autocvar_g_vehicle_raptor_cannon_locked_time); + + if (vehic.lock_target != NULL) { + if (autocvar_g_vehicle_raptor_cannon_predicttarget) { + if (vehic.lock_strength == 1) { + float i, distance, impact_time; + + vf = real_origin(vehic.lock_target); + ad = vf; + for (i = 0; i < 4; ++i) { + distance = vlen(ad - vehic.origin); + impact_time = distance / autocvar_g_vehicle_raptor_cannon_speed; + ad = vf + vehic.lock_target.velocity * impact_time; + } + trace_endpos = ad; + } } - trace_endpos = ad; } - if(vehic.lock_target) - { - if(vehic.lock_strength == 1) + if (vehic.lock_target) { + if (vehic.lock_strength == 1) { UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '1 0 0', 1); - else if(vehic.lock_strength > 0.5) + } else if (vehic.lock_strength > 0.5) { UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 1 0', 1); - else if(vehic.lock_strength < 0.5) + } else if (vehic.lock_strength < 0.5) { UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 0 1', 1); + } } } vehicle_aimturret(vehic, trace_endpos, vehic.gun1, "fire1", - autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1, autocvar_g_vehicle_raptor_cannon_pitchlimit_up, - autocvar_g_vehicle_raptor_cannon_turnlimit * -1, autocvar_g_vehicle_raptor_cannon_turnlimit, autocvar_g_vehicle_raptor_cannon_turnspeed); + autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1, autocvar_g_vehicle_raptor_cannon_pitchlimit_up, + autocvar_g_vehicle_raptor_cannon_turnlimit * -1, autocvar_g_vehicle_raptor_cannon_turnlimit, autocvar_g_vehicle_raptor_cannon_turnspeed); vehicle_aimturret(vehic, trace_endpos, vehic.gun2, "fire1", - autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1, autocvar_g_vehicle_raptor_cannon_pitchlimit_up, - autocvar_g_vehicle_raptor_cannon_turnlimit * -1, autocvar_g_vehicle_raptor_cannon_turnlimit, autocvar_g_vehicle_raptor_cannon_turnspeed); + autocvar_g_vehicle_raptor_cannon_pitchlimit_down * -1, autocvar_g_vehicle_raptor_cannon_pitchlimit_up, + autocvar_g_vehicle_raptor_cannon_turnlimit * -1, autocvar_g_vehicle_raptor_cannon_turnlimit, autocvar_g_vehicle_raptor_cannon_turnspeed); /* ad = ad * 0.5; @@ -358,45 +343,47 @@ bool raptor_frame(entity this, float dt) Weapon wep1 = WEP_RAPTOR; .entity weaponentity = weaponentities[0]; - if(!forbidWeaponUse(this)) - if(PHYS_INPUT_BUTTON_ATCK(this)) - if (wep1.wr_checkammo1(wep1, vehic, weaponentity)) - { - wep1.wr_think(wep1, vehic, weaponentity, 1); + if (!forbidWeaponUse(this)) { + if (PHYS_INPUT_BUTTON_ATCK(this)) { + if (wep1.wr_checkammo1(wep1, vehic, weaponentity)) { + wep1.wr_think(wep1, vehic, weaponentity, 1); + } + } } - if(vehic.vehicle_flags & VHF_SHIELDREGEN) + if (vehic.vehicle_flags & VHF_SHIELDREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_raptor_shield, autocvar_g_vehicle_raptor_shield_regen_pause, autocvar_g_vehicle_raptor_shield_regen, dt, true); + } - if(vehic.vehicle_flags & VHF_HEALTHREGEN) + if (vehic.vehicle_flags & VHF_HEALTHREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_raptor_health, autocvar_g_vehicle_raptor_health_regen_pause, autocvar_g_vehicle_raptor_health_regen, dt, false); + } - if(vehic.vehicle_flags & VHF_ENERGYREGEN) + if (vehic.vehicle_flags & VHF_ENERGYREGEN) { vehicles_regen(vehic, vehic.cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, dt, false); + } Weapon wep2a = WEP_RAPTOR_BOMB; - if(!forbidWeaponUse(this)) - if(vehic.vehicle_weapon2mode == RSM_BOMB) - { - if(time > vehic.lip + autocvar_g_vehicle_raptor_bombs_refire) - if(PHYS_INPUT_BUTTON_ATCK2(this)) - { - .entity weaponentity = weaponentities[1]; - wep2a.wr_think(wep2a, vehic, weaponentity, 2); - vehic.delay = time + autocvar_g_vehicle_raptor_bombs_refire; - vehic.lip = time; - } - } - else - { - Weapon wep2b = WEP_RAPTOR_FLARE; - if(time > vehic.lip + autocvar_g_vehicle_raptor_flare_refire) - if(PHYS_INPUT_BUTTON_ATCK2(this)) - { - .entity weaponentity = weaponentities[1]; - wep2b.wr_think(wep2b, vehic, weaponentity, 2); - vehic.delay = time + autocvar_g_vehicle_raptor_flare_refire; - vehic.lip = time; + if (!forbidWeaponUse(this)) { + if (vehic.vehicle_weapon2mode == RSM_BOMB) { + if (time > vehic.lip + autocvar_g_vehicle_raptor_bombs_refire) { + if (PHYS_INPUT_BUTTON_ATCK2(this)) { + .entity weaponentity = weaponentities[1]; + wep2a.wr_think(wep2a, vehic, weaponentity, 2); + vehic.delay = time + autocvar_g_vehicle_raptor_bombs_refire; + vehic.lip = time; + } + } + } else { + Weapon wep2b = WEP_RAPTOR_FLARE; + if (time > vehic.lip + autocvar_g_vehicle_raptor_flare_refire) { + if (PHYS_INPUT_BUTTON_ATCK2(this)) { + .entity weaponentity = weaponentities[1]; + wep2b.wr_think(wep2b, vehic, weaponentity, 2); + vehic.delay = time + autocvar_g_vehicle_raptor_flare_refire; + vehic.lip = time; + } + } } } @@ -404,21 +391,19 @@ bool raptor_frame(entity this, float dt) this.vehicle_reload2 = bound(0, vehic.bomb1.alpha * 100, 100); this.vehicle_ammo2 = (this.vehicle_reload2 == 100) ? 100 : 0; - if(vehic.bomb1.cnt < time) - { + if (vehic.bomb1.cnt < time) { bool incoming = false; IL_EACH(g_projectiles, it.enemy == vehic, { - if(MISSILE_IS_TRACKING(it)) - if(vdist(vehic.origin - it.origin, <, 2 * autocvar_g_vehicle_raptor_flare_range)) - { - incoming = true; - break; + if (MISSILE_IS_TRACKING(it)) { + if (vdist(vehic.origin - it.origin, <, 2 * autocvar_g_vehicle_raptor_flare_range)) { + incoming = true; + break; + } } }); - if(incoming) - { + if (incoming) { msg_entity = this; soundto(MSG_ONE, vehic, CH_PAIN_SINGLE, SND(VEH_MISSILE_ALARM), VOL_BASE, ATTEN_NONE); } @@ -429,8 +414,9 @@ bool raptor_frame(entity this, float dt) VEHICLE_UPDATE_PLAYER(this, vehic, health, raptor); VEHICLE_UPDATE_PLAYER(this, vehic, energy, raptor); - if(vehic.vehicle_flags & VHF_HASSHIELD) + if (vehic.vehicle_flags & VHF_HASSHIELD) { VEHICLE_UPDATE_PLAYER(this, vehic, shield, raptor); + } PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false; } @@ -442,17 +428,15 @@ bool raptor_takeoff(entity this, float dt) vehic.nextthink = time; CSQCMODEL_AUTOUPDATE(vehic); - vehic.nextthink = 0; // will this work? + vehic.nextthink = 0; // will this work? - if(vehic.sound_nexttime < time) - { - vehic.sound_nexttime = time + 7.955812; //soundlength("vehicles/raptor_fly.wav"); - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, VOL_VEHICLEENGINE, ATTEN_NORM); + if (vehic.sound_nexttime < time) { + vehic.sound_nexttime = time + 7.955812; // soundlength("vehicles/raptor_fly.wav"); + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_RAPTOR_SPEED, VOL_VEHICLEENGINE, ATTEN_NORM); } // Takeoff sequense - if(vehic.frame < 25) - { + if (vehic.frame < 25) { vehic.frame += 25 / (autocvar_g_vehicle_raptor_takeofftime / PHYS_INPUT_FRAMETIME); vehic.velocity_z = min(vehic.velocity_z * 1.5, 256); vehic.bomb1.gun1.avelocity_y = 90 + ((vehic.frame / 25) * 25000); @@ -461,20 +445,23 @@ bool raptor_takeoff(entity this, float dt) setorigin(this, vehic.origin + '0 0 32'); this.oldorigin = this.origin; - } - else + } else { this.PlayerPhysplug = raptor_frame; + } this.vehicle_weapon2mode = vehic.vehicle_weapon2mode; - if(vehic.vehicle_flags & VHF_SHIELDREGEN) + if (vehic.vehicle_flags & VHF_SHIELDREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_raptor_shield, autocvar_g_vehicle_raptor_shield_regen_pause, autocvar_g_vehicle_raptor_shield_regen, dt, true); + } - if(vehic.vehicle_flags & VHF_HEALTHREGEN) + if (vehic.vehicle_flags & VHF_HEALTHREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_raptor_health, autocvar_g_vehicle_raptor_health_regen_pause, autocvar_g_vehicle_raptor_health_regen, dt, false); + } - if(vehic.vehicle_flags & VHF_ENERGYREGEN) + if (vehic.vehicle_flags & VHF_ENERGYREGEN) { vehicles_regen(vehic, vehic.cnt, vehicle_energy, autocvar_g_vehicle_raptor_energy, autocvar_g_vehicle_raptor_energy_regen_pause, autocvar_g_vehicle_raptor_energy_regen, dt, false); + } vehic.bomb1.alpha = vehic.bomb2.alpha = (time - vehic.lip) / (vehic.delay - vehic.lip); @@ -483,24 +470,25 @@ bool raptor_takeoff(entity this, float dt) VEHICLE_UPDATE_PLAYER(this, vehic, health, raptor); VEHICLE_UPDATE_PLAYER(this, vehic, energy, raptor); - if(vehic.vehicle_flags & VHF_HASSHIELD) + if (vehic.vehicle_flags & VHF_HASSHIELD) { VEHICLE_UPDATE_PLAYER(this, vehic, shield, raptor); + } PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false; } void raptor_blowup(entity this, entity toucher) { - this.deadflag = DEAD_DEAD; + this.deadflag = DEAD_DEAD; this.vehicle_exit(this, VHEF_NORMAL); - RadiusDamage (this, this.enemy, 250, 15, 250, NULL, NULL, 250, DEATH_VH_RAPT_DEATH.m_id, NULL); + RadiusDamage(this, this.enemy, 250, 15, 250, NULL, NULL, 250, DEATH_VH_RAPT_DEATH.m_id, NULL); - this.alpha = -1; + this.alpha = -1; set_movetype(this, MOVETYPE_NONE); - this.effects = EF_NODRAW; - this.colormod = '0 0 0'; - this.avelocity = '0 0 0'; - this.velocity = '0 0 0'; + this.effects = EF_NODRAW; + this.colormod = '0 0 0'; + this.avelocity = '0 0 0'; + this.velocity = '0 0 0'; setorigin(this, this.pos1); settouch(this, func_null); @@ -509,15 +497,13 @@ void raptor_blowup(entity this, entity toucher) void raptor_diethink(entity this) { - if(time >= this.wait) - { + if (time >= this.wait) { raptor_blowup(this, NULL); return; } - if(random() < 0.05) - { - sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); + if (random() < 0.05) { + sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1); } this.nextthink = time; @@ -536,8 +522,7 @@ void raptor_rotor_anglefix(entity this) bool raptor_impulse(entity this, int _imp) { - switch(_imp) - { + switch (_imp) { case IMP_weapon_group_1.impulse: this.vehicle.vehicle_weapon2mode = RSM_BOMB; CSQCVehicleSetup(this, 0); @@ -551,8 +536,9 @@ bool raptor_impulse(entity this, int _imp) case IMP_weapon_next_bypriority.impulse: case IMP_weapon_next_bygroup.impulse: this.vehicle.vehicle_weapon2mode += 1; - if(this.vehicle.vehicle_weapon2mode > RSM_LAST) + if (this.vehicle.vehicle_weapon2mode > RSM_LAST) { this.vehicle.vehicle_weapon2mode = RSM_FIRST; + } CSQCVehicleSetup(this, 0); return true; @@ -561,190 +547,198 @@ bool raptor_impulse(entity this, int _imp) case IMP_weapon_prev_bypriority.impulse: case IMP_weapon_prev_bygroup.impulse: this.vehicle.vehicle_weapon2mode -= 1; - if(this.vehicle.vehicle_weapon2mode < RSM_FIRST) + if (this.vehicle.vehicle_weapon2mode < RSM_FIRST) { this.vehicle.vehicle_weapon2mode = RSM_LAST; + } CSQCVehicleSetup(this, 0); return true; - /* - case IMP_weapon_drop.impulse: // toss gun, could be used to exit? - break; - case IMP_weapon_reload.impulse: // Manual minigun reload? - break; - */ + /* + case IMP_weapon_drop.impulse: // toss gun, could be used to exit? + break; + case IMP_weapon_reload.impulse: // Manual minigun reload? + break; + */ } return false; } spawnfunc(vehicle_raptor) { - if(!autocvar_g_vehicle_raptor) { delete(this); return; } - if(!vehicle_initialize(this, VEH_RAPTOR, false)) { delete(this); return; } + if (!autocvar_g_vehicle_raptor) { delete(this); return; } + if (!vehicle_initialize(this, VEH_RAPTOR, false)) { delete(this); return; } } METHOD(Raptor, vr_impact, void(Raptor thisveh, entity instance)) { - if(autocvar_g_vehicle_raptor_bouncepain) - vehicles_impact(instance, autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z); + if (autocvar_g_vehicle_raptor_bouncepain) { + vehicles_impact(instance, autocvar_g_vehicle_raptor_bouncepain_x, autocvar_g_vehicle_raptor_bouncepain_y, autocvar_g_vehicle_raptor_bouncepain_z); + } } METHOD(Raptor, vr_enter, void(Raptor thisveh, entity instance)) { - instance.vehicle_weapon2mode = RSM_BOMB; - instance.owner.PlayerPhysplug = raptor_takeoff; - set_movetype(instance, MOVETYPE_BOUNCEMISSILE); - instance.solid = SOLID_SLIDEBOX; - instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_raptor_health) * 100; - instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_raptor_shield) * 100; - instance.velocity = '0 0 1'; // nudge upwards so takeoff sequence can work - instance.tur_head.exteriormodeltoclient = instance.owner; - - instance.delay = time + autocvar_g_vehicle_raptor_bombs_refire; - instance.lip = time; - - if(instance.owner.flagcarried) - setorigin(instance.owner.flagcarried, '-20 0 96'); - - CSQCVehicleSetup(instance.owner, 0); + instance.vehicle_weapon2mode = RSM_BOMB; + instance.owner.PlayerPhysplug = raptor_takeoff; + set_movetype(instance, MOVETYPE_BOUNCEMISSILE); + instance.solid = SOLID_SLIDEBOX; + instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_raptor_health) * 100; + instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_raptor_shield) * 100; + instance.velocity = '0 0 1'; // nudge upwards so takeoff sequence can work + instance.tur_head.exteriormodeltoclient = instance.owner; + + instance.delay = time + autocvar_g_vehicle_raptor_bombs_refire; + instance.lip = time; + + if (instance.owner.flagcarried) { + setorigin(instance.owner.flagcarried, '-20 0 96'); + } + + CSQCVehicleSetup(instance.owner, 0); } METHOD(Raptor, vr_death, void(Raptor thisveh, entity instance)) { - instance.health = 0; - instance.event_damage = func_null; - instance.solid = SOLID_CORPSE; - instance.takedamage = DAMAGE_NO; - instance.deadflag = DEAD_DYING; - set_movetype(instance, MOVETYPE_BOUNCE); - setthink(instance, raptor_diethink); - instance.nextthink = time; - instance.wait = time + 5 + (random() * 5); + instance.health = 0; + instance.event_damage = func_null; + instance.solid = SOLID_CORPSE; + instance.takedamage = DAMAGE_NO; + instance.deadflag = DEAD_DYING; + set_movetype(instance, MOVETYPE_BOUNCE); + setthink(instance, raptor_diethink); + instance.nextthink = time; + instance.wait = time + 5 + (random() * 5); - Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation (instance.origin, 16), '0 0 0', 1); + Send_Effect(EFFECT_EXPLOSION_MEDIUM, findbetterlocation(instance.origin, 16), '0 0 0', 1); - instance.velocity_z += 600; + instance.velocity_z += 600; - instance.avelocity = '0 0.5 1' * (random() * 400); - instance.avelocity -= '0 0.5 1' * (random() * 400); + instance.avelocity = '0 0.5 1' * (random() * 400); + instance.avelocity -= '0 0.5 1' * (random() * 400); - instance.colormod = '-0.5 -0.5 -0.5'; - settouch(instance, raptor_blowup); + instance.colormod = '-0.5 -0.5 -0.5'; + settouch(instance, raptor_blowup); } METHOD(Raptor, vr_spawn, void(Raptor thisveh, entity instance)) { - if(!instance.gun1) - { - entity spinner; - vector ofs; - - //FIXME: Camera is in a bad place in HUD model. - //setorigin(instance.vehicle_viewport, '25 0 5'); - - instance.vehicles_impulse = raptor_impulse; - - instance.frame = 0; - - instance.bomb1 = new(raptor_bomb); - instance.bomb2 = new(raptor_bomb); - instance.gun1 = new(raptor_gun); - instance.gun2 = new(raptor_gun); - - setmodel(instance.bomb1, MDL_VEH_RAPTOR_CB_FOLDED); - setmodel(instance.bomb2, MDL_VEH_RAPTOR_CB_FOLDED); - setmodel(instance.gun1, MDL_VEH_RAPTOR_GUN); - setmodel(instance.gun2, MDL_VEH_RAPTOR_GUN); - setmodel(instance.tur_head, MDL_VEH_RAPTOR_TAIL); - - setattachment(instance.bomb1, instance, "bombmount_left"); - setattachment(instance.bomb2, instance, "bombmount_right"); - setattachment(instance.tur_head, instance,"root"); - - // FIXMODEL Guns mounts to angled bones - instance.bomb1.angles = instance.angles; - instance.angles = '0 0 0'; - // This messes up gun-aim, so work arround it. - //setattachment(instance.gun1, instance, "gunmount_left"); - ofs = gettaginfo(instance, gettagindex(instance, "gunmount_left")); - ofs -= instance.origin; - setattachment(instance.gun1, instance, ""); - setorigin(instance.gun1, ofs); - - //setattachment(instance.gun2, instance, "gunmount_right"); - ofs = gettaginfo(instance, gettagindex(instance, "gunmount_right")); - ofs -= instance.origin; - setattachment(instance.gun2, instance, ""); - setorigin(instance.gun2, ofs); - - instance.angles = instance.bomb1.angles; - instance.bomb1.angles = '0 0 0'; - - spinner = new(raptor_spinner); - spinner.owner = instance; - setmodel(spinner, MDL_VEH_RAPTOR_PROP); - setattachment(spinner, instance, "engine_left"); - set_movetype(spinner, MOVETYPE_NOCLIP); - spinner.avelocity = '0 90 0'; - instance.bomb1.gun1 = spinner; - - spinner = new(raptor_spinner); - spinner.owner = instance; - setmodel(spinner, MDL_VEH_RAPTOR_PROP); - setattachment(spinner, instance, "engine_right"); - set_movetype(spinner, MOVETYPE_NOCLIP); - spinner.avelocity = '0 -90 0'; - instance.bomb1.gun2 = spinner; - - // Sigh. - setthink(instance.bomb1, raptor_rotor_anglefix); - instance.bomb1.nextthink = time; - - instance.mass = 1 ; - } - - instance.frame = 0; - instance.vehicle_health = autocvar_g_vehicle_raptor_health; - instance.vehicle_shield = autocvar_g_vehicle_raptor_shield; - set_movetype(instance, MOVETYPE_TOSS); - instance.solid = SOLID_SLIDEBOX; - instance.vehicle_energy = 1; - - if(!autocvar_g_vehicle_raptor_swim) - instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK; - - instance.PlayerPhysplug = raptor_frame; - - instance.bomb1.gun1.avelocity_y = 90; - instance.bomb1.gun2.avelocity_y = -90; - - instance.delay = time; - - instance.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor; - instance.bouncestop = autocvar_g_vehicle_raptor_bouncestop; - instance.damageforcescale = 0.25; - instance.vehicle_health = autocvar_g_vehicle_raptor_health; - instance.vehicle_shield = autocvar_g_vehicle_raptor_shield; + if (!instance.gun1) { + entity spinner; + vector ofs; + + // FIXME: Camera is in a bad place in HUD model. + // setorigin(instance.vehicle_viewport, '25 0 5'); + + instance.vehicles_impulse = raptor_impulse; + + instance.frame = 0; + + instance.bomb1 = new(raptor_bomb); + instance.bomb2 = new(raptor_bomb); + instance.gun1 = new(raptor_gun); + instance.gun2 = new(raptor_gun); + + setmodel(instance.bomb1, MDL_VEH_RAPTOR_CB_FOLDED); + setmodel(instance.bomb2, MDL_VEH_RAPTOR_CB_FOLDED); + setmodel(instance.gun1, MDL_VEH_RAPTOR_GUN); + setmodel(instance.gun2, MDL_VEH_RAPTOR_GUN); + setmodel(instance.tur_head, MDL_VEH_RAPTOR_TAIL); + + setattachment(instance.bomb1, instance, "bombmount_left"); + setattachment(instance.bomb2, instance, "bombmount_right"); + setattachment(instance.tur_head, instance, "root"); + + // FIXMODEL Guns mounts to angled bones + instance.bomb1.angles = instance.angles; + instance.angles = '0 0 0'; + // This messes up gun-aim, so work arround it. + // setattachment(instance.gun1, instance, "gunmount_left"); + ofs = gettaginfo(instance, gettagindex(instance, "gunmount_left")); + ofs -= instance.origin; + setattachment(instance.gun1, instance, ""); + setorigin(instance.gun1, ofs); + + // setattachment(instance.gun2, instance, "gunmount_right"); + ofs = gettaginfo(instance, gettagindex(instance, "gunmount_right")); + ofs -= instance.origin; + setattachment(instance.gun2, instance, ""); + setorigin(instance.gun2, ofs); + + instance.angles = instance.bomb1.angles; + instance.bomb1.angles = '0 0 0'; + + spinner = new(raptor_spinner); + spinner.owner = instance; + setmodel(spinner, MDL_VEH_RAPTOR_PROP); + setattachment(spinner, instance, "engine_left"); + set_movetype(spinner, MOVETYPE_NOCLIP); + spinner.avelocity = '0 90 0'; + instance.bomb1.gun1 = spinner; + + spinner = new(raptor_spinner); + spinner.owner = instance; + setmodel(spinner, MDL_VEH_RAPTOR_PROP); + setattachment(spinner, instance, "engine_right"); + set_movetype(spinner, MOVETYPE_NOCLIP); + spinner.avelocity = '0 -90 0'; + instance.bomb1.gun2 = spinner; + + // Sigh. + setthink(instance.bomb1, raptor_rotor_anglefix); + instance.bomb1.nextthink = time; + + instance.mass = 1; + } + + instance.frame = 0; + instance.vehicle_health = autocvar_g_vehicle_raptor_health; + instance.vehicle_shield = autocvar_g_vehicle_raptor_shield; + set_movetype(instance, MOVETYPE_TOSS); + instance.solid = SOLID_SLIDEBOX; + instance.vehicle_energy = 1; + + if (!autocvar_g_vehicle_raptor_swim) { + instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK; + } + + instance.PlayerPhysplug = raptor_frame; + + instance.bomb1.gun1.avelocity_y = 90; + instance.bomb1.gun2.avelocity_y = -90; + + instance.delay = time; + + instance.bouncefactor = autocvar_g_vehicle_raptor_bouncefactor; + instance.bouncestop = autocvar_g_vehicle_raptor_bouncestop; + instance.damageforcescale = 0.25; + instance.vehicle_health = autocvar_g_vehicle_raptor_health; + instance.vehicle_shield = autocvar_g_vehicle_raptor_shield; } METHOD(Raptor, vr_setup, void(Raptor thisveh, entity instance)) { - if(autocvar_g_vehicle_raptor_shield) - instance.vehicle_flags |= VHF_HASSHIELD; + if (autocvar_g_vehicle_raptor_shield) { + instance.vehicle_flags |= VHF_HASSHIELD; + } - if(autocvar_g_vehicle_raptor_shield_regen) - instance.vehicle_flags |= VHF_SHIELDREGEN; + if (autocvar_g_vehicle_raptor_shield_regen) { + instance.vehicle_flags |= VHF_SHIELDREGEN; + } - if(autocvar_g_vehicle_raptor_health_regen) - instance.vehicle_flags |= VHF_HEALTHREGEN; + if (autocvar_g_vehicle_raptor_health_regen) { + instance.vehicle_flags |= VHF_HEALTHREGEN; + } - if(autocvar_g_vehicle_raptor_energy_regen) - instance.vehicle_flags |= VHF_ENERGYREGEN; + if (autocvar_g_vehicle_raptor_energy_regen) { + instance.vehicle_flags |= VHF_ENERGYREGEN; + } - instance.vehicle_exit = raptor_exit; - instance.respawntime = autocvar_g_vehicle_raptor_respawntime; - instance.vehicle_health = autocvar_g_vehicle_raptor_health; - instance.vehicle_shield = autocvar_g_vehicle_raptor_shield; - instance.max_health = instance.vehicle_health; + instance.vehicle_exit = raptor_exit; + instance.respawntime = autocvar_g_vehicle_raptor_respawntime; + instance.vehicle_health = autocvar_g_vehicle_raptor_health; + instance.vehicle_shield = autocvar_g_vehicle_raptor_shield; + instance.max_health = instance.vehicle_health; - if(!autocvar_g_vehicle_raptor_swim) - instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK; + if (!autocvar_g_vehicle_raptor_swim) { + instance.dphitcontentsmask |= DPCONTENTS_LIQUIDSMASK; + } } #endif @@ -752,82 +746,75 @@ METHOD(Raptor, vr_setup, void(Raptor thisveh, entity instance)) METHOD(Raptor, vr_hud, void(Raptor thisveh)) { - Vehicles_drawHUD(VEH_RAPTOR.m_icon, "vehicle_raptor_weapon1", "vehicle_raptor_weapon2", - "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, - "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color); + Vehicles_drawHUD(VEH_RAPTOR.m_icon, "vehicle_raptor_weapon1", "vehicle_raptor_weapon2", + "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, + "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color); } METHOD(Raptor, vr_crosshair, void(Raptor thisveh, entity player)) { - string crosshair; - - switch(weapon2mode) - { - case RSM_FLARE: crosshair = vCROSS_RAIN; break; - case RSM_BOMB: crosshair = vCROSS_BURST; break; - default: crosshair = vCROSS_BURST; - } - - vector tmpSize = '0 0 0'; - if(weapon2mode != RSM_FLARE && !spectatee_status) - { - vector where; - - if(!dropmark) - { - dropmark = spawn(); - dropmark.owner = player; - dropmark.gravity = 1; - dropmark.dphitcontentsmask = DPCONTENTS_SOLID; - dropmark.solid = SOLID_CORPSE; + string crosshair; + + switch (weapon2mode) { + case RSM_FLARE: crosshair = vCROSS_RAIN; + break; + case RSM_BOMB: crosshair = vCROSS_BURST; + break; + default: crosshair = vCROSS_BURST; + } + + vector tmpSize = '0 0 0'; + if (weapon2mode != RSM_FLARE && !spectatee_status) { + vector where; + + if (!dropmark) { + dropmark = spawn(); + dropmark.owner = player; + dropmark.gravity = 1; + dropmark.dphitcontentsmask = DPCONTENTS_SOLID; + dropmark.solid = SOLID_CORPSE; set_movetype(dropmark, MOVETYPE_BOUNCE); - } - - float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01; - if(reload2 == 1) - { - setorigin(dropmark, pmove_org); - dropmark.velocity = pmove_vel; - tracetoss(dropmark, player); - - where = project_3d_to_2d(trace_endpos); - - setorigin(dropmark, trace_endpos); - - if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight)) - { - tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size; - where.x -= tmpSize.x * 0.5; - where.y -= tmpSize.y * 0.5; - where.z = 0; - drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE); - drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg - } - dropmark.cnt = time + 5; - } - else - { - if(dropmark.cnt > time) - { - where = project_3d_to_2d(dropmark.origin); - - if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight)) - { - tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size * 1.25; - where.x -= tmpSize.x * 0.5; - where.y -= tmpSize.y * 0.5; - where.z = 0; - drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE); - drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg - } - } - } - } - - Vehicles_drawCrosshair(crosshair); + } + + float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01; + if (reload2 == 1) { + setorigin(dropmark, pmove_org); + dropmark.velocity = pmove_vel; + tracetoss(dropmark, player); + + where = project_3d_to_2d(trace_endpos); + + setorigin(dropmark, trace_endpos); + + if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight)) { + tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size; + where.x -= tmpSize.x * 0.5; + where.y -= tmpSize.y * 0.5; + where.z = 0; + drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE); + drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg + } + dropmark.cnt = time + 5; + } else { + if (dropmark.cnt > time) { + where = project_3d_to_2d(dropmark.origin); + + if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight)) { + tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size * 1.25; + where.x -= tmpSize.x * 0.5; + where.y -= tmpSize.y * 0.5; + where.z = 0; + drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE); + drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg + } + } + } + } + + Vehicles_drawCrosshair(crosshair); } METHOD(Raptor, vr_setup, void(Raptor thisveh, entity instance)) { - AuxiliaryXhair[1].axh_image = vCROSS_LOCK; + AuxiliaryXhair[1].axh_image = vCROSS_LOCK; } #endif diff --git a/qcsrc/common/vehicles/vehicle/raptor.qh b/qcsrc/common/vehicles/vehicle/raptor.qh index 954d54aea..07148f727 100644 --- a/qcsrc/common/vehicles/vehicle/raptor.qh +++ b/qcsrc/common/vehicles/vehicle/raptor.qh @@ -8,8 +8,8 @@ CLASS(Raptor, Vehicle) /* maxs */ ATTRIB(Raptor, m_maxs, vector, '80 80 70'); /* view offset*/ ATTRIB(Raptor, view_ofs, vector, '0 0 160'); /* view dist */ ATTRIB(Raptor, height, float, 200); -/* model */ ATTRIB(Raptor, mdl, string, "models/vehicles/raptor.dpm"); -/* model */ ATTRIB(Raptor, model, string, "models/vehicles/raptor.dpm"); +/* model */ATTRIB(Raptor, mdl, string, "models/vehicles/raptor.dpm"); +/* model */ATTRIB(Raptor, model, string, "models/vehicles/raptor.dpm"); /* head_model */ ATTRIB(Raptor, head_model, string, ""); /* hud_model */ ATTRIB(Raptor, hud_model, string, "models/vehicles/raptor_cockpit.dpm"); /* tags */ ATTRIB(Raptor, tag_head, string, ""); diff --git a/qcsrc/common/vehicles/vehicle/raptor_weapons.qc b/qcsrc/common/vehicles/vehicle/raptor_weapons.qc index 514d67c0e..242f48fcf 100644 --- a/qcsrc/common/vehicles/vehicle/raptor_weapons.qc +++ b/qcsrc/common/vehicles/vehicle/raptor_weapons.qc @@ -2,143 +2,149 @@ #ifdef SVQC -METHOD(RaptorCannon, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - entity player = isPlayer ? actor : actor.owner; - entity veh = player.vehicle; - // 1 [wait] 1 [wait] 2 [wait] 2 [wait] [wait] - float t = autocvar_g_vehicle_raptor_cannon_refire * (1 + veh.misc_bulletcounter == 4); - if (fire & 1) - if (weapon_prepareattack(thiswep, player, weaponentity, false, t)) { - if (isPlayer) W_SetupShot_Dir(player, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0); - vector org = w_shotorg; - vector dir = w_shotdir; - if (veh) { - veh.misc_bulletcounter += 1; - org = (veh.misc_bulletcounter <= 2) ? gettaginfo(veh.gun1, gettagindex(veh.gun1, "fire1")) - : (((veh.misc_bulletcounter == 4) ? veh.misc_bulletcounter = 0 : 0), gettaginfo(veh.gun2, gettagindex(veh.gun2, "fire1"))); - dir = v_forward; - veh.vehicle_energy -= autocvar_g_vehicle_raptor_cannon_cost; - actor.cnt = time; - } - vehicles_projectile(veh, EFFECT_RAPTOR_MUZZLEFLASH.eent_eff_name, SND_LASERGUN_FIRE, - org, normalize(dir + randomvec() * autocvar_g_vehicle_raptor_cannon_spread) * autocvar_g_vehicle_raptor_cannon_speed, - autocvar_g_vehicle_raptor_cannon_damage, autocvar_g_vehicle_raptor_cannon_radius, autocvar_g_vehicle_raptor_cannon_force, 0, - DEATH_VH_RAPT_CANNON.m_id, PROJECTILE_RAPTORCANNON, 0, true, true, player); - weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready); - } +METHOD(RaptorCannon, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + entity player = isPlayer ? actor : actor.owner; + entity veh = player.vehicle; + // 1 [wait] 1 [wait] 2 [wait] 2 [wait] [wait] + float t = autocvar_g_vehicle_raptor_cannon_refire * (1 + veh.misc_bulletcounter == 4); + if (fire & 1) { + if (weapon_prepareattack(thiswep, player, weaponentity, false, t)) { + if (isPlayer) { W_SetupShot_Dir(player, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0); } + vector org = w_shotorg; + vector dir = w_shotdir; + if (veh) { + veh.misc_bulletcounter += 1; + org = (veh.misc_bulletcounter <= 2) ? gettaginfo(veh.gun1, gettagindex(veh.gun1, "fire1")) + : (((veh.misc_bulletcounter == 4) ? veh.misc_bulletcounter = 0 : 0), gettaginfo(veh.gun2, gettagindex(veh.gun2, "fire1"))); + dir = v_forward; + veh.vehicle_energy -= autocvar_g_vehicle_raptor_cannon_cost; + actor.cnt = time; + } + vehicles_projectile(veh, EFFECT_RAPTOR_MUZZLEFLASH.eent_eff_name, SND_LASERGUN_FIRE, + org, normalize(dir + randomvec() * autocvar_g_vehicle_raptor_cannon_spread) * autocvar_g_vehicle_raptor_cannon_speed, + autocvar_g_vehicle_raptor_cannon_damage, autocvar_g_vehicle_raptor_cannon_radius, autocvar_g_vehicle_raptor_cannon_force, 0, + DEATH_VH_RAPT_CANNON.m_id, PROJECTILE_RAPTORCANNON, 0, true, true, player); + weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready); + } + } } -METHOD(RaptorCannon, wr_checkammo1, bool(RacerAttack thiswep, entity actor, .entity weaponentity)) { - bool isPlayer = IS_PLAYER(actor); - entity player = isPlayer ? actor : actor.owner; - entity veh = player.vehicle; - return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_raptor_cannon_cost; +METHOD(RaptorCannon, wr_checkammo1, bool(RacerAttack thiswep, entity actor, .entity weaponentity)) +{ + bool isPlayer = IS_PLAYER(actor); + entity player = isPlayer ? actor : actor.owner; + entity veh = player.vehicle; + return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_raptor_cannon_cost; } void raptor_bombdrop(entity this); -METHOD(RaptorBomb, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - entity player = isPlayer ? actor : actor.owner; - entity veh = player.vehicle; - if (fire & 2) - if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_bombs_refire)) { - entity e = (veh) ? veh : player; - raptor_bombdrop(e); - weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready); - } +METHOD(RaptorBomb, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + entity player = isPlayer ? actor : actor.owner; + entity veh = player.vehicle; + if (fire & 2) { + if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_bombs_refire)) { + entity e = (veh) ? veh : player; + raptor_bombdrop(e); + weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready); + } + } } void raptor_flare_think(entity this); void raptor_flare_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force); void raptor_flare_touch(entity this, entity toucher); -METHOD(RaptorFlare, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - bool isPlayer = IS_PLAYER(actor); - entity player = isPlayer ? actor : actor.owner; - entity veh = player.vehicle; - if (fire & 2) - if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_flare_refire)) { - for(int i = 0; i < 3; ++i) { - entity _flare = spawn(); - setmodel(_flare, MDL_VEH_RAPTOR_FLARE); - _flare.effects = EF_LOWPRECISION | EF_FLAME; - _flare.scale = 0.5; - setorigin(_flare, actor.origin - '0 0 16'); - set_movetype(_flare, MOVETYPE_TOSS); - _flare.gravity = 0.15; - _flare.velocity = 0.25 * actor.velocity + (v_forward + randomvec() * 0.25)* -500; - setthink(_flare, raptor_flare_think); - _flare.nextthink = time; - _flare.owner = veh ? veh : player; - _flare.solid = SOLID_CORPSE; - _flare.takedamage = DAMAGE_YES; - _flare.event_damage = raptor_flare_damage; - _flare.health = 20; - _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime; - settouch(_flare, raptor_flare_touch); - } - weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready); - } +METHOD(RaptorFlare, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) +{ + bool isPlayer = IS_PLAYER(actor); + entity player = isPlayer ? actor : actor.owner; + entity veh = player.vehicle; + if (fire & 2) { + if (!isPlayer || weapon_prepareattack(thiswep, player, weaponentity, true, autocvar_g_vehicle_raptor_flare_refire)) { + for (int i = 0; i < 3; ++i) { + entity _flare = spawn(); + setmodel(_flare, MDL_VEH_RAPTOR_FLARE); + _flare.effects = EF_LOWPRECISION | EF_FLAME; + _flare.scale = 0.5; + setorigin(_flare, actor.origin - '0 0 16'); + set_movetype(_flare, MOVETYPE_TOSS); + _flare.gravity = 0.15; + _flare.velocity = 0.25 * actor.velocity + (v_forward + randomvec() * 0.25) * -500; + setthink(_flare, raptor_flare_think); + _flare.nextthink = time; + _flare.owner = veh ? veh : player; + _flare.solid = SOLID_CORPSE; + _flare.takedamage = DAMAGE_YES; + _flare.event_damage = raptor_flare_damage; + _flare.health = 20; + _flare.tur_impacttime = time + autocvar_g_vehicle_raptor_flare_lifetime; + settouch(_flare, raptor_flare_touch); + } + weapon_thinkf(player, weaponentity, WFRAME_FIRE2, 0, w_ready); + } + } } void raptor_bomblet_boom(entity this) { - RadiusDamage (this, this.realowner, autocvar_g_vehicle_raptor_bomblet_damage, - autocvar_g_vehicle_raptor_bomblet_edgedamage, - autocvar_g_vehicle_raptor_bomblet_radius, NULL, NULL, - autocvar_g_vehicle_raptor_bomblet_force, DEATH_VH_RAPT_BOMB.m_id, NULL); - delete(this); + RadiusDamage(this, this.realowner, autocvar_g_vehicle_raptor_bomblet_damage, + autocvar_g_vehicle_raptor_bomblet_edgedamage, + autocvar_g_vehicle_raptor_bomblet_radius, NULL, NULL, + autocvar_g_vehicle_raptor_bomblet_force, DEATH_VH_RAPT_BOMB.m_id, NULL); + delete(this); } void raptor_bomblet_touch(entity this, entity toucher) { - if(toucher == this.owner) - return; + if (toucher == this.owner) { + return; + } - PROJECTILE_TOUCH(this, toucher); - setthink(this, raptor_bomblet_boom); - this.nextthink = time + random() * autocvar_g_vehicle_raptor_bomblet_explode_delay; + PROJECTILE_TOUCH(this, toucher); + setthink(this, raptor_bomblet_boom); + this.nextthink = time + random() * autocvar_g_vehicle_raptor_bomblet_explode_delay; } void raptor_bomb_burst(entity this) { - if(this.cnt > time) - if(autocvar_g_vehicle_raptor_bomblet_alt) - { - this.nextthink = time; - traceline(this.origin, this.origin + (normalize(this.velocity) * autocvar_g_vehicle_raptor_bomblet_alt), MOVE_NORMAL, this); - if((trace_fraction == 1.0) || (vdist(this.origin - this.owner.origin, <, autocvar_g_vehicle_raptor_bomblet_radius))) - { - UpdateCSQCProjectile(this); - return; - } - } - - entity bomblet; - float i; - - Damage_DamageInfo(this.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT.m_id, 0, this); - - for(i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i) - { - bomblet = spawn(); - setorigin(bomblet, this.origin); - - set_movetype(bomblet, MOVETYPE_TOSS); - settouch(bomblet, raptor_bomblet_touch); - setthink(bomblet, raptor_bomblet_boom); - bomblet.nextthink = time + 5; - bomblet.owner = this.owner; - bomblet.realowner = this.realowner; - bomblet.velocity = normalize(normalize(this.velocity) + (randomvec() * autocvar_g_vehicle_raptor_bomblet_spread)) * vlen(this.velocity); - - PROJECTILE_MAKETRIGGER(bomblet); - CSQCProjectile(bomblet, true, PROJECTILE_RAPTORBOMBLET, true); - } - - delete(this); + if (this.cnt > time) { + if (autocvar_g_vehicle_raptor_bomblet_alt) { + this.nextthink = time; + traceline(this.origin, this.origin + (normalize(this.velocity) * autocvar_g_vehicle_raptor_bomblet_alt), MOVE_NORMAL, this); + if ((trace_fraction == 1.0) || (vdist(this.origin - this.owner.origin, <, autocvar_g_vehicle_raptor_bomblet_radius))) { + UpdateCSQCProjectile(this); + return; + } + } + } + + entity bomblet; + float i; + + Damage_DamageInfo(this.origin, 0, 0, 0, '0 0 0', DEATH_VH_RAPT_FRAGMENT.m_id, 0, this); + + for (i = 0; i < autocvar_g_vehicle_raptor_bomblets; ++i) { + bomblet = spawn(); + setorigin(bomblet, this.origin); + + set_movetype(bomblet, MOVETYPE_TOSS); + settouch(bomblet, raptor_bomblet_touch); + setthink(bomblet, raptor_bomblet_boom); + bomblet.nextthink = time + 5; + bomblet.owner = this.owner; + bomblet.realowner = this.realowner; + bomblet.velocity = normalize(normalize(this.velocity) + (randomvec() * autocvar_g_vehicle_raptor_bomblet_spread)) * vlen(this.velocity); + + PROJECTILE_MAKETRIGGER(bomblet); + CSQCProjectile(bomblet, true, PROJECTILE_RAPTORBOMBLET, true); + } + + delete(this); } void raptor_bomb_touch(entity this, entity toucher) @@ -148,66 +154,71 @@ void raptor_bomb_touch(entity this, entity toucher) void raptor_bombdrop(entity this) { - entity bomb_1, bomb_2; - - bomb_1 = spawn(); - bomb_2 = spawn(); - - vector org = gettaginfo(this, gettagindex(this, "bombmount_left")); - setorigin(bomb_1, org); - org = gettaginfo(this, gettagindex(this, "bombmount_right")); - setorigin(bomb_2, org); - - set_movetype(bomb_1, MOVETYPE_BOUNCE); - set_movetype(bomb_2, MOVETYPE_BOUNCE); - bomb_1.velocity = bomb_2.velocity = this.velocity; - settouch(bomb_1, raptor_bomb_touch); - settouch(bomb_2, raptor_bomb_touch); - setthink(bomb_1, raptor_bomb_burst); - setthink(bomb_2, raptor_bomb_burst); - bomb_1.cnt = bomb_2.cnt = time + 10; - - if(autocvar_g_vehicle_raptor_bomblet_alt) - bomb_1.nextthink = bomb_2.nextthink = time; - else - bomb_1.nextthink = bomb_2.nextthink = time + autocvar_g_vehicle_raptor_bomblet_time; - - bomb_1.owner = bomb_2.owner = this; - bomb_1.realowner = bomb_2.realowner = this.owner; - bomb_1.solid = bomb_2.solid = SOLID_BBOX; - bomb_1.gravity = bomb_2.gravity = 1; - - PROJECTILE_MAKETRIGGER(bomb_1); - PROJECTILE_MAKETRIGGER(bomb_2); - - CSQCProjectile(bomb_1, true, PROJECTILE_RAPTORBOMB, true); - CSQCProjectile(bomb_2, true, PROJECTILE_RAPTORBOMB, true); + entity bomb_1, bomb_2; + + bomb_1 = spawn(); + bomb_2 = spawn(); + + vector org = gettaginfo(this, gettagindex(this, "bombmount_left")); + setorigin(bomb_1, org); + org = gettaginfo(this, gettagindex(this, "bombmount_right")); + setorigin(bomb_2, org); + + set_movetype(bomb_1, MOVETYPE_BOUNCE); + set_movetype(bomb_2, MOVETYPE_BOUNCE); + bomb_1.velocity = bomb_2.velocity = this.velocity; + settouch(bomb_1, raptor_bomb_touch); + settouch(bomb_2, raptor_bomb_touch); + setthink(bomb_1, raptor_bomb_burst); + setthink(bomb_2, raptor_bomb_burst); + bomb_1.cnt = bomb_2.cnt = time + 10; + + if (autocvar_g_vehicle_raptor_bomblet_alt) { + bomb_1.nextthink = bomb_2.nextthink = time; + } else { + bomb_1.nextthink = bomb_2.nextthink = time + autocvar_g_vehicle_raptor_bomblet_time; + } + + bomb_1.owner = bomb_2.owner = this; + bomb_1.realowner = bomb_2.realowner = this.owner; + bomb_1.solid = bomb_2.solid = SOLID_BBOX; + bomb_1.gravity = bomb_2.gravity = 1; + + PROJECTILE_MAKETRIGGER(bomb_1); + PROJECTILE_MAKETRIGGER(bomb_2); + + CSQCProjectile(bomb_1, true, PROJECTILE_RAPTORBOMB, true); + CSQCProjectile(bomb_2, true, PROJECTILE_RAPTORBOMB, true); } void raptor_flare_touch(entity this, entity toucher) { - delete(this); + delete(this); } void raptor_flare_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) { - this.health -= damage; - if(this.health <= 0) - delete(this); + this.health -= damage; + if (this.health <= 0) { + delete(this); + } } void raptor_flare_think(entity this) { - this.nextthink = time + 0.1; - IL_EACH(g_projectiles, it.enemy == this.owner, - { - if(vdist(this.origin - it.origin, <, autocvar_g_vehicle_raptor_flare_range)) - if(random() > autocvar_g_vehicle_raptor_flare_chase) - it.enemy = this; - }); - - if(this.tur_impacttime < time) - delete(this); + this.nextthink = time + 0.1; + IL_EACH(g_projectiles, it.enemy == this.owner, + { + if (vdist(this.origin - it.origin, <, autocvar_g_vehicle_raptor_flare_range)) { + if (random() > autocvar_g_vehicle_raptor_flare_chase) { + it.enemy = this; + } + } + }); + + if (this.tur_impacttime < time) { + delete(this); + } } #endif @@ -216,44 +227,47 @@ void raptor_flare_think(entity this) void RaptorCBShellfragDraw(entity this) { - if(wasfreed(this)) - return; + if (wasfreed(this)) { + return; + } - Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy); - this.avelocity += randomvec() * 15; - this.renderflags = 0; + Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy); + this.avelocity += randomvec() * 15; + this.renderflags = 0; - if(this.cnt < time) - this.alpha = bound(0, this.nextthink - time, 1); + if (this.cnt < time) { + this.alpha = bound(0, this.nextthink - time, 1); + } - if(this.alpha < ALPHA_MIN_VISIBLE) - delete(this); + if (this.alpha < ALPHA_MIN_VISIBLE) { + delete(this); + } } void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang) { - entity sfrag = spawn(); - setmodel(sfrag, MDL_VEH_RAPTOR_CB_FRAGMENT); - setorigin(sfrag, _org); + entity sfrag = spawn(); + setmodel(sfrag, MDL_VEH_RAPTOR_CB_FRAGMENT); + setorigin(sfrag, _org); - set_movetype(sfrag, MOVETYPE_BOUNCE); - sfrag.gravity = 0.15; - sfrag.solid = SOLID_CORPSE; + set_movetype(sfrag, MOVETYPE_BOUNCE); + sfrag.gravity = 0.15; + sfrag.solid = SOLID_CORPSE; - sfrag.draw = RaptorCBShellfragDraw; - IL_PUSH(g_drawables, sfrag); + sfrag.draw = RaptorCBShellfragDraw; + IL_PUSH(g_drawables, sfrag); - sfrag.velocity = _vel; - sfrag.avelocity = prandomvec() * vlen(sfrag.velocity); - sfrag.angles = _ang; + sfrag.velocity = _vel; + sfrag.avelocity = prandomvec() * vlen(sfrag.velocity); + sfrag.angles = _ang; - sfrag.move_time = time; - sfrag.damageforcescale = 4; + sfrag.move_time = time; + sfrag.damageforcescale = 4; - sfrag.nextthink = time + 3; - sfrag.cnt = time + 2; - sfrag.alpha = 1; - sfrag.drawmask = MASK_NORMAL; + sfrag.nextthink = time + 3; + sfrag.cnt = time + 2; + sfrag.alpha = 1; + sfrag.drawmask = MASK_NORMAL; } #endif diff --git a/qcsrc/common/vehicles/vehicle/spiderbot.qc b/qcsrc/common/vehicles/vehicle/spiderbot.qc index 57486a2f3..dbf9f9236 100644 --- a/qcsrc/common/vehicles/vehicle/spiderbot.qc +++ b/qcsrc/common/vehicles/vehicle/spiderbot.qc @@ -46,8 +46,7 @@ bool spiderbot_frame(entity this, float dt) entity vehic = this.vehicle; return = true; - if(game_stopped) - { + if (game_stopped) { vehic.solid = SOLID_NOT; vehic.takedamage = DAMAGE_NO; set_movetype(vehic, MOVETYPE_NONE); @@ -58,8 +57,7 @@ bool spiderbot_frame(entity this, float dt) PHYS_INPUT_BUTTON_ZOOM(this) = false; PHYS_INPUT_BUTTON_CROUCH(this) = false; - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; this.(weaponentity).m_switchweapon = WEP_Null; } @@ -91,7 +89,7 @@ bool spiderbot_frame(entity this, float dt) ad = vectoangles(normalize(trace_endpos - ad)); ad = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(vehic.angles), AnglesTransform_FromAngles(ad))) - vehic.tur_head.angles; ad = AnglesTransform_Normalize(ad, true); - //UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload2) + ('0 1 0' * (1 - this.vehicle_reload2)), 2); + // UpdateAuxiliaryXhair(this, trace_endpos, ('1 0 0' * this.vehicle_reload2) + ('0 1 0' * (1 - this.vehicle_reload2)), 2); // Rotate head float ftmp = autocvar_g_vehicle_spiderbot_head_turnspeed * PHYS_INPUT_FRAMETIME; @@ -103,140 +101,131 @@ bool spiderbot_frame(entity this, float dt) vehic.tur_head.angles_x = bound(autocvar_g_vehicle_spiderbot_head_pitchlimit_down, vehic.tur_head.angles_x + ad_x, autocvar_g_vehicle_spiderbot_head_pitchlimit_up); - //fixedmakevectors(vehic.angles); + // fixedmakevectors(vehic.angles); makevectors(vehic.angles + '-2 0 0' * vehic.angles_x); movelib_groundalign4point(vehic, autocvar_g_vehicle_spiderbot_springlength, autocvar_g_vehicle_spiderbot_springup, autocvar_g_vehicle_spiderbot_springblend, autocvar_g_vehicle_spiderbot_tiltlimit); - if(IS_ONGROUND(vehic)) + if (IS_ONGROUND(vehic)) { vehic.jump_delay = time; // reset now so movement can begin - - //if(IS_ONGROUND(vehic)) + } + // if(IS_ONGROUND(vehic)) { - if(IS_ONGROUND(vehic)) - if(vehic.frame == 4 && vehic.tur_head.wait != 0) - { - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_LAND, VOL_VEHICLEENGINE, ATTEN_NORM); - vehic.frame = 5; + if (IS_ONGROUND(vehic)) { + if (vehic.frame == 4 && vehic.tur_head.wait != 0) { + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_LAND, VOL_VEHICLEENGINE, ATTEN_NORM); + vehic.frame = 5; + } } - if (!PHYS_INPUT_BUTTON_JUMP(this)) + if (!PHYS_INPUT_BUTTON_JUMP(this)) { vehic.button2 = false; + } - if((IS_ONGROUND(vehic)) && PHYS_INPUT_BUTTON_JUMP(this) && !vehic.button2 && vehic.tur_head.wait < time) - { - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_JUMP, VOL_VEHICLEENGINE, ATTEN_NORM); - //dprint("spiderbot_jump:", ftos(soundlength("vehicles/spiderbot_jump.wav")), "\n"); + if ((IS_ONGROUND(vehic)) && PHYS_INPUT_BUTTON_JUMP(this) && !vehic.button2 && vehic.tur_head.wait < time) { + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_JUMP, VOL_VEHICLEENGINE, ATTEN_NORM); + // dprint("spiderbot_jump:", ftos(soundlength("vehicles/spiderbot_jump.wav")), "\n"); vehic.delay = 0; vehic.tur_head.wait = time + 2; vehic.jump_delay = time + 2; vehic.button2 = true; // set spider's jump - //PHYS_INPUT_BUTTON_JUMP(this) = false; + // PHYS_INPUT_BUTTON_JUMP(this) = false; vector movefix = '0 0 0'; - if(CS(this).movement_x > 0) movefix_x = 1; - if(CS(this).movement_x < 0) movefix_x = -1; - if(CS(this).movement_y > 0) movefix_y = 1; - if(CS(this).movement_y < 0) movefix_y = -1; + if (CS(this).movement_x > 0) { movefix_x = 1; } + if (CS(this).movement_x < 0) { movefix_x = -1; } + if (CS(this).movement_y > 0) { movefix_y = 1; } + if (CS(this).movement_y < 0) { movefix_y = -1; } vector rt = movefix_y * v_right; vector sd = movefix_x * v_forward; - if(movefix_y == 0 && movefix_x == 0) + if (movefix_y == 0 && movefix_x == 0) { sd = v_forward; // always do forward - + } UNSET_ONGROUND(vehic); vehic.velocity = sd * 700 + rt * 600 + v_up * 600; vehic.frame = 4; - } - else if(time >= vehic.jump_delay) - { - if(!CS(this).movement) - { - if(IS_ONGROUND(vehic)) - { - if(vehic.sound_nexttime < time || vehic.delay != 3) - { + } else if (time >= vehic.jump_delay) { + if (!CS(this).movement) { + if (IS_ONGROUND(vehic)) { + if (vehic.sound_nexttime < time || vehic.delay != 3) { vehic.delay = 3; - vehic.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_idle.wav"); - //dprint("spiderbot_idle:", ftos(soundlength("vehicles/spiderbot_idle.wav")), "\n"); - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM); + vehic.sound_nexttime = time + 6.486500; // soundlength("vehicles/spiderbot_idle.wav"); + // dprint("spiderbot_idle:", ftos(soundlength("vehicles/spiderbot_idle.wav")), "\n"); + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM); } movelib_brake_simple(vehic, autocvar_g_vehicle_spiderbot_speed_stop); vehic.frame = 5; } - } - else - { + } else { // Turn Body - if(CS(this).movement_x == 0 && CS(this).movement_y != 0) + if (CS(this).movement_x == 0 && CS(this).movement_y != 0) { ftmp = autocvar_g_vehicle_spiderbot_turnspeed_strafe * PHYS_INPUT_FRAMETIME; - else + } else { ftmp = autocvar_g_vehicle_spiderbot_turnspeed * PHYS_INPUT_FRAMETIME; + } ftmp = bound(-ftmp, vehic.tur_head.angles_y, ftmp); vehic.angles_y = anglemods(vehic.angles_y + ftmp); vehic.tur_head.angles_y -= ftmp; - if(CS(this).movement_x != 0) - { - if(CS(this).movement_x > 0) - { + if (CS(this).movement_x != 0) { + if (CS(this).movement_x > 0) { CS(this).movement_x = 1; - if(IS_ONGROUND(vehic)) + if (IS_ONGROUND(vehic)) { vehic.frame = 0; - } - else if(CS(this).movement_x < 0) - { + } + } else if (CS(this).movement_x < 0) { CS(this).movement_x = -1; - if(IS_ONGROUND(vehic)) + if (IS_ONGROUND(vehic)) { vehic.frame = 1; + } } CS(this).movement_y = 0; float oldvelz = vehic.velocity_z; - movelib_move_simple(vehic, normalize(v_forward * CS(this).movement_x),((PHYS_INPUT_BUTTON_JUMP(this)) ? autocvar_g_vehicle_spiderbot_speed_run : autocvar_g_vehicle_spiderbot_speed_walk),autocvar_g_vehicle_spiderbot_movement_inertia); + movelib_move_simple(vehic, normalize(v_forward * CS(this).movement_x), ((PHYS_INPUT_BUTTON_JUMP(this)) ? autocvar_g_vehicle_spiderbot_speed_run : autocvar_g_vehicle_spiderbot_speed_walk), autocvar_g_vehicle_spiderbot_movement_inertia); vehic.velocity_z = oldvelz; float g = ((autocvar_sv_gameplayfix_gravityunaffectedbyticrate) ? 0.5 : 1); - if(vehic.velocity_z <= 20) // not while jumping + if (vehic.velocity_z <= 20) { // not while jumping vehic.velocity_z -= g * PHYS_INPUT_FRAMETIME * autocvar_sv_gravity; - if(IS_ONGROUND(vehic)) - if(vehic.sound_nexttime < time || vehic.delay != 1) - { - vehic.delay = 1; - vehic.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_walk.wav"); - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_WALK, VOL_VEHICLEENGINE, ATTEN_NORM); - //dprint("spiderbot_walk:", ftos(soundlength("vehicles/spiderbot_walk.wav")), "\n"); } - } - else if(CS(this).movement_y != 0) - { - if(CS(this).movement_y < 0) - { + if (IS_ONGROUND(vehic)) { + if (vehic.sound_nexttime < time || vehic.delay != 1) { + vehic.delay = 1; + vehic.sound_nexttime = time + 6.486500; // soundlength("vehicles/spiderbot_walk.wav"); + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_WALK, VOL_VEHICLEENGINE, ATTEN_NORM); + // dprint("spiderbot_walk:", ftos(soundlength("vehicles/spiderbot_walk.wav")), "\n"); + } + } + } else if (CS(this).movement_y != 0) { + if (CS(this).movement_y < 0) { CS(this).movement_y = -1; - if(IS_ONGROUND(vehic)) + if (IS_ONGROUND(vehic)) { vehic.frame = 2; - } - else if(CS(this).movement_y > 0) - { + } + } else if (CS(this).movement_y > 0) { CS(this).movement_y = 1; - if(IS_ONGROUND(vehic)) + if (IS_ONGROUND(vehic)) { vehic.frame = 3; + } } float oldvelz = vehic.velocity_z; - movelib_move_simple(vehic, normalize(v_right * CS(this).movement_y),autocvar_g_vehicle_spiderbot_speed_strafe,autocvar_g_vehicle_spiderbot_movement_inertia); + movelib_move_simple(vehic, normalize(v_right * CS(this).movement_y), autocvar_g_vehicle_spiderbot_speed_strafe, autocvar_g_vehicle_spiderbot_movement_inertia); vehic.velocity_z = oldvelz; float g = ((autocvar_sv_gameplayfix_gravityunaffectedbyticrate) ? 0.5 : 1); - if(vehic.velocity_z <= 20) // not while jumping + if (vehic.velocity_z <= 20) { // not while jumping vehic.velocity_z -= g * PHYS_INPUT_FRAMETIME * autocvar_sv_gravity; - if(IS_ONGROUND(vehic)) - if(vehic.sound_nexttime < time || vehic.delay != 2) - { - vehic.delay = 2; - vehic.sound_nexttime = time + 6.486500; //soundlength("vehicles/spiderbot_strafe.wav"); - sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_STRAFE, VOL_VEHICLEENGINE, ATTEN_NORM); - //dprint("spiderbot_strafe:", ftos(soundlength("vehicles/spiderbot_strafe.wav")), "\n"); + } + if (IS_ONGROUND(vehic)) { + if (vehic.sound_nexttime < time || vehic.delay != 2) { + vehic.delay = 2; + vehic.sound_nexttime = time + 6.486500; // soundlength("vehicles/spiderbot_strafe.wav"); + sound(vehic, CH_TRIGGER_SINGLE, SND_VEH_SPIDERBOT_STRAFE, VOL_VEHICLEENGINE, ATTEN_NORM); + // dprint("spiderbot_strafe:", ftos(soundlength("vehicles/spiderbot_strafe.wav")), "\n"); + } } } } @@ -246,64 +235,65 @@ bool spiderbot_frame(entity this, float dt) vehic.angles_x = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, vehic.angles_x, autocvar_g_vehicle_spiderbot_tiltlimit); vehic.angles_z = bound(-autocvar_g_vehicle_spiderbot_tiltlimit, vehic.angles_z, autocvar_g_vehicle_spiderbot_tiltlimit); - if(!forbidWeaponUse(this)) - if(PHYS_INPUT_BUTTON_ATCK(this)) - { - vehic.cnt = time; - if(vehic.vehicle_ammo1 >= autocvar_g_vehicle_spiderbot_minigun_ammo_cost && vehic.tur_head.attack_finished_single[0] <= time) - { - entity gun; - vector v; - vehic.misc_bulletcounter += 1; - - gun = (vehic.misc_bulletcounter % 2) ? vehic.gun1 : vehic.gun2; - - v = gettaginfo(gun, gettagindex(gun, "barrels")); - v_forward = normalize(v_forward); - v += v_forward * 50; - - .entity weaponentity = weaponentities[0]; // TODO: unhardcode - fireBullet(this, weaponentity, v, v_forward, autocvar_g_vehicle_spiderbot_minigun_spread, autocvar_g_vehicle_spiderbot_minigun_solidpenetration, - autocvar_g_vehicle_spiderbot_minigun_damage, autocvar_g_vehicle_spiderbot_minigun_force, DEATH_VH_SPID_MINIGUN.m_id, 0); - - sound (gun, CH_WEAPON_A, SND_UZI_FIRE, VOL_BASE, ATTEN_NORM); - //trailparticles(this, _particleeffectnum("spiderbot_minigun_trail"), v, trace_endpos); - Send_Effect(EFFECT_SPIDERBOT_MINIGUN_MUZZLEFLASH, v, v_forward * 2500, 1); - - vehic.vehicle_ammo1 -= autocvar_g_vehicle_spiderbot_minigun_ammo_cost; - vehic.tur_head.attack_finished_single[0] = time + autocvar_g_vehicle_spiderbot_minigun_refire; - this.vehicle_ammo1 = (vehic.vehicle_ammo1 / autocvar_g_vehicle_spiderbot_minigun_ammo_max) * 100; - vehic.gun1.angles_z += 45; - vehic.gun2.angles_z -= 45; - if(vehic.gun1.angles_z >= 360) - { - vehic.gun1.angles_z = 0; - vehic.gun2.angles_z = 0; + if (!forbidWeaponUse(this)) { + if (PHYS_INPUT_BUTTON_ATCK(this)) { + vehic.cnt = time; + if (vehic.vehicle_ammo1 >= autocvar_g_vehicle_spiderbot_minigun_ammo_cost && vehic.tur_head.attack_finished_single[0] <= time) { + entity gun; + vector v; + vehic.misc_bulletcounter += 1; + + gun = (vehic.misc_bulletcounter % 2) ? vehic.gun1 : vehic.gun2; + + v = gettaginfo(gun, gettagindex(gun, "barrels")); + v_forward = normalize(v_forward); + v += v_forward * 50; + + .entity weaponentity = weaponentities[0]; // TODO: unhardcode + fireBullet(this, weaponentity, v, v_forward, autocvar_g_vehicle_spiderbot_minigun_spread, autocvar_g_vehicle_spiderbot_minigun_solidpenetration, + autocvar_g_vehicle_spiderbot_minigun_damage, autocvar_g_vehicle_spiderbot_minigun_force, DEATH_VH_SPID_MINIGUN.m_id, 0); + + sound(gun, CH_WEAPON_A, SND_UZI_FIRE, VOL_BASE, ATTEN_NORM); + // trailparticles(this, _particleeffectnum("spiderbot_minigun_trail"), v, trace_endpos); + Send_Effect(EFFECT_SPIDERBOT_MINIGUN_MUZZLEFLASH, v, v_forward * 2500, 1); + + vehic.vehicle_ammo1 -= autocvar_g_vehicle_spiderbot_minigun_ammo_cost; + vehic.tur_head.attack_finished_single[0] = time + autocvar_g_vehicle_spiderbot_minigun_refire; + this.vehicle_ammo1 = (vehic.vehicle_ammo1 / autocvar_g_vehicle_spiderbot_minigun_ammo_max) * 100; + vehic.gun1.angles_z += 45; + vehic.gun2.angles_z -= 45; + if (vehic.gun1.angles_z >= 360) { + vehic.gun1.angles_z = 0; + vehic.gun2.angles_z = 0; + } } + } else { + vehicles_regen(vehic, vehic.cnt, vehicle_ammo1, autocvar_g_vehicle_spiderbot_minigun_ammo_max, + autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause, + autocvar_g_vehicle_spiderbot_minigun_ammo_regen, dt, false); } } - else - vehicles_regen(vehic, vehic.cnt, vehicle_ammo1, autocvar_g_vehicle_spiderbot_minigun_ammo_max, - autocvar_g_vehicle_spiderbot_minigun_ammo_regen_pause, - autocvar_g_vehicle_spiderbot_minigun_ammo_regen, dt, false); spiderbot_rocket_do(vehic); - if(vehic.vehicle_flags & VHF_SHIELDREGEN) + if (vehic.vehicle_flags & VHF_SHIELDREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_spiderbot_shield, autocvar_g_vehicle_spiderbot_shield_regen_pause, autocvar_g_vehicle_spiderbot_shield_regen, dt, true); + } - if(vehic.vehicle_flags & VHF_HEALTHREGEN) + if (vehic.vehicle_flags & VHF_HEALTHREGEN) { vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_spiderbot_health, autocvar_g_vehicle_spiderbot_health_regen_pause, autocvar_g_vehicle_spiderbot_health_regen, dt, false); + } PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false; - //this.vehicle_ammo2 = vehic.tur_head.frame; + // this.vehicle_ammo2 = vehic.tur_head.frame; this.vehicle_ammo2 = (9 - vehic.tur_head.frame) / 8 * 100; // Percentage, like ammo1 - if(vehic.gun2.cnt <= time) + if (vehic.gun2.cnt <= time) { this.vehicle_reload2 = 100; - else + } else { this.vehicle_reload2 = 100 - ((vehic.gun2.cnt - time) / vehic.attack_finished_single[0]) * 100; + } setorigin(this, vehic.origin + '0 0 1' * vehic.maxs_z); this.oldorigin = this.origin; // negate fall damage @@ -311,8 +301,9 @@ bool spiderbot_frame(entity this, float dt) VEHICLE_UPDATE_PLAYER(this, vehic, health, spiderbot); - if(vehic.vehicle_flags & VHF_HASSHIELD) + if (vehic.vehicle_flags & VHF_HASSHIELD) { VEHICLE_UPDATE_PLAYER(this, vehic, shield, spiderbot); + } } void spiderbot_exit(entity this, int eject) @@ -330,33 +321,26 @@ void spiderbot_exit(entity this, int eject) this.frame = 5; set_movetype(this, MOVETYPE_WALK); - if(!player) - { + if (!player) { this.owner = NULL; // reset owner anyway? return; } makevectors(this.angles); vector spot; - if(eject) - { + if (eject) { spot = this.origin + v_forward * 100 + '0 0 64'; spot = vehicles_findgoodexit(this, player, spot); setorigin(player, spot); player.velocity = (v_up + v_forward * 0.25) * 750; player.oldvelocity = player.velocity; - } - else - { - if(vdist(this.velocity, >, autocvar_g_vehicle_spiderbot_speed_strafe)) - { + } else { + if (vdist(this.velocity, >, autocvar_g_vehicle_spiderbot_speed_strafe)) { player.velocity = normalize(this.velocity) * vlen(this.velocity); player.velocity_z += 200; spot = this.origin + v_forward * 128 + '0 0 64'; spot = vehicles_findgoodexit(this, player, spot); - } - else - { + } else { player.velocity = this.velocity * 0.5; player.velocity_z += 10; spot = this.origin + v_forward * 256 + '0 0 64'; @@ -376,11 +360,9 @@ void spiderbot_headfade(entity this) this.nextthink = this.fade_time; this.alpha = 1 - (time - this.fade_time) * this.fade_rate; - if(this.cnt < time || this.alpha < 0.1) - { - if(this.alpha > 0.1) - { - sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); + if (this.cnt < time || this.alpha < 0.1) { + if (this.alpha > 0.1) { + sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); Send_Effect(EFFECT_EXPLOSION_BIG, this.origin + '0 0 100', '0 0 0', 1); } delete(this); @@ -389,11 +371,9 @@ void spiderbot_headfade(entity this) void spiderbot_blowup(entity this) { - if(this.cnt > time) - { - if(random() < 0.1) - { - sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); + if (this.cnt > time) { + if (random() < 0.1) { + sound(this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1); } this.nextthink = time + 0.1; @@ -445,11 +425,11 @@ void spiderbot_blowup(entity this) h.colormod = b.colormod = g1.colormod = g2.colormod = '-2 -2 -2'; SUB_SetFade(b, time + 5, min(this.respawntime, 1)); - //SUB_SetFade(h, time, min(this.respawntime, 10)); + // SUB_SetFade(h, time, min(this.respawntime, 10)); SUB_SetFade(g1, time, min(this.respawntime, 10)); SUB_SetFade(g2, time, min(this.respawntime, 10)); - RadiusDamage (this, this.enemy, 250, 15, 250, NULL, NULL, 250, DEATH_VH_SPID_DEATH.m_id, NULL); + RadiusDamage(this, this.enemy, 250, 15, 250, NULL, NULL, 250, DEATH_VH_SPID_DEATH.m_id, NULL); this.alpha = this.tur_head.alpha = this.gun1.alpha = this.gun2.alpha = -1; set_movetype(this, MOVETYPE_NONE); @@ -461,8 +441,7 @@ void spiderbot_blowup(entity this) bool spiderbot_impulse(entity this, int _imp) { - switch(_imp) - { + switch (_imp) { case IMP_weapon_group_1.impulse: this.vehicle.vehicle_weapon2mode = SBRM_VOLLY; CSQCVehicleSetup(this, 0); @@ -480,10 +459,11 @@ bool spiderbot_impulse(entity this, int _imp) case IMP_weapon_next_bypriority.impulse: case IMP_weapon_next_bygroup.impulse: this.vehicle.vehicle_weapon2mode += 1; - if(this.vehicle.vehicle_weapon2mode > SBRM_LAST) + if (this.vehicle.vehicle_weapon2mode > SBRM_LAST) { this.vehicle.vehicle_weapon2mode = SBRM_FIRST; + } - //centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode))); + // centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode))); CSQCVehicleSetup(this, 0); return true; case IMP_weapon_last.impulse: @@ -491,149 +471,155 @@ bool spiderbot_impulse(entity this, int _imp) case IMP_weapon_prev_bypriority.impulse: case IMP_weapon_prev_bygroup.impulse: this.vehicle.vehicle_weapon2mode -= 1; - if(this.vehicle.vehicle_weapon2mode < SBRM_FIRST) + if (this.vehicle.vehicle_weapon2mode < SBRM_FIRST) { this.vehicle.vehicle_weapon2mode = SBRM_LAST; + } - //centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode))); + // centerprint(this, strcat("Rocket mode is ", ftos(this.vehicle.vehicle_weapon2mode))); CSQCVehicleSetup(this, 0); return true; - /* - case IMP_weapon_drop.impulse: // toss gun, could be used to exit? - break; - case IMP_weapon_reload.impulse: // Manual minigun reload? - break; - */ + /* + case IMP_weapon_drop.impulse: // toss gun, could be used to exit? + break; + case IMP_weapon_reload.impulse: // Manual minigun reload? + break; + */ } return false; } spawnfunc(vehicle_spiderbot) { - if(!autocvar_g_vehicle_spiderbot) { delete(this); return; } - if(!vehicle_initialize(this, VEH_SPIDERBOT, false)) { delete(this); return; } + if (!autocvar_g_vehicle_spiderbot) { delete(this); return; } + if (!vehicle_initialize(this, VEH_SPIDERBOT, false)) { delete(this); return; } } METHOD(Spiderbot, vr_impact, void(Spiderbot thisveh, entity instance)) { - if(autocvar_g_vehicle_spiderbot_bouncepain) - vehicles_impact(instance, autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z); + if (autocvar_g_vehicle_spiderbot_bouncepain) { + vehicles_impact(instance, autocvar_g_vehicle_spiderbot_bouncepain_x, autocvar_g_vehicle_spiderbot_bouncepain_y, autocvar_g_vehicle_spiderbot_bouncepain_z); + } } METHOD(Spiderbot, vr_enter, void(Spiderbot thisveh, entity instance)) { - instance.vehicle_weapon2mode = SBRM_GUIDE; - set_movetype(instance, MOVETYPE_WALK); - CSQCVehicleSetup(instance.owner, 0); - instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100; - instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100; - - if(instance.owner.flagcarried) - { - setattachment(instance.owner.flagcarried, instance.tur_head, ""); - setorigin(instance.owner.flagcarried, '-20 0 120'); - } + instance.vehicle_weapon2mode = SBRM_GUIDE; + set_movetype(instance, MOVETYPE_WALK); + CSQCVehicleSetup(instance.owner, 0); + instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_spiderbot_health) * 100; + instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_spiderbot_shield) * 100; + + if (instance.owner.flagcarried) { + setattachment(instance.owner.flagcarried, instance.tur_head, ""); + setorigin(instance.owner.flagcarried, '-20 0 120'); + } } METHOD(Spiderbot, vr_think, void(Spiderbot thisveh, entity instance)) { - if(IS_ONGROUND(instance)) - movelib_brake_simple(instance, autocvar_g_vehicle_spiderbot_speed_stop); + if (IS_ONGROUND(instance)) { + movelib_brake_simple(instance, autocvar_g_vehicle_spiderbot_speed_stop); + } } METHOD(Spiderbot, vr_death, void(Spiderbot thisveh, entity instance)) { - instance.health = 0; - instance.event_damage = func_null; - instance.takedamage = DAMAGE_NO; - settouch(instance, func_null); - instance.cnt = 3.4 + time + random() * 2; - setthink(instance, spiderbot_blowup); - instance.nextthink = time; - instance.deadflag = DEAD_DYING; - instance.frame = 5; - instance.tur_head.effects |= EF_FLAME; - instance.colormod = instance.tur_head.colormod = '-1 -1 -1'; - instance.frame = 10; - set_movetype(instance, MOVETYPE_TOSS); - - CSQCModel_UnlinkEntity(instance); // networking the death scene would be a nightmare + instance.health = 0; + instance.event_damage = func_null; + instance.takedamage = DAMAGE_NO; + settouch(instance, func_null); + instance.cnt = 3.4 + time + random() * 2; + setthink(instance, spiderbot_blowup); + instance.nextthink = time; + instance.deadflag = DEAD_DYING; + instance.frame = 5; + instance.tur_head.effects |= EF_FLAME; + instance.colormod = instance.tur_head.colormod = '-1 -1 -1'; + instance.frame = 10; + set_movetype(instance, MOVETYPE_TOSS); + + CSQCModel_UnlinkEntity(instance); // networking the death scene would be a nightmare } METHOD(Spiderbot, vr_spawn, void(Spiderbot thisveh, entity instance)) { - if(!instance.gun1) - { - instance.vehicles_impulse = spiderbot_impulse; - instance.gun1 = spawn(); - instance.gun2 = spawn(); - setmodel(instance.gun1, MDL_VEH_SPIDERBOT_GUN); - setmodel(instance.gun2, MDL_VEH_SPIDERBOT_GUN); - setattachment(instance.gun1, instance.tur_head, "tag_hardpoint01"); - setattachment(instance.gun2, instance.tur_head, "tag_hardpoint02"); - instance.gravity = 2; - instance.mass = 5000; - } - - instance.frame = 5; - instance.tur_head.frame = 1; - set_movetype(instance, MOVETYPE_WALK); - instance.solid = SOLID_SLIDEBOX; - instance.alpha = instance.tur_head.alpha = instance.gun1.alpha = instance.gun2.alpha = 1; - instance.tur_head.angles = '0 0 0'; - instance.vehicle_exit = spiderbot_exit; - - setorigin(instance, instance.pos1 + '0 0 128'); - instance.angles = instance.pos2; - instance.damageforcescale = 0.03; - instance.vehicle_health = autocvar_g_vehicle_spiderbot_health; - instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield; - - instance.PlayerPhysplug = spiderbot_frame; + if (!instance.gun1) { + instance.vehicles_impulse = spiderbot_impulse; + instance.gun1 = spawn(); + instance.gun2 = spawn(); + setmodel(instance.gun1, MDL_VEH_SPIDERBOT_GUN); + setmodel(instance.gun2, MDL_VEH_SPIDERBOT_GUN); + setattachment(instance.gun1, instance.tur_head, "tag_hardpoint01"); + setattachment(instance.gun2, instance.tur_head, "tag_hardpoint02"); + instance.gravity = 2; + instance.mass = 5000; + } + + instance.frame = 5; + instance.tur_head.frame = 1; + set_movetype(instance, MOVETYPE_WALK); + instance.solid = SOLID_SLIDEBOX; + instance.alpha = instance.tur_head.alpha = instance.gun1.alpha = instance.gun2.alpha = 1; + instance.tur_head.angles = '0 0 0'; + instance.vehicle_exit = spiderbot_exit; + + setorigin(instance, instance.pos1 + '0 0 128'); + instance.angles = instance.pos2; + instance.damageforcescale = 0.03; + instance.vehicle_health = autocvar_g_vehicle_spiderbot_health; + instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield; + + instance.PlayerPhysplug = spiderbot_frame; } METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance)) { - if(autocvar_g_vehicle_spiderbot_shield) - instance.vehicle_flags |= VHF_HASSHIELD; + if (autocvar_g_vehicle_spiderbot_shield) { + instance.vehicle_flags |= VHF_HASSHIELD; + } - if(autocvar_g_vehicle_spiderbot_shield_regen) - instance.vehicle_flags |= VHF_SHIELDREGEN; + if (autocvar_g_vehicle_spiderbot_shield_regen) { + instance.vehicle_flags |= VHF_SHIELDREGEN; + } - if(autocvar_g_vehicle_spiderbot_health_regen) - instance.vehicle_flags |= VHF_HEALTHREGEN; + if (autocvar_g_vehicle_spiderbot_health_regen) { + instance.vehicle_flags |= VHF_HEALTHREGEN; + } - instance.respawntime = autocvar_g_vehicle_spiderbot_respawntime; - instance.vehicle_health = autocvar_g_vehicle_spiderbot_health; - instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield; - instance.max_health = instance.vehicle_health; - instance.pushable = true; // spiderbot can use jumppads + instance.respawntime = autocvar_g_vehicle_spiderbot_respawntime; + instance.vehicle_health = autocvar_g_vehicle_spiderbot_health; + instance.vehicle_shield = autocvar_g_vehicle_spiderbot_shield; + instance.max_health = instance.vehicle_health; + instance.pushable = true; // spiderbot can use jumppads } #endif // SVQC #ifdef CSQC -//float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6; -//float autocvar_cl_vehicle_spiderbot_cross_size = 1; +// float autocvar_cl_vehicle_spiderbot_cross_alpha = 0.6; +// float autocvar_cl_vehicle_spiderbot_cross_size = 1; METHOD(Spiderbot, vr_hud, void(Spiderbot thisveh)) { - Vehicles_drawHUD(VEH_SPIDERBOT.m_icon, "vehicle_spider_weapon1", "vehicle_spider_weapon2", - "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, - "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color); + Vehicles_drawHUD(VEH_SPIDERBOT.m_icon, "vehicle_spider_weapon1", "vehicle_spider_weapon2", + "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color, + "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color); } METHOD(Spiderbot, vr_crosshair, void(Spiderbot thisveh, entity player)) { - string crosshair; + string crosshair; - switch(weapon2mode) - { - case SBRM_VOLLY: crosshair = vCROSS_BURST; break; - case SBRM_GUIDE: crosshair = vCROSS_GUIDE; break; - case SBRM_ARTILLERY: crosshair = vCROSS_RAIN; break; - default: crosshair = vCROSS_BURST; - } + switch (weapon2mode) { + case SBRM_VOLLY: crosshair = vCROSS_BURST; + break; + case SBRM_GUIDE: crosshair = vCROSS_GUIDE; + break; + case SBRM_ARTILLERY: crosshair = vCROSS_RAIN; + break; + default: crosshair = vCROSS_BURST; + } - Vehicles_drawCrosshair(crosshair); + Vehicles_drawCrosshair(crosshair); } METHOD(Spiderbot, vr_setup, void(Spiderbot thisveh, entity instance)) { - AuxiliaryXhair[0].axh_image = vCROSS_HINT; // Minigun1 - AuxiliaryXhair[1].axh_image = vCROSS_HINT; // Minigun2 + AuxiliaryXhair[0].axh_image = vCROSS_HINT; // Minigun1 + AuxiliaryXhair[1].axh_image = vCROSS_HINT; // Minigun2 } #endif diff --git a/qcsrc/common/vehicles/vehicle/spiderbot.qh b/qcsrc/common/vehicles/vehicle/spiderbot.qh index 414e0f805..070ee9b38 100644 --- a/qcsrc/common/vehicles/vehicle/spiderbot.qh +++ b/qcsrc/common/vehicles/vehicle/spiderbot.qh @@ -8,8 +8,8 @@ CLASS(Spiderbot, Vehicle) /* maxs */ ATTRIB(Spiderbot, m_maxs, vector, '75 75 125'); /* view offset*/ ATTRIB(Spiderbot, view_ofs, vector, '0 0 70'); /* view dist */ ATTRIB(Spiderbot, height, float, 170); -/* model */ ATTRIB(Spiderbot, mdl, string, "models/vehicles/spiderbot.dpm"); -/* model */ ATTRIB(Spiderbot, model, string, "models/vehicles/spiderbot.dpm"); +/* model */ATTRIB(Spiderbot, mdl, string, "models/vehicles/spiderbot.dpm"); +/* model */ATTRIB(Spiderbot, model, string, "models/vehicles/spiderbot.dpm"); /* head_model */ ATTRIB(Spiderbot, head_model, string, "models/vehicles/spiderbot_top.dpm"); /* hud_model */ ATTRIB(Spiderbot, hud_model, string, "models/vehicles/spiderbot_cockpit.dpm"); /* tags */ ATTRIB(Spiderbot, tag_head, string, "tag_head"); diff --git a/qcsrc/common/vehicles/vehicle/spiderbot_weapons.qc b/qcsrc/common/vehicles/vehicle/spiderbot_weapons.qc index 7887781ed..eddc29b9a 100644 --- a/qcsrc/common/vehicles/vehicle/spiderbot_weapons.qc +++ b/qcsrc/common/vehicles/vehicle/spiderbot_weapons.qc @@ -4,245 +4,244 @@ void spiderbot_rocket_artillery(entity this) { - this.nextthink = time; - UpdateCSQCProjectile(this); + this.nextthink = time; + UpdateCSQCProjectile(this); } void spiderbot_rocket_unguided(entity this) { - vector newdir, olddir; + vector newdir, olddir; - this.nextthink = time; + this.nextthink = time; - olddir = normalize(this.velocity); - newdir = normalize(this.pos1 - this.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise; - this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed; + olddir = normalize(this.velocity); + newdir = normalize(this.pos1 - this.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise; + this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed; - UpdateCSQCProjectile(this); + UpdateCSQCProjectile(this); - if (IS_DEAD(this.owner) || this.cnt < time || vdist(this.pos1 - this.origin, <, 16)) - this.use(this, NULL, NULL); + if (IS_DEAD(this.owner) || this.cnt < time || vdist(this.pos1 - this.origin, <, 16)) { + this.use(this, NULL, NULL); + } } void spiderbot_rocket_guided(entity this) { - vector newdir, olddir; + vector newdir, olddir; - this.nextthink = time; + this.nextthink = time; - if(!this.realowner.vehicle) - setthink(this, spiderbot_rocket_unguided); + if (!this.realowner.vehicle) { + setthink(this, spiderbot_rocket_unguided); + } - crosshair_trace(this.realowner); - olddir = normalize(this.velocity); - newdir = normalize(trace_endpos - this.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise; - this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed; + crosshair_trace(this.realowner); + olddir = normalize(this.velocity); + newdir = normalize(trace_endpos - this.origin) + randomvec() * autocvar_g_vehicle_spiderbot_rocket_noise; + this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_spiderbot_rocket_turnrate) * autocvar_g_vehicle_spiderbot_rocket_speed; - UpdateCSQCProjectile(this); + UpdateCSQCProjectile(this); - if (IS_DEAD(this.owner) || this.cnt < time) - this.use(this, NULL, NULL); + if (IS_DEAD(this.owner) || this.cnt < time) { + this.use(this, NULL, NULL); + } } void spiderbot_guide_release(entity this) { - bool donetrace = false; - IL_EACH(g_projectiles, it.realowner == this.owner && getthink(it) == spiderbot_rocket_guided, - { - if(!donetrace) // something exists, let's trace! - { - donetrace = true; - crosshair_trace(this.owner); - } - - it.pos1 = trace_endpos; - setthink(it, spiderbot_rocket_unguided); - }); + bool donetrace = false; + IL_EACH(g_projectiles, it.realowner == this.owner && getthink(it) == spiderbot_rocket_guided, + { + if (!donetrace) { // something exists, let's trace! + donetrace = true; + crosshair_trace(this.owner); + } + + it.pos1 = trace_endpos; + setthink(it, spiderbot_rocket_unguided); + }); } float spiberbot_calcartillery_flighttime; vector spiberbot_calcartillery(vector org, vector tgt, float ht) { - float grav, sdist, zdist, vs, vz, jumpheight; - vector sdir; - - grav = autocvar_sv_gravity; - zdist = tgt_z - org_z; - sdist = vlen(tgt - org - zdist * '0 0 1'); - sdir = normalize(tgt - org - zdist * '0 0 1'); - - // how high do we need to go? - jumpheight = fabs(ht); - if(zdist > 0) - jumpheight = jumpheight + zdist; - - // push so high... - vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)! - - // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump! - if(ht < 0) - if(zdist < 0) - vz = -vz; - - vector solution; - solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist" - // ALWAYS solvable because jumpheight >= zdist - if(!solution_z) - solution_y = solution_x; // just in case it is not solvable due to roundoff errors, assume two equal solutions at their center (this is mainly for the usual case with ht == 0) - if(zdist == 0) - solution_x = solution_y; // solution_x is 0 in this case, so don't use it, but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually) - - if(zdist < 0) - { - // down-jump - if(ht < 0) - { - // almost straight line type - // jump apex is before the jump - // we must take the larger one - spiberbot_calcartillery_flighttime = solution_y; - } - else - { - // regular jump - // jump apex is during the jump - // we must take the larger one too - spiberbot_calcartillery_flighttime = solution_y; - } - } - else - { - // up-jump - if(ht < 0) - { - // almost straight line type - // jump apex is after the jump - // we must take the smaller one - spiberbot_calcartillery_flighttime = solution_x; - } - else - { - // regular jump - // jump apex is during the jump - // we must take the larger one - spiberbot_calcartillery_flighttime = solution_y; - } - } - vs = sdist / spiberbot_calcartillery_flighttime; - - // finally calculate the velocity - return sdir * vs + '0 0 1' * vz; + float grav, sdist, zdist, vs, vz, jumpheight; + vector sdir; + + grav = autocvar_sv_gravity; + zdist = tgt_z - org_z; + sdist = vlen(tgt - org - zdist * '0 0 1'); + sdir = normalize(tgt - org - zdist * '0 0 1'); + + // how high do we need to go? + jumpheight = fabs(ht); + if (zdist > 0) { + jumpheight = jumpheight + zdist; + } + + // push so high... + vz = sqrt(2 * grav * jumpheight); // NOTE: sqrt(positive)! + + // we start with downwards velocity only if it's a downjump and the jump apex should be outside the jump! + if (ht < 0) { + if (zdist < 0) { + vz = -vz; + } + } + + vector solution; + solution = solve_quadratic(0.5 * grav, -vz, zdist); // equation "z(ti) = zdist" + // ALWAYS solvable because jumpheight >= zdist + if (!solution_z) { + solution_y = solution_x; // just in case it is not solvable due to roundoff errors, assume two equal solutions at their center (this is mainly for the usual case with ht == 0) + } + if (zdist == 0) { + solution_x = solution_y; // solution_x is 0 in this case, so don't use it, but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually) + } + if (zdist < 0) { + // down-jump + if (ht < 0) { + // almost straight line type + // jump apex is before the jump + // we must take the larger one + spiberbot_calcartillery_flighttime = solution_y; + } else { + // regular jump + // jump apex is during the jump + // we must take the larger one too + spiberbot_calcartillery_flighttime = solution_y; + } + } else { + // up-jump + if (ht < 0) { + // almost straight line type + // jump apex is after the jump + // we must take the smaller one + spiberbot_calcartillery_flighttime = solution_x; + } else { + // regular jump + // jump apex is during the jump + // we must take the larger one + spiberbot_calcartillery_flighttime = solution_y; + } + } + vs = sdist / spiberbot_calcartillery_flighttime; + + // finally calculate the velocity + return sdir * vs + '0 0 1' * vz; } void spiderbot_rocket_do(entity this) { - vector v; - entity rocket = NULL; - - if (this.wait != -10) - { - if (PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.vehicle_weapon2mode == SBRM_GUIDE) - { - if (this.wait == 1) - if (this.tur_head.frame == 9 || this.tur_head.frame == 1) - { - if(this.gun2.cnt < time && this.tur_head.frame == 9) - this.tur_head.frame = 1; - - return; - } - this.wait = 1; - } - else - { - if(this.wait) - spiderbot_guide_release(this); - - this.wait = 0; - } - } - - if(this.gun2.cnt > time) - return; - - if (this.tur_head.frame >= 9) - { - this.tur_head.frame = 1; - this.wait = 0; - } - - if(this.wait != -10) - if(!PHYS_INPUT_BUTTON_ATCK2(this.owner)) - return; - - if(forbidWeaponUse(this.owner)) - return; - - v = gettaginfo(this.tur_head,gettagindex(this.tur_head,"tag_fire")); - - switch(this.vehicle_weapon2mode) - { - case SBRM_VOLLY: - rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, - v, normalize(randomvec() * autocvar_g_vehicle_spiderbot_rocket_spread + v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed, - autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1, - DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner); - crosshair_trace(this.owner); - float _dist = (random() * autocvar_g_vehicle_spiderbot_rocket_radius) + vlen(v - trace_endpos); - _dist -= (random() * autocvar_g_vehicle_spiderbot_rocket_radius) ; - rocket.nextthink = time + (_dist / autocvar_g_vehicle_spiderbot_rocket_speed); - setthink(rocket, vehicles_projectile_explode_think); - - if(PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.tur_head.frame == 1) - this.wait = -10; - break; - case SBRM_GUIDE: - rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, - v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed, - autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1, - DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, false, this.owner); - crosshair_trace(this.owner); - rocket.pos1 = trace_endpos; - rocket.nextthink = time; - setthink(rocket, spiderbot_rocket_guided); - - - break; - case SBRM_ARTILLERY: - rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, - v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed, - autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1, - DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner); - - crosshair_trace(this.owner); - - rocket.pos1 = trace_endpos + randomvec() * (0.75 * autocvar_g_vehicle_spiderbot_rocket_radius); - rocket.pos1_z = trace_endpos_z; - - traceline(v, v + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this); - float h1 = 0.75 * vlen(v - trace_endpos); - - //v = trace_endpos; - traceline(v , rocket.pos1 + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this); - float h2 = 0.75 * vlen(rocket.pos1 - v); - - rocket.velocity = spiberbot_calcartillery(v, rocket.pos1, ((h1 < h2) ? h1 : h2)); - set_movetype(rocket, MOVETYPE_TOSS); - rocket.gravity = 1; - //setthink(rocket, spiderbot_rocket_artillery); - break; - } - rocket.classname = "spiderbot_rocket"; - - rocket.cnt = time + autocvar_g_vehicle_spiderbot_rocket_lifetime; - - this.tur_head.frame += 1; - if (this.tur_head.frame == 9) - this.attack_finished_single[0] = autocvar_g_vehicle_spiderbot_rocket_reload; - else - this.attack_finished_single[0] = ((this.vehicle_weapon2mode == SBRM_VOLLY) ? autocvar_g_vehicle_spiderbot_rocket_refire2 : autocvar_g_vehicle_spiderbot_rocket_refire); - - this.gun2.cnt = time + this.attack_finished_single[0]; + vector v; + entity rocket = NULL; + + if (this.wait != -10) { + if (PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.vehicle_weapon2mode == SBRM_GUIDE) { + if (this.wait == 1) { + if (this.tur_head.frame == 9 || this.tur_head.frame == 1) { + if (this.gun2.cnt < time && this.tur_head.frame == 9) { + this.tur_head.frame = 1; + } + + return; + } + } + this.wait = 1; + } else { + if (this.wait) { + spiderbot_guide_release(this); + } + + this.wait = 0; + } + } + + if (this.gun2.cnt > time) { + return; + } + + if (this.tur_head.frame >= 9) { + this.tur_head.frame = 1; + this.wait = 0; + } + + if (this.wait != -10) { + if (!PHYS_INPUT_BUTTON_ATCK2(this.owner)) { + return; + } + } + + if (forbidWeaponUse(this.owner)) { + return; + } + + v = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_fire")); + + switch (this.vehicle_weapon2mode) { + case SBRM_VOLLY: + rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, + v, normalize(randomvec() * autocvar_g_vehicle_spiderbot_rocket_spread + v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed, + autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1, + DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner); + crosshair_trace(this.owner); + float _dist = (random() * autocvar_g_vehicle_spiderbot_rocket_radius) + vlen(v - trace_endpos); + _dist -= (random() * autocvar_g_vehicle_spiderbot_rocket_radius); + rocket.nextthink = time + (_dist / autocvar_g_vehicle_spiderbot_rocket_speed); + setthink(rocket, vehicles_projectile_explode_think); + + if (PHYS_INPUT_BUTTON_ATCK2(this.owner) && this.tur_head.frame == 1) { + this.wait = -10; + } + break; + case SBRM_GUIDE: + rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, + v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed, + autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1, + DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, false, this.owner); + crosshair_trace(this.owner); + rocket.pos1 = trace_endpos; + rocket.nextthink = time; + setthink(rocket, spiderbot_rocket_guided); + + + break; + case SBRM_ARTILLERY: + rocket = vehicles_projectile(this, EFFECT_SPIDERBOT_ROCKETLAUNCH.eent_eff_name, SND_ROCKET_FIRE, + v, normalize(v_forward) * autocvar_g_vehicle_spiderbot_rocket_speed, + autocvar_g_vehicle_spiderbot_rocket_damage, autocvar_g_vehicle_spiderbot_rocket_radius, autocvar_g_vehicle_spiderbot_rocket_force, 1, + DEATH_VH_SPID_ROCKET.m_id, PROJECTILE_SPIDERROCKET, autocvar_g_vehicle_spiderbot_rocket_health, false, true, this.owner); + + crosshair_trace(this.owner); + + rocket.pos1 = trace_endpos + randomvec() * (0.75 * autocvar_g_vehicle_spiderbot_rocket_radius); + rocket.pos1_z = trace_endpos_z; + + traceline(v, v + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this); + float h1 = 0.75 * vlen(v - trace_endpos); + + // v = trace_endpos; + traceline(v, rocket.pos1 + '0 0 1' * max_shot_distance, MOVE_WORLDONLY, this); + float h2 = 0.75 * vlen(rocket.pos1 - v); + + rocket.velocity = spiberbot_calcartillery(v, rocket.pos1, ((h1 < h2) ? h1 : h2)); + set_movetype(rocket, MOVETYPE_TOSS); + rocket.gravity = 1; + // setthink(rocket, spiderbot_rocket_artillery); + break; + } + rocket.classname = "spiderbot_rocket"; + + rocket.cnt = time + autocvar_g_vehicle_spiderbot_rocket_lifetime; + + this.tur_head.frame += 1; + if (this.tur_head.frame == 9) { + this.attack_finished_single[0] = autocvar_g_vehicle_spiderbot_rocket_reload; + } else { + this.attack_finished_single[0] = ((this.vehicle_weapon2mode == SBRM_VOLLY) ? autocvar_g_vehicle_spiderbot_rocket_refire2 : autocvar_g_vehicle_spiderbot_rocket_refire); + } + + this.gun2.cnt = time + this.attack_finished_single[0]; } #endif diff --git a/qcsrc/common/viewloc.qc b/qcsrc/common/viewloc.qc index e20b660e5..9b392fe0c 100644 --- a/qcsrc/common/viewloc.qc +++ b/qcsrc/common/viewloc.qc @@ -2,8 +2,8 @@ #include "util.qh" #if defined(CSQC) - #include "../client/defs.qh" - #include "constants.qh" + #include "../client/defs.qh" + #include "constants.qh" #elif defined(MENUQC) #elif defined(SVQC) #include "../server/defs.qh" @@ -12,17 +12,17 @@ // client movement void viewloc_PlayerPhysics(entity this) { - if(this.viewloc) - { - if(this.viewloc.goalentity == this.viewloc.enemy) + if (this.viewloc) { + if (this.viewloc.goalentity == this.viewloc.enemy) { return; // we can't side-scroll in this case - + } vector old_movement = PHYS_CS(this).movement; PHYS_CS(this).movement_x = old_movement_y; PHYS_CS(this).movement_y = 0; - if(PHYS_CS(this).movement_x < 0) + if (PHYS_CS(this).movement_x < 0) { PHYS_CS(this).movement_x = -PHYS_CS(this).movement_x; + } vector level_start, level_end; level_start = this.viewloc.enemy.origin; @@ -31,35 +31,37 @@ void viewloc_PlayerPhysics(entity this) forward = vectoangles(normalize(level_end - level_start)); backward = vectoangles(normalize(level_start - level_end)); - if(PHYS_CS(this).movement_x < 0) // left + if (PHYS_CS(this).movement_x < 0) { // left this.angles_y = backward_y; - if(PHYS_CS(this).movement_x > 0) // right + } + if (PHYS_CS(this).movement_x > 0) { // right this.angles_y = forward_y; + } - if(old_movement_x > 0) { + if (old_movement_x > 0) { #ifdef CSQC input_angles_x = #endif this.v_angle_x = this.angles_x = -50; - } else if(old_movement_x < 0) { + } else if (old_movement_x < 0) { #ifdef CSQC input_angles_x = #endif this.v_angle_x = this.angles_x = 50; } - //if(!PHYS_INPUT_BUTTON_CROUCH(this) && !IS_DUCKED(this)) + // if(!PHYS_INPUT_BUTTON_CROUCH(this) && !IS_DUCKED(this)) #ifdef SVQC - //PHYS_INPUT_BUTTON_CROUCH(this) = (old_movement_x < 0); - if (old_movement.x < 0) { - PHYS_INPUT_BUTTON_CROUCH(this) = true; - } + // PHYS_INPUT_BUTTON_CROUCH(this) = (old_movement_x < 0); + if (old_movement.x < 0) { + PHYS_INPUT_BUTTON_CROUCH(this) = true; + } #elif defined(CSQC) - if (old_movement.x < 0) { - input_buttons |= BIT(4); - this.flags |= FL_DUCKED; - } - //else { input_buttons &= ~16; this.flags &= ~FL_DUCKED; } + if (old_movement.x < 0) { + input_buttons |= BIT(4); + this.flags |= FL_DUCKED; + } + // else { input_buttons &= ~16; this.flags &= ~FL_DUCKED; } #endif } } @@ -68,14 +70,17 @@ void viewloc_PlayerPhysics(entity this) void viewloc_SetTags(entity this) { - if(this.viewloc && wasfreed(this.viewloc)) + if (this.viewloc && wasfreed(this.viewloc)) { this.viewloc = NULL; + } - if(this.viewloc.entnum != this.tag_networkviewloc) - if(this.tag_networkviewloc == 0) - this.viewloc = NULL; - else - this.viewloc = findfloat(NULL, entnum, this.tag_networkviewloc); + if (this.viewloc.entnum != this.tag_networkviewloc) { + if (this.tag_networkviewloc == 0) { + this.viewloc = NULL; + } else { + this.viewloc = findfloat(NULL, entnum, this.tag_networkviewloc); + } + } } vector old_camera_angle = '0 0 0'; @@ -86,13 +91,12 @@ bool autocvar_cam_snap_unlock; void viewloc_SetViewLocation() { entity view = CSQCModel_server2csqc(player_localentnum - 1); - if (!view) return; - //NOTE: the "cam_" cvars sould probably be changed out with a spawnflag or an entity key. I have it like this for my testing -- Player_2 - if(view.viewloc && !wasfreed(view.viewloc) && view.viewloc.enemy && view.viewloc.goalentity) - { + if (!view) { return; } + // NOTE: the "cam_" cvars sould probably be changed out with a spawnflag or an entity key. I have it like this for my testing -- Player_2 + if (view.viewloc && !wasfreed(view.viewloc) && view.viewloc.enemy && view.viewloc.goalentity) { bool have_sidescroll = (view.viewloc.enemy != view.viewloc.goalentity); vector position_a, position_b, camera_position, camera_angle = '0 0 0', forward, backward; - //vector scratch; + // vector scratch; position_a = view.viewloc.enemy.origin; position_b = view.viewloc.goalentity.origin; @@ -103,25 +107,23 @@ void viewloc_SetViewLocation() */ if (cvar("cam_box")) { camera_position = vec_bounds_in(view.origin, position_a, position_b); - } - else + } else #endif - camera_position = vec_bounds_in(view.origin, position_a, position_b); + camera_position = vec_bounds_in(view.origin, position_a, position_b); // a tracking camera follows the player when it leaves the world box if (autocvar_cam_track || !have_sidescroll) { - camera_angle = aim_vec (camera_position, view.origin); + camera_angle = aim_vec(camera_position, view.origin); } // hard snap changes the angle as soon as it crosses over the nearest 90 degree mark - if (autocvar_cam_snap_hard){ + if (autocvar_cam_snap_hard) { camera_angle = angle_snap_vec(aim_vec(camera_position, view.origin), 90); } // tries to avoid snapping unless it *really* needs to - if (autocvar_cam_snap_close){ - + if (autocvar_cam_snap_close) { // like hard snap, but don't snap angles yet. camera_angle = aim_vec(camera_position, view.origin); @@ -131,13 +133,14 @@ void viewloc_SetViewLocation() */ float camera_angle_diff = max(camera_angle_y, old_camera_angle_y) - min(camera_angle_y, old_camera_angle_y); - if ( camera_angle_diff >= 60) + if (camera_angle_diff >= 60) { old_camera_angle_y = angle_snap_f(camera_angle_y, 90); - else + } else { camera_angle_y = old_camera_angle_y; + } } - //unlocking this allows the camera to look up and down. this also allows a top-down view. + // unlocking this allows the camera to look up and down. this also allows a top-down view. if (!autocvar_cam_snap_unlock) { camera_angle_x = 0; camera_angle_z = 0; @@ -154,15 +157,16 @@ void viewloc_SetViewLocation() setproperty(VF_ORIGIN, camera_position); setproperty(VF_ANGLES, camera_angle); - if(have_sidescroll) - { + if (have_sidescroll) { forward = vectoangles(normalize(vec_to_min(position_b, position_a) - vec_to_max(position_b, position_a))); backward = vectoangles(normalize(vec_to_max(position_b, position_a) - vec_to_min(position_b, position_a))); - if(input_movevalues_y < 0) // left + if (input_movevalues_y < 0) { // left view.angles_y = backward.y; - if(input_movevalues_y > 0) // favour right + } + if (input_movevalues_y > 0) { // favour right view.angles_y = forward.y; + } setproperty(VF_CL_VIEWANGLES, view.angles); } diff --git a/qcsrc/common/weapons/calculations.qc b/qcsrc/common/weapons/calculations.qc index 3323d8e36..7ef6fbbf6 100644 --- a/qcsrc/common/weapons/calculations.qc +++ b/qcsrc/common/weapons/calculations.qc @@ -9,12 +9,13 @@ float explosion_calcpush_getmultiplier(vector explosion_v, vector target_v) float a; a = explosion_v * (explosion_v - target_v); - if(a <= 0) + if (a <= 0) { // target is too fast to be hittable by this return 0; + } a /= (explosion_v * explosion_v); - // we know we can divide by this, or above a would be == 0 + // we know we can divide by this, or above a would be == 0 return a; } @@ -45,8 +46,9 @@ vector explosion_calcpush(vector explosion_v, float explosion_m, vector target_v vector damage_explosion_calcpush(vector explosion_f, vector target_v, float speedfactor) { // if below 1, the formulas make no sense (and would cause superjumps) - if(speedfactor < 1) + if (speedfactor < 1) { return explosion_f; + } #if 0 float m; @@ -80,37 +82,33 @@ vector cliptoplane(vector v, vector p) vector solve_cubic_pq(float p, float q) { float D, u, v, a; - D = q*q/4.0 + p*p*p/27.0; - if(D < 0) - { + D = q * q / 4.0 + p * p * p / 27.0; + if (D < 0) { // irreducibilis - a = 1.0/3.0 * acos(-q/2.0 * sqrt(-27.0/(p*p*p))); - u = sqrt(-4.0/3.0 * p); + a = 1.0 / 3.0 * acos(-q / 2.0 * sqrt(-27.0 / (p * p * p))); + u = sqrt(-4.0 / 3.0 * p); // a in range 0..pi/3 // cos(a) // cos(a + 2pi/3) // cos(a + 4pi/3) return u * vec3( - cos(a + 2.0/3.0*M_PI), - cos(a + 4.0/3.0*M_PI), + cos(a + 2.0 / 3.0 * M_PI), + cos(a + 4.0 / 3.0 * M_PI), cos(a) ); - } - else if(D == 0) - { + } else if (D == 0) { // simple - if(p == 0) + if (p == 0) { return '0 0 0'; - u = 3*q/p; - v = -u/2; + } + u = 3 * q / p; + v = -u / 2; return (u >= v) ? vec3(v, v, u) : vec3(u, v, v); - } - else - { + } else { // cardano - //u = cbrt(-q/2.0 + sqrt(D)); - //v = cbrt(-q/2.0 - sqrt(D)); - a = cbrt(-q/2.0 + sqrt(D)) + cbrt(-q/2.0 - sqrt(D)); + // u = cbrt(-q/2.0 + sqrt(D)); + // v = cbrt(-q/2.0 - sqrt(D)); + a = cbrt(-q / 2.0 + sqrt(D)) + cbrt(-q / 2.0 - sqrt(D)); return vec3(a, a, a); } } @@ -120,12 +118,13 @@ vector solve_cubic_abcd(float a, float b, float c, float d) // x = (y - b) / 3a float p, q; vector v; - p = (9*a*c - 3*b*b); - q = (27*a*a*d - 9*a*b*c + 2*b*b*b); + p = (9 * a * c - 3 * b * b); + q = (27 * a * a * d - 9 * a * b * c + 2 * b * b * b); v = solve_cubic_pq(p, q); v = (v - b * '1 1 1') * (1.0 / (3.0 * a)); - if(a < 0) + if (a < 0) { v += '1 0 -1' * (v.z - v.x); // swap x, z + } return v; } @@ -135,49 +134,52 @@ vector findperpendicular(vector v) } #ifdef SVQC - int W_GunAlign(entity this, int preferred_align) - { - if(this.m_gunalign) - return this.m_gunalign; // no adjustment needed - - entity own = this.owner; - - if(preferred_align < 1 || preferred_align > 4) - preferred_align = 3; // default +int W_GunAlign(entity this, int preferred_align) +{ + if (this.m_gunalign) { + return this.m_gunalign; // no adjustment needed + } + entity own = this.owner; - for(int j = 4; j > 1; --j) // > 1 as 1 is just center again - { - int taken = 0; - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { - .entity weaponentity = weaponentities[slot]; - if(own.(weaponentity).m_gunalign == j) // we know it can't be ours thanks to the above check - taken |= BIT(j); - if(own.(weaponentity).m_gunalign == preferred_align) - taken |= BIT(preferred_align); + if (preferred_align < 1 || preferred_align > 4) { + preferred_align = 3; // default + } + for (int j = 4; j > 1; --j) { // > 1 as 1 is just center again + int taken = 0; + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { + .entity weaponentity = weaponentities[slot]; + if (own.(weaponentity).m_gunalign == j) { // we know it can't be ours thanks to the above check + taken |= BIT(j); + } + if (own.(weaponentity).m_gunalign == preferred_align) { + taken |= BIT(preferred_align); } - - if(!(taken & BIT(preferred_align))) - return preferred_align; // prefer the recommended - if(!(taken & BIT(j))) - return j; // or fall back if it's not available } - return preferred_align; // return it anyway + if (!(taken & BIT(preferred_align))) { + return preferred_align; // prefer the recommended + } + if (!(taken & BIT(j))) { + return j; // or fall back if it's not available + } } + + return preferred_align; // return it anyway +} #else - int W_GunAlign(entity this, int preferred_align) - { - return this.m_gunalign > 0 ? this.m_gunalign : preferred_align; - } +int W_GunAlign(entity this, int preferred_align) +{ + return this.m_gunalign > 0 ? this.m_gunalign : preferred_align; +} #endif #if 0 int W_GetGunAlignment(entity player) { int gunalign = STAT(GUNALIGN, player); - if(gunalign < 1 || gunalign > 4) + if (gunalign < 1 || gunalign > 4) { gunalign = 3; // default value + } --gunalign; return gunalign; @@ -189,12 +191,12 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float float sigma; vector v1 = '0 0 0', v2; float dx, dy, r; - spread *= spreadfactor; //g_weaponspreadfactor; - if(spread <= 0) + spread *= spreadfactor; // g_weaponspreadfactor; + if (spread <= 0) { return forward; + } - switch(spreadstyle) - { + switch (spreadstyle) { case 0: { // this is the baseline for the spread value! @@ -222,7 +224,7 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float r = sqrt(r); return normalize(forward + (v1 * dx + v2 * dy) * r * sigma); } - case 3: // gauss 3d + case 3: // gauss 3d { sigma = spread * 0.44721359549996; // match baseline stddev // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right @@ -232,7 +234,7 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float v1_z += gsl_ran_gaussian(sigma); return v1; } - case 4: // gauss 2d + case 4: // gauss 2d { sigma = spread * 0.44721359549996; // match baseline stddev // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right @@ -241,7 +243,7 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float v1_z = gsl_ran_gaussian(sigma); return normalize(forward + cliptoplane(v1, forward)); } - case 5: // 1-r + case 5: // 1-r { sigma = spread * 1.154700538379252; // match baseline stddev v1 = findperpendicular(forward); @@ -255,7 +257,7 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float r = solve_cubic_abcd(-2, 3, 0, -r) * '0 1 0'; return normalize(forward + (v1 * dx + v2 * dy) * r * sigma); } - case 6: // 1-r^2 + case 6: // 1-r^2 { sigma = spread * 1.095445115010332; // match baseline stddev v1 = findperpendicular(forward); @@ -270,7 +272,7 @@ vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float r = sqrt(1 - r); return normalize(forward + (v1 * dx + v2 * dy) * r * sigma); } - case 7: // (1-r) (2-r) + case 7: // (1-r) (2-r) { sigma = spread * 1.224744871391589; // match baseline stddev v1 = findperpendicular(forward); diff --git a/qcsrc/common/weapons/calculations.qh b/qcsrc/common/weapons/calculations.qh index d749cc15e..468dc083f 100644 --- a/qcsrc/common/weapons/calculations.qh +++ b/qcsrc/common/weapons/calculations.qh @@ -3,5 +3,5 @@ vector damage_explosion_calcpush(vector explosion_f, vector target_v, float speedfactor); vector W_CalculateSpread(vector forward, float spread, float spreadfactor, float spreadstyle); int W_GunAlign(entity this, int preferred_align); -//int W_GetGunAlignment(entity player); +// int W_GetGunAlignment(entity player); float explosion_calcpush_getmultiplier(vector explosion_v, vector target_v); diff --git a/qcsrc/common/weapons/config.qc b/qcsrc/common/weapons/config.qc index d2443f167..527948a07 100644 --- a/qcsrc/common/weapons/config.qc +++ b/qcsrc/common/weapons/config.qc @@ -2,8 +2,8 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include - #include "all.qh" + #include + #include "all.qh" #endif // ========================== @@ -28,8 +28,9 @@ void Dump_Weapon_Settings() FOREACH(Weapons, it != WEP_Null, { // step 1: clear the queue WEP_CONFIG_COUNT = 0; - for (int x = 0; x <= MAX_CONFIG_SETTINGS; ++x) + for (int x = 0; x <= MAX_CONFIG_SETTINGS; ++x) { config_queue[x] = string_null; + } // step 2: build new queue it.wr_config(it); @@ -39,12 +40,14 @@ void Dump_Weapon_Settings() // step 4: write queue WEP_CONFIG_WRITETOFILE(sprintf( - "// {{{ #%d: %s%s\n", - i, - it.m_name, - ((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) ? " (MUTATOR WEAPON)" : "") + "// {{{ #%d: %s%s\n", + i, + it.m_name, + ((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) ? " (MUTATOR WEAPON)" : "") )); - for (int x = 0; x <= WEP_CONFIG_COUNT; ++x) { WEP_CONFIG_WRITETOFILE(config_queue[x]); } + for (int x = 0; x <= WEP_CONFIG_COUNT; ++x) { + WEP_CONFIG_WRITETOFILE(config_queue[x]); + } WEP_CONFIG_WRITETOFILE("// }}}\n"); // step 5: debug info @@ -55,8 +58,9 @@ void Dump_Weapon_Settings() // clear queue now that we're finished WEP_CONFIG_COUNT = 0; - for(int x = 0; x <= MAX_CONFIG_SETTINGS; ++x) + for (int x = 0; x <= MAX_CONFIG_SETTINGS; ++x) { config_queue[x] = string_null; + } // extra information LOG_INFOF("Totals: %d weapons, %d settings", totalweapons, totalsettings); diff --git a/qcsrc/common/weapons/config.qh b/qcsrc/common/weapons/config.qh index 883082c97..4cbafab74 100644 --- a/qcsrc/common/weapons/config.qh +++ b/qcsrc/common/weapons/config.qh @@ -10,26 +10,29 @@ int wep_config_file; bool wep_config_alsoprint; int WEP_CONFIG_COUNT; -#define WEP_CONFIG_QUEUE(a) { \ - config_queue[WEP_CONFIG_COUNT] = a; \ - ++WEP_CONFIG_COUNT; } +#define WEP_CONFIG_QUEUE(a) \ + { \ + config_queue[WEP_CONFIG_COUNT] = a; \ + ++WEP_CONFIG_COUNT; \ + } -#define WEP_CONFIG_WRITETOFILE(a) MACRO_BEGIN \ - fputs(wep_config_file, a); \ - if(wep_config_alsoprint) { LOG_INFO(a); } \ -MACRO_END +#define WEP_CONFIG_WRITETOFILE(a) \ + MACRO_BEGIN \ + fputs(wep_config_file, a); \ + if (wep_config_alsoprint) { LOG_INFO(a); } \ + MACRO_END #define WEP_CONFIG_WRITE_CVARS(wepname, name, T) WEP_CONFIG_WRITE_PROPS_##T(wepname, name) #define WEP_CONFIG_WRITE_PROPS_string(wepname, name) \ { WEP_CONFIG_QUEUE( \ - sprintf("set g_balance_%s_%s \"%s\"\n", #wepname, #name, \ - cvar_string(sprintf("g_balance_%s_%s", #wepname, #name)))) } + sprintf("set g_balance_%s_%s \"%s\"\n", #wepname, #name, \ + cvar_string(sprintf("g_balance_%s_%s", #wepname, #name)))) } #define WEP_CONFIG_WRITE_PROPS_float(wepname, name) \ { WEP_CONFIG_QUEUE( \ - sprintf("set g_balance_%s_%s %g\n", #wepname, #name, \ - cvar(sprintf("g_balance_%s_%s", #wepname, #name)))) } + sprintf("set g_balance_%s_%s %g\n", #wepname, #name, \ + cvar(sprintf("g_balance_%s_%s", #wepname, #name)))) } #endif diff --git a/qcsrc/common/weapons/weapon/fireball.qc b/qcsrc/common/weapons/weapon/fireball.qc index 3f9cd4c4e..5049f885b 100644 --- a/qcsrc/common/weapons/weapon/fireball.qc +++ b/qcsrc/common/weapons/weapon/fireball.qc @@ -1,7 +1,10 @@ #include "fireball.qh" #ifdef SVQC -spawnfunc(weapon_fireball) { weapon_defaultspawnfunc(this, WEP_FIREBALL); } +spawnfunc(weapon_fireball) +{ + weapon_defaultspawnfunc(this, WEP_FIREBALL); +} void W_Fireball_Explode(entity this, entity directhitentity) { @@ -17,36 +20,45 @@ void W_Fireball_Explode(entity this, entity directhitentity) // 1. dist damage d = (this.realowner.health + this.realowner.armorvalue); RadiusDamage(this, this.realowner, WEP_CVAR_PRI(fireball, damage), WEP_CVAR_PRI(fireball, edgedamage), WEP_CVAR_PRI(fireball, radius), NULL, NULL, WEP_CVAR_PRI(fireball, force), this.projectiledeathtype, directhitentity); - if(this.realowner.health + this.realowner.armorvalue >= d) - if(!this.cnt) - { - modeleffect_spawn("models/sphere/sphere.md3", 0, 0, this.origin, '0 0 0', '0 0 0', '0 0 0', 0, WEP_CVAR_PRI(fireball, bfgradius), 0.2, 0.05, 0.25); - - // 2. bfg effect - // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here. - for(e = findradius(this.origin, WEP_CVAR_PRI(fireball, bfgradius)); e; e = e.chain) - if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this)) - { - // can we see fireball? - traceline(e.origin + e.view_ofs, this.origin, MOVE_NORMAL, e); - if(/* trace_startsolid || */ trace_fraction != 1) // startsolid should be never happening anyway - continue; - // can we see player who shot fireball? - traceline(e.origin + e.view_ofs, this.realowner.origin + this.realowner.view_ofs, MOVE_NORMAL, e); - if(trace_ent != this.realowner) - if(/* trace_startsolid || */ trace_fraction != 1) - continue; - dist = vlen(this.origin - e.origin - e.view_ofs); - points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius))); - if(points <= 0) - continue; - dir = normalize(e.origin + e.view_ofs - this.origin); - - if(accuracy_isgooddamage(this.realowner, e)) - accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points); - - Damage(e, this, this.realowner, WEP_CVAR_PRI(fireball, bfgdamage) * points, this.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, WEP_CVAR_PRI(fireball, bfgforce) * dir); - Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1); + if (this.realowner.health + this.realowner.armorvalue >= d) { + if (!this.cnt) { + modeleffect_spawn("models/sphere/sphere.md3", 0, 0, this.origin, '0 0 0', '0 0 0', '0 0 0', 0, WEP_CVAR_PRI(fireball, bfgradius), 0.2, 0.05, 0.25); + + // 2. bfg effect + // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here. + for (e = findradius(this.origin, WEP_CVAR_PRI(fireball, bfgradius)); e; e = e.chain) { + if (e != this.realowner) { + if (e.takedamage == DAMAGE_AIM) { + if (!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this)) { + // can we see fireball? + traceline(e.origin + e.view_ofs, this.origin, MOVE_NORMAL, e); + if ( /* trace_startsolid || */ trace_fraction != 1) { // startsolid should be never happening anyway + continue; + } + // can we see player who shot fireball? + traceline(e.origin + e.view_ofs, this.realowner.origin + this.realowner.view_ofs, MOVE_NORMAL, e); + if (trace_ent != this.realowner) { + if ( /* trace_startsolid || */ trace_fraction != 1) { + continue; + } + } + dist = vlen(this.origin - e.origin - e.view_ofs); + points = (1 - sqrt(dist / WEP_CVAR_PRI(fireball, bfgradius))); + if (points <= 0) { + continue; + } + dir = normalize(e.origin + e.view_ofs - this.origin); + + if (accuracy_isgooddamage(this.realowner, e)) { + accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points); + } + + Damage(e, this, this.realowner, WEP_CVAR_PRI(fireball, bfgdamage) * points, this.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, e.origin + e.view_ofs, WEP_CVAR_PRI(fireball, bfgforce) * dir); + Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1); + } + } + } + } } } @@ -75,38 +87,40 @@ void W_Fireball_LaserPlay(entity this, float dt, float dist, float damage, float float d; vector p; - if(damage <= 0) + if (damage <= 0) { return; + } RandomSelection_Init(); - for(e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain) - if(e != this.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this)) - { - p = e.origin; - p.x += e.mins.x + random() * (e.maxs.x - e.mins.x); - p.y += e.mins.y + random() * (e.maxs.y - e.mins.y); - p.z += e.mins.z + random() * (e.maxs.z - e.mins.z); - d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p); - if(d < dist) - { - e.fireball_impactvec = p; - RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e)); + for (e = WarpZone_FindRadius(this.origin, dist, true); e; e = e.chain) { + if (e != this.realowner) { + if (e.takedamage == DAMAGE_AIM) { + if (!IS_PLAYER(e) || !this.realowner || DIFF_TEAM(e, this)) { + p = e.origin; + p.x += e.mins.x + random() * (e.maxs.x - e.mins.x); + p.y += e.mins.y + random() * (e.maxs.y - e.mins.y); + p.z += e.mins.z + random() * (e.maxs.z - e.mins.z); + d = vlen(WarpZone_UnTransformOrigin(e, this.origin) - p); + if (d < dist) { + e.fireball_impactvec = p; + RandomSelection_AddEnt(e, 1 / (1 + d), !Fire_IsBurning(e)); + } + } + } } } - if(RandomSelection_chosen_ent) - { + if (RandomSelection_chosen_ent) { d = vlen(WarpZone_UnTransformOrigin(RandomSelection_chosen_ent, this.origin) - RandomSelection_chosen_ent.fireball_impactvec); d = damage + (edgedamage - damage) * (d / dist); Fire_AddDamage(RandomSelection_chosen_ent, this.realowner, d * burntime, burntime, this.projectiledeathtype | HITTYPE_BOUNCE); - //trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec); + // trailparticles(this, particleeffectnum(EFFECT_FIREBALL_LASER), this.origin, RandomSelection_chosen_ent.fireball_impactvec); Send_Effect(EFFECT_FIREBALL_LASER, this.origin, RandomSelection_chosen_ent.fireball_impactvec - this.origin, 1); } } void W_Fireball_Think(entity this) { - if(time > this.pushltime) - { + if (time > this.pushltime) { this.cnt = 1; this.projectiledeathtype |= HITTYPE_SPLASH; W_Fireball_Explode(this, NULL); @@ -120,15 +134,15 @@ void W_Fireball_Think(entity this) void W_Fireball_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) { - if(this.health <= 0) + if (this.health <= 0) { return; + } - if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions + if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) { // no exceptions return; // g_projectiles_damage says to halt - + } this.health = this.health - damage; - if(this.health <= 0) - { + if (this.health <= 0) { this.cnt = 1; W_PrepareExplosionByDamage(this, attacker, W_Fireball_Explode_think); } @@ -165,7 +179,7 @@ void W_Fireball_Attack1(entity actor, .entity weaponentity) proj.flags = FL_PROJECTILE; IL_PUSH(g_projectiles, proj); IL_PUSH(g_bot_dodge, proj); - proj.missile_flags = MIF_SPLASH | MIF_PROXY; + proj.missile_flags = MIF_SPLASH | MIF_PROXY; CSQCProjectile(proj, true, PROJECTILE_FIREBALL, true); @@ -212,23 +226,21 @@ void W_Fireball_Attack1_Frame0(Weapon thiswep, entity actor, .entity weaponentit void W_Fireball_Firemine_Think(entity this) { - if(time > this.pushltime) - { + if (time > this.pushltime) { delete(this); return; } // make it "hot" once it leaves its owner - if(this.owner) - { - if(vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius))) - { + if (this.owner) { + if (vdist(this.origin - this.owner.origin - this.owner.view_ofs, >, WEP_CVAR_SEC(fireball, laserradius))) { this.cnt += 1; - if(this.cnt == 3) + if (this.cnt == 3) { this.owner = NULL; - } - else + } + } else { this.cnt = 0; + } } W_Fireball_LaserPlay(this, 0.1, WEP_CVAR_SEC(fireball, laserradius), WEP_CVAR_SEC(fireball, laserdamage), WEP_CVAR_SEC(fireball, laseredgedamage), WEP_CVAR_SEC(fireball, laserburntime)); @@ -239,11 +251,11 @@ void W_Fireball_Firemine_Think(entity this) void W_Fireball_Firemine_Touch(entity this, entity toucher) { PROJECTILE_TOUCH(this, toucher); - if(toucher.takedamage == DAMAGE_AIM) - if(Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0) - { - delete(this); - return; + if (toucher.takedamage == DAMAGE_AIM) { + if (Fire_AddDamage(toucher, this.realowner, WEP_CVAR_SEC(fireball, damage), WEP_CVAR_SEC(fireball, damagetime), this.projectiledeathtype) >= 0) { + delete(this); + return; + } } this.projectiledeathtype |= HITTYPE_BOUNCE; } @@ -255,8 +267,7 @@ void W_Fireball_Attack2(entity actor, .entity weaponentity) float c; c = actor.(weaponentity).bulletcounter % 4; - switch(c) - { + switch (c) { case 0: f_diff = '-1.25 -3.75 0'; break; @@ -297,7 +308,7 @@ void W_Fireball_Attack2(entity actor, .entity weaponentity) proj.flags = FL_PROJECTILE; IL_PUSH(g_projectiles, proj); IL_PUSH(g_bot_dodge, proj); - proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC; + proj.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_ARC; CSQCProjectile(proj, true, PROJECTILE_FIREMINE, true); @@ -306,74 +317,66 @@ void W_Fireball_Attack2(entity actor, .entity weaponentity) METHOD(Fireball, wr_aim, void(entity thiswep, entity actor, .entity weaponentity)) { - PHYS_INPUT_BUTTON_ATCK(actor) = false; - PHYS_INPUT_BUTTON_ATCK2(actor) = false; - if(actor.bot_primary_fireballmooth == 0) - { - if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false)) - { - PHYS_INPUT_BUTTON_ATCK(actor) = true; - if(random() < 0.02) actor.bot_primary_fireballmooth = 0; - } - } - else - { - if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true)) - { - PHYS_INPUT_BUTTON_ATCK2(actor) = true; - if(random() < 0.01) actor.bot_primary_fireballmooth = 1; - } - } + PHYS_INPUT_BUTTON_ATCK(actor) = false; + PHYS_INPUT_BUTTON_ATCK2(actor) = false; + if (actor.bot_primary_fireballmooth == 0) { + if (bot_aim(actor, weaponentity, WEP_CVAR_PRI(fireball, speed), 0, WEP_CVAR_PRI(fireball, lifetime), false)) { + PHYS_INPUT_BUTTON_ATCK(actor) = true; + if (random() < 0.02) { actor.bot_primary_fireballmooth = 0; } + } + } else { + if (bot_aim(actor, weaponentity, WEP_CVAR_SEC(fireball, speed), WEP_CVAR_SEC(fireball, speed_up), WEP_CVAR_SEC(fireball, lifetime), true)) { + PHYS_INPUT_BUTTON_ATCK2(actor) = true; + if (random() < 0.01) { actor.bot_primary_fireballmooth = 1; } + } + } } METHOD(Fireball, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - if(fire & 1) - { - if(time >= actor.(weaponentity).fireball_primarytime) - if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire))) - { - W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire); - actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor); - } - } - else if(fire & 2) - { - if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire))) - { - W_Fireball_Attack2(actor, weaponentity); - weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready); - } - } + if (fire & 1) { + if (time >= actor.(weaponentity).fireball_primarytime) { + if (weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(fireball, refire))) { + W_Fireball_Attack1_Frame0(thiswep, actor, weaponentity, fire); + actor.(weaponentity).fireball_primarytime = time + WEP_CVAR_PRI(fireball, refire2) * W_WeaponRateFactor(actor); + } + } + } else if (fire & 2) { + if (weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(fireball, refire))) { + W_Fireball_Attack2(actor, weaponentity); + weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(fireball, animtime), w_ready); + } + } } METHOD(Fireball, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity)) { - return true; // infinite ammo + return true; // infinite ammo } METHOD(Fireball, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity)) { - return true; // fireball has infinite ammo + return true; // fireball has infinite ammo } METHOD(Fireball, wr_resetplayer, void(entity thiswep, entity actor)) { - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - actor.(weaponentity).fireball_primarytime = time; + actor.(weaponentity).fireball_primarytime = time; } } METHOD(Fireball, wr_suicidemessage, Notification(entity thiswep)) { - if(w_deathtype & HITTYPE_SECONDARY) - return WEAPON_FIREBALL_SUICIDE_FIREMINE; - else - return WEAPON_FIREBALL_SUICIDE_BLAST; + if (w_deathtype & HITTYPE_SECONDARY) { + return WEAPON_FIREBALL_SUICIDE_FIREMINE; + } else { + return WEAPON_FIREBALL_SUICIDE_BLAST; + } } METHOD(Fireball, wr_killmessage, Notification(entity thiswep)) { - if(w_deathtype & HITTYPE_SECONDARY) - return WEAPON_FIREBALL_MURDER_FIREMINE; - else - return WEAPON_FIREBALL_MURDER_BLAST; + if (w_deathtype & HITTYPE_SECONDARY) { + return WEAPON_FIREBALL_MURDER_FIREMINE; + } else { + return WEAPON_FIREBALL_MURDER_BLAST; + } } #endif @@ -381,18 +384,16 @@ METHOD(Fireball, wr_killmessage, Notification(entity thiswep)) METHOD(Fireball, wr_impacteffect, void(entity thiswep, entity actor)) { - vector org2; - if(w_deathtype & HITTYPE_SECONDARY) - { - // firemine goes out silently - } - else - { - org2 = w_org + w_backoff * 16; - pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1); - if(!w_issilent) - sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom - } + vector org2; + if (w_deathtype & HITTYPE_SECONDARY) { + // firemine goes out silently + } else { + org2 = w_org + w_backoff * 16; + pointparticles(EFFECT_FIREBALL_EXPLODE, org2, '0 0 0', 1); + if (!w_issilent) { + sound(actor, CH_SHOTS, SND_FIREBALL_IMPACT2, VOL_BASE, ATTEN_NORM * 0.25); // long range boom + } + } } #endif diff --git a/qcsrc/common/weapons/weapon/hook.qc b/qcsrc/common/weapons/weapon/hook.qc index 04383716a..ea26d8bfc 100644 --- a/qcsrc/common/weapons/weapon/hook.qc +++ b/qcsrc/common/weapons/weapon/hook.qc @@ -2,7 +2,10 @@ #ifdef SVQC -spawnfunc(weapon_hook) { weapon_defaultspawnfunc(this, WEP_HOOK); } +spawnfunc(weapon_hook) +{ + weapon_defaultspawnfunc(this, WEP_HOOK); +} void W_Hook_ExplodeThink(entity this) { @@ -16,12 +19,13 @@ void W_Hook_ExplodeThink(entity this) RadiusDamage(this, this.realowner, this.dmg * f, this.dmg_edge * f, this.dmg_radius, this.realowner, NULL, this.dmg_force * f, this.projectiledeathtype, NULL); this.projectiledeathtype |= HITTYPE_BOUNCE; - //RadiusDamage(this, NULL, this.dmg * f, this.dmg_edge * f, this.dmg_radius, NULL, NULL, this.dmg_force * f, this.projectiledeathtype, NULL); + // RadiusDamage(this, NULL, this.dmg * f, this.dmg_edge * f, this.dmg_radius, NULL, NULL, this.dmg_force * f, this.projectiledeathtype, NULL); - if(dt < this.dmg_duration) + if (dt < this.dmg_duration) { this.nextthink = time + 0.05; // soon - else + } else { delete(this); + } } void W_Hook_Explode2(entity this) @@ -50,16 +54,18 @@ void W_Hook_Explode2_use(entity this, entity actor, entity trigger) void W_Hook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) { - if(this.health <= 0) + if (this.health <= 0) { return; + } - if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions + if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) { // no exceptions return; // g_projectiles_damage says to halt - + } this.health = this.health - damage; - if(this.health <= 0) + if (this.health <= 0) { W_PrepareExplosionByDamage(this, this.realowner, W_Hook_Explode2); + } } void W_Hook_Touch2(entity this, entity toucher) @@ -70,7 +76,7 @@ void W_Hook_Touch2(entity this, entity toucher) void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity) { - //W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb) + // W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hook, ammo)); // WEAPONTODO: Figure out how to handle ammo with hook secondary (gravitybomb) W_SetupShot(actor, weaponentity, false, 4, SND_HOOKBOMB_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hook, damage)); entity gren = new(hookbomb); @@ -97,11 +103,12 @@ void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity) gren.missile_flags = MIF_SPLASH | MIF_ARC; gren.velocity = '0 0 1' * WEP_CVAR_SEC(hook, speed); - if (autocvar_g_projectiles_newton_style) + if (autocvar_g_projectiles_newton_style) { gren.velocity = gren.velocity + actor.velocity; + } gren.gravity = WEP_CVAR_SEC(hook, gravity); - //W_SetupProjVelocity_Basic(gren); // just falling down! + // W_SetupProjVelocity_Basic(gren); // just falling down! gren.angles = '0 0 0'; gren.flags = FL_PROJECTILE; @@ -115,96 +122,87 @@ void W_Hook_Attack2(Weapon thiswep, entity actor, .entity weaponentity) METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - if (fire & 1) { - if(!actor.(weaponentity).hook) - if(!(actor.(weaponentity).hook_state & HOOK_WAITING_FOR_RELEASE)) - if(time > actor.(weaponentity).hook_refire) - if(weapon_prepareattack(thiswep, actor, weaponentity, false, -1)) - { - W_DecreaseAmmo(thiswep, actor, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo), weaponentity); - actor.(weaponentity).hook_state |= HOOK_FIRING; - actor.(weaponentity).hook_state |= HOOK_WAITING_FOR_RELEASE; - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready); - } - } else { - actor.(weaponentity).hook_state |= HOOK_REMOVING; - actor.(weaponentity).hook_state &= ~HOOK_WAITING_FOR_RELEASE; - } - - if(fire & 2) - { - if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hook, refire))) - { - W_Hook_Attack2(thiswep, actor, weaponentity); - weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready); - } - } - - if(actor.(weaponentity).hook) - { - // if hooked, no bombs, and increase the timer - actor.(weaponentity).hook_refire = max(actor.(weaponentity).hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor(actor)); - - // hook also inhibits health regeneration, but only for 1 second - if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) - actor.pauseregen_finished = max(actor.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen); - } - - if(actor.(weaponentity).hook && actor.(weaponentity).hook.state == 1) - { - float hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max); - if(hooked_time_max > 0) - { - if( time > actor.(weaponentity).hook_time_hooked + hooked_time_max ) - actor.(weaponentity).hook_state |= HOOK_REMOVING; - } - - float hooked_fuel = thiswep.ammo_factor * WEP_CVAR_PRI(hook, hooked_ammo); - if(hooked_fuel > 0) - { - if( time > actor.(weaponentity).hook_time_fueldecrease ) - { - if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) - { - if( actor.ammo_fuel >= (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel ) - { - W_DecreaseAmmo(thiswep, actor, (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel, weaponentity); - actor.(weaponentity).hook_time_fueldecrease = time; - // decrease next frame again - } - else - { - actor.ammo_fuel = 0; - actor.(weaponentity).hook_state |= HOOK_REMOVING; - if(actor.(weaponentity).m_weapon != WEP_Null) // offhand - W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity); - } - } - } - } - } - else - { - actor.(weaponentity).hook_time_hooked = time; - actor.(weaponentity).hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free); - } - - actor.(weaponentity).hook_state = BITSET(actor.(weaponentity).hook_state, HOOK_PULLING, (!PHYS_INPUT_BUTTON_CROUCH(actor) || !autocvar_g_balance_grapplehook_crouchslide)); - - if (actor.(weaponentity).hook_state & HOOK_FIRING) - { - if (actor.(weaponentity).hook) - RemoveHook(actor.(weaponentity).hook); - FireGrapplingHook(actor, weaponentity); - actor.(weaponentity).hook_state &= ~HOOK_FIRING; - actor.(weaponentity).hook_refire = max(actor.(weaponentity).hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor(actor)); - } - else if (actor.(weaponentity).hook_state & HOOK_REMOVING) - { - if (actor.(weaponentity).hook) - RemoveHook(actor.(weaponentity).hook); - actor.(weaponentity).hook_state &= ~HOOK_REMOVING; - } + if (fire & 1) { + if (!actor.(weaponentity).hook) { + if (!(actor.(weaponentity).hook_state & HOOK_WAITING_FOR_RELEASE)) { + if (time > actor.(weaponentity).hook_refire) { + if (weapon_prepareattack(thiswep, actor, weaponentity, false, -1)) { + W_DecreaseAmmo(thiswep, actor, thiswep.ammo_factor * WEP_CVAR_PRI(hook, ammo), weaponentity); + actor.(weaponentity).hook_state |= HOOK_FIRING; + actor.(weaponentity).hook_state |= HOOK_WAITING_FOR_RELEASE; + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hook, animtime), w_ready); + } + } + } + } + } else { + actor.(weaponentity).hook_state |= HOOK_REMOVING; + actor.(weaponentity).hook_state &= ~HOOK_WAITING_FOR_RELEASE; + } + + if (fire & 2) { + if (weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hook, refire))) { + W_Hook_Attack2(thiswep, actor, weaponentity); + weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hook, animtime), w_ready); + } + } + + if (actor.(weaponentity).hook) { + // if hooked, no bombs, and increase the timer + actor.(weaponentity).hook_refire = max(actor.(weaponentity).hook_refire, time + WEP_CVAR_PRI(hook, refire) * W_WeaponRateFactor(actor)); + + // hook also inhibits health regeneration, but only for 1 second + if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { + actor.pauseregen_finished = max(actor.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen); + } + } + + if (actor.(weaponentity).hook && actor.(weaponentity).hook.state == 1) { + float hooked_time_max = WEP_CVAR_PRI(hook, hooked_time_max); + if (hooked_time_max > 0) { + if (time > actor.(weaponentity).hook_time_hooked + hooked_time_max) { + actor.(weaponentity).hook_state |= HOOK_REMOVING; + } + } + + float hooked_fuel = thiswep.ammo_factor * WEP_CVAR_PRI(hook, hooked_ammo); + if (hooked_fuel > 0) { + if (time > actor.(weaponentity).hook_time_fueldecrease) { + if (!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { + if (actor.ammo_fuel >= (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel) { + W_DecreaseAmmo(thiswep, actor, (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel, weaponentity); + actor.(weaponentity).hook_time_fueldecrease = time; + // decrease next frame again + } else { + actor.ammo_fuel = 0; + actor.(weaponentity).hook_state |= HOOK_REMOVING; + if (actor.(weaponentity).m_weapon != WEP_Null) { // offhand + W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity); + } + } + } + } + } + } else { + actor.(weaponentity).hook_time_hooked = time; + actor.(weaponentity).hook_time_fueldecrease = time + WEP_CVAR_PRI(hook, hooked_time_free); + } + + actor.(weaponentity).hook_state = BITSET(actor.(weaponentity).hook_state, HOOK_PULLING, (!PHYS_INPUT_BUTTON_CROUCH(actor) || !autocvar_g_balance_grapplehook_crouchslide)); + + if (actor.(weaponentity).hook_state & HOOK_FIRING) { + if (actor.(weaponentity).hook) { + RemoveHook(actor.(weaponentity).hook); + } + FireGrapplingHook(actor, weaponentity); + actor.(weaponentity).hook_state &= ~HOOK_FIRING; + actor.(weaponentity).hook_refire = max(actor.(weaponentity).hook_refire, time + autocvar_g_balance_grapplehook_refire * W_WeaponRateFactor(actor)); + } else if (actor.(weaponentity).hook_state & HOOK_REMOVING) { + if (actor.(weaponentity).hook) { + RemoveHook(actor.(weaponentity).hook); + } + actor.(weaponentity).hook_state &= ~HOOK_REMOVING; + } } METHOD(Hook, wr_setup, void(entity thiswep, entity actor, .entity weaponentity)) { @@ -212,31 +210,31 @@ METHOD(Hook, wr_setup, void(entity thiswep, entity actor, .entity weaponentity)) } METHOD(Hook, wr_checkammo1, bool(Hook thiswep, entity actor, .entity weaponentity)) { - if (!thiswep.ammo_factor) return true; + if (!thiswep.ammo_factor) { return true; } - if(actor.(weaponentity).hook) - return actor.ammo_fuel > 0; + if (actor.(weaponentity).hook) { + return actor.ammo_fuel > 0; + } - return actor.ammo_fuel >= WEP_CVAR_PRI(hook, ammo); + return actor.ammo_fuel >= WEP_CVAR_PRI(hook, ammo); } METHOD(Hook, wr_checkammo2, bool(Hook thiswep, entity actor, .entity weaponentity)) { - // infinite ammo for now - return true; // actor.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above + // infinite ammo for now + return true; // actor.ammo_cells >= WEP_CVAR_SEC(hook, ammo); // WEAPONTODO: see above } METHOD(Hook, wr_resetplayer, void(entity thiswep, entity actor)) { - RemoveGrapplingHooks(actor); - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { - .entity weaponentity = weaponentities[slot]; - actor.(weaponentity).hook_time = 0; - actor.(weaponentity).hook_refire = time; - } + RemoveGrapplingHooks(actor); + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { + .entity weaponentity = weaponentities[slot]; + actor.(weaponentity).hook_time = 0; + actor.(weaponentity).hook_refire = time; + } } METHOD(Hook, wr_killmessage, Notification(entity thiswep)) { - return WEAPON_HOOK_MURDER; + return WEAPON_HOOK_MURDER; } #endif @@ -244,11 +242,12 @@ METHOD(Hook, wr_killmessage, Notification(entity thiswep)) METHOD(Hook, wr_impacteffect, void(entity thiswep, entity actor)) { - vector org2; - org2 = w_org + w_backoff * 2; - pointparticles(EFFECT_HOOK_EXPLODE, org2, '0 0 0', 1); - if(!w_issilent) - sound(actor, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM); + vector org2; + org2 = w_org + w_backoff * 2; + pointparticles(EFFECT_HOOK_EXPLODE, org2, '0 0 0', 1); + if (!w_issilent) { + sound(actor, CH_SHOTS, SND_HOOKBOMB_IMPACT, VOL_BASE, ATTN_NORM); + } } #endif @@ -262,11 +261,11 @@ float autocvar_cl_grapplehook_alpha = 1; void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg); entityclass(Hook); -class(Hook) .entity HookType; // ENT_CLIENT_* -class(Hook) .vector origin; -class(Hook) .vector velocity; -class(Hook) .float HookSilent; -class(Hook) .float HookRange; +class(Hook).entity HookType; // ENT_CLIENT_* +class(Hook).vector origin; +class(Hook).vector velocity; +class(Hook).float HookSilent; +class(Hook).float HookRange; string Draw_GrapplingHook_trace_callback_tex; float Draw_GrapplingHook_trace_callback_rnd; @@ -277,12 +276,13 @@ void Draw_GrapplingHook_trace_callback(vector start, vector hit, vector end) float i; vector vorg; vorg = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin); - for(i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i) + for (i = 0; i < Draw_GrapplingHook_trace_callback_a; ++i) { Draw_CylindricLine(hit, start, 8, Draw_GrapplingHook_trace_callback_tex, 0.25, Draw_GrapplingHook_trace_callback_rnd, Draw_GrapplingHook_trace_callback_rgb, min(1, Draw_GrapplingHook_trace_callback_a - i), DRAWFLAG_NORMAL, vorg); + } Draw_GrapplingHook_trace_callback_rnd += 0.25 * vlen(hit - start) / 8; } -class(Hook) .float teleport_time; +class(Hook).float teleport_time; void Draw_GrapplingHook(entity this) { vector a, b, atrans; @@ -292,19 +292,18 @@ void Draw_GrapplingHook(entity this) vector vs; float intensity, offset; - if(this.teleport_time) - if(time > this.teleport_time) - { - sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); // safeguard - this.teleport_time = 0; + if (this.teleport_time) { + if (time > this.teleport_time) { + sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); // safeguard + this.teleport_time = 0; + } } InterpolateOrigin_Do(this); int s = W_GunAlign(viewmodels[this.cnt], STAT(GUNALIGN)) - 1; - switch(this.HookType) - { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: vs = hook_shotorigin[s]; @@ -314,33 +313,30 @@ void Draw_GrapplingHook(entity this) break; } - if((this.owner.sv_entnum == player_localentnum - 1)) - { - switch(this.HookType) - { + if ((this.owner.sv_entnum == player_localentnum - 1)) { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: - if(autocvar_chase_active > 0) + if (autocvar_chase_active > 0) { a = csqcplayer.origin; - else + } else { a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z; + } b = this.origin; break; case NET_ENT_CLIENT_ARC_BEAM: - if(this.HookRange) + if (this.HookRange) { b = view_origin + view_forward * this.HookRange; - else + } else { b = view_origin + view_forward * vlen(this.velocity - this.origin); // honor original length of beam! + } WarpZone_TraceLine(view_origin, b, MOVE_NORMAL, NULL); b = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos); a = view_origin + view_forward * vs.x + view_right * -vs.y + view_up * vs.z; break; } - } - else - { - switch(this.HookType) - { + } else { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: a = this.velocity; @@ -355,19 +351,27 @@ void Draw_GrapplingHook(entity this) t = entcs_GetTeamColor(this.owner.sv_entnum); - switch(this.HookType) - { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: intensity = autocvar_cl_grapplehook_alpha; offset = 0; - switch(t) - { - case NUM_TEAM_1: tex = "particles/hook_red"; rgb = '1 0.3 0.3'; break; - case NUM_TEAM_2: tex = "particles/hook_blue"; rgb = '0.3 0.3 1'; break; - case NUM_TEAM_3: tex = "particles/hook_yellow"; rgb = '1 1 0.3'; break; - case NUM_TEAM_4: tex = "particles/hook_pink"; rgb = '1 0.3 1'; break; - default: tex = "particles/hook_white"; rgb = entcs_GetColor(this.sv_entnum - 1); break; + switch (t) { + case NUM_TEAM_1: tex = "particles/hook_red"; + rgb = '1 0.3 0.3'; + break; + case NUM_TEAM_2: tex = "particles/hook_blue"; + rgb = '0.3 0.3 1'; + break; + case NUM_TEAM_3: tex = "particles/hook_yellow"; + rgb = '1 1 0.3'; + break; + case NUM_TEAM_4: tex = "particles/hook_pink"; + rgb = '1 0.3 1'; + break; + default: tex = "particles/hook_white"; + rgb = entcs_GetColor(this.sv_entnum - 1); + break; } break; case NET_ENT_CLIENT_ARC_BEAM: // todo @@ -391,18 +395,14 @@ void Draw_GrapplingHook(entity this) atrans = WarpZone_TransformOrigin(WarpZone_trace_transform, a); - switch(this.HookType) - { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: - if(vdist(trace_endpos - atrans, >, 0.5)) - { + if (vdist(trace_endpos - atrans, >, 0.5)) { setorigin(this, trace_endpos); // hook endpoint! this.angles = vectoangles(trace_endpos - atrans); this.drawmask = MASK_NORMAL; - } - else - { + } else { this.drawmask = 0; } break; @@ -411,8 +411,7 @@ void Draw_GrapplingHook(entity this) break; } - switch(this.HookType) - { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: break; @@ -424,13 +423,13 @@ void Draw_GrapplingHook(entity this) void Remove_GrapplingHook(entity this) { - sound (this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); + sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM); - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { entity wep = viewmodels[slot]; - if(wep.hook == this) + if (wep.hook == this) { wep.hook = NULL; + } } } @@ -445,17 +444,16 @@ NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew) InterpolateOrigin_Undo(this); - if(sf & 1) - { + if (sf & 1) { int myowner = ReadByte(); int slot = ReadByte(); this.owner = playerslots[myowner - 1]; this.sv_entnum = myowner; - if(myowner == player_localentnum) + if (myowner == player_localentnum) { viewmodels[slot].hook = this; + } this.cnt = slot; - switch(this.HookType) - { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: this.HookRange = 0; @@ -465,15 +463,13 @@ NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew) break; } } - if(sf & 2) - { + if (sf & 2) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); setorigin(this, this.origin); } - if(sf & 4) - { + if (sf & 4) { this.velocity_x = ReadCoord(); this.velocity_y = ReadCoord(); this.velocity_z = ReadCoord(); @@ -481,14 +477,12 @@ NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew) InterpolateOrigin_Note(this); - if(bIsNew || !this.teleport_time) - { + if (bIsNew || !this.teleport_time) { this.draw = Draw_GrapplingHook; IL_PUSH(g_drawables, this); this.entremove = Remove_GrapplingHook; - switch(this.HookType) - { + switch (this.HookType) { default: case NET_ENT_CLIENT_HOOK: // for the model @@ -496,7 +490,7 @@ NET_HANDLE(ENT_CLIENT_HOOK, bool bIsNew) this.drawmask = MASK_NORMAL; break; case NET_ENT_CLIENT_ARC_BEAM: - sound (this, CH_SHOTS_SINGLE, SND_LGBEAM_FLY, VOL_BASE, ATTEN_NORM); + sound(this, CH_SHOTS_SINGLE, SND_LGBEAM_FLY, VOL_BASE, ATTEN_NORM); break; } } diff --git a/qcsrc/common/weapons/weapon/shockwave.qc b/qcsrc/common/weapons/weapon/shockwave.qc index bc9e94767..8b5347187 100644 --- a/qcsrc/common/weapons/weapon/shockwave.qc +++ b/qcsrc/common/weapons/weapon/shockwave.qc @@ -5,18 +5,18 @@ REGISTER_NET_TEMP(TE_CSQC_SHOCKWAVEPARTICLE) #ifdef SVQC spawnfunc(weapon_shockwave) { - //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO - if(autocvar_sv_q3acompat_machineshotgunswap) - if(this.classname != "droppedweapon") - { - weapon_defaultspawnfunc(this, WEP_MACHINEGUN); - return; + // if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO + if (autocvar_sv_q3acompat_machineshotgunswap) { + if (this.classname != "droppedweapon") { + weapon_defaultspawnfunc(this, WEP_MACHINEGUN); + return; + } } weapon_defaultspawnfunc(this, WEP_SHOCKWAVE); } const float MAX_SHOCKWAVE_HITS = 10; -//#define DEBUG_SHOCKWAVE +// #define DEBUG_SHOCKWAVE .float swing_prev; .entity swing_alreadyhit; @@ -34,15 +34,13 @@ void W_Shockwave_Melee_Think(entity this) vector targpos; // check to see if we can still continue, otherwise give up now - if(IS_DEAD(this.realowner) && WEP_CVAR(shockwave, melee_no_doubleslap)) - { + if (IS_DEAD(this.realowner) && WEP_CVAR(shockwave, melee_no_doubleslap)) { delete(this); return; } // set start time of melee - if(!this.cnt) - { + if (!this.cnt) { this.cnt = time; W_PlayStrengthSound(this.realowner); } @@ -56,8 +54,7 @@ void W_Shockwave_Melee_Think(entity this) f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces)); // perform the traces needed for this frame - for(i=this.swing_prev; i < f; ++i) - { + for (i = this.swing_prev; i < f; ++i) { swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1); targpos = (this.realowner.origin + this.realowner.view_ofs @@ -82,17 +79,17 @@ void W_Shockwave_Melee_Think(entity this) is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent)); - if((trace_fraction < 1) // if trace is good, apply the damage and remove this if necessary + if ((trace_fraction < 1) // if trace is good, apply the damage and remove this if necessary && (trace_ent.takedamage == DAMAGE_AIM) && (trace_ent != this.swing_alreadyhit) - && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage))) - { + && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage))) { target_victim = trace_ent; // so it persists through other calls - if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught + if (is_player) { // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1)); - else + } else { swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1)); + } // trigger damage with this calculated info Damage( @@ -106,8 +103,8 @@ void W_Shockwave_Melee_Think(entity this) ); // handle accuracy - if(accuracy_isgooddamage(this.realowner, target_victim)) - { accuracy_add(this.realowner, WEP_SHOCKWAVE.m_id, 0, swing_damage); } + if (accuracy_isgooddamage(this.realowner, target_victim)) + { accuracy_add(this.realowner, WEP_SHOCKWAVE.m_id, 0, swing_damage); } #ifdef DEBUG_SHOCKWAVE LOG_INFOF( @@ -121,27 +118,21 @@ void W_Shockwave_Melee_Think(entity this) #endif // allow multiple hits with one swing, but not against the same player twice - if(WEP_CVAR(shockwave, melee_multihit)) - { + if (WEP_CVAR(shockwave, melee_multihit)) { this.swing_alreadyhit = target_victim; continue; // move along to next trace - } - else - { + } else { delete(this); return; } } } - if(time >= this.cnt + meleetime) - { + if (time >= this.cnt + meleetime) { // melee is finished delete(this); return; - } - else - { + } else { // set up next frame this.swing_prev = i; this.nextthink = time; @@ -161,11 +152,7 @@ void W_Shockwave_Melee(Weapon thiswep, entity actor, .entity weaponentity, int f } // SHOCKWAVE ATTACK MODE -float W_Shockwave_Attack_CheckSpread( - vector targetorg, - vector nearest_on_line, - vector sw_shotorg, - vector attack_endpos) +float W_Shockwave_Attack_CheckSpread(vector targetorg, vector nearest_on_line, vector sw_shotorg, vector attack_endpos) { float spreadlimit; float distance_of_attack = vlen(sw_shotorg - attack_endpos); @@ -174,27 +161,21 @@ float W_Shockwave_Attack_CheckSpread( spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1); spreadlimit = ( - (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit)) - + - (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit) + (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit)) + + + (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit) ); - if( + if ( (spreadlimit && (distance_from_line <= spreadlimit)) && ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90) ) - { return bound(0, (distance_from_line / spreadlimit), 1); } - else - { return false; } + { return bound(0, (distance_from_line / spreadlimit), 1); } else + { return false; } } -float W_Shockwave_Attack_IsVisible( - entity actor, - entity head, - vector nearest_on_line, - vector sw_shotorg, - vector attack_endpos) +float W_Shockwave_Attack_IsVisible(entity actor, entity head, vector nearest_on_line, vector sw_shotorg, vector attack_endpos) { vector nearest_to_attacker = head.WarpZone_findradius_nearest; vector center = (head.origin + (head.mins + head.maxs) * 0.5); @@ -202,48 +183,38 @@ float W_Shockwave_Attack_IsVisible( float i; // STEP ONE: Check if the nearest point is clear - if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos)) - { + if (W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos)) { WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, actor); - if(trace_fraction == 1) { return true; } // yes, the nearest point is clear and we can allow the damage + if (trace_fraction == 1) { return true; } // yes, the nearest point is clear and we can allow the damage } // STEP TWO: Check if shotorg to center point is clear - if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos)) - { + if (W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos)) { WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, actor); - if(trace_fraction == 1) { return true; } // yes, the center point is clear and we can allow the damage + if (trace_fraction == 1) { return true; } // yes, the center point is clear and we can allow the damage } // STEP THREE: Check each corner to see if they are clear - for(i=1; i<=8; ++i) - { + for (i = 1; i <= 8; ++i) { corner = get_corner_position(head, i); - if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos)) - { + if (W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos)) { WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, actor); - if(trace_fraction == 1) { return true; } // yes, this corner is clear and we can allow the damage + if (trace_fraction == 1) { return true; } // yes, this corner is clear and we can allow the damage } } return false; } -float W_Shockwave_Attack_CheckHit( - float queue, - entity head, - vector final_force, - float final_damage) +float W_Shockwave_Attack_CheckHit(float queue, entity head, vector final_force, float final_damage) { - if(!head) { return false; } + if (!head) { return false; } float i; - for(i = 0; i <= queue; ++i) - { - if(shockwave_hit[i] == head) - { - if(vlen2(final_force) > vlen2(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; } - if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; } + for (i = 0; i <= queue; ++i) { + if (shockwave_hit[i] == head) { + if (vlen2(final_force) > vlen2(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; } + if (final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; } return false; } } @@ -286,7 +257,7 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) vector attack_hitpos = trace_endpos; float distance_to_end = vlen(w_shotorg - attack_endpos); float distance_to_hit = vlen(w_shotorg - attack_hitpos); - //entity transform = WarpZone_trace_transform; + // entity transform = WarpZone_trace_transform; // do the firing effect now W_Shockwave_Send(actor); @@ -305,20 +276,21 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) head = WarpZone_FindRadius( attack_hitpos, max( - WEP_CVAR(shockwave, blast_splash_radius), - WEP_CVAR(shockwave, blast_jump_radius) + WEP_CVAR(shockwave, blast_splash_radius), + WEP_CVAR(shockwave, blast_jump_radius) ), false - ); + ); float lag = ((IS_REAL_CLIENT(actor)) ? ANTILAG_LATENCY(actor) : 0); bool noantilag = ((IS_CLIENT(actor)) ? CS(actor).cvar_cl_noantilag : false); - if(lag < 0.001) + if (lag < 0.001) { lag = 0; - if(autocvar_g_antilag == 0 || noantilag) + } + if (autocvar_g_antilag == 0 || noantilag) { lag = 0; // only do hitscan, but no antilag - if(lag) - { + } + if (lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_takeback(it, CS(it), time - lag)); IL_EACH(g_monsters, it != actor, { @@ -326,58 +298,55 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) }); } - while(head) - { - if(head.takedamage) - { + while (head) { + if (head.takedamage) { float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest); - if((head == actor) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius))) - { + if ((head == actor) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius))) { // ======================== // BLAST JUMP CALCULATION // ======================== // calculate importance of distance and accuracy for this attack - multiplier_from_accuracy = (1 - - (distance_to_head ? - min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius))) - : - 0 + multiplier_from_accuracy = (1 + - (distance_to_head + ? min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius))) + : + 0 ) - ); - multiplier_from_distance = (1 - - (distance_to_hit ? - min(1, (distance_to_hit / distance_to_end)) - : - 0 + ); + multiplier_from_distance = (1 + - (distance_to_hit + ? min(1, (distance_to_hit / distance_to_end)) + : + 0 ) - ); + ); multiplier = max( - WEP_CVAR(shockwave, blast_jump_multiplier_min), - ( - (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy)) - + - (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance)) - ) + WEP_CVAR(shockwave, blast_jump_multiplier_min), + ( + (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy)) + + + (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance)) + ) ); // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage final_damage = ( - (WEP_CVAR(shockwave, blast_jump_damage) * multiplier) - + - (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier)) + (WEP_CVAR(shockwave, blast_jump_damage) * multiplier) + + + (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier)) ); // figure out the direction of force vel = normalize(vec2(head.velocity)); vel *= ( - bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1) - * - WEP_CVAR(shockwave, blast_jump_force_velocitybias) + bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1) + * + WEP_CVAR(shockwave, blast_jump_force_velocitybias) ); final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel); @@ -407,57 +376,55 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) multiplier_from_distance ); #endif - } - else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius)) - { + } else if (distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius)) { // ========================== // BLAST SPLASH CALCULATION // ========================== // calculate importance of distance and accuracy for this attack - multiplier_from_accuracy = (1 - - (distance_to_head ? - min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius))) - : - 0 + multiplier_from_accuracy = (1 + - (distance_to_head + ? min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius))) + : + 0 ) - ); - multiplier_from_distance = (1 - - (distance_to_hit ? - min(1, (distance_to_hit / distance_to_end)) - : - 0 + ); + multiplier_from_distance = (1 + - (distance_to_hit + ? min(1, (distance_to_hit / distance_to_end)) + : + 0 ) - ); + ); multiplier = max( - WEP_CVAR(shockwave, blast_splash_multiplier_min), - ( - (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy)) - + - (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance)) - ) + WEP_CVAR(shockwave, blast_splash_multiplier_min), + ( + (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy)) + + + (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance)) + ) ); // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage final_damage = ( - (WEP_CVAR(shockwave, blast_splash_damage) * multiplier) - + - (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier)) + (WEP_CVAR(shockwave, blast_splash_damage) * multiplier) + + + (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier)) ); // figure out the direction of force final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias)); final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force)); - //te_lightning2(NULL, attack_hitpos, (attack_hitpos + (final_force * 200))); + // te_lightning2(NULL, attack_hitpos, (attack_hitpos + (final_force * 200))); // now multiply the direction by force units final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier); final_force.z *= WEP_CVAR(shockwave, blast_force_zscale); // queue damage with this calculated info - if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); } + if (W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); } #ifdef DEBUG_SHOCKWAVE LOG_INFOF( @@ -477,10 +444,8 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) // cone damage trace head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), false); - while(head) - { - if((head != actor) && head.takedamage) - { + while (head) { + if ((head != actor) && head.takedamage) { // ======================== // BLAST CONE CALCULATION // ======================== @@ -499,54 +464,53 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) vector nearest_on_line = (w_shotorg + a * w_shotdir); vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line); - if((vdist(head.WarpZone_findradius_dist, <=, WEP_CVAR(shockwave, blast_distance))) - && (W_Shockwave_Attack_IsVisible(actor, head, nearest_on_line, w_shotorg, attack_endpos))) - { + if ((vdist(head.WarpZone_findradius_dist, <=, WEP_CVAR(shockwave, blast_distance))) + && (W_Shockwave_Attack_IsVisible(actor, head, nearest_on_line, w_shotorg, attack_endpos))) { // calculate importance of distance and accuracy for this attack - multiplier_from_accuracy = (1 - - W_Shockwave_Attack_CheckSpread( - nearest_to_attacker, - nearest_on_line, - w_shotorg, - attack_endpos + multiplier_from_accuracy = (1 + - W_Shockwave_Attack_CheckSpread( + nearest_to_attacker, + nearest_on_line, + w_shotorg, + attack_endpos ) - ); - multiplier_from_distance = (1 - - (distance_to_hit ? - min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end)) - : - 0 + ); + multiplier_from_distance = (1 + - (distance_to_hit + ? min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end)) + : + 0 ) - ); + ); multiplier = max( - WEP_CVAR(shockwave, blast_multiplier_min), - ( - (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy)) - + - (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance)) - ) + WEP_CVAR(shockwave, blast_multiplier_min), + ( + (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy)) + + + (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance)) + ) ); // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage final_damage = ( - (WEP_CVAR(shockwave, blast_damage) * multiplier) - + - (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier)) + (WEP_CVAR(shockwave, blast_damage) * multiplier) + + + (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier)) ); // figure out the direction of force final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias)); final_force = normalize(center - (nearest_on_line - final_force)); - //te_lightning2(NULL, nearest_on_line, (attack_hitpos + (final_force * 200))); + // te_lightning2(NULL, nearest_on_line, (attack_hitpos + (final_force * 200))); // now multiply the direction by force units final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier); final_force.z *= WEP_CVAR(shockwave, blast_force_zscale); // queue damage with this calculated info - if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); } + if (W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); } #ifdef DEBUG_SHOCKWAVE LOG_INFOF( @@ -564,11 +528,10 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) head = head.chain; } - for(i = 1; i <= queue; ++i) - { - head = shockwave_hit[i-1]; - final_force = shockwave_hit_force[i-1]; - final_damage = shockwave_hit_damage[i-1]; + for (i = 1; i <= queue; ++i) { + head = shockwave_hit[i - 1]; + final_force = shockwave_hit_force[i - 1]; + final_damage = shockwave_hit_damage[i - 1]; Damage( head, @@ -580,8 +543,9 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) final_force ); - if(accuracy_isgooddamage(actor, head)) + if (accuracy_isgooddamage(actor, head)) { accuracy_add(actor, WEP_SHOCKWAVE.m_id, 0, final_damage); + } #ifdef DEBUG_SHOCKWAVE LOG_INFOF( @@ -592,13 +556,12 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) ); #endif - shockwave_hit[i-1] = NULL; - shockwave_hit_force[i-1] = '0 0 0'; - shockwave_hit_damage[i-1] = 0; + shockwave_hit[i - 1] = NULL; + shockwave_hit_force[i - 1] = '0 0 0'; + shockwave_hit_damage[i - 1] = 0; } - if(lag) - { + if (lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_restore(it, CS(it))); IL_EACH(g_monsters, it != actor, { @@ -609,54 +572,48 @@ void W_Shockwave_Attack(entity actor, .entity weaponentity) METHOD(Shockwave, wr_aim, void(entity thiswep, entity actor, .entity weaponentity)) { - if(vdist(actor.origin - actor.enemy.origin, <=, WEP_CVAR(shockwave, melee_range))) - { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false); } - else - { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false); } + if (vdist(actor.origin - actor.enemy.origin, <=, WEP_CVAR(shockwave, melee_range))) + { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false); } else + { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false); } } METHOD(Shockwave, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - if(fire & 1) - { - if(time >= actor.(weaponentity).shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary - { - if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(shockwave, blast_animtime))) - { - W_Shockwave_Attack(actor, weaponentity); - actor.(weaponentity).shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor(actor); - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready); - } - } - } - else if(fire & 2) - { - //if(actor.clip_load >= 0) // we are not currently reloading - if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR(shockwave, melee_refire))) - { - // attempt forcing playback of the anim by switching to another anim (that we never play) here... - weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shockwave_Melee); - } - } + if (fire & 1) { + if (time >= actor.(weaponentity).shockwave_blasttime) { // handle refire separately so the secondary can be fired straight after a primary + if (weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(shockwave, blast_animtime))) { + W_Shockwave_Attack(actor, weaponentity); + actor.(weaponentity).shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor(actor); + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready); + } + } + } else if (fire & 2) { + // if(actor.clip_load >= 0) // we are not currently reloading + if (weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR(shockwave, melee_refire))) { + // attempt forcing playback of the anim by switching to another anim (that we never play) here... + weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shockwave_Melee); + } + } } METHOD(Shockwave, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity)) { - return true; // infinite ammo + return true; // infinite ammo } METHOD(Shockwave, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity)) { - // shockwave has infinite ammo - return true; + // shockwave has infinite ammo + return true; } METHOD(Shockwave, wr_suicidemessage, Notification(entity thiswep)) { - return WEAPON_THINKING_WITH_PORTALS; + return WEAPON_THINKING_WITH_PORTALS; } METHOD(Shockwave, wr_killmessage, Notification(entity thiswep)) { - if(w_deathtype & HITTYPE_SECONDARY) - return WEAPON_SHOCKWAVE_MURDER_SLAP; - else - return WEAPON_SHOCKWAVE_MURDER; + if (w_deathtype & HITTYPE_SECONDARY) { + return WEAPON_SHOCKWAVE_MURDER_SLAP; + } else { + return WEAPON_SHOCKWAVE_MURDER; + } } #endif @@ -669,7 +626,7 @@ void Draw_Shockwave(entity this) { // fading/removal control float a = bound(0, (SW_MAXALPHA - ((time - this.sw_time) / SW_FADETIME)), SW_MAXALPHA); - if(a < ALPHA_MIN_VISIBLE) { delete(this); } + if (a < ALPHA_MIN_VISIBLE) { delete(this); } // WEAPONTODO: save this only once when creating the entity vector sw_color = entcs_GetColor(this.sv_entnum - 1); // GetTeamRGB(entcs_GetTeam(this.sv_entnum)); @@ -679,7 +636,7 @@ void Draw_Shockwave(entity this) vectorvectors(this.sw_shotdir); vector right = v_right; // save this for when we do makevectors later - vector up = v_up; // save this for when we do makevectors later + vector up = v_up; // save this for when we do makevectors later // WEAPONTODO: combine and simplify these calculations vector min_end = ((this.sw_shotorg + (this.sw_shotdir * SW_DISTTOMIN)) + (up * this.sw_spread_min)); @@ -693,8 +650,7 @@ void Draw_Shockwave(entity this) vector deviation, angle = '0 0 0'; float counter, divisions = 20; - for(counter = 0; counter < divisions; ++counter) - { + for (counter = 0; counter < divisions; ++counter) { // perfect circle effect lines makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions)); angle.y = v_forward.x; @@ -705,24 +661,22 @@ void Draw_Shockwave(entity this) deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z))); new_min_dist = SW_DISTTOMIN; new_min_end = (this.sw_shotorg + (deviation * new_min_dist)); - //te_lightning2(NULL, new_min_end, this.sw_shotorg); + // te_lightning2(NULL, new_min_end, this.sw_shotorg); // then calculate spread_to_max effect deviation = angle * spread_to_max; deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z))); new_max_dist = vlen(new_min_end - endpos); new_max_end = (new_min_end + (deviation * new_max_dist)); - //te_lightning2(NULL, new_end, prev_min_end); + // te_lightning2(NULL, new_end, prev_min_end); - if(counter == 0) - { + if (counter == 0) { first_min_end = new_min_end; first_max_end = new_max_end; } - if(counter >= 1) - { + if (counter >= 1) { // draw from shot origin to min spread radius R_BeginPolygon("", DRAWFLAG_NORMAL); R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a); @@ -743,8 +697,7 @@ void Draw_Shockwave(entity this) prev_max_end = new_max_end; // last division only - if((counter + 1) == divisions) - { + if ((counter + 1) == divisions) { // draw from shot origin to min spread radius R_BeginPolygon("", DRAWFLAG_NORMAL); R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a); @@ -776,8 +729,12 @@ void Net_ReadShockwaveParticle() shockwave.draw = Draw_Shockwave; IL_PUSH(g_drawables, shockwave); - shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord(); - shockwave.sw_shotdir_x = ReadCoord(); shockwave.sw_shotdir_y = ReadCoord(); shockwave.sw_shotdir_z = ReadCoord(); + shockwave.sw_shotorg_x = ReadCoord(); + shockwave.sw_shotorg_y = ReadCoord(); + shockwave.sw_shotorg_z = ReadCoord(); + shockwave.sw_shotdir_x = ReadCoord(); + shockwave.sw_shotdir_y = ReadCoord(); + shockwave.sw_shotdir_z = ReadCoord(); shockwave.sw_distance = ReadShort(); shockwave.sw_spread_max = ReadByte(); @@ -790,10 +747,10 @@ void Net_ReadShockwaveParticle() METHOD(Shockwave, wr_impacteffect, void(entity thiswep, entity actor)) { - // handled by Net_ReadShockwaveParticle - //vector org2; - //org2 = w_org + w_backoff * 2; - //pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1); + // handled by Net_ReadShockwaveParticle + // vector org2; + // org2 = w_org + w_backoff * 2; + // pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1); } #endif diff --git a/qcsrc/common/weapons/weapon/tuba.qh b/qcsrc/common/weapons/weapon/tuba.qh index 714a2b8b5..e4188bb00 100644 --- a/qcsrc/common/weapons/weapon/tuba.qh +++ b/qcsrc/common/weapons/weapon/tuba.qh @@ -10,7 +10,7 @@ CLASS(Tuba, Weapon) /* model */ ATTRIB(Tuba, m_model, Model, MDL_TUBA_ITEM); #endif /* crosshair */ ATTRIB(Tuba, w_crosshair, string, "gfx/crosshairtuba"); -/* crosshair */ //ATTRIB(Tuba, w_crosshair_size, float, 0.65); +/* crosshair */ // ATTRIB(Tuba, w_crosshair_size, float, 0.65); /* wepimg */ ATTRIB(Tuba, model2, string, "weapontuba"); /* refname */ ATTRIB(Tuba, netname, string, "tuba"); /* xgettext:no-c-format */ @@ -18,33 +18,33 @@ CLASS(Tuba, Weapon) #define X(BEGIN, P, END, class, prefix) \ BEGIN(class) \ - P(class, prefix, animtime, float, NONE) \ - P(class, prefix, attenuation, float, NONE) \ - P(class, prefix, damage, float, NONE) \ - P(class, prefix, edgedamage, float, NONE) \ - P(class, prefix, fadetime, float, NONE) \ - P(class, prefix, force, float, NONE) \ - P(class, prefix, pitchstep, float, NONE) \ - P(class, prefix, radius, float, NONE) \ - P(class, prefix, refire, float, NONE) \ - P(class, prefix, switchdelay_drop, float, NONE) \ - P(class, prefix, switchdelay_raise, float, NONE) \ - P(class, prefix, volume, float, NONE) \ - P(class, prefix, weaponreplace, string, NONE) \ - P(class, prefix, weaponstartoverride, float, NONE) \ - P(class, prefix, weaponstart, float, NONE) \ - P(class, prefix, weaponthrowable, float, NONE) \ + P(class, prefix, animtime, float, NONE) \ + P(class, prefix, attenuation, float, NONE) \ + P(class, prefix, damage, float, NONE) \ + P(class, prefix, edgedamage, float, NONE) \ + P(class, prefix, fadetime, float, NONE) \ + P(class, prefix, force, float, NONE) \ + P(class, prefix, pitchstep, float, NONE) \ + P(class, prefix, radius, float, NONE) \ + P(class, prefix, refire, float, NONE) \ + P(class, prefix, switchdelay_drop, float, NONE) \ + P(class, prefix, switchdelay_raise, float, NONE) \ + P(class, prefix, volume, float, NONE) \ + P(class, prefix, weaponreplace, string, NONE) \ + P(class, prefix, weaponstartoverride, float, NONE) \ + P(class, prefix, weaponstart, float, NONE) \ + P(class, prefix, weaponthrowable, float, NONE) \ END() - W_PROPS(X, Tuba, tuba) + W_PROPS(X, Tuba, tuba) #undef X ENDCLASS(Tuba) REGISTER_WEAPON(TUBA, tuba, NEW(Tuba)); #ifdef CSQC entityclass(Tuba); -class(Tuba) .int note; -class(Tuba) .bool tuba_attenuate; -class(Tuba) .float tuba_volume; -class(Tuba) .float tuba_volume_initial; -class(Tuba) .int tuba_instrument; +class(Tuba).int note; +class(Tuba).bool tuba_attenuate; +class(Tuba).float tuba_volume; +class(Tuba).float tuba_volume_initial; +class(Tuba).int tuba_instrument; #endif diff --git a/qcsrc/ecs/lib.qh b/qcsrc/ecs/lib.qh index 2d48e577b..04df3d3fd 100644 --- a/qcsrc/ecs/lib.qh +++ b/qcsrc/ecs/lib.qh @@ -12,13 +12,13 @@ #define emit(T, ...) \ MACRO_BEGIN \ - FOREACH_ENTITY_FLOAT_ORDERED(evt_##T##_listener, true, it.evt_##T(__VA_ARGS__)); \ + FOREACH_ENTITY_FLOAT_ORDERED(evt_##T##_listener, true, it.evt_##T(__VA_ARGS__)); \ MACRO_END #define subscribe(listener, T, fn) \ MACRO_BEGIN \ - listener.evt_##T = (fn); \ - listener.evt_##T##_listener = true; \ + listener.evt_##T = (fn); \ + listener.evt_##T##_listener = true; \ MACRO_END @@ -33,25 +33,24 @@ #define SYSTEM_UPDATE(sys) \ MACRO_BEGIN \ - static float t = 0; \ - float dt = autocvar_xon_sys_##sys##_dt; \ - float minfps = autocvar_xon_sys_##sys##_minfps; \ - static float accumulator = 0; \ - float a = 0; \ - if (dt) { \ - accumulator += min(frametime, 1 / (minfps)); \ - } else { \ - accumulator += frametime; \ - dt = accumulator; \ - a = 1; \ - } \ - while (accumulator >= dt) \ - { \ - time = t; \ - FOREACH_COMPONENT(sys, sys_##sys##_update(it, dt)); \ - t += dt; \ - accumulator -= dt; \ - } \ - if (!a) a = accumulator / dt; \ - FOREACH_COMPONENT(sys, com_##sys##_interpolate(it, a)); \ + static float t = 0; \ + float dt = autocvar_xon_sys_##sys##_dt; \ + float minfps = autocvar_xon_sys_##sys##_minfps; \ + static float accumulator = 0; \ + float a = 0; \ + if (dt) { \ + accumulator += min(frametime, 1 / (minfps)); \ + } else { \ + accumulator += frametime; \ + dt = accumulator; \ + a = 1; \ + } \ + while (accumulator >= dt) { \ + time = t; \ + FOREACH_COMPONENT(sys, sys_##sys##_update(it, dt)); \ + t += dt; \ + accumulator -= dt; \ + } \ + if (!a) { a = accumulator / dt; } \ + FOREACH_COMPONENT(sys, com_##sys##_interpolate(it, a)); \ MACRO_END diff --git a/qcsrc/ecs/systems/cl_physics.qc b/qcsrc/ecs/systems/cl_physics.qc index f74e9c2d5..d74b15c9c 100644 --- a/qcsrc/ecs/systems/cl_physics.qc +++ b/qcsrc/ecs/systems/cl_physics.qc @@ -7,8 +7,9 @@ void sys_phys_fix(entity this, float dt) this.movement = PHYS_INPUT_MOVEVALUES(this); this.items = STAT(ITEMS, this); this.spectatorspeed = STAT(SPECTATORSPEED, this); - if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump - UNSET_JUMP_HELD(this); // canjump = true + if (!(PHYS_INPUT_BUTTON_JUMP(this))) { // !jump + UNSET_JUMP_HELD(this); // canjump = true + } PM_ClientMovement_UpdateStatus(this); } diff --git a/qcsrc/ecs/systems/sv_physics.qc b/qcsrc/ecs/systems/sv_physics.qc index c20ae8bda..ea9c69d86 100644 --- a/qcsrc/ecs/systems/sv_physics.qc +++ b/qcsrc/ecs/systems/sv_physics.qc @@ -23,8 +23,8 @@ void sys_phys_monitor(entity this, float dt) anticheat_physics(this); if (sv_maxidle > 0) { if (buttons != CS(this).buttons_old - || CS(this).movement != CS(this).movement_old - || this.v_angle != CS(this).v_angle_old) { CS(this).parm_idlesince = time; } + || CS(this).movement != CS(this).movement_old + || this.v_angle != CS(this).v_angle_old) { CS(this).parm_idlesince = time; } } PM_check_nickspam(this); PM_check_punch(this, dt); @@ -56,26 +56,26 @@ void sys_phys_spectator_control(entity this) float maxspeed_mod = autocvar_sv_spectator_speed_multiplier; if (!this.spectatorspeed) { this.spectatorspeed = maxspeed_mod; } if ((CS(this).impulse >= 1 && CS(this).impulse <= 19) - || (CS(this).impulse >= 200 && CS(this).impulse <= 209) - || (CS(this).impulse >= 220 && CS(this).impulse <= 229) - ) { + || (CS(this).impulse >= 200 && CS(this).impulse <= 209) + || (CS(this).impulse >= 220 && CS(this).impulse <= 229) + ) { if (this.lastclassname != STR_PLAYER) { if (CS(this).impulse == 10 - || CS(this).impulse == 15 - || CS(this).impulse == 18 - || (CS(this).impulse >= 200 && CS(this).impulse <= 209) - ) { this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5); } else if (CS(this).impulse == 11) { + || CS(this).impulse == 15 + || CS(this).impulse == 18 + || (CS(this).impulse >= 200 && CS(this).impulse <= 209) + ) { this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5); } else if (CS(this).impulse == 11) { this.spectatorspeed = maxspeed_mod; } else if (CS(this).impulse == 12 - || CS(this).impulse == 16 - || CS(this).impulse == 19 - || (CS(this).impulse >= 220 && CS(this).impulse <= 229) - ) { + || CS(this).impulse == 16 + || CS(this).impulse == 19 + || (CS(this).impulse >= 220 && CS(this).impulse <= 229) + ) { this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5); } else if (CS(this).impulse >= 1 && CS(this).impulse <= 9) { this.spectatorspeed = 1 + 0.5 * (CS(this).impulse - 1); } - } // otherwise just clear + } // otherwise just clear CS(this).impulse = 0; } } diff --git a/qcsrc/lib/accumulate.qh b/qcsrc/lib/accumulate.qh index c265325f8..dd2dc784e 100644 --- a/qcsrc/lib/accumulate.qh +++ b/qcsrc/lib/accumulate.qh @@ -2,12 +2,12 @@ #ifdef QCC_SUPPORT_ACCUMULATE #define ACCUMULATE_FUNCTION(func, otherfunc) \ - [[accumulate]] void func() \ - { \ - otherfunc(); \ - } + [[accumulate]] void func() \ + { \ + otherfunc(); \ + } #define CALL_ACCUMULATED_FUNCTION(func) \ - func() + func() #else #ifdef HAVE_YO_DAWG_CPP // YO DAWG! @@ -15,35 +15,34 @@ // SO I PUT A MACRO DEFINITION IN YO MACRO DEFINITION // SO YO CAN EXPAND MACROS WHILE YO EXPAND MACROS #define ACCUMULATE_FUNCTION(func, otherfunc) \ - #ifdef func \ - void __merge__##otherfunc() \ - { \ - func(); otherfunc(); \ - } \ - #undef func \ - #define func __merge__##otherfunc \ - #else \ - #define func otherfunc \ - #endif + #ifdef func \ + void __merge__##otherfunc() \ + { \ + func(); otherfunc(); \ + } \ + #undef func \ + #define func __merge__##otherfunc \ + #else \ + #define func otherfunc \ + #endif #define CALL_ACCUMULATED_FUNCTION(func) \ - func() + func() #else #define ACCUMULATE_FUNCTION(func, otherfunc) \ - .float _ACCUMULATE_##func##__##otherfunc; - void ACCUMULATE_call(string func) - { - float i; - float n = numentityfields(); - string funcprefix = strcat("_ACCUMULATE_", func, "__"); - float funcprefixlen = strlen(funcprefix); - for (i = 0; i < n; ++i) - { - string name = entityfieldname(i); - if (substring(name, 0, funcprefixlen) == funcprefix) callfunction(substring(name, funcprefixlen, -1)); - } - } + .float _ACCUMULATE_##func##__##otherfunc; +void ACCUMULATE_call(string func) +{ + float i; + float n = numentityfields(); + string funcprefix = strcat("_ACCUMULATE_", func, "__"); + float funcprefixlen = strlen(funcprefix); + for (i = 0; i < n; ++i) { + string name = entityfieldname(i); + if (substring(name, 0, funcprefixlen) == funcprefix) { callfunction(substring(name, funcprefixlen, -1)); } + } +} #define CALL_ACCUMULATED_FUNCTION(func) \ - ACCUMULATE_call( #func) + ACCUMULATE_call( #func) #endif #endif diff --git a/qcsrc/lib/angle.qc b/qcsrc/lib/angle.qc index 1757c55b8..56e3cfc07 100644 --- a/qcsrc/lib/angle.qc +++ b/qcsrc/lib/angle.qc @@ -14,12 +14,13 @@ float anglemods(float v) { v = v - 360 * floor(v / 360); - if(v >= 180) + if (v >= 180) { return v - 360; - else if(v <= -180) + } else if (v <= -180) { return v + 360; - else + } else { return v; + } } /* @@ -28,15 +29,14 @@ float anglemods(float v) ERASEABLE float shortangle_f(float ang1, float ang2) { - if(ang1 > ang2) - { - if(ang1 > 180) + if (ang1 > ang2) { + if (ang1 > 180) { return ang1 - 360; - } - else - { - if(ang1 < -180) + } + } else { + if (ang1 < -180) { return ang1 + 360; + } } return ang1; @@ -47,9 +47,9 @@ vector shortangle_v(vector ang1, vector ang2) { vector vtmp; - vtmp_x = shortangle_f(ang1_x,ang2_x); - vtmp_y = shortangle_f(ang1_y,ang2_y); - vtmp_z = shortangle_f(ang1_z,ang2_z); + vtmp_x = shortangle_f(ang1_x, ang2_x); + vtmp_y = shortangle_f(ang1_y, ang2_y); + vtmp_z = shortangle_f(ang1_z, ang2_z); return vtmp; } @@ -59,8 +59,8 @@ vector shortangle_vxy(vector ang1, vector ang2) { vector vtmp = '0 0 0'; - vtmp_x = shortangle_f(ang1_x,ang2_x); - vtmp_y = shortangle_f(ang1_y,ang2_y); + vtmp_x = shortangle_f(ang1_x, ang2_x); + vtmp_y = shortangle_f(ang1_y, ang2_y); return vtmp; } @@ -78,11 +78,11 @@ vector angleofs3(vector from, vector ang, vector to) v_res = vectoangles(v_res); v_res = v_res - ang; - if (v_res_x < 0) v_res_x += 360; - if (v_res_x > 180) v_res_x -= 360; + if (v_res_x < 0) { v_res_x += 360; } + if (v_res_x > 180) { v_res_x -= 360; } - if (v_res_y < 0) v_res_y += 360; - if (v_res_y > 180) v_res_y -= 360; + if (v_res_y < 0) { v_res_y += 360; } + if (v_res_y > 180) { v_res_y -= 360; } return v_res; } diff --git a/qcsrc/lib/bits.qh b/qcsrc/lib/bits.qh index c158ea032..ae15b4a7e 100644 --- a/qcsrc/lib/bits.qh +++ b/qcsrc/lib/bits.qh @@ -24,21 +24,19 @@ int lowestbit(int f) ERASEABLE int randombit(int bits) { - if (!(bits & (bits - 1))) // this ONLY holds for powers of two! + if (!(bits & (bits - 1))) { // this ONLY holds for powers of two! return bits; + } int r = random(); int b = 0; int n = 0; - for (int f = 1; f <= bits; f *= 2) - { - if (bits & f) - { + for (int f = 1; f <= bits; f *= 2) { + if (bits & f) { ++n; r *= n; - if (r <= 1) b = f; - else r = (r - 1) / (n - 1); + if (r <= 1) { b = f; } else { r = (r - 1) / (n - 1); } } } return b; @@ -48,13 +46,12 @@ ERASEABLE int randombits(int bits, int k, bool error_return) { int r = 0; - while (k > 0 && bits != r) - { + while (k > 0 && bits != r) { r += randombit(bits - r); --k; } - if (error_return) - if (k > 0) return -1; + if (error_return) { + if (k > 0) { return -1; } } // all return r; } @@ -62,11 +59,11 @@ int randombits(int bits, int k, bool error_return) /* void randombit_test(int bits, int iter) { - while (iter > 0) - { - LOG_INFO(ftos(randombit(bits)), "\n"); - --iter; - } + while (iter > 0) + { + LOG_INFO(ftos(randombit(bits)), "\n"); + --iter; + } } */ @@ -82,21 +79,19 @@ ERASEABLE bool GiveBit(entity e, .int fld, int bit, int op, int val) { int v0 = (e.(fld) & bit); - switch (op) - { + switch (op) { case OP_SET: - if (val > 0) e.(fld) |= bit; - else e.(fld) &= ~bit; + if (val > 0) { e.(fld) |= bit; } else { e.(fld) &= ~bit; } break; case OP_MIN: case OP_PLUS: - if (val > 0) e.(fld) |= bit; + if (val > 0) { e.(fld) |= bit; } break; case OP_MAX: - if (val <= 0) e.(fld) &= ~bit; + if (val <= 0) { e.(fld) &= ~bit; } break; case OP_MINUS: - if (val > 0) e.(fld) &= ~bit; + if (val > 0) { e.(fld) &= ~bit; } break; } int v1 = (e.(fld) & bit); @@ -107,13 +102,12 @@ ERASEABLE bool GiveValue(entity e, .int fld, int op, int val) { int v0 = e.(fld); - switch (op) - { + switch (op) { case OP_SET: e.(fld) = val; break; case OP_MIN: - e.(fld) = max(e.(fld), val); // min 100 cells = at least 100 cells + e.(fld) = max(e.(fld), val); // min 100 cells = at least 100 cells break; case OP_MAX: e.(fld) = min(e.(fld), val); diff --git a/qcsrc/lib/bool.qh b/qcsrc/lib/bool.qh index c78f717d9..d81bf45f2 100644 --- a/qcsrc/lib/bool.qh +++ b/qcsrc/lib/bool.qh @@ -1,9 +1,9 @@ #pragma once #ifndef QCC_SUPPORT_BOOL - // Boolean Constants - const int true = 1; - const int false = 0; +// Boolean Constants +const int true = 1; +const int false = 0; #endif #define boolean(value) ((value) != 0) @@ -12,8 +12,7 @@ ERASEABLE float InterpretBoolean(string input) { - switch (strtolower(input)) - { + switch (strtolower(input)) { case "yes": case "true": case "on": diff --git a/qcsrc/lib/color.qh b/qcsrc/lib/color.qh index 5f9297f2d..38a75326b 100644 --- a/qcsrc/lib/color.qh +++ b/qcsrc/lib/color.qh @@ -6,8 +6,7 @@ ERASEABLE vector colormapPaletteColor_(int c, bool isPants, float t) { - switch (c) - { + switch (c) { case 0: return '1.000000 1.000000 1.000000'; case 1: return '1.000000 0.333333 0.000000'; case 2: return '0.000000 1.000000 0.501961'; @@ -24,14 +23,15 @@ vector colormapPaletteColor_(int c, bool isPants, float t) case 13: return '0.000000 0.333333 1.000000'; case 14: return '1.000000 0.666667 0.000000'; case 15: - if (isPants) + if (isPants) { return '1 0 0' * (0.502 + 0.498 * sin(t / 2.7182818285 + 0.0000000000)) - + '0 1 0' * (0.502 + 0.498 * sin(t / 2.7182818285 + 2.0943951024)) - + '0 0 1' * (0.502 + 0.498 * sin(t / 2.7182818285 + 4.1887902048)); - else + + '0 1 0' * (0.502 + 0.498 * sin(t / 2.7182818285 + 2.0943951024)) + + '0 0 1' * (0.502 + 0.498 * sin(t / 2.7182818285 + 4.1887902048)); + } else { return '1 0 0' * (0.502 + 0.498 * sin(t / 3.1415926536 + 5.2359877560)) - + '0 1 0' * (0.502 + 0.498 * sin(t / 3.1415926536 + 3.1415926536)) - + '0 0 1' * (0.502 + 0.498 * sin(t / 3.1415926536 + 1.0471975512)); + + '0 1 0' * (0.502 + 0.498 * sin(t / 3.1415926536 + 3.1415926536)) + + '0 0 1' * (0.502 + 0.498 * sin(t / 3.1415926536 + 1.0471975512)); + } default: return '0.000 0.000 0.000'; } } @@ -39,21 +39,13 @@ vector colormapPaletteColor_(int c, bool isPants, float t) ERASEABLE float rgb_mi_ma_to_hue(vector rgb, float mi, float ma) { - if (mi == ma) - { + if (mi == ma) { return 0; - } - else if (ma == rgb.x) - { - if (rgb.y >= rgb.z) return (rgb.y - rgb.z) / (ma - mi); - else return (rgb.y - rgb.z) / (ma - mi) + 6; - } - else if (ma == rgb.y) - { + } else if (ma == rgb.x) { + if (rgb.y >= rgb.z) { return (rgb.y - rgb.z) / (ma - mi); } else { return (rgb.y - rgb.z) / (ma - mi) + 6; } + } else if (ma == rgb.y) { return (rgb.z - rgb.x) / (ma - mi) + 2; - } - else // if(ma == rgb_z) - { + } else { // if(ma == rgb_z) return (rgb.x - rgb.y) / (ma - mi) + 4; } } @@ -67,44 +59,36 @@ vector hue_mi_ma_to_rgb(float hue, float mi, float ma) // else if(ma == rgb_x) // hue = 60 * (rgb_y - rgb_z) / (ma - mi); - if (hue <= 1) - { + if (hue <= 1) { rgb.x = ma; rgb.y = hue * (ma - mi) + mi; rgb.z = mi; } // else if(ma == rgb_y) // hue = 60 * (rgb_z - rgb_x) / (ma - mi) + 120; - else if (hue <= 2) - { + else if (hue <= 2) { rgb.x = (2 - hue) * (ma - mi) + mi; rgb.y = ma; rgb.z = mi; - } - else if (hue <= 3) - { + } else if (hue <= 3) { rgb.x = mi; rgb.y = ma; rgb.z = (hue - 2) * (ma - mi) + mi; } // else // if(ma == rgb_z) // hue = 60 * (rgb_x - rgb_y) / (ma - mi) + 240; - else if (hue <= 4) - { + else if (hue <= 4) { rgb.x = mi; rgb.y = (4 - hue) * (ma - mi) + mi; rgb.z = ma; - } - else if (hue <= 5) - { + } else if (hue <= 5) { rgb.x = (hue - 4) * (ma - mi) + mi; rgb.y = mi; rgb.z = ma; } // else if(ma == rgb_x) // hue = 60 * (rgb_y - rgb_z) / (ma - mi); - else // if(hue <= 6) - { + else { // if(hue <= 6) rgb.x = ma; rgb.y = mi; rgb.z = (6 - hue) * (ma - mi) + mi; @@ -125,8 +109,7 @@ vector rgb_to_hsv(vector rgb) hsv.x = rgb_mi_ma_to_hue(rgb, mi, ma); hsv.z = ma; - if (ma == 0) hsv.y = 0; - else hsv.y = 1 - mi / ma; + if (ma == 0) { hsv.y = 0; } else { hsv.y = 1 - mi / ma; } return hsv; } @@ -149,10 +132,11 @@ vector rgb_to_hsl(vector rgb) hsl.x = rgb_mi_ma_to_hue(rgb, mi, ma); hsl.z = 0.5 * (mi + ma); - if (mi == ma) hsl.y = 0; - else if (hsl.z <= 0.5) hsl.y = (ma - mi) / (2 * hsl.z); - else // if(hsl_z > 0.5) + if (mi == ma) { hsl.y = 0; } else if (hsl.z <= 0.5) { + hsl.y = (ma - mi) / (2 * hsl.z); + } else { // if(hsl_z > 0.5) hsl.y = (ma - mi) / (2 - 2 * hsl.z); + } return hsl; } @@ -162,8 +146,7 @@ vector hsl_to_rgb(vector hsl) { float mi, ma, maminusmi; - if (hsl.z <= 0.5) maminusmi = hsl.y * 2 * hsl.z; - else maminusmi = hsl.y * (2 - 2 * hsl.z); + if (hsl.z <= 0.5) { maminusmi = hsl.y * 2 * hsl.z; } else { maminusmi = hsl.y * (2 - 2 * hsl.z); } // hsl_z = 0.5 * mi + 0.5 * ma // maminusmi = - mi + ma @@ -181,5 +164,5 @@ string rgb_to_hexcolor(vector rgb) DEC_TO_HEXDIGIT(floor(rgb.x * 15 + 0.5)), DEC_TO_HEXDIGIT(floor(rgb.y * 15 + 0.5)), DEC_TO_HEXDIGIT(floor(rgb.z * 15 + 0.5)) - ); + ); } diff --git a/qcsrc/lib/counting.qh b/qcsrc/lib/counting.qh index b38ba9d05..9c92aeb22 100644 --- a/qcsrc/lib/counting.qh +++ b/qcsrc/lib/counting.qh @@ -71,18 +71,15 @@ string count_ordinal(int interval) // Basically, it just allows you to represent a number or count in different ways // depending on the number... like, with count_ordinal you can provide integers // and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way. - if (floor((interval % 100) / 10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block - { + if (floor((interval % 100) / 10) * 10 != 10) { // examples: 12th, 111th, 213th will not execute this block // otherwise, check normally for 1st,2nd,3rd insertions - switch (interval % 10) - { + switch (interval % 10) { case 1: return sprintf(_("%dst"), interval); case 2: return sprintf(_("%dnd"), interval); case 3: return sprintf(_("%drd"), interval); default: return sprintf(_("%dth"), interval); } - } - else { return sprintf(_("%dth"), interval); } + } else { return sprintf(_("%dth"), interval); } return ""; } @@ -102,14 +99,13 @@ string count_fill(float interval, string zeroth, string first, string second, st // 3 seconds // etc... minutes, hours, days, etc. - switch (floor(interval)) - { + switch (floor(interval)) { case 0: return sprintf(CTX(zeroth), interval); case 1: { - if (interval == 1) // EXACTLY value of 1 + if (interval == 1) { // EXACTLY value of 1 return sprintf(CTX(first), interval); - else return sprintf(CTX(multi), interval); + } else { return sprintf(CTX(multi), interval); } } case 2: return sprintf(CTX(second), interval); case 3: return sprintf(CTX(third), interval); @@ -126,27 +122,22 @@ string process_time(float outputtype, float seconds) tmp_seconds = floor(seconds); - if (tmp_seconds) - { + if (tmp_seconds) { tmp_minutes = floor(tmp_seconds / 60); - if (tmp_minutes) - { + if (tmp_minutes) { tmp_seconds -= (tmp_minutes * 60); tmp_hours = floor(tmp_minutes / 60); - if (tmp_hours) - { + if (tmp_hours) { tmp_minutes -= (tmp_hours * 60); tmp_days = floor(tmp_hours / 24); - if (tmp_days) - { + if (tmp_days) { tmp_hours -= (tmp_days * 24); tmp_weeks = floor(tmp_days / 7); - if (tmp_weeks) - { + if (tmp_weeks) { tmp_days -= (tmp_weeks * 7); tmp_years = floor(tmp_weeks / 52); } @@ -155,8 +146,7 @@ string process_time(float outputtype, float seconds) } } - switch (outputtype) - { + switch (outputtype) { case 1: return sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds); case 2: { @@ -164,36 +154,31 @@ string process_time(float outputtype, float seconds) output = count_seconds(tmp_seconds); - if (tmp_minutes) - { + if (tmp_minutes) { output = strcat( count_minutes(tmp_minutes), ((output != "") ? strcat(", ", output) : "")); } - if (tmp_hours) - { + if (tmp_hours) { output = strcat( count_hours(tmp_hours), ((output != "") ? strcat(", ", output) : "")); } - if (tmp_days) - { + if (tmp_days) { output = strcat( count_days(tmp_days), ((output != "") ? strcat(", ", output) : "")); } - if (tmp_weeks) - { + if (tmp_weeks) { output = strcat( count_weeks(tmp_weeks), ((output != "") ? strcat(", ", output) : "")); } - if (tmp_years) - { + if (tmp_years) { output = strcat( count_years(tmp_years), ((output != "") ? strcat(", ", output) : "")); @@ -207,10 +192,9 @@ string process_time(float outputtype, float seconds) output = count_hours(tmp_hours); - if (tmp_weeks) tmp_days += (tmp_weeks * 7); - if (tmp_years) tmp_days += (tmp_years * 365); - if (tmp_days) - { + if (tmp_weeks) { tmp_days += (tmp_weeks * 7); } + if (tmp_years) { tmp_days += (tmp_years * 365); } + if (tmp_days) { output = sprintf( count_days(tmp_days), ((output != "") ? strcat(", ", output) : "")); diff --git a/qcsrc/lib/csqcmodel/cl_model.qc b/qcsrc/lib/csqcmodel/cl_model.qc index 05aba388c..a3e1de5bc 100644 --- a/qcsrc/lib/csqcmodel/cl_model.qc +++ b/qcsrc/lib/csqcmodel/cl_model.qc @@ -36,18 +36,15 @@ float autocvar_cl_nolerp = 0; void CSQCModel_InterpolateAnimation_2To4_PreNote(entity this, int sf) { - if(sf & CSQCMODEL_PROPERTY_FRAME) - { + if (sf & CSQCMODEL_PROPERTY_FRAME) { this.frame3 = this.frame; this.frame3time = this.frame1time; } - if(sf & CSQCMODEL_PROPERTY_FRAME2) - { + if (sf & CSQCMODEL_PROPERTY_FRAME2) { this.frame4 = this.frame2; this.frame4time = this.frame2time; } - if(sf & CSQCMODEL_PROPERTY_LERPFRAC) - { + if (sf & CSQCMODEL_PROPERTY_LERPFRAC) { this.csqcmodel_lerpfrac2 = this.csqcmodel_lerpfrac; this.csqcmodel_lerpfrac2time = this.csqcmodel_lerpfractime; this.lerpfrac = this.csqcmodel_lerpfrac; @@ -55,8 +52,7 @@ void CSQCModel_InterpolateAnimation_2To4_PreNote(entity this, int sf) } void CSQCModel_InterpolateAnimation_1To2_PreNote(entity this, int sf) { - if(sf & CSQCMODEL_PROPERTY_FRAME) - { + if (sf & CSQCMODEL_PROPERTY_FRAME) { this.frame2 = this.frame; this.frame2time = this.frame1time; } @@ -72,29 +68,29 @@ void CSQCModel_InterpolateAnimation_PreNote(entity this, int sf) void CSQCModel_InterpolateAnimation_2To4_Note(entity this, int sf, bool set_times) { - if(sf & CSQCMODEL_PROPERTY_FRAME) - { - if(set_times) + if (sf & CSQCMODEL_PROPERTY_FRAME) { + if (set_times) { this.frame1time = time; + } } - if(sf & CSQCMODEL_PROPERTY_FRAME2) - { - if(set_times) + if (sf & CSQCMODEL_PROPERTY_FRAME2) { + if (set_times) { this.frame2time = time; + } } - if(sf & CSQCMODEL_PROPERTY_LERPFRAC) - { + if (sf & CSQCMODEL_PROPERTY_LERPFRAC) { this.csqcmodel_lerpfrac = this.lerpfrac; - if(set_times) + if (set_times) { this.csqcmodel_lerpfractime = time; + } } } void CSQCModel_InterpolateAnimation_1To2_Note(entity this, int sf, bool set_times) { - if(sf & CSQCMODEL_PROPERTY_FRAME) - { - if(set_times) + if (sf & CSQCMODEL_PROPERTY_FRAME) { + if (set_times) { this.frame1time = time; + } } } void CSQCModel_InterpolateAnimation_Note(entity this, int sf) @@ -108,31 +104,31 @@ void CSQCModel_InterpolateAnimation_Note(entity this, int sf) void CSQCModel_InterpolateAnimation_2To4_Do(entity this) { - if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0)) - { + if (autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0)) { this.lerpfrac = this.csqcmodel_lerpfrac; this.lerpfrac3 = 0; this.lerpfrac4 = 0; - } - else - { + } else { float l13, l24, llf; float l24_13; - if(this.frame3time == 0) // if frame1/3 were not previously displayed, only frame1 can make sense + if (this.frame3time == 0) { // if frame1/3 were not previously displayed, only frame1 can make sense l13 = 1; - else + } else { l13 = bound(0, (time - this.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + } - if(this.frame4time == 0) // if frame2/4 were not previously displayed, only frame2 can make sense + if (this.frame4time == 0) { // if frame2/4 were not previously displayed, only frame2 can make sense l24 = 1; - else + } else { l24 = bound(0, (time - this.frame2time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + } - if(this.csqcmodel_lerpfrac2time == 0) // if there is no old lerpfrac (newly displayed model), only lerpfrac makes sense + if (this.csqcmodel_lerpfrac2time == 0) { // if there is no old lerpfrac (newly displayed model), only lerpfrac makes sense llf = 1; - else + } else { llf = bound(0, (time - this.csqcmodel_lerpfractime) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + } l24_13 = this.csqcmodel_lerpfrac * llf + this.csqcmodel_lerpfrac2 * (1 - llf); @@ -140,14 +136,12 @@ void CSQCModel_InterpolateAnimation_2To4_Do(entity this) this.lerpfrac4 = (1 - l24) * l24_13; this.lerpfrac3 = (1 - l13) * (1 - l24_13); - if(l24_13 == 0) // if frames 2/4 are not displayed, clear their frametime - { + if (l24_13 == 0) { // if frames 2/4 are not displayed, clear their frametime this.frame2time = 0; this.frame4time = 0; } - if(l24_13 == 1) // if frames 1/3 are not displayed, clear their frametime - { + if (l24_13 == 1) { // if frames 1/3 are not displayed, clear their frametime this.frame1time = 0; this.frame3time = 0; } @@ -155,16 +149,14 @@ void CSQCModel_InterpolateAnimation_2To4_Do(entity this) } void CSQCModel_InterpolateAnimation_1To2_Do(entity this) { - if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0)) - { + if (autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0)) { this.lerpfrac = 0; - } - else - { - if(this.frame2time == 0) // if frame2 was not previously displayed, only frame1 can make sense + } else { + if (this.frame2time == 0) { // if frame2 was not previously displayed, only frame1 can make sense this.lerpfrac = 0; - else + } else { this.lerpfrac = 1 - bound(0, (time - this.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + } } } void CSQCModel_InterpolateAnimation_Do(entity this) @@ -185,26 +177,26 @@ void CSQCModel_Draw(entity this) // we don't do this for the local player as that one is already handled // by CSQCPlayer_SetCamera() - if (!CSQCPlayer_IsLocalPlayer(this)) InterpolateOrigin_Do(this); + if (!CSQCPlayer_IsLocalPlayer(this)) { InterpolateOrigin_Do(this); } CSQCModel_InterpolateAnimation_Do(this); CSQCModel_Hook_PreDraw(this, isplayer); - if(isplayer) - { - if(this.entnum == player_localentnum) + if (isplayer) { + if (this.entnum == player_localentnum) { this.renderflags |= RF_EXTERNALMODEL; - else + } else { this.renderflags &= ~RF_EXTERNALMODEL; + } } // inherit draw flags easily entity root = this; - while(root.tag_entity) + while (root.tag_entity) { root = root.tag_entity; - if(this != root) - { + } + if (this != root) { this.renderflags &= ~(RF_EXTERNALMODEL | RF_VIEWMODEL); this.renderflags |= (root.renderflags & (RF_EXTERNALMODEL | RF_VIEWMODEL)); } @@ -226,8 +218,7 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) // some nice flags for CSQCMODEL_IF and the hooks bool isplayer = ReadByte() || (this.entnum >= 1 && this.entnum <= maxclients); - if (isnew && isplayer) - { + if (isnew && isplayer) { CSQCModel_players[this.entnum - 1] = this; this.entremove = CSQCModel_remove; } @@ -235,8 +226,8 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) noref bool isnolocalplayer = (isplayer && !islocalplayer); this.classname = "csqcmodel"; - this.iflags |= IFLAG_ORIGIN; // interpolate origin too - this.iflags |= IFLAG_ANGLES; // interpolate angles too + this.iflags |= IFLAG_ORIGIN; // interpolate origin too + this.iflags |= IFLAG_ANGLES; // interpolate angles too this.iflags |= IFLAG_VELOCITY | IFLAG_AUTOVELOCITY; // let's calculate velocity automatically CSQCModel_Hook_PreUpdate(this, isnew, isplayer, islocalplayer); @@ -245,35 +236,37 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) InterpolateOrigin_Undo(this); CSQCModel_InterpolateAnimation_PreNote(this, sf); -#define CSQCMODEL_IF(cond) if(cond) { -#define CSQCMODEL_ENDIF } -#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ - if(sf & flag) \ - this.f = r(); -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \ - if(sf & flag) \ - this.f = (r() + mi) / s; +#define CSQCMODEL_IF(cond) if (cond) { +#define CSQCMODEL_ENDIF \ + } +#define CSQCMODEL_PROPERTY(flag, t, r, w, f) \ + if (sf & flag) { \ + this.f = r(); \ + } +#define CSQCMODEL_PROPERTY_SCALED(flag, t, r, w, f, s, mi, ma) \ + if (sf & flag) { \ + this.f = (r() + mi) / s; \ + } ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY #undef CSQCMODEL_ENDIF #undef CSQCMODEL_IF - if(sf & CSQCMODEL_PROPERTY_MODELINDEX) - { + if (sf & CSQCMODEL_PROPERTY_MODELINDEX) { vector pmin = this.mins, pmax = this.maxs; setmodelindex(this, this.modelindex); // this retrieves the .model key and sets mins/maxs/absmin/absmax setsize(this, pmin, pmax); } - if(sf & CSQCMODEL_PROPERTY_TELEPORTED) - { + if (sf & CSQCMODEL_PROPERTY_TELEPORTED) { this.iflags |= IFLAG_TELEPORTED; this.csqcmodel_teleported = 1; } - if(sf & BIT(14)) + if (sf & BIT(14)) { viewloc_SetTags(this); + } CSQCModel_InterpolateAnimation_Note(this, sf); InterpolateOrigin_Note(this); @@ -290,10 +283,11 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) setorigin(this, this.origin); // set obvious render flags - if(this.entnum == player_localentnum) + if (this.entnum == player_localentnum) { this.renderflags |= RF_EXTERNALMODEL; - else + } else { this.renderflags &= ~RF_EXTERNALMODEL; + } // draw it this.drawmask = MASK_NORMAL; @@ -306,7 +300,7 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) */ entity CSQCModel_server2csqc(int i) { - if (i < maxclients) return CSQCModel_players[i]; + if (i < maxclients) { return CSQCModel_players[i]; } ++i; LOG_DEBUGF("player out of bounds: %d", i); return findfloat(NULL, entnum, i); diff --git a/qcsrc/lib/csqcmodel/cl_model.qh b/qcsrc/lib/csqcmodel/cl_model.qh index b5d9f8bd3..ffd64dc71 100644 --- a/qcsrc/lib/csqcmodel/cl_model.qh +++ b/qcsrc/lib/csqcmodel/cl_model.qh @@ -25,10 +25,10 @@ #define CSQCMODEL_IF(cond) #define CSQCMODEL_ENDIF -#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ +#define CSQCMODEL_PROPERTY(flag, t, r, w, f) \ .t f; -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) CSQCMODEL_PROPERTY(flag,t,r,w,f) - ALLPROPERTIES +#define CSQCMODEL_PROPERTY_SCALED(flag, t, r, w, f, s, mi, ma) CSQCMODEL_PROPERTY(flag, t, r, w, f) +ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY #undef CSQCMODEL_ENDIF diff --git a/qcsrc/lib/csqcmodel/cl_player.qc b/qcsrc/lib/csqcmodel/cl_player.qc index 225c7307d..159c74c14 100644 --- a/qcsrc/lib/csqcmodel/cl_player.qc +++ b/qcsrc/lib/csqcmodel/cl_player.qc @@ -43,13 +43,13 @@ float csqcplayer_predictionerrorfactor; vector CSQCPlayer_GetPredictionErrorO() { - if (time >= csqcplayer_predictionerrortime) return '0 0 0'; + if (time >= csqcplayer_predictionerrortime) { return '0 0 0'; } return csqcplayer_predictionerroro * (csqcplayer_predictionerrortime - time) * csqcplayer_predictionerrorfactor; } vector CSQCPlayer_GetPredictionErrorV() { - if (time >= csqcplayer_predictionerrortime) return '0 0 0'; + if (time >= csqcplayer_predictionerrortime) { return '0 0 0'; } return csqcplayer_predictionerrorv * (csqcplayer_predictionerrortime - time) * csqcplayer_predictionerrorfactor; } @@ -64,18 +64,16 @@ void CSQCPlayer_SetPredictionError(vector o, vector v, float onground_diff) // commented out as this one did not help if(onground_diff) { - printf("ONGROUND MISMATCH: %d x=%v v=%v\n", onground_diff, o, v); - return; + printf("ONGROUND MISMATCH: %d x=%v v=%v\n", onground_diff, o, v); + return; } */ - if(vdist(o, >, 32) || vdist(v, >, 192)) - { - //printf("TOO BIG: x=%v v=%v\n", o, v); + if (vdist(o, >, 32) || vdist(v, >, 192)) { + // printf("TOO BIG: x=%v v=%v\n", o, v); return; } - if(!autocvar_cl_movement_errorcompensation) - { + if (!autocvar_cl_movement_errorcompensation) { csqcplayer_predictionerrorfactor = 0; return; } @@ -88,8 +86,8 @@ void CSQCPlayer_SetPredictionError(vector o, vector v, float onground_diff) void CSQCPlayer_Unpredict(entity this) { - if (csqcplayer_status == CSQCPLAYERSTATUS_UNPREDICTED) return; - if (csqcplayer_status != CSQCPLAYERSTATUS_PREDICTED) LOG_FATALF("Cannot unpredict in current status (%d)", csqcplayer_status); + if (csqcplayer_status == CSQCPLAYERSTATUS_UNPREDICTED) { return; } + if (csqcplayer_status != CSQCPLAYERSTATUS_PREDICTED) { LOG_FATALF("Cannot unpredict in current status (%d)", csqcplayer_status); } this.origin = csqcplayer_origin; this.velocity = csqcplayer_velocity; csqcplayer_moveframe = csqcplayer_sequence + 1; // + 1 because the recieved frame has the move already done (server side) @@ -98,14 +96,11 @@ void CSQCPlayer_Unpredict(entity this) void CSQCPlayer_SetMinsMaxs(entity this) { - if (IS_DUCKED(this) || !this.isplayermodel) - { + if (IS_DUCKED(this) || !this.isplayermodel) { this.mins = PHYS_PL_CROUCH_MIN(this); this.maxs = PHYS_PL_CROUCH_MAX(this); this.view_ofs = PHYS_PL_CROUCH_VIEWOFS(this); - } - else - { + } else { this.mins = PHYS_PL_MIN(this); this.maxs = PHYS_PL_MAX(this); this.view_ofs = PHYS_PL_VIEWOFS(this); @@ -125,9 +120,9 @@ void CSQC_ClientMovement_PlayerMove_Frame(entity this); void CSQCPlayer_Physics(entity this) { - if(!autocvar_cl_movement) { return; } + if (!autocvar_cl_movement) { return; } - _Movetype_CheckWater(this); // we apparently need to check water *before* physics so it can use this for water jump + _Movetype_CheckWater(this); // we apparently need to check water *before* physics so it can use this for water jump vector oldv_angle = this.v_angle; vector oldangles = this.angles; // we need to save these, as they're abused by other code @@ -144,16 +139,15 @@ void CSQCPlayer_Physics(entity this) this.angles = oldangles; this.pmove_flags = - ((IS_DUCKED(this)) ? PMF_DUCKED : 0) | - ((IS_JUMP_HELD(this)) ? PMF_JUMP_HELD : 0) | - ((IS_ONGROUND(this)) ? PMF_ONGROUND : 0); + ((IS_DUCKED(this)) ? PMF_DUCKED : 0) + | ((IS_JUMP_HELD(this)) ? PMF_JUMP_HELD : 0) + | ((IS_ONGROUND(this)) ? PMF_ONGROUND : 0); } void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error) { CSQCPlayer_Unpredict(this); - if (apply_error) - { + if (apply_error) { this.origin += CSQCPlayer_GetPredictionErrorO(); this.velocity += CSQCPlayer_GetPredictionErrorV(); } @@ -164,38 +158,32 @@ void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error) #if 0 // we don't need this // darkplaces makes servercommandframe == 0 in these cases anyway - if (STAT(HEALTH) <= 0) - { + if (STAT(HEALTH) <= 0) { csqcplayer_moveframe = clientcommandframe; - getinputstate(csqcplayer_moveframe-1); + getinputstate(csqcplayer_moveframe - 1); LOG_INFO("the Weird code path got hit"); return; } #endif - if (csqcplayer_moveframe >= endframe) - { + if (csqcplayer_moveframe >= endframe) { getinputstate(csqcplayer_moveframe - 1); - } - else - { - do - { - if (!getinputstate(csqcplayer_moveframe)) break; + } else { + do { + if (!getinputstate(csqcplayer_moveframe)) { break; } /*if (input_timelength > 0.0005) { - if (input_timelength > 0.05) - { - input_timelength /= 2; - CSQCPlayer_Physics(this); - } - CSQCPlayer_Physics(this); + if (input_timelength > 0.05) + { + input_timelength /= 2; + CSQCPlayer_Physics(this); + } + CSQCPlayer_Physics(this); }*/ CSQCPlayer_Physics(this); CSQCPlayer_SetMinsMaxs(this); ++csqcplayer_moveframe; - } - while (csqcplayer_moveframe < endframe); + } while (csqcplayer_moveframe < endframe); } // add in anything that was applied after (for low packet rate protocols) @@ -204,7 +192,7 @@ void CSQCPlayer_PredictTo(entity this, float endframe, bool apply_error) bool CSQCPlayer_IsLocalPlayer(entity this) { - return (this == csqcplayer); + return this == csqcplayer; } /** Called once per CSQC_UpdateView() */ @@ -215,16 +203,15 @@ void CSQCPlayer_SetCamera() const vector pl_viewofs = PHYS_PL_VIEWOFS(NULL); const vector pl_viewofs_crouch = PHYS_PL_CROUCH_VIEWOFS(NULL); const entity e = csqcplayer; - if (e) - { - if (servercommandframe == 0 || clientcommandframe == 0) - { + if (e) { + if (servercommandframe == 0 || clientcommandframe == 0) { InterpolateOrigin_Do(e); e.view_ofs = '0 0 1' * vh; // get crouch state from the server - if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED; - else if (vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED; + if (vh == pl_viewofs.z) { e.flags &= ~FL_DUCKED; } else if (vh == pl_viewofs_crouch.z) { + e.flags |= FL_DUCKED; + } // get onground state from the server e.flags = BITSET(e.flags, FL_ONGROUND, pmove_onground); @@ -236,15 +223,13 @@ void CSQCPlayer_SetCamera() // set velocity e.velocity = v0; - } - else - { - const int flg = e.iflags; e.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES); + } else { + const int flg = e.iflags; + e.iflags &= ~(IFLAG_ORIGIN | IFLAG_ANGLES); InterpolateOrigin_Do(e); e.iflags = flg; - if (csqcplayer_status == CSQCPLAYERSTATUS_FROMSERVER) - { + if (csqcplayer_status == CSQCPLAYERSTATUS_FROMSERVER) { const vector o = e.origin; csqcplayer_status = CSQCPLAYERSTATUS_PREDICTED; CSQCPlayer_PredictTo(e, servercommandframe + 1, false); @@ -253,8 +238,9 @@ void CSQCPlayer_SetCamera() e.velocity = v0; // get crouch state from the server - if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED; - else if(vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED; + if (vh == pl_viewofs.z) { e.flags &= ~FL_DUCKED; } else if (vh == pl_viewofs_crouch.z) { + e.flags |= FL_DUCKED; + } // get onground state from the server e.flags = BITSET(e.flags, FL_ONGROUND, pmove_onground); @@ -265,8 +251,9 @@ void CSQCPlayer_SetCamera() #ifdef CSQCMODEL_SERVERSIDE_CROUCH // get crouch state from the server (LAG) - if (vh == pl_viewofs.z) e.flags &= ~FL_DUCKED; - else if (vh == pl_viewofs_crouch.z) e.flags |= FL_DUCKED; + if (vh == pl_viewofs.z) { e.flags &= ~FL_DUCKED; } else if (vh == pl_viewofs_crouch.z) { + e.flags |= FL_DUCKED; + } #endif CSQCPlayer_SetMinsMaxs(e); @@ -278,23 +265,19 @@ void CSQCPlayer_SetCamera() } const entity view = CSQCModel_server2csqc(player_localentnum - 1); - if (view) - { - if (view != csqcplayer) - { + if (view) { + if (view != csqcplayer) { InterpolateOrigin_Do(view); view.view_ofs = '0 0 1' * vh; } int refdefflags = 0; - if (view.csqcmodel_teleported) refdefflags |= REFDEFFLAG_TELEPORTED; - if (input_buttons & BIT(1)) refdefflags |= REFDEFFLAG_JUMPING; + if (view.csqcmodel_teleported) { refdefflags |= REFDEFFLAG_TELEPORTED; } + if (input_buttons & BIT(1)) { refdefflags |= REFDEFFLAG_JUMPING; } // note: these two only work in WIP2, but are harmless in WIP1 - if (PHYS_HEALTH(NULL) <= 0 && PHYS_HEALTH(NULL) != -666 && PHYS_HEALTH(NULL) != -2342) refdefflags |= REFDEFFLAG_DEAD; - if (intermission) refdefflags |= REFDEFFLAG_INTERMISSION; + if (PHYS_HEALTH(NULL) <= 0 && PHYS_HEALTH(NULL) != -666 && PHYS_HEALTH(NULL) != -2342) { refdefflags |= REFDEFFLAG_DEAD; } + if (intermission) { refdefflags |= REFDEFFLAG_INTERMISSION; } V_CalcRefdef(view, refdefflags); - } - else - { + } else { // FIXME by CSQC spec we have to do this: // but it breaks chase cam /* @@ -313,14 +296,14 @@ void CSQCPlayer_Remove(entity this) bool CSQCPlayer_PreUpdate(entity this) { - if (this != csqcplayer) return false; - if (csqcplayer_status != CSQCPLAYERSTATUS_FROMSERVER) CSQCPlayer_Unpredict(this); + if (this != csqcplayer) { return false; } + if (csqcplayer_status != CSQCPLAYERSTATUS_FROMSERVER) { CSQCPlayer_Unpredict(this); } return true; } bool CSQCPlayer_PostUpdate(entity this) { - if (this.entnum != player_localnum + 1) return false; + if (this.entnum != player_localnum + 1) { return false; } csqcplayer = this; csqcplayer_status = CSQCPLAYERSTATUS_FROMSERVER; cvar_settemp("cl_movement_replay", "0"); diff --git a/qcsrc/lib/csqcmodel/cl_player.qh b/qcsrc/lib/csqcmodel/cl_player.qh index 297e2e69d..0c6bac43c 100644 --- a/qcsrc/lib/csqcmodel/cl_player.qh +++ b/qcsrc/lib/csqcmodel/cl_player.qh @@ -32,8 +32,8 @@ const int CSQCPLAYERSTATUS_PREDICTED = 2; // only ever READ these! .int pmove_flags; const int PMF_JUMP_HELD = 1; -//const int PMF_DUCKED = 4; -//const int PMF_ONGROUND = 8; +// const int PMF_DUCKED = 4; +// const int PMF_ONGROUND = 8; const int FL_DUCKED = 524288; diff --git a/qcsrc/lib/csqcmodel/common.qh b/qcsrc/lib/csqcmodel/common.qh index 37b88997e..2be662cc1 100644 --- a/qcsrc/lib/csqcmodel/common.qh +++ b/qcsrc/lib/csqcmodel/common.qh @@ -87,7 +87,8 @@ const int CSQCMODEL_PROPERTY_SIZE = BIT(15); .float frame4; .float frame4time; .float lerpfrac4; -#define ALLPROPERTIES ALLPROPERTIES_COMMON \ +#define ALLPROPERTIES \ + ALLPROPERTIES_COMMON \ CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_FRAME2, int, ReadByte, WriteByte, frame2) \ CSQCMODEL_PROPERTY_SCALED(CSQCMODEL_PROPERTY_LERPFRAC, float, ReadByte, WriteByte, lerpfrac, 255, 0, 255) #else diff --git a/qcsrc/lib/csqcmodel/settings.qh b/qcsrc/lib/csqcmodel/settings.qh index 359cf1738..ab43283b8 100644 --- a/qcsrc/lib/csqcmodel/settings.qh +++ b/qcsrc/lib/csqcmodel/settings.qh @@ -1,9 +1,9 @@ #pragma once // define this if svqc code wants to use .frame2 and .lerpfrac -//#define CSQCMODEL_HAVE_TWO_FRAMES +// #define CSQCMODEL_HAVE_TWO_FRAMES // don't define this ever -//#define CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW +// #define CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW // add properties you want networked to CSQC here #define CSQCMODEL_EXTRAPROPERTIES \ @@ -17,9 +17,9 @@ #define CSQCPLAYER_FORCE_UPDATES 4 // mod must define: -//vector PL_MIN = ...; -//vector PL_MAX = ...; -//vector PL_VIEW_OFS = ...; -//vector PL_CROUCH_MIN = ...; -//vector PL_CROUCH_MAX = ...; -//vector PL_CROUCH_VIEW_OFS = ...; +// vector PL_MIN = ...; +// vector PL_MAX = ...; +// vector PL_VIEW_OFS = ...; +// vector PL_CROUCH_MIN = ...; +// vector PL_CROUCH_MAX = ...; +// vector PL_CROUCH_VIEW_OFS = ...; diff --git a/qcsrc/lib/csqcmodel/sv_model.qc b/qcsrc/lib/csqcmodel/sv_model.qc index 0ff438994..c90d2796b 100644 --- a/qcsrc/lib/csqcmodel/sv_model.qc +++ b/qcsrc/lib/csqcmodel/sv_model.qc @@ -36,14 +36,14 @@ bool CSQCModel_Send(entity this, entity to, int sf) WriteInt24_t(MSG_ENTITY, sf); WriteByte(MSG_ENTITY, isplayer); -#define CSQCMODEL_IF(cond) if(cond) { -#define CSQCMODEL_ENDIF } -#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ - if(sf & flag) \ - { \ +#define CSQCMODEL_IF(cond) if (cond) { +#define CSQCMODEL_ENDIF \ + } +#define CSQCMODEL_PROPERTY(flag, t, r, w, f) \ + if (sf & flag) { \ w(MSG_ENTITY, this.csqcmodel_##f); \ } -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) CSQCMODEL_PROPERTY(flag,t,r,w,f) +#define CSQCMODEL_PROPERTY_SCALED(flag, t, r, w, f, s, mi, ma) CSQCMODEL_PROPERTY(flag, t, r, w, f) ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY @@ -60,45 +60,41 @@ void CSQCModel_CheckUpdate(entity e) { // some nice flags for CSQCMODEL_IF noref float isplayer = IS_CLIENT(e); - noref float islocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags + noref float islocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags noref float isnolocalplayer = isplayer; // we set BOTH to 1 here as we need the sendflags #if CSQCPLAYER_FORCE_UPDATES - if(isplayer && time > e.csqcmodel_nextforcedupdate) - { + if (isplayer && time > e.csqcmodel_nextforcedupdate) { e.SendFlags |= CSQCMODEL_PROPERTY_ORIGIN; e.csqcmodel_nextforcedupdate = time + (1 / (CSQCPLAYER_FORCE_UPDATES)) * (0.5 + random()); // ensure about 4 origin sends per sec } #endif - if(e.effects & EF_RESTARTANIM_BIT) - { + if (e.effects & EF_RESTARTANIM_BIT) { e.SendFlags |= CSQCMODEL_PROPERTY_FRAME | CSQCMODEL_PROPERTY_FRAME2; // full anim resend please e.effects &= ~EF_RESTARTANIM_BIT; } - if(e.effects & EF_TELEPORT_BIT) - { + if (e.effects & EF_TELEPORT_BIT) { e.SendFlags |= CSQCMODEL_PROPERTY_TELEPORTED; // no interpolation please e.effects &= ~EF_TELEPORT_BIT; } -#define CSQCMODEL_IF(cond) if(cond) { -#define CSQCMODEL_ENDIF } -#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ +#define CSQCMODEL_IF(cond) if (cond) { +#define CSQCMODEL_ENDIF \ + } +#define CSQCMODEL_PROPERTY(flag, t, r, w, f) \ { \ t tmp = e.f; \ - if(tmp != e.csqcmodel_##f) \ - { \ + if (tmp != e.csqcmodel_##f) { \ e.csqcmodel_##f = tmp; \ e.SendFlags |= flag; \ } \ } -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \ +#define CSQCMODEL_PROPERTY_SCALED(flag, t, r, w, f, s, mi, ma) \ { \ t tmp = rint(bound(mi, s * e.f, ma) - mi); \ - if(tmp != e.csqcmodel_##f) \ - { \ + if (tmp != e.csqcmodel_##f) { \ e.csqcmodel_##f = tmp; \ e.SendFlags |= flag; \ } \ diff --git a/qcsrc/lib/csqcmodel/sv_model.qh b/qcsrc/lib/csqcmodel/sv_model.qh index e963f12a1..66dd85445 100644 --- a/qcsrc/lib/csqcmodel/sv_model.qh +++ b/qcsrc/lib/csqcmodel/sv_model.qh @@ -31,11 +31,11 @@ void CSQCModel_UnlinkEntity(entity e); #define CSQCMODEL_IF(cond) #define CSQCMODEL_ENDIF -#define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ +#define CSQCMODEL_PROPERTY(flag, t, r, w, f) \ .t f; \ .t csqcmodel_##f; -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) CSQCMODEL_PROPERTY(flag,t,r,w,f) - ALLPROPERTIES +#define CSQCMODEL_PROPERTY_SCALED(flag, t, r, w, f, s, mi, ma) CSQCMODEL_PROPERTY(flag, t, r, w, f) +ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY #undef CSQCMODEL_ENDIF diff --git a/qcsrc/lib/cvar.qh b/qcsrc/lib/cvar.qh index a17f2bad7..87e11a4af 100644 --- a/qcsrc/lib/cvar.qh +++ b/qcsrc/lib/cvar.qh @@ -10,12 +10,12 @@ void RegisterCvars(void(string name, string def, string desc, bool archive, stri ERASEABLE bool cvar_value_issafe(string s) { - if (strstrofs(s, "\"", 0) >= 0) return false; - if (strstrofs(s, "\\", 0) >= 0) return false; - if (strstrofs(s, ";", 0) >= 0) return false; - if (strstrofs(s, "$", 0) >= 0) return false; - if (strstrofs(s, "\r", 0) >= 0) return false; - if (strstrofs(s, "\n", 0) >= 0) return false; + if (strstrofs(s, "\"", 0) >= 0) { return false; } + if (strstrofs(s, "\\", 0) >= 0) { return false; } + if (strstrofs(s, ";", 0) >= 0) { return false; } + if (strstrofs(s, "$", 0) >= 0) { return false; } + if (strstrofs(s, "\r", 0) >= 0) { return false; } + if (strstrofs(s, "\n", 0) >= 0) { return false; } return true; } @@ -46,14 +46,14 @@ ERASEABLE void RegisterCvars_Set(string name, string def, string desc, bool archive, string file) { cvar_describe(name, desc); - if (archive) cvar_archive(name); + if (archive) { cvar_archive(name); } } int RegisterCvars_Save_fd; ERASEABLE void RegisterCvars_Save(string name, string def, string desc, bool archive, string file) { - if (!archive) return; + if (!archive) { return; } fputs(RegisterCvars_Save_fd, sprintf("seta %s \"%s\"\n", name, def)); } @@ -61,8 +61,7 @@ STATIC_INIT_LATE(Cvars) { RegisterCvars(RegisterCvars_Set); RegisterCvars_Save_fd = fopen(sprintf("default%s.cfg", PROGNAME), FILE_WRITE); - if (RegisterCvars_Save_fd >= 0) - { + if (RegisterCvars_Save_fd >= 0) { RegisterCvars(RegisterCvars_Save); fclose(RegisterCvars_Save_fd); } @@ -80,7 +79,7 @@ const noref vector default_vector = '0 0 0'; #define repr_cvar_string(x) (x) #define repr_cvar_vector(x) (sprintf("%v", x)) -//pseudo prototypes: +// pseudo prototypes: // void AUTOCVAR(, , default_cvar_value, string desc) // void AUTOCVAR_SAVE(, , default_cvar_value, string desc) // where default_cvar_value has type diff --git a/qcsrc/lib/defer.qh b/qcsrc/lib/defer.qh index 4f34bb485..33bfdf962 100644 --- a/qcsrc/lib/defer.qh +++ b/qcsrc/lib/defer.qh @@ -5,34 +5,34 @@ #include "oo.qh" #include "self.qh" - entityclass(Defer); - class(Defer).entity owner; - class(Defer).void(entity) defer_func; +entityclass(Defer); +class(Defer).entity owner; +class(Defer).void(entity) defer_func; - /** Remove entity */ - void SUB_Remove(entity this) - { - delete(this); - } +/** Remove entity */ +void SUB_Remove(entity this) +{ + delete(this); +} - void defer_think(entity this) - { - setthink(this, SUB_Remove); - this.nextthink = time; - this.defer_func(this.owner); - } +void defer_think(entity this) +{ + setthink(this, SUB_Remove); + this.nextthink = time; + this.defer_func(this.owner); +} - /** - * Execute func() after time + fdelay. - * self when func is executed = self when defer is called - */ - void defer(entity this, float fdelay, void(entity) func) - { - entity e = new_pure(deferred); - e.owner = this; - e.defer_func = func; - setthink(e, defer_think); - e.nextthink = time + fdelay; - } +/** + * Execute func() after time + fdelay. + * self when func is executed = self when defer is called + */ +void defer(entity this, float fdelay, void(entity) func) +{ + entity e = new_pure(deferred); + e.owner = this; + e.defer_func = func; + setthink(e, defer_think); + e.nextthink = time + fdelay; +} #endif diff --git a/qcsrc/lib/enumclass.qh b/qcsrc/lib/enumclass.qh index 86948075b..663ee4105 100644 --- a/qcsrc/lib/enumclass.qh +++ b/qcsrc/lib/enumclass.qh @@ -22,7 +22,11 @@ .int enum_ordinal; #define ENUMCLASS(id) CLASS(id, Object) int id##_count; const noref entity id##_Null = nil; CASE(id, Null__) -#define CASE(class, id) class class##_##id; STATIC_INIT(class##_##id) { entity e = class##_##id = NEW(class); e.enum_ordinal = class##_count++; } +#define CASE(class, id) \ + class class##_##id; STATIC_INIT(class##_##id) \ + { \ + entity e = class##_##id = NEW(class); e.enum_ordinal = class##_count++; \ + } #define ENUMCLASS_END(id) ENDCLASS(id) #define ORDINAL(it) ((it).enum_ordinal) #define ENUMCAST(T, it) ftoe(etof(T##_Null__) + (it)) diff --git a/qcsrc/lib/file.qh b/qcsrc/lib/file.qh index 5bc24f627..a23115884 100644 --- a/qcsrc/lib/file.qh +++ b/qcsrc/lib/file.qh @@ -4,7 +4,7 @@ ERASEABLE bool fexists(string f) { int fh = fopen(f, FILE_READ); - if (fh < 0) return false; + if (fh < 0) { return false; } fclose(fh); return true; } diff --git a/qcsrc/lib/i18n.qh b/qcsrc/lib/i18n.qh index 3dfac6224..f17712110 100644 --- a/qcsrc/lib/i18n.qh +++ b/qcsrc/lib/i18n.qh @@ -14,11 +14,10 @@ ERASEABLE string language_filename(string s) { string fn = prvm_language; - if (fn == "" || fn == "dump") return s; + if (fn == "" || fn == "dump") { return s; } fn = strcat(s, ".", fn); int fh = fopen(fn, FILE_READ); - if (fh >= 0) - { + if (fh >= 0) { fclose(fh); return fn; } @@ -30,29 +29,29 @@ string language_filename(string s) #endif #if CTX_CACHE - HashMap CTX_cache; - STATIC_INIT(CTX_cache) - { - HM_NEW(CTX_cache); - } - SHUTDOWN(CTX_cache) - { - HM_DELETE(CTX_cache); - } +HashMap CTX_cache; +STATIC_INIT(CTX_cache) +{ + HM_NEW(CTX_cache); +} +SHUTDOWN(CTX_cache) +{ + HM_DELETE(CTX_cache); +} #endif ERASEABLE string CTX(string s) { #if CTX_CACHE - string c = HM_gets(CTX_cache, s); - if (c != "") return c; + string c = HM_gets(CTX_cache, s); + if (c != "") { return c; } #endif int p = strstrofs(s, "^", 0); string ret = (p < 0) ? s : substring(s, p + 1, -1); #if CTX_CACHE - LOG_DEBUGF("CTX(\"%s\")", s); - HM_sets(CTX_cache, s, ret); + LOG_DEBUGF("CTX(\"%s\")", s); + HM_sets(CTX_cache, s, ret); #endif return ret; } diff --git a/qcsrc/lib/iter.qh b/qcsrc/lib/iter.qh index 7a284e2de..9cda6d909 100644 --- a/qcsrc/lib/iter.qh +++ b/qcsrc/lib/iter.qh @@ -8,8 +8,7 @@ #define FOREACH_ARRAY(arr, start, end, cond, body) \ MACRO_BEGIN \ - for (int _i = start; _i < end; ++_i) \ - { \ + for (int _i = start; _i < end; ++_i) { \ const noref int i = _i; \ ITER_CONST noref entity it = arr[i]; \ if (cond) { LAMBDA(body); } \ @@ -21,8 +20,7 @@ #define FOREACH_LIST(list, next, cond, body) \ MACRO_BEGIN \ int _i = 0; \ - for (entity _it = list##_first, _next = NULL; _it; (_it = _next, ++_i)) \ - { \ + for (entity _it = list##_first, _next = NULL; _it; (_it = _next, ++_i)) { \ const noref int i = _i; \ ITER_CONST noref entity it = _it; \ _next = _it.next; \ @@ -34,8 +32,7 @@ MACRO_BEGIN \ string _words = words; \ int _i = 0; \ - for (string _it; (_it = car(_words)); (_words = cdr(_words), ++_i)) \ - { \ + for (string _it; (_it = car(_words)); (_words = cdr(_words), ++_i)) { \ const noref int i = _i; \ const noref string it = _it; \ if (cond) { LAMBDA(body); } \ @@ -63,69 +60,69 @@ MACRO_BEGIN \ STRING_ITERATOR(iter, s, 0); \ int _it; \ - while ((_it = STRING_ITERATOR_GET(iter)) > 0) \ - { \ + while ((_it = STRING_ITERATOR_GET(iter)) > 0) { \ const noref int it = _it; \ if (cond) { LAMBDA(body); } \ } \ MACRO_END #if defined(CSQC) - entity(entity start, .string fld, string match) _findstring = #18; - entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402; +entity(entity start, .string fld, string match) _findstring = #18; +entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402; - entity(entity start, .entity fld, entity match) _findentity = #98; - entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #403; +entity(entity start, .entity fld, entity match) _findentity = #98; +entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #403; - entity(entity start, .float fld, float match) _findfloat = #98; - entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403; +entity(entity start, .float fld, float match) _findfloat = #98; +entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403; - entity(entity start, .float fld, float match) _findflags = #449; - entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450; +entity(entity start, .float fld, float match) _findflags = #449; +entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450; #elif defined(SVQC) - entity(entity start, .string fld, string match) _findstring = #18; - entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402; +entity(entity start, .string fld, string match) _findstring = #18; +entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402; - entity(entity start, .entity fld, entity match) _findentity = #98; - entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #403; +entity(entity start, .entity fld, entity match) _findentity = #98; +entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #403; - entity(entity start, .float fld, float match) _findfloat = #98; - entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403; +entity(entity start, .float fld, float match) _findfloat = #98; +entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403; - entity(entity start, .float fld, float match) _findflags = #449; - entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450; +entity(entity start, .float fld, float match) _findflags = #449; +entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450; #elif defined(MENUQC) - entity(entity start, .string fld, string match) _findstring = #24; - entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #26; +entity(entity start, .string fld, string match) _findstring = #24; +entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #26; - entity(entity start, .entity fld, entity match) _findentity = #25; - entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #27; +entity(entity start, .entity fld, entity match) _findentity = #25; +entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #27; - entity(entity start, .float fld, float match) _findfloat = #25; - entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #27; +entity(entity start, .float fld, float match) _findfloat = #25; +entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #27; - entity(entity start, .float fld, float match) _findflags = #87; - entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #88; +entity(entity start, .float fld, float match) _findflags = #87; +entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #88; #endif #define ORDERED(F) F##_UNORDERED #define _FOREACH_ENTITY_FIND_ORDERED(T, fld, match, cond, body) \ - MACRO_BEGIN \ - int _i = 0; \ - for (entity _it = NULL; (_it = _find##T(_it, fld, match)); ++_i) \ - { \ - const noref int i = _i; \ - ITER_CONST noref entity it = _it; \ - if (cond) LAMBDA(body); \ - } \ - MACRO_END -#define MUTEX_LOCK(this) MACRO_BEGIN \ - if (this) LOG_SEVEREF("Loop mutex held by %s", this); \ - this = __FUNC__; \ -MACRO_END -#define MUTEX_UNLOCK(this) MACRO_BEGIN \ - this = string_null; \ -MACRO_END + MACRO_BEGIN \ + int _i = 0; \ + for (entity _it = NULL; (_it = _find##T(_it, fld, match)); ++_i) { \ + const noref int i = _i; \ + ITER_CONST noref entity it = _it; \ + if (cond) { LAMBDA(body); } \ + } \ + MACRO_END +#define MUTEX_LOCK(this) \ + MACRO_BEGIN \ + if (this) { LOG_SEVEREF("Loop mutex held by %s", this); } \ + this = __FUNC__; \ + MACRO_END +#define MUTEX_UNLOCK(this) \ + MACRO_BEGIN \ + this = string_null; \ + MACRO_END #define _FOREACH_ENTITY_FIND_UNORDERED(id, T, fld, match, cond, body) \ MACRO_BEGIN \ MUTEX_LOCK(_FOREACH_ENTITY_FIND_##T##_##id##mutex); \ @@ -138,55 +135,62 @@ MACRO_END #define FOREACH_ENTITY_ORDERED(cond, body) \ MACRO_BEGIN \ int _i = 0; \ - for (entity _it = NULL; (_it = nextent(_it)); ++_i) \ - { \ + for (entity _it = NULL; (_it = nextent(_it)); ++_i) { \ const noref int i = _i; \ ITER_CONST noref entity it = _it; \ - if (cond) LAMBDA(body); \ + if (cond) { LAMBDA(body); } \ } \ MACRO_END /** marker field, always NULL */ .entity _FOREACH_ENTITY_fld; -.entity _FOREACH_ENTITY_FIND_entity_nextall; noref string _FOREACH_ENTITY_FIND_entity_allmutex; +.entity _FOREACH_ENTITY_FIND_entity_nextall; +noref string _FOREACH_ENTITY_FIND_entity_allmutex; #define FOREACH_ENTITY_UNORDERED(cond, body) _FOREACH_ENTITY_FIND_UNORDERED(all, entity, _FOREACH_ENTITY_fld, NULL, cond, body) #define FOREACH_ENTITY_FLAGS(fld, match, body) ORDERED(FOREACH_ENTITY_FLAGS)(fld, match, body) #define FOREACH_ENTITY_FLAGS_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(flags, fld, match, true, body) -.entity _FOREACH_ENTITY_FIND_flags_next; noref string _FOREACH_ENTITY_FIND_flags_mutex; +.entity _FOREACH_ENTITY_FIND_flags_next; +noref string _FOREACH_ENTITY_FIND_flags_mutex; #define FOREACH_ENTITY_FLAGS_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, flags, fld, match, true, body) #ifdef GAMEQC entity(vector org, float rad, .entity tofield) _findchainradius_tofield = #22; #define FOREACH_ENTITY_RADIUS(org, dist, cond, body) ORDERED(FOREACH_ENTITY_RADIUS)(org, dist, cond, body) -.entity _FOREACH_ENTITY_FIND_radius_next; noref string _FOREACH_ENTITY_FIND_radius_mutex; +.entity _FOREACH_ENTITY_FIND_radius_next; +noref string _FOREACH_ENTITY_FIND_radius_mutex; #define FOREACH_ENTITY_RADIUS_UNORDERED(org, dist, cond, body) _FOREACH_ENTITY_FIND_UNORDERED(, radius, org, dist, cond, body) -.entity _FOREACH_ENTITY_FIND_radius_nexttmp; noref string _FOREACH_ENTITY_FIND_radius_tmpmutex; +.entity _FOREACH_ENTITY_FIND_radius_nexttmp; +noref string _FOREACH_ENTITY_FIND_radius_tmpmutex; #define FOREACH_ENTITY_RADIUS_ORDERED(org, dist, cond, body) \ -MACRO_BEGIN \ - entity _rev_first = NULL; \ - _FOREACH_ENTITY_FIND_UNORDERED(tmp, radius, org, dist, cond, (it._FOREACH_ENTITY_FIND_radius_nexttmp = _rev_first, _rev_first = it)); \ - MUTEX_LOCK(_FOREACH_ENTITY_FIND_radius_tmpmutex); \ - FOREACH_LIST(_rev, _FOREACH_ENTITY_FIND_radius_nexttmp, true, body); \ - MUTEX_UNLOCK(_FOREACH_ENTITY_FIND_radius_tmpmutex); \ -MACRO_END + MACRO_BEGIN \ + entity _rev_first = NULL; \ + _FOREACH_ENTITY_FIND_UNORDERED(tmp, radius, org, dist, cond, (it._FOREACH_ENTITY_FIND_radius_nexttmp = _rev_first, _rev_first = it)); \ + MUTEX_LOCK(_FOREACH_ENTITY_FIND_radius_tmpmutex); \ + FOREACH_LIST(_rev, _FOREACH_ENTITY_FIND_radius_nexttmp, true, body); \ + MUTEX_UNLOCK(_FOREACH_ENTITY_FIND_radius_tmpmutex); \ + MACRO_END #endif #define FOREACH_ENTITY_FLOAT(fld, match, body) ORDERED(FOREACH_ENTITY_FLOAT)(fld, match, body) #define FOREACH_ENTITY_FLOAT_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(float, fld, match, true, body) -.entity _FOREACH_ENTITY_FIND_float_next; noref string _FOREACH_ENTITY_FIND_float_mutex; +.entity _FOREACH_ENTITY_FIND_float_next; +noref string _FOREACH_ENTITY_FIND_float_mutex; #define FOREACH_ENTITY_FLOAT_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, float, fld, match, true, body) #define FOREACH_ENTITY_ENT(fld, match, body) ORDERED(FOREACH_ENTITY_ENT)(fld, match, body) #define FOREACH_ENTITY_ENT_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(entity, fld, match, true, body) -.entity _FOREACH_ENTITY_FIND_entity_next; noref string _FOREACH_ENTITY_FIND_entity_mutex; +.entity _FOREACH_ENTITY_FIND_entity_next; +noref string _FOREACH_ENTITY_FIND_entity_mutex; #define FOREACH_ENTITY_ENT_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, entity, fld, match, true, body) #define FOREACH_ENTITY_STRING(fld, match, body) ORDERED(FOREACH_ENTITY_STRING)(fld, match, body) #define FOREACH_ENTITY_STRING_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(string, fld, match, true, body) -.entity _FOREACH_ENTITY_FIND_string_next; noref string _FOREACH_ENTITY_FIND_string_mutex; +.entity _FOREACH_ENTITY_FIND_string_next; +noref string _FOREACH_ENTITY_FIND_string_mutex; #define FOREACH_ENTITY_STRING_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, string, fld, match, true, body) #define FOREACH_ENTITY_CLASS(class, cond, body) ORDERED(FOREACH_ENTITY_CLASS)(class, cond, body) #define FOREACH_ENTITY_CLASS_ORDERED(class, cond, body) _FOREACH_ENTITY_FIND_ORDERED(string, classname, class, cond, body) -.entity _FOREACH_ENTITY_FIND_string_nextclazz; noref string _FOREACH_ENTITY_FIND_string_clazzmutex; +.entity _FOREACH_ENTITY_FIND_string_nextclazz; +noref string _FOREACH_ENTITY_FIND_string_clazzmutex; #define FOREACH_ENTITY_CLASS_UNORDERED(class, cond, body) _FOREACH_ENTITY_FIND_UNORDERED(clazz, string, classname, class, cond, body) diff --git a/qcsrc/lib/json.qc b/qcsrc/lib/json.qc index 241b537aa..a1a9c4ec7 100644 --- a/qcsrc/lib/json.qc +++ b/qcsrc/lib/json.qc @@ -8,291 +8,320 @@ string _json_temp; /** parse a json object */ bool _json_parse_object(); - bool _json_parse_members(); - bool _json_parse_pair(); +bool _json_parse_members(); +bool _json_parse_pair(); bool _json_parse_array(); bool _json_parse_value(); - bool _json_parse_true(); - bool _json_parse_false(); - bool _json_parse_null(); +bool _json_parse_true(); +bool _json_parse_false(); +bool _json_parse_null(); bool _json_parse_string(bool add); bool _json_parse_number(); - bool _json_parse_float(); - bool _json_parse_int(); +bool _json_parse_float(); +bool _json_parse_int(); #define JSON_BEGIN() int __i = STRING_ITERATOR_SAVE(_json) #define JSON_FAIL(reason) goto fail #define JSON_END() \ - return true; \ -LABEL(fail) \ - STRING_ITERATOR_LOAD(_json, __i); \ - return false; + return true; \ + LABEL(fail) \ + STRING_ITERATOR_LOAD(_json, __i); \ + return false; // Current namespace string _json_ns; // Current keys int _json_keys; ERASEABLE -bool _json_parse_object() { - JSON_BEGIN(); - if (STRING_ITERATOR_GET(_json) != '{') JSON_FAIL("expected '{'"); - WITH(int, _json_keys, bufstr_add(_json_buffer, "", 0), _json_parse_members()); - if (STRING_ITERATOR_GET(_json) != '}') JSON_FAIL("expected '}'"); - JSON_END(); +bool _json_parse_object() +{ + JSON_BEGIN(); + if (STRING_ITERATOR_GET(_json) != '{') { JSON_FAIL("expected '{'"); } + WITH(int, _json_keys, bufstr_add(_json_buffer, "", 0), _json_parse_members()); + if (STRING_ITERATOR_GET(_json) != '}') { JSON_FAIL("expected '}'"); } + JSON_END(); } - ERASEABLE - bool _json_parse_members() { - JSON_BEGIN(); - for (;;) { - if (!_json_parse_pair()) JSON_FAIL("expected pair"); - if (STRING_ITERATOR_PEEK(_json) == ',') { - STRING_ITERATOR_NEXT(_json); - continue; - } - break; - } - JSON_END(); - } +ERASEABLE +bool _json_parse_members() +{ + JSON_BEGIN(); + for ( ; ; ) { + if (!_json_parse_pair()) { JSON_FAIL("expected pair"); } + if (STRING_ITERATOR_PEEK(_json) == ',') { + STRING_ITERATOR_NEXT(_json); + continue; + } + break; + } + JSON_END(); +} - ERASEABLE - bool _json_parse_pair() { - JSON_BEGIN(); - if (!_json_parse_string(false)) JSON_FAIL("expected string"); - string key = _json_temp; - bufstr_set(_json_buffer, _json_keys, cons(bufstr_get(_json_buffer, _json_keys), key)); - key = _json_ns ? strcat(_json_ns, ".", key) : key; - bufstr_add(_json_buffer, key, 0); - if (STRING_ITERATOR_GET(_json) != ':') JSON_FAIL("expected ':'"); - bool ret = false; WITH(string, _json_ns, key, ret = _json_parse_value()); - if (!ret) JSON_FAIL("expected value"); - JSON_END(); - } +ERASEABLE +bool _json_parse_pair() +{ + JSON_BEGIN(); + if (!_json_parse_string(false)) { JSON_FAIL("expected string"); } + string key = _json_temp; + bufstr_set(_json_buffer, _json_keys, cons(bufstr_get(_json_buffer, _json_keys), key)); + key = _json_ns ? strcat(_json_ns, ".", key) : key; + bufstr_add(_json_buffer, key, 0); + if (STRING_ITERATOR_GET(_json) != ':') { JSON_FAIL("expected ':'"); } + bool ret = false; + WITH(string, _json_ns, key, ret = _json_parse_value()); + if (!ret) { JSON_FAIL("expected value"); } + JSON_END(); +} ERASEABLE -bool _json_parse_array() { - JSON_BEGIN(); - if (STRING_ITERATOR_GET(_json) != '[') JSON_FAIL("expected '['"); - int len = bufstr_add(_json_buffer, "0", 0); - if (len) bufstr_set(_json_buffer, len - 1, strcat(bufstr_get(_json_buffer, len - 1), ".length")); - bool required = false; - for (int n = 0; ; n++) { - string key = ftos(n); - key = _json_ns ? strcat(_json_ns, ".", key) : key; - int it = bufstr_add(_json_buffer, key, 0); - bool ret = false; WITH(string, _json_ns, key, ret = _json_parse_value()); - if (!ret) { - bufstr_free(_json_buffer, it); - if (required) JSON_FAIL("expected value"); else break; - } - bufstr_set(_json_buffer, len, ftos(n + 1)); - if (STRING_ITERATOR_PEEK(_json) == ',') { - STRING_ITERATOR_NEXT(_json); - required = true; - continue; - } - break; - } - if (STRING_ITERATOR_GET(_json) != ']') JSON_FAIL("expected ']'"); - JSON_END(); +bool _json_parse_array() +{ + JSON_BEGIN(); + if (STRING_ITERATOR_GET(_json) != '[') { JSON_FAIL("expected '['"); } + int len = bufstr_add(_json_buffer, "0", 0); + if (len) { bufstr_set(_json_buffer, len - 1, strcat(bufstr_get(_json_buffer, len - 1), ".length")); } + bool required = false; + for (int n = 0; ; n++) { + string key = ftos(n); + key = _json_ns ? strcat(_json_ns, ".", key) : key; + int it = bufstr_add(_json_buffer, key, 0); + bool ret = false; + WITH(string, _json_ns, key, ret = _json_parse_value()); + if (!ret) { + bufstr_free(_json_buffer, it); + if (required) { JSON_FAIL("expected value"); } else { break; } + } + bufstr_set(_json_buffer, len, ftos(n + 1)); + if (STRING_ITERATOR_PEEK(_json) == ',') { + STRING_ITERATOR_NEXT(_json); + required = true; + continue; + } + break; + } + if (STRING_ITERATOR_GET(_json) != ']') { JSON_FAIL("expected ']'"); } + JSON_END(); } ERASEABLE -bool _json_parse_value() { - JSON_BEGIN(); - if (!(_json_parse_string(true) - || _json_parse_number() - || _json_parse_object() - || _json_parse_array() - || _json_parse_true() - || _json_parse_false() - || _json_parse_null())) JSON_FAIL("expected value"); - JSON_END(); +bool _json_parse_value() +{ + JSON_BEGIN(); + if (!(_json_parse_string(true) + || _json_parse_number() + || _json_parse_object() + || _json_parse_array() + || _json_parse_true() + || _json_parse_false() + || _json_parse_null())) { JSON_FAIL("expected value"); } + JSON_END(); } - ERASEABLE - bool _json_parse_true() { - JSON_BEGIN(); - if (!(STRING_ITERATOR_GET(_json) == 't' - && STRING_ITERATOR_GET(_json) == 'r' - && STRING_ITERATOR_GET(_json) == 'u' - && STRING_ITERATOR_GET(_json) == 'e')) - JSON_FAIL("expected 'true'"); - bufstr_add(_json_buffer, "1", 0); - JSON_END(); - } +ERASEABLE +bool _json_parse_true() +{ + JSON_BEGIN(); + if (!(STRING_ITERATOR_GET(_json) == 't' + && STRING_ITERATOR_GET(_json) == 'r' + && STRING_ITERATOR_GET(_json) == 'u' + && STRING_ITERATOR_GET(_json) == 'e')) { + JSON_FAIL("expected 'true'"); + } + bufstr_add(_json_buffer, "1", 0); + JSON_END(); +} - ERASEABLE - bool _json_parse_false() { - JSON_BEGIN(); - if (!(STRING_ITERATOR_GET(_json) == 'f' - && STRING_ITERATOR_GET(_json) == 'a' - && STRING_ITERATOR_GET(_json) == 'l' - && STRING_ITERATOR_GET(_json) == 's' - && STRING_ITERATOR_GET(_json) == 'e')) - JSON_FAIL("expected 'false'"); - bufstr_add(_json_buffer, "0", 0); - JSON_END(); - } +ERASEABLE +bool _json_parse_false() +{ + JSON_BEGIN(); + if (!(STRING_ITERATOR_GET(_json) == 'f' + && STRING_ITERATOR_GET(_json) == 'a' + && STRING_ITERATOR_GET(_json) == 'l' + && STRING_ITERATOR_GET(_json) == 's' + && STRING_ITERATOR_GET(_json) == 'e')) { + JSON_FAIL("expected 'false'"); + } + bufstr_add(_json_buffer, "0", 0); + JSON_END(); +} - ERASEABLE - bool _json_parse_null() { - JSON_BEGIN(); - if (!(STRING_ITERATOR_GET(_json) == 'n' - && STRING_ITERATOR_GET(_json) == 'u' - && STRING_ITERATOR_GET(_json) == 'l' - && STRING_ITERATOR_GET(_json) == 'l')) - JSON_FAIL("expected 'null'"); - bufstr_add(_json_buffer, "", 0); - JSON_END(); - } +ERASEABLE +bool _json_parse_null() +{ + JSON_BEGIN(); + if (!(STRING_ITERATOR_GET(_json) == 'n' + && STRING_ITERATOR_GET(_json) == 'u' + && STRING_ITERATOR_GET(_json) == 'l' + && STRING_ITERATOR_GET(_json) == 'l')) { + JSON_FAIL("expected 'null'"); + } + bufstr_add(_json_buffer, "", 0); + JSON_END(); +} ERASEABLE -bool _json_parse_string(bool add) { - JSON_BEGIN(); - if (STRING_ITERATOR_GET(_json) != '"') JSON_FAIL("expected opening '\"'"); - string s = ""; - for (int c; (c = STRING_ITERATOR_GET(_json)); ) { - if (c == '"') { - STRING_ITERATOR_UNGET(_json); - break; - } else if (c == '\\') { - string esc; - switch (STRING_ITERATOR_GET(_json)) { - default: - JSON_FAIL("expected ( '\"' | '\\' | 'n' | 't' )"); - case '"': esc = "\""; break; - case '\\': esc = "\\"; break; - case 'n': esc = "\n"; break; - case 't': esc = "\t"; break; - case 'u': esc = "\\u"; break; // TODO - case '/': esc = "/"; break; - } - s = strcat(s, esc); - } else { - s = strcat(s, chr2str(c)); - } - } - if (STRING_ITERATOR_GET(_json) != '"') JSON_FAIL("expected closing '\"'"); - if (add) bufstr_add(_json_buffer, s, 0); - _json_temp = s; - JSON_END(); +bool _json_parse_string(bool add) +{ + JSON_BEGIN(); + if (STRING_ITERATOR_GET(_json) != '"') { JSON_FAIL("expected opening '\"'"); } + string s = ""; + for (int c; (c = STRING_ITERATOR_GET(_json)); ) { + if (c == '"') { + STRING_ITERATOR_UNGET(_json); + break; + } else if (c == '\\') { + string esc; + switch (STRING_ITERATOR_GET(_json)) { + default: + JSON_FAIL("expected ( '\"' | '\\' | 'n' | 't' )"); + case '"': esc = "\""; + break; + case '\\': esc = "\\"; + break; + case 'n': esc = "\n"; + break; + case 't': esc = "\t"; + break; + case 'u': esc = "\\u"; + break; // TODO + case '/': esc = "/"; + break; + } + s = strcat(s, esc); + } else { + s = strcat(s, chr2str(c)); + } + } + if (STRING_ITERATOR_GET(_json) != '"') { JSON_FAIL("expected closing '\"'"); } + if (add) { bufstr_add(_json_buffer, s, 0); } + _json_temp = s; + JSON_END(); } ERASEABLE -bool _json_parse_number() { - JSON_BEGIN(); - if (!(_json_parse_float() || _json_parse_int())) JSON_FAIL("expected number"); - JSON_END(); +bool _json_parse_number() +{ + JSON_BEGIN(); + if (!(_json_parse_float() || _json_parse_int())) { JSON_FAIL("expected number"); } + JSON_END(); } - ERASEABLE - bool _json_parse_float() { - JSON_BEGIN(); - string s = ""; - bool needdot = true; - for (int c; (c = STRING_ITERATOR_GET(_json)); ) { - if (!(c >= '0' && c <= '9')) { - if (c == '.' && needdot) { - // fine - needdot = false; - } else { - STRING_ITERATOR_UNGET(_json); - break; - } - } - s = strcat(s, chr2str(c)); - } - if (s == "") JSON_FAIL("expected float"); - bufstr_add(_json_buffer, s, 0); - JSON_END(); - } +ERASEABLE +bool _json_parse_float() +{ + JSON_BEGIN(); + string s = ""; + bool needdot = true; + for (int c; (c = STRING_ITERATOR_GET(_json)); ) { + if (!(c >= '0' && c <= '9')) { + if (c == '.' && needdot) { + // fine + needdot = false; + } else { + STRING_ITERATOR_UNGET(_json); + break; + } + } + s = strcat(s, chr2str(c)); + } + if (s == "") { JSON_FAIL("expected float"); } + bufstr_add(_json_buffer, s, 0); + JSON_END(); +} - ERASEABLE - bool _json_parse_int() { - JSON_BEGIN(); - string s = ""; - for (int c; (c = STRING_ITERATOR_GET(_json)); ) { - if (!(c >= '0' && c <= '9')) { - STRING_ITERATOR_UNGET(_json); - break; - } - if (s == "" && c == '0') JSON_FAIL("expected [1-9]"); - s = strcat(s, chr2str(c)); - } - if (s == "") JSON_FAIL("expected int"); - if (ftos(stof(s)) != s) JSON_FAIL("expected int"); - bufstr_add(_json_buffer, s, 0); - JSON_END(); - } +ERASEABLE +bool _json_parse_int() +{ + JSON_BEGIN(); + string s = ""; + for (int c; (c = STRING_ITERATOR_GET(_json)); ) { + if (!(c >= '0' && c <= '9')) { + STRING_ITERATOR_UNGET(_json); + break; + } + if (s == "" && c == '0') { JSON_FAIL("expected [1-9]"); } + s = strcat(s, chr2str(c)); + } + if (s == "") { JSON_FAIL("expected int"); } + if (ftos(stof(s)) != s) { JSON_FAIL("expected int"); } + bufstr_add(_json_buffer, s, 0); + JSON_END(); +} ERASEABLE -int json_parse(string in, bool() func) { - string trimmed = ""; - LABEL(trim) { - int o = strstrofs(in, "\"", 0); - if (o >= 0) { - string part = substring(in, 0, o + 1); in = substring(in, o + 1, -1); - part = strreplace(" ", "", part); - part = strreplace("\n", "", part); - trimmed = strcat(trimmed, part); - goto trim_str; - } else { - string part = in; - part = strreplace(" ", "", part); - part = strreplace("\n", "", part); - trimmed = strcat(trimmed, part); - goto done; - } - } - LABEL(trim_str) { - int o = strstrofs(in, "\"", 0); - int esc = strstrofs(in, "\\\"", 0); - if (o < esc || esc < 0) { - // simple string - string part = substring(in, 0, o + 1); in = substring(in, o + 1, -1); - trimmed = strcat(trimmed, part); - goto trim; - } else { - // has escape - string part = substring(in, 0, esc + 2); in = substring(in, esc + 2, -1); - trimmed = strcat(trimmed, part); - goto trim_str; - } - } - LABEL(done); +int json_parse(string in, bool() func) +{ + string trimmed = ""; + LABEL(trim) + { + int o = strstrofs(in, "\"", 0); + if (o >= 0) { + string part = substring(in, 0, o + 1); + in = substring(in, o + 1, -1); + part = strreplace(" ", "", part); + part = strreplace("\n", "", part); + trimmed = strcat(trimmed, part); + goto trim_str; + } else { + string part = in; + part = strreplace(" ", "", part); + part = strreplace("\n", "", part); + trimmed = strcat(trimmed, part); + goto done; + } + } + LABEL(trim_str) + { + int o = strstrofs(in, "\"", 0); + int esc = strstrofs(in, "\\\"", 0); + if (o < esc || esc < 0) { + // simple string + string part = substring(in, 0, o + 1); + in = substring(in, o + 1, -1); + trimmed = strcat(trimmed, part); + goto trim; + } else { + // has escape + string part = substring(in, 0, esc + 2); + in = substring(in, esc + 2, -1); + trimmed = strcat(trimmed, part); + goto trim_str; + } + } + LABEL(done); - STRING_ITERATOR_SET(_json, trimmed, 0); - _json_buffer = buf_create(); - bool ret = func(); - if (!ret) { - buf_del(_json_buffer); - _json_buffer = -1; - } - return _json_buffer; + STRING_ITERATOR_SET(_json, trimmed, 0); + _json_buffer = buf_create(); + bool ret = func(); + if (!ret) { + buf_del(_json_buffer); + _json_buffer = -1; + } + return _json_buffer; } ERASEABLE string json_get(int buf, string key) { - for (int i = 1, n = buf_getsize(buf); i < n; i += 2) { - if (bufstr_get(buf, i) == key) return bufstr_get(buf, i + 1); - } - return string_null; + for (int i = 1, n = buf_getsize(buf); i < n; i += 2) { + if (bufstr_get(buf, i) == key) { return bufstr_get(buf, i + 1); } + } + return string_null; } ERASEABLE void json_del(int buf) { - buf_del(buf); + buf_del(buf); } ERASEABLE void json_dump(int buf) { - for (int i = 0, n = buf_getsize(buf); i < n; ++i) { - print(bufstr_get(buf, i), "\n"); - } + for (int i = 0, n = buf_getsize(buf); i < n; ++i) { + print(bufstr_get(buf, i), "\n"); + } } #undef JSON_BEGIN @@ -301,16 +330,16 @@ void json_dump(int buf) TEST(json, Parse) { - string s = "{\n\ + string s = "{\n\ \"m_string\": \"\\\"string\\\"\",\n\ \"m_int\": 123,\n\ \"m_bool\": true,\n\ \"m_null\": null,\n\ \"m_obj\": { },\n\ \"m_arr\": [ ]\n}"; // " - print(s, "\n"); - int buf = json_parse(s, _json_parse_object); - EXPECT_NE(-1, buf); - json_dump(buf); - SUCCEED(); + print(s, "\n"); + int buf = json_parse(s, _json_parse_object); + EXPECT_NE(-1, buf); + json_dump(buf); + SUCCEED(); } diff --git a/qcsrc/lib/linkedlist.qh b/qcsrc/lib/linkedlist.qh index e2194f574..a6c5f5d28 100644 --- a/qcsrc/lib/linkedlist.qh +++ b/qcsrc/lib/linkedlist.qh @@ -34,12 +34,11 @@ entity LL_PUSH(LinkedList this, entity e) entity LL_POP(LinkedList this) { assert(this); - if (!this.ll_tail) return NULL; + if (!this.ll_tail) { return NULL; } LinkedListNode n = this.ll_tail; entity e = n.ll_data; LinkedListNode prev = n.ll_prev; - if (prev) (this.ll_tail = prev).ll_next = NULL; - else this.ll_head = this.ll_tail = NULL; + if (prev) { (this.ll_tail = prev).ll_next = NULL; } else { this.ll_head = this.ll_tail = NULL; } delete(n); return e; } @@ -51,10 +50,9 @@ entity LL_POP(LinkedList this) MACRO_BEGIN \ LinkedList _ll = this; \ assert(_ll); \ - while (_ll.ll_tail) \ - { \ + while (_ll.ll_tail) { \ entity it = LL_POP(_ll); \ - if (!it) continue; \ + if (!it) { continue; } \ dtor \ delete(it); \ } \ @@ -73,8 +71,7 @@ entity LL_POP(LinkedList this) #define LL_EACH(list, cond, body) \ MACRO_BEGIN \ noref int i = 0; \ - for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i)) \ - { \ + for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i)) { \ ITER_CONST noref entity it = _it.ll_data; \ if (cond) { body } \ } \ diff --git a/qcsrc/lib/log.qh b/qcsrc/lib/log.qh index b751bfb2a..61879df3d 100644 --- a/qcsrc/lib/log.qh +++ b/qcsrc/lib/log.qh @@ -3,26 +3,24 @@ #include "progname.qh" #define assert(expr, ...) _assert(LOG_SEVERE, expr, __VA_ARGS__) -#define devassert(...) MACRO_BEGIN if (autocvar_developer) assert(__VA_ARGS__); MACRO_END +#define devassert(...) MACRO_BEGIN if (autocvar_developer) { assert(__VA_ARGS__); } MACRO_END #define assert_once(expr, ...) \ MACRO_BEGIN \ static bool __once; \ - if (!__once) \ - { \ + if (!__once) { \ assert(expr, __VA_ARGS__); \ __once = true; \ } \ MACRO_END -#define devassert_once(...) MACRO_BEGIN if (autocvar_developer) assert_once(__VA_ARGS__); MACRO_END +#define devassert_once(...) MACRO_BEGIN if (autocvar_developer) { assert_once(__VA_ARGS__); } MACRO_END #define demand(expr, ...) _assert(LOG_FATAL, expr, __VA_ARGS__) -#define devdemand(...) MACRO_BEGIN if (autocvar_developer) demand(__VA_ARGS__); MACRO_END +#define devdemand(...) MACRO_BEGIN if (autocvar_developer) { demand(__VA_ARGS__); } MACRO_END #define _assert(f, expr, then) \ MACRO_BEGIN \ - if (!(expr)) \ - { \ + if (!(expr)) { \ f("assertion failed: `" #expr "`\n"); \ then; \ } \ @@ -32,20 +30,20 @@ #if defined(MENUQC) -string(string, string...) strcat1n = #53; +string(string, string ...) strcat1n = #53; #else -string(string, string...) strcat1n = #115; +string(string, string ...) strcat1n = #115; #endif // would be nice if __FUNC__ could be concatenated at compile time #if 0 - // less work, bigger binary - #define __SOURCELOC__ (sprintf("^7%s^9" "(" "^9"__FILE__"^7" ":" "^9"STR(__LINE__)"^7" ")", __FUNC__)) +// less work, bigger binary + #define __SOURCELOC__ (sprintf("^7%s^9" "(" "^9"__FILE__ "^7" ":" "^9"STR (__LINE__)"^7" ")", __FUNC__)) #else #define __SOURCELOC__ (sprintf("^7%s^9" "(" "^9%s^7" ":" "^9%s^7" ")", __FUNC__, __FILE__, STR(__LINE__))) #endif -#define _LOG_HEADER(level) "^9[::" "^7"PROGNAME"^9" "::" level"^9" "] ", __SOURCELOC__ +#define _LOG_HEADER(level) "^9[::" "^7"PROGNAME "^9" "::" level "^9" "] ", __SOURCELOC__ #define _LOG(f, level, s) \ MACRO_BEGIN \ f(strcat1n(_LOG_HEADER(level), "\n^7", s, "\n")); \ @@ -84,7 +82,7 @@ string(string, string...) strcat1n = #115; #define dprint2(msg) \ MACRO_BEGIN \ - if (autocvar_developer > 1) dprint(msg); \ + if (autocvar_developer > 1) { dprint(msg); } \ MACRO_END // TODO: this sucks, lets find a better way to do backtraces? diff --git a/qcsrc/lib/map.qh b/qcsrc/lib/map.qh index ea7f0e1fe..21fe5cf40 100644 --- a/qcsrc/lib/map.qh +++ b/qcsrc/lib/map.qh @@ -8,14 +8,14 @@ ERASEABLE void db_save(int db, string filename) { int fh = fopen(filename, FILE_WRITE); - if (fh < 0) - { + if (fh < 0) { LOG_WARNF("^1Can't write DB to %s", filename); return; } fputs(fh, strcat(ftos(DB_BUCKETS), "\n")); - for (int i = 0, n = buf_getsize(db); i < n; ++i) + for (int i = 0, n = buf_getsize(db); i < n; ++i) { fputs(fh, strcat(bufstr_get(db, i), "\n")); + } fclose(fh); } @@ -35,31 +35,26 @@ ERASEABLE int db_load(string filename) { int db = buf_create(); - if (db < 0) return -1; + if (db < 0) { return -1; } int fh = fopen(filename, FILE_READ); - if (fh < 0) return db; + if (fh < 0) { return db; } string l = fgets(fh); - if (stoi(l) == DB_BUCKETS) - { - for (int i = 0; (l = fgets(fh)); ++i) - { - if (l != "") bufstr_set(db, i, l); + if (stoi(l) == DB_BUCKETS) { + for (int i = 0; (l = fgets(fh)); ++i) { + if (l != "") { bufstr_set(db, i, l); } } - } - else - { + } else { // different count of buckets, or a dump? // need to reorganize the database then (SLOW) // // note: we also parse the first line (l) in case the DB file is // missing the bucket count - do - { + do { int n = tokenizebyseparator(l, "\\"); - for (int j = 2; j < n; j += 2) + for (int j = 2; j < n; j += 2) { db_put(db, argv(j - 1), uri_unescape(argv(j))); - } - while ((l = fgets(fh))); + } + } while ((l = fgets(fh))); } fclose(fh); return db; @@ -69,13 +64,13 @@ ERASEABLE void db_dump(int db, string filename) { int fh = fopen(filename, FILE_WRITE); - if (fh < 0) LOG_FATALF("Can't dump DB to %s"); + if (fh < 0) { LOG_FATALF("Can't dump DB to %s"); } fputs(fh, "0\n"); - for (int i = 0, n = buf_getsize(db); i < n; ++i) - { + for (int i = 0, n = buf_getsize(db); i < n; ++i) { int m = tokenizebyseparator(bufstr_get(db, i), "\\"); - for (int j = 2; j < m; j += 2) + for (int j = 2; j < m; j += 2) { fputs(fh, strcat("\\", argv(j - 1), "\\", argv(j), "\n")); + } } fclose(fh); } @@ -108,15 +103,15 @@ void db_put(int db, string key, string value) /* void db_test() { - LOG_INFO("LOAD...\n"); - int db = db_load("foo.db"); - LOG_INFO("LOADED. FILL...\n"); - for (int i = 0; i < DB_BUCKETS; ++i) - db_put(db, ftos(random()), "X"); - LOG_INFO("FILLED. SAVE...\n"); - db_save(db, "foo.db"); - LOG_INFO("SAVED. CLOSE...\n"); - db_close(db); - LOG_INFO("CLOSED.\n"); + LOG_INFO("LOAD...\n"); + int db = db_load("foo.db"); + LOG_INFO("LOADED. FILL...\n"); + for (int i = 0; i < DB_BUCKETS; ++i) + db_put(db, ftos(random()), "X"); + LOG_INFO("FILLED. SAVE...\n"); + db_save(db, "foo.db"); + LOG_INFO("SAVED. CLOSE...\n"); + db_close(db); + LOG_INFO("CLOSED.\n"); } */ diff --git a/qcsrc/lib/markdown.qh b/qcsrc/lib/markdown.qh index a3bffeaae..3cda3a376 100644 --- a/qcsrc/lib/markdown.qh +++ b/qcsrc/lib/markdown.qh @@ -14,7 +14,7 @@ string markdown(string s) FOREACH_CHAR(s, true, { switch (it) { default: - for (; spaces > 0; --spaces) { + for ( ; spaces > 0; --spaces) { buf = strcat(buf, " "); } buf = strcat(buf, chr2str(it)); @@ -44,7 +44,8 @@ string markdown(string s) TEST(Markdown, LineWrap) { - #define X(expect, in) MACRO_BEGIN \ + #define X(expect, in) \ + MACRO_BEGIN \ string out = markdown(in); \ EXPECT_TRUE(expect == out); \ LOG_INFO(expect); \ diff --git a/qcsrc/lib/matrix/command.qc b/qcsrc/lib/matrix/command.qc index 449aa373b..e72d7cba9 100644 --- a/qcsrc/lib/matrix/command.qc +++ b/qcsrc/lib/matrix/command.qc @@ -2,47 +2,48 @@ #include -GENERIC_COMMAND(mx, "Send a matrix command") { - switch (argv(1)) { - case "user": - if (matrix_user) strunzone(matrix_user); - matrix_user = strzone(substring(command, argv_start_index(2), -1)); - break; - case "token": - if (matrix_access_token) strunzone(matrix_access_token); - matrix_access_token = strzone(substring(command, argv_start_index(2), -1)); - break; - case "messages": - MX_Messages(string_null); - break; - case "nick": - MX_Nick(substring(command, argv_start_index(2), -1)); - break; - case "join": - string s = substring(command, argv_start_index(2), -1); - if (s != matrix_room && matrix_room != "") { - MX_Leave(matrix_room); - strunzone(matrix_room); - } - matrix_room = strzone(s); - MX_Join(matrix_room); - break; - case "sync": - MX_Sync(string_null); - break; - case "typing": - MX_Typing(true); - break; - case "say": - MX_Say(substring(command, argv_start_index(2), -1)); - break; - case "leave": - MX_Leave(matrix_room); - matrix_room = string_null; - break; - case "forget": - MX_Forget(matrix_room); - matrix_room = ""; - break; - } +GENERIC_COMMAND(mx, "Send a matrix command") +{ + switch (argv(1)) { + case "user": + if (matrix_user) { strunzone(matrix_user); } + matrix_user = strzone(substring(command, argv_start_index(2), -1)); + break; + case "token": + if (matrix_access_token) { strunzone(matrix_access_token); } + matrix_access_token = strzone(substring(command, argv_start_index(2), -1)); + break; + case "messages": + MX_Messages(string_null); + break; + case "nick": + MX_Nick(substring(command, argv_start_index(2), -1)); + break; + case "join": + string s = substring(command, argv_start_index(2), -1); + if (s != matrix_room && matrix_room != "") { + MX_Leave(matrix_room); + strunzone(matrix_room); + } + matrix_room = strzone(s); + MX_Join(matrix_room); + break; + case "sync": + MX_Sync(string_null); + break; + case "typing": + MX_Typing(true); + break; + case "say": + MX_Say(substring(command, argv_start_index(2), -1)); + break; + case "leave": + MX_Leave(matrix_room); + matrix_room = string_null; + break; + case "forget": + MX_Forget(matrix_room); + matrix_room = ""; + break; + } } diff --git a/qcsrc/lib/matrix/matrix.qc b/qcsrc/lib/matrix/matrix.qc index c399c2aa6..1ea79f113 100644 --- a/qcsrc/lib/matrix/matrix.qc +++ b/qcsrc/lib/matrix/matrix.qc @@ -5,208 +5,221 @@ void MX_Nick_(entity fh, entity pass, int status); void MX_Nick(string name) { - if (!matrix_access_token) return; - entity pass = new_pure(mx); - pass.message = name; - url_single_fopen( - sprintf("%s/_matrix/client/r0/profile/%s/displayname?access_token=%s", autocvar_matrix_server, matrix_user, matrix_access_token), - FILE_WRITE, - MX_Nick_, - pass - ); + if (!matrix_access_token) { return; } + entity pass = new_pure(mx); + pass.message = name; + url_single_fopen( + sprintf("%s/_matrix/client/r0/profile/%s/displayname?access_token=%s", autocvar_matrix_server, matrix_user, matrix_access_token), + FILE_WRITE, + MX_Nick_, + pass + ); } void MX_Nick_(entity fh, entity pass, int status) { - switch (status) { - case URL_READY_CANWRITE: { - fh.url_verb = "PUT"; - fh.url_content_type = "application/json"; - url_fputs(fh, sprintf("{\"displayname\": \"%s\"}", pass.message)); - delete(pass); - url_fclose(fh); - break; - } - } + switch (status) { + case URL_READY_CANWRITE: + { + fh.url_verb = "PUT"; + fh.url_content_type = "application/json"; + url_fputs(fh, sprintf("{\"displayname\": \"%s\"}", pass.message)); + delete(pass); + url_fclose(fh); + break; + } + } } void MX_Messages_(entity fh, entity pass, int status); void MX_Messages(string from) { - if (!matrix_access_token) return; - string s = sprintf("%s/_matrix/client/r0/events?room_id=%s&limit=50&timeout=30000&from=%s&access_token=%s", autocvar_matrix_server, matrix_room, from, matrix_access_token); - url_single_fopen( - s, - FILE_READ, - MX_Messages_, - NULL - ); + if (!matrix_access_token) { return; } + string s = sprintf("%s/_matrix/client/r0/events?room_id=%s&limit=50&timeout=30000&from=%s&access_token=%s", autocvar_matrix_server, matrix_room, from, matrix_access_token); + url_single_fopen( + s, + FILE_READ, + MX_Messages_, + NULL + ); } void MX_Messages_(entity fh, entity pass, int status) { - switch (status) { - default: { - LOG_WARNF("status: %d", status); - break; - } - case URL_READY_CLOSED: break; - case URL_READY_CANREAD: { - string json = ""; - for (string s; (s = url_fgets(fh)); ) { json = strcat(json, s, "\n"); } - url_fclose(fh); - int buf = json_parse(json, _json_parse_object); - EXPECT_NE(-1, buf); - for (int i = 0, n = stof(json_get(buf, "chunk.length")); i < n; ++i) { - MX_Handle(buf, sprintf("chunk.%d", i)); - } - MX_Messages(json_get(buf, "end")); - break; - } - } + switch (status) { + default: + { + LOG_WARNF("status: %d", status); + break; + } + case URL_READY_CLOSED: break; + case URL_READY_CANREAD: + { + string json = ""; + for (string s; (s = url_fgets(fh)); ) { + json = strcat(json, s, "\n"); + } + url_fclose(fh); + int buf = json_parse(json, _json_parse_object); + EXPECT_NE(-1, buf); + for (int i = 0, n = stof(json_get(buf, "chunk.length")); i < n; ++i) { + MX_Handle(buf, sprintf("chunk.%d", i)); + } + MX_Messages(json_get(buf, "end")); + break; + } + } } void MX_Sync_(entity fh, entity pass, int status); void MX_Sync(string since) { - if (!matrix_access_token) return; - string s = strcat(autocvar_matrix_server, "/_matrix/client/r0/sync?"); - if (since) { - s = strcat(s, - "since=", since, "&", - "timeout=30000&", - sprintf("filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[\"%s\"]}}&", matrix_room) - ); - } else { - s = strcat(s, - "timeout=0&", - "filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[]}}&" - ); - } - s = strcat(s, "access_token=", matrix_access_token); - url_single_fopen(s, FILE_READ, MX_Sync_, NULL); + if (!matrix_access_token) { return; } + string s = strcat(autocvar_matrix_server, "/_matrix/client/r0/sync?"); + if (since) { + s = strcat(s, + "since=", since, "&", + "timeout=30000&", + sprintf("filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[\"%s\"]}}&", matrix_room) + ); + } else { + s = strcat(s, + "timeout=0&", + "filter={\"account_data\":{\"types\":[]},\"presence\":{\"types\":[]},\"room\":{\"rooms\":[]}}&" + ); + } + s = strcat(s, "access_token=", matrix_access_token); + url_single_fopen(s, FILE_READ, MX_Sync_, NULL); } void MX_Sync_(entity fh, entity pass, int status) { - switch (status) { - default: { - LOG_WARNF("status: %d", status); - break; - } - case URL_READY_CLOSED: break; - case URL_READY_CANREAD: { - string json = ""; - for (string s; (s = url_fgets(fh)); ) { json = strcat(json, s, "\n"); } - url_fclose(fh); - int buf = json_parse(json, _json_parse_object); - EXPECT_NE(-1, buf); - string arr = sprintf("rooms.join.%s.timeline.events", matrix_room); - for (int i = 0, n = stof(json_get(buf, sprintf("%s.length", arr))); i < n; ++i) { - MX_Handle(buf, sprintf("%s.%d", arr, i)); - } - MX_Sync(json_get(buf, "next_batch")); - break; - } - } + switch (status) { + default: + { + LOG_WARNF("status: %d", status); + break; + } + case URL_READY_CLOSED: break; + case URL_READY_CANREAD: + { + string json = ""; + for (string s; (s = url_fgets(fh)); ) { + json = strcat(json, s, "\n"); + } + url_fclose(fh); + int buf = json_parse(json, _json_parse_object); + EXPECT_NE(-1, buf); + string arr = sprintf("rooms.join.%s.timeline.events", matrix_room); + for (int i = 0, n = stof(json_get(buf, sprintf("%s.length", arr))); i < n; ++i) { + MX_Handle(buf, sprintf("%s.%d", arr, i)); + } + MX_Sync(json_get(buf, "next_batch")); + break; + } + } } void MX_JLF_(entity fh, entity pass, int status); void MX_Join(string room) { - if (!matrix_access_token) return; - url_single_fopen( - sprintf("%s/_matrix/client/r0/rooms/%s/join?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token), - FILE_WRITE, - MX_JLF_, - NULL - ); + if (!matrix_access_token) { return; } + url_single_fopen( + sprintf("%s/_matrix/client/r0/rooms/%s/join?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token), + FILE_WRITE, + MX_JLF_, + NULL + ); } void MX_Leave(string room) { - if (!matrix_access_token) return; - url_single_fopen( - sprintf("%s/_matrix/client/r0/rooms/%s/leave?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token), - FILE_WRITE, - MX_JLF_, - NULL - ); + if (!matrix_access_token) { return; } + url_single_fopen( + sprintf("%s/_matrix/client/r0/rooms/%s/leave?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token), + FILE_WRITE, + MX_JLF_, + NULL + ); } void MX_Forget(string room) { - if (!matrix_access_token) return; - url_single_fopen( - sprintf("%s/_matrix/client/r0/rooms/%s/forget?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token), - FILE_WRITE, - MX_JLF_, - NULL - ); + if (!matrix_access_token) { return; } + url_single_fopen( + sprintf("%s/_matrix/client/r0/rooms/%s/forget?access_token=%s", autocvar_matrix_server, matrix_room, matrix_access_token), + FILE_WRITE, + MX_JLF_, + NULL + ); } void MX_JLF_(entity fh, entity pass, int status) { - switch (status) { - case URL_READY_CANWRITE: { - fh.url_content_type = "application/json"; - url_fputs(fh, sprintf("{}", pass.message)); - url_fclose(fh); - break; - } - } + switch (status) { + case URL_READY_CANWRITE: + { + fh.url_content_type = "application/json"; + url_fputs(fh, sprintf("{}", pass.message)); + url_fclose(fh); + break; + } + } } void MX_Typing_(entity fh, entity pass, int status); void MX_Typing(bool state) { - if (!matrix_access_token) return; - entity pass = new_pure(mx); - pass.message = state ? "true" : "false"; - url_single_fopen( - sprintf("%s/_matrix/client/r0/rooms/%s/typing/%s?access_token=%s", autocvar_matrix_server, matrix_room, matrix_user, matrix_access_token), - FILE_WRITE, - MX_Typing_, - pass - ); + if (!matrix_access_token) { return; } + entity pass = new_pure(mx); + pass.message = state ? "true" : "false"; + url_single_fopen( + sprintf("%s/_matrix/client/r0/rooms/%s/typing/%s?access_token=%s", autocvar_matrix_server, matrix_room, matrix_user, matrix_access_token), + FILE_WRITE, + MX_Typing_, + pass + ); } void MX_Typing_(entity fh, entity pass, int status) { - switch (status) { - case URL_READY_CANWRITE: { - fh.url_verb = "PUT"; - fh.url_content_type = "application/json"; - url_fputs(fh, sprintf("{\"typing\": %s, \"timeout\": 30000}", pass.message)); - delete(pass); - url_fclose(fh); - break; - } - } + switch (status) { + case URL_READY_CANWRITE: + { + fh.url_verb = "PUT"; + fh.url_content_type = "application/json"; + url_fputs(fh, sprintf("{\"typing\": %s, \"timeout\": 30000}", pass.message)); + delete(pass); + url_fclose(fh); + break; + } + } } void MX_Say_(entity fh, entity pass, int status); void MX_Say(string body) { - if (!matrix_access_token) return; - static int txnid; - entity pass = new_pure(mx); - pass.message = strzone(body); - url_single_fopen( - sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message/%d?access_token=%s", autocvar_matrix_server, matrix_room, ++txnid, matrix_access_token), - FILE_WRITE, - MX_Say_, - pass - ); + if (!matrix_access_token) { return; } + static int txnid; + entity pass = new_pure(mx); + pass.message = strzone(body); + url_single_fopen( + sprintf("%s/_matrix/client/r0/rooms/%s/send/m.room.message/%d?access_token=%s", autocvar_matrix_server, matrix_room, ++txnid, matrix_access_token), + FILE_WRITE, + MX_Say_, + pass + ); } void MX_Say_(entity fh, entity pass, int status) { - switch (status) { - case URL_READY_CANWRITE: { - fh.url_verb = "PUT"; - fh.url_content_type = "application/json"; - url_fputs(fh, sprintf("{\"msgtype\": \"m.text\", \"body\": \"%s\"}", pass.message)); - strunzone(pass.message); delete(pass); - url_fclose(fh); - break; - } - } + switch (status) { + case URL_READY_CANWRITE: + { + fh.url_verb = "PUT"; + fh.url_content_type = "application/json"; + url_fputs(fh, sprintf("{\"msgtype\": \"m.text\", \"body\": \"%s\"}", pass.message)); + strunzone(pass.message); + delete(pass); + url_fclose(fh); + break; + } + } } diff --git a/qcsrc/lib/nil.qh b/qcsrc/lib/nil.qh index 77a1e770b..58c3d3200 100644 --- a/qcsrc/lib/nil.qh +++ b/qcsrc/lib/nil.qh @@ -5,6 +5,6 @@ #define string_null nil #else // the NULL function - var void func_null(); - string string_null; +var void func_null(); +string string_null; #endif diff --git a/qcsrc/lib/noise.qh b/qcsrc/lib/noise.qh index 53026be4d..cf427f0e7 100644 --- a/qcsrc/lib/noise.qh +++ b/qcsrc/lib/noise.qh @@ -11,7 +11,7 @@ class(Noise).float noise_bstate; ERASEABLE float Noise_Brown(entity e, float dt) { - e.noise_baccum += random() * sqrt(dt); // same stddev for all dt + e.noise_baccum += random() * sqrt(dt); // same stddev for all dt return e.noise_baccum; } ERASEABLE @@ -20,9 +20,9 @@ float Noise_Pink(entity e, float dt) float f; f = dt * 60; // http://home.earthlink.net/~ltrammell/tech/pinkalg.htm - if (random() > POW(0.3190, f)) e.noise_paccum = 0.34848 * (2 * random() - 1); - if (random() > POW(0.7756, f)) e.noise_paccum2 = 0.28768 * (2 * random() - 1); - if (random() > POW(0.9613, f)) e.noise_paccum3 = 0.43488 * (2 * random() - 1); + if (random() > POW(0.3190, f)) { e.noise_paccum = 0.34848 * (2 * random() - 1); } + if (random() > POW(0.7756, f)) { e.noise_paccum2 = 0.28768 * (2 * random() - 1); } + if (random() > POW(0.9613, f)) { e.noise_paccum3 = 0.43488 * (2 * random() - 1); } return e.noise_paccum + e.noise_paccum2 + e.noise_paccum3; } ERASEABLE @@ -34,6 +34,6 @@ float Noise_White(entity e, float dt) ERASEABLE float Noise_Burst(entity e, float dt, float p) { - if (random() > POW(p, dt)) e.noise_bstate = !e.noise_bstate; + if (random() > POW(p, dt)) { e.noise_bstate = !e.noise_bstate; } return 2 * e.noise_bstate - 1; } diff --git a/qcsrc/lib/p2mathlib.qc b/qcsrc/lib/p2mathlib.qc index ce6f7ea89..8d527d4d4 100644 --- a/qcsrc/lib/p2mathlib.qc +++ b/qcsrc/lib/p2mathlib.qc @@ -72,9 +72,8 @@ vector vec_bounds_out(vector point, vector a, vector b) ERASEABLE float angle_snap_f(float f, float increment) { - for (int j = 0; j <= 360; ) - { - if (f <= j - increment) return j - increment; + for (int j = 0; j <= 360; ) { + if (f <= j - increment) { return j - increment; } j = j + increment; } diff --git a/qcsrc/lib/p99.qh b/qcsrc/lib/p99.qh index 927410cde..961e15959 100644 --- a/qcsrc/lib/p99.qh +++ b/qcsrc/lib/p99.qh @@ -16,69 +16,71 @@ #define P99_MAX_NUMBER 16 #define P00_ARG( \ - _01, _02, _03, _04, _05, _06, _07, _08, \ - _09, _10, _11, _12, _13, _14, _15, _16, \ - _00, ...) _00 -#define P00_NARG(...) P00_ARG(__VA_ARGS__, \ - 16, 15, 14, 13, 12, 11, 10, 9, \ - 8, 7, 6, 5, 4, 3, 2, 1, \ - 0, ) -#define P99_HAS_COMMA(...) P00_ARG(__VA_ARGS__, \ - 1, 1, 1, 1, 1, 1, 1, 1, \ - 1, 1, 1, 1, 1, 1, 1, 0, \ - 0) + _01, _02, _03, _04, _05, _06, _07, _08, \ + _09, _10, _11, _12, _13, _14, _15, _16, \ + _00, ...) _00 +#define P00_NARG(...) \ + P00_ARG(__VA_ARGS__, \ + 16, 15, 14, 13, 12, 11, 10, 9, \ + 8, 7, 6, 5, 4, 3, 2, 1, \ + 0, ) +#define P99_HAS_COMMA(...) \ + P00_ARG(__VA_ARGS__, \ + 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 1, 1, 1, 1, 1, 0, \ + 0) #define P99_IF_EMPTY(...) P99_IF_EQ(1, P99_IS_EMPTY(__VA_ARGS__)) - // P99_HAS_COMMA(__VA_ARGS__), : test if there is just one argument, that might be empty - // P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__), : test if P99_IS__EQ__ together with the argument adds a comma - // P99_HAS_COMMA(__VA_ARGS__ (/*empty*/)), : test if the argument together with a parenthesis adds a comma - // P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__ (/*empty*/)) : test if placing it between P99_IS__EQ__ and the parenthesis adds a comma - #define P99_IS_EMPTY(...) \ - P00_ISEMPTY( \ - P99_HAS_COMMA(__VA_ARGS__), \ - P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__), \ - P99_HAS_COMMA(__VA_ARGS__ (/*empty*/)), \ - P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__ (/*empty*/)) \ - ) - #define P00_IS__EQ__(...) , - #define P00_ISEMPTY(_1, _2, _3, _4) P99_HAS_COMMA(P99_PASTE5(P00_IS_EMPTY_CASE_, _1, _2, _3, _4)) - #define P00_IS_EMPTY_CASE_0000 P00_IS_EMPTY_CASE_0000 - #define P00_IS_EMPTY_CASE_0001 , - #define P00_IS_EMPTY_CASE_0010 P00_IS_EMPTY_CASE_0010 - #define P00_IS_EMPTY_CASE_0011 P00_IS_EMPTY_CASE_0011 - #define P00_IS_EMPTY_CASE_0100 P00_IS_EMPTY_CASE_0100 - #define P00_IS_EMPTY_CASE_0101 P00_IS_EMPTY_CASE_0101 - #define P00_IS_EMPTY_CASE_0110 P00_IS_EMPTY_CASE_0110 - #define P00_IS_EMPTY_CASE_0111 P00_IS_EMPTY_CASE_0111 - #define P00_IS_EMPTY_CASE_1000 P00_IS_EMPTY_CASE_1000 - #define P00_IS_EMPTY_CASE_1001 P00_IS_EMPTY_CASE_1001 - #define P00_IS_EMPTY_CASE_1010 P00_IS_EMPTY_CASE_1010 - #define P00_IS_EMPTY_CASE_1011 P00_IS_EMPTY_CASE_1011 - #define P00_IS_EMPTY_CASE_1100 P00_IS_EMPTY_CASE_1100 - #define P00_IS_EMPTY_CASE_1101 P00_IS_EMPTY_CASE_1101 - #define P00_IS_EMPTY_CASE_1110 P00_IS_EMPTY_CASE_1110 - #define P00_IS_EMPTY_CASE_1111 P00_IS_EMPTY_CASE_1111 +// P99_HAS_COMMA(__VA_ARGS__), : test if there is just one argument, that might be empty +// P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__), : test if P99_IS__EQ__ together with the argument adds a comma +// P99_HAS_COMMA(__VA_ARGS__ (/*empty*/)), : test if the argument together with a parenthesis adds a comma +// P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__ (/*empty*/)) : test if placing it between P99_IS__EQ__ and the parenthesis adds a comma + #define P99_IS_EMPTY(...) \ + P00_ISEMPTY( \ + P99_HAS_COMMA(__VA_ARGS__), \ + P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__), \ + P99_HAS_COMMA(__VA_ARGS__( /*empty*/)), \ + P99_HAS_COMMA(P00_IS__EQ__ __VA_ARGS__( /*empty*/)) \ + ) + #define P00_IS__EQ__(...) , + #define P00_ISEMPTY(_1, _2, _3, _4) P99_HAS_COMMA(P99_PASTE5(P00_IS_EMPTY_CASE_, _1, _2, _3, _4)) + #define P00_IS_EMPTY_CASE_0000 P00_IS_EMPTY_CASE_0000 + #define P00_IS_EMPTY_CASE_0001 , + #define P00_IS_EMPTY_CASE_0010 P00_IS_EMPTY_CASE_0010 + #define P00_IS_EMPTY_CASE_0011 P00_IS_EMPTY_CASE_0011 + #define P00_IS_EMPTY_CASE_0100 P00_IS_EMPTY_CASE_0100 + #define P00_IS_EMPTY_CASE_0101 P00_IS_EMPTY_CASE_0101 + #define P00_IS_EMPTY_CASE_0110 P00_IS_EMPTY_CASE_0110 + #define P00_IS_EMPTY_CASE_0111 P00_IS_EMPTY_CASE_0111 + #define P00_IS_EMPTY_CASE_1000 P00_IS_EMPTY_CASE_1000 + #define P00_IS_EMPTY_CASE_1001 P00_IS_EMPTY_CASE_1001 + #define P00_IS_EMPTY_CASE_1010 P00_IS_EMPTY_CASE_1010 + #define P00_IS_EMPTY_CASE_1011 P00_IS_EMPTY_CASE_1011 + #define P00_IS_EMPTY_CASE_1100 P00_IS_EMPTY_CASE_1100 + #define P00_IS_EMPTY_CASE_1101 P00_IS_EMPTY_CASE_1101 + #define P00_IS_EMPTY_CASE_1110 P00_IS_EMPTY_CASE_1110 + #define P00_IS_EMPTY_CASE_1111 P00_IS_EMPTY_CASE_1111 #define P00_IF_CLAUSE(EXP) P00__IF_CLAUSE(EXP, P00_CLAUSE1, P00_CLAUSE2, ~) - #define P00__IF_CLAUSE(A, B, C, ...) C - #define P00_CLAUSE1(...) __VA_ARGS__ P00_IGNORE - #define P00_IGNORE(...) - #define P00_CLAUSE2(...) P00_IDENT - #define P00_IDENT(...) __VA_ARGS__ + #define P00__IF_CLAUSE(A, B, C, ...) C + #define P00_CLAUSE1(...) __VA_ARGS__ P00_IGNORE + #define P00_IGNORE(...) + #define P00_CLAUSE2(...) P00_IDENT + #define P00_IDENT(...) __VA_ARGS__ #define P99_IF_EQ(A, B) P00_IF_CLAUSE(P99_PASTE4(P00_IS_, A, _EQ_, B)()) - #define P00_IS_0_EQ_0(...) , - #define P00_IS_1_EQ_1(...) , + #define P00_IS_0_EQ_0(...) , + #define P00_IS_1_EQ_1(...) , -#define P99_CAT2(_1, _2) _1 ## _2 +#define P99_CAT2(_1, _2) _1##_2 #define P99_PASTE2(_1, _2) \ - P99_CAT2(_1, _2) + P99_CAT2(_1, _2) #define P99_PASTE3(_1, _2, _3) \ - P99_PASTE2(P99_PASTE2(_1, _2), _3) + P99_PASTE2(P99_PASTE2(_1, _2), _3) #define P99_PASTE4(_1, _2, _3, _4) \ - P99_PASTE2(P99_PASTE3(_1, _2, _3), _4) + P99_PASTE2(P99_PASTE3(_1, _2, _3), _4) #define P99_PASTE5(_1, _2, _3, _4, _5) \ - P99_PASTE2(P99_PASTE4(_1, _2, _3, _4), _5) + P99_PASTE2(P99_PASTE4(_1, _2, _3, _4), _5) diff --git a/qcsrc/lib/random.qc b/qcsrc/lib/random.qc index a5ff69356..a675ee727 100644 --- a/qcsrc/lib/random.qc +++ b/qcsrc/lib/random.qc @@ -13,20 +13,16 @@ void RandomSelection_Init() ERASEABLE void RandomSelection_Add(entity e, float f, string s, vector v, float weight, float priority) { - if (priority > RandomSelection_best_priority) - { + if (priority > RandomSelection_best_priority) { RandomSelection_best_priority = priority; RandomSelection_chosen_ent = e; RandomSelection_chosen_float = f; RandomSelection_chosen_string = s; RandomSelection_chosen_vec = v; RandomSelection_totalweight = weight; - } - else if (priority == RandomSelection_best_priority) - { + } else if (priority == RandomSelection_best_priority) { RandomSelection_totalweight += weight; - if (random() * RandomSelection_totalweight <= weight) - { + if (random() * RandomSelection_totalweight <= weight) { RandomSelection_chosen_ent = e; RandomSelection_chosen_float = f; RandomSelection_chosen_string = s; @@ -41,12 +37,10 @@ float DistributeEvenly_totalweight; ERASEABLE void DistributeEvenly_Init(float amount, float totalweight) { - if (DistributeEvenly_amount) - { + if (DistributeEvenly_amount) { LOG_TRACE("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ", ftos(DistributeEvenly_totalweight), " left!)"); } - if (totalweight == 0) DistributeEvenly_amount = 0; - else DistributeEvenly_amount = amount; + if (totalweight == 0) { DistributeEvenly_amount = 0; } else { DistributeEvenly_amount = amount; } DistributeEvenly_totalweight = totalweight; } @@ -54,7 +48,7 @@ ERASEABLE float DistributeEvenly_Get(float weight) { float f; - if (weight <= 0) return 0; + if (weight <= 0) { return 0; } f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight); DistributeEvenly_totalweight -= weight; DistributeEvenly_amount -= f; @@ -65,7 +59,7 @@ ERASEABLE float DistributeEvenly_GetRandomized(float weight) { float f; - if (weight <= 0) return 0; + if (weight <= 0) { return 0; } f = floor(random() + DistributeEvenly_amount * weight / DistributeEvenly_totalweight); DistributeEvenly_totalweight -= weight; DistributeEvenly_amount -= f; @@ -78,13 +72,10 @@ float gsl_ran_gaussian_lastvalue_set; ERASEABLE float gsl_ran_gaussian(float sigma) { - if (gsl_ran_gaussian_lastvalue_set) - { + if (gsl_ran_gaussian_lastvalue_set) { gsl_ran_gaussian_lastvalue_set = 0; return sigma * gsl_ran_gaussian_lastvalue; - } - else - { + } else { float a = random() * 2 * M_PI; float b = sqrt(-2 * log(random())); gsl_ran_gaussian_lastvalue = cos(a) * b; @@ -96,47 +87,45 @@ float gsl_ran_gaussian(float sigma) // prandom - PREDICTABLE random number generator (not seeded yet) #ifdef USE_PRANDOM - float prandom_seed; - float prandom() - { - float c; - c = crc16(false, strcat(ftos(prandom_seed), ftos(prandom_seed + M_PI))); - prandom_seed = c; +float prandom_seed; +float prandom() +{ + float c; + c = crc16(false, strcat(ftos(prandom_seed), ftos(prandom_seed + M_PI))); + prandom_seed = c; #ifdef USE_PRANDOM_DEBUG - LOG_TRACE("RANDOM -> ", ftos(c)); + LOG_TRACE("RANDOM -> ", ftos(c)); #endif - return c / 65536; // in [0..1[ - } + return c / 65536; // in [0..1[ +} - vector prandomvec() - { - vector v; +vector prandomvec() +{ + vector v; - do - { - v.x = prandom(); - v.y = prandom(); - v.z = prandom(); - } - while (v * v > 1); + do { + v.x = prandom(); + v.y = prandom(); + v.z = prandom(); + } while (v * v > 1); - return v; - } + return v; +} - void psrandom(float seed) - { - prandom_seed = seed; +void psrandom(float seed) +{ + prandom_seed = seed; #ifdef USE_PRANDOM_DEBUG - LOG_TRACE("SRANDOM ", ftos(seed)); + LOG_TRACE("SRANDOM ", ftos(seed)); #endif - } +} #ifdef USE_PRANDOM_DEBUG - void prandom_debug() - { - LOG_TRACE("Current random seed = ", ftos(prandom_seed)); - } +void prandom_debug() +{ + LOG_TRACE("Current random seed = ", ftos(prandom_seed)); +} #endif #endif diff --git a/qcsrc/lib/random.qh b/qcsrc/lib/random.qh index e3900697b..210ccffa4 100644 --- a/qcsrc/lib/random.qh +++ b/qcsrc/lib/random.qh @@ -21,12 +21,12 @@ void RandomSelection_Add(entity e, float f, string s, vector v, float weight, fl #define USE_PRANDOM #ifdef USE_PRANDOM - float prandom(); - vector prandomvec(); +float prandom(); +vector prandomvec(); - void psrandom(float seed); +void psrandom(float seed); #ifdef USE_PRANDOM_DEBUG - void prandom_debug(); +void prandom_debug(); #else #define prandom_debug() #endif diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index 100f82b67..7fccb8d0a 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -3,7 +3,11 @@ #include "oo.qh" #if 1 - #define _R_MAP(r, max) ArrayList r; STATIC_INIT(r) { AL_NEW(r, max, NULL, e); } + #define _R_MAP(r, max) \ + ArrayList r; STATIC_INIT(r) \ + { \ + AL_NEW(r, max, NULL, e); \ + } #define _R_GET(r, i) AL_gete(r, i) #define _R_SET(r, i, e) AL_sete(r, i, e) #define _R_DEL(r) AL_DELETE(r) @@ -27,24 +31,53 @@ [[accumulate]] REGISTRY_END(id) {} \ void _Register##id() {} \ int id##_state = 0; \ - void Register##id() { if (id##_state) return; id##_state = 1; REGISTRY_DEPENDS_(id); REGISTRY_BEGIN_(id); _Register##id(); id##_state = 2; REGISTRY_END_(id); } \ + void Register##id() \ + { \ + if (id##_state) { \ + return; \ + } \ + id##_state = 1; REGISTRY_DEPENDS_(id); REGISTRY_BEGIN_(id); _Register##id(); id##_state = 2; REGISTRY_END_(id); \ + } \ const int id##_MAX = max; \ int id##_COUNT; \ noref entity id##_first, id##_last; \ _R_MAP(_##id, id##_MAX); \ - SHUTDOWN(id) { _R_DEL(_##id); } \ - entity _##id##_from(int i, entity null) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; } + SHUTDOWN(id) \ + { \ + _R_DEL(_##id); \ + } \ + entity _##id##_from(int i, entity null) \ + { \ + if (i >= 0 && i < id##_COUNT) { \ + entity e = _R_GET(_##id, i); if (e) { \ + return e; \ + } \ + } \ + return null; \ + } /** Add registry dependencies to a registry */ -#define REGISTRY_DEPENDS(id, dep) void Register##dep(); void REGISTRY_DEPENDS_(id) { Register##dep(); } +#define REGISTRY_DEPENDS(id, dep) \ + void Register##dep(); void REGISTRY_DEPENDS_(id) \ + { \ + Register##dep(); \ + } #define REGISTRY_DEPENDS_(id) Register##id##_Depends() /** Called before initializing a registry. */ -#define REGISTRY_BEGIN(id) [[accumulate]] void REGISTRY_BEGIN_(id) { noref void() f = Register##id; } void REGISTRY_BEGIN_(id) +#define REGISTRY_BEGIN(id) \ + [[accumulate]] void REGISTRY_BEGIN_(id) \ + { \ + noref void() f = Register##id; \ + } void REGISTRY_BEGIN_(id) #define REGISTRY_BEGIN_(id) Register##id##_First() /** Called after initializing a registry. */ -#define REGISTRY_END(id) [[accumulate]] void REGISTRY_END_(id) { noref void() f = Register##id; } void REGISTRY_END_(id) +#define REGISTRY_END(id) \ + [[accumulate]] void REGISTRY_END_(id) \ + { \ + noref void() f = Register##id; \ + } void REGISTRY_END_(id) #define REGISTRY_END_(id) Register##id##_Done() REGISTRY(Registries, BITS(8)) @@ -79,7 +112,7 @@ REGISTRY(Registries, BITS(8)) { \ entity this = id; \ if (this == NULL) { \ - if (registry##_COUNT >= registry##_MAX) LOG_FATALF("Registry capacity exceeded (%d)", registry##_MAX); \ + if (registry##_COUNT >= registry##_MAX) { LOG_FATALF("Registry capacity exceeded (%d)", registry##_MAX); } \ this = id = inst; \ this.registered_id = #id; \ REGISTRY_PUSH(registry, fld, this); \ @@ -89,20 +122,22 @@ REGISTRY(Registries, BITS(8)) ACCUMULATE_FUNCTION(_Register##registry, Register_##id) \ REGISTER_INIT(id) -#define REGISTRY_PUSH(registry, fld, it) MACRO_BEGIN \ - it.fld = registry##_COUNT; \ - _R_SET(_##registry, registry##_COUNT, it); \ - ++registry##_COUNT; \ - if (!registry##_first) registry##_first = it; \ - if (registry##_last) registry##_last.REGISTRY_NEXT = it; \ - registry##_last = it; \ -MACRO_END - -#define REGISTRY_RESERVE(registry, fld, id, suffix) MACRO_BEGIN \ - entity e = new_pure(registry_reserved); \ - e.registered_id = #id "/" #suffix; \ - REGISTRY_PUSH(registry, fld, e); \ -MACRO_END +#define REGISTRY_PUSH(registry, fld, it) \ + MACRO_BEGIN \ + it.fld = registry##_COUNT; \ + _R_SET(_##registry, registry##_COUNT, it); \ + ++registry##_COUNT; \ + if (!registry##_first) { registry##_first = it; } \ + if (registry##_last) { registry##_last.REGISTRY_NEXT = it; } \ + registry##_last = it; \ + MACRO_END + +#define REGISTRY_RESERVE(registry, fld, id, suffix) \ + MACRO_BEGIN \ + entity e = new_pure(registry_reserved); \ + e.registered_id = #id "/" #suffix; \ + REGISTRY_PUSH(registry, fld, e); \ + MACRO_END #define REGISTER_INIT(id) [[accumulate]] void Register_##id##_init(entity this) @@ -117,7 +152,7 @@ MACRO_END void _REGISTRY_SWAP_##id(int i, int j, entity pass) \ { \ i += skip; j += skip; \ - \ + \ entity a = _R_GET(_##id, i), b = _R_GET(_##id, j); \ _R_SET(_##id, i, b); \ _R_SET(_##id, j, a); \ @@ -126,11 +161,9 @@ MACRO_END a.REGISTRY_NEXT = b_next; \ b.REGISTRY_NEXT = a_next; \ \ - if (i == 0) id##_first = b; \ - else _R_GET(_##id, i - 1).REGISTRY_NEXT = b; \ + if (i == 0) { id##_first = b; } else { _R_GET(_##id, i - 1).REGISTRY_NEXT = b; } \ \ - if (j == 0) id##_first = a; \ - else _R_GET(_##id, j - 1).REGISTRY_NEXT = a; \ + if (j == 0) { id##_first = a; } else { _R_GET(_##id, j - 1).REGISTRY_NEXT = a; } \ } \ int _REGISTRY_CMP_##id(int i, int j, entity pass) \ { \ @@ -147,9 +180,9 @@ MACRO_END #define REGISTRY_HASH(id) Registry_hash_##id ERASEABLE -[[accumulate]] void Registry_check(string r, string server) { } +[[accumulate]] void Registry_check(string r, string server) {} ERASEABLE -[[accumulate]] void Registry_send_all() { } +[[accumulate]] void Registry_send_all() {} #ifdef SVQC void Registry_send(string id, string hash); @@ -168,20 +201,21 @@ void Registry_send(string id, string hash); FOREACH(id, true, s = strcat(s, join, it.registered_id)); \ s = substring(s, strlen(join), -1); \ string h = REGISTRY_HASH(id) = strzone(digest_hex(algo, s)); \ - LOG_DEBUGF(#id ": %s\n[%s]", h, s); \ + LOG_DEBUGF( #id ": %s\n[%s]", h, s); \ } \ void Registry_check(string r, string sv) \ { \ - if (r == #id) \ - { \ + if (r == #id) { \ string cl = REGISTRY_HASH(id); \ - if (cl != sv) \ - { \ + if (cl != sv) { \ LOG_FATALF("client/server mismatch (%s).\nCL: %s\nSV: %s", r, cl, sv); \ } \ } \ } \ - void Registry_send_all() { Registry_send(#id, REGISTRY_HASH(id)); } \ + void Registry_send_all() \ + { \ + Registry_send( #id, REGISTRY_HASH(id)); \ + } \ #define REGISTER_REGISTRY(...) EVAL_REGISTER_REGISTRY(OVERLOAD(REGISTER_REGISTRY, __VA_ARGS__)) #define EVAL_REGISTER_REGISTRY(...) __VA_ARGS__ @@ -194,7 +228,8 @@ void Registry_send(string id, string hash); METHOD(id##Registry, m_reload, void()); \ ENDCLASS(id##Registry) \ REGISTER(Registries, REGISTRY, id, m_id, NEW(id##Registry)); \ - METHOD(id##Registry, m_reload, void()) { \ - id##_state = 0; \ + METHOD(id##Registry, m_reload, void()) \ + { \ + id##_state = 0; \ Register##id(); \ } diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh index c7a42042d..609b4ccbb 100644 --- a/qcsrc/lib/replicate.qh +++ b/qcsrc/lib/replicate.qh @@ -2,31 +2,30 @@ #ifdef GAMEQC - /** - * Replicate a client cvar into a server field - * - * @param fld The field to replicate into - * @param type The field type - * @param cvar The cvar name - */ +/** + * Replicate a client cvar into a server field + * + * @param fld The field to replicate into + * @param type The field type + * @param cvar The cvar name + */ #define REPLICATE(...) EVAL_REPLICATE(OVERLOAD(REPLICATE, __VA_ARGS__)) #define EVAL_REPLICATE(...) __VA_ARGS__ - [[accumulate]] void ReplicateVars(entity this, entity store, string thisname, int i) {} +[[accumulate]] void ReplicateVars(entity this, entity store, string thisname, int i) {} #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, ) #define REPLICATE_4(fld, type, var, func) REPLICATE_##type(fld, var, func) #define REPLICATE_string(fld, var, func) \ - REPLICATE_7(fld, string, var, , \ - { if (field) strunzone(field); field = strzone(it); }, \ - { if (field) strunzone(field); field = string_null; }, \ + REPLICATE_7(fld, string, var, , \ + { if (field) { strunzone(field); } field = strzone(it); }, \ + { if (field) { strunzone(field); } field = string_null; }, \ { \ /* also initialize to the default value of func when requesting cvars */ \ string s = func(field); \ - if (s != field) \ - { \ - strunzone(field); \ - field = strzone(s); \ + if (s != field) { \ + strunzone(field); \ + field = strzone(s); \ } \ }) #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, { field = stof(it); }, , ) @@ -35,28 +34,23 @@ #if defined(SVQC) #define REPLICATE_7(fld, type, var, func, create, destroy, after) \ - void ReplicateVars(entity this, entity store, string thisname, int i) \ - { \ - type field = store.fld; \ - if (i < 0) { destroy } \ - else \ - { \ - string it = func(argv(i + 1)); \ - bool current = thisname == var; \ - if (i > 0) \ - { \ - if (current) { create } \ - } \ - else \ - { \ - stuffcmd(this, "cl_cmd sendcvar " var "\n"); \ - } \ - if (current) { after } \ - } \ - store.fld = field; \ - } + void ReplicateVars(entity this, entity store, string thisname, int i) \ + { \ + type field = store.fld; \ + if (i < 0) { destroy } else { \ + string it = func(argv(i + 1)); \ + bool current = thisname == var; \ + if (i > 0) { \ + if (current) { create } \ + } else { \ + stuffcmd(this, "cl_cmd sendcvar " var "\n"); \ + } \ + if (current) { after } \ + } \ + store.fld = field; \ + } #elif defined(CSQC) - // TODO +// TODO #define REPLICATE_7(fld, type, var, func, create, destroy, after) #endif diff --git a/qcsrc/lib/sort.qh b/qcsrc/lib/sort.qh index cd0000912..3d045985f 100644 --- a/qcsrc/lib/sort.qh +++ b/qcsrc/lib/sort.qh @@ -1,37 +1,34 @@ #pragma once /** is only ever called for i1 < i2 */ -USING(swapfunc_t, void (int i1, int i2, entity pass)); +USING(swapfunc_t, void(int i1, int i2, entity pass)); /** <0 for <, ==0 for ==, >0 for > (like strcmp) */ -USING(comparefunc_t, int (int i1, int i2, entity pass)); +USING(comparefunc_t, int(int i1, int i2, entity pass)); ERASEABLE void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass) { #define heapify(_count) \ - MACRO_BEGIN \ - for (int start = floor(((_count) - 2) / 2); start >= 0; --start) \ - { \ - siftdown(start, (_count) - 1); \ - } \ - MACRO_END + MACRO_BEGIN \ + for (int start = floor(((_count) - 2) / 2); start >= 0; --start) { \ + siftdown(start, (_count) - 1); \ + } \ + MACRO_END #define siftdown(_start, _end) \ - MACRO_BEGIN \ - for (int root = (_start); root * 2 + 1 <= (_end); ) \ - { \ - int child = root * 2 + 1; \ - if (child < (_end) && cmp(child, child + 1, pass) < 0) child += 1; \ - if (cmp(root, child, pass) >= 0) break; \ - swap(root, child, pass); \ - root = child; \ - } \ - MACRO_END + MACRO_BEGIN \ + for (int root = (_start); root * 2 + 1 <= (_end); ) { \ + int child = root * 2 + 1; \ + if (child < (_end) && cmp(child, child + 1, pass) < 0) { child += 1; } \ + if (cmp(root, child, pass) >= 0) { break; } \ + swap(root, child, pass); \ + root = child; \ + } \ + MACRO_END heapify(n); int end = n - 1; - while (end > 0) - { + while (end > 0) { swap(0, end, pass); end -= 1; siftdown(0, end); @@ -41,8 +38,7 @@ void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass) ERASEABLE void shuffle(float n, swapfunc_t swap, entity pass) { - for (int i = 1; i < n; ++i) - { + for (int i = 1; i < n; ++i) { // swap i-th item at a random position from 0 to i // proof for even distribution: // n = 1: obvious @@ -53,6 +49,6 @@ void shuffle(float n, swapfunc_t swap, entity pass) // 1/n * n/(n+1) = 1/(n+1) // q.e.d. int j = floor(random() * (i + 1)); - if (j != i) swap(j, i, pass); + if (j != i) { swap(j, i, pass); } } } diff --git a/qcsrc/lib/sortlist.qh b/qcsrc/lib/sortlist.qh index af4b47ab8..ef0ca33b7 100644 --- a/qcsrc/lib/sortlist.qh +++ b/qcsrc/lib/sortlist.qh @@ -14,7 +14,7 @@ entity Sort_Spawn(); #define SORT_SWAP(a, b) \ b.sort_prev = a.sort_prev; \ a.sort_next = b.sort_next; \ - if (b.sort_next) b.sort_next.sort_prev = a; \ - if (a.sort_prev) a.sort_prev.sort_next = b; \ + if (b.sort_next) { b.sort_next.sort_prev = a; } \ + if (a.sort_prev) { a.sort_prev.sort_next = b; } \ a.sort_prev = b; \ b.sort_next = a diff --git a/qcsrc/lib/static.qh b/qcsrc/lib/static.qh index 6f511fcec..5dcd2682a 100644 --- a/qcsrc/lib/static.qh +++ b/qcsrc/lib/static.qh @@ -12,38 +12,41 @@ void profile(string s) { static float g_starttime; float rt = _gettime(GETTIME_REALTIME); - if (!g_starttime) g_starttime = rt; + if (!g_starttime) { g_starttime = rt; } LOG_TRACEF("[%f] %s", rt - g_starttime, s); } #define _STATIC_INIT(func, where) \ - [[accumulate]] void _static_##func() { profile(#func); } \ + [[accumulate]] void _static_##func() \ + { \ + profile( #func); \ + } \ ACCUMULATE_FUNCTION(where, _static_##func) \ void _static_##func() /** before worldspawn */ #define STATIC_INIT_EARLY(func) _STATIC_INIT(func##_0, __static_init_0) -#define static_init_early() CALL_ACCUMULATED_FUNCTION(__static_init_0) +#define static_init_early() CALL_ACCUMULATED_FUNCTION(__static_init_0) void __static_init_0() {} /** during worldspawn */ -#define STATIC_INIT(func) _STATIC_INIT(func##_1, __static_init_1) -#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init_1) +#define STATIC_INIT(func) _STATIC_INIT(func##_1, __static_init_1) +#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init_1) void __static_init_1() {} /** directly after STATIC_INIT */ -#define STATIC_INIT_LATE(func) _STATIC_INIT(func##_2, __static_init_2) -#define static_init_late() CALL_ACCUMULATED_FUNCTION(__static_init_2) +#define STATIC_INIT_LATE(func) _STATIC_INIT(func##_2, __static_init_2) +#define static_init_late() CALL_ACCUMULATED_FUNCTION(__static_init_2) void __static_init_2() {} /** directly after STATIC_INIT_LATE */ -#define PRECACHE(func) _STATIC_INIT(func##_3, __static_init_3) -#define static_init_precache() CALL_ACCUMULATED_FUNCTION(__static_init_3) +#define PRECACHE(func) _STATIC_INIT(func##_3, __static_init_3) +#define static_init_precache() CALL_ACCUMULATED_FUNCTION(__static_init_3) void __static_init_3() {} /* other map entities spawn now */ /** before shutdown */ -#define SHUTDOWN(func) _STATIC_INIT(func##_shutdown, __shutdown) -#define shutdownhooks() CALL_ACCUMULATED_FUNCTION( __shutdown) +#define SHUTDOWN(func) _STATIC_INIT(func##_shutdown, __shutdown) +#define shutdownhooks() CALL_ACCUMULATED_FUNCTION(__shutdown) void __shutdown() {} diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index b05a316c9..128628471 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -5,26 +5,26 @@ #include "oo.qh" #ifdef CSQC - float stringwidth_colors(string s, vector theSize) - { - return stringwidth_builtin(s, true, theSize); - } +float stringwidth_colors(string s, vector theSize) +{ + return stringwidth_builtin(s, true, theSize); +} - float stringwidth_nocolors(string s, vector theSize) - { - return stringwidth_builtin(s, false, theSize); - } +float stringwidth_nocolors(string s, vector theSize) +{ + return stringwidth_builtin(s, false, theSize); +} #endif #ifdef MENUQC - float stringwidth_colors(string s, vector theSize) - { - return stringwidth(s, true, theSize); - } +float stringwidth_colors(string s, vector theSize) +{ + return stringwidth(s, true, theSize); +} - float stringwidth_nocolors(string s, vector theSize) - { - return stringwidth(s, false, theSize); - } +float stringwidth_nocolors(string s, vector theSize) +{ + return stringwidth(s, false, theSize); +} #endif ERASEABLE @@ -45,8 +45,7 @@ string format_time(float seconds) seconds -= hours * 36000; float minutes = floor(seconds / 600); seconds -= minutes * 600; - if (days > 0) return sprintf(_("%d days, %02d:%02d:%02d"), days, hours, minutes, seconds); - else return sprintf(_("%02d:%02d:%02d"), hours, minutes, seconds); + if (days > 0) { return sprintf(_("%d days, %02d:%02d:%02d"), days, hours, minutes, seconds); } else { return sprintf(_("%02d:%02d:%02d"), hours, minutes, seconds); } } ERASEABLE @@ -109,7 +108,7 @@ string CCR(string input) // background colors input = strreplace("^BG", strcat("^", autocvar_hud_colorset_background), input); - input = strreplace("^N", "^7", input); // "none"-- reset to white... + input = strreplace("^N", "^7", input); // "none"-- reset to white... return input; } #endif @@ -129,7 +128,7 @@ noref string _endsWith_suffix; ERASEABLE string fstrunzone(string s) { - if (!s) return s; + if (!s) { return s; } string sc = strcat(s, ""); strunzone(s); return sc; @@ -140,7 +139,7 @@ ERASEABLE string car(string s) { int o = strstrofs(s, " ", 0); - if (o < 0) return s; + if (o < 0) { return s; } return substring(s, 0, o); } @@ -149,15 +148,15 @@ ERASEABLE string cdr(string s) { int o = strstrofs(s, " ", 0); - if (o < 0) return string_null; + if (o < 0) { return string_null; } return substring(s, o + 1, strlen(s) - (o + 1)); } ERASEABLE string cons(string a, string b) { - if (a == "") return b; - if (b == "") return a; + if (a == "") { return b; } + if (b == "") { return a; } return strcat(a, " ", b); } @@ -173,7 +172,7 @@ string swapwords(string str, float i, float j) float n; string s1, s2, s3, s4, s5; float si, ei, sj, ej, s0, en; - n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle" + n = tokenizebyseparator(str, " "); // must match g_maplist processing in ShuffleMaplist and "shuffle" si = argv_start_index(i); sj = argv_start_index(j); ei = argv_end_index(i); @@ -209,19 +208,17 @@ string shufflewords(string str) ERASEABLE string unescape(string in) { - in = strzone(in); // but it doesn't seem to be necessary in my tests at least + in = strzone(in); // but it doesn't seem to be necessary in my tests at least int len = strlen(in); string str = ""; - for (int i = 0; i < len; ++i) - { + for (int i = 0; i < len; ++i) { string s = substring(in, i, 1); - if (s == "\\") - { + if (s == "\\") { s = substring(in, i + 1, 1); - if (s == "n") str = strcat(str, "\n"); - else if (s == "\\") str = strcat(str, "\\"); - else str = strcat(str, substring(in, i, 2)); + if (s == "n") { str = strcat(str, "\n"); } else if (s == "\\") { + str = strcat(str, "\\"); + } else { str = strcat(str, substring(in, i, 2)); } ++i; continue; } @@ -235,9 +232,10 @@ ERASEABLE string strwords(string s, int w) { int endpos = 0; - for ( ; w && endpos >= 0; --w) + for ( ; w && endpos >= 0; --w) { endpos = strstrofs(s, " ", endpos + 1); - if (endpos < 0) return s; + } + if (endpos < 0) { return s; } return substring(s, 0, endpos); } @@ -247,8 +245,7 @@ ERASEABLE int u8_strsize(string s) { int l = 0; - for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l) - { + for (int i = 0, c; (c = str2chr(s, i)) > 0; ++i, ++l) { l += (c >= 0x80); l += (c >= 0x800); l += (c >= 0x10000); @@ -261,20 +258,18 @@ bool isInvisibleString(string s) { s = strdecolorize(s); bool utf8 = cvar("utf8_enable"); - for (int i = 0, n = strlen(s); i < n; ++i) - { + for (int i = 0, n = strlen(s); i < n; ++i) { int c = str2chr(s, i); - switch (c) - { + switch (c) { case 0: case 32: // space break; case 192: // charmap space - if (!utf8) break; + if (!utf8) { break; } return false; case 160: // space in unicode fonts case 0xE000 + 192: // utf8 charmap space - if (utf8) break; + if (utf8) { break; } default: return false; } @@ -288,16 +283,16 @@ ERASEABLE int buf_load(string pFilename) { int buf = buf_create(); - if (buf < 0) return -1; + if (buf < 0) { return -1; } int fh = fopen(pFilename, FILE_READ); - if (fh < 0) - { + if (fh < 0) { buf_del(buf); return -1; } string l; - for (int i = 0; (l = fgets(fh)); ++i) + for (int i = 0; (l = fgets(fh)); ++i) { bufstr_set(buf, i, l); + } fclose(fh); return buf; } @@ -306,10 +301,11 @@ ERASEABLE void buf_save(float buf, string pFilename) { int fh = fopen(pFilename, FILE_WRITE); - if (fh < 0) error(strcat("Can't write buf to ", pFilename)); + if (fh < 0) { error(strcat("Can't write buf to ", pFilename)); } int n = buf_getsize(buf); - for (int i = 0; i < n; ++i) + for (int i = 0; i < n; ++i) { fputs(fh, strcat(bufstr_get(buf, i), "\n")); + } fclose(fh); } @@ -320,7 +316,7 @@ ERASEABLE string ftos_decimals(float number, int decimals) { // inhibit stupid negative zero - if (number == 0) number = 0; + if (number == 0) { number = 0; } return sprintf("%.*f", decimals, number); } @@ -331,7 +327,7 @@ ERASEABLE string ftos_mindecimals(float number) { // inhibit stupid negative zero - if (number == 0) number = 0; + if (number == 0) { number = 0; } return sprintf("%.7g", number); } @@ -345,23 +341,23 @@ int vercmp_recursive(string v1, string v2) float r; r = stof(s1) - stof(s2); - if (r != 0) return r; + if (r != 0) { return r; } r = strcasecmp(s1, s2); - if (r != 0) return r; + if (r != 0) { return r; } - if (dot1 == -1) return (dot2 == -1) ? 0 : -1; - else return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999)); + if (dot1 == -1) { return (dot2 == -1) ? 0 : -1; } else { return (dot2 == -1) ? 1 : vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999)); } } ERASEABLE int vercmp(string v1, string v2) { - if (strcasecmp(v1, v2) == 0) return 0; // early out check - + if (strcasecmp(v1, v2) == 0) { + return 0; // early out check + } // "git" beats all - if (v1 == "git") return 1; - if (v2 == "git") return -1; + if (v1 == "git") { return 1; } + if (v2 == "git") { return -1; } return vercmp_recursive(v1, v2); } diff --git a/qcsrc/lib/test.qc b/qcsrc/lib/test.qc index 86b0e6187..e2b7b56a7 100644 --- a/qcsrc/lib/test.qc +++ b/qcsrc/lib/test.qc @@ -4,13 +4,10 @@ int TEST_RunAll_accumulated(int init); bool RUN_ALL_TESTS() { int f = TEST_RunAll_accumulated(0); - if (f) - { + if (f) { LOG_INFOF("%d tests failed", f); return true; - } - else - { + } else { LOG_INFO("All tests OK"); return false; } @@ -23,14 +20,11 @@ bool TEST_Run(string s) TEST_fatal = 0; TEST_ok = false; string fn = strcat("_TEST_", s); - if (isfunction(fn)) callfunction(fn); - if (TEST_failed > 0) - { + if (isfunction(fn)) { callfunction(fn); } + if (TEST_failed > 0) { LOG_INFOF("%s: %d items failed.", s, TEST_failed); return false; - } - else if (!TEST_ok) - { + } else if (!TEST_ok) { LOG_INFOF("%s: did not complete.", s); return false; } diff --git a/qcsrc/lib/test.qh b/qcsrc/lib/test.qh index f0fef90c8..04937dc16 100644 --- a/qcsrc/lib/test.qh +++ b/qcsrc/lib/test.qh @@ -5,8 +5,9 @@ /** Use UpperCamelCase for suite and test only */ #define TEST(suite, test) \ void _TEST_##suite##_##test(); \ - [[accumulate]] int TEST_RunAll_accumulated(int f) { \ - if (!TEST_Run(#suite "_" #test)) ++f; \ + [[accumulate]] int TEST_RunAll_accumulated(int f) \ + { \ + if (!TEST_Run( #suite "_" #test)) { ++f; } \ return = f; \ } \ void _TEST_##suite##_##test() @@ -26,18 +27,19 @@ bool RUN_ALL_TESTS(); // difference between expect/assert: assert returns early -#define EXPECT_EQ(expected_, actual_) MACRO_BEGIN \ - int expected = expected_; \ - int actual = actual_; \ - if ((expected) != (actual)) { \ - ADD_FAILURE(sprintf( \ - "Value of: " #actual_ "\n" \ - " Actual: %d\n" \ - "Expected: %d\n", \ - actual, expected \ - )); \ - } \ -MACRO_END +#define EXPECT_EQ(expected_, actual_) \ + MACRO_BEGIN \ + int expected = expected_; \ + int actual = actual_; \ + if ((expected) != (actual)) { \ + ADD_FAILURE(sprintf( \ + "Value of: " #actual_ "\n" \ + " Actual: %d\n" \ + "Expected: %d\n", \ + actual, expected \ + )); \ + } \ + MACRO_END #define ASSERT_EQ(expected, actual) _TEST_ASSERT(EXPECT_EQ(expected, actual)) #define EXPECT_TRUE(condition) EXPECT_EQ(true, condition) @@ -61,7 +63,7 @@ MACRO_END #define EXPECT_GE(val1, val2) EXPECT_TRUE((val1) >= (val2)) #define ASSERT_GE(val1, val2) _TEST_ASSERT(EXPECT_GE(val1, val2)) -#define EXPECT_NO_FATAL_FAILURE(statement) EXPECT_NO_FATAL_FAILURE_(statement, { }) +#define EXPECT_NO_FATAL_FAILURE(statement) EXPECT_NO_FATAL_FAILURE_(statement, {}) #define ASSERT_NO_FATAL_FAILURE(statement) EXPECT_NO_FATAL_FAILURE_(statement, { ++TEST_fatal; return; }) // private: @@ -81,16 +83,17 @@ int TEST_failed; MACRO_BEGIN \ int TEST_prevfatal = TEST_fatal; \ LAMBDA(statement); \ - if (TEST_fatal != TEST_prevfatal) \ + if (TEST_fatal != TEST_prevfatal) { \ LAMBDA(then); \ + } \ MACRO_END #define EXPECT_NO_FATAL_FAILURE_(statement, then) \ EXPECT_NO_FATAL_FAILURE__(statement, { \ LOG_WARNF( \ - " Actual: %d fatal failures\n" \ - "Expected: no fatal failures\n", \ - TEST_fatal - TEST_prevfatal \ + " Actual: %d fatal failures\n" \ + "Expected: no fatal failures\n", \ + TEST_fatal - TEST_prevfatal \ ); \ LAMBDA(then); \ }) diff --git a/qcsrc/lib/urllib.qc b/qcsrc/lib/urllib.qc index 1572fec07..4cf1da235 100644 --- a/qcsrc/lib/urllib.qc +++ b/qcsrc/lib/urllib.qc @@ -27,14 +27,13 @@ int autocvar__urllib_nextslot; ERASEABLE float url_URI_Get_Callback(int id, float status, string data) { - if (id < MIN_URL_ID) return 0; + if (id < MIN_URL_ID) { return 0; } id -= MIN_URL_ID; - if (id >= NUM_URL_ID) return 0; + if (id >= NUM_URL_ID) { return 0; } entity e; e = url_fromid[id]; - if (!e) return 0; - if (e.url_rbuf >= 0 || e.url_wbuf >= 0) - { + if (!e) { return 0; } + if (e.url_rbuf >= 0 || e.url_wbuf >= 0) { LOG_INFOF("WARNING: handle %d (%s) has already received data?!?", id + NUM_URL_ID, e.url_url); return 0; } @@ -43,16 +42,14 @@ float url_URI_Get_Callback(int id, float status, string data) url_fromid[id] = NULL; // if we get here, we MUST have both buffers cleared - if (e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh != URL_FH_CURL) error("url_URI_Get_Callback: not a request waiting for data"); + if (e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh != URL_FH_CURL) { error("url_URI_Get_Callback: not a request waiting for data"); } - if (status == 0) - { + if (status == 0) { // WE GOT DATA! float n, i; n = tokenizebyseparator(data, "\n"); e.url_rbuf = buf_create(); - if (e.url_rbuf < 0) - { + if (e.url_rbuf < 0) { LOG_INFO("url_URI_Get_Callback: out of memory in buf_create"); e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); strunzone(e.url_url); @@ -60,21 +57,19 @@ float url_URI_Get_Callback(int id, float status, string data) return 1; } e.url_rbufpos = 0; - if (e.url_rbuf < 0) - { + if (e.url_rbuf < 0) { LOG_INFO("url_URI_Get_Callback: out of memory in buf_create"); e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); strunzone(e.url_url); delete(e); return 1; } - for (i = 0; i < n; ++i) + for (i = 0; i < n; ++i) { bufstr_set(e.url_rbuf, i, argv(i)); + } e.url_ready(e, e.url_ready_pass, URL_READY_CANREAD); return 1; - } - else - { + } else { // an ERROR e.url_ready(e, e.url_ready_pass, -fabs(status)); strunzone(e.url_url); @@ -88,10 +83,8 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) { entity e; int i; - if (strstrofs(url, "://", 0) >= 0) - { - switch (mode) - { + if (strstrofs(url, "://", 0) >= 0) { + switch (mode) { case FILE_WRITE: case FILE_APPEND: // collect data to a stringbuffer for a POST request @@ -104,8 +97,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) e.url_verb = ""; e.url_fh = URL_FH_CURL; e.url_wbuf = buf_create(); - if (e.url_wbuf < 0) - { + if (e.url_wbuf < 0) { LOG_INFO("url_single_fopen: out of memory in buf_create"); rdy(e, pass, URL_READY_ERROR); strunzone(e.url_url); @@ -123,14 +115,12 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) // read data only // get slot for HTTP request - for (i = autocvar__urllib_nextslot; i < NUM_URL_ID; ++i) - if (url_fromid[i] == NULL) break; - if (i >= NUM_URL_ID) - { - for (i = 0; i < autocvar__urllib_nextslot; ++i) - if (url_fromid[i] == NULL) break; - if (i >= autocvar__urllib_nextslot) - { + for (i = autocvar__urllib_nextslot; i < NUM_URL_ID; ++i) { + if (url_fromid[i] == NULL) { break; } } + if (i >= NUM_URL_ID) { + for (i = 0; i < autocvar__urllib_nextslot; ++i) { + if (url_fromid[i] == NULL) { break; } } + if (i >= autocvar__urllib_nextslot) { LOG_INFO("url_single_fopen: too many concurrent requests"); rdy(NULL, pass, URL_READY_ERROR); return; @@ -138,8 +128,7 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) } // GET the data - if (!crypto_uri_postbuf(url, i + MIN_URL_ID, string_null, string_null, -1, 0)) - { + if (!crypto_uri_postbuf(url, i + MIN_URL_ID, string_null, string_null, -1, 0)) { LOG_INFO("url_single_fopen: failure in crypto_uri_postbuf"); rdy(NULL, pass, URL_READY_ERROR); return; @@ -162,11 +151,8 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) cvar_set("_urllib_nextslot", ftos((i + 1) % NUM_URL_ID)); break; } - } - else if (url == "-") - { - switch (mode) - { + } else if (url == "-") { + switch (mode) { case FILE_WRITE: case FILE_APPEND: e = new_pure(url_single_fopen_stdout); @@ -180,24 +166,18 @@ void url_single_fopen(string url, int mode, url_ready_func rdy, entity pass) rdy(NULL, pass, URL_READY_ERROR); break; } - } - else - { + } else { float fh; fh = fopen(url, mode); - if (fh < 0) - { + if (fh < 0) { rdy(NULL, pass, URL_READY_ERROR); return; - } - else - { + } else { e = new_pure(url_single_fopen_file); e.url_fh = fh; e.url_ready = rdy; e.url_ready_pass = pass; - if (mode == FILE_READ) rdy(e, pass, URL_READY_CANREAD); - else rdy(e, pass, URL_READY_CANWRITE); + if (mode == FILE_READ) { rdy(e, pass, URL_READY_CANREAD); } else { rdy(e, pass, URL_READY_CANWRITE); } } } } @@ -208,26 +188,24 @@ void url_fclose(entity e) { int i; - if (e.url_fh == URL_FH_CURL) - { - if (e.url_rbuf == -1 || e.url_wbuf != -1) // not(post GET/POST request) - if (e.url_rbuf != -1 || e.url_wbuf == -1) // not(pre POST request) + if (e.url_fh == URL_FH_CURL) { + if (e.url_rbuf == -1 || e.url_wbuf != -1) { // not(post GET/POST request) + if (e.url_rbuf != -1 || e.url_wbuf == -1) { // not(pre POST request) error("url_fclose: not closable in current state"); + } + } // closing an URL! - if (e.url_wbuf >= 0) - { + if (e.url_wbuf >= 0) { // we are closing the write end (HTTP POST request) // get slot for HTTP request - for (i = autocvar__urllib_nextslot; i < NUM_URL_ID; ++i) - if (url_fromid[i] == NULL) break; - if (i >= NUM_URL_ID) - { - for (i = 0; i < autocvar__urllib_nextslot; ++i) - if (url_fromid[i] == NULL) break; - if (i >= autocvar__urllib_nextslot) - { + for (i = autocvar__urllib_nextslot; i < NUM_URL_ID; ++i) { + if (url_fromid[i] == NULL) { break; } } + if (i >= NUM_URL_ID) { + for (i = 0; i < autocvar__urllib_nextslot; ++i) { + if (url_fromid[i] == NULL) { break; } } + if (i >= autocvar__urllib_nextslot) { LOG_INFO("url_fclose: too many concurrent requests"); e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); buf_del(e.url_wbuf); @@ -238,8 +216,7 @@ void url_fclose(entity e) } // POST the data - if (!crypto_uri_postbuf(e.url_url, i + MIN_URL_ID, e.url_content_type, e.url_verb, e.url_wbuf, 0)) - { + if (!crypto_uri_postbuf(e.url_url, i + MIN_URL_ID, e.url_content_type, e.url_verb, e.url_wbuf, 0)) { LOG_INFO("url_fclose: failure in crypto_uri_postbuf"); e.url_ready(e, e.url_ready_pass, URL_READY_ERROR); buf_del(e.url_wbuf); @@ -258,26 +235,20 @@ void url_fclose(entity e) // make sure this slot won't be reused quickly even on map change cvar_set("_urllib_nextslot", ftos((i + 1) % NUM_URL_ID)); - } - else - { + } else { // we have READ all data, just close e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); buf_del(e.url_rbuf); strunzone(e.url_url); delete(e); } - } - else if (e.url_fh == URL_FH_STDOUT) - { - e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle + } else if (e.url_fh == URL_FH_STDOUT) { + e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle delete(e); - } - else - { + } else { // file fclose(e.url_fh); - e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle + e.url_ready(e, e.url_ready_pass, URL_READY_CLOSED); // closing creates no reading handle delete(e); } } @@ -286,22 +257,17 @@ void url_fclose(entity e) ERASEABLE string url_fgets(entity e) { - if (e.url_fh == URL_FH_CURL) - { - if (e.url_rbuf == -1) error("url_fgets: not readable in current state"); + if (e.url_fh == URL_FH_CURL) { + if (e.url_rbuf == -1) { error("url_fgets: not readable in current state"); } // curl string s; s = bufstr_get(e.url_rbuf, e.url_rbufpos); e.url_rbufpos += 1; return s; - } - else if (e.url_fh == URL_FH_STDOUT) - { + } else if (e.url_fh == URL_FH_STDOUT) { // stdout return string_null; - } - else - { + } else { // file return fgets(e.url_fh); } @@ -311,20 +277,15 @@ string url_fgets(entity e) ERASEABLE void url_fputs(entity e, string s) { - if (e.url_fh == URL_FH_CURL) - { - if (e.url_wbuf == -1) error("url_fputs: not writable in current state"); + if (e.url_fh == URL_FH_CURL) { + if (e.url_wbuf == -1) { error("url_fputs: not writable in current state"); } // curl bufstr_set(e.url_wbuf, e.url_wbufpos, s); e.url_wbufpos += 1; - } - else if (e.url_fh == URL_FH_STDOUT) - { + } else if (e.url_fh == URL_FH_STDOUT) { // stdout print(s); - } - else - { + } else { // file fputs(e.url_fh, s); } @@ -335,10 +296,8 @@ ERASEABLE void url_multi_ready(entity fh, entity me, float status) { float n; - if (status == URL_READY_ERROR || status < 0) - { - if (status == -422) // Unprocessable Entity - { + if (status == URL_READY_ERROR || status < 0) { + if (status == -422) { // Unprocessable Entity LOG_INFO("uri_multi_ready: got HTTP error 422, data is in unusable format - not continuing"); me.url_ready(fh, me.url_ready_pass, status); strunzone(me.url_url); @@ -347,8 +306,7 @@ void url_multi_ready(entity fh, entity me, float status) } me.url_attempt += 1; n = tokenize_console(me.url_url); - if (n <= me.url_attempt) - { + if (n <= me.url_attempt) { me.url_ready(fh, me.url_ready_pass, status); strunzone(me.url_url); delete(me); @@ -365,8 +323,7 @@ void url_multi_fopen(string url, int mode, url_ready_func rdy, entity pass) { float n; n = tokenize_console(url); - if (n <= 0) - { + if (n <= 0) { LOG_INFO("url_multi_fopen: need at least one URL"); rdy(NULL, pass, URL_READY_ERROR); return; diff --git a/qcsrc/lib/urllib.qh b/qcsrc/lib/urllib.qh index 8918ca0a2..3337df84c 100644 --- a/qcsrc/lib/urllib.qh +++ b/qcsrc/lib/urllib.qh @@ -15,7 +15,7 @@ const float URL_READY_CLOSED = 0; const float URL_READY_CANWRITE = 1; const float URL_READY_CANREAD = 2; // errors: -1, or negative HTTP status code -USING(url_ready_func, void (entity handle, entity pass, float status)); +USING(url_ready_func, void(entity handle, entity pass, float status)); ERASEABLE void url_single_fopen(string url, float mode, url_ready_func rdy, entity pass); diff --git a/qcsrc/lib/warpzone/anglestransform.qc b/qcsrc/lib/warpzone/anglestransform.qc index 9e98199f3..2fd4f57d9 100644 --- a/qcsrc/lib/warpzone/anglestransform.qc +++ b/qcsrc/lib/warpzone/anglestransform.qc @@ -6,15 +6,18 @@ vector AnglesTransform_Apply(vector transform, vector v) { fixedmakevectors(transform); return v_forward * v.x - + v_right * (-v.y) - + v_up * v.z; + + v_right * (-v.y) + + v_up * v.z; } vector AnglesTransform_Multiply(vector t1, vector t2) { vector m_forward, m_up; - fixedmakevectors(t2); m_forward = v_forward; m_up = v_up; - m_forward = AnglesTransform_Apply(t1, m_forward); m_up = AnglesTransform_Apply(t1, m_up); + fixedmakevectors(t2); + m_forward = v_forward; + m_up = v_up; + m_forward = AnglesTransform_Apply(t1, m_forward); + m_up = AnglesTransform_Apply(t1, m_up); return fixedvectoangles2(m_forward, m_up); } @@ -39,8 +42,8 @@ vector AnglesTransform_TurnDirectionFR(vector transform) { // turn 180 degrees around v_up // changes in-direction to out-direction - //fixedmakevectors(transform); - //return fixedvectoangles2(-1 * v_forward, 1 * v_up); + // fixedmakevectors(transform); + // return fixedvectoangles2(-1 * v_forward, 1 * v_up); transform.x = -transform.x; transform.y = 180 + transform.y; transform.z = -transform.z; @@ -54,8 +57,8 @@ vector AnglesTransform_TurnDirectionFU(vector transform) { // turn 180 degrees around v_up // changes in-direction to out-direction - //fixedmakevectors(transform); - //return fixedvectoangles2(-1 * v_forward, 1 * v_up); + // fixedmakevectors(transform); + // return fixedvectoangles2(-1 * v_forward, 1 * v_up); transform.x = -transform.x; transform.y = 180 + transform.y; transform.z = 180 - transform.z; @@ -79,15 +82,15 @@ vector AnglesTransform_Normalize(vector t, float minimize_roll) t.x = t.x - 360 * rint(t.x / 360); t.y = t.y - 360 * rint(t.y / 360); t.z = t.z - 360 * rint(t.z / 360); - if(minimize_roll) + if (minimize_roll) { need_flip = (t.z > 90 || t.z <= -90); - else + } else { need_flip = (t.x > 90 || t.x < -90); // for pitch we prefer to allow exactly -90 degrees for looking straight down - if(need_flip) - { - if(t.x >= 0) t.x = 180 - t.x; else t.x = -180 - t.x; - if(t.y > 0) t.y -= 180; else t.y += 180; - if(t.z > 0) t.z -= 180; else t.z += 180; + } + if (need_flip) { + if (t.x >= 0) { t.x = 180 - t.x; } else { t.x = -180 - t.x; } + if (t.y > 0) { t.y -= 180; } else { t.y += 180; } + if (t.z > 0) { t.z -= 180; } else { t.z += 180; } } return t; } @@ -105,18 +108,14 @@ vector AnglesTransform_CancelRoll(vector t) // FIXME find a better method f = fabs(t.x - (-90)) / epsilon; - if(f < 1) - { - //t_x = -90; + if (f < 1) { + // t_x = -90; t.y += t.z; t.z = 0; - } - else - { + } else { f = fabs(t.x - 90) / epsilon; - if(f < 1) - { - //t_x = 90; + if (f < 1) { + // t_x = 90; t.y -= t.z; t.z = 0; } diff --git a/qcsrc/lib/warpzone/anglestransform.qh b/qcsrc/lib/warpzone/anglestransform.qh index b287651a1..145fe236d 100644 --- a/qcsrc/lib/warpzone/anglestransform.qh +++ b/qcsrc/lib/warpzone/anglestransform.qh @@ -5,20 +5,20 @@ #endif #if POSITIVE_PITCH_IS_DOWN - #define fixedmakevectors makevectors - noref vector _fixedvectoangles; - #define fixedvectoangles(a) (_fixedvectoangles = vectoangles(a), _fixedvectoangles.x *= -1, _fixedvectoangles) - noref vector _fixedvectoangles2; - #define fixedvectoangles2(a, b) (_fixedvectoangles2 = vectoangles2(a, b), _fixedvectoangles2.x *= -1, _fixedvectoangles2) + #define fixedmakevectors makevectors +noref vector _fixedvectoangles; + #define fixedvectoangles(a) (_fixedvectoangles = vectoangles(a), _fixedvectoangles.x *= -1, _fixedvectoangles) +noref vector _fixedvectoangles2; + #define fixedvectoangles2(a, b) (_fixedvectoangles2 = vectoangles2(a, b), _fixedvectoangles2.x *= -1, _fixedvectoangles2) #else - void fixedmakevectors(vector a) - { - // a makevectors that actually inverts vectoangles - a.x = -a.x; - makevectors(a); - } - #define fixedvectoangles2 vectoangles2 - #define fixedvectoangles vectoangles +void fixedmakevectors(vector a) +{ + // a makevectors that actually inverts vectoangles + a.x = -a.x; + makevectors(a); +} + #define fixedvectoangles2 vectoangles2 + #define fixedvectoangles vectoangles #endif vector AnglesTransform_Apply(vector transform, vector v); @@ -27,9 +27,9 @@ vector AnglesTransform_Invert(vector transform); vector AnglesTransform_TurnDirectionFU(vector transform); vector AnglesTransform_TurnDirectionFR(vector transform); vector AnglesTransform_RightDivide(vector to_transform, vector from_transform); // A B^-1 -vector AnglesTransform_LeftDivide(vector from_transform, vector to_transform); // A^-1 B +vector AnglesTransform_LeftDivide(vector from_transform, vector to_transform); // A^-1 B -vector AnglesTransform_Normalize(vector t, float minimize_roll); // makes sure all angles are in their range: yaw in -180..180, pitch in -90..90, roll in -180..180 (or if minimize_roll is set, pitch in -180..180, roll in -90..90) +vector AnglesTransform_Normalize(vector t, float minimize_roll); // makes sure all angles are in their range: yaw in -180..180, pitch in -90..90, roll in -180..180 (or if minimize_roll is set, pitch in -180..180, roll in -90..90) vector AnglesTransform_ApplyToAngles(vector transform, vector v); vector AnglesTransform_ApplyToVAngles(vector transform, vector v); diff --git a/qcsrc/lib/warpzone/client.qc b/qcsrc/lib/warpzone/client.qc index 15a3ca4c3..97f1ae158 100644 --- a/qcsrc/lib/warpzone/client.qc +++ b/qcsrc/lib/warpzone/client.qc @@ -12,42 +12,43 @@ void WarpZone_Fade_PreDraw(entity this) { vector org; org = getpropertyvec(VF_ORIGIN); - if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones + if (!checkpvs(org, this)) { // this makes sense as long as we don't support recursive warpzones this.alpha = 0; - else if(this.warpzone_fadestart) + } else if (this.warpzone_fadestart) { this.alpha = bound(0, (this.warpzone_fadeend - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.warpzone_fadeend - this.warpzone_fadestart), 1); - else + } else { this.alpha = 1; - //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs)); - if(this.alpha <= 0) + } + // printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs)); + if (this.alpha <= 0) { this.drawmask = 0; - else + } else { this.drawmask = MASK_NORMAL; + } } void WarpZone_Touch(entity this, entity toucher); NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew) { warpzone_warpzones_exist = 1; - if (!this.enemy) - { + if (!this.enemy) { this.enemy = new(warpzone_from); } this.classname = "trigger_warpzone"; - if(isnew) + if (isnew) { IL_PUSH(g_warpzones, this); + } int f = ReadByte(); this.warpzone_isboxy = (f & 1); - if(f & 4) - { + if (f & 4) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); - } - else + } else { this.origin = '0 0 0'; + } this.modelindex = ReadShort(); this.mins_x = ReadCoord(); this.mins_y = ReadCoord(); @@ -69,13 +70,10 @@ NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew) this.avelocity_y = ReadCoord(); this.avelocity_z = ReadCoord(); - if(f & 2) - { + if (f & 2) { this.warpzone_fadestart = ReadShort(); this.warpzone_fadeend = max(this.warpzone_fadestart + 1, ReadShort()); - } - else - { + } else { this.warpzone_fadestart = 0; this.warpzone_fadeend = 0; } @@ -84,7 +82,7 @@ NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew) WarpZone_SetUp(this, this.enemy.oldorigin, this.enemy.avelocity, this.oldorigin, this.avelocity); // link me - //setmodel(this, this.model); + // setmodel(this, this.model); setorigin(this, this.origin); setsize(this, this.mins, this.maxs); @@ -92,7 +90,7 @@ NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew) // engine currently wants this setpredraw(this, WarpZone_Fade_PreDraw); - //settouch(this, WarpZone_Touch); + // settouch(this, WarpZone_Touch); return true; } @@ -102,14 +100,13 @@ NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew) this.classname = "func_warpzone_camera"; int f = ReadByte(); - if(f & 4) - { + if (f & 4) { this.origin_x = ReadCoord(); this.origin_y = ReadCoord(); this.origin_z = ReadCoord(); - } - else + } else { this.origin = '0 0 0'; + } this.modelindex = ReadShort(); this.mins_x = ReadCoord(); this.mins_y = ReadCoord(); @@ -125,13 +122,10 @@ NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew) this.avelocity_y = ReadCoord(); this.avelocity_z = ReadCoord(); - if(f & 2) - { + if (f & 2) { this.warpzone_fadestart = ReadShort(); this.warpzone_fadeend = max(this.warpzone_fadestart + 1, ReadShort()); - } - else - { + } else { this.warpzone_fadestart = 0; this.warpzone_fadeend = 0; } @@ -143,7 +137,7 @@ NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew) this.drawmask = MASK_NORMAL; // link me - //setmodel(this, this.model); + // setmodel(this, this.model); setorigin(this, this.origin); setsize(this, this.mins, this.maxs); @@ -162,12 +156,13 @@ NET_HANDLE(ENT_CLIENT_WARPZONE_TELEPORTED, bool isnew) v.y = ReadCoord(); v.z = ReadCoord(); return = true; - if (!isnew) return; + if (!isnew) { return; } this.warpzone_transform = v; setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(this, getpropertyvec(VF_CL_VIEWANGLES))); - if(checkextension("DP_CSQC_ROTATEMOVES")) + if (checkextension("DP_CSQC_ROTATEMOVES")) { CL_RotateMoves(v); - //CL_RotateMoves('0 90 0'); + } + // CL_RotateMoves('0 90 0'); } float warpzone_fixingview; @@ -175,21 +170,22 @@ float warpzone_fixingview_drawexteriormodel; void WarpZone_View_Outside() { - if(!warpzone_fixingview) + if (!warpzone_fixingview) { return; + } warpzone_fixingview = 0; cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel)); } void WarpZone_View_Inside() { - if(autocvar_chase_active) - { + if (autocvar_chase_active) { WarpZone_View_Outside(); return; } - if(warpzone_fixingview) + if (warpzone_fixingview) { return; + } warpzone_fixingview = 1; warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel"); cvar_set("r_drawexteriormodel", "0"); @@ -209,19 +205,20 @@ vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3 ma.z = max(o.z, c0_z, c1_z, c2_z, c3_z); e = WarpZone_Find(mi, ma); - if(e) - { - if(WarpZone_PlaneDist(e, o) < 0) + if (e) { + if (WarpZone_PlaneDist(e, o) < 0) { return '0 0 0'; - // can't really be, though, but if it is, this is not my warpzone, but a random different one in the same mins/maxs + } + // can't really be, though, but if it is, this is not my warpzone, but a random different one in the same mins/maxs pd = min( - WarpZone_PlaneDist(e, c0), - WarpZone_PlaneDist(e, c1), - WarpZone_PlaneDist(e, c2), - WarpZone_PlaneDist(e, c3) + WarpZone_PlaneDist(e, c0), + WarpZone_PlaneDist(e, c1), + WarpZone_PlaneDist(e, c2), + WarpZone_PlaneDist(e, c3) ); - if(pd < 0) + if (pd < 0) { return e.warpzone_forward * -pd; + } } return '0 0 0'; @@ -230,8 +227,7 @@ vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3 void WarpZone_FixPMove() { entity e = WarpZone_Find(pmove_org, pmove_org); - if(e) - { + if (e) { pmove_org = WarpZone_TransformOrigin(e, pmove_org); input_angles = WarpZone_TransformVAngles(e, input_angles); } @@ -249,39 +245,36 @@ void WarpZone_FixView() warpzone_save_view_angles = ang = getpropertyvec(VF_ANGLES); e = WarpZone_Find(org, org); - if(e) - { + if (e) { org = WarpZone_TransformOrigin(e, org); ang = WarpZone_TransformVAngles(e, ang); WarpZone_View_Inside(); - } - else + } else { WarpZone_View_Outside(); + } #ifndef KEEP_ROLL float rick; float f; static float rollkill; - if (STAT(HEALTH) > 0 || STAT(HEALTH) == -666 || STAT(HEALTH) == -2342) - { + if (STAT(HEALTH) > 0 || STAT(HEALTH) == -666 || STAT(HEALTH) == -2342) { f = 0; // reset roll when passing through a warpzone that change player's roll angle - if(autocvar_cl_rollkillspeed) + if (autocvar_cl_rollkillspeed) { f = max(0, (1 - frametime * autocvar_cl_rollkillspeed)); - if(rollkill) + } + if (rollkill) { rollkill = 0; - } - else - { + } + } else { f = 1; // roll the view when killed (v_deathtilt) - if(autocvar_cl_rollkillspeed) - { + if (autocvar_cl_rollkillspeed) { rollkill += frametime * autocvar_cl_rollkillspeed; f = min(1, rollkill); - } - else if(rollkill) + } else if (rollkill) { rollkill = 0; + } } rick = getproperty(VF_CL_VIEWANGLES_Z); @@ -299,8 +292,9 @@ void WarpZone_FixView() corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip); corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip); o = WarpZone_FixNearClip(org, corner0, corner1, corner2, corner3); - if(o != '0 0 0') + if (o != '0 0 0') { setproperty(VF_ORIGIN, org + o); + } } void WarpZone_Shutdown() diff --git a/qcsrc/lib/warpzone/common.qc b/qcsrc/lib/warpzone/common.qc index 65b1a7f64..72f59adb2 100644 --- a/qcsrc/lib/warpzone/common.qc +++ b/qcsrc/lib/warpzone/common.qc @@ -1,10 +1,10 @@ #include "common.qh" #if defined(CSQC) - #include + #include #elif defined(MENUQC) #elif defined(SVQC) - #include + #include #endif void WarpZone_Accumulator_Clear(entity acc) @@ -41,11 +41,13 @@ float autocvar_cl_warpzone_usetrace = 1; vector WarpZone_camera_transform(entity this, vector org, vector ang) { vector vf, vr, vu; - if(this.warpzone_fadestart) - if(vdist(org - this.origin - 0.5 * (this.mins + this.maxs), >, this.warpzone_fadeend + 400)) + if (this.warpzone_fadestart) { + if (vdist(org - this.origin - 0.5 * (this.mins + this.maxs), >, this.warpzone_fadeend + 400)) { return org; - // don't transform if zone faded out (plus 400qu safety margin for typical speeds and latencies) - // unneeded on client, on server this helps a lot + } + } + // don't transform if zone faded out (plus 400qu safety margin for typical speeds and latencies) + // unneeded on client, on server this helps a lot vf = v_forward; vr = v_right; vu = v_up; @@ -53,10 +55,11 @@ vector WarpZone_camera_transform(entity this, vector org, vector ang) vf = WarpZone_TransformVelocity(this, vf); vr = WarpZone_TransformVelocity(this, vr); vu = WarpZone_TransformVelocity(this, vu); - if(autocvar_cl_warpzone_usetrace) + if (autocvar_cl_warpzone_usetrace) { traceline(this.warpzone_targetorigin, org, MOVE_NOMONSTERS, NULL); - else + } else { trace_endpos = this.warpzone_targetorigin; + } v_forward = vf; v_right = vr; v_up = vu; @@ -71,19 +74,23 @@ void WarpZone_SetUp(entity e, vector my_org, vector my_ang, vector other_org, ve e.warpzone_targetorigin = other_org; e.warpzone_angles = my_ang; e.warpzone_targetangles = other_ang; - fixedmakevectors(my_ang); e.warpzone_forward = v_forward; - fixedmakevectors(other_ang); e.warpzone_targetforward = v_forward; + fixedmakevectors(my_ang); + e.warpzone_forward = v_forward; + fixedmakevectors(other_ang); + e.warpzone_targetforward = v_forward; setcamera_transform(e, WarpZone_camera_transform); } vector WarpZone_Camera_camera_transform(entity this, vector org, vector ang) { // a fixed camera view - if(this.warpzone_fadestart) - if(vdist(org - this.origin - 0.5 * (this.mins + this.maxs), >, this.warpzone_fadeend + 400)) + if (this.warpzone_fadestart) { + if (vdist(org - this.origin - 0.5 * (this.mins + this.maxs), >, this.warpzone_fadeend + 400)) { return org; - // don't transform if zone faded out (plus 400qu safety margin for typical speeds and latencies) - // unneeded on client, on server this helps a lot + } + } + // don't transform if zone faded out (plus 400qu safety margin for typical speeds and latencies) + // unneeded on client, on server this helps a lot trace_endpos = this.warpzone_origin; makevectors(this.warpzone_angles); return this.warpzone_origin; @@ -110,18 +117,19 @@ float WarpZoneLib_BoxTouchesBrush_Recurse() tracebox('0 0 0', WarpZoneLib_BoxTouchesBrush_mins, WarpZoneLib_BoxTouchesBrush_maxs, '0 0 0', MOVE_NOMONSTERS, WarpZoneLib_BoxTouchesBrush_ignore); #ifdef CSQC - if (trace_networkentity) - { + if (trace_networkentity) { LOG_TRACE("hit a network ent, cannot continue WarpZoneLib_BoxTouchesBrush"); // we cannot continue, as a player blocks us... // so, abort return 0; } #endif - if (!trace_ent) + if (!trace_ent) { return 0; - if (trace_ent == WarpZoneLib_BoxTouchesBrush_ent) + } + if (trace_ent == WarpZoneLib_BoxTouchesBrush_ent) { return 1; + } se = trace_ent; s = se.solid; @@ -134,28 +142,30 @@ float WarpZoneLib_BoxTouchesBrush_Recurse() float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig) { - float f, s; + float f, s; - if(!e.modelindex || e.warpzone_isboxy) - return 1; + if (!e.modelindex || e.warpzone_isboxy) { + return 1; + } - s = e.solid; - e.solid = SOLID_BSP; - WarpZoneLib_BoxTouchesBrush_mins = mi; - WarpZoneLib_BoxTouchesBrush_maxs = ma; - WarpZoneLib_BoxTouchesBrush_ent = e; - WarpZoneLib_BoxTouchesBrush_ignore = ig; - f = WarpZoneLib_BoxTouchesBrush_Recurse(); - e.solid = s; + s = e.solid; + e.solid = SOLID_BSP; + WarpZoneLib_BoxTouchesBrush_mins = mi; + WarpZoneLib_BoxTouchesBrush_maxs = ma; + WarpZoneLib_BoxTouchesBrush_ent = e; + WarpZoneLib_BoxTouchesBrush_ignore = ig; + f = WarpZoneLib_BoxTouchesBrush_Recurse(); + e.solid = s; - return f; + return f; } entity WarpZone_Find(vector mi, vector ma) { // if we are near any warpzone planes - MOVE AWAY (work around nearclip) - if(!warpzone_warpzones_exist) + if (!warpzone_warpzones_exist) { return NULL; + } IL_EACH(g_warpzones, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL), { return it; @@ -165,8 +175,9 @@ entity WarpZone_Find(vector mi, vector ma) void WarpZone_MakeAllSolid() { - if(!warpzone_warpzones_exist) + if (!warpzone_warpzones_exist) { return; + } IL_EACH(g_warpzones, true, { it.solid = SOLID_BSP; @@ -175,8 +186,9 @@ void WarpZone_MakeAllSolid() void WarpZone_MakeAllOther() { - if(!warpzone_warpzones_exist) + if (!warpzone_warpzones_exist) { return; + } IL_EACH(g_warpzones, true, { it.solid = SOLID_TRIGGER; @@ -185,8 +197,7 @@ void WarpZone_MakeAllOther() void WarpZone_Trace_InitTransform() { - if(!WarpZone_trace_transform) - { + if (!WarpZone_trace_transform) { WarpZone_trace_transform = new_pure(warpzone_trace_transform); } WarpZone_Accumulator_Clear(WarpZone_trace_transform); @@ -209,21 +220,19 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, WarpZone_trace_firstzone = NULL; WarpZone_trace_lastzone = NULL; WarpZone_Trace_InitTransform(); - if(!warpzone_warpzones_exist) - { - if(nomonsters == MOVE_NOTHING) - { + if (!warpzone_warpzones_exist) { + if (nomonsters == MOVE_NOTHING) { trace_endpos = end; trace_fraction = 1; - if(cb) + if (cb) { cb(org, trace_endpos, end); + } return; - } - else - { + } else { tracebox(org, mi, ma, end, nomonsters, WarpZone_trace_forent); - if(cb) + if (cb) { cb(org, trace_endpos, end); + } return; } } @@ -234,8 +243,7 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, o0 = org; e0 = end; - switch(nomonsters) - { + switch (nomonsters) { case MOVE_WORLDONLY: case MOVE_NOTHING: nomonsters_adjusted = MOVE_NOMONSTERS; @@ -244,17 +252,16 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, nomonsters_adjusted = nomonsters; break; } - if((contentshack = (WarpZone_trace_forent.dphitcontentsmask && !(WarpZone_trace_forent.dphitcontentsmask & DPCONTENTS_SOLID)))) + if ((contentshack = (WarpZone_trace_forent.dphitcontentsmask && !(WarpZone_trace_forent.dphitcontentsmask & DPCONTENTS_SOLID)))) { BITSET_ASSIGN(WarpZone_trace_forent.dphitcontentsmask, DPCONTENTS_SOLID); + } // if starting in warpzone, first transform wz = WarpZone_Find(org + mi, org + ma); - if(wz) - { + if (wz) { WarpZone_trace_firstzone = wz; WarpZone_trace_lastzone = wz; - if(zone && wz != zone) - { + if (zone && wz != zone) { // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return. sol = 1; trace_fraction = 0; @@ -269,27 +276,26 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, sol = -1; frac = 0; i = 16; - for (;;) - { - if(--i < 1) - { + for ( ; ; ) { + if (--i < 1) { LOG_TRACE("Too many warpzones in sequence, aborting trace."); trace_ent = NULL; break; } tracebox(org, mi, ma, end, nomonsters_adjusted, WarpZone_trace_forent); - if(cb) + if (cb) { cb(org, trace_endpos, end); - if(sol < 0) + } + if (sol < 0) { sol = trace_startsolid; + } frac = trace_fraction = frac + (1 - frac) * trace_fraction; - if(trace_fraction >= 1) + if (trace_fraction >= 1) { break; - if(trace_ent.classname != "trigger_warpzone") - { - if((nomonsters == MOVE_NOTHING) || ((nomonsters == MOVE_WORLDONLY) && trace_ent) || (contentshack && (trace_dphitcontents & WarpZone_trace_forent.dphitcontentsmask) == DPCONTENTS_SOLID)) - { + } + if (trace_ent.classname != "trigger_warpzone") { + if ((nomonsters == MOVE_NOTHING) || ((nomonsters == MOVE_WORLDONLY) && trace_ent) || (contentshack && (trace_dphitcontents & WarpZone_trace_forent.dphitcontentsmask) == DPCONTENTS_SOLID)) { // continue the trace, ignoring this hit (we only care for warpzones) org = trace_endpos + normalize(end - org); continue; @@ -300,17 +306,19 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, } /*if(trace_ent == wz) { - // FIXME can this check be removed? Do we really need it? - LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace"); - trace_ent = NULL; - break; + // FIXME can this check be removed? Do we really need it? + LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace"); + trace_ent = NULL; + break; }*/ wz = trace_ent; - if(!WarpZone_trace_firstzone) + if (!WarpZone_trace_firstzone) { WarpZone_trace_firstzone = wz; + } WarpZone_trace_lastzone = wz; - if(zone && wz != zone) + if (zone && wz != zone) { break; + } WarpZone_Trace_AddTransform(wz); // we hit a warpzone... so, let's perform the trace after the warp again org = WarpZone_TransformOrigin(wz, trace_endpos); @@ -321,9 +329,10 @@ void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, org = trace_endpos; } WarpZone_MakeAllOther(); -LABEL(fail) - if(contentshack) + LABEL(fail) + if (contentshack) { BITCLR_ASSIGN(WarpZone_trace_forent.dphitcontentsmask, DPCONTENTS_SOLID); + } trace_startsolid = sol; v_forward = vf; v_right = vr; @@ -355,11 +364,11 @@ void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZo WarpZone_trace_lastzone = NULL; WarpZone_Trace_InitTransform(); WarpZone_tracetoss_time = 0; - if(!warpzone_warpzones_exist) - { + if (!warpzone_warpzones_exist) { tracetoss(e, WarpZone_trace_forent); - if(cb) + if (cb) { cb(e.origin, trace_endpos, trace_endpos); + } dt = vlen(e.origin - o0) / vlen(e.velocity); WarpZone_tracetoss_time += dt; e.velocity_z -= dt * g; @@ -374,12 +383,10 @@ void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZo // if starting in warpzone, first transform wz = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs); - if(wz) - { + if (wz) { WarpZone_trace_firstzone = wz; WarpZone_trace_lastzone = wz; - if(zone && wz != zone) - { + if (zone && wz != zone) { // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return. WarpZone_tracetoss_time = 0; @@ -393,38 +400,40 @@ void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZo } WarpZone_MakeAllSolid(); i = 16; - for (;;) - { - if(--i < 1) - { + for ( ; ; ) { + if (--i < 1) { LOG_TRACE("Too many warpzones in sequence, aborting trace."); trace_ent = NULL; break; } tracetoss(e, WarpZone_trace_forent); - if(cb) + if (cb) { cb(e.origin, trace_endpos, trace_endpos); + } dt = vlen(trace_endpos - e.origin) / vlen(e.velocity); WarpZone_tracetoss_time += dt; e.origin = trace_endpos; e.velocity_z -= dt * g; - if(trace_fraction >= 1) + if (trace_fraction >= 1) { break; - if(trace_ent.classname != "trigger_warpzone") + } + if (trace_ent.classname != "trigger_warpzone") { break; - if(trace_ent == wz) - { + } + if (trace_ent == wz) { // FIXME can this check be removed? Do we really need it? LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace"); trace_ent = NULL; break; } wz = trace_ent; - if(!WarpZone_trace_firstzone) + if (!WarpZone_trace_firstzone) { WarpZone_trace_firstzone = wz; + } WarpZone_trace_lastzone = wz; - if(zone && wz != zone) + if (zone && wz != zone) { break; + } WarpZone_Trace_AddTransform(wz); // we hit a warpzone... so, let's perform the trace after the warp again e.origin = WarpZone_TransformOrigin(wz, e.origin); @@ -439,7 +448,7 @@ void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZo e.velocity = -e.velocity; } WarpZone_MakeAllOther(); -LABEL(fail) + LABEL(fail) WarpZone_tracetoss_velocity = e.velocity; v_forward = vf; v_right = vr; @@ -573,15 +582,15 @@ vector WarpZoneLib_NearestPointOnBox(vector mi, vector ma, vector org) bool WarpZoneLib_BadEntity(entity e) { - if (is_pure(e)) return true; + if (is_pure(e)) { return true; } string s = e.classname; - //if (s == "net_linked") return true; // actually some real entities are linked without classname, fail - if (s == "") return true; + // if (s == "net_linked") return true; // actually some real entities are linked without classname, fail + if (s == "") { return true; } - if (startsWith(s, "target_")) return true; + if (startsWith(s, "target_")) { return true; } - if (startsWith(s, "info_")) return true; + if (startsWith(s, "info_")) { return true; } return false; } @@ -589,54 +598,43 @@ bool WarpZoneLib_BadEntity(entity e) .float WarpZone_findradius_hit; .entity WarpZone_findradius_next; void WarpZone_FindRadius_Recurse( - /** blast origin of current search */ - vector org, - float rad, - /** original blast origin */ - vector org0, - /** how to untransform (victim to blast system) */ - vector transform, - vector shift, - bool needlineofsight) -{ - if (rad <= 0) return; + /** blast origin of current search */ + vector org, float rad, + /** original blast origin */ + vector org0, + /** how to untransform (victim to blast system) */ + vector transform, vector shift, bool needlineofsight) +{ + if (rad <= 0) { return; } entity wz = NULL; FOREACH_ENTITY_RADIUS(org, rad, !WarpZoneLib_BadEntity(it), { vector p = WarpZoneLib_NearestPointOnBox(it.origin + it.mins, it.origin + it.maxs, org0); - if (needlineofsight) - { + if (needlineofsight) { traceline(org, p, MOVE_NOMONSTERS, it); - if (trace_fraction < 1) continue; + if (trace_fraction < 1) { continue; } } - if (!it.WarpZone_findradius_hit || vlen2(it.WarpZone_findradius_dist) > vlen2(org0 - p)) - { + if (!it.WarpZone_findradius_hit || vlen2(it.WarpZone_findradius_dist) > vlen2(org0 - p)) { it.WarpZone_findradius_nearest = p; it.WarpZone_findradius_dist = org0 - p; it.WarpZone_findradius_findorigin = org; it.WarpZone_findradius_findradius = rad; - if (it.classname == "warpzone_refsys") - { - // ignore, especially: do not overwrite the refsys parameters - } - else if (it.classname == "trigger_warpzone") - { + if (it.classname == "warpzone_refsys") { + // ignore, especially: do not overwrite the refsys parameters + } else if (it.classname == "trigger_warpzone") { it.WarpZone_findradius_next = wz; wz = it; it.WarpZone_findradius_hit = 1; it.enemy.WarpZone_findradius_dist = '0 0 0'; // we don't want to go through this zone ever again it.enemy.WarpZone_findradius_hit = 1; - } - else - { + } else { it.warpzone_transform = transform; it.warpzone_shift = shift; it.WarpZone_findradius_hit = 1; } } - }); - for(entity e = wz; e; e = e.WarpZone_findradius_next) - { - if (WarpZoneLib_BadEntity(e)) continue; + }); + for (entity e = wz; e; e = e.WarpZone_findradius_next) { + if (WarpZoneLib_BadEntity(e)) { continue; } vector org0_new = WarpZone_TransformOrigin(e, org); traceline(e.warpzone_targetorigin, org0_new, MOVE_NOMONSTERS, e); @@ -656,8 +654,8 @@ void WarpZone_FindRadius_Recurse( } entity WarpZone_FindRadius(vector org, float rad, bool needlineofsight) { - // FIXME: why can't we do this? (sometimes finds nothing, breaking explosions) - // if (!warpzone_warpzones_exist && !needlineofsight) return findradius(org, rad); + // FIXME: why can't we do this? (sometimes finds nothing, breaking explosions) + // if (!warpzone_warpzones_exist && !needlineofsight) return findradius(org, rad); WarpZone_FindRadius_Recurse(org, rad, org, '0 0 0', '0 0 0', needlineofsight); entity list_first = findchainfloat(WarpZone_findradius_hit, 1); FOREACH_LIST(list, chain, true, it.WarpZone_findradius_hit = 0); @@ -669,13 +667,13 @@ void WarpZone_RefSys_GC(entity this) { // garbage collect unused reference systems this.nextthink = time + 1; - if(this.owner.WarpZone_refsys != this) + if (this.owner.WarpZone_refsys != this) { delete(this); + } } void WarpZone_RefSys_CheckCreate(entity me) { - if(me.WarpZone_refsys.owner != me) - { + if (me.WarpZone_refsys.owner != me) { me.WarpZone_refsys = new(warpzone_refsys); me.WarpZone_refsys.owner = me; setthink(me.WarpZone_refsys, WarpZone_RefSys_GC); @@ -685,16 +683,14 @@ void WarpZone_RefSys_CheckCreate(entity me) } void WarpZone_RefSys_Clear(entity me) { - if(me.WarpZone_refsys) - { + if (me.WarpZone_refsys) { delete(me.WarpZone_refsys); me.WarpZone_refsys = NULL; } } void WarpZone_RefSys_AddTransform(entity me, vector t, vector s) { - if(t != '0 0 0' || s != '0 0 0') - { + if (t != '0 0 0' || s != '0 0 0') { WarpZone_RefSys_CheckCreate(me); WarpZone_Accumulator_AddTransform(me.WarpZone_refsys, t, s); } @@ -705,8 +701,7 @@ void WarpZone_RefSys_Add(entity me, entity wz) } void WarpZone_RefSys_AddInverseTransform(entity me, vector t, vector s) { - if(t != '0 0 0' || s != '0 0 0') - { + if (t != '0 0 0' || s != '0 0 0') { WarpZone_RefSys_CheckCreate(me); WarpZone_Accumulator_AddInverseTransform(me.WarpZone_refsys, t, s); } @@ -719,10 +714,12 @@ void WarpZone_RefSys_AddInverse(entity me, entity wz) .vector WarpZone_refsys_incremental_transform; void WarpZone_RefSys_AddIncrementally(entity me, entity ref) { - //vector t, s; - if(me.WarpZone_refsys_incremental_transform == ref.WarpZone_refsys.warpzone_transform) - if(me.WarpZone_refsys_incremental_shift == ref.WarpZone_refsys.warpzone_shift) - return; + // vector t, s; + if (me.WarpZone_refsys_incremental_transform == ref.WarpZone_refsys.warpzone_transform) { + if (me.WarpZone_refsys_incremental_shift == ref.WarpZone_refsys.warpzone_shift) { + return; + } + } WarpZone_Accumulator_AddInverseTransform(me.WarpZone_refsys, me.WarpZone_refsys_incremental_transform, me.WarpZone_refsys_incremental_shift); WarpZone_Accumulator_Add(me.WarpZone_refsys, ref.WarpZone_refsys); me.WarpZone_refsys_incremental_shift = ref.WarpZone_refsys.warpzone_shift; @@ -735,46 +732,53 @@ void WarpZone_RefSys_BeginAddingIncrementally(entity me, entity ref) } vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org) { - if(from.WarpZone_refsys) + if (from.WarpZone_refsys) { org = WarpZone_UnTransformOrigin(from.WarpZone_refsys, org); - if(to.WarpZone_refsys) + } + if (to.WarpZone_refsys) { org = WarpZone_TransformOrigin(to.WarpZone_refsys, org); + } return org; } vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel) { - if(from.WarpZone_refsys) + if (from.WarpZone_refsys) { vel = WarpZone_UnTransformVelocity(from.WarpZone_refsys, vel); - if(to.WarpZone_refsys) + } + if (to.WarpZone_refsys) { vel = WarpZone_TransformVelocity(to.WarpZone_refsys, vel); + } return vel; } vector WarpZone_RefSys_TransformAngles(entity from, entity to, vector ang) { - if(from.WarpZone_refsys) + if (from.WarpZone_refsys) { ang = WarpZone_UnTransformAngles(from.WarpZone_refsys, ang); - if(to.WarpZone_refsys) + } + if (to.WarpZone_refsys) { ang = WarpZone_TransformAngles(to.WarpZone_refsys, ang); + } return ang; } vector WarpZone_RefSys_TransformVAngles(entity from, entity to, vector ang) { - if(from.WarpZone_refsys) + if (from.WarpZone_refsys) { ang = WarpZone_UnTransformVAngles(from.WarpZone_refsys, ang); - if(to.WarpZone_refsys) + } + if (to.WarpZone_refsys) { ang = WarpZone_TransformVAngles(to.WarpZone_refsys, ang); + } return ang; } void WarpZone_RefSys_Copy(entity me, entity from) { - if(from.WarpZone_refsys) - { + if (from.WarpZone_refsys) { WarpZone_RefSys_CheckCreate(me); me.WarpZone_refsys.warpzone_shift = from.WarpZone_refsys.warpzone_shift; me.WarpZone_refsys.warpzone_transform = from.WarpZone_refsys.warpzone_transform; - } - else + } else { WarpZone_RefSys_Clear(me); + } } entity WarpZone_RefSys_SpawnSameRefSys(entity me) { @@ -794,10 +798,10 @@ void WarpZoneLib_MoveOutOfSolid_Expand(entity e, vector by) { float eps = 0.0625; tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e); - if (trace_startsolid) + if (trace_startsolid) { return; - if (trace_fraction < 1) - { + } + if (trace_fraction < 1) { // hit something // adjust origin in the other direction... setorigin(e, e.origin - by * (1 - trace_fraction)); @@ -808,28 +812,35 @@ bool WarpZoneLib_MoveOutOfSolid(entity e) { vector o = e.origin; traceline(o, o, MOVE_WORLDONLY, e); - if (trace_startsolid) + if (trace_startsolid) { return false; + } tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e); - if (!trace_startsolid) + if (!trace_startsolid) { return true; + } vector m0 = e.mins; vector m1 = e.maxs; e.mins = '0 0 0'; e.maxs = '0 0 0'; - WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m0.x); e.mins.x = m0.x; - WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m1.x); e.maxs.x = m1.x; - WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m0.y); e.mins.y = m0.y; - WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m1.y); e.maxs.y = m1.y; - WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m0.z); e.mins.z = m0.z; - WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m1.z); e.maxs.z = m1.z; + WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m0.x); + e.mins.x = m0.x; + WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m1.x); + e.maxs.x = m1.x; + WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m0.y); + e.mins.y = m0.y; + WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m1.y); + e.maxs.y = m1.y; + WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m0.z); + e.mins.z = m0.z; + WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m1.z); + e.maxs.z = m1.z; setorigin(e, e.origin); tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e); - if (trace_startsolid) - { + if (trace_startsolid) { setorigin(e, o); return false; } diff --git a/qcsrc/lib/warpzone/common.qh b/qcsrc/lib/warpzone/common.qh index 0ddd0d052..3c2eb2ea0 100644 --- a/qcsrc/lib/warpzone/common.qh +++ b/qcsrc/lib/warpzone/common.qh @@ -4,7 +4,10 @@ // #define KEEP_ROLL IntrusiveList g_warpzones; -STATIC_INIT(g_warpzones) { g_warpzones = IL_NEW(); } +STATIC_INIT(g_warpzones) +{ + g_warpzones = IL_NEW(); +} float warpzone_warpzones_exist; float warpzone_cameras_exist; @@ -31,14 +34,14 @@ void WarpZone_MakeAllSolid(); void WarpZone_MakeAllOther(); #define MOVE_NOTHING -1 -entity WarpZone_trace_forent; // temp, callback is allowed to change it +entity WarpZone_trace_forent; // temp, callback is allowed to change it USING(WarpZone_trace_callback_t, void(vector start, vector hit, vector end)); // called on every elementary trace var WarpZone_trace_callback_t WarpZone_trace_callback_t_null; -entity WarpZone_trace_transform; // transform accumulator during a trace -entity WarpZone_trace_firstzone; // first warpzone hit by a trace (can differ from the requested zone in case of _ThroughZone, the trace is aborted then) -entity WarpZone_trace_lastzone; // first warpzone hit by a trace (can differ from the requested zone in case of _ThroughZone, the trace is aborted then) -vector WarpZone_tracetoss_velocity; // ending velocity of a tracetoss (post-transform) -float WarpZone_tracetoss_time; // duration of toss (approximate) +entity WarpZone_trace_transform; // transform accumulator during a trace +entity WarpZone_trace_firstzone; // first warpzone hit by a trace (can differ from the requested zone in case of _ThroughZone, the trace is aborted then) +entity WarpZone_trace_lastzone; // first warpzone hit by a trace (can differ from the requested zone in case of _ThroughZone, the trace is aborted then) +vector WarpZone_tracetoss_velocity; // ending velocity of a tracetoss (post-transform) +float WarpZone_tracetoss_time; // duration of toss (approximate) void WarpZone_TraceBox(vector org, vector min, vector max, vector end, float nomonsters, entity forent); void WarpZone_TraceBox_ThroughZone(vector org, vector min, vector max, vector end, float nomonsters, entity forent, entity zone, WarpZone_trace_callback_t cb); void WarpZone_TraceLine(vector org, vector end, float nomonsters, entity forent); @@ -68,43 +71,43 @@ vector WarpZone_UnTransformAngles(entity wz, vector v); vector WarpZone_UnTransformVAngles(entity wz, vector v); // reference systems (chained warpzone transforms) -void WarpZone_RefSys_Clear(entity me); // R := id -void WarpZone_RefSys_Add(entity me, entity wz); // me.R := wz me.R -void WarpZone_RefSys_AddInverse(entity me, entity wz); // me.R := wz^-1 me.R -void WarpZone_RefSys_AddTransform(entity me, vector t, vector s); // me.R := [t s] me.R +void WarpZone_RefSys_Clear(entity me); // R := id +void WarpZone_RefSys_Add(entity me, entity wz); // me.R := wz me.R +void WarpZone_RefSys_AddInverse(entity me, entity wz); // me.R := wz^-1 me.R +void WarpZone_RefSys_AddTransform(entity me, vector t, vector s); // me.R := [t s] me.R void WarpZone_RefSys_AddInverseTransform(entity me, vector t, vector s); // me.R := [t s]^-1 me.R // makes this reference system track ref's changes // NOTE: this is ONLY sensible if WarpZone_RefSys_Add is no longer called on "me" while doing this // To achieve this, make sure no touch events on warpzone are raised by this entity // or set a movetype that causes no warpzoning (e.g. MOVETYPE_NONE, MOVETYPE_FOLLOW) -void WarpZone_RefSys_AddIncrementally(entity me, entity ref); // me.R := ref.R me.Rref^-1 me.R; me.Rref := ref.R -void WarpZone_RefSys_BeginAddingIncrementally(entity me, entity ref); // me.Rref := ref.R +void WarpZone_RefSys_AddIncrementally(entity me, entity ref); // me.R := ref.R me.Rref^-1 me.R; me.Rref := ref.R +void WarpZone_RefSys_BeginAddingIncrementally(entity me, entity ref); // me.Rref := ref.R -vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org); // return to.R from.R^-1 org +vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org); // return to.R from.R^-1 org vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel); // return to.R from.R^-1 vel -vector WarpZone_RefSys_TransformAngles(entity from, entity to, vector ang); // return to.R from.R^-1 ang -vector WarpZone_RefSys_TransformVAngles(entity from, entity to, vector ang); // return to.R from.R^-1 ang -void WarpZone_RefSys_Copy(entity me, entity from); // to.R := from.R -entity WarpZone_RefSys_SpawnSameRefSys(entity me); // spawn().R = me.R +vector WarpZone_RefSys_TransformAngles(entity from, entity to, vector ang); // return to.R from.R^-1 ang +vector WarpZone_RefSys_TransformVAngles(entity from, entity to, vector ang); // return to.R from.R^-1 ang +void WarpZone_RefSys_Copy(entity me, entity from); // to.R := from.R +entity WarpZone_RefSys_SpawnSameRefSys(entity me); // spawn().R = me.R #ifndef BITCLR -# define BITCLR(a,b) ((a) - ((a) & (b))) +#define BITCLR(a, b) ((a) - ((a) & (b))) #endif #ifndef BITSET -# define BITSET(a,b) ((a) | (b)) +#define BITSET(a, b) ((a) | (b)) #endif #ifndef BITXOR -# define BITXOR(a,b) (((a) | (b)) - ((a) & (b))) +#define BITXOR(a, b) (((a) | (b)) - ((a) & (b))) #endif #ifndef BITCLR_ASSIGN -# define BITCLR_ASSIGN(a,b) ((a) = (a) - ((a) & (b))) +#define BITCLR_ASSIGN(a, b) ((a) = (a) - ((a) & (b))) #endif #ifndef BITSET_ASSIGN -# define BITSET_ASSIGN(a,b) ((a) |= (b)) +#define BITSET_ASSIGN(a, b) ((a) |= (b)) #endif #ifndef BITXOR_ASSIGN -# define BITXOR_ASSIGN(a,b) ((a) = ((a) | (b)) - ((a) & (b))) +#define BITXOR_ASSIGN(a, b) ((a) = ((a) | (b)) - ((a) & (b))) #endif bool WarpZoneLib_MoveOutOfSolid(entity e); #define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e) @@ -113,5 +116,5 @@ bool WarpZoneLib_ExactTrigger_Touch(entity this, entity toucher); void WarpZoneLib_ExactTrigger_Init(entity this); // WARNING: this kills the trace globals -#define EXACTTRIGGER_TOUCH(e,t) if(WarpZoneLib_ExactTrigger_Touch((e), (t))) return -#define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init(this) +#define EXACTTRIGGER_TOUCH(e, t) if (WarpZoneLib_ExactTrigger_Touch((e), (t))) return +#define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init(this) diff --git a/qcsrc/lib/warpzone/mathlib.qc b/qcsrc/lib/warpzone/mathlib.qc index 71fc25858..91eb1566e 100644 --- a/qcsrc/lib/warpzone/mathlib.qc +++ b/qcsrc/lib/warpzone/mathlib.qc @@ -4,12 +4,15 @@ int fpclassify(float e) { - if(isnan(e)) + if (isnan(e)) { return FP_NAN; - if(isinf(e)) + } + if (isinf(e)) { return FP_INFINITE; - if(e == 0) + } + if (e == 0) { return FP_ZERO; + } return FP_NORMAL; } bool isfinite(float e) @@ -23,7 +26,7 @@ bool isinf(float e) bool isnan(float e) { float f = e; - return (e != f); + return e != f; } bool isnormal(float e) { @@ -31,20 +34,20 @@ bool isnormal(float e) } bool signbit(float e) { - return (e < 0); + return e < 0; } float acosh(float e) { - return log(e + sqrt(e*e - 1)); + return log(e + sqrt(e * e - 1)); } float asinh(float e) { - return log(e + sqrt(e*e + 1)); + return log(e + sqrt(e * e + 1)); } float atanh(float e) { - return 0.5 * log((1+e) / (1-e)); + return 0.5 * log((1 + e) / (1 - e)); } float cosh(float e) { @@ -120,18 +123,18 @@ float scalbn(float e, int n) float cbrt(float e) { - return copysign(POW(fabs(e), (1.0/3.0)), e); + return copysign(POW(fabs(e), (1.0 / 3.0)), e); } float hypot(float e, float f) { - return sqrt(e*e + f*f); + return sqrt(e * e + f * f); } float erf(float e) { // approximation taken from wikipedia float f; - f = e*e; + f = e * e; return copysign(sqrt(1 - exp(-f * (1.273239544735163 + 0.14001228868667 * f) / (1 + 0.14001228868667 * f))), e); } float erfc(float e) @@ -141,12 +144,13 @@ float erfc(float e) vector lgamma(float e) { // TODO improve accuracy - if(!isfinite(e)) + if (!isfinite(e)) { return fabs(e) * '1 0 0' + copysign(1, e) * '0 1 0'; - if(e < 1 && e == floor(e)) + } + if (e < 1 && e == floor(e)) { return nan("gamma") * '1 1 1'; - if(e < 0.1) - { + } + if (e < 0.1) { vector v; v = lgamma(1.0 - e); // reflection formula: @@ -155,13 +159,15 @@ vector lgamma(float e) // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z) v.z = sin(M_PI * e); v.x = log(M_PI) - log(fabs(v.z)) - v.x; - if(v.z < 0) + if (v.z < 0) { v.y = -v.y; + } v.z = 0; return v; } - if(e < 1.1) + if (e < 1.1) { return lgamma(e + 1) - log(e) * '1 0 0'; + } e -= 1; return (0.5 * log(2 * M_PI * e) + e * (log(e) - 1)) * '1 0 0' + '0 1 0'; } @@ -191,7 +197,7 @@ float nearbyint(float e) } float trunc(float e) { - return (e>=0) ? floor(e) : ceil(e); + return (e >= 0) ? floor(e) : ceil(e); } float fmod(float e, float f) @@ -213,7 +219,7 @@ vector remquo(float e, float f) float copysign(float e, float f) { - return fabs(e) * ((f>0) ? 1 : -1); + return fabs(e) * ((f > 0) ? 1 : -1); } float nan(string tag) { @@ -222,22 +228,22 @@ float nan(string tag) float nextafter(float e, float f) { // TODO very crude - if(e == f) + if (e == f) { return nan("nextafter"); - if(e > f) + } + if (e > f) { return -nextafter(-e, -f); + } // now we know that e < f // so we need the next number > e float d, a, b; d = max(fabs(e), 0.00000000000000000000001); a = e + d; - do - { + do { d *= 0.5; b = a; a = e + d; - } - while(a != e); + } while (a != e); return b; } float nexttoward(float e, float f) @@ -247,7 +253,7 @@ float nexttoward(float e, float f) float fdim(float e, float f) { - return max(e-f, 0); + return max(e - f, 0); } float fmax(float e, float f) { diff --git a/qcsrc/lib/warpzone/mathlib.qh b/qcsrc/lib/warpzone/mathlib.qh index f5d8f63e7..1fc528513 100644 --- a/qcsrc/lib/warpzone/mathlib.qh +++ b/qcsrc/lib/warpzone/mathlib.qh @@ -17,13 +17,13 @@ bool isnan(float e); bool isnormal(float e); bool signbit(float e); -//float acos(float e); -//float asin(float e); -//float atan(float e); -//float atan2(float f, float e); -//float cos(float e); -//float sin(float e); -//float tan(float e); +// float acos(float e); +// float asin(float e); +// float atan(float e); +// float atan2(float f, float e); +// float cos(float e); +// float sin(float e); +// float tan(float e); float acosh(float e); float asinh(float e); @@ -39,7 +39,7 @@ float expm1(float e); vector frexp(float e); // returns mantissa as _x, exponent as _y int ilogb(float e); float ldexp(float e, int e); -//float log(float e); +// float log(float e); float logn(float e, float base); float log10(float e); float log1p(float e); @@ -50,10 +50,10 @@ vector modf(float f); // fraction as _x, integer as _y float scalbn(float e, int n); float cbrt(float e); -//float fabs(float e); +// float fabs(float e); float hypot(float e, float f); -//float pow(float e, float f); -//float sqrt(float e, float f); +// float pow(float e, float f); +// float sqrt(float e, float f); float erf(float e); float erfc(float e); @@ -71,11 +71,11 @@ float tgamma(float e); */ float pymod(float e, float f); -//float ceil(float e); -//float floor(float e); +// float ceil(float e); +// float floor(float e); float nearbyint(float e); -//float rint(float e); -//float round(float e); +// float rint(float e); +// float round(float e); float trunc(float e); float fmod(float e, float f); @@ -99,17 +99,17 @@ int islessequal(float e, float f); int islessgreater(float e, float f); int isunordered(float e, float f); -const float M_E = 2.7182818284590452354; /* e */ -const float M_LOG2E = 1.4426950408889634074; /* log_2 e */ -const float M_LOG10E = 0.43429448190325182765; /* log_10 e */ -const float M_LN2 = 0.69314718055994530942; /* log_e 2 */ -const float M_LN10 = 2.30258509299404568402; /* log_e 10 */ +const float M_E = 2.7182818284590452354; /* e */ +const float M_LOG2E = 1.4426950408889634074; /* log_2 e */ +const float M_LOG10E = 0.43429448190325182765; /* log_10 e */ +const float M_LN2 = 0.69314718055994530942; /* log_e 2 */ +const float M_LN10 = 2.30258509299404568402; /* log_e 10 */ // -Wdouble-declaration -#define M_PI 3.14159265358979323846 /* pi */ -const float M_PI_2 = 1.57079632679489661923; /* pi/2 */ -const float M_PI_4 = 0.78539816339744830962; /* pi/4 */ -const float M_1_PI = 0.31830988618379067154; /* 1/pi */ -const float M_2_PI = 0.63661977236758134308; /* 2/pi */ -const float M_2_SQRTPI = 1.12837916709551257390; /* 2/sqrt(pi) */ -const float M_SQRT2 = 1.41421356237309504880; /* sqrt(2) */ -const float M_SQRT1_2 = 0.70710678118654752440; /* 1/sqrt(2) */ +#define M_PI 3.14159265358979323846 /* pi */ +const float M_PI_2 = 1.57079632679489661923; /* pi/2 */ +const float M_PI_4 = 0.78539816339744830962; /* pi/4 */ +const float M_1_PI = 0.31830988618379067154; /* 1/pi */ +const float M_2_PI = 0.63661977236758134308; /* 2/pi */ +const float M_2_SQRTPI = 1.12837916709551257390; /* 2/sqrt(pi) */ +const float M_SQRT2 = 1.41421356237309504880; /* sqrt(2) */ +const float M_SQRT1_2 = 0.70710678118654752440; /* 1/sqrt(2) */ diff --git a/qcsrc/lib/warpzone/server.qc b/qcsrc/lib/warpzone/server.qc index e15fd4707..392cc84df 100644 --- a/qcsrc/lib/warpzone/server.qc +++ b/qcsrc/lib/warpzone/server.qc @@ -28,11 +28,12 @@ .float warpzone_teleport_finishtime; .entity warpzone_teleport_zone; -#define WarpZone_StoreProjectileData(e_) MACRO_BEGIN \ - entity e = e_; \ - e.warpzone_oldorigin = e.origin; \ - e.warpzone_oldvelocity = e.velocity; \ - e.warpzone_oldangles = e.angles; \ +#define WarpZone_StoreProjectileData(e_) \ + MACRO_BEGIN \ + entity e = e_; \ + e.warpzone_oldorigin = e.origin; \ + e.warpzone_oldvelocity = e.velocity; \ + e.warpzone_oldangles = e.angles; \ MACRO_END void WarpZone_TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity) @@ -47,8 +48,9 @@ void WarpZone_TeleportPlayer(entity teleporter, entity player, vector to, vector BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT); - if(IS_PLAYER(player)) + if (IS_PLAYER(player)) { BITCLR_ASSIGN(player.flags, FL_ONGROUND); + } WarpZone_PostTeleportPlayer_Callback(player); } @@ -74,13 +76,13 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) o10 = o1 = WarpZone_TransformOrigin(wz, o0); v1 = WarpZone_TransformVelocity(wz, v0); - if (!IS_NOT_A_CLIENT(player)) + if (!IS_NOT_A_CLIENT(player)) { a1 = WarpZone_TransformVAngles(wz, PHYS_INPUT_ANGLES(player)); - else + } else { a1 = WarpZone_TransformAngles(wz, a0); + } - if(f0 != 0 || f1 != 0) - { + if (f0 != 0 || f1 != 0) { // retry last move but behind the warpzone! // we must first go back as far as we can, then forward again, to not cause double touch events! @@ -98,22 +100,19 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) md = max(vlen(player.mins), vlen(player.maxs)); d = WarpZone_TargetPlaneDist(wz, o1); dv = WarpZone_TargetPlaneDist(wz, v1); - if(d < 0) + if (d < 0) { o1 = o1 - v1 * (d / dv); + } } // put him out of solid tracebox(o1 - player.view_ofs, player.mins, player.maxs, o1 - player.view_ofs, MOVE_NOMONSTERS, player); - if(trace_startsolid) - { + if (trace_startsolid) { setorigin(player, o1 - player.view_ofs); - if(WarpZoneLib_MoveOutOfSolid(player)) - { + if (WarpZoneLib_MoveOutOfSolid(player)) { o1 = player.origin + player.view_ofs; setorigin(player, o0 - player.view_ofs); - } - else - { + } else { LOG_INFO("would have to put player in solid, won't do that"); setorigin(player, o0 - player.view_ofs); return 0; @@ -131,16 +130,17 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) #ifdef SVQC // prevent further teleports back float dt = (o1 - o10) * v1 * (1 / (v1 * v1)); - if(dt < PHYS_INPUT_FRAMETIME) + if (dt < PHYS_INPUT_FRAMETIME) { player.warpzone_teleport_finishtime += PHYS_INPUT_FRAMETIME - dt; + } #endif #ifndef WARPZONE_USE_FIXANGLE #ifdef SVQC - if(IS_VEHICLE(player) && player.owner) + if (IS_VEHICLE(player) && player.owner) { player = player.owner; // hax - if(IS_PLAYER(player)) - { + } + if (IS_PLAYER(player)) { // instead of fixangle, send the transform to the client for smoother operation player.fixangle = false; @@ -158,8 +158,8 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) } #elif defined(CSQC) setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(wz, getpropertyvec(VF_CL_VIEWANGLES))); - //if(checkextension("DP_CSQC_ROTATEMOVES")) - //CL_RotateMoves(wz.warpzone_transform); + // if(checkextension("DP_CSQC_ROTATEMOVES")) + // CL_RotateMoves(wz.warpzone_transform); #endif #endif @@ -168,25 +168,30 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) void WarpZone_Touch(entity this, entity toucher) { - if(toucher.classname == "trigger_warpzone") + if (toucher.classname == "trigger_warpzone") { return; + } - if(time <= toucher.warpzone_teleport_finishtime) // already teleported this frame + if (time <= toucher.warpzone_teleport_finishtime) { // already teleported this frame return; + } // FIXME needs a better check to know what is safe to teleport and what not - if((toucher.move_movetype == MOVETYPE_NONE && toucher.move_movetype == MOVETYPE_NONE) || toucher.move_movetype == MOVETYPE_FOLLOW || toucher.move_movetype == MOVETYPE_FOLLOW || toucher.tag_entity + if ((toucher.move_movetype == MOVETYPE_NONE && toucher.move_movetype == MOVETYPE_NONE) || toucher.move_movetype == MOVETYPE_FOLLOW || toucher.move_movetype == MOVETYPE_FOLLOW || toucher.tag_entity #ifdef CSQC - || tag_networkentity + || tag_networkentity #endif - ) + ) { return; + } - if(WarpZoneLib_ExactTrigger_Touch(this, toucher)) + if (WarpZoneLib_ExactTrigger_Touch(this, toucher)) { return; + } - if(WarpZone_PlaneDist(this, toucher.origin + toucher.view_ofs) >= 0) // wrong side of the trigger_warpzone (don't teleport yet) + if (WarpZone_PlaneDist(this, toucher.origin + toucher.view_ofs) >= 0) { // wrong side of the trigger_warpzone (don't teleport yet) return; + } float f; // number of frames we need to go back: @@ -201,30 +206,32 @@ void WarpZone_Touch(entity this, entity toucher) // 96*frametime float d; d = 24 + max(vlen(toucher.mins), vlen(toucher.maxs)); - if(IS_NOT_A_CLIENT(toucher)) + if (IS_NOT_A_CLIENT(toucher)) { f = -d / bound(frametime * d * 1, frametime * vlen(toucher.velocity), d); - else + } else { f = -1; - if(WarpZone_Teleport(this, toucher, f, 0)) - { + } + if (WarpZone_Teleport(this, toucher, f, 0)) { #ifdef SVQC string save1, save2; - save1 = this.target; this.target = string_null; - save2 = this.target3; this.target3 = string_null; + save1 = this.target; + this.target = string_null; + save2 = this.target3; + this.target3 = string_null; SUB_UseTargets(this, toucher, toucher); // use toucher too? - if (!this.target) this.target = save1; - if (!this.target3) this.target3 = save2; + if (!this.target) { this.target = save1; } + if (!this.target3) { this.target3 = save2; } - save1 = this.target; this.target = string_null; - save2 = this.target2; this.target2 = string_null; + save1 = this.target; + this.target = string_null; + save2 = this.target2; + this.target2 = string_null; SUB_UseTargets(this.enemy, toucher, toucher); // use toucher too? - if (!this.target) this.target = save1; - if (!this.target2) this.target2 = save2; + if (!this.target) { this.target = save1; } + if (!this.target2) { this.target2 = save2; } #endif - } - else - { + } else { LOG_TRACE("WARPZONE FAIL AHAHAHAHAH))"); } } @@ -236,17 +243,19 @@ bool WarpZone_Send(entity this, entity to, int sendflags) // we must send this flag for clientside to match properly too int f = 0; - if(this.warpzone_isboxy) + if (this.warpzone_isboxy) { BITSET_ASSIGN(f, 1); - if(this.warpzone_fadestart) + } + if (this.warpzone_fadestart) { BITSET_ASSIGN(f, 2); - if(this.origin != '0 0 0') + } + if (this.origin != '0 0 0') { BITSET_ASSIGN(f, 4); + } WriteByte(MSG_ENTITY, f); // we need THESE to render the warpzone (and cull properly)... - if(f & 4) - { + if (f & 4) { WriteCoord(MSG_ENTITY, this.origin.x); WriteCoord(MSG_ENTITY, this.origin.y); WriteCoord(MSG_ENTITY, this.origin.z); @@ -275,8 +284,7 @@ bool WarpZone_Send(entity this, entity to, int sendflags) WriteCoord(MSG_ENTITY, this.warpzone_targetangles.y); WriteCoord(MSG_ENTITY, this.warpzone_targetangles.z); - if(f & 2) - { + if (f & 2) { WriteShort(MSG_ENTITY, this.warpzone_fadestart); WriteShort(MSG_ENTITY, this.warpzone_fadeend); } @@ -289,15 +297,16 @@ bool WarpZone_Camera_Send(entity this, entity to, int sendflags) int f = 0; WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE_CAMERA); - if(this.warpzone_fadestart) + if (this.warpzone_fadestart) { BITSET_ASSIGN(f, 2); - if(this.origin != '0 0 0') + } + if (this.origin != '0 0 0') { BITSET_ASSIGN(f, 4); + } WriteByte(MSG_ENTITY, f); // we need THESE to render the warpzone (and cull properly)... - if(f & 4) - { + if (f & 4) { WriteCoord(MSG_ENTITY, this.origin.x); WriteCoord(MSG_ENTITY, this.origin.y); WriteCoord(MSG_ENTITY, this.origin.z); @@ -320,8 +329,7 @@ bool WarpZone_Camera_Send(entity this, entity to, int sendflags) WriteCoord(MSG_ENTITY, this.enemy.angles.y); WriteCoord(MSG_ENTITY, this.enemy.angles.z); - if(f & 2) - { + if (f & 2) { WriteShort(MSG_ENTITY, this.warpzone_fadestart); WriteShort(MSG_ENTITY, this.warpzone_fadeend); } @@ -338,14 +346,16 @@ float WarpZone_CheckProjectileImpact(entity player) v0 = player.velocity; // if we teleported shortly before, abort - if(time <= player.warpzone_teleport_finishtime + 0.1) + if (time <= player.warpzone_teleport_finishtime + 0.1) { return 0; + } // if player hit a warpzone, abort entity wz; wz = WarpZone_Find(o0 + player.mins, o0 + player.maxs); - if(!wz) + if (!wz) { return 0; + } #ifdef WARPZONELIB_REMOVEHACK LOG_INFO("impactfilter found something - and it no longer gets handled correctly - please tell divVerent whether anything behaves broken now"); @@ -362,24 +372,25 @@ float WarpZone_CheckProjectileImpact(entity player) // retry previous move setorigin(player, player.warpzone_oldorigin); player.velocity = player.warpzone_oldvelocity; - if(WarpZone_Teleport(wz, player, 0, 1)) - { + if (WarpZone_Teleport(wz, player, 0, 1)) { string save1, save2; - save1 = wz.target; wz.target = string_null; - save2 = wz.target3; wz.target3 = string_null; + save1 = wz.target; + wz.target = string_null; + save2 = wz.target3; + wz.target3 = string_null; SUB_UseTargets(wz, player, player); - if (!wz.target) wz.target = save1; - if (!wz.target3) wz.target3 = save2; + if (!wz.target) { wz.target = save1; } + if (!wz.target3) { wz.target3 = save2; } - save1 = wz.enemy.target; wz.enemy.target = string_null; - save2 = wz.enemy.target2; wz.enemy.target2 = string_null; + save1 = wz.enemy.target; + wz.enemy.target = string_null; + save2 = wz.enemy.target2; + wz.enemy.target2 = string_null; SUB_UseTargets(wz.enemy, player, player); - if (!wz.enemy.target) wz.enemy.target = save1; - if (!wz.enemy.target2) wz.enemy.target2 = save2; - } - else - { + if (!wz.enemy.target) { wz.enemy.target = save1; } + if (!wz.enemy.target2) { wz.enemy.target2 = save2; } + } else { setorigin(player, o0 - player.view_ofs); player.velocity = v0; } @@ -392,8 +403,9 @@ float WarpZone_CheckProjectileImpact(entity player) float WarpZone_Projectile_Touch(entity this, entity toucher) { - if(toucher.classname == "trigger_warpzone") + if (toucher.classname == "trigger_warpzone") { return true; + } // no further impacts if we teleported this frame! // this is because even if we did teleport, the engine still may raise @@ -401,8 +413,9 @@ float WarpZone_Projectile_Touch(entity this, entity toucher) // engine now aborts moves on teleport, so this SHOULD not happen any more // but if this is called from TouchAreaGrid of the projectile moving, // then this won't do - if(time == this.warpzone_teleport_time) + if (time == this.warpzone_teleport_time) { return true; + } #ifdef SVQC #ifdef WARPZONELIB_KEEPDEBUG @@ -435,7 +448,7 @@ float WarpZone_Projectile_Touch(entity this, entity toucher) save_inopen = trace_inopen; save_inwater = trace_inwater; float f = WarpZone_CheckProjectileImpact(this); - if (f) return (f > 0); + if (f) { return f > 0; } trace_dpstartcontents = save_dpstartcontents; trace_dphitcontents = save_dphitcontents; trace_dphitq3surfaceflags = save_dphitq3surfaceflags; @@ -452,8 +465,9 @@ float WarpZone_Projectile_Touch(entity this, entity toucher) } #endif - if(WarpZone_Projectile_Touch_ImpactFilter_Callback(this, toucher)) + if (WarpZone_Projectile_Touch_ImpactFilter_Callback(this, toucher)) { return true; + } #endif return false; @@ -463,11 +477,9 @@ float WarpZone_Projectile_Touch(entity this, entity toucher) void WarpZone_InitStep_FindOriginTarget(entity this) { - if(this.killtarget != "") - { + if (this.killtarget != "") { this.aiment = find(NULL, targetname, this.killtarget); - if(this.aiment == NULL) - { + if (this.aiment == NULL) { error("Warp zone with nonexisting killtarget"); return; } @@ -477,19 +489,16 @@ void WarpZone_InitStep_FindOriginTarget(entity this) void WarpZonePosition_InitStep_FindTarget(entity this) { - if(this.target == "") - { + if (this.target == "") { error("Warp zone position with no target"); return; } this.enemy = find(NULL, targetname, this.target); - if(this.enemy == NULL) - { + if (this.enemy == NULL) { error("Warp zone position with nonexisting target"); return; } - if(this.enemy.aiment) - { + if (this.enemy.aiment) { // already is positioned error("Warp zone position targeting already oriented warpzone"); return; @@ -499,11 +508,10 @@ void WarpZonePosition_InitStep_FindTarget(entity this) void WarpZoneCamera_Think(entity this) { - if(this.warpzone_save_origin != this.origin - || this.warpzone_save_angles != this.angles - || this.warpzone_save_eorigin != this.enemy.origin - || this.warpzone_save_eangles != this.enemy.angles) - { + if (this.warpzone_save_origin != this.origin + || this.warpzone_save_angles != this.angles + || this.warpzone_save_eorigin != this.enemy.origin + || this.warpzone_save_eangles != this.enemy.angles) { WarpZone_Camera_SetUp(this, this.enemy.origin, this.enemy.angles); this.warpzone_save_origin = this.origin; this.warpzone_save_angles = this.angles; @@ -517,30 +525,29 @@ void WarpZoneCamera_InitStep_FindTarget(entity this) { entity e; float i; - if(this.target == "") - { + if (this.target == "") { error("Camera with no target"); return; } this.enemy = NULL; - for(e = NULL, i = 0; (e = find(e, targetname, this.target)); ) - if(random() * ++i < 1) + for (e = NULL, i = 0; (e = find(e, targetname, this.target)); ) { + if (random() * ++i < 1) { this.enemy = e; - if(this.enemy == NULL) - { + } + } + if (this.enemy == NULL) { error("Camera with nonexisting target"); return; } warpzone_cameras_exist = 1; WarpZone_Camera_SetUp(this, this.enemy.origin, this.enemy.angles); this.SendFlags = 0xFFFFFF; - if(this.spawnflags & 1) - { + if (this.spawnflags & 1) { setthink(this, WarpZoneCamera_Think); this.nextthink = time; - } - else + } else { this.nextthink = 0; + } } void WarpZone_InitStep_UpdateTransform(entity this) @@ -552,21 +559,22 @@ void WarpZone_InitStep_UpdateTransform(entity this) string tex; org = this.origin; - if(org == '0 0 0') + if (org == '0 0 0') { org = 0.5 * (this.mins + this.maxs); + } norm = point = '0 0 0'; area = 0; - for(i_s = 0; ; ++i_s) - { + for (i_s = 0; ; ++i_s) { tex = getsurfacetexture(this, i_s); - if (!tex) + if (!tex) { break; // this is beyond the last one - if(tex == "textures/common/trigger" || tex == "trigger") + } + if (tex == "textures/common/trigger" || tex == "trigger") { continue; + } n_t = getsurfacenumtriangles(this, i_s); - for(i_t = 0; i_t < n_t; ++i_t) - { + for (i_t = 0; i_t < n_t; ++i_t) { tri = getsurfacetriangle(this, i_s, i_t); a = getsurfacepoint(this, i_s, tri.x); b = getsurfacepoint(this, i_s, tri.y); @@ -577,12 +585,10 @@ void WarpZone_InitStep_UpdateTransform(entity this) point = point + vlen(n) * (a + b + c); } } - if(area > 0) - { + if (area > 0) { norm = norm * (1 / area); point = point * (1 / (3 * area)); - if(vdist(norm, <, 0.99)) - { + if (vdist(norm, <, 0.99)) { LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " is nonplanar. BEWARE."); area = 0; // no autofixing in this case } @@ -590,35 +596,32 @@ void WarpZone_InitStep_UpdateTransform(entity this) } ang = '0 0 0'; - if(this.aiment) - { + if (this.aiment) { org = this.aiment.origin; ang = this.aiment.angles; - if(area > 0) - { + if (area > 0) { org = org - ((org - point) * norm) * norm; // project to plane makevectors(ang); - if(norm * v_forward < 0) - { + if (norm * v_forward < 0) { LOG_INFO("Position target of trigger_warpzone near ", vtos(this.aiment.origin), " points into trigger_warpzone. BEWARE."); norm = -1 * norm; } ang = vectoangles2(norm, v_up); // keep rotation, but turn exactly against plane ang.x = -ang.x; - if(norm * v_forward < 0.99) + if (norm * v_forward < 0.99) { LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " has been turned to match plane orientation (", vtos(this.aiment.angles), " -> ", vtos(ang)); - if(vdist(org - this.aiment.origin, >, 0.5)) + } + if (vdist(org - this.aiment.origin, >, 0.5)) { LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " has been moved to match the plane (", vtos(this.aiment.origin), " -> ", vtos(org), ")."); + } } - } - else if(area > 0) - { + } else if (area > 0) { org = point; ang = vectoangles(norm); ang.x = -ang.x; - } - else + } else { error("cannot infer origin/angles for this warpzone, please use a killtarget or a trigger_warpzone_position"); + } this.warpzone_origin = org; this.warpzone_angles = ang; @@ -626,8 +629,9 @@ void WarpZone_InitStep_UpdateTransform(entity this) void WarpZone_InitStep_ClearTarget(entity this) { - if(this.enemy) + if (this.enemy) { this.enemy.enemy = NULL; + } this.enemy = NULL; } @@ -636,22 +640,25 @@ void WarpZone_InitStep_FindTarget(entity this) float i; entity e, e2; - if(this.enemy) + if (this.enemy) { return; + } // this way only one of the two ents needs to target - if(this.target != "") - { + if (this.target != "") { this.enemy = this; // so the if(!e.enemy) check also skips this, saves one IF e2 = NULL; - for(e = NULL, i = 0; (e = find(e, targetname, this.target)); ) - if(!e.enemy) - if(e.classname == this.classname) // possibly non-warpzones may use the same targetname! - if(random() * ++i < 1) + for (e = NULL, i = 0; (e = find(e, targetname, this.target)); ) { + if (!e.enemy) { + if (e.classname == this.classname) { // possibly non-warpzones may use the same targetname! + if (random() * ++i < 1) { e2 = e; - if(!e2) - { + } + } + } + } + if (!e2) { this.enemy = NULL; error("Warpzone with non-existing target"); return; @@ -664,8 +671,7 @@ void WarpZone_InitStep_FindTarget(entity this) void WarpZone_Think(entity this); void WarpZone_InitStep_FinalizeTransform(entity this) { - if(!this.enemy || this.enemy.enemy != this) - { + if (!this.enemy || this.enemy.enemy != this) { error("Invalid warp zone detected. Killed."); return; } @@ -674,17 +680,16 @@ void WarpZone_InitStep_FinalizeTransform(entity this) WarpZone_SetUp(this, this.warpzone_origin, this.warpzone_angles, this.enemy.warpzone_origin, this.enemy.warpzone_angles); settouch(this, WarpZone_Touch); this.SendFlags = 0xFFFFFF; - if(this.spawnflags & 1) - { + if (this.spawnflags & 1) { setthink(this, WarpZone_Think); this.nextthink = time; - } - else + } else { this.nextthink = 0; + } } float warpzone_initialized; -//entity warpzone_first; +// entity warpzone_first; entity warpzone_position_first; entity warpzone_camera_first; .entity warpzone_next; @@ -708,23 +713,25 @@ spawnfunc(trigger_warpzone) // the map, with another killtarget to designate its // orientation - if(!this.scale) + if (!this.scale) { this.scale = this.modelscale; - if(!this.scale) + } + if (!this.scale) { this.scale = 1; + } string m; m = this.model; WarpZoneLib_ExactTrigger_Init(this); - if(m != "") - { - precache_model(m); - _setmodel(this, m); // no precision needed + if (m != "") { + precache_model(m); + _setmodel(this, m); // no precision needed } setorigin(this, this.origin); - if(this.scale) + if (this.scale) { setsize(this, this.mins * this.scale, this.maxs * this.scale); - else + } else { setsize(this, this.mins, this.maxs); + } setSendEntity(this, WarpZone_Send); this.SendFlags = 0xFFFFFF; BITSET_ASSIGN(this.effects, EF_NODEPTHTEST); @@ -735,24 +742,27 @@ spawnfunc(trigger_warpzone) } spawnfunc(func_camera) { - if(!this.scale) + if (!this.scale) { this.scale = this.modelscale; - if(!this.scale) + } + if (!this.scale) { this.scale = 1; - if(this.model != "") - { - precache_model(this.model); - _setmodel(this, this.model); // no precision needed + } + if (this.model != "") { + precache_model(this.model); + _setmodel(this, this.model); // no precision needed } setorigin(this, this.origin); - if(this.scale) + if (this.scale) { setsize(this, this.mins * this.scale, this.maxs * this.scale); - else + } else { setsize(this, this.mins, this.maxs); - if(!this.solid) + } + if (!this.solid) { this.solid = SOLID_BSP; - else if(this.solid < 0) + } else if (this.solid < 0) { this.solid = SOLID_NOT; + } setSendEntity(this, WarpZone_Camera_Send); this.SendFlags = 0xFFFFFF; this.warpzone_next = warpzone_camera_first; @@ -760,23 +770,26 @@ spawnfunc(func_camera) } void WarpZones_Reconnect() { - for(entity e = warpzone_first; e; e = e.warpzone_next) + for (entity e = warpzone_first; e; e = e.warpzone_next) { WarpZone_InitStep_ClearTarget(e); - for(entity e = warpzone_first; e; e = e.warpzone_next) + } + for (entity e = warpzone_first; e; e = e.warpzone_next) { WarpZone_InitStep_FindTarget(e); - for(entity e = warpzone_camera_first; e; e = e.warpzone_next) + } + for (entity e = warpzone_camera_first; e; e = e.warpzone_next) { WarpZoneCamera_InitStep_FindTarget(e); - for(entity e = warpzone_first; e; e = e.warpzone_next) + } + for (entity e = warpzone_first; e; e = e.warpzone_next) { WarpZone_InitStep_FinalizeTransform(e); + } } void WarpZone_Think(entity this) { - if(this.warpzone_save_origin != this.origin - || this.warpzone_save_angles != this.angles - || this.warpzone_save_eorigin != this.enemy.origin - || this.warpzone_save_eangles != this.enemy.angles) - { + if (this.warpzone_save_origin != this.origin + || this.warpzone_save_angles != this.angles + || this.warpzone_save_eorigin != this.enemy.origin + || this.warpzone_save_eangles != this.enemy.angles) { WarpZone_InitStep_UpdateTransform(this); WarpZone_InitStep_UpdateTransform(this.enemy); WarpZone_InitStep_FinalizeTransform(this); @@ -791,21 +804,22 @@ void WarpZone_Think(entity this) void WarpZone_StartFrame() { - if (!warpzone_initialized) - { + if (!warpzone_initialized) { warpzone_initialized = true; - for(entity e = warpzone_first; e; e = e.warpzone_next) + for (entity e = warpzone_first; e; e = e.warpzone_next) { WarpZone_InitStep_FindOriginTarget(e); - for(entity e = warpzone_position_first; e; e = e.warpzone_next) + } + for (entity e = warpzone_position_first; e; e = e.warpzone_next) { WarpZonePosition_InitStep_FindTarget(e); - for(entity e = warpzone_first; e; e = e.warpzone_next) + } + for (entity e = warpzone_first; e; e = e.warpzone_next) { WarpZone_InitStep_UpdateTransform(e); + } WarpZones_Reconnect(); WarpZone_PostInitialize_Callback(); } - if(warpzone_warpzones_exist) - { + if (warpzone_warpzones_exist) { IL_EACH(g_projectiles, true, { WarpZone_StoreProjectileData(it); @@ -815,28 +829,32 @@ void WarpZone_StartFrame() FOREACH_CLIENT(true, { - if(warpzone_warpzones_exist) + if (warpzone_warpzones_exist) { WarpZone_StoreProjectileData(it); // TODO: not actually needed - - if(IS_OBSERVER(it) || it.solid == SOLID_NOT) - if(IS_CLIENT(it)) // we don't care about it being a bot - { - // warpzones - if (warpzone_warpzones_exist) { - entity e = WarpZone_Find(it.origin + it.mins, it.origin + it.maxs); - if (e) - if (!WarpZoneLib_ExactTrigger_Touch(e, it)) - if (WarpZone_PlaneDist(e, it.origin + it.view_ofs) <= 0) - WarpZone_Teleport(e, it, -1, 0); // NOT triggering targets by this! - } - - // teleporters - if(it.teleportable) - { - entity ent = Teleport_Find(it.origin + it.mins, it.origin + it.maxs); - if (ent) - if (!WarpZoneLib_ExactTrigger_Touch(ent, it)) - Simple_TeleportPlayer(ent, it); // NOT triggering targets by this! + } + if (IS_OBSERVER(it) || it.solid == SOLID_NOT) { + if (IS_CLIENT(it)) { // we don't care about it being a bot + // warpzones + if (warpzone_warpzones_exist) { + entity e = WarpZone_Find(it.origin + it.mins, it.origin + it.maxs); + if (e) { + if (!WarpZoneLib_ExactTrigger_Touch(e, it)) { + if (WarpZone_PlaneDist(e, it.origin + it.view_ofs) <= 0) { + WarpZone_Teleport(e, it, -1, 0); // NOT triggering targets by this! + } + } + } + } + + // teleporters + if (it.teleportable) { + entity ent = Teleport_Find(it.origin + it.mins, it.origin + it.maxs); + if (ent) { + if (!WarpZoneLib_ExactTrigger_Touch(ent, it)) { + Simple_TeleportPlayer(ent, it); // NOT triggering targets by this! + } + } + } } } }); @@ -855,22 +873,32 @@ void trigger_warpzone_reconnect_use(entity this, entity actor, entity trigger) { // NOTE: this matches for target, not targetname, but of course // targetname must be set too on the other entities - for(entity e = warpzone_first; e; e = e.warpzone_next) + for (entity e = warpzone_first; e; e = e.warpzone_next) { e.warpzone_reconnecting = ((this.target == "" || e.target == this.target) && !((this.spawnflags & 1) && (visible_to_some_client(e) || visible_to_some_client(e.enemy)))); - for(entity e = warpzone_camera_first; e; e = e.warpzone_next) + } + for (entity e = warpzone_camera_first; e; e = e.warpzone_next) { e.warpzone_reconnecting = ((this.target == "" || e.target == this.target) && !((this.spawnflags & 1) && visible_to_some_client(e))); - for(entity e = warpzone_first; e; e = e.warpzone_next) - if(e.warpzone_reconnecting) + } + for (entity e = warpzone_first; e; e = e.warpzone_next) { + if (e.warpzone_reconnecting) { WarpZone_InitStep_ClearTarget(e); - for(entity e = warpzone_first; e; e = e.warpzone_next) - if(e.warpzone_reconnecting) + } + } + for (entity e = warpzone_first; e; e = e.warpzone_next) { + if (e.warpzone_reconnecting) { WarpZone_InitStep_FindTarget(e); - for(entity e = warpzone_camera_first; e; e = e.warpzone_next) - if(e.warpzone_reconnecting) + } + } + for (entity e = warpzone_camera_first; e; e = e.warpzone_next) { + if (e.warpzone_reconnecting) { WarpZoneCamera_InitStep_FindTarget(e); - for(entity e = warpzone_first; e; e = e.warpzone_next) - if(e.warpzone_reconnecting || e.enemy.warpzone_reconnecting) + } + } + for (entity e = warpzone_first; e; e = e.warpzone_next) { + if (e.warpzone_reconnecting || e.enemy.warpzone_reconnecting) { WarpZone_InitStep_FinalizeTransform(e); + } + } } spawnfunc(trigger_warpzone_reconnect) @@ -886,12 +914,13 @@ spawnfunc(target_warpzone_reconnect) void WarpZone_PlayerPhysics_FixVAngle(entity this) { #ifndef WARPZONE_DONT_FIX_VANGLE - if(IS_REAL_CLIENT(this)) - if(this.v_angle.z <= 360) // if not already adjusted - if(time - CS(this).ping * 0.001 < this.warpzone_teleport_time) - { - this.v_angle = WarpZone_TransformVAngles(this.warpzone_teleport_zone, this.v_angle); - this.v_angle_z += 720; // mark as adjusted + if (IS_REAL_CLIENT(this)) { + if (this.v_angle.z <= 360) { // if not already adjusted + if (time - CS(this).ping * 0.001 < this.warpzone_teleport_time) { + this.v_angle = WarpZone_TransformVAngles(this.warpzone_teleport_zone, this.v_angle); + this.v_angle_z += 720; // mark as adjusted + } + } } #endif } diff --git a/qcsrc/lib/warpzone/server.qh b/qcsrc/lib/warpzone/server.qh index 4287ef60d..b468c70e1 100644 --- a/qcsrc/lib/warpzone/server.qh +++ b/qcsrc/lib/warpzone/server.qh @@ -1,7 +1,8 @@ #pragma once #ifdef SVQC -entity warpzone_first; .entity warpzone_next; +entity warpzone_first; +.entity warpzone_next; void WarpZone_StartFrame(); float WarpZone_Projectile_Touch(entity this, entity toucher); @@ -11,8 +12,8 @@ void WarpZone_PostTeleportPlayer_Callback(entity pl); bool WarpZone_Projectile_Touch_ImpactFilter_Callback(entity this, entity toucher); // server must also define a float called ENT_CLIENT_WARPZONE for the initial byte of WarpZone entities -//const float ENT_CLIENT_WARPZONE; -//const float ENT_CLIENT_WARPZONE_CAMERA; +// const float ENT_CLIENT_WARPZONE; +// const float ENT_CLIENT_WARPZONE_CAMERA; void WarpZone_PlayerPhysics_FixVAngle(entity this); diff --git a/qcsrc/lib/warpzone/util_server.qc b/qcsrc/lib/warpzone/util_server.qc index d5533647f..50294aacc 100644 --- a/qcsrc/lib/warpzone/util_server.qc +++ b/qcsrc/lib/warpzone/util_server.qc @@ -5,44 +5,41 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include + #include #endif #include "common.qh" void WarpZoneLib_ExactTrigger_Init(entity this) { vector mi, ma; - if (this.movedir == '0 0 0') - if (this.angles != '0 0 0') - { - makevectors (this.angles); - this.movedir = v_forward; + if (this.movedir == '0 0 0') { + if (this.angles != '0 0 0') { + makevectors(this.angles); + this.movedir = v_forward; + } } - if(this.model == "") - { + if (this.model == "") { // It's a box! No need to match with exacttriggers. this.warpzone_isboxy = 1; - } - else - { + } else { mi = this.mins; ma = this.maxs; - precache_model(this.model); - _setmodel(this, this.model); + precache_model(this.model); + _setmodel(this, this.model); // let mapper-set mins/maxs override the model's bounds if set - if(mi != '0 0 0' || ma != '0 0 0') - { + if (mi != '0 0 0' || ma != '0 0 0') { // It's a box! No need to match with exacttriggers. this.mins = mi; this.maxs = ma; this.warpzone_isboxy = 1; } - } + } setorigin(this, this.origin); - if(this.scale) + if (this.scale) { setsize(this, this.mins * this.scale, this.maxs * this.scale); - else + } else { setsize(this, this.mins, this.maxs); + } set_movetype(this, MOVETYPE_NONE); this.solid = SOLID_TRIGGER; this.model = ""; diff --git a/qcsrc/lib/yenc.qh b/qcsrc/lib/yenc.qh index 29338666e..6050bb460 100644 --- a/qcsrc/lib/yenc.qh +++ b/qcsrc/lib/yenc.qh @@ -6,9 +6,8 @@ MACRO_BEGIN \ int conv = c; \ conv += 42; \ - if (conv >= 256) conv -= 256; \ - switch (conv) \ - { \ + if (conv >= 256) { conv -= 256; } \ + switch (conv) { \ default: \ { \ string yenc_it = chr2str(conv); \ @@ -40,7 +39,7 @@ conv = STRING_ITERATOR_GET(stringiter); \ conv -= 64; \ } \ - if (conv < 42) conv += 256; \ + if (conv < 42) { conv += 256; } \ conv -= 42; \ ret = conv; \ } \ @@ -48,8 +47,7 @@ TEST(yEnc, EncodeDecode) { - for (int i = 0; i <= 255; ++i) - { + for (int i = 0; i <= 255; ++i) { int expect = i; string fragment = string_null; diff --git a/qcsrc/menu/anim/animation.qc b/qcsrc/menu/anim/animation.qc index 72bcc5e94..60741bd6f 100644 --- a/qcsrc/menu/anim/animation.qc +++ b/qcsrc/menu/anim/animation.qc @@ -2,87 +2,86 @@ #include "../menu.qh" - METHOD(Animation, configureAnimation, void(entity this, entity obj, void(entity, float) objSetter, float animStartTime, float animDuration, float animStartValue, float animEndValue)) - { - this.setObjectSetter(this, obj, objSetter); - this.setTimeStartDuration(this, animStartTime, animDuration); - this.setValueStartEnd(this, animStartValue, animEndValue); - } - - METHOD(Animation, update, void(entity this, float animDuration, float animStartValue, float animEndValue)) - { - this.setTimeStartDuration(this, time, animDuration); - this.setValueStartEnd(this, animStartValue, animEndValue); - } - - METHOD(Animation, setTimeStartEnd, void(entity this, float s, float e)) - { - this.startTime = s; - this.duration = e - s; - } - - METHOD(Animation, setTimeStartDuration, void(entity this, float s, float d)) - { - this.startTime = s; - this.duration = d; - } - - METHOD(Animation, setValueStartEnd, void(entity this, float s, float e)) - { - this.startValue = s; - this.delta = e - s; - } - - METHOD(Animation, setValueStartDelta, void(entity this, float s, float d)) - { - this.startValue = s; - this.delta = d; - } - - METHOD(Animation, setObjectSetter, void(entity this, entity o, void(entity, float) s)) - { - this.object = o; - this.setter = s; - } - - METHOD(Animation, tick, void(entity this, float tickTime)) - { - if (this.isStopped(this) || this.isFinished(this) || (tickTime < this.startTime)) return; - - if (tickTime >= (this.startTime + this.duration)) this.finishAnim(this); - else this.value = this.calcValue(this, (tickTime - this.startTime), this.duration, this.startValue, this.delta); - - this.setter(this.object, this.value); - } - - METHOD(Animation, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta)) - { - return animStartValue; - } - - METHOD(Animation, isStopped, bool(entity this)) - { - return this.stopped; - } - - METHOD(Animation, stopAnim, void(entity this)) - { - this.stopped = true; - } - - METHOD(Animation, resumeAnim, void(entity this)) - { - this.stopped = false; - } - - METHOD(Animation, isFinished, bool(entity this)) - { - return this.finished; - } - - METHOD(Animation, finishAnim, void(entity this)) - { - this.value = this.delta + this.startValue; - this.finished = true; - this.setter(this.object, this.value); - } +METHOD(Animation, configureAnimation, void(entity this, entity obj, void(entity, float) objSetter, float animStartTime, float animDuration, float animStartValue, float animEndValue)) +{ + this.setObjectSetter(this, obj, objSetter); + this.setTimeStartDuration(this, animStartTime, animDuration); + this.setValueStartEnd(this, animStartValue, animEndValue); +} + +METHOD(Animation, update, void(entity this, float animDuration, float animStartValue, float animEndValue)) +{ + this.setTimeStartDuration(this, time, animDuration); + this.setValueStartEnd(this, animStartValue, animEndValue); +} + +METHOD(Animation, setTimeStartEnd, void(entity this, float s, float e)) +{ + this.startTime = s; + this.duration = e - s; +} + +METHOD(Animation, setTimeStartDuration, void(entity this, float s, float d)) +{ + this.startTime = s; + this.duration = d; +} + +METHOD(Animation, setValueStartEnd, void(entity this, float s, float e)) +{ + this.startValue = s; + this.delta = e - s; +} + +METHOD(Animation, setValueStartDelta, void(entity this, float s, float d)) +{ + this.startValue = s; + this.delta = d; +} + +METHOD(Animation, setObjectSetter, void(entity this, entity o, void(entity, float) s)) +{ + this.object = o; + this.setter = s; +} + +METHOD(Animation, tick, void(entity this, float tickTime)) +{ + if (this.isStopped(this) || this.isFinished(this) || (tickTime < this.startTime)) { return; } + + if (tickTime >= (this.startTime + this.duration)) { this.finishAnim(this); } else { this.value = this.calcValue(this, (tickTime - this.startTime), this.duration, this.startValue, this.delta); } + + this.setter(this.object, this.value); +} + +METHOD(Animation, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta)) +{ + return animStartValue; +} + +METHOD(Animation, isStopped, bool(entity this)) +{ + return this.stopped; +} + +METHOD(Animation, stopAnim, void(entity this)) +{ + this.stopped = true; +} + +METHOD(Animation, resumeAnim, void(entity this)) +{ + this.stopped = false; +} + +METHOD(Animation, isFinished, bool(entity this)) +{ + return this.finished; +} + +METHOD(Animation, finishAnim, void(entity this)) +{ + this.value = this.delta + this.startValue; + this.finished = true; + this.setter(this.object, this.value); +} diff --git a/qcsrc/menu/anim/animhost.qc b/qcsrc/menu/anim/animhost.qc index 3009ab4ea..d5419f88e 100644 --- a/qcsrc/menu/anim/animhost.qc +++ b/qcsrc/menu/anim/animhost.qc @@ -4,122 +4,113 @@ #include "animation.qh" - .entity parent; - METHOD(AnimHost, addAnim, void(entity this, entity other)) - { - if (other.parent) error("Can't add already added anim!"); +.entity parent; +METHOD(AnimHost, addAnim, void(entity this, entity other)) +{ + if (other.parent) { error("Can't add already added anim!"); } - if (other.isFinished(other)) error("Can't add finished anim!"); + if (other.isFinished(other)) { error("Can't add finished anim!"); } - other.parent = this; + other.parent = this; - entity l = this.lastChild; + entity l = this.lastChild; - if (l) l.nextSibling = other; - else this.firstChild = other; + if (l) { l.nextSibling = other; } else { this.firstChild = other; } - other.prevSibling = l; - other.nextSibling = NULL; - this.lastChild = other; - } + other.prevSibling = l; + other.nextSibling = NULL; + this.lastChild = other; +} + +METHOD(AnimHost, removeAnim, void(entity this, entity other)) +{ + if (other.parent != this) { error("Can't remove from wrong AnimHost!"); } - METHOD(AnimHost, removeAnim, void(entity this, entity other)) - { - if (other.parent != this) error("Can't remove from wrong AnimHost!"); + other.parent = NULL; - other.parent = NULL; + entity n = other.nextSibling; + entity p = other.prevSibling; - entity n = other.nextSibling; - entity p = other.prevSibling; + if (p) { p.nextSibling = n; } else { this.firstChild = n; } - if (p) p.nextSibling = n; - else this.firstChild = n; + if (n) { n.prevSibling = p; } else { this.lastChild = p; } + delete(other); +} - if (n) n.prevSibling = p; - else this.lastChild = p; - delete(other); +METHOD(AnimHost, removeAllAnim, void(entity this)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + entity tmp = e; + e = tmp.prevSibling; + this.removeAnim(this, tmp); } +} - METHOD(AnimHost, removeAllAnim, void(entity this)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - { +METHOD(AnimHost, removeObjAnim, void(entity this, entity obj)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + if (e.object == obj) { entity tmp = e; e = tmp.prevSibling; this.removeAnim(this, tmp); } } +} - METHOD(AnimHost, removeObjAnim, void(entity this, entity obj)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - { - if (e.object == obj) - { - entity tmp = e; - e = tmp.prevSibling; - this.removeAnim(this, tmp); - } - } - } - - METHOD(AnimHost, stopAllAnim, void(entity this)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - e.stopAnim(e); +METHOD(AnimHost, stopAllAnim, void(entity this)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + e.stopAnim(e); } - - METHOD(AnimHost, stopObjAnim, void(entity this, entity obj)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - if (e.object == obj) e.stopAnim(e); +} + +METHOD(AnimHost, stopObjAnim, void(entity this, entity obj)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + if (e.object == obj) { e.stopAnim(e); } } +} + +METHOD(AnimHost, resumeAllAnim, void(entity this)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + e.resumeAnim(e); } - - METHOD(AnimHost, resumeAllAnim, void(entity this)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - e.resumeAnim(e); +} + +METHOD(AnimHost, resumeObjAnim, void(entity this, entity obj)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + if (e.object == obj) { e.resumeAnim(e); } } +} + +METHOD(AnimHost, finishAllAnim, void(entity this)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + entity tmp = e; + e = tmp.prevSibling; + tmp.finishAnim(tmp); } +} - METHOD(AnimHost, resumeObjAnim, void(entity this, entity obj)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - if (e.object == obj) e.resumeAnim(e); - } - - METHOD(AnimHost, finishAllAnim, void(entity this)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - { +METHOD(AnimHost, finishObjAnim, void(entity this, entity obj)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + if (e.object == obj) { entity tmp = e; e = tmp.prevSibling; tmp.finishAnim(tmp); } } +} - METHOD(AnimHost, finishObjAnim, void(entity this, entity obj)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - { - if (e.object == obj) - { - entity tmp = e; - e = tmp.prevSibling; - tmp.finishAnim(tmp); - } - } - } - - METHOD(AnimHost, tickAll, void(entity this)) - { - for (entity e = this.firstChild; e; e = e.nextSibling) - { - e.tick(e, time); - if (e.isFinished(e)) - { - entity tmp = e; - e = tmp.prevSibling; - this.removeAnim(this, tmp); - } +METHOD(AnimHost, tickAll, void(entity this)) +{ + for (entity e = this.firstChild; e; e = e.nextSibling) { + e.tick(e, time); + if (e.isFinished(e)) { + entity tmp = e; + e = tmp.prevSibling; + this.removeAnim(this, tmp); } } +} diff --git a/qcsrc/menu/anim/easing.qc b/qcsrc/menu/anim/easing.qc index 3014fa808..15d9ba249 100644 --- a/qcsrc/menu/anim/easing.qc +++ b/qcsrc/menu/anim/easing.qc @@ -3,50 +3,49 @@ #include "../menu.qh" #include "keyframe.qh" - entity makeHostedEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animDuration, float animStartValue, float animEnd) - { - entity this = makeEasing(obj, objSetter, func, time, animDuration, animStartValue, animEnd); - anim.addAnim(anim, this); - return this; - } - - entity makeEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animStartTime, float animDuration, float animStartValue, float animEnd) - { - entity this = NEW(Easing); - this.configureAnimation(this, obj, objSetter, animStartTime, animDuration, animStartValue, animEnd); - this.setMath(this, func); - return this; - } - - METHOD(Easing, calcValue, float(entity this, float tickTime, float animDuration, float animStart, float animDelta)) - { - return this.math(tickTime, animDuration, animStart, animDelta); - } - - METHOD(Easing, setMath, void(entity this, float(float, float, float, float) func)) - { - this.math = func; - } - - float easingLinear(float tickTime, float animDuration, float animStart, float animDelta) - { - return (animDelta * (tickTime / animDuration)) + animStart; - } - - float easingQuadIn(float tickTime, float animDuration, float animStart, float animDelta) - { - float frac = tickTime / animDuration; - return (animDelta * frac * frac) + animStart; - } - - float easingQuadOut(float tickTime, float animDuration, float animStart, float animDelta) - { - float frac = tickTime / animDuration; - return (-animDelta * frac * (frac - 2)) + animStart; - } - - float easingQuadInOut(float tickTime, float animDuration, float animStart, float animDelta) - { - if (tickTime < (animDuration / 2)) return easingQuadIn(tickTime, (animDuration / 2), animStart, (animDelta / 2)); - else return easingQuadOut((tickTime - (animDuration / 2)), (animDuration / 2), (animStart + (animDelta / 2)), (animDelta / 2)); - } +entity makeHostedEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animDuration, float animStartValue, float animEnd) +{ + entity this = makeEasing(obj, objSetter, func, time, animDuration, animStartValue, animEnd); + anim.addAnim(anim, this); + return this; +} + +entity makeEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animStartTime, float animDuration, float animStartValue, float animEnd) +{ + entity this = NEW(Easing); + this.configureAnimation(this, obj, objSetter, animStartTime, animDuration, animStartValue, animEnd); + this.setMath(this, func); + return this; +} + +METHOD(Easing, calcValue, float(entity this, float tickTime, float animDuration, float animStart, float animDelta)) +{ + return this.math(tickTime, animDuration, animStart, animDelta); +} + +METHOD(Easing, setMath, void(entity this, float(float, float, float, float) func)) +{ + this.math = func; +} + +float easingLinear(float tickTime, float animDuration, float animStart, float animDelta) +{ + return (animDelta * (tickTime / animDuration)) + animStart; +} + +float easingQuadIn(float tickTime, float animDuration, float animStart, float animDelta) +{ + float frac = tickTime / animDuration; + return (animDelta * frac * frac) + animStart; +} + +float easingQuadOut(float tickTime, float animDuration, float animStart, float animDelta) +{ + float frac = tickTime / animDuration; + return (-animDelta * frac * (frac - 2)) + animStart; +} + +float easingQuadInOut(float tickTime, float animDuration, float animStart, float animDelta) +{ + if (tickTime < (animDuration / 2)) { return easingQuadIn(tickTime, (animDuration / 2), animStart, (animDelta / 2)); } else { return easingQuadOut((tickTime - (animDuration / 2)), (animDuration / 2), (animStart + (animDelta / 2)), (animDelta / 2)); } +} diff --git a/qcsrc/menu/anim/keyframe.qc b/qcsrc/menu/anim/keyframe.qc index 12c0c9aca..f6e5b5de0 100644 --- a/qcsrc/menu/anim/keyframe.qc +++ b/qcsrc/menu/anim/keyframe.qc @@ -7,83 +7,77 @@ .entity parent; - entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd) - { - entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd); - anim.addAnim(anim, this); - return this; +entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd) +{ + entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd); + anim.addAnim(anim, this); + return this; +} + +entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd) +{ + entity this = NEW(Keyframe); + this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd); + return this; +} + +METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func)) +{ + entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd); + this.addAnim(this, other); + return other; +} + +float getNewChildStart(entity this) +{ + if (this.lastChild) { return this.lastChild.startTime + this.lastChild.duration; } else { return 0; } +} + +float getNewChildDuration(entity this, float durationTime) +{ + float maxDura = this.duration; + if (this.lastChild) { maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration); } + float dura = durationTime; + if (0 >= dura || dura > maxDura) { dura = maxDura; } + return dura; +} + +float getNewChildValue(entity this) +{ + if (this.lastChild) { return this.lastChild.startValue + this.lastChild.delta; } else { return this.startValue; } +} + +METHOD(Keyframe, addAnim, void(entity this, entity other)) +{ + if (other.parent) { error("Can't add already added anim!"); } + + if (other.isFinished(other)) { error("Can't add finished anim!"); } + + other.parent = this; + + entity l = this.lastChild; + + if (l) { + l.nextSibling = other; + } else { + this.currentChild = other; + this.firstChild = other; } - entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd) - { - entity this = NEW(Keyframe); - this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd); - return this; - } - - METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func)) - { - entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd); - this.addAnim(this, other); - return other; - } - - float getNewChildStart(entity this) - { - if (this.lastChild) return this.lastChild.startTime + this.lastChild.duration; - else return 0; - } - - float getNewChildDuration(entity this, float durationTime) - { - float maxDura = this.duration; - if (this.lastChild) maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration); - float dura = durationTime; - if (0 >= dura || dura > maxDura) dura = maxDura; - return dura; - } - - float getNewChildValue(entity this) - { - if (this.lastChild) return this.lastChild.startValue + this.lastChild.delta; - else return this.startValue; - } - - METHOD(Keyframe, addAnim, void(entity this, entity other)) - { - if (other.parent) error("Can't add already added anim!"); - - if (other.isFinished(other)) error("Can't add finished anim!"); - - other.parent = this; + other.prevSibling = l; + other.nextSibling = NULL; + this.lastChild = other; +} - entity l = this.lastChild; +METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta)) +{ + if (this.currentChild) { + if (this.currentChild.isFinished(this.currentChild)) { this.currentChild = this.currentChild.nextSibling; } } - if (l) - { - l.nextSibling = other; - } - else - { - this.currentChild = other; - this.firstChild = other; - } - - other.prevSibling = l; - other.nextSibling = NULL; - this.lastChild = other; + if (this.currentChild) { + this.currentChild.tick(this.currentChild, tickTime); + return this.currentChild.value; } - METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta)) - { - if (this.currentChild) - if (this.currentChild.isFinished(this.currentChild)) this.currentChild = this.currentChild.nextSibling; - - if (this.currentChild) - { - this.currentChild.tick(this.currentChild, tickTime); - return this.currentChild.value; - } - - return animStartValue + animDelta; - } + return animStartValue + animDelta; +} diff --git a/qcsrc/menu/gamesettings.qh b/qcsrc/menu/gamesettings.qh index 80133b8b3..d0bbc7fd0 100644 --- a/qcsrc/menu/gamesettings.qh +++ b/qcsrc/menu/gamesettings.qh @@ -8,7 +8,7 @@ REGISTRY(Settings, BITS(3)) #define Settings_from(i) _Settings_from(i, NULL) REGISTER_REGISTRY(Settings) #define REGISTER_SETTINGS(id, impl) \ - LAZY_NEW(id, impl) \ - REGISTER(Settings, MENU, id, m_id, NEW(Lazy, LAZY(id))) + LAZY_NEW(id, impl) \ + REGISTER(Settings, MENU, id, m_id, NEW(Lazy, LAZY(id))) #endif diff --git a/qcsrc/menu/item/borderimage.qc b/qcsrc/menu/item/borderimage.qc index ff37b4b86..441e7d56a 100644 --- a/qcsrc/menu/item/borderimage.qc +++ b/qcsrc/menu/item/borderimage.qc @@ -2,87 +2,81 @@ #include "nexposee.qh" #include "dialog.qh" - void BorderImage_recalcPositionWithText(entity me, string t) - { - if (me.isNexposeeTitleBar) - { - vector scrs; - scrs = eX * conwidth + eY * conheight; - me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_smallOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_smallSize, scrs)); - SUPER(BorderImage).recalcPositionWithText(me, t); - me.realOrigin_y = me.realFontSize.y * me.zoomedOutTitleBarPosition; - me.realOrigin_Nexposeed = me.realOrigin; - me.realFontSize_Nexposeed = me.realFontSize; - me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_initialOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_initialSize, scrs)); - } +void BorderImage_recalcPositionWithText(entity me, string t) +{ + if (me.isNexposeeTitleBar) { + vector scrs; + scrs = eX * conwidth + eY * conheight; + me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_smallOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_smallSize, scrs)); SUPER(BorderImage).recalcPositionWithText(me, t); + me.realOrigin_y = me.realFontSize.y * me.zoomedOutTitleBarPosition; + me.realOrigin_Nexposeed = me.realOrigin; + me.realFontSize_Nexposeed = me.realFontSize; + me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_initialOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_initialSize, scrs)); } - void BorderImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) - { - me.isNexposeeTitleBar = 0; - if (me.zoomedOutTitleBar) - if (me.parent.parent.instanceOfNexposee) - if (me.parent.instanceOfDialog) - if (me == me.parent.frame) me.isNexposeeTitleBar = 1; - me.saveRelOrigin = relOrigin; - me.saveRelSize = relSize; - SUPER(BorderImage).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); - me.borderVec_x = me.borderHeight / absSize.x; - me.borderVec_y = me.borderHeight / absSize.y; - me.realOrigin_y = 0.5 * (me.borderVec.y - me.realFontSize.y); - if (me.closeButton) - { - // move the close button to the right place - me.closeButton.Container_origin = '1 0 0' * (1 - me.borderVec.x); - me.closeButton.Container_size = me.borderVec; - me.closeButton.color = me.color; - me.closeButton.colorC = me.color; - me.closeButton.colorF = me.color; + SUPER(BorderImage).recalcPositionWithText(me, t); +} +void BorderImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + me.isNexposeeTitleBar = 0; + if (me.zoomedOutTitleBar) { + if (me.parent.parent.instanceOfNexposee) { + if (me.parent.instanceOfDialog) { + if (me == me.parent.frame) { me.isNexposeeTitleBar = 1; } } } } - void BorderImage_configureBorderImage(entity me, string theTitle, float sz, vector theColor, string path, float theBorderHeight) - { - me.configureLabel(me, theTitle, sz, 0.5); - me.src = path; - me.color = theColor; - me.borderHeight = theBorderHeight; + me.saveRelOrigin = relOrigin; + me.saveRelSize = relSize; + SUPER(BorderImage).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + me.borderVec_x = me.borderHeight / absSize.x; + me.borderVec_y = me.borderHeight / absSize.y; + me.realOrigin_y = 0.5 * (me.borderVec.y - me.realFontSize.y); + if (me.closeButton) { + // move the close button to the right place + me.closeButton.Container_origin = '1 0 0' * (1 - me.borderVec.x); + me.closeButton.Container_size = me.borderVec; + me.closeButton.color = me.color; + me.closeButton.colorC = me.color; + me.closeButton.colorF = me.color; } - void BorderImage_draw(entity me) - { - if (me.src) draw_BorderPicture('0 0 0', me.src, '1 1 0', me.color, 1, me.borderVec); +} +void BorderImage_configureBorderImage(entity me, string theTitle, float sz, vector theColor, string path, float theBorderHeight) +{ + me.configureLabel(me, theTitle, sz, 0.5); + me.src = path; + me.color = theColor; + me.borderHeight = theBorderHeight; +} +void BorderImage_draw(entity me) +{ + if (me.src) { draw_BorderPicture('0 0 0', me.src, '1 1 0', me.color, 1, me.borderVec); } - if (me.fontSize > 0) - { - if (me.recalcPos) me.recalcPositionWithText(me, me.text); + if (me.fontSize > 0) { + if (me.recalcPos) { me.recalcPositionWithText(me, me.text); } - if (me.isNexposeeTitleBar) - { - vector ro, rf, df; + if (me.isNexposeeTitleBar) { + vector ro, rf, df; - // me.parent.Nexposee_animationFactor 0 (small) or 1 (full) - // default values are for 1 - ro = me.realOrigin; - rf = me.realFontSize; - df = draw_fontscale; - me.realOrigin = ro * me.parent.Nexposee_animationFactor + me.realOrigin_Nexposeed * (1 - me.parent.Nexposee_animationFactor); - me.realFontSize = rf * me.parent.Nexposee_animationFactor + me.realFontSize_Nexposeed * (1 - me.parent.Nexposee_animationFactor); - draw_fontscale = globalToBoxSize(boxToGlobalSize(df, me.realFontSize), rf); + // me.parent.Nexposee_animationFactor 0 (small) or 1 (full) + // default values are for 1 + ro = me.realOrigin; + rf = me.realFontSize; + df = draw_fontscale; + me.realOrigin = ro * me.parent.Nexposee_animationFactor + me.realOrigin_Nexposeed * (1 - me.parent.Nexposee_animationFactor); + me.realFontSize = rf * me.parent.Nexposee_animationFactor + me.realFontSize_Nexposeed * (1 - me.parent.Nexposee_animationFactor); + draw_fontscale = globalToBoxSize(boxToGlobalSize(df, me.realFontSize), rf); - SUPER(BorderImage).draw(me); + SUPER(BorderImage).draw(me); - // me.Nexposee_animationState 0 (small) or 1 (full) - // default values are for 1 - me.realOrigin = ro; - me.realFontSize = rf; - draw_fontscale = df; - } - else - { - SUPER(BorderImage).draw(me); - } - } - else - { + // me.Nexposee_animationState 0 (small) or 1 (full) + // default values are for 1 + me.realOrigin = ro; + me.realFontSize = rf; + draw_fontscale = df; + } else { SUPER(BorderImage).draw(me); } + } else { + SUPER(BorderImage).draw(me); } +} diff --git a/qcsrc/menu/item/checkbox.qc b/qcsrc/menu/item/checkbox.qc index 79cfe7a99..c7f51a63a 100644 --- a/qcsrc/menu/item/checkbox.qc +++ b/qcsrc/menu/item/checkbox.qc @@ -1,39 +1,36 @@ #include "checkbox.qh" - void CheckBox_setChecked(entity me, float val) - { - me.checked = val; - } - void CheckBox_Click(entity me, entity other) - { - me.setChecked(me, !me.checked); - } - string CheckBox_toString(entity me) - { - return strcat(SUPER(CheckBox).toString(me), ", ", me.checked ? "checked" : "unchecked"); - } - void CheckBox_configureCheckBox(entity me, string txt, float sz, string gfx) - { - me.configureButton(me, txt, sz, gfx); - me.align = 0; - } - void CheckBox_draw(entity me) - { - float s; - s = me.pressed; - if (me.useDownAsChecked) - { - me.srcSuffix = string_null; - me.forcePressed = me.checked; - } - else - { - me.srcSuffix = (me.checked ? "1" : "0"); - } - me.pressed = s; - SUPER(CheckBox).draw(me); - } - void CheckBox_playClickSound(entity me) - { - m_play_click_sound(MENU_SOUND_SELECT); +void CheckBox_setChecked(entity me, float val) +{ + me.checked = val; +} +void CheckBox_Click(entity me, entity other) +{ + me.setChecked(me, !me.checked); +} +string CheckBox_toString(entity me) +{ + return strcat(SUPER(CheckBox).toString(me), ", ", me.checked ? "checked" : "unchecked"); +} +void CheckBox_configureCheckBox(entity me, string txt, float sz, string gfx) +{ + me.configureButton(me, txt, sz, gfx); + me.align = 0; +} +void CheckBox_draw(entity me) +{ + float s; + s = me.pressed; + if (me.useDownAsChecked) { + me.srcSuffix = string_null; + me.forcePressed = me.checked; + } else { + me.srcSuffix = (me.checked ? "1" : "0"); } + me.pressed = s; + SUPER(CheckBox).draw(me); +} +void CheckBox_playClickSound(entity me) +{ + m_play_click_sound(MENU_SOUND_SELECT); +} diff --git a/qcsrc/menu/item/checkbox.qh b/qcsrc/menu/item/checkbox.qh index 931e4f79c..705f2511c 100644 --- a/qcsrc/menu/item/checkbox.qh +++ b/qcsrc/menu/item/checkbox.qh @@ -9,7 +9,7 @@ CLASS(CheckBox, Button) METHOD(CheckBox, setChecked, void(entity, float)); ATTRIB(CheckBox, useDownAsChecked, float, 0); ATTRIB(CheckBox, checked, float, 0); - void CheckBox_Click(entity me, entity other); + void CheckBox_Click(entity me, entity other); ATTRIB(CheckBox, onClick, void(entity, entity), CheckBox_Click); ATTRIB(CheckBox, srcMulti, float, 0); ATTRIB(CheckBox, disabled, float, 0); diff --git a/qcsrc/menu/item/dialog.qc b/qcsrc/menu/item/dialog.qc index 9e0ea95eb..7383580a9 100644 --- a/qcsrc/menu/item/dialog.qc +++ b/qcsrc/menu/item/dialog.qc @@ -4,131 +4,127 @@ #include "button.qh" #include "nexposee.qh" - void Dialog_Close(entity button, entity me) - { - me.close(me); +void Dialog_Close(entity button, entity me) +{ + me.close(me); +} + +void Dialog_fill(entity me) +{} + +void Dialog_addItemSimple(entity me, float row, float col, float rowspan, float colspan, entity e, vector v) +{ + vector o, s; + o = me.itemOrigin + eX * (col * me.itemSpacing.x) + eY * (row * me.itemSpacing.y); + s = me.itemSize + eX * ((colspan - 1) * me.itemSpacing.x) + eY * ((rowspan - 1) * me.itemSpacing.y); + o.x -= 0.5 * (me.itemSpacing.x - me.itemSize.x) * v.x; + s.x += (me.itemSpacing.x - me.itemSize.x) * v.x; + o.y -= 0.5 * (me.itemSpacing.y - me.itemSize.y) * v.y; + s.y += (me.itemSpacing.y - me.itemSize.y) * v.y; + me.addItem(me, e, o, s, 1); +} + +void Dialog_gotoRC(entity me, float row, float col) +{ + me.currentRow = row; + me.currentColumn = col; +} + +void Dialog_TR(entity me) +{ + me.currentRow += 1; + me.currentColumn = me.firstColumn; +} + +void Dialog_TD(entity me, float rowspan, float colspan, entity e) +{ + me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, '0 0 0'); + me.currentColumn += colspan; +} + +void Dialog_TDNoMargin(entity me, float rowspan, float colspan, entity e, vector v) +{ + me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, v); + me.currentColumn += colspan; +} + +void Dialog_setFirstColumn(entity me, float col) +{ + me.firstColumn = col; +} + +void Dialog_TDempty(entity me, float colspan) +{ + me.currentColumn += colspan; +} + +void Dialog_configureDialog(entity me) +{ + float absWidth, absHeight; + + if (me.isTabRoot) { + me.frame = NEW(BorderImage); + me.frame.configureBorderImage(me.frame, me.title, me.titleFontSize, me.color, me.backgroundImage, me.borderLines * me.titleHeight); + me.frame.zoomedOutTitleBarPosition = me.zoomedOutTitleBarPosition; + me.frame.zoomedOutTitleBar = me.zoomedOutTitleBar; + me.frame.alpha = me.alpha; + me.addItem(me, me.frame, '0 0 0', '1 1 0', 1); } - void Dialog_fill(entity me) - {} - - void Dialog_addItemSimple(entity me, float row, float col, float rowspan, float colspan, entity e, vector v) - { - vector o, s; - o = me.itemOrigin + eX * (col * me.itemSpacing.x) + eY * (row * me.itemSpacing.y); - s = me.itemSize + eX * ((colspan - 1) * me.itemSpacing.x) + eY * ((rowspan - 1) * me.itemSpacing.y); - o.x -= 0.5 * (me.itemSpacing.x - me.itemSize.x) * v.x; - s.x += (me.itemSpacing.x - me.itemSize.x) * v.x; - o.y -= 0.5 * (me.itemSpacing.y - me.itemSize.y) * v.y; - s.y += (me.itemSpacing.y - me.itemSize.y) * v.y; - me.addItem(me, e, o, s, 1); + if (!me.titleFontSize) { + me.titleHeight = 0; // no title bar } - - void Dialog_gotoRC(entity me, float row, float col) - { - me.currentRow = row; - me.currentColumn = col; - } - - void Dialog_TR(entity me) - { - me.currentRow += 1; - me.currentColumn = me.firstColumn; - } - - void Dialog_TD(entity me, float rowspan, float colspan, entity e) - { - me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, '0 0 0'); - me.currentColumn += colspan; + absWidth = me.intendedWidth * conwidth; + absHeight = me.borderLines * me.titleHeight + me.marginTop + me.rows * me.rowHeight + (me.rows - 1) * me.rowSpacing + me.marginBottom; + me.itemOrigin = eX * (me.marginLeft / absWidth) + + eY * ((me.borderLines * me.titleHeight + me.marginTop) / absHeight); + me.itemSize = eX * ((1 - (me.marginLeft + me.marginRight + me.columnSpacing * (me.columns - 1)) / absWidth) / me.columns) + + eY * (me.rowHeight / absHeight); + me.itemSpacing = me.itemSize + + eX * (me.columnSpacing / absWidth) + + eY * (me.rowSpacing / absHeight); + me.intendedHeight = absHeight / conheight; + me.currentRow = -1; + me.currentColumn = -1; + + me.fill(me); + + if (me.isTabRoot && me.closable && me.borderLines > 0) { + entity closebutton; + closebutton = me.closeButton = me.frame.closeButton = NEW(Button); + closebutton.configureButton(closebutton, "", 0, me.closeButtonImage); + closebutton.onClick = Dialog_Close; + closebutton.onClickEntity = me; + closebutton.srcMulti = 0; + me.addItem(me, closebutton, '0 0 0', '1 1 0', 1); // put it as LAST } - - void Dialog_TDNoMargin(entity me, float rowspan, float colspan, entity e, vector v) - { - me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, v); - me.currentColumn += colspan; - } - - void Dialog_setFirstColumn(entity me, float col) - { - me.firstColumn = col; - } - - void Dialog_TDempty(entity me, float colspan) - { - me.currentColumn += colspan; - } - - void Dialog_configureDialog(entity me) - { - float absWidth, absHeight; - - if (me.isTabRoot) - { - me.frame = NEW(BorderImage); - me.frame.configureBorderImage(me.frame, me.title, me.titleFontSize, me.color, me.backgroundImage, me.borderLines * me.titleHeight); - me.frame.zoomedOutTitleBarPosition = me.zoomedOutTitleBarPosition; - me.frame.zoomedOutTitleBar = me.zoomedOutTitleBar; - me.frame.alpha = me.alpha; - me.addItem(me, me.frame, '0 0 0', '1 1 0', 1); - } - - if (!me.titleFontSize) me.titleHeight = 0; // no title bar - - absWidth = me.intendedWidth * conwidth; - absHeight = me.borderLines * me.titleHeight + me.marginTop + me.rows * me.rowHeight + (me.rows - 1) * me.rowSpacing + me.marginBottom; - me.itemOrigin = eX * (me.marginLeft / absWidth) - + eY * ((me.borderLines * me.titleHeight + me.marginTop) / absHeight); - me.itemSize = eX * ((1 - (me.marginLeft + me.marginRight + me.columnSpacing * (me.columns - 1)) / absWidth) / me.columns) - + eY * (me.rowHeight / absHeight); - me.itemSpacing = me.itemSize - + eX * (me.columnSpacing / absWidth) - + eY * (me.rowSpacing / absHeight); - me.intendedHeight = absHeight / conheight; - me.currentRow = -1; - me.currentColumn = -1; - - me.fill(me); - - if (me.isTabRoot && me.closable && me.borderLines > 0) - { - entity closebutton; - closebutton = me.closeButton = me.frame.closeButton = NEW(Button); - closebutton.configureButton(closebutton, "", 0, me.closeButtonImage); - closebutton.onClick = Dialog_Close; - closebutton.onClickEntity = me; - closebutton.srcMulti = 0; - me.addItem(me, closebutton, '0 0 0', '1 1 0', 1); // put it as LAST +} + +void Dialog_close(entity me) +{ + if (me.parent.instanceOfNexposee) { + ExposeeCloseButton_Click(me, me.parent); + if (me.hideMenuOnClose) { + me.hideMenuOnClose = false; + m_hide(); } + } else if (me.parent.instanceOfModalController) { + DialogCloseButton_Click(me, me); } - - void Dialog_close(entity me) - { - if (me.parent.instanceOfNexposee) - { - ExposeeCloseButton_Click(me, me.parent); - if(me.hideMenuOnClose) - { - me.hideMenuOnClose = false; - m_hide(); - } +} + +float Dialog_keyDown(entity me, float key, float ascii, float shift) +{ + if (me.closable) { + if (key == K_ESCAPE) { + m_play_click_sound(MENU_SOUND_CLOSE); + me.close(me); + return 1; } - else if (me.parent.instanceOfModalController) - DialogCloseButton_Click(me, me); } - - float Dialog_keyDown(entity me, float key, float ascii, float shift) - { - if (me.closable) - { - if (key == K_ESCAPE) - { - m_play_click_sound(MENU_SOUND_CLOSE); - me.close(me); - return 1; - } - } - float r = SUPER(Dialog).keyDown(me, key, ascii, shift); - if (!me.closable && key == K_ESCAPE) - return 1; - return r; + float r = SUPER(Dialog).keyDown(me, key, ascii, shift); + if (!me.closable && key == K_ESCAPE) { + return 1; } + return r; +} diff --git a/qcsrc/menu/item/dialog.qh b/qcsrc/menu/item/dialog.qh index 6fa9b26ab..3f38f2ec4 100644 --- a/qcsrc/menu/item/dialog.qh +++ b/qcsrc/menu/item/dialog.qh @@ -60,7 +60,7 @@ CLASS(Dialog, InputContainer) ATTRIB(Dialog, zoomedOutTitleBarPosition, float, 0); ATTRIB(Dialog, zoomedOutTitleBar, float, 0); - ATTRIB(Dialog, requiresConnection, float, 0); // set to true if the dialog requires a connection to be opened + ATTRIB(Dialog, requiresConnection, float, 0); // set to true if the dialog requires a connection to be opened ATTRIB(Dialog, backgroundImage, string); ATTRIB(Dialog, borderLines, float, 1); diff --git a/qcsrc/menu/item/label.qc b/qcsrc/menu/item/label.qc index d21b5676b..627ad3917 100644 --- a/qcsrc/menu/item/label.qc +++ b/qcsrc/menu/item/label.qc @@ -1,52 +1,118 @@ #include "label.qh" - string Label_toString(entity me) - { - return me.text; +string Label_toString(entity me) +{ + return me.text; +} +void Label_setText(entity me, string txt) +{ + me.text = txt; + if (txt != me.currentText) { + if (me.currentText) { strunzone(me.currentText); } + me.currentText = strzone(txt); + me.recalcPos = 1; } - void Label_setText(entity me, string txt) - { - me.text = txt; - if (txt != me.currentText) - { - if (me.currentText) strunzone(me.currentText); - me.currentText = strzone(txt); - me.recalcPos = 1; - } +} +void Label_recalcPositionWithText(entity me, string t) +{ + float spaceAvail; + spaceAvail = 1 - me.keepspaceLeft - me.keepspaceRight; + + if (me.isBold) { draw_beginBoldFont(); } + + float spaceUsed; + spaceUsed = draw_TextWidth(t, me.allowColors, me.realFontSize); + + if (spaceUsed <= spaceAvail) { + if (!me.overrideRealOrigin_x) { me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft; } + if (!me.overrideCondenseFactor) { me.condenseFactor = 1; } + } else if (me.allowCut || me.allowWrap) { + if (!me.overrideRealOrigin_x) { me.realOrigin_x = me.keepspaceLeft; } + if (!me.overrideCondenseFactor) { me.condenseFactor = 1; } + } else { + if (!me.overrideRealOrigin_x) { me.realOrigin_x = me.keepspaceLeft; } + if (!me.overrideCondenseFactor) { me.condenseFactor = spaceAvail / spaceUsed; } + LOG_TRACEF("NOTE: label text %s too wide for label, condensed by factor %f", t, me.condenseFactor); } - void Label_recalcPositionWithText(entity me, string t) - { - float spaceAvail; - spaceAvail = 1 - me.keepspaceLeft - me.keepspaceRight; - if (me.isBold) draw_beginBoldFont(); + if (!me.overrideRealOrigin_y) { + float lines; + vector dfs; + vector fs; + + // set up variables to draw in condensed size, but use hinting for original size + fs = me.realFontSize; + fs.x *= me.condenseFactor; + + dfs = draw_fontscale; + draw_fontscale.x *= me.condenseFactor; + + if (me.allowCut) { // FIXME allowCut incompatible with align != 0 + lines = 1; + } else if (me.allowWrap) { // FIXME allowWrap incompatible with align != 0 + getWrappedLine_remaining = me.text; + lines = 0; + while (getWrappedLine_remaining) { + if (me.allowColors) { getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors); } else { getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors); } + ++lines; + } + } else { + lines = 1; + } + + draw_fontscale = dfs; - float spaceUsed; - spaceUsed = draw_TextWidth(t, me.allowColors, me.realFontSize); + me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize.y); + } - if (spaceUsed <= spaceAvail) - { - if (!me.overrideRealOrigin_x) me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft; - if (!me.overrideCondenseFactor) me.condenseFactor = 1; - } - else if (me.allowCut || me.allowWrap) - { - if (!me.overrideRealOrigin_x) me.realOrigin_x = me.keepspaceLeft; - if (!me.overrideCondenseFactor) me.condenseFactor = 1; - } - else - { - if (!me.overrideRealOrigin_x) me.realOrigin_x = me.keepspaceLeft; - if (!me.overrideCondenseFactor) me.condenseFactor = spaceAvail / spaceUsed; - LOG_TRACEF("NOTE: label text %s too wide for label, condensed by factor %f", t, me.condenseFactor); + if (me.isBold) { draw_endBoldFont(); } + + me.recalcPos = 0; +} +void Label_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + + // absSize_y is height of label + me.realFontSize_y = absSize.y == 0 ? 0 : (me.fontSize / absSize.y); + me.realFontSize_x = absSize.x == 0 ? 0 : (me.fontSize / absSize.x); + if (me.marginLeft) { me.keepspaceLeft = me.marginLeft * me.realFontSize.x; } + if (me.marginRight) { me.keepspaceRight = me.marginRight * me.realFontSize.x; } + + me.recalcPos = 1; +} +void Label_configureLabel(entity me, string txt, float sz, float algn) +{ + me.fontSize = sz; + me.align = algn; + me.setText(me, txt); +} +void Label_draw(entity me) +{ + string t; + vector o; + if (me.disabled) { draw_alpha *= me.disabledAlpha; } + + if (me.textEntity) { + t = me.textEntity.toString(me.textEntity); + if (t != me.currentText) { + if (me.currentText) { strunzone(me.currentText); } + me.currentText = strzone(t); + me.recalcPos = 1; } + } else { + t = me.text; + } + + if (me.recalcPos) { me.recalcPositionWithText(me, t); } - if (!me.overrideRealOrigin_y) - { - float lines; + if (me.fontSize) { + if (t) { vector dfs; vector fs; + if (me.isBold) { draw_beginBoldFont(); } + // set up variables to draw in condensed size, but use hinting for original size fs = me.realFontSize; fs.x *= me.condenseFactor; @@ -54,116 +120,25 @@ dfs = draw_fontscale; draw_fontscale.x *= me.condenseFactor; - if (me.allowCut) // FIXME allowCut incompatible with align != 0 - { - lines = 1; - } - else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0 - { - getWrappedLine_remaining = me.text; - lines = 0; - while (getWrappedLine_remaining) - { - if (me.allowColors) getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors); - else getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors); - ++lines; + if (me.allowCut) { // FIXME allowCut incompatible with align != 0 + draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, fs), fs, me.colorL, me.alpha, me.allowColors); + } else if (me.allowWrap) { // FIXME allowWrap incompatible with align != 0 + getWrappedLine_remaining = t; + o = me.realOrigin; + while (getWrappedLine_remaining) { + if (me.allowColors) { t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors); } else { t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors); } + draw_Text(o, t, fs, me.colorL, me.alpha, me.allowColors); + o.y += me.realFontSize.y; } - } - else - { - lines = 1; + } else { + draw_Text(me.realOrigin, t, fs, me.colorL, me.alpha, me.allowColors); } draw_fontscale = dfs; - me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize.y); + if (me.isBold) { draw_endBoldFont(); } } - - if (me.isBold) draw_endBoldFont(); - - me.recalcPos = 0; - } - void Label_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) - { - SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); - - // absSize_y is height of label - me.realFontSize_y = absSize.y == 0 ? 0 : (me.fontSize / absSize.y); - me.realFontSize_x = absSize.x == 0 ? 0 : (me.fontSize / absSize.x); - if (me.marginLeft) me.keepspaceLeft = me.marginLeft * me.realFontSize.x; - if (me.marginRight) me.keepspaceRight = me.marginRight * me.realFontSize.x; - - me.recalcPos = 1; - } - void Label_configureLabel(entity me, string txt, float sz, float algn) - { - me.fontSize = sz; - me.align = algn; - me.setText(me, txt); } - void Label_draw(entity me) - { - string t; - vector o; - if (me.disabled) draw_alpha *= me.disabledAlpha; - - if (me.textEntity) - { - t = me.textEntity.toString(me.textEntity); - if (t != me.currentText) - { - if (me.currentText) strunzone(me.currentText); - me.currentText = strzone(t); - me.recalcPos = 1; - } - } - else - { - t = me.text; - } - - if (me.recalcPos) me.recalcPositionWithText(me, t); - - if (me.fontSize) - if (t) - { - vector dfs; - vector fs; - - if (me.isBold) draw_beginBoldFont(); - - // set up variables to draw in condensed size, but use hinting for original size - fs = me.realFontSize; - fs.x *= me.condenseFactor; - dfs = draw_fontscale; - draw_fontscale.x *= me.condenseFactor; - - if (me.allowCut) // FIXME allowCut incompatible with align != 0 - { - draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, fs), fs, me.colorL, me.alpha, me.allowColors); - } - else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0 - { - getWrappedLine_remaining = t; - o = me.realOrigin; - while (getWrappedLine_remaining) - { - if (me.allowColors) t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors); - else t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors); - draw_Text(o, t, fs, me.colorL, me.alpha, me.allowColors); - o.y += me.realFontSize.y; - } - } - else - { - draw_Text(me.realOrigin, t, fs, me.colorL, me.alpha, me.allowColors); - } - - draw_fontscale = dfs; - - if (me.isBold) draw_endBoldFont(); - } - - SUPER(Label).draw(me); - } + SUPER(Label).draw(me); +} diff --git a/qcsrc/menu/item/modalcontroller.qc b/qcsrc/menu/item/modalcontroller.qc index 660431d60..343efba66 100644 --- a/qcsrc/menu/item/modalcontroller.qc +++ b/qcsrc/menu/item/modalcontroller.qc @@ -2,237 +2,216 @@ #include "button.qh" - .vector ModalController_initialSize; - .vector ModalController_initialOrigin; - .vector ModalController_initialFontScale; - .float ModalController_initialAlpha; - .vector ModalController_buttonSize; - .vector ModalController_buttonOrigin; - .float ModalController_state; - .float ModalController_factor; - .entity ModalController_controllingButton; - - void ModalController_initializeDialog(entity me, entity root) - { - me.hideAll(me, 1); - me.showChild(me, root, '0 0 0', '0 0 0', 1); // someone else animates for us - } - - void TabButton_Click(entity button, entity tab) - { - if (tab.ModalController_state == 1) return; - tab.parent.hideAll(tab.parent, 0); - button.forcePressed = 1; - tab.ModalController_controllingButton = button; - tab.parent.showChild(tab.parent, tab, button.origin, button.size, 0); - } - - void DialogOpenButton_Click(entity button, entity tab) - { - DialogOpenButton_Click_withCoords(button, tab, button.origin, button.size); - } - - void DialogOpenButton_Click_withCoords(entity button, entity tab, vector theOrigin, vector theSize) - { - if (tab.ModalController_state) return; - if (button) button.forcePressed = 1; - if (tab.parent.focusedChild) tab.parent.focusedChild.saveFocus(tab.parent.focusedChild); - tab.ModalController_controllingButton = button; - tab.parent.showChild(tab.parent, tab, theOrigin, theSize, 0); - } - - void DialogCloseButton_Click(entity button, entity tab) - { - tab.parent.hideChild(tab.parent, tab, 0); - } - - void ModalController_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) - { - me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, ModalController_initialOrigin, ModalController_initialSize, ModalController_initialFontScale); +.vector ModalController_initialSize; +.vector ModalController_initialOrigin; +.vector ModalController_initialFontScale; +.float ModalController_initialAlpha; +.vector ModalController_buttonSize; +.vector ModalController_buttonOrigin; +.float ModalController_state; +.float ModalController_factor; +.entity ModalController_controllingButton; + +void ModalController_initializeDialog(entity me, entity root) +{ + me.hideAll(me, 1); + me.showChild(me, root, '0 0 0', '0 0 0', 1); // someone else animates for us +} + +void TabButton_Click(entity button, entity tab) +{ + if (tab.ModalController_state == 1) { return; } + tab.parent.hideAll(tab.parent, 0); + button.forcePressed = 1; + tab.ModalController_controllingButton = button; + tab.parent.showChild(tab.parent, tab, button.origin, button.size, 0); +} + +void DialogOpenButton_Click(entity button, entity tab) +{ + DialogOpenButton_Click_withCoords(button, tab, button.origin, button.size); +} + +void DialogOpenButton_Click_withCoords(entity button, entity tab, vector theOrigin, vector theSize) +{ + if (tab.ModalController_state) { return; } + if (button) { button.forcePressed = 1; } + if (tab.parent.focusedChild) { tab.parent.focusedChild.saveFocus(tab.parent.focusedChild); } + tab.ModalController_controllingButton = button; + tab.parent.showChild(tab.parent, tab, theOrigin, theSize, 0); +} + +void DialogCloseButton_Click(entity button, entity tab) +{ + tab.parent.hideChild(tab.parent, tab, 0); +} + +void ModalController_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, ModalController_initialOrigin, ModalController_initialSize, ModalController_initialFontScale); +} + +void ModalController_switchState(entity me, entity other, float state, float skipAnimation) +{ + float previousState; + previousState = other.ModalController_state; + if (state == previousState && !skipAnimation) { return; } + other.ModalController_state = state; + switch (state) { + case 0: + other.ModalController_factor = 1 - other.Container_alpha / other.ModalController_initialAlpha; + // fading out + break; + case 1: + other.ModalController_factor = other.Container_alpha / other.ModalController_initialAlpha; + if (previousState == 0 && !skipAnimation) { + other.Container_origin = other.ModalController_buttonOrigin; + other.Container_size = other.ModalController_buttonSize; + } + // zooming in + break; + case 2: + other.ModalController_factor = bound(0, (1 - other.Container_alpha / other.ModalController_initialAlpha) / me.fadedAlpha, 1); + // fading out halfway + break; } - - void ModalController_switchState(entity me, entity other, float state, float skipAnimation) - { - float previousState; - previousState = other.ModalController_state; - if (state == previousState && !skipAnimation) return; - other.ModalController_state = state; - switch (state) - { - case 0: - other.ModalController_factor = 1 - other.Container_alpha / other.ModalController_initialAlpha; - // fading out - break; - case 1: - other.ModalController_factor = other.Container_alpha / other.ModalController_initialAlpha; - if (previousState == 0 && !skipAnimation) - { - other.Container_origin = other.ModalController_buttonOrigin; - other.Container_size = other.ModalController_buttonSize; - } - // zooming in - break; - case 2: - other.ModalController_factor = bound(0, (1 - other.Container_alpha / other.ModalController_initialAlpha) / me.fadedAlpha, 1); - // fading out halfway - break; + if (skipAnimation) { other.ModalController_factor = 1; } +} + +void ModalController_draw(entity me) +{ + entity e; + entity front; + float animating; + float f; // animation factor + float df; // animation step size + float prevFactor, targetFactor; + vector targetOrigin, targetSize; + float targetAlpha; + vector fs; + animating = 0; + + front = NULL; + for (e = me.firstChild; e; e = e.nextSibling) { + if (e.ModalController_state) { + if (front) { me.switchState(me, front, 2, 0); } + front = e; } - if (skipAnimation) other.ModalController_factor = 1; } + if (front) { me.switchState(me, front, 1, 0); } + + df = frametime * 3; // animation speed + + for (e = me.firstChild; e; e = e.nextSibling) { + if (e.ModalController_state == 2) { + // fading out partially + targetOrigin = e.Container_origin; // stay as is + targetSize = e.Container_size; // stay as is + targetAlpha = me.fadedAlpha * e.ModalController_initialAlpha; + } else if (e.ModalController_state == 1) { + // zooming in + targetOrigin = e.ModalController_initialOrigin; + targetSize = e.ModalController_initialSize; + targetAlpha = e.ModalController_initialAlpha; + } else { + // fading out + targetOrigin = e.Container_origin; // stay as is + targetSize = e.Container_size; // stay as is + targetAlpha = 0; + } - void ModalController_draw(entity me) - { - entity e; - entity front; - float animating; - float f; // animation factor - float df; // animation step size - float prevFactor, targetFactor; - vector targetOrigin, targetSize; - float targetAlpha; - vector fs; - animating = 0; - - front = NULL; - for (e = me.firstChild; e; e = e.nextSibling) - if (e.ModalController_state) - { - if (front) me.switchState(me, front, 2, 0); - front = e; - } - if (front) me.switchState(me, front, 1, 0); - - df = frametime * 3; // animation speed - - for (e = me.firstChild; e; e = e.nextSibling) - { - if (e.ModalController_state == 2) - { - // fading out partially - targetOrigin = e.Container_origin; // stay as is - targetSize = e.Container_size; // stay as is - targetAlpha = me.fadedAlpha * e.ModalController_initialAlpha; - } - else if (e.ModalController_state == 1) - { - // zooming in - targetOrigin = e.ModalController_initialOrigin; - targetSize = e.ModalController_initialSize; - targetAlpha = e.ModalController_initialAlpha; - } - else - { - // fading out - targetOrigin = e.Container_origin; // stay as is - targetSize = e.Container_size; // stay as is - targetAlpha = 0; - } - - f = (e.ModalController_factor = min(1, e.ModalController_factor + df)); - if (f == 1) - { - prevFactor = 0; - targetFactor = 1; - e.Container_origin = targetOrigin; - e.Container_size = targetSize; - me.setAlphaOf(me, e, targetAlpha); - } - else - { - prevFactor = (1 - f) / (1 - f + df); - if (!e.ModalController_state) // optimize code and avoid precision errors - { - me.setAlphaOf(me, e, e.Container_alpha * prevFactor); + f = (e.ModalController_factor = min(1, e.ModalController_factor + df)); + if (f == 1) { + prevFactor = 0; + targetFactor = 1; + e.Container_origin = targetOrigin; + e.Container_size = targetSize; + me.setAlphaOf(me, e, targetAlpha); + } else { + prevFactor = (1 - f) / (1 - f + df); + if (!e.ModalController_state) { // optimize code and avoid precision errors + me.setAlphaOf(me, e, e.Container_alpha * prevFactor); + } else { + animating = 1; + targetFactor = df / (1 - f + df); + + if (e.ModalController_state == 1) { + e.Container_origin = e.Container_origin * prevFactor + targetOrigin * targetFactor; + e.Container_size = e.Container_size * prevFactor + targetSize * targetFactor; } - else - { - animating = 1; - targetFactor = df / (1 - f + df); - - if (e.ModalController_state == 1) - { - e.Container_origin = e.Container_origin * prevFactor + targetOrigin * targetFactor; - e.Container_size = e.Container_size * prevFactor + targetSize * targetFactor; - } - me.setAlphaOf(me, e, e.Container_alpha * prevFactor + targetAlpha * targetFactor); - } - } - // assume: o == to * f_prev + X * (1 - f_prev) - // make: o' = to * f + X * (1 - f) - // --> - // X == (o - to * f_prev) / (1 - f_prev) - // o' = to * f + (o - to * f_prev) / (1 - f_prev) * (1 - f) - // --> (maxima) - // o' = (to * (f - f_prev) + o * (1 - f)) / (1 - f_prev) - - if (e.ModalController_state == 1) - { - fs = globalToBoxSize(e.Container_size, e.ModalController_initialSize); - e.Container_fontscale_x = fs.x * e.ModalController_initialFontScale.x; - e.Container_fontscale_y = fs.y * e.ModalController_initialFontScale.y; + me.setAlphaOf(me, e, e.Container_alpha * prevFactor + targetAlpha * targetFactor); } } - - if (animating || !me.focused) me.setFocus(me, NULL); - else me.setFocus(me, front); - SUPER(ModalController).draw(me); - } - - void ModalController_addTab(entity me, entity other, entity tabButton) - { - me.addItem(me, other, '0 0 0', '1 1 1', 1); - tabButton.onClick = TabButton_Click; - tabButton.onClickEntity = other; - other.tabSelectingButton = tabButton; - if (other == me.firstChild) - { - tabButton.forcePressed = 1; - other.ModalController_controllingButton = tabButton; - me.showChild(me, other, '0 0 0', '0 0 0', 1); + // assume: o == to * f_prev + X * (1 - f_prev) + // make: o' = to * f + X * (1 - f) + // --> + // X == (o - to * f_prev) / (1 - f_prev) + // o' = to * f + (o - to * f_prev) / (1 - f_prev) * (1 - f) + // --> (maxima) + // o' = (to * (f - f_prev) + o * (1 - f)) / (1 - f_prev) + + if (e.ModalController_state == 1) { + fs = globalToBoxSize(e.Container_size, e.ModalController_initialSize); + e.Container_fontscale_x = fs.x * e.ModalController_initialFontScale.x; + e.Container_fontscale_y = fs.y * e.ModalController_initialFontScale.y; } } - void ModalController_addItem(entity me, entity other, vector theOrigin, vector theSize, float theAlpha) - { - SUPER(ModalController).addItem(me, other, theOrigin, theSize, (other == me.firstChild) ? theAlpha : 0); - other.ModalController_initialFontScale = other.Container_fontscale; - other.ModalController_initialSize = other.Container_size; - other.ModalController_initialOrigin = other.Container_origin; - other.ModalController_initialAlpha = theAlpha; // hope Container never modifies this - if (other.ModalController_initialFontScale == '0 0 0') other.ModalController_initialFontScale = '1 1 0'; + if (animating || !me.focused) { me.setFocus(me, NULL); } else { me.setFocus(me, front); } + SUPER(ModalController).draw(me); +} + +void ModalController_addTab(entity me, entity other, entity tabButton) +{ + me.addItem(me, other, '0 0 0', '1 1 1', 1); + tabButton.onClick = TabButton_Click; + tabButton.onClickEntity = other; + other.tabSelectingButton = tabButton; + if (other == me.firstChild) { + tabButton.forcePressed = 1; + other.ModalController_controllingButton = tabButton; + me.showChild(me, other, '0 0 0', '0 0 0', 1); } - - void ModalController_showChild(entity me, entity other, vector theOrigin, vector theSize, float skipAnimation) - { - if (other.ModalController_state == 0 || skipAnimation) - { - me.setFocus(me, NULL); - if (!skipAnimation) - { - other.ModalController_buttonOrigin = globalToBox(theOrigin, me.origin, me.size); - other.ModalController_buttonSize = globalToBoxSize(theSize, me.size); - } - me.switchState(me, other, 1, skipAnimation); - } // zoom in from button (factor increases) - } - - void ModalController_hideAll(entity me, float skipAnimation) - { - entity e; - for (e = me.firstChild; e; e = e.nextSibling) - me.hideChild(me, e, skipAnimation); - } - - void ModalController_hideChild(entity me, entity other, float skipAnimation) - { - if (other.ModalController_state || skipAnimation) - { - me.setFocus(me, NULL); - me.switchState(me, other, 0, skipAnimation); - if (other.ModalController_controllingButton) - { - other.ModalController_controllingButton.forcePressed = 0; - other.ModalController_controllingButton = NULL; - } - } // just alpha fade out (factor increases and decreases alpha) +} + +void ModalController_addItem(entity me, entity other, vector theOrigin, vector theSize, float theAlpha) +{ + SUPER(ModalController).addItem(me, other, theOrigin, theSize, (other == me.firstChild) ? theAlpha : 0); + other.ModalController_initialFontScale = other.Container_fontscale; + other.ModalController_initialSize = other.Container_size; + other.ModalController_initialOrigin = other.Container_origin; + other.ModalController_initialAlpha = theAlpha; // hope Container never modifies this + if (other.ModalController_initialFontScale == '0 0 0') { other.ModalController_initialFontScale = '1 1 0'; } +} + +void ModalController_showChild(entity me, entity other, vector theOrigin, vector theSize, float skipAnimation) +{ + if (other.ModalController_state == 0 || skipAnimation) { + me.setFocus(me, NULL); + if (!skipAnimation) { + other.ModalController_buttonOrigin = globalToBox(theOrigin, me.origin, me.size); + other.ModalController_buttonSize = globalToBoxSize(theSize, me.size); + } + me.switchState(me, other, 1, skipAnimation); + } // zoom in from button (factor increases) +} + +void ModalController_hideAll(entity me, float skipAnimation) +{ + entity e; + for (e = me.firstChild; e; e = e.nextSibling) { + me.hideChild(me, e, skipAnimation); } +} + +void ModalController_hideChild(entity me, entity other, float skipAnimation) +{ + if (other.ModalController_state || skipAnimation) { + me.setFocus(me, NULL); + me.switchState(me, other, 0, skipAnimation); + if (other.ModalController_controllingButton) { + other.ModalController_controllingButton.forcePressed = 0; + other.ModalController_controllingButton = NULL; + } + } // just alpha fade out (factor increases and decreases alpha) +} diff --git a/qcsrc/menu/item/radiobutton.qc b/qcsrc/menu/item/radiobutton.qc index 00dcb680a..e2a2c9fe0 100644 --- a/qcsrc/menu/item/radiobutton.qc +++ b/qcsrc/menu/item/radiobutton.qc @@ -1,24 +1,22 @@ #include "radiobutton.qh" - void RadioButton_configureRadioButton(entity me, string txt, float sz, string gfx, float theGroup, float doAllowDeselect) - { - me.configureCheckBox(me, txt, sz, gfx); - me.align = 0; - me.group = theGroup; - me.allowDeselect = doAllowDeselect; - } - void RadioButton_Click(entity me, entity other) - { - if (me.checked) - { - if (me.allowDeselect) me.setChecked(me, 0); - } - else - { - entity e; - for (e = me.parent.firstChild; e; e = e.nextSibling) - if (e != me) - if (e.group == me.group) e.setChecked(e, 0); - me.setChecked(me, 1); +void RadioButton_configureRadioButton(entity me, string txt, float sz, string gfx, float theGroup, float doAllowDeselect) +{ + me.configureCheckBox(me, txt, sz, gfx); + me.align = 0; + me.group = theGroup; + me.allowDeselect = doAllowDeselect; +} +void RadioButton_Click(entity me, entity other) +{ + if (me.checked) { + if (me.allowDeselect) { me.setChecked(me, 0); } + } else { + entity e; + for (e = me.parent.firstChild; e; e = e.nextSibling) { + if (e != me) { + if (e.group == me.group) { e.setChecked(e, 0); } } } + me.setChecked(me, 1); } +} diff --git a/qcsrc/menu/item/tab.qh b/qcsrc/menu/item/tab.qh index 18c9e4959..2b0c9d106 100644 --- a/qcsrc/menu/item/tab.qh +++ b/qcsrc/menu/item/tab.qh @@ -6,7 +6,7 @@ CLASS(Tab, Dialog) ATTRIB(Tab, closable, float, 0); ATTRIB(Tab, rootDialog, float, 0); ATTRIB(Tab, title, string); - ATTRIB(Tab, titleFontSize, float, 0); // pixels + ATTRIB(Tab, titleFontSize, float, 0); // pixels // still to be customized ATTRIB(Tab, intendedWidth, float, 0); diff --git a/qcsrc/menu/item/textslider.qc b/qcsrc/menu/item/textslider.qc index 01f89fc4d..ce8cbf6f5 100644 --- a/qcsrc/menu/item/textslider.qc +++ b/qcsrc/menu/item/textslider.qc @@ -1,64 +1,63 @@ #include "textslider.qh" - string TextSlider_valueToIdentifier(entity me, int val) - { - if (val >= me.nValues) return "custom"; - if (val < 0) return "custom"; - return me.(valueIdentifiers[val]); - } - string TextSlider_valueToText(entity me, int val) - { - if (val >= me.nValues) return _("Custom"); - if (val < 0) return _("Custom"); - return me.(valueStrings[val]); - } - void TextSlider_setValueFromIdentifier_allowAnim(entity me, string id, bool allowAnim) - { - int i; - for (i = 0; i < me.nValues; ++i) - if (me.valueToIdentifier(me, i) == id) - { - SUPER(TextSlider).setValue_allowAnim(me, i, allowAnim); - return; - } - SUPER(TextSlider).setValue_allowAnim(me, -1, allowAnim); - } - void TextSlider_setValueFromIdentifier_noAnim(entity me, string id) - { - TextSlider_setValueFromIdentifier_allowAnim(me, id, false); - } - void TextSlider_setValueFromIdentifier(entity me, string id) - { - TextSlider_setValueFromIdentifier_allowAnim(me, id, true); - } - string TextSlider_getIdentifier(entity me) - { - return me.valueToIdentifier(me, me.value); - } - void TextSlider_clearValues(entity me) - { - me.nValues = 0; - } - void TextSlider_addValue(entity me, string theString, string theIdentifier) - { - me.(valueStrings[me.nValues]) = theString; - me.(valueIdentifiers[me.nValues]) = theIdentifier; - me.nValues += 1; - } - void TextSlider_insertValue(entity me, int pos, string theString, string theIdentifier) - { - int i; - for (i = me.nValues; i > pos; --i) - { - me.(valueStrings[i]) = me.(valueStrings[i - 1]); - me.(valueIdentifiers[i]) = me.(valueIdentifiers[i - 1]); +string TextSlider_valueToIdentifier(entity me, int val) +{ + if (val >= me.nValues) { return "custom"; } + if (val < 0) { return "custom"; } + return me.(valueIdentifiers[val]); +} +string TextSlider_valueToText(entity me, int val) +{ + if (val >= me.nValues) { return _("Custom"); } + if (val < 0) { return _("Custom"); } + return me.(valueStrings[val]); +} +void TextSlider_setValueFromIdentifier_allowAnim(entity me, string id, bool allowAnim) +{ + int i; + for (i = 0; i < me.nValues; ++i) { + if (me.valueToIdentifier(me, i) == id) { + SUPER(TextSlider).setValue_allowAnim(me, i, allowAnim); + return; } - me.(valueStrings[pos]) = theString; - me.(valueIdentifiers[pos]) = theIdentifier; - me.nValues += 1; - } - void TextSlider_configureTextSliderValues(entity me, string theDefault) - { - me.configureSliderValues(me, 0, 0, me.nValues - 1, 1, 1, 1); - me.setValueFromIdentifier_noAnim(me, theDefault); } + SUPER(TextSlider).setValue_allowAnim(me, -1, allowAnim); +} +void TextSlider_setValueFromIdentifier_noAnim(entity me, string id) +{ + TextSlider_setValueFromIdentifier_allowAnim(me, id, false); +} +void TextSlider_setValueFromIdentifier(entity me, string id) +{ + TextSlider_setValueFromIdentifier_allowAnim(me, id, true); +} +string TextSlider_getIdentifier(entity me) +{ + return me.valueToIdentifier(me, me.value); +} +void TextSlider_clearValues(entity me) +{ + me.nValues = 0; +} +void TextSlider_addValue(entity me, string theString, string theIdentifier) +{ + me.(valueStrings[me.nValues]) = theString; + me.(valueIdentifiers[me.nValues]) = theIdentifier; + me.nValues += 1; +} +void TextSlider_insertValue(entity me, int pos, string theString, string theIdentifier) +{ + int i; + for (i = me.nValues; i > pos; --i) { + me.(valueStrings[i]) = me.(valueStrings[i - 1]); + me.(valueIdentifiers[i]) = me.(valueIdentifiers[i - 1]); + } + me.(valueStrings[pos]) = theString; + me.(valueIdentifiers[pos]) = theIdentifier; + me.nValues += 1; +} +void TextSlider_configureTextSliderValues(entity me, string theDefault) +{ + me.configureSliderValues(me, 0, 0, me.nValues - 1, 1, 1, 1); + me.setValueFromIdentifier_noAnim(me, theDefault); +} diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index af14e0842..8d5d51055 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -40,7 +40,7 @@ float realconwidth, realconheight; void m_sync() { updateCompression(); - vidwidth_s = vidheight_s = vidpixelheight_s = 0; // Force updateConwidths on next draw + vidwidth_s = vidheight_s = vidpixelheight_s = 0; // Force updateConwidths on next draw loadAllCvars(main); } @@ -48,9 +48,9 @@ void m_sync() void m_gamestatus() { gamestatus = 0; - if (isserver()) gamestatus |= GAME_ISSERVER; - if (clientstate() == CS_CONNECTED || isdemo()) gamestatus |= GAME_CONNECTED; - if (cvar("developer")) gamestatus |= GAME_DEVELOPER; + if (isserver()) { gamestatus |= GAME_ISSERVER; } + if (clientstate() == CS_CONNECTED || isdemo()) { gamestatus |= GAME_CONNECTED; } + if (cvar("developer")) { gamestatus |= GAME_DEVELOPER; } } void m_init() @@ -58,8 +58,7 @@ void m_init() bool restarting = false; cvar_set("_menu_alpha", "0"); prvm_language = cvar_string("prvm_language"); - if (prvm_language == "") - { + if (prvm_language == "") { prvm_language = "en"; cvar_set("prvm_language", prvm_language); localcmd("\nmenu_restart\n"); @@ -69,16 +68,14 @@ void m_init() cvar_set("_menu_prvm_language", prvm_language); #ifdef WATERMARK - LOG_INFOF("^4MQC Build information: ^1%s", WATERMARK); + LOG_INFOF("^4MQC Build information: ^1%s", WATERMARK); #endif // list all game dirs (TEST) - if (cvar("developer")) - { - for (int i = 0; ; ++i) - { + if (cvar("developer")) { + for (int i = 0; ; ++i) { string s = getgamedirinfo(i, GETGAMEDIRINFO_NAME); - if (!s) break; + if (!s) { break; } LOG_TRACE(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION)); } } @@ -93,13 +90,12 @@ void m_init() float ddsload = cvar("r_texture_dds_load"); float texcomp = cvar("gl_texturecompression"); updateCompression(); - if (ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression")) localcmd("\nr_restart\n"); + if (ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression")) { localcmd("\nr_restart\n"); } - if (!restarting) - { - if (cvar("_menu_initialized")) // always show menu after menu_restart + if (!restarting) { + if (cvar("_menu_initialized")) { // always show menu after menu_restart m_display(); - else m_hide(); + } else { m_hide(); } cvar_set("_menu_initialized", "1"); } } @@ -117,9 +113,8 @@ void draw_reset_full() void UpdateConWidthHeight(float w, float h, float p) { - if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s) - { - if (updateConwidths(w, h, p)) localcmd(sprintf("\nexec %s\n", cvar_string("menu_font_cfg"))); + if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s) { + if (updateConwidths(w, h, p)) { localcmd(sprintf("\nexec %s\n", cvar_string("menu_font_cfg"))); } vidwidth_s = w; vidheight_s = h; vidpixelheight_s = p; @@ -128,29 +123,22 @@ void UpdateConWidthHeight(float w, float h, float p) conheight_s = conheight; realconwidth = cvar("vid_conwidth"); realconheight = cvar("vid_conheight"); - if (realconwidth / realconheight > MENU_ASPECT) - { + if (realconwidth / realconheight > MENU_ASPECT) { // widescreen conwidth = realconheight * MENU_ASPECT; conheight = realconheight; - } - else - { + } else { // squarescreen conwidth = realconwidth; conheight = realconwidth / MENU_ASPECT; } - if (main) - { - if (conwidth_s != conwidth || conheight_s != conheight) - { + if (main) { + if (conwidth_s != conwidth || conheight_s != conheight) { draw_reset_cropped(); main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight); } - } - else - { - vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame + } else { + vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame } } @@ -160,44 +148,40 @@ void m_init_delayed() draw_reset_cropped(); menuInitialized = false; - if (!preMenuInit()) return; + if (!preMenuInit()) { return; } menuInitialized = true; int fh = -1; - if (cvar_string("menu_skin") != "") - { + if (cvar_string("menu_skin") != "") { draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin")); fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); } - if (fh < 0 && cvar_defstring("menu_skin") != "") - { + if (fh < 0 && cvar_defstring("menu_skin") != "") { cvar_set("menu_skin", cvar_defstring("menu_skin")); draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin")); fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); } - if (fh < 0) - { + if (fh < 0) { draw_currentSkin = "gfx/menu/default"; fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); } - if (fh < 0) error("cannot load any menu skin\n"); + if (fh < 0) { error("cannot load any menu skin\n"); } draw_currentSkin = strzone(draw_currentSkin); - for (string s; (s = fgets(fh)); ) - { + for (string s; (s = fgets(fh)); ) { // these two are handled by skinlist.qc - if (substring(s, 0, 6) == "title ") continue; - if (substring(s, 0, 7) == "author ") continue; + if (substring(s, 0, 6) == "title ") { continue; } + if (substring(s, 0, 7) == "author ") { continue; } int n = tokenize_console(s); - if (n < 2) continue; + if (n < 2) { continue; } Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); } fclose(fh); int glob = search_begin(strcat(draw_currentSkin, "/*.tga"), true, true); - if (glob >= 0) - { - for (int i = 0, n = search_getsize(glob); i < n; ++i) + if (glob >= 0) { + for (int i = 0, n = search_getsize(glob); i < n; ++i) { precache_pic(search_getfilename(glob, i)); + } search_end(glob); } @@ -214,84 +198,78 @@ void m_init_delayed() m_sync(); - if (m_goto_buffer) - { + if (m_goto_buffer) { m_goto(m_goto_buffer); strunzone(m_goto_buffer); m_goto_buffer = string_null; } - if (Menu_Active) m_display(); // delayed menu display + if (Menu_Active) { + m_display(); // delayed menu display + } } void m_keyup(float key, float ascii) { - if (!menuInitialized) return; - if (!Menu_Active) return; + if (!menuInitialized) { return; } + if (!Menu_Active) { return; } draw_reset_cropped(); main.keyUp(main, key, ascii, menuShiftState); - if (key >= K_MOUSE1 && key <= K_MOUSE3) - { + if (key >= K_MOUSE1 && key <= K_MOUSE3) { --mouseButtonsPressed; - if (!mouseButtonsPressed) main.mouseRelease(main, menuMousePos); - if (mouseButtonsPressed < 0) - { + if (!mouseButtonsPressed) { main.mouseRelease(main, menuMousePos); } + if (mouseButtonsPressed < 0) { mouseButtonsPressed = 0; LOG_TRACE("Warning: released an already released button"); } } - if (key == K_ALT) menuShiftState &= ~S_ALT; - if (key == K_CTRL) menuShiftState &= ~S_CTRL; - if (key == K_SHIFT) menuShiftState &= ~S_SHIFT; + if (key == K_ALT) { menuShiftState &= ~S_ALT; } + if (key == K_CTRL) { menuShiftState &= ~S_CTRL; } + if (key == K_SHIFT) { menuShiftState &= ~S_SHIFT; } } void m_keydown(float key, float ascii) { - if (!menuInitialized) return; - if (!Menu_Active) return; + if (!menuInitialized) { return; } + if (!Menu_Active) { return; } - if (menuMouseMode && key >= K_MOUSE1 && key <= K_MOUSE3) - { + if (menuMouseMode && key >= K_MOUSE1 && key <= K_MOUSE3) { // detect a click outside of the game window vector p = getmousepos(); - if (p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight) - { + if (p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight) { ++mouseButtonsPressed; return; } } - if (keyGrabber) - { + if (keyGrabber) { entity e = keyGrabber; keyGrabber = NULL; e.keyGrabbed(e, key, ascii); - } - else - { + } else { draw_reset_cropped(); - if (!mouseButtonsPressed && key >= K_MOUSE1 && key <= K_MOUSE3) + if (!mouseButtonsPressed && key >= K_MOUSE1 && key <= K_MOUSE3) { main.mousePress(main, menuMousePos); - if (!main.keyDown(main, key, ascii, menuShiftState)) - { + } + if (!main.keyDown(main, key, ascii, menuShiftState)) { // disable menu on unhandled ESC - if (key == K_ESCAPE) - if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only + if (key == K_ESCAPE) { + if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) { // don't back out to console only m_hide(); + } + } } } - if (key >= K_MOUSE1 && key <= K_MOUSE3) - { + if (key >= K_MOUSE1 && key <= K_MOUSE3) { ++mouseButtonsPressed; - if (mouseButtonsPressed > 10) - { + if (mouseButtonsPressed > 10) { mouseButtonsPressed = 10; LOG_TRACE("Warning: pressed an already pressed button"); } } - if (key == K_ALT) menuShiftState |= S_ALT; - if (key == K_CTRL) menuShiftState |= S_CTRL; - if (key == K_SHIFT) menuShiftState |= S_SHIFT; + if (key == K_ALT) { menuShiftState |= S_ALT; } + if (key == K_CTRL) { menuShiftState |= S_CTRL; } + if (key == K_SHIFT) { menuShiftState |= S_SHIFT; } } enum { @@ -308,8 +286,7 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a) vector isz_w = '1 0 0' + '0 1 0' * ((sz.y / sz.x) * (draw_scale.x / draw_scale.y)); vector isz_h = '0 1 0' + '1 0 0' * ((sz.x / sz.y) * (draw_scale.y / draw_scale.x)); vector isz; - switch (scalemode) - { + switch (scalemode) { default: case SCALEMODE_CROP: isz = (width_is_larger ? isz_h : isz_w); @@ -333,14 +310,12 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a) void drawBackground(string img, float a, string algn, float force1) { - if (main.mainNexposee.ModalController_state == 0) return; + if (main.mainNexposee.ModalController_state == 0) { return; } vector v = '0 0 0'; int scalemode = SCALEMODE_CROP; - for (int i = 0, l = 0; i < strlen(algn); ++i) - { + for (int i = 0, l = 0; i < strlen(algn); ++i) { string c = substring(algn, i, 1); - switch (c) - { + switch (c) { case "c": scalemode = SCALEMODE_CROP; goto nopic; @@ -369,8 +344,7 @@ void drawBackground(string img, float a, string algn, float force1) v.x = random(); break; } - switch (c) - { + switch (c) { case "7": case "8": case "9": v.y = 0.0; break; @@ -384,23 +358,18 @@ void drawBackground(string img, float a, string algn, float force1) v.y = random(); break; } - if (l == 0) - { + if (l == 0) { draw_Picture_Aligned(v, scalemode, img, a); - } - else if (force1) - { + } else if (force1) { // force all secondary layers to use alpha 1. Prevents ugly issues // with overlap. It's a flag because it cannot be used for the // ingame background draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), 1); - } - else - { + } else { draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), a); } ++l; -LABEL(nopic) + LABEL(nopic) } } @@ -412,20 +381,20 @@ vector menuTooltipOrigin; vector menuTooltipSize; float menuTooltipAlpha; string menuTooltipText; -int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out +int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out bool m_testmousetooltipbox(vector pos) { return !( - (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x) - && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y) - ); + (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x) + && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y) + ); } bool m_testtooltipbox(vector tooltippos) { - if (tooltippos.x < 0) return false; - if (tooltippos.y < 0) return false; - if (tooltippos.x + menuTooltipSize.x > 1) return false; - if (tooltippos.y + menuTooltipSize.y > 1) return false; + if (tooltippos.x < 0) { return false; } + if (tooltippos.y < 0) { return false; } + if (tooltippos.x + menuTooltipSize.x > 1) { return false; } + if (tooltippos.y + menuTooltipSize.y > 1) { return false; } menuTooltipOrigin = tooltippos; return true; } @@ -443,58 +412,53 @@ bool m_allocatetooltipbox(vector pos) // bottom right vector v = pos + avoidplus; - if (m_testtooltipbox(v)) return true; + if (m_testtooltipbox(v)) { return true; } // bottom center v.x = pos.x - menuTooltipSize.x * 0.5; - if (m_testtooltipbox(v)) return true; + if (m_testtooltipbox(v)) { return true; } // bottom left v.x = pos.x - avoidminus.x; - if (m_testtooltipbox(v)) return true; + if (m_testtooltipbox(v)) { return true; } // top left v.y = pos.y - avoidminus.y; - if (m_testtooltipbox(v)) return true; + if (m_testtooltipbox(v)) { return true; } // top center v.x = pos.x - menuTooltipSize.x * 0.5; - if (m_testtooltipbox(v)) return true; + if (m_testtooltipbox(v)) { return true; } // top right v.x = pos.x + avoidplus.x; - if (m_testtooltipbox(v)) return true; + if (m_testtooltipbox(v)) { return true; } return false; } entity m_findtooltipitem(entity root, vector pos) { entity best = NULL; - for (entity it = root; it.instanceOfContainer; ) - { - while (it.instanceOfNexposee && it.focusedChild) - { + for (entity it = root; it.instanceOfContainer; ) { + while (it.instanceOfNexposee && it.focusedChild) { it = it.focusedChild; pos = globalToBox(pos, it.Container_origin, it.Container_size); } - if (it.instanceOfNexposee) - { + if (it.instanceOfNexposee) { it = it.itemFromPoint(it, pos); - if (it.tooltip) best = it; - else if (menu_tooltips == 2 && (it.cvarName || it.onClickCommand)) best = it; + if (it.tooltip) { best = it; } else if (menu_tooltips == 2 && (it.cvarName || it.onClickCommand)) { + best = it; + } it = NULL; - } - else if (it.instanceOfModalController) - { + } else if (it.instanceOfModalController) { it = it.focusedChild; - } - else - { + } else { it = it.itemFromPoint(it, pos); } - if (!it) break; - if (it.tooltip) best = it; - else if (menu_tooltips == 2 && (it.cvarName || it.onClickCommand)) best = it; + if (!it) { break; } + if (it.tooltip) { best = it; } else if (menu_tooltips == 2 && (it.cvarName || it.onClickCommand)) { + best = it; + } pos = globalToBox(pos, it.Container_origin, it.Container_size); } @@ -502,24 +466,19 @@ entity m_findtooltipitem(entity root, vector pos) } string gettooltip() { - if (menu_tooltips == 2) - { + if (menu_tooltips == 2) { string s; - if (menuTooltipItem.cvarName) - { - if (getCvarsMulti(menuTooltipItem)) s = - strcat("[", menuTooltipItem.cvarName, " ", getCvarsMulti(menuTooltipItem), "]"); - else s = strcat("[", menuTooltipItem.cvarName, "]"); - } - else if (menuTooltipItem.onClickCommand) - { + if (menuTooltipItem.cvarName) { + if (getCvarsMulti(menuTooltipItem)) { + s = + strcat("[", menuTooltipItem.cvarName, " ", getCvarsMulti(menuTooltipItem), "]"); + } else { s = strcat("[", menuTooltipItem.cvarName, "]"); } + } else if (menuTooltipItem.onClickCommand) { s = strcat("<", menuTooltipItem.onClickCommand, ">"); - } - else - { + } else { return menuTooltipItem.tooltip; } - if (menuTooltipItem.tooltip) return strcat(menuTooltipItem.tooltip, " ", s); + if (menuTooltipItem.tooltip) { return strcat(menuTooltipItem.tooltip, " ", s); } return s; } return menuTooltipItem.tooltip; @@ -529,73 +488,59 @@ void m_tooltip(vector pos) static string prev_tooltip; entity it; menu_tooltips = cvar("menu_tooltips"); - if (!menu_tooltips) - { + if (!menu_tooltips) { // don't return immediately, fade out the active tooltip first - if (menuTooltipItem == NULL) return; + if (menuTooltipItem == NULL) { return; } it = NULL; menu_tooltips_old = menu_tooltips; - } - else - { + } else { float f = bound(0, frametime * 2, 1); menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f; - if (vdist(pos - menuTooltipAveragedMousePos, <, 0.01)) - { + if (vdist(pos - menuTooltipAveragedMousePos, <, 0.01)) { it = m_findtooltipitem(main, pos); - if (it.instanceOfListBox && it.isScrolling(it)) it = NULL; + if (it.instanceOfListBox && it.isScrolling(it)) { it = NULL; } - if (it && prev_tooltip != it.tooltip) - { + if (it && prev_tooltip != it.tooltip) { // fade out if tooltip of a certain item has changed menuTooltipState = 3; - if (prev_tooltip) strunzone(prev_tooltip); + if (prev_tooltip) { strunzone(prev_tooltip); } prev_tooltip = strzone(it.tooltip); + } else if (menuTooltipItem && !m_testmousetooltipbox(pos)) { + menuTooltipState = 3; // fade out if mouse touches it } - else if (menuTooltipItem && !m_testmousetooltipbox(pos)) - { - menuTooltipState = 3; // fade out if mouse touches it - } - } - else - { + } else { it = NULL; } } vector fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight); // float menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out - if (it != menuTooltipItem) - { - switch (menuTooltipState) - { + if (it != menuTooltipItem) { + switch (menuTooltipState) { case 0: - if (menuTooltipItem) - { + if (menuTooltipItem) { // another item: fade out first menuTooltipState = 2; - } - else - { + } else { // new item: fade in menuTooltipState = 1; menuTooltipItem = it; - menuTooltipOrigin.x = -1; // unallocated + menuTooltipOrigin.x = -1; // unallocated - if (menuTooltipText) strunzone(menuTooltipText); + if (menuTooltipText) { strunzone(menuTooltipText); } menuTooltipText = strzone(gettooltip()); int i = 0; float w = 0; - for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i) - { + for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i) { string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors); - if (i == 16) + if (i == 16) { s = "..."; + } float f = draw_TextWidth(s, false, fontsize); - if (f > w) w = f; + if (f > w) { w = f; } } menuTooltipSize.x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth); menuTooltipSize.y = i * fontsize.y + 2 * (SKINMARGIN_TOOLTIP_y / conheight); @@ -610,51 +555,41 @@ void m_tooltip(vector pos) // changing item while fading out: can't break; } - } - else if (menuTooltipState == 2) // re-fade in? - { + } else if (menuTooltipState == 2) { // re-fade in? menuTooltipState = 1; } - switch (menuTooltipState) - { - case 1: // fade in + switch (menuTooltipState) { + case 1: // fade in menuTooltipAlpha = bound(0, menuTooltipAlpha + 5 * frametime, 1); - if (menuTooltipAlpha == 1) menuTooltipState = 0; + if (menuTooltipAlpha == 1) { menuTooltipState = 0; } break; - case 2: // fade out - case 3: // forced fade out + case 2: // fade out + case 3: // forced fade out menuTooltipAlpha = bound(0, menuTooltipAlpha - 2 * frametime, 1); - if (menuTooltipAlpha == 0) - { + if (menuTooltipAlpha == 0) { menuTooltipState = 0; menuTooltipItem = NULL; } break; } - if (menuTooltipItem == NULL) - { - if (menuTooltipText) - { + if (menuTooltipItem == NULL) { + if (menuTooltipText) { strunzone(menuTooltipText); menuTooltipText = string_null; } return; - } - else - { - if (menu_tooltips != menu_tooltips_old) - { - if (menu_tooltips != 0 && menu_tooltips_old != 0) menuTooltipItem = NULL; // reload tooltip next frame + } else { + if (menu_tooltips != menu_tooltips_old) { + if (menu_tooltips != 0 && menu_tooltips_old != 0) { + menuTooltipItem = NULL; // reload tooltip next frame + } menu_tooltips_old = menu_tooltips; - } - else if (menuTooltipOrigin.x < 0) // unallocated? - { + } else if (menuTooltipOrigin.x < 0) { // unallocated? m_allocatetooltipbox(pos); } - if (menuTooltipOrigin.x >= 0) - { + if (menuTooltipOrigin.x >= 0) { // draw the tooltip! vector p = SKINBORDER_TOOLTIP; p.x *= 1 / conwidth; @@ -664,11 +599,11 @@ void m_tooltip(vector pos) p.x += SKINMARGIN_TOOLTIP_x / conwidth; p.y += SKINMARGIN_TOOLTIP_y / conheight; int i = 0; - for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i, p.y += fontsize.y) - { + for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i, p.y += fontsize.y) { string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors); - if (i == 16) + if (i == 16) { s = "..."; + } draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, false); } } @@ -678,19 +613,16 @@ void m_tooltip(vector pos) float autocvar_menu_force_on_disconnection; void m_draw(float width, float height) { - if (autocvar_menu_force_on_disconnection > 0) - { + if (autocvar_menu_force_on_disconnection > 0) { static float connected_time; - if (clientstate() == CS_DISCONNECTED) - { - if (connected_time && time - connected_time > autocvar_menu_force_on_disconnection) - { + if (clientstate() == CS_DISCONNECTED) { + if (connected_time && time - connected_time > autocvar_menu_force_on_disconnection) { m_toggle(true); connected_time = 0; } - } - else + } else { connected_time = time; + } } m_gamestatus(); @@ -699,24 +631,21 @@ void m_draw(float width, float height) menuMouseMode = cvar("menu_mouse_absolute"); - if (anim) anim.tickAll(anim); + if (anim) { anim.tickAll(anim); } UpdateConWidthHeight(width, height, cvar("vid_pixelheight")); - if (!menuInitialized) - { + if (!menuInitialized) { // TODO draw an info image about this situation m_init_delayed(); return; } - if (!menuNotTheFirstFrame) - { + if (!menuNotTheFirstFrame) { menuNotTheFirstFrame = true; - if (Menu_Active && !cvar("menu_video_played")) - { - localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n"); - menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME - } + if (Menu_Active && !cvar("menu_video_played")) { + localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n"); + menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME + } // ALWAYS set this cvar; if we start but menu is not active, this means we want no background music! localcmd("set menu_video_played 1\n"); } @@ -727,67 +656,52 @@ void m_draw(float width, float height) time += frametime; t = cvar("menu_slowmo"); - if (t) - { + if (t) { frametime *= t; realFrametime *= t; - } - else - { + } else { t = 1; } - if (Menu_Active) - { + if (Menu_Active) { if (getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) - && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED)) - setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU); - else m_hide(); + && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED)) { + setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU); + } else { m_hide(); } } - if (cvar("cl_capturevideo")) frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly - + if (cvar("cl_capturevideo")) { + frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly + } prevMenuAlpha = menuAlpha; - if (Menu_Active) - { - if (menuAlpha == 0 && menuLogoAlpha < 2) - { + if (Menu_Active) { + if (menuAlpha == 0 && menuLogoAlpha < 2) { menuLogoAlpha += 2 * frametime; - } - else - { + } else { menuAlpha = min(1, menuAlpha + 5 * frametime); menuLogoAlpha = 2; } - } - else - { + } else { menuAlpha = max(0, menuAlpha - 5 * frametime); menuLogoAlpha = 2; } draw_reset_cropped(); - if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) - { - if (menuLogoAlpha > 0) - { + if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) { + if (menuLogoAlpha > 0) { draw_reset_full(); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_BACKGROUND, 1); drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, true); draw_reset_cropped(); - if (menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0) - { + if (menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0) { draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1); draw_drawMousePointer(menuMousePos); draw_alpha = 1; } } - } - else if (SKINALPHA_BACKGROUND_INGAME) - { - if (menuAlpha > 0) - { + } else if (SKINALPHA_BACKGROUND_INGAME) { + if (menuAlpha > 0) { draw_reset_full(); drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME, SKINALIGN_BACKGROUND_INGAME, false); @@ -795,15 +709,14 @@ void m_draw(float width, float height) } } - if (menuAlpha != prevMenuAlpha) cvar_set("_menu_alpha", ftos(menuAlpha)); + if (menuAlpha != prevMenuAlpha) { cvar_set("_menu_alpha", ftos(menuAlpha)); } draw_reset_cropped(); preMenuDraw(); draw_reset_cropped(); - if (menuAlpha <= 0) - { - if (prevMenuAlpha > 0) main.initializeDialog(main, main.firstChild); + if (menuAlpha <= 0) { + if (prevMenuAlpha > 0) { main.initializeDialog(main, main.firstChild); } draw_reset_cropped(); postMenuDraw(); return; @@ -811,30 +724,23 @@ void m_draw(float width, float height) draw_alpha *= menuAlpha; - if (menuMouseMode) - { + if (menuMouseMode) { vector rawMousePos = getmousepos(); vector newMouse = globalToBox(rawMousePos, draw_shift, draw_scale); - if (rawMousePos != '0 0 0' && newMouse != menuMousePos) - { + if (rawMousePos != '0 0 0' && newMouse != menuMousePos) { menuMousePos = newMouse; - if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos); - else main.mouseMove(main, menuMousePos); + if (mouseButtonsPressed) { main.mouseDrag(main, menuMousePos); } else { main.mouseMove(main, menuMousePos); } } - } - else if (frametime > 0) - { - vector dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo - if (dMouse != '0 0 0') - { + } else if (frametime > 0) { + vector dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo + if (dMouse != '0 0 0') { vector minpos = globalToBox('0 0 0', draw_shift, draw_scale); vector maxpos = globalToBox(eX * (realconwidth - 1) + eY * (realconheight - 1), draw_shift, draw_scale); dMouse = globalToBoxSize(dMouse, draw_scale); menuMousePos += dMouse * cvar("menu_mouse_speed"); menuMousePos.x = bound(minpos.x, menuMousePos.x, maxpos.x); menuMousePos.y = bound(minpos.y, menuMousePos.y, maxpos.y); - if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos); - else main.mouseMove(main, menuMousePos); + if (mouseButtonsPressed) { main.mouseDrag(main, menuMousePos); } else { main.mouseMove(main, menuMousePos); } } } main.draw(main); @@ -858,9 +764,9 @@ void m_display() setkeydest(KEY_MENU); setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU)); - if (!menuInitialized) return; + if (!menuInitialized) { return; } - if (mouseButtonsPressed) main.mouseRelease(main, menuMousePos); + if (mouseButtonsPressed) { main.mouseRelease(main, menuMousePos); } mouseButtonsPressed = 0; main.focusEnter(main); @@ -873,7 +779,7 @@ void m_hide() setkeydest(KEY_GAME); setmousetarget(MT_CLIENT); - if (!menuInitialized) return; + if (!menuInitialized) { return; } main.focusLeave(main); main.hideNotify(main); @@ -881,14 +787,11 @@ void m_hide() void m_toggle(int mode) { - if (Menu_Active) - { - if (mode == 1) return; + if (Menu_Active) { + if (mode == 1) { return; } m_hide(); - } - else - { - if (mode == 0) return; + } else { + if (mode == 0) { return; } m_display(); } } @@ -897,88 +800,77 @@ void Shutdown() { m_hide(); FOREACH_ENTITY_ORDERED(it.destroy, { - if (it.classname == "vtbl") continue; + if (it.classname == "vtbl") { continue; } it.destroy(it); }); } void m_focus_item_chain(entity outermost, entity innermost) { - if (innermost.parent != outermost) m_focus_item_chain(outermost, innermost.parent); + if (innermost.parent != outermost) { m_focus_item_chain(outermost, innermost.parent); } innermost.parent.setFocus(innermost.parent, innermost); } void m_activate_window(entity wnd) { entity par = wnd.parent; - if (par) m_activate_window(par); + if (par) { m_activate_window(par); } - if (par.instanceOfModalController) - { - if (wnd.tabSelectingButton) + if (par.instanceOfModalController) { + if (wnd.tabSelectingButton) { // tabs TabButton_Click(wnd.tabSelectingButton, wnd); - else + } else { // root par.initializeDialog(par, wnd); - } - else if (par.instanceOfNexposee) - { + } + } else if (par.instanceOfNexposee) { // nexposee (sorry for violating abstraction here) par.selectedChild = wnd; par.animationState = 1; Container_setFocus(par, NULL); - } - else if (par.instanceOfContainer) - { + } else if (par.instanceOfContainer) { // other containers - if (par.focused) par.setFocus(par, wnd); + if (par.focused) { par.setFocus(par, wnd); } } } void m_setpointerfocus(entity wnd) { - if (!wnd.instanceOfContainer) return; + if (!wnd.instanceOfContainer) { return; } entity focus = wnd.preferredFocusedGrandChild(wnd); - if (!focus) return; + if (!focus) { return; } menuMousePos = focus.origin + 0.5 * focus.size; menuMousePos.x *= 1 / conwidth; menuMousePos.y *= 1 / conheight; entity par = wnd.parent; - if (par.focused) par.setFocus(par, wnd); - if (wnd.focused) m_focus_item_chain(wnd, focus); + if (par.focused) { par.setFocus(par, wnd); } + if (wnd.focused) { m_focus_item_chain(wnd, focus); } } void m_goto(string itemname) { - if (!menuInitialized) - { - if (m_goto_buffer) strunzone(m_goto_buffer); + if (!menuInitialized) { + if (m_goto_buffer) { strunzone(m_goto_buffer); } m_goto_buffer = strzone(itemname); return; } - if (itemname == "") // this can be called by GameCommand - { - if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) - { + if (itemname == "") { // this can be called by GameCommand + if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) { m_hide(); - } - else - { + } else { m_activate_window(main.mainNexposee); m_display(); } - } - else - { + } else { entity e; - for (e = NULL; (e = find(e, name, itemname)); ) - if (e.classname != "vtbl") break; + for (e = NULL; (e = find(e, name, itemname)); ) { + if (e.classname != "vtbl") { break; } } - if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)))) - { - if(!Menu_Active) + if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)))) { + if (!Menu_Active) { e.hideMenuOnClose = true; + } m_hide(); m_activate_window(e); m_setpointerfocus(e); @@ -990,14 +882,14 @@ void m_goto(string itemname) void m_play_focus_sound() { static float menuLastFocusSoundTime; - if (cvar("menu_sounds") < 2) return; - if (time - menuLastFocusSoundTime <= 0.25) return; + if (cvar("menu_sounds") < 2) { return; } + if (time - menuLastFocusSoundTime <= 0.25) { return; } localsound(MENU_SOUND_FOCUS); menuLastFocusSoundTime = time; } void m_play_click_sound(string soundfile) { - if (!cvar("menu_sounds")) return; + if (!cvar("menu_sounds")) { return; } localsound(soundfile); } diff --git a/qcsrc/menu/skin.qh b/qcsrc/menu/skin.qh index 4287e24e5..e1d5f5a99 100644 --- a/qcsrc/menu/skin.qh +++ b/qcsrc/menu/skin.qh @@ -1,10 +1,10 @@ #pragma once #define SKINBEGIN -#define SKINVECTOR(name,def) vector SKIN##name = def -#define SKINFLOAT(name,def) float SKIN##name = def -//#define SKINSTRING(name,def) const string SKIN##name = def -#define SKINSTRING(name,def) string SKIN##name = def +#define SKINVECTOR(name, def) vector SKIN##name = def +#define SKINFLOAT(name, def) float SKIN##name = def +// #define SKINSTRING(name,def) const string SKIN##name = def +#define SKINSTRING(name, def) string SKIN##name = def #define SKINEND #include "skin-customizables.inc" #undef SKINEND @@ -13,12 +13,12 @@ #undef SKINFLOAT #undef SKINVECTOR -#define SKINBEGIN void Skin_ApplySetting(string key, string _value) { switch(key) { -#define SKINVECTOR(name,def) case #name: SKIN##name = stov(_value); break -#define SKINFLOAT(name,def) case #name: SKIN##name = stof(_value); break -//#define SKINSTRING(name,def) case #name: break -#define SKINSTRING(name,def) case #name: SKIN##name = strzone(_value); break - // I know this leaks memory when skin is read multiple times. Screw it. +#define SKINBEGIN void Skin_ApplySetting(string key, string _value) { switch (key) { +#define SKINVECTOR(name, def) case #name: SKIN##name = stov(_value); break +#define SKINFLOAT(name, def) case #name: SKIN##name = stof(_value); break +// #define SKINSTRING(name,def) case #name: break +#define SKINSTRING(name, def) case #name: SKIN##name = strzone(_value); break +// I know this leaks memory when skin is read multiple times. Screw it. #define SKINEND case "": break; case "//": break; default: LOG_TRACE("Invalid key in skin file: ", key); } } #include "skin-customizables.inc" #undef SKINEND diff --git a/qcsrc/menu/xonotic/button.qc b/qcsrc/menu/xonotic/button.qc index d86c4a453..ea6df3561 100644 --- a/qcsrc/menu/xonotic/button.qc +++ b/qcsrc/menu/xonotic/button.qc @@ -14,12 +14,9 @@ entity makeXonoticButton(string theText, vector theColor) void XonoticButton_configureXonoticButton(entity me, string theText, vector theColor, string theTooltip) { - if(theColor == '0 0 0') - { + if (theColor == '0 0 0') { me.configureButton(me, theText, me.fontSize, me.image); - } - else - { + } else { me.configureButton(me, theText, me.fontSize, me.grayImage); me.color = theColor; me.colorC = theColor; diff --git a/qcsrc/menu/xonotic/campaign.qc b/qcsrc/menu/xonotic/campaign.qc index cb418a4e1..a095323ac 100644 --- a/qcsrc/menu/xonotic/campaign.qc +++ b/qcsrc/menu/xonotic/campaign.qc @@ -11,37 +11,35 @@ void rewrapCampaign(float w, float l0, float emptyheight, vector theFontSize) int n; float l; string r, s; - for(i = 0; i < campaign_entries; ++i) - { + for (i = 0; i < campaign_entries; ++i) { l = l0; - if(campaign_longdesc_wrapped[i]) + if (campaign_longdesc_wrapped[i]) { strunzone(campaign_longdesc_wrapped[i]); + } n = tokenizebyseparator(campaign_longdesc[i], "\n"); r = ""; - for(j = 0; j < n; ++j) - { + for (j = 0; j < n; ++j) { s = argv(j); - if(s == "") - { + if (s == "") { l -= emptyheight; r = strcat(r, "\n"); continue; } getWrappedLine_remaining = s; - while(getWrappedLine_remaining) - { + while (getWrappedLine_remaining) { s = getWrappedLine(w, theFontSize, draw_TextWidth_WithoutColors); - if(--l < 0) goto toolong; + if (--l < 0) { goto toolong; } r = strcat(r, s, "\n"); } } goto nottoolong; -LABEL(toolong) - while(substring(r, strlen(r) - 1, 1) == "\n") + LABEL(toolong) + while (substring(r, strlen(r) - 1, 1) == "\n") { r = substring(r, 0, strlen(r) - 1); + } r = strcat(r, "...\n"); -LABEL(nottoolong) + LABEL(nottoolong) campaign_longdesc_wrapped[i] = strzone(substring(r, 0, strlen(r) - 1)); } } @@ -63,17 +61,20 @@ void XonoticCampaignList_configureXonoticCampaignList(entity me) void XonoticCampaignList_destroy(entity me) { - if(me.campaignGlob >= 0) + if (me.campaignGlob >= 0) { search_end(me.campaignGlob); + } } void XonoticCampaignList_loadCvars(entity me) { // read campaign cvars - if(campaign_name) + if (campaign_name) { strunzone(campaign_name); - if(me.cvarName) + } + if (me.cvarName) { strunzone(me.cvarName); + } campaign_name = strzone(cvar_string("g_campaign_name")); me.cvarName = strzone(strcat("g_campaign", campaign_name, "_index")); registercvar(me.cvarName, "", 0); // saved by server QC anyway @@ -81,14 +82,17 @@ void XonoticCampaignList_loadCvars(entity me) CampaignFile_Load(0, CAMPAIGN_MAX_ENTRIES); me.campaignIndex = bound(0, cvar(me.cvarName), campaign_entries); cvar_set(me.cvarName, ftos(me.campaignIndex)); - if(me.columnNameSize) + if (me.columnNameSize) { rewrapCampaign(me.columnNameSize, me.rowsPerItem - 3, me.emptyLineHeight, me.realFontSize); + } me.nItems = min(me.campaignIndex + 2, campaign_entries); me.setSelected(me, min(me.campaignIndex, me.nItems - 1)); - if(me.nItems - 1 > me.campaignIndex) + if (me.nItems - 1 > me.campaignIndex) { me.scrollToItem(me, me.nItems - 1); - if(me.labelTitle) + } + if (me.labelTitle) { me.labelTitle.setText(me.labelTitle, campaign_title); + } } void XonoticCampaignList_saveCvars(entity me) @@ -107,36 +111,33 @@ void XonoticCampaignList_campaignGo(entity me, float step) canNext = canPrev = 0; - if(me.campaignGlob >= 0) - { + if (me.campaignGlob >= 0) { n = search_getsize(me.campaignGlob); - if(n > 0) - { + if (n > 0) { j = -1; s = strcat("maps/campaign", campaign_name, ".txt"); - for(i = 0; i < n; ++i) - { - if(search_getfilename(me.campaignGlob, i) == s) + for (i = 0; i < n; ++i) { + if (search_getfilename(me.campaignGlob, i) == s) { j = i; + } } - if(j < 0) - { + if (j < 0) { s = strcat("maps/campaign", cvar_defstring("g_campaign_name"), ".txt"); - for(i = 0; i < n; ++i) - { - if(search_getfilename(me.campaignGlob, i) == s) + for (i = 0; i < n; ++i) { + if (search_getfilename(me.campaignGlob, i) == s) { j = i; + } } } - if(j < 0) - { - if(step >= 0) + if (j < 0) { + if (step >= 0) { j = 0; - else + } else { j = n - 1; - } - else + } + } else { j = mod(j + step, n); + } s = search_getfilename(me.campaignGlob, j); s = substring(s, 13, strlen(s) - 17); cvar_set("g_campaign_name", s); @@ -146,10 +147,12 @@ void XonoticCampaignList_campaignGo(entity me, float step) } } - if(me.buttonNext) + if (me.buttonNext) { me.buttonNext.disabled = !canNext; - if(me.buttonPrev) + } + if (me.buttonPrev) { me.buttonPrev.disabled = !canPrev; + } } void MultiCampaign_Next(entity btn, entity me) @@ -163,8 +166,9 @@ void MultiCampaign_Prev(entity btn, entity me) void XonoticCampaignList_draw(entity me) { - if(cvar(me.cvarName) != me.campaignIndex || cvar_string("g_campaign_name") != campaign_name) + if (cvar(me.cvarName) != me.campaignIndex || cvar_string("g_campaign_name") != campaign_name) { me.loadCvars(me); + } SUPER(XonoticCampaignList).draw(me); } @@ -203,63 +207,60 @@ void XonoticCampaignList_drawListBoxItem(entity me, int i, vector absSize, bool float j, n; vector o; - if(i < me.campaignIndex) - { + if (i < me.campaignIndex) { theAlpha = SKINALPHA_CAMPAIGN_SELECTABLE; theColor = SKINCOLOR_CAMPAIGN_SELECTABLE; - } - else if(i == me.campaignIndex) - { + } else if (i == me.campaignIndex) { theAlpha = SKINALPHA_CAMPAIGN_CURRENT; theColor = SKINCOLOR_CAMPAIGN_CURRENT; - } - else - { + } else { theAlpha = SKINALPHA_CAMPAIGN_FUTURE; theColor = SKINCOLOR_CAMPAIGN_FUTURE; } - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - if(draw_PictureSize(strcat("/maps/", campaign_mapname[i])) == '0 0 0') + if (draw_PictureSize(strcat("/maps/", campaign_mapname[i])) == '0 0 0') { draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); - else + } else { draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", campaign_mapname[i]), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + } - if(i < me.campaignIndex) + if (i < me.campaignIndex) { draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1); - if(i <= me.campaignIndex) + } + if (i <= me.campaignIndex) { s = campaign_shortdesc[i]; // fteqcc sucks - else + } else { s = "???"; - s = draw_TextShortenToWidth(sprintf(_("Level %d: %s"), i+1, s), me.columnNameSize, 0, me.realFontSize); + } + s = draw_TextShortenToWidth(sprintf(_("Level %d: %s"), i + 1, s), me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, theColor, theAlpha, 0); - if(i <= me.campaignIndex) - { + if (i <= me.campaignIndex) { s = campaign_longdesc_wrapped[i]; n = tokenizebyseparator(s, "\n"); o = me.realUpperMargin2 * eY + me.columnNameOrigin * eX; - for(j = 0; j < n; ++j) - if(argv(j) != "") - { + for (j = 0; j < n; ++j) { + if (argv(j) != "") { draw_Text(o, argv(j), me.realFontSize, theColor, theAlpha * SKINALPHA_CAMPAIGN_DESCRIPTION, 0); o.y += me.realFontSize.y; - } - else + } else { o.y += me.realFontSize.y * me.emptyLineHeight; + } + } } } void CampaignList_LoadMap(entity btn, entity me) { - if(me.selectedItem >= me.nItems || me.selectedItem < 0) + if (me.selectedItem >= me.nItems || me.selectedItem < 0) { return; + } CampaignSetup(me.selectedItem); } @@ -271,9 +272,10 @@ void XonoticCampaignList_setSelected(entity me, float i) float XonoticCampaignList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_SPACE || scan == K_KP_ENTER) + if (scan == K_ENTER || scan == K_SPACE || scan == K_KP_ENTER) { CampaignList_LoadMap(me, me); - else + } else { return SUPER(XonoticCampaignList).keyDown(me, scan, ascii, shift); + } return 1; } diff --git a/qcsrc/menu/xonotic/charmap.qc b/qcsrc/menu/xonotic/charmap.qc index 28f67d9f5..2513a6e89 100644 --- a/qcsrc/menu/xonotic/charmap.qc +++ b/qcsrc/menu/xonotic/charmap.qc @@ -23,10 +23,11 @@ string charmap_cellToChar(entity me, vector cell) { string character = substring(CHARMAP, cell.y * me.columns + cell.x, 1); - if(character != " ") + if (character != " ") { return character; - else + } else { return ""; + } } entity makeXonoticCharmap(entity controlledInputBox) @@ -50,45 +51,45 @@ void XonoticCharmap_resizeNotify(entity me, vector relOrigin, vector relSize, ve float maxFontWidth = SKINFONTSIZE_NORMAL / absSize.x; float maxFontHeight = SKINFONTSIZE_NORMAL / absSize.y; - if((me.realCellSize.x * absSize.x) > (me.realCellSize.y * absSize.y)) - { + if ((me.realCellSize.x * absSize.x) > (me.realCellSize.y * absSize.y)) { me.realFontSize_x = me.realCellSize.y * absSize.y / absSize.x; me.realFontSize_y = me.realCellSize.y; - } - else - { + } else { me.realFontSize_x = me.realCellSize.x; me.realFontSize_y = me.realCellSize.x * absSize.x / absSize.y; } - if(me.realFontSize.x > maxFontWidth || me.realFontSize.y > maxFontHeight) + if (me.realFontSize.x > maxFontWidth || me.realFontSize.y > maxFontHeight) { me.realFontSize = eX * maxFontWidth + eY * maxFontHeight; + } me.charOffset = eX * me.realCellSize.x / 2 + eY * ((me.realCellSize.y - me.realFontSize.y) / 2); } float XonoticCharmap_keyDown(entity me, float key, float ascii, float shift) { - if(SUPER(XonoticCharmap).keyDown(me, key, ascii, shift)) + if (SUPER(XonoticCharmap).keyDown(me, key, ascii, shift)) { return 1; + } return me.inputBox.keyDown(me.inputBox, key, ascii, shift); } void XonoticCharmap_cellSelect(entity me, vector cell) { string character = charmap_cellToChar(me, cell); - if(character != "") - { + if (character != "") { me.inputBox.enterText(me.inputBox, character); - if(me.inputBox.applyButton) + if (me.inputBox.applyButton) { me.inputBox.applyButton.disabled = false; + } } } bool XonoticCharmap_cellIsValid(entity me, vector cell) { - if(charmap_cellToChar(me, cell) == "") + if (charmap_cellToChar(me, cell) == "") { return false; + } return true; } diff --git a/qcsrc/menu/xonotic/checkbox.qc b/qcsrc/menu/xonotic/checkbox.qc index 949b01c41..29f372cce 100644 --- a/qcsrc/menu/xonotic/checkbox.qc +++ b/qcsrc/menu/xonotic/checkbox.qc @@ -3,23 +3,16 @@ entity makeXonoticCheckBox_T(float isInverted, string theCvar, string theText, string theTooltip) { float m, n; - if(isInverted > 1) - { + if (isInverted > 1) { n = isInverted - 1; m = -n; - } - else if(isInverted < -1) - { + } else if (isInverted < -1) { n = isInverted + 1; m = -n; - } - else if(isInverted == 1) - { + } else if (isInverted == 1) { n = 1; m = 0; - } - else - { + } else { n = 0; m = 1; } @@ -54,20 +47,21 @@ void XonoticCheckBox_configureXonoticCheckBox(entity me, float theYesValue, floa } void XonoticCheckBox_setChecked(entity me, float val) { - if(val != me.checked) - { + if (val != me.checked) { me.checked = val; me.saveCvars(me); - if(me.linkedCheckBox) + if (me.linkedCheckBox) { me.linkedCheckBox.loadCvars(me.linkedCheckBox); + } } } void XonoticCheckBox_loadCvars(entity me) { float m, d; - if (!me.cvarName) + if (!me.cvarName) { return; + } m = (me.yesValue + me.noValue) * 0.5; d = (cvar(me.cvarName) - m) / (me.yesValue - m); @@ -75,13 +69,15 @@ void XonoticCheckBox_loadCvars(entity me) } void XonoticCheckBox_saveCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } - if(me.checked) + if (me.checked) { cvar_set(me.cvarName, ftos_mindecimals(me.yesValue)); - else + } else { cvar_set(me.cvarName, ftos_mindecimals(me.noValue)); + } CheckSendCvars(me, me.cvarName); } diff --git a/qcsrc/menu/xonotic/checkbox_slider_invalid.qc b/qcsrc/menu/xonotic/checkbox_slider_invalid.qc index 839e66b21..e564a1dbf 100644 --- a/qcsrc/menu/xonotic/checkbox_slider_invalid.qc +++ b/qcsrc/menu/xonotic/checkbox_slider_invalid.qc @@ -14,10 +14,11 @@ void XonoticSliderCheckBox_configureXonoticSliderCheckBox(entity me, float theOf me.offValue = theOffValue; me.inverted = isInverted; me.checked = (theControlledSlider.value == theOffValue); - if(theControlledSlider.value == median(theControlledSlider.valueMin, theControlledSlider.value, theControlledSlider.valueMax)) + if (theControlledSlider.value == median(theControlledSlider.valueMin, theControlledSlider.value, theControlledSlider.valueMax)) { me.savedValue = theControlledSlider.value; - else + } else { me.savedValue = theControlledSlider.valueMin; + } me.controlledSlider = theControlledSlider; me.configureCheckBox(me, theText, me.fontSize, me.image); me.cvarName = theControlledSlider.cvarName; // in case we want to display the cvar in the tooltip @@ -26,17 +27,20 @@ void XonoticSliderCheckBox_configureXonoticSliderCheckBox(entity me, float theOf void XonoticSliderCheckBox_draw(entity me) { me.checked = ((me.controlledSlider.value == me.offValue) != me.inverted); - if(me.controlledSlider.value == median(me.controlledSlider.valueMin, me.controlledSlider.value, me.controlledSlider.valueMax)) + if (me.controlledSlider.value == median(me.controlledSlider.valueMin, me.controlledSlider.value, me.controlledSlider.valueMax)) { me.savedValue = me.controlledSlider.value; + } SUPER(XonoticSliderCheckBox).draw(me); } void XonoticSliderCheckBox_setChecked(entity me, float val) { - if(me.checked == val) + if (me.checked == val) { return; + } me.checked = val; - if(val == me.inverted) + if (val == me.inverted) { me.controlledSlider.setValue(me.controlledSlider, median(me.controlledSlider.valueMin, me.savedValue, me.controlledSlider.valueMax)); - else + } else { me.controlledSlider.setValue(me.controlledSlider, me.offValue); + } } diff --git a/qcsrc/menu/xonotic/checkbox_string.qc b/qcsrc/menu/xonotic/checkbox_string.qc index 99db16e35..aaace6ee1 100644 --- a/qcsrc/menu/xonotic/checkbox_string.qc +++ b/qcsrc/menu/xonotic/checkbox_string.qc @@ -23,21 +23,25 @@ void XonoticCheckBoxString_setChecked(entity me, float foo) } void XonoticCheckBoxString_loadCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } - if(cvar_string(me.cvarName) == me.yesString) + if (cvar_string(me.cvarName) == me.yesString) { me.checked = 1; + } } void XonoticCheckBoxString_saveCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } - if(me.checked) + if (me.checked) { cvar_set(me.cvarName, me.yesString); - else + } else { cvar_set(me.cvarName, me.noString); + } CheckSendCvars(me, me.cvarName); } diff --git a/qcsrc/menu/xonotic/colorbutton.qc b/qcsrc/menu/xonotic/colorbutton.qc index 6675c1aee..9410b5b26 100644 --- a/qcsrc/menu/xonotic/colorbutton.qc +++ b/qcsrc/menu/xonotic/colorbutton.qc @@ -9,23 +9,36 @@ entity makeXonoticColorButton(float theGroup, float theColor, float theValue) } void XonoticColorButton_configureXonoticColorButton(entity me, float theGroup, float theColor, float theValue) { - switch(theValue) - { + switch (theValue) { // rearrange 1..14 for rainbow order - case 1: theValue = 10; break; - case 2: theValue = 4; break; - case 3: theValue = 1; break; - case 4: theValue = 14; break; - case 5: theValue = 12; break; - case 6: theValue = 7; break; - case 7: theValue = 3; break; - case 8: theValue = 2; break; - case 9: theValue = 6; break; - case 10: theValue = 5; break; - case 11: theValue = 13; break; - case 12: theValue = 11; break; - case 13: theValue = 8; break; - case 14: theValue = 9; break; + case 1: theValue = 10; + break; + case 2: theValue = 4; + break; + case 3: theValue = 1; + break; + case 4: theValue = 14; + break; + case 5: theValue = 12; + break; + case 6: theValue = 7; + break; + case 7: theValue = 3; + break; + case 8: theValue = 2; + break; + case 9: theValue = 6; + break; + case 10: theValue = 5; + break; + case 11: theValue = 13; + break; + case 12: theValue = 11; + break; + case 13: theValue = 8; + break; + case 14: theValue = 9; + break; default: // no change break; @@ -38,36 +51,39 @@ void XonoticColorButton_configureXonoticColorButton(entity me, float theGroup, f } void XonoticColorButton_setChecked(entity me, float val) { - if(val != me.checked) - { + if (val != me.checked) { me.checked = val; me.saveCvars(me); } } void XonoticColorButton_loadCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } - if(cvar_string(me.cvarName) == cvar_defstring(me.cvarName)) + if (cvar_string(me.cvarName) == cvar_defstring(me.cvarName)) { cvar_set(me.cvarName, ftos(16 * floor(random() * 15) + floor(random() * 15))); + } - if(me.cvarPart == 1) + if (me.cvarPart == 1) { me.checked = (cvar(me.cvarName) & 240) == me.cvarValueFloat * 16; - else + } else { me.checked = (cvar(me.cvarName) & 15) == me.cvarValueFloat; + } } void XonoticColorButton_saveCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } - if(me.checked) - { - if(me.cvarPart == 1) + if (me.checked) { + if (me.cvarPart == 1) { cvar_set(me.cvarName, ftos((cvar(me.cvarName) & 15) + me.cvarValueFloat * 16)); - else + } else { cvar_set(me.cvarName, ftos((cvar(me.cvarName) & 240) + me.cvarValueFloat)); + } } // TODO on an apply button, read _cl_color and execute the color command for it } diff --git a/qcsrc/menu/xonotic/commandbutton.qc b/qcsrc/menu/xonotic/commandbutton.qc index 8e691a036..e978ddc26 100644 --- a/qcsrc/menu/xonotic/commandbutton.qc +++ b/qcsrc/menu/xonotic/commandbutton.qc @@ -14,13 +14,14 @@ entity makeXonoticCommandButton(string theText, vector theColor, string theComma void XonoticCommandButton_Click(entity me, entity other) { - //if(me.flags & COMMANDBUTTON_APPLY) + // if(me.flags & COMMANDBUTTON_APPLY) // saveAllCvars(me.parent); cmd("\n", me.onClickCommand, "\n"); - //if(me.flags & COMMANDBUTTON_REVERT) + // if(me.flags & COMMANDBUTTON_REVERT) // loadAllCvars(me.parent); - if(me.flags & COMMANDBUTTON_CLOSE) + if (me.flags & COMMANDBUTTON_CLOSE) { m_goto(string_null); + } } void XonoticCommandButton_configureXonoticCommandButton(entity me, string theText, vector theColor, string theCommand, float theFlags, string theTooltip) diff --git a/qcsrc/menu/xonotic/commandbutton.qh b/qcsrc/menu/xonotic/commandbutton.qh index 5de59ee07..4a019c6e4 100644 --- a/qcsrc/menu/xonotic/commandbutton.qh +++ b/qcsrc/menu/xonotic/commandbutton.qh @@ -11,7 +11,7 @@ entity makeXonoticCommandButton_T(string theText, vector theColor, string theCom entity makeXonoticCommandButton(string theText, vector theColor, string theCommand, float closesMenu); #ifndef COMMANDBUTTON_CLOSE -# define COMMANDBUTTON_CLOSE 1 -# define COMMANDBUTTON_APPLY 2 -//# define COMMANDBUTTON_REVERT 4 +#define COMMANDBUTTON_CLOSE 1 +#define COMMANDBUTTON_APPLY 2 +// # define COMMANDBUTTON_REVERT 4 #endif diff --git a/qcsrc/menu/xonotic/credits.qc b/qcsrc/menu/xonotic/credits.qc index 6debcb713..0b80f0ff7 100644 --- a/qcsrc/menu/xonotic/credits.qc +++ b/qcsrc/menu/xonotic/credits.qc @@ -2,402 +2,402 @@ #define CREDITS(TITLE, FUNCTION, PERSON, PERSON_, NL) \ TITLE(_("Core Team")) \ - PERSON(Rudolf "divVerent" Polzer) \ - PERSON(Ant "Antibody" Zucaro) \ - PERSON(Marvin "Mirio" Beck) \ - PERSON(Merlijn Hofstra) \ - PERSON(Peter "Morphed" Pielak) \ - PERSON(Ruszkai "CuBe0wL" Ákos) \ - PERSON(Samual "Ares" Lenks) \ - PERSON(TimePath) \ - PERSON(Tyler "-z-" Mulligan) \ - PERSON(Zac "Mario" Jardine) \ + PERSON(Rudolf "divVerent" Polzer) \ + PERSON(Ant "Antibody" Zucaro) \ + PERSON(Marvin "Mirio" Beck) \ + PERSON(Merlijn Hofstra) \ + PERSON(Peter "Morphed" Pielak) \ + PERSON(Ruszkai "CuBe0wL" Ákos) \ + PERSON(Samual "Ares" Lenks) \ + PERSON(TimePath) \ + PERSON(Tyler "-z-" Mulligan) \ + PERSON(Zac "Mario" Jardine) \ NL() \ TITLE(_("Extended Team")) \ - PERSON(AllieWay) \ - PERSON(Antonio "terencehill" Piu) \ - PERSON(Archer) \ - PERSON(BuddyFriendGuy) \ - PERSON(Debugger) \ - PERSON(Diomedes) \ - PERSON(Freddy) \ - PERSON(GATTS) \ - PERSON(Halogene) \ - PERSON(IDWMaster) \ - PERSON(Jan "zykure" Behrens) \ - PERSON(JH0nny) \ - PERSON(Jubilant) \ - PERSON(Łukasz "kuniu the frogg" Polek) \ - PERSON(martin-t) \ - PERSON(Matthias "matthiaskrgr" Krüger) \ - PERSON(Mattia "Melanosuchus" Basaglia) \ - PERSON(MrBougo) \ - PERSON(Nick "bitbomb" Lucca) \ - PERSON(nilyt/nyov) \ - PERSON(Nitroxis) \ - PERSON(packer) \ - PERSON(Pearce "theShadow" Michal) \ - PERSON(Rasmus "FruitieX" Eskola) \ - PERSON(s1lence) \ - PERSON(Severin "sev" Meyer) \ - PERSON(Soelen) \ - PERSON(Sydes) \ - PERSON(unfa) \ + PERSON(AllieWay) \ + PERSON(Antonio "terencehill" Piu) \ + PERSON(Archer) \ + PERSON(BuddyFriendGuy) \ + PERSON(Debugger) \ + PERSON(Diomedes) \ + PERSON(Freddy) \ + PERSON(GATTS) \ + PERSON(Halogene) \ + PERSON(IDWMaster) \ + PERSON(Jan "zykure" Behrens) \ + PERSON(JH0nny) \ + PERSON(Jubilant) \ + PERSON(Łukasz "kuniu the frogg" Polek) \ + PERSON(martin - t) \ + PERSON(Matthias "matthiaskrgr" Krüger) \ + PERSON(Mattia "Melanosuchus" Basaglia) \ + PERSON(MrBougo) \ + PERSON(Nick "bitbomb" Lucca) \ + PERSON(nilyt / nyov) \ + PERSON(Nitroxis) \ + PERSON(packer) \ + PERSON(Pearce "theShadow" Michal) \ + PERSON(Rasmus "FruitieX" Eskola) \ + PERSON(s1lence) \ + PERSON(Severin "sev" Meyer) \ + PERSON(Soelen) \ + PERSON(Sydes) \ + PERSON(unfa) \ NL() \ NL() \ FUNCTION(_("Website")) \ - PERSON(Ant "Antibody" Zucaro (web)) \ - PERSON(Merlijn Hofstra) \ - PERSON(Tyler "-z-" Mulligan (web / game)) \ + PERSON(Ant "Antibody" Zucaro(web)) \ + PERSON(Merlijn Hofstra) \ + PERSON(Tyler "-z-" Mulligan(web / game)) \ NL() \ FUNCTION(_("Stats")) \ - PERSON(Ant "Antibody" Zucaro) \ - PERSON(Jan "zykure" Behrens) \ + PERSON(Ant "Antibody" Zucaro) \ + PERSON(Jan "zykure" Behrens) \ NL() \ FUNCTION(_("Art")) \ - PERSON(Severin "sev" Meyer) \ - PERSON(Sahil "DiaboliK" Singhal) \ - PERSON(Peter "Morphed" Pielak) \ - PERSON(Sam "LJFHutch" Hutchinson) \ - PERSON(Pearce "theShadow" Michal) \ - PERSON(KingPimpCommander) \ + PERSON(Severin "sev" Meyer) \ + PERSON(Sahil "DiaboliK" Singhal) \ + PERSON(Peter "Morphed" Pielak) \ + PERSON(Sam "LJFHutch" Hutchinson) \ + PERSON(Pearce "theShadow" Michal) \ + PERSON(KingPimpCommander) \ NL() \ FUNCTION(_("Animation")) \ - PERSON(Sahil "DiaboliK" Singhal) \ - PERSON(nifrek) \ + PERSON(Sahil "DiaboliK" Singhal) \ + PERSON(nifrek) \ NL() \ FUNCTION(_("Level Design")) \ - PERSON(Amadeusz "amade/proraide" Sławiński) \ - PERSON(Ben "MooKow" Banker) \ - PERSON(Cortez) \ - PERSON(Cuinn "Cuinnton" Herrick) \ - PERSON(Debugger) \ - PERSON(Hugo "Calinou" Locurcio) \ - PERSON(Jakob "tZork" Markström Gröhn) \ - PERSON(Konrad "Justin" Slawinski) \ - PERSON(Maddin) \ - PERSON(L0) \ - PERSON(Łukasz "kuniu the frogg" Polek) \ - PERSON(Maik "SavageX" Merten) \ - PERSON(Marvin "Mirio" Beck) \ - PERSON(MintOX) \ - PERSON(packer) \ - PERSON(Pearce "theShadow" Michal) \ - PERSON(Rasmus "FruitieX" Eskola) \ - PERSON(Ruszkai "CuBe0wL" Ákos) \ - PERSON(Severin "sev" Meyer) \ - PERSON(ShadoW) \ - PERSON(t0uYK8Ne) \ + PERSON(Amadeusz "amade/proraide" Sławiński) \ + PERSON(Ben "MooKow" Banker) \ + PERSON(Cortez) \ + PERSON(Cuinn "Cuinnton" Herrick) \ + PERSON(Debugger) \ + PERSON(Hugo "Calinou" Locurcio) \ + PERSON(Jakob "tZork" Markström Gröhn) \ + PERSON(Konrad "Justin" Slawinski) \ + PERSON(Maddin) \ + PERSON(L0) \ + PERSON(Łukasz "kuniu the frogg" Polek) \ + PERSON(Maik "SavageX" Merten) \ + PERSON(Marvin "Mirio" Beck) \ + PERSON(MintOX) \ + PERSON(packer) \ + PERSON(Pearce "theShadow" Michal) \ + PERSON(Rasmus "FruitieX" Eskola) \ + PERSON(Ruszkai "CuBe0wL" Ákos) \ + PERSON(Severin "sev" Meyer) \ + PERSON(ShadoW) \ + PERSON(t0uYK8Ne) \ NL() \ FUNCTION(_("Music / Sound FX")) \ - PERSON(AquaNova (Archer)) \ - PERSON(blkrbt) \ - PERSON(chooksta) \ - PERSON(Independent.nu) \ - PERSON(Lea "TheAudioMonkey" Edwards) \ - PERSON([master]mind) \ - PERSON(Merlijn Hofstra) \ - PERSON(Mick Rippon) \ - PERSON(Nick "bitbomb" Lucca) \ - PERSON(remaxim) \ - PERSON(Saulo "mand1nga" Gil) \ - PERSON({SC0RP} - Ian "ID" Dorrell) \ - PERSON(Stephan) \ - PERSON(unfa) \ + PERSON(AquaNova(Archer)) \ + PERSON(blkrbt) \ + PERSON(chooksta) \ + PERSON(Independent.nu) \ + PERSON(Lea "TheAudioMonkey" Edwards) \ + PERSON([master] mind) \ + PERSON(Merlijn Hofstra) \ + PERSON(Mick Rippon) \ + PERSON(Nick "bitbomb" Lucca) \ + PERSON(remaxim) \ + PERSON(Saulo "mand1nga" Gil) \ + PERSON({ SC0RP } -Ian "ID" Dorrell) \ + PERSON(Stephan) \ + PERSON(unfa) \ NL() \ FUNCTION(_("Game Code")) \ - PERSON(Samual "Ares" Lenks) \ - PERSON(Rudolf "divVerent" Polzer) \ - PERSON(Jakob "tZork" Markström Gröhn) \ - PERSON(Rasmus "FruitieX" Eskola) \ - PERSON(TimePath) \ - PERSON(Zac "Mario" Jardine) \ + PERSON(Samual "Ares" Lenks) \ + PERSON(Rudolf "divVerent" Polzer) \ + PERSON(Jakob "tZork" Markström Gröhn) \ + PERSON(Rasmus "FruitieX" Eskola) \ + PERSON(TimePath) \ + PERSON(Zac "Mario" Jardine) \ NL() \ FUNCTION(_("Marketing / PR")) \ - PERSON(Tyler "-z-" Mulligan) \ - PERSON(Ruszkai "CuBe0wL" Ákos) \ - PERSON(Samual "Ares" Lenks) \ - PERSON(Saulo "mand1nga" Gil) \ + PERSON(Tyler "-z-" Mulligan) \ + PERSON(Ruszkai "CuBe0wL" Ákos) \ + PERSON(Samual "Ares" Lenks) \ + PERSON(Saulo "mand1nga" Gil) \ NL() \ FUNCTION(_("Legal")) \ - PERSON(Rudolf "divVerent" Polzer) \ - PERSON(Merlijn Hofstra) \ + PERSON(Rudolf "divVerent" Polzer) \ + PERSON(Merlijn Hofstra) \ NL() \ NL() \ TITLE(_("Game Engine")) \ - FUNCTION("DarkPlaces") \ - PERSON(Forest "LordHavoc" Hale) \ - NL() \ - FUNCTION(_("Engine Additions")) \ - PERSON(Rudolf "divVerent" Polzer) \ - PERSON(Samual "Ares" Lenks) \ - NL() \ + FUNCTION("DarkPlaces") \ + PERSON(Forest "LordHavoc" Hale) \ + NL() \ + FUNCTION(_("Engine Additions")) \ + PERSON(Rudolf "divVerent" Polzer) \ + PERSON(Samual "Ares" Lenks) \ + NL() \ NL() \ TITLE(_("Compiler")) \ - FUNCTION("GMQCC") \ - PERSON(Wolfgang "Blub\0" Bumiller) \ - PERSON(Dale "graphitemaster" Weiler) \ - NL() \ + FUNCTION("GMQCC") \ + PERSON(Wolfgang "Blub\0" Bumiller) \ + PERSON(Dale "graphitemaster" Weiler) \ + NL() \ NL() \ TITLE(_("Other Active Contributors")) \ - PERSON(Jeff) \ - PERSON(Lyberta) \ - PERSON(Mircea "Taoki" Kitsune) \ - PERSON(Penguinum) \ + PERSON(Jeff) \ + PERSON(Lyberta) \ + PERSON(Mircea "Taoki" Kitsune) \ + PERSON(Penguinum) \ NL() \ NL() \ TITLE(_("Translators")) \ - NL() \ - FUNCTION(_("Asturian")) \ - PERSON(Llumex03) \ - PERSON(Tornes "Tornes.Llume" Ḷḷume) \ - PERSON(Ximielga) \ - NL() \ - FUNCTION(_("Belarusian")) \ - PERSON(Mihail "meequz" Varantsou) \ - NL() \ - FUNCTION(_("Bulgarian")) \ - PERSON(Alexander "alex4o" Bonin) \ - PERSON(ifohancroft) \ - PERSON(lokster) \ - PERSON(set_killer) \ - PERSON(ubone) \ - NL() \ - FUNCTION(_("Chinese (China)")) \ - PERSON(Antonidas) \ - PERSON(Armcoon) \ - PERSON(kalawore) \ - PERSON(sapphireliu) \ - NL() \ - FUNCTION(_("Chinese (Taiwan)")) \ - PERSON(Alisha) \ - PERSON(Armcoon) \ - PERSON(Jeff "s8321414" Huang) \ - NL() \ - FUNCTION(_("Cornish")) \ - PERSON(Nicky "nrowe" Rowe) \ - NL() \ - FUNCTION(_("Czech")) \ - PERSON(shogun assassin/woky) \ - PERSON(Superovoce) \ - PERSON(Tomáš "CZHeron" Volavka) \ - NL() \ - FUNCTION(_("Dutch")) \ - PERSON(Alexander "freefang" van Dam) \ - PERSON(Joeke "Mappack" de Graaf) \ - PERSON(Jonathan "Jonakeys" van der Steege) \ - PERSON(PinkRobot) \ - PERSON(vegiburger) \ - NL() \ - FUNCTION(_("English (Australia)")) \ - PERSON(Laurene "sunflowers" Albrand) \ - PERSON(Stuart "Cefiar" Young) \ - PERSON(Zac "Mario" Jardine) \ - NL() \ - FUNCTION(_("Finnish")) \ - PERSON(Jonas "PowaTree" Sahlberg) \ - PERSON(Henry "Exitium" Sanmark) \ - PERSON(Rasmus "FruitieX" Eskola) \ - NL() \ - FUNCTION(_("French")) \ - PERSON(Hugo "Calinou" Locurcio) \ - PERSON(Kim "coughingmouse" Lee) \ - PERSON(Maxime "Taximus" Paradis) \ - PERSON(RedGuff) \ - PERSON(Thomas "illwieckz" Debesse) \ - PERSON(Yannick "SpiKe" Le Guen) \ - NL() \ - FUNCTION(_("German")) \ - PERSON(Brot) \ - PERSON(cvcxc) \ - PERSON(Erik "Ablu" Schilling) \ - PERSON(Jope "Sless" Withers) \ - PERSON(Marvin "Mirio" Beck) \ - PERSON(Paul "Snapper") \ - PERSON(Rudolf "divVerent" Polzer) \ - PERSON(Wuzzy) \ - PERSON(Yepoleb) \ - NL() \ - FUNCTION(_("Greek")) \ - PERSON_("Γιάννης \"Evropi\" Ανθυμίδης") \ - PERSON(Konstantinos "LDinos" Mihalenas) \ - PERSON(Savoritias) \ - PERSON(Vindex) \ - NL() \ - FUNCTION(_("Hungarian")) \ - PERSON(Ruszkai "CuBe0wL" Ákos) \ - PERSON(xaN1C4n3) \ - NL() \ - FUNCTION(_("Irish")) \ - PERSON(Kevin "kscanne" Scannell) \ - NL() \ - FUNCTION(_("Italian")) \ - PERSON(Antonio "terencehill" Piu) \ - PERSON(Felice "MaidenBeast" Sallustio) \ - PERSON(stdi) \ - PERSON(XCostaX) \ - NL() \ - FUNCTION(_("Kazakh")) \ - PERSON("Артем "bystrov.arterm" Быстров") \ - NL() \ - FUNCTION(_("Korean")) \ - PERSON(Jisoo "s6e9x" Lim) \ - PERSON(Kim "coughingmouse" Lee) \ - NL() \ - FUNCTION(_("Polish")) \ - PERSON(4m) \ - PERSON(Alex "tiprogrammierer.alex" Progger) \ - PERSON(Amadeusz "amade/proraide" Sławiński) \ - PERSON(Artur "artur9010" Motyka) \ - PERSON(Jakub "KubeQ11" Pędziszewski) \ - PERSON(Kriss7475) \ - NL() \ - FUNCTION(_("Portuguese")) \ - PERSON(Ivan Paulos "greylica" Tomé) \ - PERSON(Jean Trindade "Muleke_Trairao" Pereira) \ - PERSON(Ricardo Manuel "Hellgardia" da Cruz Coelho da Silva) \ - PERSON(xXxCHAOTICxXx) \ - NL() \ - FUNCTION(_("Romanian")) \ - PERSON(Adrian-Ciprian "adrian.tinjala" Tînjală) \ - PERSON(BusterDBK) \ - PERSON(Mircea "Taoki" Kitsune) \ - PERSON(Sorin "unic_sorin" Botirla) \ - PERSON(Tudor "TropiKo" Ionel) \ - NL() \ - FUNCTION(_("Russian")) \ - PERSON(Alex "alextalker7" Talker) \ - PERSON(Alexandr "zrg") \ - PERSON(Andrei "adem4ik" Stepanov) \ - PERSON(Andrey "dekrY" P.) \ - PERSON(gravicappa) \ - PERSON(Hot Dog) \ - PERSON(Lord Canistra) \ - PERSON(Nikoli) \ - PERSON(Sergej "Clearness High" Lutsyk) \ - NL() \ - FUNCTION(_("Scottish Gaelic")) \ - PERSON_("GunChleoc") \ - NL() \ - FUNCTION(_("Serbian")) \ - PERSON_("Саша \"salepetronije\" Петровић") \ - PERSON(Marko M. Kostić) \ - PERSON(Pendulla) \ - PERSON(Rafael "Ristovski") \ - NL() \ - FUNCTION(_("Spanish")) \ - PERSON_("0000simon") \ - PERSON(Alan "aagp" Garcia) \ - PERSON(Ari_tent) \ - PERSON(brunodeleo) \ - PERSON(Kammy) \ - PERSON(roader_gentoo) \ - PERSON(Rodrigo Mouton Laudin) \ - PERSON(SouL) \ - PERSON(Starfire24680) \ - NL() \ - FUNCTION(_("Swedish")) \ - PERSON(Karl-Oskar "machine" Rikås) \ - PERSON(marcus256) \ - NL() \ - FUNCTION(_("Ukrainian")) \ - PERSON(Dmitro "Gamebot" Sokhin) \ - PERSON(Oleh "BlaXpirit" Prypin) \ - PERSON(Vasyl "Harmata" Melnyk) \ - PERSON(Yuriy "herrniemand" Ackermann) \ - NL() \ + NL() \ + FUNCTION(_("Asturian")) \ + PERSON(Llumex03) \ + PERSON(Tornes "Tornes.Llume" Ḷḷume) \ + PERSON(Ximielga) \ + NL() \ + FUNCTION(_("Belarusian")) \ + PERSON(Mihail "meequz" Varantsou) \ + NL() \ + FUNCTION(_("Bulgarian")) \ + PERSON(Alexander "alex4o" Bonin) \ + PERSON(ifohancroft) \ + PERSON(lokster) \ + PERSON(set_killer) \ + PERSON(ubone) \ + NL() \ + FUNCTION(_("Chinese (China)")) \ + PERSON(Antonidas) \ + PERSON(Armcoon) \ + PERSON(kalawore) \ + PERSON(sapphireliu) \ + NL() \ + FUNCTION(_("Chinese (Taiwan)")) \ + PERSON(Alisha) \ + PERSON(Armcoon) \ + PERSON(Jeff "s8321414" Huang) \ + NL() \ + FUNCTION(_("Cornish")) \ + PERSON(Nicky "nrowe" Rowe) \ + NL() \ + FUNCTION(_("Czech")) \ + PERSON(shogun assassin / woky) \ + PERSON(Superovoce) \ + PERSON(Tomáš "CZHeron" Volavka) \ + NL() \ + FUNCTION(_("Dutch")) \ + PERSON(Alexander "freefang" van Dam) \ + PERSON(Joeke "Mappack" de Graaf) \ + PERSON(Jonathan "Jonakeys" van der Steege) \ + PERSON(PinkRobot) \ + PERSON(vegiburger) \ + NL() \ + FUNCTION(_("English (Australia)")) \ + PERSON(Laurene "sunflowers" Albrand) \ + PERSON(Stuart "Cefiar" Young) \ + PERSON(Zac "Mario" Jardine) \ + NL() \ + FUNCTION(_("Finnish")) \ + PERSON(Jonas "PowaTree" Sahlberg) \ + PERSON(Henry "Exitium" Sanmark) \ + PERSON(Rasmus "FruitieX" Eskola) \ + NL() \ + FUNCTION(_("French")) \ + PERSON(Hugo "Calinou" Locurcio) \ + PERSON(Kim "coughingmouse" Lee) \ + PERSON(Maxime "Taximus" Paradis) \ + PERSON(RedGuff) \ + PERSON(Thomas "illwieckz" Debesse) \ + PERSON(Yannick "SpiKe" Le Guen) \ + NL() \ + FUNCTION(_("German")) \ + PERSON(Brot) \ + PERSON(cvcxc) \ + PERSON(Erik "Ablu" Schilling) \ + PERSON(Jope "Sless" Withers) \ + PERSON(Marvin "Mirio" Beck) \ + PERSON(Paul "Snapper") \ + PERSON(Rudolf "divVerent" Polzer) \ + PERSON(Wuzzy) \ + PERSON(Yepoleb) \ + NL() \ + FUNCTION(_("Greek")) \ + PERSON_("Γιάννης \"Evropi\" Ανθυμίδης") \ + PERSON(Konstantinos "LDinos" Mihalenas) \ + PERSON(Savoritias) \ + PERSON(Vindex) \ + NL() \ + FUNCTION(_("Hungarian")) \ + PERSON(Ruszkai "CuBe0wL" Ákos) \ + PERSON(xaN1C4n3) \ + NL() \ + FUNCTION(_("Irish")) \ + PERSON(Kevin "kscanne" Scannell) \ + NL() \ + FUNCTION(_("Italian")) \ + PERSON(Antonio "terencehill" Piu) \ + PERSON(Felice "MaidenBeast" Sallustio) \ + PERSON(stdi) \ + PERSON(XCostaX) \ + NL() \ + FUNCTION(_("Kazakh")) \ + PERSON("Артем "bystrov.arterm " Быстров") \ + NL() \ + FUNCTION(_("Korean")) \ + PERSON(Jisoo "s6e9x" Lim) \ + PERSON(Kim "coughingmouse" Lee) \ + NL() \ + FUNCTION(_("Polish")) \ + PERSON(4m) \ + PERSON(Alex "tiprogrammierer.alex" Progger) \ + PERSON(Amadeusz "amade/proraide" Sławiński) \ + PERSON(Artur "artur9010" Motyka) \ + PERSON(Jakub "KubeQ11" Pędziszewski) \ + PERSON(Kriss7475) \ + NL() \ + FUNCTION(_("Portuguese")) \ + PERSON(Ivan Paulos "greylica" Tomé) \ + PERSON(Jean Trindade "Muleke_Trairao" Pereira) \ + PERSON(Ricardo Manuel "Hellgardia" da Cruz Coelho da Silva) \ + PERSON(xXxCHAOTICxXx) \ + NL() \ + FUNCTION(_("Romanian")) \ + PERSON(Adrian - Ciprian "adrian.tinjala" Tînjală) \ + PERSON(BusterDBK) \ + PERSON(Mircea "Taoki" Kitsune) \ + PERSON(Sorin "unic_sorin" Botirla) \ + PERSON(Tudor "TropiKo" Ionel) \ + NL() \ + FUNCTION(_("Russian")) \ + PERSON(Alex "alextalker7" Talker) \ + PERSON(Alexandr "zrg") \ + PERSON(Andrei "adem4ik" Stepanov) \ + PERSON(Andrey "dekrY" P.) \ + PERSON(gravicappa) \ + PERSON(Hot Dog) \ + PERSON(Lord Canistra) \ + PERSON(Nikoli) \ + PERSON(Sergej "Clearness High" Lutsyk) \ + NL() \ + FUNCTION(_("Scottish Gaelic")) \ + PERSON_("GunChleoc") \ + NL() \ + FUNCTION(_("Serbian")) \ + PERSON_("Саша \"salepetronije\" Петровић") \ + PERSON(Marko M.Kostić) \ + PERSON(Pendulla) \ + PERSON(Rafael "Ristovski") \ + NL() \ + FUNCTION(_("Spanish")) \ + PERSON_("0000simon") \ + PERSON(Alan "aagp" Garcia) \ + PERSON(Ari_tent) \ + PERSON(brunodeleo) \ + PERSON(Kammy) \ + PERSON(roader_gentoo) \ + PERSON(Rodrigo Mouton Laudin) \ + PERSON(SouL) \ + PERSON(Starfire24680) \ + NL() \ + FUNCTION(_("Swedish")) \ + PERSON(Karl - Oskar "machine" Rikås) \ + PERSON(marcus256) \ + NL() \ + FUNCTION(_("Ukrainian")) \ + PERSON(Dmitro "Gamebot" Sokhin) \ + PERSON(Oleh "BlaXpirit" Prypin) \ + PERSON(Vasyl "Harmata" Melnyk) \ + PERSON(Yuriy "herrniemand" Ackermann) \ + NL() \ NL() \ TITLE(_("Past Contributors")) \ - PERSON(Akari) \ - PERSON(Alexander "naryl" Suhoverhov) \ - PERSON(Alexander "motorsep" Zubov) \ - PERSON(Amos "torus" Dudley) \ - PERSON(Andreas "Black" Kirsch) \ - PERSON(Attila "WW3" Houtkooper) \ - PERSON(BigMac) \ - PERSON(Braden "meoblast001" Walters) \ - PERSON(Brain Younds) \ - PERSON(Chris "amethyst7" Matz) \ - PERSON(Christian Ice) \ - PERSON(Clinton "Kaziganthe" Freeman) \ - PERSON(Dan "Digger" Korostelev) \ - PERSON(Dan "Wazat" Hale) \ - PERSON(Dokujisan) \ - PERSON(Donkey) \ - PERSON(dstrek) \ - PERSON(Dustin Geeraert) \ - PERSON(Edgenetwork) \ - PERSON(Edward "Ed" Holness) \ - PERSON(Eric "Munyul Verminard" Sambach) \ - PERSON(Erik "Ablu" Schilling) \ - PERSON(Fabien "H. Reaper" Tschirhart) \ - PERSON(Florian Paul "lda17h" Schmidt) \ - PERSON(FrikaC) \ - PERSON(Garth "Zombie" Hendy) \ - PERSON(Gerd "Elysis" Raudenbusch) \ - PERSON(Gottfried "Toddd" Hofmann) \ - PERSON(Henning "Tymo" Janssen) \ - PERSON(Innovati) \ - PERSON(Jitspoe) \ - PERSON(Jody Gallagher) \ - PERSON(Jope "Sless" Withers) \ - PERSON(Juergen "LowDragon" Timm) \ - PERSON(KadaverJack) \ - PERSON(Kevin "Tyrann" Shanahan) \ - PERSON(Kristian "morfar" Johansson) \ - PERSON(Kurt Dereli) \ - PERSON(lcatlnx) \ - PERSON(Lee David Ash) \ - PERSON(Lee Vermeulen) \ - PERSON(leileilol) \ - PERSON(magorian) \ - PERSON(Marius "GreEn`mArine" Shekow) \ - PERSON(Marko "Urre" Permanto) \ - PERSON(Mathieu "Elric" Olivier) \ - PERSON(Mattrew "Tronyn" Rye) \ - PERSON(MauveBib) \ - PERSON(Mephisto) \ - PERSON(michaelb) \ - PERSON(Michael "Tenshihan" Quinn) \ - PERSON(Mepper) \ - PERSON(Munyul) \ - PERSON(Netzwerg) \ - PERSON(NoelCower) \ - PERSON(Parapraxis) \ - PERSON(parasti) \ - PERSON(Paul "Strahlemann" Evers) \ - PERSON(Paul Scott) \ - PERSON(Petithomme) \ - PERSON(PlasmaSheep) \ - PERSON(Przemysław "atheros" Grzywacz) \ - PERSON(Q1 Retexturing Project) \ - PERSON(Qantourisc) \ - PERSON(Oleh "BlaXpirit" Prypin) \ - PERSON(Rick "Rat" Kelley) \ - PERSON(Robert "ai" Kuroto) \ - PERSON(Ronan) \ - PERSON(Sajt) \ - PERSON(Saulo "mand1nga" Gil) \ - PERSON(Shaggy) \ - PERSON(Shank) \ - PERSON(Simon O’Callaghan) \ - PERSON(SomeGuy) \ - PERSON(SoulKeeper_p) \ - PERSON(Spike) \ - PERSON(Spirit) \ - PERSON(Stephan "esteel" Stahl) \ - PERSON(Steve Vermeulen) \ - PERSON(Supajoe) \ - PERSON(Tei) \ - PERSON(The player with the unnecessarily long name) \ - PERSON(Tomaz) \ - PERSON(Ulrich Galbraith) \ - PERSON(Vortex) \ - PERSON(William Libert) \ - PERSON(William "Willis" Weilep) \ - PERSON(Yves "EviLair" Allaire) \ - PERSON(Zenex) \ - /**/ + PERSON(Akari) \ + PERSON(Alexander "naryl" Suhoverhov) \ + PERSON(Alexander "motorsep" Zubov) \ + PERSON(Amos "torus" Dudley) \ + PERSON(Andreas "Black" Kirsch) \ + PERSON(Attila "WW3" Houtkooper) \ + PERSON(BigMac) \ + PERSON(Braden "meoblast001" Walters) \ + PERSON(Brain Younds) \ + PERSON(Chris "amethyst7" Matz) \ + PERSON(Christian Ice) \ + PERSON(Clinton "Kaziganthe" Freeman) \ + PERSON(Dan "Digger" Korostelev) \ + PERSON(Dan "Wazat" Hale) \ + PERSON(Dokujisan) \ + PERSON(Donkey) \ + PERSON(dstrek) \ + PERSON(Dustin Geeraert) \ + PERSON(Edgenetwork) \ + PERSON(Edward "Ed" Holness) \ + PERSON(Eric "Munyul Verminard" Sambach) \ + PERSON(Erik "Ablu" Schilling) \ + PERSON(Fabien "H. Reaper" Tschirhart) \ + PERSON(Florian Paul "lda17h" Schmidt) \ + PERSON(FrikaC) \ + PERSON(Garth "Zombie" Hendy) \ + PERSON(Gerd "Elysis" Raudenbusch) \ + PERSON(Gottfried "Toddd" Hofmann) \ + PERSON(Henning "Tymo" Janssen) \ + PERSON(Innovati) \ + PERSON(Jitspoe) \ + PERSON(Jody Gallagher) \ + PERSON(Jope "Sless" Withers) \ + PERSON(Juergen "LowDragon" Timm) \ + PERSON(KadaverJack) \ + PERSON(Kevin "Tyrann" Shanahan) \ + PERSON(Kristian "morfar" Johansson) \ + PERSON(Kurt Dereli) \ + PERSON(lcatlnx) \ + PERSON(Lee David Ash) \ + PERSON(Lee Vermeulen) \ + PERSON(leileilol) \ + PERSON(magorian) \ + PERSON(Marius "GreEn`mArine" Shekow) \ + PERSON(Marko "Urre" Permanto) \ + PERSON(Mathieu "Elric" Olivier) \ + PERSON(Mattrew "Tronyn" Rye) \ + PERSON(MauveBib) \ + PERSON(Mephisto) \ + PERSON(michaelb) \ + PERSON(Michael "Tenshihan" Quinn) \ + PERSON(Mepper) \ + PERSON(Munyul) \ + PERSON(Netzwerg) \ + PERSON(NoelCower) \ + PERSON(Parapraxis) \ + PERSON(parasti) \ + PERSON(Paul "Strahlemann" Evers) \ + PERSON(Paul Scott) \ + PERSON(Petithomme) \ + PERSON(PlasmaSheep) \ + PERSON(Przemysław "atheros" Grzywacz) \ + PERSON(Q1 Retexturing Project) \ + PERSON(Qantourisc) \ + PERSON(Oleh "BlaXpirit" Prypin) \ + PERSON(Rick "Rat" Kelley) \ + PERSON(Robert "ai" Kuroto) \ + PERSON(Ronan) \ + PERSON(Sajt) \ + PERSON(Saulo "mand1nga" Gil) \ + PERSON(Shaggy) \ + PERSON(Shank) \ + PERSON(Simon O’Callaghan) \ + PERSON(SomeGuy) \ + PERSON(SoulKeeper_p) \ + PERSON(Spike) \ + PERSON(Spirit) \ + PERSON(Stephan "esteel" Stahl) \ + PERSON(Steve Vermeulen) \ + PERSON(Supajoe) \ + PERSON(Tei) \ + PERSON(The player with the unnecessarily long name) \ + PERSON(Tomaz) \ + PERSON(Ulrich Galbraith) \ + PERSON(Vortex) \ + PERSON(William Libert) \ + PERSON(William "Willis" Weilep) \ + PERSON(Yves "EviLair" Allaire) \ + PERSON(Zenex) \ + /**/ int credits_get() { @@ -405,9 +405,9 @@ int credits_get() #define CREDITS_TITLE(t) bufstr_add(n, strcat("**", t), 0); #define CREDITS_FUNCTION(f) bufstr_add(n, strcat("*", f), 0); #define CREDITS_PERSON(p) bufstr_add(n, p, 0); - #define _CREDITS_PERSON(p) CREDITS_PERSON(#p) + #define _CREDITS_PERSON(p) CREDITS_PERSON( #p) #define CREDITS_NL() bufstr_add(n, "", 0); - CREDITS(CREDITS_TITLE, CREDITS_FUNCTION, _CREDITS_PERSON, CREDITS_PERSON, CREDITS_NL) + CREDITS(CREDITS_TITLE, CREDITS_FUNCTION, _CREDITS_PERSON, CREDITS_PERSON, CREDITS_NL) #undef CREDITS_TITLE #undef CREDITS_FUNCTION #undef CREDITS_PERSON @@ -428,7 +428,7 @@ entity makeXonoticCreditsList() void XonoticCreditsList_configureXonoticCreditsList(entity me) { me.configureXonoticListBox(me); - me.bufferIndex = credits_get(); + me.bufferIndex = credits_get(); me.nItems = buf_getsize(me.bufferIndex); } void XonoticCreditsList_destroy(entity me) @@ -437,8 +437,7 @@ void XonoticCreditsList_destroy(entity me) } void XonoticCreditsList_draw(entity me) { - if(me.scrolling) - { + if (me.scrolling) { me.scrollPos = bound(0, (time - me.scrolling) * me.itemHeight, me.nItems * me.itemHeight - 1); me.scrollPosTarget = me.scrollPos; } @@ -460,20 +459,15 @@ void XonoticCreditsList_drawListBoxItem(entity me, int i, vector absSize, bool i s = bufstr_get(me.bufferIndex, i); - if(substring(s, 0, 2) == "**") - { + if (substring(s, 0, 2) == "**") { s = substring(s, 2, strlen(s) - 2); theColor = SKINCOLOR_CREDITS_TITLE; theAlpha = SKINALPHA_CREDITS_TITLE; - } - else if(substring(s, 0, 1) == "*") - { + } else if (substring(s, 0, 1) == "*") { s = substring(s, 1, strlen(s) - 1); theColor = SKINCOLOR_CREDITS_FUNCTION; theAlpha = SKINALPHA_CREDITS_FUNCTION; - } - else - { + } else { theColor = SKINCOLOR_CREDITS_PERSON; theAlpha = SKINALPHA_CREDITS_PERSON; } diff --git a/qcsrc/menu/xonotic/crosshairpicker.qc b/qcsrc/menu/xonotic/crosshairpicker.qc index 318141259..00ada9922 100644 --- a/qcsrc/menu/xonotic/crosshairpicker.qc +++ b/qcsrc/menu/xonotic/crosshairpicker.qc @@ -2,16 +2,18 @@ string crosshairpicker_cellToCrosshair(entity me, vector cell) { - if(cell.x < 0 || cell.x >= me.columns || cell.y < 0 || cell.y >= me.rows) + if (cell.x < 0 || cell.x >= me.columns || cell.y < 0 || cell.y >= me.rows) { return ""; + } return ftos(31 + cell.y * me.columns + cell.x); } vector crosshairpicker_crosshairToCell(entity me, string crosshair_str) { float crosshair = stof(crosshair_str) - 31; - if(crosshair - floor(crosshair) > 0) + if (crosshair - floor(crosshair) > 0) { return '-1 -1 0'; + } return mod(crosshair, me.columns) * eX + floor(crosshair / me.columns) * eY; } @@ -37,8 +39,9 @@ void XonoticCrosshairPicker_cellSelect(entity me, vector cell) bool XonoticCrosshairPicker_cellIsValid(entity me, vector cell) { - if(crosshairpicker_cellToCrosshair(me, cell) == "") + if (crosshairpicker_cellToCrosshair(me, cell) == "") { return false; + } return true; } @@ -56,6 +59,7 @@ void XonoticCrosshairPicker_cellDraw(entity me, vector cell, vector cellPos) vector crosshairPos = cellPos + 0.5 * me.realCellSize; draw_Picture(crosshairPos - 0.5 * sz, s, sz, SKINCOLOR_CROSSHAIRPICKER_CROSSHAIR, SKINALPHA_CROSSHAIRPICKER_CROSSHAIR); - if(cvar("crosshair_dot")) + if (cvar("crosshair_dot")) { draw_Picture(crosshairPos - 0.5 * sz * cvar("crosshair_dot_size"), "/gfx/crosshairdot", sz * cvar("crosshair_dot_size"), SKINCOLOR_CROSSHAIRPICKER_CROSSHAIR, SKINALPHA_CROSSHAIRPICKER_CROSSHAIR); + } } diff --git a/qcsrc/menu/xonotic/crosshairpreview.qc b/qcsrc/menu/xonotic/crosshairpreview.qc index e11d7dcc0..e0103b977 100644 --- a/qcsrc/menu/xonotic/crosshairpreview.qc +++ b/qcsrc/menu/xonotic/crosshairpreview.qc @@ -18,15 +18,17 @@ void XonoticCrosshairPreview_draw(entity me) { float save; save = draw_alpha; - if(me.disabled) + if (me.disabled) { draw_alpha *= me.disabledAlpha; + } vector sz, rgb; float a; rgb = stov(cvar_string("crosshair_color")); a = cvar("crosshair_alpha"); - if(me.src) + if (me.src) { strunzone(me.src); + } me.src = strzone(strcat("/gfx/crosshair", cvar_string("crosshair"))); sz = draw_PictureSize(me.src); @@ -34,10 +36,10 @@ void XonoticCrosshairPreview_draw(entity me) sz = sz * cvar("crosshair_size"); draw_Picture('0.5 0.5 0' - 0.5 * sz, me.src, sz, rgb, a); - if(cvar("crosshair_dot")) - { - if(cvar("crosshair_dot_color_custom") && (cvar_string("crosshair_dot_color") != "0")) + if (cvar("crosshair_dot")) { + if (cvar("crosshair_dot_color_custom") && (cvar_string("crosshair_dot_color") != "0")) { rgb = stov(cvar_string("crosshair_dot_color")); + } draw_Picture('0.5 0.5 0' - 0.5 * sz * cvar("crosshair_dot_size"), me.src2, sz * cvar("crosshair_dot_size"), rgb, a * cvar("crosshair_dot_alpha")); } diff --git a/qcsrc/menu/xonotic/cvarlist.qc b/qcsrc/menu/xonotic/cvarlist.qc index 12bb2810b..c339b659c 100644 --- a/qcsrc/menu/xonotic/cvarlist.qc +++ b/qcsrc/menu/xonotic/cvarlist.qc @@ -20,19 +20,19 @@ void XonoticCvarList_configureXonoticCvarList(entity me) } void CvarList_Load(entity me, string filter) { - if(me.handle < 0) + if (me.handle < 0) { return; + } buf_cvarlist(me.handle, filter, "_"); me.nItems = buf_getsize(me.handle); - if(autocvar_menu_cvarlist_onlymodified) - { + if (autocvar_menu_cvarlist_onlymodified) { float newbuf = buf_create(); - for (int i = 0; i < me.nItems; ++i) - { + for (int i = 0; i < me.nItems; ++i) { string k = bufstr_get(me.handle, i); - if(cvar_string(k) != cvar_defstring(k)) + if (cvar_string(k) != cvar_defstring(k)) { bufstr_add(newbuf, k, false); + } } buf_del(me.handle); me.handle = newbuf; @@ -42,23 +42,27 @@ void CvarList_Load(entity me, string filter) void XonoticCvarList_showNotify(entity me) { bool force_initial_selection = false; - if(me.handle >= 0 && me.nItems <= 0) // me.handle not loaded yet? + if (me.handle >= 0 && me.nItems <= 0) { // me.handle not loaded yet? force_initial_selection = true; + } CvarList_Load(me, me.controlledTextbox.text); - if(force_initial_selection) + if (force_initial_selection) { me.setSelected(me, 0); + } } void XonoticCvarList_hideNotify(entity me) { - if(me.handle) + if (me.handle) { buf_del(me.handle); + } me.handle = buf_create(); me.nItems = 0; } void XonoticCvarList_destroy(entity me) { - if(me.handle) + if (me.handle) { buf_del(me.handle); + } } string autocvar_menu_forced_saved_cvars; string autocvar_menu_reverted_nonsaved_cvars; @@ -68,33 +72,29 @@ float XonoticCvarList_updateCvarType(entity me) t = cvar_type(me.cvarName); me.cvarType = ""; float needsForcing; - if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName)) - { + if (strhasword(autocvar_menu_forced_saved_cvars, me.cvarName)) { me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg")); needsForcing = 0; - } - else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, me.cvarName)) - { + } else if (strhasword(autocvar_menu_reverted_nonsaved_cvars, me.cvarName)) { // Currently claims to be saved, but won't be on next startup. me.cvarType = strcat(me.cvarType, ", ", _("will not be saved")); needsForcing = 1; - } - else if(t & CVAR_TYPEFLAG_SAVED) - { + } else if (t & CVAR_TYPEFLAG_SAVED) { me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg")); needsForcing = 0; - } - else - { + } else { me.cvarType = strcat(me.cvarType, ", ", _("will not be saved")); needsForcing = 1; } - if(t & CVAR_TYPEFLAG_PRIVATE) + if (t & CVAR_TYPEFLAG_PRIVATE) { me.cvarType = strcat(me.cvarType, ", ", _("private")); - if(t & CVAR_TYPEFLAG_ENGINE) + } + if (t & CVAR_TYPEFLAG_ENGINE) { me.cvarType = strcat(me.cvarType, ", ", _("engine setting")); - if(t & CVAR_TYPEFLAG_READONLY) + } + if (t & CVAR_TYPEFLAG_READONLY) { me.cvarType = strcat(me.cvarType, ", ", _("read only")); + } me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2)); me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType); return needsForcing; @@ -104,17 +104,22 @@ void XonoticCvarList_setSelected(entity me, float i) string s; SUPER(XonoticCvarList).setSelected(me, i); - if(me.nItems == 0) + if (me.nItems == 0) { return; + } - if(me.cvarName) + if (me.cvarName) { strunzone(me.cvarName); - if(me.cvarDescription) + } + if (me.cvarDescription) { strunzone(me.cvarDescription); - if(me.cvarType) + } + if (me.cvarType) { strunzone(me.cvarType); - if(me.cvarDefault) + } + if (me.cvarDefault) { strunzone(me.cvarDefault); + } me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem)); me.cvarDescription = strzone(cvar_description(me.cvarName)); me.cvarDefault = strzone(cvar_defstring(me.cvarName)); @@ -165,10 +170,9 @@ void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSe string s; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } @@ -178,18 +182,20 @@ void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSe v = cvar_string(k); d = cvar_defstring(k); t = cvar_type(k); - if(strhasword(autocvar_menu_forced_saved_cvars, k)) + if (strhasword(autocvar_menu_forced_saved_cvars, k)) { theAlpha = SKINALPHA_CVARLIST_SAVED; - else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, k)) + } else if (strhasword(autocvar_menu_reverted_nonsaved_cvars, k)) { theAlpha = SKINALPHA_CVARLIST_TEMPORARY; - else if(t & CVAR_TYPEFLAG_SAVED) + } else if (t & CVAR_TYPEFLAG_SAVED) { theAlpha = SKINALPHA_CVARLIST_SAVED; - else + } else { theAlpha = SKINALPHA_CVARLIST_TEMPORARY; - if(v == d) + } + if (v == d) { theColor = SKINCOLOR_CVARLIST_UNCHANGED; - else + } else { theColor = SKINCOLOR_CVARLIST_CHANGED; + } s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0); @@ -199,42 +205,40 @@ void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSe float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift) { - if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE)) - { + if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE)) { CvarList_Revert_Click(NULL, me); return 1; - } - else if(scan == K_ENTER) - { + } else if (scan == K_ENTER) { me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox); return 1; - } - else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift)) + } else if (SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift)) { return 1; - else if(!me.controlledTextbox) + } else if (!me.controlledTextbox) { return 0; - else + } else { return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift); + } } float XonoticCvarList_mouseRelease(entity me, vector pos) { - if(me.pressed == 2) + if (me.pressed == 2) { me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox); + } return SUPER(XonoticCvarList).mouseRelease(me, pos); } void CvarList_Value_Change(entity box, entity me) { cvar_set(me.cvarNameBox.text, box.text); - if(me.cvarNeedsForcing) - { + if (me.cvarNeedsForcing) { localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName)); cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2)); - if (autocvar_menu_forced_saved_cvars == "") + if (autocvar_menu_forced_saved_cvars == "") { cvar_set("menu_forced_saved_cvars", me.cvarName); - else + } else { cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName)); + } me.cvarNeedsForcing = 0; me.updateCvarType(me); } @@ -244,13 +248,13 @@ void CvarList_Revert_Click(entity btn, entity me) { me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault); me.cvarValueBox.cursorPos = strlen(me.cvarDefault); - if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName)) - { + if (strhasword(autocvar_menu_forced_saved_cvars, me.cvarName)) { cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2)); - if (autocvar_menu_reverted_nonsaved_cvars == "") + if (autocvar_menu_reverted_nonsaved_cvars == "") { cvar_set("menu_reverted_nonsaved_cvars", me.cvarName); - else + } else { cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName)); + } } me.cvarNeedsForcing = me.updateCvarType(me); } diff --git a/qcsrc/menu/xonotic/datasource.qc b/qcsrc/menu/xonotic/datasource.qc index d51a1f748..40b61de83 100644 --- a/qcsrc/menu/xonotic/datasource.qc +++ b/qcsrc/menu/xonotic/datasource.qc @@ -1,39 +1,39 @@ #include "datasource.qh" - CONSTRUCTOR(StringSource, string str, string sep) - { - CONSTRUCT(StringSource); - this.StringSource_str = str; - this.StringSource_sep = sep; - } - METHOD(StringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) - { - int n = tokenizebyseparator(this.StringSource_str, this.StringSource_sep); - if (i < 0 || i >= n) return DataSource_false; - string s = argv(i); - if (returns) returns(s, string_null); - return DataSource_true; - } - METHOD(StringSource, reload, int(entity this, string filter)) - { - return tokenizebyseparator(this.StringSource_str, this.StringSource_sep); - } +CONSTRUCTOR(StringSource, string str, string sep) +{ + CONSTRUCT(StringSource); + this.StringSource_str = str; + this.StringSource_sep = sep; +} +METHOD(StringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) +{ + int n = tokenizebyseparator(this.StringSource_str, this.StringSource_sep); + if (i < 0 || i >= n) { return DataSource_false; } + string s = argv(i); + if (returns) { returns(s, string_null); } + return DataSource_true; +} +METHOD(StringSource, reload, int(entity this, string filter)) +{ + return tokenizebyseparator(this.StringSource_str, this.StringSource_sep); +} - CONSTRUCTOR(CvarStringSource, string cv, string sep) - { - CONSTRUCT(CvarStringSource); - this.CvarStringSource_cvar = cv; - this.StringSource_sep = sep; - } - METHOD(CvarStringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) - { - string s = this.CvarStringSource_cvar; - this.StringSource_str = s ? cvar_string(s) : string_null; - return SUPER(CvarStringSource).getEntry(this, i, returns); - } - METHOD(CvarStringSource, reload, int(entity this, string filter)) - { - string s = this.CvarStringSource_cvar; - this.StringSource_str = s ? cvar_string(s) : string_null; - return SUPER(CvarStringSource).reload(this, filter); - } +CONSTRUCTOR(CvarStringSource, string cv, string sep) +{ + CONSTRUCT(CvarStringSource); + this.CvarStringSource_cvar = cv; + this.StringSource_sep = sep; +} +METHOD(CvarStringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) +{ + string s = this.CvarStringSource_cvar; + this.StringSource_str = s ? cvar_string(s) : string_null; + return SUPER(CvarStringSource).getEntry(this, i, returns); +} +METHOD(CvarStringSource, reload, int(entity this, string filter)) +{ + string s = this.CvarStringSource_cvar; + this.StringSource_str = s ? cvar_string(s) : string_null; + return SUPER(CvarStringSource).reload(this, filter); +} diff --git a/qcsrc/menu/xonotic/datasource.qh b/qcsrc/menu/xonotic/datasource.qh index 87c614ab7..5a8723004 100644 --- a/qcsrc/menu/xonotic/datasource.qh +++ b/qcsrc/menu/xonotic/datasource.qh @@ -1,34 +1,43 @@ #pragma once CLASS(DataSource, Object) - STATIC_ATTRIB(DataSource, true, entity, NEW(Object)); - STATIC_ATTRIB(DataSource, false, entity, NULL); - /** - * get entry `i` passing `name` and `icon` through `returns` if it is not null - * returns `DataSource_false` if out of bounds - * otherwise returns an entity or `DataSource_true` - */ - METHOD(DataSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) { return DataSource_false; } - /** return the index of the first match for `find`. optional */ - METHOD(DataSource, indexOf, int(entity this, string find)) { return -1; } - /** reload all entries matching `filter` returning how many matches were found */ - METHOD(DataSource, reload, int(entity this, string filter)) { return 0; } - /** cleanup on shutdown. optional */ - METHOD(DataSource, destroy, void(entity this)) { } + STATIC_ATTRIB(DataSource, true, entity, NEW(Object)); + STATIC_ATTRIB(DataSource, false, entity, NULL); + /** + * get entry `i` passing `name` and `icon` through `returns` if it is not null + * returns `DataSource_false` if out of bounds + * otherwise returns an entity or `DataSource_true` + */ + METHOD(DataSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) + { + return DataSource_false; + } + /** return the index of the first match for `find`. optional */ + METHOD(DataSource, indexOf, int(entity this, string find)) + { + return -1; + } + /** reload all entries matching `filter` returning how many matches were found */ + METHOD(DataSource, reload, int(entity this, string filter)) + { + return 0; + } + /** cleanup on shutdown. optional */ + METHOD(DataSource, destroy, void(entity this)) {} ENDCLASS(DataSource) CLASS(StringSource, DataSource) - ATTRIB(StringSource, StringSource_str, string); - ATTRIB(StringSource, StringSource_sep, string); - CONSTRUCTOR(StringSource, string str, string sep); - METHOD(StringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)); - METHOD(StringSource, reload, int(entity this, string filter)); + ATTRIB(StringSource, StringSource_str, string); + ATTRIB(StringSource, StringSource_sep, string); + CONSTRUCTOR(StringSource, string str, string sep); + METHOD(StringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)); + METHOD(StringSource, reload, int(entity this, string filter)); ENDCLASS(StringSource) CLASS(CvarStringSource, StringSource) - ATTRIB(CvarStringSource, CvarStringSource_cvar, string); - CONSTRUCTOR(CvarStringSource, string cv, string sep); - METHOD(CvarStringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)); - METHOD(CvarStringSource, reload, int(entity this, string filter)); + ATTRIB(CvarStringSource, CvarStringSource_cvar, string); + CONSTRUCTOR(CvarStringSource, string cv, string sep); + METHOD(CvarStringSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)); + METHOD(CvarStringSource, reload, int(entity this, string filter)); ENDCLASS(CvarStringSource) diff --git a/qcsrc/menu/xonotic/demolist.qc b/qcsrc/menu/xonotic/demolist.qc index b527542a5..4143bd8e8 100644 --- a/qcsrc/menu/xonotic/demolist.qc +++ b/qcsrc/menu/xonotic/demolist.qc @@ -21,9 +21,9 @@ string XonoticDemoList_demoName(entity me, float i) string s; s = bufstr_get(me.listDemo, i); - if(substring(s, 0, 1) == "/") - s = substring(s, 1, strlen(s) - 1); // remove the first forward slash - + if (substring(s, 0, 1) == "/") { + s = substring(s, 1, strlen(s) - 1); // remove the first forward slash + } return s; } @@ -31,60 +31,61 @@ string XonoticDemoList_demoName(entity me, float i) void getDemos_for_ext(entity me, string ext, float subdir) { string s; - if (subdir) - s="demos/*/"; - else - s="demos/"; - if(me.filterString) - s=strcat(s, me.filterString, ext); - else - s=strcat(s, "*", ext); + if (subdir) { + s = "demos/*/"; + } else { + s = "demos/"; + } + if (me.filterString) { + s = strcat(s, me.filterString, ext); + } else { + s = strcat(s, "*", ext); + } float list, i, n; list = search_begin(s, false, true); - if(list >= 0) - { + if (list >= 0) { n = search_getsize(list); - for(i = 0; i < n; ++i) - { - s = search_getfilename(list, i); // get initial full file name - s = substring(s, 6, (strlen(s) - 6 - 4)); // remove "demos/" prefix and ".dem" suffix - s = strdecolorize(s); // remove any pre-existing colors - if(subdir) - { - s = strreplace("/", "^7/", s); // clear colors at the forward slash + for (i = 0; i < n; ++i) { + s = search_getfilename(list, i); // get initial full file name + s = substring(s, 6, (strlen(s) - 6 - 4)); // remove "demos/" prefix and ".dem" suffix + s = strdecolorize(s); // remove any pre-existing colors + if (subdir) { + s = strreplace("/", "^7/", s); // clear colors at the forward slash s = strcat("/", rgb_to_hexcolor(SKINCOLOR_DEMOLIST_SUBDIR), s); // add a forward slash for sorting, then color bufstr_add(me.listDemo, s, true); - } - else { bufstr_add(me.listDemo, s, true); } + } else { bufstr_add(me.listDemo, s, true); } } search_end(list); } - if (subdir) + if (subdir) { getDemos_for_ext(me, ext, false); + } } void XonoticDemoList_getDemos(entity me) { - if (me.listDemo >= 0) + if (me.listDemo >= 0) { buf_del(me.listDemo); + } me.listDemo = buf_create(); - if (me.listDemo < 0) - { + if (me.listDemo < 0) { me.nItems = 0; return; } getDemos_for_ext(me, ".dem", true); me.nItems = buf_getsize(me.listDemo); - if(me.nItems > 0) + if (me.nItems > 0) { buf_sort(me.listDemo, 128, false); + } } void XonoticDemoList_destroy(entity me) { - if(me.nItems > 0) + if (me.nItems > 0) { buf_del(me.listDemo); + } } void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) @@ -103,15 +104,14 @@ void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, v void XonoticDemoList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { string s; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - s = me.demoName(me,i); + s = me.demoName(me, i); s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 1); } @@ -124,23 +124,24 @@ void XonoticDemoList_showNotify(entity me) void DemoList_Refresh_Click(entity btn, entity me) { me.getDemos(me); - me.setSelected(me, 0); //always select the first element after a list update + me.setSelected(me, 0); // always select the first element after a list update } void DemoList_Filter_Change(entity box, entity me) { - if(me.filterString) + if (me.filterString) { strunzone(me.filterString); + } - if(box.text != "") - { - if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0) + if (box.text != "") { + if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0) { me.filterString = strzone(box.text); - else + } else { me.filterString = strzone(strcat("*", box.text, "*")); - } - else + } + } else { me.filterString = string_null; + } me.getDemos(me); } @@ -165,12 +166,9 @@ void XonoticDemoList_timeDemo(entity me) void DemoConfirm_ListClick_Check_Gamestatus(entity me) { - if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, lets watch the demo - { + if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) { // we're not in a match, lets watch the demo me.startDemo(me); - } - else // already in a match, player has to confirm - { + } else { // already in a match, player has to confirm DialogOpenButton_Click_withCoords( me, main.demostartconfirmDialog, @@ -187,13 +185,10 @@ void XonoticDemoList_doubleClickListBoxItem(entity me, float i, vector where) float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER) - { + if (scan == K_ENTER || scan == K_KP_ENTER) { DemoConfirm_ListClick_Check_Gamestatus(me); return 1; - } - else - { + } else { return SUPER(XonoticDemoList).keyDown(me, scan, ascii, shift); } } diff --git a/qcsrc/menu/xonotic/demolist.qh b/qcsrc/menu/xonotic/demolist.qh index 6341db1a3..a717016a9 100644 --- a/qcsrc/menu/xonotic/demolist.qh +++ b/qcsrc/menu/xonotic/demolist.qh @@ -27,7 +27,7 @@ CLASS(XonoticDemoList, XonoticListBox) ATTRIB(XonoticDemoList, filterString, string); ENDCLASS(XonoticDemoList) -entity demolist; // for reference elsewhere +entity demolist; // for reference elsewhere entity makeXonoticDemoList(); void DemoList_Refresh_Click(entity btn, entity me); void DemoList_Filter_Change(entity box, entity me); diff --git a/qcsrc/menu/xonotic/dialog_credits.qc b/qcsrc/menu/xonotic/dialog_credits.qc index 16469dbdd..609444d64 100644 --- a/qcsrc/menu/xonotic/dialog_credits.qc +++ b/qcsrc/menu/xonotic/dialog_credits.qc @@ -8,11 +8,11 @@ void XonoticCreditsDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, me.rows - 1, me.columns, me.creditsList = makeXonoticCreditsList()); + me.TD(me, me.rows - 1, me.columns, me.creditsList = makeXonoticCreditsList()); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } void XonoticCreditsDialog_focusEnter(entity me) { diff --git a/qcsrc/menu/xonotic/dialog_firstrun.qc b/qcsrc/menu/xonotic/dialog_firstrun.qc index 0d3b5c975..35e1bb0ad 100644 --- a/qcsrc/menu/xonotic/dialog_firstrun.qc +++ b/qcsrc/menu/xonotic/dialog_firstrun.qc @@ -10,22 +10,25 @@ float CheckFirstRunButton(entity me) { - if(cvar_string("_cl_name") != cvar_defstring("_cl_name")) + if (cvar_string("_cl_name") != cvar_defstring("_cl_name")) { return 1; + } - if(cvar_string("_menu_prvm_language") != prvm_language) + if (cvar_string("_menu_prvm_language") != prvm_language) { return 1; // OK will then reopen the dialog in another language - - if(cvar_string("cl_allow_uid2name") != "-1") + } + if (cvar_string("cl_allow_uid2name") != "-1") { return 1; + } return 0; } void firstRun_setLanguage(entity me) { - if(prvm_language != cvar_string("_menu_prvm_language")) + if (prvm_language != cvar_string("_menu_prvm_language")) { localcmd("\nprvm_language \"$_menu_prvm_language\"; saveconfig; menu_restart\n"); + } } void XonoticFirstRunDialog_fill(entity me) @@ -35,42 +38,43 @@ void XonoticFirstRunDialog_fill(entity me) me.TR(me); me.TR(me); - me.TDempty(me, 1); - me.TD(me, 2, 4, e = makeXonoticTextLabel(0, _("Welcome to Xonotic, please select your language preference and enter your player name to get started. You can change these options later through the menu system."))); - e.allowWrap = 1; + me.TDempty(me, 1); + me.TD(me, 2, 4, e = makeXonoticTextLabel(0, _("Welcome to Xonotic, please select your language preference and enter your player name to get started. You can change these options later through the menu system."))); + e.allowWrap = 1; me.TR(me); me.TR(me); me.TR(me); - me.TD(me, 1, 0.5, me.playerNameLabel = makeXonoticTextLabel(0, _("Name:"))); - me.playerNameLabelAlpha = me.playerNameLabel.alpha; - me.TD(me, 1, 3.25, label = makeXonoticTextLabel(0, string_null)); - label.allowCut = 1; - label.allowColors = 1; - label.alpha = 1; + me.TD(me, 1, 0.5, me.playerNameLabel = makeXonoticTextLabel(0, _("Name:"))); + me.playerNameLabelAlpha = me.playerNameLabel.alpha; + me.TD(me, 1, 3.25, label = makeXonoticTextLabel(0, string_null)); + label.allowCut = 1; + label.allowColors = 1; + label.alpha = 1; me.TR(me); - me.TD(me, 1, 3.75, box = makeXonoticInputBox_T(1, "_cl_name", + me.TD(me, 1, 3.75, box = makeXonoticInputBox_T(1, "_cl_name", _("Name under which you will appear in the game"))); - box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved - box.maxLength = -127; // negative means encoded length in bytes - box.saveImmediately = 0; // Sorry, can't do this, it spams "name" commands. - box.enableClearButton = 0; - label.textEntity = box; + box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved + box.maxLength = -127; // negative means encoded length in bytes + box.saveImmediately = 0; // Sorry, can't do this, it spams "name" commands. + box.enableClearButton = 0; + label.textEntity = box; me.TR(me); - me.TD(me, 5, 1.25, e = makeXonoticColorpicker(box)); - me.TD(me, 5, 2.5, e = makeXonoticCharmap(box)); + me.TD(me, 5, 1.25, e = makeXonoticColorpicker(box)); + me.TD(me, 5, 2.5, e = makeXonoticCharmap(box)); me.TR(me); me.TR(me); me.TR(me); me.TR(me); - me.gotoRC(me, 3, 4); me.setFirstColumn(me, me.currentColumn); + me.gotoRC(me, 3, 4); + me.setFirstColumn(me, me.currentColumn); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0, _("Text language:"))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0, _("Text language:"))); me.TR(me); - me.TD(me, 6, 2, e = makeXonoticLanguageList()); - e.name = "languageselector_firstrun"; - e.setLanguage = firstRun_setLanguage; + me.TD(me, 6, 2, e = makeXonoticLanguageList()); + e.name = "languageselector_firstrun"; + e.setLanguage = firstRun_setLanguage; me.TR(me); me.TR(me); @@ -86,5 +90,5 @@ void XonoticFirstRunDialog_fill(entity me) // because of the language selector, this is a menu_restart! me.gotoRC(me, me.rows - 1, 0); me.TD(me, 1, me.columns, e = makeXonoticCommandButton(_("Save settings"), '0 0 0', "prvm_language \"$_menu_prvm_language\"; saveconfig; menu_restart", COMMANDBUTTON_APPLY)); - setDependentWeird(e, CheckFirstRunButton); + setDependentWeird(e, CheckFirstRunButton); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_ammo.qc b/qcsrc/menu/xonotic/dialog_hudpanel_ammo.qc index 2e67e7acf..d7c0d7707 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_ammo.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_ammo.qc @@ -13,21 +13,21 @@ void XonoticHUDAmmoDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Ammunition display:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Ammunition display:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_ammo_onlycurrent", _("Show only current ammo type"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_ammo_onlycurrent", _("Show only current ammo type"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent alpha:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_ammo_noncurrent_alpha")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent alpha:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_ammo_noncurrent_alpha")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent scale:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_ammo_noncurrent_scale")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent scale:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_ammo_noncurrent_scale")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Align icon:"))); - me.TD(me, 1, 2.6/2, e = makeXonoticRadioButton(2, "hud_panel_ammo_iconalign", "0", _("Left"))); - me.TD(me, 1, 2.6/2, e = makeXonoticRadioButton(2, "hud_panel_ammo_iconalign", "1", _("Right"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Align icon:"))); + me.TD(me, 1, 2.6 / 2, e = makeXonoticRadioButton(2, "hud_panel_ammo_iconalign", "0", _("Left"))); + me.TD(me, 1, 2.6 / 2, e = makeXonoticRadioButton(2, "hud_panel_ammo_iconalign", "1", _("Right"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_centerprint.qc b/qcsrc/menu/xonotic/dialog_hudpanel_centerprint.qc index 332f6753f..51f0f619b 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_centerprint.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_centerprint.qc @@ -13,25 +13,25 @@ void XonoticHUDCenterprintDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Message duration:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(1, 10, 1, "hud_panel_centerprint_time")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Message duration:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(1, 10, 1, "hud_panel_centerprint_time")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Fade time:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.05, "hud_panel_centerprint_fade_out")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Fade time:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.05, "hud_panel_centerprint_fade_out")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_centerprint_flip", _("Flip messages order"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_centerprint_flip", _("Flip messages order"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Text alignment:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Text alignment:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8/3, e = makeXonoticRadioButton(3, "hud_panel_centerprint_align", "0", _("Left"))); - me.TD(me, 1, 3.8/3, e = makeXonoticRadioButton(3, "hud_panel_centerprint_align", "0.5", _("Center"))); - me.TD(me, 1, 3.8/3, e = makeXonoticRadioButton(3, "hud_panel_centerprint_align", "1", _("Right"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8 / 3, e = makeXonoticRadioButton(3, "hud_panel_centerprint_align", "0", _("Left"))); + me.TD(me, 1, 3.8 / 3, e = makeXonoticRadioButton(3, "hud_panel_centerprint_align", "0.5", _("Center"))); + me.TD(me, 1, 3.8 / 3, e = makeXonoticRadioButton(3, "hud_panel_centerprint_align", "1", _("Right"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Font scale:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0.5, 2, 0.1, "hud_panel_centerprint_fontscale")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Font scale:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0.5, 2, 0.1, "hud_panel_centerprint_fontscale")); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_chat.qc b/qcsrc/menu/xonotic/dialog_hudpanel_chat.qc index 1ffa41f68..d841c661d 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_chat.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_chat.qc @@ -12,16 +12,16 @@ void XonoticHUDChatDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0, _("Chat entries:"))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0, _("Chat entries:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Chat size:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(6, 20, 1, "con_chatsize")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Chat size:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(6, 20, 1, "con_chatsize")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Chat lifetime:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(5, 60, 5, "con_chattime")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Chat lifetime:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(5, 60, 5, "con_chattime")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "con_chatsound", _("Chat beep sound"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "con_chatsound", _("Chat beep sound"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_engineinfo.qc b/qcsrc/menu/xonotic/dialog_hudpanel_engineinfo.qc index b46d3aa02..3e3532bd4 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_engineinfo.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_engineinfo.qc @@ -11,8 +11,8 @@ void XonoticHUDEngineInfoDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Engine info:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Engine info:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_engineinfo_framecounter_exponentialmovingaverage", _("Use an averaging algorithm for fps"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_engineinfo_framecounter_exponentialmovingaverage", _("Use an averaging algorithm for fps"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_healtharmor.qc b/qcsrc/menu/xonotic/dialog_hudpanel_healtharmor.qc index ac305b832..54034d7e6 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_healtharmor.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_healtharmor.qc @@ -12,30 +12,30 @@ void XonoticHUDHealthArmorDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_healtharmor_combined", _("Combine health and armor"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_healtharmor_combined", _("Combine health and armor"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_healtharmor_progressbar", _("Enable status bar"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_healtharmor_progressbar", _("Enable status bar"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Status bar alignment:"))); - setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Status bar alignment:"))); + setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "0", _("Left"))); - setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "1", _("Right"))); - setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "2", _("Inward"))); - setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "3", _("Outward"))); - setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "0", _("Left"))); + setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "1", _("Right"))); + setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "2", _("Inward"))); + setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_healtharmor_baralign", "3", _("Outward"))); + setDependent(e, "hud_panel_healtharmor_progressbar", 1, 1); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Icon alignment:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Icon alignment:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "0", _("Left"))); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "1", _("Right"))); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "2", _("Inward"))); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "3", _("Outward"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "0", _("Left"))); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "1", _("Right"))); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "2", _("Inward"))); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_healtharmor_iconalign", "3", _("Outward"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_healtharmor_flip", _("Flip health and armor positions"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_healtharmor_flip", _("Flip health and armor positions"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_infomessages.qc b/qcsrc/menu/xonotic/dialog_hudpanel_infomessages.qc index d758ad206..fcf5f7636 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_infomessages.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_infomessages.qc @@ -11,8 +11,8 @@ void XonoticHUDInfoMessagesDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Info messages:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Info messages:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_infomessages_flip", _("Flip align"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_infomessages_flip", _("Flip align"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_itemstime.qc b/qcsrc/menu/xonotic/dialog_hudpanel_itemstime.qc index aeb8c8c77..3867a05c8 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_itemstime.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_itemstime.qc @@ -12,29 +12,29 @@ void XonoticHUDItemsTimeDialog_fill(entity me) string panelname = "itemstime"; me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_itemstime")); - e.addValue(e, ZCTX(_("PNL^Disabled")), "0"); - e.addValue(e, ZCTX(_("PNL^Enabled spectating")), "1"); - e.addValue(e, ZCTX(_("PNL^Enabled even playing in warmup")), "2"); - e.configureXonoticTextSliderValues(e); + me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_itemstime")); + e.addValue(e, ZCTX(_("PNL^Disabled")), "0"); + e.addValue(e, ZCTX(_("PNL^Enabled spectating")), "1"); + e.addValue(e, ZCTX(_("PNL^Enabled even playing in warmup")), "2"); + e.configureXonoticTextSliderValues(e); DIALOG_HUDPANEL_COMMON_NOTOGGLE(); me.TR(me); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Align icon:"))); - me.TD(me, 1, 2.6/2, e = makeXonoticRadioButton(2, "hud_panel_itemstime_iconalign", "0", _("Left"))); - me.TD(me, 1, 2.6/2, e = makeXonoticRadioButton(2, "hud_panel_itemstime_iconalign", "1", _("Right"))); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Align icon:"))); + me.TD(me, 1, 2.6 / 2, e = makeXonoticRadioButton(2, "hud_panel_itemstime_iconalign", "0", _("Left"))); + me.TD(me, 1, 2.6 / 2, e = makeXonoticRadioButton(2, "hud_panel_itemstime_iconalign", "1", _("Right"))); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "hud_panel_itemstime_progressbar", _("Enable status bar"))); - me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "hud_panel_itemstime_progressbar_reduced", _("Reduced"))); - setDependent(e, "hud_panel_itemstime_progressbar", 1, 1); + me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "hud_panel_itemstime_progressbar", _("Enable status bar"))); + me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "hud_panel_itemstime_progressbar_reduced", _("Reduced"))); + setDependent(e, "hud_panel_itemstime_progressbar", 1, 1); me.TR(me); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Text/icon ratio:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(2, 8, 0.5, "hud_panel_itemstime_ratio")); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Text/icon ratio:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(2, 8, 0.5, "hud_panel_itemstime_ratio")); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_itemstime_hidespawned", _("Hide spawned items"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_itemstime_hidespawned", _("Hide spawned items"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_itemstime_hidebig", _("Hide big armor and health"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_itemstime_hidebig", _("Hide big armor and health"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_itemstime_dynamicsize", _("Dynamic size"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_itemstime_dynamicsize", _("Dynamic size"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_notification.qc b/qcsrc/menu/xonotic/dialog_hudpanel_notification.qc index 490051846..96e907ad9 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_notification.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_notification.qc @@ -12,19 +12,19 @@ void XonoticHUDNotificationDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Notifications:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Notifications:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_notify_print", _("Also print notifications to the console"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_notify_print", _("Also print notifications to the console"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_notify_flip", _("Flip notify order"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_notify_flip", _("Flip notify order"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Entry lifetime:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(3, 15, 1, "hud_panel_notify_time")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Entry lifetime:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(3, 15, 1, "hud_panel_notify_time")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Entry fadetime:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0.5, 5, 0.5, "hud_panel_notify_fadetime")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Entry fadetime:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0.5, 5, 0.5, "hud_panel_notify_fadetime")); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc b/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc index eabc93dab..64f58c8a5 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc @@ -11,64 +11,64 @@ void XonoticHUDPhysicsDialog_fill(entity me) string panelname = "physics"; me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_physics")); - e.addValue(e, _("Panel disabled"), "0"); - e.addValue(e, _("Panel enabled"), "1"); - e.addValue(e, _("Panel enabled even observing"), "2"); - e.addValue(e, _("Panel enabled only in Race/CTS"), "3"); - e.configureXonoticTextSliderValues(e); + me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_physics")); + e.addValue(e, _("Panel disabled"), "0"); + e.addValue(e, _("Panel enabled"), "1"); + e.addValue(e, _("Panel enabled even observing"), "2"); + e.addValue(e, _("Panel enabled only in Race/CTS"), "3"); + e.configureXonoticTextSliderValues(e); DIALOG_HUDPANEL_COMMON_NOTOGGLE(); me.TR(me); - me.TD(me, 1, 1.4, e = makeXonoticCheckBox(0, "hud_panel_physics_progressbar", _("Status bar"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_physics_baralign")); - e.addValue(e, _("Left align") , "0"); - e.addValue(e, _("Right align") , "1"); - e.addValue(e, _("Inward align") , "2"); - e.addValue(e, _("Outward align"), "3"); - e.configureXonoticTextSliderValues(e); - setDependent(e, "hud_panel_physics_progressbar", 1, 3); + me.TD(me, 1, 1.4, e = makeXonoticCheckBox(0, "hud_panel_physics_progressbar", _("Status bar"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_physics_baralign")); + e.addValue(e, _("Left align"), "0"); + e.addValue(e, _("Right align"), "1"); + e.addValue(e, _("Inward align"), "2"); + e.addValue(e, _("Outward align"), "3"); + e.configureXonoticTextSliderValues(e); + setDependent(e, "hud_panel_physics_progressbar", 1, 3); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_physics_flip", _("Flip speed/acceleration positions"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_physics_flip", _("Flip speed/acceleration positions"))); -//speed +// speed me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Speed:"))); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_physics_speed_vertical", _("Include vertical speed"))); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Speed:"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_physics_speed_vertical", _("Include vertical speed"))); // me.TR(me); - // me.TDempty(me, 0.2); - // me.TD(me, 1, 1.8, e = makeXonoticTextLabel(0, _("Full status bar at:"))); - // setDependent(e, "hud_panel_physics_progressbar", 1, 1); - // me.TD(me, 1, 1, e = makeXonoticInputBox(1, "hud_panel_physics_speed_max")); - // setDependent(e, "hud_panel_physics_progressbar", 1, 1); - // me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("qu/s"))); - // setDependent(e, "hud_panel_physics_progressbar", 1, 1); + // me.TDempty(me, 0.2); + // me.TD(me, 1, 1.8, e = makeXonoticTextLabel(0, _("Full status bar at:"))); + // setDependent(e, "hud_panel_physics_progressbar", 1, 1); + // me.TD(me, 1, 1, e = makeXonoticInputBox(1, "hud_panel_physics_speed_max")); + // setDependent(e, "hud_panel_physics_progressbar", 1, 1); + // me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("qu/s"))); + // setDependent(e, "hud_panel_physics_progressbar", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Speed unit:"))); - me.TD(me, 1, 2.6/3*2, e = makeXonoticTextSlider("hud_panel_physics_speed_unit")); - e.addValue(e, _("qu/s") , "1"); - e.addValue(e, _("m/s") , "2"); - e.addValue(e, _("km/h") , "3"); - e.addValue(e, _("mph") , "4"); - e.addValue(e, _("knots"), "5"); - e.configureXonoticTextSliderValues(e); - me.TD(me, 1, 2.6/3, e = makeXonoticCheckBox(0, "hud_panel_physics_speed_unit_show", _("Show"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Speed unit:"))); + me.TD(me, 1, 2.6 / 3 * 2, e = makeXonoticTextSlider("hud_panel_physics_speed_unit")); + e.addValue(e, _("qu/s"), "1"); + e.addValue(e, _("m/s"), "2"); + e.addValue(e, _("km/h"), "3"); + e.addValue(e, _("mph"), "4"); + e.addValue(e, _("knots"), "5"); + e.configureXonoticTextSliderValues(e); + me.TD(me, 1, 2.6 / 3, e = makeXonoticCheckBox(0, "hud_panel_physics_speed_unit_show", _("Show"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8/2, e = makeXonoticCheckBox(0, "hud_panel_physics_topspeed", _("Top speed"))); - me.TD(me, 1, 3.8/2, e = makeXonoticSlider(1, 10, 1, "hud_panel_physics_topspeed_time")); - setDependent(e, "hud_panel_physics_topspeed", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8 / 2, e = makeXonoticCheckBox(0, "hud_panel_physics_topspeed", _("Top speed"))); + me.TD(me, 1, 3.8 / 2, e = makeXonoticSlider(1, 10, 1, "hud_panel_physics_topspeed_time")); + setDependent(e, "hud_panel_physics_topspeed", 1, 1); -//acceleration +// acceleration me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Acceleration:"))); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_physics_acceleration_vertical", _("Include vertical acceleration"))); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Acceleration:"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_physics_acceleration_vertical", _("Include vertical acceleration"))); // me.TR(me); - // me.TDempty(me, 0.2); - // me.TD(me, 1, 1.8, e = makeXonoticTextLabel(0, _("Full status bar at:"))); - // setDependent(e, "hud_panel_physics_progressbar", 1, 1); - // me.TD(me, 1, 0.6, e = makeXonoticInputBox(1, "hud_panel_physics_acceleration_max")); - // setDependent(e, "hud_panel_physics_progressbar", 1, 1); + // me.TDempty(me, 0.2); + // me.TD(me, 1, 1.8, e = makeXonoticTextLabel(0, _("Full status bar at:"))); + // setDependent(e, "hud_panel_physics_progressbar", 1, 1); + // me.TD(me, 1, 0.6, e = makeXonoticInputBox(1, "hud_panel_physics_acceleration_max")); + // setDependent(e, "hud_panel_physics_progressbar", 1, 1); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_powerups.qc b/qcsrc/menu/xonotic/dialog_hudpanel_powerups.qc index 1b490d102..442fbd9ed 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_powerups.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_powerups.qc @@ -12,26 +12,26 @@ void XonoticHUDPowerupsDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_powerups_progressbar", _("Enable status bar"))); + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, "hud_panel_powerups_progressbar", _("Enable status bar"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Status bar alignment:"))); - setDependent(e, "hud_panel_powerups_progressbar", 1, 1); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Status bar alignment:"))); + setDependent(e, "hud_panel_powerups_progressbar", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "0", _("Left"))); - setDependent(e, "hud_panel_powerups_progressbar", 1, 1); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "1", _("Right"))); - setDependent(e, "hud_panel_powerups_progressbar", 1, 1); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "2", _("Inward"))); - setDependent(e, "hud_panel_powerups_progressbar", 1, 1); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "3", _("Outward"))); - setDependent(e, "hud_panel_powerups_progressbar", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "0", _("Left"))); + setDependent(e, "hud_panel_powerups_progressbar", 1, 1); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "1", _("Right"))); + setDependent(e, "hud_panel_powerups_progressbar", 1, 1); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "2", _("Inward"))); + setDependent(e, "hud_panel_powerups_progressbar", 1, 1); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(2, "hud_panel_powerups_baralign", "3", _("Outward"))); + setDependent(e, "hud_panel_powerups_progressbar", 1, 1); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Icon alignment:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Icon alignment:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "0", _("Left"))); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "1", _("Right"))); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "2", _("Inward"))); - me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "3", _("Outward"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "0", _("Left"))); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "1", _("Right"))); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "2", _("Inward"))); + me.TD(me, 1, 0.95, e = makeXonoticRadioButton(3, "hud_panel_powerups_iconalign", "3", _("Outward"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_pressedkeys.qc b/qcsrc/menu/xonotic/dialog_hudpanel_pressedkeys.qc index 4e24ff998..da5d9d7fe 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_pressedkeys.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_pressedkeys.qc @@ -10,16 +10,16 @@ void XonoticHUDPressedKeysDialog_fill(entity me) string panelname = "pressedkeys"; me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_pressedkeys")); - e.addValue(e, _("Panel disabled"), "0"); - e.addValue(e, _("Panel enabled when spectating"), "1"); - e.addValue(e, _("Panel always enabled"), "2"); - e.configureXonoticTextSliderValues(e); + me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_pressedkeys")); + e.addValue(e, _("Panel disabled"), "0"); + e.addValue(e, _("Panel enabled when spectating"), "1"); + e.addValue(e, _("Panel always enabled"), "2"); + e.configureXonoticTextSliderValues(e); DIALOG_HUDPANEL_COMMON_NOTOGGLE(); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Forced aspect:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0.2, 4, 0.1, "hud_panel_pressedkeys_aspect")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Forced aspect:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0.2, 4, 0.1, "hud_panel_pressedkeys_aspect")); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_quickmenu.qc b/qcsrc/menu/xonotic/dialog_hudpanel_quickmenu.qc index 4012bc61a..e0f8b68d4 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_quickmenu.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_quickmenu.qc @@ -12,10 +12,10 @@ void XonoticHUDQuickMenuDialog_fill(entity me) DIALOG_HUDPANEL_COMMON_NOTOGGLE(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Text alignment:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Text alignment:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8/3, e = makeXonoticRadioButton(3, "hud_panel_quickmenu_align", "0", _("Left"))); - me.TD(me, 1, 3.8/3, e = makeXonoticRadioButton(3, "hud_panel_quickmenu_align", "0.5", _("Center"))); - me.TD(me, 1, 3.8/3, e = makeXonoticRadioButton(3, "hud_panel_quickmenu_align", "1", _("Right"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8 / 3, e = makeXonoticRadioButton(3, "hud_panel_quickmenu_align", "0", _("Left"))); + me.TD(me, 1, 3.8 / 3, e = makeXonoticRadioButton(3, "hud_panel_quickmenu_align", "0.5", _("Center"))); + me.TD(me, 1, 3.8 / 3, e = makeXonoticRadioButton(3, "hud_panel_quickmenu_align", "1", _("Right"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_radar.qc b/qcsrc/menu/xonotic/dialog_hudpanel_radar.qc index de9ed6898..65e322bdd 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_radar.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_radar.qc @@ -11,41 +11,41 @@ void XonoticHUDRadarDialog_fill(entity me) string panelname = "radar"; me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_radar")); - e.addValue(e, _("Panel disabled"), "0"); - e.addValue(e, _("Panel enabled in teamgames"), "1"); - e.addValue(e, _("Panel always enabled"), "2"); - e.configureXonoticTextSliderValues(e); + me.TD(me, 1, 4, e = makeXonoticTextSlider("hud_panel_radar")); + e.addValue(e, _("Panel disabled"), "0"); + e.addValue(e, _("Panel enabled in teamgames"), "1"); + e.addValue(e, _("Panel always enabled"), "2"); + e.configureXonoticTextSliderValues(e); DIALOG_HUDPANEL_COMMON_NOTOGGLE(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Radar:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Radar:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0.1, 1, 0.1, "hud_panel_radar_foreground_alpha")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0.1, 1, 0.1, "hud_panel_radar_foreground_alpha")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Rotation:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_radar_rotation")); - e.addValue(e, _("Forward"), "0"); - e.addValue(e, _("West"), "1"); - e.addValue(e, _("South"), "2"); - e.addValue(e, _("East"), "3"); - e.addValue(e, _("North"), "4"); - e.configureXonoticTextSliderValues(e); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Rotation:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_radar_rotation")); + e.addValue(e, _("Forward"), "0"); + e.addValue(e, _("West"), "1"); + e.addValue(e, _("South"), "2"); + e.addValue(e, _("East"), "3"); + e.addValue(e, _("North"), "4"); + e.configureXonoticTextSliderValues(e); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Scale:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(1024, 8192, 512, "hud_panel_radar_scale")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Scale:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(1024, 8192, 512, "hud_panel_radar_scale")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Zoom mode:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_radar_zoommode")); - e.addValue(e, _("Zoomed in"), "0"); - e.addValue(e, _("Zoomed out"), "1"); - e.addValue(e, _("Always zoomed"), "2"); - e.addValue(e, _("Never zoomed"), "3"); - e.configureXonoticTextSliderValues(e); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Zoom mode:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_radar_zoommode")); + e.addValue(e, _("Zoomed in"), "0"); + e.addValue(e, _("Zoomed out"), "1"); + e.addValue(e, _("Always zoomed"), "2"); + e.addValue(e, _("Never zoomed"), "3"); + e.configureXonoticTextSliderValues(e); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_score.qc b/qcsrc/menu/xonotic/dialog_hudpanel_score.qc index f04ca30da..af6f54021 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_score.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_score.qc @@ -12,11 +12,11 @@ void XonoticHUDScoreDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Score:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Score:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Rankings:"))); - me.TD(me, 1, 2.6/3, e = makeXonoticRadioButton(1, "hud_panel_score_rankings", "0", _("Off"))); - me.TD(me, 1, 2.6/3, e = makeXonoticRadioButton(1, "hud_panel_score_rankings", "1", _("And me"))); - me.TD(me, 1, 2.6/3, e = makeXonoticRadioButton(1, "hud_panel_score_rankings", "2", _("Pure"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Rankings:"))); + me.TD(me, 1, 2.6 / 3, e = makeXonoticRadioButton(1, "hud_panel_score_rankings", "0", _("Off"))); + me.TD(me, 1, 2.6 / 3, e = makeXonoticRadioButton(1, "hud_panel_score_rankings", "1", _("And me"))); + me.TD(me, 1, 2.6 / 3, e = makeXonoticRadioButton(1, "hud_panel_score_rankings", "2", _("Pure"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_timer.qc b/qcsrc/menu/xonotic/dialog_hudpanel_timer.qc index dd9a7b878..581acb2c6 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_timer.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_timer.qc @@ -11,8 +11,8 @@ void XonoticHUDTimerDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Timer:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Timer:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_timer_increment", _("Show elapsed time"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_timer_increment", _("Show elapsed time"))); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_vote.qc b/qcsrc/menu/xonotic/dialog_hudpanel_vote.qc index e8afa7ca7..670cbf343 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_vote.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_vote.qc @@ -12,6 +12,6 @@ void XonoticHUDVoteDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Alpha after voting:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0.1, 1, 0.1, "hud_panel_vote_alreadyvoted_alpha")); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Alpha after voting:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0.1, 1, 0.1, "hud_panel_vote_alreadyvoted_alpha")); } diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_weapons.qc b/qcsrc/menu/xonotic/dialog_hudpanel_weapons.qc index 61339b6b9..9fd28d791 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_weapons.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_weapons.qc @@ -16,64 +16,65 @@ void XonoticHUDWeaponsDialog_fill(entity me) DIALOG_HUDPANEL_COMMON(); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Fade out after:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_timeout")))); - e.addValue(e, _("Never"), "0"); - for(i = 1; i <= 10; ++i) - e.addValue(e, strzone(sprintf(_("%ds"), i)), strzone(ftos(i))); - e.configureXonoticTextSliderValues(e); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Fade out after:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_timeout")))); + e.addValue(e, _("Never"), "0"); + for (i = 1; i <= 10; ++i) { + e.addValue(e, strzone(sprintf(_("%ds"), i)), strzone(ftos(i))); + } + e.configureXonoticTextSliderValues(e); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Fade effect:"))); - setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_timeout")), "0"); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_timeout_effect")))); - e.addValue(e, ZCTX(_("EF^None")), "0"); - e.addValue(e, _("Alpha"), "1"); - e.addValue(e, _("Slide"), "2"); - e.addValue(e, ZCTX(_("EF^Both")), "3"); - e.configureXonoticTextSliderValues(e); - setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_timeout")), "0"); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Fade effect:"))); + setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_timeout")), "0"); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider(strzone(strcat("hud_panel_", panelname, "_timeout_effect")))); + e.addValue(e, ZCTX(_("EF^None")), "0"); + e.addValue(e, _("Alpha"), "1"); + e.addValue(e, _("Slide"), "2"); + e.addValue(e, ZCTX(_("EF^Both")), "3"); + e.configureXonoticTextSliderValues(e); + setDependentStringNotEqual(e, strzone(strcat("hud_panel_", panelname, "_timeout")), "0"); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Weapon icons:"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("Weapon icons:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_weapons_onlyowned", _("Show only owned weapons"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_panel_weapons_onlyowned", _("Show only owned weapons"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent alpha:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_weapons_noncurrent_alpha")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent alpha:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_weapons_noncurrent_alpha")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent scale:"))); - me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_weapons_noncurrent_scale")); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Noncurrent scale:"))); + me.TD(me, 1, 2.6, e = makeXonoticSlider(0, 1, 0.1, "hud_panel_weapons_noncurrent_scale")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Show weapon ID as:"))); - me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "hud_panel_weapons_label", "0", ZCTX(_("SHOWAS^None")))); - me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "hud_panel_weapons_label", "1", _("Number"))); - me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "hud_panel_weapons_label", "2", _("Bind"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Show weapon ID as:"))); + me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "hud_panel_weapons_label", "0", ZCTX(_("SHOWAS^None")))); + me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "hud_panel_weapons_label", "1", _("Number"))); + me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "hud_panel_weapons_label", "2", _("Bind"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Weapon ID scale:"))); - setDependent(e, "hud_panel_weapons_label", 1, 2); - me.TD(me, 1, 2.4, e = makeXonoticSlider(0.1, 1, 0.05, "hud_panel_weapons_label_scale")); - setDependent(e, "hud_panel_weapons_label", 1, 2); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Weapon ID scale:"))); + setDependent(e, "hud_panel_weapons_label", 1, 2); + me.TD(me, 1, 2.4, e = makeXonoticSlider(0.1, 1, 0.05, "hud_panel_weapons_label_scale")); + setDependent(e, "hud_panel_weapons_label", 1, 2); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8/2, e = makeXonoticCheckBox(0, "hud_panel_weapons_accuracy", _("Show Accuracy"))); - me.TD(me, 1, 3.8/2, e = makeXonoticCheckBox(0, "hud_panel_weapons_ammo", _("Show Ammo"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8 / 2, e = makeXonoticCheckBox(0, "hud_panel_weapons_accuracy", _("Show Accuracy"))); + me.TD(me, 1, 3.8 / 2, e = makeXonoticCheckBox(0, "hud_panel_weapons_ammo", _("Show Ammo"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Ammo bar alpha:"))); - setDependent(e, "hud_panel_weapons_ammo", 1, 1); - me.TD(me, 1, 2.4, e = makeXonoticSlider(0.1, 1, 0.1, "hud_panel_weapons_ammo_alpha")); - setDependent(e, "hud_panel_weapons_ammo", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Ammo bar alpha:"))); + setDependent(e, "hud_panel_weapons_ammo", 1, 1); + me.TD(me, 1, 2.4, e = makeXonoticSlider(0.1, 1, 0.1, "hud_panel_weapons_ammo_alpha")); + setDependent(e, "hud_panel_weapons_ammo", 1, 1); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Ammo bar color:"))); + setDependent(e, "hud_panel_weapons_ammo", 1, 1); + me.TD(me, 2, 2.4, e = makeXonoticColorpickerString("hud_panel_weapons_ammo_color", "hud_panel_weapons_ammo_color")); + setDependent(e, "hud_panel_weapons_ammo", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Ammo bar color:"))); - setDependent(e, "hud_panel_weapons_ammo", 1, 1); - me.TD(me, 2, 2.4, e = makeXonoticColorpickerString("hud_panel_weapons_ammo_color", "hud_panel_weapons_ammo_color")); - setDependent(e, "hud_panel_weapons_ammo", 1, 1); - me.TR(me); } diff --git a/qcsrc/menu/xonotic/dialog_hudsetup_exit.qc b/qcsrc/menu/xonotic/dialog_hudsetup_exit.qc index 802ee96b5..77c50f544 100644 --- a/qcsrc/menu/xonotic/dialog_hudsetup_exit.qc +++ b/qcsrc/menu/xonotic/dialog_hudsetup_exit.qc @@ -16,131 +16,140 @@ void XonoticHUDExitDialog_fill(entity me) hudskinlist = makeXonoticHUDSkinList(); me.TR(me); - me.TD(me, 1, 4, makeXonoticHeaderLabel(_("HUD skins"))); + me.TD(me, 1, 4, makeXonoticHeaderLabel(_("HUD skins"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.7, e = makeXonoticTextLabel(0.5, _("Filter:"))); - me.TD(me, 1, 2.9, e = makeXonoticInputBox(0, string_null)); - e.onChange = HUDSkinList_Filter_Change; - e.onChangeEntity = hudskinlist; + me.TDempty(me, 0.2); + me.TD(me, 1, 0.7, e = makeXonoticTextLabel(0.5, _("Filter:"))); + me.TD(me, 1, 2.9, e = makeXonoticInputBox(0, string_null)); + e.onChange = HUDSkinList_Filter_Change; + e.onChangeEntity = hudskinlist; me.TR(me); - me.TD(me, 12, 4, hudskinlist); + me.TD(me, 12, 4, hudskinlist); me.gotoRC(me, me.rows - 4, 0); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.4, e = makeXonoticButton(_("Refresh"), '0 0 0')); - e.onClick = HUDSkinList_Refresh_Click; - e.onClickEntity = hudskinlist; - me.TD(me, 1, 2.2, e = makeXonoticButton(_("Set skin"), '0 0 0')); - e.onClick = SetHUDSkin_Click; - e.onClickEntity = hudskinlist; + me.TDempty(me, 0.2); + me.TD(me, 1, 1.4, e = makeXonoticButton(_("Refresh"), '0 0 0')); + e.onClick = HUDSkinList_Refresh_Click; + e.onClickEntity = hudskinlist; + me.TD(me, 1, 2.2, e = makeXonoticButton(_("Set skin"), '0 0 0')); + e.onClick = SetHUDSkin_Click; + e.onClickEntity = hudskinlist; me.gotoRC(me, me.rows - 2.5, 0); - me.TD(me, 1, 2, e = makeXonoticButton_T(_("Save current skin"), '0 0 0', + me.TD(me, 1, 2, e = makeXonoticButton_T(_("Save current skin"), '0 0 0', "Note: HUD skins are saved in data/data/ directory and can be manually renamed/deleted from there")); - e.onClick = SaveHUDSkin_Click; - e.onClickEntity = hudskinlist; - me.TD(me, 1, 2, e = makeXonoticInputBox(0, string_null)); - e.onChange = HUDSkinList_SavedName_Change; - e.onChangeEntity = hudskinlist; + e.onClick = SaveHUDSkin_Click; + e.onClickEntity = hudskinlist; + me.TD(me, 1, 2, e = makeXonoticInputBox(0, string_null)); + e.onChange = HUDSkinList_SavedName_Change; + e.onChangeEntity = hudskinlist; - me.gotoRC(me, 0, 4.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Panel background defaults:"))); - me.TR(me); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Background:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg")); - e.addValue(e, _("Disable"), "0"); - e.addValue(e, "border_default", "border_default"); // this is a file name! - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:"))); - me.TD(me, 2, 2.6, e = makeXonoticColorpickerString("hud_panel_bg_color", "hud_panel_bg_color")); - me.TR(me); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Border size:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_border")); - e.addValue(e, _("Disable"), "0"); - for(i = 1; i <= 10; ++i) - e.addValue(e, strzone(ftos_decimals(i * 2, 0)), strzone(ftos(i * 2))); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_alpha")); - for(i = 1; i <= 10; ++i) - e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10))); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team color:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_color_team")); - e.addValue(e, _("Disable"), "0"); - for(i = 1; i <= 10; ++i) - e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10))); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TDempty(me, 0.4); - me.TD(me, 1, 3.6, e = makeXonoticCheckBox(0, "hud_configure_teamcolorforced", _("Test team color in configure mode"))); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Padding:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_padding")); - for(i = 0; i <= 10; ++i) - e.addValue(e, strzone(ftos_decimals(i - 5, 0)), strzone(ftos(i - 5))); - e.configureXonoticTextSliderValues(e); + me.gotoRC(me, 0, 4.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Panel background defaults:"))); + me.TR(me); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("Background:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg")); + e.addValue(e, _("Disable"), "0"); + e.addValue(e, "border_default", "border_default"); // this is a file name! + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:"))); + me.TD(me, 2, 2.6, e = makeXonoticColorpickerString("hud_panel_bg_color", "hud_panel_bg_color")); + me.TR(me); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Border size:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_border")); + e.addValue(e, _("Disable"), "0"); + for (i = 1; i <= 10; ++i) { + e.addValue(e, strzone(ftos_decimals(i * 2, 0)), strzone(ftos(i * 2))); + } + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_alpha")); + for (i = 1; i <= 10; ++i) { + e.addValue(e, strzone(ftos_decimals(i / 10, 1)), strzone(ftos(i / 10))); + } + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team color:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_color_team")); + e.addValue(e, _("Disable"), "0"); + for (i = 1; i <= 10; ++i) { + e.addValue(e, strzone(ftos_decimals(i / 10, 1)), strzone(ftos(i / 10))); + } + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TDempty(me, 0.4); + me.TD(me, 1, 3.6, e = makeXonoticCheckBox(0, "hud_configure_teamcolorforced", _("Test team color in configure mode"))); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Padding:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_panel_bg_padding")); + for (i = 0; i <= 10; ++i) { + e.addValue(e, strzone(ftos_decimals(i - 5, 0)), strzone(ftos(i - 5))); + } + e.configureXonoticTextSliderValues(e); me.TR(me); - me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("HUD Dock:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_dock")); - e.addValue(e, ZCTX(_("DOCK^Disabled")), "0"); - e.addValue(e, ZCTX(_("DOCK^Small")), "dock_small"); - e.addValue(e, ZCTX(_("DOCK^Medium")), "dock_medium"); - e.addValue(e, ZCTX(_("DOCK^Large")), "dock_large"); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:"))); - me.TD(me, 2, 2.6, e = makeXonoticColorpickerString("hud_dock_color", "hud_dock_color")); - me.TR(me); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_dock_alpha")); - for(i = 1; i <= 10; ++i) - e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10))); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team color:"))); - me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_dock_color_team")); - e.addValue(e, _("Disable"), "0"); - for(i = 1; i <= 10; ++i) - e.addValue(e, strzone(ftos_decimals(i/10, 1)), strzone(ftos(i/10))); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Grid settings:"))); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_configure_grid", _("Snap panels to grid"))); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Grid size:"))); - setDependent(e, "hud_configure_grid", 1, 1); - me.TD(me, 1, 0.2, e = makeXonoticTextLabel(0, _("X:"))); - setDependent(e, "hud_configure_grid", 1, 1); - me.TD(me, 1, 1.1, e = makeXonoticTextSlider("hud_configure_grid_xsize")); - for(i = 1; i <= 14; ++i) - e.addValue(e, strzone(sprintf("%.1f%%", i/2)), strzone(ftos(i/200))); - e.configureXonoticTextSliderValues(e); - setDependent(e, "hud_configure_grid", 1, 1); - me.TD(me, 1, 0.2, e = makeXonoticTextLabel(0, _("Y:"))); - setDependent(e, "hud_configure_grid", 1, 1); - me.TD(me, 1, 1.1, e = makeXonoticTextSlider("hud_configure_grid_ysize")); - for(i = 1; i <= 14; ++i) - e.addValue(e, strzone(sprintf("%.1f%%", i/2)), strzone(ftos(i/200))); - e.configureXonoticTextSliderValues(e); - setDependent(e, "hud_configure_grid", 1, 1); + me.TD(me, 1, 1.4, e = makeXonoticTextLabel(0, _("HUD Dock:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_dock")); + e.addValue(e, ZCTX(_("DOCK^Disabled")), "0"); + e.addValue(e, ZCTX(_("DOCK^Small")), "dock_small"); + e.addValue(e, ZCTX(_("DOCK^Medium")), "dock_medium"); + e.addValue(e, ZCTX(_("DOCK^Large")), "dock_large"); + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Color:"))); + me.TD(me, 2, 2.6, e = makeXonoticColorpickerString("hud_dock_color", "hud_dock_color")); + me.TR(me); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Alpha:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_dock_alpha")); + for (i = 1; i <= 10; ++i) { + e.addValue(e, strzone(ftos_decimals(i / 10, 1)), strzone(ftos(i / 10))); + } + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Team color:"))); + me.TD(me, 1, 2.6, e = makeXonoticTextSlider("hud_dock_color_team")); + e.addValue(e, _("Disable"), "0"); + for (i = 1; i <= 10; ++i) { + e.addValue(e, strzone(ftos_decimals(i / 10, 1)), strzone(ftos(i / 10))); + } + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Grid settings:"))); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 3.8, e = makeXonoticCheckBox(0, "hud_configure_grid", _("Snap panels to grid"))); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Grid size:"))); + setDependent(e, "hud_configure_grid", 1, 1); + me.TD(me, 1, 0.2, e = makeXonoticTextLabel(0, _("X:"))); + setDependent(e, "hud_configure_grid", 1, 1); + me.TD(me, 1, 1.1, e = makeXonoticTextSlider("hud_configure_grid_xsize")); + for (i = 1; i <= 14; ++i) { + e.addValue(e, strzone(sprintf("%.1f%%", i / 2)), strzone(ftos(i / 200))); + } + e.configureXonoticTextSliderValues(e); + setDependent(e, "hud_configure_grid", 1, 1); + me.TD(me, 1, 0.2, e = makeXonoticTextLabel(0, _("Y:"))); + setDependent(e, "hud_configure_grid", 1, 1); + me.TD(me, 1, 1.1, e = makeXonoticTextSlider("hud_configure_grid_ysize")); + for (i = 1; i <= 14; ++i) { + e.addValue(e, strzone(sprintf("%.1f%%", i / 2)), strzone(ftos(i / 200))); + } + e.configureXonoticTextSliderValues(e); + setDependent(e, "hud_configure_grid", 1, 1); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, e = makeXonoticCommandButton(_("Exit setup"), '0 0 0', "_hud_configure 0", 1)); + me.TD(me, 1, me.columns, e = makeXonoticCommandButton(_("Exit setup"), '0 0 0', "_hud_configure 0", 1)); } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer.qc b/qcsrc/menu/xonotic/dialog_multiplayer.qc index 41ab2f93f..60b4cbff9 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer.qc @@ -11,13 +11,13 @@ void XonoticMultiplayerDialog_fill(entity me) entity mc, e; mc = makeXonoticTabController(me.rows - 1); me.TR(me); - me.TD(me, 1, 1, e = mc.makeTabButton_T(mc, _("Servers"), makeXonoticServerListTab(), + me.TD(me, 1, 1, e = mc.makeTabButton_T(mc, _("Servers"), makeXonoticServerListTab(), _("Find servers to play on"))); - me.TD(me, 1, 1, e = mc.makeTabButton_T(mc, _("Create"), makeXonoticServerCreateTab(), + me.TD(me, 1, 1, e = mc.makeTabButton_T(mc, _("Create"), makeXonoticServerCreateTab(), _("Host your own game"))); - me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Media"), makeXonoticMediaTab())); - me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Profile"), makeXonoticProfileTab())); + me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Media"), makeXonoticMediaTab())); + me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Profile"), makeXonoticProfileTab())); me.TR(me); - me.TD(me, me.rows - 1, me.columns, mc); + me.TD(me, me.rows - 1, me.columns, mc); } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create.qh b/qcsrc/menu/xonotic/dialog_multiplayer_create.qh index e27552286..aa7271af3 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create.qh @@ -7,7 +7,7 @@ CLASS(XonoticServerCreateTab, XonoticTab) METHOD(XonoticServerCreateTab, gameTypeSelectNotify, void(entity)); ATTRIB(XonoticServerCreateTab, intendedWidth, float, 0.9); ATTRIB(XonoticServerCreateTab, rows, float, 23); - ATTRIB(XonoticServerCreateTab, columns, float, 6.2); // added extra .2 for center space + ATTRIB(XonoticServerCreateTab, columns, float, 6.2); // added extra .2 for center space ATTRIB(XonoticServerCreateTab, mapListBox, entity); ATTRIB(XonoticServerCreateTab, sliderFraglimit, entity); diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mapinfo.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create_mapinfo.qc index 2f2ab901a..c62f8a088 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mapinfo.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mapinfo.qc @@ -12,8 +12,7 @@ void XonoticMapInfoDialog_loadMapInfo(entity me, int i, entity mlb) me.startButton.onClickEntity = mlb; MapInfo_Get_ByID(i); - if(me.currentMapBSPName) - { + if (me.currentMapBSPName) { strunzone(me.currentMapBSPName); strunzone(me.currentMapTitle); strunzone(me.currentMapAuthor); @@ -30,13 +29,13 @@ void XonoticMapInfoDialog_loadMapInfo(entity me, int i, entity mlb) me.titleLabel.setText(me.titleLabel, me.currentMapTitle); me.authorLabel.setText(me.authorLabel, me.currentMapAuthor); me.descriptionLabel.setText(me.descriptionLabel, me.currentMapDescription); - if(draw_PictureSize(me.currentMapPreviewImage) == '0 0 0') + if (draw_PictureSize(me.currentMapPreviewImage) == '0 0 0') { me.previewImage.src = "nopreview_map"; - else + } else { me.previewImage.src = me.currentMapPreviewImage; + } - for(i = 0; i < GameType_GetTotalCount(); ++i) - { + for (i = 0; i < GameType_GetTotalCount(); ++i) { entity e; e = me.(typeLabels[i]); e.disabled = !(MapInfo_Map_supportedGametypes & GameType_GetID(i).m_flags); @@ -50,50 +49,49 @@ void XonoticMapInfoDialog_fill(entity me) int i; float w, wgt, n; me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, me.rows - 2, 3, e = makeXonoticImage(string_null, 4.0/3.0)); - me.previewImage = e; - me.gotoRC(me, 0, 3.5); me.setFirstColumn(me, me.currentColumn); + me.TDempty(me, 0.2); + me.TD(me, me.rows - 2, 3, e = makeXonoticImage(string_null, 4.0 / 3.0)); + me.previewImage = e; + me.gotoRC(me, 0, 3.5); + me.setFirstColumn(me, me.currentColumn); w = me.columns - me.currentColumn; - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Title:"))); - me.TD(me, 1, w-1, e = makeXonoticTextLabel(0, "")); - e.colorL = SKINCOLOR_MAPLIST_TITLE; - e.allowCut = 1; - me.titleLabel = e; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Title:"))); + me.TD(me, 1, w - 1, e = makeXonoticTextLabel(0, "")); + e.colorL = SKINCOLOR_MAPLIST_TITLE; + e.allowCut = 1; + me.titleLabel = e; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Author:"))); - me.TD(me, 1, w-1, e = makeXonoticTextLabel(0, "")); - e.colorL = SKINCOLOR_MAPLIST_AUTHOR; - e.allowCut = 1; - me.authorLabel = e; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Author:"))); + me.TD(me, 1, w - 1, e = makeXonoticTextLabel(0, "")); + e.colorL = SKINCOLOR_MAPLIST_AUTHOR; + e.allowCut = 1; + me.authorLabel = e; me.TR(me); - me.TD(me, 1, w, e = makeXonoticTextLabel(0, _("Game types:"))); + me.TD(me, 1, w, e = makeXonoticTextLabel(0, _("Game types:"))); n = ceil(GameType_GetTotalCount() / (me.rows - 6)); wgt = (w - 0.2) / n; - for(i = 0; i < GameType_GetTotalCount(); ++i) - { - if(mod(i, n) == 0) - { + for (i = 0; i < GameType_GetTotalCount(); ++i) { + if (mod(i, n) == 0) { me.TR(me); me.TDempty(me, 0.2); } me.TD(me, 1, wgt, e = makeXonoticTextLabel(0, MapInfo_Type_ToText(GameType_GetID(i)))); - me.(typeLabels[i]) = e; + me.(typeLabels[i]) = e; } me.gotoRC(me, me.rows - 2, 0); - me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, "")); - e.allowCut = 1; - me.descriptionLabel = e; + me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, "")); + e.allowCut = 1; + me.descriptionLabel = e; me.gotoRC(me, me.rows - 1, 0); - me.TDempty(me, 0.5); + me.TDempty(me, 0.5); - me.TD(me, 1, me.columns - 5.5, e = makeXonoticButton(_("Close"), '0 0 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; - me.TD(me, 1, me.columns - 5.5, me.startButton = e = makeXonoticButton(ZCTX(_("MAP^Play")), '0 0 0')); - me.startButton.onClick = MapList_LoadMap; - me.startButton.onClickEntity = NULL; // filled later + me.TD(me, 1, me.columns - 5.5, e = makeXonoticButton(_("Close"), '0 0 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; + me.TD(me, 1, me.columns - 5.5, me.startButton = e = makeXonoticButton(ZCTX(_("MAP^Play")), '0 0 0')); + me.startButton.onClick = MapList_LoadMap; + me.startButton.onClickEntity = NULL; // filled later } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc index 0ea24a889..9c69a78ee 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc @@ -22,28 +22,34 @@ string WeaponArenaString() string s; float n, i; s = cvar_string("g_weaponarena"); - if(s == "0") + if (s == "0") { return ""; - if(s == "all" || s == "1") + } + if (s == "all" || s == "1") { return _("All Weapons Arena"); - if(s == "most") + } + if (s == "most") { return _("Most Weapons Arena"); - if(s == weaponarenastring_cvar) + } + if (s == weaponarenastring_cvar) { return weaponarenastring; - if(weaponarenastring) + } + if (weaponarenastring) { strunzone(weaponarenastring); - if(weaponarenastring_cvar) + } + if (weaponarenastring_cvar) { strunzone(weaponarenastring_cvar); + } weaponarenastring_cvar = strzone(s); n = tokenize_console(s); s = ""; - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { FOREACH(Weapons, it != WEP_Null, { - if(argv(i) == it.netname) + if (argv(i) == it.netname) { s = strcat(s, " & ", it.m_name); + } }); } s = sprintf(_("%s Arena"), substring(s, 3, strlen(s) - 3)); @@ -57,64 +63,89 @@ string XonoticMutatorsDialog_toString(entity me) { string s; s = ""; - if(cvar("g_dodging")) + if (cvar("g_dodging")) { s = strcat(s, ", ", _("Dodging")); - if(cvar("g_instagib")) + } + if (cvar("g_instagib")) { s = strcat(s, ", ", _("InstaGib")); - if(cvar("g_new_toys")) + } + if (cvar("g_new_toys")) { s = strcat(s, ", ", _("New Toys")); - if(cvar("g_nix")) + } + if (cvar("g_nix")) { s = strcat(s, ", ", _("NIX")); - if(cvar("g_rocket_flying")) + } + if (cvar("g_rocket_flying")) { s = strcat(s, ", ", _("Rocket Flying")); - if(cvar("g_invincible_projectiles")) + } + if (cvar("g_invincible_projectiles")) { s = strcat(s, ", ", _("Invincible Projectiles")); - if(cvar_string("g_weaponarena") != "0") + } + if (cvar_string("g_weaponarena") != "0") { s = strcat(s, ", ", WeaponArenaString()); - else if(cvar("g_balance_blaster_weaponstartoverride") == 0) + } else if (cvar("g_balance_blaster_weaponstartoverride") == 0) { s = strcat(s, ", ", _("No start weapons")); - if(cvar("sv_gravity") < stof(cvar_defstring("sv_gravity"))) + } + if (cvar("sv_gravity") < stof(cvar_defstring("sv_gravity"))) { s = strcat(s, ", ", _("Low gravity")); - if(cvar("g_cloaked")) + } + if (cvar("g_cloaked")) { s = strcat(s, ", ", _("Cloaked")); - if(cvar("g_grappling_hook")) + } + if (cvar("g_grappling_hook")) { s = strcat(s, ", ", _("Hook")); - if(cvar("g_midair")) + } + if (cvar("g_midair")) { s = strcat(s, ", ", _("Midair")); - if(cvar("g_vampire")) + } + if (cvar("g_vampire")) { s = strcat(s, ", ", _("Vampire")); - if(cvar("g_pinata")) + } + if (cvar("g_pinata")) { s = strcat(s, ", ", _("Piñata")); - if(cvar("g_weapon_stay")) + } + if (cvar("g_weapon_stay")) { s = strcat(s, ", ", _("Weapons stay")); - if(cvar("g_bloodloss") > 0) + } + if (cvar("g_bloodloss") > 0) { s = strcat(s, ", ", _("Blood loss")); - if(cvar("g_jetpack")) + } + if (cvar("g_jetpack")) { s = strcat(s, ", ", _("Jet pack")); - if(cvar("g_buffs") > 0) + } + if (cvar("g_buffs") > 0) { s = strcat(s, ", ", _("Buffs")); - if(cvar("g_overkill")) + } + if (cvar("g_overkill")) { s = strcat(s, ", ", _("Overkill")); - if(cvar("g_powerups") == 0) + } + if (cvar("g_powerups") == 0) { s = strcat(s, ", ", _("No powerups")); - if(cvar("g_powerups") > 0) + } + if (cvar("g_powerups") > 0) { s = strcat(s, ", ", _("Powerups")); - if(cvar("g_touchexplode") > 0) + } + if (cvar("g_touchexplode") > 0) { s = strcat(s, ", ", _("Touch explode")); - if(s == "") + } + if (s == "") { return ZCTX(_("MUT^None")); - else + } else { return substring(s, 2, strlen(s) - 2); + } } float checkCompatibility_pinata(entity me) { - if(cvar("g_instagib")) + if (cvar("g_instagib")) { return 0; - if(cvar("g_nix")) + } + if (cvar("g_nix")) { return 0; - if(cvar_string("g_weaponarena") != "0") + } + if (cvar_string("g_weaponarena") != "0") { return 0; + } return 1; } float checkCompatibility_weaponstay(entity me) @@ -123,28 +154,37 @@ float checkCompatibility_weaponstay(entity me) } float checkCompatibility_newtoys(entity me) { - if(cvar("g_instagib")) + if (cvar("g_instagib")) { return 0; - if(cvar_string("g_weaponarena") == "most") + } + if (cvar_string("g_weaponarena") == "most") { return 1; - if(cvar_string("g_weaponarena") == "all" || cvar_string("g_weaponarena") == "1") + } + if (cvar_string("g_weaponarena") == "all" || cvar_string("g_weaponarena") == "1") { return 1; - if(cvar_string("g_weaponarena") != "0") + } + if (cvar_string("g_weaponarena") != "0") { return 0; + } return 1; } float checkCompatibility_weaponarena_weapon(entity me) { - if(cvar("g_instagib")) + if (cvar("g_instagib")) { return 0; - if(cvar_string("g_weaponarena") == "most") + } + if (cvar_string("g_weaponarena") == "most") { return 0; - if(cvar_string("g_weaponarena") == "all" || cvar_string("g_weaponarena") == "1") + } + if (cvar_string("g_weaponarena") == "all" || cvar_string("g_weaponarena") == "1") { return 0; - if(cvar_string("g_weaponarena") == "0") + } + if (cvar_string("g_weaponarena") == "0") { return 0; - if(cvar_string("g_balance_blaster_weaponstartoverride") == "0") + } + if (cvar_string("g_balance_blaster_weaponstartoverride") == "0") { return 0; + } return 1; } @@ -153,147 +193,150 @@ void XonoticMutatorsDialog_fill(entity me) entity e, s, w; float i, j; me.TR(me); - me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Gameplay mutators:"))); + me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Gameplay mutators:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_dodging", _("Dodging"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_dodging", _("Dodging"), _("Enable dodging"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_touchexplode", _("Touch explode"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_touchexplode", _("Touch explode"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_cloaked", _("Cloaked"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_cloaked", _("Cloaked"), _("All players are almost invisible"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_buffs", _("Buffs"))); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_buffs", _("Buffs"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_midair", _("Midair"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_midair", _("Midair"), _("Only possible to inflict damage on your enemy while he's airborne"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_vampire", _("Vampire"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_vampire", _("Vampire"), _("Damage done to your enemy gets added to your own health"))); - setDependent(e, "g_instagib", 0, 0); + setDependent(e, "g_instagib", 0, 0); me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticSlider_T(10, 50, 1, "g_bloodloss", - _("Amount of health below which your player gets stunned because of blood loss")); - me.TD(me, 1, 1.8, e = makeXonoticSliderCheckBox(0, 1, s, _("Blood loss"))); - setDependent(e, "g_instagib", 0, 0); + me.TDempty(me, 0.2); + s = makeXonoticSlider_T(10, 50, 1, "g_bloodloss", + _("Amount of health below which your player gets stunned because of blood loss")); + me.TD(me, 1, 1.8, e = makeXonoticSliderCheckBox(0, 1, s, _("Blood loss"))); + setDependent(e, "g_instagib", 0, 0); me.TR(me); - me.TDempty(me, 0.4); - me.TD(me, 1, 1.6, s); + me.TDempty(me, 0.4); + me.TD(me, 1, 1.6, s); me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticSlider_T(80, 400, 8, "sv_gravity", - _("Make things fall to the ground slower, lower value means lower gravity")); - s.valueDigits = 0; - s.valueDisplayMultiplier = 0.125; // show gravity in percent - me.TD(me, 1, 1.8, e = makeXonoticSliderCheckBox(800, 1, s, _("Low gravity"))); - e.savedValue = 200; // good on silvercity + me.TDempty(me, 0.2); + s = makeXonoticSlider_T(80, 400, 8, "sv_gravity", + _("Make things fall to the ground slower, lower value means lower gravity")); + s.valueDigits = 0; + s.valueDisplayMultiplier = 0.125; // show gravity in percent + me.TD(me, 1, 1.8, e = makeXonoticSliderCheckBox(800, 1, s, _("Low gravity"))); + e.savedValue = 200; // good on silvercity me.TR(me); - me.TDempty(me, 0.4); - me.TD(me, 1, 1.6, s); + me.TDempty(me, 0.4); + me.TD(me, 1, 1.6, s); me.TR(me); - me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Weapon & item mutators:"))); + me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Weapon & item mutators:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_grappling_hook", _("Grappling hook"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_grappling_hook", _("Grappling hook"), _("Players spawn with the grappling hook"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_jetpack", _("Jet pack"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_jetpack", _("Jet pack"), _("Players spawn with the jetpack"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_invincible_projectiles", _("Invincible Projectiles"))); - setDependent(e, "g_instagib", 0, 0); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_invincible_projectiles", _("Invincible Projectiles"))); + setDependent(e, "g_instagib", 0, 0); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_new_toys", _("New Toys"))); - setDependentWeird(e, checkCompatibility_newtoys); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_new_toys", _("New Toys"))); + setDependentWeird(e, checkCompatibility_newtoys); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_rocket_flying", _("Rocket Flying"))); - setDependent(e, "g_instagib", 0, 0); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "g_rocket_flying", _("Rocket Flying"))); + setDependent(e, "g_instagib", 0, 0); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_pinata", _("Piñata"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_pinata", _("Piñata"), _("Players will drop all weapons they possessed when they are killed"))); - setDependentWeird(e, checkCompatibility_pinata); + setDependentWeird(e, checkCompatibility_pinata); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_weapon_stay", _("Weapons stay"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "g_weapon_stay", _("Weapons stay"), _("Weapons stay after they are picked up"))); - setDependentWeird(e, checkCompatibility_weaponstay); + setDependentWeird(e, checkCompatibility_weaponstay); me.TR(me); - me.gotoRC(me, 0, 2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 2, e = makeXonoticRadioButton(1, string_null, string_null, _("Regular (no arena)"))); + me.gotoRC(me, 0, 2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 2, e = makeXonoticRadioButton(1, string_null, string_null, _("Regular (no arena)"))); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticRadioButton_T(1, "g_weaponarena", "menu_weaponarena", _("Weapon arenas:"), + me.TD(me, 1, 2, e = makeXonoticRadioButton_T(1, "g_weaponarena", "menu_weaponarena", _("Weapon arenas:"), _("Selecting a weapon arena will give all players that weapon at spawn as well as unlimited ammo, and disable all other weapon pickups."))); - e.cvarValueIsAnotherCvar = true; - e.cvarOffValue = "0"; - for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i) - { + e.cvarValueIsAnotherCvar = true; + e.cvarOffValue = "0"; + for (i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i) { w = Weapons_from(i); - if(w.spawnflags & WEP_FLAG_HIDDEN) + if (w.spawnflags & WEP_FLAG_HIDDEN) { continue; - if((j & 1) == 0) + } + if ((j & 1) == 0) { me.TR(me); + } me.TDempty(me, 0.2); me.TD(me, 1, 1.8, e = makeXonoticWeaponarenaCheckBox(strzone(w.netname), strzone(w.m_name))); - setDependentWeird(e, checkCompatibility_weaponarena_weapon); + setDependentWeird(e, checkCompatibility_weaponarena_weapon); ++j; } me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_weaponarena", "most", _("Most weapons"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_weaponarena", "most", _("Most weapons"), _("Selecting a weapon arena will give all players that weapon at spawn as well as unlimited ammo, and disable all other weapon pickups."))); - e.cvarOffValue = "0"; + e.cvarOffValue = "0"; me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_weaponarena", "all", _("All weapons"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_weaponarena", "all", _("All weapons"), _("Selecting a weapon arena will give all players that weapon at spawn as well as unlimited ammo, and disable all other weapon pickups."))); - e.cvarOffValue = "0"; + e.cvarOffValue = "0"; me.TR(me); - me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Special arenas:"))); + me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Special arenas:"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_instagib", "1", _("InstaGib"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_instagib", "1", _("InstaGib"), _("Players will be given only one weapon, which can instantly kill the opponent with a single shot. If the player runs out of ammo, he will have 10 seconds to find some or if he fails to do so, face death. The secondary fire mode does not inflict any damage but is good for doing trickjumps."))); - e.cvarOffValue = "0"; + e.cvarOffValue = "0"; me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_nix", "1", _("NIX"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_nix", "1", _("NIX"), _("No items Xonotic - instead of pickup items, everyone plays with the same weapon. After some time, a countdown will start, after which everyone will switch to another weapon."))); - e.cvarOffValue = "0"; + e.cvarOffValue = "0"; me.TR(me); - me.TDempty(me, 0.4); - me.TD(me, 1, 1.6, e = makeXonoticCheckBox_T(0, "g_nix_with_blaster", _("with blaster"), + me.TDempty(me, 0.4); + me.TD(me, 1, 1.6, e = makeXonoticCheckBox_T(0, "g_nix_with_blaster", _("with blaster"), _("Always carry the blaster as an additional weapon in Nix"))); - setDependent(e, "g_nix", 1, 1); + setDependent(e, "g_nix", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_balance_blaster_weaponstartoverride", "0", _("No start weapons"), "-")); - e.cvarOffValue = "-1"; - makeMulti(e, "g_balance_shotgun_weaponstartoverride g_balance_machinegun_weaponstartoverride g_balance_devastator_weaponstartoverride g_balance_minelayer_weaponstartoverride g_balance_electro_weaponstartoverride g_balance_crylink_weaponstartoverride g_balance_hagar_weaponstartoverride g_balance_porto_weaponstartoverride g_balance_vaporizer_weaponstartoverride g_balance_hook_weaponstartoverride g_balance_rifle_weaponstartoverride g_balance_fireball_weaponstartoverride g_balance_seeker_weaponstartoverride g_balance_tuba_weaponstartoverride g_balance_arc_weaponstartoverride g_balance_vortex_weaponstartoverride g_balance_mortar_weaponstartoverride"); + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticRadioButton_T(1, "g_balance_blaster_weaponstartoverride", "0", _("No start weapons"), "-")); + e.cvarOffValue = "-1"; + makeMulti(e, "g_balance_shotgun_weaponstartoverride g_balance_machinegun_weaponstartoverride g_balance_devastator_weaponstartoverride g_balance_minelayer_weaponstartoverride g_balance_electro_weaponstartoverride g_balance_crylink_weaponstartoverride g_balance_hagar_weaponstartoverride g_balance_porto_weaponstartoverride g_balance_vaporizer_weaponstartoverride g_balance_hook_weaponstartoverride g_balance_rifle_weaponstartoverride g_balance_fireball_weaponstartoverride g_balance_seeker_weaponstartoverride g_balance_tuba_weaponstartoverride g_balance_arc_weaponstartoverride g_balance_vortex_weaponstartoverride g_balance_mortar_weaponstartoverride"); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } .void(entity) refilter; void XonoticMutatorsDialog_close(entity me) { - if(me.refilterEntity) + if (me.refilterEntity) { me.refilterEntity.refilter(me.refilterEntity); + } SUPER(XonoticMutatorsDialog).close(me); } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_join.qc b/qcsrc/menu/xonotic/dialog_multiplayer_join.qc index a34d0d80a..4b5edb6c3 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_join.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_join.qc @@ -17,8 +17,8 @@ entity makeXonoticServerListTab() void XonoticServerListTab_refresh(entity this, entity slist) { - bool clear = false; - slist.refreshServerList(slist, clear ? REFRESHSERVERLIST_RESET : REFRESHSERVERLIST_ASK); + bool clear = false; + slist.refreshServerList(slist, clear ? REFRESHSERVERLIST_RESET : REFRESHSERVERLIST_ASK); } void XonoticServerListTab_fill(entity me) @@ -28,61 +28,61 @@ void XonoticServerListTab_fill(entity me) slist = makeXonoticServerList(); me.gotoRC(me, 0.5, 0); - me.TD(me, 1, 0.5, e = makeXonoticTextLabel(1, _("Filter:"))); - me.TD(me, 1, 2, e = makeXonoticInputBox(0, string_null)); - e.onChange = ServerList_Filter_Change; - e.onChangeEntity = slist; - slist.controlledTextbox = e; + me.TD(me, 1, 0.5, e = makeXonoticTextLabel(1, _("Filter:"))); + me.TD(me, 1, 2, e = makeXonoticInputBox(0, string_null)); + e.onChange = ServerList_Filter_Change; + e.onChangeEntity = slist; + slist.controlledTextbox = e; me.gotoRC(me, 0.5, 2.6); - me.TD(me, 1, 0.9, e = makeXonoticCheckBox(0, "menu_slist_categories", ZCTX(_("SRVS^Categories")))); - e.onClickEntity = slist; - e.onClick = ServerList_Categories_Click; - me.TD(me, 1, 0.6, e = makeXonoticCheckBox_T(0, "menu_slist_showempty", ZCTX(_("SRVS^Empty")), + me.TD(me, 1, 0.9, e = makeXonoticCheckBox(0, "menu_slist_categories", ZCTX(_("SRVS^Categories")))); + e.onClickEntity = slist; + e.onClick = ServerList_Categories_Click; + me.TD(me, 1, 0.6, e = makeXonoticCheckBox_T(0, "menu_slist_showempty", ZCTX(_("SRVS^Empty")), _("Show empty servers"))); - slist.filterShowEmpty = e.checked; - e.onClickEntity = slist; - e.onClick = ServerList_ShowEmpty_Click; - me.TD(me, 1, 0.6, e = makeXonoticCheckBox_T(0, "menu_slist_showfull", ZCTX(_("SRVS^Full")), + slist.filterShowEmpty = e.checked; + e.onClickEntity = slist; + e.onClick = ServerList_ShowEmpty_Click; + me.TD(me, 1, 0.6, e = makeXonoticCheckBox_T(0, "menu_slist_showfull", ZCTX(_("SRVS^Full")), _("Show full servers that have no slots available"))); - slist.filterShowFull = e.checked; - e.onClickEntity = slist; - e.onClick = ServerList_ShowFull_Click; - me.TD(me, 1, 0.6, e = makeXonoticCheckBox_T(0, "net_slist_pause", _("Pause"), + slist.filterShowFull = e.checked; + e.onClickEntity = slist; + e.onClick = ServerList_ShowFull_Click; + me.TD(me, 1, 0.6, e = makeXonoticCheckBox_T(0, "net_slist_pause", _("Pause"), _("Pause updating the server list to prevent servers from \"jumping around\""))); - me.TD(me, 1, 1, e = makeXonoticButton_T(_("Refresh"), '0 0 0', _("Reload the server list"))); - e.onClick = XonoticServerListTab_refresh; - e.onClickEntity = slist; + me.TD(me, 1, 1, e = makeXonoticButton_T(_("Refresh"), '0 0 0', _("Reload the server list"))); + e.onClick = XonoticServerListTab_refresh; + e.onClickEntity = slist; me.gotoRC(me, 2, 0); - me.TD(me, 1, 1, slist.sortButton1 = makeXonoticButton(string_null, '0 0 0')); - me.TD(me, 1, 1, slist.sortButton2 = makeXonoticButton(string_null, '0 0 0')); - me.TD(me, 1, 1, slist.sortButton3 = makeXonoticButton(string_null, '0 0 0')); - me.TD(me, 1, 1, slist.sortButton4 = makeXonoticButton(string_null, '0 0 0')); - me.TD(me, 1, 1, slist.sortButton5 = makeXonoticButton(string_null, '0 0 0')); + me.TD(me, 1, 1, slist.sortButton1 = makeXonoticButton(string_null, '0 0 0')); + me.TD(me, 1, 1, slist.sortButton2 = makeXonoticButton(string_null, '0 0 0')); + me.TD(me, 1, 1, slist.sortButton3 = makeXonoticButton(string_null, '0 0 0')); + me.TD(me, 1, 1, slist.sortButton4 = makeXonoticButton(string_null, '0 0 0')); + me.TD(me, 1, 1, slist.sortButton5 = makeXonoticButton(string_null, '0 0 0')); me.TR(me); - me.TD(me, me.rows - 5, me.columns, slist); + me.TD(me, me.rows - 5, me.columns, slist); me.gotoRC(me, me.rows - 2, 0); - me.TD(me, 1, 0.6, e = makeXonoticTextLabel(0, _("Address:"))); - me.TD(me, 1, 2.9, e = makeXonoticInputBox(0, string_null)); - e.onEnter = ServerList_Connect_Click; - e.onEnterEntity = slist; - e.onChange = ServerList_Update_favoriteButton; - e.onChangeEntity = slist; - slist.ipAddressBox = e; - me.TD(me, 1, 1.5, e = makeXonoticButton("", '0 0 0')); - e.onClick = ServerList_Favorite_Click; - e.onClickEntity = slist; - slist.favoriteButton = e; - me.TD(me, 1, 1.5, e = makeXonoticButton_T(_("Info..."), '0 0 0', + me.TD(me, 1, 0.6, e = makeXonoticTextLabel(0, _("Address:"))); + me.TD(me, 1, 2.9, e = makeXonoticInputBox(0, string_null)); + e.onEnter = ServerList_Connect_Click; + e.onEnterEntity = slist; + e.onChange = ServerList_Update_favoriteButton; + e.onChangeEntity = slist; + slist.ipAddressBox = e; + me.TD(me, 1, 1.5, e = makeXonoticButton("", '0 0 0')); + e.onClick = ServerList_Favorite_Click; + e.onClickEntity = slist; + slist.favoriteButton = e; + me.TD(me, 1, 1.5, e = makeXonoticButton_T(_("Info..."), '0 0 0', _("Show more information about the currently highlighted server"))); - e.onClick = ServerList_Info_Click; - e.onClickEntity = slist; - slist.infoButton = e; + e.onClick = ServerList_Info_Click; + e.onClickEntity = slist; + slist.infoButton = e; me.TR(me); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("Join!"), '0 0 0')); - e.onClick = ServerList_Connect_Click; - e.onClickEntity = slist; - slist.connectButton = e; + me.TD(me, 1, me.columns, e = makeXonoticButton(_("Join!"), '0 0 0')); + e.onClick = ServerList_Connect_Click; + e.onClickEntity = slist; + slist.connectButton = e; } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_demo.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_demo.qc index 6ba33e2a7..8d27e1c9b 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_demo.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_demo.qc @@ -10,19 +10,16 @@ const float DMO_PLAY = 1; const float DMO_TIME = 2; void DemoConfirm_Check_Gamestatus(entity btn, entity me) { - if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, lets watch the demo - { - if(btn.democlicktype == DMO_PLAY) - { demolist.startDemo(demolist); } - else if(btn.democlicktype == DMO_TIME) - { demolist.timeDemo(demolist); } - } - else // already in a match, player has to confirm - { - if(btn.democlicktype == DMO_PLAY) - { DialogOpenButton_Click(btn, main.demostartconfirmDialog); } - else if(btn.democlicktype == DMO_TIME) - { DialogOpenButton_Click(btn, main.demotimeconfirmDialog); } + if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) { // we're not in a match, lets watch the demo + if (btn.democlicktype == DMO_PLAY) + { demolist.startDemo(demolist); } else if (btn.democlicktype == DMO_TIME) { + demolist.timeDemo(demolist); + } + } else { // already in a match, player has to confirm + if (btn.democlicktype == DMO_PLAY) + { DialogOpenButton_Click(btn, main.demostartconfirmDialog); } else if (btn.democlicktype == DMO_TIME) { + DialogOpenButton_Click(btn, main.demotimeconfirmDialog); + } } } @@ -39,28 +36,28 @@ void XonoticDemoBrowserTab_fill(entity me) demolist = makeXonoticDemoList(); me.TR(me); - me.TD(me, 1, 0.6, e = makeXonoticTextLabel(1, _("Filter:"))); - me.TD(me, 1, 2.9, e = makeXonoticInputBox(0, string_null)); - e.onChange = DemoList_Filter_Change; - e.onChangeEntity = demolist; + me.TD(me, 1, 0.6, e = makeXonoticTextLabel(1, _("Filter:"))); + me.TD(me, 1, 2.9, e = makeXonoticInputBox(0, string_null)); + e.onChange = DemoList_Filter_Change; + e.onChangeEntity = demolist; me.gotoRC(me, 0, 3.7); - me.TD(me, 1, 1.5, e = makeXonoticCheckBox(0, "cl_autodemo", _("Auto record demos"))); - me.TD(me, 1, 1, e = makeXonoticButton(_("Refresh"), '0 0 0')); - e.onClick = DemoList_Refresh_Click; - e.onClickEntity = demolist; + me.TD(me, 1, 1.5, e = makeXonoticCheckBox(0, "cl_autodemo", _("Auto record demos"))); + me.TD(me, 1, 1, e = makeXonoticButton(_("Refresh"), '0 0 0')); + e.onClick = DemoList_Refresh_Click; + e.onClickEntity = demolist; me.gotoRC(me, 1.5, 0); - me.TD(me, me.rows - 2.5, me.columns, demolist); + me.TD(me, me.rows - 2.5, me.columns, demolist); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns / 2, e = makeXonoticButton_T(_("Timedemo"), '0 0 0', + me.TD(me, 1, me.columns / 2, e = makeXonoticButton_T(_("Timedemo"), '0 0 0', _("Benchmark how fast your computer can run the highlighted demo"))); - e.democlicktype = DMO_TIME; - e.onClick = DemoConfirm_Check_Gamestatus; - e.onClickEntity = me; // demolist is global anyway - me.TD(me, 1, me.columns / 2, e = makeXonoticButton(ZCTX(_("DEMO^Play")), '0 0 0')); - e.democlicktype = DMO_PLAY; - e.onClick = DemoConfirm_Check_Gamestatus; - e.onClickEntity = me; // demolist is global anyway + e.democlicktype = DMO_TIME; + e.onClick = DemoConfirm_Check_Gamestatus; + e.onClickEntity = me; // demolist is global anyway + me.TD(me, 1, me.columns / 2, e = makeXonoticButton(ZCTX(_("DEMO^Play")), '0 0 0')); + e.democlicktype = DMO_PLAY; + e.onClick = DemoConfirm_Check_Gamestatus; + e.onClickEntity = me; // demolist is global anyway } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_startconfirm.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_startconfirm.qc index 068a8217b..561995025 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_startconfirm.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_startconfirm.qc @@ -10,15 +10,15 @@ void XonoticDemoStartConfirmDialog_fill(entity me) entity e; me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Playing a demo will disconnect you from the current match."))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Playing a demo will disconnect you from the current match."))); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Do you really wish to disconnect now?"))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Do you really wish to disconnect now?"))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticButton(_("Yes"), '1 0 0')); - e.onClick = Handle_StartDemo_Click; - e.onClickEntity = demolist; - me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, 1, e = makeXonoticButton(_("Yes"), '1 0 0')); + e.onClick = Handle_StartDemo_Click; + e.onClickEntity = demolist; + me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_timeconfirm.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_timeconfirm.qc index 55760d14a..ebbf21c9f 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_timeconfirm.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_demo_timeconfirm.qc @@ -10,15 +10,15 @@ void XonoticDemoTimeConfirmDialog_fill(entity me) entity e; me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Timing a demo will disconnect you from the current match."))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Timing a demo will disconnect you from the current match."))); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Do you really wish to disconnect now?"))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Do you really wish to disconnect now?"))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticButton(_("Yes"), '1 0 0')); - e.onClick = Handle_TimeDemo_Click; - e.onClickEntity = demolist; - me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, 1, e = makeXonoticButton(_("Yes"), '1 0 0')); + e.onClick = Handle_TimeDemo_Click; + e.onClickEntity = demolist; + me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_musicplayer.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_musicplayer.qc index c3606508a..e0effe123 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_musicplayer.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_musicplayer.qc @@ -22,61 +22,62 @@ void XonoticMusicPlayerTab_fill(entity me) float columns_nospacing = (me.columns - 0.2); me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticTextLabel(0, _("Filter:"))); - me.TD(me, 1, 2.5, e = makeXonoticInputBox(0, string_null)); - soundList = makeXonoticSoundList(); - e.onChange = SoundList_Filter_Change; - e.onChangeEntity = soundList; - playList = makeXonoticPlayList(); - soundList.playlist = playList; + me.TD(me, 1, 0.5, e = makeXonoticTextLabel(0, _("Filter:"))); + me.TD(me, 1, 2.5, e = makeXonoticInputBox(0, string_null)); + soundList = makeXonoticSoundList(); + e.onChange = SoundList_Filter_Change; + e.onChangeEntity = soundList; + playList = makeXonoticPlayList(); + soundList.playlist = playList; me.TR(me); - me.TD(me, me.rows - 4, columns_nospacing / 2, soundList); + me.TD(me, me.rows - 4, columns_nospacing / 2, soundList); me.gotoRC(me, me.rows - 3, 0); - me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Add")), '0 0 0')); - e.onClick = SoundList_Add; - e.onClickEntity = soundList; - me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Add all")), '0 0 0')); - e.onClick = SoundList_Add_All; - e.onClickEntity = soundList; + me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Add")), '0 0 0')); + e.onClick = SoundList_Add; + e.onClickEntity = soundList; + me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Add all")), '0 0 0')); + e.onClick = SoundList_Add_All; + e.onClickEntity = soundList; me.TR(me); - me.TD(me, 1, columns_nospacing / 2, e = makeXonoticButton(_("Set as menu track"), '0 0 0')); - e.onClick = SoundList_Menu_Track_Change; - e.onClickEntity = soundList; + me.TD(me, 1, columns_nospacing / 2, e = makeXonoticButton(_("Set as menu track"), '0 0 0')); + e.onClick = SoundList_Menu_Track_Change; + e.onClickEntity = soundList; me.TR(me); - me.TD(me, 1, columns_nospacing / 2, e = makeXonoticButton(_("Reset default menu track"), '0 0 0')); - e.onClick = SoundList_Menu_Track_Reset; - e.onClickEntity = soundList; + me.TD(me, 1, columns_nospacing / 2, e = makeXonoticButton(_("Reset default menu track"), '0 0 0')); + e.onClick = SoundList_Menu_Track_Reset; + e.onClickEntity = soundList; me.TR(me); me.TR(me); - me.gotoRC(me, 0, columns_nospacing / 2 + 0.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, columns_nospacing / 4, e = makeXonoticTextLabel(0, _("Playlist:"))); - me.TD(me, 1, columns_nospacing / 4, e = makeXonoticCheckBox(0, "music_playlist_random0", _("Random order"))); + me.gotoRC(me, 0, columns_nospacing / 2 + 0.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, columns_nospacing / 4, e = makeXonoticTextLabel(0, _("Playlist:"))); + me.TD(me, 1, columns_nospacing / 4, e = makeXonoticCheckBox(0, "music_playlist_random0", _("Random order"))); me.TR(me); - me.TD(me, me.rows - 3, columns_nospacing / 2, playList); + me.TD(me, me.rows - 3, columns_nospacing / 2, playList); me.gotoRC(me, me.rows - 2, columns_nospacing / 2 + 0.2); - me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Stop")), '0 0 0')); - e.onClick = StopSound_Click; - e.onClickEntity = playList; - me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Play")), '0 0 0')); - e.onClick = StartSound_Click; - e.onClickEntity = playList; - me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Pause")), '0 0 0')); - e.onClick = PauseSound_Click; - e.onClickEntity = playList; - me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Prev")), '0 0 0')); - e.onClick = PrevSound_Click; - e.onClickEntity = playList; - me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Next")), '0 0 0')); - e.onClick = NextSound_Click; - e.onClickEntity = playList; + me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Stop")), '0 0 0')); + e.onClick = StopSound_Click; + e.onClickEntity = playList; + me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Play")), '0 0 0')); + e.onClick = StartSound_Click; + e.onClickEntity = playList; + me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Pause")), '0 0 0')); + e.onClick = PauseSound_Click; + e.onClickEntity = playList; + me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Prev")), '0 0 0')); + e.onClick = PrevSound_Click; + e.onClickEntity = playList; + me.TD(me, 1, columns_nospacing / 10, e = makeXonoticButton(ZCTX(_("MUSICPL^Next")), '0 0 0')); + e.onClick = NextSound_Click; + e.onClickEntity = playList; me.TR(me); - me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Remove")), '0 0 0')); - e.onClick = PlayList_Remove; - e.onClickEntity = playList; - me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Remove all")), '0 0 0')); - e.onClick = PlayList_Remove_All; - e.onClickEntity = playList; + me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Remove")), '0 0 0')); + e.onClick = PlayList_Remove; + e.onClickEntity = playList; + me.TD(me, 1, columns_nospacing / 4, e = makeXonoticButton(ZCTX(_("MUSICPL^Remove all")), '0 0 0')); + e.onClick = PlayList_Remove_All; + e.onClickEntity = playList; } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot.qc index 1229be714..754d88227 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot.qc @@ -17,10 +17,12 @@ entity makeXonoticScreenshotBrowserTab() } void XonoticScreenshotBrowserTab_loadPreviewScreenshot(entity me, string scrImage) { - if (me.currentScrPath == scrImage) + if (me.currentScrPath == scrImage) { return; - if (me.currentScrPath) + } + if (me.currentScrPath) { strunzone(me.currentScrPath); + } me.currentScrPath = strzone(scrImage); me.screenshotImage.load(me.screenshotImage, me.currentScrPath); } @@ -32,43 +34,43 @@ void XonoticScreenshotBrowserTab_fill(entity me) me.TR(me); - me.TD(me, 1, 0.6, e = makeXonoticTextLabel(1, _("Filter:"))); - me.TD(me, 1, 2.4, e = makeXonoticInputBox(0, string_null)); - e.onChange = ScreenshotList_Filter_Would_Change; - e.onChangeEntity = slist; - slist.screenshotViewerDialog = main.screenshotViewerDialog; - main.screenshotViewerDialog.scrList = slist; + me.TD(me, 1, 0.6, e = makeXonoticTextLabel(1, _("Filter:"))); + me.TD(me, 1, 2.4, e = makeXonoticInputBox(0, string_null)); + e.onChange = ScreenshotList_Filter_Would_Change; + e.onChangeEntity = slist; + slist.screenshotViewerDialog = main.screenshotViewerDialog; + main.screenshotViewerDialog.scrList = slist; me.gotoRC(me, 0, 3.1); - me.TD(me, 1, 1.9, e = makeXonoticCheckBoxEx(2, 1, "cl_autoscreenshot", _("Auto screenshot scoreboard"))); - me.TD(me, 1, 1, e = makeXonoticButton(_("Refresh"), '0 0 0')); - e.onClick = ScreenshotList_Refresh_Click; - e.onClickEntity = slist; + me.TD(me, 1, 1.9, e = makeXonoticCheckBoxEx(2, 1, "cl_autoscreenshot", _("Auto screenshot scoreboard"))); + me.TD(me, 1, 1, e = makeXonoticButton(_("Refresh"), '0 0 0')); + e.onClick = ScreenshotList_Refresh_Click; + e.onClickEntity = slist; /*me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticTextLabel(0, "Filter:")); - me.TD(me, 1, me.columns - 1.5, e = makeXonoticInputBox(0, string_null)); - e.onChange = ScreenshotList_Filter_Would_Change; - e.onChangeEntity = slist; - slist.screenshotViewerDialog = main.screenshotViewerDialog; - main.screenshotViewerDialog.scrList = slist; - me.TD(me, 1, 1, e = makeXonoticButton(_("Refresh"), '0 0 0')); - e.onClick = ScreenshotList_Refresh_Click; - e.onClickEntity = slist;*/ + me.TD(me, 1, 0.5, e = makeXonoticTextLabel(0, "Filter:")); + me.TD(me, 1, me.columns - 1.5, e = makeXonoticInputBox(0, string_null)); + e.onChange = ScreenshotList_Filter_Would_Change; + e.onChangeEntity = slist; + slist.screenshotViewerDialog = main.screenshotViewerDialog; + main.screenshotViewerDialog.scrList = slist; + me.TD(me, 1, 1, e = makeXonoticButton(_("Refresh"), '0 0 0')); + e.onClick = ScreenshotList_Refresh_Click; + e.onClickEntity = slist;*/ me.gotoRC(me, 1.5, 0); - me.TD(me, me.rows - 2.5, me.columns, slist); + me.TD(me, me.rows - 2.5, me.columns, slist); me.gotoRC(me, slist_height + 1, 0); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("Open in the viewer"), '0 0 0')); - e.onClick = StartScreenshot_Click; - e.onClickEntity = slist; + me.TD(me, 1, me.columns, e = makeXonoticButton(_("Open in the viewer"), '0 0 0')); + e.onClick = StartScreenshot_Click; + e.onClickEntity = slist; /* - me.TR(me); - me.TD(me, me.rows - me.currentRow, me.columns, e = makeXonoticScreenshotImage()); - e.showTitle = 0; - me.screenshotImage = e; - slist.screenshotPreview = e; - slist.screenshotBrowserDialog = me; + me.TR(me); + me.TD(me, me.rows - me.currentRow, me.columns, e = makeXonoticScreenshotImage()); + e.showTitle = 0; + me.screenshotImage = e; + slist.screenshotPreview = e; + slist.screenshotBrowserDialog = me; */ } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot_viewer.qc b/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot_viewer.qc index d6d545eee..d27e44c4b 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot_viewer.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot_viewer.qc @@ -8,24 +8,25 @@ float music_playlist_index_backup; void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage) { // disable music as it can lag depending on image loading time - if(!cvar("menu_screenshotviewer_enablemusic")) - if(cvar("music_playlist_index") != 999) // if the playlist isn't paused - { - // pause music - if(cvar("music_playlist_index") != -1) - { - music_playlist_index_backup = cvar("music_playlist_index"); - cvar_set("music_playlist_sampleposition0", "0"); - cvar_set("music_playlist_index", "999"); + if (!cvar("menu_screenshotviewer_enablemusic")) { + if (cvar("music_playlist_index") != 999) { // if the playlist isn't paused + // pause music + if (cvar("music_playlist_index") != -1) { + music_playlist_index_backup = cvar("music_playlist_index"); + cvar_set("music_playlist_sampleposition0", "0"); + cvar_set("music_playlist_index", "999"); + } else { + localcmd("\ncd pause\n"); + } } - else - localcmd("\ncd pause\n"); } - if (me.currentScrPath == scrImage) + if (me.currentScrPath == scrImage) { return; - if (me.currentScrPath) + } + if (me.currentScrPath) { strunzone(me.currentScrPath); + } me.currentScrPath = strzone(scrImage); me.screenshotImage.load(me.screenshotImage, me.currentScrPath); me.frame.setText(me.frame, me.screenshotImage.screenshotTitle); @@ -44,7 +45,7 @@ void increaseZoom_Click(entity btn, entity me) } void decreaseZoom_Click(entity btn, entity me) { - me.screenshotImage.setZoom(me.screenshotImage, -1/2, false); + me.screenshotImage.setZoom(me.screenshotImage, -1 / 2, false); } void resetZoom_Click(entity btn, entity me) { @@ -52,21 +53,17 @@ void resetZoom_Click(entity btn, entity me) } void toggleSlideShow_Click(entity btn, entity me) { - if (me.slideShowButton.forcePressed) - { + if (me.slideShowButton.forcePressed) { me.scrList.stopSlideShow(me.scrList); me.slideShowButton.forcePressed = 0; - } - else - { + } else { me.scrList.startSlideShow(me.scrList); me.slideShowButton.forcePressed = 1; } } float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift) { - switch(key) - { + switch (key) { case K_KP_LEFTARROW: case K_LEFTARROW: me.scrList.goScreenshot(me.scrList, -1); @@ -80,25 +77,20 @@ float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, f case K_SPACE: // we cannot use SPACE/ENTER directly, as in a dialog they are needed // to press buttons while browsing with only the keyboard - if (shift & S_CTRL) - { + if (shift & S_CTRL) { toggleSlideShow_Click(NULL, me); return 1; } return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift); default: - if (key == K_MWHEELUP || ascii == '+') - { + if (key == K_MWHEELUP || ascii == '+') { me.screenshotImage.setZoom(me.screenshotImage, -2, (key == K_MWHEELUP)); return 1; - } - else if (key == K_MWHEELDOWN || ascii == '-') - { - me.screenshotImage.setZoom(me.screenshotImage, -1/2, (key == K_MWHEELDOWN)); + } else if (key == K_MWHEELDOWN || ascii == '-') { + me.screenshotImage.setZoom(me.screenshotImage, -1 / 2, (key == K_MWHEELDOWN)); return 1; } - if (me.scrList.keyDown(me.scrList, key, ascii, shift)) - { + if (me.scrList.keyDown(me.scrList, key, ascii, shift)) { // keyDown has already changed the selected item me.scrList.goScreenshot(me.scrList, 0); return 1; @@ -109,13 +101,13 @@ float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, f void XonoticScreenshotViewerDialog_close(entity me) { // resume music - if(!cvar("menu_screenshotviewer_enablemusic")) - if(cvar("music_playlist_index") == 999) - { - cvar_set("music_playlist_index", ftos(music_playlist_index_backup)); + if (!cvar("menu_screenshotviewer_enablemusic")) { + if (cvar("music_playlist_index") == 999) { + cvar_set("music_playlist_index", ftos(music_playlist_index_backup)); + } else { + localcmd("\ncd resume\n"); + } } - else - localcmd("\ncd resume\n"); me.scrList.stopSlideShow(me.scrList); me.slideShowButton.forcePressed = 0; @@ -125,32 +117,32 @@ void XonoticScreenshotViewerDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage()); - e.showTitle = 0; // dialog title is enough - me.screenshotImage = e; + me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage()); + e.showTitle = 0; // dialog title is enough + me.screenshotImage = e; me.gotoRC(me, me.rows - 1, 0); - me.TDempty(me, 1/20 * me.columns); - me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0')); - e.onClick = decreaseZoom_Click; - e.onClickEntity = me; - me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0')); - e.onClick = increaseZoom_Click; - e.onClickEntity = me; - me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0')); - e.onClick = resetZoom_Click; - e.onClickEntity = me; + me.TDempty(me, 1 / 20 * me.columns); + me.TD(me, 1, 1 / 20 * me.columns, e = makeXonoticButton("-", '0 0 0')); + e.onClick = decreaseZoom_Click; + e.onClickEntity = me; + me.TD(me, 1, 1 / 20 * me.columns, e = makeXonoticButton("+", '0 0 0')); + e.onClick = increaseZoom_Click; + e.onClickEntity = me; + me.TD(me, 1, 2 / 20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0')); + e.onClick = resetZoom_Click; + e.onClickEntity = me; - me.TDempty(me, 2/20 * me.columns); - me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0')); - e.onClick = prevScreenshot_Click; - e.onClickEntity = me; - me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0')); - e.onClick = nextScreenshot_Click; - e.onClickEntity = me; + me.TDempty(me, 2 / 20 * me.columns); + me.TD(me, 1, 3 / 20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0')); + e.onClick = prevScreenshot_Click; + e.onClickEntity = me; + me.TD(me, 1, 3 / 20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0')); + e.onClick = nextScreenshot_Click; + e.onClickEntity = me; - me.TDempty(me, 2/20 * me.columns); - me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0')); - e.onClick = toggleSlideShow_Click; - e.onClickEntity = me; - me.slideShowButton = e; + me.TDempty(me, 2 / 20 * me.columns); + me.TD(me, 1, 4 / 20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0')); + e.onClick = toggleSlideShow_Click; + e.onClickEntity = me; + me.slideShowButton = e; } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc index 681542218..cd4420e3b 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qc @@ -21,10 +21,11 @@ entity makeXonoticProfileTab() } void XonoticProfileTab_draw(entity me) { - if(cvar_string("_cl_name") == "Player") + if (cvar_string("_cl_name") == "Player") { me.playerNameLabel.alpha = ((mod(time * 2, 2) < 1) ? 1 : 0); - else + } else { me.playerNameLabel.alpha = me.playerNameLabelAlpha; + } SUPER(XonoticProfileTab).draw(me); } void XonoticProfileTab_fill(entity me) @@ -37,143 +38,148 @@ void XonoticProfileTab_fill(entity me) "playermodel $_cl_playermodel;" "playerskin $_cl_playerskin;" "sendcvar cl_allow_uidtracking;" - "sendcvar cl_allow_uid2name;" - , COMMANDBUTTON_APPLY); + "sendcvar cl_allow_uid2name;", + COMMANDBUTTON_APPLY); profileApplyButton.disableOnClick = true; // ============== // NAME SECTION // ============== me.gotoRC(me, 0.5, 0); - me.TD(me, 1, 3, me.playerNameLabel = makeXonoticHeaderLabel(_("Name"))); + me.TD(me, 1, 3, me.playerNameLabel = makeXonoticHeaderLabel(_("Name"))); me.gotoRC(me, 1.5, 0); - me.TD(me, 1, 3, label = makeXonoticTextLabel(0.5, string_null)); - label.allowCut = 1; - label.allowColors = 1; - label.alpha = 1; - label.isBold = true; - label.fontSize = SKINFONTSIZE_TITLE; + me.TD(me, 1, 3, label = makeXonoticTextLabel(0.5, string_null)); + label.allowCut = 1; + label.allowColors = 1; + label.alpha = 1; + label.isBold = true; + label.fontSize = SKINFONTSIZE_TITLE; me.gotoRC(me, 2.5, 0); - me.TD(me, 1, 3.0, box = makeXonoticInputBox_T(1, "_cl_name", + me.TD(me, 1, 3.0, box = makeXonoticInputBox_T(1, "_cl_name", _("Name under which you will appear in the game"))); - box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved - box.maxLength = -127; // negative means encoded length in bytes - box.saveImmediately = 0; // Sorry, can't do this, it spams "name" commands. - box.enableClearButton = 0; - box.applyButton = profileApplyButton; - label.textEntity = box; + box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved + box.maxLength = -127; // negative means encoded length in bytes + box.saveImmediately = 0; // Sorry, can't do this, it spams "name" commands. + box.enableClearButton = 0; + box.applyButton = profileApplyButton; + label.textEntity = box; me.TR(me); - me.TD(me, 5, 1, e = makeXonoticColorpicker(box)); - me.TD(me, 5, 2, e = makeXonoticCharmap(box)); + me.TD(me, 5, 1, e = makeXonoticColorpicker(box)); + me.TD(me, 5, 2, e = makeXonoticCharmap(box)); // =============== // MODEL SECTION // =============== - //me.gotoRC(me, 0.5, 3.1); me.setFirstColumn(me, me.currentColumn); // TOP RIGHT - //me.gotoRC(me, 9, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM RIGHT - me.gotoRC(me, 9, 0); me.setFirstColumn(me, me.currentColumn); // BOTTOM LEFT - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Model"))); + // me.gotoRC(me, 0.5, 3.1); me.setFirstColumn(me, me.currentColumn); // TOP RIGHT + // me.gotoRC(me, 9, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM RIGHT + me.gotoRC(me, 9, 0); + me.setFirstColumn(me, me.currentColumn); // BOTTOM LEFT + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Model"))); me.TR(me); - //me.TDempty(me, 0); // MODEL LEFT, COLOR RIGHT - me.TDempty(me, 1); // MODEL RIGHT, COLOR LEFT - pms = makeXonoticPlayerModelSelector(); - me.TD(me, 1, 0.3, e = makeXonoticButton("<<", '0 0 0')); - e.onClick = PlayerModelSelector_Prev_Click; - e.onClickEntity = pms; - e.applyButton = profileApplyButton; - me.TD(me, 11.5, 1.4, pms); - me.TD(me, 1, 0.3, e = makeXonoticButton(">>", '0 0 0')); - e.onClick = PlayerModelSelector_Next_Click; - e.onClickEntity = pms; - e.applyButton = profileApplyButton; + // me.TDempty(me, 0); // MODEL LEFT, COLOR RIGHT + me.TDempty(me, 1); // MODEL RIGHT, COLOR LEFT + pms = makeXonoticPlayerModelSelector(); + me.TD(me, 1, 0.3, e = makeXonoticButton("<<", '0 0 0')); + e.onClick = PlayerModelSelector_Prev_Click; + e.onClickEntity = pms; + e.applyButton = profileApplyButton; + me.TD(me, 11.5, 1.4, pms); + me.TD(me, 1, 0.3, e = makeXonoticButton(">>", '0 0 0')); + e.onClick = PlayerModelSelector_Next_Click; + e.onClickEntity = pms; + e.applyButton = profileApplyButton; - //me.setFirstColumn(me, me.currentColumn + 2); // MODEL LEFT, COLOR RIGHT - me.gotoRC(me, me.currentRow, 0); me.setFirstColumn(me, me.currentColumn); // MODEL RIGHT, COLOR LEFT + // me.setFirstColumn(me, me.currentColumn + 2); // MODEL LEFT, COLOR RIGHT + me.gotoRC(me, me.currentRow, 0); + me.setFirstColumn(me, me.currentColumn); // MODEL RIGHT, COLOR LEFT me.TR(me); - me.TD(me, 1, 1, e = makeXonoticHeaderLabel(_("Glowing color"))); - for(i = 0; i < 15; ++i) - { - if(mod(i, 5) == 0) - me.TR(me); - me.TDNoMargin(me, 1, 0.2, e = makeXonoticColorButton(1, 0, i), '0 1 0'); - e.applyButton = profileApplyButton; + me.TD(me, 1, 1, e = makeXonoticHeaderLabel(_("Glowing color"))); + for (i = 0; i < 15; ++i) { + if (mod(i, 5) == 0) { + me.TR(me); } + me.TDNoMargin(me, 1, 0.2, e = makeXonoticColorButton(1, 0, i), '0 1 0'); + e.applyButton = profileApplyButton; + } me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticHeaderLabel(_("Detail color"))); - for(i = 0; i < 15; ++i) - { - if(mod(i, 5) == 0) - me.TR(me); - me.TDNoMargin(me, 1, 0.2, e = makeXonoticColorButton(2, 1, i), '0 1 0'); - e.applyButton = profileApplyButton; + me.TD(me, 1, 1, e = makeXonoticHeaderLabel(_("Detail color"))); + for (i = 0; i < 15; ++i) { + if (mod(i, 5) == 0) { + me.TR(me); } + me.TDNoMargin(me, 1, 0.2, e = makeXonoticColorButton(2, 1, i), '0 1 0'); + e.applyButton = profileApplyButton; + } // ==================== // STATISTICS SECTION // ==================== - me.gotoRC(me, 0.5, 3.1); me.setFirstColumn(me, me.currentColumn); // TOP RIGHT - //me.gotoRC(me, 9, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM RIGHT - //me.gotoRC(me, 9, 0); me.setFirstColumn(me, me.currentColumn); // BOTTOM LEFT - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Statistics"))); + me.gotoRC(me, 0.5, 3.1); + me.setFirstColumn(me, me.currentColumn); // TOP RIGHT + // me.gotoRC(me, 9, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM RIGHT + // me.gotoRC(me, 9, 0); me.setFirstColumn(me, me.currentColumn); // BOTTOM LEFT + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Statistics"))); me.TR(me); - me.TDempty(me, 0.25); - me.TD(me, 1, 2.5, e = makeXonoticCheckBox(0, "cl_allow_uidtracking", _("Allow player statistics to track your client"))); - e.applyButton = profileApplyButton; + me.TDempty(me, 0.25); + me.TD(me, 1, 2.5, e = makeXonoticCheckBox(0, "cl_allow_uidtracking", _("Allow player statistics to track your client"))); + e.applyButton = profileApplyButton; me.TR(me); - me.TDempty(me, 0.25); - me.TD(me, 1, 2.5, e = makeXonoticCheckBox(0, "cl_allow_uid2name", _("Allow player statistics to use your nickname"))); - e.applyButton = profileApplyButton; - setDependent(e, "cl_allow_uidtracking", 1, 1); + me.TDempty(me, 0.25); + me.TD(me, 1, 2.5, e = makeXonoticCheckBox(0, "cl_allow_uid2name", _("Allow player statistics to use your nickname"))); + e.applyButton = profileApplyButton; + setDependent(e, "cl_allow_uidtracking", 1, 1); me.gotoRC(me, 4, 3.1); // TOP RIGHT - //me.gotoRC(me, 12.5, 3.1); // BOTTOM RIGHT - //me.gotoRC(me, 12.5, 0); // BOTTOM LEFT - me.TDempty(me, 0.25); - me.TD(me, 9, 2.5, statslist = makeXonoticStatsList()); - //setDependent(statslist, "cl_allow_uidtracking", 1, 1); + // me.gotoRC(me, 12.5, 3.1); // BOTTOM RIGHT + // me.gotoRC(me, 12.5, 0); // BOTTOM LEFT + me.TDempty(me, 0.25); + me.TD(me, 9, 2.5, statslist = makeXonoticStatsList()); + // setDependent(statslist, "cl_allow_uidtracking", 1, 1); // ================= // COUNTRY SECTION // ================= - me.gotoRC(me, 16, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, TOP POS - //me.gotoRC(me, 13.5, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, TOP POS - //me.gotoRC(me, 0.5, 3.1); me.setFirstColumn(me, me.currentColumn); // TOP SECTION, TOP POS - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Country"))); + me.gotoRC(me, 16, 3.1); + me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, TOP POS + // me.gotoRC(me, 13.5, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, TOP POS + // me.gotoRC(me, 0.5, 3.1); me.setFirstColumn(me, me.currentColumn); // TOP SECTION, TOP POS + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Country"))); me.TR(me); - me.TDempty(me, 0.5); - me.TD(me, 4.5, 2, e = makeXonoticLanguageList()); // todo: cl_country: create proper country list + me.TDempty(me, 0.5); + me.TD(me, 4.5, 2, e = makeXonoticLanguageList()); // todo: cl_country: create proper country list // ================ // GENDER SECTION // ================ - me.gotoRC(me, 13.5, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, TOP POS - //me.gotoRC(me, 19.5, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, BOTTOM POS - //me.gotoRC(me, 6.5, 3.1); me.setFirstColumn(me, me.currentColumn); // TOP SECTION, BOTTOM POS + me.gotoRC(me, 13.5, 3.1); + me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, TOP POS + // me.gotoRC(me, 19.5, 3.1); me.setFirstColumn(me, me.currentColumn); // BOTTOM SECTION, BOTTOM POS + // me.gotoRC(me, 6.5, 3.1); me.setFirstColumn(me, me.currentColumn); // TOP SECTION, BOTTOM POS #if 0 - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Gender:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("_cl_gender")); - e.addValue(e, _("Undisclosed"), "0"); - e.addValue(e, _("Female"), "1"); - e.addValue(e, _("Male"), "2"); - e.configureXonoticTextSliderValues(e); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Gender:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("_cl_gender")); + e.addValue(e, _("Undisclosed"), "0"); + e.addValue(e, _("Female"), "1"); + e.addValue(e, _("Male"), "2"); + e.configureXonoticTextSliderValues(e); #else - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Gender"))); - me.TR(me); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Gender"))); + me.TR(me); #define GENDERWIDTH_OFFSET 0.25 #define GENDERWIDTH_LENGTH 2.5 #define GENDERWIDTH_ITEM (GENDERWIDTH_LENGTH / 3) - me.TDempty(me, GENDERWIDTH_OFFSET); - me.TD(me, 1, GENDERWIDTH_ITEM, e = makeXonoticRadioButton(3, "_cl_gender", "2", _("Female"))); - me.TD(me, 1, GENDERWIDTH_ITEM, e = makeXonoticRadioButton(3, "_cl_gender", "1", _("Male"))); - me.TD(me, 1, GENDERWIDTH_ITEM, e = makeXonoticRadioButton(3, "_cl_gender", "0", _("Undisclosed"))); + me.TDempty(me, GENDERWIDTH_OFFSET); + me.TD(me, 1, GENDERWIDTH_ITEM, e = makeXonoticRadioButton(3, "_cl_gender", "2", _("Female"))); + me.TD(me, 1, GENDERWIDTH_ITEM, e = makeXonoticRadioButton(3, "_cl_gender", "1", _("Male"))); + me.TD(me, 1, GENDERWIDTH_ITEM, e = makeXonoticRadioButton(3, "_cl_gender", "0", _("Undisclosed"))); #endif me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, profileApplyButton); + me.TD(me, 1, me.columns, profileApplyButton); } diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh index 2285efcaf..c693c62cd 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_profile.qh @@ -6,7 +6,7 @@ CLASS(XonoticProfileTab, XonoticTab) METHOD(XonoticProfileTab, draw, void(entity)); ATTRIB(XonoticProfileTab, intendedWidth, float, 0.9); ATTRIB(XonoticProfileTab, rows, float, 23); - ATTRIB(XonoticProfileTab, columns, float, 6.1); // added extra .2 for center space + ATTRIB(XonoticProfileTab, columns, float, 6.1); // added extra .2 for center space ATTRIB(XonoticProfileTab, playerNameLabel, entity); ATTRIB(XonoticProfileTab, playerNameLabelAlpha, float, SKINALPHA_HEADER); ENDCLASS(XonoticProfileTab) diff --git a/qcsrc/menu/xonotic/dialog_quit.qc b/qcsrc/menu/xonotic/dialog_quit.qc index e68b967a0..1616f2e4f 100644 --- a/qcsrc/menu/xonotic/dialog_quit.qc +++ b/qcsrc/menu/xonotic/dialog_quit.qc @@ -8,13 +8,13 @@ void XonoticQuitDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Are you sure you want to quit?"))); + me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Are you sure you want to quit?"))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCommandButton_T(_("Yes"), '1 0 0', "echo ]quit\nquit", 0, + me.TD(me, 1, 1, e = makeXonoticCommandButton_T(_("Yes"), '1 0 0', "echo ]quit\nquit", 0, _("Back to work..."))); - me.TD(me, 1, 1, e = makeXonoticButton_T(_("No"), '0 1 0', + me.TD(me, 1, 1, e = makeXonoticButton_T(_("No"), '0 1 0', _("I got some more fragging to do!"))); - e.onClick = Dialog_Close; - e.onClickEntity = me; + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_sandboxtools.qc b/qcsrc/menu/xonotic/dialog_sandboxtools.qc index bfd26b5fe..0aee5d72a 100644 --- a/qcsrc/menu/xonotic/dialog_sandboxtools.qc +++ b/qcsrc/menu/xonotic/dialog_sandboxtools.qc @@ -12,77 +12,77 @@ void XonoticSandboxToolsDialog_fill(entity me) entity e, box; me.TR(me); - me.TD(me, 1, 0.25, e = makeXonoticTextLabel(0, _("Model:"))); - me.TD(me, 1, 1.5, box = makeXonoticInputBox(1, "menu_sandbox_spawn_model")); - box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved - box.maxLength = -127; // negative means encoded length in bytes - box.saveImmediately = 1; - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Spawn"), '0 0 0', "sandbox object_spawn \"$menu_sandbox_spawn_model\"", 0)); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Remove *"), '0 0 0', "sandbox object_remove", 0)); + me.TD(me, 1, 0.25, e = makeXonoticTextLabel(0, _("Model:"))); + me.TD(me, 1, 1.5, box = makeXonoticInputBox(1, "menu_sandbox_spawn_model")); + box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved + box.maxLength = -127; // negative means encoded length in bytes + box.saveImmediately = 1; + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Spawn"), '0 0 0', "sandbox object_spawn \"$menu_sandbox_spawn_model\"", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Remove *"), '0 0 0', "sandbox object_remove", 0)); me.TDempty(me, 0.1); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Copy *"), '0 0 0', "sandbox object_duplicate copy cl_sandbox_clipboard", 0)); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Paste"), '0 0 0', "sandbox object_duplicate paste \"$cl_sandbox_clipboard\"", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Copy *"), '0 0 0', "sandbox object_duplicate copy cl_sandbox_clipboard", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Paste"), '0 0 0', "sandbox object_duplicate paste \"$cl_sandbox_clipboard\"", 0)); me.TR(me); - me.TD(me, 1, 0.25, e = makeXonoticTextLabel(0, _("Bone:"))); - me.TD(me, 1, 1.5, box = makeXonoticInputBox(1, "menu_sandbox_attach_bone")); - box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved - box.maxLength = -127; // negative means encoded length in bytes - box.saveImmediately = 1; - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set * as child"), '0 0 0', "sandbox object_attach get", 0)); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Attach to *"), '0 0 0', "sandbox object_attach set \"$menu_sandbox_attach_bone\"", 0)); + me.TD(me, 1, 0.25, e = makeXonoticTextLabel(0, _("Bone:"))); + me.TD(me, 1, 1.5, box = makeXonoticInputBox(1, "menu_sandbox_attach_bone")); + box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved + box.maxLength = -127; // negative means encoded length in bytes + box.saveImmediately = 1; + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set * as child"), '0 0 0', "sandbox object_attach get", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Attach to *"), '0 0 0', "sandbox object_attach set \"$menu_sandbox_attach_bone\"", 0)); me.TDempty(me, 0.1); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Detach from *"), '0 0 0', "sandbox object_attach remove", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Detach from *"), '0 0 0', "sandbox object_attach remove", 0)); me.TR(me); me.TR(me); me.TD(me, 1, 1.5, e = makeXonoticTextLabel(0, _("Visual object properties for *:"))); me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set skin:"), '0 0 0', "sandbox object_edit skin $menu_sandbox_edit_skin", 0)); - me.TD(me, 1, 1.5, e = makeXonoticSlider(0, 99, 1, "menu_sandbox_edit_skin")); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set alpha:"), '0 0 0', "sandbox object_edit alpha $menu_sandbox_edit_alpha", 0)); - me.TD(me, 1, 1.5, e = makeXonoticSlider(0.1, 1, 0.05, "menu_sandbox_edit_alpha")); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set skin:"), '0 0 0', "sandbox object_edit skin $menu_sandbox_edit_skin", 0)); + me.TD(me, 1, 1.5, e = makeXonoticSlider(0, 99, 1, "menu_sandbox_edit_skin")); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set alpha:"), '0 0 0', "sandbox object_edit alpha $menu_sandbox_edit_alpha", 0)); + me.TD(me, 1, 1.5, e = makeXonoticSlider(0.1, 1, 0.05, "menu_sandbox_edit_alpha")); me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set color main:"), '0 0 0', "sandbox object_edit color_main \"$menu_sandbox_edit_color_main\"", 0)); - me.TD(me, 2, 1.5, e = makeXonoticColorpickerString("menu_sandbox_edit_color_main", "menu_sandbox_edit_color_main")); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set color glow:"), '0 0 0', "sandbox object_edit color_glow \"$menu_sandbox_edit_color_glow\"", 0)); - me.TD(me, 2, 1.5, e = makeXonoticColorpickerString("menu_sandbox_edit_color_glow", "menu_sandbox_edit_color_glow")); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set color main:"), '0 0 0', "sandbox object_edit color_main \"$menu_sandbox_edit_color_main\"", 0)); + me.TD(me, 2, 1.5, e = makeXonoticColorpickerString("menu_sandbox_edit_color_main", "menu_sandbox_edit_color_main")); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set color glow:"), '0 0 0', "sandbox object_edit color_glow \"$menu_sandbox_edit_color_glow\"", 0)); + me.TD(me, 2, 1.5, e = makeXonoticColorpickerString("menu_sandbox_edit_color_glow", "menu_sandbox_edit_color_glow")); me.TR(me); me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set frame:"), '0 0 0', "sandbox object_edit frame $menu_sandbox_edit_frame", 0)); - me.TD(me, 1, 1.5, e = makeXonoticSlider(0, 99, 1, "menu_sandbox_edit_frame")); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set frame:"), '0 0 0', "sandbox object_edit frame $menu_sandbox_edit_frame", 0)); + me.TD(me, 1, 1.5, e = makeXonoticSlider(0, 99, 1, "menu_sandbox_edit_frame")); me.TR(me); me.TR(me); me.TD(me, 1, 1.5, e = makeXonoticTextLabel(0, _("Physical object properties for *:"))); me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set material:"), '0 0 0', "sandbox object_edit material \"$menu_sandbox_edit_material\"", 0)); - me.TD(me, 1, 1.5, box = makeXonoticInputBox(1, "menu_sandbox_edit_material")); - box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved - box.maxLength = -127; // negative means encoded length in bytes - box.saveImmediately = 1; + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set material:"), '0 0 0', "sandbox object_edit material \"$menu_sandbox_edit_material\"", 0)); + me.TD(me, 1, 1.5, box = makeXonoticInputBox(1, "menu_sandbox_edit_material")); + box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved + box.maxLength = -127; // negative means encoded length in bytes + box.saveImmediately = 1; me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set solidity:"), '0 0 0', "sandbox object_edit solidity $menu_sandbox_edit_solidity", 0)); - me.TD(me, 1, 0.75, e = makeXonoticRadioButton(1, "menu_sandbox_edit_solidity", "0", _("Non-solid"))); - me.TD(me, 1, 0.75, e = makeXonoticRadioButton(1, "menu_sandbox_edit_solidity", "1", _("Solid"))); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set physics:"), '0 0 0', "sandbox object_edit physics $menu_sandbox_edit_physics", 0)); - me.TD(me, 1, 0.5, e = makeXonoticRadioButton(2, "menu_sandbox_edit_physics", "0", _("Static"))); - me.TD(me, 1, 0.5, e = makeXonoticRadioButton(2, "menu_sandbox_edit_physics", "1", _("Movable"))); - me.TD(me, 1, 0.5, e = makeXonoticRadioButton(2, "menu_sandbox_edit_physics", "2", _("Physical"))); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set solidity:"), '0 0 0', "sandbox object_edit solidity $menu_sandbox_edit_solidity", 0)); + me.TD(me, 1, 0.75, e = makeXonoticRadioButton(1, "menu_sandbox_edit_solidity", "0", _("Non-solid"))); + me.TD(me, 1, 0.75, e = makeXonoticRadioButton(1, "menu_sandbox_edit_solidity", "1", _("Solid"))); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set physics:"), '0 0 0', "sandbox object_edit physics $menu_sandbox_edit_physics", 0)); + me.TD(me, 1, 0.5, e = makeXonoticRadioButton(2, "menu_sandbox_edit_physics", "0", _("Static"))); + me.TD(me, 1, 0.5, e = makeXonoticRadioButton(2, "menu_sandbox_edit_physics", "1", _("Movable"))); + me.TD(me, 1, 0.5, e = makeXonoticRadioButton(2, "menu_sandbox_edit_physics", "2", _("Physical"))); me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set scale:"), '0 0 0', "sandbox object_edit scale $menu_sandbox_edit_scale", 0)); - me.TD(me, 1, 1.5, e = makeXonoticSlider(0.25, 2, 0.05, "menu_sandbox_edit_scale")); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set force:"), '0 0 0', "sandbox object_edit force $menu_sandbox_edit_force", 0)); - me.TD(me, 1, 1.5, e = makeXonoticSlider(0, 10, 0.5, "menu_sandbox_edit_force")); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set scale:"), '0 0 0', "sandbox object_edit scale $menu_sandbox_edit_scale", 0)); + me.TD(me, 1, 1.5, e = makeXonoticSlider(0.25, 2, 0.05, "menu_sandbox_edit_scale")); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Set force:"), '0 0 0', "sandbox object_edit force $menu_sandbox_edit_force", 0)); + me.TD(me, 1, 1.5, e = makeXonoticSlider(0, 10, 0.5, "menu_sandbox_edit_force")); me.TR(me); me.TR(me); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Claim *"), '0 0 0', "sandbox object_claim", 0)); - me.TDempty(me, 0.5); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("* object info"), '1 1 0.5', "sandbox object_info object; toggleconsole", 0)); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("* mesh info"), '1 1 0.5', "sandbox object_info mesh; toggleconsole", 0)); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("* attachment info"), '1 1 0.5', "sandbox object_info attachments; toggleconsole", 0)); - me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Show help"), '1 0.5 0.5', "sandbox help; toggleconsole", 0)); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("* is the object you are facing"))); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Claim *"), '0 0 0', "sandbox object_claim", 0)); + me.TDempty(me, 0.5); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("* object info"), '1 1 0.5', "sandbox object_info object; toggleconsole", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("* mesh info"), '1 1 0.5', "sandbox object_info mesh; toggleconsole", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("* attachment info"), '1 1 0.5', "sandbox object_info attachments; toggleconsole", 0)); + me.TD(me, 1, 0.5, e = makeXonoticCommandButton(_("Show help"), '1 0.5 0.5', "sandbox help; toggleconsole", 0)); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("* is the object you are facing"))); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_settings.qc b/qcsrc/menu/xonotic/dialog_settings.qc index bd6fd4c4f..bcf973206 100644 --- a/qcsrc/menu/xonotic/dialog_settings.qc +++ b/qcsrc/menu/xonotic/dialog_settings.qc @@ -15,14 +15,14 @@ void XonoticSettingsDialog_fill(entity me) entity mc; mc = makeXonoticTabController(me.rows - 2.5); me.TR(me); - me.TD(me, 1, 2, mc.makeTabButton(mc, _("Video"), makeXonoticVideoSettingsTab())); - me.TD(me, 1, 2, mc.makeTabButton(mc, _("Effects"), makeXonoticEffectsSettingsTab())); - me.TD(me, 1, 2, mc.makeTabButton(mc, _("Audio"), makeXonoticAudioSettingsTab())); + me.TD(me, 1, 2, mc.makeTabButton(mc, _("Video"), makeXonoticVideoSettingsTab())); + me.TD(me, 1, 2, mc.makeTabButton(mc, _("Effects"), makeXonoticEffectsSettingsTab())); + me.TD(me, 1, 2, mc.makeTabButton(mc, _("Audio"), makeXonoticAudioSettingsTab())); me.TR(me); - me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("Game"), NEW(XonoticGameSettingsTab))); - me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("Input"), makeXonoticInputSettingsTab())); - me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("User"), makeXonoticUserSettingsTab())); - me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("Misc"), makeXonoticMiscSettingsTab())); + me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("Game"), NEW(XonoticGameSettingsTab))); + me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("Input"), makeXonoticInputSettingsTab())); + me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("User"), makeXonoticUserSettingsTab())); + me.TD(me, 1, 1.5, mc.makeTabButton(mc, _("Misc"), makeXonoticMiscSettingsTab())); me.gotoRC(me, 2.5, 0); - me.TD(me, me.rows - 2.5, me.columns, mc); + me.TD(me, me.rows - 2.5, me.columns, mc); } diff --git a/qcsrc/menu/xonotic/dialog_settings_audio.qc b/qcsrc/menu/xonotic/dialog_settings_audio.qc index 7af8c5500..de1d3eabc 100644 --- a/qcsrc/menu/xonotic/dialog_settings_audio.qc +++ b/qcsrc/menu/xonotic/dialog_settings_audio.qc @@ -20,161 +20,163 @@ void XonoticAudioSettingsTab_fill(entity me) entity e, e2, s; entity audioApplyButton = makeXonoticCommandButton(_("Apply immediately"), '0 0 0', "snd_restart;" - "snd_attenuation_method_${menu_snd_attenuation_method};" - , COMMANDBUTTON_APPLY); + "snd_attenuation_method_${menu_snd_attenuation_method};", + COMMANDBUTTON_APPLY); audioApplyButton.disableOnClick = true; me.TR(me); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "mastervolume", "-"); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Master:"))); - me.TD(me, 1, 2, s); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "bgmvolume", "-"); - makeMulti(s, "snd_channel8volume"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Music:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_staticvolume", "-"); - makeMulti(s, "snd_channel9volume"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, ZCTX(_("VOL^Ambient:")))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel0volume", "-"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Info:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel3volume", "-"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Items:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel6volume", "-"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Pain:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel7volume", "-"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Player:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel4volume", "-"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Shots:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel2volume", "-"); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Voice:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TDempty(me, 0.2); - s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel1volume", "-"); - makeMulti(s, "snd_channel5volume"); // @!#%'n Tuba - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Weapons:"))); - me.TD(me, 1, 2, s); - setDependentStringNotEqual(e, "mastervolume", "0"); - setDependentStringNotEqual(s, "mastervolume", "0"); - me.TR(me); - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "menu_snd_attenuation_method", _("New style sound attenuation"))); - e.applyButton = audioApplyButton; - me.TR(me); - me.TD(me, 1, 3, makeXonoticCheckBox(0, "snd_mutewhenidle", _("Mute sounds when not active"))); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "mastervolume", "-"); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Master:"))); + me.TD(me, 1, 2, s); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "bgmvolume", "-"); + makeMulti(s, "snd_channel8volume"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Music:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_staticvolume", "-"); + makeMulti(s, "snd_channel9volume"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, ZCTX(_("VOL^Ambient:")))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel0volume", "-"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Info:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel3volume", "-"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Items:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel6volume", "-"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Pain:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel7volume", "-"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Player:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel4volume", "-"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Shots:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel2volume", "-"); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Voice:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TDempty(me, 0.2); + s = makeXonoticDecibelsSlider_T(-40, 0, 0.4, "snd_channel1volume", "-"); + makeMulti(s, "snd_channel5volume"); // @!#%'n Tuba + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Weapons:"))); + me.TD(me, 1, 2, s); + setDependentStringNotEqual(e, "mastervolume", "0"); + setDependentStringNotEqual(s, "mastervolume", "0"); + me.TR(me); + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "menu_snd_attenuation_method", _("New style sound attenuation"))); + e.applyButton = audioApplyButton; + me.TR(me); + me.TD(me, 1, 3, makeXonoticCheckBox(0, "snd_mutewhenidle", _("Mute sounds when not active"))); - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Frequency:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("snd_speed", + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Frequency:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("snd_speed", _("Sound output frequency"))); - e.addValue(e, _("8 kHz"), "8000"); - e.addValue(e, _("11.025 kHz"), "11025"); - e.addValue(e, _("16 kHz"), "16000"); - e.addValue(e, _("22.05 kHz"), "22050"); - e.addValue(e, _("24 kHz"), "24000"); - e.addValue(e, _("32 kHz"), "32000"); - e.addValue(e, _("44.1 kHz"), "44100"); - e.addValue(e, _("48 kHz"), "48000"); - e.configureXonoticTextSliderValues(e); - e.applyButton = audioApplyButton; - me.TR(me); - me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Channels:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("snd_channels", + e.addValue(e, _("8 kHz"), "8000"); + e.addValue(e, _("11.025 kHz"), "11025"); + e.addValue(e, _("16 kHz"), "16000"); + e.addValue(e, _("22.05 kHz"), "22050"); + e.addValue(e, _("24 kHz"), "24000"); + e.addValue(e, _("32 kHz"), "32000"); + e.addValue(e, _("44.1 kHz"), "44100"); + e.addValue(e, _("48 kHz"), "48000"); + e.configureXonoticTextSliderValues(e); + e.applyButton = audioApplyButton; + me.TR(me); + me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Channels:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("snd_channels", _("Number of channels for the sound output"))); - e.addValue(e, _("Mono"), "1"); - e.addValue(e, _("Stereo"), "2"); - e.addValue(e, _("2.1"), "3"); - e.addValue(e, _("4"), "4"); - e.addValue(e, _("5"), "5"); - e.addValue(e, _("5.1"), "6"); - e.addValue(e, _("6.1"), "7"); - e.addValue(e, _("7.1"), "8"); - e.configureXonoticTextSliderValues(e); - e.applyButton = audioApplyButton; - me.TR(me); - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "snd_swapstereo", _("Swap stereo output channels"), + e.addValue(e, _("Mono"), "1"); + e.addValue(e, _("Stereo"), "2"); + e.addValue(e, _("2.1"), "3"); + e.addValue(e, _("4"), "4"); + e.addValue(e, _("5"), "5"); + e.addValue(e, _("5.1"), "6"); + e.addValue(e, _("6.1"), "7"); + e.addValue(e, _("7.1"), "8"); + e.configureXonoticTextSliderValues(e); + e.applyButton = audioApplyButton; + me.TR(me); + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "snd_swapstereo", _("Swap stereo output channels"), _("Swap left/right channels"))); - setDependent(e, "snd_channels", 1.5, 0.5); + setDependent(e, "snd_channels", 1.5, 0.5); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "snd_spatialization_control", _("Headphone friendly mode"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "snd_spatialization_control", _("Headphone friendly mode"), _("Enable spatialization (blend the right and left channel slightly to decrease stereo separation a bit for headphones)"))); - setDependent(e, "snd_channels", 1.5, 0.5); + setDependent(e, "snd_channels", 1.5, 0.5); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_hitsound", _("Hit indication sound"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_hitsound", _("Hit indication sound"), _("Play a hit indicator sound when your shot hits an enemy"))); - e.sendCvars = true; + e.sendCvars = true; me.TR(me); - me.TD(me, 1, 3, makeXonoticCheckBox(0, "con_chatsound", _("Chat message sound"))); + me.TD(me, 1, 3, makeXonoticCheckBox(0, "con_chatsound", _("Chat message sound"))); me.TR(me); - me.TD(me, 1, 1.2, e = makeXonoticCheckBox_T(0, "menu_sounds", _("Menu sounds"), + me.TD(me, 1, 1.2, e = makeXonoticCheckBox_T(0, "menu_sounds", _("Menu sounds"), _("Play sounds when clicking menu items"))); - me.TD(me, 1, 1.2, e.linkedCheckBox = e2 = makeXonoticCheckBoxEx_T(2, 1, "menu_sounds", _("Focus sounds"), + me.TD(me, 1, 1.2, e.linkedCheckBox = e2 = makeXonoticCheckBoxEx_T(2, 1, "menu_sounds", _("Focus sounds"), _("Play sounds when hovering over menu items too"))); - setDependent(e2, "menu_sounds", 1, 2); + setDependent(e2, "menu_sounds", 1, 2); me.TR(me); me.TR(me); - me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Time announcer:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_announcer_maptime")); - e.addValue(e, ZCTX(_("WRN^Disabled")), "0"); - e.addValue(e, _("1 minute"), "1"); - e.addValue(e, _("5 minutes"), "2"); - e.addValue(e, ZCTX(_("WRN^Both")), "3"); - e.configureXonoticTextSliderValues(e); + me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Time announcer:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_announcer_maptime")); + e.addValue(e, ZCTX(_("WRN^Disabled")), "0"); + e.addValue(e, _("1 minute"), "1"); + e.addValue(e, _("5 minutes"), "2"); + e.addValue(e, ZCTX(_("WRN^Both")), "3"); + e.configureXonoticTextSliderValues(e); me.TR(me); - me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Automatic taunts:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("cl_autotaunt", + me.TD(me, 1, 1, makeXonoticTextLabel(0, _("Automatic taunts:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("cl_autotaunt", _("Automatically taunt enemies after fragging them"))); - e.addValue(e, _("Never"), "0"); - e.addValue(e, _("Sometimes"), "0.35"); - e.addValue(e, _("Often"), "0.65"); - e.addValue(e, _("Always"), "1"); - e.configureXonoticTextSliderValues(e); - e.sendCvars = true; + e.addValue(e, _("Never"), "0"); + e.addValue(e, _("Sometimes"), "0.35"); + e.addValue(e, _("Often"), "0.65"); + e.addValue(e, _("Always"), "1"); + e.configureXonoticTextSliderValues(e); + e.sendCvars = true; me.TR(me); me.TR(me); - if(cvar("developer")) - me.TD(me, 1, 3, makeXonoticCheckBox(0, "showsound", _("Debug info about sounds"))); + if (cvar("developer")) { + me.TD(me, 1, 3, makeXonoticCheckBox(0, "showsound", _("Debug info about sounds"))); + } me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, audioApplyButton); + me.TD(me, 1, me.columns, audioApplyButton); } diff --git a/qcsrc/menu/xonotic/dialog_settings_audio.qh b/qcsrc/menu/xonotic/dialog_settings_audio.qh index 5794a70cc..4f51ce60d 100644 --- a/qcsrc/menu/xonotic/dialog_settings_audio.qh +++ b/qcsrc/menu/xonotic/dialog_settings_audio.qh @@ -5,7 +5,7 @@ CLASS(XonoticAudioSettingsTab, XonoticTab) METHOD(XonoticAudioSettingsTab, fill, void(entity)); ATTRIB(XonoticAudioSettingsTab, intendedWidth, float, 0.9); ATTRIB(XonoticAudioSettingsTab, rows, float, 15.5); - ATTRIB(XonoticAudioSettingsTab, columns, float, 6.2); // added extra .2 for center space + ATTRIB(XonoticAudioSettingsTab, columns, float, 6.2); // added extra .2 for center space ATTRIB(XonoticAudioSettingsTab, hiddenMenuSoundsSlider, entity); ENDCLASS(XonoticAudioSettingsTab) entity makeXonoticAudioSettingsTab(); diff --git a/qcsrc/menu/xonotic/dialog_settings_effects.qc b/qcsrc/menu/xonotic/dialog_settings_effects.qc index 6f5ba8f57..fd172fe9f 100644 --- a/qcsrc/menu/xonotic/dialog_settings_effects.qc +++ b/qcsrc/menu/xonotic/dialog_settings_effects.qc @@ -22,12 +22,16 @@ entity makeXonoticEffectsSettingsTab() float someShadowCvarIsEnabled(entity box) { - if(cvar("r_shadow_realtime_dlight")) - if(cvar("r_shadow_realtime_dlight_shadows")) + if (cvar("r_shadow_realtime_dlight")) { + if (cvar("r_shadow_realtime_dlight_shadows")) { return true; - if(cvar("r_shadow_realtime_world")) - if(cvar("r_shadow_realtime_world_shadows")) + } + } + if (cvar("r_shadow_realtime_world")) { + if (cvar("r_shadow_realtime_world_shadows")) { return true; + } + } return false; } @@ -38,224 +42,223 @@ void XonoticEffectsSettingsTab_fill(entity me) effectsApplyButton.disableOnClick = true; float n; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Quality preset:"))); - n = 5 + 2 * boolean(cvar("developer")); - if(cvar("developer")) - { - me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^OMG!")), '1 0 1', "exec effects-omg.cfg", 0)); - e.applyButton = effectsApplyButton; - } - me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Low")), '0 0 0', "exec effects-low.cfg", 0)); - e.applyButton = effectsApplyButton; - me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Medium")), '0 0 0', "exec effects-med.cfg", 0)); - e.applyButton = effectsApplyButton; - me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Normal")), '0 0 0', "exec effects-normal.cfg", 0)); - e.applyButton = effectsApplyButton; - me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^High")), '0 0 0', "exec effects-high.cfg", 0)); - e.applyButton = effectsApplyButton; - me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Ultra")), '0 0 0', "exec effects-ultra.cfg", 0)); - e.applyButton = effectsApplyButton; - if(cvar("developer")) - { - me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Ultimate")), '0.5 0 0', "exec effects-ultimate.cfg", 0)); - e.applyButton = effectsApplyButton; - } + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Quality preset:"))); + n = 5 + 2 * boolean(cvar("developer")); + if (cvar("developer")) { + me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^OMG!")), '1 0 1', "exec effects-omg.cfg", 0)); + e.applyButton = effectsApplyButton; + } + me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Low")), '0 0 0', "exec effects-low.cfg", 0)); + e.applyButton = effectsApplyButton; + me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Medium")), '0 0 0', "exec effects-med.cfg", 0)); + e.applyButton = effectsApplyButton; + me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Normal")), '0 0 0', "exec effects-normal.cfg", 0)); + e.applyButton = effectsApplyButton; + me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^High")), '0 0 0', "exec effects-high.cfg", 0)); + e.applyButton = effectsApplyButton; + me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Ultra")), '0 0 0', "exec effects-ultra.cfg", 0)); + e.applyButton = effectsApplyButton; + if (cvar("developer")) { + me.TD(me, 1, 5 / n, e = makeXonoticCommandButton(ZCTX(_("PRE^Ultimate")), '0.5 0 0', "exec effects-ultimate.cfg", 0)); + e.applyButton = effectsApplyButton; + } me.gotoRC(me, 1.25, 0); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Geometry detail:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("r_subdivisions_tolerance", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Geometry detail:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("r_subdivisions_tolerance", _("Change the smoothness of the curves on the map (default: normal)"))); - e.addValue(e, ZCTX(_("DET^Lowest")), "16"); - e.addValue(e, ZCTX(_("DET^Low")), "8"); - e.addValue(e, ZCTX(_("DET^Normal")), "4"); - e.addValue(e, ZCTX(_("DET^Good")), "3"); - e.addValue(e, ZCTX(_("DET^Best")), "2"); - e.addValue(e, ZCTX(_("DET^Insane")), "1"); - e.configureXonoticTextSliderValues(e); - e.applyButton = effectsApplyButton; + e.addValue(e, ZCTX(_("DET^Lowest")), "16"); + e.addValue(e, ZCTX(_("DET^Low")), "8"); + e.addValue(e, ZCTX(_("DET^Normal")), "4"); + e.addValue(e, ZCTX(_("DET^Good")), "3"); + e.addValue(e, ZCTX(_("DET^Best")), "2"); + e.addValue(e, ZCTX(_("DET^Insane")), "1"); + e.configureXonoticTextSliderValues(e); + e.applyButton = effectsApplyButton; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Player detail:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_playerdetailreduction")); - e.addValue(e, ZCTX(_("PDET^Low")), "4"); - e.addValue(e, ZCTX(_("PDET^Medium")), "3"); - e.addValue(e, ZCTX(_("PDET^Normal")), "2"); - e.addValue(e, ZCTX(_("PDET^Good")), "1"); - e.addValue(e, ZCTX(_("PDET^Best")), "0"); - e.configureXonoticTextSliderValues(e); - e.applyButton = effectsApplyButton; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Player detail:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_playerdetailreduction")); + e.addValue(e, ZCTX(_("PDET^Low")), "4"); + e.addValue(e, ZCTX(_("PDET^Medium")), "3"); + e.addValue(e, ZCTX(_("PDET^Normal")), "2"); + e.addValue(e, ZCTX(_("PDET^Good")), "1"); + e.addValue(e, ZCTX(_("PDET^Best")), "0"); + e.configureXonoticTextSliderValues(e); + e.applyButton = effectsApplyButton; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Texture resolution:"))); - setDependent(e, "r_showsurfaces", 0, 0); - me.TD(me, 1, 2, e = makeXonoticPicmipSlider()); - if(cvar("developer")) - e.addValue(e, ZCTX(_("RES^Leet")), "1337"); - e.addValue(e, ZCTX(_("RES^Lowest")), "3"); - e.addValue(e, ZCTX(_("RES^Very low")), "2"); - e.addValue(e, ZCTX(_("RES^Low")), "1"); - e.addValue(e, ZCTX(_("RES^Normal")), "0"); - e.addValue(e, ZCTX(_("RES^Good")), "-1"); - e.addValue(e, ZCTX(_("RES^Best")), "-2"); - e.configureXonoticTextSliderValues(e); - setDependent(e, "r_showsurfaces", 0, 0); - e.applyButton = effectsApplyButton; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Texture resolution:"))); + setDependent(e, "r_showsurfaces", 0, 0); + me.TD(me, 1, 2, e = makeXonoticPicmipSlider()); + if (cvar("developer")) { + e.addValue(e, ZCTX(_("RES^Leet")), "1337"); + } + e.addValue(e, ZCTX(_("RES^Lowest")), "3"); + e.addValue(e, ZCTX(_("RES^Very low")), "2"); + e.addValue(e, ZCTX(_("RES^Low")), "1"); + e.addValue(e, ZCTX(_("RES^Normal")), "0"); + e.addValue(e, ZCTX(_("RES^Good")), "-1"); + e.addValue(e, ZCTX(_("RES^Best")), "-2"); + e.configureXonoticTextSliderValues(e); + setDependent(e, "r_showsurfaces", 0, 0); + e.applyButton = effectsApplyButton; me.TR(me); - me.TDempty(me, 0.2); - { - // detect texture compression method - float f; - f = updateCompression(); - switch(f) - { - case 0: - me.TD(me, 1, 2.8, e = makeXonoticCheckBox(1, "r_texture_dds_load", _("Avoid lossy texture compression"))); - e.disabled = 1; // just show the checkbox anyway, but with no ability to control it - e.applyButton = effectsApplyButton; - break; - case 1: - me.TD(me, 1, 2.8, e = makeXonoticCheckBox(1, "r_texture_dds_load", _("Avoid lossy texture compression"))); - setDependent(e, "r_showsurfaces", 0, 0); - e.applyButton = effectsApplyButton; - break; - case 2: - me.TD(me, 1, 2.8, e = makeXonoticCheckBox(1, "r_texture_dds_load", _("Avoid lossy texture compression"))); - setDependent(e, "r_showsurfaces", 0, 0); - makeMulti(e, "gl_texturecompression"); - e.applyButton = effectsApplyButton; - break; - } + me.TDempty(me, 0.2); + { + // detect texture compression method + float f; + f = updateCompression(); + switch (f) { + case 0: + me.TD(me, 1, 2.8, e = makeXonoticCheckBox(1, "r_texture_dds_load", _("Avoid lossy texture compression"))); + e.disabled = 1; // just show the checkbox anyway, but with no ability to control it + e.applyButton = effectsApplyButton; + break; + case 1: + me.TD(me, 1, 2.8, e = makeXonoticCheckBox(1, "r_texture_dds_load", _("Avoid lossy texture compression"))); + setDependent(e, "r_showsurfaces", 0, 0); + e.applyButton = effectsApplyButton; + break; + case 2: + me.TD(me, 1, 2.8, e = makeXonoticCheckBox(1, "r_texture_dds_load", _("Avoid lossy texture compression"))); + setDependent(e, "r_showsurfaces", 0, 0); + makeMulti(e, "gl_texturecompression"); + e.applyButton = effectsApplyButton; + break; } + } me.TR(me); - if(cvar("developer")) - { - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx_T(3, 0, "r_showsurfaces", _("Show surfaces"), + if (cvar("developer")) { + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx_T(3, 0, "r_showsurfaces", _("Show surfaces"), _("Disable textures completely for very slow hardware. This gives a huge performance boost, but looks very ugly. (default: disabled)"))); - } + } me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(1, "mod_q3bsp_nolightmaps", _("Use lightmaps"), + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(1, "mod_q3bsp_nolightmaps", _("Use lightmaps"), _("Use high resolution lightmaps, which will look pretty but use up some extra video memory (default: enabled)"))); - e.applyButton = effectsApplyButton; - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_glsl_deluxemapping", _("Deluxe mapping"), + e.applyButton = effectsApplyButton; + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_glsl_deluxemapping", _("Deluxe mapping"), _("Use per-pixel lighting effects (default: enabled)"))); - setDependentAND(e, "vid_gl20", 1, 1, "mod_q3bsp_nolightmaps", 0, 0); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_shadow_gloss", _("Gloss"), + setDependentAND(e, "vid_gl20", 1, 1, "mod_q3bsp_nolightmaps", 0, 0); + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_shadow_gloss", _("Gloss"), _("Enable the use of glossmaps on textures supporting it (default: enabled)"))); - setDependentAND3(e, "vid_gl20", 1, 1, "mod_q3bsp_nolightmaps", 0, 0, "r_glsl_deluxemapping", 1, 1); + setDependentAND3(e, "vid_gl20", 1, 1, "mod_q3bsp_nolightmaps", 0, 0, "r_glsl_deluxemapping", 1, 1); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_glsl_offsetmapping", _("Offset mapping"), + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_glsl_offsetmapping", _("Offset mapping"), _("Offset mapping effect that will make textures with bumpmaps appear like they \"pop out\" of the flat 2D surface (default: disabled)"))); - setDependent(e, "vid_gl20", 1, 1); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_glsl_offsetmapping_reliefmapping", _("Relief mapping"), + setDependent(e, "vid_gl20", 1, 1); + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_glsl_offsetmapping_reliefmapping", _("Relief mapping"), _("Higher quality offset mapping, which also has a huge impact on performance (default: disabled)"))); - setDependentAND(e, "vid_gl20", 1, 1, "r_glsl_offsetmapping", 1, 1); + setDependentAND(e, "vid_gl20", 1, 1, "r_glsl_offsetmapping", 1, 1); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_water", _("Reflections:"), + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_water", _("Reflections:"), _("Reflection and refraction quality, has a huge impact on performance on maps with reflecting surfaces (default: disabled)"))); - setDependent(e, "vid_gl20", 1, 1); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("r_water_resolutionmultiplier", + setDependent(e, "vid_gl20", 1, 1); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("r_water_resolutionmultiplier", _("Resolution of reflections/refractions (default: good)"))); - e.addValue(e, _("Blurred"), "0.25"); - e.addValue(e, ZCTX(_("REFL^Good")), "0.5"); - e.addValue(e, _("Sharp"), "1"); - e.configureXonoticTextSliderValues(e); - setDependentAND(e, "vid_gl20", 1, 1, "r_water", 1, 1); + e.addValue(e, _("Blurred"), "0.25"); + e.addValue(e, ZCTX(_("REFL^Good")), "0.5"); + e.addValue(e, _("Sharp"), "1"); + e.configureXonoticTextSliderValues(e); + setDependentAND(e, "vid_gl20", 1, 1, "r_water", 1, 1); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "cl_decals", _("Decals"), + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "cl_decals", _("Decals"), _("Enable decals (bullet holes and blood) (default: enabled)"))); - me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "cl_decals_models", _("Decals on models"))); - setDependent(e, "cl_decals", 1, 1); + me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "cl_decals_models", _("Decals on models"))); + setDependent(e, "cl_decals", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Distance:"))); - setDependent(e, "cl_decals", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider_T(200, 500, 20, "r_drawdecals_drawdistance", + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Distance:"))); + setDependent(e, "cl_decals", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider_T(200, 500, 20, "r_drawdecals_drawdistance", _("Decals further away than this will not be drawn (default: 300)"))); - setDependent(e, "cl_decals", 1, 1); + setDependent(e, "cl_decals", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Time:"))); - setDependent(e, "cl_decals", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 20, 1, "cl_decals_fadetime", + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Time:"))); + setDependent(e, "cl_decals", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 20, 1, "cl_decals_fadetime", _("Time in seconds before decals fade away (default: 2)"))); - setDependent(e, "cl_decals", 1, 1); + setDependent(e, "cl_decals", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Damage effects:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_damageeffect")); - e.addValue(e, ZCTX(_("DMGFX^Disabled")), "0"); - e.addValue(e, _("Skeletal"), "1"); - e.addValue(e, ZCTX(_("DMGFX^All")), "2"); - e.configureXonoticTextSliderValues(e); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Damage effects:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_damageeffect")); + e.addValue(e, ZCTX(_("DMGFX^Disabled")), "0"); + e.addValue(e, _("Skeletal"), "1"); + e.addValue(e, ZCTX(_("DMGFX^All")), "2"); + e.configureXonoticTextSliderValues(e); - me.gotoRC(me, 1.25, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticRadioButton_T(1, "r_coronas", "0", _("No dynamic lighting"), + me.gotoRC(me, 1.25, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticRadioButton_T(1, "r_coronas", "0", _("No dynamic lighting"), _("Enable corona flares around certain lights (default: enabled)"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticRadioButton_T(1, "gl_flashblend", string_null, _("Fake corona lighting"), + me.TD(me, 1, 3, e = makeXonoticRadioButton_T(1, "gl_flashblend", string_null, _("Fake corona lighting"), _("Enable faster but uglier dynamic lights by rendering bright coronas instead of real dynamic lights (default: disabled)"))); - makeMulti(e, "r_coronas"); + makeMulti(e, "r_coronas"); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticRadioButton_T(1, "r_shadow_realtime_dlight", string_null, _("Realtime dynamic lighting"), + me.TD(me, 1, 2, e = makeXonoticRadioButton_T(1, "r_shadow_realtime_dlight", string_null, _("Realtime dynamic lighting"), _("Enable rendering of dynamic lights such as explosions and rocket lights (default: enabled)"))); - makeMulti(e, "r_coronas"); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_shadow_realtime_dlight_shadows", _("Shadows"), + makeMulti(e, "r_coronas"); + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_shadow_realtime_dlight_shadows", _("Shadows"), _("Enable rendering of shadows from dynamic lights (default: disabled)"))); - setDependent(e, "r_shadow_realtime_dlight", 1, 1); + setDependent(e, "r_shadow_realtime_dlight", 1, 1); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticCheckBox_T(0, "r_shadow_realtime_world", _("Realtime world lighting"), + me.TD(me, 1, 2, e = makeXonoticCheckBox_T(0, "r_shadow_realtime_world", _("Realtime world lighting"), _("Enable rendering of full realtime world lighting on maps that support it. Note that this might have a big impact on performance. (default: disabled)"))); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_shadow_realtime_world_shadows", _("Shadows"), + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_shadow_realtime_world_shadows", _("Shadows"), _("Enable rendering of shadows from realtime world lights (default: disabled)"))); - setDependent(e, "r_shadow_realtime_world", 1, 1); + setDependent(e, "r_shadow_realtime_world", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "r_shadow_usenormalmap", _("Use normal maps"), + me.TDempty(me, 0.2); + me.TD(me, 1, 1.8, e = makeXonoticCheckBox_T(0, "r_shadow_usenormalmap", _("Use normal maps"), _("Enable use of directional shading on textures (default: enabled)"))); - setDependentOR(e, "r_shadow_realtime_dlight", 1, 1, "r_shadow_realtime_world", 1, 1); - me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "r_shadow_shadowmapping", _("Soft shadows"))); - setDependentWeird(e, someShadowCvarIsEnabled); + setDependentOR(e, "r_shadow_realtime_dlight", 1, 1, "r_shadow_realtime_world", 1, 1); + me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "r_shadow_shadowmapping", _("Soft shadows"))); + setDependentWeird(e, someShadowCvarIsEnabled); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "r_coronas_occlusionquery", _("Fade corona according to visibility"), + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "r_coronas_occlusionquery", _("Fade corona according to visibility"), _("Fade coronas according to visibility (default: enabled)"))); - setDependent(e, "r_coronas", 1, 1); + setDependent(e, "r_coronas", 1, 1); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_bloom", _("Bloom"), + me.TD(me, 1, 1, e = makeXonoticCheckBox_T(0, "r_bloom", _("Bloom"), _("Enable bloom effect, which brightens the neighboring pixels of very bright pixels. Has a big impact on performance. (default: disabled)"))); - me.TD(me, 1, 2, e = makeXonoticCheckBoxEx_T(0.5, 0, "hud_postprocessing_maxbluralpha", _("Extra postprocessing effects"), + me.TD(me, 1, 2, e = makeXonoticCheckBoxEx_T(0.5, 0, "hud_postprocessing_maxbluralpha", _("Extra postprocessing effects"), _("Enables special postprocessing effects for when damaged or under water or using a powerup (default: disabled)"))); - makeMulti(e, "hud_powerup"); - setDependent(e, "vid_gl20", 1, 1); + makeMulti(e, "hud_powerup"); + setDependent(e, "vid_gl20", 1, 1); me.TR(me); - s = makeXonoticSlider_T(0.1, 1, 0.1, "r_motionblur", - _("Motion blur strength - 0.4 recommended")); - me.TD(me, 1, 1, e = makeXonoticSliderCheckBox(0, 1, s, _("Motion blur:"))); - if(s.value != e.savedValue) - e.savedValue = 0.4; // default - me.TD(me, 1, 2, s); + s = makeXonoticSlider_T(0.1, 1, 0.1, "r_motionblur", + _("Motion blur strength - 0.4 recommended")); + me.TD(me, 1, 1, e = makeXonoticSliderCheckBox(0, 1, s, _("Motion blur:"))); + if (s.value != e.savedValue) { + e.savedValue = 0.4; // default + } + me.TD(me, 1, 2, s); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "cl_particles", _("Particles"))); - me.TD(me, 1, 2, e = makeXonoticCheckBox_T(0, "cl_spawn_point_particles", _("Spawnpoint effects"), + me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "cl_particles", _("Particles"))); + me.TD(me, 1, 2, e = makeXonoticCheckBox_T(0, "cl_spawn_point_particles", _("Spawnpoint effects"), _("Particles effects at all spawn points and whenever a player spawns"))); - makeMulti(e, "cl_spawn_event_particles"); - setDependent(e, "cl_particles", 1, 1); + makeMulti(e, "cl_spawn_event_particles"); + setDependent(e, "cl_particles", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Quality:"))); - setDependent(e, "cl_particles", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 3.0, 0.25, "cl_particles_quality", + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Quality:"))); + setDependent(e, "cl_particles", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 3.0, 0.25, "cl_particles_quality", _("Multiplier for amount of particles. Less means less particles, which in turn gives for better performance (default: 1.0)"))); - setDependent(e, "cl_particles", 1, 1); + setDependent(e, "cl_particles", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Distance:"))); - setDependent(e, "cl_particles", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider_T(200, 3000, 200, "r_drawparticles_drawdistance", + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Distance:"))); + setDependent(e, "cl_particles", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider_T(200, 3000, 200, "r_drawparticles_drawdistance", _("Particles further away than this will not be drawn (default: 1000)"))); - setDependent(e, "cl_particles", 1, 1); + setDependent(e, "cl_particles", 1, 1); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, effectsApplyButton); + me.TD(me, 1, me.columns, effectsApplyButton); } diff --git a/qcsrc/menu/xonotic/dialog_settings_effects.qh b/qcsrc/menu/xonotic/dialog_settings_effects.qh index 369c68d91..82ce85f87 100644 --- a/qcsrc/menu/xonotic/dialog_settings_effects.qh +++ b/qcsrc/menu/xonotic/dialog_settings_effects.qh @@ -5,6 +5,6 @@ CLASS(XonoticEffectsSettingsTab, XonoticTab) METHOD(XonoticEffectsSettingsTab, fill, void(entity)); ATTRIB(XonoticEffectsSettingsTab, intendedWidth, float, 0.9); ATTRIB(XonoticEffectsSettingsTab, rows, float, 15.5); - ATTRIB(XonoticEffectsSettingsTab, columns, float, 6.2); // added extra .2 for center space + ATTRIB(XonoticEffectsSettingsTab, columns, float, 6.2); // added extra .2 for center space ENDCLASS(XonoticEffectsSettingsTab) entity makeXonoticEffectsSettingsTab(); diff --git a/qcsrc/menu/xonotic/dialog_settings_game_crosshair.qc b/qcsrc/menu/xonotic/dialog_settings_game_crosshair.qc index 2d30dc244..a3cb2e81d 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game_crosshair.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game_crosshair.qc @@ -27,122 +27,123 @@ void XonoticGameCrosshairSettingsTab_fill(entity me) // crosshair_enabled: 0 = no crosshair options, 1 = no crosshair selection, but everything else enabled, 2 = all crosshair options enabled // FIXME: In the future, perhaps make one global crosshair_type cvar which has 0 for disabled, 1 for custom, 2 for per weapon, etc? - me.TR(me); //me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1, e = makeXonoticRadioButton(3, "crosshair_enabled", "0", _("No crosshair"))); - //me.TR(me); - me.TD(me, 1, 1, e = makeXonoticRadioButton_T(3, "crosshair_per_weapon", string_null, _("Per weapon"), + me.TR(me); // me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 1, e = makeXonoticRadioButton(3, "crosshair_enabled", "0", _("No crosshair"))); + // me.TR(me); + me.TD(me, 1, 1, e = makeXonoticRadioButton_T(3, "crosshair_per_weapon", string_null, _("Per weapon"), _("Set a different crosshair for each weapon, good if you play without weapon models"))); - makeMulti(e, "crosshair_enabled"); - //me.TR(me); - me.TD(me, 1, 1, e = makeXonoticRadioButton(3, "crosshair_enabled", "2", _("Custom"))); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 3, 2, e = makeXonoticCrosshairPicker()); - setDependentAND(e, "crosshair_per_weapon", 0, 0, "crosshair_enabled", 1, 2); - me.TD(me, 3, 0.9, e = makeXonoticCrosshairPreview()); - setDependentAND(e, "crosshair_per_weapon", 0, 0, "crosshair_enabled", 1, 2); - me.TR(me); - me.TR(me); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Size:"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TD(me, 1, 1.9, e = makeXonoticSlider(0.1, 1.0, 0.01, "crosshair_size")); - setDependent(e, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Alpha:"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TD(me, 1, 1.9, e = makeXonoticSlider(0, 1, 0.1, "crosshair_alpha")); - setDependent(e, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Color:"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TD(me, 1, 0.9, e = makeXonoticRadioButton(5, "crosshair_color_special", "1", _("Per weapon"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TD(me, 1, 1, e = makeXonoticRadioButton(5, "crosshair_color_special", "2", _("By health"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticRadioButton(5, "crosshair_color_special", "0", _("Custom"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TD(me, 2, 2, e = makeXonoticColorpickerString("crosshair_color", "crosshair_color")); - setDependentAND(e, "crosshair_color_special", 0, 0, "crosshair_enabled", 1, 2); - me.TR(me); - me.TR(me); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 2.9, e = makeXonoticCheckBox_T(0, "crosshair_ring", _("Use rings to indicate weapon status"), "-")); - makeMulti(e, "crosshair_ring_reload"); - setDependent(e, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.3); - me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Size:"))); - setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); - me.TD(me, 1, 1.8, e = makeXonoticSlider(2, 4, 0.1, "crosshair_ring_size")); - setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.3); - me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Alpha:"))); - setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); - me.TD(me, 1, 1.8, e = makeXonoticSlider(0.1, 1, 0.1, "crosshair_ring_alpha")); - setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); + makeMulti(e, "crosshair_enabled"); + // me.TR(me); + me.TD(me, 1, 1, e = makeXonoticRadioButton(3, "crosshair_enabled", "2", _("Custom"))); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 3, 2, e = makeXonoticCrosshairPicker()); + setDependentAND(e, "crosshair_per_weapon", 0, 0, "crosshair_enabled", 1, 2); + me.TD(me, 3, 0.9, e = makeXonoticCrosshairPreview()); + setDependentAND(e, "crosshair_per_weapon", 0, 0, "crosshair_enabled", 1, 2); + me.TR(me); + me.TR(me); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Size:"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 1, 1.9, e = makeXonoticSlider(0.1, 1.0, 0.01, "crosshair_size")); + setDependent(e, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Alpha:"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 1, 1.9, e = makeXonoticSlider(0, 1, 0.1, "crosshair_alpha")); + setDependent(e, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Color:"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 1, 0.9, e = makeXonoticRadioButton(5, "crosshair_color_special", "1", _("Per weapon"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 1, 1, e = makeXonoticRadioButton(5, "crosshair_color_special", "2", _("By health"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticRadioButton(5, "crosshair_color_special", "0", _("Custom"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 2, 2, e = makeXonoticColorpickerString("crosshair_color", "crosshair_color")); + setDependentAND(e, "crosshair_color_special", 0, 0, "crosshair_enabled", 1, 2); + me.TR(me); + me.TR(me); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 1, 2.9, e = makeXonoticCheckBox_T(0, "crosshair_ring", _("Use rings to indicate weapon status"), "-")); + makeMulti(e, "crosshair_ring_reload"); + setDependent(e, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.3); + me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Size:"))); + setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); + me.TD(me, 1, 1.8, e = makeXonoticSlider(2, 4, 0.1, "crosshair_ring_size")); + setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.3); + me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Alpha:"))); + setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); + me.TD(me, 1, 1.8, e = makeXonoticSlider(0.1, 1, 0.1, "crosshair_ring_alpha")); + setDependentAND(e, "crosshair_ring", 1, 1, "crosshair_enabled", 1, 2); - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "crosshair_dot", _("Enable center crosshair dot"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Size:"))); - setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); - me.TD(me, 1, 2, e = makeXonoticSlider(0.2, 2, 0.1, "crosshair_dot_size")); - setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Alpha:"))); - setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); - me.TD(me, 1, 2, e = makeXonoticSlider(0.1, 1, 0.1, "crosshair_dot_alpha")); - setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Color:"))); - setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); - me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "crosshair_dot_color_custom", "0", _("Use normal crosshair color"))); - setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticRadioButton(1, "crosshair_dot_color_custom", "1", _("Custom"))); - setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); - me.TD(me, 2, 2, e = makeXonoticColorpickerString("crosshair_dot_color", "crosshair_dot_color")); - setDependentAND3(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2, "crosshair_dot_color_custom", 1, 1); - me.TR(me); - me.TR(me); - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "crosshair_effect_scalefade", _("Smooth effects of crosshairs"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Hit testing:"))); - setDependent(e, "crosshair_enabled", 1, 2); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("crosshair_hittest", + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "crosshair_dot", _("Enable center crosshair dot"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Size:"))); + setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); + me.TD(me, 1, 2, e = makeXonoticSlider(0.2, 2, 0.1, "crosshair_dot_size")); + setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Alpha:"))); + setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); + me.TD(me, 1, 2, e = makeXonoticSlider(0.1, 1, 0.1, "crosshair_dot_alpha")); + setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.1); + me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Color:"))); + setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); + me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "crosshair_dot_color_custom", "0", _("Use normal crosshair color"))); + setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticRadioButton(1, "crosshair_dot_color_custom", "1", _("Custom"))); + setDependentAND(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2); + me.TD(me, 2, 2, e = makeXonoticColorpickerString("crosshair_dot_color", "crosshair_dot_color")); + setDependentAND3(e, "crosshair_dot", 1, 1, "crosshair_enabled", 1, 2, "crosshair_dot_color_custom", 1, 1); + me.TR(me); + me.TR(me); + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "crosshair_effect_scalefade", _("Smooth effects of crosshairs"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Hit testing:"))); + setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("crosshair_hittest", _("None: do not do hit tests for the crosshair; TrueAim: blur the crosshair when there's an obstacle between your gun and the target; Enemies: also enlarge the crosshair when you would hit an enemy"))); - e.addValue(e, ZCTX(_("HTTST^Disabled")), "0"); - e.addValue(e, ZCTX(_("HTTST^TrueAim")), "1"); - e.addValue(e, ZCTX(_("HTTST^Enemies")), "1.25"); - e.configureXonoticTextSliderValues(e); - setDependent(e, "crosshair_enabled", 1, 2); + e.addValue(e, ZCTX(_("HTTST^Disabled")), "0"); + e.addValue(e, ZCTX(_("HTTST^TrueAim")), "1"); + e.addValue(e, ZCTX(_("HTTST^Enemies")), "1.25"); + e.configureXonoticTextSliderValues(e); + setDependent(e, "crosshair_enabled", 1, 2); me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 2.9, e = makeXonoticCheckBox(0, "crosshair_hittest_blur", _("Blur crosshair if the shot is obstructed"))); - setDependentAND(e, "crosshair_hittest", 1, 100, "crosshair_enabled", 1, 2); + me.TDempty(me, 0.1); + me.TD(me, 1, 2.9, e = makeXonoticCheckBox(0, "crosshair_hittest_blur", _("Blur crosshair if the shot is obstructed"))); + setDependentAND(e, "crosshair_hittest", 1, 100, "crosshair_enabled", 1, 2); me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 2.9, e = makeXonoticCheckBoxEx(1.25, 0, "crosshair_hittest_scale", _("Enlarge crosshair if targeting an enemy"))); - setDependentAND(e, "crosshair_hittest", 1, 100, "crosshair_enabled", 1, 2); + me.TDempty(me, 0.1); + me.TD(me, 1, 2.9, e = makeXonoticCheckBoxEx(1.25, 0, "crosshair_hittest_scale", _("Enlarge crosshair if targeting an enemy"))); + setDependentAND(e, "crosshair_hittest", 1, 100, "crosshair_enabled", 1, 2); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(0.5, 0, "crosshair_hitindication", _("Animate crosshair when hitting an enemy"))); - setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(0.5, 0, "crosshair_hitindication", _("Animate crosshair when hitting an enemy"))); + setDependent(e, "crosshair_enabled", 1, 2); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(0.25, 0, "crosshair_pickup", _("Animate crosshair when picking up an item"))); - setDependent(e, "crosshair_enabled", 1, 2); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(0.25, 0, "crosshair_pickup", _("Animate crosshair when picking up an item"))); + setDependent(e, "crosshair_enabled", 1, 2); } diff --git a/qcsrc/menu/xonotic/dialog_settings_game_hud.qc b/qcsrc/menu/xonotic/dialog_settings_game_hud.qc index e16693675..8ab6b0f1c 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game_hud.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game_hud.qc @@ -10,12 +10,9 @@ void HUDSetup_Check_Gamestatus(entity me, entity btn) { - if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, ask the player if they want to start one anyway - { + if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) { // we're not in a match, ask the player if they want to start one anyway DialogOpenButton_Click(me, main.hudconfirmDialog); - } - else // already in a match, lets just cut to the point and open up the hud editor directly - { + } else { // already in a match, lets just cut to the point and open up the hud editor directly HUDSetup_Start(me, btn); } } @@ -40,132 +37,133 @@ void XonoticGameHUDSettingsTab_fill(entity me) // scoreboard_alpha* me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Scoreboard"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Scoreboard"))); me.TR(me); me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Alpha:"))); me.TD(me, 1, 2, e = makeXonoticSlider(0, 1, 0.05, "hud_panel_scoreboard_bg_alpha")); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Fading speed:"))); - me.TD(me, 1, 2, e = makeXonoticScoreboardFadeTimeSlider()); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Fading speed:"))); + me.TD(me, 1, 2, e = makeXonoticScoreboardFadeTimeSlider()); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_scoreboard_table_highlight", _("Enable rows / columns highlighting"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_scoreboard_table_highlight", _("Enable rows / columns highlighting"))); me.TR(me); - //me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_scoreboard_respawntime_decimals", _("Show decimals in respawn countdown"))); + // me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_scoreboard_respawntime_decimals", _("Show decimals in respawn countdown"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_scoreboard_accuracy", _("Show accuracy underneath scoreboard"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_scoreboard_accuracy", _("Show accuracy underneath scoreboard"))); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Waypoints"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Waypoints"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(1, "cl_hidewaypoints", _("Display waypoint markers for objectives on the map"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(1, "cl_hidewaypoints", _("Display waypoint markers for objectives on the map"), _("Show various gametype specific waypoints"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Alpha:"))); - setDependent(e, "cl_hidewaypoints", 0, 0); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0.1, 1, 0.05, "g_waypointsprite_alpha", + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Alpha:"))); + setDependent(e, "cl_hidewaypoints", 0, 0); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0.1, 1, 0.05, "g_waypointsprite_alpha", _("Control transparency of the waypoints"))); - setDependent(e, "cl_hidewaypoints", 0, 0); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Fontsize:"))); - setDependent(e, "cl_hidewaypoints", 0, 0); - me.TD(me, 1, 2, e = makeXonoticSlider(5, 16, 1, "g_waypointsprite_fontsize")); - setDependent(e, "cl_hidewaypoints", 0, 0); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Edge offset:"))); - setDependent(e, "cl_hidewaypoints", 0, 0); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 0.3, 0.01, "g_waypointsprite_edgeoffset_bottom", "-")); - makeMulti(e, "g_waypointsprite_edgeoffset_top g_waypointsprite_edgeoffset_left g_waypointsprite_edgeoffset_right"); - setDependent(e, "cl_hidewaypoints", 0, 0); + setDependent(e, "cl_hidewaypoints", 0, 0); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Fontsize:"))); + setDependent(e, "cl_hidewaypoints", 0, 0); + me.TD(me, 1, 2, e = makeXonoticSlider(5, 16, 1, "g_waypointsprite_fontsize")); + setDependent(e, "cl_hidewaypoints", 0, 0); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Edge offset:"))); + setDependent(e, "cl_hidewaypoints", 0, 0); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 0.3, 0.01, "g_waypointsprite_edgeoffset_bottom", "-")); + makeMulti(e, "g_waypointsprite_edgeoffset_top g_waypointsprite_edgeoffset_left g_waypointsprite_edgeoffset_right"); + setDependent(e, "cl_hidewaypoints", 0, 0); me.TR(me); - //me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(0.25, 1, "g_waypointsprite_crosshairfadealpha", _("Fade when near the crosshair"))); - setDependent(e, "cl_hidewaypoints", 0, 0); + // me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(0.25, 1, "g_waypointsprite_crosshairfadealpha", _("Fade when near the crosshair"))); + setDependent(e, "cl_hidewaypoints", 0, 0); #if 0 me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Damage"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Damage"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Overlay:"))); - me.TD(me, 1, 2, e = makeXonoticSlider(0, 1, 0.05, "hud_damage")); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Overlay:"))); + me.TD(me, 1, 2, e = makeXonoticSlider(0, 1, 0.05, "hud_damage")); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Factor:"))); - setDependent(e, "hud_damage", 0.001, 100); - me.TD(me, 1, 2, e = makeXonoticSlider(0.025, 0.1, 0.025, "hud_damage_factor")); - setDependent(e, "hud_damage", 0.001, 100); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Factor:"))); + setDependent(e, "hud_damage", 0.001, 100); + me.TD(me, 1, 2, e = makeXonoticSlider(0.025, 0.1, 0.025, "hud_damage_factor")); + setDependent(e, "hud_damage", 0.001, 100); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Fade rate:"))); - setDependent(e, "hud_damage", 0.001, 100); - me.TD(me, 1, 2, e = makeXonoticSlider(0.25, 1, 0.05, "hud_damage_fade_rate")); - setDependent(e, "hud_damage", 0.001, 100); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Fade rate:"))); + setDependent(e, "hud_damage", 0.001, 100); + me.TD(me, 1, 2, e = makeXonoticSlider(0.25, 1, 0.05, "hud_damage_fade_rate")); + setDependent(e, "hud_damage", 0.001, 100); me.TR(me); #endif - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Player Names"))); + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Player Names"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_shownames", _("Show names above players"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_shownames", _("Show names above players"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Alpha:"))); - setDependent(e, "hud_shownames", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider(0.1, 1, 0.05, "hud_shownames_alpha")); - setDependent(e, "hud_shownames", 1, 1); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Fontsize:"))); - setDependent(e, "hud_shownames", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider(5, 16, 1, "hud_shownames_fontsize")); - setDependent(e, "hud_shownames", 1, 1); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Max distance:"))); - setDependent(e, "hud_shownames", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider(2000, 10000, 500, "hud_shownames_maxdistance")); - setDependent(e, "hud_shownames", 1, 1); - me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Decolorize:"))); - setDependent(e, "hud_shownames", 1, 1); - me.TD(me, 1, 2, e = makeXonoticTextSlider("hud_shownames_decolorize")); - e.addValue(e, _("Never"), "0"); - e.addValue(e, _("Teamplay"), "1"); - e.addValue(e, _("Always"), "2"); - e.configureXonoticTextSliderValues(e); - setDependent(e, "hud_shownames", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Alpha:"))); + setDependent(e, "hud_shownames", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider(0.1, 1, 0.05, "hud_shownames_alpha")); + setDependent(e, "hud_shownames", 1, 1); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Fontsize:"))); + setDependent(e, "hud_shownames", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider(5, 16, 1, "hud_shownames_fontsize")); + setDependent(e, "hud_shownames", 1, 1); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Max distance:"))); + setDependent(e, "hud_shownames", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider(2000, 10000, 500, "hud_shownames_maxdistance")); + setDependent(e, "hud_shownames", 1, 1); + me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Decolorize:"))); + setDependent(e, "hud_shownames", 1, 1); + me.TD(me, 1, 2, e = makeXonoticTextSlider("hud_shownames_decolorize")); + e.addValue(e, _("Never"), "0"); + e.addValue(e, _("Teamplay"), "1"); + e.addValue(e, _("Always"), "2"); + e.configureXonoticTextSliderValues(e); + setDependent(e, "hud_shownames", 1, 1); me.TR(me); - //me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(25, 0, "hud_shownames_crosshairdistance", _("Only when near crosshair"))); - setDependent(e, "hud_shownames", 1, 1); + // me.TR(me); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(25, 0, "hud_shownames_crosshairdistance", _("Only when near crosshair"))); + setDependent(e, "hud_shownames", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox(0, "hud_shownames_status", _("Display health and armor"))); - setDependent(e, "hud_shownames", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox(0, "hud_shownames_status", _("Display health and armor"))); + setDependent(e, "hud_shownames", 1, 1); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Damage overlay:"))); - me.TD(me, 1, 2, e = makeXonoticSlider(0, 1, 0.05, "hud_damage")); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Damage overlay:"))); + me.TD(me, 1, 2, e = makeXonoticSlider(0, 1, 0.05, "hud_damage")); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "hud_dynamic_follow", _("Dynamic HUD"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "hud_dynamic_follow", _("Dynamic HUD"), _("HUD moves around following player's movement"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_dynamic_shake", _("Shake the HUD when hurt"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_dynamic_shake", _("Shake the HUD when hurt"))); me.TR(me); me.TR(me); - me.TDempty(me, 0.5); - me.TD(me, 1, 2, e = makeXonoticButton(_("Enter HUD editor"), '0 0 0')); - e.onClick = HUDSetup_Check_Gamestatus; - e.onClickEntity = me; - // TODO: show hud config name with text here + me.TDempty(me, 0.5); + me.TD(me, 1, 2, e = makeXonoticButton(_("Enter HUD editor"), '0 0 0')); + e.onClick = HUDSetup_Check_Gamestatus; + e.onClickEntity = me; + // TODO: show hud config name with text here } diff --git a/qcsrc/menu/xonotic/dialog_settings_game_hudconfirm.qc b/qcsrc/menu/xonotic/dialog_settings_game_hudconfirm.qc index b1426c2c9..d4f7673ea 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game_hudconfirm.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game_hudconfirm.qc @@ -5,10 +5,11 @@ void HUDSetup_Start(entity me, entity btn) { - if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) + if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) { localcmd("map _hudsetup\n"); - else + } else { localcmd("togglemenu 0\n"); + } localcmd("_hud_configure 1\n"); } @@ -18,15 +19,15 @@ void XonoticHUDConfirmDialog_fill(entity me) entity e; me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("In order for the HUD editor to show, you must first be in game."))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("In order for the HUD editor to show, you must first be in game."))); me.TR(me); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Do you wish to start a local game to set up the HUD?"))); + me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Do you wish to start a local game to set up the HUD?"))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticButton(_("Yes"), '1 0 0')); - e.onClick = HUDSetup_Start; - e.onClickEntity = me; - me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, 1, e = makeXonoticButton(_("Yes"), '1 0 0')); + e.onClick = HUDSetup_Start; + e.onClickEntity = me; + me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_settings_game_messages.qc b/qcsrc/menu/xonotic/dialog_settings_game_messages.qc index 31cc98215..01a2824a6 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game_messages.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game_messages.qc @@ -21,86 +21,89 @@ void XonoticGameMessageSettingsTab_fill(entity me) entity e; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Frag Information"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Frag Information"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_show_sprees", _("Display information about killing sprees"), "-")); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_show_sprees", _("Display information about killing sprees"), "-")); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "notification_show_sprees_info_specialonly", _("Only display sprees if they are achievements"), "-")); - makeMulti(e, "notification_show_sprees_center_specialonly"); - setDependent(e, "notification_show_sprees", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "notification_show_sprees_info_specialonly", _("Only display sprees if they are achievements"), "-")); + makeMulti(e, "notification_show_sprees_center_specialonly"); + setDependent(e, "notification_show_sprees", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "notification_show_sprees_center", _("Show spree information in centerprints"), "-")); - setDependent(e, "notification_show_sprees", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "notification_show_sprees_center", _("Show spree information in centerprints"), "-")); + setDependent(e, "notification_show_sprees", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx_T(3, 0, "notification_show_sprees_info", _("Show spree information in death messages"), "-")); - setDependent(e, "notification_show_sprees", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx_T(3, 0, "notification_show_sprees_info", _("Show spree information in death messages"), "-")); + setDependent(e, "notification_show_sprees", 1, 1); #if 0 me.TR(me); - me.TDempty(me, 0.1); - me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Sprees in info messages:"))); - setDependent(e, "notification_show_sprees", 1, 1); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("notification_show_sprees_info", "-")); - e.addValue(e, ZCTX(_("SPREES^Disabled")), "0"); - e.addValue(e, _("Target"), "1"); - e.addValue(e, _("Attacker"), "2"); - e.addValue(e, ZCTX(_("SPREES^Both")), "3"); - e.configureXonoticTextSliderValues(e); - setDependent(e, "notification_show_sprees", 1, 1); + me.TDempty(me, 0.1); + me.TD(me, 1, 0.9, e = makeXonoticTextLabel(0, _("Sprees in info messages:"))); + setDependent(e, "notification_show_sprees", 1, 1); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("notification_show_sprees_info", "-")); + e.addValue(e, ZCTX(_("SPREES^Disabled")), "0"); + e.addValue(e, _("Target"), "1"); + e.addValue(e, _("Attacker"), "2"); + e.addValue(e, ZCTX(_("SPREES^Both")), "3"); + e.configureXonoticTextSliderValues(e); + setDependent(e, "notification_show_sprees", 1, 1); #endif me.TR(me); - me.TDempty(me, 0.4); - me.TD(me, 1, 2.6, e = makeXonoticCheckBox_T(0, "notification_show_sprees_info_newline", _("Print on a seperate line"), "-")); - setDependentAND(e, "notification_show_sprees", 1, 1, "notification_show_sprees_info", 1, 3); + me.TDempty(me, 0.4); + me.TD(me, 1, 2.6, e = makeXonoticCheckBox_T(0, "notification_show_sprees_info_newline", _("Print on a seperate line"), "-")); + setDependentAND(e, "notification_show_sprees", 1, 1, "notification_show_sprees_info", 1, 3); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_CHOICE_FRAG", _("Add extra frag information to centerprint when available"), "-")); - makeMulti(e, "notification_CHOICE_FRAGGED notification_CHOICE_TYPEFRAG notification_CHOICE_TYPEFRAGGED notification_CHOICE_FRAG_FIRE notification_CHOICE_FRAGGED_FIRE notification_CHOICE_FRAG_FREEZE notification_CHOICE_FRAGGED_FREEZE"); - e.sendCvars = true; + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_CHOICE_FRAG", _("Add extra frag information to centerprint when available"), "-")); + makeMulti(e, "notification_CHOICE_FRAGGED notification_CHOICE_TYPEFRAG notification_CHOICE_TYPEFRAGGED notification_CHOICE_FRAG_FIRE notification_CHOICE_FRAGGED_FIRE notification_CHOICE_FRAG_FREEZE notification_CHOICE_FRAGGED_FREEZE"); + e.sendCvars = true; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_show_location", _("Add frag location to death messages when available"), "-")); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_show_location", _("Add frag location to death messages when available"), "-")); - me.gotoRC(me, 9, 0); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Gamemode Settings"))); + me.gotoRC(me, 9, 0); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Gamemode Settings"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_CHOICE_CTF_CAPTURE_TIME", _("Display capture times in Capture The Flag"), "-")); - makeMulti(e, "notification_CHOICE_CTF_CAPTURE_BROKEN notification_CHOICE_CTF_CAPTURE_UNBROKEN"); - e.sendCvars = true; + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_CHOICE_CTF_CAPTURE_TIME", _("Display capture times in Capture The Flag"), "-")); + makeMulti(e, "notification_CHOICE_CTF_CAPTURE_BROKEN notification_CHOICE_CTF_CAPTURE_UNBROKEN"); + e.sendCvars = true; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_CHOICE_CTF_PICKUP_ENEMY", _("Display name of flag stealer in Capture The Flag"), "-")); - makeMulti(e, "notification_CHOICE_CTF_PICKUP_ENEMY_TEAM notification_CHOICE_CTF_PICKUP_ENEMY_NEUTRAL"); - e.sendCvars = true; + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_CHOICE_CTF_PICKUP_ENEMY", _("Display name of flag stealer in Capture The Flag"), "-")); + makeMulti(e, "notification_CHOICE_CTF_PICKUP_ENEMY_TEAM notification_CHOICE_CTF_PICKUP_ENEMY_NEUTRAL"); + e.sendCvars = true; - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Other"))); + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Other"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(4, 0, "con_notify", _("Display console messages in the top left corner"), "-")); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(4, 0, "con_notify", _("Display console messages in the top left corner"), "-")); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_allow_chatboxprint", _("Display all info messages in the chatbox"), "-")); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_allow_chatboxprint", _("Display all info messages in the chatbox"), "-")); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_INFO_QUIT_DISCONNECT", _("Display player statuses in the chatbox"), "-")); - makeMulti(e, "notification_INFO_QUIT_KICK_IDLING notification_INFO_JOIN_CONNECT_TEAM"); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 1, "notification_INFO_QUIT_DISCONNECT", _("Display player statuses in the chatbox"), "-")); + makeMulti(e, "notification_INFO_QUIT_KICK_IDLING notification_INFO_JOIN_CONNECT_TEAM"); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_CENTER_POWERUP_INVISIBILITY", _("Powerup notifications"), "-")); - makeMulti(e, "notification_CENTER_POWERUP_SHIELD notification_CENTER_POWERUP_SPEED notification_CENTER_POWERUP_STRENGTH notification_CENTER_POWERDOWN_INVISIBILITY notification_CENTER_POWERDOWN_SHIELD notification_CENTER_POWERDOWN_SPEED notification_CENTER_POWERDOWN_STRENGTH notification_CENTER_SUPERWEAPON_BROKEN notification_CENTER_SUPERWEAPON_LOST notification_CENTER_SUPERWEAPON_PICKUP notification_INFO_POWERUP_INVISIBILITY notification_INFO_POWERUP_SHIELD notification_INFO_POWERUP_SPEED notification_INFO_POWERUP_STRENGTH"); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_CENTER_POWERUP_INVISIBILITY", _("Powerup notifications"), "-")); + makeMulti(e, "notification_CENTER_POWERUP_SHIELD notification_CENTER_POWERUP_SPEED notification_CENTER_POWERUP_STRENGTH notification_CENTER_POWERDOWN_INVISIBILITY notification_CENTER_POWERDOWN_SHIELD notification_CENTER_POWERDOWN_SPEED notification_CENTER_POWERDOWN_STRENGTH notification_CENTER_SUPERWEAPON_BROKEN notification_CENTER_SUPERWEAPON_LOST notification_CENTER_SUPERWEAPON_PICKUP notification_INFO_POWERUP_INVISIBILITY notification_INFO_POWERUP_SHIELD notification_INFO_POWERUP_SPEED notification_INFO_POWERUP_STRENGTH"); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_CENTER_ITEM_WEAPON_DONTHAVE", _("Weapon centerprint notifications"), "-")); - makeMulti(e, "notification_CENTER_ITEM_WEAPON_DROP notification_CENTER_ITEM_WEAPON_GOT notification_CENTER_ITEM_WEAPON_NOAMMO notification_CENTER_ITEM_WEAPON_PRIMORSEC notification_CENTER_ITEM_WEAPON_UNAVAILABLE"); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_CENTER_ITEM_WEAPON_DONTHAVE", _("Weapon centerprint notifications"), "-")); + makeMulti(e, "notification_CENTER_ITEM_WEAPON_DROP notification_CENTER_ITEM_WEAPON_GOT notification_CENTER_ITEM_WEAPON_NOAMMO notification_CENTER_ITEM_WEAPON_PRIMORSEC notification_CENTER_ITEM_WEAPON_UNAVAILABLE"); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_INFO_ITEM_WEAPON_DONTHAVE", _("Weapon info message notifications"), "-")); - makeMulti(e, "notification_INFO_ITEM_WEAPON_DROP notification_INFO_ITEM_WEAPON_GOT notification_INFO_ITEM_WEAPON_NOAMMO notification_INFO_ITEM_WEAPON_PRIMORSEC notification_INFO_ITEM_WEAPON_UNAVAILABLE"); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "notification_INFO_ITEM_WEAPON_DONTHAVE", _("Weapon info message notifications"), "-")); + makeMulti(e, "notification_INFO_ITEM_WEAPON_DROP notification_INFO_ITEM_WEAPON_GOT notification_INFO_ITEM_WEAPON_NOAMMO notification_INFO_ITEM_WEAPON_PRIMORSEC notification_INFO_ITEM_WEAPON_UNAVAILABLE"); - me.gotoRC(me, 9, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Announcers"))); + me.gotoRC(me, 9, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Announcers"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 0, "notification_ANNCE_NUM_RESPAWN_1", _("Respawn countdown sounds"), "-")); - makeMulti(e, "notification_ANNCE_NUM_RESPAWN_2 notification_ANNCE_NUM_RESPAWN_3 notification_ANNCE_NUM_RESPAWN_4 notification_ANNCE_NUM_RESPAWN_5 notification_ANNCE_NUM_RESPAWN_6 notification_ANNCE_NUM_RESPAWN_7 notification_ANNCE_NUM_RESPAWN_8 notification_ANNCE_NUM_RESPAWN_9 notification_ANNCE_NUM_RESPAWN_10"); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(2, 0, "notification_ANNCE_NUM_RESPAWN_1", _("Respawn countdown sounds"), "-")); + makeMulti(e, "notification_ANNCE_NUM_RESPAWN_2 notification_ANNCE_NUM_RESPAWN_3 notification_ANNCE_NUM_RESPAWN_4 notification_ANNCE_NUM_RESPAWN_5 notification_ANNCE_NUM_RESPAWN_6 notification_ANNCE_NUM_RESPAWN_7 notification_ANNCE_NUM_RESPAWN_8 notification_ANNCE_NUM_RESPAWN_9 notification_ANNCE_NUM_RESPAWN_10"); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(1, 0, "notification_ANNCE_KILLSTREAK_03", _("Killstreak sounds"), "-")); - makeMulti(e, "notification_ANNCE_KILLSTREAK_05 notification_ANNCE_KILLSTREAK_10 notification_ANNCE_KILLSTREAK_15 notification_ANNCE_KILLSTREAK_20 notification_ANNCE_KILLSTREAK_25 notification_ANNCE_KILLSTREAK_30"); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(1, 0, "notification_ANNCE_KILLSTREAK_03", _("Killstreak sounds"), "-")); + makeMulti(e, "notification_ANNCE_KILLSTREAK_05 notification_ANNCE_KILLSTREAK_10 notification_ANNCE_KILLSTREAK_15 notification_ANNCE_KILLSTREAK_20 notification_ANNCE_KILLSTREAK_25 notification_ANNCE_KILLSTREAK_30"); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(1, 0, "notification_ANNCE_ACHIEVEMENT_AIRSHOT", _("Achievement sounds"), "-")); - makeMulti(e, "notification_ANNCE_ACHIEVEMENT_AMAZING notification_ANNCE_ACHIEVEMENT_AWESOME notification_ANNCE_ACHIEVEMENT_BOTLIKE notification_ANNCE_ACHIEVEMENT_ELECTROBITCH notification_ANNCE_ACHIEVEMENT_IMPRESSIVE notification_ANNCE_ACHIEVEMENT_YODA"); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx_T(1, 0, "notification_ANNCE_ACHIEVEMENT_AIRSHOT", _("Achievement sounds"), "-")); + makeMulti(e, "notification_ANNCE_ACHIEVEMENT_AMAZING notification_ANNCE_ACHIEVEMENT_AWESOME notification_ANNCE_ACHIEVEMENT_BOTLIKE notification_ANNCE_ACHIEVEMENT_ELECTROBITCH notification_ANNCE_ACHIEVEMENT_IMPRESSIVE notification_ANNCE_ACHIEVEMENT_YODA"); } diff --git a/qcsrc/menu/xonotic/dialog_settings_game_view.qc b/qcsrc/menu/xonotic/dialog_settings_game_view.qc index 2f5d79586..266044fa2 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game_view.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game_view.qc @@ -23,99 +23,100 @@ void XonoticGameViewSettingsTab_fill(entity me) entity e; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticRadioButton(1, "chase_active", "0", _("1st person perspective"))); - makeMulti(e, "crosshair_hittest_showimpact"); + me.TD(me, 1, 3, e = makeXonoticRadioButton(1, "chase_active", "0", _("1st person perspective"))); + makeMulti(e, "crosshair_hittest_showimpact"); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox(0, "cl_eventchase_death", _("Slide to third person upon death"))); - setDependent(e, "chase_active", -1, 0); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox(0, "cl_eventchase_death", _("Slide to third person upon death"))); + setDependent(e, "chase_active", -1, 0); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(0.05, 0, "cl_bobfall", _("Smooth the view when landing from a jump"))); - setDependent(e, "chase_active", -1, 0); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(0.05, 0, "cl_bobfall", _("Smooth the view when landing from a jump"))); + setDependent(e, "chase_active", -1, 0); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(0.05, 0, "cl_smoothviewheight", _("Smooth the view while crouching"))); - setDependent(e, "chase_active", -1, 0); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(0.05, 0, "cl_smoothviewheight", _("Smooth the view while crouching"))); + setDependent(e, "chase_active", -1, 0); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(1, 0, "v_idlescale", _("View waving while idle"))); - setDependent(e, "chase_active", -1, 0); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx(1, 0, "v_idlescale", _("View waving while idle"))); + setDependent(e, "chase_active", -1, 0); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx_T(0.01, 0, "cl_bob", _("View bobbing while walking around"), "-")); - makeMulti(e, "cl_bob2"); - setDependent(e, "chase_active", -1, 0); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBoxEx_T(0.01, 0, "cl_bob", _("View bobbing while walking around"), "-")); + makeMulti(e, "cl_bob2"); + setDependent(e, "chase_active", -1, 0); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticRadioButton(1, "chase_active", "1", _("3rd person perspective"))); - makeMulti(e, "crosshair_hittest_showimpact"); + me.TD(me, 1, 3, e = makeXonoticRadioButton(1, "chase_active", "1", _("3rd person perspective"))); + makeMulti(e, "crosshair_hittest_showimpact"); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Back distance"))); - setDependent(e, "chase_active", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider(10, 100, 1, "chase_back")); - setDependent(e, "chase_active", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Back distance"))); + setDependent(e, "chase_active", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider(10, 100, 1, "chase_back")); + setDependent(e, "chase_active", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Up distance"))); - setDependent(e, "chase_active", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider(10, 50, 1, "chase_up")); - setDependent(e, "chase_active", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, _("Up distance"))); + setDependent(e, "chase_active", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider(10, 50, 1, "chase_up")); + setDependent(e, "chase_active", 1, 1); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(1, "cl_clippedspectating", _("Allow passing through walls while spectating"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(1, "cl_clippedspectating", _("Allow passing through walls while spectating"))); - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Field of view:"))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(60, 130, 5, "fov", + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Field of view:"))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(60, 130, 5, "fov", _("Field of vision in degrees (default: 100)"))); me.TR(me); me.TR(me); - //me.TDempty(me, 0.2); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("ZOOM^Zoom factor:")))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(2, 30, 0.5, "cl_zoomfactor", + // me.TDempty(me, 0.2); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("ZOOM^Zoom factor:")))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(2, 30, 0.5, "cl_zoomfactor", _("How big the zoom factor is when the zoom button is pressed"))); me.TR(me); - //me.TDempty(me, 0.2); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("ZOOM^Zoom speed:")))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("cl_zoomspeed", + // me.TDempty(me, 0.2); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("ZOOM^Zoom speed:")))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("cl_zoomspeed", _("How fast the view will be zoomed, disable to zoom instantly"))); - e.addValue(e, "1", "1"); // Samual: for() loop doesn't work here, even though it would make sense. - e.addValue(e, "2", "2"); - e.addValue(e, "3", "3"); - e.addValue(e, "4", "4"); - e.addValue(e, "5", "5"); - e.addValue(e, "6", "6"); - e.addValue(e, "7", "7"); - e.addValue(e, "8", "8"); - e.addValue(e, ZCTX(_("ZOOM^Instant")), "-1"); - e.configureXonoticTextSliderValues(e); - me.TR(me); - //me.TDempty(me, 0.2); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("ZOOM^Zoom sensitivity:")))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 1, 0.1, "cl_zoomsensitivity", + e.addValue(e, "1", "1"); // Samual: for() loop doesn't work here, even though it would make sense. + e.addValue(e, "2", "2"); + e.addValue(e, "3", "3"); + e.addValue(e, "4", "4"); + e.addValue(e, "5", "5"); + e.addValue(e, "6", "6"); + e.addValue(e, "7", "7"); + e.addValue(e, "8", "8"); + e.addValue(e, ZCTX(_("ZOOM^Instant")), "-1"); + e.configureXonoticTextSliderValues(e); + me.TR(me); + // me.TDempty(me, 0.2); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("ZOOM^Zoom sensitivity:")))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 1, 0.1, "cl_zoomsensitivity", _("How zoom changes sensitivity, from 0 (lower sensitivity) to 1 (no sensitivity change)"))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "cl_velocityzoom_enabled", _("Velocity zoom"))); - me.TD(me, 1, 2, e = makeXonoticCheckBoxEx(3, 1, "cl_velocityzoom_type", _("Forward movement only"))); - setDependent(e, "cl_velocityzoom_enabled", 1, 1); + me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "cl_velocityzoom_enabled", _("Velocity zoom"))); + me.TD(me, 1, 2, e = makeXonoticCheckBoxEx(3, 1, "cl_velocityzoom_type", _("Forward movement only"))); + setDependent(e, "cl_velocityzoom_enabled", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, ZCTX(_("VZOOM^Factor")))); - setDependentAND(e, "cl_velocityzoom_enabled", 1, 1, "cl_velocityzoom_type", 1, 3); - me.TD(me, 1, 2, e = makeXonoticSlider(-1, 1, 0.1, "cl_velocityzoom_factor")); - setDependentAND(e, "cl_velocityzoom_enabled", 1, 1, "cl_velocityzoom_type", 1, 3); + me.TDempty(me, 0.2); + me.TD(me, 1, 0.8, e = makeXonoticTextLabel(0, ZCTX(_("VZOOM^Factor")))); + setDependentAND(e, "cl_velocityzoom_enabled", 1, 1, "cl_velocityzoom_type", 1, 3); + me.TD(me, 1, 2, e = makeXonoticSlider(-1, 1, 0.1, "cl_velocityzoom_factor")); + setDependentAND(e, "cl_velocityzoom_enabled", 1, 1, "cl_velocityzoom_type", 1, 3); me.TR(me); me.TR(me); - //me.TDempty(me, 0.2); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_reticle", _("Display reticle 2D overlay while zooming"))); + // me.TDempty(me, 0.2); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_reticle", _("Display reticle 2D overlay while zooming"))); me.TR(me); - //me.TDempty(me, 0.2); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_unpress_zoom_on_death", _("Release zoom when you die or respawn"), "-")); - makeMulti(e, "cl_unpress_zoom_on_spawn"); + // me.TDempty(me, 0.2); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_unpress_zoom_on_death", _("Release zoom when you die or respawn"), "-")); + makeMulti(e, "cl_unpress_zoom_on_spawn"); me.TR(me); - //me.TDempty(me, 0.2); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_unpress_zoom_on_weapon_switch", _("Release zoom when you switch weapons"))); + // me.TDempty(me, 0.2); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_unpress_zoom_on_weapon_switch", _("Release zoom when you switch weapons"))); } diff --git a/qcsrc/menu/xonotic/dialog_settings_game_weapons.qc b/qcsrc/menu/xonotic/dialog_settings_game_weapons.qc index 1d75ecb49..8276a6f25 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game_weapons.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game_weapons.qc @@ -25,65 +25,67 @@ void XonoticGameWeaponsSettingsTab_fill(entity me) entity weaponsApplyButton = makeXonoticCommandButton(_("Apply immediately"), '0 0 0', "sendcvar cl_autoswitch;" "sendcvar cl_weaponpriority;" - "sendcvar cl_weaponimpulsemode;" - , COMMANDBUTTON_APPLY); + "sendcvar cl_weaponimpulsemode;", + COMMANDBUTTON_APPLY); weaponsApplyButton.disableOnClick = true; me.TR(me); - me.TDempty(me, 0.25); - me.TD(me, 1, 2.5, e = makeXonoticHeaderLabel(_("Weapon Priority List (* = mutator weapon)"))); + me.TDempty(me, 0.25); + me.TD(me, 1, 2.5, e = makeXonoticHeaderLabel(_("Weapon Priority List (* = mutator weapon)"))); me.TR(me); - me.TDempty(me, 0.25); - me.TD(me, 9, 2.5, e = me.weaponsList = makeXonoticWeaponsList()); - e.applyButton = weaponsApplyButton; + me.TDempty(me, 0.25); + me.TD(me, 9, 2.5, e = me.weaponsList = makeXonoticWeaponsList()); + e.applyButton = weaponsApplyButton; me.gotoRC(me, 10, 0.25); - me.TD(me, 1, 1.25, e = makeXonoticButton(_("Up"), '0 0 0')); - e.onClick = WeaponsList_MoveUp_Click; - e.onClickEntity = me.weaponsList; - e.applyButton = weaponsApplyButton; - me.TD(me, 1, 1.25, e = makeXonoticButton(_("Down"), '0 0 0')); - e.onClick = WeaponsList_MoveDown_Click; - e.onClickEntity = me.weaponsList; - e.applyButton = weaponsApplyButton; + me.TD(me, 1, 1.25, e = makeXonoticButton(_("Up"), '0 0 0')); + e.onClick = WeaponsList_MoveUp_Click; + e.onClickEntity = me.weaponsList; + e.applyButton = weaponsApplyButton; + me.TD(me, 1, 1.25, e = makeXonoticButton(_("Down"), '0 0 0')); + e.onClick = WeaponsList_MoveDown_Click; + e.onClickEntity = me.weaponsList; + e.applyButton = weaponsApplyButton; - me.gotoRC(me, 0, 3); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_weaponpriority_useforcycling", _("Use priority list for weapon cycling"), + me.gotoRC(me, 0, 3); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_weaponpriority_useforcycling", _("Use priority list for weapon cycling"), _("Make use of the list above when cycling through weapons with the mouse wheel"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(1, "cl_weaponimpulsemode", _("Cycle through only usable weapon selections"))); - e.applyButton = weaponsApplyButton; + me.TD(me, 1, 3, e = makeXonoticCheckBox(1, "cl_weaponimpulsemode", _("Cycle through only usable weapon selections"))); + e.applyButton = weaponsApplyButton; me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_autoswitch", _("Auto switch weapons on pickup"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "cl_autoswitch", _("Auto switch weapons on pickup"), _("Automatically switch to newly picked up weapons if they are better than what you are carrying"))); - e.applyButton = weaponsApplyButton; + e.applyButton = weaponsApplyButton; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_unpress_attack_on_weapon_switch", _("Release attack buttons when you switch weapons"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_unpress_attack_on_weapon_switch", _("Release attack buttons when you switch weapons"))); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "r_drawviewmodel", _("Draw 1st person weapon model"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "r_drawviewmodel", _("Draw 1st person weapon model"), _("Draw the weapon model"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.9, e = makeXonoticRadioButton_T(1, "cl_gunalign", "4", _("Left align"), + me.TDempty(me, 0.2); + me.TD(me, 1, 0.9, e = makeXonoticRadioButton_T(1, "cl_gunalign", "4", _("Left align"), _("Position of the weapon model; requires reconnect"))); - setDependent(e, "r_drawviewmodel", 1, 1); - me.TD(me, 1, 0.9, e = makeXonoticRadioButton_T(1, "cl_gunalign", "1", _("Center"), + setDependent(e, "r_drawviewmodel", 1, 1); + me.TD(me, 1, 0.9, e = makeXonoticRadioButton_T(1, "cl_gunalign", "1", _("Center"), _("Position of the weapon model; requires reconnect"))); - setDependent(e, "r_drawviewmodel", 1, 1); - me.TD(me, 1, 1.0, e = makeXonoticRadioButton_T(1, "cl_gunalign", "3", _("Right align"), + setDependent(e, "r_drawviewmodel", 1, 1); + me.TD(me, 1, 1.0, e = makeXonoticRadioButton_T(1, "cl_gunalign", "3", _("Right align"), _("Position of the weapon model; requires reconnect"))); - setDependent(e, "r_drawviewmodel", 1, 1); + setDependent(e, "r_drawviewmodel", 1, 1); me.TR(me); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "cl_followmodel", _("Gun model swaying"), "-")); - makeMulti(e, "cl_leanmodel"); - setDependent(e, "r_drawviewmodel", 1, 1); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "cl_followmodel", _("Gun model swaying"), "-")); + makeMulti(e, "cl_leanmodel"); + setDependent(e, "r_drawviewmodel", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox(0, "cl_bobmodel", _("Gun model bobbing"))); - setDependent(e, "r_drawviewmodel", 1, 1); - me.gotoRC(me, me.rows - 1, 0); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, me.columns, weaponsApplyButton); + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox(0, "cl_bobmodel", _("Gun model bobbing"))); + setDependent(e, "r_drawviewmodel", 1, 1); + me.gotoRC(me, me.rows - 1, 0); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, me.columns, weaponsApplyButton); } diff --git a/qcsrc/menu/xonotic/dialog_settings_input.qc b/qcsrc/menu/xonotic/dialog_settings_input.qc index 7f3af39f8..ed0eaa5f1 100644 --- a/qcsrc/menu/xonotic/dialog_settings_input.qc +++ b/qcsrc/menu/xonotic/dialog_settings_input.qc @@ -22,7 +22,7 @@ void CheckBox_Click_Redisplay(entity me, entity checkbox) { CheckBox_Click(me, checkbox); cmd("\ndefer 0.2 \"togglemenu 1\"\n"); - //m_display(); + // m_display(); } void XonoticInputSettingsTab_fill(entity me) { @@ -30,93 +30,86 @@ void XonoticInputSettingsTab_fill(entity me) entity kb = makeXonoticKeyBinder(); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Key Bindings"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Key Bindings"))); me.TR(me); - me.TD(me, me.rows - 3, 3, kb); + me.TD(me, me.rows - 3, 3, kb); me.gotoRC(me, me.rows - 2, 0); - me.TD(me, 1, 1, e = makeXonoticButton(_("Change key..."), '0 0 0')); - e.onClick = KeyBinder_Bind_Change; - e.onClickEntity = kb; - kb.keyGrabButton = e; - me.TD(me, 1, 1, e = makeXonoticButton(_("Edit..."), '0 0 0')); - e.onClick = KeyBinder_Bind_Edit; - e.onClickEntity = kb; - kb.userbindEditButton = e; - kb.userbindEditDialog = main.userbindEditDialog; - main.userbindEditDialog.keybindBox = kb; - me.TD(me, 1, 1, e = makeXonoticButton(_("Clear"), '0 0 0')); - e.onClick = KeyBinder_Bind_Clear; - e.onClickEntity = kb; - kb.clearButton = e; + me.TD(me, 1, 1, e = makeXonoticButton(_("Change key..."), '0 0 0')); + e.onClick = KeyBinder_Bind_Change; + e.onClickEntity = kb; + kb.keyGrabButton = e; + me.TD(me, 1, 1, e = makeXonoticButton(_("Edit..."), '0 0 0')); + e.onClick = KeyBinder_Bind_Edit; + e.onClickEntity = kb; + kb.userbindEditButton = e; + kb.userbindEditDialog = main.userbindEditDialog; + main.userbindEditDialog.keybindBox = kb; + me.TD(me, 1, 1, e = makeXonoticButton(_("Clear"), '0 0 0')); + e.onClick = KeyBinder_Bind_Clear; + e.onClickEntity = kb; + kb.clearButton = e; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticButton(_("Reset all"), '0 0 0')); - e.onClick = KeyBinder_Bind_Reset_All; - e.onClickEntity = kb; + me.TD(me, 1, 3, e = makeXonoticButton(_("Reset all"), '0 0 0')); + e.onClick = KeyBinder_Bind_Reset_All; + e.onClickEntity = kb; - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Mouse"))); + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Mouse"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Sensitivity:"))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 32, 0.2, "sensitivity", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Sensitivity:"))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 32, 0.2, "sensitivity", _("Mouse speed multiplier"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "m_filter", _("Smooth aiming"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "m_filter", _("Smooth aiming"), _("Smoothes the mouse movement, but makes aiming slightly less responsive"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(1.022, "m_pitch", _("Invert aiming"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(1.022, "m_pitch", _("Invert aiming"), _("Invert mouse movement on the Y-axis"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "menu_mouse_absolute", _("Use system mouse positioning"), "-")); - makeMulti(e, "hud_cursormode"); - e.onClick = CheckBox_Click_Redisplay; - e.onClickEntity = e; + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "menu_mouse_absolute", _("Use system mouse positioning"), "-")); + makeMulti(e, "hud_cursormode"); + e.onClick = CheckBox_Click_Redisplay; + e.onClickEntity = e; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "m_accelerate", _("Enable built in mouse acceleration"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "m_accelerate", _("Enable built in mouse acceleration"))); me.TR(me); - if(cvar_type("vid_dgamouse") & CVAR_TYPEFLAG_ENGINE) - { - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "vid_dgamouse", _("Disable system mouse acceleration"), + if (cvar_type("vid_dgamouse") & CVAR_TYPEFLAG_ENGINE) { + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "vid_dgamouse", _("Disable system mouse acceleration"), _("Make use of DGA mouse input"))); - } - else if(cvar_type("apple_mouse_noaccel") & CVAR_TYPEFLAG_ENGINE) - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "apple_mouse_noaccel", _("Disable system mouse acceleration"))); - else - { - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, string_null, _("Disable system mouse acceleration"))); - e.disabled = 1; // the option is never available in this case, just there for show - } + } else if (cvar_type("apple_mouse_noaccel") & CVAR_TYPEFLAG_ENGINE) { + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "apple_mouse_noaccel", _("Disable system mouse acceleration"))); + } else { + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, string_null, _("Disable system mouse acceleration"))); + e.disabled = 1; // the option is never available in this case, just there for show + } me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Other"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Other"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "con_closeontoggleconsole", _("Pressing \"enter console\" key also closes it"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "con_closeontoggleconsole", _("Pressing \"enter console\" key also closes it"), _("Allow the console toggling bind to also close the console"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(1, "cl_movement_track_canjump", _("Automatically repeat jumping if holding jump"))); - e.sendCvars = true; + me.TD(me, 1, 3, e = makeXonoticCheckBox(1, "cl_movement_track_canjump", _("Automatically repeat jumping if holding jump"))); + e.sendCvars = true; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Jetpack on jump:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_jetpack_jump")); - e.addValue(e, ZCTX(_("JPJUMP^Disabled")), "0"); - e.addValue(e, _("Air only"), "1"); - e.addValue(e, ZCTX(_("JPJUMP^All")), "2"); - e.configureXonoticTextSliderValues(e); - e.sendCvars = true; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Jetpack on jump:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_jetpack_jump")); + e.addValue(e, ZCTX(_("JPJUMP^Disabled")), "0"); + e.addValue(e, _("Air only"), "1"); + e.addValue(e, ZCTX(_("JPJUMP^All")), "2"); + e.configureXonoticTextSliderValues(e); + e.sendCvars = true; me.TR(me); - if(cvar_type("joy_enable") & CVAR_TYPEFLAG_ENGINE) - { - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "joy_enable", _("Use joystick input"))); - setDependent(e, "joy_detected", 1, 10000000); - } - else if(cvar_type("joystick") & CVAR_TYPEFLAG_ENGINE) - { - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "joystick", _("Use joystick input"))); - setDependent(e, "joy_detected", 1, 10000000); - } - else - { - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, string_null, _("Use joystick input"))); - e.disabled = 1; // the option is never available in this case, just there for show - } + if (cvar_type("joy_enable") & CVAR_TYPEFLAG_ENGINE) { + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "joy_enable", _("Use joystick input"))); + setDependent(e, "joy_detected", 1, 10000000); + } else if (cvar_type("joystick") & CVAR_TYPEFLAG_ENGINE) { + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "joystick", _("Use joystick input"))); + setDependent(e, "joy_detected", 1, 10000000); + } else { + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, string_null, _("Use joystick input"))); + e.disabled = 1; // the option is never available in this case, just there for show + } } diff --git a/qcsrc/menu/xonotic/dialog_settings_input.qh b/qcsrc/menu/xonotic/dialog_settings_input.qh index 040908298..c4cd60379 100644 --- a/qcsrc/menu/xonotic/dialog_settings_input.qh +++ b/qcsrc/menu/xonotic/dialog_settings_input.qh @@ -5,6 +5,6 @@ CLASS(XonoticInputSettingsTab, XonoticTab) METHOD(XonoticInputSettingsTab, fill, void(entity)); ATTRIB(XonoticInputSettingsTab, intendedWidth, float, 0.9); ATTRIB(XonoticInputSettingsTab, rows, float, 15.5); - ATTRIB(XonoticInputSettingsTab, columns, float, 6.2); // added extra .2 for center space + ATTRIB(XonoticInputSettingsTab, columns, float, 6.2); // added extra .2 for center space ENDCLASS(XonoticInputSettingsTab) entity makeXonoticInputSettingsTab(); diff --git a/qcsrc/menu/xonotic/dialog_settings_input_userbind.qc b/qcsrc/menu/xonotic/dialog_settings_input_userbind.qc index d8d5e7e18..83d3db04d 100644 --- a/qcsrc/menu/xonotic/dialog_settings_input_userbind.qc +++ b/qcsrc/menu/xonotic/dialog_settings_input_userbind.qc @@ -14,30 +14,30 @@ void XonoticUserbindEditDialog_Save(entity btn, entity me) void XonoticUserbindEditDialog_loadUserBind(entity me, string theName, string theCommandPress, string theCommandRelease) { me.nameBox.setText(me.nameBox, theName); - me.nameBox.keyDown(me.nameBox, K_END, 0, 0); + me.nameBox.keyDown(me.nameBox, K_END, 0, 0); me.commandPressBox.setText(me.commandPressBox, theCommandPress); - me.nameBox.keyDown(me.commandPressBox, K_END, 0, 0); + me.nameBox.keyDown(me.commandPressBox, K_END, 0, 0); me.commandReleaseBox.setText(me.commandReleaseBox, theCommandRelease); - me.nameBox.keyDown(me.commandReleaseBox, K_END, 0, 0); + me.nameBox.keyDown(me.commandReleaseBox, K_END, 0, 0); } void XonoticUserbindEditDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Name:"))); - me.TD(me, 1, me.columns - 1, me.nameBox = makeXonoticInputBox(0, string_null)); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Name:"))); + me.TD(me, 1, me.columns - 1, me.nameBox = makeXonoticInputBox(0, string_null)); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Command when pressed:"))); - me.TD(me, 1, me.columns - 1, me.commandPressBox = makeXonoticInputBox(0, string_null)); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Command when pressed:"))); + me.TD(me, 1, me.columns - 1, me.commandPressBox = makeXonoticInputBox(0, string_null)); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Command when released:"))); - me.TD(me, 1, me.columns - 1, me.commandReleaseBox = makeXonoticInputBox(0, string_null)); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Command when released:"))); + me.TD(me, 1, me.columns - 1, me.commandReleaseBox = makeXonoticInputBox(0, string_null)); me.TR(me); - me.TD(me, 1, me.columns / 2, e = makeXonoticButton(_("Save"), '0 0 0')); - e.onClick = XonoticUserbindEditDialog_Save; - e.onClickEntity = me; - me.TD(me, 1, me.columns / 2, e = makeXonoticButton(_("Cancel"), '0 0 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, me.columns / 2, e = makeXonoticButton(_("Save"), '0 0 0')); + e.onClick = XonoticUserbindEditDialog_Save; + e.onClickEntity = me; + me.TD(me, 1, me.columns / 2, e = makeXonoticButton(_("Cancel"), '0 0 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_settings_misc.qc b/qcsrc/menu/xonotic/dialog_settings_misc.qc index 594b581fe..8fea82e7c 100644 --- a/qcsrc/menu/xonotic/dialog_settings_misc.qc +++ b/qcsrc/menu/xonotic/dialog_settings_misc.qc @@ -21,141 +21,141 @@ entity makeXonoticMiscSettingsTab() void XonoticMiscSettingsTab_fill(entity me) { entity e; - //entity sk; + // entity sk; me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Network"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Network"))); me.TR(me); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Client UDP port:"))); - me.TD(me, 1, 1.5, e = makeXonoticInputBox_T(0, "cl_port", + me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Client UDP port:"))); + me.TD(me, 1, 1.5, e = makeXonoticInputBox_T(0, "cl_port", _("Force client to use chosen port unless it is set to 0"))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Bandwidth:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("_cl_rate", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Bandwidth:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("_cl_rate", _("Specify your network speed"))); - e.addValue(e, _("56k"), "4000"); - e.addValue(e, _("ISDN"), "7000"); - e.addValue(e, _("Slow ADSL"), "15000"); - e.addValue(e, _("Fast ADSL"), "20000"); - e.addValue(e, _("Broadband"), "66666"); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Input packets/s:"))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(20, 100, 5, "cl_netfps", + e.addValue(e, _("56k"), "4000"); + e.addValue(e, _("ISDN"), "7000"); + e.addValue(e, _("Slow ADSL"), "15000"); + e.addValue(e, _("Fast ADSL"), "20000"); + e.addValue(e, _("Broadband"), "66666"); + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Input packets/s:"))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(20, 100, 5, "cl_netfps", _("How many input packets to send to the server each second"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Server queries/s:"))); - me.TD(me, 1, 2, e = makeXonoticSlider(20, 100, 10, "net_slist_queriespersecond")); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Server queries/s:"))); + me.TD(me, 1, 2, e = makeXonoticSlider(20, 100, 10, "net_slist_queriespersecond")); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Downloads:"))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 5, 1, "cl_curl_maxdownloads", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Downloads:"))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(1, 5, 1, "cl_curl_maxdownloads", _("Maximum number of concurrent HTTP/FTP downloads"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Download speed:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_curl_maxspeed")); - ADDVALUE_SPEED_KB(50); - ADDVALUE_SPEED_KB(100); - ADDVALUE_SPEED_KB(300); - ADDVALUE_SPEED_KB(500); - ADDVALUE_SPEED_MB(1, 1000); - ADDVALUE_SPEED_MB(2, 2000); - e.addValue(e, strzone(_("Unlimited")), "0"); - e.configureXonoticTextSliderValues(e); - me.TR(me); - if(cvar("developer")) - { - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Local latency:"))); - me.TD(me, 1, 2, e = makeXonoticSlider(0, 1000, 25, "cl_netlocalping")); - } - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "shownetgraph", _("Show netgraph"), + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Download speed:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_curl_maxspeed")); + ADDVALUE_SPEED_KB(50); + ADDVALUE_SPEED_KB(100); + ADDVALUE_SPEED_KB(300); + ADDVALUE_SPEED_KB(500); + ADDVALUE_SPEED_MB(1, 1000); + ADDVALUE_SPEED_MB(2, 2000); + e.addValue(e, strzone(_("Unlimited")), "0"); + e.configureXonoticTextSliderValues(e); + me.TR(me); + if (cvar("developer")) { + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Local latency:"))); + me.TD(me, 1, 2, e = makeXonoticSlider(0, 1000, 25, "cl_netlocalping")); + } + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "shownetgraph", _("Show netgraph"), _("Show a graph of packet sizes and other information"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_movement", _("Client-side movement prediction"))); - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_movement_errorcompensation", _("Movement error compensation"))); - setDependent(e, "cl_movement", 1, 1); - me.TR(me); - if(cvar_type("crypto_aeslevel") & CVAR_TYPEFLAG_ENGINE) - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(2, 1, "crypto_aeslevel", _("Use encryption (AES) when available"))); // TODO: move up - - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Framerate"))); - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Maximum:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_maxfps")); - ADDVALUE_FPS(30); - ADDVALUE_FPS(40); - ADDVALUE_FPS(50); - ADDVALUE_FPS(60); - ADDVALUE_FPS(70); - ADDVALUE_FPS(80); - ADDVALUE_FPS(100); - ADDVALUE_FPS(125); - ADDVALUE_FPS(150); - ADDVALUE_FPS(200); - e.addValue(e, ZCTX(_("MAXFPS^Unlimited")), "0"); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Target:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_minfps")); - e.addValue(e, ZCTX(_("TRGT^Disabled")), "0"); - ADDVALUE_FPS(30); - ADDVALUE_FPS(40); - ADDVALUE_FPS(50); - ADDVALUE_FPS(60); - ADDVALUE_FPS(80); - ADDVALUE_FPS(100); - ADDVALUE_FPS(125); - ADDVALUE_FPS(150); - ADDVALUE_FPS(200); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Idle limit:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_maxidlefps")); - ADDVALUE_FPS(10); - ADDVALUE_FPS(20); - ADDVALUE_FPS(30); - ADDVALUE_FPS(60); - e.addValue(e, ZCTX(_("IDLFPS^Unlimited")), "0"); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_maxfps_alwayssleep", _("Save processing time for other apps"))); - setDependent(e, "cl_maxfps", 1, 1000); - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "showfps", _("Show frames per second"), + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_movement", _("Client-side movement prediction"))); + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_movement_errorcompensation", _("Movement error compensation"))); + setDependent(e, "cl_movement", 1, 1); + me.TR(me); + if (cvar_type("crypto_aeslevel") & CVAR_TYPEFLAG_ENGINE) { + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(2, 1, "crypto_aeslevel", _("Use encryption (AES) when available"))); // TODO: move up + } + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Framerate"))); + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Maximum:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_maxfps")); + ADDVALUE_FPS(30); + ADDVALUE_FPS(40); + ADDVALUE_FPS(50); + ADDVALUE_FPS(60); + ADDVALUE_FPS(70); + ADDVALUE_FPS(80); + ADDVALUE_FPS(100); + ADDVALUE_FPS(125); + ADDVALUE_FPS(150); + ADDVALUE_FPS(200); + e.addValue(e, ZCTX(_("MAXFPS^Unlimited")), "0"); + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Target:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_minfps")); + e.addValue(e, ZCTX(_("TRGT^Disabled")), "0"); + ADDVALUE_FPS(30); + ADDVALUE_FPS(40); + ADDVALUE_FPS(50); + ADDVALUE_FPS(60); + ADDVALUE_FPS(80); + ADDVALUE_FPS(100); + ADDVALUE_FPS(125); + ADDVALUE_FPS(150); + ADDVALUE_FPS(200); + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Idle limit:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("cl_maxidlefps")); + ADDVALUE_FPS(10); + ADDVALUE_FPS(20); + ADDVALUE_FPS(30); + ADDVALUE_FPS(60); + e.addValue(e, ZCTX(_("IDLFPS^Unlimited")), "0"); + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "cl_maxfps_alwayssleep", _("Save processing time for other apps"))); + setDependent(e, "cl_maxfps", 1, 1000); + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "showfps", _("Show frames per second"), _("Show your rendered frames per second"))); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Other"))); + me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Other"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Menu tooltips:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("menu_tooltips", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Menu tooltips:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("menu_tooltips", _("Menu tooltips: disabled, standard or advanced (also shows cvar or console command bound to the menu item)"))); - e.addValue(e, ZCTX(_("TLTIP^Disabled")), "0"); - e.addValue(e, ZCTX(_("TLTIP^Standard")), "1"); - e.addValue(e, ZCTX(_("TLTIP^Advanced")), "2"); - e.configureXonoticTextSliderValues(e); + e.addValue(e, ZCTX(_("TLTIP^Disabled")), "0"); + e.addValue(e, ZCTX(_("TLTIP^Standard")), "1"); + e.addValue(e, ZCTX(_("TLTIP^Advanced")), "2"); + e.configureXonoticTextSliderValues(e); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "showtime", _("Show current date and time"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "showtime", _("Show current date and time"), _("Show current date and time of day, useful on screenshots"))); - makeMulti(e, "showdate"); + makeMulti(e, "showdate"); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "developer", _("Enable developer mode"))); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "developer", _("Enable developer mode"))); me.TR(me); - me.TDempty(me, 0.5); - me.TD(me, 1, 2, e = makeXonoticButton_T(_("Advanced settings..."), '0 0 0', + me.TDempty(me, 0.5); + me.TD(me, 1, 2, e = makeXonoticButton_T(_("Advanced settings..."), '0 0 0', _("Advanced settings where you can tweak every single variable of the game"))); - e.onClick = DialogOpenButton_Click; - e.onClickEntity = main.cvarsDialog; + e.onClick = DialogOpenButton_Click; + e.onClickEntity = main.cvarsDialog; me.TR(me); - me.TDempty(me, 0.5); - me.TD(me, 1, 2, e = makeXonoticButton(_("Factory reset"), '0 0 0')); - e.onClick = DialogOpenButton_Click; - e.onClickEntity = main.resetDialog; + me.TDempty(me, 0.5); + me.TD(me, 1, 2, e = makeXonoticButton(_("Factory reset"), '0 0 0')); + e.onClick = DialogOpenButton_Click; + e.onClickEntity = main.resetDialog; } #undef ADDVALUE_FPS diff --git a/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc b/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc index f35e0d22d..904c93f2a 100644 --- a/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc +++ b/qcsrc/menu/xonotic/dialog_settings_misc_cvars.qc @@ -13,66 +13,65 @@ void XonoticCvarsDialog_showNotify(entity me) } void XonoticCvarsDialog_fill(entity me) // in this dialog, use SKINCOLOR_CVARLIST_CONTROLS to color ALL controls { - entity e, cvarlist; cvarlist = makeXonoticCvarList(); cvarlist.color = cvarlist.colorF = - cvarlist.color2 = - cvarlist.colorC = - SKINCOLOR_CVARLIST_CONTROLS; + cvarlist.color2 = + cvarlist.colorC = + SKINCOLOR_CVARLIST_CONTROLS; // todo: // add button which does cvar_resettodefaults_saveonly me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Cvar filter:"))); - me.TD(me, 1, 3, e = makeXonoticInputBox(0, string_null)); - e.color = e.colorF = SKINCOLOR_CVARLIST_CONTROLS; - e.cb_color = e.cb_colorC = e.cb_colorF = SKINCOLOR_CVARLIST_CONTROLS; - e.onChange = CvarList_Filter_Change; - e.onChangeEntity = cvarlist; - cvarlist.controlledTextbox = e; // this COULD also be the Value box, but this leads to accidentally editing stuff - me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "menu_cvarlist_onlymodified", _("Modified cvars only"))); - e.color = e.colorC = e.colorF = e.colorD = SKINCOLOR_CVARLIST_CONTROLS; - e.onClickEntity = cvarlist; - e.onClick = CvarList_Filter_ModifiedCvars; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Cvar filter:"))); + me.TD(me, 1, 3, e = makeXonoticInputBox(0, string_null)); + e.color = e.colorF = SKINCOLOR_CVARLIST_CONTROLS; + e.cb_color = e.cb_colorC = e.cb_colorF = SKINCOLOR_CVARLIST_CONTROLS; + e.onChange = CvarList_Filter_Change; + e.onChangeEntity = cvarlist; + cvarlist.controlledTextbox = e; // this COULD also be the Value box, but this leads to accidentally editing stuff + me.TD(me, 1, 2, e = makeXonoticCheckBox(0, "menu_cvarlist_onlymodified", _("Modified cvars only"))); + e.color = e.colorC = e.colorF = e.colorD = SKINCOLOR_CVARLIST_CONTROLS; + e.onClickEntity = cvarlist; + e.onClick = CvarList_Filter_ModifiedCvars; me.TR(me); - me.TD(me, me.rows - me.currentRow - 9, me.columns, cvarlist); + me.TD(me, me.rows - me.currentRow - 9, me.columns, cvarlist); me.gotoRC(me, me.rows - 8, 0); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Setting:"))); - me.TD(me, 1, me.columns - 1, e = makeXonoticTextLabel(0, string_null)); - cvarlist.cvarNameBox = e; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Setting:"))); + me.TD(me, 1, me.columns - 1, e = makeXonoticTextLabel(0, string_null)); + cvarlist.cvarNameBox = e; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Type:"))); - me.TD(me, 1, me.columns - 1, e = makeXonoticTextLabel(0, string_null)); - cvarlist.cvarTypeBox = e; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Type:"))); + me.TD(me, 1, me.columns - 1, e = makeXonoticTextLabel(0, string_null)); + cvarlist.cvarTypeBox = e; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Value:"))); - me.TD(me, 1, me.columns - 2, e = makeXonoticInputBox(0, string_null)); - cvarlist.cvarValueBox = e; - e.color = e.colorF = SKINCOLOR_CVARLIST_CONTROLS; - e.cb_color = e.cb_colorC = e.cb_colorF = SKINCOLOR_CVARLIST_CONTROLS; - e.onChange = CvarList_Value_Change; - e.onChangeEntity = cvarlist; - e.onEnter = CvarList_End_Editing; - e.onEnterEntity = cvarlist; - me.TD(me, 1, 1, e = makeXonoticButton(string_null, SKINCOLOR_CVARLIST_CONTROLS)); - cvarlist.cvarDefaultBox = e; - e.onClick = CvarList_Revert_Click; - e.onClickEntity = cvarlist; - e.allowCut = 1; - e.marginLeft = e.marginRight = 0.5; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Value:"))); + me.TD(me, 1, me.columns - 2, e = makeXonoticInputBox(0, string_null)); + cvarlist.cvarValueBox = e; + e.color = e.colorF = SKINCOLOR_CVARLIST_CONTROLS; + e.cb_color = e.cb_colorC = e.cb_colorF = SKINCOLOR_CVARLIST_CONTROLS; + e.onChange = CvarList_Value_Change; + e.onChangeEntity = cvarlist; + e.onEnter = CvarList_End_Editing; + e.onEnterEntity = cvarlist; + me.TD(me, 1, 1, e = makeXonoticButton(string_null, SKINCOLOR_CVARLIST_CONTROLS)); + cvarlist.cvarDefaultBox = e; + e.onClick = CvarList_Revert_Click; + e.onClickEntity = cvarlist; + e.allowCut = 1; + e.marginLeft = e.marginRight = 0.5; me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Description:"))); - me.TD(me, 1, me.columns - 1, e = makeXonoticTextLabel(0, string_null)); - cvarlist.cvarDescriptionBox = e; - e.allowWrap = 1; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Description:"))); + me.TD(me, 1, me.columns - 1, e = makeXonoticTextLabel(0, string_null)); + cvarlist.cvarDescriptionBox = e; + e.allowWrap = 1; me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), SKINCOLOR_CVARLIST_CONTROLS)); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), SKINCOLOR_CVARLIST_CONTROLS)); + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_settings_misc_reset.qc b/qcsrc/menu/xonotic/dialog_settings_misc_reset.qc index d3ba0e420..b5d57f2db 100644 --- a/qcsrc/menu/xonotic/dialog_settings_misc_reset.qc +++ b/qcsrc/menu/xonotic/dialog_settings_misc_reset.qc @@ -8,13 +8,13 @@ void XonoticResetDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Are you sure you want to reset all settings?"))); + me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Are you sure you want to reset all settings?"))); me.TR(me); - me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("This will create a backup config in your data directory"))); + me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("This will create a backup config in your data directory"))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCommandButton(_("Yes"), '1 0 0', "saveconfig backup.cfg\n;\n exec defaultXonotic.cfg\n", 0)); - me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, 1, e = makeXonoticCommandButton(_("Yes"), '1 0 0', "saveconfig backup.cfg\n;\n exec defaultXonotic.cfg\n", 0)); + me.TD(me, 1, 1, e = makeXonoticButton(_("No"), '0 1 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } diff --git a/qcsrc/menu/xonotic/dialog_settings_user.qc b/qcsrc/menu/xonotic/dialog_settings_user.qc index fc6521c4d..fe619e225 100644 --- a/qcsrc/menu/xonotic/dialog_settings_user.qc +++ b/qcsrc/menu/xonotic/dialog_settings_user.qc @@ -21,61 +21,63 @@ void XonoticUserSettingsTab_fill(entity me) userApplyButton.disableOnClick = true; me.TR(me); - me.TDempty(me, 0.25); - me.TD(me, 1, 2.5, e = makeXonoticHeaderLabel(_("Menu Skins"))); + me.TDempty(me, 0.25); + me.TD(me, 1, 2.5, e = makeXonoticHeaderLabel(_("Menu Skins"))); me.TR(me); - me.TDempty(me, 0.25); - me.TD(me, me.rows - 3.5, 2.5, sk = makeXonoticSkinList()); + me.TDempty(me, 0.25); + me.TD(me, me.rows - 3.5, 2.5, sk = makeXonoticSkinList()); me.gotoRC(me, me.rows - 2.5, 0.25); - me.TD(me, 1, 2.5, e = makeXonoticButton(_("Set skin"), '0 0 0')); - e.onClick = SetSkin_Click; - e.onClickEntity = sk; + me.TD(me, 1, 2.5, e = makeXonoticButton(_("Set skin"), '0 0 0')); + e.onClick = SetSkin_Click; + e.onClickEntity = sk; /* AFTER 0.6 RELEASE TODO: Add a listbox which has fonts too, this way user can select the font they want. me.gotoRC(me, 0, 2.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Text language:"))); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Text language:"))); me.TR(me); - me.TD(me, 6, 1, sk = makeXonoticLanguageList()); + me.TD(me, 6, 1, sk = makeXonoticLanguageList()); me.TR(me); me.TR(me); me.TR(me); me.TR(me); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticButton(_("Set language"), '0 0 0')); - e.onClick = SetLanguage_Click; - e.onClickEntity = sk; + me.TD(me, 1, 1, e = makeXonoticButton(_("Set language"), '0 0 0')); + e.onClick = SetLanguage_Click; + e.onClickEntity = sk; me.gotoRC(me, 0, 3.3); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1.5, e = makeXonoticTextLabel(0, _("Font:"))); + me.TD(me, 1, 1.5, e = makeXonoticTextLabel(0, _("Font:"))); me.TR(me); - me.TD(me, 2, 1.5, sk = makeXonoticLanguageList()); + me.TD(me, 2, 1.5, sk = makeXonoticLanguageList()); me.TR(me); me.TR(me); me.TR(me); me.TR(me); me.TR(me); me.TR(me); - me.TD(me, 1, 1.5, e = makeXonoticButton(_("Set font"), '0 0 0')); - e.onClick = SetLanguage_Click; - e.onClickEntity = sk;*/ + me.TD(me, 1, 1.5, e = makeXonoticButton(_("Set font"), '0 0 0')); + e.onClick = SetLanguage_Click; + e.onClickEntity = sk;*/ - me.gotoRC(me, 0, 3.75); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1.5, e = makeXonoticHeaderLabel(_("Text Language"))); + me.gotoRC(me, 0, 3.75); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 1.5, e = makeXonoticHeaderLabel(_("Text Language"))); me.TR(me); - me.TD(me, 8, 1.5, sk = makeXonoticLanguageList()); + me.TD(me, 8, 1.5, sk = makeXonoticLanguageList()); - me.gotoRC(me, 9, 3.75); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1.5, e = makeXonoticButton(_("Set language"), '0 0 0')); - e.onClick = SetLanguage_Click; - e.onClickEntity = sk; + me.gotoRC(me, 9, 3.75); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 1.5, e = makeXonoticButton(_("Set language"), '0 0 0')); + e.onClick = SetLanguage_Click; + e.onClickEntity = sk; - me.gotoRC(me, 11.5, 3.25); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 2.5, e = makeXonoticCheckBox_T(0, "cl_gentle", _("Disable gore effects and harsh language"), + me.gotoRC(me, 11.5, 3.25); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 2.5, e = makeXonoticCheckBox_T(0, "cl_gentle", _("Disable gore effects and harsh language"), _("Replace blood and gibs with content that does not have any gore effects (default: disabled)"))); - e.applyButton = userApplyButton; + e.applyButton = userApplyButton; me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, 6, userApplyButton); - + me.TD(me, 1, 6, userApplyButton); } diff --git a/qcsrc/menu/xonotic/dialog_settings_user_languagewarning.qc b/qcsrc/menu/xonotic/dialog_settings_user_languagewarning.qc index 3cbd15bb4..1b8f33fbe 100644 --- a/qcsrc/menu/xonotic/dialog_settings_user_languagewarning.qc +++ b/qcsrc/menu/xonotic/dialog_settings_user_languagewarning.qc @@ -7,12 +7,12 @@ void XonoticLanguageWarningDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("While connected language changes will be applied only to the menu,"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("While connected language changes will be applied only to the menu,"))); me.TR(me); - me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("full language changes will take effect starting from the next game"))); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0, _("full language changes will take effect starting from the next game"))); me.TR(me); me.TR(me); - // reconnect command doesn't work properly, otherwise it would replace disconnect - me.TD(me, 1, 2, e = makeXonoticCommandButton(_("Disconnect now"), '0 0 0', "disconnect", 0)); - me.TD(me, 1, 2, e = makeXonoticCommandButton(_("Switch language"), '0 0 0', "prvm_language \"$_menu_prvm_language\"; menu_restart; menu_cmd languageselect", 0)); + // reconnect command doesn't work properly, otherwise it would replace disconnect + me.TD(me, 1, 2, e = makeXonoticCommandButton(_("Disconnect now"), '0 0 0', "disconnect", 0)); + me.TD(me, 1, 2, e = makeXonoticCommandButton(_("Switch language"), '0 0 0', "prvm_language \"$_menu_prvm_language\"; menu_restart; menu_cmd languageselect", 0)); } diff --git a/qcsrc/menu/xonotic/dialog_settings_video.qc b/qcsrc/menu/xonotic/dialog_settings_video.qc index 8ee51fde9..c298ea2e6 100644 --- a/qcsrc/menu/xonotic/dialog_settings_video.qc +++ b/qcsrc/menu/xonotic/dialog_settings_video.qc @@ -25,153 +25,152 @@ void XonoticVideoSettingsTab_fill(entity me) "vid_desktopfullscreen $_menu_vid_desktopfullscreen;" "menu_cmd update_conwidths_before_vid_restart;" "vid_restart;" - "menu_cmd sync;" - , COMMANDBUTTON_APPLY); + "menu_cmd sync;", + COMMANDBUTTON_APPLY); videoApplyButton.disableOnClick = true; me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Resolution:"))); - me.TD(me, 1, 2, e = makeXonoticResolutionSlider()); - e.applyButton = videoApplyButton; - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Font/UI size:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider("menu_vid_scale")); - e.addValue(e, ZCTX(_("SZ^Unreadable")), "-1"); - e.addValue(e, ZCTX(_("SZ^Tiny")), "-0.75"); - e.addValue(e, ZCTX(_("SZ^Little")), "-0.5"); - e.addValue(e, ZCTX(_("SZ^Small")), "-0.25"); - e.addValue(e, ZCTX(_("SZ^Medium")), "0"); - e.addValue(e, ZCTX(_("SZ^Large")), "0.25"); - e.addValue(e, ZCTX(_("SZ^Huge")), "0.5"); - e.addValue(e, ZCTX(_("SZ^Gigantic")), "0.75"); - e.addValue(e, ZCTX(_("SZ^Colossal")), "1"); - e.configureXonoticTextSliderValues(e); - e.applyButton = videoApplyButton; - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Color depth:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("vid_bitsperpixel", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Resolution:"))); + me.TD(me, 1, 2, e = makeXonoticResolutionSlider()); + e.applyButton = videoApplyButton; + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Font/UI size:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("menu_vid_scale")); + e.addValue(e, ZCTX(_("SZ^Unreadable")), "-1"); + e.addValue(e, ZCTX(_("SZ^Tiny")), "-0.75"); + e.addValue(e, ZCTX(_("SZ^Little")), "-0.5"); + e.addValue(e, ZCTX(_("SZ^Small")), "-0.25"); + e.addValue(e, ZCTX(_("SZ^Medium")), "0"); + e.addValue(e, ZCTX(_("SZ^Large")), "0.25"); + e.addValue(e, ZCTX(_("SZ^Huge")), "0.5"); + e.addValue(e, ZCTX(_("SZ^Gigantic")), "0.75"); + e.addValue(e, ZCTX(_("SZ^Colossal")), "1"); + e.configureXonoticTextSliderValues(e); + e.applyButton = videoApplyButton; + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Color depth:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("vid_bitsperpixel", _("How many bits per pixel (BPP) to render at, 32 is recommended"))); - e.addValue(e, _("16bit"), "16"); - e.addValue(e, _("32bit"), "32"); - e.configureXonoticTextSliderValues(e); - e.applyButton = videoApplyButton; - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "vid_fullscreen", _("Full screen"))); - e.applyButton = videoApplyButton; - me.TD(me, 1, 2, e = makeXonoticCheckBox_T(0, "vid_vsync", _("Vertical Synchronization"), + e.addValue(e, _("16bit"), "16"); + e.addValue(e, _("32bit"), "32"); + e.configureXonoticTextSliderValues(e); + e.applyButton = videoApplyButton; + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticCheckBox(0, "vid_fullscreen", _("Full screen"))); + e.applyButton = videoApplyButton; + me.TD(me, 1, 2, e = makeXonoticCheckBox_T(0, "vid_vsync", _("Vertical Synchronization"), _("Enable vertical synchronization to prevent tearing, will cap your fps to the screen refresh rate (default: disabled)"))); me.TR(me); - if(cvar("developer")) - { - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "v_flipped", _("Flip view horizontally"), + if (cvar("developer")) { + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "v_flipped", _("Flip view horizontally"), _("Poor man's left handed mode (default: off)"))); - } + } me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Anisotropy:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("gl_texture_anisotropy", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Anisotropy:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("gl_texture_anisotropy", _("Anisotropic filtering quality (default: 1x)"))); - e.addValue(e, ZCTX(_("ANISO^Disabled")), "1"); - e.addValue(e, _("2x"), "2"); - e.addValue(e, _("4x"), "4"); - e.addValue(e, _("8x"), "8"); - e.addValue(e, _("16x"), "16"); - e.configureXonoticTextSliderValues(e); - me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Antialiasing:"))); - setDependent(e, "r_viewfbo", 0, 0); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("vid_samples", + e.addValue(e, ZCTX(_("ANISO^Disabled")), "1"); + e.addValue(e, _("2x"), "2"); + e.addValue(e, _("4x"), "4"); + e.addValue(e, _("8x"), "8"); + e.addValue(e, _("16x"), "16"); + e.configureXonoticTextSliderValues(e); + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Antialiasing:"))); + setDependent(e, "r_viewfbo", 0, 0); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("vid_samples", _("Enable antialiasing, which smooths the edges of 3D geometry. Note that it might decrease performance by quite a lot (default: disabled)"))); - e.addValue(e, ZCTX(_("AA^Disabled")), "1"); - e.addValue(e, _("2x"), "2"); - e.addValue(e, _("4x"), "4"); - e.configureXonoticTextSliderValues(e); - setDependent(e, "r_viewfbo", 0, 0); - e.applyButton = videoApplyButton; - me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(2, 0, "r_viewfbo", _("High-quality frame buffer"))); - setDependent(e, "vid_samples", 1, 1); + e.addValue(e, ZCTX(_("AA^Disabled")), "1"); + e.addValue(e, _("2x"), "2"); + e.addValue(e, _("4x"), "4"); + e.configureXonoticTextSliderValues(e); + setDependent(e, "r_viewfbo", 0, 0); + e.applyButton = videoApplyButton; + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticCheckBoxEx(2, 0, "r_viewfbo", _("High-quality frame buffer"))); + setDependent(e, "vid_samples", 1, 1); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Depth first:"))); - me.TD(me, 1, 2, e = makeXonoticTextSlider_T("r_depthfirst", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Depth first:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider_T("r_depthfirst", _("Eliminate overdraw by rendering a depth-only version of the scene before the normal rendering starts (default: disabled)"))); - e.addValue(e, ZCTX(_("DF^Disabled")), "0"); - e.addValue(e, ZCTX(_("DF^World")), "1"); - e.addValue(e, ZCTX(_("DF^All")), "2"); - e.configureXonoticTextSliderValues(e); + e.addValue(e, ZCTX(_("DF^Disabled")), "0"); + e.addValue(e, ZCTX(_("DF^World")), "1"); + e.addValue(e, ZCTX(_("DF^All")), "2"); + e.configureXonoticTextSliderValues(e); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Vertex Buffer Objects (VBOs)"))); + me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Vertex Buffer Objects (VBOs)"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.9, e = makeXonoticRadioButton(1, "gl_vbo", "0", ZCTX(_("VBO^Off")))); - me.TD(me, 1, 1.9, e = makeXonoticRadioButton_T(1, "gl_vbo", "3", _("Vertices, some Tris (compatible)"), + me.TDempty(me, 0.2); + me.TD(me, 1, 0.9, e = makeXonoticRadioButton(1, "gl_vbo", "0", ZCTX(_("VBO^Off")))); + me.TD(me, 1, 1.9, e = makeXonoticRadioButton_T(1, "gl_vbo", "3", _("Vertices, some Tris (compatible)"), _("Make use of Vertex Buffer Objects to store static geometry in video memory for faster rendering (default: Vertex and Triangles)"))); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 0.9, e = makeXonoticRadioButton_T(1, "gl_vbo", "2", _("Vertices"), + me.TDempty(me, 0.2); + me.TD(me, 1, 0.9, e = makeXonoticRadioButton_T(1, "gl_vbo", "2", _("Vertices"), _("Make use of Vertex Buffer Objects to store static geometry in video memory for faster rendering (default: Vertex and Triangles)"))); - me.TD(me, 1, 1.9, e = makeXonoticRadioButton_T(1, "gl_vbo", "1", _("Vertices and Triangles"), + me.TD(me, 1, 1.9, e = makeXonoticRadioButton_T(1, "gl_vbo", "1", _("Vertices and Triangles"), _("Make use of Vertex Buffer Objects to store static geometry in video memory for faster rendering (default: Vertex and Triangles)"))); - me.gotoRC(me, 0, 3.2); me.setFirstColumn(me, me.currentColumn); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Brightness:"))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0.0, 0.5, 0.02, "v_brightness", + me.gotoRC(me, 0, 3.2); + me.setFirstColumn(me, me.currentColumn); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Brightness:"))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0.0, 0.5, 0.02, "v_brightness", _("Brightness of black (default: 0)"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Contrast:"))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(1.0, 3.0, 0.05, "v_contrast", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Contrast:"))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(1.0, 3.0, 0.05, "v_contrast", _("Brightness of white (default: 1)"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Gamma:"))); - setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0.5, 2.0, 0.05, "v_gamma", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Gamma:"))); + setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0.5, 2.0, 0.05, "v_gamma", _("Inverse gamma correction value, a brightness effect that does not affect white or black (default: 1.125)"))); - setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); + setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Contrast boost:"))); - setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider_T(1.0, 5.0, 0.1, "v_contrastboost", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Contrast boost:"))); + setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider_T(1.0, 5.0, 0.1, "v_contrastboost", _("By how much to multiply the contrast in dark areas (default: 1)"))); - setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); + setDependentAND(e, "vid_gl20", 1, 1, "v_glslgamma", 1, 1); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Saturation:"))); - setDependent(e, "vid_gl20", 1, 1); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0.5, 2.0, 0.05, "r_glsl_saturation", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Saturation:"))); + setDependent(e, "vid_gl20", 1, 1); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0.5, 2.0, 0.05, "r_glsl_saturation", _("Saturation adjustment (0 = grayscale, 1 = normal, 2 = oversaturated), requires GLSL color control (default: 1)"))); - setDependent(e, "vid_gl20", 1, 1); + setDependent(e, "vid_gl20", 1, 1); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("LIT^Ambient:")))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 20.0, 0.25, "r_ambient", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, ZCTX(_("LIT^Ambient:")))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0, 20.0, 0.25, "r_ambient", _("Ambient lighting, if set too high it tends to make light on maps look dull and flat (default: 4)"))); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Intensity:"))); - me.TD(me, 1, 2, e = makeXonoticSlider_T(0.5, 2.0, 0.05, "r_hdr_scenebrightness", + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Intensity:"))); + me.TD(me, 1, 2, e = makeXonoticSlider_T(0.5, 2.0, 0.05, "r_hdr_scenebrightness", _("Global rendering brightness (default: 1)"))); me.TR(me); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "gl_finish", _("Wait for GPU to finish each frame"), + me.TD(me, 1, 3, e = makeXonoticCheckBox_T(0, "gl_finish", _("Wait for GPU to finish each frame"), _("Make the CPU wait for the GPU to finish each frame, can help with some strange input or video lag on some machines (default: disabled)"))); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "vid_gl20", _("Use OpenGL 2.0 shaders (GLSL)"))); - e.applyButton = videoApplyButton; + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "vid_gl20", _("Use OpenGL 2.0 shaders (GLSL)"))); + e.applyButton = videoApplyButton; me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "v_glslgamma", _("Use GLSL to handle color control"), + me.TDempty(me, 0.2); + me.TD(me, 1, 2.8, e = makeXonoticCheckBox_T(0, "v_glslgamma", _("Use GLSL to handle color control"), _("Enable use of GLSL to apply gamma correction, note that it might decrease performance by a lot (default: disabled)"))); - setDependent(e, "vid_gl20", 1, 1); - if(cvar("developer")) - { + setDependent(e, "vid_gl20", 1, 1); + if (cvar("developer")) { me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "v_psycho", _("Psycho coloring (easter egg)"))); - setDependent(e, "vid_gl20", 1, 1); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "v_psycho", _("Psycho coloring (easter egg)"))); + setDependent(e, "vid_gl20", 1, 1); me.TR(me); - me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "r_trippy", _("Trippy vertices (easter egg)"))); - setDependent(e, "vid_gl20", 1, 1); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "r_trippy", _("Trippy vertices (easter egg)"))); + setDependent(e, "vid_gl20", 1, 1); } me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, videoApplyButton); + me.TD(me, 1, me.columns, videoApplyButton); } diff --git a/qcsrc/menu/xonotic/dialog_settings_video.qh b/qcsrc/menu/xonotic/dialog_settings_video.qh index 61d8a368e..90d54929c 100644 --- a/qcsrc/menu/xonotic/dialog_settings_video.qh +++ b/qcsrc/menu/xonotic/dialog_settings_video.qh @@ -5,7 +5,7 @@ CLASS(XonoticVideoSettingsTab, XonoticTab) METHOD(XonoticVideoSettingsTab, fill, void(entity)); ATTRIB(XonoticVideoSettingsTab, intendedWidth, float, 0.9); ATTRIB(XonoticVideoSettingsTab, rows, float, 15.5); - ATTRIB(XonoticVideoSettingsTab, columns, float, 6.2); // added extra .2 for center space + ATTRIB(XonoticVideoSettingsTab, columns, float, 6.2); // added extra .2 for center space ATTRIB(XonoticVideoSettingsTab, name, string, "videosettings"); ENDCLASS(XonoticVideoSettingsTab) entity makeXonoticVideoSettingsTab(); diff --git a/qcsrc/menu/xonotic/dialog_singleplayer.qc b/qcsrc/menu/xonotic/dialog_singleplayer.qc index 20984034d..c3e0cbcf2 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer.qc +++ b/qcsrc/menu/xonotic/dialog_singleplayer.qc @@ -13,41 +13,31 @@ void InstantAction_LoadMap(entity btn, entity dummy) cvar_set("timelimit_override", "10"); cvar_set("g_lms_lives_override", "9"); - if(random() < 0.4) // 40% are DM - { + if (random() < 0.4) { // 40% are DM MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH); pmin = 2; pmax = 8; pstep = 1; - } - else if(random() < 0.5) // half of the remaining 60%, i.e. 30%, are CTF - { + } else if (random() < 0.5) { // half of the remaining 60%, i.e. 30%, are CTF MapInfo_SwitchGameType(MAPINFO_TYPE_CTF); pmin = 4; pmax = 12; pstep = 2; - } - else if(random() < 0.5) // half of the remaining 30%, i.e. 15%, are TDM - { + } else if (random() < 0.5) { // half of the remaining 30%, i.e. 15%, are TDM MapInfo_SwitchGameType(MAPINFO_TYPE_TEAM_DEATHMATCH); pmin = 4; pmax = 8; pstep = 2; - } - else if(random() < 0.666) // 2/3 of the remaining 15%, i.e. 10%, are KH - { + } else if (random() < 0.666) { // 2/3 of the remaining 15%, i.e. 10%, are KH MapInfo_SwitchGameType(MAPINFO_TYPE_KEYHUNT); pmin = 6; pmax = 6; pstep = 6; // works both for 2 and 3 teams // TODO find team count of map, set pstep=2 or 3, and use 2v2(v2) games at least - } - else // somehow distribute the remaining 5% - { + } else { // somehow distribute the remaining 5% float r; r = floor(random() * 4); - switch(r) - { + switch (r) { default: case 0: MapInfo_SwitchGameType(MAPINFO_TYPE_LMS); @@ -74,20 +64,18 @@ void InstantAction_LoadMap(entity btn, entity dummy) pmax = 16; pstep = 2; break; - // CA, Freezetag: bot AI does not work, add them once it does + // CA, Freezetag: bot AI does not work, add them once it does } } // find random map MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); string s; - do - { + do { float m; m = floor(random() * MapInfo_count); s = MapInfo_BSPName_ByID(m); - } - while(!fexists(sprintf("maps/%s.waypoints", s))); + } while (!fexists(sprintf("maps/%s.waypoints", s))); MapInfo_LoadMap(s, 1); // configure bots @@ -106,33 +94,33 @@ void XonoticSingleplayerDialog_fill(entity me) entity e, btnPrev, btnNext, lblTitle; me.TR(me); - me.TDempty(me, (me.columns - 3) / 2); - me.TD(me, 2, 3, e = makeXonoticBigButton(_("Instant action! (random map with bots)"), '0 0 0')); - e.onClick = InstantAction_LoadMap; - e.onClickEntity = NULL; + me.TDempty(me, (me.columns - 3) / 2); + me.TD(me, 2, 3, e = makeXonoticBigButton(_("Instant action! (random map with bots)"), '0 0 0')); + e.onClick = InstantAction_LoadMap; + e.onClickEntity = NULL; me.TR(me); me.TR(me); me.TR(me); - me.TD(me, 1, 1, btnPrev = makeXonoticButton("<<", '0 0 0')); - me.TD(me, 1, me.columns - 2, lblTitle = makeXonoticTextLabel(0.5, _("???"))); - me.TD(me, 1, 1, btnNext = makeXonoticButton(">>", '0 0 0')); + me.TD(me, 1, 1, btnPrev = makeXonoticButton("<<", '0 0 0')); + me.TD(me, 1, me.columns - 2, lblTitle = makeXonoticTextLabel(0.5, _("???"))); + me.TD(me, 1, 1, btnNext = makeXonoticButton(">>", '0 0 0')); me.TR(me); - me.TD(me, me.rows - 6, me.columns, me.campaignBox = makeXonoticCampaignList()); - btnPrev.onClick = MultiCampaign_Prev; - btnPrev.onClickEntity = me.campaignBox; - btnNext.onClick = MultiCampaign_Next; - btnNext.onClickEntity = me.campaignBox; - me.campaignBox.buttonNext = btnNext; - me.campaignBox.buttonPrev = btnPrev; - me.campaignBox.labelTitle = lblTitle; + me.TD(me, me.rows - 6, me.columns, me.campaignBox = makeXonoticCampaignList()); + btnPrev.onClick = MultiCampaign_Prev; + btnPrev.onClickEntity = me.campaignBox; + btnNext.onClick = MultiCampaign_Next; + btnNext.onClickEntity = me.campaignBox; + me.campaignBox.buttonNext = btnNext; + me.campaignBox.buttonPrev = btnPrev; + me.campaignBox.labelTitle = lblTitle; me.gotoRC(me, me.rows - 2, 0); - me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Campaign Difficulty:"))); - me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-2", ZCTX(_("CSKL^Easy")))); - me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-1", ZCTX(_("CSKL^Medium")))); - me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "0", ZCTX(_("CSKL^Hard")))); - me.TR(me); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Singleplayer!"), '0 0 0')); - e.onClick = CampaignList_LoadMap; - e.onClickEntity = me.campaignBox; + me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Campaign Difficulty:"))); + me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-2", ZCTX(_("CSKL^Easy")))); + me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-1", ZCTX(_("CSKL^Medium")))); + me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "0", ZCTX(_("CSKL^Hard")))); + me.TR(me); + me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Singleplayer!"), '0 0 0')); + e.onClick = CampaignList_LoadMap; + e.onClickEntity = me.campaignBox; } diff --git a/qcsrc/menu/xonotic/dialog_singleplayer_winner.qc b/qcsrc/menu/xonotic/dialog_singleplayer_winner.qc index ff81d7d89..3d4e91c84 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer_winner.qc +++ b/qcsrc/menu/xonotic/dialog_singleplayer_winner.qc @@ -8,12 +8,12 @@ void XonoticWinnerDialog_fill(entity me) entity e; me.TR(me); - me.TD(me, me.rows - 2, me.columns, e = makeXonoticImage("/gfx/winner", -1)); + me.TD(me, me.rows - 2, me.columns, e = makeXonoticImage("/gfx/winner", -1)); me.gotoRC(me, me.rows - 1, 0); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); - e.onClick = Dialog_Close; - e.onClickEntity = me; + me.TD(me, 1, me.columns, e = makeXonoticButton(_("OK"), '0 0 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; } void XonoticWinnerDialog_focusEnter(entity me) { diff --git a/qcsrc/menu/xonotic/dialog_teamselect.qc b/qcsrc/menu/xonotic/dialog_teamselect.qc index b12de7c29..61c3e594a 100644 --- a/qcsrc/menu/xonotic/dialog_teamselect.qc +++ b/qcsrc/menu/xonotic/dialog_teamselect.qc @@ -19,26 +19,30 @@ void XonoticTeamSelectDialog_showNotify(entity me) float teams, nTeams; teams = cvar("_teams_available"); nTeams = 0; - me.team1.disabled = !(teams & 1); nTeams += boolean(teams & 1); - me.team2.disabled = !(teams & 2); nTeams += boolean(teams & 2); - me.team3.disabled = !(teams & 4); nTeams += boolean(teams & 4); - me.team4.disabled = !(teams & 8); nTeams += boolean(teams & 8); + me.team1.disabled = !(teams & 1); + nTeams += boolean(teams & 1); + me.team2.disabled = !(teams & 2); + nTeams += boolean(teams & 2); + me.team3.disabled = !(teams & 4); + nTeams += boolean(teams & 4); + me.team4.disabled = !(teams & 8); + nTeams += boolean(teams & 8); } void XonoticTeamSelectDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, 2, 4, e = makeTeamButton_T(_("join 'best' team (auto-select)"), '0 0 0', "cmd selectteam auto; cmd join", + me.TD(me, 2, 4, e = makeTeamButton_T(_("join 'best' team (auto-select)"), '0 0 0', "cmd selectteam auto; cmd join", _("Autoselect team (recommended)"))); - e.preferredFocusPriority = 1; + e.preferredFocusPriority = 1; me.TR(me); me.TR(me); - me.TD(me, 2, 1, e = me.team1 = makeTeamButton(_("red"), '1 0.5 0.5', "cmd selectteam red; cmd join")); - me.TD(me, 2, 1, e = me.team2 = makeTeamButton(_("blue"), '0.5 0.5 1', "cmd selectteam blue; cmd join")); - me.TD(me, 2, 1, e = me.team3 = makeTeamButton(_("yellow"), '1 1 0.5', "cmd selectteam yellow; cmd join")); - me.TD(me, 2, 1, e = me.team4 = makeTeamButton(_("pink"), '1 0.5 1', "cmd selectteam pink; cmd join")); + me.TD(me, 2, 1, e = me.team1 = makeTeamButton(_("red"), '1 0.5 0.5', "cmd selectteam red; cmd join")); + me.TD(me, 2, 1, e = me.team2 = makeTeamButton(_("blue"), '0.5 0.5 1', "cmd selectteam blue; cmd join")); + me.TD(me, 2, 1, e = me.team3 = makeTeamButton(_("yellow"), '1 1 0.5', "cmd selectteam yellow; cmd join")); + me.TD(me, 2, 1, e = me.team4 = makeTeamButton(_("pink"), '1 0.5 1', "cmd selectteam pink; cmd join")); me.TR(me); me.TR(me); - me.TD(me, 1, 4, makeXonoticCommandButton(_("spectate"), '0 0 0', "cmd spectate", 1)); + me.TD(me, 1, 4, makeXonoticCommandButton(_("spectate"), '0 0 0', "cmd spectate", 1)); } diff --git a/qcsrc/menu/xonotic/dialog_uid2name.qc b/qcsrc/menu/xonotic/dialog_uid2name.qc index 1cd77b0ca..eccd0b1ea 100644 --- a/qcsrc/menu/xonotic/dialog_uid2name.qc +++ b/qcsrc/menu/xonotic/dialog_uid2name.qc @@ -7,12 +7,12 @@ void XonoticUid2NameDialog_fill(entity me) { entity e; me.TR(me); - me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Allow player statistics to use your nickname?"))); + me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Allow player statistics to use your nickname?"))); me.TR(me); - me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Answering \"No\" you will appear as \"Anonymous player\""))); + me.TD(me, 1, 2, makeXonoticTextLabel(0.5, _("Answering \"No\" you will appear as \"Anonymous player\""))); me.TR(me); me.TR(me); - me.TD(me, 1, 1, e = makeXonoticCommandButton(_("Yes"), '0 0 0', "vyes; setreport cl_allow_uid2name 1", COMMANDBUTTON_CLOSE)); - e.preferredFocusPriority = 1; - me.TD(me, 1, 1, e = makeXonoticCommandButton(_("No"), '0 0 0', "vno; setreport cl_allow_uid2name 0", COMMANDBUTTON_CLOSE)); + me.TD(me, 1, 1, e = makeXonoticCommandButton(_("Yes"), '0 0 0', "vyes; setreport cl_allow_uid2name 1", COMMANDBUTTON_CLOSE)); + e.preferredFocusPriority = 1; + me.TD(me, 1, 1, e = makeXonoticCommandButton(_("No"), '0 0 0', "vno; setreport cl_allow_uid2name 0", COMMANDBUTTON_CLOSE)); } diff --git a/qcsrc/menu/xonotic/gametypelist.qc b/qcsrc/menu/xonotic/gametypelist.qc index a08e4dbbc..4bcea6a55 100644 --- a/qcsrc/menu/xonotic/gametypelist.qc +++ b/qcsrc/menu/xonotic/gametypelist.qc @@ -15,10 +15,10 @@ void XonoticGametypeList_configureXonoticGametypeList(entity me) me.configureXonoticListBox(me); me.nItems = GameType_GetCount(); - if(SKINBOOL_GAMETYPELIST_ICON_BLUR) - { - for(int i = 0; i < GameType_GetTotalCount(); ++i) + if (SKINBOOL_GAMETYPELIST_ICON_BLUR) { + for (int i = 0; i < GameType_GetTotalCount(); ++i) { draw_PreloadPictureWithFlags(GameType_GetIcon(i), PRECACHE_PIC_MIPMAP); + } } me.loadCvars(me); @@ -32,16 +32,20 @@ void XonoticGametypeList_loadCvars(entity me) { Gametype t = MapInfo_CurrentGametype(); float i; - for(i = 0; i < GameType_GetCount(); ++i) - if(t == GameType_GetID(i)) + for (i = 0; i < GameType_GetCount(); ++i) { + if (t == GameType_GetID(i)) { break; - if(i >= GameType_GetCount()) - { - for(i = 0; i < GameType_GetCount(); ++i) - if(t == MAPINFO_TYPE_DEATHMATCH) + } + } + if (i >= GameType_GetCount()) { + for (i = 0; i < GameType_GetCount(); ++i) { + if (t == MAPINFO_TYPE_DEATHMATCH) { break; - if(i >= GameType_GetCount()) + } + } + if (i >= GameType_GetCount()) { i = 0; + } } me.setSelected(me, i); // do we need this: me.parent.gameTypeChangeNotify(me.parent); // to make sure @@ -60,8 +64,7 @@ void XonoticGametypeList_saveCvars(entity me) } void XonoticGametypeList_draw(entity me) { - if(me.nItems != GameType_GetCount()) - { + if (me.nItems != GameType_GetCount()) { me.nItems = GameType_GetCount(); me.setSelected(me, 0); } @@ -71,10 +74,9 @@ void XonoticGametypeList_drawListBoxItem(entity me, int i, vector absSize, bool { string s1, s2; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } @@ -82,10 +84,11 @@ void XonoticGametypeList_drawListBoxItem(entity me, int i, vector absSize, bool draw_Picture(me.columnIconOrigin * eX, GameType_GetIcon(i), me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED); s1 = GameType_GetName(i); - if(_MapInfo_GetTeamPlayBool(GameType_GetID(i))) + if (_MapInfo_GetTeamPlayBool(GameType_GetID(i))) { s2 = _("teamplay"); - else + } else { s2 = _("free for all"); + } vector save_fontscale = draw_fontscale; float f = draw_CondensedFontFactor(strcat(s1, " ", s2), false, me.realFontSize, 1); @@ -111,8 +114,7 @@ void XonoticGametypeList_resizeNotify(entity me, vector relOrigin, vector relSiz } float XonoticGametypeList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER) - { + if (scan == K_ENTER || scan == K_KP_ENTER) { m_play_click_sound(MENU_SOUND_EXECUTE); me.parent.gameTypeSelectNotify(me.parent); return 1; @@ -126,8 +128,9 @@ void XonoticGametypeList_clickListBoxItem(entity me, float i, vector where) } void XonoticGametypeList_focusedItemChangeNotify(entity me) { - if(me.focusedItem >= 0) + if (me.focusedItem >= 0) { setZonedTooltip(me, MapInfo_Type_Description(GameType_GetID(me.focusedItem)), string_null); - else + } else { clearTooltip(me); + } } diff --git a/qcsrc/menu/xonotic/hudskinlist.qc b/qcsrc/menu/xonotic/hudskinlist.qc index 66c96046d..2cf647f21 100644 --- a/qcsrc/menu/xonotic/hudskinlist.qc +++ b/qcsrc/menu/xonotic/hudskinlist.qc @@ -42,34 +42,30 @@ string XonoticHUDSkinList_hudskinAuthor(entity me, float i) void getHUDSkinFiles(entity me, int sortbuf, string subdir) { string s; - if(me.filterString) + if (me.filterString) { s = me.filterString; - else + } else { s = "*"; + } s = strcat(subdir, "hud_", s, ".cfg"); int list = search_begin(s, false, true); - if(list >= 0) - { + if (list >= 0) { int n = search_getsize(list); - for(int i = 0; i < n; ++i) - { + for (int i = 0; i < n; ++i) { string s = search_getfilename(list, i); int subdir_ofs = strstrofs(s, "/", 0); - if(subdir_ofs >= 0) - { + if (subdir_ofs >= 0) { int ofs = subdir_ofs; - while(ofs != -1) - { + while (ofs != -1) { subdir_ofs = ofs; ofs = strstrofs(s, "/", subdir_ofs + 1); } } - if(subdir_ofs == -1) + if (subdir_ofs == -1) { bufstr_add(sortbuf, s, true); - else - { + } else { subdir = substring(s, 0, subdir_ofs); string filename = substring(s, subdir_ofs + 1, -1); // invert path and filename position so we can sort sortbuf by filename @@ -83,34 +79,33 @@ void getHUDSkinFiles(entity me, int sortbuf, string subdir) void getAllHUDSkins(entity me, int sortbuf) { int n = buf_getsize(sortbuf); - for(int i = 0; i < n; ++i) - { + for (int i = 0; i < n; ++i) { string entry = bufstr_get(sortbuf, i); int ofs = strstrofs(entry, "/", 0); string s = ""; string filename = entry; - if(ofs >= 0) - { + if (ofs >= 0) { s = substring(entry, ofs + 1, -1); // skip initial "/" s = strcat(s, "/"); bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_PATH, s); filename = strcat(s, substring(entry, 0, ofs)); - } - else + } else { ofs = strlen(entry); + } s = substring(entry, 4, ofs - 4 - 4); // remove "hud_" prefix and ".cfg" suffix bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_NAME, s); int fh = fopen(filename, FILE_READ); - if(fh < 0) + if (fh < 0) { continue; - while((s = fgets(fh)) && substring(s, 0, 2) == "//") - { + } + while ((s = fgets(fh)) && substring(s, 0, 2) == "//") { tokenize_console(substring(s, 2, -1)); - if(argv(0) == "title") + if (argv(0) == "title") { bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_TITLE, argv(1)); - else if(argv(0) == "author") + } else if (argv(0) == "author") { bufstr_set(me.listHUDSkin, i * HUDSKINPARM_COUNT + HUDSKINPARM_AUTHOR, argv(1)); + } } fclose(fh); } @@ -118,11 +113,11 @@ void getAllHUDSkins(entity me, int sortbuf) void XonoticHUDSkinList_getHUDSkins(entity me) { - if (me.listHUDSkin >= 0) + if (me.listHUDSkin >= 0) { buf_del(me.listHUDSkin); + } me.listHUDSkin = buf_create(); - if (me.listHUDSkin < 0) - { + if (me.listHUDSkin < 0) { me.nItems = 0; return; } @@ -137,8 +132,9 @@ void XonoticHUDSkinList_getHUDSkins(entity me) void XonoticHUDSkinList_destroy(entity me) { - if(me.nItems > 0) + if (me.nItems > 0) { buf_del(me.listHUDSkin); + } } void XonoticHUDSkinList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) @@ -157,20 +153,21 @@ void XonoticHUDSkinList_resizeNotify(entity me, vector relOrigin, vector relSize void XonoticHUDSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { string s, s2; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } s = me.hudskinTitle(me, i); - if(s == "") + if (s == "") { s = me.hudskinName(me, i); + } s2 = me.hudskinAuthor(me, i); - if(s2 != "") + if (s2 != "") { s = strcat(s, " (", s2, ")"); + } s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 1); } @@ -183,34 +180,37 @@ void XonoticHUDSkinList_showNotify(entity me) void HUDSkinList_Refresh_Click(entity btn, entity me) { me.getHUDSkins(me); - me.setSelected(me, 0); //always select the first element after a list update + me.setSelected(me, 0); // always select the first element after a list update } void HUDSkinList_SavedName_Change(entity box, entity me) { - if(me.savedName) + if (me.savedName) { strunzone(me.savedName); + } - if(box.text != "") + if (box.text != "") { me.savedName = strzone(box.text); - else + } else { me.savedName = string_null; + } } void HUDSkinList_Filter_Change(entity box, entity me) { - if(me.filterString) + if (me.filterString) { strunzone(me.filterString); + } - if(box.text != "") - { - if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0) + if (box.text != "") { + if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0) { me.filterString = strzone(box.text); - else + } else { me.filterString = strzone(strcat("*", box.text, "*")); - } - else + } + } else { me.filterString = string_null; + } me.getHUDSkins(me); } @@ -218,16 +218,16 @@ void HUDSkinList_Filter_Change(entity box, entity me) void SaveHUDSkin_Click(entity btn, entity me) { string s = me.savedName; - if(s == "") + if (s == "") { s = "myconfig"; + } localcmd(sprintf("hud save \"%s\"\n", s)); me.delayedRefreshTime = time + 1; } void XonoticHUDSkinList_draw(entity me) { - if(me.delayedRefreshTime > 0 && me.delayedRefreshTime < time) - { + if (me.delayedRefreshTime > 0 && me.delayedRefreshTime < time) { HUDSkinList_Refresh_Click(NULL, me); me.delayedRefreshTime = 0; } @@ -253,13 +253,10 @@ void XonoticHUDSkinList_doubleClickListBoxItem(entity me, float i, vector where) float XonoticHUDSkinList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER) - { + if (scan == K_ENTER || scan == K_KP_ENTER) { me.setHUDSkin(me); return 1; - } - else - { + } else { return SUPER(XonoticHUDSkinList).keyDown(me, scan, ascii, shift); } } diff --git a/qcsrc/menu/xonotic/inputbox.qc b/qcsrc/menu/xonotic/inputbox.qc index 22a7ce717..6645e64f8 100644 --- a/qcsrc/menu/xonotic/inputbox.qc +++ b/qcsrc/menu/xonotic/inputbox.qc @@ -26,27 +26,30 @@ void XonoticInputBox_focusLeave(entity me) } void XonoticInputBox_setText(entity me, string val) { - if(me.text != val) - { + if (me.text != val) { SUPER(XonoticInputBox).setText(me, val); - if(me.onChange) + if (me.onChange) { me.onChange(me, me.onChangeEntity); - if(me.saveImmediately) + } + if (me.saveImmediately) { me.saveCvars(me); - } - else + } + } else { SUPER(XonoticInputBox).setText(me, val); + } } void XonoticInputBox_loadCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } SUPER(XonoticInputBox).setText(me, cvar_string(me.cvarName)); } void XonoticInputBox_saveCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } cvar_set(me.cvarName, me.text); CheckSendCvars(me, me.cvarName); } @@ -54,17 +57,17 @@ float XonoticInputBox_keyDown(entity me, float key, float ascii, float shift) { float r; r = 0; - if(key == K_ENTER || key == K_KP_ENTER) - { - if(me.cvarName) - { + if (key == K_ENTER || key == K_KP_ENTER) { + if (me.cvarName) { me.saveCvars(me); r = 1; } - if(me.onEnter) + if (me.onEnter) { me.onEnter(me, me.onEnterEntity); + } } - if(SUPER(XonoticInputBox).keyDown(me, key, ascii, shift)) + if (SUPER(XonoticInputBox).keyDown(me, key, ascii, shift)) { r = 1; + } return r; } diff --git a/qcsrc/menu/xonotic/inputbox.qh b/qcsrc/menu/xonotic/inputbox.qh index 7be855cd9..dcc301de6 100644 --- a/qcsrc/menu/xonotic/inputbox.qh +++ b/qcsrc/menu/xonotic/inputbox.qh @@ -20,7 +20,7 @@ CLASS(XonoticInputBox, InputBox) ATTRIB(XonoticInputBox, alpha, float, SKINALPHA_TEXT); // Clear button attributes - ATTRIB(XonoticInputBox, cb_offset, float, SKINOFFSET_CLEARBUTTON); // bound to range -1, 0 + ATTRIB(XonoticInputBox, cb_offset, float, SKINOFFSET_CLEARBUTTON); // bound to range -1, 0 ATTRIB(XonoticInputBox, cb_src, string, SKINGFX_CLEARBUTTON); ATTRIB(XonoticInputBox, cb_color, vector, SKINCOLOR_CLEARBUTTON_N); ATTRIB(XonoticInputBox, cb_colorF, vector, SKINCOLOR_CLEARBUTTON_F); diff --git a/qcsrc/menu/xonotic/languagelist.qc b/qcsrc/menu/xonotic/languagelist.qc index 6840769d7..308be3ba2 100644 --- a/qcsrc/menu/xonotic/languagelist.qc +++ b/qcsrc/menu/xonotic/languagelist.qc @@ -27,10 +27,9 @@ void XonoticLanguageList_configureXonoticLanguageList(entity me) void XonoticLanguageList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { string s, p; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } @@ -46,8 +45,7 @@ void XonoticLanguageList_drawListBoxItem(entity me, int i, vector absSize, bool draw_fontscale = save_fontscale; p = me.languageParameter(me, i, LANGPARM_PERCENTAGE); - if(p != "") - { + if (p != "") { vector save_fontscale = draw_fontscale; float f = draw_CondensedFontFactor(p, false, me.realFontSize, 1); draw_fontscale.x *= f; @@ -84,20 +82,16 @@ void XonoticLanguageList_loadCvars(entity me) n = me.nItems; // default to English - for(i = 0; i < n; ++i) - { - if(me.languageParameter(me, i, LANGPARM_ID) == "en") - { + for (i = 0; i < n; ++i) { + if (me.languageParameter(me, i, LANGPARM_ID) == "en") { SUPER(XonoticLanguageList).setSelected(me, i); break; } } // otherwise, find the language - for(i = 0; i < n; ++i) - { - if(me.languageParameter(me, i, LANGPARM_ID) == s) - { + for (i = 0; i < n; ++i) { + if (me.languageParameter(me, i, LANGPARM_ID) == s) { SUPER(XonoticLanguageList).setSelected(me, i); break; } @@ -120,14 +114,13 @@ void XonoticLanguageList_doubleClickListBoxItem(entity me, float i, vector where float XonoticLanguageList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER) - { + if (scan == K_ENTER || scan == K_KP_ENTER) { m_play_click_sound(MENU_SOUND_EXECUTE); me.setLanguage(me); return 1; - } - else + } else { return SUPER(XonoticLanguageList).keyDown(me, scan, ascii, shift); + } } void XonoticLanguageList_destroy(entity me) @@ -144,17 +137,18 @@ void XonoticLanguageList_getLanguages(entity me) fh = fopen("languages.txt", FILE_READ); i = 0; - while((s = fgets(fh))) - { + while ((s = fgets(fh))) { n = tokenize_console(s); - if(n < 3) + if (n < 3) { continue; + } bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_ID, argv(0)); bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_NAME, argv(1)); bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_NAME_LOCALIZED, argv(2)); string percent = argv(3); - if(percent && percent != "100%") + if (percent && percent != "100%") { bufstr_set(buf, i * LANGPARM_COUNT + LANGPARM_PERCENTAGE, percent); + } ++i; } fclose(fh); @@ -165,12 +159,12 @@ void XonoticLanguageList_getLanguages(entity me) void XonoticLanguageList_setLanguage(entity me) { - if(prvm_language != cvar_string("_menu_prvm_language")) - { - if(!(gamestatus & GAME_CONNECTED)) + if (prvm_language != cvar_string("_menu_prvm_language")) { + if (!(gamestatus & GAME_CONNECTED)) { localcmd("\nprvm_language \"$_menu_prvm_language\"; menu_restart; menu_cmd languageselect\n"); - else + } else { DialogOpenButton_Click(me, main.languageWarningDialog); + } } } diff --git a/qcsrc/menu/xonotic/languagelist.qh b/qcsrc/menu/xonotic/languagelist.qh index daf249e45..8abd54e1a 100644 --- a/qcsrc/menu/xonotic/languagelist.qh +++ b/qcsrc/menu/xonotic/languagelist.qh @@ -18,7 +18,7 @@ CLASS(XonoticLanguageList, XonoticListBox) ATTRIB(XonoticLanguageList, columnPercentageSize, float, 0); METHOD(XonoticLanguageList, doubleClickListBoxItem, void(entity, float, vector)); - METHOD(XonoticLanguageList, keyDown, float(entity, float, float, float)); // enter handling + METHOD(XonoticLanguageList, keyDown, float(entity, float, float, float)); // enter handling METHOD(XonoticLanguageList, destroy, void(entity)); @@ -27,7 +27,7 @@ CLASS(XonoticLanguageList, XonoticListBox) METHOD(XonoticLanguageList, setLanguage, void(entity)); METHOD(XonoticLanguageList, languageParameter, string(entity, float, float)); - ATTRIB(XonoticLanguageList, name, string, "languageselector"); // change this to make it noninteractive (for first run dialog); + ATTRIB(XonoticLanguageList, name, string, "languageselector"); // change this to make it noninteractive (for first run dialog); ENDCLASS(XonoticLanguageList) entity makeXonoticLanguageList(); diff --git a/qcsrc/menu/xonotic/maplist.qc b/qcsrc/menu/xonotic/maplist.qc index 111744e96..c7f07215b 100644 --- a/qcsrc/menu/xonotic/maplist.qc +++ b/qcsrc/menu/xonotic/maplist.qc @@ -47,39 +47,44 @@ void XonoticMapList_g_maplistCacheToggle(entity me, float i) string a, b, c, s, bspname; float n; s = me.g_maplistCache; - if (!s) + if (!s) { return; + } b = substring(s, i, 1); - if(b == "0") + if (b == "0") { b = "1"; - else if(b == "1") + } else if (b == "1") { b = "0"; - else + } else { return; // nothing happens + } a = substring(s, 0, i); - c = substring(s, i+1, strlen(s) - (i+1)); + c = substring(s, i + 1, strlen(s) - (i + 1)); strunzone(s); me.g_maplistCache = strzone(strcat(a, b, c)); // TODO also update the actual cvar - if (!((bspname = MapInfo_BSPName_ByID(i)))) + if (!((bspname = MapInfo_BSPName_ByID(i)))) { return; - if(b == "1") + } + if (b == "1") { cvar_set("g_maplist", strcat(bspname, " ", cvar_string("g_maplist"))); - else - { + } else { s = ""; n = tokenize_console(cvar_string("g_maplist")); - for(i = 0; i < n; ++i) - if(argv(i) != bspname) + for (i = 0; i < n; ++i) { + if (argv(i) != bspname) { s = strcat(s, " ", argv(i)); + } + } cvar_set("g_maplist", substring(s, 1, strlen(s) - 1)); } } void XonoticMapList_draw(entity me) { - if(me.startButton) + if (me.startButton) { me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems)); + } SUPER(XonoticMapList).draw(me); } @@ -104,24 +109,24 @@ void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, ve void XonoticMapList_clickListBoxItem(entity me, float i, vector where) { - if(where.x <= me.columnPreviewOrigin + me.columnPreviewSize) - if(where.x >= 0) - { + if (where.x <= me.columnPreviewOrigin + me.columnPreviewSize) { + if (where.x >= 0) { m_play_click_sound(MENU_SOUND_SELECT); me.g_maplistCacheToggle(me, i); } + } } void XonoticMapList_doubleClickListBoxItem(entity me, float i, vector where) { - if(where.x >= me.columnNameOrigin) - if(where.x <= 1) - { + if (where.x >= me.columnNameOrigin) { + if (where.x <= 1) { // pop up map info screen m_play_click_sound(MENU_SOUND_OPEN); main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, i, me); DialogOpenButton_Click_withCoords(NULL, main.mapInfoDialog, me.origin + eX * (me.columnNameOrigin * me.size.x) + eY * ((me.itemHeight * i - me.scrollPos) * me.size.y), eY * me.itemAbsSize.y + eX * (me.itemAbsSize.x * me.columnNameSize)); } + } } void XonoticMapList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) @@ -131,35 +136,38 @@ void XonoticMapList_drawListBoxItem(entity me, int i, vector absSize, bool isSel float theAlpha; float included; - if(!MapInfo_Get_ByID(i)) + if (!MapInfo_Get_ByID(i)) { return; + } included = me.g_maplistCacheQuery(me, i); - if(included || isSelected) + if (included || isSelected) { theAlpha = SKINALPHA_MAPLIST_INCLUDEDFG; - else + } else { theAlpha = SKINALPHA_MAPLIST_NOTINCLUDEDFG; + } - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else - { - if(included) + } else { + if (included) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG); - if(isFocused) - { + } + if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } } - if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0') + if (draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0') { draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); - else + } else { draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + } - if(included) + if (included) { draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1); + } s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_titlestring), me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_TITLE, theAlpha, 0); s = draw_TextShortenToWidth(strdecolorize(MapInfo_Map_author), me.columnNameSize, 0, me.realFontSize); @@ -175,35 +183,37 @@ void XonoticMapList_refilter(entity me) Gametype gt = MapInfo_CurrentGametype(); int f = MapInfo_CurrentFeatures(); MapInfo_FilterGametype(gt, f, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); - if (me.stringFilter) + if (me.stringFilter) { MapInfo_FilterString(me.stringFilter); + } me.nItems = MapInfo_count; - for(i = 0; i < MapInfo_count; ++i) + for (i = 0; i < MapInfo_count; ++i) { draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i))); - if(me.g_maplistCache) + } + if (me.g_maplistCache) { strunzone(me.g_maplistCache); + } s = "0"; - for(i = 1; i < MapInfo_count; i *= 2) + for (i = 1; i < MapInfo_count; i *= 2) { s = strcat(s, s); + } n = tokenize_console(cvar_string("g_maplist")); - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { j = MapInfo_FindName(argv(i)); - if(j >= 0) - { + if (j >= 0) { // double check that the two mapnames are "identical", not just share the same prefix - if (strlen(MapInfo_BSPName_ByID(j)) == strlen(argv(i))) + if (strlen(MapInfo_BSPName_ByID(j)) == strlen(argv(i))) { s = strcat( substring(s, 0, j), "1", - substring(s, j+1, MapInfo_count - (j+1)) - ); + substring(s, j + 1, MapInfo_count - (j + 1)) + ); + } } } me.g_maplistCache = strzone(s); - if(gt != me.lastGametype || f != me.lastFeatures) - { + if (gt != me.lastGametype || f != me.lastFeatures) { me.lastGametype = gt; me.lastFeatures = f; me.setSelected(me, 0); @@ -217,12 +227,14 @@ void XonoticMapList_refilterCallback(entity me, entity cb) void MapList_StringFilterBox_Change(entity box, entity me) { - if(me.stringFilter) + if (me.stringFilter) { strunzone(me.stringFilter); - if(box.text != "") + } + if (box.text != "") { me.stringFilter = strzone(box.text); - else + } else { me.stringFilter = string_null; + } me.refilter(me); } @@ -231,10 +243,10 @@ void MapList_Add_Shown(entity btn, entity me) { float i, n; n = strlen(me.g_maplistCache); - for (i = 0 ; i < n; i++) - { - if (!me.g_maplistCacheQuery(me, i)) + for (i = 0; i < n; i++) { + if (!me.g_maplistCacheQuery(me, i)) { me.g_maplistCacheToggle(me, i); + } } me.refilter(me); } @@ -243,10 +255,10 @@ void MapList_Remove_Shown(entity btn, entity me) { float i, n; n = strlen(me.g_maplistCache); - for (i = 0 ; i < n; i++) - { - if (me.g_maplistCacheQuery(me, i)) + for (i = 0; i < n; i++) { + if (me.g_maplistCacheQuery(me, i)) { me.g_maplistCacheToggle(me, i); + } } me.refilter(me); } @@ -257,8 +269,9 @@ void MapList_Add_All(entity btn, entity me) string s; _MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, MapInfo_ForbiddenFlags(), 0); // all s = ""; - for(i = 0; i < MapInfo_count; ++i) + for (i = 0; i < MapInfo_count; ++i) { s = strcat(s, " ", MapInfo_BSPName_ByID(i)); + } cvar_set("g_maplist", substring(s, 1, strlen(s) - 1)); me.refilter(me); } @@ -276,31 +289,28 @@ void MapList_LoadMap(entity btn, entity me) i = me.selectedItem; - if(btn.parent.instanceOfXonoticMapInfoDialog) - { + if (btn.parent.instanceOfXonoticMapInfoDialog) { i = btn.parent.currentMapIndex; Dialog_Close(btn, btn.parent); } - if(i >= me.nItems || i < 0) + if (i >= me.nItems || i < 0) { return; + } m = MapInfo_BSPName_ByID(i); - if (!m) - { + if (!m) { LOG_INFO(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.")); me.refilter(me); return; } - if(MapInfo_CheckMap(m)) - { + if (MapInfo_CheckMap(m)) { localcmd("\nmenu_loadmap_prepare\n"); - if(cvar("menu_use_default_hostname")) + if (cvar("menu_use_default_hostname")) { localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n"); + } MapInfo_LoadMap(m, 1); - } - else - { + } else { LOG_INFO(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.")); me.refilter(me); return; @@ -310,79 +320,66 @@ void MapList_LoadMap(entity btn, entity me) float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift) { string ch, save; - if(me.nItems <= 0) + if (me.nItems <= 0) { return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift); - if(scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER) - { + } + if (scan == K_MOUSE2 || scan == K_SPACE || scan == K_ENTER || scan == K_KP_ENTER) { // pop up map info screen m_play_click_sound(MENU_SOUND_OPEN); main.mapInfoDialog.loadMapInfo(main.mapInfoDialog, me.selectedItem, me); DialogOpenButton_Click_withCoords(NULL, main.mapInfoDialog, me.origin + eX * (me.columnNameOrigin * me.size.x) + eY * ((me.itemHeight * me.selectedItem - me.scrollPos) * me.size.y), eY * me.itemAbsSize.y + eX * (me.itemAbsSize.x * me.columnNameSize)); - } - else if(scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS) - { + } else if (scan == K_MOUSE3 || scan == K_INS || scan == K_KP_INS) { m_play_click_sound(MENU_SOUND_SELECT); me.g_maplistCacheToggle(me, me.selectedItem); - } - else if(ascii == 43) // + - { - if (!me.g_maplistCacheQuery(me, me.selectedItem)) - { + } else if (ascii == 43) { // + + if (!me.g_maplistCacheQuery(me, me.selectedItem)) { m_play_click_sound(MENU_SOUND_SELECT); me.g_maplistCacheToggle(me, me.selectedItem); } - } - else if(ascii == 45) // - - { - if(me.g_maplistCacheQuery(me, me.selectedItem)) - { + } else if (ascii == 45) { // - + if (me.g_maplistCacheQuery(me, me.selectedItem)) { m_play_click_sound(MENU_SOUND_SELECT); me.g_maplistCacheToggle(me, me.selectedItem); } - } - else if(scan == K_BACKSPACE) - { - if(time < me.typeToSearchTime) - { + } else if (scan == K_BACKSPACE) { + if (time < me.typeToSearchTime) { save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1); - if(me.typeToSearchString) + if (me.typeToSearchString) { strunzone(me.typeToSearchString); + } me.typeToSearchString = strzone(save); me.typeToSearchTime = time + 0.5; - if(strlen(me.typeToSearchString)) - { + if (strlen(me.typeToSearchString)) { MapInfo_FindName(me.typeToSearchString); - if(MapInfo_FindName_firstResult >= 0) + if (MapInfo_FindName_firstResult >= 0) { me.setSelected(me, MapInfo_FindName_firstResult); + } } } - } - else if(ascii >= 32 && ascii != 127) - { + } else if (ascii >= 32 && ascii != 127) { ch = chr(ascii); - if(time > me.typeToSearchTime) + if (time > me.typeToSearchTime) { save = ch; - else + } else { save = strcat(me.typeToSearchString, ch); - if(me.typeToSearchString) + } + if (me.typeToSearchString) { strunzone(me.typeToSearchString); + } me.typeToSearchString = strzone(save); me.typeToSearchTime = time + 0.5; MapInfo_FindName(me.typeToSearchString); - if(MapInfo_FindName_firstResult >= 0) + if (MapInfo_FindName_firstResult >= 0) { me.setSelected(me, MapInfo_FindName_firstResult); - } - else if(shift & S_CTRL && scan == 'f') // ctrl-f (as in "F"ind) - { + } + } else if (shift & S_CTRL && scan == 'f') { // ctrl-f (as in "F"ind) me.parent.setFocus(me.parent, me.stringFilterBox); - } - else if(shift & S_CTRL && scan == 'u') // ctrl-u (remove stringFilter line - { + } else if (shift & S_CTRL && scan == 'u') { // ctrl-u (remove stringFilter line me.stringFilterBox.setText(me.stringFilterBox, ""); MapList_StringFilterBox_Change(me.stringFilterBox, me); - } - else + } else { return SUPER(XonoticMapList).keyDown(me, scan, ascii, shift); + } return 1; } @@ -390,8 +387,7 @@ float MapList_StringFilterBox_keyDown(entity me, float scan, float ascii, float { // in this section, note that onChangeEntity has the ref to mapListBox // we make use of that, instead of extending a class to add one more attrib - switch(scan) - { + switch (scan) { case K_KP_ENTER: case K_ENTER: // move the focus to the mapListBox diff --git a/qcsrc/menu/xonotic/nexposee.qc b/qcsrc/menu/xonotic/nexposee.qc index 7c2bcacd9..6a95a8588 100644 --- a/qcsrc/menu/xonotic/nexposee.qc +++ b/qcsrc/menu/xonotic/nexposee.qc @@ -9,8 +9,7 @@ entity makeXonoticNexposee() } void XonoticNexposee_configureXonoticNexposee(entity me) -{ -} +{} void XonoticNexposee_close(entity me) { diff --git a/qcsrc/menu/xonotic/playerlist.qc b/qcsrc/menu/xonotic/playerlist.qc index c6033050a..ef23acfca 100644 --- a/qcsrc/menu/xonotic/playerlist.qc +++ b/qcsrc/menu/xonotic/playerlist.qc @@ -18,30 +18,25 @@ entity makeXonoticPlayerList() void XonoticPlayerList_setPlayerList(entity me, string plist) { - int buf,i,n; + int buf, i, n; string s; buf = buf_create(); me.nItems = tokenizebyseparator(plist, "\n"); - for(i = 0; i < me.nItems; ++i) - { + for (i = 0; i < me.nItems; ++i) { bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(i)); // -666 100 "^4Nex ^2Player" } - for(i = 0; i < me.nItems; ++i) - { + for (i = 0; i < me.nItems; ++i) { s = bufstr_get(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME); n = tokenize_console(s); - if(n == 4) - { + if (n == 4) { bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING, argv(1)); // 100 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, argv(2)); // 0 for spec, else 1, 2, 3, 4 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_NAME, argv(3)); // ^4Nex ^2Player - } - else - { + } else { bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_SCORE, argv(0)); // -666 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_PING, argv(1)); // 100 bufstr_set(buf, i * PLAYERPARM_COUNT + PLAYERPARM_TEAM, "-1"); @@ -81,33 +76,34 @@ void XonoticPlayerList_drawListBoxItem(entity me, int i, vector absSize, bool is vector rgb; t = stof(me.getPlayerList(me, i, PLAYERPARM_TEAM)); - if(t == 1) + if (t == 1) { rgb = colormapPaletteColor(4, 0); - else if(t == 2) + } else if (t == 2) { rgb = colormapPaletteColor(13, 0); - else if(t == 3) + } else if (t == 3) { rgb = colormapPaletteColor(12, 0); - else if(t == 4) + } else if (t == 4) { rgb = colormapPaletteColor(9, 0); - else + } else { rgb = SKINCOLOR_TEXT; + } s = me.getPlayerList(me, i, PLAYERPARM_NAME); score = me.getPlayerList(me, i, PLAYERPARM_SCORE); - if(substring(score, strlen(score) - 10, 10) == ":spectator") - { + if (substring(score, strlen(score) - 10, 10) == ":spectator") { score = _("spectator"); - } - else - { - if((t = strstrofs(score, ":", 0)) >= 0) + } else { + if ((t = strstrofs(score, ":", 0)) >= 0) { score = substring(score, 0, t); - if((t = strstrofs(score, ",", 0)) >= 0) + } + if ((t = strstrofs(score, ",", 0)) >= 0) { score = substring(score, 0, t); + } - if(stof(score) == FRAGS_SPECTATOR) + if (stof(score) == FRAGS_SPECTATOR) { score = _("spectator"); + } } s = draw_TextShortenToWidth(s, me.columnNameSize, 1, me.realFontSize); diff --git a/qcsrc/menu/xonotic/playlist.qc b/qcsrc/menu/xonotic/playlist.qc index c912ba3a7..30175f92d 100644 --- a/qcsrc/menu/xonotic/playlist.qc +++ b/qcsrc/menu/xonotic/playlist.qc @@ -33,16 +33,15 @@ void XonoticPlayList_resizeNotify(entity me, vector relOrigin, vector relSize, v void XonoticPlayList_addToPlayList(entity me, string track) { me.nItems = tokenize_console(cvar_string("music_playlist_list0")); - if(me.nItems == 0) - { + if (me.nItems == 0) { cvar_set("music_playlist_list0", track); return; } float i; - for(i = 0; i < me.nItems; ++i) - { - if(argv(i) == track) + for (i = 0; i < me.nItems; ++i) { + if (argv(i) == track) { return; // track is already in playlist + } } cvar_set("music_playlist_list0", strcat(cvar_string("music_playlist_list0"), " ", track)); } @@ -52,20 +51,20 @@ void XonoticPlayList_removeSelectedFromPlayList(entity me) float i, cpt = false; string s = ""; me.nItems = tokenize_console(cvar_string("music_playlist_list0")); - if(me.nItems == 0) + if (me.nItems == 0) { return; - for(i = 0; i < me.nItems; ++i) - { - if(i == me.selectedItem) - { - if(i == me.nItems - 1) + } + for (i = 0; i < me.nItems; ++i) { + if (i == me.selectedItem) { + if (i == me.nItems - 1) { me.setSelected(me, me.selectedItem - 1); - if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999) - { - if(cvar("music_playlist_current0") == i) + } + if (cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999) { + if (cvar("music_playlist_current0") == i) { cpt = true; // current playing track (we can't start next track here because startSound calls tokenize_console) - else if(cvar("music_playlist_current0") > i) + } else if (cvar("music_playlist_current0") > i) { cvar_set("music_playlist_current0", ftos(cvar("music_playlist_current0") - 1)); + } } continue; } @@ -73,17 +72,16 @@ void XonoticPlayList_removeSelectedFromPlayList(entity me) } // we must stop the current playing track if it has been removed // otherwise pause/play button will resume from another track - if(s == "") - { + if (s == "") { cvar_set("music_playlist_list0", ""); - if(cpt) + if (cpt) { me.stopSound(me); - } - else - { + } + } else { cvar_set("music_playlist_list0", substring(s, 1, strlen(s))); // remove initial space - if(cpt) + if (cpt) { me.startSound(me, 0); + } } } @@ -105,16 +103,15 @@ float XonoticPlayList_mouseDrag(entity me, vector pos) i = me.selectedItem; f = SUPER(XonoticPlayList).mouseDrag(me, pos); - if(me.pressed != 1) // don't change priority if the person is just scrolling - { - if(me.selectedItem != i) - { + if (me.pressed != 1) { // don't change priority if the person is just scrolling + if (me.selectedItem != i) { cvar_set("music_playlist_list0", swapInPriorityList(cvar_string("music_playlist_list0"), me.selectedItem, i)); float c = cvar("music_playlist_current0"); - if(c == i) + if (c == i) { cvar_set("music_playlist_current0", ftos(me.selectedItem)); - else if(c == me.selectedItem) + } else if (c == me.selectedItem) { cvar_set("music_playlist_current0", ftos(i)); + } } } @@ -124,32 +121,32 @@ float XonoticPlayList_mouseDrag(entity me, vector pos) void XonoticPlayList_draw(entity me) { me.nItems = tokenize_console(cvar_string("music_playlist_list0")); - if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999) + if (cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999) { me.playingTrack = cvar("music_playlist_current0"); - else + } else { me.playingTrack = -1; + } SUPER(XonoticPlayList).draw(me); } void XonoticPlayList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { string s; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - if(i == me.playingTrack) - { + if (i == me.playingTrack) { float f = cvar("music_playlist_sampleposition0"); - if(f <= 0 || (((time * 2) & 1) && f > 0)) + if (f <= 0 || (((time * 2) & 1) && f > 0)) { draw_Text(me.realUpperMargin * eY + (me.columnNumberOrigin + me.columnNumberSize) * eX, "\xE2\x96\xB6", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); + } } - s = ftos(i+1); + s = ftos(i + 1); draw_CenterText(me.realUpperMargin * eY + (me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); s = draw_TextShortenToWidth(argv(i), me.columnNameSize, 0, me.realFontSize); @@ -160,8 +157,7 @@ void XonoticPlayList_stopSound(entity me) { // STOP: list 0 is disabled by setting the index to -1 // we set sampleposition0 to 0 to forget the position that the engine saves in this frame (for this reason we need to wait a frame) - if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999) - { + if (cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999) { cvar_set("music_playlist_index", "-1"); localcmd("\nwait; music_playlist_sampleposition0 0\n"); localcmd("\ndefer 3 \"cd play $menu_cdtrack\"\n"); @@ -177,23 +173,22 @@ void XonoticPlayList_startSound(entity me, float offset) { float f; me.nItems = tokenize_console(cvar_string("music_playlist_list0")); - if(offset) - { - if(cvar("music_playlist_index") == -1) + if (offset) { + if (cvar("music_playlist_index") == -1) { return; + } f = bound(0, cvar("music_playlist_current0") + offset, me.nItems - 1); - if(f == cvar("music_playlist_current0")) + if (f == cvar("music_playlist_current0")) { return; - } - else - { + } + } else { f = me.selectedItem; // if it was paused then resume - if(f == cvar("music_playlist_current0")) - if(cvar("music_playlist_index") == 999) - { - me.resumeSound(me); - return; + if (f == cvar("music_playlist_current0")) { + if (cvar("music_playlist_index") == 999) { + me.resumeSound(me); + return; + } } // if it was not paused then proceed with restart } @@ -225,16 +220,17 @@ void XonoticPlayList_resumeSound(entity me) { // RESUME: list 0 is enabled by setting the index to 0 // (we reset sampleposition0 to 0 to mark the track as in playing back state) - if(cvar("music_playlist_index") == 999) + if (cvar("music_playlist_index") == 999) { localcmd("\nmusic_playlist_index 0; wait; music_playlist_sampleposition0 0\n"); + } } void XonoticPlayList_pauseSound(entity me) { // PAUSE: list 0 is disabled by setting the index to 999 // (we know the track is paused because the engine sets sampleposition0 to remember current position) - if(cvar("music_playlist_index") == 0) + if (cvar("music_playlist_index") == 0) { localcmd("\nmusic_playlist_index 999\n"); - else me.resumeSound(me); + } else { me.resumeSound(me); } } void PauseSound_Click(entity btn, entity me) @@ -249,18 +245,16 @@ void XonoticPlayList_doubleClickListBoxItem(entity me, float i, vector where) float XonoticPlayList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER) { + if (scan == K_ENTER || scan == K_KP_ENTER) { me.startSound(me, 0); return 1; - } - else if(scan == K_SPACE) { + } else if (scan == K_SPACE) { me.pauseSound(me); return 1; - } - else if(scan == K_DEL || scan == K_KP_DEL || scan == K_BACKSPACE || scan == K_MOUSE3) { + } else if (scan == K_DEL || scan == K_KP_DEL || scan == K_BACKSPACE || scan == K_MOUSE3) { me.removeSelectedFromPlayList(me); return 1; - } - else + } else { return SUPER(XonoticPlayList).keyDown(me, scan, ascii, shift); + } } diff --git a/qcsrc/menu/xonotic/radiobutton.qc b/qcsrc/menu/xonotic/radiobutton.qc index 536ea4f15..b17cb0074 100644 --- a/qcsrc/menu/xonotic/radiobutton.qc +++ b/qcsrc/menu/xonotic/radiobutton.qc @@ -21,32 +21,25 @@ void XonoticRadioButton_configureXonoticRadioButton(entity me, float theGroup, s } void XonoticRadioButton_setChecked(entity me, float val) { - if(val != me.checked) - { + if (val != me.checked) { me.checked = val; me.saveCvars(me); } } void XonoticRadioButton_loadCvars(entity me) { - if(me.cvarValue) - { - if(me.cvarName) - { - if(me.cvarValueIsAnotherCvar) + if (me.cvarValue) { + if (me.cvarName) { + if (me.cvarValueIsAnotherCvar) { me.checked = (cvar_string(me.cvarName) == cvar_string(me.cvarValue)); - else + } else { me.checked = (cvar_string(me.cvarName) == me.cvarValue); + } } - } - else - { - if(me.cvarName) - { + } else { + if (me.cvarName) { me.checked = boolean(cvar(me.cvarName)); - } - else - { + } else { // this is difficult // this is the "generic" selection... but at this time, not // everything is constructed yet. @@ -57,44 +50,43 @@ void XonoticRadioButton_loadCvars(entity me) } void XonoticRadioButton_draw(entity me) { - if (!me.cvarValue) - if (!me.cvarName) - { + if (!me.cvarValue) { + if (!me.cvarName) { // this is the "other" option // always select this if none other is entity e; float found; found = 0; - for(e = me.parent.firstChild; e; e = e.nextSibling) - if(e.group == me.group) - if(e.checked) + for (e = me.parent.firstChild; e; e = e.nextSibling) { + if (e.group == me.group) { + if (e.checked) { found = 1; - if(!found) + } + } + } + if (!found) { me.setChecked(me, 1); + } } + } SUPER(XonoticRadioButton).draw(me); } void XonoticRadioButton_saveCvars(entity me) { - if(me.cvarValue) - { - if(me.cvarName) - { - if(me.checked) - { - if(me.cvarValueIsAnotherCvar) + if (me.cvarValue) { + if (me.cvarName) { + if (me.checked) { + if (me.cvarValueIsAnotherCvar) { cvar_set(me.cvarName, cvar_string(me.cvarValue)); - else + } else { cvar_set(me.cvarName, me.cvarValue); - } - else if(me.cvarOffValue) + } + } else if (me.cvarOffValue) { cvar_set(me.cvarName, me.cvarOffValue); + } } - } - else - { - if(me.cvarName) - { + } else { + if (me.cvarName) { cvar_set(me.cvarName, ftos(me.checked)); } } diff --git a/qcsrc/menu/xonotic/screenshotlist.qc b/qcsrc/menu/xonotic/screenshotlist.qc index a948ce86f..41a6b9983 100644 --- a/qcsrc/menu/xonotic/screenshotlist.qc +++ b/qcsrc/menu/xonotic/screenshotlist.qc @@ -24,9 +24,9 @@ string XonoticScreenshotList_screenshotName(entity me, float i) string s; s = bufstr_get(me.listScreenshot, i); - if(substring(s, 0, 1) == "/") - s = substring(s, 1, strlen(s) - 1); // remove the first forward slash - + if (substring(s, 0, 1) == "/") { + s = substring(s, 1, strlen(s) - 1); // remove the first forward slash + } return s; } @@ -34,47 +34,46 @@ string XonoticScreenshotList_screenshotName(entity me, float i) void getScreenshots_for_ext(entity me, string ext, float subdir) { string s; - if (subdir) - s="screenshots/*/"; - else - s="screenshots/"; - if(me.filterString) - s=strcat(s, me.filterString, ext); - else - s=strcat(s, "*", ext); + if (subdir) { + s = "screenshots/*/"; + } else { + s = "screenshots/"; + } + if (me.filterString) { + s = strcat(s, me.filterString, ext); + } else { + s = strcat(s, "*", ext); + } float list, i, n; list = search_begin(s, false, true); - if(list >= 0) - { + if (list >= 0) { n = search_getsize(list); - for(i = 0; i < n; ++i) - { - s = search_getfilename(list, i); // get initial full file name - s = substring(s, 12, (strlen(s) - 12 - 4)); // remove "screenshots/" prefix and "." suffix - s = strdecolorize(s); // remove any pre-existing colors - if(subdir) - { - s = strreplace("/", "^7/", s); // clear colors at the forward slash + for (i = 0; i < n; ++i) { + s = search_getfilename(list, i); // get initial full file name + s = substring(s, 12, (strlen(s) - 12 - 4)); // remove "screenshots/" prefix and "." suffix + s = strdecolorize(s); // remove any pre-existing colors + if (subdir) { + s = strreplace("/", "^7/", s); // clear colors at the forward slash s = strcat("/", rgb_to_hexcolor(SKINCOLOR_SCREENSHOTLIST_SUBDIR), s); // add a forward slash for sorting, then color bufstr_add(me.listScreenshot, s, true); - } - else { bufstr_add(me.listScreenshot, s, true); } + } else { bufstr_add(me.listScreenshot, s, true); } } search_end(list); } - if (subdir) + if (subdir) { getScreenshots_for_ext(me, ext, false); + } } void XonoticScreenshotList_getScreenshots(entity me) { - if (me.listScreenshot >= 0) + if (me.listScreenshot >= 0) { buf_del(me.listScreenshot); + } me.listScreenshot = buf_create(); - if (me.listScreenshot < 0) - { + if (me.listScreenshot < 0) { me.nItems = 0; return; } @@ -82,14 +81,16 @@ void XonoticScreenshotList_getScreenshots(entity me) getScreenshots_for_ext(me, ".tga", true); getScreenshots_for_ext(me, ".png", true); me.nItems = buf_getsize(me.listScreenshot); - if(me.nItems > 0) + if (me.nItems > 0) { buf_sort(me.listScreenshot, 128, false); + } } void XonoticScreenshotList_destroy(entity me) { - if(me.nItems > 0) + if (me.nItems > 0) { buf_del(me.listScreenshot); + } } void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) @@ -107,17 +108,15 @@ void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relS void XonoticScreenshotList_setSelected(entity me, float i) { - if (me.newSlideShowScreenshotTime) + if (me.newSlideShowScreenshotTime) { me.startSlideShow(me); + } float selectedItem_save = me.selectedItem; SUPER(XonoticScreenshotList).setSelected(me, i); - if (me.pressed && me.selectedItem != selectedItem_save) - { + if (me.pressed && me.selectedItem != selectedItem_save) { // avoid immediate image loading on quick repeated selection changes me.newScreenshotTime = time + 0.22; - } - else if (time > me.newScreenshotTime) - { + } else if (time > me.newScreenshotTime) { me.newScreenshotTime = 0; me.previewScreenshot(me); // load the preview on selection change } @@ -126,15 +125,14 @@ void XonoticScreenshotList_setSelected(entity me, float i) void XonoticScreenshotList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { string s; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - s = me.screenshotName(me,i); + s = me.screenshotName(me, i); s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 1); } @@ -148,23 +146,24 @@ void XonoticScreenshotList_showNotify(entity me) void ScreenshotList_Refresh_Click(entity btn, entity me) { me.getScreenshots(me); - me.setSelected(me, 0); //always select the first element after a list update + me.setSelected(me, 0); // always select the first element after a list update } void ScreenshotList_Filter_Change(entity box, entity me) { - if(me.filterString) + if (me.filterString) { strunzone(me.filterString); + } - if(box.text != "") - { - if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0) + if (box.text != "") { + if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0) { me.filterString = strzone(box.text); - else + } else { me.filterString = strzone(strcat("*", box.text, "*")); - } - else + } + } else { me.filterString = string_null; + } ScreenshotList_Refresh_Click(NULL, me); } @@ -177,26 +176,21 @@ void ScreenshotList_Filter_Would_Change(entity box, entity me) void XonoticScreenshotList_draw(entity me) { - if (me.filterTime && time > me.filterTime) - { + if (me.filterTime && time > me.filterTime) { ScreenshotList_Filter_Change(me.filterBox, me); me.filterTime = 0; } - if (me.newScreenshotTime && time > me.newScreenshotTime) - { + if (me.newScreenshotTime && time > me.newScreenshotTime) { me.previewScreenshot(me); me.newScreenshotTime = 0; - } - else if (me.newSlideShowScreenshotTime && time > me.newSlideShowScreenshotTime) - { - if (me.selectedItem == me.nItems - 1) //last screenshot? - { + } else if (me.newSlideShowScreenshotTime && time > me.newSlideShowScreenshotTime) { + if (me.selectedItem == me.nItems - 1) { // last screenshot? // restart from the first screenshot me.setSelected(me, 0); me.goScreenshot(me, +0); - } - else + } else { me.goScreenshot(me, +1); + } } SUPER(XonoticScreenshotList).draw(me); } @@ -213,27 +207,30 @@ void XonoticScreenshotList_stopSlideShow(entity me) void XonoticScreenshotList_goScreenshot(entity me, float d) { - if(!me.screenshotViewerDialog) + if (!me.screenshotViewerDialog) { return; + } me.setSelected(me, me.selectedItem + d); - me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem)))); + me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me, me.selectedItem)))); } void XonoticScreenshotList_startScreenshot(entity me) { - me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem)))); + me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me, me.selectedItem)))); // pop up screenshot DialogOpenButton_Click_withCoords(NULL, me.screenshotViewerDialog, me.origin + eX * (me.columnNameOrigin * me.size.x) + eY * ((me.itemHeight * me.selectedItem - me.scrollPos) * me.size.y), eY * me.itemAbsSize.y + eX * (me.itemAbsSize.x * me.columnNameSize)); } void XonoticScreenshotList_previewScreenshot(entity me) { - if(!me.screenshotBrowserDialog) + if (!me.screenshotBrowserDialog) { return; - if (me.nItems <= 0) + } + if (me.nItems <= 0) { me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, ""); - else - me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem)))); + } else { + me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me, me.selectedItem)))); + } } void StartScreenshot_Click(entity btn, entity me) @@ -248,7 +245,7 @@ void XonoticScreenshotList_doubleClickListBoxItem(entity me, float i, vector whe float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_MOUSE2 || scan == K_SPACE) { + if (scan == K_ENTER || scan == K_KP_ENTER || scan == K_MOUSE2 || scan == K_SPACE) { me.startScreenshot(me); return 1; } diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index 5e6a567b6..02c531cde 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -9,52 +9,48 @@ void RegisterSLCategories() { entity cat; - #define SLIST_CATEGORY(name,enoverride,dioverride,str) \ - SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \ - CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \ - cat = categories[name - 1] = new(slist_category); \ - cat.cat_name = #name; \ - cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \ - cat.cat_dioverride_string = strzone(dioverride); \ - cat.cat_string = strzone(str); + #define SLIST_CATEGORY(name, enoverride, dioverride, str) \ + SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \ + CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \ + cat = categories[name - 1] = new(slist_category); \ + cat.cat_name = #name; \ + cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \ + cat.cat_dioverride_string = strzone(dioverride); \ + cat.cat_string = strzone(str); SLIST_CATEGORIES #undef SLIST_CATEGORY int i, x, catnum; string s; - #define PROCESS_OVERRIDE(override_string,override_field) \ - for(i = 0; i < category_ent_count; ++i) \ - { \ - s = categories[i].override_string; \ - if((s != "") && (s != categories[i].cat_name)) \ - { \ - catnum = 0; \ - for(x = 0; x < category_ent_count; ++x) \ - { if(categories[x].cat_name == s) { \ - catnum = (x+1); \ + #define PROCESS_OVERRIDE(override_string, override_field) \ + for (i = 0; i < category_ent_count; ++i) { \ + s = categories[i].override_string; \ + if ((s != "") && (s != categories[i].cat_name)) { \ + catnum = 0; \ + for (x = 0; x < category_ent_count; ++x) { \ + if (categories[x].cat_name == s) { \ + catnum = (x + 1); \ break; \ - } } \ - if(catnum) \ - { \ - strunzone(categories[i].override_string); \ - categories[i].override_string = string_null; \ - categories[i].override_field = catnum; \ - continue; \ - } \ - else \ - { \ - LOG_INFOF( \ - "RegisterSLCategories(): Improper override '%s' for category '%s'!", \ - s, \ - categories[i].cat_name \ - ); \ } \ } \ - strunzone(categories[i].override_string); \ - categories[i].override_string = string_null; \ - categories[i].override_field = 0; \ - } + if (catnum) { \ + strunzone(categories[i].override_string); \ + categories[i].override_string = string_null; \ + categories[i].override_field = catnum; \ + continue; \ + } else { \ + LOG_INFOF( \ + "RegisterSLCategories(): Improper override '%s' for category '%s'!", \ + s, \ + categories[i].cat_name \ + ); \ + } \ + } \ + strunzone(categories[i].override_string); \ + categories[i].override_string = string_null; \ + categories[i].override_field = 0; \ + } PROCESS_OVERRIDE(cat_enoverride_string, cat_enoverride) PROCESS_OVERRIDE(cat_dioverride_string, cat_dioverride) #undef PROCESS_OVERRIDE @@ -63,12 +59,9 @@ void RegisterSLCategories() // Supporting Functions entity RetrieveCategoryEnt(int catnum) { - if((catnum > 0) && (catnum <= category_ent_count)) - { + if ((catnum > 0) && (catnum <= category_ent_count)) { return categories[catnum - 1]; - } - else - { + } else { error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum)); return NULL; } @@ -78,25 +71,26 @@ bool IsServerInList(string list, string srv) { string p; int i, n; - if(srv == "") + if (srv == "") { return false; + } srv = netaddress_resolve(srv, 26000); - if(srv == "") + if (srv == "") { return false; + } p = crypto_getidfp(srv); n = tokenize_console(list); - for(i = 0; i < n; ++i) - { - if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) - { - if(p) - if(argv(i) == p) + for (i = 0; i < n; ++i) { + if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) { + if (p) { + if (argv(i) == p) { return true; - } - else - { - if(srv == netaddress_resolve(argv(i), 26000)) + } + } + } else { + if (srv == netaddress_resolve(argv(i), 26000)) { return true; + } } } return false; @@ -105,14 +99,10 @@ bool IsServerInList(string list, string srv) int CheckCategoryOverride(int cat) { entity catent = RetrieveCategoryEnt(cat); - if(catent) - { + if (catent) { int override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride); - if(override) { return override; } - else { return cat; } - } - else - { + if (override) { return override; } else { return cat; } + } else { error(sprintf("CheckCategoryOverride(%d): Improper category number!\n", cat)); return cat; } @@ -125,42 +115,46 @@ int CheckCategoryForEntry(int entry) s = gethostcachestring(SLIST_FIELD_QCSTATUS, entry); m = tokenizebyseparator(s, ":"); - for(j = 2; j < m; ++j) - { - if(argv(j) == "") { break; } + for (j = 2; j < m; ++j) { + if (argv(j) == "") { break; } k = substring(argv(j), 0, 1); v = substring(argv(j), 1, -1); - switch(k) - { - case "P": { impure = stof(v); break; } - case "S": { freeslots = stof(v); break; } - case "F": { sflags = stof(v); break; } - case "M": { modtype = strtolower(v); break; } + switch (k) { + case "P": + { impure = stof(v); + break; + } + case "S": + { freeslots = stof(v); + break; + } + case "F": + { sflags = stof(v); + break; + } + case "M": + { modtype = strtolower(v); + break; + } } } - if(modtype != "xonotic") { impure += autocvar_menu_slist_modimpurity; } + if (modtype != "xonotic") { impure += autocvar_menu_slist_modimpurity; } // check if this server is favorited - if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, entry)) { return CAT_FAVORITED; } + if (gethostcachenumber(SLIST_FIELD_ISFAVORITE, entry)) { return CAT_FAVORITED; } // now check if it's recommended - if(autocvar_menu_slist_recommendations) - { + if (autocvar_menu_slist_recommendations) { string cname = gethostcachestring(SLIST_FIELD_CNAME, entry); - if(IsPromoted(cname)) { return CAT_RECOMMENDED; } - else - { + if (IsPromoted(cname)) { return CAT_RECOMMENDED; } else { float recommended = 0; - if(autocvar_menu_slist_recommendations & 1) - { - if(IsRecommended(cname)) { ++recommended; } - else { --recommended; } + if (autocvar_menu_slist_recommendations & 1) { + if (IsRecommended(cname)) { ++recommended; } else { --recommended; } } - if(autocvar_menu_slist_recommendations & 2) - { - if( + if (autocvar_menu_slist_recommendations & 2) { + if ( ///// check for minimum free slots (freeslots >= autocvar_menu_slist_recommendations_minfreeslots) @@ -185,39 +179,49 @@ int CheckCategoryForEntry(int entry) autocvar_menu_slist_recommendations_maxping ) ) - { ++recommended; } - else - { --recommended; } + { ++recommended; } else + { --recommended; } } - if(recommended > 0) { return CAT_RECOMMENDED; } + if (recommended > 0) { return CAT_RECOMMENDED; } } } // if not favorited or recommended, check modname - if(modtype != "xonotic") - { - switch(modtype) - { + if (modtype != "xonotic") { + switch (modtype) { // old servers which don't report their mod name are considered modified now - case "": { return CAT_MODIFIED; } + case "": + { return CAT_MODIFIED; + } - case "xpm": { return CAT_XPM; } + case "xpm": + { return CAT_XPM; + } case "minstagib": - case "instagib": { return CAT_INSTAGIB; } - case "overkill": { return CAT_OVERKILL; } - //case "nix": { return CAT_NIX; } - //case "newtoys": { return CAT_NEWTOYS; } + case "instagib": + { return CAT_INSTAGIB; + } + case "overkill": + { return CAT_OVERKILL; + } + // case "nix": { return CAT_NIX; } + // case "newtoys": { return CAT_NEWTOYS; } // "cts" is allowed as compat, xdf is replacement case "cts": - case "xdf": { return CAT_DEFRAG; } + case "xdf": + { return CAT_DEFRAG; + } - default: { LOG_TRACEF("Found strange mod type: %s", modtype); return CAT_MODIFIED; } + default: + { LOG_TRACEF("Found strange mod type: %s", modtype); + return CAT_MODIFIED; + } } } // must be normal or impure server - return ((impure > autocvar_menu_slist_purethreshold) ? CAT_MODIFIED : CAT_NORMAL); + return (impure > autocvar_menu_slist_purethreshold) ? CAT_MODIFIED : CAT_NORMAL; } METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string srv)) @@ -227,20 +231,16 @@ METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string sr string p = crypto_getidfp(srv_resolved); string s = cvar_string("net_slist_favorites"); string ret = s; - for (int i = 0, n = tokenize_console(s); i < n; ++i) - { + for (int i = 0, n = tokenize_console(s); i < n; ++i) { bool match; - if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) - { + if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) { // it's a pubkey hash match = (p && p == argv(i)); - } - else - { + } else { // it's an ip match = (srv_resolved == netaddress_resolve(argv(i), 26000)); } - if (!match) continue; + if (!match) { continue; } // on match: remove adding = false; string before = (i > 0) ? substring(s, 0, argv_end_index(i - 1)) : ""; @@ -252,8 +252,7 @@ METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string sr n = tokenize_console(s); --i; // offset the increment that is about to happen } - if (adding) - { + if (adding) { ret = strcat(s, (s != "" ? " " : ""), p ? p : srv); } cvar_set("net_slist_favorites", ret); @@ -263,13 +262,10 @@ METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string sr void ServerList_Update_favoriteButton(entity btn, entity me) { entity e = me.favoriteButton; - if(IsFavorite(me.ipAddressBox.text)) - { + if (IsFavorite(me.ipAddressBox.text)) { e.setText(e, _("Remove")); clearTooltip(e); - } - else - { + } else { e.setText(e, _("Favorite")); setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null); } @@ -287,7 +283,7 @@ void XonoticServerList_configureXonoticServerList(entity me) me.configureXonoticListBox(me); // update field ID's - #define SLIST_FIELD(suffix,name) SLIST_FIELD_##suffix = gethostcacheindexforkey(name); + #define SLIST_FIELD(suffix, name) SLIST_FIELD_##suffix = gethostcacheindexforkey(name); SLIST_FIELDS #undef SLIST_FIELD @@ -297,19 +293,21 @@ void XonoticServerList_configureXonoticServerList(entity me) void XonoticServerList_setSelected(entity me, int i) { me.lockedSelectedItem = false; - //int save = me.selectedItem; + // int save = me.selectedItem; SUPER(XonoticServerList).setSelected(me, i); /* if(me.selectedItem == save) - return; + return; */ - if(me.nItems == 0) + if (me.nItems == 0) { return; - if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems) + } + if (gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems) { return; // sorry, it would be wrong - - if(me.selectedServer) + } + if (me.selectedServer) { strunzone(me.selectedServer); + } me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer); @@ -318,10 +316,9 @@ void XonoticServerList_setSelected(entity me, int i) } void XonoticServerList_refreshServerList(entity me, int mode) { - //print("refresh of type ", ftos(mode), "\n"); + // print("refresh of type ", ftos(mode), "\n"); - if(mode >= REFRESHSERVERLIST_REFILTER) - { + if (mode >= REFRESHSERVERLIST_REFILTER) { float m; int i, n; int listflags = 0; @@ -330,15 +327,15 @@ void XonoticServerList_refreshServerList(entity me, int mode) s = me.filterString; m = strstrofs(s, ":", 0); - if(m >= 0) - { + if (m >= 0) { typestr = substring(s, 0, m); s = substring(s, m + 1, strlen(s) - m - 1); - while(substring(s, 0, 1) == " ") + while (substring(s, 0, 1) == " ") { s = substring(s, 1, strlen(s) - 1); - } - else + } + } else { typestr = ""; + } modstr = cvar_string("menu_slist_modfilter"); @@ -349,38 +346,40 @@ void XonoticServerList_refreshServerList(entity me, int mode) sethostcachemasknumber(++m, SLIST_FIELD_PING, 0, SLIST_TEST_GREATEREQUAL); // show full button - if(!me.filterShowFull) - { - sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy + if (!me.filterShowFull) { + sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, ":S0:", SLIST_TEST_NOTCONTAIN); // g_maxplayers support } // show empty button - if(!me.filterShowEmpty) + if (!me.filterShowEmpty) { sethostcachemasknumber(++m, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL); + } // gametype filtering - if(typestr != "") + if (typestr != "") { sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(typestr, ":"), SLIST_TEST_STARTSWITH); + } // mod filtering - if(modstr != "") - { - if(substring(modstr, 0, 1) == "!") + if (modstr != "") { + if (substring(modstr, 0, 1) == "!") { sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(substring(modstr, 1, strlen(modstr) - 1)), SLIST_TEST_NOTEQUAL); - else + } else { sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(modstr), SLIST_TEST_EQUAL); + } } // server banning n = tokenizebyseparator(_Nex_ExtResponseSystem_BannedServers, " "); - for(i = 0; i < n; ++i) - if(argv(i) != "") + for (i = 0; i < n; ++i) { + if (argv(i) != "") { sethostcachemaskstring(++m, SLIST_FIELD_CNAME, argv(i), SLIST_TEST_NOTSTARTSWITH); + } + } m = SLIST_MASK_OR - 1; - if(s != "") - { + if (s != "") { sethostcachemaskstring(++m, SLIST_FIELD_NAME, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_MAP, s, SLIST_TEST_CONTAINS); sethostcachemaskstring(++m, SLIST_FIELD_PLAYERS, s, SLIST_TEST_CONTAINS); @@ -388,22 +387,22 @@ void XonoticServerList_refreshServerList(entity me, int mode) } // sorting flags - //listflags |= SLSF_FAVORITES; + // listflags |= SLSF_FAVORITES; listflags |= SLSF_CATEGORIES; - if(me.currentSortOrder < 0) { listflags |= SLSF_DESCENDING; } + if (me.currentSortOrder < 0) { listflags |= SLSF_DESCENDING; } sethostcachesort(me.currentSortField, listflags); } resorthostcache(); - if(mode >= REFRESHSERVERLIST_ASK) + if (mode >= REFRESHSERVERLIST_ASK) { refreshhostcache(mode >= REFRESHSERVERLIST_RESET); + } } void XonoticServerList_focusEnter(entity me) { SUPER(XonoticServerList).focusEnter(me); - if(time < me.nextRefreshTime) - { - //print("sorry, no refresh yet\n"); + if (time < me.nextRefreshTime) { + // print("sorry, no refresh yet\n"); return; } me.nextRefreshTime = time + 10; @@ -415,64 +414,59 @@ void XonoticServerList_draw(entity me) int i; bool found = false, owned; - if(_Nex_ExtResponseSystem_BannedServersNeedsRefresh) - { - if(!me.needsRefresh) + if (_Nex_ExtResponseSystem_BannedServersNeedsRefresh) { + if (!me.needsRefresh) { me.needsRefresh = 2; + } _Nex_ExtResponseSystem_BannedServersNeedsRefresh = 0; } - if(_Nex_ExtResponseSystem_PromotedServersNeedsRefresh) - { - if(!me.needsRefresh) + if (_Nex_ExtResponseSystem_PromotedServersNeedsRefresh) { + if (!me.needsRefresh) { me.needsRefresh = 3; + } _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 0; } - if(_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh) - { - if(!me.needsRefresh) + if (_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh) { + if (!me.needsRefresh) { me.needsRefresh = 3; + } _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 0; } - if(me.currentSortField == -1) - { + if (me.currentSortField == -1) { me.setSortOrder(me, SLIST_FIELD_PING, +1); me.refreshServerList(me, REFRESHSERVERLIST_RESET); - } - else if(me.needsRefresh == 1) - { + } else if (me.needsRefresh == 1) { me.needsRefresh = 2; // delay by one frame to make sure "slist" has been executed - } - else if(me.needsRefresh == 2) - { + } else if (me.needsRefresh == 2) { me.needsRefresh = 0; me.refreshServerList(me, REFRESHSERVERLIST_REFILTER); - } - else if(me.needsRefresh == 3) - { + } else if (me.needsRefresh == 3) { me.needsRefresh = 0; me.refreshServerList(me, REFRESHSERVERLIST_RESORT); } owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != "")); - for(i = 0; i < category_draw_count; ++i) { category_name[i] = -1; category_item[i] = -1; } + for (i = 0; i < category_draw_count; ++i) { + category_name[i] = -1; + category_item[i] = -1; + } category_draw_count = 0; - if(autocvar_menu_slist_categories >= 0) // if less than 0, don't even draw a category heading for favorites - { + if (autocvar_menu_slist_categories >= 0) { // if less than 0, don't even draw a category heading for favorites float itemcount = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); me.nItems = itemcount; - //float visible = floor(me.scrollPos / me.itemHeight); + // float visible = floor(me.scrollPos / me.itemHeight); // ^ unfortunately no such optimization can be made-- we must process through the // entire list, otherwise there is no way to know which item is first in its category. // binary search method suggested by div float begin = 0; - for(int j = 1; j <= category_ent_count; ++j) { + for (int j = 1; j <= category_ent_count; ++j) { float first = begin; float last = (itemcount - 1); if (first > last) { @@ -494,11 +488,14 @@ void XonoticServerList_draw(entity me) // Starts at first. This breaks the loop // invariant in the binary search and thus has // to be handled separately. - if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != j) + if (gethostcachenumber(SLIST_FIELD_CATEGORY, first) != j) { error("Category mismatch I"); - if(first > 0) - if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == j) + } + if (first > 0) { + if (gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == j) { error("Category mismatch II"); + } + } category_name[category_draw_count] = j; category_item[category_draw_count] = first; ++category_draw_count; @@ -525,53 +522,48 @@ void XonoticServerList_draw(entity me) } } if (catl == j) { - if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != j) + if (gethostcachenumber(SLIST_FIELD_CATEGORY, last) != j) { error("Category mismatch III"); - if(last > 0) - if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == j) + } + if (last > 0) { + if (gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == j) { error("Category mismatch IV"); + } + } category_name[category_draw_count] = j; category_item[category_draw_count] = last; ++category_draw_count; begin = last + 1; // already scanned through these, skip 'em + } else { + begin = last; // already scanned through these, skip 'em } - else - begin = last; // already scanned through these, skip 'em } } - if(autocvar_menu_slist_categories_onlyifmultiple && (category_draw_count == 1)) - { + if (autocvar_menu_slist_categories_onlyifmultiple && (category_draw_count == 1)) { category_name[0] = -1; category_item[0] = -1; category_draw_count = 0; me.nItems = itemcount; } - } - else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); } + } else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); } me.connectButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); me.infoButton.disabled = ((me.nItems == 0) || !owned); me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); - if(me.lockedSelectedItem) - { - if(me.nItems > 0) - { - if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer) - { - if(me.selectedServer) + if (me.lockedSelectedItem) { + if (me.nItems > 0) { + if (gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer) { + if (me.selectedServer) { strunzone(me.selectedServer); + } me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } found = true; } - } - else if(me.selectedServer) - { - for(i = 0; i < me.nItems; ++i) - { - if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer) - { + } else if (me.selectedServer) { + for (i = 0; i < me.nItems; ++i) { + if (gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer) { // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i); me.selectedItem = i; found = true; @@ -579,33 +571,31 @@ void XonoticServerList_draw(entity me) } } } - if(!found) - { - if(me.nItems > 0) - { + if (!found) { + if (me.nItems > 0) { // selected server disappeared, select the last server (scrolling to it) - if(me.selectedItem >= me.nItems) + if (me.selectedItem >= me.nItems) { SUPER(XonoticServerList).setSelected(me, me.nItems - 1); - if(me.selectedServer) + } + if (me.selectedServer) { strunzone(me.selectedServer); + } me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } } - if(owned) - { - if(me.selectedServer != me.ipAddressBox.text) - { + if (owned) { + if (me.selectedServer != me.ipAddressBox.text) { me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer); me.ipAddressBox.cursorPos = strlen(me.selectedServer); me.ipAddressBoxFocused = -1; } } - if(me.ipAddressBoxFocused != me.ipAddressBox.focused) - { - if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0) + if (me.ipAddressBoxFocused != me.ipAddressBox.focused) { + if (me.ipAddressBox.focused || me.ipAddressBoxFocused < 0) { ServerList_Update_favoriteButton(NULL, me); + } me.ipAddressBoxFocused = me.ipAddressBox.focused; } @@ -631,23 +621,25 @@ void ServerList_TypeSort_Click(entity btn, entity me) { string s = me.filterString; int m = strstrofs(s, ":", 0); - if(m >= 0) - { + if (m >= 0) { s = substring(s, 0, m); - while(substring(s, m+1, 1) == " ") // skip spaces + while (substring(s, m + 1, 1) == " ") { // skip spaces ++m; - } - else + } + } else { s = ""; + } - Gametype first = NULL; FOREACH(Gametypes, !first, first = it; break); + Gametype first = NULL; + FOREACH(Gametypes, !first, first = it; + break); bool flag = false; FOREACH(Gametypes, s == MapInfo_Type_ToString(it), { // the type was found // choose the next one flag = true; s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1)); - if (s == "") s = MapInfo_Type_ToString(first); + if (s == "") { s = MapInfo_Type_ToString(first); } break; }); if (!flag) { @@ -656,22 +648,24 @@ void ServerList_TypeSort_Click(entity btn, entity me) s = MapInfo_Type_ToString(first); } - if(s != "") s = strcat(s, ":"); - s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1)); + if (s != "") { s = strcat(s, ":"); } + s = strcat(s, substring(me.filterString, m + 1, strlen(me.filterString) - m - 1)); me.controlledTextbox.setText(me.controlledTextbox, s); me.controlledTextbox.keyDown(me.controlledTextbox, K_END, 0, 0); me.controlledTextbox.keyUp(me.controlledTextbox, K_END, 0, 0); - //ServerList_Filter_Change(me.controlledTextbox, me); + // ServerList_Filter_Change(me.controlledTextbox, me); } void ServerList_Filter_Change(entity box, entity me) { - if(me.filterString) + if (me.filterString) { strunzone(me.filterString); - if(box.text != "") + } + if (box.text != "") { me.filterString = strzone(box.text); - else + } else { me.filterString = string_null; + } me.refreshServerList(me, REFRESHSERVERLIST_REFILTER); me.ipAddressBox.setText(me.ipAddressBox, ""); @@ -707,8 +701,9 @@ void ServerList_ShowFull_Click(entity box, entity me) } void XonoticServerList_setSortOrder(entity me, int fld, int direction) { - if(me.currentSortField == fld) + if (me.currentSortField == fld) { direction = -me.currentSortOrder; + } me.currentSortOrder = direction; me.currentSortField = fld; me.sortButton1.forcePressed = (fld == SLIST_FIELD_PING); @@ -717,8 +712,9 @@ void XonoticServerList_setSortOrder(entity me, int fld, int direction) me.sortButton4.forcePressed = 0; me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS); me.selectedItem = 0; - if(me.selectedServer) + if (me.selectedServer) { strunzone(me.selectedServer); + } me.selectedServer = string_null; me.refreshServerList(me, REFRESHSERVERLIST_REFILTER); } @@ -767,8 +763,7 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click); int f = me.currentSortField; - if(f >= 0) - { + if (f >= 0) { me.currentSortField = -1; me.setSortOrder(me, f, me.currentSortOrder); // force resetting the sort order } @@ -776,24 +771,25 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, void ServerList_Connect_Click(entity btn, entity me) { localcmd(sprintf("connect %s\n", - ((me.ipAddressBox.text != "") ? - me.ipAddressBox.text : me.selectedServer + ((me.ipAddressBox.text != "") + ? me.ipAddressBox.text : me.selectedServer ) - )); + )); } void ServerList_Favorite_Click(entity btn, entity this) { string addr = this.ipAddressBox.text; string ipstr = netaddress_resolve(addr, 26000); - if (ipstr == "") return; + if (ipstr == "") { return; } m_play_click_sound(MENU_SOUND_SELECT); this.toggleFavorite(this, addr); this.ipAddressBoxFocused = -1; } void ServerList_Info_Click(entity btn, entity me) { - if (me.nItems != 0) + if (me.nItems != 0) { main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem); + } vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size); vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size); @@ -815,25 +811,24 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is int freeslots = -1, sflags = -1, j, m; string s, typestr, versionstr, k, v, modname; - //printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems); + // printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems); vector oldscale = draw_scale; vector oldshift = draw_shift; -#define SET_YRANGE(start,end) \ +#define SET_YRANGE(start, end) \ draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \ draw_shift = boxToGlobal(eY * start, oldshift, oldscale); for (j = 0; j < category_draw_count; ++j) { // Matches exactly the headings with increased height. - if (i == category_item[j]) + if (i == category_item[j]) { break; + } } - if (j < category_draw_count) - { + if (j < category_draw_count) { entity catent = RetrieveCategoryEnt(category_name[j]); - if(catent) - { + if (catent) { SET_YRANGE( (me.categoriesHeight - 1) / (me.categoriesHeight + 1), me.categoriesHeight / (me.categoriesHeight + 1) @@ -857,10 +852,9 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is } } - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } @@ -868,35 +862,34 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is s = gethostcachestring(SLIST_FIELD_QCSTATUS, i); m = tokenizebyseparator(s, ":"); typestr = ""; - if(m >= 2) - { + if (m >= 2) { typestr = argv(0); versionstr = argv(1); } freeslots = -1; modname = ""; - for(j = 2; j < m; ++j) - { - if(argv(j) == "") + for (j = 2; j < m; ++j) { + if (argv(j) == "") { break; + } k = substring(argv(j), 0, 1); v = substring(argv(j), 1, -1); - if(k == "P") - { + if (k == "P") { pure = (stof(v) == 0); pure_available = true; - } - else if(k == "S") + } else if (k == "S") { freeslots = stof(v); - else if(k == "F") + } else if (k == "F") { sflags = stoi(v); - else if(k == "M") + } else if (k == "M") { modname = v; + } } #ifdef COMPAT_NO_MOD_IS_XONOTIC - if(modname == "") + if (modname == "") { modname = "Xonotic"; + } #endif string original_modname = modname; @@ -906,48 +899,50 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is SLIST_FIELD_MOD = gethostcacheindexforkey("mod"); s = gethostcachestring(SLIST_FIELD_MOD, i); if(s != "data") - if(modname == "xonotic") - modname = s; + if(modname == "xonotic") + modname = s; */ // list the mods here on which the pure server check actually works - if(modname != "xonotic") - if(modname != "instagib" || modname != "minstagib") - if(modname != "cts") - if(modname != "nix") - if(modname != "newtoys") - pure_available = false; - - if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0) + if (modname != "xonotic") { + if (modname != "instagib" || modname != "minstagib") { + if (modname != "cts") { + if (modname != "nix") { + if (modname != "newtoys") { + pure_available = false; + } + } + } + } + } + + if (gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0) { theAlpha = SKINALPHA_SERVERLIST_FULL; - else if(freeslots == 0) + } else if (freeslots == 0) { theAlpha = SKINALPHA_SERVERLIST_FULL; // g_maxplayers support - else if (!gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)) + } else if (!gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)) { theAlpha = SKINALPHA_SERVERLIST_EMPTY; - else + } else { theAlpha = 1; + } p = gethostcachenumber(SLIST_FIELD_PING, i); const int PING_LOW = 75; const int PING_MED = 200; const int PING_HIGH = 500; - if(p < PING_LOW) + if (p < PING_LOW) { theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (p / PING_LOW); - else if(p < PING_MED) + } else if (p < PING_MED) { theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((p - PING_LOW) / (PING_MED - PING_LOW)); - else if(p < PING_HIGH) - { + } else if (p < PING_HIGH) { theColor = SKINCOLOR_SERVERLIST_HIGHPING; theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((p - PING_MED) / (PING_HIGH - PING_MED)); - } - else - { + } else { theColor = eX; theAlpha *= SKINALPHA_SERVERLIST_HIGHPING; } - if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, i)) - { + if (gethostcachenumber(SLIST_FIELD_ISFAVORITE, i)) { theColor = theColor * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINCOLOR_SERVERLIST_FAVORITE * SKINALPHA_SERVERLIST_FAVORITE; theAlpha = theAlpha * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINALPHA_SERVERLIST_FAVORITE; } @@ -955,38 +950,35 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is s = gethostcachestring(SLIST_FIELD_CNAME, i); isv4 = isv6 = false; - if(substring(s, 0, 1) == "[") - { + if (substring(s, 0, 1) == "[") { isv6 = true; me.seenIPv6 += 1; - } - else if(IS_DIGIT(substring(s, 0, 1))) - { + } else if (IS_DIGIT(substring(s, 0, 1))) { isv4 = true; me.seenIPv4 += 1; } q = stof(substring(crypto_getencryptlevel(s), 0, 1)); - if((q <= 0 && cvar("crypto_aeslevel") >= 3) || (q >= 3 && cvar("crypto_aeslevel") <= 0)) - { + if ((q <= 0 && cvar("crypto_aeslevel") >= 3) || (q >= 3 && cvar("crypto_aeslevel") <= 0)) { theColor = SKINCOLOR_SERVERLIST_IMPOSSIBLE; theAlpha = SKINALPHA_SERVERLIST_IMPOSSIBLE; } - if(q == 1) - { - if(cvar("crypto_aeslevel") >= 2) + if (q == 1) { + if (cvar("crypto_aeslevel") >= 2) { q |= 4; + } } - if(q == 2) - { - if(cvar("crypto_aeslevel") >= 1) + if (q == 2) { + if (cvar("crypto_aeslevel") >= 1) { q |= 4; + } } - if(q == 3) + if (q == 3) { q = 5; - else if(q >= 3) + } else if (q >= 3) { q -= 2; + } // possible status: // 0: crypto off // 1: AES possible @@ -1007,60 +999,63 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is iconPos_y = (1 - iconSize.y) * 0.5; // IP - if(me.seenIPv4 && me.seenIPv6) - { - if(isv6) + if (me.seenIPv4 && me.seenIPv6) { + if (isv6) { draw_Picture(iconPos, "icon_ipv6", iconSize, '1 1 1', 1); - else if(isv4) + } else if (isv4) { draw_Picture(iconPos, "icon_ipv4", iconSize, '1 1 1', 1); + } } iconPos.x += iconSize.x; // AES - if(q > 0) + if (q > 0) { draw_Picture(iconPos, strcat("icon_aeslevel", ftos(q)), iconSize, '1 1 1', 1); + } iconPos.x += iconSize.x; // Mod - if(modname == "xonotic") - { + if (modname == "xonotic") { // Here, pure_available should always be set. If not, consider // it an impurity. - if(pure_available && pure) + if (pure_available && pure) { draw_Picture(iconPos, "icon_pure1", iconSize, '1 1 1', 1); - } - else - { + } + } else { string icon = strcat("icon_mod_", modname); - if(draw_PictureSize(icon) == '0 0 0') + if (draw_PictureSize(icon) == '0 0 0') { icon = "icon_mod_"; + } // In mods, pure_available not being present indicates // non-support of the feature. Just show the mod icon as is // then. - if(pure_available && !pure) + if (pure_available && !pure) { draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE); - else + } else { draw_Picture(iconPos, icon, iconSize, '1 1 1', 1); + } } iconPos.x += iconSize.x; // Stats - if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) + if (sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) { draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1); + } - if(isFocused && me.mouseOverIcons && !me.tooltip) - { + if (isFocused && me.mouseOverIcons && !me.tooltip) { string t = ""; - if(me.seenIPv4 && me.seenIPv6) + if (me.seenIPv4 && me.seenIPv6) { t = strcat(t, (isv6) ? "IPv6, " : "IPv4, "); + } t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", "); t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname))); - if(pure_available) + if (pure_available) { t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings"))); + } t = strcat(t, ", "); t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled"))); setZonedTooltip(me, t, string_null); @@ -1097,16 +1092,16 @@ void XonoticServerList_focusedItemChangeNotify(entity me) float XonoticServerList_mouseMove(entity me, vector pos) { - if(!SUPER(XonoticServerList).mouseMove(me, pos)) - { + if (!SUPER(XonoticServerList).mouseMove(me, pos)) { me.mouseOverIcons = false; clearTooltip(me); return 1; } me.mouseOverIcons = (pos_x <= me.columnIconsSize); - if(!me.mouseOverIcons) + if (!me.mouseOverIcons) { clearTooltip(me); + } return 1; } @@ -1117,38 +1112,31 @@ bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift) org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size); sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size); - if(scan == K_ENTER || scan == K_KP_ENTER) - { + if (scan == K_ENTER || scan == K_KP_ENTER) { ServerList_Connect_Click(NULL, me); return true; - } - else if(scan == K_MOUSE2 || scan == K_SPACE) - { - if(me.nItems != 0) - { + } else if (scan == K_MOUSE2 || scan == K_SPACE) { + if (me.nItems != 0) { m_play_click_sound(MENU_SOUND_OPEN); main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem); DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz); return true; } return false; - } - else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS) - { - if(me.nItems != 0) - { + } else if (scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS) { + if (me.nItems != 0) { me.toggleFavorite(me, me.selectedServer); me.ipAddressBoxFocused = -1; return true; } return false; - } - else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift)) + } else if (SUPER(XonoticServerList).keyDown(me, scan, ascii, shift)) { return true; - else if(!me.controlledTextbox) + } else if (!me.controlledTextbox) { return false; - else + } else { return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift); + } } float XonoticServerList_getTotalHeight(entity me) @@ -1164,10 +1152,12 @@ int XonoticServerList_getItemAtPos(entity me, float pos) for (i = category_draw_count - 1; i >= 0; --i) { int itemidx = category_item[i]; float itempos = i * me.categoriesHeight + category_item[i]; - if (pos >= itempos + me.categoriesHeight + 1) + if (pos >= itempos + me.categoriesHeight + 1) { return itemidx + 1 + floor(pos - (itempos + me.categoriesHeight + 1)); - if (pos >= itempos) + } + if (pos >= itempos) { return itemidx; + } } // No category matches? Note that category 0 is... 0. Therefore no headings exist at all. return floor(pos); @@ -1178,10 +1168,12 @@ float XonoticServerList_getItemStart(entity me, int item) for (i = category_draw_count - 1; i >= 0; --i) { int itemidx = category_item[i]; float itempos = i * me.categoriesHeight + category_item[i]; - if (item >= itemidx + 1) + if (item >= itemidx + 1) { return (itempos + me.categoriesHeight + 1 + item - (itemidx + 1)) * me.itemHeight; - if (item >= itemidx) + } + if (item >= itemidx) { return itempos * me.itemHeight; + } } // No category matches? Note that category 0 is... 0. Therefore no headings exist at all. return item * me.itemHeight; @@ -1191,8 +1183,9 @@ float XonoticServerList_getItemHeight(entity me, int item) int i; for (i = 0; i < category_draw_count; ++i) { // Matches exactly the headings with increased height. - if (item == category_item[i]) + if (item == category_item[i]) { return me.itemHeight * (me.categoriesHeight + 1); + } } return me.itemHeight; } diff --git a/qcsrc/menu/xonotic/serverlist.qh b/qcsrc/menu/xonotic/serverlist.qh index e45abfda3..71e565efc 100644 --- a/qcsrc/menu/xonotic/serverlist.qh +++ b/qcsrc/menu/xonotic/serverlist.qh @@ -30,9 +30,9 @@ CLASS(XonoticServerList, XonoticListBox) ATTRIB(XonoticServerList, columnTypeSize, float, 0); ATTRIB(XonoticServerList, columnPlayersOrigin, float, 0); ATTRIB(XonoticServerList, columnPlayersSize, float, 0); - ATTRIB(XonoticServerList, lockedSelectedItem, bool, true); // initially keep selected the first item of the list, avoiding an unwanted scrolling + ATTRIB(XonoticServerList, lockedSelectedItem, bool, true); // initially keep selected the first item of the list, avoiding an unwanted scrolling - ATTRIB(XonoticServerList, selectedServer, string); // to restore selected server when needed + ATTRIB(XonoticServerList, selectedServer, string); // to restore selected server when needed METHOD(XonoticServerList, setSelected, void(entity, float)); METHOD(XonoticServerList, setSortOrder, void(entity, float, float)); ATTRIB(XonoticServerList, filterShowEmpty, float, 1); @@ -42,7 +42,7 @@ CLASS(XonoticServerList, XonoticListBox) ATTRIB(XonoticServerList, ipAddressBox, entity); ATTRIB(XonoticServerList, favoriteButton, entity); ATTRIB(XonoticServerList, nextRefreshTime, float, 0); - METHOD(XonoticServerList, refreshServerList, void(entity, float)); // refresh mode: REFRESHSERVERLIST_* + METHOD(XonoticServerList, refreshServerList, void(entity, float)); // refresh mode: REFRESHSERVERLIST_* ATTRIB(XonoticServerList, needsRefresh, float, 1); METHOD(XonoticServerList, focusEnter, void(entity)); METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity))); @@ -99,7 +99,7 @@ void ServerList_Info_Click(entity btn, entity me); SLIST_FIELD(CATEGORY, "category") \ SLIST_FIELD(ISFAVORITE, "isfavorite") -#define SLIST_FIELD(suffix,name) float SLIST_FIELD_##suffix; +#define SLIST_FIELD(suffix, name) float SLIST_FIELD_##suffix; SLIST_FIELDS #undef SLIST_FIELD @@ -113,10 +113,10 @@ float autocvar_menu_slist_recommendations_minfreeslots; float autocvar_menu_slist_recommendations_minhumans; float autocvar_menu_slist_recommendations_purethreshold; -const float REFRESHSERVERLIST_RESORT = 0; // sort the server list again to update for changes to e.g. favorite status, categories -const float REFRESHSERVERLIST_REFILTER = 1; // ..., also update filter and sort criteria -const float REFRESHSERVERLIST_ASK = 2; // ..., also suggest querying servers now -const float REFRESHSERVERLIST_RESET = 3; // ..., also clear the list first +const float REFRESHSERVERLIST_RESORT = 0; // sort the server list again to update for changes to e.g. favorite status, categories +const float REFRESHSERVERLIST_REFILTER = 1; // ..., also update filter and sort criteria +const float REFRESHSERVERLIST_ASK = 2; // ..., also suggest querying servers now +const float REFRESHSERVERLIST_RESET = 3; // ..., also clear the list first // function declarations float IsServerInList(string list, string srv); @@ -159,7 +159,7 @@ int category_draw_count; SLIST_CATEGORY(CAT_DEFRAG, "", "CAT_SERVERS", CTX(_("SLCAT^Defrag Mode"))) #define SLIST_CATEGORY_AUTOCVAR(name) autocvar_menu_slist_categories_##name##_override -#define SLIST_CATEGORY(name,enoverride,dioverride,str) \ +#define SLIST_CATEGORY(name, enoverride, dioverride, str) \ int name; \ string SLIST_CATEGORY_AUTOCVAR(name) = enoverride; SLIST_CATEGORIES diff --git a/qcsrc/menu/xonotic/skinlist.qc b/qcsrc/menu/xonotic/skinlist.qc index e72ca12e2..862de304e 100644 --- a/qcsrc/menu/xonotic/skinlist.qc +++ b/qcsrc/menu/xonotic/skinlist.qc @@ -27,10 +27,8 @@ void XonoticSkinList_loadCvars(entity me) float i, n; s = cvar_string("menu_skin"); n = me.nItems; - for(i = 0; i < n; ++i) - { - if(me.skinParameter(me, i, SKINPARM_NAME) == s) - { + for (i = 0; i < n; ++i) { + if (me.skinParameter(me, i, SKINPARM_NAME) == s) { me.setSelected(me, i); break; } @@ -54,43 +52,40 @@ void XonoticSkinList_getSkins(entity me) buf = buf_create(); glob = search_begin("gfx/menu/*/skinvalues.txt", true, true); - if(glob < 0) - { + if (glob < 0) { me.skinlist = buf; me.nItems = 0; return; } n = search_getsize(glob); - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { s = search_getfilename(glob, i); name = substring(s, 9, strlen(s) - 24); // the * part bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_NAME, name); bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, _("")); bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, _("<AUTHOR>")); - if(draw_PictureSize(strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview")) == '0 0 0') + if (draw_PictureSize(strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview")) == '0 0 0') { bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, "nopreview_menuskin"); - else + } else { bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview")); + } fh = fopen(s, FILE_READ); - if(fh < 0) - { + if (fh < 0) { LOG_INFO("Warning: can't open skinvalues.txt file"); continue; } - while((s = fgets(fh))) - { + while ((s = fgets(fh))) { // these two are handled by skinlist.qc - if(substring(s, 0, 6) == "title ") - { - if (name == cvar_defstring("menu_skin")) + if (substring(s, 0, 6) == "title ") { + if (name == cvar_defstring("menu_skin")) { bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, strcat(substring(s, 6, strlen(s) - 6), " (", _("Default"), ")")); - else + } else { bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, substring(s, 6, strlen(s) - 6)); - } - else if(substring(s, 0, 7) == "author ") + } + } else if (substring(s, 0, 7) == "author ") { bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, substring(s, 7, strlen(s) - 7)); + } } fclose(fh); } @@ -126,10 +121,9 @@ void XonoticSkinList_drawListBoxItem(entity me, int i, vector absSize, bool isSe { string s; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } @@ -165,12 +159,11 @@ void XonoticSkinList_doubleClickListBoxItem(entity me, float i, vector where) float XonoticSkinList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER) - { + if (scan == K_ENTER || scan == K_KP_ENTER) { m_play_click_sound(MENU_SOUND_EXECUTE); me.setSkin(me); return 1; - } - else + } else { return SUPER(XonoticSkinList).keyDown(me, scan, ascii, shift); + } } diff --git a/qcsrc/menu/xonotic/slider.qc b/qcsrc/menu/xonotic/slider.qc index c8e057a64..e369291db 100644 --- a/qcsrc/menu/xonotic/slider.qc +++ b/qcsrc/menu/xonotic/slider.qc @@ -15,48 +15,50 @@ void XonoticSlider_configureXonoticSlider(entity me, float theValueMin, float th { float vp; vp = theValueStep * 10; - while(fabs(vp) < fabs(theValueMax - theValueMin) / 40) + while (fabs(vp) < fabs(theValueMax - theValueMin) / 40) { vp *= 10; + } me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image); me.cvarName = (theCvar) ? theCvar : string_null; - if(theCvar) + if (theCvar) { // Prevent flickering of the slider button by initialising the // slider out of bounds to hide the button before loading the cvar - me.configureSliderValues(me, theValueMin, theValueMin-theValueStep, theValueMax, theValueStep, theValueStep, vp); - else + me.configureSliderValues(me, theValueMin, theValueMin - theValueStep, theValueMax, theValueStep, theValueStep, vp); + } else { me.configureSliderValues(me, theValueMin, theValueMin, theValueMax, theValueStep, theValueStep, vp); + } me.loadCvars(me); setZonedTooltip(me, theTooltip, theCvar); } void XonoticSlider_setValue(entity me, float val) { - if(val != me.value) - { - SUPER(XonoticSlider).setValue( me, val ); + if (val != me.value) { + SUPER(XonoticSlider).setValue(me, val); me.saveCvars(me); } } void XonoticSlider_setValue_noAnim(entity me, float val) { - if(val != me.value) - { + if (val != me.value) { SUPER(XonoticSlider).setValue_noAnim(me, val); me.saveCvars(me); } } void XonoticSlider_loadCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } me.setValue_noAnim(me, cvar(me.cvarName)); } void XonoticSlider_saveCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } cvar_set(me.cvarName, ftos_mindecimals(me.value)); diff --git a/qcsrc/menu/xonotic/slider_decibels.qc b/qcsrc/menu/xonotic/slider_decibels.qc index e26076b65..b778b1a21 100644 --- a/qcsrc/menu/xonotic/slider_decibels.qc +++ b/qcsrc/menu/xonotic/slider_decibels.qc @@ -3,13 +3,13 @@ float toDecibelOfSquare(float f, float mi) { float A = log(10) / 20; // note: about 0.115; inverse: about 8.686 - if(mi != 0) - { + if (mi != 0) { // linear scale part float t = 1 / A + mi; float u = exp(1 + A * mi); - if(f <= u) + if (f <= u) { return mi + (t - mi) * (f / u); + } } return log(f) / A; } @@ -17,13 +17,13 @@ float toDecibelOfSquare(float f, float mi) float fromDecibelOfSquare(float f, float mi) { float A = log(10) / 20; // note: about 0.115; inverse: about 8.686 - if(mi != 0) - { + if (mi != 0) { // linear scale part float t = 1 / A + mi; float u = exp(1 + A * mi); - if(f <= t) + if (f <= t) { return u * ((f - mi) / (t - mi)); + } } return exp(A * f); } @@ -43,51 +43,55 @@ void XonoticDecibelsSlider_loadCvars(entity me) { float v; - if (!me.cvarName) + if (!me.cvarName) { return; + } v = cvar(me.cvarName); // snapping - if(v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep, me.valueMin)) + if (v > fromDecibelOfSquare(me.valueMax - 0.5 * me.valueStep, me.valueMin)) { Slider_setValue_noAnim(me, me.valueMax); - else + } else { Slider_setValue_noAnim(me, me.valueStep * floor(0.5 + toDecibelOfSquare(v, me.valueMin) / me.valueStep)); + } } void XonoticDecibelsSlider_saveCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } - if(me.value > me.valueMax - 0.5 * me.valueStep) + if (me.value > me.valueMax - 0.5 * me.valueStep) { cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.valueMax, me.valueMin))); - else + } else { cvar_set(me.cvarName, ftos(fromDecibelOfSquare(me.value, me.valueMin))); + } } float autocvar_menu_snd_sliderscale; string XonoticDecibelsSlider_valueToText(entity me, float v) { - if(v > me.valueMax - 0.5 * me.valueStep) + if (v > me.valueMax - 0.5 * me.valueStep) { return CTX(_("VOL^MAX")); - else if(v <= me.valueMin) + } else if (v <= me.valueMin) { return CTX(_("VOL^OFF")); - else if(autocvar_menu_snd_sliderscale == 3) // fake percent scale + } else if (autocvar_menu_snd_sliderscale == 3) { // fake percent scale return sprintf("%d %%", (v - me.valueMin) / (me.valueMax - me.valueMin) * 100); - else if(autocvar_menu_snd_sliderscale == 2) // 0..10 scale + } else if (autocvar_menu_snd_sliderscale == 2) { // 0..10 scale return sprintf("%.1f", (v - me.valueMin) / (me.valueMax - me.valueMin) * 10); - else if(autocvar_menu_snd_sliderscale == 1) // real percent scale + } else if (autocvar_menu_snd_sliderscale == 1) { // real percent scale return sprintf("%.2f %%", fromDecibelOfSquare(v, me.valueMin) * 100); - else // decibel scale + } else { // decibel scale return sprintf(_("%s dB"), ftos_decimals(toDecibelOfSquare(fromDecibelOfSquare(v, me.valueMin), 0), me.valueDigits)); + } } bool autocvar_test_XonoticDecibelsSlider = false; TEST(XonoticDecibelsSlider, SoundTest) { if (!autocvar_test_XonoticDecibelsSlider) { SUCCEED(); return; } - for (int i = -400; i < 0; ++i) - { + for (int i = -400; i < 0; ++i) { float db = i * 0.1; float v = fromDecibelOfSquare(db, -40); float dbv = toDecibelOfSquare(v, -40); diff --git a/qcsrc/menu/xonotic/slider_particles.qc b/qcsrc/menu/xonotic/slider_particles.qc index 3a89b00a7..16e9e661b 100644 --- a/qcsrc/menu/xonotic/slider_particles.qc +++ b/qcsrc/menu/xonotic/slider_particles.qc @@ -11,13 +11,13 @@ void XonoticParticlesSlider_configureXonoticParticlesSlider(entity me) { me.configureXonoticTextSlider(me, "cl_particles_quality", _("Multiplier for amount of particles. Less means less particles, which in turn gives for better performance (default: 1)")); - if(cvar("developer")) { me.addValue(me, ZCTX(_("PART^OMG")), "0.25 250 0"); } + if (cvar("developer")) { me.addValue(me, ZCTX(_("PART^OMG")), "0.25 250 0"); } me.addValue(me, ZCTX(_("PART^Low")), "0.5 500 0"); me.addValue(me, ZCTX(_("PART^Medium")), "0.75 750 0"); me.addValue(me, ZCTX(_("PART^Normal")), "1.0 1000 1"); me.addValue(me, ZCTX(_("PART^High")), "1.5 1500 1"); me.addValue(me, ZCTX(_("PART^Ultra")), "2.0 2000 2"); - if(cvar("developer")) { me.addValue(me, ZCTX(_("PART^Ultimate")), "3.0 3000 2"); } + if (cvar("developer")) { me.addValue(me, ZCTX(_("PART^Ultimate")), "3.0 3000 2"); } me.configureXonoticTextSliderValues(me); } void XonoticParticlesSlider_loadCvars(entity me) @@ -26,12 +26,11 @@ void XonoticParticlesSlider_loadCvars(entity me) cvar_string("cl_particles_quality"), cvar_string("r_drawparticles_drawdistance"), cvar_string("cl_damageeffect") - )); + )); } void XonoticParticlesSlider_saveCvars(entity me) { - if(me.value >= 0 || me.value < me.nValues) - { + if (me.value >= 0 || me.value < me.nValues) { tokenize_console(me.getIdentifier(me)); cvar_set("cl_particles_quality", argv(0)); cvar_set("r_drawparticles_drawdistance", argv(1)); diff --git a/qcsrc/menu/xonotic/slider_picmip.qc b/qcsrc/menu/xonotic/slider_picmip.qc index 561107933..024d766e9 100644 --- a/qcsrc/menu/xonotic/slider_picmip.qc +++ b/qcsrc/menu/xonotic/slider_picmip.qc @@ -16,23 +16,23 @@ void XonoticPicmipSlider_configureXonoticPicmipSlider(entity me) } float texmemsize(float s3tc) { - return - ( - 2500 * POW(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_other"))) + return ( + 2500 * POW(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_other"))) + 1500 * POW(0.25, max(0, cvar("gl_picmip") + cvar("gl_picmip_world"))) ) * ((s3tc && (cvar("r_texture_dds_load") || cvar("gl_texturecompression"))) ? 0.2 : 1.0); // TC: normalmaps 50%, other 25%, few incompressible, guessing 40% as conservative average } void XonoticPicmipSlider_autofix(entity me) { float max_hard, max_soft; - if(cvar("menu_picmip_bypass")) + if (cvar("menu_picmip_bypass")) { return; + } max_hard = cvar("sys_memsize_virtual"); max_soft = cvar("sys_memsize_physical"); - if(max_hard > 0) - { - while(me.value > 0 && texmemsize(me.have_s3tc) > max_hard) + if (max_hard > 0) { + while (me.value > 0 && texmemsize(me.have_s3tc) > max_hard) { me.setValue(me, me.value - 1); + } } // TODO also check the soft limit! // TODO better handling than clamping the slider! diff --git a/qcsrc/menu/xonotic/slider_picmip.qh b/qcsrc/menu/xonotic/slider_picmip.qh index 3661fd493..99574a4f9 100644 --- a/qcsrc/menu/xonotic/slider_picmip.qh +++ b/qcsrc/menu/xonotic/slider_picmip.qh @@ -7,4 +7,4 @@ CLASS(XonoticPicmipSlider, XonoticTextSlider) METHOD(XonoticPicmipSlider, autofix, void(entity)); ATTRIB(XonoticPicmipSlider, have_s3tc, float, 0); ENDCLASS(XonoticPicmipSlider) -entity makeXonoticPicmipSlider(); // note: you still need to call addValue and configureXonoticTextSliderValues! +entity makeXonoticPicmipSlider(); // note: you still need to call addValue and configureXonoticTextSliderValues! diff --git a/qcsrc/menu/xonotic/slider_resolution.qc b/qcsrc/menu/xonotic/slider_resolution.qc index 9a55f8840..1517b5eb4 100644 --- a/qcsrc/menu/xonotic/slider_resolution.qc +++ b/qcsrc/menu/xonotic/slider_resolution.qc @@ -10,9 +10,9 @@ float updateConwidths(float width, float height, float pixelheight) float sz, f; sz = cvar("menu_vid_scale"); - if (sz < -1) - return 0; // No recalculation. - + if (sz < -1) { + return 0; // No recalculation. + } // Save off current settings. cvar_set("_menu_vid_width", ftos(width)); cvar_set("_menu_vid_height", ftos(height)); @@ -27,27 +27,27 @@ float updateConwidths(float width, float height, float pixelheight) c_z = 0; c_x = 800; c_y = c.x * r.y * r.z / r.x; - if(c.y < 600) - { + if (c.y < 600) { c_y = 600; c_x = c.y * r.x / (r.y * r.z); } f = min(r.x / c.x, r.y / c.y); - if(f < 1) - c = c * f; // ensures that c_x <= r_x and c_y <= r_y - + if (f < 1) { + c = c * f; // ensures that c_x <= r_x and c_y <= r_y + } minfactor = min(1, 640 / c.x); // can be > 1 only if c_x is <640 maxfactor = max(1, r.x / c.x, r.y / c.y); // can be < 1 only if r_x < c_x and r_y < c_y LOG_TRACE("min factor: ", ftos(minfactor)); LOG_TRACE("max factor: ", ftos(maxfactor)); - if(sz < 0) + if (sz < 0) { f = 1 - (maxfactor - 1) * sz; - else if(sz > 0) + } else if (sz > 0) { f = 1 + (minfactor - 1) * sz; - else + } else { f = 1; + } c = c * f; // fteqcc fail c_x = rint(c.x); @@ -56,8 +56,7 @@ float updateConwidths(float width, float height, float pixelheight) // Please reload resolutions list and such stuff. XonoticResolutionSlider_DataHasChanged = true; - if (c.x != cvar("vid_conwidth") || c.y != cvar("vid_conheight")) - { + if (c.x != cvar("vid_conwidth") || c.y != cvar("vid_conheight")) { cvar_set("vid_conwidth", ftos(c.x)); cvar_set("vid_conheight", ftos(c.y)); return 1; @@ -73,40 +72,39 @@ entity makeXonoticResolutionSlider() } void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight) { - if (me.maxAllowedWidth && w > me.maxAllowedWidth) + if (me.maxAllowedWidth && w > me.maxAllowedWidth) { return; - if (me.maxAllowedHeight && h > me.maxAllowedHeight) + } + if (me.maxAllowedHeight && h > me.maxAllowedHeight) { return; + } float i; - for (i = 0; i < me.nValues; ++i) - { + for (i = 0; i < me.nValues; ++i) { tokenize_console(me.valueToIdentifier(me, i)); - if (w > stof(argv(0))) continue; - if (w < stof(argv(0))) break; - if (h > stof(argv(1))) continue; - if (h < stof(argv(1))) break; - if (pixelheight > stof(argv(2)) + 0.01) continue; - if (pixelheight < stof(argv(2)) - 0.01) break; - return; // already there + if (w > stof(argv(0))) { continue; } + if (w < stof(argv(0))) { break; } + if (h > stof(argv(1))) { continue; } + if (h < stof(argv(1))) { break; } + if (pixelheight > stof(argv(2)) + 0.01) { continue; } + if (pixelheight < stof(argv(2)) - 0.01) { break; } + return; // already there } - if (pixelheight != 1) - { + if (pixelheight != 1) { float aspect = w / (h * pixelheight); float bestdenom = rint(aspect); float bestnum = 1; float denom; for (denom = 2; denom < 10; ++denom) { float num = rint(aspect * denom); - if (fabs(num / denom - aspect) < fabs(bestnum / bestdenom - aspect)) - { + if (fabs(num / denom - aspect) < fabs(bestnum / bestdenom - aspect)) { bestnum = num; bestdenom = denom; } } me.insertValue(me, i, strzone(sprintf("%dx%d (%d:%d)", w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); - } - else + } else { me.insertValue(me, i, strzone(sprintf("%dx%d", w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); + } } float autocvar_menu_vid_allowdualscreenresolution; void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me) @@ -122,8 +120,7 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen) // HACK: text slider assumes the strings are constants, so clearValues // will not unzone them - for(i = 0; i < me.nValues; ++i) - { + for (i = 0; i < me.nValues; ++i) { strunzone(me.valueToIdentifier(me, i)); strunzone(me.valueToText(me, i)); } @@ -132,58 +129,60 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen) me.maxAllowedWidth = 0; me.maxAllowedHeight = 0; - if (fullscreen) - { - for(i = 0;; ++i) - { + if (fullscreen) { + for (i = 0; ; ++i) { r = getresolution(i); - if(r_x == 0 && r_y == 0) + if (r_x == 0 && r_y == 0) { break; - if(r.x < 640 || r.y < 480) + } + if (r.x < 640 || r.y < 480) { continue; - if(r.x > 2 * r.y) // likely dualscreen resolution, skip this one - if(autocvar_menu_vid_allowdualscreenresolution <= 0) + } + if (r.x > 2 * r.y) { // likely dualscreen resolution, skip this one + if (autocvar_menu_vid_allowdualscreenresolution <= 0) { continue; + } + } me.addResolution(me, r.x, r.y, r.z); } r = getresolution(-1); - if(r.x != 0 || r.y != 0) + if (r.x != 0 || r.y != 0) { me.addResolution(me, r.x, r.y, r.z); + } LOG_TRACE("Added system resolutions."); } - if(me.nValues == 0) - { + if (me.nValues == 0) { // Get workarea. r = getresolution(-2); // If workarea is not supported, get desktop size. - if(r.x == 0 && r.y == 0) + if (r.x == 0 && r.y == 0) { r = getresolution(-1); + } // Add it, and limit all other resolutions to the workarea/desktop size. - if(r.x != 0 || r.y != 0) - { + if (r.x != 0 || r.y != 0) { me.maxAllowedWidth = r.x; me.maxAllowedHeight = r.y; me.addResolution(me, r.x, r.y, r.z); } // Add nice hardcoded defaults. - me.addResolution(me, 640, 480, 1); // pc res + me.addResolution(me, 640, 480, 1); // pc res #if 0 - me.addResolution(me, 720, 480, 1.125); // DVD NTSC 4:3 - me.addResolution(me, 720, 576, 0.9375); // DVD PAL 4:3 - me.addResolution(me, 720, 480, 0.84375); // DVD NTSC 16:9 + me.addResolution(me, 720, 480, 1.125); // DVD NTSC 4:3 + me.addResolution(me, 720, 576, 0.9375); // DVD PAL 4:3 + me.addResolution(me, 720, 480, 0.84375); // DVD NTSC 16:9 me.addResolution(me, 720, 576, 0.703125); // DVD PAL 16:9 #endif - me.addResolution(me, 800, 480, 1); // 480p at 1:1 pixel aspect - me.addResolution(me, 800, 600, 1); // pc res - me.addResolution(me, 1024, 600, 1); // notebook res - me.addResolution(me, 1024, 768, 1); // pc res - me.addResolution(me, 1280, 720, 1); // 720p - me.addResolution(me, 1280, 960, 1); // pc res - me.addResolution(me, 1280, 1024, 1); // pc res - me.addResolution(me, 1920, 1080, 1); // 1080p + me.addResolution(me, 800, 480, 1); // 480p at 1:1 pixel aspect + me.addResolution(me, 800, 600, 1); // pc res + me.addResolution(me, 1024, 600, 1); // notebook res + me.addResolution(me, 1024, 768, 1); // pc res + me.addResolution(me, 1280, 720, 1); // 720p + me.addResolution(me, 1280, 960, 1); // pc res + me.addResolution(me, 1280, 1024, 1); // pc res + me.addResolution(me, 1920, 1080, 1); // 1080p LOG_TRACE("Added default resolutions."); } LOG_TRACE("Total number of resolutions detected: ", ftos(me.nValues)); @@ -198,28 +197,26 @@ void XonoticResolutionSlider_loadCvars(entity me) } void XonoticResolutionSlider_saveCvars(entity me) { - if(me.value >= 0 || me.value < me.nValues) - { + if (me.value >= 0 || me.value < me.nValues) { tokenize_console(me.getIdentifier(me)); cvar_set("_menu_vid_width", argv(0)); cvar_set("_menu_vid_height", argv(1)); cvar_set("_menu_vid_pixelheight", argv(2)); vector r = getresolution(-1); - if (stof(argv(0)) == r.x && stof(argv(1)) == r.y && fabs(stof(argv(2)) - r.z) < 0.01) + if (stof(argv(0)) == r.x && stof(argv(1)) == r.y && fabs(stof(argv(2)) - r.z) < 0.01) { cvar_set("_menu_vid_desktopfullscreen", "1"); - else + } else { cvar_set("_menu_vid_desktopfullscreen", "0"); + } } } void XonoticResolutionSlider_draw(entity me) { - if (cvar("vid_fullscreen") != me.vid_fullscreen) - { + if (cvar("vid_fullscreen") != me.vid_fullscreen) { me.loadResolutions(me, cvar("vid_fullscreen")); XonoticResolutionSlider_DataHasChanged = true; } - if (XonoticResolutionSlider_DataHasChanged) - { + if (XonoticResolutionSlider_DataHasChanged) { XonoticResolutionSlider_DataHasChanged = false; me.loadCvars(me); } diff --git a/qcsrc/menu/xonotic/slider_sbfadetime.qc b/qcsrc/menu/xonotic/slider_sbfadetime.qc index 048a42184..5a10eccd2 100644 --- a/qcsrc/menu/xonotic/slider_sbfadetime.qc +++ b/qcsrc/menu/xonotic/slider_sbfadetime.qc @@ -21,12 +21,11 @@ void XonoticScoreboardFadeTimeSlider_loadCvars(entity me) me.setValueFromIdentifier_noAnim(me, sprintf("%s %s", cvar_string("hud_panel_scoreboard_fadeinspeed"), cvar_string("hud_panel_scoreboard_fadeoutspeed") - )); + )); } void XonoticScoreboardFadeTimeSlider_saveCvars(entity me) { - if(me.value >= 0 || me.value < me.nValues) - { + if (me.value >= 0 || me.value < me.nValues) { tokenize_console(me.getIdentifier(me)); cvar_set("hud_panel_scoreboard_fadeinspeed", argv(0)); cvar_set("hud_panel_scoreboard_fadeoutspeed", argv(1)); diff --git a/qcsrc/menu/xonotic/soundlist.qc b/qcsrc/menu/xonotic/soundlist.qc index 13e6ba34c..e2af7c441 100644 --- a/qcsrc/menu/xonotic/soundlist.qc +++ b/qcsrc/menu/xonotic/soundlist.qc @@ -21,7 +21,7 @@ string XonoticSoundList_soundName(entity me, int i) { string s; s = search_getfilename(me.listSound, i); - s = substring(s, 15, strlen(s) - 15 - 4); // sound/cdtracks/, .ogg + s = substring(s, 15, strlen(s) - 15 - 4); // sound/cdtracks/, .ogg return s; } @@ -30,14 +30,16 @@ void XonoticSoundList_getSounds(entity me) { string s; - if(me.filterString) - //subdirectory in filterString allowed + if (me.filterString) { + // subdirectory in filterString allowed s = strcat("sound/cdtracks/*", me.filterString, "*.ogg"); - else + } else { s = "sound/cdtracks/*.ogg"; + } - if(me.listSound >= 0) + if (me.listSound >= 0) { search_end(me.listSound); + } me.listSound = search_begin(s, false, true); @@ -46,8 +48,9 @@ void XonoticSoundList_getSounds(entity me) void XonoticSoundList_destroy(entity me) { - if(me.listSound >= 0) + if (me.listSound >= 0) { search_end(me.listSound); + } } void XonoticSoundList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) @@ -69,19 +72,19 @@ void XonoticSoundList_resizeNotify(entity me, vector relOrigin, vector relSize, void XonoticSoundList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { string s; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } s = me.soundName(me, i); - if(s == cvar_string("menu_cdtrack")) // current menu track + if (s == cvar_string("menu_cdtrack")) { // current menu track draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[C]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); - else if(s == cvar_defstring("menu_cdtrack")) // default menu track + } else if (s == cvar_defstring("menu_cdtrack")) { // default menu track draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[D]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); + } s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0); @@ -104,13 +107,15 @@ void SoundList_Menu_Track_Reset(entity box, entity me) void SoundList_Filter_Change(entity box, entity me) { - if(me.filterString) + if (me.filterString) { strunzone(me.filterString); + } - if(box.text != "") + if (box.text != "") { me.filterString = strzone(box.text); - else + } else { me.filterString = string_null; + } me.getSounds(me); } @@ -123,8 +128,9 @@ void SoundList_Add(entity box, entity me) void SoundList_Add_All(entity box, entity me) { int i; - for(i = 0; i < me.nItems; ++i) + for (i = 0; i < me.nItems; ++i) { me.playlist.addToPlayList(me.playlist, me.soundName(me, i)); + } } void XonoticSoundList_doubleClickListBoxItem(entity me, int i, vector where) @@ -134,10 +140,10 @@ void XonoticSoundList_doubleClickListBoxItem(entity me, int i, vector where) float XonoticSoundList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_SPACE) { + if (scan == K_ENTER || scan == K_KP_ENTER || scan == K_SPACE) { me.playlist.addToPlayList(me.playlist, me.soundName(me, me.selectedItem)); return 1; - } - else + } else { return SUPER(XonoticSoundList).keyDown(me, scan, ascii, shift); + } } diff --git a/qcsrc/menu/xonotic/statslist.qc b/qcsrc/menu/xonotic/statslist.qc index 3e94738a9..9fa441206 100644 --- a/qcsrc/menu/xonotic/statslist.qc +++ b/qcsrc/menu/xonotic/statslist.qc @@ -19,25 +19,37 @@ string XonoticStatsList_convertDate(string input) { // 2013-12-21 // 0123456789 - if(strlen(input) != 10) + if (strlen(input) != 10) { return input; + } string monthname = ""; - switch(stof(substring(input, 5, 2))) - { - case 1: monthname = _("January"); break; - case 2: monthname = _("February"); break; - case 3: monthname = _("March"); break; - case 4: monthname = _("April"); break; - case 5: monthname = _("May"); break; - case 6: monthname = _("June"); break; - case 7: monthname = _("July"); break; - case 8: monthname = _("August"); break; - case 9: monthname = _("September"); break; - case 10: monthname = _("October"); break; - case 11: monthname = _("November"); break; - case 12: monthname = _("December"); break; + switch (stof(substring(input, 5, 2))) { + case 1: monthname = _("January"); + break; + case 2: monthname = _("February"); + break; + case 3: monthname = _("March"); + break; + case 4: monthname = _("April"); + break; + case 5: monthname = _("May"); + break; + case 6: monthname = _("June"); + break; + case 7: monthname = _("July"); + break; + case 8: monthname = _("August"); + break; + case 9: monthname = _("September"); + break; + case 10: monthname = _("October"); + break; + case 11: monthname = _("November"); + break; + case 12: monthname = _("December"); + break; default: return input; // failed, why? } @@ -53,16 +65,17 @@ void XonoticStatsList_getStats(entity me) { LOG_TRACE("XonoticStatsList_getStats() at time: ", ftos(time)); // delete the old buffer if it exists - if(me.listStats >= 0) + if (me.listStats >= 0) { buf_del(me.listStats); + } // create the new buffer if we have a stats buffer - if(PS_D_IN_DB >= 0) + if (PS_D_IN_DB >= 0) { me.listStats = buf_create(); + } // now confirmation, if we didn't create a buffer then just return now - if(me.listStats < 0) - { + if (me.listStats < 0) { me.nItems = 0; return; } @@ -80,16 +93,14 @@ void XonoticStatsList_getStats(entity me) float out_total_kills = -1; float out_total_deaths = -1; - for(e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en) - { + for (e = PS_D_IN_EVL; (en = db_get(PS_D_IN_DB, e)) != ""; e = en) { order = 0; outstr = ""; orderstr = ""; data = db_get(PS_D_IN_DB, sprintf("#%s", e)); // non-gamemode specific stuff - switch(e) - { + switch (e) { case "overall/joined_dt": { order = 1; @@ -144,12 +155,10 @@ void XonoticStatsList_getStats(entity me) } } - if((order == -1) && (out_total_matches >= 0) && (out_total_wins >= 0)) - { + if ((order == -1) && (out_total_matches >= 0) && (out_total_wins >= 0)) { bufstr_add(me.listStats, sprintf("003Matches: %d", out_total_matches), true); - if(out_total_matches > 0) // don't show extra info if there are no matches played - { + if (out_total_matches > 0) { // don't show extra info if there are no matches played out_total_losses = max(0, (out_total_matches - out_total_wins)); bufstr_add(me.listStats, sprintf("003Wins/Losses: %d/%d", out_total_wins, out_total_losses), true); bufstr_add(me.listStats, sprintf("004Win_Percentage: %d%%", ((out_total_wins / out_total_matches) * 100)), true); @@ -161,15 +170,15 @@ void XonoticStatsList_getStats(entity me) continue; } - if((order == -1) && (out_total_kills >= 0) && (out_total_deaths >= 0)) - { + if ((order == -1) && (out_total_kills >= 0) && (out_total_deaths >= 0)) { bufstr_add(me.listStats, sprintf("005Kills/Deaths: %d/%d", out_total_kills, out_total_deaths), true); // if there are no deaths, just show kill count - if(out_total_deaths > 0) + if (out_total_deaths > 0) { bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", (out_total_kills / out_total_deaths)), true); - else + } else { bufstr_add(me.listStats, sprintf("006Kill_Ratio: %.2f", out_total_kills), true); + } out_total_kills = -1; out_total_deaths = -1; @@ -177,29 +186,24 @@ void XonoticStatsList_getStats(entity me) } // game mode specific stuff - if(order > 0) - { + if (order > 0) { orderstr = sprintf("%03d", order); - } - else - { + } else { float dividerpos = strstrofs(e, "/", 0); string gametype = substring(e, 0, dividerpos); - if(gametype == "overall") { continue; } + if (gametype == "overall") { continue; } string event = substring(e, (dividerpos + 1), strlen(e) - (dividerpos + 1)); // if we are ranked, read these sets of possible options - if(stof(db_get(PS_D_IN_DB, sprintf("#%s/rank", gametype)))) - { - switch(event) - { + if (stof(db_get(PS_D_IN_DB, sprintf("#%s/rank", gametype)))) { + switch (event) { case "matches": { order = 1; outstr = sprintf(_("%s_Matches:"), strtoupper(gametype)); - //data = sprintf(_("%d (unranked)"), data); + // data = sprintf(_("%d (unranked)"), data); break; } case "elo": @@ -229,7 +233,7 @@ void XonoticStatsList_getStats(entity me) { order = 5; outstr = sprintf(_("%s_Favorite_Map:"), strtoupper(gametype)); - //data = sprintf(_("%d (unranked)"), data); + // data = sprintf(_("%d (unranked)"), data); break; } #endif @@ -239,30 +243,29 @@ void XonoticStatsList_getStats(entity me) // now set up order for sorting later orderstr = sprintf("%2.2s%d", gametype, order); - } - else if(event == "matches") - { + } else if (event == "matches") { outstr = sprintf(_("%s_Matches:"), strtoupper(gametype)); data = sprintf(_("%d (unranked)"), stof(data)); // unranked game modes ALWAYS get put last orderstr = "zzz"; - } - else { continue; } + } else { continue; } } bufstr_add(me.listStats, sprintf("%s%s %s", orderstr, outstr, data), true); } me.nItems = buf_getsize(me.listStats); - if(me.nItems > 0) + if (me.nItems > 0) { buf_sort(me.listStats, 128, false); + } } void XonoticStatsList_destroy(entity me) { - if(me.nItems > 0) + if (me.nItems > 0) { buf_del(me.listStats); + } } void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) @@ -276,7 +279,7 @@ void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, #if 0 me.columnNameOrigin = me.realFontSize.x; - me.columnNameSize = 0.5 - me.realFontSize.x; // end halfway at maximum length + me.columnNameSize = 0.5 - me.realFontSize.x; // end halfway at maximum length me.columnDataOrigin = me.columnNameOrigin + me.columnNameSize; me.columnDataSize = 1 - me.columnNameSize - me.realFontSize.x; // fill the rest of the control #else @@ -287,8 +290,7 @@ void XonoticStatsList_resizeNotify(entity me, vector relOrigin, vector relSize, void XonoticStatsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { - if(isFocused) - { + if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } @@ -313,18 +315,15 @@ void XonoticStatsList_showNotify(entity me) void XonoticStatsList_doubleClickListBoxItem(entity me, float i, vector where) { - //DemoConfirm_ListClick_Check_Gamestatus(me); + // DemoConfirm_ListClick_Check_Gamestatus(me); } float XonoticStatsList_keyDown(entity me, float scan, float ascii, float shift) { - if(scan == K_ENTER || scan == K_KP_ENTER) - { - //DemoConfirm_ListClick_Check_Gamestatus(me); + if (scan == K_ENTER || scan == K_KP_ENTER) { + // DemoConfirm_ListClick_Check_Gamestatus(me); return 1; - } - else - { + } else { return SUPER(XonoticStatsList).keyDown(me, scan, ascii, shift); } } diff --git a/qcsrc/menu/xonotic/statslist.qh b/qcsrc/menu/xonotic/statslist.qh index 01fb93645..4da72c61b 100644 --- a/qcsrc/menu/xonotic/statslist.qh +++ b/qcsrc/menu/xonotic/statslist.qh @@ -20,5 +20,5 @@ CLASS(XonoticStatsList, XonoticListBox) ATTRIB(XonoticStatsList, columnNameSize, float, 0); ENDCLASS(XonoticStatsList) -entity statslist; // for reference elsewhere +entity statslist; // for reference elsewhere entity makeXonoticStatsList(); diff --git a/qcsrc/menu/xonotic/tabcontroller.qc b/qcsrc/menu/xonotic/tabcontroller.qc index fe6941723..c03c297ec 100644 --- a/qcsrc/menu/xonotic/tabcontroller.qc +++ b/qcsrc/menu/xonotic/tabcontroller.qc @@ -16,10 +16,11 @@ void XonoticTabController_configureXonoticTabController(entity me, float theRows entity XonoticTabController_makeTabButton_T(entity me, string theTitle, entity tab, string theTooltip) { entity b; - if(me.rows != tab.rows) + if (me.rows != tab.rows) { error("Tab dialog height mismatch!"); + } b = makeXonoticButton_T(theTitle, '0 0 0', theTooltip); - me.addTab(me, tab, b); + me.addTab(me, tab, b); // TODO make this real tab buttons (with color parameters, and different gfx) return b; } diff --git a/qcsrc/menu/xonotic/textslider.qc b/qcsrc/menu/xonotic/textslider.qc index 54c7e5fb1..088a530d9 100644 --- a/qcsrc/menu/xonotic/textslider.qc +++ b/qcsrc/menu/xonotic/textslider.qc @@ -20,78 +20,72 @@ void XonoticTextSlider_configureXonoticTextSlider(entity me, string theCvar, str } void XonoticTextSlider_setValue(entity me, float val) { - if(val != me.value) - { - SUPER(XonoticTextSlider).setValue( me, val ); + if (val != me.value) { + SUPER(XonoticTextSlider).setValue(me, val); me.saveCvars(me); } } void XonoticTextSlider_setValue_noAnim(entity me, float val) { - if(val != me.value) - { + if (val != me.value) { SUPER(XonoticTextSlider).setValue_noAnim(me, val); me.saveCvars(me); } } void XonoticTextSlider_loadCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } float n = tokenize_console(me.cvarName); string s = cvar_string(argv(0)); float i; - for(i = 1; i < n; ++i) + for (i = 1; i < n; ++i) { s = strcat(s, " ", cvar_string(argv(i))); + } me.setValueFromIdentifier_noAnim(me, s); - if(me.value < 0 && n > 1) - { + if (me.value < 0 && n > 1) { // if it failed: check if all cvars have the same value // if yes, try its value as 1-word identifier - for(i = 1; i < n; ++i) - if(cvar_string(argv(i)) != cvar_string(argv(i-1))) + for (i = 1; i < n; ++i) { + if (cvar_string(argv(i)) != cvar_string(argv(i - 1))) { break; - if(i >= n) + } + } + if (i >= n) { me.setValueFromIdentifier_noAnim(me, cvar_string(argv(0))); + } } } void XonoticTextSlider_saveCvars(entity me) { - if (!me.cvarName) + if (!me.cvarName) { return; + } - if(me.value >= 0 && me.value < me.nValues) - { + if (me.value >= 0 && me.value < me.nValues) { float n = tokenize_console(me.cvarName); - if(n == 1) - { + if (n == 1) { // this is a special case to allow spaces in the identifiers cvar_set(argv(0), me.getIdentifier(me)); CheckSendCvars(me, argv(0)); - } - else - { + } else { float i; float m = tokenize_console(strcat(me.cvarName, " ", me.getIdentifier(me))); - if(m == n + 1) - { - for(i = 0; i < n; ++i) - { + if (m == n + 1) { + for (i = 0; i < n; ++i) { cvar_set(argv(i), argv(n)); CheckSendCvars(me, argv(i)); } - } - else if(m == n * 2) - { - for(i = 0; i < n; ++i) - { + } else if (m == n * 2) { + for (i = 0; i < n; ++i) { cvar_set(argv(i), argv(i + n)); CheckSendCvars(me, argv(i)); } - } - else + } else { error("XonoticTextSlider: invalid identifier ", me.getIdentifier(me), " does not match cvar list ", me.cvarName); + } } } } diff --git a/qcsrc/menu/xonotic/textslider.qh b/qcsrc/menu/xonotic/textslider.qh index 58fe8e86b..1de3eec21 100644 --- a/qcsrc/menu/xonotic/textslider.qh +++ b/qcsrc/menu/xonotic/textslider.qh @@ -26,4 +26,4 @@ CLASS(XonoticTextSlider, TextSlider) ATTRIB(XonoticTextSlider, disabledAlpha, float, SKINALPHA_DISABLED); ENDCLASS(XonoticTextSlider) entity makeXonoticTextSlider_T(string, string theTooltip); -entity makeXonoticTextSlider(string); // note: you still need to call addValue and configureXonoticTextSliderValues! +entity makeXonoticTextSlider(string); // note: you still need to call addValue and configureXonoticTextSliderValues! diff --git a/qcsrc/menu/xonotic/util.qh b/qcsrc/menu/xonotic/util.qh index 96fef2ad4..5fc79600b 100644 --- a/qcsrc/menu/xonotic/util.qh +++ b/qcsrc/menu/xonotic/util.qh @@ -32,7 +32,7 @@ void UpdateNotification_URI_Get_Callback(float id, float status, string data); entity GameType_GetID(int cnt); string GameType_GetName(int cnt); string GameType_GetIcon(int cnt); -//string GameType_GetTeams(float cnt); +// string GameType_GetTeams(float cnt); int GameType_GetCount(); int GameType_GetTotalCount(); @@ -41,7 +41,7 @@ void dialog_hudpanel_common_notoggle(entity me, string panelname); dialog_hudpanel_common_notoggle(me, panelname) #define DIALOG_HUDPANEL_COMMON() \ me.TR(me); \ - me.TD(me, 1, 4, e = makeXonoticCheckBox(0, strzone(strcat("hud_panel_", panelname)), _("Enable panel"))); \ + me.TD(me, 1, 4, e = makeXonoticCheckBox(0, strzone(strcat("hud_panel_", panelname)), _("Enable panel"))); \ DIALOG_HUDPANEL_COMMON_NOTOGGLE() float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha); diff --git a/qcsrc/menu/xonotic/weaponarenacheckbox.qc b/qcsrc/menu/xonotic/weaponarenacheckbox.qc index fd4f51385..76ff7cb5f 100644 --- a/qcsrc/menu/xonotic/weaponarenacheckbox.qc +++ b/qcsrc/menu/xonotic/weaponarenacheckbox.qc @@ -23,10 +23,8 @@ void XonoticWeaponarenaCheckBox_loadCvars(entity me) { float n = tokenize_console(cvar_string("menu_weaponarena")); float i; - for(i=0; i<n; ++i) - { - if(argv(i) == me.netname) - { + for (i = 0; i < n; ++i) { + if (argv(i) == me.netname) { me.checked = true; break; } @@ -35,9 +33,10 @@ void XonoticWeaponarenaCheckBox_loadCvars(entity me) void XonoticWeaponarenaCheckBox_saveCvars(entity me) { - if(me.checked) + if (me.checked) { localcmd(strcat("\nmenu_cmd addtolist menu_weaponarena ", me.netname, "\n")); - else + } else { localcmd(strcat("\nmenu_cmd removefromlist menu_weaponarena ", me.netname, "\n")); + } localcmd("\ng_weaponarena \"$menu_weaponarena\"\n"); } diff --git a/qcsrc/menu/xonotic/weaponslist.qc b/qcsrc/menu/xonotic/weaponslist.qc index 7b3d7375b..9d33bb1c4 100644 --- a/qcsrc/menu/xonotic/weaponslist.qc +++ b/qcsrc/menu/xonotic/weaponslist.qc @@ -21,23 +21,22 @@ void XonoticWeaponsList_draw(entity me) string s, t; s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority")); t = W_FixWeaponOrder(s, 1); - if(t != s) + if (t != s) { cvar_set("cl_weaponpriority", W_NameWeaponOrder(t)); + } me.nItems = tokenize_console(t); SUPER(XonoticWeaponsList).draw(me); } void WeaponsList_MoveUp_Click(entity box, entity me) { - if(me.selectedItem > 0) - { + if (me.selectedItem > 0) { cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem - 1, me.selectedItem)); me.setSelected(me, me.selectedItem - 1); } } void WeaponsList_MoveDown_Click(entity box, entity me) { - if(me.selectedItem < me.nItems - 1) - { + if (me.selectedItem < me.nItems - 1) { cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, me.selectedItem + 1)); me.setSelected(me, me.selectedItem + 1); } @@ -55,12 +54,11 @@ float XonoticWeaponsList_mouseDrag(entity me, vector pos) int i = me.selectedItem; float f = SUPER(XonoticWeaponsList).mouseDrag(me, pos); - if(me.pressed != 1) // don't change priority if the person is just scrolling - { - if(me.selectedItem != i) - { - if(me.applyButton) + if (me.pressed != 1) { // don't change priority if the person is just scrolling + if (me.selectedItem != i) { + if (me.applyButton) { me.applyButton.disabled = false; + } cvar_set("cl_weaponpriority", swapInPriorityList(cvar_string("cl_weaponpriority"), me.selectedItem, i)); } } @@ -74,8 +72,7 @@ string XonoticWeaponsList_toString(entity me) entity e; n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority"))); s = ""; - for(i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { e = Weapons_from(stof(argv(i))); s = strcat(s, e.m_name, ", "); } @@ -84,17 +81,17 @@ string XonoticWeaponsList_toString(entity me) void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { entity e; - if(isSelected) + if (isSelected) { draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); - else if(isFocused) - { + } else if (isFocused) { me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } e = Weapons_from(stof(argv(i))); string msg = e.m_name; - if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED) + if (e.spawnflags & WEP_FLAG_MUTATORBLOCKED) { msg = strcat(msg, "*"); + } vector save_fontscale = draw_fontscale; float f = draw_CondensedFontFactor(msg, false, me.realFontSize, 1); @@ -107,17 +104,14 @@ void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool i float XonoticWeaponsList_keyDown(entity me, float scan, float ascii, float shift) { - if(ascii == 43) // + - { + if (ascii == 43) { // + WeaponsList_MoveUp_Click(NULL, me); return 1; - } - else if(ascii == 45) // - - { + } else if (ascii == 45) { // - WeaponsList_MoveDown_Click(NULL, me); return 1; - } - else if(SUPER(XonoticWeaponsList).keyDown(me, scan, ascii, shift)) + } else if (SUPER(XonoticWeaponsList).keyDown(me, scan, ascii, shift)) { return 1; + } return 0; } diff --git a/qcsrc/server-testcase/framework.qc b/qcsrc/server-testcase/framework.qc index 1735e1c11..4582f2684 100644 --- a/qcsrc/server-testcase/framework.qc +++ b/qcsrc/server-testcase/framework.qc @@ -9,10 +9,11 @@ spawnfunc(worldspawn) float r; LOG_TRACE("TESTCASE: START"); r = test(); - if(r == 1) + if (r == 1) { error("TESTCASE: PASS"); - else if(r == 0) + } else if (r == 0) { error("TESTCASE: FAIL"); - else + } else { error("TESTCASE: INVALID"); + } } diff --git a/qcsrc/server/antilag.qc b/qcsrc/server/antilag.qc index 46c871876..ec19a9675 100644 --- a/qcsrc/server/antilag.qc +++ b/qcsrc/server/antilag.qc @@ -2,10 +2,10 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include <server/defs.qh> - #include <common/state.qh> - #include <common/vehicles/all.qh> - #include "antilag.qh" + #include <server/defs.qh> + #include <common/state.qh> + #include <common/vehicles/all.qh> + #include "antilag.qh" #endif const int ANTILAG_MAX_ORIGINS = 64; @@ -19,38 +19,48 @@ const int ANTILAG_MAX_ORIGINS = 64; void antilag_record(entity e, entity store, float t) { - if (e.vehicle) { - if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return; - antilag_record(e.vehicle, e.vehicle, t); - } + if (e.vehicle) { + if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) { return; } + antilag_record(e.vehicle, e.vehicle, t); + } - if (time < store.antilag_times[store.antilag_index]) return; + if (time < store.antilag_times[store.antilag_index]) { return; } store.antilag_index += 1; - if (store.antilag_index >= ANTILAG_MAX_ORIGINS) + if (store.antilag_index >= ANTILAG_MAX_ORIGINS) { store.antilag_index = 0; + } store.antilag_times[store.antilag_index] = t; store.antilag_origins[store.antilag_index] = e.origin; - if (store.antilag_debug) + if (store.antilag_debug) { te_spark(antilag_takebackorigin(e, store, t - store.antilag_debug), '0 0 0', 32); + } } // finds the index BEFORE t float antilag_find(entity e, entity store, float t) { - for(int i = store.antilag_index; i > 0; --i) - if(store.antilag_times[i] >= t) - if(store.antilag_times[i - 1] < t) + for (int i = store.antilag_index; i > 0; --i) { + if (store.antilag_times[i] >= t) { + if (store.antilag_times[i - 1] < t) { return i - 1; + } + } + } - if(store.antilag_times[0] >= t) - if(store.antilag_times[ANTILAG_MAX_ORIGINS - 1] < t) + if (store.antilag_times[0] >= t) { + if (store.antilag_times[ANTILAG_MAX_ORIGINS - 1] < t) { return ANTILAG_MAX_ORIGINS - 1; + } + } - for(int i = ANTILAG_MAX_ORIGINS - 1; i > store.antilag_index + 1; --i) - if(store.antilag_times[i] >= t) - if(store.antilag_times[i - 1] < t) + for (int i = ANTILAG_MAX_ORIGINS - 1; i > store.antilag_index + 1; --i) { + if (store.antilag_times[i] >= t) { + if (store.antilag_times[i - 1] < t) { return i - 1; + } + } + } // if we get here, t is sandwiched nowhere, so let's assume it's in the present return -1; @@ -59,24 +69,25 @@ float antilag_find(entity e, entity store, float t) vector antilag_takebackorigin(entity e, entity store, float t) { int i0 = antilag_find(e, store, t); - if (i0 < 0) - { + if (i0 < 0) { // IN THE PRESENT - if(store.antilag_takenback) + if (store.antilag_takenback) { return store.antilag_saved_origin; - else + } else { return e.origin; + } } int i1 = i0 + 1; - if (i1 >= ANTILAG_MAX_ORIGINS) + if (i1 >= ANTILAG_MAX_ORIGINS) { i1 = 0; + } return lerpv(store.antilag_times[i0], store.antilag_origins[i0], store.antilag_times[i1], store.antilag_origins[i1], t); } vector antilag_takebackavgvelocity(entity e, entity store, float t0, float t1) { - if (t0 >= t1) return '0 0 0'; + if (t0 >= t1) { return '0 0 0'; } vector o0 = antilag_takebackorigin(e, store, t0); vector o1 = antilag_takebackorigin(e, store, t1); return (o1 - o0) * (1 / (t1 - t0)); @@ -85,12 +96,13 @@ vector antilag_takebackavgvelocity(entity e, entity store, float t0, float t1) void antilag_takeback(entity e, entity store, float t) { if (e.vehicle) { - if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return; + if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) { return; } antilag_takeback(e.vehicle, e.vehicle, t); - } + } - if (!store.antilag_takenback) + if (!store.antilag_takenback) { store.antilag_saved_origin = e.origin; + } vector org = antilag_takebackorigin(e, store, t); setorigin(e, org); @@ -100,11 +112,11 @@ void antilag_takeback(entity e, entity store, float t) void antilag_restore(entity e, entity store) { if (e.vehicle) { - if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) return; + if (e.vehicle.vehicle_flags == VHF_PLAYERSLOT) { return; } antilag_restore(e.vehicle, e.vehicle); } - if (!store.antilag_takenback) return; + if (!store.antilag_takenback) { return; } setorigin(e, store.antilag_saved_origin); store.antilag_takenback = false; diff --git a/qcsrc/server/bot/default/aim.qc b/qcsrc/server/bot/default/aim.qc index ddd0afa82..e928ed251 100644 --- a/qcsrc/server/bot/default/aim.qc +++ b/qcsrc/server/bot/default/aim.qc @@ -21,12 +21,15 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f { float c, savesolid, shottime; vector dir, end, v, o; - if (shotspeed < 1) + if (shotspeed < 1) { return false; // could cause division by zero if calculated - if (targ.solid < SOLID_BBOX) // SOLID_NOT and SOLID_TRIGGER + } + if (targ.solid < SOLID_BBOX) { // SOLID_NOT and SOLID_TRIGGER return false; // could never hit it - if (!tracetossent) + } + if (!tracetossent) { tracetossent = new(tracetossent); + } tracetossent.owner = ignore; setsize(tracetossent, m1, m2); savesolid = targ.solid; @@ -37,15 +40,15 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f tracebox(o, targ.mins, targ.maxs, v, false, targ); v = trace_endpos; end = v + (targ.mins + targ.maxs) * 0.5; - if ((vlen(end - org) / shotspeed + 0.2) > maxtime) - { + if ((vlen(end - org) / shotspeed + 0.2) > maxtime) { // out of range targ.solid = savesolid; return false; } - if (!tracetossfaketarget) + if (!tracetossfaketarget) { tracetossfaketarget = new(tracetossfaketarget); + } tracetossfaketarget.solid = savesolid; set_movetype(tracetossfaketarget, targ.move_movetype); _setmodel(tracetossfaketarget, targ.model); // no low precision @@ -56,13 +59,11 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f c = 0; dir = normalize(end - org); - while (c < 10) // 10 traces - { - setorigin(tracetossent, org); // reset + while (c < 10) { // 10 traces + setorigin(tracetossent, org); // reset tracetossent.velocity = findtrajectory_velocity = normalize(dir) * shotspeed + shotspeedupward * '0 0 1'; tracetoss(tracetossent, ignore); // love builtin functions... - if (trace_ent == tracetossfaketarget) // done - { + if (trace_ent == tracetossfaketarget) { // done targ.solid = savesolid; // make it disappear @@ -95,83 +96,92 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f void lag_update(entity this) { - if (this.lag1_time) if (time > this.lag1_time) {this.lag_func(this, this.lag1_time, this.lag1_float1, this.lag1_float2, this.lag1_entity1, this.lag1_vec1, this.lag1_vec2, this.lag1_vec3, this.lag1_vec4);this.lag1_time = 0;} - if (this.lag2_time) if (time > this.lag2_time) {this.lag_func(this, this.lag2_time, this.lag2_float1, this.lag2_float2, this.lag2_entity1, this.lag2_vec1, this.lag2_vec2, this.lag2_vec3, this.lag2_vec4);this.lag2_time = 0;} - if (this.lag3_time) if (time > this.lag3_time) {this.lag_func(this, this.lag3_time, this.lag3_float1, this.lag3_float2, this.lag3_entity1, this.lag3_vec1, this.lag3_vec2, this.lag3_vec3, this.lag3_vec4);this.lag3_time = 0;} - if (this.lag4_time) if (time > this.lag4_time) {this.lag_func(this, this.lag4_time, this.lag4_float1, this.lag4_float2, this.lag4_entity1, this.lag4_vec1, this.lag4_vec2, this.lag4_vec3, this.lag4_vec4);this.lag4_time = 0;} - if (this.lag5_time) if (time > this.lag5_time) {this.lag_func(this, this.lag5_time, this.lag5_float1, this.lag5_float2, this.lag5_entity1, this.lag5_vec1, this.lag5_vec2, this.lag5_vec3, this.lag5_vec4);this.lag5_time = 0;} + if (this.lag1_time) { if (time > this.lag1_time) { this.lag_func(this, this.lag1_time, this.lag1_float1, this.lag1_float2, this.lag1_entity1, this.lag1_vec1, this.lag1_vec2, this.lag1_vec3, this.lag1_vec4); this.lag1_time = 0; } } + if (this.lag2_time) { if (time > this.lag2_time) { this.lag_func(this, this.lag2_time, this.lag2_float1, this.lag2_float2, this.lag2_entity1, this.lag2_vec1, this.lag2_vec2, this.lag2_vec3, this.lag2_vec4); this.lag2_time = 0; } } + if (this.lag3_time) { if (time > this.lag3_time) { this.lag_func(this, this.lag3_time, this.lag3_float1, this.lag3_float2, this.lag3_entity1, this.lag3_vec1, this.lag3_vec2, this.lag3_vec3, this.lag3_vec4); this.lag3_time = 0; } } + if (this.lag4_time) { if (time > this.lag4_time) { this.lag_func(this, this.lag4_time, this.lag4_float1, this.lag4_float2, this.lag4_entity1, this.lag4_vec1, this.lag4_vec2, this.lag4_vec3, this.lag4_vec4); this.lag4_time = 0; } } + if (this.lag5_time) { if (time > this.lag5_time) { this.lag_func(this, this.lag5_time, this.lag5_float1, this.lag5_float2, this.lag5_entity1, this.lag5_vec1, this.lag5_vec2, this.lag5_vec3, this.lag5_vec4); this.lag5_time = 0; } } } float lag_additem(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) { - if (this.lag1_time == 0) {this.lag1_time = t;this.lag1_float1 = f1;this.lag1_float2 = f2;this.lag1_entity1 = e1;this.lag1_vec1 = v1;this.lag1_vec2 = v2;this.lag1_vec3 = v3;this.lag1_vec4 = v4;return true;} - if (this.lag2_time == 0) {this.lag2_time = t;this.lag2_float1 = f1;this.lag2_float2 = f2;this.lag2_entity1 = e1;this.lag2_vec1 = v1;this.lag2_vec2 = v2;this.lag2_vec3 = v3;this.lag2_vec4 = v4;return true;} - if (this.lag3_time == 0) {this.lag3_time = t;this.lag3_float1 = f1;this.lag3_float2 = f2;this.lag3_entity1 = e1;this.lag3_vec1 = v1;this.lag3_vec2 = v2;this.lag3_vec3 = v3;this.lag3_vec4 = v4;return true;} - if (this.lag4_time == 0) {this.lag4_time = t;this.lag4_float1 = f1;this.lag4_float2 = f2;this.lag4_entity1 = e1;this.lag4_vec1 = v1;this.lag4_vec2 = v2;this.lag4_vec3 = v3;this.lag4_vec4 = v4;return true;} - if (this.lag5_time == 0) {this.lag5_time = t;this.lag5_float1 = f1;this.lag5_float2 = f2;this.lag5_entity1 = e1;this.lag5_vec1 = v1;this.lag5_vec2 = v2;this.lag5_vec3 = v3;this.lag5_vec4 = v4;return true;} + if (this.lag1_time == 0) { this.lag1_time = t; this.lag1_float1 = f1; this.lag1_float2 = f2; this.lag1_entity1 = e1; this.lag1_vec1 = v1; this.lag1_vec2 = v2; this.lag1_vec3 = v3; this.lag1_vec4 = v4; return true; } + if (this.lag2_time == 0) { this.lag2_time = t; this.lag2_float1 = f1; this.lag2_float2 = f2; this.lag2_entity1 = e1; this.lag2_vec1 = v1; this.lag2_vec2 = v2; this.lag2_vec3 = v3; this.lag2_vec4 = v4; return true; } + if (this.lag3_time == 0) { this.lag3_time = t; this.lag3_float1 = f1; this.lag3_float2 = f2; this.lag3_entity1 = e1; this.lag3_vec1 = v1; this.lag3_vec2 = v2; this.lag3_vec3 = v3; this.lag3_vec4 = v4; return true; } + if (this.lag4_time == 0) { this.lag4_time = t; this.lag4_float1 = f1; this.lag4_float2 = f2; this.lag4_entity1 = e1; this.lag4_vec1 = v1; this.lag4_vec2 = v2; this.lag4_vec3 = v3; this.lag4_vec4 = v4; return true; } + if (this.lag5_time == 0) { this.lag5_time = t; this.lag5_float1 = f1; this.lag5_float2 = f2; this.lag5_entity1 = e1; this.lag5_vec1 = v1; this.lag5_vec2 = v2; this.lag5_vec3 = v3; this.lag5_vec4 = v4; return true; } // no room for it (what is the best thing to do here??) return false; } bool bot_shouldattack(entity this, entity targ) { - if (targ.team == this.team) - { - if (targ == this) - return false; - if (teamplay) - if (targ.team != 0) + if (targ.team == this.team) { + if (targ == this) { return false; + } + if (teamplay) { + if (targ.team != 0) { + return false; + } + } } - if(STAT(FROZEN, targ)) + if (STAT(FROZEN, targ)) { return false; + } - if(teamplay) - { - if(targ.team==0) + if (teamplay) { + if (targ.team == 0) { return false; - } - else if(bot_ignore_bots) - if(IS_BOT_CLIENT(targ)) + } + } else if (bot_ignore_bots) { + if (IS_BOT_CLIENT(targ)) { return false; + } + } - if (!targ.takedamage) + if (!targ.takedamage) { return false; - if (IS_DEAD(targ)) + } + if (IS_DEAD(targ)) { return false; - if (PHYS_INPUT_BUTTON_CHAT(targ)) + } + if (PHYS_INPUT_BUTTON_CHAT(targ)) { return false; - if(targ.flags & FL_NOTARGET) + } + if (targ.flags & FL_NOTARGET) { return false; + } - if(MUTATOR_CALLHOOK(BotShouldAttack, this, targ)) + if (MUTATOR_CALLHOOK(BotShouldAttack, this, targ)) { return false; + } return true; } void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) { - if(this.flags & FL_INWATER) - { + if (this.flags & FL_INWATER) { this.bot_aimtarg = NULL; return; } this.bot_aimtarg = e1; this.bot_aimlatency = CS(this).ping; // FIXME? Shouldn't this be in the lag item? - //this.bot_aimorigin = v1; - //this.bot_aimvelocity = v2; + // this.bot_aimorigin = v1; + // this.bot_aimvelocity = v2; this.bot_aimtargorigin = v3; this.bot_aimtargvelocity = v4; - if(skill <= 0) + if (skill <= 0) { this.bot_canfire = (random() < 0.8); - else if(skill <= 1) + } else if (skill <= 1) { this.bot_canfire = (random() < 0.9); - else if(skill <= 2) + } else if (skill <= 2) { this.bot_canfire = (random() < 0.95); - else + } else { this.bot_canfire = 1; + } } float bot_aimdir(entity this, vector v, float maxfiredeviation) @@ -179,140 +189,145 @@ float bot_aimdir(entity this, vector v, float maxfiredeviation) float dist, delta_t, blend; vector desiredang, diffang; - //dprint("aim ", this.netname, ": old:", vtos(this.v_angle)); + // dprint("aim ", this.netname, ": old:", vtos(this.v_angle)); // make sure v_angle is sane first this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360; this.v_angle_z = 0; // get the desired angles to aim at - //dprint(" at:", vtos(v)); + // dprint(" at:", vtos(v)); v = normalize(v); - //te_lightning2(NULL, this.origin + this.view_ofs, this.origin + this.view_ofs + v * 200); - if (time >= this.bot_badaimtime) - { + // te_lightning2(NULL, this.origin + this.view_ofs, this.origin + this.view_ofs + v * 200); + if (time >= this.bot_badaimtime) { this.bot_badaimtime = max(this.bot_badaimtime + 0.3, time); - this.bot_badaimoffset = randomvec() * bound(0, 5 - 0.5 * (skill+this.bot_offsetskill), 5) * autocvar_bot_ai_aimskill_offset; + this.bot_badaimoffset = randomvec() * bound(0, 5 - 0.5 * (skill + this.bot_offsetskill), 5) * autocvar_bot_ai_aimskill_offset; } desiredang = vectoangles(v) + this.bot_badaimoffset; - //dprint(" desired:", vtos(desiredang)); - if (desiredang.x >= 180) + // dprint(" desired:", vtos(desiredang)); + if (desiredang.x >= 180) { desiredang.x = desiredang.x - 360; + } desiredang.x = bound(-90, 0 - desiredang.x, 90); desiredang.z = this.v_angle.z; - //dprint(" / ", vtos(desiredang)); + // dprint(" / ", vtos(desiredang)); //// pain throws off aim - //if (this.bot_painintensity) - //{ + // if (this.bot_painintensity) + // { // // shake from pain // desiredang = desiredang + randomvec() * this.bot_painintensity * 0.2; - //} + // } // calculate turn angles diffang = (desiredang - this.bot_olddesiredang); // wrap yaw turn diffang.y = diffang.y - floor(diffang.y / 360) * 360; - if (diffang.y >= 180) + if (diffang.y >= 180) { diffang.y = diffang.y - 360; + } this.bot_olddesiredang = desiredang; - //dprint(" diff:", vtos(diffang)); + // dprint(" diff:", vtos(diffang)); - delta_t = time-this.bot_prevaimtime; + delta_t = time - this.bot_prevaimtime; this.bot_prevaimtime = time; // Here we will try to anticipate the comming aiming direction - this.bot_1st_order_aimfilter= this.bot_1st_order_aimfilter - + (diffang * (1 / delta_t) - this.bot_1st_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_1st,1); - this.bot_2nd_order_aimfilter= this.bot_2nd_order_aimfilter - + (this.bot_1st_order_aimfilter - this.bot_2nd_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_2nd,1); - this.bot_3th_order_aimfilter= this.bot_3th_order_aimfilter - + (this.bot_2nd_order_aimfilter - this.bot_3th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_3th,1); - this.bot_4th_order_aimfilter= this.bot_4th_order_aimfilter - + (this.bot_3th_order_aimfilter - this.bot_4th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_4th,1); - this.bot_5th_order_aimfilter= this.bot_5th_order_aimfilter - + (this.bot_4th_order_aimfilter - this.bot_5th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_5th,1); - - //blend = (bound(0,skill,10)*0.1)*((1-bound(0,skill,10)*0.05) ** 2.5)*5.656854249; //Plot formule before changing ! - blend = bound(0,skill+this.bot_aimskill,10)*0.1; - desiredang = desiredang + blend * - ( - this.bot_1st_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_1st + this.bot_1st_order_aimfilter = this.bot_1st_order_aimfilter + + (diffang * (1 / delta_t) - this.bot_1st_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_1st, 1); + this.bot_2nd_order_aimfilter = this.bot_2nd_order_aimfilter + + (this.bot_1st_order_aimfilter - this.bot_2nd_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_2nd, 1); + this.bot_3th_order_aimfilter = this.bot_3th_order_aimfilter + + (this.bot_2nd_order_aimfilter - this.bot_3th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_3th, 1); + this.bot_4th_order_aimfilter = this.bot_4th_order_aimfilter + + (this.bot_3th_order_aimfilter - this.bot_4th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_4th, 1); + this.bot_5th_order_aimfilter = this.bot_5th_order_aimfilter + + (this.bot_4th_order_aimfilter - this.bot_5th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_5th, 1); + + // blend = (bound(0,skill,10)*0.1)*((1-bound(0,skill,10)*0.05) ** 2.5)*5.656854249; //Plot formule before changing ! + blend = bound(0, skill + this.bot_aimskill, 10) * 0.1; + desiredang = desiredang + blend + * ( + this.bot_1st_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_1st + this.bot_2nd_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_2nd + this.bot_3th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_3th + this.bot_4th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_4th + this.bot_5th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_5th - ); + ); // calculate turn angles diffang = desiredang - this.bot_mouseaim; // wrap yaw turn diffang.y = diffang.y - floor(diffang.y / 360) * 360; - if (diffang.y >= 180) + if (diffang.y >= 180) { diffang.y = diffang.y - 360; - //dprint(" diff:", vtos(diffang)); + } + // dprint(" diff:", vtos(diffang)); - if (time >= this.bot_aimthinktime) - { - this.bot_aimthinktime = max(this.bot_aimthinktime + 0.5 - 0.05*(skill+this.bot_thinkskill), time); - this.bot_mouseaim = this.bot_mouseaim + diffang * (1-random()*0.1*bound(1,10-(skill+this.bot_thinkskill),10)); + if (time >= this.bot_aimthinktime) { + this.bot_aimthinktime = max(this.bot_aimthinktime + 0.5 - 0.05 * (skill + this.bot_thinkskill), time); + this.bot_mouseaim = this.bot_mouseaim + diffang * (1 - random() * 0.1 * bound(1, 10 - (skill + this.bot_thinkskill), 10)); } - //this.v_angle = this.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1); + // this.v_angle = this.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1); diffang = this.bot_mouseaim - desiredang; // wrap yaw turn diffang.y = diffang.y - floor(diffang.y / 360) * 360; - if (diffang.y >= 180) + if (diffang.y >= 180) { diffang.y = diffang.y - 360; - desiredang = desiredang + diffang * bound(0,autocvar_bot_ai_aimskill_think,1); + } + desiredang = desiredang + diffang * bound(0, autocvar_bot_ai_aimskill_think, 1); // calculate turn angles diffang = desiredang - this.v_angle; // wrap yaw turn diffang.y = diffang.y - floor(diffang.y / 360) * 360; - if (diffang.y >= 180) + if (diffang.y >= 180) { diffang.y = diffang.y - 360; - //dprint(" diff:", vtos(diffang)); + } + // dprint(" diff:", vtos(diffang)); // jitter tracking dist = vlen(diffang); - //diffang = diffang + randomvec() * (dist * 0.05 * (3.5 - bound(0, skill, 3))); + // diffang = diffang + randomvec() * (dist * 0.05 * (3.5 - bound(0, skill, 3))); // turn float r, fixedrate, blendrate; - fixedrate = autocvar_bot_ai_aimskill_fixedrate / bound(1,dist,1000); + fixedrate = autocvar_bot_ai_aimskill_fixedrate / bound(1, dist, 1000); blendrate = autocvar_bot_ai_aimskill_blendrate; r = max(fixedrate, blendrate); - //this.v_angle = this.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1); + // this.v_angle = this.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1); this.v_angle = this.v_angle + diffang * bound(delta_t, r * delta_t * (2 + POW((skill + this.bot_mouseskill), 3) * 0.005 - random()), 1); - this.v_angle = this.v_angle * bound(0,autocvar_bot_ai_aimskill_mouse,1) + desiredang * bound(0,(1-autocvar_bot_ai_aimskill_mouse),1); - //this.v_angle = this.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1); - //this.v_angle = this.v_angle + diffang * (1/ blendrate); + this.v_angle = this.v_angle * bound(0, autocvar_bot_ai_aimskill_mouse, 1) + desiredang * bound(0, (1 - autocvar_bot_ai_aimskill_mouse), 1); + // this.v_angle = this.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1); + // this.v_angle = this.v_angle + diffang * (1/ blendrate); this.v_angle_z = 0; this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360; - //dprint(" turn:", vtos(this.v_angle)); + // dprint(" turn:", vtos(this.v_angle)); makevectors(this.v_angle); shotorg = this.origin + this.view_ofs; shotdir = v_forward; - //dprint(" dir:", vtos(v_forward)); - //te_lightning2(NULL, shotorg, shotorg + shotdir * 100); + // dprint(" dir:", vtos(v_forward)); + // te_lightning2(NULL, shotorg, shotorg + shotdir * 100); // calculate turn angles again - //diffang = desiredang - this.v_angle; - //diffang_y = diffang_y - floor(diffang_y / 360) * 360; - //if (diffang_y >= 180) + // diffang = desiredang - this.v_angle; + // diffang_y = diffang_y - floor(diffang_y / 360) * 360; + // if (diffang_y >= 180) // diffang_y = diffang_y - 360; - //dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n"); + // dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n"); // decide whether to fire this time - if (v * shotdir >= cos(maxfiredeviation * DEG2RAD)) - if(vdist(trace_endpos-shotorg, <, 500 + 500 * bound(0, skill + this.bot_aggresskill, 10)) || random()*random()>bound(0,(skill+this.bot_aggresskill)*0.05,1)) - this.bot_firetimer = time + bound(0.1, 0.5-(skill+this.bot_aggresskill)*0.05, 0.5); - //traceline(shotorg,shotorg+shotdir*1000,false,NULL); - //dprint(ftos(maxfiredeviation),"\n"); - //dprint(" diff:", vtos(diffang), "\n"); + if (v * shotdir >= cos(maxfiredeviation * DEG2RAD)) { + if (vdist(trace_endpos - shotorg, <, 500 + 500 * bound(0, skill + this.bot_aggresskill, 10)) || random() * random() > bound(0, (skill + this.bot_aggresskill) * 0.05, 1)) { + this.bot_firetimer = time + bound(0.1, 0.5 - (skill + this.bot_aggresskill) * 0.05, 0.5); + } + } + // traceline(shotorg,shotorg+shotdir*1000,false,NULL); + // dprint(ftos(maxfiredeviation),"\n"); + // dprint(" diff:", vtos(diffang), "\n"); return this.bot_canfire && (time < this.bot_firetimer); } @@ -341,13 +356,11 @@ bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeed shotspeed *= W_WeaponSpeedFactor(this); shotspeedupward *= W_WeaponSpeedFactor(this); - if (!shotspeed) - { + if (!shotspeed) { LOG_TRACE("bot_aim: WARNING: weapon ", this.(weaponentity).m_weapon.m_name, " shotspeed is zero!"); shotspeed = 1000000; } - if (!maxshottime) - { + if (!maxshottime) { LOG_TRACE("bot_aim: WARNING: weapon ", this.(weaponentity).m_weapon.m_name, " maxshottime is zero!"); maxshottime = 1; } @@ -355,40 +368,37 @@ bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeed shotorg = this.origin + this.view_ofs; shotdir = v_forward; v = bot_shotlead(this.bot_aimtargorigin, this.bot_aimtargvelocity, shotspeed, this.bot_aimlatency); - distanceratio = sqrt(bound(0,skill,10000))*0.3*(vlen(v-shotorg)-100)/autocvar_bot_ai_aimskill_firetolerance_distdegrees; - distanceratio = bound(0,distanceratio,1); - r = (autocvar_bot_ai_aimskill_firetolerance_maxdegrees-autocvar_bot_ai_aimskill_firetolerance_mindegrees) - * (1-distanceratio) + autocvar_bot_ai_aimskill_firetolerance_mindegrees; - if (applygravity && this.bot_aimtarg) - { - if (!findtrajectorywithleading(shotorg, '0 0 0', '0 0 0', this.bot_aimtarg, shotspeed, shotspeedupward, maxshottime, 0, this)) - { + distanceratio = sqrt(bound(0, skill, 10000)) * 0.3 * (vlen(v - shotorg) - 100) / autocvar_bot_ai_aimskill_firetolerance_distdegrees; + distanceratio = bound(0, distanceratio, 1); + r = (autocvar_bot_ai_aimskill_firetolerance_maxdegrees - autocvar_bot_ai_aimskill_firetolerance_mindegrees) + * (1 - distanceratio) + autocvar_bot_ai_aimskill_firetolerance_mindegrees; + if (applygravity && this.bot_aimtarg) { + if (!findtrajectorywithleading(shotorg, '0 0 0', '0 0 0', this.bot_aimtarg, shotspeed, shotspeedupward, maxshottime, 0, this)) { this.dphitcontentsmask = hf; return false; } f = bot_aimdir(this, findtrajectory_velocity - shotspeedupward * '0 0 1', r); - } - else - { + } else { f = bot_aimdir(this, v - shotorg, r); - //dprint("AIM: ");dprint(vtos(this.bot_aimtargorigin));dprint(" + ");dprint(vtos(this.bot_aimtargvelocity));dprint(" * ");dprint(ftos(this.bot_aimlatency + vlen(this.bot_aimtargorigin - shotorg) / shotspeed));dprint(" = ");dprint(vtos(v));dprint(" : aimdir = ");dprint(vtos(normalize(v - shotorg)));dprint(" : ");dprint(vtos(shotdir));dprint("\n"); - //traceline(shotorg, shotorg + shotdir * 10000, false, this); - //if (trace_ent.takedamage) - //if (trace_fraction < 1) - //if (!bot_shouldattack(this, trace_ent)) + // dprint("AIM: ");dprint(vtos(this.bot_aimtargorigin));dprint(" + ");dprint(vtos(this.bot_aimtargvelocity));dprint(" * ");dprint(ftos(this.bot_aimlatency + vlen(this.bot_aimtargorigin - shotorg) / shotspeed));dprint(" = ");dprint(vtos(v));dprint(" : aimdir = ");dprint(vtos(normalize(v - shotorg)));dprint(" : ");dprint(vtos(shotdir));dprint("\n"); + // traceline(shotorg, shotorg + shotdir * 10000, false, this); + // if (trace_ent.takedamage) + // if (trace_fraction < 1) + // if (!bot_shouldattack(this, trace_ent)) // return false; traceline(shotorg, this.bot_aimtargorigin, false, this); - if (trace_fraction < 1) - if (trace_ent != this.enemy) - if (!bot_shouldattack(this, trace_ent)) - { - this.dphitcontentsmask = hf; - return false; + if (trace_fraction < 1) { + if (trace_ent != this.enemy) { + if (!bot_shouldattack(this, trace_ent)) { + this.dphitcontentsmask = hf; + return false; + } + } } } - //if (r > maxshottime * shotspeed) + // if (r > maxshottime * shotspeed) // return false; this.dphitcontentsmask = hf; return true; diff --git a/qcsrc/server/bot/default/aim.qh b/qcsrc/server/bot/default/aim.qh index e7c60758a..393889fd1 100644 --- a/qcsrc/server/bot/default/aim.qh +++ b/qcsrc/server/bot/default/aim.qh @@ -8,7 +8,6 @@ entity tracetossfaketarget; vector findtrajectory_velocity; - vector shotorg; vector shotdir; @@ -74,8 +73,8 @@ vector shotdir; .vector bot_5th_order_aimfilter; .vector bot_olddesiredang; -//.vector bot_aimorigin; -//.vector bot_aimvelocity; +// .vector bot_aimorigin; +// .vector bot_aimvelocity; .vector bot_aimtargorigin; .vector bot_aimtargvelocity; diff --git a/qcsrc/server/bot/default/scripting.qc b/qcsrc/server/bot/default/scripting.qc index 3d9aa50d3..a73b09464 100644 --- a/qcsrc/server/bot/default/scripting.qc +++ b/qcsrc/server/bot/default/scripting.qc @@ -19,8 +19,9 @@ void bot_clearqueue(entity bot) { - if(!bot.bot_cmdqueuebuf_allocated) + if (!bot.bot_cmdqueuebuf_allocated) { return; + } buf_del(bot.bot_cmdqueuebuf); bot.bot_cmdqueuebuf_allocated = false; LOG_TRACE("bot ", bot.netname, " queue cleared"); @@ -28,8 +29,7 @@ void bot_clearqueue(entity bot) void bot_queuecommand(entity bot, string cmdstring) { - if(!bot.bot_cmdqueuebuf_allocated) - { + if (!bot.bot_cmdqueuebuf_allocated) { bot.bot_cmdqueuebuf = buf_create(); bot.bot_cmdqueuebuf_allocated = true; bot.bot_cmdqueuebuf_start = 0; @@ -46,18 +46,16 @@ void bot_queuecommand(entity bot, string cmdstring) string cmdstr; sp = strstrofs(cmdstring, " ", 0); - if(sp >= 0) - { + if (sp >= 0) { parm = substring(cmdstring, sp + 1, -1); cmdstr = substring(cmdstring, 0, sp); - if(cmdstr == "sound") - { + if (cmdstr == "sound") { // find the LAST word - for (;;) - { + for ( ; ; ) { sp = strstrofs(parm, " ", 0); - if(sp < 0) + if (sp < 0) { break; + } parm = substring(parm, sp + 1, -1); } precache_sound(parm); @@ -70,38 +68,49 @@ void bot_queuecommand(entity bot, string cmdstring) void bot_dequeuecommand(entity bot, float idx) { - if(!bot.bot_cmdqueuebuf_allocated) + if (!bot.bot_cmdqueuebuf_allocated) { error("dequeuecommand but no queue allocated"); - if(idx < bot.bot_cmdqueuebuf_start) + } + if (idx < bot.bot_cmdqueuebuf_start) { error("dequeueing a command in the past"); - if(idx >= bot.bot_cmdqueuebuf_end) + } + if (idx >= bot.bot_cmdqueuebuf_end) { error("dequeueing a command in the future"); + } bufstr_set(bot.bot_cmdqueuebuf, idx, ""); - if(idx == bot.bot_cmdqueuebuf_start) + if (idx == bot.bot_cmdqueuebuf_start) { bot.bot_cmdqueuebuf_start += 1; - if(bot.bot_cmdqueuebuf_start >= bot.bot_cmdqueuebuf_end) + } + if (bot.bot_cmdqueuebuf_start >= bot.bot_cmdqueuebuf_end) { bot_clearqueue(bot); + } } string bot_readcommand(entity bot, float idx) { - if(!bot.bot_cmdqueuebuf_allocated) + if (!bot.bot_cmdqueuebuf_allocated) { error("readcommand but no queue allocated"); - if(idx < bot.bot_cmdqueuebuf_start) + } + if (idx < bot.bot_cmdqueuebuf_start) { error("reading a command in the past"); - if(idx >= bot.bot_cmdqueuebuf_end) + } + if (idx >= bot.bot_cmdqueuebuf_end) { error("reading a command in the future"); + } return bufstr_get(bot.bot_cmdqueuebuf, idx); } bool bot_havecommand(entity this, int idx) { - if(!this.bot_cmdqueuebuf_allocated) + if (!this.bot_cmdqueuebuf_allocated) { return false; - if(idx < this.bot_cmdqueuebuf_start) + } + if (idx < this.bot_cmdqueuebuf_start) { return false; - if(idx >= this.bot_cmdqueuebuf_end) + } + if (idx >= this.bot_cmdqueuebuf_end) { return false; + } return true; } @@ -112,40 +121,39 @@ const int MAX_BOT_PLACES = 4; entity bot_getplace(entity this, string placename) { entity e; - if(substring(placename, 0, 1) == "@") - { + if (substring(placename, 0, 1) == "@") { int i, p; placename = substring(placename, 1, -1); string s, s2; - for(i = 0; i < this.bot_places_count; ++i) - if(this.(bot_placenames[i]) == placename) + for (i = 0; i < this.bot_places_count; ++i) { + if (this.(bot_placenames[i]) == placename) { return this.(bot_places[i]); + } + } // now: i == this.bot_places_count s = s2 = cvar_string(placename); p = strstrofs(s2, " ", 0); - if(p >= 0) - { + if (p >= 0) { s = substring(s2, 0, p); - //print("places: ", placename, " -> ", cvar_string(placename), "\n"); - cvar_set(placename, strcat(substring(s2, p+1, -1), " ", s)); - //print("places: ", placename, " := ", cvar_string(placename), "\n"); + // print("places: ", placename, " -> ", cvar_string(placename), "\n"); + cvar_set(placename, strcat(substring(s2, p + 1, -1), " ", s)); + // print("places: ", placename, " := ", cvar_string(placename), "\n"); } e = find(NULL, targetname, s); - if(!e) + if (!e) { LOG_INFO("invalid place ", s); - if(i < MAX_BOT_PLACES) - { + } + if (i < MAX_BOT_PLACES) { this.(bot_placenames[i]) = strzone(placename); this.(bot_places[i]) = e; this.bot_places_count += 1; } return e; - } - else - { + } else { e = find(NULL, targetname, placename); - if(!e) + if (!e) { LOG_INFO("invalid place ", placename); + } return e; } } @@ -247,16 +255,16 @@ entity find_bot_by_number(float number) entity bot; float c = 0; - if(!number) + if (!number) { return NULL; + } bot = findchainflags(flags, FL_CLIENT); // TODO: doesn't findchainflags loop backwards through entities? - while (bot) - { - if(IS_BOT_CLIENT(bot)) - { - if(++c==number) + while (bot) { + if (IS_BOT_CLIENT(bot)) { + if (++c == number) { return bot; + } } bot = bot.chain; } @@ -271,29 +279,26 @@ float bot_decodecommand(string cmdstring) string parm; sp = strstrofs(cmdstring, " ", 0); - if(sp < 0) - { + if (sp < 0) { parm = ""; - } - else - { + } else { parm = substring(cmdstring, sp + 1, -1); cmdstring = substring(cmdstring, 0, sp); } - if(!bot_cmds_initialized) + if (!bot_cmds_initialized) { bot_commands_init(); + } int i; - for(i=1;i<BOT_CMD_COUNTER;++i) - { - if(bot_cmd_string[i]!=cmdstring) + for (i = 1; i < BOT_CMD_COUNTER; ++i) { + if (bot_cmd_string[i] != cmdstring) { continue; + } cmd_parm_type = bot_cmd_parm_type[i]; - if(cmd_parm_type!=BOT_CMD_PARAMETER_NONE&&parm=="") - { + if (cmd_parm_type != BOT_CMD_PARAMETER_NONE && parm == "") { LOG_INFO("ERROR: A parameter is required for this command"); return 0; } @@ -302,19 +307,18 @@ float bot_decodecommand(string cmdstring) bot_cmd.bot_cmd_type = i; // Attach parameter - switch(cmd_parm_type) - { + switch (cmd_parm_type) { case BOT_CMD_PARAMETER_FLOAT: bot_cmd.bot_cmd_parm_float = stof(parm); break; case BOT_CMD_PARAMETER_STRING: - if(bot_cmd.bot_cmd_parm_string) + if (bot_cmd.bot_cmd_parm_string) { strunzone(bot_cmd.bot_cmd_parm_string); + } bot_cmd.bot_cmd_parm_string = strzone(parm); break; case BOT_CMD_PARAMETER_VECTOR: - if(substring(parm, 0, 1) != "\'") - { + if (substring(parm, 0, 1) != "\'") { LOG_INFOF("ERROR: expected vector type \'x y z\', got %s", parm); return 0; } @@ -334,18 +338,18 @@ void bot_cmdhelp(string scmd) int i, ntype; string stype; - if(!bot_cmds_initialized) + if (!bot_cmds_initialized) { bot_commands_init(); + } - for(i=1;i<BOT_CMD_COUNTER;++i) - { - if(bot_cmd_string[i]!=scmd) + for (i = 1; i < BOT_CMD_COUNTER; ++i) { + if (bot_cmd_string[i] != scmd) { continue; + } ntype = bot_cmd_parm_type[i]; - switch(ntype) - { + switch (ntype) { case BOT_CMD_PARAMETER_FLOAT: stype = "float number"; break; @@ -361,12 +365,11 @@ void bot_cmdhelp(string scmd) } string prelude = strcat( - "Command: ", bot_cmd_string[i], "\n", - "Parameter: <", stype, ">", "\n", - "Description: " - ); - switch(i) - { + "Command: ", bot_cmd_string[i], "\n", + "Parameter: <", stype, ">", "\n", + "Description: " + ); + switch (i) { case BOT_CMD_PAUSE: LOG_INFO(prelude, "Stops the bot completely. Any command other than 'continue' will be ignored."); break; @@ -399,18 +402,18 @@ void bot_cmdhelp(string scmd) break; case BOT_CMD_IF: LOG_INFO(prelude, "Perform simple conditional execution.\n" - "Syntax: \n" - " sv_cmd .. if \"condition\"\n" - " sv_cmd .. <instruction if true>\n" - " sv_cmd .. <instruction if true>\n" - " sv_cmd .. else\n" - " sv_cmd .. <instruction if false>\n" - " sv_cmd .. <instruction if false>\n" - " sv_cmd .. fi\n" - "Conditions: a=b, a>b, a<b, a\t\t(spaces not allowed)\n" - " Values in conditions can be numbers, cvars in the form cvar.cvar_string or special fields\n" - "Fields: health, speed, flagcarrier\n" - "Examples: if health>50; if health>cvar.g_balance_laser_primary_damage; if flagcarrier;" + "Syntax: \n" + " sv_cmd .. if \"condition\"\n" + " sv_cmd .. <instruction if true>\n" + " sv_cmd .. <instruction if true>\n" + " sv_cmd .. else\n" + " sv_cmd .. <instruction if false>\n" + " sv_cmd .. <instruction if false>\n" + " sv_cmd .. fi\n" + "Conditions: a=b, a>b, a<b, a\t\t(spaces not allowed)\n" + " Values in conditions can be numbers, cvars in the form cvar.cvar_string or special fields\n" + "Fields: health, speed, flagcarrier\n" + "Examples: if health>50; if health>cvar.g_balance_laser_primary_damage; if flagcarrier;" ); break; case BOT_CMD_RESETAIM: @@ -418,9 +421,9 @@ void bot_cmdhelp(string scmd) break; case BOT_CMD_AIM: LOG_INFO(prelude, "Move the aim x/y (horizontal/vertical) degrees relatives to the bot\n" - "There is a 3rd optional parameter telling in how many seconds the aim has to reach the new position\n" - "Examples: aim \"90 0\" // Turn 90 degrees inmediately (positive numbers move to the left/up)\n" - " aim \"0 90 2\" // Will gradually look to the sky in the next two seconds" + "There is a 3rd optional parameter telling in how many seconds the aim has to reach the new position\n" + "Examples: aim \"90 0\" // Turn 90 degrees inmediately (positive numbers move to the left/up)\n" + " aim \"0 90 2\" // Will gradually look to the sky in the next two seconds" ); break; case BOT_CMD_AIMTARGET: @@ -452,18 +455,17 @@ void bot_list_commands() int i; string ptype; - if(!bot_cmds_initialized) + if (!bot_cmds_initialized) { bot_commands_init(); + } LOG_INFO( - "List of all available commands:\n" - " Command - Parameter Type\n" - ); + "List of all available commands:\n" + " Command - Parameter Type\n" + ); - for(i=1;i<BOT_CMD_COUNTER;++i) - { - switch(bot_cmd_parm_type[i]) - { + for (i = 1; i < BOT_CMD_COUNTER; ++i) { + switch (bot_cmd_parm_type[i]) { case BOT_CMD_PARAMETER_FLOAT: ptype = "float number"; break; @@ -477,7 +479,7 @@ void bot_list_commands() ptype = "none"; break; } - LOG_INFO(" ", bot_cmd_string[i]," - <", ptype, ">"); + LOG_INFO(" ", bot_cmd_string[i], " - <", ptype, ">"); } } @@ -506,15 +508,13 @@ float bot_cmd_continue(entity this) .float bot_cmd_wait_time; float bot_cmd_wait(entity this) { - if(this.bot_exec_status & BOT_EXEC_STATUS_WAITING) - { - if(time>=this.bot_cmd_wait_time) - { + if (this.bot_exec_status & BOT_EXEC_STATUS_WAITING) { + if (time >= this.bot_cmd_wait_time) { this.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING; return CMD_STATUS_FINISHED; - } - else + } else { return CMD_STATUS_EXECUTING; + } } this.bot_cmd_wait_time = time + bot_cmd.bot_cmd_parm_float; @@ -524,8 +524,7 @@ float bot_cmd_wait(entity this) float bot_cmd_wait_until(entity this) { - if(time < bot_cmd.bot_cmd_parm_float + bot_barriertime) - { + if (time < bot_cmd.bot_cmd_parm_float + bot_barriertime) { this.bot_exec_status |= BOT_EXEC_STATUS_WAITING; return CMD_STATUS_EXECUTING; } @@ -537,25 +536,26 @@ float bot_cmd_barrier(entity this) { // 0 = no barrier, 1 = waiting, 2 = waiting finished - if(this.bot_barrier == 0) // initialization - { + if (this.bot_barrier == 0) { // initialization this.bot_barrier = 1; - //this.colormod = '4 4 0'; + // this.colormod = '4 4 0'; } - if(this.bot_barrier == 1) // find other bots - { + if (this.bot_barrier == 1) { // find other bots FOREACH_CLIENT(it.isbot, { - if(it.bot_cmdqueuebuf_allocated) - if(it.bot_barrier != 1) - return CMD_STATUS_EXECUTING; // not all are at the barrier yet + if (it.bot_cmdqueuebuf_allocated) { + if (it.bot_barrier != 1) { + return CMD_STATUS_EXECUTING; // not all are at the barrier yet + } + } }); // all bots hit the barrier! // acknowledge barrier - FOREACH_CLIENT(it.isbot, { it.bot_barrier = 2; }); + FOREACH_CLIENT(it.isbot, { it.bot_barrier = 2; + }); bot_barriertime = time; } @@ -563,7 +563,7 @@ float bot_cmd_barrier(entity this) // if we get here, the barrier is finished // so end it... this.bot_barrier = 0; - //this.colormod = '0 0 0'; + // this.colormod = '0 0 0'; return CMD_STATUS_FINISHED; } @@ -579,26 +579,27 @@ float bot_cmd_select_weapon(entity this) { float id = bot_cmd.bot_cmd_parm_float; - if(id < WEP_FIRST || id > WEP_LAST) + if (id < WEP_FIRST || id > WEP_LAST) { return CMD_STATUS_ERROR; + } bool success = false; - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { .entity weaponentity = weaponentities[slot]; - if(this.(weaponentity).m_weapon == WEP_Null && slot != 0) + if (this.(weaponentity).m_weapon == WEP_Null && slot != 0) { continue; + } - if(client_hasweapon(this, Weapons_from(id), weaponentity, true, false)) - { + if (client_hasweapon(this, Weapons_from(id), weaponentity, true, false)) { success = true; this.(weaponentity).m_switchweapon = Weapons_from(id); } } - if(!success) + if (!success) { return CMD_STATUS_ERROR; + } return CMD_STATUS_FINISHED; } @@ -614,22 +615,23 @@ const int CMD_CONDITION_false_BLOCK = 8; float bot_cmd_eval(entity this, string expr) { // Search for numbers - if(IS_DIGIT(substring(expr, 0, 1))) + if (IS_DIGIT(substring(expr, 0, 1))) { return stof(expr); + } // Search for cvars - if(substring(expr, 0, 5)=="cvar.") + if (substring(expr, 0, 5) == "cvar.") { return cvar(substring(expr, 5, strlen(expr))); + } // Search for fields - switch(expr) - { + switch (expr) { case "health": return this.health; case "speed": return vlen(this.velocity); case "flagcarrier": - return ((this.flagcarried!=NULL)); + return (this.flagcarried != NULL); } LOG_INFO("ERROR: Unable to convert the expression '", expr, "' into a numeric value"); @@ -641,8 +643,7 @@ float bot_cmd_if(entity this) string expr, val_a, val_b; float cmpofs; - if(this.bot_cmd_condition_status != CMD_CONDITION_NONE) - { + if (this.bot_cmd_condition_status != CMD_CONDITION_NONE) { // Only one "if" block is allowed at time LOG_INFO("ERROR: Only one conditional block can be processed at time"); bot_clearqueue(this); @@ -654,57 +655,58 @@ float bot_cmd_if(entity this) // search for operators expr = bot_cmd.bot_cmd_parm_string; - cmpofs = strstrofs(expr,"=",0); + cmpofs = strstrofs(expr, "=", 0); - if(cmpofs>0) - { - val_a = substring(expr,0,cmpofs); - val_b = substring(expr,cmpofs+1,strlen(expr)); + if (cmpofs > 0) { + val_a = substring(expr, 0, cmpofs); + val_b = substring(expr, cmpofs + 1, strlen(expr)); - if(bot_cmd_eval(this, val_a)==bot_cmd_eval(this, val_b)) + if (bot_cmd_eval(this, val_a) == bot_cmd_eval(this, val_b)) { this.bot_cmd_condition_status |= CMD_CONDITION_true; - else + } else { this.bot_cmd_condition_status |= CMD_CONDITION_false; + } - return CMD_STATUS_FINISHED; + return CMD_STATUS_FINISHED; } - cmpofs = strstrofs(expr,">",0); + cmpofs = strstrofs(expr, ">", 0); - if(cmpofs>0) - { - val_a = substring(expr,0,cmpofs); - val_b = substring(expr,cmpofs+1,strlen(expr)); + if (cmpofs > 0) { + val_a = substring(expr, 0, cmpofs); + val_b = substring(expr, cmpofs + 1, strlen(expr)); - if(bot_cmd_eval(this, val_a)>bot_cmd_eval(this, val_b)) + if (bot_cmd_eval(this, val_a) > bot_cmd_eval(this, val_b)) { this.bot_cmd_condition_status |= CMD_CONDITION_true; - else + } else { this.bot_cmd_condition_status |= CMD_CONDITION_false; + } return CMD_STATUS_FINISHED; } - cmpofs = strstrofs(expr,"<",0); + cmpofs = strstrofs(expr, "<", 0); - if(cmpofs>0) - { - val_a = substring(expr,0,cmpofs); - val_b = substring(expr,cmpofs+1,strlen(expr)); + if (cmpofs > 0) { + val_a = substring(expr, 0, cmpofs); + val_b = substring(expr, cmpofs + 1, strlen(expr)); - if(bot_cmd_eval(this, val_a)<bot_cmd_eval(this, val_b)) + if (bot_cmd_eval(this, val_a) < bot_cmd_eval(this, val_b)) { this.bot_cmd_condition_status |= CMD_CONDITION_true; - else + } else { this.bot_cmd_condition_status |= CMD_CONDITION_false; + } - return CMD_STATUS_FINISHED; + return CMD_STATUS_FINISHED; } - if(bot_cmd_eval(this, expr)) + if (bot_cmd_eval(this, expr)) { this.bot_cmd_condition_status |= CMD_CONDITION_true; - else + } else { this.bot_cmd_condition_status |= CMD_CONDITION_false; + } - return CMD_STATUS_FINISHED; + return CMD_STATUS_FINISHED; } float bot_cmd_else(entity this) @@ -734,20 +736,18 @@ float bot_cmd_resetaim(entity this) float bot_cmd_aim(entity this) { // Current direction - if(this.bot_cmd_aim_endtime) - { + if (this.bot_cmd_aim_endtime) { float progress; - progress = min(1 - (this.bot_cmd_aim_endtime - time) / (this.bot_cmd_aim_endtime - this.bot_cmd_aim_begintime),1); + progress = min(1 - (this.bot_cmd_aim_endtime - time) / (this.bot_cmd_aim_endtime - this.bot_cmd_aim_begintime), 1); this.v_angle = this.bot_cmd_aim_begin + ((this.bot_cmd_aim_end - this.bot_cmd_aim_begin) * progress); - if(time>=this.bot_cmd_aim_endtime) - { + if (time >= this.bot_cmd_aim_endtime) { this.bot_cmd_aim_endtime = 0; return CMD_STATUS_FINISHED; - } - else + } else { return CMD_STATUS_EXECUTING; + } } // New aiming direction @@ -758,13 +758,13 @@ float bot_cmd_aim(entity this) tokens = tokenizebyseparator(parms, " "); - if(tokens<2||tokens>3) + if (tokens < 2 || tokens > 3) { return CMD_STATUS_ERROR; + } step = (tokens == 3) ? stof(argv(2)) : 0; - if(step == 0) - { + if (step == 0) { this.v_angle_x -= stof(argv(1)); this.v_angle_y += stof(argv(0)); return CMD_STATUS_FINISHED; @@ -784,8 +784,7 @@ float bot_cmd_aim(entity this) float bot_cmd_aimtarget(entity this) { - if(this.bot_cmd_aim_endtime) - { + if (this.bot_cmd_aim_endtime) { return bot_cmd_aim(this); } @@ -799,20 +798,21 @@ float bot_cmd_aimtarget(entity this) tokens = tokenizebyseparator(parms, " "); e = bot_getplace(this, argv(0)); - if(!e) + if (!e) { return CMD_STATUS_ERROR; + } v = e.origin + (e.mins + e.maxs) * 0.5; - if(tokens==1) - { + if (tokens == 1) { this.v_angle = vectoangles(v - (this.origin + this.view_ofs)); this.v_angle_x = -this.v_angle.x; return CMD_STATUS_FINISHED; } - if(tokens<1||tokens>2) + if (tokens < 1 || tokens > 2) { return CMD_STATUS_ERROR; + } step = stof(argv(1)); @@ -828,18 +828,18 @@ float bot_cmd_aimtarget(entity this) .int bot_cmd_keys; -const int BOT_CMD_KEY_NONE = 0; -const int BOT_CMD_KEY_FORWARD = BIT(0); -const int BOT_CMD_KEY_BACKWARD = BIT(1); -const int BOT_CMD_KEY_RIGHT = BIT(2); -const int BOT_CMD_KEY_LEFT = BIT(3); -const int BOT_CMD_KEY_JUMP = BIT(4); -const int BOT_CMD_KEY_ATTACK1 = BIT(5); -const int BOT_CMD_KEY_ATTACK2 = BIT(6); -const int BOT_CMD_KEY_USE = BIT(7); -const int BOT_CMD_KEY_HOOK = BIT(8); -const int BOT_CMD_KEY_CROUCH = BIT(9); -const int BOT_CMD_KEY_CHAT = BIT(10); +const int BOT_CMD_KEY_NONE = 0; +const int BOT_CMD_KEY_FORWARD = BIT(0); +const int BOT_CMD_KEY_BACKWARD = BIT(1); +const int BOT_CMD_KEY_RIGHT = BIT(2); +const int BOT_CMD_KEY_LEFT = BIT(3); +const int BOT_CMD_KEY_JUMP = BIT(4); +const int BOT_CMD_KEY_ATTACK1 = BIT(5); +const int BOT_CMD_KEY_ATTACK2 = BIT(6); +const int BOT_CMD_KEY_USE = BIT(7); +const int BOT_CMD_KEY_HOOK = BIT(8); +const int BOT_CMD_KEY_CROUCH = BIT(9); +const int BOT_CMD_KEY_CHAT = BIT(10); bool bot_presskeys(entity this) { @@ -852,39 +852,49 @@ bool bot_presskeys(entity this) PHYS_INPUT_BUTTON_HOOK(this) = false; PHYS_INPUT_BUTTON_CHAT(this) = false; - if(this.bot_cmd_keys == BOT_CMD_KEY_NONE) + if (this.bot_cmd_keys == BOT_CMD_KEY_NONE) { return false; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_FORWARD) + if (this.bot_cmd_keys & BOT_CMD_KEY_FORWARD) { CS(this).movement_x = autocvar_sv_maxspeed; - else if(this.bot_cmd_keys & BOT_CMD_KEY_BACKWARD) + } else if (this.bot_cmd_keys & BOT_CMD_KEY_BACKWARD) { CS(this).movement_x = -autocvar_sv_maxspeed; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_RIGHT) + if (this.bot_cmd_keys & BOT_CMD_KEY_RIGHT) { CS(this).movement_y = autocvar_sv_maxspeed; - else if(this.bot_cmd_keys & BOT_CMD_KEY_LEFT) + } else if (this.bot_cmd_keys & BOT_CMD_KEY_LEFT) { CS(this).movement_y = -autocvar_sv_maxspeed; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_JUMP) + if (this.bot_cmd_keys & BOT_CMD_KEY_JUMP) { PHYS_INPUT_BUTTON_JUMP(this) = true; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_CROUCH) + if (this.bot_cmd_keys & BOT_CMD_KEY_CROUCH) { PHYS_INPUT_BUTTON_CROUCH(this) = true; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_ATTACK1) + if (this.bot_cmd_keys & BOT_CMD_KEY_ATTACK1) { PHYS_INPUT_BUTTON_ATCK(this) = true; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_ATTACK2) + if (this.bot_cmd_keys & BOT_CMD_KEY_ATTACK2) { PHYS_INPUT_BUTTON_ATCK2(this) = true; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_USE) + if (this.bot_cmd_keys & BOT_CMD_KEY_USE) { PHYS_INPUT_BUTTON_USE(this) = true; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_HOOK) + if (this.bot_cmd_keys & BOT_CMD_KEY_HOOK) { PHYS_INPUT_BUTTON_HOOK(this) = true; + } - if(this.bot_cmd_keys & BOT_CMD_KEY_CHAT) + if (this.bot_cmd_keys & BOT_CMD_KEY_CHAT) { PHYS_INPUT_BUTTON_CHAT(this) = true; + } return true; } @@ -892,90 +902,93 @@ bool bot_presskeys(entity this) float bot_cmd_keypress_handler(entity this, string key, float enabled) { - switch(key) - { + switch (key) { case "all": - if(enabled) + if (enabled) { this.bot_cmd_keys = POW(2, 20) - 1; // >:) - else + } else { this.bot_cmd_keys = BOT_CMD_KEY_NONE; + } case "forward": - if(enabled) - { + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_FORWARD; this.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD; - } - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD; + } break; case "backward": - if(enabled) - { + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_BACKWARD; this.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD; - } - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD; + } break; case "left": - if(enabled) - { + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_LEFT; this.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT; - } - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT; + } break; case "right": - if(enabled) - { + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_RIGHT; this.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT; - } - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT; + } break; case "jump": - if(enabled) + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_JUMP; - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_JUMP; + } break; case "crouch": - if(enabled) + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_CROUCH; - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_CROUCH; + } break; case "attack1": - if(enabled) + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_ATTACK1; - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK1; + } break; case "attack2": - if(enabled) + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_ATTACK2; - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK2; + } break; case "use": - if(enabled) + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_USE; - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_USE; + } break; case "hook": - if(enabled) + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_HOOK; - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_HOOK; + } break; case "chat": - if(enabled) + if (enabled) { this.bot_cmd_keys |= BOT_CMD_KEY_CHAT; - else + } else { this.bot_cmd_keys &= ~BOT_CMD_KEY_CHAT; + } break; default: break; @@ -990,7 +1003,7 @@ float bot_cmd_presskey(entity this) key = bot_cmd.bot_cmd_parm_string; - bot_cmd_keypress_handler(this, key,true); + bot_cmd_keypress_handler(this, key, true); return CMD_STATUS_FINISHED; } @@ -1001,7 +1014,7 @@ float bot_cmd_releasekey(entity this) key = bot_cmd.bot_cmd_parm_string; - return bot_cmd_keypress_handler(this, key,false); + return bot_cmd_keypress_handler(this, key, false); } float bot_cmd_pause(entity this) @@ -1032,8 +1045,9 @@ float bot_cmd_movetotarget(entity this) { entity e; e = bot_getplace(this, bot_cmd.bot_cmd_parm_string); - if(!e) + if (!e) { return CMD_STATUS_ERROR; + } return this.cmd_moveto(this, e.origin + (e.mins + e.maxs) * 0.5); } @@ -1055,14 +1069,18 @@ float bot_cmd_sound(entity this) float vol = VOL_BASE; float atten = ATTEN_MIN; - if(n >= 1) + if (n >= 1) { sample = argv(n - 1); - if(n >= 2) + } + if (n >= 2) { chan = stof(argv(0)); - if(n >= 3) + } + if (n >= 3) { vol = stof(argv(1)); - if(n >= 4) + } + if (n >= 4) { atten = stof(argv(2)); + } precache_sound(f); _sound(this, chan, sample, vol, atten); @@ -1077,34 +1095,23 @@ float bot_cmd_debug_assert_canfire(entity this) int slot = 0; // TODO: unhardcode? .entity weaponentity = weaponentities[slot]; - if(this.(weaponentity).state != WS_READY) - { - if(f) - { + if (this.(weaponentity).state != WS_READY) { + if (f) { this.colormod = '0 8 8'; LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by weaponentity state"); } - } - else if(ATTACK_FINISHED(this, slot) > time) - { - if(f) - { + } else if (ATTACK_FINISHED(this, slot) > time) { + if (f) { this.colormod = '8 0 8'; LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left)"); } - } - else if(this.(weaponentity).tuba_note) - { - if(f) - { + } else if (this.(weaponentity).tuba_note) { + if (f) { this.colormod = '8 0 0'; LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, bot still has an active tuba note"); } - } - else - { - if(!f) - { + } else { + if (!f) { this.colormod = '8 8 0'; LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left"); } @@ -1121,8 +1128,9 @@ void bot_command_executed(entity this, bool rm) cmd = bot_cmd; - if(rm) + if (rm) { bot_dequeuecommand(this, this.bot_cmd_execution_index); + } this.bot_cmd_execution_index++; } @@ -1131,33 +1139,27 @@ void bot_setcurrentcommand(entity this) { bot_cmd = NULL; - if(!this.bot_cmd_current) - { + if (!this.bot_cmd_current) { this.bot_cmd_current = new_pure(bot_cmd); } bot_cmd = this.bot_cmd_current; - if(bot_cmd.bot_cmd_index != this.bot_cmd_execution_index || this.bot_cmd_execution_index == 0) - { - if(bot_havecommand(this, this.bot_cmd_execution_index)) - { + if (bot_cmd.bot_cmd_index != this.bot_cmd_execution_index || this.bot_cmd_execution_index == 0) { + if (bot_havecommand(this, this.bot_cmd_execution_index)) { string cmdstring; cmdstring = bot_readcommand(this, this.bot_cmd_execution_index); - if(bot_decodecommand(cmdstring)) - { + if (bot_decodecommand(cmdstring)) { bot_cmd.owner = this; bot_cmd.bot_cmd_index = this.bot_cmd_execution_index; - } - else - { + } else { // Invalid command, remove from queue bot_cmd = NULL; bot_dequeuecommand(this, this.bot_cmd_execution_index); this.bot_cmd_execution_index++; } - } - else + } else { bot_cmd = NULL; + } } } @@ -1168,8 +1170,7 @@ void bot_resetqueues() bot_clearqueue(it); // also, cancel all barriers it.bot_barrier = 0; - for(int i = 0; i < it.bot_places_count; ++i) - { + for (int i = 0; i < it.bot_places_count; ++i) { strunzone(it.(bot_placenames[i])); it.(bot_placenames[i]) = string_null; } @@ -1189,19 +1190,16 @@ float bot_execute_commands_once(entity this) bot_setcurrentcommand(this); // Ignore all commands except continue when the bot is paused - if(!(this.bot_exec_status & BOT_EXEC_STATUS_PAUSED)) - { + if (!(this.bot_exec_status & BOT_EXEC_STATUS_PAUSED)) { // if we have no bot command, better return // old logic kept pressing previously pressed keys, but that has problems // (namely, it means you cannot make a bot "normal" ever again) // to keep a bot walking for a while, use the "wait" bot command - if(bot_cmd == world) + if (bot_cmd == world) { return 0; - } - else if(bot_cmd.bot_cmd_type != BOT_CMD_CONTINUE) - { - if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL) - { + } + } else if (bot_cmd.bot_cmd_type != BOT_CMD_CONTINUE) { + if (bot_cmd.bot_cmd_type != BOT_CMD_NULL) { bot_command_executed(this, true); LOG_INFO("WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead."); } @@ -1212,24 +1210,21 @@ float bot_execute_commands_once(entity this) ispressingkey = boolean(bot_presskeys(this)); // Handle conditions - if (!(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE)) - if(this.bot_cmd_condition_status & CMD_CONDITION_true && this.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK) - { - bot_command_executed(this, true); - return -1; - } - else if(this.bot_cmd_condition_status & CMD_CONDITION_false && this.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK) - { - bot_command_executed(this, true); - return -1; + if (!(bot_cmd.bot_cmd_type == BOT_CMD_FI || bot_cmd.bot_cmd_type == BOT_CMD_ELSE)) { + if (this.bot_cmd_condition_status & CMD_CONDITION_true && this.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK) { + bot_command_executed(this, true); + return -1; + } else if (this.bot_cmd_condition_status & CMD_CONDITION_false && this.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK) { + bot_command_executed(this, true); + return -1; + } } // Map commands to functions - switch(bot_cmd.bot_cmd_type) - { + switch (bot_cmd.bot_cmd_type) { case BOT_CMD_NULL: return ispressingkey; - //break; + // break; case BOT_CMD_PAUSE: status = bot_cmd_pause(this); break; @@ -1305,22 +1300,18 @@ float bot_execute_commands_once(entity this) return 0; } - if (status==CMD_STATUS_ERROR) + if (status == CMD_STATUS_ERROR) { LOG_INFOF("ERROR: The command '%s' returned an error status", bot_cmd_string[bot_cmd.bot_cmd_type]); + } // Move execution pointer - if(status==CMD_STATUS_EXECUTING) - { + if (status == CMD_STATUS_EXECUTING) { return 1; - } - else - { - if(autocvar_g_debug_bot_commands) - { + } else { + if (autocvar_g_debug_bot_commands) { string parms; - switch(bot_cmd_parm_type[bot_cmd.bot_cmd_type]) - { + switch (bot_cmd_parm_type[bot_cmd.bot_cmd_type]) { case BOT_CMD_PARAMETER_FLOAT: parms = ftos(bot_cmd.bot_cmd_parm_float); break; @@ -1334,14 +1325,15 @@ float bot_execute_commands_once(entity this) parms = ""; break; } - clientcommand(this,strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type]," ",parms,"\n")); + clientcommand(this, strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type], " ", parms, "\n")); } bot_command_executed(this, true); } - if(status == CMD_STATUS_FINISHED) + if (status == CMD_STATUS_FINISHED) { return -1; + } return CMD_STATUS_ERROR; } @@ -1350,10 +1342,8 @@ float bot_execute_commands_once(entity this) int bot_execute_commands(entity this) { int f; - do - { + do { f = bot_execute_commands_once(this); - } - while(f < 0); + } while (f < 0); return f; } diff --git a/qcsrc/server/bot/default/scripting.qh b/qcsrc/server/bot/default/scripting.qh index cb5bf625f..44854fda2 100644 --- a/qcsrc/server/bot/default/scripting.qh +++ b/qcsrc/server/bot/default/scripting.qh @@ -10,35 +10,35 @@ // NOTE: New commands should be added here. Do not forget to update BOT_CMD_COUNTER -const int BOT_CMD_NULL = 0; -const int BOT_CMD_PAUSE = 1; -const int BOT_CMD_CONTINUE = 2; -const int BOT_CMD_WAIT = 3; -const int BOT_CMD_TURN = 4; -const int BOT_CMD_MOVETO = 5; -const int BOT_CMD_RESETGOAL = 6; // Not implemented yet -const int BOT_CMD_CC = 7; -const int BOT_CMD_IF = 8; -const int BOT_CMD_ELSE = 9; -const int BOT_CMD_FI = 10; -const int BOT_CMD_RESETAIM = 11; -const int BOT_CMD_AIM = 12; -const int BOT_CMD_PRESSKEY = 13; -const int BOT_CMD_RELEASEKEY = 14; -const int BOT_CMD_SELECTWEAPON = 15; -const int BOT_CMD_IMPULSE = 16; -const int BOT_CMD_WAIT_UNTIL = 17; -const int BOT_CMD_MOVETOTARGET = 18; -const int BOT_CMD_AIMTARGET = 19; -const int BOT_CMD_BARRIER = 20; -const int BOT_CMD_CONSOLE = 21; -const int BOT_CMD_SOUND = 22; +const int BOT_CMD_NULL = 0; +const int BOT_CMD_PAUSE = 1; +const int BOT_CMD_CONTINUE = 2; +const int BOT_CMD_WAIT = 3; +const int BOT_CMD_TURN = 4; +const int BOT_CMD_MOVETO = 5; +const int BOT_CMD_RESETGOAL = 6; // Not implemented yet +const int BOT_CMD_CC = 7; +const int BOT_CMD_IF = 8; +const int BOT_CMD_ELSE = 9; +const int BOT_CMD_FI = 10; +const int BOT_CMD_RESETAIM = 11; +const int BOT_CMD_AIM = 12; +const int BOT_CMD_PRESSKEY = 13; +const int BOT_CMD_RELEASEKEY = 14; +const int BOT_CMD_SELECTWEAPON = 15; +const int BOT_CMD_IMPULSE = 16; +const int BOT_CMD_WAIT_UNTIL = 17; +const int BOT_CMD_MOVETOTARGET = 18; +const int BOT_CMD_AIMTARGET = 19; +const int BOT_CMD_BARRIER = 20; +const int BOT_CMD_CONSOLE = 21; +const int BOT_CMD_SOUND = 22; const int BOT_CMD_DEBUG_ASSERT_CANFIRE = 23; -//const int BOT_CMD_WHILE = 24; // TODO: Not implemented yet -//const int BOT_CMD_WEND = 25; // TODO: Not implemented yet -//const int BOT_CMD_CHASE = 26; // TODO: Not implemented yet +// const int BOT_CMD_WHILE = 24; // TODO: Not implemented yet +// const int BOT_CMD_WEND = 25; // TODO: Not implemented yet +// const int BOT_CMD_CHASE = 26; // TODO: Not implemented yet -const int BOT_CMD_COUNTER = 24; // Update this value if you add/remove a command +const int BOT_CMD_COUNTER = 24; // Update this value if you add/remove a command // NOTE: Following commands should be implemented on the bot ai // If a new command should be handled by the target ai(s) please declare it here @@ -56,19 +56,19 @@ int bot_cmd_parm_type[BOT_CMD_COUNTER]; string bot_cmd_string[BOT_CMD_COUNTER]; // Bots command queue -entity bot_cmd; // global current command -.entity bot_cmd_current; // current command of this bot +entity bot_cmd; // global current command +.entity bot_cmd_current; // current command of this bot -.float bot_cmd_index; // Position of the command in the queue -.int bot_cmd_type; // If of command (see the BOT_CMD_* defines) -.float bot_cmd_parm_float; // Field to store a float parameter -.string bot_cmd_parm_string; // Field to store a string parameter -.vector bot_cmd_parm_vector; // Field to store a vector parameter +.float bot_cmd_index; // Position of the command in the queue +.int bot_cmd_type; // If of command (see the BOT_CMD_* defines) +.float bot_cmd_parm_float; // Field to store a float parameter +.string bot_cmd_parm_string; // Field to store a string parameter +.vector bot_cmd_parm_vector; // Field to store a vector parameter float bot_barriertime; .float bot_barrier; -.float bot_cmd_execution_index; // Position in the queue of the command to be executed +.float bot_cmd_execution_index; // Position in the queue of the command to be executed void bot_resetqueues(); diff --git a/qcsrc/server/campaign.qc b/qcsrc/server/campaign.qc index e80769cc2..7351b01d2 100644 --- a/qcsrc/server/campaign.qc +++ b/qcsrc/server/campaign.qc @@ -11,13 +11,13 @@ // campaign cvars: // _campaign_index: index of CURRENT map // _campaign_name: name of the current campaign -// g_campaign(name)_index: index of current LAST map (saved) +// g_campaign(name) _index: index of current LAST map (saved) // g_campaign_skill: bot skill offset float campaign_level; float campaign_won; string campaign_index_var; -//float checkrules_equality; +// float checkrules_equality; float CampaignBailout(string s) { @@ -26,8 +26,9 @@ float CampaignBailout(string s) cvar_set = cvar_set_normal; cvar_set("g_campaign", "0"); LOG_INFO("^4campaign initialization failed: ", s); - if(autocvar__campaign_testrun) + if (autocvar__campaign_testrun) { error("CAMPAIGN FAIL AHAHAHAHAHAHAHAHAH))"); + } return 1; } @@ -36,12 +37,14 @@ string cvar_string_campaignwrapper(string theCvar) { float p, q; p = strstrofs(cvar_campaignwrapper_list, strcat("; ", theCvar, " "), 0); - if(p < 0) + if (p < 0) { return cvar_defstring(theCvar); + } p += strlen(theCvar) + 3; q = strstrofs(cvar_campaignwrapper_list, ";", p); - if(q < 0) + if (q < 0) { return cvar_defstring(theCvar); + } return substring(cvar_campaignwrapper_list, p, q - p); } float cvar_campaignwrapper(string theCvar) @@ -50,13 +53,14 @@ float cvar_campaignwrapper(string theCvar) } void cvar_set_campaignwrapper(string theCvar, string theValue) { - if(cvar_string_campaignwrapper(theCvar) == theValue) + if (cvar_string_campaignwrapper(theCvar) == theValue) { return; + } string s; s = cvar_campaignwrapper_list; cvar_campaignwrapper_list = strzone(strcat("; ", theCvar, " ", theValue, s)); strunzone(s); - //print(cvar_campaignwrapper_list, "\n"); + // print(cvar_campaignwrapper_list, "\n"); } float Campaign_Invalid() @@ -64,11 +68,13 @@ float Campaign_Invalid() string thismapname, wantedmapname; thismapname = GetMapname(); wantedmapname = campaign_gametype[0]; - if(MapInfo_CurrentGametype() != MapInfo_Type_FromString(wantedmapname)) + if (MapInfo_CurrentGametype() != MapInfo_Type_FromString(wantedmapname)) { return CampaignBailout("wrong game type!"); + } wantedmapname = campaign_mapname[0]; - if(wantedmapname != thismapname) + if (wantedmapname != thismapname) { return CampaignBailout(strcat("wrong map: ", wantedmapname, " != ", thismapname)); + } return 0; } @@ -81,14 +87,12 @@ void CampaignPreInit() campaign_index_var = strzone(strcat("g_campaign", campaign_name, "_index")); CampaignFile_Load(campaign_level, 2); - if(campaign_entries < 1) - { + if (campaign_entries < 1) { CampaignBailout("unknown map"); return; } - if(autocvar_sv_cheats) - { + if (autocvar_sv_cheats) { MapInfo_SwitchGameType(MapInfo_Type_FromString(campaign_gametype[0])); CampaignFile_Unload(); CampaignBailout("JOLLY CHEATS AHAHAHAHAHAHAH))"); @@ -97,8 +101,9 @@ void CampaignPreInit() baseskill = autocvar_g_campaign_skill; baseskill = baseskill + campaign_botskill[0]; - if(baseskill < 0) + if (baseskill < 0) { baseskill = 0; + } cvar_set("sv_public", "0"); cvar_set("pausable", "1"); @@ -119,8 +124,9 @@ void CampaignPreInit() // with the menu a little still...) cvar_set_normal("sv_gravity", ftos(autocvar_sv_gravity)); - if(Campaign_Invalid()) + if (Campaign_Invalid()) { return; + } title = campaign_shortdesc[0]; title = strzone(strcat("Level ", ftos(campaign_level + 1), ": ", title)); @@ -131,17 +137,15 @@ void CampaignPreInit() void CampaignPostInit() { // now some sanity checks - if(Campaign_Invalid()) + if (Campaign_Invalid()) { return; - if(autocvar__campaign_testrun) - { + } + if (autocvar__campaign_testrun) { cvar_set("fraglimit", "0"); cvar_set("timelimit", "0.01"); cvar_set_normal("fraglimit", "0"); cvar_set_normal("timelimit", "0.01"); - } - else - { + } else { cvar_set("fraglimit", ftos(campaign_fraglimit[0])); cvar_set("timelimit", ftos(campaign_timelimit[0])); cvar_set_normal("fraglimit", ftos(campaign_fraglimit[0])); @@ -162,29 +166,27 @@ void CampaignSaveCvar(string cvarname, float value) fh = fopen("campaign.cfg", FILE_READ); contents = ""; - if(fh >= 0) - { - while((l = fgets(fh))) - { + if (fh >= 0) { + while ((l = fgets(fh))) { len = tokenize_console(l); - if(len != 3) + if (len != 3) { continue; - if(argv(0) != "set") + } + if (argv(0) != "set") { continue; - if(argv(1) == cvarname) + } + if (argv(1) == cvarname) { continue; + } contents = strcat(contents, "set ", argv(1), " ", argv(2), "\n"); } fclose(fh); } contents = strcat(contents, "set ", cvarname, " ", ftos(value), "\n"); fh = fopen("campaign.cfg", FILE_WRITE); - if(fh >= 0) - { + if (fh >= 0) { fputs(fh, contents); - } - else - { + } else { error("Cannot write to campaign file"); } } @@ -196,59 +198,45 @@ void CampaignPreIntermission() string savevar; FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { - if(it.winning) + if (it.winning) { won += 1; - else + } else { lost += 1; + } }); - if(autocvar__campaign_testrun) - { + if (autocvar__campaign_testrun) { campaign_won = 1; bprint("Campaign test run, advancing level.\n"); - } - else if(won == 1 && lost == 0 && checkrules_equality == 0) - { - if(autocvar_timelimit != 0 && autocvar_fraglimit != 0 && time > autocvar_timelimit * 60) // checks if the timelimit has expired. - { + } else if (won == 1 && lost == 0 && checkrules_equality == 0) { + if (autocvar_timelimit != 0 && autocvar_fraglimit != 0 && time > autocvar_timelimit * 60) { // checks if the timelimit has expired. campaign_won = 0; bprint("Time's up! The current level has been LOST.\n"); // sound! - } - else - { + } else { campaign_won = 1; bprint("The current level has been WON.\n"); // sound! } - } - else if(autocvar_timelimit != 0 && time > autocvar_timelimit * 60) - { + } else if (autocvar_timelimit != 0 && time > autocvar_timelimit * 60) { campaign_won = 0; bprint("Time's up! The current level has been LOST.\n"); // sound! - } - else - { + } else { campaign_won = 0; bprint("The current level has been LOST.\n"); // sound! } - if(campaign_won && cheatcount_total == 0 && !autocvar__campaign_testrun) - { - if(campaign_level == cvar_normal(campaign_index_var)) - { - if(campaign_entries < 2) - { + if (campaign_won && cheatcount_total == 0 && !autocvar__campaign_testrun) { + if (campaign_level == cvar_normal(campaign_index_var)) { + if (campaign_entries < 2) { // I have won savevar = strcat("g_campaign", campaign_name, "_won"); CampaignSaveCvar(savevar, 1); // advance level (for menu to show it right) CampaignSaveCvar(campaign_index_var, campaign_level + 1); - } - else - { + } else { // advance level CampaignSaveCvar(campaign_index_var, campaign_level + 1); } @@ -260,8 +248,7 @@ void CampaignPostIntermission() { // NOTE: campaign_won is 0 or 1, that is, points to the next level - if(campaign_won && campaign_entries < 2) - { + if (campaign_won && campaign_entries < 2) { // last map won! LOG_DEBUG("^2test run: campaign looks GOOD"); localcmd("togglemenu 1\n"); @@ -278,17 +265,17 @@ void CampaignPostIntermission() } - void CampaignLevelWarp(float n) { - if(n < 0) + if (n < 0) { n = campaign_level + 1; + } CampaignFile_Unload(); CampaignFile_Load(n, 1); - if(campaign_entries) + if (campaign_entries) { CampaignSetup(0); - else + } else { error("Sorry, cheater. You are NOT WELCOME."); + } CampaignFile_Unload(); } - diff --git a/qcsrc/server/cheats.qh b/qcsrc/server/cheats.qh index 1bf080641..03f13f5fc 100644 --- a/qcsrc/server/cheats.qh +++ b/qcsrc/server/cheats.qh @@ -2,7 +2,7 @@ #include <common/impulses/all.qh> -//float autocvar_sv_cheats; // must... declare... global +// float autocvar_sv_cheats; // must... declare... global float cheatcount_total; .float cheatcount; diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index 2282c09cb..4e22ceacd 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -6,222 +6,232 @@ void ClientState_attach(entity this); IntrusiveList g_players; -STATIC_INIT(g_players) { g_players = IL_NEW(); } +STATIC_INIT(g_players) +{ + g_players = IL_NEW(); +} CLASS(Client, Object) - /** Client name */ - ATTRIB(Client, netname, string, this.netname); - ATTRIB(Client, colormap, int, this.colormap); - ATTRIB(Client, team, int, this.team); - ATTRIB(Client, clientcolors, int, this.clientcolors); - /** Client IP */ - ATTRIB(Client, netaddress, string, this.netaddress); - ATTRIB(Client, playermodel, string, this.playermodel); - ATTRIB(Client, playerskin, int, this.playerskin); - - /** fingerprint of CA key the player used to authenticate */ - ATTRIB(Client, crypto_keyfp, string, this.crypto_keyfp); - /** fingerprint of CA key the server used to authenticate to the player */ - ATTRIB(Client, crypto_mykeyfp, string, this.crypto_mykeyfp); - /** fingerprint of ID used by the player entity, or string_null if not identified */ - ATTRIB(Client, crypto_idfp, string, this.crypto_idfp); - /** set if the player's ID has been signed */ - ATTRIB(Client, crypto_idfp_signed, bool, this.crypto_idfp_signed); - /** the string "AES128" if encrypting, and string_null if plaintext */ - ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod); - /** the string "HMAC-SHA256" if signing, and string_null if plaintext */ - ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod); - - // engine client fields - ATTRIB(Client, impulse, int, this.impulse); - - ATTRIB(Client, button0, int, this.button0); - ATTRIB(Client, button2, int, this.button2); - ATTRIB(Client, button3, int, this.button3); - ATTRIB(Client, button4, int, this.button4); - ATTRIB(Client, button5, int, this.button5); - ATTRIB(Client, button6, int, this.button6); - ATTRIB(Client, button7, int, this.button7); - ATTRIB(Client, button8, int, this.button8); - ATTRIB(Client, button9, int, this.button9); - ATTRIB(Client, button10, int, this.button10); - ATTRIB(Client, button11, int, this.button11); - ATTRIB(Client, button12, int, this.button12); - ATTRIB(Client, button13, int, this.button13); - ATTRIB(Client, button14, int, this.button14); - ATTRIB(Client, button15, int, this.button15); - ATTRIB(Client, button16, int, this.button16); - ATTRIB(Client, buttonuse, int, this.buttonuse); - ATTRIB(Client, buttonchat, int, this.buttonchat); - - ATTRIB(Client, cursor_active, int, this.cursor_active); - ATTRIB(Client, cursor_screen, vector, this.cursor_screen); - ATTRIB(Client, cursor_trace_start, vector, this.cursor_trace_start); - ATTRIB(Client, cursor_trace_endpos, vector, this.cursor_trace_endpos); - ATTRIB(Client, cursor_trace_ent, entity, this.cursor_trace_ent); - - ATTRIB(Client, ping, float, this.ping); - ATTRIB(Client, ping_packetloss, float, this.ping_packetloss); - ATTRIB(Client, ping_movementloss, float, this.ping_movementloss); - - ATTRIB(Client, v_angle, vector, this.v_angle); - ATTRIB(Client, movement, vector, this.movement); - - // custom - - ATTRIB(Client, playerid, int, this.playerid); - - ATTRIB(Client, parm_idlesince, int, this.parm_idlesince); - ATTRIB(Client, muted, bool, this.muted); - ATTRIB(Client, killindicator_teamchange, int, this.killindicator_teamchange); - ATTRIB(Client, idlekick_lasttimeleft, float, this.idlekick_lasttimeleft); - ATTRIB(Client, pm_frametime, float, this.pm_frametime); - ATTRIB(Client, pressedkeys, int, this.pressedkeys); - ATTRIB(Client, movement_old, vector, this.movement_old); - ATTRIB(Client, buttons_old, int, this.buttons_old); - ATTRIB(Client, teamkill_complain, float, this.teamkill_complain); - ATTRIB(Client, teamkill_soundtime, float, this.teamkill_soundtime); - ATTRIB(Client, teamkill_soundsource, entity, this.teamkill_soundsource); - ATTRIB(Client, usekeypressed, bool, this.usekeypressed); - ATTRIB(Client, motd_actived_time, float, this.motd_actived_time); - ATTRIB(Client, jointime, float, this.jointime); - ATTRIB(Client, spectatortime, float, this.spectatortime); - ATTRIB(Client, version_nagtime, float, this.version_nagtime); - ATTRIB(Client, netname_previous, string, this.netname_previous); - ATTRIB(Client, allowed_timeouts, int, this.allowed_timeouts); - ATTRIB(Client, active_minigame, entity, this.active_minigame); - ATTRIB(Client, taunt_soundtime, float, this.taunt_soundtime); - ATTRIB(Client, killcount, int, this.killcount); - ATTRIB(Client, version_mismatch, bool, this.version_mismatch); - ATTRIB(Client, version, int, this.version); - ATTRIB(Client, spectatee_status, int, this.spectatee_status); - ATTRIB(Client, zoomstate, bool, this.zoomstate); - ATTRIB(Client, just_joined, bool, this.just_joined); - ATTRIB(Client, race_completed, bool, this.race_completed); - ATTRIBARRAY(Client, msg_choice_choices, int, 50); // TODO: actually NOTIF_CHOICE_MAX - ATTRIB(Client, latency_sum, float, this.latency_sum); - ATTRIB(Client, latency_cnt, int, this.latency_cnt); - ATTRIB(Client, latency_time, float, this.latency_time); - ATTRIB(Client, v_angle_old, vector, this.v_angle_old); - ATTRIB(Client, model_randomizer, float, this.model_randomizer); - ATTRIB(Client, accuracy, entity, this.accuracy); - ATTRIB(Client, hasweapon_complain_spam, float, this.hasweapon_complain_spam); - ATTRIB(Client, scorekeeper, entity, this.scorekeeper); - ATTRIB(Client, specialcommand_pos, int, this.specialcommand_pos); - ATTRIB(Client, hitplotfh, int, this.hitplotfh); - ATTRIB(Client, clientdata, entity, this.clientdata); - ATTRIB(Client, cmd_floodcount, int, this.cmd_floodcount); - ATTRIB(Client, cmd_floodtime, float, this.cmd_floodtime); - ATTRIB(Client, wasplayer, bool, this.wasplayer); - - // networked cvars - - ATTRIB(Client, cvar_cl_allow_uid2name, int, this.cvar_cl_allow_uid2name); - ATTRIB(Client, cvar_cl_allow_uidtracking, int, this.cvar_cl_allow_uidtracking); - ATTRIB(Client, cvar_cl_autotaunt, float, this.cvar_cl_autotaunt); - ATTRIB(Client, cvar_cl_voice_directional, int, this.cvar_cl_voice_directional); - ATTRIB(Client, cvar_cl_voice_directional_taunt_attenuation, float, this.cvar_cl_voice_directional_taunt_attenuation); - ATTRIB(Client, cvar_cl_physics, string, this.cvar_cl_physics); - ATTRIB(Client, cvar_cl_buffs_autoreplace, bool, this.cvar_cl_buffs_autoreplace); - ATTRIB(Client, cvar_cl_nade_type, int, this.cvar_cl_nade_type); - ATTRIB(Client, cvar_cl_pokenade_type, string, this.cvar_cl_pokenade_type); - ATTRIB(Client, cvar_cl_spawn_near_teammate, bool, this.cvar_cl_spawn_near_teammate); - ATTRIB(Client, cvar_cl_gunalign, int, this.cvar_cl_gunalign); - ATTRIB(Client, cvar_cl_handicap, float, this.cvar_cl_handicap); - ATTRIB(Client, cvar_cl_clippedspectating, bool, this.cvar_cl_clippedspectating); - ATTRIB(Client, cvar_cl_autoscreenshot, int, this.cvar_cl_autoscreenshot); - ATTRIB(Client, cvar_cl_jetpack_jump, bool, this.cvar_cl_jetpack_jump); - ATTRIB(Client, cvar_cl_newusekeysupported, bool, this.cvar_cl_newusekeysupported); - ATTRIB(Client, cvar_cl_noantilag, bool, this.cvar_cl_noantilag); - ATTRIB(Client, cvar_cl_movement_track_canjump, bool, this.cvar_cl_movement_track_canjump); - ATTRIB(Client, cvar_cl_weaponimpulsemode, int, this.cvar_cl_weaponimpulsemode); - ATTRIB(Client, cvar_g_xonoticversion, string, this.cvar_g_xonoticversion); - ATTRIB(Client, autoswitch, bool, this.autoswitch); - ATTRIB(Client, cvar_cl_dodging_timeout, float, this.cvar_cl_dodging_timeout); - ATTRIB(Client, cvar_cl_multijump, bool, this.cvar_cl_multijump); - ATTRIB(Client, cvar_cl_accuracy_data_share, bool, this.cvar_cl_accuracy_data_share); - ATTRIB(Client, cvar_cl_accuracy_data_receive, bool, this.cvar_cl_accuracy_data_receive); - ATTRIBARRAY(Client, cvar_cl_weaponpriorities, string, 10); - ATTRIB(Client, cvar_cl_weaponpriority, string, this.cvar_cl_weaponpriority); - - METHOD(Client, m_unwind, bool(Client this)); - - STATIC_METHOD(Client, Add, void(Client this, int _team)); - STATIC_METHOD(Client, Remove, void(Client this)); - - INIT(Client) { - if (this.m_unwind(this)) return this; - make_impure(this); - this.classname = "player_joining"; - static int playerid_last; - this.playerid = ++playerid_last; - ClientState_attach(this); - } - DESTRUCTOR(Client) { - Client_Remove(this); - } - CONSTRUCTOR(Client, string name) { - CONSTRUCT(Client); - this.netname = name; - this.netaddress = "local"; - this.playermodel = cvar_defstring("sv_defaultplayermodel"); - } + /** Client name */ + ATTRIB(Client, netname, string, this.netname); + ATTRIB(Client, colormap, int, this.colormap); + ATTRIB(Client, team, int, this.team); + ATTRIB(Client, clientcolors, int, this.clientcolors); + /** Client IP */ + ATTRIB(Client, netaddress, string, this.netaddress); + ATTRIB(Client, playermodel, string, this.playermodel); + ATTRIB(Client, playerskin, int, this.playerskin); + + /** fingerprint of CA key the player used to authenticate */ + ATTRIB(Client, crypto_keyfp, string, this.crypto_keyfp); + /** fingerprint of CA key the server used to authenticate to the player */ + ATTRIB(Client, crypto_mykeyfp, string, this.crypto_mykeyfp); + /** fingerprint of ID used by the player entity, or string_null if not identified */ + ATTRIB(Client, crypto_idfp, string, this.crypto_idfp); + /** set if the player's ID has been signed */ + ATTRIB(Client, crypto_idfp_signed, bool, this.crypto_idfp_signed); + /** the string "AES128" if encrypting, and string_null if plaintext */ + ATTRIB(Client, crypto_encryptmethod, string, this.crypto_encryptmethod); + /** the string "HMAC-SHA256" if signing, and string_null if plaintext */ + ATTRIB(Client, crypto_signmethod, string, this.crypto_signmethod); + + // engine client fields + ATTRIB(Client, impulse, int, this.impulse); + + ATTRIB(Client, button0, int, this.button0); + ATTRIB(Client, button2, int, this.button2); + ATTRIB(Client, button3, int, this.button3); + ATTRIB(Client, button4, int, this.button4); + ATTRIB(Client, button5, int, this.button5); + ATTRIB(Client, button6, int, this.button6); + ATTRIB(Client, button7, int, this.button7); + ATTRIB(Client, button8, int, this.button8); + ATTRIB(Client, button9, int, this.button9); + ATTRIB(Client, button10, int, this.button10); + ATTRIB(Client, button11, int, this.button11); + ATTRIB(Client, button12, int, this.button12); + ATTRIB(Client, button13, int, this.button13); + ATTRIB(Client, button14, int, this.button14); + ATTRIB(Client, button15, int, this.button15); + ATTRIB(Client, button16, int, this.button16); + ATTRIB(Client, buttonuse, int, this.buttonuse); + ATTRIB(Client, buttonchat, int, this.buttonchat); + + ATTRIB(Client, cursor_active, int, this.cursor_active); + ATTRIB(Client, cursor_screen, vector, this.cursor_screen); + ATTRIB(Client, cursor_trace_start, vector, this.cursor_trace_start); + ATTRIB(Client, cursor_trace_endpos, vector, this.cursor_trace_endpos); + ATTRIB(Client, cursor_trace_ent, entity, this.cursor_trace_ent); + + ATTRIB(Client, ping, float, this.ping); + ATTRIB(Client, ping_packetloss, float, this.ping_packetloss); + ATTRIB(Client, ping_movementloss, float, this.ping_movementloss); + + ATTRIB(Client, v_angle, vector, this.v_angle); + ATTRIB(Client, movement, vector, this.movement); + + // custom + + ATTRIB(Client, playerid, int, this.playerid); + + ATTRIB(Client, parm_idlesince, int, this.parm_idlesince); + ATTRIB(Client, muted, bool, this.muted); + ATTRIB(Client, killindicator_teamchange, int, this.killindicator_teamchange); + ATTRIB(Client, idlekick_lasttimeleft, float, this.idlekick_lasttimeleft); + ATTRIB(Client, pm_frametime, float, this.pm_frametime); + ATTRIB(Client, pressedkeys, int, this.pressedkeys); + ATTRIB(Client, movement_old, vector, this.movement_old); + ATTRIB(Client, buttons_old, int, this.buttons_old); + ATTRIB(Client, teamkill_complain, float, this.teamkill_complain); + ATTRIB(Client, teamkill_soundtime, float, this.teamkill_soundtime); + ATTRIB(Client, teamkill_soundsource, entity, this.teamkill_soundsource); + ATTRIB(Client, usekeypressed, bool, this.usekeypressed); + ATTRIB(Client, motd_actived_time, float, this.motd_actived_time); + ATTRIB(Client, jointime, float, this.jointime); + ATTRIB(Client, spectatortime, float, this.spectatortime); + ATTRIB(Client, version_nagtime, float, this.version_nagtime); + ATTRIB(Client, netname_previous, string, this.netname_previous); + ATTRIB(Client, allowed_timeouts, int, this.allowed_timeouts); + ATTRIB(Client, active_minigame, entity, this.active_minigame); + ATTRIB(Client, taunt_soundtime, float, this.taunt_soundtime); + ATTRIB(Client, killcount, int, this.killcount); + ATTRIB(Client, version_mismatch, bool, this.version_mismatch); + ATTRIB(Client, version, int, this.version); + ATTRIB(Client, spectatee_status, int, this.spectatee_status); + ATTRIB(Client, zoomstate, bool, this.zoomstate); + ATTRIB(Client, just_joined, bool, this.just_joined); + ATTRIB(Client, race_completed, bool, this.race_completed); + ATTRIBARRAY(Client, msg_choice_choices, int, 50); // TODO: actually NOTIF_CHOICE_MAX + ATTRIB(Client, latency_sum, float, this.latency_sum); + ATTRIB(Client, latency_cnt, int, this.latency_cnt); + ATTRIB(Client, latency_time, float, this.latency_time); + ATTRIB(Client, v_angle_old, vector, this.v_angle_old); + ATTRIB(Client, model_randomizer, float, this.model_randomizer); + ATTRIB(Client, accuracy, entity, this.accuracy); + ATTRIB(Client, hasweapon_complain_spam, float, this.hasweapon_complain_spam); + ATTRIB(Client, scorekeeper, entity, this.scorekeeper); + ATTRIB(Client, specialcommand_pos, int, this.specialcommand_pos); + ATTRIB(Client, hitplotfh, int, this.hitplotfh); + ATTRIB(Client, clientdata, entity, this.clientdata); + ATTRIB(Client, cmd_floodcount, int, this.cmd_floodcount); + ATTRIB(Client, cmd_floodtime, float, this.cmd_floodtime); + ATTRIB(Client, wasplayer, bool, this.wasplayer); + + // networked cvars + + ATTRIB(Client, cvar_cl_allow_uid2name, int, this.cvar_cl_allow_uid2name); + ATTRIB(Client, cvar_cl_allow_uidtracking, int, this.cvar_cl_allow_uidtracking); + ATTRIB(Client, cvar_cl_autotaunt, float, this.cvar_cl_autotaunt); + ATTRIB(Client, cvar_cl_voice_directional, int, this.cvar_cl_voice_directional); + ATTRIB(Client, cvar_cl_voice_directional_taunt_attenuation, float, this.cvar_cl_voice_directional_taunt_attenuation); + ATTRIB(Client, cvar_cl_physics, string, this.cvar_cl_physics); + ATTRIB(Client, cvar_cl_buffs_autoreplace, bool, this.cvar_cl_buffs_autoreplace); + ATTRIB(Client, cvar_cl_nade_type, int, this.cvar_cl_nade_type); + ATTRIB(Client, cvar_cl_pokenade_type, string, this.cvar_cl_pokenade_type); + ATTRIB(Client, cvar_cl_spawn_near_teammate, bool, this.cvar_cl_spawn_near_teammate); + ATTRIB(Client, cvar_cl_gunalign, int, this.cvar_cl_gunalign); + ATTRIB(Client, cvar_cl_handicap, float, this.cvar_cl_handicap); + ATTRIB(Client, cvar_cl_clippedspectating, bool, this.cvar_cl_clippedspectating); + ATTRIB(Client, cvar_cl_autoscreenshot, int, this.cvar_cl_autoscreenshot); + ATTRIB(Client, cvar_cl_jetpack_jump, bool, this.cvar_cl_jetpack_jump); + ATTRIB(Client, cvar_cl_newusekeysupported, bool, this.cvar_cl_newusekeysupported); + ATTRIB(Client, cvar_cl_noantilag, bool, this.cvar_cl_noantilag); + ATTRIB(Client, cvar_cl_movement_track_canjump, bool, this.cvar_cl_movement_track_canjump); + ATTRIB(Client, cvar_cl_weaponimpulsemode, int, this.cvar_cl_weaponimpulsemode); + ATTRIB(Client, cvar_g_xonoticversion, string, this.cvar_g_xonoticversion); + ATTRIB(Client, autoswitch, bool, this.autoswitch); + ATTRIB(Client, cvar_cl_dodging_timeout, float, this.cvar_cl_dodging_timeout); + ATTRIB(Client, cvar_cl_multijump, bool, this.cvar_cl_multijump); + ATTRIB(Client, cvar_cl_accuracy_data_share, bool, this.cvar_cl_accuracy_data_share); + ATTRIB(Client, cvar_cl_accuracy_data_receive, bool, this.cvar_cl_accuracy_data_receive); + ATTRIBARRAY(Client, cvar_cl_weaponpriorities, string, 10); + ATTRIB(Client, cvar_cl_weaponpriority, string, this.cvar_cl_weaponpriority); + + METHOD(Client, m_unwind, bool(Client this)); + + STATIC_METHOD(Client, Add, void(Client this, int _team)); + STATIC_METHOD(Client, Remove, void(Client this)); + + INIT(Client) + { + if (this.m_unwind(this)) { return this; } + make_impure(this); + this.classname = "player_joining"; + static int playerid_last; + this.playerid = ++playerid_last; + ClientState_attach(this); + } + DESTRUCTOR(Client) + { + Client_Remove(this); + } + CONSTRUCTOR(Client, string name) + { + CONSTRUCT(Client); + this.netname = name; + this.netaddress = "local"; + this.playermodel = cvar_defstring("sv_defaultplayermodel"); + } ENDCLASS(Client) CLASS(Observer, Client) - INIT(Observer) { - this.classname = STR_OBSERVER; - } - DESTRUCTOR(Observer) { } + INIT(Observer) + { + this.classname = STR_OBSERVER; + } + DESTRUCTOR(Observer) {} ENDCLASS(Observer) CLASS(Spectator, Client) - INIT(Spectator) { - this.classname = STR_SPECTATOR; - } - DESTRUCTOR(Spectator) { } + INIT(Spectator) + { + this.classname = STR_SPECTATOR; + } + DESTRUCTOR(Spectator) {} ENDCLASS(Spectator) CLASS(Player, Client) - // custom - - ATTRIB(Player, dual_weapons, vector, this.dual_weapons); // TODO: actually WepSet! - ATTRIB(Player, itemkeys, int, this.itemkeys); - ATTRIB(Player, ballistics_density, float, this.ballistics_density); - ATTRIB(Player, prevstrengthsound, float, this.prevstrengthsound); - ATTRIB(Player, prevstrengthsoundattempt, float, this.prevstrengthsoundattempt); - ATTRIB(Player, buff_shield, float, this.buff_shield); - - INIT(Player) { - this.classname = STR_PLAYER; - IL_PUSH(g_players, this); - } - DESTRUCTOR(Player) { - IL_REMOVE(g_players, this); - } + // custom + + ATTRIB(Player, dual_weapons, vector, this.dual_weapons); // TODO: actually WepSet! + ATTRIB(Player, itemkeys, int, this.itemkeys); + ATTRIB(Player, ballistics_density, float, this.ballistics_density); + ATTRIB(Player, prevstrengthsound, float, this.prevstrengthsound); + ATTRIB(Player, prevstrengthsoundattempt, float, this.prevstrengthsoundattempt); + ATTRIB(Player, buff_shield, float, this.buff_shield); + + INIT(Player) + { + this.classname = STR_PLAYER; + IL_PUSH(g_players, this); + } + DESTRUCTOR(Player) + { + IL_REMOVE(g_players, this); + } ENDCLASS(Player) METHOD(Client, m_unwind, bool(Client this)) { - TC(Client, this); - #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END - switch (this.classname) { - case "Observer": - UNWIND(Spectator); - UNWIND(Player); - return true; - case "Spectator": - UNWIND(Observer); - UNWIND(Player); - return true; - case "Player": - UNWIND(Observer); - UNWIND(Spectator); - return true; - } - #undef UNWIND - return false; + TC(Client, this); + #define UNWIND(class) MACRO_BEGIN if (this.instanceOf##class) { METHOD_REFERENCE(class, dtorimpl)(this); } MACRO_END + switch (this.classname) { + case "Observer": + UNWIND(Spectator); + UNWIND(Player); + return true; + case "Spectator": + UNWIND(Observer); + UNWIND(Player); + return true; + case "Player": + UNWIND(Observer); + UNWIND(Spectator); + return true; + } + #undef UNWIND + return false; } void play_countdown(entity this, float finished, Sound samp); @@ -231,4 +241,8 @@ float CalcRotRegen(float current, float regenstable, float regenfactor, float re bool Spectate(entity this, entity pl); #define SPECTATE_COPY() [[accumulate]] void SpectateCopy(entity this, entity spectatee) -#define SPECTATE_COPYFIELD(fld) SPECTATE_COPY() { this.(fld) = spectatee.(fld); } +#define SPECTATE_COPYFIELD(fld) \ + SPECTATE_COPY() \ + { \ + this.(fld) = spectatee.(fld); \ + } diff --git a/qcsrc/server/command/banning.qc b/qcsrc/server/command/banning.qc index da495f796..5e73059e0 100644 --- a/qcsrc/server/command/banning.qc +++ b/qcsrc/server/command/banning.qc @@ -20,12 +20,10 @@ void BanCommand_ban(float request, float argc, string command) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if (argc >= 2) - { + if (argc >= 2) { string ip = argv(1); float reason_arg, bantime; string reason; @@ -56,8 +54,7 @@ void BanCommand_ban(float request, float argc, string command) void BanCommand_banlist(float request) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { Ban_View(); @@ -77,19 +74,16 @@ void BanCommand_banlist(float request) void BanCommand_kickban(float request, float argc, string command) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if (argc >= 2) - { + if (argc >= 2) { entity client = GetIndexedEntity(argc, 1); float accepted = VerifyKickableEntity(client); float reason_arg, bantime, masksize; string reason; - if (accepted > 0) - { + if (accepted > 0) { reason_arg = next_token; GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime); @@ -99,9 +93,7 @@ void BanCommand_kickban(float request, float argc, string command) Ban_KickBanClient(client, bantime, masksize, reason); return; - } - else - { + } else { LOG_INFO("kickban: ", GetClientErrorString(accepted, argv(1)), "."); } } @@ -122,24 +114,19 @@ void BanCommand_kickban(float request, float argc, string command) } } -void BanCommand_mute(float request, float argc, string command) // TODO: Add a sort of mute-"ban" which allows players to be muted based on IP/cryptokey +void BanCommand_mute(float request, float argc, string command) // TODO: Add a sort of mute-"ban" which allows players to be muted based on IP/cryptokey { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if (argc >= 2) - { + if (argc >= 2) { entity client = GetFilteredEntity(argv(1)); float accepted = VerifyClientEntity(client, true, false); - if (accepted > 0) - { + if (accepted > 0) { CS(client).muted = true; return; - } - else - { + } else { LOG_INFO("mute: ", GetClientErrorString(accepted, argv(1)), "."); } } @@ -159,33 +146,27 @@ void BanCommand_mute(float request, float argc, string command) // TODO: Add a void BanCommand_unban(float request, float argc) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if (argv(1)) - { + if (argv(1)) { float tmp_number = -1; string tmp_string; - if (substring(argv(1), 0, 1) == "#") - { + if (substring(argv(1), 0, 1) == "#") { tmp_string = substring(argv(1), 1, -1); - if (tmp_string != "") // is it all one token? like #1 + if (tmp_string != "") { // is it all one token? like #1 tmp_number = stof(tmp_string); - else if (argc > 2) // no, it's two tokens? # 1 + } else if (argc > 2) { // no, it's two tokens? # 1 tmp_number = stof(argv(2)); - else tmp_number = -1; - } - else // maybe it's ONLY a number? - { + } else { tmp_number = -1; } + } else { // maybe it's ONLY a number? tmp_number = stof(argv(1)); - if ((tmp_number == 0) && (argv(1) != "0")) tmp_number = -1; } + if ((tmp_number == 0) && (argv(1) != "0")) { tmp_number = -1; } } - if (tmp_number >= 0) - { + if (tmp_number >= 0) { Ban_Delete(tmp_number); return; } @@ -205,22 +186,17 @@ void BanCommand_unban(float request, float argc) void BanCommand_unmute(float request, float argc) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if (argc >= 2) - { + if (argc >= 2) { entity client = GetFilteredEntity(argv(1)); float accepted = VerifyClientEntity(client, true, false); - if (accepted > 0) - { + if (accepted > 0) { CS(client).muted = false; return; - } - else - { + } else { LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), "."); } } @@ -279,7 +255,7 @@ void BanCommand_(float request) void BanCommand_macro_help() { #define BAN_COMMAND(name, function, description) \ - { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description); } } + { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description); } } BAN_COMMANDS(0, 0, ""); #undef BAN_COMMAND @@ -288,7 +264,7 @@ void BanCommand_macro_help() float BanCommand_macro_command(float argc, string command) { #define BAN_COMMAND(name, function, description) \ - { if (name == strtolower(argv(0))) { function; return true; } } + { if (name == strtolower(argv(0))) { function; return true; } } BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command); #undef BAN_COMMAND @@ -299,7 +275,7 @@ float BanCommand_macro_command(float argc, string command) float BanCommand_macro_usage(float argc) { #define BAN_COMMAND(name, function, description) \ - { if (name == strtolower(argv(1))) { function; return true; } } + { if (name == strtolower(argv(1))) { function; return true; } } BAN_COMMANDS(CMD_REQUEST_USAGE, argc, ""); #undef BAN_COMMAND @@ -310,7 +286,7 @@ float BanCommand_macro_usage(float argc) void BanCommand_macro_write_aliases(float fh) { #define BAN_COMMAND(name, function, description) \ - { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } } + { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } } BAN_COMMANDS(0, 0, ""); #undef BAN_COMMAND @@ -325,8 +301,8 @@ float BanCommand(string command) // argv: 0 - 1 - 2 - 3 // cmd vote - master - login - password - if (BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands - return true; // handled by one of the above GenericCommand_* functions - + if (BanCommand_macro_command(argc, command)) { // continue as usual and scan for normal commands + return true; // handled by one of the above GenericCommand_* functions + } return false; } diff --git a/qcsrc/server/command/banning.qh b/qcsrc/server/command/banning.qh index d6b1ae60f..bb8c163f5 100644 --- a/qcsrc/server/command/banning.qh +++ b/qcsrc/server/command/banning.qh @@ -5,8 +5,8 @@ // Last updated: December 29th, 2011 // ===================================== -#define GET_BAN_ARG(v, d) if (argc > reason_arg) { if ((v = stof(argv(reason_arg))) != 0) ++reason_arg; else v = d; } else { v = d; } -#define GET_BAN_REASON(v, d) if (argc > reason_arg) v = substring(command, argv_start_index(reason_arg), strlen(command) - argv_start_index(reason_arg)); else v = d; +#define GET_BAN_ARG(v, d) if (argc > reason_arg) { if ((v = stof(argv(reason_arg))) != 0) { ++reason_arg; } else { v = d; } } else { v = d; } +#define GET_BAN_REASON(v, d) if (argc > reason_arg) { v = substring(command, argv_start_index(reason_arg), strlen(command) - argv_start_index(reason_arg)); } else { v = d; } void Ban_KickBanClient(entity client, float bantime, float masksize, string reason); void Ban_View(); diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 46d1d2b6f..e5546127d 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -21,30 +21,32 @@ // select the proper prefix for usage and other messages string GetCommandPrefix(entity caller) { - if (caller) return "cmd"; - else return "sv_cmd"; + if (caller) { return "cmd"; } else { return "sv_cmd"; } } // if client return player nickname, or if server return admin nickname string GetCallerName(entity caller) { - if (caller) return playername(caller, false); - else return ((autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : "SERVER ADMIN"); // autocvar_hostname + if (caller) { return playername(caller, false); } else { + return (autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : "SERVER ADMIN"; // autocvar_hostname + } } // verify that the client provided is acceptable for kicking float VerifyKickableEntity(entity client) { - if (!IS_REAL_CLIENT(client)) return CLIENT_NOT_REAL; + if (!IS_REAL_CLIENT(client)) { return CLIENT_NOT_REAL; } return CLIENT_ACCEPTABLE; } // verify that the client provided is acceptable for use float VerifyClientEntity(entity client, float must_be_real, float must_be_bots) { - if (!IS_CLIENT(client)) return CLIENT_DOESNT_EXIST; - else if (must_be_real && !IS_REAL_CLIENT(client)) return CLIENT_NOT_REAL; - else if (must_be_bots && !IS_BOT_CLIENT(client)) return CLIENT_NOT_BOT; + if (!IS_CLIENT(client)) { return CLIENT_DOESNT_EXIST; } else if (must_be_real && !IS_REAL_CLIENT(client)) { + return CLIENT_NOT_REAL; + } else if (must_be_bots && !IS_BOT_CLIENT(client)) { + return CLIENT_NOT_BOT; + } return CLIENT_ACCEPTABLE; } @@ -52,8 +54,7 @@ float VerifyClientEntity(entity client, float must_be_real, float must_be_bots) // if the client is not acceptable, return a string to be used for error messages string GetClientErrorString_color(float clienterror, string original_input, string col) { - switch (clienterror) - { + switch (clienterror) { case CLIENT_DOESNT_EXIST: { return strcat(col, "Client '", original_input, col, "' doesn't exist"); } @@ -72,8 +73,7 @@ string GetClientErrorString_color(float clienterror, string original_input, stri // is this entity number even in the possible range of entities? float VerifyClientNumber(float tmp_number) { - if ((tmp_number < 1) || (tmp_number > maxclients)) return false; - else return true; + if ((tmp_number < 1) || (tmp_number > maxclients)) { return false; } else { return true; } } entity GetIndexedEntity(float argc, float start_index) @@ -86,42 +86,29 @@ entity GetIndexedEntity(float argc, float start_index) index = start_index; selection = NULL; - if (argc > start_index) - { - if (substring(argv(index), 0, 1) == "#") - { + if (argc > start_index) { + if (substring(argv(index), 0, 1) == "#") { tmp_string = substring(argv(index), 1, -1); ++index; - if (tmp_string != "") // is it all one token? like #1 - { + if (tmp_string != "") { // is it all one token? like #1 tmp_number = stof(tmp_string); - } - else if (argc > index) // no, it's two tokens? # 1 - { + } else if (argc > index) { // no, it's two tokens? # 1 tmp_number = stof(argv(index)); ++index; - } - else - { + } else { tmp_number = 0; } - } - else // maybe it's ONLY a number? - { + } else { // maybe it's ONLY a number? tmp_number = stof(argv(index)); ++index; } - if (VerifyClientNumber(tmp_number)) - { - selection = edict_num(tmp_number); // yes, it was a number - } - else // no, maybe it's a name? - { + if (VerifyClientNumber(tmp_number)) { + selection = edict_num(tmp_number); // yes, it was a number + } else { // no, maybe it's a name? FOREACH_CLIENT(true, { - if(strdecolorize(it.netname) == strdecolorize(argv(start_index))) - { + if (strdecolorize(it.netname) == strdecolorize(argv(start_index))) { selection = it; break; // no reason to keep looking } @@ -142,19 +129,14 @@ entity GetFilteredEntity(string input) entity selection; float tmp_number; - if (substring(input, 0, 1) == "#") tmp_number = stof(substring(input, 1, -1)); - else tmp_number = stof(input); + if (substring(input, 0, 1) == "#") { tmp_number = stof(substring(input, 1, -1)); } else { tmp_number = stof(input); } - if (VerifyClientNumber(tmp_number)) - { + if (VerifyClientNumber(tmp_number)) { selection = edict_num(tmp_number); - } - else - { + } else { selection = NULL; FOREACH_CLIENT(true, { - if(strdecolorize(it.netname) == strdecolorize(input)) - { + if (strdecolorize(it.netname) == strdecolorize(input)) { selection = it; break; // no reason to keep looking } @@ -178,8 +160,7 @@ float GetFilteredNumber(string input) // switch between sprint and print depending on whether the receiver is the server or a player void print_to(entity to, string input) { - if (to) sprint(to, strcat(input, "\n")); - else print(input, "\n"); + if (to) { sprint(to, strcat(input, "\n")); } else { print(input, "\n"); } } // ========================================== @@ -198,22 +179,19 @@ void timeout_handler_reset(entity this) void timeout_handler_think(entity this) { - switch (timeout_status) - { + switch (timeout_status) { case TIMEOUT_ACTIVE: { - if (timeout_time > 0) // countdown is still going - { + if (timeout_time > 0) { // countdown is still going Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_TIMEOUT_ENDING, timeout_time); - if (timeout_time == autocvar_sv_timeout_resumetime) // play a warning sound when only <sv_timeout_resumetime> seconds are left + if (timeout_time == autocvar_sv_timeout_resumetime) { // play a warning sound when only <sv_timeout_resumetime> seconds are left Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_PREPARE); + } - this.nextthink = time + TIMEOUT_SLOWMO_VALUE; // think again in one second - timeout_time -= 1; // decrease the time counter - } - else // time to end the timeout - { + this.nextthink = time + TIMEOUT_SLOWMO_VALUE; // think again in one second + timeout_time -= 1; // decrease the time counter + } else { // time to end the timeout Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_TIMEIN); timeout_status = TIMEOUT_INACTIVE; @@ -233,15 +211,12 @@ void timeout_handler_think(entity this) case TIMEOUT_LEADTIME: { - if (timeout_leadtime > 0) // countdown is still going - { + if (timeout_leadtime > 0) { // countdown is still going Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_TIMEOUT_BEGINNING, timeout_leadtime); this.nextthink = time + 1; // think again in one second timeout_leadtime -= 1; // decrease the time counter - } - else // time to begin the timeout - { + } else { // time to begin the timeout timeout_status = TIMEOUT_ACTIVE; // set the slowmo value to the timeout default slowmo value @@ -250,8 +225,8 @@ void timeout_handler_think(entity this) // reset all the flood variables FOREACH_CLIENT(true, { it.nickspamcount = it.nickspamtime = it.floodcontrol_chat = - it.floodcontrol_chatteam = it.floodcontrol_chattell = - it.floodcontrol_voice = it.floodcontrol_voiceteam = 0; + it.floodcontrol_chatteam = it.floodcontrol_chattell = + it.floodcontrol_voice = it.floodcontrol_voiceteam = 0; }); // copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink) @@ -259,7 +234,7 @@ void timeout_handler_think(entity this) it.lastV_angle = it.v_angle; }); - this.nextthink = time; // think again next frame to handle it under TIMEOUT_ACTIVE code + this.nextthink = time; // think again next frame to handle it under TIMEOUT_ACTIVE code } return; @@ -282,12 +257,11 @@ void timeout_handler_think(entity this) void CommonCommand_cvar_changes(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { print_to(caller, cvar_changes); - return; // never fall through to usage + return; // never fall through to usage } default: @@ -303,12 +277,11 @@ void CommonCommand_cvar_changes(float request, entity caller) void CommonCommand_cvar_purechanges(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { print_to(caller, cvar_purechanges); - return; // never fall through to usage + return; // never fall through to usage } default: @@ -324,15 +297,13 @@ void CommonCommand_cvar_purechanges(float request, entity caller) void CommonCommand_editmob(int request, entity caller, int argc) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { if (autocvar_g_campaign) { print_to(caller, "Monster editing is disabled in singleplayer"); return; } // no checks for g_monsters here, as it may be toggled mid match which existing monsters - if (caller) - { + if (caller) { makevectors(caller.v_angle); WarpZone_TraceLine(caller.origin + caller.view_ofs, caller.origin + caller.view_ofs + v_forward * 100, MOVE_NORMAL, caller); } @@ -341,12 +312,13 @@ void CommonCommand_editmob(int request, entity caller, int argc) bool is_visible = IS_MONSTER(mon); string argument = argv(2); - switch (argv(1)) - { + switch (argv(1)) { case "name": { if (!caller) { print_to(caller, "Only players can edit monsters"); return; } - if (!argument) break; // escape to usage + if (!argument) { + break; // escape to usage + } if (!autocvar_g_monsters_edit) { print_to(caller, "Monster editing is disabled"); return; } if (mon.realowner != caller && autocvar_g_monsters_edit < 2) { print_to(caller, "This monster does not belong to you"); return; } if (!is_visible) { print_to(caller, "You must look at your monster to edit it"); return; } @@ -354,18 +326,19 @@ void CommonCommand_editmob(int request, entity caller, int argc) string mon_oldname = mon.monster_name; mon.monster_name = argument; - if (mon.sprite) WaypointSprite_UpdateSprites(mon.sprite, WP_Monster, WP_Null, WP_Null); + if (mon.sprite) { WaypointSprite_UpdateSprites(mon.sprite, WP_Monster, WP_Null, WP_Null); } print_to(caller, sprintf("Your pet '%s' is now known as '%s'", mon_oldname, mon.monster_name)); return; } case "spawn": { if (!caller) { print_to(caller, "Only players can spawn monsters"); return; } - if (!argv(2)) break; // escape to usage - + if (!argv(2)) { + break; // escape to usage + } int moveflag, tmp_moncount = 0; string arg_lower = strtolower(argument); - moveflag = (argv(3)) ? stof(argv(3)) : 1; // follow owner if not defined + moveflag = (argv(3)) ? stof(argv(3)) : 1; // follow owner if not defined if (arg_lower == "list") { print_to(caller, monsterlist_reply); return; } @@ -412,11 +385,13 @@ void CommonCommand_editmob(int request, entity caller, int argc) case "skin": { if (!caller) { print_to(caller, "Only players can edit monsters"); return; } - if (!argument) break; // escape to usage + if (!argument) { + break; // escape to usage + } if (!autocvar_g_monsters_edit) { print_to(caller, "Monster editing is disabled"); return; } if (!is_visible) { print_to(caller, "You must look at your monster to edit it"); return; } if (mon.realowner != caller && autocvar_g_monsters_edit < 2) { print_to(caller, "This monster does not belong to you"); return; } - if (mon.monsterid == MON_MAGE.monsterid) { print_to(caller, "Mage skins can't be changed"); return; } // TODO + if (mon.monsterid == MON_MAGE.monsterid) { print_to(caller, "Mage skins can't be changed"); return; } // TODO mon.skin = stof(argument); print_to(caller, strcat("Monster skin successfully changed to ", ftos(mon.skin))); @@ -425,7 +400,9 @@ void CommonCommand_editmob(int request, entity caller, int argc) case "movetarget": { if (!caller) { print_to(caller, "Only players can edit monsters"); return; } - if (!argument) break; // escape to usage + if (!argument) { + break; // escape to usage + } if (!autocvar_g_monsters_edit) { print_to(caller, "Monster editing is disabled"); return; } if (!is_visible) { print_to(caller, "You must look at your monster to edit it"); return; } if (mon.realowner != caller && autocvar_g_monsters_edit < 2) { print_to(caller, "This monster does not belong to you"); return; } @@ -471,16 +448,14 @@ void CommonCommand_editmob(int request, entity caller, int argc) void CommonCommand_info(float request, entity caller, float argc) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { string command = builtin_cvar_string(strcat("sv_info_", argv(1))); - if (command) wordwrap_sprint(caller, command, 1000); - else print_to(caller, "ERROR: unsupported info command"); + if (command) { wordwrap_sprint(caller, command, 1000); } else { print_to(caller, "ERROR: unsupported info command"); } - return; // never fall through to usage + return; // never fall through to usage } default: @@ -495,12 +470,11 @@ void CommonCommand_info(float request, entity caller, float argc) void CommonCommand_ladder(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { print_to(caller, ladder_reply); - return; // never fall through to usage + return; // never fall through to usage } default: @@ -515,12 +489,11 @@ void CommonCommand_ladder(float request, entity caller) void CommonCommand_lsmaps(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { print_to(caller, lsmaps_reply); - return; // never fall through to usage + return; // never fall through to usage } default: @@ -535,12 +508,11 @@ void CommonCommand_lsmaps(float request, entity caller) void CommonCommand_printmaplist(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { print_to(caller, maplist_reply); - return; // never fall through to usage + return; // never fall through to usage } default: @@ -555,12 +527,11 @@ void CommonCommand_printmaplist(float request, entity caller) void CommonCommand_rankings(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { print_to(caller, rankings_reply); - return; // never fall through to usage + return; // never fall through to usage } default: @@ -575,20 +546,18 @@ void CommonCommand_rankings(float request, entity caller) void CommonCommand_records(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { int num = stoi(argv(1)); - if(num > 0 && num <= 10 && records_reply[num - 1] != "") + if (num > 0 && num <= 10 && records_reply[num - 1] != "") { print_to(caller, records_reply[num - 1]); - else - { - for (int i = 0; i < 10; ++i) - if (records_reply[i] != "") print_to(caller, records_reply[i]); + } else { + for (int i = 0; i < 10; ++i) { + if (records_reply[i] != "") { print_to(caller, records_reply[i]); } } } - return; // never fall through to usage + return; // never fall through to usage } default: @@ -603,12 +572,11 @@ void CommonCommand_records(float request, entity caller) void CommonCommand_teamstatus(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { Score_NicePrint(caller); - return; // never fall through to usage + return; // never fall through to usage } default: @@ -623,8 +591,7 @@ void CommonCommand_teamstatus(float request, entity caller) void CommonCommand_time(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { print_to(caller, strcat("time = ", ftos(time))); @@ -649,27 +616,19 @@ void CommonCommand_time(float request, entity caller) void CommonCommand_timein(float request, entity caller) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if (!caller || autocvar_sv_timeout) - { - if (!timeout_status) { print_to(caller, "^7Error: There is no active timeout called."); } - else if (caller && (caller != timeout_caller)) - { + if (!caller || autocvar_sv_timeout) { + if (!timeout_status) { print_to(caller, "^7Error: There is no active timeout called."); } else if (caller && (caller != timeout_caller)) { print_to(caller, "^7Error: You are not allowed to stop the active timeout."); - } - - else // everything should be okay, continue aborting timeout - { - switch (timeout_status) - { + } else { // everything should be okay, continue aborting timeout + switch (timeout_status) { case TIMEOUT_LEADTIME: { timeout_status = TIMEOUT_INACTIVE; timeout_time = 0; - timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately + timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately bprint(strcat("^7The timeout was aborted by ", GetCallerName(caller), " !\n")); return; } @@ -677,7 +636,7 @@ void CommonCommand_timein(float request, entity caller) case TIMEOUT_ACTIVE: { timeout_time = autocvar_sv_timeout_resumetime; - timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately + timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately bprint(strcat("^1Attention: ^7", GetCallerName(caller), " resumed the game! Prepare for battle!\n")); return; } @@ -686,10 +645,9 @@ void CommonCommand_timein(float request, entity caller) return; } } - } - else { print_to(caller, "^1Timeins are not allowed to be called, enable them with sv_timeout 1.\n"); } + } else { print_to(caller, "^1Timeins are not allowed to be called, enable them with sv_timeout 1.\n"); } - return; // never fall through to usage + return; // never fall through to usage } default: @@ -702,45 +660,28 @@ void CommonCommand_timein(float request, entity caller) } } -void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAND IS TERRIBLE. +void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAND IS TERRIBLE. { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { - if (!caller || autocvar_sv_timeout) - { + if (!caller || autocvar_sv_timeout) { float last_possible_timeout = ((autocvar_timelimit * 60) - autocvar_sv_timeout_leadtime - 1); - if (timeout_status) { print_to(caller, "^7Error: A timeout is already active."); } - else if (vote_called) - { + if (timeout_status) { print_to(caller, "^7Error: A timeout is already active."); } else if (vote_called) { print_to(caller, "^7Error: You can not call a timeout while a vote is active."); - } - else if (warmup_stage && !g_warmup_allow_timeout) - { + } else if (warmup_stage && !g_warmup_allow_timeout) { print_to(caller, "^7Error: You can not call a timeout in warmup-stage."); - } - else if (time < game_starttime) - { + } else if (time < game_starttime) { print_to(caller, "^7Error: You can not call a timeout while the map is being restarted."); - } - else if (caller && (CS(caller).allowed_timeouts < 1)) - { + } else if (caller && (CS(caller).allowed_timeouts < 1)) { print_to(caller, "^7Error: You already used all your timeout calls for this map."); - } - else if (caller && !IS_PLAYER(caller)) - { + } else if (caller && !IS_PLAYER(caller)) { print_to(caller, "^7Error: You must be a player to call a timeout."); - } - else if ((autocvar_timelimit) && (last_possible_timeout < time - game_starttime)) - { + } else if ((autocvar_timelimit) && (last_possible_timeout < time - game_starttime)) { print_to(caller, "^7Error: It is too late to call a timeout now!"); - } - - else // everything should be okay, proceed with starting the timeout - { - if (caller) CS(caller).allowed_timeouts -= 1; + } else { // everything should be okay, proceed with starting the timeout + if (caller) { CS(caller).allowed_timeouts -= 1; } // write a bprint who started the timeout (and how many they have left) bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(CS(caller).allowed_timeouts), " timeout(s) left)") : ""), "!\n"); @@ -751,14 +692,13 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMA timeout_handler = spawn(); setthink(timeout_handler, timeout_handler_think); - timeout_handler.nextthink = time; // always let the entity think asap + timeout_handler.nextthink = time; // always let the entity think asap Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_TIMEOUT); } - } - else { print_to(caller, "^1Timeouts are not allowed to be called, enable them with sv_timeout 1.\n"); } + } else { print_to(caller, "^1Timeouts are not allowed to be called, enable them with sv_timeout 1.\n"); } - return; // never fall through to usage + return; // never fall through to usage } default: @@ -773,8 +713,7 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMA void CommonCommand_who(float request, entity caller, float argc) { - switch (request) - { + switch (request) { case CMD_REQUEST_COMMAND: { float total_listed_players, is_bot; @@ -791,37 +730,32 @@ void CommonCommand_who(float request, entity caller, float argc) FOREACH_CLIENT(true, { is_bot = (IS_BOT_CLIENT(it)); - if (is_bot) - { + if (is_bot) { tmp_netaddress = "null/botclient"; tmp_crypto_idfp = "null/botclient"; - } - else if (privacy) - { + } else if (privacy) { tmp_netaddress = "hidden"; tmp_crypto_idfp = "hidden"; - } - else - { + } else { tmp_netaddress = it.netaddress; tmp_crypto_idfp = it.crypto_idfp; } print_to(caller, sprintf(strreplace(" ", separator, " #%-3d %-20.20s %-5d %-3d %-9s %-16s %s "), - etof(it), - it.netname, - CS(it).ping, - CS(it).ping_packetloss, - process_time(1, time - CS(it).jointime), - tmp_netaddress, - tmp_crypto_idfp)); + etof(it), + it.netname, + CS(it).ping, + CS(it).ping_packetloss, + process_time(1, time - CS(it).jointime), + tmp_netaddress, + tmp_crypto_idfp)); ++total_listed_players; }); print_to(caller, strcat("Finished listing ", ftos(total_listed_players), " client(s) out of ", ftos(maxclients), " slots.")); - return; // never fall through to usage + return; // never fall through to usage } default: diff --git a/qcsrc/server/command/common.qh b/qcsrc/server/command/common.qh index 13cbfe49e..1b9bc8c9a 100644 --- a/qcsrc/server/command/common.qh +++ b/qcsrc/server/command/common.qh @@ -9,13 +9,15 @@ REGISTRY_SORT(COMMON_COMMANDS) #define COMMON_COMMAND(id, description) \ CLASS(commoncommand_##id, Command) \ ATTRIB(commoncommand_##id, m_name, string, #id); \ - ATTRIB(commoncommand_##id, m_description, string, description); \ + ATTRIB(commoncommand_##id, m_description, string, description); \ ENDCLASS(commoncommand_##id) \ - REGISTER(COMMON_COMMANDS, CMD_SV, id, m_id, NEW(commoncommand_##id)); \ + REGISTER(COMMON_COMMANDS, CMD_SV, id, m_id, NEW(commoncommand_##id)); \ METHOD(commoncommand_##id, m_invokecmd, void(commoncommand_##id this, int request, entity caller, int arguments, string command)) -STATIC_INIT(COMMON_COMMANDS_aliases) { - FOREACH(COMMON_COMMANDS, true, { localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svcmd")); }); +STATIC_INIT(COMMON_COMMANDS_aliases) +{ + FOREACH(COMMON_COMMANDS, true, { localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svcmd")); + }); } #include "vote.qh" @@ -139,25 +141,71 @@ void CommonCommand_who(float request, entity caller, float argc); // ================================== // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) -COMMON_COMMAND(cvar_changes, "Prints a list of all changed server cvars") { CommonCommand_cvar_changes(request, caller); } -COMMON_COMMAND(cvar_purechanges, "Prints a list of all changed gameplay cvars") { CommonCommand_cvar_purechanges(request, caller); } -COMMON_COMMAND(editmob, "Modifies a monster or all monsters") { CommonCommand_editmob(request, caller, arguments); } -COMMON_COMMAND(info, "Request for unique server information set up by admin") { CommonCommand_info(request, caller, arguments); } -COMMON_COMMAND(ladder, "Get information about top players if supported") { CommonCommand_ladder(request, caller); } -COMMON_COMMAND(lsmaps, "List maps which can be used with the current game mode") { CommonCommand_lsmaps(request, caller); } -COMMON_COMMAND(printmaplist, "Display full server maplist reply") { CommonCommand_printmaplist(request, caller); } -COMMON_COMMAND(rankings, "Print information about rankings") { CommonCommand_rankings(request, caller); } -COMMON_COMMAND(records, "List top 10 records for the current map") { CommonCommand_records(request, caller); } -COMMON_COMMAND(teamstatus, "Show information about player and team scores") { CommonCommand_teamstatus(request, caller); } -COMMON_COMMAND(time, "Print different formats/readouts of time") { CommonCommand_time(request, caller); } -COMMON_COMMAND(timein, "Resume the game from being paused with a timeout") { CommonCommand_timein(request, caller); } -COMMON_COMMAND(timeout, "Call a timeout which pauses the game for certain amount of time unless unpaused") { CommonCommand_timeout(request, caller); } -COMMON_COMMAND(vote, "Request an action to be voted upon by players") { VoteCommand(request, caller, arguments, command); } -COMMON_COMMAND(who, "Display detailed client information about all players") { CommonCommand_who(request, caller, arguments);} +COMMON_COMMAND(cvar_changes, "Prints a list of all changed server cvars") +{ + CommonCommand_cvar_changes(request, caller); +} +COMMON_COMMAND(cvar_purechanges, "Prints a list of all changed gameplay cvars") +{ + CommonCommand_cvar_purechanges(request, caller); +} +COMMON_COMMAND(editmob, "Modifies a monster or all monsters") +{ + CommonCommand_editmob(request, caller, arguments); +} +COMMON_COMMAND(info, "Request for unique server information set up by admin") +{ + CommonCommand_info(request, caller, arguments); +} +COMMON_COMMAND(ladder, "Get information about top players if supported") +{ + CommonCommand_ladder(request, caller); +} +COMMON_COMMAND(lsmaps, "List maps which can be used with the current game mode") +{ + CommonCommand_lsmaps(request, caller); +} +COMMON_COMMAND(printmaplist, "Display full server maplist reply") +{ + CommonCommand_printmaplist(request, caller); +} +COMMON_COMMAND(rankings, "Print information about rankings") +{ + CommonCommand_rankings(request, caller); +} +COMMON_COMMAND(records, "List top 10 records for the current map") +{ + CommonCommand_records(request, caller); +} +COMMON_COMMAND(teamstatus, "Show information about player and team scores") +{ + CommonCommand_teamstatus(request, caller); +} +COMMON_COMMAND(time, "Print different formats/readouts of time") +{ + CommonCommand_time(request, caller); +} +COMMON_COMMAND(timein, "Resume the game from being paused with a timeout") +{ + CommonCommand_timein(request, caller); +} +COMMON_COMMAND(timeout, "Call a timeout which pauses the game for certain amount of time unless unpaused") +{ + CommonCommand_timeout(request, caller); +} +COMMON_COMMAND(vote, "Request an action to be voted upon by players") +{ + VoteCommand(request, caller, arguments, command); +} +COMMON_COMMAND(who, "Display detailed client information about all players") +{ + CommonCommand_who(request, caller, arguments); +} void CommonCommand_macro_help(entity caller) { - FOREACH(COMMON_COMMANDS, true, { print_to(caller, sprintf(" ^2%s^7: %s", it.m_name, it.m_description)); }); + FOREACH(COMMON_COMMANDS, true, { print_to(caller, sprintf(" ^2%s^7: %s", it.m_name, it.m_description)); + }); } float CommonCommand_macro_command(float argc, entity caller, string command) @@ -182,5 +230,6 @@ float CommonCommand_macro_usage(float argc, entity caller) void CommonCommand_macro_write_aliases(float fh) { - FOREACH(COMMON_COMMANDS, true, { CMD_Write_Alias("qc_cmd_svcmd", it.m_name, it.m_description); }); + FOREACH(COMMON_COMMANDS, true, { CMD_Write_Alias("qc_cmd_svcmd", it.m_name, it.m_description); + }); } diff --git a/qcsrc/server/command/getreplies.qc b/qcsrc/server/command/getreplies.qc index e67625a30..b0e776d36 100644 --- a/qcsrc/server/command/getreplies.qc +++ b/qcsrc/server/command/getreplies.qc @@ -27,7 +27,7 @@ // See common.qc for their proper commands -string getrecords(int page) // 50 records per page +string getrecords(int page) // 50 records per page { string s = ""; @@ -36,8 +36,7 @@ string getrecords(int page) // 50 records per page MapInfo_ClearTemps(); - if (s == "" && page == 0) return "No records are available on this server.\n"; - else return s; + if (s == "" && page == 0) { return "No records are available on this server.\n"; } else { return s; } } string getrankings() @@ -48,11 +47,10 @@ string getrankings() map = GetMapname(); s = ""; - for (i = 1; i <= RANKINGS_CNT; ++i) - { + for (i = 1; i <= RANKINGS_CNT; ++i) { t = race_readTime(map, i); - if (t == 0) continue; + if (t == 0) { continue; } n = race_readName(map, i); p = count_ordinal(i); @@ -61,8 +59,7 @@ string getrankings() MapInfo_ClearTemps(); - if (s == "") return strcat("No records are available for the map: ", map, "\n"); - else return strcat("Records for ", map, ":\n", s); + if (s == "") { return strcat("No records are available for the map: ", map, "\n"); } else { return strcat("Records for ", map, ":\n", s); } } string getladder() @@ -72,21 +69,15 @@ string getladder() rr = (g_cts) ? CTS_RECORD : RACE_RECORD; - for (k = 0; k < MapInfo_count; ++k) - { - if (MapInfo_Get_ByID(k)) - { - for (i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award - { - if (i == 0) // speed award - { - if (stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) continue; + for (k = 0; k < MapInfo_count; ++k) { + if (MapInfo_Get_ByID(k)) { + for (i = 0; i <= LADDER_CNT; ++i) { // i = 0 because it is the speed award + if (i == 0) { // speed award + if (stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) { continue; } myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp")); - } - else // normal record, if it exists (else break) - { - if (race_readTime(MapInfo_Map_bspname, i) == 0) continue; + } else { // normal record, if it exists (else break) + if (race_readTime(MapInfo_Map_bspname, i) == 0) { continue; } myuid = race_readUID(MapInfo_Map_bspname, i); } @@ -100,38 +91,35 @@ string getladder() temp_s = db_get(TemporaryDB, strcat("ladder", myuid)); - if (temp_s == "") - { + if (temp_s == "") { db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid); ++uidcnt; - for (j = 0; j <= LADDER_CNT + 1; ++j) - { - if (j != LADDER_CNT + 1) temp_s = strcat(temp_s, "0 "); - else temp_s = strcat(temp_s, "0"); + for (j = 0; j <= LADDER_CNT + 1; ++j) { + if (j != LADDER_CNT + 1) { temp_s = strcat(temp_s, "0 "); } else { temp_s = strcat(temp_s, "0"); } } } tokenize_console(temp_s); s = ""; - if (i == 0) // speed award - { - for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string - { - if (j == 0) // speed award + if (i == 0) { // speed award + for (j = 0; j <= LADDER_CNT; ++j) { // loop over each arg in the string + if (j == 0) { // speed award s = strcat(s, ftos(stof(argv(j)) + 1)); // add 1 to speed rec count and write - else s = strcat(s, " ", argv(j)); // just copy over everything else + } else { + s = strcat(s, " ", argv(j)); // just copy over everything else + } } - } - else // record - { - for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string - { - if (j == 0) s = strcat(s, argv(j)); // speed award, dont prefix with " " - else if (j == i) // wanted rec! + } else { // record + for (j = 0; j <= LADDER_CNT; ++j) { // loop over each arg in the string + if (j == 0) { + s = strcat(s, argv(j)); // speed award, dont prefix with " " + } else if (j == i) { // wanted rec! s = strcat(s, " ", ftos(stof(argv(j)) + 1)); // update argv(j) - else s = strcat(s, " ", argv(j)); // just copy over everything else + } else { + s = strcat(s, " ", argv(j)); // just copy over everything else + } } } @@ -144,29 +132,26 @@ string getladder() // 5th place = floor(100 / 5) = 20 points // ... etc - if (i == 0) s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points - else s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points - + if (i == 0) { + s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points + } else { + s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points + } db_put(TemporaryDB, strcat("ladder", myuid), s); } } } - for (i = 0; i <= uidcnt; ++i) // for each known uid - { + for (i = 0; i <= uidcnt; ++i) { // for each known uid thisuid = db_get(TemporaryDB, strcat("uid", ftos(i))); temp_s = db_get(TemporaryDB, strcat("ladder", thisuid)); tokenize_console(temp_s); thiscnt = stof(argv(LADDER_CNT + 1)); - if (thiscnt > top_scores[LADDER_SIZE - 1]) - { - for (j = 0; j < LADDER_SIZE; ++j) // for each place in ladder - { - if (thiscnt > top_scores[j]) - { - for (k = LADDER_SIZE - 1; k >= j; --k) - { + if (thiscnt > top_scores[LADDER_SIZE - 1]) { + for (j = 0; j < LADDER_SIZE; ++j) { // for each place in ladder + if (thiscnt > top_scores[j]) { + for (k = LADDER_SIZE - 1; k >= j; --k) { top_uids[k] = top_uids[k - 1]; top_scores[k] = top_scores[k - 1]; } @@ -184,47 +169,50 @@ string getladder() s = strcat(s, "Pos ^3|"); s = strcat(s, " ^7Total ^3|"); - for (i = 1; i <= LADDER_CNT; ++i) + for (i = 1; i <= LADDER_CNT; ++i) { s = strcat(s, " ^7", count_ordinal(i), " ^3|"); + } s = strcat(s, " ^7Speed awards ^3| ^7Name"); s = strcat(s, "\n^3----+--------"); - for (i = 1; i <= min(9, LADDER_CNT); ++i) + for (i = 1; i <= min(9, LADDER_CNT); ++i) { s = strcat(s, "+-----"); + } #if LADDER_CNT > 9 - for (i = 1; i <= LADDER_CNT - 9; ++i) - s = strcat(s, "+------"); + for (i = 1; i <= LADDER_CNT - 9; ++i) { + s = strcat(s, "+------"); + } #endif s = strcat(s, "+--------------+--------------------\n"); - for (i = 0; i < LADDER_SIZE; ++i) - { + for (i = 0; i < LADDER_SIZE; ++i) { temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i])); tokenize_console(temp_s); - if (argv(LADDER_CNT + 1) == "") // total is 0, skip + if (argv(LADDER_CNT + 1) == "") { // total is 0, skip continue; + } s = strcat(s, strpad(4, count_ordinal(i + 1)), "^3| ^7"); // pos s = strcat(s, strpad(7, argv(LADDER_CNT + 1)), "^3| ^7"); // total - for (j = 1; j <= min(9, LADDER_CNT); ++j) + for (j = 1; j <= min(9, LADDER_CNT); ++j) { s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt - + } #if LADDER_CNT > 9 - for (j = 10; j <= LADDER_CNT; ++j) - s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt + for (j = 10; j <= LADDER_CNT; ++j) { + s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt + } #endif - s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt - s = strcat(s, uid2name(top_uids[i]), "\n"); // name + s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt + s = strcat(s, uid2name(top_uids[i]), "\n"); // name } MapInfo_ClearTemps(); - if (s == "") return "No ladder on this server!\n"; - else return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s); + if (s == "") { return "No ladder on this server!\n"; } else { return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s); } } string getmaplist() @@ -233,11 +221,9 @@ string getmaplist() int i, argc; argc = tokenize_console(autocvar_g_maplist); - for (i = 0; i < argc; ++i) - { - if (MapInfo_CheckMap(argv(i))) - { - if (i % 2) col = "^2"; else col = "^3"; + for (i = 0; i < argc; ++i) { + if (MapInfo_CheckMap(argv(i))) { + if (i % 2) { col = "^2"; } else { col = "^3"; } maplist = sprintf("%s%s%s ", maplist, col, argv(i)); } } @@ -253,32 +239,28 @@ string getlsmaps() bool newmaps = false; int added = 0; - for (int i = 0; i < MapInfo_count; ++i) - { - if ((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags())) - { + for (int i = 0; i < MapInfo_count; ++i) { + if ((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags())) { ++added; - if(added > LSMAPS_MAX) + if (added > LSMAPS_MAX) { continue; // we still get the added count, but skip the actual processing - + } // todo: Check by play count of maps for other game types? - if((g_race || g_cts) && !race_readTime(MapInfo_Map_bspname, 1)) - { + if ((g_race || g_cts) && !race_readTime(MapInfo_Map_bspname, 1)) { newmaps = true; - if (i % 2) col = "^4*"; else col = "^5*"; - } - else - { - if (i % 2) col = "^2"; else col = "^3"; + if (i % 2) { col = "^4*"; } else { col = "^5*"; } + } else { + if (i % 2) { col = "^2"; } else { col = "^3"; } } lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname); } } - if(added > LSMAPS_MAX) + if (added > LSMAPS_MAX) { lsmaps = sprintf("%s^7(%d not listed)", lsmaps, added - LSMAPS_MAX); + } MapInfo_ClearTemps(); return sprintf("^7Maps available (%d)%s: %s\n", added, (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps); diff --git a/qcsrc/server/command/radarmap.qc b/qcsrc/server/command/radarmap.qc index 6c31af72c..5a42b8188 100644 --- a/qcsrc/server/command/radarmap.qc +++ b/qcsrc/server/command/radarmap.qc @@ -27,15 +27,13 @@ float FullTraceFraction(vector a, vector mi, vector ma, vector b) float n, m; n = m = 0; - while (vdist(c - b, >, 1)) - { + while (vdist(c - b, >, 1)) { ++m; tracebox(c, mi, ma, b, MOVE_WORLDONLY, NULL); ++n; - if (!trace_startsolid) - { + if (!trace_startsolid) { black += vlen(trace_endpos - c); c = trace_endpos; } @@ -46,7 +44,7 @@ float FullTraceFraction(vector a, vector mi, vector ma, vector b) c = trace_endpos; } - if (n > 200) LOG_TRACE("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations"); + if (n > 200) { LOG_TRACE("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations"); } return white / (black + white); } @@ -75,14 +73,13 @@ float RadarMapAtPoint_LineBlock(float e, float f, float w, float h, float zmin, ma = '1 0 0' * w + '0 1 0' * h + dz; o = '1 0 0' * e + '0 1 0' * f + '0 0 1' * zmin; - if (e < world.absmin.x - w) return 0; - if (f < world.absmin.y - h) return 0; - if (e > world.absmax.x) return 0; - if (f > world.absmax.y) return 0; + if (e < world.absmin.x - w) { return 0; } + if (f < world.absmin.y - h) { return 0; } + if (e > world.absmax.x) { return 0; } + if (f > world.absmax.y) { return 0; } r = 0; - for (i = 0; i < q; ++i) - { + for (i = 0; i < q; ++i) { vector v1, v2; v1 = v2 = o + dz * i + mi; v1_x += random() * (ma.x - mi.x); @@ -92,7 +89,7 @@ float RadarMapAtPoint_LineBlock(float e, float f, float w, float h, float zmin, v2_y += random() * (ma.y - mi.y); v2_z += random() * (ma.z - mi.z); traceline(v1, v2, MOVE_WORLDONLY, NULL); - if (trace_startsolid || trace_fraction < 1) ++r; + if (trace_startsolid || trace_fraction < 1) { ++r; } } return r / q; } @@ -110,16 +107,15 @@ float RadarMapAtPoint_Block(float e, float f, float w, float h, float zmin, floa ma = '1 0 0' * w + '0 1 0' * h + dz; o = '1 0 0' * e + '0 1 0' * f + '0 0 1' * zmin; - if (e < world.absmin.x - w) return 0; - if (f < world.absmin.y - h) return 0; - if (e > world.absmax.x) return 0; - if (f > world.absmax.y) return 0; + if (e < world.absmin.x - w) { return 0; } + if (f < world.absmin.y - h) { return 0; } + if (e > world.absmax.x) { return 0; } + if (f > world.absmax.y) { return 0; } r = 0; - for (i = 0; i < q; ++i) - { + for (i = 0; i < q; ++i) { tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, NULL); - if (trace_startsolid) ++r; + if (trace_startsolid) { ++r; } } return r / q; } @@ -127,7 +123,7 @@ float RadarMapAtPoint_Sample(float e, float f, float w, float h, float zmin, flo { vector a, b, mi, ma; - q *= 4; // choose q so it matches the regular algorithm in speed + q *= 4; // choose q so it matches the regular algorithm in speed q = 256 * q - 1; // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value @@ -140,14 +136,13 @@ float RadarMapAtPoint_Sample(float e, float f, float w, float h, float zmin, flo float c, i; c = 0; - for (i = 0; i < q; ++i) - { + for (i = 0; i < q; ++i) { vector v; v.x = a.x + random() * b.x; v.y = a.y + random() * b.y; v.z = a.z + random() * b.z; traceline(v, v, MOVE_WORLDONLY, NULL); - if (trace_startsolid) ++c; + if (trace_startsolid) { ++c; } } return c / q; @@ -158,16 +153,16 @@ void sharpen_set(int b, float v) } float sharpen_getpixel(int b, int c) { - if (b < 0) return 0; - if (b >= RADAR_WIDTH_MAX) return 0; - if (c < 0) return 0; - if (c > 2) return 0; + if (b < 0) { return 0; } + if (b >= RADAR_WIDTH_MAX) { return 0; } + if (c < 0) { return 0; } + if (c > 2) { return 0; } return sharpen_buffer[b + c * RADAR_WIDTH_MAX]; } float sharpen_get(float b, float a) { float sum = sharpen_getpixel(b, 1); - if (a == 0) return sum; + if (a == 0) { return sum; } sum *= (8 + 1 / a); sum -= sharpen_getpixel(b - 1, 0); sum -= sharpen_getpixel(b - 1, 1); @@ -181,8 +176,7 @@ float sharpen_get(float b, float a) } void sharpen_shift(int w) { - for (int i = 0; i < w; ++i) - { + for (int i = 0; i < w; ++i) { sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX]; sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX]; sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0; @@ -190,8 +184,7 @@ void sharpen_shift(int w) } void sharpen_init(int w) { - for (int i = 0; i < w; ++i) - { + for (int i = 0; i < w; ++i) { sharpen_buffer[i] = 0; sharpen_buffer[i + RADAR_WIDTH_MAX] = 0; sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0; @@ -199,12 +192,9 @@ void sharpen_init(int w) } void RadarMap_Next() { - if (radarmapper.count & 4) - { + if (radarmapper.count & 4) { localcmd("quit\n"); - } - else if (radarmapper.count & 2) - { + } else if (radarmapper.count & 2) { localcmd(strcat("defer 1 \"sv_cmd radarmap --flags ", ftos(radarmapper.count), strcat(" --res ", ftos(radarmapper.size.x), " ", ftos(radarmapper.size.y), " --sharpen ", ftos(radarmapper.ltime), " --qual ", ftos(radarmapper.size.z)), "\"\n")); GotoNextMap(0); } @@ -222,8 +212,7 @@ void RadarMap_Think(entity this) float i, x, l; string si; - if (this.frame == 0) - { + if (this.frame == 0) { // initialize get_mi_min_max_texcoords(1); this.mins = mi_picmin; @@ -232,17 +221,15 @@ void RadarMap_Think(entity this) this.maxs_z = mi_max.z - mi_min.z; LOG_INFO("Picture mins/maxs: ", ftos(this.maxs.x), " and ", ftos(this.maxs.y), " should match"); this.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm")); - if (!(this.count & 1)) - { + if (!(this.count & 1)) { this.cnt = fopen(this.netname, FILE_READ); - if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ); - if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ); - if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ); - if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ); - if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ); - if (this.cnt < 0) this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ); - if (this.cnt >= 0) - { + if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ); } + if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ); } + if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ); } + if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ); } + if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ); } + if (this.cnt < 0) { this.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ); } + if (this.cnt >= 0) { fclose(this.cnt); LOG_INFO(this.netname, " already exists, aborting (you may want to specify --force)"); @@ -251,8 +238,7 @@ void RadarMap_Think(entity this) } } this.cnt = fopen(this.netname, FILE_WRITE); - if (this.cnt < 0) - { + if (this.cnt < 0) { LOG_INFO("Error writing ", this.netname); delete(this); radarmapper = NULL; @@ -263,48 +249,40 @@ void RadarMap_Think(entity this) fputs(this.cnt, "static char *RadarMap[] = {\n"); fputs(this.cnt, "/* columns rows colors chars-per-pixel */\n"); fputs(this.cnt, strcat("\"", ftos(this.size.x), " ", ftos(this.size.y), " 256 2\",\n")); - for (i = 0; i < 256; ++i) - { + for (i = 0; i < 256; ++i) { si = substring(doublehex, i * 2, 2); fputs(this.cnt, strcat("\"", si, " c #", si, si, si, "\",\n")); } this.frame += 1; this.nextthink = time; sharpen_init(this.size.x); - } - else if (this.frame <= this.size.y) - { + } else if (this.frame <= this.size.y) { // fill the sharpen buffer with this line sharpen_shift(this.size.x); i = this.count & 24; - switch (i) - { + switch (i) { case 0: default: - for (x = 0; x < this.size.x; ++x) - { + for (x = 0; x < this.size.x; ++x) { l = RadarMapAtPoint_Block(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z); sharpen_set(x, l); } break; case 8: - for (x = 0; x < this.size.x; ++x) - { + for (x = 0; x < this.size.x; ++x) { l = RadarMapAtPoint_Trace(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z); sharpen_set(x, l); } break; case 16: - for (x = 0; x < this.size.x; ++x) - { + for (x = 0; x < this.size.x; ++x) { l = RadarMapAtPoint_Sample(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z); sharpen_set(x, l); } break; case 24: - for (x = 0; x < this.size.x; ++x) - { + for (x = 0; x < this.size.x; ++x) { l = RadarMapAtPoint_LineBlock(this.mins.x + x * this.maxs.x, this.mins.y + (this.size.y - this.frame) * this.maxs.y, this.maxs.x, this.maxs.y, this.mins.z, this.maxs.z, this.size.z); sharpen_set(x, l); } @@ -312,43 +290,33 @@ void RadarMap_Think(entity this) } // do we have enough lines? - if (this.frame >= 2) - { + if (this.frame >= 2) { // write a pixel line fputs(this.cnt, "\""); - for (x = 0; x < this.size.x; ++x) - { + for (x = 0; x < this.size.x; ++x) { l = sharpen_get(x, this.ltime); fputs(this.cnt, substring(doublehex, 2 * floor(l * 256.0), 2)); } - if (this.frame == this.size.y) - { + if (this.frame == this.size.y) { fputs(this.cnt, "\"\n"); - } - else - { + } else { fputs(this.cnt, "\",\n"); LOG_INFO(ftos(this.size.y - this.frame), " lines left"); } } // is this the last line? then write back the missing line - if (this.frame == this.size.y) - { + if (this.frame == this.size.y) { sharpen_shift(this.size.x); // write a pixel line fputs(this.cnt, "\""); - for (x = 0; x < this.size.x; ++x) - { + for (x = 0; x < this.size.x; ++x) { l = sharpen_get(x, this.ltime); fputs(this.cnt, substring(doublehex, 2 * floor(l * 256.0), 2)); } - if (this.frame == this.size.y) - { + if (this.frame == this.size.y) { fputs(this.cnt, "\"\n"); - } - else - { + } else { fputs(this.cnt, "\",\n"); LOG_INFO(ftos(this.size.y - this.frame), " lines left"); } @@ -356,9 +324,7 @@ void RadarMap_Think(entity this) this.frame += 1; this.nextthink = time; - } - else - { + } else { // close the file fputs(this.cnt, "};\n"); fclose(this.cnt); @@ -371,18 +337,15 @@ bool RadarMap_Make(float argc) { float i; - if (!radarmapper) - { + if (!radarmapper) { radarmapper = new(radarmapper); setthink(radarmapper, RadarMap_Think); radarmapper.nextthink = time; - radarmapper.count = 8; // default to the --trace method, as it is faster now + radarmapper.count = 8; // default to the --trace method, as it is faster now radarmapper.ltime = 1; radarmapper.size = '512 512 1'; - for (i = 1; i < argc; ++i) - { - switch (argv(i)) - { + for (i = 1; i < argc; ++i) { + switch (argv(i)) { case "--force": { radarmapper.count |= 1; break; @@ -417,13 +380,13 @@ bool RadarMap_Make(float argc) { ++i; radarmapper.count = stof(argv(i)); break; - } // for the recursive call + } // for the recursive call case "--sharpen": { ++i; radarmapper.ltime = stof(argv(i)); break; - } // for the recursive call - case "--res": // minor alias + } // for the recursive call + case "--res": // minor alias case "--resolution": { ++i; radarmapper.size_x = stof(argv(i)); @@ -431,7 +394,7 @@ bool RadarMap_Make(float argc) radarmapper.size_y = stof(argv(i)); break; } - case "--qual": // minor alias + case "--qual": // minor alias case "--quality": { ++i; radarmapper.size_z = stof(argv(i)); @@ -446,10 +409,9 @@ bool RadarMap_Make(float argc) } } - if (radarmapper) // after doing the arguments, see if we successfully went forward. - { + if (radarmapper) { // after doing the arguments, see if we successfully went forward. LOG_INFO("Radarmap entity spawned."); - return true; // if so, don't print usage. + return true; // if so, don't print usage. } } diff --git a/qcsrc/server/command/reg.qh b/qcsrc/server/command/reg.qh index 8115d712e..6dea8ed77 100644 --- a/qcsrc/server/command/reg.qh +++ b/qcsrc/server/command/reg.qh @@ -8,11 +8,13 @@ REGISTRY_SORT(SERVER_COMMANDS) #define SERVER_COMMAND(id, description) \ CLASS(servercommand_##id, Command) \ ATTRIB(servercommand_##id, m_name, string, #id); \ - ATTRIB(servercommand_##id, m_description, string, description); \ + ATTRIB(servercommand_##id, m_description, string, description); \ ENDCLASS(servercommand_##id) \ - REGISTER(SERVER_COMMANDS, CMD_SV, id, m_id, NEW(servercommand_##id)); \ + REGISTER(SERVER_COMMANDS, CMD_SV, id, m_id, NEW(servercommand_##id)); \ METHOD(servercommand_##id, m_invokecmd, void(servercommand_##id this, int request, entity caller, int arguments, string command)) -STATIC_INIT(SERVER_COMMANDS_aliases) { - FOREACH(SERVER_COMMANDS, true, { localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_sv")); }); +STATIC_INIT(SERVER_COMMANDS_aliases) +{ + FOREACH(SERVER_COMMANDS, true, { localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_sv")); + }); } diff --git a/qcsrc/server/compat/halflife.qc b/qcsrc/server/compat/halflife.qc index 74e50137f..322b4d9ef 100644 --- a/qcsrc/server/compat/halflife.qc +++ b/qcsrc/server/compat/halflife.qc @@ -24,7 +24,7 @@ void ammo_9mmAR() {} spawnfunc(ammo_357) {} spawnfunc(weapon_gauss) {} spawnfunc(weapon_hornetgun) {} -//spawnfunc(weapon_shotgun) {} +// spawnfunc(weapon_shotgun) {} spawnfunc(item_healthkit) {} spawnfunc(item_longjump) {} spawnfunc(item_antidote) {} diff --git a/qcsrc/server/compat/quake.qc b/qcsrc/server/compat/quake.qc index 126a0f6f6..48157e65d 100644 --- a/qcsrc/server/compat/quake.qc +++ b/qcsrc/server/compat/quake.qc @@ -12,21 +12,43 @@ spawnfunc(item_armor_mega); spawnfunc(item_health_mega); spawnfunc(item_health_medium); -//*********************** -//QUAKE 1 ENTITIES - So people can play quake1 maps with the xonotic weapons -//*********************** -spawnfunc(weapon_nailgun) {spawnfunc_weapon_electro(this);} -spawnfunc(weapon_supernailgun) {spawnfunc_weapon_hagar(this);} -spawnfunc(weapon_supershotgun) {spawnfunc_weapon_machinegun(this);} - -spawnfunc(item_spikes) {spawnfunc_item_bullets(this);} -//spawnfunc(item_armor1) {spawnfunc_item_armor_medium(this);} // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard -spawnfunc(item_armor2) {spawnfunc_item_armor_mega(this);} -spawnfunc(item_armorInv) {spawnfunc_item_armor_mega(this);} // TODO: make sure we actually want this -spawnfunc(item_health) {if (this.spawnflags & 2) spawnfunc_item_health_mega(this);else spawnfunc_item_health_medium(this);} - -//spawnfunc_item_spikes -//spawnfunc_item_health - - - +// *********************** +// QUAKE 1 ENTITIES - So people can play quake1 maps with the xonotic weapons +// *********************** +spawnfunc(weapon_nailgun) +{ + spawnfunc_weapon_electro(this); +} +spawnfunc(weapon_supernailgun) +{ + spawnfunc_weapon_hagar(this); +} +spawnfunc(weapon_supershotgun) +{ + spawnfunc_weapon_machinegun(this); +} + +spawnfunc(item_spikes) +{ + spawnfunc_item_bullets(this); +} +// spawnfunc(item_armor1) {spawnfunc_item_armor_medium(this);} // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard +spawnfunc(item_armor2) +{ + spawnfunc_item_armor_mega(this); +} +spawnfunc(item_armorInv) +{ + spawnfunc_item_armor_mega(this); +} // TODO: make sure we actually want this +spawnfunc(item_health) +{ + if (this.spawnflags & 2) { + spawnfunc_item_health_mega(this); + } else { + spawnfunc_item_health_medium(this); + } +} + +// spawnfunc_item_spikes +// spawnfunc_item_health diff --git a/qcsrc/server/compat/quake2.qc b/qcsrc/server/compat/quake2.qc index df99f1570..6a9c97a06 100644 --- a/qcsrc/server/compat/quake2.qc +++ b/qcsrc/server/compat/quake2.qc @@ -5,11 +5,17 @@ spawnfunc(item_armor_medium); spawnfunc(item_invincible); -//*********************** -//QUAKE 2 ENTITIES - So people can play quake2 maps with the xonotic weapons -//*********************** -spawnfunc(item_armor_jacket) {spawnfunc_item_armor_medium(this);} +// *********************** +// QUAKE 2 ENTITIES - So people can play quake2 maps with the xonotic weapons +// *********************** +spawnfunc(item_armor_jacket) +{ + spawnfunc_item_armor_medium(this); +} -spawnfunc(item_invulnerability) {spawnfunc_item_invincible(this);} +spawnfunc(item_invulnerability) +{ + spawnfunc_item_invincible(this); +} // rest of the quake 2 entities are handled by q1 and q3 compat diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index 2e2301d0b..b17c7b50c 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -28,58 +28,121 @@ spawnfunc(item_armor_small); spawnfunc(item_health_medium); spawnfunc(item_health_mega); -//*********************** -//QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons -//*********************** +// *********************** +// QUAKE 3 ENTITIES - So people can play quake3 maps with the xonotic weapons +// *********************** // NOTE: for best experience, you need to swap MGs with SGs in the map or it won't have a MG // SG -> SG -spawnfunc(ammo_shells) { spawnfunc_item_shells(this); } +spawnfunc(ammo_shells) +{ + spawnfunc_item_shells(this); +} // MG -> MG -spawnfunc(ammo_bullets) { spawnfunc_item_bullets(this); } +spawnfunc(ammo_bullets) +{ + spawnfunc_item_bullets(this); +} // GL -> Mortar -spawnfunc(ammo_grenades) { spawnfunc_item_rockets(this); } +spawnfunc(ammo_grenades) +{ + spawnfunc_item_rockets(this); +} // Mines -> Rockets -spawnfunc(weapon_prox_launcher) { spawnfunc_weapon_minelayer(this); } -spawnfunc(ammo_mines) { spawnfunc_item_rockets(this); } +spawnfunc(weapon_prox_launcher) +{ + spawnfunc_weapon_minelayer(this); +} +spawnfunc(ammo_mines) +{ + spawnfunc_item_rockets(this); +} // LG -> Lightning -spawnfunc(weapon_lightning) { spawnfunc_weapon_electro(this); } -spawnfunc(ammo_lightning) { spawnfunc_item_cells(this); } +spawnfunc(weapon_lightning) +{ + spawnfunc_weapon_electro(this); +} +spawnfunc(ammo_lightning) +{ + spawnfunc_item_cells(this); +} // Plasma -> Hagar -spawnfunc(weapon_plasmagun) { spawnfunc_weapon_hagar(this); } -spawnfunc(ammo_cells) { spawnfunc_item_rockets(this); } +spawnfunc(weapon_plasmagun) +{ + spawnfunc_weapon_hagar(this); +} +spawnfunc(ammo_cells) +{ + spawnfunc_item_rockets(this); +} // Rail -> Vortex -spawnfunc(weapon_railgun) { spawnfunc_weapon_vortex(this); } -spawnfunc(ammo_slugs) { spawnfunc_item_cells(this); } +spawnfunc(weapon_railgun) +{ + spawnfunc_weapon_vortex(this); +} +spawnfunc(ammo_slugs) +{ + spawnfunc_item_cells(this); +} // BFG -> Crylink -spawnfunc(weapon_bfg) { spawnfunc_weapon_crylink(this); } -spawnfunc(ammo_bfg) { spawnfunc_item_cells(this); } +spawnfunc(weapon_bfg) +{ + spawnfunc_weapon_crylink(this); +} +spawnfunc(ammo_bfg) +{ + spawnfunc_item_cells(this); +} // grappling hook -> hook -spawnfunc(weapon_grapplinghook) { spawnfunc_weapon_hook(this); } +spawnfunc(weapon_grapplinghook) +{ + spawnfunc_weapon_hook(this); +} // RL -> RL -spawnfunc(ammo_rockets) { spawnfunc_item_rockets(this); } +spawnfunc(ammo_rockets) +{ + spawnfunc_item_rockets(this); +} // Armor -spawnfunc(item_armor_body) { spawnfunc_item_armor_mega(this); } -spawnfunc(item_armor_combat) { spawnfunc_item_armor_big(this); } -spawnfunc(item_armor_shard) { spawnfunc_item_armor_small(this); } -spawnfunc(item_enviro) { spawnfunc_item_invincible(this); } +spawnfunc(item_armor_body) +{ + spawnfunc_item_armor_mega(this); +} +spawnfunc(item_armor_combat) +{ + spawnfunc_item_armor_big(this); +} +spawnfunc(item_armor_shard) +{ + spawnfunc_item_armor_small(this); +} +spawnfunc(item_enviro) +{ + spawnfunc_item_invincible(this); +} // medkit -> armor (we have no holdables) -spawnfunc(holdable_medkit) { spawnfunc_item_armor_mega(this); } +spawnfunc(holdable_medkit) +{ + spawnfunc_item_armor_mega(this); +} // doubler -> strength -spawnfunc(item_doubler) { spawnfunc_item_strength(this); } +spawnfunc(item_doubler) +{ + spawnfunc_item_strength(this); +} .float wait; .float delay; @@ -88,24 +151,25 @@ spawnfunc(item_doubler) { spawnfunc_item_strength(this); } void target_init_verify(entity this) { entity trigger, targ; - for(trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); ) - for(targ = NULL; (targ = find(targ, targetname, trigger.target)); ) - if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items") - { + for (trigger = NULL; (trigger = find(trigger, classname, "trigger_multiple")); ) { + for (targ = NULL; (targ = find(targ, targetname, trigger.target)); ) { + if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items") { trigger.wait = 0; trigger.delay = 0; targ.wait = 0; targ.delay = 0; - //setsize(targ, trigger.mins, trigger.maxs); - //setorigin(targ, trigger.origin); - //remove(trigger); + // setsize(targ, trigger.mins, trigger.maxs); + // setorigin(targ, trigger.origin); + // remove(trigger); } + } + } } spawnfunc(target_init) { - this.spawnflags = 0; // remove all weapons except the ones listed below + this.spawnflags = 0; // remove all weapons except the ones listed below this.netname = "shotgun"; // keep these weapons through the remove trigger spawnfunc_target_items(this); InitializeEntity(this, target_init_verify, INITPRIO_FINDTARGET); @@ -119,30 +183,26 @@ void target_give_init(entity this) if (it.classname == "weapon_rocketlauncher" || it.classname == "weapon_devastator") { this.ammo_rockets += it.count * WEP_CVAR(devastator, ammo); this.netname = cons(this.netname, "devastator"); - } - else if (it.classname == "weapon_lightning") { + } else if (it.classname == "weapon_lightning") { this.ammo_cells += it.count * WEP_CVAR_PRI(electro, ammo); // WEAPONTODO this.netname = cons(this.netname, "electro"); - } - else if (it.classname == "weapon_plasmagun") { + } else if (it.classname == "weapon_plasmagun") { this.ammo_rockets += it.count * WEP_CVAR_PRI(hagar, ammo); // WEAPONTODO this.netname = cons(this.netname, "hagar"); - } - else if (it.classname == "weapon_bfg") { + } else if (it.classname == "weapon_bfg") { this.ammo_cells += it.count * WEP_CVAR_PRI(crylink, ammo); this.netname = cons(this.netname, "crylink"); - } - else if (it.classname == "weapon_grenadelauncher" || it.classname == "weapon_mortar") { + } else if (it.classname == "weapon_grenadelauncher" || it.classname == "weapon_mortar") { this.ammo_rockets += it.count * WEP_CVAR_PRI(mortar, ammo); // WEAPONTODO this.netname = cons(this.netname, "mortar"); - } - else if (it.classname == "item_armor_body") + } else if (it.classname == "item_armor_body") { this.armorvalue = 100; - else if (it.classname == "item_health_mega") + } else if (it.classname == "item_health_mega") { this.health = 200; - //remove(it); // removing ents in init functions causes havoc, workaround: - setthink(it, SUB_Remove); - it.nextthink = time; + } + // remove(it); // removing ents in init functions causes havoc, workaround: + setthink(it, SUB_Remove); + it.nextthink = time; }); this.spawnflags = 2; this.spawnfunc_checked = true; @@ -155,14 +215,14 @@ spawnfunc(target_give) InitializeEntity(this, target_give_init, INITPRIO_FINDTARGET); } -//spawnfunc(item_flight) /* handled by buffs mutator */ -//spawnfunc(item_haste) /* handled by buffs mutator */ -//spawnfunc(item_health) /* handled in t_quake.qc */ -//spawnfunc(item_health_large) /* handled in t_items.qc */ -//spawnfunc(item_health_small) /* handled in t_items.qc */ -//spawnfunc(item_health_mega) /* handled in t_items.qc */ -//spawnfunc(item_invis) /* handled by buffs mutator */ -//spawnfunc(item_regen) /* handled by buffs mutator */ +// spawnfunc(item_flight) /* handled by buffs mutator */ +// spawnfunc(item_haste) /* handled by buffs mutator */ +// spawnfunc(item_health) /* handled in t_quake.qc */ +// spawnfunc(item_health_large) /* handled in t_items.qc */ +// spawnfunc(item_health_small) /* handled in t_items.qc */ +// spawnfunc(item_health_mega) /* handled in t_items.qc */ +// spawnfunc(item_invis) /* handled by buffs mutator */ +// spawnfunc(item_regen) /* handled by buffs mutator */ // CTF spawnfuncs handled in mutators/gamemode_ctf.qc now @@ -176,40 +236,53 @@ bool DoesQ3ARemoveThisEntity(entity this) { // Q3 style filters (DO NOT USE, THIS IS COMPAT ONLY) - if(this.notq3a) - if(!teamplay || g_tdm || g_ctf) + if (this.notq3a) { + if (!teamplay || g_tdm || g_ctf) { return true; + } + } - if(this.notta) - if (!(!teamplay || g_tdm || g_ctf)) + if (this.notta) { + if (!(!teamplay || g_tdm || g_ctf)) { return true; + } + } - if(this.notsingle) - if(maxclients == 1) + if (this.notsingle) { + if (maxclients == 1) { return true; + } + } - if(this.notteam) - if(teamplay) + if (this.notteam) { + if (teamplay) { return true; + } + } - if(this.notfree) - if(!teamplay) + if (this.notfree) { + if (!teamplay) { return true; + } + } - if(this.gametype) - { + if (this.gametype) { string gametypename; // static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester", "teamtournament"} gametypename = "ffa"; - if(teamplay) + if (teamplay) { gametypename = "team"; - if(g_ctf) + } + if (g_ctf) { gametypename = "ctf"; - if(maxclients == 1) + } + if (maxclients == 1) { gametypename = "single"; + } // we do not have the other types (oneflag, obelisk, harvester, teamtournament) - if(strstrofs(this.gametype, gametypename, 0) < 0) + if (strstrofs(this.gametype, gametypename, 0) < 0) { return true; + } } return false; diff --git a/qcsrc/server/compat/wop.qc b/qcsrc/server/compat/wop.qc index 6c69859fd..024567747 100644 --- a/qcsrc/server/compat/wop.qc +++ b/qcsrc/server/compat/wop.qc @@ -32,35 +32,101 @@ spawnfunc(item_health_medium); spawnfunc(item_health_mega); spawnfunc(item_invis); -//*********************** -//WORD OF PADMAN ENTITIES - So people can play wop maps with the xonotic weapons -//*********************** +// *********************** +// WORD OF PADMAN ENTITIES - So people can play wop maps with the xonotic weapons +// *********************** -//spawnfunc(item_revival) /* handled by buffs mutator */ -//spawnfunc(item_jumper) /* handled by buffs mutator */ +// spawnfunc(item_revival) /* handled by buffs mutator */ +// spawnfunc(item_jumper) /* handled by buffs mutator */ -spawnfunc(weapon_punchy) { spawnfunc_weapon_arc(this); } -spawnfunc(weapon_nipper) { spawnfunc_weapon_machinegun(this); } -spawnfunc(weapon_pumper) { spawnfunc_weapon_shotgun(this); } -spawnfunc(weapon_boaster) { spawnfunc_weapon_electro(this); } -spawnfunc(weapon_splasher) { spawnfunc_weapon_vortex(this); } -spawnfunc(weapon_bubbleg) { spawnfunc_weapon_hagar(this); } -spawnfunc(weapon_balloony) { spawnfunc_weapon_mortar(this); } -spawnfunc(weapon_betty) { spawnfunc_weapon_devastator(this); } -spawnfunc(weapon_imperius) { spawnfunc_weapon_crylink(this); } +spawnfunc(weapon_punchy) +{ + spawnfunc_weapon_arc(this); +} +spawnfunc(weapon_nipper) +{ + spawnfunc_weapon_machinegun(this); +} +spawnfunc(weapon_pumper) +{ + spawnfunc_weapon_shotgun(this); +} +spawnfunc(weapon_boaster) +{ + spawnfunc_weapon_electro(this); +} +spawnfunc(weapon_splasher) +{ + spawnfunc_weapon_vortex(this); +} +spawnfunc(weapon_bubbleg) +{ + spawnfunc_weapon_hagar(this); +} +spawnfunc(weapon_balloony) +{ + spawnfunc_weapon_mortar(this); +} +spawnfunc(weapon_betty) +{ + spawnfunc_weapon_devastator(this); +} +spawnfunc(weapon_imperius) +{ + spawnfunc_weapon_crylink(this); +} -spawnfunc(ammo_pumper) { spawnfunc_item_shells(this); } -spawnfunc(ammo_nipper) { spawnfunc_item_bullets(this); } -spawnfunc(ammo_balloony) { spawnfunc_item_rockets(this); } -spawnfunc(ammo_bubbleg) { spawnfunc_item_rockets(this); } -spawnfunc(ammo_boaster) { spawnfunc_item_cells(this); } -spawnfunc(ammo_betty) { spawnfunc_item_rockets(this); } -spawnfunc(ammo_imperius) { spawnfunc_item_cells(this); } +spawnfunc(ammo_pumper) +{ + spawnfunc_item_shells(this); +} +spawnfunc(ammo_nipper) +{ + spawnfunc_item_bullets(this); +} +spawnfunc(ammo_balloony) +{ + spawnfunc_item_rockets(this); +} +spawnfunc(ammo_bubbleg) +{ + spawnfunc_item_rockets(this); +} +spawnfunc(ammo_boaster) +{ + spawnfunc_item_cells(this); +} +spawnfunc(ammo_betty) +{ + spawnfunc_item_rockets(this); +} +spawnfunc(ammo_imperius) +{ + spawnfunc_item_cells(this); +} -spawnfunc(item_padpower) { spawnfunc_item_quad(this); } -spawnfunc(item_climber) { spawnfunc_item_invincible(this); } -spawnfunc(item_speedy) { spawnfunc_item_haste(this); } -spawnfunc(item_visionless) { spawnfunc_item_invis(this); } -spawnfunc(item_armor_padshield) { spawnfunc_item_armor_mega(this); } +spawnfunc(item_padpower) +{ + spawnfunc_item_quad(this); +} +spawnfunc(item_climber) +{ + spawnfunc_item_invincible(this); +} +spawnfunc(item_speedy) +{ + spawnfunc_item_haste(this); +} +spawnfunc(item_visionless) +{ + spawnfunc_item_invis(this); +} +spawnfunc(item_armor_padshield) +{ + spawnfunc_item_armor_mega(this); +} -spawnfunc(holdable_floater) { spawnfunc_item_jetpack(this); } +spawnfunc(holdable_floater) +{ + spawnfunc_item_jetpack(this); +} diff --git a/qcsrc/server/g_damage.qh b/qcsrc/server/g_damage.qh index aee4a93df..772410096 100644 --- a/qcsrc/server/g_damage.qh +++ b/qcsrc/server/g_damage.qh @@ -3,30 +3,30 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include <server/defs.qh> - #include <server/miscfunctions.qh> - #include <lib/warpzone/common.qh> - #include <common/constants.qh> - #include <common/teams.qh> - #include <common/util.qh> - #include <common/weapons/_all.qh> - #include "weapons/accuracy.qh" - #include "weapons/csqcprojectile.qh" - #include "weapons/selection.qh" - #include <common/t_items.qh> - #include "autocvars.qh" - #include "constants.qh" - #include "defs.qh" - #include <common/notifications/all.qh> - #include <common/deathtypes/all.qh> - #include "mutators/_mod.qh" - #include <common/turrets/sv_turrets.qh> - #include <common/vehicles/all.qh> - #include <lib/csqcmodel/sv_model.qh> - #include <common/playerstats.qh> - #include "g_hook.qh" - #include "scores.qh" - #include "spawnpoints.qh" + #include <server/defs.qh> + #include <server/miscfunctions.qh> + #include <lib/warpzone/common.qh> + #include <common/constants.qh> + #include <common/teams.qh> + #include <common/util.qh> + #include <common/weapons/_all.qh> + #include "weapons/accuracy.qh" + #include "weapons/csqcprojectile.qh" + #include "weapons/selection.qh" + #include <common/t_items.qh> + #include "autocvars.qh" + #include "constants.qh" + #include "defs.qh" + #include <common/notifications/all.qh> + #include <common/deathtypes/all.qh> + #include "mutators/_mod.qh" + #include <common/turrets/sv_turrets.qh> + #include <common/vehicles/all.qh> + #include <lib/csqcmodel/sv_model.qh> + #include <common/playerstats.qh> + #include "g_hook.qh" + #include "scores.qh" + #include "spawnpoints.qh" #endif .float dmg; @@ -59,42 +59,32 @@ void UpdateFrags(entity player, int f); // NOTE: f=0 means still count as a (positive) kill, but count no frags for it void W_SwitchWeapon_Force(Player this, Weapon w, .entity weaponentity); entity GiveFrags_randomweapons; -void GiveFrags (entity attacker, entity targ, float f, int deathtype); +void GiveFrags(entity attacker, entity targ, float f, int deathtype); string AppendItemcodes(string s, entity player); void LogDeath(string mode, int deathtype, entity killer, entity killed); -void Obituary_SpecialDeath( - entity notif_target, - float murder, - int deathtype, - string s1, string s2, string s3, - float f1, float f2, float f3); +void Obituary_SpecialDeath(entity notif_target, float murder, int deathtype, string s1, string s2, string s3, float f1, float f2, float f3); float w_deathtype; -float Obituary_WeaponDeath( - entity notif_target, - float murder, - int deathtype, - string s1, string s2, string s3, - float f1, float f2); +float Obituary_WeaponDeath(entity notif_target, float murder, int deathtype, string s1, string s2, string s3, float f1, float f2); void Obituary(entity attacker, entity inflictor, entity targ, int deathtype); void Ice_Think(entity this); -void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint); +void Freeze(entity targ, float freeze_time, float frozen_type, float show_waypoint); -void Unfreeze (entity targ); +void Unfreeze(entity targ); -void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force); +void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force); float RadiusDamage_running; -float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector inflictorvelocity, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float inflictorselfdamage, float forceintensity, int deathtype, entity directhitentity); - // Returns total damage applies to creatures +float RadiusDamageForSource(entity inflictor, vector inflictororigin, vector inflictorvelocity, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float inflictorselfdamage, float forceintensity, int deathtype, entity directhitentity); +// Returns total damage applies to creatures -float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype, entity directhitentity); +float RadiusDamage(entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype, entity directhitentity); .float fire_damagepersec; .float fire_endtime; diff --git a/qcsrc/server/g_hook.qc b/qcsrc/server/g_hook.qc index 0fc60b2cd..8c52a2999 100644 --- a/qcsrc/server/g_hook.qc +++ b/qcsrc/server/g_hook.qc @@ -53,16 +53,16 @@ const float GRAPHOOK_RELEASE = 21; 4. Open client.c and add this to the top of PutClientInServer(): - RemoveGrapplingHook(this); // Wazat's Grappling Hook + RemoveGrapplingHook(this); // Wazat's Grappling Hook 5. Find ClientConnect() (in client.c) and add these lines to the bottom: - // Wazat's grappling hook - SetGrappleHookBindings(); + // Wazat's grappling hook + SetGrappleHookBindings(); 6. Still in client.c, find PlayerPreThink and add this line just above the call to W_WeaponFrame: - GrapplingHookFrame(); + GrapplingHookFrame(); 7. Build and test the mod. You'll want to bind a key to "+hook" like this: bind ctrl "+hook" @@ -76,33 +76,37 @@ And you should be done! void RemoveGrapplingHooks(entity pl) { - if(pl.move_movetype == MOVETYPE_FLY) + if (pl.move_movetype == MOVETYPE_FLY) { set_movetype(pl, MOVETYPE_WALK); + } - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { - .entity weaponentity = weaponentities[slot]; - if(!pl.(weaponentity)) - continue; // continue incase other slots exist? - if(pl.(weaponentity).hook) - delete(pl.(weaponentity).hook); - pl.(weaponentity).hook = NULL; - } - - //pl.disableclientprediction = false; + for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { + .entity weaponentity = weaponentities[slot]; + if (!pl.(weaponentity)) { + continue; // continue incase other slots exist? + } + if (pl.(weaponentity).hook) { + delete(pl.(weaponentity).hook); + } + pl.(weaponentity).hook = NULL; + } + + // pl.disableclientprediction = false; } void RemoveHook(entity this) { entity player = this.realowner; - .entity weaponentity = this.weaponentity_fld; + .entity weaponentity = this.weaponentity_fld; - if(player.(weaponentity).hook == this) - player.(weaponentity).hook = NULL; + if (player.(weaponentity).hook == this) { + player.(weaponentity).hook = NULL; + } - if(player.move_movetype == MOVETYPE_FLY) - set_movetype(player, MOVETYPE_WALK); - delete(this); + if (player.move_movetype == MOVETYPE_FLY) { + set_movetype(player, MOVETYPE_WALK); + } + delete(this); } void GrapplingHookReset(entity this) @@ -114,7 +118,7 @@ void GrapplingHookThink(entity this); void GrapplingHook_Stop(entity this) { Send_Effect(EFFECT_HOOK_IMPACT, this.origin, '0 0 0', 1); - sound (this, CH_SHOTS, SND_HOOK_IMPACT, VOL_BASE, ATTEN_NORM); + sound(this, CH_SHOTS, SND_HOOK_IMPACT, VOL_BASE, ATTEN_NORM); this.state = 1; setthink(this, GrapplingHookThink); @@ -130,22 +134,20 @@ bool GrapplingHookSend(entity this, entity to, int sf) { WriteHeader(MSG_ENTITY, ENT_CLIENT_HOOK); sf = sf & 0x7F; - if(sound_allowed(MSG_BROADCAST, this.realowner)) + if (sound_allowed(MSG_BROADCAST, this.realowner)) { sf |= 0x80; + } WriteByte(MSG_ENTITY, sf); - if(sf & 1) - { + if (sf & 1) { WriteByte(MSG_ENTITY, etof(this.realowner)); WriteByte(MSG_ENTITY, weaponslot(this.weaponentity_fld)); } - if(sf & 2) - { + if (sf & 2) { WriteCoord(MSG_ENTITY, this.hook_start.x); WriteCoord(MSG_ENTITY, this.hook_start.y); WriteCoord(MSG_ENTITY, this.hook_start.z); } - if(sf & 4) - { + if (sf & 4) { WriteCoord(MSG_ENTITY, this.hook_end.x); WriteCoord(MSG_ENTITY, this.hook_end.y); WriteCoord(MSG_ENTITY, this.hook_end.z); @@ -160,18 +162,17 @@ void GrapplingHookThink(entity this) float spd, dist, minlength, pullspeed, ropestretch, ropeairfriction, rubberforce, newlength, rubberforce_overstretch; vector dir, org, end, v0, dv, v, myorg, vs; .entity weaponentity = this.weaponentity_fld; - if(this.realowner.(weaponentity).hook != this) // how did that happen? - { + if (this.realowner.(weaponentity).hook != this) { // how did that happen? error("Owner lost the hook!\n"); return; } - if(LostMovetypeFollow(this) || game_stopped || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || ((this.aiment.flags & FL_PROJECTILE) && this.aiment.classname != "nade")) - { + if (LostMovetypeFollow(this) || game_stopped || (round_handler_IsActive() && !round_handler_IsRoundStarted()) || ((this.aiment.flags & FL_PROJECTILE) && this.aiment.classname != "nade")) { RemoveHook(this); return; } - if(this.aiment) + if (this.aiment) { WarpZone_RefSys_AddIncrementally(this, this.aiment); + } this.nextthink = time; @@ -182,8 +183,9 @@ void GrapplingHookThink(entity this) org = this.realowner.origin + this.realowner.view_ofs + v_forward * vs.x + v_right * -vs.y + v_up * vs.z; myorg = WarpZone_RefSys_TransformOrigin(this.realowner, this, org); - if(this.hook_length < 0) + if (this.hook_length < 0) { this.hook_length = vlen(myorg - this.origin); + } int tarzan = autocvar_g_grappling_hook_tarzan; entity pull_entity = this.realowner; @@ -193,26 +195,25 @@ void GrapplingHookThink(entity this) pull_entity = M_ARGV(2, entity); velocity_multiplier = M_ARGV(3, float); - if(this.state == 1) - { - pullspeed = autocvar_g_balance_grapplehook_speed_pull;//2000; + if (this.state == 1) { + pullspeed = autocvar_g_balance_grapplehook_speed_pull; // 2000; // speed the rope is pulled with - rubberforce = autocvar_g_balance_grapplehook_force_rubber;//2000; + rubberforce = autocvar_g_balance_grapplehook_force_rubber; // 2000; // force the rope will use if it is stretched - rubberforce_overstretch = autocvar_g_balance_grapplehook_force_rubber_overstretch;//1000; + rubberforce_overstretch = autocvar_g_balance_grapplehook_force_rubber_overstretch; // 1000; // force the rope will use if it is stretched - minlength = autocvar_g_balance_grapplehook_length_min;//100; + minlength = autocvar_g_balance_grapplehook_length_min; // 100; // minimal rope length // if the rope goes below this length, it isn't pulled any more - ropestretch = autocvar_g_balance_grapplehook_stretch;//400; + ropestretch = autocvar_g_balance_grapplehook_stretch; // 400; // if the rope is stretched by more than this amount, more rope is // given to you again - ropeairfriction = autocvar_g_balance_grapplehook_airfriction;//0.2 + ropeairfriction = autocvar_g_balance_grapplehook_airfriction; // 0.2 // while hanging on the rope, this friction component will help you a // bit to control the rope @@ -222,57 +223,52 @@ void GrapplingHookThink(entity this) dist = vlen(dir); dir = normalize(dir); - if(tarzan) - { + if (tarzan) { v = v0 = WarpZone_RefSys_TransformVelocity(pull_entity, this, pull_entity.velocity); // first pull the rope... - if(this.realowner.(weaponentity).hook_state & HOOK_PULLING) - { + if (this.realowner.(weaponentity).hook_state & HOOK_PULLING) { newlength = this.hook_length; newlength = max(newlength - pullspeed * frametime, minlength); - if(newlength < dist - ropestretch) // overstretched? - { + if (newlength < dist - ropestretch) { // overstretched? newlength = dist - ropestretch; - if(v * dir < 0) // only if not already moving in hook direction + if (v * dir < 0) { // only if not already moving in hook direction v = v + frametime * dir * rubberforce_overstretch; + } } this.hook_length = newlength; } - if(pull_entity.move_movetype == MOVETYPE_FLY) + if (pull_entity.move_movetype == MOVETYPE_FLY) { set_movetype(pull_entity, MOVETYPE_WALK); + } - if(this.realowner.(weaponentity).hook_state & HOOK_RELEASING) - { + if (this.realowner.(weaponentity).hook_state & HOOK_RELEASING) { newlength = dist; this.hook_length = newlength; - } - else - { + } else { // then pull the player spd = bound(0, (dist - this.hook_length) / ropestretch, 1); v = v * (1 - frametime * ropeairfriction); v = v + frametime * dir * spd * rubberforce; dv = ((v - v0) * dir) * dir; - if(tarzan >= 2) - { - if(this.aiment.move_movetype == MOVETYPE_WALK || this.aiment.classname == "nade") - { + if (tarzan >= 2) { + if (this.aiment.move_movetype == MOVETYPE_WALK || this.aiment.classname == "nade") { entity aim_ent = ((IS_VEHICLE(this.aiment) && this.aiment.owner) ? this.aiment.owner : this.aiment); v = v - dv * 0.5; - if((frozen_pulling && STAT(FROZEN, this.aiment)) || !frozen_pulling) - { + if ((frozen_pulling && STAT(FROZEN, this.aiment)) || !frozen_pulling) { this.aiment.velocity = this.aiment.velocity - dv * 0.5; UNSET_ONGROUND(this.aiment); - if(this.aiment.flags & FL_PROJECTILE) + if (this.aiment.flags & FL_PROJECTILE) { UpdateCSQCProjectile(this.aiment); + } } - if(this.aiment.classname == "nade") + if (this.aiment.classname == "nade") { this.aiment.nextthink = time + autocvar_g_balance_grapplehook_nade_time; // set time after letting go? + } aim_ent.pusher = this.realowner; aim_ent.pushltime = time + autocvar_g_maxpushtime; aim_ent.istypefrag = PHYS_INPUT_BUTTON_CHAT(aim_ent); @@ -282,26 +278,26 @@ void GrapplingHookThink(entity this) UNSET_ONGROUND(pull_entity); } - if(!frozen_pulling && !(this.aiment.flags & FL_PROJECTILE)) + if (!frozen_pulling && !(this.aiment.flags & FL_PROJECTILE)) { pull_entity.velocity = WarpZone_RefSys_TransformVelocity(this, pull_entity, v * velocity_multiplier); + } - if(frozen_pulling && autocvar_g_balance_grapplehook_pull_frozen == 2 && !STAT(FROZEN, this.aiment)) - { + if (frozen_pulling && autocvar_g_balance_grapplehook_pull_frozen == 2 && !STAT(FROZEN, this.aiment)) { RemoveHook(this); return; } - } - else - { - end = this.origin - dir*50; + } else { + end = this.origin - dir * 50; dist = vlen(end - myorg); - if(dist < 200) + if (dist < 200) { spd = dist * (pullspeed / 200); - else + } else { spd = pullspeed; - if(spd < 50) + } + if (spd < 50) { spd = 0; - this.realowner.velocity = dir*spd; + } + this.realowner.velocity = dir * spd; set_movetype(this.realowner, MOVETYPE_FLY); UNSET_ONGROUND(this.realowner); @@ -311,13 +307,11 @@ void GrapplingHookThink(entity this) makevectors(this.angles.x * '-1 0 0' + this.angles.y * '0 1 0'); myorg = WarpZone_RefSys_TransformOrigin(this, this.realowner, this.origin); // + v_forward * (-9); - if(myorg != this.hook_start) - { + if (myorg != this.hook_start) { this.SendFlags |= 2; this.hook_start = myorg; } - if(org != this.hook_end) - { + if (org != this.hook_end) { this.SendFlags |= 4; this.hook_end = org; } @@ -325,36 +319,36 @@ void GrapplingHookThink(entity this) void GrapplingHookTouch(entity this, entity toucher) { - if(toucher.move_movetype == MOVETYPE_FOLLOW) + if (toucher.move_movetype == MOVETYPE_FOLLOW) { return; + } PROJECTILE_TOUCH(this, toucher); GrapplingHook_Stop(this); - if(toucher) - if(toucher.move_movetype != MOVETYPE_NONE) - { + if (toucher) { + if (toucher.move_movetype != MOVETYPE_NONE) { SetMovetypeFollow(this, toucher); WarpZone_RefSys_BeginAddingIncrementally(this, this.aiment); } + } - //this.realowner.disableclientprediction = true; + // this.realowner.disableclientprediction = true; } void GrapplingHook_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) { - if(this.health <= 0) + if (this.health <= 0) { return; + } - if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions + if (!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) { // no exceptions return; // g_balance_projectiledamage says to halt - + } this.health = this.health - damage; - if (this.health <= 0) - { - if(attacker != this.realowner) - { + if (this.health <= 0) { + if (attacker != this.realowner) { this.realowner.pusher = attacker; this.realowner.pushltime = time + autocvar_g_maxpushtime; this.realowner.istypefrag = PHYS_INPUT_BUTTON_CHAT(this.realowner); @@ -365,8 +359,8 @@ void GrapplingHook_Damage(entity this, entity inflictor, entity attacker, float void FireGrapplingHook(entity actor, .entity weaponentity) { - if(forbidWeaponUse(actor)) return; - if(actor.vehicle) return; + if (forbidWeaponUse(actor)) { return; } + if (actor.vehicle) { return; } makevectors(actor.v_angle); @@ -374,7 +368,7 @@ void FireGrapplingHook(entity actor, .entity weaponentity) vector vs = hook_shotorigin[s]; // UGLY WORKAROUND: play this on CH_WEAPON_B so it can't cut off fire sounds - sound (actor, CH_WEAPON_B, SND_HOOK_FIRE, VOL_BASE, ATTEN_NORM); + sound(actor, CH_WEAPON_B, SND_HOOK_FIRE, VOL_BASE, ATTEN_NORM); vector org = actor.origin + actor.view_ofs + v_forward * vs.x + v_right * -vs.y + v_up * vs.z; tracebox(actor.origin + actor.view_ofs, '-3 -3 -3', '3 3 3', org, MOVE_NORMAL, actor); @@ -395,30 +389,31 @@ void FireGrapplingHook(entity actor, .entity weaponentity) set_movetype(missile, ((autocvar_g_balance_grapplehook_gravity) ? MOVETYPE_TOSS : MOVETYPE_FLY)); PROJECTILE_MAKETRIGGER(missile); - //setmodel (missile, MDL_HOOK); // precision set below - setsize (missile, '-3 -3 -3', '3 3 3'); + // setmodel (missile, MDL_HOOK); // precision set below + setsize(missile, '-3 -3 -3', '3 3 3'); setorigin(missile, org); missile.state = 0; // not latched onto anything W_SetupProjVelocity_Explicit(missile, v_forward, v_up, autocvar_g_balance_grapplehook_speed_fly, 0, 0, 0, false); - missile.angles = vectoangles (missile.velocity); - //missile.glow_color = 250; // 244, 250 - //missile.glow_size = 120; + missile.angles = vectoangles(missile.velocity); + // missile.glow_color = 250; // 244, 250 + // missile.glow_size = 120; settouch(missile, GrapplingHookTouch); setthink(missile, GrapplingHookThink); missile.nextthink = time; missile.effects = /*EF_FULLBRIGHT | EF_ADDITIVE |*/ EF_LOWPRECISION; - missile.health = autocvar_g_balance_grapplehook_health;//120 + missile.health = autocvar_g_balance_grapplehook_health; // 120 missile.event_damage = GrapplingHook_Damage; missile.takedamage = DAMAGE_AIM; missile.damageforcescale = 0; missile.damagedbycontents = (autocvar_g_balance_grapplehook_damagedbycontents); - if(missile.damagedbycontents) + if (missile.damagedbycontents) { IL_PUSH(g_damagedbycontents, missile); + } missile.hook_start = missile.hook_end = missile.origin; @@ -427,15 +422,12 @@ void FireGrapplingHook(entity actor, .entity weaponentity) void GrappleHookInit() { - if(g_grappling_hook) - { + if (g_grappling_hook) { hook_shotorigin[0] = '8 8 -12'; hook_shotorigin[1] = '8 8 -12'; hook_shotorigin[2] = '8 8 -12'; hook_shotorigin[3] = '8 8 -12'; - } - else - { + } else { Weapon w = WEP_HOOK; w.wr_init(w); hook_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_HOOK.m_id), false, false, 1); diff --git a/qcsrc/server/g_hook.qh b/qcsrc/server/g_hook.qh index 719bf5b60..3d04416b5 100644 --- a/qcsrc/server/g_hook.qh +++ b/qcsrc/server/g_hook.qh @@ -1,7 +1,7 @@ #pragma once // Wazat's grappling hook -.entity hook; +.entity hook; void RemoveGrapplingHooks(entity pl); void RemoveHook(entity this); // (note: you can change the hook impulse #'s to whatever you please) diff --git a/qcsrc/server/g_lights.qc b/qcsrc/server/g_lights.qc index 852f1efc0..e7714d9ab 100644 --- a/qcsrc/server/g_lights.qc +++ b/qcsrc/server/g_lights.qc @@ -39,16 +39,18 @@ flags: */ void dynlight_think(entity this) { - if(!this.owner) + if (!this.owner) { delete(this); + } this.nextthink = time + 0.1; } void dynlight_find_aiment(entity this) { entity targ; - if (!this.target) - objerror (this, "dynlight: no target to follow"); + if (!this.target) { + objerror(this, "dynlight: no target to follow"); + } targ = find(NULL, targetname, this.target); set_movetype(this, MOVETYPE_FOLLOW); @@ -63,8 +65,9 @@ void dynlight_find_aiment(entity this) void dynlight_find_path(entity this) { entity targ; - if (!this.target) - objerror (this, "dynlight: no target to follow"); + if (!this.target) { + objerror(this, "dynlight: no target to follow"); + } targ = find(NULL, targetname, this.target); this.target = targ.target; @@ -75,8 +78,9 @@ void dynlight_find_path(entity this) void dynlight_find_target(entity this) { entity targ; - if (!this.target) - objerror (this, "dynlight: no target to follow"); + if (!this.target) { + objerror(this, "dynlight: no target to follow"); + } targ = find(NULL, targetname, this.target); setattachment(this, targ, this.dtagname); @@ -86,49 +90,50 @@ void dynlight_find_target(entity this) } void dynlight_use(entity this, entity actor, entity trigger) { - if (this.light_lev == 0) + if (this.light_lev == 0) { this.light_lev = this.lefty; - else + } else { this.light_lev = 0; + } } spawnfunc(dynlight) { - if (!this.light_lev) + if (!this.light_lev) { this.light_lev = 200; - if (!this.color) + } + if (!this.color) { this.color = '1 1 1'; + } this.lefty = this.light_lev; this.use = dynlight_use; - setsize (this, '0 0 0', '0 0 0'); + setsize(this, '0 0 0', '0 0 0'); setorigin(this, this.origin); - //this.pflags = PFLAGS_FULLDYNAMIC; + // this.pflags = PFLAGS_FULLDYNAMIC; this.solid = SOLID_NOT; - //this.blocked = func_null; - //if (this.spawnflags & DNOSHADOW) + // this.blocked = func_null; + // if (this.spawnflags & DNOSHADOW) // this.pflags = this.pflags + PFLAGS_NOSHADOW; - //if (this.spawnflags & START_OFF) + // if (this.spawnflags & START_OFF) // this.light_lev = 0; -//tag attaching - if (this.dtagname) - { +// tag attaching + if (this.dtagname) { InitializeEntity(this, dynlight_find_target, INITPRIO_FINDTARGET); return; } // entity following - if (this.spawnflags & DFOLLOW) - { + if (this.spawnflags & DFOLLOW) { InitializeEntity(this, dynlight_find_aiment, INITPRIO_FINDTARGET); return; } // path following - if (this.target) + if (this.target) { // if (!(this.spawnflags & DFOLLOW)) - { set_movetype(this, MOVETYPE_NOCLIP); - if (!this.speed) + if (!this.speed) { this.speed = 100; + } InitializeEntity(this, dynlight_find_path, INITPRIO_FINDTARGET); return; } diff --git a/qcsrc/server/g_subs.qc b/qcsrc/server/g_subs.qc index 713577fad..0b3202019 100644 --- a/qcsrc/server/g_subs.qc +++ b/qcsrc/server/g_subs.qc @@ -21,10 +21,8 @@ main unused but required by the engine ================== */ -void main () -{ - -} +void main() +{} // Misc @@ -36,21 +34,22 @@ A version of traceline that must be used by SOLID_SLIDEBOX things that want to h Additionally it moves players back into the past before the trace and restores them afterward. ================== */ -void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz) +void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz) { // check whether antilagged traces are enabled - if (lag < 0.001) + if (lag < 0.001) { lag = 0; - if (!IS_REAL_CLIENT(forent)) + } + if (!IS_REAL_CLIENT(forent)) { lag = 0; // only antilag for clients - + } // change shooter to SOLID_BBOX so the shot can hit corpses int oldsolid = source.dphitcontentsmask; - if(source) + if (source) { source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE; + } - if (lag) - { + if (lag) { // take players back into the past FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_takeback(it, CS(it), time - lag)); IL_EACH(g_monsters, it != forent, @@ -60,14 +59,14 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, } // do the trace - if(wz) - WarpZone_TraceBox (v1, mi, ma, v2, nomonst, forent); - else - tracebox (v1, mi, ma, v2, nomonst, forent); + if (wz) { + WarpZone_TraceBox(v1, mi, ma, v2, nomonst, forent); + } else { + tracebox(v1, mi, ma, v2, nomonst, forent); + } // restore players to current positions - if (lag) - { + if (lag) { FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_restore(it, CS(it))); IL_EACH(g_monsters, it != forent, { @@ -76,53 +75,58 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, } // restore shooter solid type - if(source) + if (source) { source.dphitcontentsmask = oldsolid; + } } -void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag) +void traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag) { tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, false); } -void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag) +void traceline_antilag(entity source, vector v1, vector v2, float nomonst, entity forent, float lag) { bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false); - if (autocvar_g_antilag != 2 || noantilag) + if (autocvar_g_antilag != 2 || noantilag) { lag = 0; + } traceline_antilag_force(source, v1, v2, nomonst, forent, lag); } -void tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag) +void tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag) { bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false); - if (autocvar_g_antilag != 2 || noantilag) + if (autocvar_g_antilag != 2 || noantilag) { lag = 0; + } tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, false); } -void WarpZone_traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag) +void WarpZone_traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag) { tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, true); } -void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag) +void WarpZone_traceline_antilag(entity source, vector v1, vector v2, float nomonst, entity forent, float lag) { bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false); - if (autocvar_g_antilag != 2 || noantilag) + if (autocvar_g_antilag != 2 || noantilag) { lag = 0; + } WarpZone_traceline_antilag_force(source, v1, v2, nomonst, forent, lag); } -void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag) +void WarpZone_tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag) { bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false); - if (autocvar_g_antilag != 2 || noantilag) + if (autocvar_g_antilag != 2 || noantilag) { lag = 0; + } tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, true); } -float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity) // returns the number of traces done, for benchmarking +float tracebox_inverted(vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity) // returns the number of traces done, for benchmarking { vector pos, dir, t; float nudge; entity stopentity; - //nudge = 2 * cvar("collision_impactnudge"); // why not? + // nudge = 2 * cvar("collision_impactnudge"); // why not? nudge = 0.5; dir = normalize(v2 - v1); @@ -132,10 +136,8 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon float c; c = 0; - for (;;) - { - if(pos * dir >= v2 * dir) - { + for ( ; ; ) { + if (pos * dir >= v2 * dir) { // went too far trace_fraction = 1; trace_endpos = v2; @@ -145,8 +147,7 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon tracebox(pos, mi, ma, v2, nomonsters, forent); ++c; - if(c == 50) - { + if (c == 50) { LOG_TRACE("HOLY SHIT! When tracing from ", vtos(v1), " to ", vtos(v2)); LOG_TRACE(" Nudging gets us nowhere at ", vtos(pos)); LOG_TRACE(" trace_endpos is ", vtos(trace_endpos)); @@ -155,37 +156,30 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon stopentity = trace_ent; - if(trace_startsolid) - { + if (trace_startsolid) { // we started inside solid. // then trace from endpos to pos t = trace_endpos; tracebox(t, mi, ma, pos, nomonsters, forent); ++c; - if(trace_startsolid) - { + if (trace_startsolid) { // t is still inside solid? bad // force advance, then, and retry pos = t + dir * nudge; // but if we hit an entity, stop RIGHT before it - if(stopatentity && stopentity && stopentity != ignorestopatentity) - { + if (stopatentity && stopentity && stopentity != ignorestopatentity) { trace_ent = stopentity; trace_endpos = t; trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir); return c; } - } - else - { + } else { // we actually LEFT solid! trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir); return c; } - } - else - { + } else { // pos is outside solid?!? but why?!? never mind, just return it. trace_endpos = pos; trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir); @@ -194,7 +188,7 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon } } -void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity) +void traceline_inverted(vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity) { tracebox_inverted(v1, '0 0 0', '0 0 0', v2, nomonsters, forent, stopatentity, ignorestopatentity); } @@ -208,23 +202,21 @@ Returns a point at least 12 units away from walls Ripped from DPMod ================== */ -vector findbetterlocation (vector org, float mindist) +vector findbetterlocation(vector org, float mindist) { vector vec = mindist * '1 0 0'; int c = 0; - while (c < 6) - { - traceline (org, org + vec, true, NULL); + while (c < 6) { + traceline(org, org + vec, true, NULL); vec = vec * -1; - if (trace_fraction < 1) - { + if (trace_fraction < 1) { vector loc = trace_endpos; - traceline (loc, loc + vec, true, NULL); - if (trace_fraction >= 1) + traceline(loc, loc + vec, true, NULL); + if (trace_fraction >= 1) { org = loc + vec; + } } - if (c & 1) - { + if (c & 1) { float h = vec.y; vec.y = vec.x; vec.x = vec.z; @@ -238,26 +230,27 @@ vector findbetterlocation (vector org, float mindist) bool LOD_customize(entity this, entity client) { - if(autocvar_loddebug) - { + if (autocvar_loddebug) { int d = autocvar_loddebug; - if(d == 1) + if (d == 1) { this.modelindex = this.lodmodelindex0; - else if(d == 2 || !this.lodmodelindex2) + } else if (d == 2 || !this.lodmodelindex2) { this.modelindex = this.lodmodelindex1; - else // if(d == 3) + } else { // if(d == 3) this.modelindex = this.lodmodelindex2; + } return true; } // TODO csqc network this so it only gets sent once vector near_point = NearestPointOnBox(this, client.origin); - if(vdist(near_point - client.origin, <, this.loddistance1)) + if (vdist(near_point - client.origin, <, this.loddistance1)) { this.modelindex = this.lodmodelindex0; - else if(!this.lodmodelindex2 || vdist(near_point - client.origin, <, this.loddistance2)) + } else if (!this.lodmodelindex2 || vdist(near_point - client.origin, <, this.loddistance2)) { this.modelindex = this.lodmodelindex1; - else + } else { this.modelindex = this.lodmodelindex2; + } return true; } @@ -271,38 +264,34 @@ void LODmodel_attach(entity this) { entity e; - if(!this.loddistance1) + if (!this.loddistance1) { this.loddistance1 = 1000; - if(!this.loddistance2) + } + if (!this.loddistance2) { this.loddistance2 = 2000; + } this.lodmodelindex0 = this.modelindex; - if(this.lodtarget1 != "") - { + if (this.lodtarget1 != "") { e = find(NULL, targetname, this.lodtarget1); - if(e) - { + if (e) { this.lodmodel1 = e.model; delete(e); } } - if(this.lodtarget2 != "") - { + if (this.lodtarget2 != "") { e = find(NULL, targetname, this.lodtarget2); - if(e) - { + if (e) { this.lodmodel2 = e.model; delete(e); } } - if(autocvar_loddebug < 0) - { + if (autocvar_loddebug < 0) { this.lodmodel1 = this.lodmodel2 = ""; // don't even initialize } - if(this.lodmodel1 != "") - { + if (this.lodmodel1 != "") { vector mi, ma; mi = this.mins; ma = this.maxs; @@ -311,8 +300,7 @@ void LODmodel_attach(entity this) _setmodel(this, this.lodmodel1); this.lodmodelindex1 = this.modelindex; - if(this.lodmodel2 != "") - { + if (this.lodmodel2 != "") { precache_model(this.lodmodel2); _setmodel(this, this.lodmodel2); this.lodmodelindex2 = this.modelindex; @@ -322,73 +310,69 @@ void LODmodel_attach(entity this) setsize(this, mi, ma); } - if(this.lodmodelindex1) - if (!getSendEntity(this)) + if (this.lodmodelindex1) { + if (!getSendEntity(this)) { SetCustomizer(this, LOD_customize, LOD_uncustomize); + } + } } void ApplyMinMaxScaleAngles(entity e) { - if(e.angles.x != 0 || e.angles.z != 0 || e.avelocity.x != 0 || e.avelocity.z != 0) // "weird" rotation - { + if (e.angles.x != 0 || e.angles.z != 0 || e.avelocity.x != 0 || e.avelocity.z != 0) { // "weird" rotation e.maxs = '1 1 1' * vlen( - '1 0 0' * max(-e.mins.x, e.maxs.x) + - '0 1 0' * max(-e.mins.y, e.maxs.y) + - '0 0 1' * max(-e.mins.z, e.maxs.z) - ); + '1 0 0' * max(-e.mins.x, e.maxs.x) + + '0 1 0' * max(-e.mins.y, e.maxs.y) + + '0 0 1' * max(-e.mins.z, e.maxs.z) + ); e.mins = -e.maxs; - } - else if(e.angles.y != 0 || e.avelocity.y != 0) // yaw only is a bit better - { + } else if (e.angles.y != 0 || e.avelocity.y != 0) { // yaw only is a bit better e.maxs_x = vlen( - '1 0 0' * max(-e.mins.x, e.maxs.x) + - '0 1 0' * max(-e.mins.y, e.maxs.y) - ); + '1 0 0' * max(-e.mins.x, e.maxs.x) + + '0 1 0' * max(-e.mins.y, e.maxs.y) + ); e.maxs_y = e.maxs.x; e.mins_x = -e.maxs.x; e.mins_y = -e.maxs.x; } - if(e.scale) + if (e.scale) { setsize(e, e.mins * e.scale, e.maxs * e.scale); - else + } else { setsize(e, e.mins, e.maxs); + } } void SetBrushEntityModel(entity this) { - if(this.model != "") - { - precache_model(this.model); - if(this.mins != '0 0 0' || this.maxs != '0 0 0') - { + if (this.model != "") { + precache_model(this.model); + if (this.mins != '0 0 0' || this.maxs != '0 0 0') { vector mi = this.mins; vector ma = this.maxs; _setmodel(this, this.model); // no precision needed setsize(this, mi, ma); - } - else + } else { _setmodel(this, this.model); // no precision needed + } InitializeEntity(this, LODmodel_attach, INITPRIO_FINDTARGET); - } + } setorigin(this, this.origin); ApplyMinMaxScaleAngles(this); } void SetBrushEntityModelNoLOD(entity this) { - if(this.model != "") - { - precache_model(this.model); - if(this.mins != '0 0 0' || this.maxs != '0 0 0') - { + if (this.model != "") { + precache_model(this.model); + if (this.mins != '0 0 0' || this.maxs != '0 0 0') { vector mi = this.mins; vector ma = this.maxs; _setmodel(this, this.model); // no precision needed setsize(this, mi, ma); - } - else + } else { _setmodel(this, this.model); // no precision needed - } + } + } setorigin(this, this.origin); ApplyMinMaxScaleAngles(this); } @@ -401,10 +385,9 @@ InitTrigger void SetMovedir(entity this) { - if(this.movedir != '0 0 0') + if (this.movedir != '0 0 0') { this.movedir = normalize(this.movedir); - else - { + } else { makevectors(this.angles); this.movedir = v_forward; } @@ -443,8 +426,7 @@ bool InitMovingBrushTrigger(entity this) this.solid = SOLID_BSP; SetBrushEntityModel(this); set_movetype(this, MOVETYPE_PUSH); - if(this.modelindex == 0) - { + if (this.modelindex == 0) { objerror(this, "InitMovingBrushTrigger: no brushes found!"); return false; } diff --git a/qcsrc/server/g_subs.qh b/qcsrc/server/g_subs.qh index 1f5537cea..ec6c6436c 100644 --- a/qcsrc/server/g_subs.qh +++ b/qcsrc/server/g_subs.qh @@ -15,7 +15,7 @@ Applies some friction to this ================== */ .float friction; -void SUB_Friction (entity this); +void SUB_Friction(entity this); /* ================== @@ -24,9 +24,9 @@ SUB_VanishOrRemove Makes client invisible or removes non-client ================== */ -void SUB_VanishOrRemove (entity ent); +void SUB_VanishOrRemove(entity ent); -void SUB_SetFade_Think (entity this); +void SUB_SetFade_Think(entity this); /* ================== @@ -35,7 +35,7 @@ SUB_SetFade Fade 'ent' out when time >= 'when' ================== */ -void SUB_SetFade (entity ent, float when, float fadetime); +void SUB_SetFade(entity ent, float when, float fadetime); /* ============= @@ -48,17 +48,17 @@ this.origin traveling at speed void SUB_CalcMoveDone(entity this); .float platmovetype_turn; -void SUB_CalcMove_controller_think (entity this); +void SUB_CalcMove_controller_think(entity this); -void SUB_CalcMove_controller_setbezier (entity controller, vector org, vector control, vector dest); +void SUB_CalcMove_controller_setbezier(entity controller, vector org, vector control, vector dest); -void SUB_CalcMove_controller_setlinear (entity controller, vector org, vector dest); +void SUB_CalcMove_controller_setlinear(entity controller, vector org, vector dest); -void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func); +void SUB_CalcMove_Bezier(entity this, vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func); -void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func); +void SUB_CalcMove(entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func); -void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func); +void SUB_CalcMoveEnt(entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func); /* ============= @@ -70,12 +70,12 @@ this.angles rotating The calling function should make sure this.think is valid =============== */ -void SUB_CalcAngleMoveDone (entity this); +void SUB_CalcAngleMoveDone(entity this); // FIXME: I fixed this function only for rotation around the main axes -void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func); +void SUB_CalcAngleMove(entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func); -void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func); +void SUB_CalcAngleMoveEnt(entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func); /* ================== @@ -84,7 +84,7 @@ main unused but required by the engine ================== */ -void main (); +void main(); // Misc @@ -96,17 +96,17 @@ A version of traceline that must be used by SOLID_SLIDEBOX things that want to h Additionally it moves players back into the past before the trace and restores them afterward. ================== */ -void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz); -void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag); -void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag); -void tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag); -void WarpZone_traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag); -void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag); -void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag); +void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz); +void traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag); +void traceline_antilag(entity source, vector v1, vector v2, float nomonst, entity forent, float lag); +void tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag); +void WarpZone_traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag); +void WarpZone_traceline_antilag(entity source, vector v1, vector v2, float nomonst, entity forent, float lag); +void WarpZone_tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag); -float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity); // returns the number of traces done, for benchmarking +float tracebox_inverted(vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity); // returns the number of traces done, for benchmarking -void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity); +void traceline_inverted(vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity); /* ================== @@ -117,7 +117,7 @@ Returns a point at least 12 units away from walls Ripped from DPMod ================== */ -vector findbetterlocation (vector org, float mindist); +vector findbetterlocation(vector org, float mindist); /* ================== @@ -126,7 +126,7 @@ Angc used for animations */ -float angc (float a1, float a2); +float angc(float a1, float a2); .string lodtarget1; .string lodtarget2; diff --git a/qcsrc/server/g_world.qh b/qcsrc/server/g_world.qh index 034407bc1..d452923d0 100644 --- a/qcsrc/server/g_world.qh +++ b/qcsrc/server/g_world.qh @@ -3,11 +3,11 @@ float checkrules_equality; float checkrules_suddendeathwarning; float checkrules_suddendeathend; -float checkrules_overtimesadded; //how many overtimes have been already added +float checkrules_overtimesadded; // how many overtimes have been already added -const int WINNING_NO = 0; // no winner, but time limits may terminate the game -const int WINNING_YES = 1; // winner found -const int WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached +const int WINNING_NO = 0; // no winner, but time limits may terminate the game +const int WINNING_YES = 1; // winner found +const int WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached const int WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW float WinningCondition_Scores(float limit, float leadlimit); diff --git a/qcsrc/server/ipban.qc b/qcsrc/server/ipban.qc index 98dbf5c55..6876af32b 100644 --- a/qcsrc/server/ipban.qc +++ b/qcsrc/server/ipban.qc @@ -38,20 +38,21 @@ void OnlineBanList_SendBan(string ip, float bantime, string reason) string uri; float i, n; - uri = strcat( "action=ban&hostname=", uri_escape(autocvar_hostname)); + uri = strcat("action=ban&hostname=", uri_escape(autocvar_hostname)); uri = strcat(uri, "&ip=", uri_escape(ip)); uri = strcat(uri, "&duration=", ftos(bantime)); uri = strcat(uri, "&reason=", uri_escape(reason)); n = tokenize_console(autocvar_g_ban_sync_uri); - if(n >= MAX_IPBAN_URIS) + if (n >= MAX_IPBAN_URIS) { n = MAX_IPBAN_URIS; - for(i = 0; i < n; ++i) - { - if(strstrofs(argv(i), "?", 0) >= 0) + } + for (i = 0; i < n; ++i) { + if (strstrofs(argv(i), "?", 0) >= 0) { uri_get(strcat(argv(i), "&", uri), URI_GET_DISCARD); // 0 = "discard" callback target - else + } else { uri_get(strcat(argv(i), "?", uri), URI_GET_DISCARD); // 0 = "discard" callback target + } } } @@ -60,18 +61,19 @@ void OnlineBanList_SendUnban(string ip) string uri; float i, n; - uri = strcat( "action=unban&hostname=", uri_escape(autocvar_hostname)); + uri = strcat("action=unban&hostname=", uri_escape(autocvar_hostname)); uri = strcat(uri, "&ip=", uri_escape(ip)); n = tokenize_console(autocvar_g_ban_sync_uri); - if(n >= MAX_IPBAN_URIS) + if (n >= MAX_IPBAN_URIS) { n = MAX_IPBAN_URIS; - for(i = 0; i < n; ++i) - { - if(strstrofs(argv(i), "?", 0) >= 0) + } + for (i = 0; i < n; ++i) { + if (strstrofs(argv(i), "?", 0) >= 0) { uri_get(strcat(argv(i), "&", uri), URI_GET_DISCARD); // 0 = "discard" callback target - else + } else { uri_get(strcat(argv(i), "?", uri), URI_GET_DISCARD); // 0 = "discard" callback target + } } } @@ -91,8 +93,7 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) id -= URI_GET_IPBAN; - if(id >= MAX_IPBAN_URIS) - { + if (id >= MAX_IPBAN_URIS) { LOG_INFO("Received ban list for invalid ID"); return; } @@ -102,62 +103,56 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) string prelude = strcat("Received ban list from ", uri, ": "); - if(OnlineBanList_RequestWaiting[id] == 0) - { + if (OnlineBanList_RequestWaiting[id] == 0) { LOG_INFO(prelude, "rejected (unexpected)"); return; } OnlineBanList_RequestWaiting[id] = 0; - if(time > OnlineBanList_Timeout) - { + if (time > OnlineBanList_Timeout) { LOG_INFO(prelude, "rejected (too late)"); return; } syncinterval = autocvar_g_ban_sync_interval; - if(syncinterval == 0) - { + if (syncinterval == 0) { LOG_INFO(prelude, "rejected (syncing disabled)"); return; } - if(syncinterval > 0) + if (syncinterval > 0) { syncinterval *= 60; + } - if(status != 0) - { + if (status != 0) { LOG_INFO(prelude, "error: status is ", ftos(status)); return; } - if(substring(data, 0, 1) == "<") - { + if (substring(data, 0, 1) == "<") { LOG_INFO(prelude, "error: received HTML instead of a ban list"); return; } - if(strstrofs(data, "\r", 0) != -1) - { + if (strstrofs(data, "\r", 0) != -1) { LOG_INFO(prelude, "error: received carriage returns"); return; } - if(data == "") + if (data == "") { n = 0; - else + } else { n = tokenizebyseparator(data, "\n"); + } - if((n % 4) != 0) - { + if ((n % 4) != 0) { LOG_INFO(prelude, "error: received invalid item count: ", ftos(n)); return; } LOG_INFO(prelude, "OK, ", ftos(n / 4), " items"); - for(i = 0; i < n; i += 4) - { + for (i = 0; i < n; i += 4) { ip = argv(i); timeleft = stof(argv(i + 1)); reason = argv(i + 2); @@ -168,32 +163,35 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) LOG_TRACE(" serverip=", serverip); timeleft -= 1.5 * autocvar_g_ban_sync_timeout; - if(timeleft < 0) + if (timeleft < 0) { continue; + } l = strlen(ip); - if(l != 44) // length 44 is a cryptographic ID - { - for(j = 0; j < l; ++j) - if(strstrofs("0123456789.", substring(ip, j, 1), 0) == -1) - { + if (l != 44) { // length 44 is a cryptographic ID + for (j = 0; j < l; ++j) { + if (strstrofs("0123456789.", substring(ip, j, 1), 0) == -1) { LOG_INFO("Invalid character ", substring(ip, j, 1), " in IP address ", ip, ". Skipping this ban."); goto skip; } + } } - if(autocvar_g_ban_sync_trusted_servers_verify) - if((strstrofs(strcat(";", OnlineBanList_Servers, ";"), strcat(";", serverip, ";"), 0) == -1)) + if (autocvar_g_ban_sync_trusted_servers_verify) { + if ((strstrofs(strcat(";", OnlineBanList_Servers, ";"), strcat(";", serverip, ";"), 0) == -1)) { continue; + } + } - if(syncinterval > 0) + if (syncinterval > 0) { timeleft = min(syncinterval + (OnlineBanList_Timeout - time) + 5, timeleft); - // the ban will be prolonged on the next sync - // or expire 5 seconds after the next timeout + } + // the ban will be prolonged on the next sync + // or expire 5 seconds after the next timeout Ban_Insert(ip, timeleft, strcat("ban synced from ", serverip, " at ", uri), 0); LOG_INFO("Ban list syncing: accepted ban of ", ip, " by ", serverip, " at ", uri, ": ", reason); -LABEL(skip) + LABEL(skip) } } @@ -203,47 +201,55 @@ void OnlineBanList_Think(entity this) string uri; float i, n; - if(autocvar_g_ban_sync_uri == "") + if (autocvar_g_ban_sync_uri == "") { goto killme; - if(autocvar_g_ban_sync_interval == 0) // < 0 is okay, it means "sync on level start only" + } + if (autocvar_g_ban_sync_interval == 0) { // < 0 is okay, it means "sync on level start only" goto killme; + } argc = tokenize_console(autocvar_g_ban_sync_trusted_servers); - if(argc == 0) + if (argc == 0) { goto killme; + } - if(OnlineBanList_Servers) + if (OnlineBanList_Servers) { strunzone(OnlineBanList_Servers); + } OnlineBanList_Servers = argv(0); - for(i = 1; i < argc; ++i) + for (i = 1; i < argc; ++i) { OnlineBanList_Servers = strcat(OnlineBanList_Servers, ";", argv(i)); + } OnlineBanList_Servers = strzone(OnlineBanList_Servers); - uri = strcat( "action=list&hostname=", uri_escape(autocvar_hostname)); + uri = strcat("action=list&hostname=", uri_escape(autocvar_hostname)); uri = strcat(uri, "&servers=", uri_escape(OnlineBanList_Servers)); OnlineBanList_Timeout = time + autocvar_g_ban_sync_timeout; n = tokenize_console(autocvar_g_ban_sync_uri); - if(n >= MAX_IPBAN_URIS) + if (n >= MAX_IPBAN_URIS) { n = MAX_IPBAN_URIS; - for(i = 0; i < n; ++i) - { - if(OnlineBanList_RequestWaiting[i]) + } + for (i = 0; i < n; ++i) { + if (OnlineBanList_RequestWaiting[i]) { continue; + } OnlineBanList_RequestWaiting[i] = 1; - if(strstrofs(argv(i), "?", 0) >= 0) + if (strstrofs(argv(i), "?", 0) >= 0) { uri_get(strcat(argv(i), "&", uri), URI_GET_IPBAN + i); // 1000 = "banlist" callback target - else + } else { uri_get(strcat(argv(i), "?", uri), URI_GET_IPBAN + i); // 1000 = "banlist" callback target + } } - if(autocvar_g_ban_sync_interval > 0) + if (autocvar_g_ban_sync_interval > 0) { this.nextthink = time + max(60, autocvar_g_ban_sync_interval * 60); - else + } else { goto killme; + } return; -LABEL(killme) + LABEL(killme) delete(this); } @@ -264,34 +270,38 @@ void Ban_SaveBans() string out; float i; - if(!ban_loaded) + if (!ban_loaded) { return; + } // version of list out = "1"; - for(i = 0; i < ban_count; ++i) - { - if(time > ban_expire[i]) + for (i = 0; i < ban_count; ++i) { + if (time > ban_expire[i]) { continue; + } out = strcat(out, " ", ban_ip[i]); out = strcat(out, " ", ftos(ban_expire[i] - time)); } - if(strlen(out) <= 1) // no real entries + if (strlen(out) <= 1) { // no real entries cvar_set("g_banned_list", ""); - else + } else { cvar_set("g_banned_list", out); + } } float Ban_Delete(float i) { - if(i < 0) + if (i < 0) { return false; - if(i >= ban_count) + } + if (i >= ban_count) { return false; - if(ban_expire[i] == 0) + } + if (ban_expire[i] == 0) { return false; - if(ban_expire[i] > 0) - { + } + if (ban_expire[i] > 0) { OnlineBanList_SendUnban(ban_ip[i]); strunzone(ban_ip[i]); } @@ -304,18 +314,17 @@ float Ban_Delete(float i) void Ban_LoadBans() { float i, n; - for(i = 0; i < ban_count; ++i) + for (i = 0; i < ban_count; ++i) { Ban_Delete(i); + } ban_count = 0; ban_loaded = true; n = tokenize_console(autocvar_g_banned_list); - if(stof(argv(0)) == 1) - { + if (stof(argv(0)) == 1) { ban_count = (n - 1) / 2; - for(i = 0; i < ban_count; ++i) - { - ban_ip[i] = strzone(argv(2*i+1)); - ban_expire[i] = time + stof(argv(2*i+2)); + for (i = 0; i < ban_count; ++i) { + ban_ip[i] = strzone(argv(2 * i + 1)); + ban_expire[i] = time + stof(argv(2 * i + 2)); } } @@ -332,10 +341,10 @@ void Ban_View() LOG_INFO("^2Listing all existing active bans:"); n = 0; - for(i = 0; i < ban_count; ++i) - { - if(time > ban_expire[i]) + for (i = 0; i < ban_count; ++i) { + if (time > ban_expire[i]) { continue; + } ++n; // total number of existing bans @@ -355,54 +364,64 @@ float Ban_GetClientIP(entity client) float i1, i2, i3, i4; string s; - if(client.crypto_idfp_signed) + if (client.crypto_idfp_signed) { ban_idfp = client.crypto_idfp; - else + } else { ban_idfp = string_null; + } s = client.netaddress; i1 = strstrofs(s, ".", 0); - if(i1 < 0) + if (i1 < 0) { goto ipv6; + } i2 = strstrofs(s, ".", i1 + 1); - if(i2 < 0) + if (i2 < 0) { return false; + } i3 = strstrofs(s, ".", i2 + 1); - if(i3 < 0) + if (i3 < 0) { return false; + } i4 = strstrofs(s, ".", i3 + 1); - if(i4 >= 0) + if (i4 >= 0) { s = substring(s, 0, i4); + } ban_ip1 = substring(s, 0, i1); // 8 ban_ip2 = substring(s, 0, i2); // 16 ban_ip3 = substring(s, 0, i3); // 24 - ban_ip4 = strcat1(s); // 32 + ban_ip4 = strcat1(s); // 32 return true; -LABEL(ipv6) + LABEL(ipv6) i1 = strstrofs(s, ":", 0); - if(i1 < 0) + if (i1 < 0) { return false; + } i1 = strstrofs(s, ":", i1 + 1); - if(i1 < 0) + if (i1 < 0) { return false; + } i2 = strstrofs(s, ":", i1 + 1); - if(i2 < 0) + if (i2 < 0) { return false; + } i3 = strstrofs(s, ":", i2 + 1); - if(i3 < 0) + if (i3 < 0) { return false; + } ban_ip1 = strcat(substring(s, 0, i1), "::/32"); // 32 ban_ip2 = strcat(substring(s, 0, i2), "::/48"); // 48 ban_ip4 = strcat(substring(s, 0, i3), "::/64"); // 64 - if(i3 - i2 > 3) // means there is more than 2 digits and a : in the range + if (i3 - i2 > 3) { // means there is more than 2 digits and a : in the range ban_ip3 = strcat(substring(s, 0, i2), ":", substring(s, i2 + 1, i3 - i2 - 3), "00::/56"); - else + } else { ban_ip3 = strcat(substring(s, 0, i2), ":0::/56"); + } return true; } @@ -410,47 +429,46 @@ LABEL(ipv6) float Ban_IsClientBanned(entity client, float idx) { float i, b, e, ipbanned; - if(!ban_loaded) + if (!ban_loaded) { Ban_LoadBans(); - if(!Ban_GetClientIP(client)) + } + if (!Ban_GetClientIP(client)) { return false; - if(idx < 0) - { + } + if (idx < 0) { b = 0; e = ban_count; - } - else - { + } else { b = idx; e = idx + 1; } ipbanned = false; - for(i = b; i < e; ++i) - { + for (i = b; i < e; ++i) { string s; - if(time > ban_expire[i]) + if (time > ban_expire[i]) { continue; + } s = ban_ip[i]; - if(ban_ip1 == s) ipbanned = true; - if(ban_ip2 == s) ipbanned = true; - if(ban_ip3 == s) ipbanned = true; - if(ban_ip4 == s) ipbanned = true; - if(ban_idfp == s) return true; + if (ban_ip1 == s) { ipbanned = true; } + if (ban_ip2 == s) { ipbanned = true; } + if (ban_ip3 == s) { ipbanned = true; } + if (ban_ip4 == s) { ipbanned = true; } + if (ban_idfp == s) { return true; } } - if(ipbanned) - { - if(!autocvar_g_banned_list_idmode) + if (ipbanned) { + if (!autocvar_g_banned_list_idmode) { return true; - if (!ban_idfp) + } + if (!ban_idfp) { return true; + } } return false; } bool Ban_MaybeEnforceBan(entity client) { - if (Ban_IsClientBanned(client, -1)) - { + if (Ban_IsClientBanned(client, -1)) { string s = sprintf("^1NOTE:^7 banned client %s just tried to enter\n", client.netaddress); dropclient(client); bprint(s); @@ -462,7 +480,7 @@ bool Ban_MaybeEnforceBan(entity client) .bool ban_checked; bool Ban_MaybeEnforceBanOnce(entity client) { - if (client.ban_checked) return false; + if (client.ban_checked) { return false; } client.ban_checked = true; return Ban_MaybeEnforceBan(client); } @@ -475,14 +493,13 @@ string Ban_Enforce(float j, string reason) s = ""; FOREACH_CLIENTSLOT(IS_REAL_CLIENT(it), { - if(Ban_IsClientBanned(it, j)) - { - if(reason != "") - { - if(s == "") + if (Ban_IsClientBanned(it, j)) { + if (reason != "") { + if (s == "") { reason = strcat(reason, ": affects "); - else + } else { reason = strcat(reason, ", "); + } reason = strcat(reason, it.netname); } s = strcat(s, "^1NOTE:^7 banned client ", it.netaddress, "^7 has to go\n"); @@ -501,43 +518,44 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) float bestscore; // already banned? - for(i = 0; i < ban_count; ++i) - if(ban_ip[i] == ip) - { + for (i = 0; i < ban_count; ++i) { + if (ban_ip[i] == ip) { // prolong the ban - if(time + bantime > ban_expire[i]) - { + if (time + bantime > ban_expire[i]) { ban_expire[i] = time + bantime; LOG_TRACE(ip, "'s ban has been prolonged to ", ftos(bantime), " seconds from now"); - } - else + } else { LOG_TRACE(ip, "'s ban is still active until ", ftos(ban_expire[i] - time), " seconds from now"); + } // and enforce reason = Ban_Enforce(i, reason); // and abort - if(dosync) - if(reason != "") - if(substring(reason, 0, 1) != "~") // like IRC: unauthenticated banner + if (dosync) { + if (reason != "") { + if (substring(reason, 0, 1) != "~") { // like IRC: unauthenticated banner OnlineBanList_SendBan(ip, bantime, reason); + } + } + } return false; } + } // do we have a free slot? - for(i = 0; i < ban_count; ++i) - if(time > ban_expire[i]) + for (i = 0; i < ban_count; ++i) { + if (time > ban_expire[i]) { break; + } + } // no free slot? Then look for the one who would get unbanned next - if(i >= BAN_MAX) - { + if (i >= BAN_MAX) { i = 0; bestscore = ban_expire[i]; - for(j = 1; j < ban_count; ++j) - { - if(ban_expire[j] < bestscore) - { + for (j = 1; j < ban_count; ++j) { + if (ban_expire[j] < bestscore) { i = j; bestscore = ban_expire[i]; } @@ -545,11 +563,11 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) } // if we replace someone, will we be banned longer than him (so long-term // bans never get overridden by short-term bans) - if(i < ban_count) - if(ban_expire[i] > time + bantime) - { - LOG_INFO(ip, " could not get banned due to no free ban slot"); - return false; + if (i < ban_count) { + if (ban_expire[i] > time + bantime) { + LOG_INFO(ip, " could not get banned due to no free ban slot"); + return false; + } } // okay, insert our new victim as i Ban_Delete(i); @@ -563,10 +581,13 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) reason = Ban_Enforce(i, reason); // and abort - if(dosync) - if(reason != "") - if(substring(reason, 0, 1) != "~") // like IRC: unauthenticated banner + if (dosync) { + if (reason != "") { + if (substring(reason, 0, 1) != "~") { // like IRC: unauthenticated banner OnlineBanList_SendBan(ip, bantime, reason); + } + } + } return true; } @@ -574,16 +595,14 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) void Ban_KickBanClient(entity client, float bantime, float masksize, string reason) { string ip, id; - if(!Ban_GetClientIP(client)) - { + if (!Ban_GetClientIP(client)) { sprint(client, strcat("Kickbanned: ", reason, "\n")); dropclient(client); return; } // who to ban? - switch(masksize) - { + switch (masksize) { case 1: ip = strcat1(ban_ip1); break; @@ -598,14 +617,16 @@ void Ban_KickBanClient(entity client, float bantime, float masksize, string reas ip = strcat1(ban_ip4); break; } - if(ban_idfp) + if (ban_idfp) { id = strcat1(ban_idfp); - else + } else { id = string_null; + } Ban_Insert(ip, bantime, reason, 1); - if(id) + if (id) { Ban_Insert(id, bantime, reason, 1); + } /* * not needed, as we enforce the ban in Ban_Insert anyway // and kick him diff --git a/qcsrc/server/item_key.qc b/qcsrc/server/item_key.qc index c645c7fac..683116788 100644 --- a/qcsrc/server/item_key.qc +++ b/qcsrc/server/item_key.qc @@ -33,26 +33,30 @@ bool item_keys_usekey(entity l, entity p) } } -string item_keys_keylist(float keylist) { +string item_keys_keylist(float keylist) +{ // no keys - if (!keylist) + if (!keylist) { return ""; + } // one key - if ((keylist & (keylist-1)) == 0) + if ((keylist & (keylist - 1)) == 0) { return strcat("the ", item_keys_names[lowestbit(keylist)]); + } string n = ""; int base = 0; while (keylist) { int l = lowestbit(keylist); - if (n) + if (n) { n = strcat(n, ", the ", item_keys_names[base + l]); - else + } else { n = strcat("the ", item_keys_names[base + l]); + } keylist = bitshift(keylist, -(l + 1)); - base+= l + 1; + base += l + 1; } return n; @@ -70,12 +74,14 @@ item_key */ void item_key_touch(entity this, entity toucher) { - if (!IS_PLAYER(toucher)) + if (!IS_PLAYER(toucher)) { return; + } // player already picked up this key - if (PS(toucher).itemkeys & this.itemkeys) + if (PS(toucher).itemkeys & this.itemkeys) { return; + } PS(toucher).itemkeys |= this.itemkeys; play2(toucher, this.noise); @@ -86,7 +92,7 @@ void item_key_touch(entity this, entity toucher) this.message = ""; SUB_UseTargets(this, toucher, toucher); // TODO: should we be using toucher for the trigger here? this.message = oldmsg; -}; +} /** * Spawn a key with given model, key code and color. @@ -95,27 +101,28 @@ void spawn_item_key(entity this) { precache_model(this.model); - if (this.spawnflags & 1) // FLOATING + if (this.spawnflags & 1) { // FLOATING this.noalign = 1; + } - if (this.noalign) + if (this.noalign) { set_movetype(this, MOVETYPE_NONE); - else + } else { set_movetype(this, MOVETYPE_TOSS); + } precache_sound(this.noise); this.mdl = this.model; this.effects = EF_LOWPRECISION; _setmodel(this, this.model); - //setsize(this, '-16 -16 -24', '16 16 32'); + // setsize(this, '-16 -16 -24', '16 16 32'); setorigin(this, this.origin + '0 0 32'); setsize(this, '-16 -16 -56', '16 16 0'); this.modelflags |= MF_ROTATE; this.solid = SOLID_TRIGGER; - if (!this.noalign) - { + if (!this.noalign) { // first nudge it off the floor a little bit to avoid math errors setorigin(this, this.origin + '0 0 1'); // note droptofloor returns false if stuck/or would fall too far @@ -123,7 +130,7 @@ void spawn_item_key(entity this) } settouch(this, item_key_touch); -}; +} /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING @@ -158,55 +165,54 @@ spawnfunc(item_key) vector _colormod; // reject this entity if more than one key was set! - if (this.itemkeys>0 && (this.itemkeys & (this.itemkeys-1)) != 0) { + if (this.itemkeys > 0 && (this.itemkeys & (this.itemkeys - 1)) != 0) { objerror(this, "item_key.itemkeys must contain only 1 bit set specifying the key it represents!"); delete(this); return; } // find default netname and colormod - switch(this.itemkeys) { - case BIT(0): - _netname = "GOLD key"; - _colormod = '1 .9 0'; - break; - - case BIT(1): - _netname = "SILVER key"; - _colormod = '.9 .9 .9'; - break; - - case BIT(2): - _netname = "BRONZE key"; - _colormod = '.6 .25 0'; - break; - - case BIT(3): - _netname = "RED keycard"; - _colormod = '.9 0 0'; - break; - - case BIT(4): - _netname = "BLUE keycard"; - _colormod = '0 0 .9'; - break; - - case BIT(5): - _netname = "GREEN keycard"; - _colormod = '0 .9 0'; - break; - - default: - _netname = "FLUFFY PINK keycard"; - _colormod = '1 1 1'; - - if (this.netname == "") { - objerror(this, "item_key doesn't have a default name for this key and a custom one was not specified!"); - delete(this); - return; - } - break; - + switch (this.itemkeys) { + case BIT(0): + _netname = "GOLD key"; + _colormod = '1 .9 0'; + break; + + case BIT(1): + _netname = "SILVER key"; + _colormod = '.9 .9 .9'; + break; + + case BIT(2): + _netname = "BRONZE key"; + _colormod = '.6 .25 0'; + break; + + case BIT(3): + _netname = "RED keycard"; + _colormod = '.9 0 0'; + break; + + case BIT(4): + _netname = "BLUE keycard"; + _colormod = '0 0 .9'; + break; + + case BIT(5): + _netname = "GREEN keycard"; + _colormod = '0 .9 0'; + break; + + default: + _netname = "FLUFFY PINK keycard"; + _colormod = '1 1 1'; + + if (this.netname == "") { + objerror(this, "item_key doesn't have a default name for this key and a custom one was not specified!"); + delete(this); + return; + } + break; } // find default model @@ -222,23 +228,28 @@ spawnfunc(item_key) } // set defailt netname - if (this.netname == "") + if (this.netname == "") { this.netname = _netname; + } // set default colormod - if (!this.colormod) + if (!this.colormod) { this.colormod = _colormod; + } // set default model - if (this.model == "") + if (this.model == "") { this.model = _model; + } // set default pickup message - if (this.message == "") + if (this.message == "") { this.message = strzone(strcat("You've picked up the ", this.netname, "!")); + } - if (this.noise == "") + if (this.noise == "") { this.noise = strzone(SND(ITEMPICKUP)); + } // save the name for later item_keys_names[lowestbit(this.itemkeys)] = this.netname; diff --git a/qcsrc/server/item_key.qh b/qcsrc/server/item_key.qh index 50be5f8db..e1d01223f 100644 --- a/qcsrc/server/item_key.qh +++ b/qcsrc/server/item_key.qh @@ -3,9 +3,9 @@ /** * Returns the bit ID of a key */ -#define ITEM_KEY_BIT(n) ( bitshift(1, n) ) +#define ITEM_KEY_BIT(n) (bitshift(1, n)) -#define ITEM_KEY_MAX 24 +#define ITEM_KEY_MAX 24 /** * list of key names. diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index 209ac7af9..ade13b317 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -42,14 +42,15 @@ entity mapvote_ent; /** * Returns the gamtype ID from its name, if type_name isn't a real gametype it - * checks for sv_vote_gametype_(type_name)_type + * checks for sv_vote_gametype_(type_name) _type */ Gametype GameTypeVote_Type_FromString(string type_name) { Gametype type = MapInfo_Type_FromString(type_name); - if (type == NULL) + if (type == NULL) { type = MapInfo_Type_FromString(cvar_string( - strcat("sv_vote_gametype_",type_name,"_type"))); + strcat("sv_vote_gametype_", type_name, "_type"))); + } return type; } @@ -58,22 +59,23 @@ int GameTypeVote_AvailabilityStatus(string type_name) int flag = GTV_FORBIDDEN; Gametype type = MapInfo_Type_FromString(type_name); - if ( type == NULL ) - { + if (type == NULL) { type = MapInfo_Type_FromString(cvar_string( - strcat("sv_vote_gametype_",type_name,"_type"))); + strcat("sv_vote_gametype_", type_name, "_type"))); flag |= GTV_CUSTOM; } - if( type == NULL ) + if (type == NULL) { return flag; + } - if ( autocvar_nextmap != "" ) - { - if ( !MapInfo_Get_ByName(autocvar_nextmap, false, NULL) ) + if (autocvar_nextmap != "") { + if (!MapInfo_Get_ByName(autocvar_nextmap, false, NULL)) { return flag; - if (!(MapInfo_Map_supportedGametypes & type.m_flags)) + } + if (!(MapInfo_Map_supportedGametypes & type.m_flags)) { return flag; + } } return flag | GTV_AVAILABLE; @@ -85,15 +87,15 @@ int GameTypeVote_GetMask() n = tokenizebyseparator(autocvar_sv_vote_gametype_options, " "); n = min(MAPVOTE_COUNT, n); gametype_mask = 0; - for(j = 0; j < n; ++j) + for (j = 0; j < n; ++j) { gametype_mask |= GameTypeVote_Type_FromString(argv(j)).m_flags; + } return gametype_mask; } string GameTypeVote_MapInfo_FixName(string m) { - if ( autocvar_sv_vote_gametype ) - { + if (autocvar_sv_vote_gametype) { MapInfo_Enumerate(); _MapInfo_FilterGametype(GameTypeVote_GetMask(), 0, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); } @@ -102,20 +104,18 @@ string GameTypeVote_MapInfo_FixName(string m) void MapVote_ClearAllVotes() { - FOREACH_CLIENT(true, { it.mapvote = 0; }); + FOREACH_CLIENT(true, { it.mapvote = 0; + }); } void MapVote_UnzoneStrings() { - for(int j = 0; j < mapvote_count; ++j) - { - if ( mapvote_maps[j] ) - { + for (int j = 0; j < mapvote_count; ++j) { + if (mapvote_maps[j]) { strunzone(mapvote_maps[j]); mapvote_maps[j] = string_null; } - if ( mapvote_maps_pakfile[j] ) - { + if (mapvote_maps_pakfile[j]) { strunzone(mapvote_maps_pakfile[j]); mapvote_maps_pakfile[j] = string_null; } @@ -125,40 +125,50 @@ void MapVote_UnzoneStrings() string MapVote_Suggest(entity this, string m) { int i; - if(m == "") + if (m == "") { return "That's not how to use this command."; - if(!autocvar_g_maplist_votable_suggestions) + } + if (!autocvar_g_maplist_votable_suggestions) { return "Suggestions are not accepted on this server."; - if(mapvote_initialized) - if(!gametypevote) - return "Can't suggest - voting is already in progress!"; + } + if (mapvote_initialized) { + if (!gametypevote) { + return "Can't suggest - voting is already in progress!"; + } + } m = GameTypeVote_MapInfo_FixName(m); - if (!m) + if (!m) { return "The map you suggested is not available on this server."; - if(!autocvar_g_maplist_votable_suggestions_override_mostrecent) - if(Map_IsRecent(m)) + } + if (!autocvar_g_maplist_votable_suggestions_override_mostrecent) { + if (Map_IsRecent(m)) { return "This server does not allow for recent maps to be played again. Please be patient for some rounds."; + } + } - if (!autocvar_sv_vote_gametype) - if(!MapInfo_CheckMap(m)) - return "The map you suggested does not support the current game mode."; - for(i = 0; i < mapvote_suggestion_ptr; ++i) - if(mapvote_suggestions[i] == m) + if (!autocvar_sv_vote_gametype) { + if (!MapInfo_CheckMap(m)) { + return "The map you suggested does not support the current game mode."; + } + } + for (i = 0; i < mapvote_suggestion_ptr; ++i) { + if (mapvote_suggestions[i] == m) { return "This map was already suggested."; - if(mapvote_suggestion_ptr >= MAPVOTE_COUNT) - { - i = floor(random() * mapvote_suggestion_ptr); + } } - else - { + if (mapvote_suggestion_ptr >= MAPVOTE_COUNT) { + i = floor(random() * mapvote_suggestion_ptr); + } else { i = mapvote_suggestion_ptr; mapvote_suggestion_ptr += 1; } - if(mapvote_suggestions[i] != "") + if (mapvote_suggestions[i] != "") { strunzone(mapvote_suggestions[i]); + } mapvote_suggestions[i] = strzone(m); - if(autocvar_sv_eventlog) + if (autocvar_sv_eventlog) { GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(this.playerid))); + } return strcat("Suggestion of ", m, " accepted."); } @@ -167,34 +177,43 @@ void MapVote_AddVotable(string nextMap, bool isSuggestion) int j, i, o; string pakfile, mapfile; - if(nextMap == "") + if (nextMap == "") { return; - for(j = 0; j < mapvote_count; ++j) - if(mapvote_maps[j] == nextMap) + } + for (j = 0; j < mapvote_count; ++j) { + if (mapvote_maps[j] == nextMap) { return; + } + } // suggestions might be no longer valid/allowed after gametype switch! - if(isSuggestion) - if(!MapInfo_CheckMap(nextMap)) + if (isSuggestion) { + if (!MapInfo_CheckMap(nextMap)) { return; + } + } mapvote_maps[mapvote_count] = strzone(nextMap); mapvote_maps_suggested[mapvote_count] = isSuggestion; pakfile = string_null; - for(i = 0; i < mapvote_screenshot_dirs_count; ++i) - { + for (i = 0; i < mapvote_screenshot_dirs_count; ++i) { mapfile = strcat(mapvote_screenshot_dirs[i], "/", nextMap); pakfile = whichpack(strcat(mapfile, ".tga")); - if(pakfile == "") + if (pakfile == "") { pakfile = whichpack(strcat(mapfile, ".jpg")); - if(pakfile == "") + } + if (pakfile == "") { pakfile = whichpack(strcat(mapfile, ".png")); - if(pakfile != "") + } + if (pakfile != "") { break; + } } - if(i >= mapvote_screenshot_dirs_count) + if (i >= mapvote_screenshot_dirs_count) { i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server? - for(o = strstrofs(pakfile, "/", 0)+1; o > 0; o = strstrofs(pakfile, "/", 0)+1) + } + for (o = strstrofs(pakfile, "/", 0) + 1; o > 0; o = strstrofs(pakfile, "/", 0) + 1) { pakfile = substring(pakfile, o, -1); + } mapvote_maps_screenshot_dir[mapvote_count] = i; mapvote_maps_pakfile[mapvote_count] = strzone(pakfile); @@ -215,48 +234,57 @@ void MapVote_Init() mapvote_detail = !autocvar_g_maplist_votable_nodetail; mapvote_abstain = boolean(autocvar_g_maplist_votable_abstain); - if(mapvote_abstain) + if (mapvote_abstain) { nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable); - else + } else { nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable); + } smax = min3(nmax, autocvar_g_maplist_votable_suggestions, mapvote_suggestion_ptr); // we need this for AddVotable, as that cycles through the screenshot dirs mapvote_screenshot_dirs_count = tokenize_console(autocvar_g_maplist_votable_screenshot_dir); - if(mapvote_screenshot_dirs_count == 0) + if (mapvote_screenshot_dirs_count == 0) { mapvote_screenshot_dirs_count = tokenize_console("maps levelshots"); + } mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT); - for(i = 0; i < mapvote_screenshot_dirs_count; ++i) + for (i = 0; i < mapvote_screenshot_dirs_count; ++i) { mapvote_screenshot_dirs[i] = strzone(argv(i)); + } - if(mapvote_suggestion_ptr) - for(i = 0; i < 100 && mapvote_count < smax; ++i) + if (mapvote_suggestion_ptr) { + for (i = 0; i < 100 && mapvote_count < smax; ++i) { MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], true); + } + } - for(i = 0; i < 100 && mapvote_count < nmax; ++i) + for (i = 0; i < 100 && mapvote_count < nmax; ++i) { MapVote_AddVotable(GetNextMap(), false); + } - if(mapvote_count == 0) - { - bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" ); + if (mapvote_count == 0) { + bprint("Maplist contains no single playable map! Resetting it to default map list.\n"); cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_CurrentGametype(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags())); - if(autocvar_g_maplist_shuffle) + if (autocvar_g_maplist_shuffle) { ShuffleMaplist(); + } localcmd("\nmenu_cmd sync\n"); - for(i = 0; i < 100 && mapvote_count < nmax; ++i) + for (i = 0; i < 100 && mapvote_count < nmax; ++i) { MapVote_AddVotable(GetNextMap(), false); + } } mapvote_count_real = mapvote_count; - if(mapvote_abstain) + if (mapvote_abstain) { MapVote_AddVotable("don't care", false); + } - //dprint("mapvote count is ", ftos(mapvote_count), "\n"); + // dprint("mapvote count is ", ftos(mapvote_count), "\n"); mapvote_keeptwotime = time + autocvar_g_maplist_votable_keeptwotime; mapvote_timeout = time + autocvar_g_maplist_votable_timeout; - if(mapvote_count_real < 3 || mapvote_keeptwotime <= time) + if (mapvote_count_real < 3 || mapvote_keeptwotime <= time) { mapvote_keeptwotime = 0; + } MapVote_Spawn(); } @@ -272,26 +300,25 @@ void MapVote_SendPicture(entity to, int id) void MapVote_WriteMask() { - if ( mapvote_count < 24 ) - { + if (mapvote_count < 24) { int mask = 0; - for(int j = 0; j < mapvote_count; ++j) - { - if(mapvote_maps_flags[j] & GTV_AVAILABLE) + for (int j = 0; j < mapvote_count; ++j) { + if (mapvote_maps_flags[j] & GTV_AVAILABLE) { mask |= BIT(j); + } } - if(mapvote_count < 8) + if (mapvote_count < 8) { WriteByte(MSG_ENTITY, mask); - else if (mapvote_count < 16) - WriteShort(MSG_ENTITY,mask); - else + } else if (mapvote_count < 16) { + WriteShort(MSG_ENTITY, mask); + } else { WriteLong(MSG_ENTITY, mask); - } - else - { - for (int j = 0; j < mapvote_count; ++j) + } + } else { + for (int j = 0; j < mapvote_count; ++j) { WriteByte(MSG_ENTITY, mapvote_maps_flags[j]); + } } } @@ -301,14 +328,11 @@ void MapVote_WriteMask() void MapVote_SendOption(int i) { // abstain - if(mapvote_abstain && i == mapvote_count - 1) - { + if (mapvote_abstain && i == mapvote_count - 1) { WriteString(MSG_ENTITY, ""); // abstain needs no text WriteString(MSG_ENTITY, ""); // abstain needs no pack - WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir - } - else - { + WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir + } else { WriteString(MSG_ENTITY, mapvote_maps[i]); WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]); WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]); @@ -321,24 +345,20 @@ void MapVote_SendOption(int i) void GameTypeVote_SendOption(int i) { // abstain - if(mapvote_abstain && i == mapvote_count - 1) - { + if (mapvote_abstain && i == mapvote_count - 1) { WriteString(MSG_ENTITY, ""); // abstain needs no text WriteByte(MSG_ENTITY, GTV_AVAILABLE); - } - else - { + } else { string type_name = mapvote_maps[i]; WriteString(MSG_ENTITY, type_name); WriteByte(MSG_ENTITY, mapvote_maps_flags[i]); - if ( mapvote_maps_flags[i] & GTV_CUSTOM ) - { + if (mapvote_maps_flags[i] & GTV_CUSTOM) { WriteString(MSG_ENTITY, cvar_string( - strcat("sv_vote_gametype_",type_name,"_name"))); + strcat("sv_vote_gametype_", type_name, "_name"))); WriteString(MSG_ENTITY, cvar_string( - strcat("sv_vote_gametype_",type_name,"_description"))); + strcat("sv_vote_gametype_", type_name, "_description"))); WriteString(MSG_ENTITY, cvar_string( - strcat("sv_vote_gametype_",type_name,"_type"))); + strcat("sv_vote_gametype_", type_name, "_type"))); } } } @@ -347,62 +367,59 @@ bool MapVote_SendEntity(entity this, entity to, int sf) { int i; - if(sf & 1) + if (sf & 1) { sf &= ~2; // if we send 1, we don't need to also send 2 - + } WriteHeader(MSG_ENTITY, ENT_CLIENT_MAPVOTE); WriteByte(MSG_ENTITY, sf); - if(sf & 1) - { + if (sf & 1) { // flag 1 == initialization - for(i = 0; i < mapvote_screenshot_dirs_count; ++i) + for (i = 0; i < mapvote_screenshot_dirs_count; ++i) { WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]); + } WriteString(MSG_ENTITY, ""); WriteByte(MSG_ENTITY, mapvote_count); WriteByte(MSG_ENTITY, mapvote_abstain); WriteByte(MSG_ENTITY, mapvote_detail); WriteCoord(MSG_ENTITY, mapvote_timeout); - if ( gametypevote ) - { + if (gametypevote) { // gametype vote WriteByte(MSG_ENTITY, 1); WriteString(MSG_ENTITY, autocvar_nextmap); - } - else if ( autocvar_sv_vote_gametype ) - { + } else if (autocvar_sv_vote_gametype) { // map vote but gametype has been chosen via voting screen WriteByte(MSG_ENTITY, 2); WriteString(MSG_ENTITY, MapInfo_Type_ToText(MapInfo_CurrentGametype())); - } - else + } else { WriteByte(MSG_ENTITY, 0); // map vote - + } MapVote_WriteMask(); // Send data for the vote options - for(i = 0; i < mapvote_count; ++i) - { - if(gametypevote) + for (i = 0; i < mapvote_count; ++i) { + if (gametypevote) { GameTypeVote_SendOption(i); - else + } else { MapVote_SendOption(i); + } } } - if(sf & 2) - { + if (sf & 2) { // flag 2 == update of mask MapVote_WriteMask(); } - if(sf & 4) - { - if(mapvote_detail) - for(i = 0; i < mapvote_count; ++i) - if ( mapvote_maps_flags[i] & GTV_AVAILABLE ) + if (sf & 4) { + if (mapvote_detail) { + for (i = 0; i < mapvote_count; ++i) { + if (mapvote_maps_flags[i] & GTV_AVAILABLE) { WriteByte(MSG_ENTITY, mapvote_selections[i]); + } + } + } WriteByte(MSG_ENTITY, to.mapvote); } @@ -427,51 +444,49 @@ void MapVote_TouchVotes(entity voter) bool MapVote_Finished(int mappos) { - if(alreadychangedlevel) + if (alreadychangedlevel) { return false; + } string result; int i; int didntvote; - if(autocvar_sv_eventlog) - { + if (autocvar_sv_eventlog) { result = strcat(":vote:finished:", mapvote_maps[mappos]); result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::"); didntvote = mapvote_voters; - for(i = 0; i < mapvote_count; ++i) - if(mapvote_maps_flags[i] & GTV_AVAILABLE ) - { + for (i = 0; i < mapvote_count; ++i) { + if (mapvote_maps_flags[i] & GTV_AVAILABLE) { didntvote -= mapvote_selections[i]; - if(i != mappos) - { + if (i != mappos) { result = strcat(result, ":", mapvote_maps[i]); result = strcat(result, ":", ftos(mapvote_selections[i])); } } + } result = strcat(result, ":didn't vote:", ftos(didntvote)); GameLogEcho(result); - if(mapvote_maps_suggested[mappos]) + if (mapvote_maps_suggested[mappos]) { GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos])); + } } - FOREACH_CLIENT(IS_REAL_CLIENT(it), { FixClientCvars(it); }); + FOREACH_CLIENT(IS_REAL_CLIENT(it), { FixClientCvars(it); + }); - if(gametypevote) - { - if ( GameTypeVote_Finished(mappos) ) - { + if (gametypevote) { + if (GameTypeVote_Finished(mappos)) { gametypevote = false; - if(autocvar_nextmap != "") - { + if (autocvar_nextmap != "") { Map_Goto_SetStr(autocvar_nextmap); Map_Goto(0); alreadychangedlevel = true; return true; - } - else + } else { MapVote_Init(); + } } return false; } @@ -485,20 +500,19 @@ bool MapVote_Finished(int mappos) void MapVote_CheckRules_1() { - for (int i = 0; i < mapvote_count; ++i) - if (mapvote_maps_flags[i] & GTV_AVAILABLE) - { - //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n"); + for (int i = 0; i < mapvote_count; ++i) { + if (mapvote_maps_flags[i] & GTV_AVAILABLE) { + // dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n"); mapvote_selections[i] = 0; } + } mapvote_voters = 0; FOREACH_CLIENT(IS_REAL_CLIENT(it), { ++mapvote_voters; - if (it.mapvote) - { + if (it.mapvote) { int idx = it.mapvote - 1; - //dprint("Player ", it.netname, " vote = ", ftos(idx), "\n"); + // dprint("Player ", it.netname, " vote = ", ftos(idx), "\n"); ++mapvote_selections[idx]; } }); @@ -512,54 +526,60 @@ bool MapVote_CheckRules_2() int mapvote_voters_real; string result; - if(mapvote_count_real == 1) + if (mapvote_count_real == 1) { return MapVote_Finished(0); + } mapvote_voters_real = mapvote_voters; - if(mapvote_abstain) + if (mapvote_abstain) { mapvote_voters_real -= mapvote_selections[mapvote_count - 1]; + } RandomSelection_Init(); currentPlace = 0; currentVotes = -1; - for(i = 0; i < mapvote_count_real; ++i) - if ( mapvote_maps_flags[i] & GTV_AVAILABLE ) - { + for (i = 0; i < mapvote_count_real; ++i) { + if (mapvote_maps_flags[i] & GTV_AVAILABLE) { RandomSelection_AddFloat(i, 1, mapvote_selections[i]); - if ( gametypevote && mapvote_maps[i] == MapInfo_Type_ToString(MapInfo_CurrentGametype()) ) - { + if (gametypevote && mapvote_maps[i] == MapInfo_Type_ToString(MapInfo_CurrentGametype())) { currentVotes = mapvote_selections[i]; currentPlace = i; } } + } firstPlaceVotes = RandomSelection_best_priority; - if ( autocvar_sv_vote_gametype_default_current && currentVotes == firstPlaceVotes ) + if (autocvar_sv_vote_gametype_default_current && currentVotes == firstPlaceVotes) { firstPlace = currentPlace; - else + } else { firstPlace = RandomSelection_chosen_float; + } - //dprint("First place: ", ftos(firstPlace), "\n"); - //dprint("First place votes: ", ftos(firstPlaceVotes), "\n"); + // dprint("First place: ", ftos(firstPlace), "\n"); + // dprint("First place votes: ", ftos(firstPlaceVotes), "\n"); RandomSelection_Init(); - for(i = 0; i < mapvote_count_real; ++i) - if(i != firstPlace) - if ( mapvote_maps_flags[i] & GTV_AVAILABLE ) - RandomSelection_AddFloat(i, 1, mapvote_selections[i]); + for (i = 0; i < mapvote_count_real; ++i) { + if (i != firstPlace) { + if (mapvote_maps_flags[i] & GTV_AVAILABLE) { + RandomSelection_AddFloat(i, 1, mapvote_selections[i]); + } + } + } secondPlace = RandomSelection_chosen_float; secondPlaceVotes = RandomSelection_best_priority; - //dprint("Second place: ", ftos(secondPlace), "\n"); - //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n"); + // dprint("Second place: ", ftos(secondPlace), "\n"); + // dprint("Second place votes: ", ftos(secondPlaceVotes), "\n"); - if(firstPlace == -1) + if (firstPlace == -1) { error("No first place in map vote... WTF?"); + } - if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes) + if (secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes) { return MapVote_Finished(firstPlace); + } - if(mapvote_keeptwotime) - if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes) - { + if (mapvote_keeptwotime) { + if (time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes) { MapVote_TouchMask(); mapvote_keeptwotime = 0; result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]); @@ -567,40 +587,39 @@ bool MapVote_CheckRules_2() result = strcat(result, ":", mapvote_maps[secondPlace]); result = strcat(result, ":", ftos(secondPlaceVotes), "::"); int didntvote = mapvote_voters; - for(i = 0; i < mapvote_count; ++i) - { + for (i = 0; i < mapvote_count; ++i) { didntvote -= mapvote_selections[i]; - if(i != firstPlace) - if(i != secondPlace) - { + if (i != firstPlace) { + if (i != secondPlace) { result = strcat(result, ":", mapvote_maps[i]); result = strcat(result, ":", ftos(mapvote_selections[i])); - if(i < mapvote_count_real) - { + if (i < mapvote_count_real) { mapvote_maps_flags[i] &= ~GTV_AVAILABLE; } } + } } result = strcat(result, ":didn't vote:", ftos(didntvote)); - if(autocvar_sv_eventlog) + if (autocvar_sv_eventlog) { GameLogEcho(result); + } } + } return false; } void MapVote_Tick() { - MapVote_CheckRules_1(); // count - if(MapVote_CheckRules_2()) // decide + if (MapVote_CheckRules_2()) { // decide return; + } int totalvotes = 0; FOREACH_CLIENT(IS_REAL_CLIENT(it), { // hide scoreboard again - if(it.health != 2342) - { + if (it.health != 2342) { it.health = 2342; CS(it).impulse = 0; @@ -610,19 +629,21 @@ void MapVote_Tick() } // clear possibly invalid votes - if ( !(mapvote_maps_flags[it.mapvote-1] & GTV_AVAILABLE) ) + if (!(mapvote_maps_flags[it.mapvote - 1] & GTV_AVAILABLE)) { it.mapvote = 0; + } // use impulses as new vote - if(CS(it).impulse >= 1 && CS(it).impulse <= mapvote_count) - if( mapvote_maps_flags[CS(it).impulse - 1] & GTV_AVAILABLE ) - { + if (CS(it).impulse >= 1 && CS(it).impulse <= mapvote_count) { + if (mapvote_maps_flags[CS(it).impulse - 1] & GTV_AVAILABLE) { it.mapvote = CS(it).impulse; MapVote_TouchVotes(it); } + } CS(it).impulse = 0; - if(it.mapvote) + if (it.mapvote) { ++totalvotes; + } }); MapVote_CheckRules_1(); // just count @@ -631,63 +652,63 @@ void MapVote_Tick() void MapVote_Start() { // if mapvote is already running, don't do this initialization again - if(mapvote_run) { return; } + if (mapvote_run) { return; } // don't start mapvote until after playerstats gamereport is sent - if(PlayerStats_GameReport_DelayMapVote) { return; } + if (PlayerStats_GameReport_DelayMapVote) { return; } MapInfo_Enumerate(); - if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1)) + if (MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1)) { mapvote_run = true; + } } void MapVote_Think() { - if(!mapvote_run) + if (!mapvote_run) { return; + } - if(alreadychangedlevel) + if (alreadychangedlevel) { return; + } - if(time < mapvote_nextthink) + if (time < mapvote_nextthink) { return; - //dprint("tick\n"); + } + // dprint("tick\n"); mapvote_nextthink = time + 0.5; - if(!mapvote_initialized) - { - if(autocvar_rescan_pending == 1) - { + if (!mapvote_initialized) { + if (autocvar_rescan_pending == 1) { cvar_set("rescan_pending", "2"); localcmd("fs_rescan\nrescan_pending 3\n"); return; - } - else if(autocvar_rescan_pending == 2) - { + } else if (autocvar_rescan_pending == 2) { return; - } - else if(autocvar_rescan_pending == 3) - { + } else if (autocvar_rescan_pending == 3) { // now build missing mapinfo files - if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1)) + if (!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1)) { return; + } // we're done, start the timer cvar_set("rescan_pending", "0"); } mapvote_initialized = true; - if(DoNextMapOverride(0)) + if (DoNextMapOverride(0)) { return; - if(!autocvar_g_maplist_votable || player_count <= 0) - { + } + if (!autocvar_g_maplist_votable || player_count <= 0) { GotoNextMap(0); return; } - if(autocvar_sv_vote_gametype) { GameTypeVote_Start(); } - else if(autocvar_nextmap == "") { MapVote_Init(); } + if (autocvar_sv_vote_gametype) { GameTypeVote_Start(); } else if (autocvar_nextmap == "") { + MapVote_Init(); + } } MapVote_Tick(); @@ -695,8 +716,9 @@ void MapVote_Think() bool GameTypeVote_SetGametype(Gametype type) { - if (MapInfo_CurrentGametype() == type) + if (MapInfo_CurrentGametype() == type) { return true; + } Gametype tsave = MapInfo_CurrentGametype(); @@ -704,26 +726,24 @@ bool GameTypeVote_SetGametype(Gametype type) MapInfo_Enumerate(); MapInfo_FilterGametype(type, MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); - if(MapInfo_count > 0) - { + if (MapInfo_count > 0) { // update lsmaps in case the gametype changed, this way people can easily list maps for it - if(lsmaps_reply != "") { strunzone(lsmaps_reply); } + if (lsmaps_reply != "") { strunzone(lsmaps_reply); } lsmaps_reply = strzone(getlsmaps()); bprint("Game type successfully switched to ", MapInfo_Type_ToString(type), "\n"); - } - else - { + } else { bprint("Cannot use this game type: no map for it found\n"); MapInfo_SwitchGameType(tsave); MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); return false; } - //localcmd("gametype ", MapInfo_Type_ToString(type), "\n"); + // localcmd("gametype ", MapInfo_Type_ToString(type), "\n"); - cvar_set("g_maplist", MapInfo_ListAllowedMaps(type, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()) ); - if(autocvar_g_maplist_shuffle) + cvar_set("g_maplist", MapInfo_ListAllowedMaps(type, MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags())); + if (autocvar_g_maplist_shuffle) { ShuffleMaplist(); + } return true; } @@ -731,11 +751,11 @@ bool GameTypeVote_SetGametype(Gametype type) bool gametypevote_finished; bool GameTypeVote_Finished(int pos) { - if(!gametypevote || gametypevote_finished) + if (!gametypevote || gametypevote_finished) { return false; + } - if ( !GameTypeVote_SetGametype(GameTypeVote_Type_FromString(mapvote_maps[pos])) ) - { + if (!GameTypeVote_SetGametype(GameTypeVote_Type_FromString(mapvote_maps[pos]))) { LOG_TRACE("Selected gametype is not supported by any map"); } @@ -749,12 +769,15 @@ bool GameTypeVote_Finished(int pos) bool GameTypeVote_AddVotable(string nextMode) { - if ( nextMode == "" || GameTypeVote_Type_FromString(nextMode) == NULL ) + if (nextMode == "" || GameTypeVote_Type_FromString(nextMode) == NULL) { return false; + } - for(int j = 0; j < mapvote_count; ++j) - if(mapvote_maps[j] == nextMode) + for (int j = 0; j < mapvote_count; ++j) { + if (mapvote_maps[j] == nextMode) { return false; + } + } mapvote_maps[mapvote_count] = strzone(nextMode); mapvote_maps_suggested[mapvote_count] = false; @@ -766,7 +789,6 @@ bool GameTypeVote_AddVotable(string nextMode) mapvote_count += 1; return true; - } bool GameTypeVote_Start() @@ -785,13 +807,12 @@ bool GameTypeVote_Start() int really_available, which_available; really_available = 0; which_available = -1; - for(int j = 0; j < n; ++j) - { - if ( GameTypeVote_AddVotable(argv(j)) ) - if ( mapvote_maps_flags[j] & GTV_AVAILABLE ) - { - really_available++; - which_available = j; + for (int j = 0; j < n; ++j) { + if (GameTypeVote_AddVotable(argv(j))) { + if (mapvote_maps_flags[j] & GTV_AVAILABLE) { + really_available++; + which_available = j; + } } } @@ -799,18 +820,17 @@ bool GameTypeVote_Start() gametypevote = 1; - if ( really_available == 0 ) - { - if ( mapvote_count > 0 ) + if (really_available == 0) { + if (mapvote_count > 0) { strunzone(mapvote_maps[0]); + } mapvote_maps[0] = strzone(MapInfo_Type_ToString(MapInfo_CurrentGametype())); - //GameTypeVote_Finished(0); + // GameTypeVote_Finished(0); MapVote_Finished(0); return false; } - if ( really_available == 1 ) - { - //GameTypeVote_Finished(which_available); + if (really_available == 1) { + // GameTypeVote_Finished(which_available); MapVote_Finished(which_available); return false; } @@ -818,8 +838,9 @@ bool GameTypeVote_Start() mapvote_count_real = mapvote_count; mapvote_keeptwotime = time + autocvar_sv_vote_gametype_keeptwotime; - if(mapvote_count_real < 3 || mapvote_keeptwotime <= time) + if (mapvote_count_real < 3 || mapvote_keeptwotime <= time) { mapvote_keeptwotime = 0; + } MapVote_Spawn(); diff --git a/qcsrc/server/mutators/loader.qc b/qcsrc/server/mutators/loader.qc index 7c20b3729..5567f31de 100644 --- a/qcsrc/server/mutators/loader.qc +++ b/qcsrc/server/mutators/loader.qc @@ -3,12 +3,15 @@ #include <server/defs.qh> #include <server/miscfunctions.qh> -STATIC_INIT_LATE(Gametype) { - Gametype g = MapInfo_CurrentGametype(); - if (g) { - for (string _s = g.m_mutators; _s != ""; _s = cdr(_s)) { - string s = car(_s); - FOREACH(Mutators, it.m_name == s, { Mutator_Add(it); break; }); - } - } +STATIC_INIT_LATE(Gametype) +{ + Gametype g = MapInfo_CurrentGametype(); + if (g) { + for (string _s = g.m_mutators; _s != ""; _s = cdr(_s)) { + string s = car(_s); + FOREACH(Mutators, it.m_name == s, { Mutator_Add(it); + break; + }); + } + } } diff --git a/qcsrc/server/mutators/mutator/gamemode_assault.qh b/qcsrc/server/mutators/mutator/gamemode_assault.qh index f437d98b5..7da981760 100644 --- a/qcsrc/server/mutators/mutator/gamemode_assault.qh +++ b/qcsrc/server/mutators/mutator/gamemode_assault.qh @@ -6,15 +6,15 @@ const int ST_ASSAULT_OBJECTIVES = 1; REGISTER_MUTATOR(as, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { - GameRules_teams(true); - int teams = BITS(2); // always red vs blue - GameRules_scoring(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, { - field_team(ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); - field(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); - }); + GameRules_teams(true); + int teams = BITS(2); // always red vs blue + GameRules_scoring(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, { + field_team(ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); + field(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY); + }); } return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_ca.qh b/qcsrc/server/mutators/mutator/gamemode_ca.qh index 0982fcca8..8bfb8972e 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ca.qh +++ b/qcsrc/server/mutators/mutator/gamemode_ca.qh @@ -6,7 +6,7 @@ int autocvar_g_ca_point_limit; int autocvar_g_ca_point_leadlimit; float autocvar_g_ca_round_timelimit; bool autocvar_g_ca_team_spawns; -//int autocvar_g_ca_teams; +// int autocvar_g_ca_teams; int autocvar_g_ca_teams_override; float autocvar_g_ca_warmup; @@ -23,22 +23,22 @@ bool ca_isEliminated(entity e); REGISTER_MUTATOR(ca, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { GameRules_teams(true); - GameRules_spawning_teams(autocvar_g_ca_team_spawns); - GameRules_limit_score(autocvar_g_ca_point_limit); - GameRules_limit_lead(autocvar_g_ca_point_leadlimit); + GameRules_spawning_teams(autocvar_g_ca_team_spawns); + GameRules_limit_score(autocvar_g_ca_point_limit); + GameRules_limit_lead(autocvar_g_ca_point_leadlimit); ca_teams = autocvar_g_ca_teams_override; - if (ca_teams < 2) + if (ca_teams < 2) { ca_teams = cvar("g_ca_teams"); // read the cvar directly as it gets written earlier in the same frame - + } ca_teams = BITS(bound(2, ca_teams, 4)); - GameRules_scoring(ca_teams, SFL_SORT_PRIO_PRIMARY, 0, { - field_team(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); - }); + GameRules_scoring(ca_teams, SFL_SORT_PRIO_PRIMARY, 0, { + field_team(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY); + }); allowed_to_spawn = true; round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart); diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qh b/qcsrc/server/mutators/mutator/gamemode_ctf.qh index 0b86a57f8..09d231643 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qh +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qh @@ -8,16 +8,16 @@ void ctf_Initialize(); REGISTER_MUTATOR(ctf, false) { - MUTATOR_STATIC(); - MUTATOR_ONADD - { - GameRules_teams(true); - GameRules_limit_score(autocvar_capturelimit_override); - GameRules_limit_lead(autocvar_captureleadlimit_override); - - ctf_Initialize(); - } - return 0; + MUTATOR_STATIC(); + MUTATOR_ONADD + { + GameRules_teams(true); + GameRules_limit_score(autocvar_capturelimit_override); + GameRules_limit_lead(autocvar_captureleadlimit_override); + + ctf_Initialize(); + } + return 0; } // used in cheats.qc @@ -27,10 +27,14 @@ void ctf_RespawnFlag(entity flag); const int ST_CTF_CAPS = 1; CLASS(Flag, Pickup) - ATTRIB(Flag, m_mins, vector, (PL_MIN_CONST + '0 0 -13') * 1.4); // scaling be damned - ATTRIB(Flag, m_maxs, vector, (PL_MAX_CONST + '0 0 -13') * 1.4); + ATTRIB(Flag, m_mins, vector, (PL_MIN_CONST + '0 0 -13') * 1.4); // scaling be damned + ATTRIB(Flag, m_maxs, vector, (PL_MAX_CONST + '0 0 -13') * 1.4); ENDCLASS(Flag) -Flag CTF_FLAG; STATIC_INIT(Flag) { CTF_FLAG = NEW(Flag); } +Flag CTF_FLAG; +STATIC_INIT(Flag) +{ + CTF_FLAG = NEW(Flag); +} void ctf_FlagTouch(entity this, entity toucher) { ITEM_HANDLE(Pickup, CTF_FLAG, this, toucher); } // flag constants // for most of these, there is just one question to be asked: WHYYYYY? @@ -68,7 +72,7 @@ const float VEHICLE_FLAG_SCALE = 1.0; // score fields .float score_assist; .float score_capture; -.float score_drop; // note: negated +.float score_drop; // note: negated .float score_pickup; .float score_return; .float score_team_capture; // shouldn't be too high @@ -123,12 +127,12 @@ void ctf_Handle_Throw(entity player, entity receiver, float droptype); // flag properties #define ctf_spawnorigin dropped_origin -bool ctf_stalemate; // indicates that a stalemate is active +bool ctf_stalemate; // indicates that a stalemate is active float ctf_captimerecord; // record time for capturing the flag .float ctf_pickuptime; .float ctf_droptime; -.int ctf_status; // status of the flag (FLAG_BASE, FLAG_DROPPED, FLAG_CARRY declared globally) -.entity ctf_dropper; // don't allow spam of dropping the flag +.int ctf_status; // status of the flag (FLAG_BASE, FLAG_DROPPED, FLAG_CARRY declared globally) +.entity ctf_dropper; // don't allow spam of dropping the flag .int max_flag_health; .float next_take_time; .bool ctf_flagdamaged_byworld; @@ -143,13 +147,13 @@ int ctf_teams; .int throw_count; // CaptureShield: If the player is too bad to be allowed to capture, shield them from taking the flag. -.bool ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture +.bool ctf_captureshielded; // set to 1 if the player is too bad to be allowed to capture float ctf_captureshield_min_negscore; // punish at -20 points -float ctf_captureshield_max_ratio; // punish at most 30% of each team -float ctf_captureshield_force; // push force of the shield +float ctf_captureshield_max_ratio; // punish at most 30% of each team +float ctf_captureshield_force; // push force of the shield // 1 flag ctf -bool ctf_oneflag; // indicates whether or not a neutral flag has been found +bool ctf_oneflag; // indicates whether or not a neutral flag has been found // bot player logic const int HAVOCBOT_CTF_ROLE_NONE = 0; @@ -165,28 +169,28 @@ const int HAVOCBOT_CTF_ROLE_ESCORT = 64; void havocbot_role_ctf_setrole(entity bot, int role); // team checking -#define CTF_SAMETEAM(a,b) ((autocvar_g_ctf_reverse || (ctf_oneflag && autocvar_g_ctf_oneflag_reverse)) ? DIFF_TEAM(a,b) : SAME_TEAM(a,b)) -#define CTF_DIFFTEAM(a,b) ((autocvar_g_ctf_reverse || (ctf_oneflag && autocvar_g_ctf_oneflag_reverse)) ? SAME_TEAM(a,b) : DIFF_TEAM(a,b)) +#define CTF_SAMETEAM(a, b) ((autocvar_g_ctf_reverse || (ctf_oneflag && autocvar_g_ctf_oneflag_reverse)) ? DIFF_TEAM(a, b) : SAME_TEAM(a, b)) +#define CTF_DIFFTEAM(a, b) ((autocvar_g_ctf_reverse || (ctf_oneflag && autocvar_g_ctf_oneflag_reverse)) ? SAME_TEAM(a, b) : DIFF_TEAM(a, b)) // networked flag statuses .int ctf_flagstatus = _STAT(CTF_FLAGSTATUS); #endif -const int CTF_RED_FLAG_TAKEN = 1; -const int CTF_RED_FLAG_LOST = 2; -const int CTF_RED_FLAG_CARRYING = 3; -const int CTF_BLUE_FLAG_TAKEN = 4; -const int CTF_BLUE_FLAG_LOST = 8; -const int CTF_BLUE_FLAG_CARRYING = 12; -const int CTF_YELLOW_FLAG_TAKEN = 16; -const int CTF_YELLOW_FLAG_LOST = 32; -const int CTF_YELLOW_FLAG_CARRYING = 48; -const int CTF_PINK_FLAG_TAKEN = 64; -const int CTF_PINK_FLAG_LOST = 128; -const int CTF_PINK_FLAG_CARRYING = 192; -const int CTF_NEUTRAL_FLAG_TAKEN = 256; -const int CTF_NEUTRAL_FLAG_LOST = 512; -const int CTF_NEUTRAL_FLAG_CARRYING = 768; -const int CTF_FLAG_NEUTRAL = 2048; -const int CTF_SHIELDED = 4096; -const int CTF_STALEMATE = 8192; +const int CTF_RED_FLAG_TAKEN = 1; +const int CTF_RED_FLAG_LOST = 2; +const int CTF_RED_FLAG_CARRYING = 3; +const int CTF_BLUE_FLAG_TAKEN = 4; +const int CTF_BLUE_FLAG_LOST = 8; +const int CTF_BLUE_FLAG_CARRYING = 12; +const int CTF_YELLOW_FLAG_TAKEN = 16; +const int CTF_YELLOW_FLAG_LOST = 32; +const int CTF_YELLOW_FLAG_CARRYING = 48; +const int CTF_PINK_FLAG_TAKEN = 64; +const int CTF_PINK_FLAG_LOST = 128; +const int CTF_PINK_FLAG_CARRYING = 192; +const int CTF_NEUTRAL_FLAG_TAKEN = 256; +const int CTF_NEUTRAL_FLAG_LOST = 512; +const int CTF_NEUTRAL_FLAG_CARRYING = 768; +const int CTF_FLAG_NEUTRAL = 2048; +const int CTF_SHIELDED = 4096; +const int CTF_STALEMATE = 8192; diff --git a/qcsrc/server/mutators/mutator/gamemode_cts.qh b/qcsrc/server/mutators/mutator/gamemode_cts.qh index c90919e6f..1842eed7a 100644 --- a/qcsrc/server/mutators/mutator/gamemode_cts.qh +++ b/qcsrc/server/mutators/mutator/gamemode_cts.qh @@ -7,13 +7,13 @@ void cts_Initialize(); REGISTER_MUTATOR(cts, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { g_race_qualifying = true; independent_players = 1; - GameRules_limit_score(0); - GameRules_limit_lead(0); + GameRules_limit_score(0); + GameRules_limit_lead(0); cts_Initialize(); } diff --git a/qcsrc/server/mutators/mutator/gamemode_deathmatch.qh b/qcsrc/server/mutators/mutator/gamemode_deathmatch.qh index f45b0800f..5f181ab14 100644 --- a/qcsrc/server/mutators/mutator/gamemode_deathmatch.qh +++ b/qcsrc/server/mutators/mutator/gamemode_deathmatch.qh @@ -4,6 +4,6 @@ REGISTER_MUTATOR(dm, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); return 0; } diff --git a/qcsrc/server/mutators/mutator/gamemode_domination.qh b/qcsrc/server/mutators/mutator/gamemode_domination.qh index cf5e54f6d..d327821f1 100644 --- a/qcsrc/server/mutators/mutator/gamemode_domination.qh +++ b/qcsrc/server/mutators/mutator/gamemode_domination.qh @@ -11,16 +11,17 @@ void dom_Initialize(); REGISTER_MUTATOR(dom, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { int fraglimit_override = autocvar_g_domination_point_limit; - if (autocvar_g_domination_roundbased && autocvar_g_domination_roundbased_point_limit) + if (autocvar_g_domination_roundbased && autocvar_g_domination_roundbased_point_limit) { fraglimit_override = autocvar_g_domination_roundbased_point_limit; + } GameRules_teams(true); - GameRules_limit_score(fraglimit_override); - GameRules_limit_lead(autocvar_g_domination_point_leadlimit); + GameRules_limit_score(fraglimit_override); + GameRules_limit_lead(autocvar_g_domination_point_leadlimit); dom_Initialize(); } @@ -55,4 +56,7 @@ float domination_teams; void AnimateDomPoint(entity this); IntrusiveList g_dompoints; -STATIC_INIT(g_dompoints) { g_dompoints = IL_NEW(); } +STATIC_INIT(g_dompoints) +{ + g_dompoints = IL_NEW(); +} diff --git a/qcsrc/server/mutators/mutator/gamemode_freezetag.qh b/qcsrc/server/mutators/mutator/gamemode_freezetag.qh index a258d82ea..1d4fd1dd4 100644 --- a/qcsrc/server/mutators/mutator/gamemode_freezetag.qh +++ b/qcsrc/server/mutators/mutator/gamemode_freezetag.qh @@ -9,13 +9,13 @@ void freezetag_Initialize(); REGISTER_MUTATOR(ft, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { GameRules_teams(true); - GameRules_spawning_teams(autocvar_g_freezetag_team_spawns); - GameRules_limit_score(autocvar_g_freezetag_point_limit); - GameRules_limit_lead(autocvar_g_freezetag_point_leadlimit); + GameRules_spawning_teams(autocvar_g_freezetag_team_spawns); + GameRules_limit_score(autocvar_g_freezetag_point_limit); + GameRules_limit_lead(autocvar_g_freezetag_point_leadlimit); freezetag_Initialize(); } diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qh b/qcsrc/server/mutators/mutator/gamemode_invasion.qh index 0ea0e82c4..caac90cf0 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qh +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qh @@ -11,14 +11,14 @@ void invasion_Initialize(); REGISTER_MUTATOR(inv, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { if (autocvar_g_invasion_teams >= 2) { GameRules_teams(true); GameRules_spawning_teams(autocvar_g_invasion_team_spawns); } - GameRules_limit_score(autocvar_g_invasion_point_limit); + GameRules_limit_score(autocvar_g_invasion_point_limit); g_invasion = true; cvar_settemp("g_monsters", "1"); @@ -43,5 +43,5 @@ float inv_monsterskill; const float ST_INV_KILLS = 1; const int INV_TYPE_ROUND = 0; // round-based waves of enemies -const int INV_TYPE_HUNT = 1; // clear the map of placed enemies +const int INV_TYPE_HUNT = 1; // clear the map of placed enemies const int INV_TYPE_STAGE = 2; // reach the end of the level diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qh b/qcsrc/server/mutators/mutator/gamemode_keepaway.qh index abbabbd5b..77d31d518 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qh +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qh @@ -6,14 +6,14 @@ void ka_Initialize(); REGISTER_MUTATOR(ka, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { - GameRules_scoring(0, SFL_SORT_PRIO_PRIMARY, 0, { - field(SP_KEEPAWAY_PICKUPS, "pickups", 0); - field(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0); - field(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY); - }); + GameRules_scoring(0, SFL_SORT_PRIO_PRIMARY, 0, { + field(SP_KEEPAWAY_PICKUPS, "pickups", 0); + field(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0); + field(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY); + }); ka_Initialize(); } diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh index 77d7c06fc..bb11120d3 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qh @@ -9,20 +9,20 @@ void kh_Initialize(); REGISTER_MUTATOR(kh, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { GameRules_teams(true); - GameRules_spawning_teams(autocvar_g_keyhunt_team_spawns); - GameRules_limit_score(autocvar_g_keyhunt_point_limit); - GameRules_limit_lead(autocvar_g_keyhunt_point_leadlimit); + GameRules_spawning_teams(autocvar_g_keyhunt_team_spawns); + GameRules_limit_score(autocvar_g_keyhunt_point_limit); + GameRules_limit_lead(autocvar_g_keyhunt_point_leadlimit); kh_Initialize(); } return 0; } -#define FOR_EACH_KH_KEY(v) for(v = kh_worldkeylist; v; v = v.kh_worldkeynext ) +#define FOR_EACH_KH_KEY(v) for (v = kh_worldkeylist; v; v = v.kh_worldkeynext) // ALL OF THESE should be removed in the future, as other code should not have to care diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qc b/qcsrc/server/mutators/mutator/gamemode_lms.qc index 4d6f70438..0fa9abf0f 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qc +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qc @@ -14,16 +14,20 @@ float LMS_NewPlayerLives() { float fl; fl = autocvar_fraglimit; - if(fl == 0) + if (fl == 0) { fl = 999; + } // first player has left the game for dying too much? Nobody else can get in. - if(lms_lowest_lives < 1) + if (lms_lowest_lives < 1) { return 0; + } - if(!autocvar_g_lms_join_anytime) - if(lms_lowest_lives < fl - autocvar_g_lms_last_join) + if (!autocvar_g_lms_join_anytime) { + if (lms_lowest_lives < fl - autocvar_g_lms_last_join) { return 0; + } + } return bound(1, lms_lowest_lives, fl); } @@ -42,52 +46,43 @@ int WinningCondition_LMS() int l = LMS_NewPlayerLives(); head = find(NULL, classname, STR_PLAYER); - if(head) + if (head) { have_player = true; + } head2 = find(head, classname, STR_PLAYER); - if(head2) + if (head2) { have_players = true; + } - if(have_player) - { + if (have_player) { // we have at least one player - if(have_players) - { + if (have_players) { // two or more active players - continue with the game - } - else - { + } else { // exactly one player? ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out - if(l) - { + if (l) { // game still running (that is, nobody got removed from the game by a frag yet)? then continue return WINNING_NO; - } - else - { + } else { // a winner! // and assign him his first place GameRules_scoring_add(head, LMS_RANK, 1); - if(warmup_stage) + if (warmup_stage) { return WINNING_NO; - else + } else { return WINNING_YES; + } } } - } - else - { + } else { // nobody is playing at all... - if(l) - { + if (l) { // wait for players... - } - else - { + } else { // SNAFU (maybe a draw game?) ClearWinners(); LOG_TRACE("No players, ending game."); @@ -100,10 +95,12 @@ int WinningCondition_LMS() WinningConditionHelper(NULL); ClearWinners(); - if(WinningConditionHelper_winner) + if (WinningConditionHelper_winner) { WinningConditionHelper_winner.winning = true; - if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore) + } + if (WinningConditionHelper_topscore == WinningConditionHelper_secondscore) { return WINNING_NEVER; + } // Top two have different scores? Way to go for our beloved TIMELIMIT! return WINNING_NO; @@ -129,17 +126,19 @@ MUTATOR_HOOKFUNCTION(lms, PutClientInServer) { entity player = M_ARGV(0, entity); - if(player.frags == FRAGS_SPECTATOR) + if (player.frags == FRAGS_SPECTATOR) { TRANSMUTE(Observer, player); - else - { + } else { float tl = GameRules_scoring_add(player, LMS_LIVES, 0); - if(tl < lms_lowest_lives) + if (tl < lms_lowest_lives) { lms_lowest_lives = tl; - if(tl <= 0) + } + if (tl <= 0) { TRANSMUTE(Observer, player); - if(warmup_stage) + } + if (warmup_stage) { GameRules_scoring_add(player, LMS_RANK, -GameRules_scoring_add(player, LMS_RANK, 0)); + } } } @@ -147,12 +146,13 @@ MUTATOR_HOOKFUNCTION(lms, ForbidSpawn) { entity player = M_ARGV(0, entity); - if(warmup_stage) + if (warmup_stage) { return false; - if(player.frags == FRAGS_SPECTATOR) + } + if (player.frags == FRAGS_SPECTATOR) { return true; - if(GameRules_scoring_add(player, LMS_LIVES, 0) <= 0) - { + } + if (GameRules_scoring_add(player, LMS_LIVES, 0) <= 0) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_LMS_NOLIVES); return true; } @@ -170,53 +170,52 @@ void lms_RemovePlayer(entity player) { static int quitters = 0; float player_rank = GameRules_scoring_add(player, LMS_RANK, 0); - if (!player_rank) - { + if (!player_rank) { int pl_cnt = 0; - FOREACH_CLIENT(IS_PLAYER(it), { pl_cnt++; }); - if (player.lms_spectate_warning != 2) - { - if(IS_BOT_CLIENT(player)) + FOREACH_CLIENT(IS_PLAYER(it), { pl_cnt++; + }); + if (player.lms_spectate_warning != 2) { + if (IS_BOT_CLIENT(player)) { bot_clear(player); + } player.frags = FRAGS_LMS_LOSER; GameRules_scoring_add(player, LMS_RANK, pl_cnt + 1); - } - else - { + } else { lms_lowest_lives = 999; FOREACH_CLIENT(true, { - if (it.frags == FRAGS_LMS_LOSER) - { + if (it.frags == FRAGS_LMS_LOSER) { float it_rank = GameRules_scoring_add(it, LMS_RANK, 0); - if (it_rank > player_rank && it_rank <= 256) + if (it_rank > player_rank && it_rank <= 256) { GameRules_scoring_add(it, LMS_RANK, -1); + } lms_lowest_lives = 0; - } - else if (it.frags != FRAGS_SPECTATOR) - { + } else if (it.frags != FRAGS_SPECTATOR) { float tl = GameRules_scoring_add(it, LMS_LIVES, 0); - if(tl < lms_lowest_lives) + if (tl < lms_lowest_lives) { lms_lowest_lives = tl; + } } }); GameRules_scoring_add(player, LMS_RANK, 665 - quitters); // different from 666 - if(!warmup_stage) - { + if (!warmup_stage) { GameRules_scoring_add(player, LMS_LIVES, -GameRules_scoring_add(player, LMS_LIVES, 0)); ++quitters; } player.frags = FRAGS_LMS_LOSER; TRANSMUTE(Observer, player); } - if (pl_cnt == 2 && !warmup_stage) // a player is forfeiting leaving only one player + if (pl_cnt == 2 && !warmup_stage) { // a player is forfeiting leaving only one player lms_lowest_lives = 0; // end the game now! + } } - if(CS(player).killcount != FRAGS_SPECTATOR) - if(GameRules_scoring_add(player, LMS_RANK, 0) > 0 && player.lms_spectate_warning != 2) + if (CS(player).killcount != FRAGS_SPECTATOR) { + if (GameRules_scoring_add(player, LMS_RANK, 0) > 0 && player.lms_spectate_warning != 2) { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_LMS_NOLIVES, player.netname); - else + } else { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_LMS_FORFEIT, player.netname); + } + } } MUTATOR_HOOKFUNCTION(lms, ClientDisconnect) @@ -228,10 +227,10 @@ MUTATOR_HOOKFUNCTION(lms, ClientDisconnect) MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); lms_RemovePlayer(player); - return true; // prevent team reset + return true; // prevent team reset } MUTATOR_HOOKFUNCTION(lms, ClientConnect) @@ -241,8 +240,7 @@ MUTATOR_HOOKFUNCTION(lms, ClientConnect) TRANSMUTE(Player, player); campaign_bots_may_start = true; - if(GameRules_scoring_add(player, LMS_LIVES, LMS_NewPlayerLives()) <= 0) - { + if (GameRules_scoring_add(player, LMS_LIVES, LMS_NewPlayerLives()) <= 0) { GameRules_scoring_add(player, LMS_RANK, 666); // mark as forced spectator for the hud code player.frags = FRAGS_SPECTATOR; } @@ -252,14 +250,16 @@ MUTATOR_HOOKFUNCTION(lms, PlayerPreThink) { entity player = M_ARGV(0, entity); - if(player.deadflag == DEAD_DYING) + if (player.deadflag == DEAD_DYING) { player.deadflag = DEAD_RESPAWNING; + } } MUTATOR_HOOKFUNCTION(lms, PlayerRegen) { - if(autocvar_g_lms_regenerate) + if (autocvar_g_lms_regenerate) { return false; + } return true; } @@ -273,18 +273,19 @@ MUTATOR_HOOKFUNCTION(lms, GiveFragsForKill) { entity frag_target = M_ARGV(1, entity); - if (!warmup_stage) - { + if (!warmup_stage) { // remove a life int tl = GameRules_scoring_add(frag_target, LMS_LIVES, -1); - if(tl < lms_lowest_lives) + if (tl < lms_lowest_lives) { lms_lowest_lives = tl; - if(tl <= 0) - { + } + if (tl <= 0) { int pl_cnt = 0; - FOREACH_CLIENT(IS_PLAYER(it), { pl_cnt++; }); - if(IS_BOT_CLIENT(frag_target)) + FOREACH_CLIENT(IS_PLAYER(it), { pl_cnt++; + }); + if (IS_BOT_CLIENT(frag_target)) { bot_clear(frag_target); + } frag_target.frags = FRAGS_LMS_LOSER; GameRules_scoring_add(frag_target, LMS_RANK, pl_cnt); } @@ -317,9 +318,11 @@ MUTATOR_HOOKFUNCTION(lms, FilterItem) { entity item = M_ARGV(0, entity); - if(autocvar_g_lms_extra_lives) - if(item.itemdef == ITEM_ExtraLife) - return false; + if (autocvar_g_lms_extra_lives) { + if (item.itemdef == ITEM_ExtraLife) { + return false; + } + } return true; } @@ -331,13 +334,13 @@ void lms_extralife(entity this) MUTATOR_HOOKFUNCTION(lms, OnEntityPreSpawn) { - if (!autocvar_g_powerups) return false; - if (!autocvar_g_lms_extra_lives) return false; + if (!autocvar_g_powerups) { return false; } + if (!autocvar_g_lms_extra_lives) { return false; } entity ent = M_ARGV(0, entity); // Can't use .itemdef here - if (ent.classname != "item_health_mega") return false; + if (ent.classname != "item_health_mega") { return false; } entity e = spawn(); setthink(e, lms_extralife); @@ -355,8 +358,7 @@ MUTATOR_HOOKFUNCTION(lms, ItemTouch) entity item = M_ARGV(0, entity); entity toucher = M_ARGV(1, entity); - if(item.itemdef == ITEM_ExtraLife) - { + if (item.itemdef == ITEM_ExtraLife) { Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES); GameRules_scoring_add(toucher, LMS_LIVES, autocvar_g_lms_extra_lives); return MUT_ITEMTOUCH_PICKUP; @@ -377,17 +379,13 @@ MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE) MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); - if(warmup_stage || player.lms_spectate_warning) - { + if (warmup_stage || player.lms_spectate_warning) { // for the forfeit message... player.lms_spectate_warning = 2; - } - else - { - if(player.frags != FRAGS_SPECTATOR && player.frags != FRAGS_LMS_LOSER) - { + } else { + if (player.frags != FRAGS_SPECTATOR && player.frags != FRAGS_LMS_LOSER) { player.lms_spectate_warning = 1; sprint(player, "WARNING: you won't be able to enter the game again after spectating in LMS. Use the same command again to spectate anyway.\n"); } @@ -414,9 +412,11 @@ MUTATOR_HOOKFUNCTION(lms, GetPlayerStatus) MUTATOR_HOOKFUNCTION(lms, AddPlayerScore) { - if(game_stopped) - if(M_ARGV(0, entity) == SP_LMS_RANK) // score field - return true; // allow writing to this field in intermission as it is needed for newly joining players + if (game_stopped) { + if (M_ARGV(0, entity) == SP_LMS_RANK) { // score field + return true; // allow writing to this field in intermission as it is needed for newly joining players + } + } } void lms_Initialize() diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qh b/qcsrc/server/mutators/mutator/gamemode_lms.qh index c69113a0c..95fd44ae1 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qh +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qh @@ -8,16 +8,16 @@ void lms_Initialize(); REGISTER_MUTATOR(lms, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { - GameRules_limit_score(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override)); - GameRules_limit_lead(0); - GameRules_score_enabled(false); - GameRules_scoring(0, 0, 0, { - field(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY); - field(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE); - }); + GameRules_limit_score(((!autocvar_g_lms_lives_override) ? -1 : autocvar_g_lms_lives_override)); + GameRules_limit_lead(0); + GameRules_score_enabled(false); + GameRules_scoring(0, 0, 0, { + field(SP_LMS_LIVES, "lives", SFL_SORT_PRIO_SECONDARY); + field(SP_LMS_RANK, "rank", SFL_LOWER_IS_BETTER | SFL_RANK | SFL_SORT_PRIO_PRIMARY | SFL_ALLOW_HIDE); + }); lms_Initialize(); } diff --git a/qcsrc/server/mutators/mutator/gamemode_race.qh b/qcsrc/server/mutators/mutator/gamemode_race.qh index 1e475e3ce..9f2e7fb3e 100644 --- a/qcsrc/server/mutators/mutator/gamemode_race.qh +++ b/qcsrc/server/mutators/mutator/gamemode_race.qh @@ -7,7 +7,7 @@ void race_Initialize(); REGISTER_MUTATOR(rc, false) { - MUTATOR_STATIC(); + MUTATOR_STATIC(); MUTATOR_ONADD { rc_SetLimits(); diff --git a/qcsrc/server/pathlib/costs.qc b/qcsrc/server/pathlib/costs.qc index 1449e382a..e562fef66 100644 --- a/qcsrc/server/pathlib/costs.qc +++ b/qcsrc/server/pathlib/costs.qc @@ -1,29 +1,31 @@ #include "costs.qh" -float pathlib_g_static(entity parent,vector to, float static_cost) +float pathlib_g_static(entity parent, vector to, float static_cost) { - return parent.pathlib_node_g + static_cost; + return parent.pathlib_node_g + static_cost; } -float pathlib_g_static_water(entity parent,vector to, float static_cost) +float pathlib_g_static_water(entity parent, vector to, float static_cost) { - if(inwater(to)) - return parent.pathlib_node_g + static_cost * pathlib_movecost_waterfactor; - else - return parent.pathlib_node_g + static_cost; + if (inwater(to)) { + return parent.pathlib_node_g + static_cost * pathlib_movecost_waterfactor; + } else { + return parent.pathlib_node_g + static_cost; + } } -float pathlib_g_euclidean(entity parent,vector to, float static_cost) +float pathlib_g_euclidean(entity parent, vector to, float static_cost) { - return parent.pathlib_node_g + vlen(parent.origin - to); + return parent.pathlib_node_g + vlen(parent.origin - to); } -float pathlib_g_euclidean_water(entity parent,vector to, float static_cost) +float pathlib_g_euclidean_water(entity parent, vector to, float static_cost) { - if(inwater(to)) - return parent.pathlib_node_g + vlen(parent.origin - to) * pathlib_movecost_waterfactor; - else - return parent.pathlib_node_g + vlen(parent.origin - to); + if (inwater(to)) { + return parent.pathlib_node_g + vlen(parent.origin - to) * pathlib_movecost_waterfactor; + } else { + return parent.pathlib_node_g + vlen(parent.origin - to); + } } @@ -31,30 +33,30 @@ float pathlib_g_euclidean_water(entity parent,vector to, float static_cost) Manhattan Menas we expect to move up,down left or right No diagonal moves espected. (like moving bewteen city blocks) **/ -float pathlib_h_manhattan(vector a,vector b) +float pathlib_h_manhattan(vector a, vector b) { - //h(n) = D * (abs(n.x-goal.x) + abs(n.y-goal.y)) + // h(n) = D * (abs(n.x-goal.x) + abs(n.y-goal.y)) - float h = fabs(a.x - b.x); - h += fabs(a.y - b.y); - h *= pathlib_gridsize; + float h = fabs(a.x - b.x); + h += fabs(a.y - b.y); + h *= pathlib_gridsize; - return h; + return h; } /** This heuristic consider both stright and disagonal moves to have teh same cost. **/ -float pathlib_h_diagonal(vector a,vector b) +float pathlib_h_diagonal(vector a, vector b) { - //h(n) = D * max(abs(n.x-goal.x), abs(n.y-goal.y)) + // h(n) = D * max(abs(n.x-goal.x), abs(n.y-goal.y)) - float hx = fabs(a.x - b.x); - float hy = fabs(a.y - b.y); - float h = pathlib_movecost * max(hx,hy); + float hx = fabs(a.x - b.x); + float hy = fabs(a.y - b.y); + float h = pathlib_movecost * max(hx, hy); - return h; + return h; } /** @@ -62,74 +64,74 @@ float pathlib_h_diagonal(vector a,vector b) Will usualy mean a lower H then G meaning A* Will speand more and run slower. **/ -float pathlib_h_euclidean(vector a,vector b) +float pathlib_h_euclidean(vector a, vector b) { - return vlen(a - b); + return vlen(a - b); } /** This heuristic consider both stright and disagonal moves, But has a separate cost for diagonal moves. **/ -float pathlib_h_diagonal2(vector a,vector b) +float pathlib_h_diagonal2(vector a, vector b) { - /* - h_diagonal(n) = min(abs(n.x-goal.x), abs(n.y-goal.y)) - h_straight(n) = (abs(n.x-goal.x) + abs(n.y-goal.y)) - h(n) = D2 * h_diagonal(n) + D * (h_straight(n) - 2*h_diagonal(n))) - */ + /* + h_diagonal(n) = min(abs(n.x-goal.x), abs(n.y-goal.y)) + h_straight(n) = (abs(n.x-goal.x) + abs(n.y-goal.y)) + h(n) = D2 * h_diagonal(n) + D * (h_straight(n) - 2*h_diagonal(n))) + */ - float hx = fabs(a.x - b.x); - float hy = fabs(a.y - b.y); + float hx = fabs(a.x - b.x); + float hy = fabs(a.y - b.y); - float h_diag = min(hx,hy); - float h_str = hx + hy; + float h_diag = min(hx, hy); + float h_str = hx + hy; - float h = pathlib_movecost_diag * h_diag; - h += pathlib_movecost * (h_str - 2 * h_diag); + float h = pathlib_movecost_diag * h_diag; + h += pathlib_movecost * (h_str - 2 * h_diag); - return h; + return h; } /** This heuristic consider both stright and disagonal moves, But has a separate cost for diagonal moves. **/ -float pathlib_h_diagonal2sdp(vector preprev,vector prev,vector point,vector end) +float pathlib_h_diagonal2sdp(vector preprev, vector prev, vector point, vector end) { - //h_diagonal(n) = min(abs(n.x-goal.x), abs(n.y-goal.y)) - //h_straight(n) = (abs(n.x-goal.x) + abs(n.y-goal.y)) - //h(n) = D2 * h_diagonal(n) + D * (h_straight(n) - 2*h_diagonal(n))) + // h_diagonal(n) = min(abs(n.x-goal.x), abs(n.y-goal.y)) + // h_straight(n) = (abs(n.x-goal.x) + abs(n.y-goal.y)) + // h(n) = D2 * h_diagonal(n) + D * (h_straight(n) - 2*h_diagonal(n))) - float hx = fabs(point.x - end.x); - float hy = fabs(point.y - end.y); - float hz = fabs(point.z - end.z); + float hx = fabs(point.x - end.x); + float hy = fabs(point.y - end.y); + float hz = fabs(point.z - end.z); - float h_diag = min3(hx,hy,hz); - float h_str = hx + hy + hz; + float h_diag = min3(hx, hy, hz); + float h_str = hx + hy + hz; - float h = pathlib_movecost_diag * h_diag; - h += pathlib_movecost * (h_str - 2 * h_diag); + float h = pathlib_movecost_diag * h_diag; + h += pathlib_movecost * (h_str - 2 * h_diag); - vector d1 = normalize(preprev - point); - vector d2 = normalize(prev - point); - float m = vlen(d1-d2); + vector d1 = normalize(preprev - point); + vector d2 = normalize(prev - point); + float m = vlen(d1 - d2); - return h * m; + return h * m; } -float pathlib_h_diagonal3(vector a,vector b) +float pathlib_h_diagonal3(vector a, vector b) { - float hx = fabs(a.x - b.x); - float hy = fabs(a.y - b.y); - float hz = fabs(a.z - b.z); + float hx = fabs(a.x - b.x); + float hy = fabs(a.y - b.y); + float hz = fabs(a.z - b.z); - float h_diag = min3(hx,hy,hz); - float h_str = hx + hy + hz; + float h_diag = min3(hx, hy, hz); + float h_str = hx + hy + hz; - float h = pathlib_movecost_diag * h_diag; - h += pathlib_movecost * (h_str - 2 * h_diag); + float h = pathlib_movecost_diag * h_diag; + h += pathlib_movecost * (h_str - 2 * h_diag); - return h; + return h; } diff --git a/qcsrc/server/pathlib/debug.qc b/qcsrc/server/pathlib/debug.qc index b84ae6414..fcb99a584 100644 --- a/qcsrc/server/pathlib/debug.qc +++ b/qcsrc/server/pathlib/debug.qc @@ -8,117 +8,112 @@ MODEL(SQUARE_BAD, "models/pathlib/badsquare.md3"); MODEL(EDGE, "models/pathlib/edge.md3"); #ifdef TURRET_DEBUG -void mark_error(vector where,float lifetime); -void mark_info(vector where,float lifetime); -entity mark_misc(vector where,float lifetime); +void mark_error(vector where, float lifetime); +void mark_info(vector where, float lifetime); +entity mark_misc(vector where, float lifetime); #endif void pathlib_showpath(entity start) { - entity e; - e = start; - while(e.path_next) - { - te_lightning1(e,e.origin,e.path_next.origin); - e = e.path_next; - } + entity e; + e = start; + while (e.path_next) { + te_lightning1(e, e.origin, e.path_next.origin); + e = e.path_next; + } } void path_dbg_think(entity this) { - pathlib_showpath(this); - this.nextthink = time + 1; + pathlib_showpath(this); + this.nextthink = time + 1; } void __showpath2_think(entity this) { - #ifdef TURRET_DEBUG - mark_info(this.origin,1); + #ifdef TURRET_DEBUG + mark_info(this.origin, 1); #endif - if(this.path_next) - { - setthink(this.path_next, __showpath2_think); - this.path_next.nextthink = time + 0.15; - } - else - { - setthink(this.owner, __showpath2_think); - this.owner.nextthink = time + 0.15; - } + if (this.path_next) { + setthink(this.path_next, __showpath2_think); + this.path_next.nextthink = time + 0.15; + } else { + setthink(this.owner, __showpath2_think); + this.owner.nextthink = time + 0.15; + } } void pathlib_showpath2(entity path) { - setthink(path, __showpath2_think); - path.nextthink = time; + setthink(path, __showpath2_think); + path.nextthink = time; } -void pathlib_showsquare2(entity node ,vector ncolor,float align) +void pathlib_showsquare2(entity node, vector ncolor, float align) { - - node.alpha = 0.25; - node.scale = pathlib_gridsize / 512.001; - node.solid = SOLID_NOT; - - setmodel(node, MDL_SQUARE); - setorigin(node, node.origin); - node.colormod = ncolor; - - if(align) - { - traceline(node.origin + '0 0 32', node.origin - '0 0 128', MOVE_WORLDONLY, node); - node.angles = vectoangles(trace_plane_normal); - node.angles_x -= 90; - } + node.alpha = 0.25; + node.scale = pathlib_gridsize / 512.001; + node.solid = SOLID_NOT; + + setmodel(node, MDL_SQUARE); + setorigin(node, node.origin); + node.colormod = ncolor; + + if (align) { + traceline(node.origin + '0 0 32', node.origin - '0 0 128', MOVE_WORLDONLY, node); + node.angles = vectoangles(trace_plane_normal); + node.angles_x -= 90; + } } -void pathlib_showsquare(vector where,float goodsquare,float _lifetime) +void pathlib_showsquare(vector where, float goodsquare, float _lifetime) { - entity s; + entity s; - if(!_lifetime) - _lifetime = time + 30; - else - _lifetime += time; + if (!_lifetime) { + _lifetime = time + 30; + } else { + _lifetime += time; + } - s = spawn(); - s.alpha = 0.25; - setthink(s, SUB_Remove); - s.nextthink = _lifetime; - s.scale = pathlib_gridsize / 512.001; - s.solid = SOLID_NOT; + s = spawn(); + s.alpha = 0.25; + setthink(s, SUB_Remove); + s.nextthink = _lifetime; + s.scale = pathlib_gridsize / 512.001; + s.solid = SOLID_NOT; - setmodel(s, goodsquare ? MDL_SQUARE_GOOD : MDL_SQUARE_BAD); + setmodel(s, goodsquare ? MDL_SQUARE_GOOD : MDL_SQUARE_BAD); - traceline(where + '0 0 32',where - '0 0 128',MOVE_WORLDONLY,s); + traceline(where + '0 0 32', where - '0 0 128', MOVE_WORLDONLY, s); - s.angles = vectoangles(trace_plane_normal); - s.angles_x -= 90; - setorigin(s, where); + s.angles = vectoangles(trace_plane_normal); + s.angles_x -= 90; + setorigin(s, where); } -void pathlib_showedge(vector where,float _lifetime,float rot) +void pathlib_showedge(vector where, float _lifetime, float rot) { - entity e; - - if(!_lifetime) - _lifetime = time + 30; - else - _lifetime += time; - - e = spawn(); - e.alpha = 0.25; - setthink(e, SUB_Remove); - e.nextthink = _lifetime; - e.scale = pathlib_gridsize / 512; - e.solid = SOLID_NOT; - setorigin(e, where); - setmodel(e, MDL_EDGE); - //traceline(where + '0 0 32',where - '0 0 128',MOVE_WORLDONLY,e); - //e.angles = vectoangles(trace_plane_normal); - e.angles_y = rot; - //e.angles_x += 90; - + entity e; + + if (!_lifetime) { + _lifetime = time + 30; + } else { + _lifetime += time; + } + + e = spawn(); + e.alpha = 0.25; + setthink(e, SUB_Remove); + e.nextthink = _lifetime; + e.scale = pathlib_gridsize / 512; + e.solid = SOLID_NOT; + setorigin(e, where); + setmodel(e, MDL_EDGE); + // traceline(where + '0 0 32',where - '0 0 128',MOVE_WORLDONLY,e); + // e.angles = vectoangles(trace_plane_normal); + e.angles_y = rot; + // e.angles_x += 90; } #endif diff --git a/qcsrc/server/pathlib/expandnode.qc b/qcsrc/server/pathlib/expandnode.qc index b77736b19..07d88894a 100644 --- a/qcsrc/server/pathlib/expandnode.qc +++ b/qcsrc/server/pathlib/expandnode.qc @@ -8,229 +8,216 @@ float plib_fvals[8]; float pathlib_expandnode_starf(entity node, vector start, vector goal) { - float fc; - - vector where = node.origin; - - vector f = PLIB_FORWARD * pathlib_gridsize; - vector r = PLIB_RIGHT * pathlib_gridsize; - - // Forward - plib_points[0] = where + f; - - // Back - plib_points[1] = where - f; - - // Right - plib_points[2] = where + r; - - // Left - plib_points[3] = where - r; - - // Forward-right - plib_points[4] = where + f + r; - - // Forward-left - plib_points[5] = where + f - r; - - // Back-right - plib_points[6] = where - f + r; - - // Back-left - plib_points[7] = where - f - r; - - for(int i=0;i < 8; ++i) - { - vector t = plib_points[i]; - fc = pathlib_heuristic(t,goal) + pathlib_cost(node, t, pathlib_gridsize); - plib_fvals[i] = fc; - - } - - fc = plib_fvals[0]; - plib_points2[0] = plib_points[0]; - vector bp; - bp = plib_points[0]; - int fc2 = 0; - for(int i = 0; i < 8; ++i) - { - bool c = false; - entity nap = pathlib_nodeatpoint(plib_points[i]); - if(nap) - { - if(nap.owner == openlist) - c = true; - } - else - c = true; - - if(c) - if(plib_fvals[i] < fc) - { - bp = plib_points[i]; - fc = plib_fvals[i]; - plib_points2[fc2] = plib_points[i]; - ++fc2; - } - - /* - nap = pathlib_nodeatpoint(plib_points[i]); - if(nap) - if not nap.owner == closedlist) - { - } - */ - } - - pathlib_makenode(node, start, bp, goal, pathlib_gridsize); - - for(int i = 0; i < 3; ++i) - { - pathlib_makenode(node, start, plib_points2[i], goal, pathlib_gridsize); - } - - return pathlib_open_cnt; + float fc; + + vector where = node.origin; + + vector f = PLIB_FORWARD * pathlib_gridsize; + vector r = PLIB_RIGHT * pathlib_gridsize; + + // Forward + plib_points[0] = where + f; + + // Back + plib_points[1] = where - f; + + // Right + plib_points[2] = where + r; + + // Left + plib_points[3] = where - r; + + // Forward-right + plib_points[4] = where + f + r; + + // Forward-left + plib_points[5] = where + f - r; + + // Back-right + plib_points[6] = where - f + r; + + // Back-left + plib_points[7] = where - f - r; + + for (int i = 0; i < 8; ++i) { + vector t = plib_points[i]; + fc = pathlib_heuristic(t, goal) + pathlib_cost(node, t, pathlib_gridsize); + plib_fvals[i] = fc; + } + + fc = plib_fvals[0]; + plib_points2[0] = plib_points[0]; + vector bp; + bp = plib_points[0]; + int fc2 = 0; + for (int i = 0; i < 8; ++i) { + bool c = false; + entity nap = pathlib_nodeatpoint(plib_points[i]); + if (nap) { + if (nap.owner == openlist) { + c = true; + } + } else { + c = true; + } + + if (c) { + if (plib_fvals[i] < fc) { + bp = plib_points[i]; + fc = plib_fvals[i]; + plib_points2[fc2] = plib_points[i]; + ++fc2; + } + } + + /* + nap = pathlib_nodeatpoint(plib_points[i]); + if(nap) + if not nap.owner == closedlist) + { + } + */ + } + + pathlib_makenode(node, start, bp, goal, pathlib_gridsize); + + for (int i = 0; i < 3; ++i) { + pathlib_makenode(node, start, plib_points2[i], goal, pathlib_gridsize); + } + + return pathlib_open_cnt; } float pathlib_expandnode_star(entity node, vector start, vector goal) { - vector point; - - vector where = node.origin; - - vector f = PLIB_FORWARD * pathlib_gridsize; - vector r = PLIB_RIGHT * pathlib_gridsize; - - if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_unknown) - node.pathlib_node_edgeflags = tile_check_plus2(node, node.origin); - - if(node.pathlib_node_edgeflags == pathlib_node_edgeflag_none) - { - LOG_TRACE("Node at ", vtos(node.origin), " not expanable"); - return pathlib_open_cnt; - } - - // Forward - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forward) - { - point = where + f; - pathlib_makenode(node, start, point, goal, pathlib_movecost); - } - - // Back - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_back) - { - point = where - f; - pathlib_makenode(node, start, point, goal, pathlib_movecost); - } - - // Right - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_right) - { - point = where + r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); - } - - // Left - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_left) - { - point = where - r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); - - } - - // Forward-right - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardright) - { - point = where + f + r; - pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); - } - - // Forward-left - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardleft) - { - point = where + f - r; - pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); - - } - - // Back-right - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backright) - { - point = where - f + r; - pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); - } - - // Back-left - if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backleft) - { - point = where - f - r; - pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); - } - - return pathlib_open_cnt; + vector point; + + vector where = node.origin; + + vector f = PLIB_FORWARD * pathlib_gridsize; + vector r = PLIB_RIGHT * pathlib_gridsize; + + if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_unknown) { + node.pathlib_node_edgeflags = tile_check_plus2(node, node.origin); + } + + if (node.pathlib_node_edgeflags == pathlib_node_edgeflag_none) { + LOG_TRACE("Node at ", vtos(node.origin), " not expanable"); + return pathlib_open_cnt; + } + + // Forward + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forward) { + point = where + f; + pathlib_makenode(node, start, point, goal, pathlib_movecost); + } + + // Back + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_back) { + point = where - f; + pathlib_makenode(node, start, point, goal, pathlib_movecost); + } + + // Right + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_right) { + point = where + r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); + } + + // Left + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_left) { + point = where - r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); + } + + // Forward-right + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardright) { + point = where + f + r; + pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); + } + + // Forward-left + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_forwardleft) { + point = where + f - r; + pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); + } + + // Back-right + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backright) { + point = where - f + r; + pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); + } + + // Back-left + if (node.pathlib_node_edgeflags & pathlib_node_edgeflag_backleft) { + point = where - f - r; + pathlib_makenode(node, start, point, goal, pathlib_movecost_diag); + } + + return pathlib_open_cnt; } float pathlib_expandnode_octagon(entity node, vector start, vector goal) { - vector point; + vector point; - vector where = node.origin; + vector where = node.origin; - vector f = PLIB_FORWARD * pathlib_gridsize; - vector r = PLIB_RIGHT * pathlib_gridsize; + vector f = PLIB_FORWARD * pathlib_gridsize; + vector r = PLIB_RIGHT * pathlib_gridsize; - // Forward - point = where + f; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Forward + point = where + f; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - // Back - point = where - f; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Back + point = where - f; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - // Right - point = where + r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Right + point = where + r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - // Left - point = where - r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Left + point = where - r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - f = PLIB_FORWARD * pathlib_gridsize * 0.5; - r = PLIB_RIGHT * pathlib_gridsize * 0.5; + f = PLIB_FORWARD * pathlib_gridsize * 0.5; + r = PLIB_RIGHT * pathlib_gridsize * 0.5; - // Forward-right - point = where + f + r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Forward-right + point = where + f + r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - // Forward-left - point = where + f - r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Forward-left + point = where + f - r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - // Back-right - point = where - f + r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Back-right + point = where - f + r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - // Back-left - point = where - f - r; - pathlib_makenode(node, start, point, goal, pathlib_movecost); + // Back-left + point = where - f - r; + pathlib_makenode(node, start, point, goal, pathlib_movecost); - return pathlib_open_cnt; + return pathlib_open_cnt; } float pathlib_expandnode_box(entity node, vector start, vector goal) { - vector v; - - for(v.z = node.origin.z - pathlib_gridsize; v.z <= node.origin.z + pathlib_gridsize; v.z += pathlib_gridsize) - for(v.y = node.origin.y - pathlib_gridsize; v.y <= node.origin.y + pathlib_gridsize; v.y += pathlib_gridsize) - for(v.x = node.origin.x - pathlib_gridsize; v.x <= node.origin.x + pathlib_gridsize; v.x += pathlib_gridsize) - { - //if(vlen(v - node.origin)) - pathlib_makenode(node,start,v,goal,pathlib_movecost); - } - - return pathlib_open_cnt; + vector v; + + for (v.z = node.origin.z - pathlib_gridsize; v.z <= node.origin.z + pathlib_gridsize; v.z += pathlib_gridsize) { + for (v.y = node.origin.y - pathlib_gridsize; v.y <= node.origin.y + pathlib_gridsize; v.y += pathlib_gridsize) { + for (v.x = node.origin.x - pathlib_gridsize; v.x <= node.origin.x + pathlib_gridsize; v.x += pathlib_gridsize) { + // if(vlen(v - node.origin)) + pathlib_makenode(node, start, v, goal, pathlib_movecost); + } + } + } + + return pathlib_open_cnt; } diff --git a/qcsrc/server/pathlib/main.qc b/qcsrc/server/pathlib/main.qc index c2f332603..af512a660 100644 --- a/qcsrc/server/pathlib/main.qc +++ b/qcsrc/server/pathlib/main.qc @@ -8,284 +8,276 @@ void pathlib_deletepath(entity start) { - if(!start) - return; - - FOREACH_ENTITY_ENT(owner, start, - { - setthink(it, SUB_Remove); - it.nextthink = time; - }); + if (!start) { + return; + } + + FOREACH_ENTITY_ENT(owner, start, + { + setthink(it, SUB_Remove); + it.nextthink = time; + }); } const float PATHLIB_NODEEXPIRE = 20; // 0.05 void dumpnode(entity n) { - if(n.is_path_node) - IL_REMOVE(g_pathlib_nodes, n); - n.is_path_node = false; - setthink(n, SUB_Remove); - n.nextthink = time; + if (n.is_path_node) { + IL_REMOVE(g_pathlib_nodes, n); + } + n.is_path_node = false; + setthink(n, SUB_Remove); + n.nextthink = time; } #if DEBUGPATHING void pathlib_showpath(entity start); void pathlib_showpath2(entity path); -void pathlib_showsquare(vector where,float goodsquare,float _lifetime); +void pathlib_showsquare(vector where, float goodsquare, float _lifetime); #endif -entity pathlib_mknode(vector where,entity parent) +entity pathlib_mknode(vector where, entity parent) { - entity node = pathlib_nodeatpoint(where); - if(node) - { - #ifdef TURRET_DEBUG - mark_error(where, 60); - #endif - return node; - } - - node = spawn(); - - setthink(node, SUB_Remove); - node.nextthink = time + PATHLIB_NODEEXPIRE; - IL_PUSH(g_pathlib_nodes, node); - node.is_path_node = true; - node.owner = openlist; - node.path_prev = parent; - - setsize(node, '0 0 0', '0 0 0'); - - setorigin(node, where); + entity node = pathlib_nodeatpoint(where); + if (node) { + #ifdef TURRET_DEBUG + mark_error(where, 60); + #endif + return node; + } + + node = spawn(); + + setthink(node, SUB_Remove); + node.nextthink = time + PATHLIB_NODEEXPIRE; + IL_PUSH(g_pathlib_nodes, node); + node.is_path_node = true; + node.owner = openlist; + node.path_prev = parent; + + setsize(node, '0 0 0', '0 0 0'); + + setorigin(node, where); #if DEBUGPATHING - pathlib_showsquare(where, 1 ,15); + pathlib_showsquare(where, 1, 15); #endif - ++pathlib_made_cnt; - ++pathlib_open_cnt; + ++pathlib_made_cnt; + ++pathlib_open_cnt; - return node; + return node; } -bool pathlib_makenode_adaptive(entity parent,vector start, vector to, vector goal,float cost) +bool pathlib_makenode_adaptive(entity parent, vector start, vector to, vector goal, float cost) { - bool dodge = false; - float f, h, g; - - ++pathlib_searched_cnt; - - if(inwater(parent.origin)) - { - LOG_DEBUG("FromWater"); - pathlib_expandnode = pathlib_expandnode_box; - pathlib_movenode = pathlib_swimnode; - } - else - { - if(inwater(to)) - { - LOG_DEBUG("ToWater"); - pathlib_expandnode = pathlib_expandnode_box; - pathlib_movenode = pathlib_walknode; - } - else - { - LOG_DEBUG("LandToLoand"); - //if(edge_check(parent.origin)) - // return 0; - - pathlib_expandnode = pathlib_expandnode_star; - pathlib_movenode = pathlib_walknode; - dodge = true; - } - } - - entity node = pathlib_nodeatpoint(to); - if(node) - { - LOG_DEBUG("NodeAtPoint"); - ++pathlib_merge_cnt; - - if(node.owner == openlist) - { - h = pathlib_heuristic(node.origin,goal); - float g = pathlib_cost(parent,node.origin,cost); - f = g + h; - - if(node.pathlib_node_g > g) - { - node.pathlib_node_h = h; - node.pathlib_node_g = g; - node.pathlib_node_f = f; - - node.path_prev = parent; - } - - if (!best_open_node) - best_open_node = node; - else if(best_open_node.pathlib_node_f > node.pathlib_node_f) - best_open_node = node; - } - - return true; - } - - vector where = pathlib_movenode(parent, parent.origin, to, 0); - - if (!pathlib_movenode_goodnode) - { - //pathlib_showsquare(where, 0 ,30); - //pathlib_showsquare(parent.origin, 1 ,30); - LOG_DEBUG("pathlib_movenode_goodnode = 0"); - return false; - } - - //pathlib_showsquare(where, 1 ,30); - - if(pathlib_nodeatpoint(where)) - { - LOG_DEBUG("NAP WHERE :",vtos(where)); - LOG_DEBUG("not NAP TO:",vtos(to)); - LOG_DEBUG("NAP-NNAP:",ftos(vlen(to-where))); - return false; - } - - - if(dodge) - if (!tile_check(parent, where)) - { - LOG_DEBUG("tile_check fail"); + bool dodge = false; + float f, h, g; + + ++pathlib_searched_cnt; + + if (inwater(parent.origin)) { + LOG_DEBUG("FromWater"); + pathlib_expandnode = pathlib_expandnode_box; + pathlib_movenode = pathlib_swimnode; + } else { + if (inwater(to)) { + LOG_DEBUG("ToWater"); + pathlib_expandnode = pathlib_expandnode_box; + pathlib_movenode = pathlib_walknode; + } else { + LOG_DEBUG("LandToLoand"); + // if(edge_check(parent.origin)) + // return 0; + + pathlib_expandnode = pathlib_expandnode_star; + pathlib_movenode = pathlib_walknode; + dodge = true; + } + } + + entity node = pathlib_nodeatpoint(to); + if (node) { + LOG_DEBUG("NodeAtPoint"); + ++pathlib_merge_cnt; + + if (node.owner == openlist) { + h = pathlib_heuristic(node.origin, goal); + float g = pathlib_cost(parent, node.origin, cost); + f = g + h; + + if (node.pathlib_node_g > g) { + node.pathlib_node_h = h; + node.pathlib_node_g = g; + node.pathlib_node_f = f; + + node.path_prev = parent; + } + + if (!best_open_node) { + best_open_node = node; + } else if (best_open_node.pathlib_node_f > node.pathlib_node_f) { + best_open_node = node; + } + } + + return true; + } + + vector where = pathlib_movenode(parent, parent.origin, to, 0); + + if (!pathlib_movenode_goodnode) { + // pathlib_showsquare(where, 0 ,30); + // pathlib_showsquare(parent.origin, 1 ,30); + LOG_DEBUG("pathlib_movenode_goodnode = 0"); + return false; + } + + // pathlib_showsquare(where, 1 ,30); + + if (pathlib_nodeatpoint(where)) { + LOG_DEBUG("NAP WHERE :", vtos(where)); + LOG_DEBUG("not NAP TO:", vtos(to)); + LOG_DEBUG("NAP-NNAP:", ftos(vlen(to - where))); + return false; + } + + + if (dodge) { + if (!tile_check(parent, where)) { + LOG_DEBUG("tile_check fail"); #if DEBUGPATHING - pathlib_showsquare(where, 0 ,30); + pathlib_showsquare(where, 0, 30); #endif - return false; - } - - - h = pathlib_heuristic(where,goal); - g = pathlib_cost(parent,where,cost); - f = g + h; - - /* - node = findradius(where,pathlib_gridsize * 0.5); - while(node) - { - if(node.is_path_node == true) - { - ++pathlib_merge_cnt; - if(node.owner == openlist) - { - if(node.pathlib_node_g > g) - { - //pathlib_movenode(node, where,node.origin,0); - //if(pathlib_movenode_goodnode) - //{ - //mark_error(node.origin + '0 0 128',30); - node.pathlib_node_h = h; - node.pathlib_node_g = g; - node.pathlib_node_f = f; - node.path_prev = parent; - //} - } - - if (!best_open_node) - best_open_node = node; - else if(best_open_node.pathlib_node_f > node.pathlib_node_f) - best_open_node = node; - } - - return 1; - } - node = node.chain; - } - */ - - node = pathlib_mknode(where, parent); - node.pathlib_node_h = h; - node.pathlib_node_g = g; - node.pathlib_node_f = f; - - if (!best_open_node) - best_open_node = node; - else if(best_open_node.pathlib_node_f > node.pathlib_node_f) - best_open_node = node; - - return true; + return false; + } + } + + + h = pathlib_heuristic(where, goal); + g = pathlib_cost(parent, where, cost); + f = g + h; + + /* + node = findradius(where,pathlib_gridsize * 0.5); + while(node) + { + if(node.is_path_node == true) + { + ++pathlib_merge_cnt; + if(node.owner == openlist) + { + if(node.pathlib_node_g > g) + { + //pathlib_movenode(node, where,node.origin,0); + //if(pathlib_movenode_goodnode) + //{ + //mark_error(node.origin + '0 0 128',30); + node.pathlib_node_h = h; + node.pathlib_node_g = g; + node.pathlib_node_f = f; + node.path_prev = parent; + //} + } + + if (!best_open_node) + best_open_node = node; + else if(best_open_node.pathlib_node_f > node.pathlib_node_f) + best_open_node = node; + } + + return 1; + } + node = node.chain; + } + */ + + node = pathlib_mknode(where, parent); + node.pathlib_node_h = h; + node.pathlib_node_g = g; + node.pathlib_node_f = f; + + if (!best_open_node) { + best_open_node = node; + } else if (best_open_node.pathlib_node_f > node.pathlib_node_f) { + best_open_node = node; + } + + return true; } entity pathlib_getbestopen() { - if(best_open_node) - { - ++pathlib_bestcash_hits; - pathlib_bestcash_saved += pathlib_open_cnt; + if (best_open_node) { + ++pathlib_bestcash_hits; + pathlib_bestcash_saved += pathlib_open_cnt; - return best_open_node; - } + return best_open_node; + } - entity bestnode = NULL; - FOREACH_ENTITY_ENT(owner, openlist, - { - ++pathlib_bestopen_searched; + entity bestnode = NULL; + FOREACH_ENTITY_ENT(owner, openlist, + { + ++pathlib_bestopen_searched; - if(!bestnode || it.pathlib_node_f < bestnode.pathlib_node_f) - bestnode = it; - }); + if (!bestnode || it.pathlib_node_f < bestnode.pathlib_node_f) { + bestnode = it; + } + }); - return bestnode; + return bestnode; } -void pathlib_close_node(entity node,vector goal) +void pathlib_close_node(entity node, vector goal) { - if(node.owner == closedlist) - { - LOG_TRACE("Pathlib: Tried to close a closed node!"); - return; - } - - if(node == best_open_node) - best_open_node = NULL; - - ++pathlib_closed_cnt; - --pathlib_open_cnt; - - node.owner = closedlist; - - if(vdist(node.origin - goal, <=, pathlib_gridsize)) - { - vector goalmove; - - goalmove = pathlib_walknode(node, node.origin, goal, 1); - if(pathlib_movenode_goodnode) - { - goal_node = node; - pathlib_foundgoal = true; - } - } + if (node.owner == closedlist) { + LOG_TRACE("Pathlib: Tried to close a closed node!"); + return; + } + + if (node == best_open_node) { + best_open_node = NULL; + } + + ++pathlib_closed_cnt; + --pathlib_open_cnt; + + node.owner = closedlist; + + if (vdist(node.origin - goal, <=, pathlib_gridsize)) { + vector goalmove; + + goalmove = pathlib_walknode(node, node.origin, goal, 1); + if (pathlib_movenode_goodnode) { + goal_node = node; + pathlib_foundgoal = true; + } + } } void pathlib_cleanup() { - best_open_node = NULL; + best_open_node = NULL; - //return; + // return; - IL_EACH(g_pathlib_nodes, it.is_path_node, - { - dumpnode(it); - }); + IL_EACH(g_pathlib_nodes, it.is_path_node, + { + dumpnode(it); + }); - IL_CLEAR(g_pathlib_nodes); + IL_CLEAR(g_pathlib_nodes); - if(openlist) - delete(openlist); + if (openlist) { + delete(openlist); + } - if(closedlist) - delete(closedlist); + if (closedlist) { + delete(closedlist); + } - openlist = NULL; - closedlist = NULL; + openlist = NULL; + closedlist = NULL; } float Cosine_Interpolate(float a, float b, float c) @@ -293,256 +285,256 @@ float Cosine_Interpolate(float a, float b, float c) float ft = c * 3.1415927; float f = (1 - cos(ft)) * 0.5; - return a*(1-f) + b*f; + return a * (1 - f) + b * f; } -bool buildpath_nodefilter_directional(vector n,vector c,vector p) +bool buildpath_nodefilter_directional(vector n, vector c, vector p) { - vector d2 = normalize(p - c); - vector d1 = normalize(c - n); - - if(vdist(d1 - d2, <, 0.25)) - { - //mark_error(c,30); - return true; - } - //mark_info(c,30); - return false; + vector d2 = normalize(p - c); + vector d1 = normalize(c - n); + + if (vdist(d1 - d2, <, 0.25)) { + // mark_error(c,30); + return true; + } + // mark_info(c,30); + return false; } -bool buildpath_nodefilter_moveskip(entity this, vector n,vector c,vector p) +bool buildpath_nodefilter_moveskip(entity this, vector n, vector c, vector p) { - pathlib_walknode(this, p, n, 1); - if(pathlib_movenode_goodnode) - return true; + pathlib_walknode(this, p, n, 1); + if (pathlib_movenode_goodnode) { + return true; + } - return false; + return false; } -bool buildpath_nodefilter_none(vector n,vector c,vector p) +bool buildpath_nodefilter_none(vector n, vector c, vector p) { - return false; + return false; } entity path_build(entity next, vector where, entity prev, entity start) { - if(prev && next) - if(buildpath_nodefilter) - if(buildpath_nodefilter(next.origin,where,prev.origin)) - return next; - - - entity path = spawn(); - path.owner = start; - path.path_next = next; - - setorigin(path, where); - - if(!next) - path.classname = "path_end"; - else - { - if(!prev) - path.classname = "path_start"; - else - path.classname = "path_node"; - } - - return path; + if (prev && next) { + if (buildpath_nodefilter) { + if (buildpath_nodefilter(next.origin, where, prev.origin)) { + return next; + } + } + } + + + entity path = spawn(); + path.owner = start; + path.path_next = next; + + setorigin(path, where); + + if (!next) { + path.classname = "path_end"; + } else { + if (!prev) { + path.classname = "path_start"; + } else { + path.classname = "path_node"; + } + } + + return path; } entity pathlib_astar(entity this, vector from, vector to) { entity open; - float ptime = gettime(GETTIME_REALTIME); - pathlib_starttime = ptime; + float ptime = gettime(GETTIME_REALTIME); + pathlib_starttime = ptime; - pathlib_cleanup(); + pathlib_cleanup(); - // Select water<->land capable node make/link - pathlib_makenode = pathlib_makenode_adaptive; + // Select water<->land capable node make/link + pathlib_makenode = pathlib_makenode_adaptive; - // Select XYZ cost estimate - //pathlib_heuristic = pathlib_h_diagonal3; - pathlib_heuristic = pathlib_h_diagonal; - - // Select distance + waterfactor cost - pathlib_cost = pathlib_g_euclidean_water; + // Select XYZ cost estimate + // pathlib_heuristic = pathlib_h_diagonal3; + pathlib_heuristic = pathlib_h_diagonal; + + // Select distance + waterfactor cost + pathlib_cost = pathlib_g_euclidean_water; - // Select star expander - pathlib_expandnode = pathlib_expandnode_star; - - // Select walk simulation movement test - pathlib_movenode = pathlib_walknode; - - // Filter final nodes by direction - buildpath_nodefilter = buildpath_nodefilter_directional; - - // Filter tiles with cross pattern - tile_check = tile_check_cross; - - // If the start is in water we need diffrent settings - if(inwater(from)) - { - // Select volumetric node expaner - pathlib_expandnode = pathlib_expandnode_box; - - // Water movement test - pathlib_movenode = pathlib_swimnode; - } - - if (!openlist) - openlist = spawn(); - - if (!closedlist) - closedlist = spawn(); - - pathlib_closed_cnt = 0; - pathlib_open_cnt = 0; - pathlib_made_cnt = 0; - pathlib_merge_cnt = 0; - pathlib_searched_cnt = 0; - pathlib_bestopen_searched = 0; - pathlib_bestcash_hits = 0; - pathlib_bestcash_saved = 0; - - pathlib_gridsize = 128; - pathlib_movecost = pathlib_gridsize; - pathlib_movecost_diag = vlen(('1 1 0' * pathlib_gridsize)); - pathlib_movecost_waterfactor = 25000000; - pathlib_foundgoal = 0; - - movenode_boxmax = this.maxs * 1.1; - movenode_boxmin = this.mins * 1.1; - - movenode_stepsize = pathlib_gridsize * 0.25; - - tile_check_size = pathlib_gridsize * 0.5; - tile_check_up = '0 0 2' * pathlib_gridsize; - tile_check_up = '0 0 128'; - tile_check_down = '0 0 3' * pathlib_gridsize; - tile_check_down = '0 0 256'; - - //movenode_stepup = '0 0 128'; - movenode_stepup = '0 0 36'; - movenode_maxdrop = '0 0 512'; - //movenode_maxdrop = '0 0 512'; - movenode_boxup = '0 0 72'; - - from.x = fsnap(from.x, pathlib_gridsize); - from.y = fsnap(from.y, pathlib_gridsize); - //from.z += 32; - - to.x = fsnap(to.x, pathlib_gridsize); - to.y = fsnap(to.y, pathlib_gridsize); - //to.z += 32; - - LOG_DEBUG("AStar init"); - entity path = pathlib_mknode(from, NULL); - pathlib_close_node(path, to); - if(pathlib_foundgoal) - { - LOG_DEBUG("AStar: Goal found on first node!"); - - open = new(path_end); - open.owner = open; - setorigin(open, path.origin); - - pathlib_cleanup(); - - return open; - } - - if(pathlib_expandnode(path, from, to) <= 0) - { - LOG_TRACE("AStar path fail."); - pathlib_cleanup(); - - return NULL; - } - - best_open_node = pathlib_getbestopen(); - entity n = best_open_node; - pathlib_close_node(best_open_node, to); - if(inwater(n.origin)) - pathlib_expandnode_box(n, from, to); - else - pathlib_expandnode_star(n, from, to); - - while(pathlib_open_cnt) - { - if((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime) - { - LOG_TRACE("Path took too long to compute!"); - LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt)); - LOG_TRACE("Nodes - open: ", ftos(pathlib_open_cnt)); - LOG_TRACE("Nodes - merged: ", ftos(pathlib_merge_cnt)); - LOG_TRACE("Nodes - closed: ", ftos(pathlib_closed_cnt)); - - pathlib_cleanup(); - return NULL; - } - - best_open_node = pathlib_getbestopen(); - n = best_open_node; - pathlib_close_node(best_open_node,to); - - if(inwater(n.origin)) - pathlib_expandnode_box(n,from,to); - else - pathlib_expandnode(n,from,to); - - if(pathlib_foundgoal) - { - LOG_DEBUG("Target found. Rebuilding and filtering path..."); - float ftime = gettime(GETTIME_REALTIME); - ptime = ftime - ptime; - - entity start = path_build(NULL,path.origin,NULL,NULL); - entity end = path_build(NULL,goal_node.origin,NULL,start); - entity ln = end; - - open = goal_node; - for(open = goal_node; open.path_prev != path; open = open.path_prev) - { - n = path_build(ln,open.origin,open.path_prev,start); - ln.path_prev = n; - ln = n; - } - start.path_next = n; - n.path_prev = start; - ftime = gettime(GETTIME_REALTIME) - ftime; - - float ctime = gettime(GETTIME_REALTIME); - pathlib_cleanup(); - ctime = gettime(GETTIME_REALTIME) - ctime; + // Select star expander + pathlib_expandnode = pathlib_expandnode_star; + + // Select walk simulation movement test + pathlib_movenode = pathlib_walknode; + + // Filter final nodes by direction + buildpath_nodefilter = buildpath_nodefilter_directional; + + // Filter tiles with cross pattern + tile_check = tile_check_cross; + + // If the start is in water we need diffrent settings + if (inwater(from)) { + // Select volumetric node expaner + pathlib_expandnode = pathlib_expandnode_box; + + // Water movement test + pathlib_movenode = pathlib_swimnode; + } + + if (!openlist) { + openlist = spawn(); + } + + if (!closedlist) { + closedlist = spawn(); + } + + pathlib_closed_cnt = 0; + pathlib_open_cnt = 0; + pathlib_made_cnt = 0; + pathlib_merge_cnt = 0; + pathlib_searched_cnt = 0; + pathlib_bestopen_searched = 0; + pathlib_bestcash_hits = 0; + pathlib_bestcash_saved = 0; + + pathlib_gridsize = 128; + pathlib_movecost = pathlib_gridsize; + pathlib_movecost_diag = vlen(('1 1 0' * pathlib_gridsize)); + pathlib_movecost_waterfactor = 25000000; + pathlib_foundgoal = 0; + + movenode_boxmax = this.maxs * 1.1; + movenode_boxmin = this.mins * 1.1; + + movenode_stepsize = pathlib_gridsize * 0.25; + + tile_check_size = pathlib_gridsize * 0.5; + tile_check_up = '0 0 2' * pathlib_gridsize; + tile_check_up = '0 0 128'; + tile_check_down = '0 0 3' * pathlib_gridsize; + tile_check_down = '0 0 256'; + + // movenode_stepup = '0 0 128'; + movenode_stepup = '0 0 36'; + movenode_maxdrop = '0 0 512'; + // movenode_maxdrop = '0 0 512'; + movenode_boxup = '0 0 72'; + + from.x = fsnap(from.x, pathlib_gridsize); + from.y = fsnap(from.y, pathlib_gridsize); + // from.z += 32; + + to.x = fsnap(to.x, pathlib_gridsize); + to.y = fsnap(to.y, pathlib_gridsize); + // to.z += 32; + + LOG_DEBUG("AStar init"); + entity path = pathlib_mknode(from, NULL); + pathlib_close_node(path, to); + if (pathlib_foundgoal) { + LOG_DEBUG("AStar: Goal found on first node!"); + + open = new(path_end); + open.owner = open; + setorigin(open, path.origin); + + pathlib_cleanup(); + + return open; + } + + if (pathlib_expandnode(path, from, to) <= 0) { + LOG_TRACE("AStar path fail."); + pathlib_cleanup(); + + return NULL; + } + + best_open_node = pathlib_getbestopen(); + entity n = best_open_node; + pathlib_close_node(best_open_node, to); + if (inwater(n.origin)) { + pathlib_expandnode_box(n, from, to); + } else { + pathlib_expandnode_star(n, from, to); + } + + while (pathlib_open_cnt) { + if ((gettime(GETTIME_REALTIME) - pathlib_starttime) > pathlib_maxtime) { + LOG_TRACE("Path took too long to compute!"); + LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt)); + LOG_TRACE("Nodes - open: ", ftos(pathlib_open_cnt)); + LOG_TRACE("Nodes - merged: ", ftos(pathlib_merge_cnt)); + LOG_TRACE("Nodes - closed: ", ftos(pathlib_closed_cnt)); + + pathlib_cleanup(); + return NULL; + } + + best_open_node = pathlib_getbestopen(); + n = best_open_node; + pathlib_close_node(best_open_node, to); + + if (inwater(n.origin)) { + pathlib_expandnode_box(n, from, to); + } else { + pathlib_expandnode(n, from, to); + } + + if (pathlib_foundgoal) { + LOG_DEBUG("Target found. Rebuilding and filtering path..."); + float ftime = gettime(GETTIME_REALTIME); + ptime = ftime - ptime; + + entity start = path_build(NULL, path.origin, NULL, NULL); + entity end = path_build(NULL, goal_node.origin, NULL, start); + entity ln = end; + + open = goal_node; + for (open = goal_node; open.path_prev != path; open = open.path_prev) { + n = path_build(ln, open.origin, open.path_prev, start); + ln.path_prev = n; + ln = n; + } + start.path_next = n; + n.path_prev = start; + ftime = gettime(GETTIME_REALTIME) - ftime; + + float ctime = gettime(GETTIME_REALTIME); + pathlib_cleanup(); + ctime = gettime(GETTIME_REALTIME) - ctime; #if DEBUGPATHING - pathlib_showpath2(start); - - LOG_TRACE("Time used - pathfinding: ", ftos(ptime)); - LOG_TRACE("Time used - rebuild & filter: ", ftos(ftime)); - LOG_TRACE("Time used - cleanup: ", ftos(ctime)); - LOG_TRACE("Time used - total: ", ftos(ptime + ftime + ctime)); - LOG_TRACE("Time used - # frames: ", ftos(ceil((ptime + ftime + ctime) / sys_frametime))); - LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt)); - LOG_TRACE("Nodes - open: ", ftos(pathlib_open_cnt)); - LOG_TRACE("Nodes - merged: ", ftos(pathlib_merge_cnt)); - LOG_TRACE("Nodes - closed: ", ftos(pathlib_closed_cnt)); - LOG_TRACE("Nodes - searched: ", ftos(pathlib_searched_cnt)); - LOG_TRACE("Nodes bestopen searched: ", ftos(pathlib_bestopen_searched)); - LOG_TRACE("Nodes bestcash - hits: ", ftos(pathlib_bestcash_hits)); - LOG_TRACE("Nodes bestcash - save: ", ftos(pathlib_bestcash_saved)); - LOG_TRACE("AStar done."); + pathlib_showpath2(start); + + LOG_TRACE("Time used - pathfinding: ", ftos(ptime)); + LOG_TRACE("Time used - rebuild & filter: ", ftos(ftime)); + LOG_TRACE("Time used - cleanup: ", ftos(ctime)); + LOG_TRACE("Time used - total: ", ftos(ptime + ftime + ctime)); + LOG_TRACE("Time used - # frames: ", ftos(ceil((ptime + ftime + ctime) / sys_frametime))); + LOG_TRACE("Nodes - created: ", ftos(pathlib_made_cnt)); + LOG_TRACE("Nodes - open: ", ftos(pathlib_open_cnt)); + LOG_TRACE("Nodes - merged: ", ftos(pathlib_merge_cnt)); + LOG_TRACE("Nodes - closed: ", ftos(pathlib_closed_cnt)); + LOG_TRACE("Nodes - searched: ", ftos(pathlib_searched_cnt)); + LOG_TRACE("Nodes bestopen searched: ", ftos(pathlib_bestopen_searched)); + LOG_TRACE("Nodes bestcash - hits: ", ftos(pathlib_bestcash_hits)); + LOG_TRACE("Nodes bestcash - save: ", ftos(pathlib_bestcash_saved)); + LOG_TRACE("AStar done."); #endif - return start; - } - } + return start; + } + } - LOG_TRACE("A* Faild to find a path! Try a smaller gridsize."); + LOG_TRACE("A* Faild to find a path! Try a smaller gridsize."); - pathlib_cleanup(); + pathlib_cleanup(); - return NULL; + return NULL; } diff --git a/qcsrc/server/pathlib/main.qh b/qcsrc/server/pathlib/main.qh index c867080dd..c6fee1f26 100644 --- a/qcsrc/server/pathlib/main.qh +++ b/qcsrc/server/pathlib/main.qh @@ -1,4 +1,4 @@ #pragma once -bool buildpath_nodefilter_none(vector n,vector c,vector p); +bool buildpath_nodefilter_none(vector n, vector c, vector p); entity path_build(entity next, vector where, entity prev, entity start); diff --git a/qcsrc/server/pathlib/movenode.qc b/qcsrc/server/pathlib/movenode.qc index cbcfe3d4c..188fa23b4 100644 --- a/qcsrc/server/pathlib/movenode.qc +++ b/qcsrc/server/pathlib/movenode.qc @@ -5,154 +5,164 @@ #include "pathlib.qh" #include "utility.qh" -.vector pos1, pos2; +.vector pos1, pos2; vector pathlib_wateroutnode(entity this, vector start, vector end, float doedge) { - vector surface; + vector surface; - pathlib_movenode_goodnode = false; + pathlib_movenode_goodnode = false; - end.x = fsnap(end.x, pathlib_gridsize); - end.y = fsnap(end.y, pathlib_gridsize); + end.x = fsnap(end.x, pathlib_gridsize); + end.y = fsnap(end.y, pathlib_gridsize); - traceline(end + ('0 0 0.25' * pathlib_gridsize),end - ('0 0 1' * pathlib_gridsize),MOVE_WORLDONLY,this); - end = trace_endpos; + traceline(end + ('0 0 0.25' * pathlib_gridsize), end - ('0 0 1' * pathlib_gridsize), MOVE_WORLDONLY, this); + end = trace_endpos; - if (!(pointcontents(end - '0 0 1') == CONTENT_SOLID)) - return end; + if (!(pointcontents(end - '0 0 1') == CONTENT_SOLID)) { + return end; + } - for(surface = start ; surface.z < (end.z + 32); ++surface.z) - { - if(pointcontents(surface) == CONTENT_EMPTY) - break; - } + for (surface = start; surface.z < (end.z + 32); ++surface.z) { + if (pointcontents(surface) == CONTENT_EMPTY) { + break; + } + } - if(pointcontents(surface + '0 0 1') != CONTENT_EMPTY) - return end; + if (pointcontents(surface + '0 0 1') != CONTENT_EMPTY) { + return end; + } - tracebox(start + '0 0 64', movenode_boxmin,movenode_boxmax, end + '0 0 64', MOVE_WORLDONLY, this); - if(trace_fraction == 1) - pathlib_movenode_goodnode = true; + tracebox(start + '0 0 64', movenode_boxmin, movenode_boxmax, end + '0 0 64', MOVE_WORLDONLY, this); + if (trace_fraction == 1) { + pathlib_movenode_goodnode = true; + } - if(fabs(surface.z - end.z) > 32) - pathlib_movenode_goodnode = false; + if (fabs(surface.z - end.z) > 32) { + pathlib_movenode_goodnode = false; + } - return end; + return end; } vector pathlib_swimnode(entity this, vector start, vector end, float doedge) { - pathlib_movenode_goodnode = false; + pathlib_movenode_goodnode = false; - if(pointcontents(start) != CONTENT_WATER) - return end; + if (pointcontents(start) != CONTENT_WATER) { + return end; + } - end.x = fsnap(end.x, pathlib_gridsize); - end.y = fsnap(end.y, pathlib_gridsize); + end.x = fsnap(end.x, pathlib_gridsize); + end.y = fsnap(end.y, pathlib_gridsize); - if(pointcontents(end) == CONTENT_EMPTY) - return pathlib_wateroutnode(this, start, end, doedge); + if (pointcontents(end) == CONTENT_EMPTY) { + return pathlib_wateroutnode(this, start, end, doedge); + } - tracebox(start, movenode_boxmin,movenode_boxmax, end, MOVE_WORLDONLY, this); - if(trace_fraction == 1) - pathlib_movenode_goodnode = true; + tracebox(start, movenode_boxmin, movenode_boxmax, end, MOVE_WORLDONLY, this); + if (trace_fraction == 1) { + pathlib_movenode_goodnode = true; + } - return end; + return end; } vector pathlib_flynode(entity this, vector start, vector end, float doedge) { - pathlib_movenode_goodnode = false; + pathlib_movenode_goodnode = false; - end.x = fsnap(end.x, pathlib_gridsize); - end.y = fsnap(end.y, pathlib_gridsize); + end.x = fsnap(end.x, pathlib_gridsize); + end.y = fsnap(end.y, pathlib_gridsize); - tracebox(start, movenode_boxmin,movenode_boxmax, end, MOVE_WORLDONLY, this); - if(trace_fraction == 1) - pathlib_movenode_goodnode = true; + tracebox(start, movenode_boxmin, movenode_boxmax, end, MOVE_WORLDONLY, this); + if (trace_fraction == 1) { + pathlib_movenode_goodnode = true; + } - return end; + return end; } void a_think(entity this) { - te_lightning1(this,this.origin, this.pos1); - if(this.cnt < time) - delete(this); - else - this.nextthink = time + 0.2; + te_lightning1(this, this.origin, this.pos1); + if (this.cnt < time) { + delete(this); + } else { + this.nextthink = time + 0.2; + } } vector pathlib_walknode(entity this, vector start, vector end, float doedge) { - vector point; - - LOG_DEBUG("Walking node from ", vtos(start), " to ", vtos(end)); - - pathlib_movenode_goodnode = false; - - end.x = fsnap(end.x,pathlib_gridsize); - end.y = fsnap(end.y,pathlib_gridsize); - start.x = fsnap(start.x,pathlib_gridsize); - start.y = fsnap(start.y,pathlib_gridsize); - - // Find the floor - traceline(start + movenode_stepup, start - movenode_maxdrop, MOVE_WORLDONLY, this); - if(trace_fraction == 1.0) - { - entity a; - a = spawn(); - setthink(a, a_think); - a.nextthink = time; - setorigin(a, start + movenode_stepup); - a.pos1 = trace_endpos; - //start - movenode_maxdrop - a.cnt = time + 10; - - LOG_TRACE("I cant walk on air!"); - return trace_endpos; - } - - start = trace_endpos; - - // Find the direcion, without Z - vector s = start; - vector e = end; - //e_z = 0; s_z = 0; - vector direction = normalize(e - s); - - float distance = vlen(start - end); - int steps = rint(distance / movenode_stepsize); - - vector last_point = start; - for(int i = 1; i < steps; ++i) - { - point = last_point + (direction * movenode_stepsize); - traceline(point + movenode_stepup,point - movenode_maxdrop,MOVE_WORLDONLY,this); - if(trace_fraction == 1.0) - return trace_endpos; - - last_point = trace_endpos; - } - - point = last_point + (direction * movenode_stepsize); - point.x = fsnap(point.x,pathlib_gridsize); - point.y = fsnap(point.y,pathlib_gridsize); - - //dprint("end_x: ",ftos(end_x), " end_y: ",ftos(end_y),"\n"); - //dprint("point_x:",ftos(point_x)," point_y:",ftos(point_y),"\n\n"); - - traceline(point + movenode_stepup, point - movenode_maxdrop,MOVE_WORLDONLY,this); - if(trace_fraction == 1.0) - return trace_endpos; - - last_point = trace_endpos; - - tracebox(start + movenode_boxup, movenode_boxmin,movenode_boxmax, last_point + movenode_boxup, MOVE_WORLDONLY, this); - if(trace_fraction != 1.0) - return trace_endpos; - - pathlib_movenode_goodnode = true; - return last_point; + vector point; + + LOG_DEBUG("Walking node from ", vtos(start), " to ", vtos(end)); + + pathlib_movenode_goodnode = false; + + end.x = fsnap(end.x, pathlib_gridsize); + end.y = fsnap(end.y, pathlib_gridsize); + start.x = fsnap(start.x, pathlib_gridsize); + start.y = fsnap(start.y, pathlib_gridsize); + + // Find the floor + traceline(start + movenode_stepup, start - movenode_maxdrop, MOVE_WORLDONLY, this); + if (trace_fraction == 1.0) { + entity a; + a = spawn(); + setthink(a, a_think); + a.nextthink = time; + setorigin(a, start + movenode_stepup); + a.pos1 = trace_endpos; + // start - movenode_maxdrop + a.cnt = time + 10; + + LOG_TRACE("I cant walk on air!"); + return trace_endpos; + } + + start = trace_endpos; + + // Find the direcion, without Z + vector s = start; + vector e = end; + // e_z = 0; s_z = 0; + vector direction = normalize(e - s); + + float distance = vlen(start - end); + int steps = rint(distance / movenode_stepsize); + + vector last_point = start; + for (int i = 1; i < steps; ++i) { + point = last_point + (direction * movenode_stepsize); + traceline(point + movenode_stepup, point - movenode_maxdrop, MOVE_WORLDONLY, this); + if (trace_fraction == 1.0) { + return trace_endpos; + } + + last_point = trace_endpos; + } + + point = last_point + (direction * movenode_stepsize); + point.x = fsnap(point.x, pathlib_gridsize); + point.y = fsnap(point.y, pathlib_gridsize); + + // dprint("end_x: ",ftos(end_x), " end_y: ",ftos(end_y),"\n"); + // dprint("point_x:",ftos(point_x)," point_y:",ftos(point_y),"\n\n"); + + traceline(point + movenode_stepup, point - movenode_maxdrop, MOVE_WORLDONLY, this); + if (trace_fraction == 1.0) { + return trace_endpos; + } + + last_point = trace_endpos; + + tracebox(start + movenode_boxup, movenode_boxmin, movenode_boxmax, last_point + movenode_boxup, MOVE_WORLDONLY, this); + if (trace_fraction != 1.0) { + return trace_endpos; + } + + pathlib_movenode_goodnode = true; + return last_point; } diff --git a/qcsrc/server/pathlib/path_waypoint.qc b/qcsrc/server/pathlib/path_waypoint.qc index 906ebc7a5..63760db47 100644 --- a/qcsrc/server/pathlib/path_waypoint.qc +++ b/qcsrc/server/pathlib/path_waypoint.qc @@ -8,237 +8,245 @@ var float pathlib_wpp_open(entity wp, entity child, float cost); void pathlib_wpp_close(entity wp) { - --pathlib_open_cnt; - ++pathlib_closed_cnt; + --pathlib_open_cnt; + ++pathlib_closed_cnt; - wp.pathlib_list = closedlist; + wp.pathlib_list = closedlist; - if(wp == best_open_node) - best_open_node = NULL; + if (wp == best_open_node) { + best_open_node = NULL; + } - if(wp == goal_node) - pathlib_foundgoal = true; + if (wp == goal_node) { + pathlib_foundgoal = true; + } } float pathlib_wpp_opencb(entity wp, entity child, float cost) { - - if(child.pathlib_list == closedlist) - return false; + if (child.pathlib_list == closedlist) { + return false; + } // FIXME! wp.wp##mincost is NOT distance. Make it distance or add a field for distance to be used here (for better speed) cost = vlen(child.origin - wp.origin); - child.path_prev = wp; - child.pathlib_list = openlist; - child.pathlib_node_g = wp.pathlib_node_g + cost; - child.pathlib_node_h = pathlib_heuristic(child.origin, goal_node.origin); - child.pathlib_node_c = pathlib_wpp_waypointcallback(child, wp); - child.pathlib_node_f = child.pathlib_node_g + child.pathlib_node_h + child.pathlib_node_c; + child.path_prev = wp; + child.pathlib_list = openlist; + child.pathlib_node_g = wp.pathlib_node_g + cost; + child.pathlib_node_h = pathlib_heuristic(child.origin, goal_node.origin); + child.pathlib_node_c = pathlib_wpp_waypointcallback(child, wp); + child.pathlib_node_f = child.pathlib_node_g + child.pathlib_node_h + child.pathlib_node_c; - if(child == goal_node) - pathlib_foundgoal = true; + if (child == goal_node) { + pathlib_foundgoal = true; + } - ++pathlib_open_cnt; + ++pathlib_open_cnt; - if(best_open_node.pathlib_node_f > child.pathlib_node_f) - best_open_node = child; + if (best_open_node.pathlib_node_f > child.pathlib_node_f) { + best_open_node = child; + } - return true; + return true; } float pathlib_wpp_openncb(entity wp, entity child, float cost) { - - if(child.pathlib_list == closedlist) - return false; + if (child.pathlib_list == closedlist) { + return false; + } // FIXME! wp.wp##mincost is NOT distance. Make it distance or add a field for distance to be used here (for better speed) cost = vlen(child.origin - wp.origin); - child.path_prev = wp; - child.pathlib_list = openlist; - child.pathlib_node_g = wp.pathlib_node_g + cost; - child.pathlib_node_h = pathlib_heuristic(child.origin, goal_node.origin); - child.pathlib_node_f = child.pathlib_node_g + child.pathlib_node_h; + child.path_prev = wp; + child.pathlib_list = openlist; + child.pathlib_node_g = wp.pathlib_node_g + cost; + child.pathlib_node_h = pathlib_heuristic(child.origin, goal_node.origin); + child.pathlib_node_f = child.pathlib_node_g + child.pathlib_node_h; - if(child == goal_node) - pathlib_foundgoal = true; + if (child == goal_node) { + pathlib_foundgoal = true; + } - ++pathlib_open_cnt; + ++pathlib_open_cnt; - if(best_open_node.pathlib_node_f > child.pathlib_node_f) - best_open_node = child; + if (best_open_node.pathlib_node_f > child.pathlib_node_f) { + best_open_node = child; + } - return true; + return true; } float pathlib_wpp_expand(entity wp) { - if(wp.wp00) pathlib_wpp_open(wp,wp.wp00,wp.wp00mincost); else return 0; - if(wp.wp01) pathlib_wpp_open(wp,wp.wp01,wp.wp01mincost); else return 1; - if(wp.wp02) pathlib_wpp_open(wp,wp.wp02,wp.wp02mincost); else return 2; - if(wp.wp03) pathlib_wpp_open(wp,wp.wp03,wp.wp03mincost); else return 3; - if(wp.wp04) pathlib_wpp_open(wp,wp.wp04,wp.wp04mincost); else return 4; - if(wp.wp05) pathlib_wpp_open(wp,wp.wp05,wp.wp05mincost); else return 5; - if(wp.wp06) pathlib_wpp_open(wp,wp.wp06,wp.wp06mincost); else return 6; - if(wp.wp07) pathlib_wpp_open(wp,wp.wp07,wp.wp07mincost); else return 7; - if(wp.wp08) pathlib_wpp_open(wp,wp.wp08,wp.wp08mincost); else return 8; - if(wp.wp09) pathlib_wpp_open(wp,wp.wp09,wp.wp09mincost); else return 9; - if(wp.wp10) pathlib_wpp_open(wp,wp.wp10,wp.wp10mincost); else return 10; - if(wp.wp11) pathlib_wpp_open(wp,wp.wp11,wp.wp11mincost); else return 11; - if(wp.wp12) pathlib_wpp_open(wp,wp.wp12,wp.wp12mincost); else return 12; - if(wp.wp13) pathlib_wpp_open(wp,wp.wp13,wp.wp13mincost); else return 13; - if(wp.wp14) pathlib_wpp_open(wp,wp.wp14,wp.wp14mincost); else return 14; - if(wp.wp15) pathlib_wpp_open(wp,wp.wp15,wp.wp15mincost); else return 15; - if(wp.wp16) pathlib_wpp_open(wp,wp.wp16,wp.wp16mincost); else return 16; - if(wp.wp17) pathlib_wpp_open(wp,wp.wp17,wp.wp17mincost); else return 17; - if(wp.wp18) pathlib_wpp_open(wp,wp.wp18,wp.wp18mincost); else return 18; - if(wp.wp19) pathlib_wpp_open(wp,wp.wp19,wp.wp19mincost); else return 19; - if(wp.wp20) pathlib_wpp_open(wp,wp.wp20,wp.wp20mincost); else return 20; - if(wp.wp21) pathlib_wpp_open(wp,wp.wp21,wp.wp21mincost); else return 21; - if(wp.wp22) pathlib_wpp_open(wp,wp.wp22,wp.wp22mincost); else return 22; - if(wp.wp23) pathlib_wpp_open(wp,wp.wp23,wp.wp23mincost); else return 23; - if(wp.wp24) pathlib_wpp_open(wp,wp.wp24,wp.wp24mincost); else return 24; - if(wp.wp25) pathlib_wpp_open(wp,wp.wp25,wp.wp25mincost); else return 25; - if(wp.wp26) pathlib_wpp_open(wp,wp.wp26,wp.wp26mincost); else return 26; - if(wp.wp27) pathlib_wpp_open(wp,wp.wp27,wp.wp27mincost); else return 27; - if(wp.wp28) pathlib_wpp_open(wp,wp.wp28,wp.wp28mincost); else return 28; - if(wp.wp29) pathlib_wpp_open(wp,wp.wp29,wp.wp29mincost); else return 29; - if(wp.wp30) pathlib_wpp_open(wp,wp.wp30,wp.wp30mincost); else return 30; - if(wp.wp31) pathlib_wpp_open(wp,wp.wp31,wp.wp31mincost); else return 31; - - return 32; + if (wp.wp00) { pathlib_wpp_open(wp, wp.wp00, wp.wp00mincost); } else { return 0; } + if (wp.wp01) { pathlib_wpp_open(wp, wp.wp01, wp.wp01mincost); } else { return 1; } + if (wp.wp02) { pathlib_wpp_open(wp, wp.wp02, wp.wp02mincost); } else { return 2; } + if (wp.wp03) { pathlib_wpp_open(wp, wp.wp03, wp.wp03mincost); } else { return 3; } + if (wp.wp04) { pathlib_wpp_open(wp, wp.wp04, wp.wp04mincost); } else { return 4; } + if (wp.wp05) { pathlib_wpp_open(wp, wp.wp05, wp.wp05mincost); } else { return 5; } + if (wp.wp06) { pathlib_wpp_open(wp, wp.wp06, wp.wp06mincost); } else { return 6; } + if (wp.wp07) { pathlib_wpp_open(wp, wp.wp07, wp.wp07mincost); } else { return 7; } + if (wp.wp08) { pathlib_wpp_open(wp, wp.wp08, wp.wp08mincost); } else { return 8; } + if (wp.wp09) { pathlib_wpp_open(wp, wp.wp09, wp.wp09mincost); } else { return 9; } + if (wp.wp10) { pathlib_wpp_open(wp, wp.wp10, wp.wp10mincost); } else { return 10; } + if (wp.wp11) { pathlib_wpp_open(wp, wp.wp11, wp.wp11mincost); } else { return 11; } + if (wp.wp12) { pathlib_wpp_open(wp, wp.wp12, wp.wp12mincost); } else { return 12; } + if (wp.wp13) { pathlib_wpp_open(wp, wp.wp13, wp.wp13mincost); } else { return 13; } + if (wp.wp14) { pathlib_wpp_open(wp, wp.wp14, wp.wp14mincost); } else { return 14; } + if (wp.wp15) { pathlib_wpp_open(wp, wp.wp15, wp.wp15mincost); } else { return 15; } + if (wp.wp16) { pathlib_wpp_open(wp, wp.wp16, wp.wp16mincost); } else { return 16; } + if (wp.wp17) { pathlib_wpp_open(wp, wp.wp17, wp.wp17mincost); } else { return 17; } + if (wp.wp18) { pathlib_wpp_open(wp, wp.wp18, wp.wp18mincost); } else { return 18; } + if (wp.wp19) { pathlib_wpp_open(wp, wp.wp19, wp.wp19mincost); } else { return 19; } + if (wp.wp20) { pathlib_wpp_open(wp, wp.wp20, wp.wp20mincost); } else { return 20; } + if (wp.wp21) { pathlib_wpp_open(wp, wp.wp21, wp.wp21mincost); } else { return 21; } + if (wp.wp22) { pathlib_wpp_open(wp, wp.wp22, wp.wp22mincost); } else { return 22; } + if (wp.wp23) { pathlib_wpp_open(wp, wp.wp23, wp.wp23mincost); } else { return 23; } + if (wp.wp24) { pathlib_wpp_open(wp, wp.wp24, wp.wp24mincost); } else { return 24; } + if (wp.wp25) { pathlib_wpp_open(wp, wp.wp25, wp.wp25mincost); } else { return 25; } + if (wp.wp26) { pathlib_wpp_open(wp, wp.wp26, wp.wp26mincost); } else { return 26; } + if (wp.wp27) { pathlib_wpp_open(wp, wp.wp27, wp.wp27mincost); } else { return 27; } + if (wp.wp28) { pathlib_wpp_open(wp, wp.wp28, wp.wp28mincost); } else { return 28; } + if (wp.wp29) { pathlib_wpp_open(wp, wp.wp29, wp.wp29mincost); } else { return 29; } + if (wp.wp30) { pathlib_wpp_open(wp, wp.wp30, wp.wp30mincost); } else { return 30; } + if (wp.wp31) { pathlib_wpp_open(wp, wp.wp31, wp.wp31mincost); } else { return 31; } + + return 32; } entity pathlib_wpp_bestopen() { - if(best_open_node) - return best_open_node; + if (best_open_node) { + return best_open_node; + } - entity best = NULL; + entity best = NULL; - FOREACH_ENTITY_ENT(pathlib_list, openlist, - { - if(!best || it.pathlib_node_f < best.pathlib_node_f) - best = it; - }); - - return best; + FOREACH_ENTITY_ENT(pathlib_list, openlist, + { + if (!best || it.pathlib_node_f < best.pathlib_node_f) { + best = it; + } + }); + return best; } entity pathlib_waypointpath(entity wp_from, entity wp_to, float callback) { - float ptime; + float ptime; - ptime = gettime(GETTIME_REALTIME); - pathlib_starttime = ptime; - pathlib_movecost = 300; - pathlib_movecost_diag = vlen('1 1 0' * pathlib_movecost); + ptime = gettime(GETTIME_REALTIME); + pathlib_starttime = ptime; + pathlib_movecost = 300; + pathlib_movecost_diag = vlen('1 1 0' * pathlib_movecost); - if (!pathlib_wpp_waypointcallback) + if (!pathlib_wpp_waypointcallback) { callback = false; + } - if (callback) + if (callback) { pathlib_wpp_open = pathlib_wpp_opencb; - else + } else { pathlib_wpp_open = pathlib_wpp_openncb; + } pathlib_heuristic = pathlib_h_none; - if (!openlist) - openlist = spawn(); - - if (!closedlist) - closedlist = spawn(); - - pathlib_closed_cnt = 0; - pathlib_open_cnt = 0; - pathlib_searched_cnt = 0; - pathlib_foundgoal = false; - - LOG_TRACE("pathlib_waypointpath init"); - - // Initialize waypoint grid - IL_EACH(g_waypoints, true, - { - it.pathlib_list = NULL; - it.pathlib_node_g = 0; - it.pathlib_node_f = 0; - it.pathlib_node_h = 0; - - //setmodel(it, "models/runematch/rune.mdl"); - //it.effects = EF_LOWPRECISION; - //it.colormod = '0 0 0'; - //it.scale = 1; - }); - - goal_node = wp_to; - start_node = wp_from; - - start_node.pathlib_list = closedlist; - LOG_TRACE("Expanding ",ftos(pathlib_wpp_expand(start_node))," links"); - if(pathlib_open_cnt <= 0) - { - LOG_TRACE("pathlib_waypointpath: Start waypoint not linked! aborting."); - return NULL; - } - - return NULL; + if (!openlist) { + openlist = spawn(); + } + + if (!closedlist) { + closedlist = spawn(); + } + + pathlib_closed_cnt = 0; + pathlib_open_cnt = 0; + pathlib_searched_cnt = 0; + pathlib_foundgoal = false; + + LOG_TRACE("pathlib_waypointpath init"); + + // Initialize waypoint grid + IL_EACH(g_waypoints, true, + { + it.pathlib_list = NULL; + it.pathlib_node_g = 0; + it.pathlib_node_f = 0; + it.pathlib_node_h = 0; + + // setmodel(it, "models/runematch/rune.mdl"); + // it.effects = EF_LOWPRECISION; + // it.colormod = '0 0 0'; + // it.scale = 1; + }); + + goal_node = wp_to; + start_node = wp_from; + + start_node.pathlib_list = closedlist; + LOG_TRACE("Expanding ", ftos(pathlib_wpp_expand(start_node)), " links"); + if (pathlib_open_cnt <= 0) { + LOG_TRACE("pathlib_waypointpath: Start waypoint not linked! aborting."); + return NULL; + } + + return NULL; } entity pathlib_waypointpath_step() { - entity n; + entity n; - n = pathlib_wpp_bestopen(); - if(!n) - { - LOG_TRACE("Cannot find best open node, abort."); - return NULL; - } - pathlib_wpp_close(n); - LOG_TRACE("Expanding ",ftos(pathlib_wpp_expand(n))," links"); + n = pathlib_wpp_bestopen(); + if (!n) { + LOG_TRACE("Cannot find best open node, abort."); + return NULL; + } + pathlib_wpp_close(n); + LOG_TRACE("Expanding ", ftos(pathlib_wpp_expand(n)), " links"); - if(pathlib_foundgoal) - { - entity start, end, open, ln; + if (pathlib_foundgoal) { + entity start, end, open, ln; - LOG_TRACE("Target found. Rebuilding and filtering path..."); + LOG_TRACE("Target found. Rebuilding and filtering path..."); buildpath_nodefilter = buildpath_nodefilter_none; start = path_build(NULL, start_node.origin, NULL, NULL); end = path_build(NULL, goal_node.origin, NULL, start); ln = end; - for(open = goal_node; open.path_prev != start_node; open = open.path_prev) - { - n = path_build(ln,open.origin,open.path_prev,start); + for (open = goal_node; open.path_prev != start_node; open = open.path_prev) { + n = path_build(ln, open.origin, open.path_prev, start); ln.path_prev = n; ln = n; } start.path_next = n; n.path_prev = start; - return start; - } + return start; + } - return NULL; + return NULL; } void plas_think(entity this) { - pathlib_waypointpath_step(); - if(pathlib_foundgoal) - return; - this.nextthink = time + 0.1; + pathlib_waypointpath_step(); + if (pathlib_foundgoal) { + return; + } + this.nextthink = time + 0.1; } void pathlib_waypointpath_autostep() { - entity n; - n = spawn(); - setthink(n, plas_think); - n.nextthink = time + 0.1; + entity n; + n = spawn(); + setthink(n, plas_think); + n.nextthink = time + 0.1; } diff --git a/qcsrc/server/pathlib/pathlib.qh b/qcsrc/server/pathlib/pathlib.qh index 21ef8b3cb..b96c0ac48 100644 --- a/qcsrc/server/pathlib/pathlib.qh +++ b/qcsrc/server/pathlib/pathlib.qh @@ -11,9 +11,9 @@ #define inwater(point) (pointcontents(point) == CONTENT_WATER) const vector PLIB_FORWARD = '0 1 0'; -//#define PLIB_BACK '0 -1 0' +// #define PLIB_BACK '0 -1 0' const vector PLIB_RIGHT = '1 0 0'; -//#define PLIB_LEFT '-1 0 0' +// #define PLIB_LEFT '-1 0 0' #if DEBUGPATHING void pathlib_showpath(entity start); @@ -32,16 +32,16 @@ entity start_node; .float pathlib_node_f; .float pathlib_node_c; -const float pathlib_node_edgeflag_unknown = 0; -const float pathlib_node_edgeflag_left = BIT(1); -const float pathlib_node_edgeflag_right = BIT(2); -const float pathlib_node_edgeflag_forward = BIT(3); -const float pathlib_node_edgeflag_back = BIT(4); -const float pathlib_node_edgeflag_backleft = BIT(5); -const float pathlib_node_edgeflag_backright = BIT(6); -const float pathlib_node_edgeflag_forwardleft = BIT(7); -const float pathlib_node_edgeflag_forwardright = BIT(8); -const float pathlib_node_edgeflag_none = BIT(9); +const float pathlib_node_edgeflag_unknown = 0; +const float pathlib_node_edgeflag_left = BIT(1); +const float pathlib_node_edgeflag_right = BIT(2); +const float pathlib_node_edgeflag_forward = BIT(3); +const float pathlib_node_edgeflag_back = BIT(4); +const float pathlib_node_edgeflag_backleft = BIT(5); +const float pathlib_node_edgeflag_backright = BIT(6); +const float pathlib_node_edgeflag_forwardleft = BIT(7); +const float pathlib_node_edgeflag_forwardright = BIT(8); +const float pathlib_node_edgeflag_none = BIT(9); .float pathlib_node_edgeflags; float pathlib_open_cnt; @@ -98,14 +98,14 @@ var float pathlib_cost(entity parent, vector to, float static_cost); float pathlib_h_manhattan(vector a, vector b); float pathlib_h_diagonal(vector a, vector b); -float pathlib_h_euclidean(vector a,vector b); +float pathlib_h_euclidean(vector a, vector b); float pathlib_h_diagonal2(vector a, vector b); float pathlib_h_diagonal3(vector a, vector b); float pathlib_h_diagonal2sdp(vector preprev, vector prev, vector point, vector end); float pathlib_h_none(vector preprev, vector prev) { return 0; } var float pathlib_heuristic(vector from, vector to); -var bool pathlib_makenode(entity parent,vector start, vector to, vector goal,float cost); -var bool buildpath_nodefilter(vector n,vector c,vector p); +var bool pathlib_makenode(entity parent, vector start, vector to, vector goal, float cost); +var bool buildpath_nodefilter(vector n, vector c, vector p); var float pathlib_wpp_waypointcallback(entity wp, entity wp_prev); diff --git a/qcsrc/server/pathlib/utility.qc b/qcsrc/server/pathlib/utility.qc index 151fb44b5..4578fed7e 100644 --- a/qcsrc/server/pathlib/utility.qc +++ b/qcsrc/server/pathlib/utility.qc @@ -6,208 +6,214 @@ bool location_isok(vector point, bool waterok, bool air_isok) { - if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) - return false; - - int pc = pointcontents(point); - int pc2 = pointcontents(point - '0 0 1'); - - if(pc == CONTENT_EMPTY && pc2 == CONTENT_SOLID) - return true; - if(pc == CONTENT_EMPTY && pc2 == CONTENT_WATER && waterok) - return true; - if(pc == CONTENT_EMPTY && pc2 == CONTENT_EMPTY && air_isok) - return true; - if(pc == CONTENT_WATER && waterok) - return true; - return false; + if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) { + return false; + } + + int pc = pointcontents(point); + int pc2 = pointcontents(point - '0 0 1'); + + if (pc == CONTENT_EMPTY && pc2 == CONTENT_SOLID) { + return true; + } + if (pc == CONTENT_EMPTY && pc2 == CONTENT_WATER && waterok) { + return true; + } + if (pc == CONTENT_EMPTY && pc2 == CONTENT_EMPTY && air_isok) { + return true; + } + if (pc == CONTENT_WATER && waterok) { + return true; + } + return false; } entity pathlib_nodeatpoint(vector where) { - ++pathlib_searched_cnt; + ++pathlib_searched_cnt; - where.x = fsnap(where.x,pathlib_gridsize); - where.y = fsnap(where.y,pathlib_gridsize); + where.x = fsnap(where.x, pathlib_gridsize); + where.y = fsnap(where.y, pathlib_gridsize); - entity found = NULL; // TODO: using FOREACH_ENTITY_RADIUS here causes mutex loop warnings, this may need a proper fix! - IL_EACH(g_pathlib_nodes, it.is_path_node && vdist(it.origin - where, <, pathlib_gridsize * 0.5), - { - found = it; - break; - }); + entity found = NULL; // TODO: using FOREACH_ENTITY_RADIUS here causes mutex loop warnings, this may need a proper fix! + IL_EACH(g_pathlib_nodes, it.is_path_node && vdist(it.origin - where, <, pathlib_gridsize * 0.5), + { + found = it; + break; + }); - return found; + return found; } bool tile_check_cross(entity this, vector where) { vector p; - vector f = PLIB_FORWARD * tile_check_size; - vector r = PLIB_RIGHT * tile_check_size; - - - // forward-right - p = where + f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (!location_isok(trace_endpos, 1, 0)) - return false; - - // Forward-left - p = where + f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (!location_isok(trace_endpos, 1, 0)) - return false; - - // Back-right - p = where - f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (!location_isok(trace_endpos, 1 ,0)) - return false; - - //Back-left - p = where - f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (!location_isok(trace_endpos, 1, 0)) - return false; - - return true; + vector f = PLIB_FORWARD * tile_check_size; + vector r = PLIB_RIGHT * tile_check_size; + + + // forward-right + p = where + f + r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + // Forward-left + p = where + f - r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + // Back-right + p = where - f + r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + // Back-left + p = where - f - r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + return true; } bool tile_check_plus(entity this, vector where) { - vector p; - - vector f = PLIB_FORWARD * tile_check_size; - vector r = PLIB_RIGHT * tile_check_size; - - // forward - p = where + f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (!location_isok(trace_endpos,1,0)) - return false; - - - //left - p = where - r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (!location_isok(trace_endpos,1,0)) - return false; - - // Right - p = where + r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (!location_isok(trace_endpos,1,0)) - return false; - - //Back - p = where - f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (!location_isok(trace_endpos,1,0)) - return false; + vector p; - return true; + vector f = PLIB_FORWARD * tile_check_size; + vector r = PLIB_RIGHT * tile_check_size; + + // forward + p = where + f; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + + // left + p = where - r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + // Right + p = where + r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + // Back + p = where - f; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (!location_isok(trace_endpos, 1, 0)) { + return false; + } + + return true; } float tile_check_plus2(entity this, vector where) { - vector p; - int j = 0, e = 0; - - vector f = PLIB_FORWARD * pathlib_gridsize; - vector r = PLIB_RIGHT * pathlib_gridsize; - -//#define pathlib_node_edgeflag_left 2 -//#define pathlib_node_edgeflag_right 4 -//#define pathlib_node_edgeflag_forward 8 -//#define pathlib_node_edgeflag_back 16 - - // forward - p = where + f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (location_isok(trace_endpos,1,0)) - { - ++j; - e |= pathlib_node_edgeflag_forward; - } - - - //left - p = where - r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (location_isok(trace_endpos,1,0)) - { - ++j; - e |= pathlib_node_edgeflag_left; - } - - - // Right - p = where + r; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (location_isok(trace_endpos,1,0)) - { - ++j; - e |= pathlib_node_edgeflag_right; - } - - //Back - p = where - f; - traceline(p+tile_check_up,p-tile_check_down,MOVE_WORLDONLY,this); - if (location_isok(trace_endpos,1,0)) - { - ++j; - e |= pathlib_node_edgeflag_back; - } - - // forward-right - p = where + f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (location_isok(trace_endpos, 1, 0)) - { - ++j; - e |= pathlib_node_edgeflag_forwardright; - } - - // Forward-left - p = where + f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (location_isok(trace_endpos, 1, 0)) - { - ++j; - e |= pathlib_node_edgeflag_forwardleft; - } - - // Back-right - p = where - f + r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (location_isok(trace_endpos, 1 ,0)) - { - ++j; - e |= pathlib_node_edgeflag_backright; - } - - //Back-left - p = where - f - r; - traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); - if (location_isok(trace_endpos, 1, 0)) - { - ++j; - e |= pathlib_node_edgeflag_backleft; - } - - - if(j == 0) - e = pathlib_node_edgeflag_none; - - return e; + vector p; + int j = 0, e = 0; + + vector f = PLIB_FORWARD * pathlib_gridsize; + vector r = PLIB_RIGHT * pathlib_gridsize; + +// #define pathlib_node_edgeflag_left 2 +// #define pathlib_node_edgeflag_right 4 +// #define pathlib_node_edgeflag_forward 8 +// #define pathlib_node_edgeflag_back 16 + + // forward + p = where + f; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_forward; + } + + + // left + p = where - r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_left; + } + + + // Right + p = where + r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_right; + } + + // Back + p = where - f; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_back; + } + + // forward-right + p = where + f + r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_forwardright; + } + + // Forward-left + p = where + f - r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_forwardleft; + } + + // Back-right + p = where - f + r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_backright; + } + + // Back-left + p = where - f - r; + traceline(p + tile_check_up, p - tile_check_down, MOVE_WORLDONLY, this); + if (location_isok(trace_endpos, 1, 0)) { + ++j; + e |= pathlib_node_edgeflag_backleft; + } + + + if (j == 0) { + e = pathlib_node_edgeflag_none; + } + + return e; } bool tile_check_star(entity this, vector where) { - if(tile_check_plus(this, where)) - return tile_check_cross(this, where); + if (tile_check_plus(this, where)) { + return tile_check_cross(this, where); + } - return false; + return false; } - diff --git a/qcsrc/server/pathlib/utility.qh b/qcsrc/server/pathlib/utility.qh index f89a60c12..74282b80b 100644 --- a/qcsrc/server/pathlib/utility.qh +++ b/qcsrc/server/pathlib/utility.qh @@ -1,6 +1,6 @@ #pragma once -float fsnap(float val,float fsize); +float fsnap(float val, float fsize); entity pathlib_nodeatpoint(vector where); float tile_check_plus2(entity this, vector where); bool location_isok(vector point, bool waterok, bool air_isok); diff --git a/qcsrc/server/playerdemo.qc b/qcsrc/server/playerdemo.qc index 411d826a8..5f044a571 100644 --- a/qcsrc/server/playerdemo.qc +++ b/qcsrc/server/playerdemo.qc @@ -2,8 +2,8 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include "defs.qh" - #include "playerdemo.qh" + #include "defs.qh" + #include "playerdemo.qh" #include <common/state.qh> #endif @@ -20,8 +20,7 @@ void playerdemo_init(entity this) } void playerdemo_shutdown(entity this) { - if(this.playerdemo_mode != PLAYERDEMO_MODE_OFF) - { + if (this.playerdemo_mode != PLAYERDEMO_MODE_OFF) { LOG_INFO("playerdemo: ", this.netname, " closed"); fclose(this.playerdemo_fh); } @@ -47,26 +46,26 @@ void playerdemo_open_write(entity this, string f) LOG_INFO("playerdemo: ", this.netname, " writing to ", f); LOG_INFO("WARNING: playerdemo file format is incomplete and not stable yet. DO NOT RELY ON IT!"); } -#define PLAYERDEMO_FIELD(ent,func,t,f) func##t(ent,f,#f); -#define PLAYERDEMO_FIELDS(ent,func) \ - PLAYERDEMO_FIELD(ent,func,originvector,origin) \ - PLAYERDEMO_FIELD(ent,func,vector,angles) \ - PLAYERDEMO_FIELD(ent,func,sizevector,mins) \ - PLAYERDEMO_FIELD(ent,func,sizevector,maxs) \ - PLAYERDEMO_FIELD(ent,func,vector,v_angle) \ - PLAYERDEMO_FIELD(ent,func,modelstring,model) \ - PLAYERDEMO_FIELD(ent,func,string,playermodel) \ - PLAYERDEMO_FIELD(ent,func,float,skin) \ - PLAYERDEMO_FIELD(ent,func,string,playerskin) \ - PLAYERDEMO_FIELD(ent,func,float,frame) \ - PLAYERDEMO_FIELD(ent,func,float,effects) \ +#define PLAYERDEMO_FIELD(ent, func, t, f) func##t(ent, f, #f); +#define PLAYERDEMO_FIELDS(ent, func) \ + PLAYERDEMO_FIELD(ent, func, originvector, origin) \ + PLAYERDEMO_FIELD(ent, func, vector, angles) \ + PLAYERDEMO_FIELD(ent, func, sizevector, mins) \ + PLAYERDEMO_FIELD(ent, func, sizevector, maxs) \ + PLAYERDEMO_FIELD(ent, func, vector, v_angle) \ + PLAYERDEMO_FIELD(ent, func, modelstring, model) \ + PLAYERDEMO_FIELD(ent, func, string, playermodel) \ + PLAYERDEMO_FIELD(ent, func, float, skin) \ + PLAYERDEMO_FIELD(ent, func, string, playerskin) \ + PLAYERDEMO_FIELD(ent, func, float, frame) \ + PLAYERDEMO_FIELD(ent, func, float, effects) \ /* PLAYERDEMO_FIELD(ent,func,float,switchweapon) */ \ - PLAYERDEMO_FIELD(CS(ent),func,float,button0) /* TODO: PHYS_INPUT_BUTTON_ATCK */ \ - PLAYERDEMO_FIELD(CS(ent),func,float,button3) /* TODO: PHYS_INPUT_BUTTON_ATCK2 */ \ - PLAYERDEMO_FIELD(CS(ent),func,float,button5) /* TODO: PHYS_INPUT_BUTTON_CROUCH */ \ - PLAYERDEMO_FIELD(CS(ent),func,float,button6) /* TODO: PHYS_INPUT_BUTTON_HOOK */ \ - PLAYERDEMO_FIELD(CS(ent),func,float,buttonuse) /* TODO: PHYS_INPUT_BUTTON_USE */ \ - PLAYERDEMO_FIELD(ent,func,float,flags) \ + PLAYERDEMO_FIELD(CS(ent), func, float, button0) /* TODO: PHYS_INPUT_BUTTON_ATCK */ \ + PLAYERDEMO_FIELD(CS(ent), func, float, button3) /* TODO: PHYS_INPUT_BUTTON_ATCK2 */ \ + PLAYERDEMO_FIELD(CS(ent), func, float, button5) /* TODO: PHYS_INPUT_BUTTON_CROUCH */ \ + PLAYERDEMO_FIELD(CS(ent), func, float, button6) /* TODO: PHYS_INPUT_BUTTON_HOOK */ \ + PLAYERDEMO_FIELD(CS(ent), func, float, buttonuse) /* TODO: PHYS_INPUT_BUTTON_USE */ \ + PLAYERDEMO_FIELD(ent, func, float, flags) \ // end of list void playerdemo_write_originvector(entity this, .vector f, string name) @@ -95,8 +94,9 @@ void playerdemo_write_float(entity this, .float f, string name) } void playerdemo_write(entity this) { - if(this.playerdemo_mode != PLAYERDEMO_MODE_WRITING) + if (this.playerdemo_mode != PLAYERDEMO_MODE_WRITING) { return; + } fputs(this.playerdemo_fh, strcat(ftos(time - this.playerdemo_starttime), "\n")); PLAYERDEMO_FIELDS(this, playerdemo_write_) } @@ -116,11 +116,10 @@ void playerdemo_read_vector(entity this, .vector f, string name) void playerdemo_read_string(entity this, .string f, string name) { string s = fgets(this.playerdemo_fh); - if (s != this.(f)) - { + if (s != this.(f)) { /* if(this.f) - strunzone(this.f); + strunzone(this.f); */ this.(f) = strzone(s); } @@ -128,8 +127,9 @@ void playerdemo_read_string(entity this, .string f, string name) void playerdemo_read_modelstring(entity this, .string f, string name) { string s = fgets(this.playerdemo_fh); - if (s != this.(f)) + if (s != this.(f)) { _setmodel(this, s); + } } void playerdemo_read_float(entity this, .float f, string name) { @@ -137,14 +137,15 @@ void playerdemo_read_float(entity this, .float f, string name) } float playerdemo_read(entity this) { - if(this.playerdemo_mode != PLAYERDEMO_MODE_READING) + if (this.playerdemo_mode != PLAYERDEMO_MODE_READING) { return 0; - if(this.playerdemo_time < 0) + } + if (this.playerdemo_time < 0) { return 1; + } float t; t = time; - while(time >= this.playerdemo_time) - { + while (time >= this.playerdemo_time) { PLAYERDEMO_FIELDS(this, playerdemo_read_) { time = this.playerdemo_time; @@ -153,8 +154,7 @@ float playerdemo_read(entity this) PlayerPostThink(this); } this.playerdemo_time = stof(fgets(this.playerdemo_fh)); - if(this.playerdemo_time == 0) - { + if (this.playerdemo_time == 0) { this.playerdemo_time = -1; return 1; } diff --git a/qcsrc/server/round_handler.qc b/qcsrc/server/round_handler.qc index ae64e74e4..e8857477d 100644 --- a/qcsrc/server/round_handler.qc +++ b/qcsrc/server/round_handler.qc @@ -8,62 +8,49 @@ void round_handler_Think(entity this) { - if (intermission_running) - { + if (intermission_running) { round_handler_Reset(0); round_handler_Remove(); return; } - if (time < game_starttime) - { + if (time < game_starttime) { round_handler_Reset(game_starttime); return; } game_stopped = false; - if (this.wait) - { + if (this.wait) { this.wait = false; - this.cnt = this.count + 1; // init countdown + this.cnt = this.count + 1; // init countdown round_starttime = time + this.count; reset_map(true); } - if (this.cnt > 0) // countdown running - { - if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start)) - { - if (this.cnt == this.count + 1) round_starttime = time + this.count; + if (this.cnt > 0) { // countdown running + if (this.canRoundStart() && !(autocvar_g_campaign && !campaign_bots_may_start)) { + if (this.cnt == this.count + 1) { round_starttime = time + this.count; } int f = this.cnt - 1; - if (f == 0) - { + if (f == 0) { this.cnt = 0; this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0; this.nextthink = time; - if (this.roundStart) this.roundStart(); + if (this.roundStart) { this.roundStart(); } return; } this.cnt = this.cnt - 1; - } - else - { + } else { round_handler_Reset(0); } - this.nextthink = time + 1; // canRoundStart every second - } - else - { - if (this.canRoundEnd()) - { + this.nextthink = time + 1; // canRoundStart every second + } else { + if (this.canRoundEnd()) { // schedule a new round this.wait = true; this.nextthink = time + this.delay; - } - else - { - this.nextthink = time; // canRoundEnd every frame + } else { + this.nextthink = time; // canRoundEnd every frame } } } @@ -88,8 +75,7 @@ void round_handler_FirstThink(entity this) void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func) { - if (round_handler) - { + if (round_handler) { backtrace("Can't spawn round_handler again!"); return; } @@ -108,8 +94,8 @@ void round_handler_Reset(float next_think) { entity this = round_handler; this.wait = false; - if (this.count) - if (this.cnt < this.count + 1) this.cnt = this.count + 1; + if (this.count) { + if (this.cnt < this.count + 1) { this.cnt = this.count + 1; } } this.nextthink = next_think; round_starttime = (next_think) ? (next_think + this.count) : -1; } diff --git a/qcsrc/server/round_handler.qh b/qcsrc/server/round_handler.qh index e6b17b0e7..4223d3c91 100644 --- a/qcsrc/server/round_handler.qh +++ b/qcsrc/server/round_handler.qh @@ -3,9 +3,9 @@ entity round_handler; .float delay; // stores delay from round end to countdown start .float count; // stores initial number of the countdown -.float wait; // it's set to true when round ends, to false when countdown starts -.float cnt; // its initial value is .count + 1, then decreased while counting down - // reaches 0 when the round starts +.float wait; // it's set to true when round ends, to false when countdown starts +.float cnt; // its initial value is .count + 1, then decreased while counting down + // reaches 0 when the round starts .float round_timelimit; .float round_endtime; .float() canRoundStart; diff --git a/qcsrc/server/steerlib.qc b/qcsrc/server/steerlib.qc index 3418a2c4e..46cccaa55 100644 --- a/qcsrc/server/steerlib.qc +++ b/qcsrc/server/steerlib.qc @@ -2,13 +2,13 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) - #include "pathlib/utility.qh" + #include "pathlib/utility.qh" #endif /** Uniform pull towards a point **/ -#define steerlib_pull(ent,point) normalize(point - (ent).origin) +#define steerlib_pull(ent, point) normalize(point - (ent).origin) /*vector steerlib_pull(entity this, vector point) { return normalize(point - this.origin); @@ -17,7 +17,7 @@ /** Uniform push from a point **/ -#define steerlib_push(ent,point) normalize(ent.origin - point) +#define steerlib_push(ent, point) normalize(ent.origin - point) /* vector steerlib_push(entity this, vector point) { @@ -29,12 +29,12 @@ vector steerlib_push(entity this, vector point) **/ vector steerlib_arrive(entity this, vector point, float maximal_distance) { - float distance; - vector direction; + float distance; + vector direction; - distance = bound(0.001,vlen(this.origin - point),maximal_distance); - direction = normalize(point - this.origin); - return direction * (distance / maximal_distance); + distance = bound(0.001, vlen(this.origin - point), maximal_distance); + direction = normalize(point - this.origin); + return direction * (distance / maximal_distance); } /** @@ -42,28 +42,28 @@ vector steerlib_arrive(entity this, vector point, float maximal_distance) **/ vector steerlib_attract(entity this, vector point, float maximal_distance) { - float distance; - vector direction; + float distance; + vector direction; - distance = bound(0.001,vlen(this.origin - point),maximal_distance); - direction = normalize(point - this.origin); + distance = bound(0.001, vlen(this.origin - point), maximal_distance); + direction = normalize(point - this.origin); - return direction * (1-(distance / maximal_distance)); + return direction * (1 - (distance / maximal_distance)); } -vector steerlib_attract2(entity this, vector point, float min_influense,float max_distance,float max_influense) +vector steerlib_attract2(entity this, vector point, float min_influense, float max_distance, float max_influense) { - float distance; - vector direction; - float influense; + float distance; + vector direction; + float influense; - distance = bound(0.00001,vlen(this.origin - point),max_distance); - direction = normalize(point - this.origin); + distance = bound(0.00001, vlen(this.origin - point), max_distance); + direction = normalize(point - this.origin); - influense = 1 - (distance / max_distance); - influense = min_influense + (influense * (max_influense - min_influense)); + influense = 1 - (distance / max_distance); + influense = min_influense + (influense * (max_influense - min_influense)); - return direction * influense; + return direction * influense; } /* @@ -99,37 +99,35 @@ vector steerlib_attract2(vector point, float maximal_distance,float min_influens /** Move away from a point. **/ -vector steerlib_repell(entity this, vector point,float maximal_distance) +vector steerlib_repell(entity this, vector point, float maximal_distance) { - float distance; - vector direction; + float distance; + vector direction; - distance = bound(0.001,vlen(this.origin - point),maximal_distance); - direction = normalize(this.origin - point); + distance = bound(0.001, vlen(this.origin - point), maximal_distance); + direction = normalize(this.origin - point); - return direction * (1-(distance / maximal_distance)); + return direction * (1 - (distance / maximal_distance)); } /** Try to keep at ideal_distance away from point **/ -vector steerlib_standoff(entity this, vector point,float ideal_distance) +vector steerlib_standoff(entity this, vector point, float ideal_distance) { - float distance; - vector direction; + float distance; + vector direction; - distance = vlen(this.origin - point); + distance = vlen(this.origin - point); - if(distance < ideal_distance) - { - direction = normalize(this.origin - point); - return direction * (distance / ideal_distance); - } - - direction = normalize(point - this.origin); - return direction * (ideal_distance / distance); + if (distance < ideal_distance) { + direction = normalize(this.origin - point); + return direction * (distance / ideal_distance); + } + direction = normalize(point - this.origin); + return direction * (ideal_distance / distance); } /** @@ -142,18 +140,19 @@ vector steerlib_standoff(entity this, vector point,float ideal_distance) **/ vector steerlib_wander(entity this, float range, float tresh, vector oldpoint) { - vector wander_point; - wander_point = v_forward - oldpoint; + vector wander_point; + wander_point = v_forward - oldpoint; - if (vdist(wander_point, >, tresh)) - return oldpoint; + if (vdist(wander_point, >, tresh)) { + return oldpoint; + } - range = bound(0,range,1); + range = bound(0, range, 1); - wander_point = this.origin + v_forward * 128; - wander_point = wander_point + randomvec() * (range * 128) - randomvec() * (range * 128); + wander_point = this.origin + v_forward * 128; + wander_point = wander_point + randomvec() * (range * 128) - randomvec() * (range * 128); - return normalize(wander_point - this.origin); + return normalize(wander_point - this.origin); } /** @@ -161,13 +160,14 @@ vector steerlib_wander(entity this, float range, float tresh, vector oldpoint) **/ vector steerlib_dodge(entity this, vector point, vector dodge_dir, float min_distance) { - float distance; + float distance; - distance = max(vlen(this.origin - point),min_distance); - if (min_distance < distance) - return '0 0 0'; + distance = max(vlen(this.origin - point), min_distance); + if (min_distance < distance) { + return '0 0 0'; + } - return dodge_dir * (min_distance/distance); + return dodge_dir * (min_distance / distance); } /** @@ -175,25 +175,24 @@ vector steerlib_dodge(entity this, vector point, vector dodge_dir, float min_dis Group will move towards the unified direction while keeping close to eachother. **/ .float flock_id; -vector steerlib_flock(entity this, float _radius, float standoff,float separation_force,float flock_force) +vector steerlib_flock(entity this, float _radius, float standoff, float separation_force, float flock_force) { - entity flock_member; - vector push = '0 0 0', pull = '0 0 0'; - float ccount = 0; - - flock_member = findradius(this.origin, _radius); - while(flock_member) - { - if(flock_member != this) - if(flock_member.flock_id == this.flock_id) - { - ++ccount; - push = push + (steerlib_repell(this, flock_member.origin,standoff) * separation_force); - pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force); - } - flock_member = flock_member.chain; - } - return push + (pull* (1 / ccount)); + entity flock_member; + vector push = '0 0 0', pull = '0 0 0'; + float ccount = 0; + + flock_member = findradius(this.origin, _radius); + while (flock_member) { + if (flock_member != this) { + if (flock_member.flock_id == this.flock_id) { + ++ccount; + push = push + (steerlib_repell(this, flock_member.origin, standoff) * separation_force); + pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force); + } + } + flock_member = flock_member.chain; + } + return push + (pull * (1 / ccount)); } /** @@ -201,29 +200,28 @@ vector steerlib_flock(entity this, float _radius, float standoff,float separatio Group will move towards the unified direction while keeping close to eachother. xy only version (for ground movers). **/ -vector steerlib_flock2d(entity this, float _radius, float standoff,float separation_force,float flock_force) +vector steerlib_flock2d(entity this, float _radius, float standoff, float separation_force, float flock_force) { - entity flock_member; - vector push = '0 0 0', pull = '0 0 0'; - float ccount = 0; - - flock_member = findradius(this.origin,_radius); - while(flock_member) - { - if(flock_member != this) - if(flock_member.flock_id == this.flock_id) - { - ++ccount; - push = push + (steerlib_repell(this, flock_member.origin, standoff) * separation_force); - pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force); - } - flock_member = flock_member.chain; - } - - push.z = 0; - pull.z = 0; - - return push + (pull * (1 / ccount)); + entity flock_member; + vector push = '0 0 0', pull = '0 0 0'; + float ccount = 0; + + flock_member = findradius(this.origin, _radius); + while (flock_member) { + if (flock_member != this) { + if (flock_member.flock_id == this.flock_id) { + ++ccount; + push = push + (steerlib_repell(this, flock_member.origin, standoff) * separation_force); + pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force); + } + } + flock_member = flock_member.chain; + } + + push.z = 0; + pull.z = 0; + + return push + (pull * (1 / ccount)); } /** @@ -232,29 +230,27 @@ vector steerlib_flock2d(entity this, float _radius, float standoff,float separat This results in a aligned movement (?!) much like flocking. **/ -vector steerlib_swarm(entity this, float _radius, float standoff,float separation_force,float swarm_force) +vector steerlib_swarm(entity this, float _radius, float standoff, float separation_force, float swarm_force) { - entity swarm_member; - vector force = '0 0 0', center = '0 0 0'; - float ccount = 0; - - swarm_member = findradius(this.origin,_radius); - - while(swarm_member) - { - if(swarm_member.flock_id == this.flock_id) - { - ++ccount; - center = center + swarm_member.origin; - force = force + (steerlib_repell(this, swarm_member.origin,standoff) * separation_force); - } - swarm_member = swarm_member.chain; - } - - center = center * (1 / ccount); - force = force + (steerlib_arrive(this, center,_radius) * swarm_force); - - return force; + entity swarm_member; + vector force = '0 0 0', center = '0 0 0'; + float ccount = 0; + + swarm_member = findradius(this.origin, _radius); + + while (swarm_member) { + if (swarm_member.flock_id == this.flock_id) { + ++ccount; + center = center + swarm_member.origin; + force = force + (steerlib_repell(this, swarm_member.origin, standoff) * separation_force); + } + swarm_member = swarm_member.chain; + } + + center = center * (1 / ccount); + force = force + (steerlib_arrive(this, center, _radius) * swarm_force); + + return force; } /** @@ -262,47 +258,46 @@ vector steerlib_swarm(entity this, float _radius, float standoff,float separatio Run four tracelines in a forward funnel, bias each diretion negative if something is found there. You need to call makevectors() (or equivalent) before this function to set v_forward and v_right **/ -vector steerlib_traceavoid(entity this, float pitch,float length) +vector steerlib_traceavoid(entity this, float pitch, float length) { - vector vup_left,vup_right,vdown_left,vdown_right; - float fup_left,fup_right,fdown_left,fdown_right; - vector upwish,downwish,leftwish,rightwish; - vector v_left,v_down; - + vector vup_left, vup_right, vdown_left, vdown_right; + float fup_left, fup_right, fdown_left, fdown_right; + vector upwish, downwish, leftwish, rightwish; + vector v_left, v_down; - v_left = v_right * -1; - v_down = v_up * -1; - vup_left = (v_forward + (v_left * pitch + v_up * pitch)) * length; - traceline(this.origin, this.origin + vup_left,MOVE_NOMONSTERS,this); - fup_left = trace_fraction; + v_left = v_right * -1; + v_down = v_up * -1; - //te_lightning1(NULL,this.origin, trace_endpos); + vup_left = (v_forward + (v_left * pitch + v_up * pitch)) * length; + traceline(this.origin, this.origin + vup_left, MOVE_NOMONSTERS, this); + fup_left = trace_fraction; - vup_right = (v_forward + (v_right * pitch + v_up * pitch)) * length; - traceline(this.origin,this.origin + vup_right ,MOVE_NOMONSTERS,this); - fup_right = trace_fraction; + // te_lightning1(NULL,this.origin, trace_endpos); - //te_lightning1(NULL,this.origin, trace_endpos); + vup_right = (v_forward + (v_right * pitch + v_up * pitch)) * length; + traceline(this.origin, this.origin + vup_right, MOVE_NOMONSTERS, this); + fup_right = trace_fraction; - vdown_left = (v_forward + (v_left * pitch + v_down * pitch)) * length; - traceline(this.origin,this.origin + vdown_left,MOVE_NOMONSTERS,this); - fdown_left = trace_fraction; + // te_lightning1(NULL,this.origin, trace_endpos); - //te_lightning1(NULL,this.origin, trace_endpos); + vdown_left = (v_forward + (v_left * pitch + v_down * pitch)) * length; + traceline(this.origin, this.origin + vdown_left, MOVE_NOMONSTERS, this); + fdown_left = trace_fraction; - vdown_right = (v_forward + (v_right * pitch + v_down * pitch)) * length; - traceline(this.origin,this.origin + vdown_right,MOVE_NOMONSTERS,this); - fdown_right = trace_fraction; + // te_lightning1(NULL,this.origin, trace_endpos); - //te_lightning1(NULL,this.origin, trace_endpos); - upwish = v_up * (fup_left + fup_right); - downwish = v_down * (fdown_left + fdown_right); - leftwish = v_left * (fup_left + fdown_left); - rightwish = v_right * (fup_right + fdown_right); + vdown_right = (v_forward + (v_right * pitch + v_down * pitch)) * length; + traceline(this.origin, this.origin + vdown_right, MOVE_NOMONSTERS, this); + fdown_right = trace_fraction; - return (upwish+leftwish+downwish+rightwish) * 0.25; + // te_lightning1(NULL,this.origin, trace_endpos); + upwish = v_up * (fup_left + fup_right); + downwish = v_down * (fdown_left + fdown_right); + leftwish = v_left * (fup_left + fdown_left); + rightwish = v_right * (fup_right + fdown_right); + return (upwish + leftwish + downwish + rightwish) * 0.25; } /** @@ -311,141 +306,140 @@ vector steerlib_traceavoid(entity this, float pitch,float length) **/ vector steerlib_traceavoid_flat(entity this, float pitch, float length, vector vofs) { - vector vt_left, vt_right,vt_front; - float f_left, f_right,f_front; - vector leftwish, rightwish,frontwish, v_left; + vector vt_left, vt_right, vt_front; + float f_left, f_right, f_front; + vector leftwish, rightwish, frontwish, v_left; - v_left = v_right * -1; + v_left = v_right * -1; - vt_front = v_forward * length; - traceline(this.origin + vofs, this.origin + vofs + vt_front,MOVE_NOMONSTERS,this); - f_front = trace_fraction; + vt_front = v_forward * length; + traceline(this.origin + vofs, this.origin + vofs + vt_front, MOVE_NOMONSTERS, this); + f_front = trace_fraction; - vt_left = (v_forward + (v_left * pitch)) * length; - traceline(this.origin + vofs, this.origin + vofs + vt_left,MOVE_NOMONSTERS,this); - f_left = trace_fraction; + vt_left = (v_forward + (v_left * pitch)) * length; + traceline(this.origin + vofs, this.origin + vofs + vt_left, MOVE_NOMONSTERS, this); + f_left = trace_fraction; - //te_lightning1(NULL,this.origin, trace_endpos); + // te_lightning1(NULL,this.origin, trace_endpos); - vt_right = (v_forward + (v_right * pitch)) * length; - traceline(this.origin + vofs, this.origin + vofs + vt_right ,MOVE_NOMONSTERS,this); - f_right = trace_fraction; + vt_right = (v_forward + (v_right * pitch)) * length; + traceline(this.origin + vofs, this.origin + vofs + vt_right, MOVE_NOMONSTERS, this); + f_right = trace_fraction; - //te_lightning1(NULL,this.origin, trace_endpos); + // te_lightning1(NULL,this.origin, trace_endpos); - leftwish = v_left * f_left; - rightwish = v_right * f_right; - frontwish = v_forward * f_front; + leftwish = v_left * f_left; + rightwish = v_right * f_right; + frontwish = v_forward * f_front; - return normalize(leftwish + rightwish + frontwish); + return normalize(leftwish + rightwish + frontwish); } -//#define BEAMSTEER_VISUAL -float beamsweep(entity this, vector from, vector dir,float length, float step,float step_up, float step_down) +// #define BEAMSTEER_VISUAL +float beamsweep(entity this, vector from, vector dir, float length, float step, float step_up, float step_down) { - float i; - vector a, b, u, d; - - u = '0 0 1' * step_up; - d = '0 0 1' * step_down; - - traceline(from + u, from - d,MOVE_NORMAL,this); - if(trace_fraction == 1.0) - return 0; - - if(!location_isok(trace_endpos, false, false)) - return 0; - - a = trace_endpos; - for(i = 0; i < length; i += step) - { - - b = a + dir * step; - tracebox(a + u,'-4 -4 -4','4 4 4', b + u,MOVE_NORMAL,this); - if(trace_fraction != 1.0) - return i / length; - - traceline(b + u, b - d,MOVE_NORMAL,this); - if(trace_fraction == 1.0) - return i / length; - - if(!location_isok(trace_endpos, false, false)) - return i / length; + float i; + vector a, b, u, d; + + u = '0 0 1' * step_up; + d = '0 0 1' * step_down; + + traceline(from + u, from - d, MOVE_NORMAL, this); + if (trace_fraction == 1.0) { + return 0; + } + + if (!location_isok(trace_endpos, false, false)) { + return 0; + } + + a = trace_endpos; + for (i = 0; i < length; i += step) { + b = a + dir * step; + tracebox(a + u, '-4 -4 -4', '4 4 4', b + u, MOVE_NORMAL, this); + if (trace_fraction != 1.0) { + return i / length; + } + + traceline(b + u, b - d, MOVE_NORMAL, this); + if (trace_fraction == 1.0) { + return i / length; + } + + if (!location_isok(trace_endpos, false, false)) { + return i / length; + } #ifdef BEAMSTEER_VISUAL - te_lightning1(NULL,a+u,b+u); - te_lightning1(NULL,b+u,b-d); + te_lightning1(NULL, a + u, b + u); + te_lightning1(NULL, b + u, b - d); #endif - a = trace_endpos; - } + a = trace_endpos; + } - return 1; + return 1; } vector steerlib_beamsteer(entity this, vector dir, float length, float step, float step_up, float step_down) { - float bm_forward, bm_right, bm_left,p; - vector vr,vl; - - dir.z *= 0.15; - vr = vectoangles(dir); - //vr_x *= -1; + float bm_forward, bm_right, bm_left, p; + vector vr, vl; - tracebox(this.origin + '0 0 1' * step_up, this.mins, this.maxs, ('0 0 1' * step_up) + this.origin + (dir * length), MOVE_NOMONSTERS, this); - if(trace_fraction == 1.0) - { - //te_lightning1(this,this.origin,this.origin + (dir * length)); - return dir; - } + dir.z *= 0.15; + vr = vectoangles(dir); + // vr_x *= -1; - makevectors(vr); - bm_forward = beamsweep(this, this.origin, v_forward, length, step, step_up, step_down); + tracebox(this.origin + '0 0 1' * step_up, this.mins, this.maxs, ('0 0 1' * step_up) + this.origin + (dir * length), MOVE_NOMONSTERS, this); + if (trace_fraction == 1.0) { + // te_lightning1(this,this.origin,this.origin + (dir * length)); + return dir; + } - vr = normalize(v_forward + v_right * 0.125); - vl = normalize(v_forward - v_right * 0.125); + makevectors(vr); + bm_forward = beamsweep(this, this.origin, v_forward, length, step, step_up, step_down); - bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); - bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); + vr = normalize(v_forward + v_right * 0.125); + vl = normalize(v_forward - v_right * 0.125); + bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); + bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); - p = bm_left + bm_right; - if(p == 2) - { - //te_lightning1(this,this.origin + '0 0 32',this.origin + '0 0 32' + vr * length); - //te_lightning1(this.tur_head,this.origin + '0 0 32',this.origin + '0 0 32' + vl * length); - return v_forward; - } + p = bm_left + bm_right; + if (p == 2) { + // te_lightning1(this,this.origin + '0 0 32',this.origin + '0 0 32' + vr * length); + // te_lightning1(this.tur_head,this.origin + '0 0 32',this.origin + '0 0 32' + vl * length); - p = 2 - p; + return v_forward; + } - vr = normalize(v_forward + v_right * p); - vl = normalize(v_forward - v_right * p); - bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); - bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); + p = 2 - p; + vr = normalize(v_forward + v_right * p); + vl = normalize(v_forward - v_right * p); + bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); + bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); - if(bm_left + bm_right < 0.15) - { - vr = normalize((v_forward*-1) + v_right * 0.90); - vl = normalize((v_forward*-1) - v_right * 0.90); - bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); - bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); - } + if (bm_left + bm_right < 0.15) { + vr = normalize((v_forward * -1) + v_right * 0.90); + vl = normalize((v_forward * -1) - v_right * 0.90); - //te_lightning1(this,this.origin + '0 0 32',this.origin + '0 0 32' + vr * length); - //te_lightning1(this.tur_head,this.origin + '0 0 32',this.origin + '0 0 32' + vl * length); + bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); + bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); + } - bm_forward *= bm_forward; - bm_right *= bm_right; - bm_left *= bm_left; + // te_lightning1(this,this.origin + '0 0 32',this.origin + '0 0 32' + vr * length); + // te_lightning1(this.tur_head,this.origin + '0 0 32',this.origin + '0 0 32' + vl * length); - vr = vr * bm_right; - vl = vl * bm_left; + bm_forward *= bm_forward; + bm_right *= bm_right; + bm_left *= bm_left; - return normalize(vr + vl); + vr = vr * bm_right; + vl = vl * bm_left; + return normalize(vr + vl); } @@ -453,170 +447,167 @@ vector steerlib_beamsteer(entity this, vector dir, float length, float step, flo // Testting // // Everything below this point is a mess :D // ////////////////////////////////////////////// -//#define TLIBS_TETSLIBS +// #define TLIBS_TETSLIBS #ifdef TLIBS_TETSLIBS void flocker_die(entity this) { Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1); - this.owner.cnt += 1; - this.owner = NULL; + this.owner.cnt += 1; + this.owner = NULL; - this.nextthink = time; - setthink(this, SUB_Remove); + this.nextthink = time; + setthink(this, SUB_Remove); } void flocker_think(entity this) { - vector dodgemove,swarmmove; - vector reprellmove,wandermove,newmove; + vector dodgemove, swarmmove; + vector reprellmove, wandermove, newmove; - this.angles_x = this.angles.x * -1; - makevectors(this.angles); - this.angles_x = this.angles.x * -1; + this.angles_x = this.angles.x * -1; + makevectors(this.angles); + this.angles_x = this.angles.x * -1; - dodgemove = steerlib_traceavoid(this, 0.35,1000); - swarmmove = steerlib_flock(this, 500,75,700,500); - reprellmove = steerlib_repell(this, this.owner.enemy.origin+this.enemy.velocity,2000) * 700; + dodgemove = steerlib_traceavoid(this, 0.35, 1000); + swarmmove = steerlib_flock(this, 500, 75, 700, 500); + reprellmove = steerlib_repell(this, this.owner.enemy.origin + this.enemy.velocity, 2000) * 700; - if(dodgemove == '0 0 0') - { - this.pos1 = steerlib_wander(this, 0.5,0.1,this.pos1); - wandermove = this.pos1 * 50; - } - else - this.pos1 = normalize(this.velocity); + if (dodgemove == '0 0 0') { + this.pos1 = steerlib_wander(this, 0.5, 0.1, this.pos1); + wandermove = this.pos1 * 50; + } else { + this.pos1 = normalize(this.velocity); + } - dodgemove = dodgemove * vlen(this.velocity) * 5; + dodgemove = dodgemove * vlen(this.velocity) * 5; - newmove = swarmmove + reprellmove + wandermove + dodgemove; - this.velocity = movelib_inertmove_byspeed(this, newmove,300,0.2,0.9); - //this.velocity = movelib_inertmove(this, dodgemove,0.65); + newmove = swarmmove + reprellmove + wandermove + dodgemove; + this.velocity = movelib_inertmove_byspeed(this, newmove, 300, 0.2, 0.9); + // this.velocity = movelib_inertmove(this, dodgemove,0.65); - this.velocity = movelib_dragvec(this, 0.01,0.6); + this.velocity = movelib_dragvec(this, 0.01, 0.6); - this.angles = vectoangles(this.velocity); + this.angles = vectoangles(this.velocity); - if(this.health <= 0) - flocker_die(this); - else - this.nextthink = time + 0.1; + if (this.health <= 0) { + flocker_die(this); + } else { + this.nextthink = time + 0.1; + } } MODEL(FLOCKER, "models/turrets/rocket.md3"); void spawn_flocker(entity this) { - entity flocker = new(flocker); - - setorigin(flocker, this.origin + '0 0 32'); - setmodel (flocker, MDL_FLOCKER); - setsize (flocker, '-3 -3 -3', '3 3 3'); - - flocker.flock_id = this.flock_id; - flocker.owner = this; - setthink(flocker, flocker_think); - flocker.nextthink = time + random() * 5; - PROJECTILE_MAKETRIGGER(flocker); - set_movetype(flocker, MOVETYPE_BOUNCEMISSILE); - flocker.effects = EF_LOWPRECISION; - flocker.velocity = randomvec() * 300; - flocker.angles = vectoangles(flocker.velocity); - flocker.health = 10; - flocker.pos1 = normalize(flocker.velocity + randomvec() * 0.1); - - IL_PUSH(g_flockers, flocker); - - this.cnt = this.cnt -1; - + entity flocker = new(flocker); + + setorigin(flocker, this.origin + '0 0 32'); + setmodel(flocker, MDL_FLOCKER); + setsize(flocker, '-3 -3 -3', '3 3 3'); + + flocker.flock_id = this.flock_id; + flocker.owner = this; + setthink(flocker, flocker_think); + flocker.nextthink = time + random() * 5; + PROJECTILE_MAKETRIGGER(flocker); + set_movetype(flocker, MOVETYPE_BOUNCEMISSILE); + flocker.effects = EF_LOWPRECISION; + flocker.velocity = randomvec() * 300; + flocker.angles = vectoangles(flocker.velocity); + flocker.health = 10; + flocker.pos1 = normalize(flocker.velocity + randomvec() * 0.1); + + IL_PUSH(g_flockers, flocker); + + this.cnt = this.cnt - 1; } void flockerspawn_think(entity this) { - if(this.cnt > 0) - spawn_flocker(this); - - this.nextthink = time + this.delay; + if (this.cnt > 0) { + spawn_flocker(this); + } + this.nextthink = time + this.delay; } void flocker_hunter_think(entity this) { - vector dodgemove,attractmove,newmove; - entity ee; - - this.angles_x = this.angles.x * -1; - makevectors(this.angles); - this.angles_x = this.angles.x * -1; - - if(this.enemy) - if(vdist(this.enemy.origin - this.origin, <, 64)) - { - ee = this.enemy; - ee.health = -1; - this.enemy = NULL; - - } - - if(!this.enemy) - { - IL_EACH(g_flockers, it.flock_id == this.flock_id, - { - if(it == this.owner || it == ee) - continue; - - if(!this.enemy || vlen2(this.origin - it.origin) > vlen2(this.origin - this.enemy.origin)) - this.enemy = it; - }); - } - - if(this.enemy) - attractmove = steerlib_attract(this, this.enemy.origin+this.enemy.velocity * 0.1,5000) * 1250; - else - attractmove = normalize(this.velocity) * 200; - - dodgemove = steerlib_traceavoid(this, 0.35,1500) * vlen(this.velocity); - - newmove = dodgemove + attractmove; - this.velocity = movelib_inertmove_byspeed(this, newmove,1250,0.3,0.7); - this.velocity = movelib_dragvec(this, 0.01,0.5); - - this.angles = vectoangles(this.velocity); - this.nextthink = time + 0.1; + vector dodgemove, attractmove, newmove; + entity ee; + + this.angles_x = this.angles.x * -1; + makevectors(this.angles); + this.angles_x = this.angles.x * -1; + + if (this.enemy) { + if (vdist(this.enemy.origin - this.origin, <, 64)) { + ee = this.enemy; + ee.health = -1; + this.enemy = NULL; + } + } + + if (!this.enemy) { + IL_EACH(g_flockers, it.flock_id == this.flock_id, + { + if (it == this.owner || it == ee) { + continue; + } + + if (!this.enemy || vlen2(this.origin - it.origin) > vlen2(this.origin - this.enemy.origin)) { + this.enemy = it; + } + }); + } + + if (this.enemy) { + attractmove = steerlib_attract(this, this.enemy.origin + this.enemy.velocity * 0.1, 5000) * 1250; + } else { + attractmove = normalize(this.velocity) * 200; + } + + dodgemove = steerlib_traceavoid(this, 0.35, 1500) * vlen(this.velocity); + + newmove = dodgemove + attractmove; + this.velocity = movelib_inertmove_byspeed(this, newmove, 1250, 0.3, 0.7); + this.velocity = movelib_dragvec(this, 0.01, 0.5); + + this.angles = vectoangles(this.velocity); + this.nextthink = time + 0.1; } float globflockcnt; spawnfunc(flockerspawn) { - ++globflockcnt; + ++globflockcnt; - if(!this.cnt) this.cnt = 20; - if(!this.delay) this.delay = 0.25; - if(!this.flock_id) this.flock_id = globflockcnt; + if (!this.cnt) { this.cnt = 20; } + if (!this.delay) { this.delay = 0.25; } + if (!this.flock_id) { this.flock_id = globflockcnt; } - setthink(this, flockerspawn_think); - this.nextthink = time + 0.25; + setthink(this, flockerspawn_think); + this.nextthink = time + 0.25; - this.enemy = new(FLock Hunter); + this.enemy = new(FLock Hunter); - setmodel(this.enemy, MDL_FLOCKER); - setorigin(this.enemy, this.origin + '0 0 768' + (randomvec() * 128)); + setmodel(this.enemy, MDL_FLOCKER); + setorigin(this.enemy, this.origin + '0 0 768' + (randomvec() * 128)); - this.enemy.scale = 3; - this.enemy.effects = EF_LOWPRECISION; - set_movetype(this.enemy, MOVETYPE_BOUNCEMISSILE); - PROJECTILE_MAKETRIGGER(this.enemy); - setthink(this.enemy, flocker_hunter_think); - this.enemy.nextthink = time + 10; - this.enemy.flock_id = this.flock_id; - this.enemy.owner = this; + this.enemy.scale = 3; + this.enemy.effects = EF_LOWPRECISION; + set_movetype(this.enemy, MOVETYPE_BOUNCEMISSILE); + PROJECTILE_MAKETRIGGER(this.enemy); + setthink(this.enemy, flocker_hunter_think); + this.enemy.nextthink = time + 10; + this.enemy.flock_id = this.flock_id; + this.enemy.owner = this; - IL_PUSH(g_flockers, this); - IL_PUSH(g_flockers, this.enemy); + IL_PUSH(g_flockers, this); + IL_PUSH(g_flockers, this.enemy); } #endif - - - diff --git a/qcsrc/server/steerlib.qh b/qcsrc/server/steerlib.qh index 89ffb698e..7cd6dbb04 100644 --- a/qcsrc/server/steerlib.qh +++ b/qcsrc/server/steerlib.qh @@ -4,7 +4,10 @@ vector steerlib_arrive(entity this, vector point, float maximal_distance); vector steerlib_attract2(entity this, vector point, float min_influense, float max_distance, float max_influense); -//vector steerlib_pull(entity this, vector point); +// vector steerlib_pull(entity this, vector point); IntrusiveList g_flockers; -STATIC_INIT(g_flockers) { g_flockers = IL_NEW(); } +STATIC_INIT(g_flockers) +{ + g_flockers = IL_NEW(); +} diff --git a/qcsrc/server/sys-pre.qh b/qcsrc/server/sys-pre.qh index 9799a087e..c5739fd31 100644 --- a/qcsrc/server/sys-pre.qh +++ b/qcsrc/server/sys-pre.qh @@ -5,29 +5,29 @@ #define cvar_string builtin_cvar_string #define cvar builtin_cvar -#define IT_SHOTGUN _IT_SHOTGUN /* BIT(0) */ -#define IT_SUPER_SHOTGUN _IT_SUPER_SHOTGUN /* BIT(1) */ -#define IT_NAILGUN _IT_NAILGUN /* BIT(2) */ -#define IT_SUPER_NAILGUN _IT_SUPER_NAILGUN /* BIT(3) */ +#define IT_SHOTGUN _IT_SHOTGUN /* BIT(0) */ +#define IT_SUPER_SHOTGUN _IT_SUPER_SHOTGUN /* BIT(1) */ +#define IT_NAILGUN _IT_NAILGUN /* BIT(2) */ +#define IT_SUPER_NAILGUN _IT_SUPER_NAILGUN /* BIT(3) */ #define IT_GRENADE_LAUNCHER _IT_GRENADE_LAUNCHER /* BIT(4) */ -#define IT_ROCKET_LAUNCHER _IT_ROCKET_LAUNCHER /* BIT(5) */ -#define IT_LIGHTNING _IT_LIGHTNING /* BIT(6) */ -#define IT_EXTRA_WEAPON _IT_EXTRA_WEAPON /* BIT(7) */ -#define IT_SHELLS _IT_SHELLS /* BIT(8) */ -#define IT_NAILS _IT_NAILS /* BIT(9) */ -#define IT_ROCKETS _IT_ROCKETS /* BIT(10) */ -#define IT_CELLS _IT_CELLS /* BIT(11) */ -#define IT_AXE _IT_AXE /* BIT(12) */ -#define IT_ARMOR1 _IT_ARMOR1 /* BIT(13) */ -#define IT_ARMOR2 _IT_ARMOR2 /* BIT(14) */ -#define IT_ARMOR3 _IT_ARMOR3 /* BIT(15) */ -#define IT_SUPERHEALTH _IT_SUPERHEALTH /* BIT(16) */ -#define IT_KEY1 _IT_KEY1 /* BIT(17) */ -#define IT_KEY2 _IT_KEY2 /* BIT(18) */ +#define IT_ROCKET_LAUNCHER _IT_ROCKET_LAUNCHER /* BIT(5) */ +#define IT_LIGHTNING _IT_LIGHTNING /* BIT(6) */ +#define IT_EXTRA_WEAPON _IT_EXTRA_WEAPON /* BIT(7) */ +#define IT_SHELLS _IT_SHELLS /* BIT(8) */ +#define IT_NAILS _IT_NAILS /* BIT(9) */ +#define IT_ROCKETS _IT_ROCKETS /* BIT(10) */ +#define IT_CELLS _IT_CELLS /* BIT(11) */ +#define IT_AXE _IT_AXE /* BIT(12) */ +#define IT_ARMOR1 _IT_ARMOR1 /* BIT(13) */ +#define IT_ARMOR2 _IT_ARMOR2 /* BIT(14) */ +#define IT_ARMOR3 _IT_ARMOR3 /* BIT(15) */ +#define IT_SUPERHEALTH _IT_SUPERHEALTH /* BIT(16) */ +#define IT_KEY1 _IT_KEY1 /* BIT(17) */ +#define IT_KEY2 _IT_KEY2 /* BIT(18) */ // FIXME: special meaning when used in client items stat -#define IT_INVISIBILITY _IT_INVISIBILITY /* BIT(19) */ -#define IT_INVULNERABILITY _IT_INVULNERABILITY /* BIT(20) */ -#define IT_SUIT _IT_SUIT /* BIT(21) */ -#define IT_QUAD _IT_QUAD /* BIT(22) */ +#define IT_INVISIBILITY _IT_INVISIBILITY /* BIT(19) */ +#define IT_INVULNERABILITY _IT_INVULNERABILITY /* BIT(20) */ +#define IT_SUIT _IT_SUIT /* BIT(21) */ +#define IT_QUAD _IT_QUAD /* BIT(22) */ #pragma noref 1 diff --git a/qcsrc/server/teamplay.qh b/qcsrc/server/teamplay.qh index 1813db04d..5b3e1456e 100644 --- a/qcsrc/server/teamplay.qh +++ b/qcsrc/server/teamplay.qh @@ -14,22 +14,22 @@ float c1; float c2; float c3; float c4; -float num_bots_team1; ///< Number of bots in the first team. -float num_bots_team2; ///< Number of bots in the second team. -float num_bots_team3; ///< Number of bots in the third team. -float num_bots_team4; ///< Number of bots in the fourth team. +float num_bots_team1; ///< Number of bots in the first team. +float num_bots_team2; ///< Number of bots in the second team. +float num_bots_team3; ///< Number of bots in the third team. +float num_bots_team4; ///< Number of bots in the fourth team. entity lowest_human_team1; ///< Human with the lowest score in the first team. entity lowest_human_team2; ///< Human with the lowest score in the second team. entity lowest_human_team3; ///< Human with the lowest score in the third team. entity lowest_human_team4; ///< Human with the lowest score in the fourth team. -entity lowest_bot_team1; ///< Bot with the lowest score in the first team. -entity lowest_bot_team2; ///< Bot with the lowest score in the second team. -entity lowest_bot_team3; ///< Bot with the lowest score in the third team. -entity lowest_bot_team4; ///< Bot with the lowest score in the fourth team. +entity lowest_bot_team1; ///< Bot with the lowest score in the first team. +entity lowest_bot_team2; ///< Bot with the lowest score in the second team. +entity lowest_bot_team3; ///< Bot with the lowest score in the third team. +entity lowest_bot_team4; ///< Bot with the lowest score in the fourth team. int redowned, blueowned, yellowowned, pinkowned; -//float audit_teams_time; +// float audit_teams_time; void TeamchangeFrags(entity e); @@ -62,8 +62,7 @@ bool SetPlayerTeamSimple(entity player, int team_num); /// \param[in] source_team Previous team of the player. /// \param[in] no_print Whether to print this event to players' console. /// \return True if team switch was successful, false otherwise. -bool SetPlayerTeam(entity player, int destination_team, int source_team, - bool no_print); +bool SetPlayerTeam(entity player, int destination_team, int source_team, bool no_print); // set c1...c4 to show what teams are allowed void CheckAllowedTeams(entity for_whom); @@ -82,8 +81,7 @@ void GetTeamCounts(entity ignore); /// \return True if first team is smaller than the second one, false otherwise. /// \note This function assumes that CheckAllowedTeams and GetTeamCounts have /// been called. -bool IsTeamSmallerThanTeam(int team_a, int team_b, entity player, - bool use_score); +bool IsTeamSmallerThanTeam(int team_a, int team_b, entity player, bool use_score); /// \brief Returns whether one team is equal to the other. /// \param[in] team_a First team. diff --git a/qcsrc/server/tests.qc b/qcsrc/server/tests.qc index 50dc5a35b..59d34571f 100644 --- a/qcsrc/server/tests.qc +++ b/qcsrc/server/tests.qc @@ -2,54 +2,54 @@ void test_weapons_hurt(entity this) { - EXPECT_NE(100, this.health); - delete(this.enemy); - delete(this); + EXPECT_NE(100, this.health); + delete(this.enemy); + delete(this); } TEST(Weapons, Hurt) { - entity it; + entity it; - noref Client a = it = NEW(Client, "A"); - WITH(float, autocvar_g_spawnshieldtime, 0, Client_Add(it, NUM_TEAM_1)); - it.origin = '-100 0 0'; - it.angles = '0 0 0'; + noref Client a = it = NEW(Client, "A"); + WITH(float, autocvar_g_spawnshieldtime, 0, Client_Add(it, NUM_TEAM_1)); + it.origin = '-100 0 0'; + it.angles = '0 0 0'; - noref Client b = it = NEW(Client, "B"); - WITH(float, autocvar_g_spawnshieldtime, 0, Client_Add(it, NUM_TEAM_2)); - it.origin = '100 0 0'; - it.angles = '0 180 0'; + noref Client b = it = NEW(Client, "B"); + WITH(float, autocvar_g_spawnshieldtime, 0, Client_Add(it, NUM_TEAM_2)); + it.origin = '100 0 0'; + it.angles = '0 180 0'; - it = a; - PHYS_INPUT_BUTTON_ATCK(it) = true; - it.items |= IT_UNLIMITED_AMMO; - Weapon wep = WEP_VORTEX; - W_GiveWeapon(it, wep.m_id); - W_SwitchWeapon_Force(it, wep, weaponentities[0]); + it = a; + PHYS_INPUT_BUTTON_ATCK(it) = true; + it.items |= IT_UNLIMITED_AMMO; + Weapon wep = WEP_VORTEX; + W_GiveWeapon(it, wep.m_id); + W_SwitchWeapon_Force(it, wep, weaponentities[0]); - it = b; - PHYS_INPUT_BUTTON_JUMP(it) = true; - it.enemy = a; + it = b; + PHYS_INPUT_BUTTON_JUMP(it) = true; + it.enemy = a; - defer(it, wep.switchdelay_raise + 0.1, test_weapons_hurt); + defer(it, wep.switchdelay_raise + 0.1, test_weapons_hurt); - SUCCEED(); + SUCCEED(); } TEST(Vehicles, Spawn) { - entity it; + entity it; - noref Client bot = it = NEW(Client, "Rider"); - Client_Add(it, NUM_TEAM_1); - it.origin = '0 0 100'; + noref Client bot = it = NEW(Client, "Rider"); + Client_Add(it, NUM_TEAM_1); + it.origin = '0 0 100'; - noref entity v = it = new(vehicle); - Vehicle veh = VEH_BUMBLEBEE; - it.active = ACTIVE_NOT; - vehicle_initialize(it, veh, false); - it.nextthink = time; + noref entity v = it = new(vehicle); + Vehicle veh = VEH_BUMBLEBEE; + it.active = ACTIVE_NOT; + vehicle_initialize(it, veh, false); + it.nextthink = time; - SUCCEED(); + SUCCEED(); } diff --git a/qcsrc/server/weapons/common.qc b/qcsrc/server/weapons/common.qc index f69faa03a..4f4da4e0d 100644 --- a/qcsrc/server/weapons/common.qc +++ b/qcsrc/server/weapons/common.qc @@ -14,27 +14,26 @@ void W_GiveWeapon(entity e, int wep) { - if (!wep) return; + if (!wep) { return; } e.weapons |= WepSet_FromWeapon(Weapons_from(wep)); if (IS_PLAYER(e)) { - Send_Notification(NOTIF_ONE, e, MSG_MULTI, ITEM_WEAPON_GOT, wep); - } + Send_Notification(NOTIF_ONE, e, MSG_MULTI, ITEM_WEAPON_GOT, wep); + } } void W_PlayStrengthSound(entity player) { - entity store = IS_PLAYER(player) ? PS(player) : player; // because non-player entities can fire, but can they have items? TODO + entity store = IS_PLAYER(player) ? PS(player) : player; // because non-player entities can fire, but can they have items? TODO - if((player.items & ITEM_Strength.m_itemid) + if ((player.items & ITEM_Strength.m_itemid) && ((time > store.prevstrengthsound + autocvar_sv_strengthsound_antispam_time) // prevent insane sound spam - || (time > store.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold))) - { - sound(player, CH_TRIGGER, SND_STRENGTH_FIRE, VOL_BASE, ATTEN_NORM); - store.prevstrengthsound = time; - } - store.prevstrengthsoundattempt = time; + || (time > store.prevstrengthsoundattempt + autocvar_sv_strengthsound_antispam_refire_threshold))) { + sound(player, CH_TRIGGER, SND_STRENGTH_FIRE, VOL_BASE, ATTEN_NORM); + store.prevstrengthsound = time; + } + store.prevstrengthsoundattempt = time; } float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float exception) @@ -43,37 +42,32 @@ float W_CheckProjectileDamage(entity inflictor, entity projowner, int deathtype, float is_from_owner = (inflictor == projowner); float is_from_exception = (exception != -1); - //dprint(strcat("W_CheckProjectileDamage: from_contents ", ftos(is_from_contents), " : from_owner ", ftos(is_from_owner), " : exception ", strcat(ftos(is_from_exception), " (", ftos(exception), "). \n"))); + // dprint(strcat("W_CheckProjectileDamage: from_contents ", ftos(is_from_contents), " : from_owner ", ftos(is_from_owner), " : exception ", strcat(ftos(is_from_exception), " (", ftos(exception), "). \n"))); - if(autocvar_g_projectiles_damage <= -2) - { - return false; // no damage to projectiles at all, not even with the exceptions - } - else if(autocvar_g_projectiles_damage == -1) - { - if(is_from_exception) - return (exception); // if exception is detected, allow it to override - else - return false; // otherwise, no other damage is allowed - } - else if(autocvar_g_projectiles_damage == 0) - { - if(is_from_exception) - return (exception); // if exception is detected, allow it to override - else if(!is_from_contents) - return false; // otherwise, only allow damage from contents - } - else if(autocvar_g_projectiles_damage == 1) - { - if(is_from_exception) - return (exception); // if exception is detected, allow it to override - else if(!(is_from_contents || is_from_owner)) - return false; // otherwise, only allow self damage and damage from contents - } - else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions - { - if(is_from_exception) - return (exception); // if exception is detected, allow it to override + if (autocvar_g_projectiles_damage <= -2) { + return false; // no damage to projectiles at all, not even with the exceptions + } else if (autocvar_g_projectiles_damage == -1) { + if (is_from_exception) { + return exception; // if exception is detected, allow it to override + } else { + return false; // otherwise, no other damage is allowed + } + } else if (autocvar_g_projectiles_damage == 0) { + if (is_from_exception) { + return exception; // if exception is detected, allow it to override + } else if (!is_from_contents) { + return false; // otherwise, only allow damage from contents + } + } else if (autocvar_g_projectiles_damage == 1) { + if (is_from_exception) { + return exception; // if exception is detected, allow it to override + } else if (!(is_from_contents || is_from_owner)) { + return false; // otherwise, only allow self damage and damage from contents + } + } else if (autocvar_g_projectiles_damage == 2) { // allow any damage, but override for exceptions + if (is_from_exception) { + return exception; // if exception is detected, allow it to override + } } return true; // if none of these return, then allow damage anyway. @@ -86,8 +80,7 @@ void W_PrepareExplosionByDamage(entity this, entity attacker, void(entity this) MUTATOR_CALLHOOK(PrepareExplosionByDamage, this, attacker); - if(IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner) - { + if (IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner) { this.owner = attacker; this.realowner = attacker; } diff --git a/qcsrc/server/weapons/common.qh b/qcsrc/server/weapons/common.qh index 363941b3a..8bde1a0e2 100644 --- a/qcsrc/server/weapons/common.qh +++ b/qcsrc/server/weapons/common.qh @@ -1,6 +1,6 @@ #pragma once -void W_GiveWeapon (entity e, float wep); +void W_GiveWeapon(entity e, float wep); .float prevstrengthsound; .float prevstrengthsoundattempt; void W_PlayStrengthSound(entity player); diff --git a/qcsrc/server/weapons/hitplot.qc b/qcsrc/server/weapons/hitplot.qc index fb13bd1b9..32eb5dffd 100644 --- a/qcsrc/server/weapons/hitplot.qc +++ b/qcsrc/server/weapons/hitplot.qc @@ -27,23 +27,23 @@ vector W_HitPlotNormalizedUntransform(vector org, entity targ, vector screenforw // x = 0..1 relative to hitbox; y = 0..1 relative to hitbox; z = distance mi = ma = targ.origin + 0.5 * (targ.mins + targ.maxs); - for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k) - { - thisv = targ.origin; - if(i) thisv.x += targ.maxs.x; else thisv.x += targ.mins.x; - if(j) thisv.y += targ.maxs.y; else thisv.y += targ.mins.y; - if(k) thisv.z += targ.maxs.z; else thisv.z += targ.mins.z; - thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, thisv); - if(i || j || k) - { - if(mi.x > thisv.x) mi.x = thisv.x; if(ma.x < thisv.x) ma.x = thisv.x; - if(mi.y > thisv.y) mi.y = thisv.y; if(ma.y < thisv.y) ma.y = thisv.y; - //if(mi_z > thisv_z) mi_z = thisv_z; if(ma_z < thisv_z) ma_y = thisv_z; - } - else - { - // first run - mi = ma = thisv; + for (i = 0; i < 2; ++i) { + for (j = 0; j < 2; ++j) { + for (k = 0; k < 2; ++k) { + thisv = targ.origin; + if (i) { thisv.x += targ.maxs.x; } else { thisv.x += targ.mins.x; } + if (j) { thisv.y += targ.maxs.y; } else { thisv.y += targ.mins.y; } + if (k) { thisv.z += targ.maxs.z; } else { thisv.z += targ.mins.z; } + thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, thisv); + if (i || j || k) { + if (mi.x > thisv.x) { mi.x = thisv.x; } if (ma.x < thisv.x) { ma.x = thisv.x; } + if (mi.y > thisv.y) { mi.y = thisv.y; } if (ma.y < thisv.y) { ma.y = thisv.y; } + // if(mi_z > thisv_z) mi_z = thisv_z; if(ma_z < thisv_z) ma_y = thisv_z; + } else { + // first run + mi = ma = thisv; + } + } } } @@ -56,42 +56,38 @@ vector W_HitPlotNormalizedUntransform(vector org, entity targ, vector screenforw void W_HitPlotAnalysis(entity player, .entity weaponentity, vector screenforward, vector screenright, vector screenup) { - if(CS(player).hitplotfh >= 0) - { + if (CS(player).hitplotfh >= 0) { float lag = ANTILAG_LATENCY(player); - if(lag < 0.001) + if (lag < 0.001) { lag = 0; - if(!IS_REAL_CLIENT(player)) + } + if (!IS_REAL_CLIENT(player)) { lag = 0; // only antilag for clients - + } vector org = player.origin + player.view_ofs; traceline_antilag_force(player, org, org + screenforward * max_shot_distance, MOVE_NORMAL, player, lag); - if(IS_CLIENT(trace_ent) || IS_MONSTER(trace_ent)) - { - entity store = IS_CLIENT(trace_ent) ? CS(trace_ent) : trace_ent; + if (IS_CLIENT(trace_ent) || IS_MONSTER(trace_ent)) { + entity store = IS_CLIENT(trace_ent) ? CS(trace_ent) : trace_ent; antilag_takeback(trace_ent, store, time - lag); vector hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos); antilag_restore(trace_ent, store); fputs(CS(player).hitplotfh, strcat(ftos(hitplot.x), " ", ftos(hitplot.y), " ", ftos(hitplot.z), " ", ftos(player.(weaponentity).m_switchweapon.m_id), "\n")); - //print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n")); + // print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n")); } } } void W_HitPlotOpen(entity player) { - if(autocvar_g_hitplots || strhasword(autocvar_g_hitplots_individuals, player.netaddress)) - { + if (autocvar_g_hitplots || strhasword(autocvar_g_hitplots_individuals, player.netaddress)) { CS(player).hitplotfh = fopen(strcat("hits-", matchid, "-", player.netaddress, "-", ftos(player.playerid), ".plot"), FILE_WRITE); fputs(CS(player).hitplotfh, strcat("#name ", playername(player, false), "\n")); - } - else { CS(player).hitplotfh = -1; } + } else { CS(player).hitplotfh = -1; } } void W_HitPlotClose(entity player) { - if(CS(player).hitplotfh >= 0) - { + if (CS(player).hitplotfh >= 0) { fclose(CS(player).hitplotfh); CS(player).hitplotfh = -1; } diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index 776d8d8d0..4a838ba7f 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -22,11 +22,12 @@ void Send_WeaponComplain(entity e, float wpn, float type) void Weapon_whereis(Weapon this, entity cl) { - if (!autocvar_g_showweaponspawns) return; + if (!autocvar_g_showweaponspawns) { return; } IL_EACH(g_items, it.weapon == this.m_id && (!it.team || (it.ItemStatus & ITS_AVAILABLE)), { - if (it.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2) + if (it.classname == "droppedweapon" && autocvar_g_showweaponspawns < 2) { continue; + } entity wp = WaypointSprite_Spawn( WP_Weapon, -2, 0, @@ -44,78 +45,73 @@ bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andam { float f = 0; - if (time < CS(this).hasweapon_complain_spam) + if (time < CS(this).hasweapon_complain_spam) { complain = 0; + } // ignore hook button when using other offhand equipment - if (this.offhand != OFFHAND_HOOK) - if (wpn == WEP_HOOK && !((this.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) - complain = 0; + if (this.offhand != OFFHAND_HOOK) { + if (wpn == WEP_HOOK && !((this.weapons | weaponsInMap) & WepSet_FromWeapon(wpn))) { + complain = 0; + } + } - if (complain) + if (complain) { CS(this).hasweapon_complain_spam = time + 0.2; + } - if (wpn == WEP_Null) - { - if (complain) + if (wpn == WEP_Null) { + if (complain) { sprint(this, "Invalid weapon\n"); + } return false; } - if (autocvar_g_weaponswitch_debug == 2 && weaponslot(weaponentity) > 0 && !(wpn.spawnflags & WEP_FLAG_DUALWIELD) && !(PS(this).dual_weapons & wpn.m_wepset)) + if (autocvar_g_weaponswitch_debug == 2 && weaponslot(weaponentity) > 0 && !(wpn.spawnflags & WEP_FLAG_DUALWIELD) && !(PS(this).dual_weapons & wpn.m_wepset)) { return false; // no complaints needed - if (this.weapons & WepSet_FromWeapon(wpn)) - { - if (andammo) - { - if(this.items & IT_UNLIMITED_WEAPON_AMMO) - { + } + if (this.weapons & WepSet_FromWeapon(wpn)) { + if (andammo) { + if (this.items & IT_UNLIMITED_WEAPON_AMMO) { f = 1; - } - else - { + } else { f = wpn.wr_checkammo1(wpn, this, weaponentity) + wpn.wr_checkammo2(wpn, this, weaponentity); // always allow selecting the Mine Layer if we placed mines, so that we can detonate them - if(wpn == WEP_MINE_LAYER) + if (wpn == WEP_MINE_LAYER) { IL_EACH(g_mines, it.owner == this && it.weaponentity_fld == weaponentity, { f = 1; break; // no need to continue }); + } } - if (!f) - { - if (complain) - if(IS_REAL_CLIENT(this)) - { - play2(this, SND(UNAVAILABLE)); - Send_WeaponComplain (this, wpn.m_id, 0); + if (!f) { + if (complain) { + if (IS_REAL_CLIENT(this)) { + play2(this, SND(UNAVAILABLE)); + Send_WeaponComplain(this, wpn.m_id, 0); + } } return false; } } return true; } - if (complain) - { + if (complain) { // DRESK - 3/16/07 // Report Proper Weapon Status / Modified Weapon Ownership Message - if (weaponsInMap & WepSet_FromWeapon(wpn)) - { + if (weaponsInMap & WepSet_FromWeapon(wpn)) { Send_WeaponComplain(this, wpn.m_id, 1); - if(autocvar_g_showweaponspawns < 3) + if (autocvar_g_showweaponspawns < 3) { Weapon_whereis(wpn, this); - else - { + } else { FOREACH(Weapons, it.impulse == wpn.impulse, { Weapon_whereis(it, this); }); } - } - else - { - Send_WeaponComplain (this, wpn.m_id, 2); + } else { + Send_WeaponComplain(this, wpn.m_id, 2); } play2(this, SND(UNAVAILABLE)); @@ -134,99 +130,116 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl float weaponcur; entity wep; - if(skipmissing || this.(weaponentity).selectweapon == 0) + if (skipmissing || this.(weaponentity).selectweapon == 0) { weaponcur = this.(weaponentity).m_switchweapon.m_id; - else + } else { weaponcur = this.(weaponentity).selectweapon; + } - if(dir == 0) + if (dir == 0) { switchtonext = 1; + } int c = 0; string rest = weaponorder; - while(rest != "") - { - weaponwant = stof(car(rest)); rest = cdr(rest); + while (rest != "") { + weaponwant = stof(car(rest)); + rest = cdr(rest); wep = Weapons_from(weaponwant); wepset = wep.m_wepset; - if(imp >= 0) - if(wep.impulse != imp) - continue; + if (imp >= 0) { + if (wep.impulse != imp) { + continue; + } + } bool have_other = false; FOREACH(Weapons, it != WEP_Null, { - if(i != weaponwant) - if(it.impulse == imp || imp < 0) - if((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) - have_other = true; + if (i != weaponwant) { + if (it.impulse == imp || imp < 0) { + if ((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) { + have_other = true; + } + } + } }); // skip weapons we don't own that aren't normal and aren't in the map - if(!(this.weapons & wepset)) - if(!(weaponsInMap & wepset)) - if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) - continue; + if (!(this.weapons & wepset)) { + if (!(weaponsInMap & wepset)) { + if ((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) { + continue; + } + } + } ++c; - if(!skipmissing || client_hasweapon(this, wep, weaponentity, true, false)) - { - if(switchtonext) + if (!skipmissing || client_hasweapon(this, wep, weaponentity, true, false)) { + if (switchtonext) { return weaponwant; - if(!first_valid) + } + if (!first_valid) { first_valid = weaponwant; - if(weaponwant == weaponcur) - { - if(dir >= 0) + } + if (weaponwant == weaponcur) { + if (dir >= 0) { switchtonext = 1; - else if(prev_valid) + } else if (prev_valid) { return prev_valid; - else + } else { switchtolast = 1; + } } prev_valid = weaponwant; } } - if(first_valid) - { - if(switchtolast) + if (first_valid) { + if (switchtolast) { return prev_valid; - else + } else { return first_valid; + } } // complain (but only for one weapon on the button that has been pressed) - if(complain) - { + if (complain) { this.weaponcomplainindex += 1; c = (this.weaponcomplainindex % c) + 1; rest = weaponorder; - while(rest != "") - { - weaponwant = stof(car(rest)); rest = cdr(rest); + while (rest != "") { + weaponwant = stof(car(rest)); + rest = cdr(rest); wep = Weapons_from(weaponwant); wepset = wep.m_wepset; - if(imp >= 0) - if(wep.impulse != imp) + if (imp >= 0) { + if (wep.impulse != imp) { continue; + } + } bool have_other = false; FOREACH(Weapons, it != WEP_Null, { - if(i != weaponwant) - if(it.impulse == imp || imp < 0) - if((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) - have_other = true; + if (i != weaponwant) { + if (it.impulse == imp || imp < 0) { + if ((this.weapons & (it.m_wepset)) || (weaponsInMap & (it.m_wepset))) { + have_other = true; + } + } + } }); // skip weapons we don't own that aren't normal and aren't in the map - if(!(this.weapons & wepset)) - if(!(weaponsInMap & wepset)) - if((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) - continue; + if (!(this.weapons & wepset)) { + if (!(weaponsInMap & wepset)) { + if ((wep.spawnflags & WEP_FLAG_MUTATORBLOCKED) || have_other) { + continue; + } + } + } --c; - if(c == 0) - { + if (c == 0) { client_hasweapon(this, wep, weaponentity, true, true); break; } @@ -237,7 +250,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl void W_SwitchWeapon_Force(Player this, Weapon wep, .entity weaponentity) { - TC(Weapon, wep); + TC(Weapon, wep); this.(weaponentity).cnt = this.(weaponentity).m_switchweapon.m_id; this.(weaponentity).m_switchweapon = wep; this.(weaponentity).selectweapon = wep.m_id; @@ -249,31 +262,26 @@ void W_SwitchToOtherWeapon(entity this, .entity weaponentity) // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway) Weapon ww; WepSet set = WepSet_FromWeapon(this.(weaponentity).m_weapon); - if (this.weapons & set) - { + if (this.weapons & set) { this.weapons &= ~set; ww = w_getbestweapon(this, weaponentity); this.weapons |= set; - } - else - { + } else { ww = w_getbestweapon(this, weaponentity); } - if (ww == WEP_Null) return; + if (ww == WEP_Null) { return; } W_SwitchWeapon_Force(this, ww, weaponentity); } void W_SwitchWeapon(entity this, Weapon w, .entity weaponentity) { - if(this.(weaponentity).m_switchweapon != w) - { - if(client_hasweapon(this, w, weaponentity, true, true)) + if (this.(weaponentity).m_switchweapon != w) { + if (client_hasweapon(this, w, weaponentity, true, true)) { W_SwitchWeapon_Force(this, w, weaponentity); - else + } else { this.(weaponentity).selectweapon = w.m_id; // update selectweapon anyway - } - else if(!forbidWeaponUse(this)) - { + } + } else if (!forbidWeaponUse(this)) { entity actor = this; w.wr_reload(w, actor, weaponentity); } @@ -283,46 +291,51 @@ void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponent { float w; w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true, weaponentity); - if(w > 0) + if (w > 0) { W_SwitchWeapon(this, Weapons_from(w), weaponentity); + } } void W_NextWeaponOnImpulse(entity this, float imp, .entity weaponentity) { float w; w = W_GetCycleWeapon(this, CS(this).cvar_cl_weaponpriority, +1, imp, 1, (CS(this).cvar_cl_weaponimpulsemode == 0), weaponentity); - if(w > 0) + if (w > 0) { W_SwitchWeapon(this, Weapons_from(w), weaponentity); + } } // next weapon void W_NextWeapon(entity this, int list, .entity weaponentity) { - if(list == 0) + if (list == 0) { W_CycleWeapon(this, weaponorder_byid, -1, weaponentity); - else if(list == 1) + } else if (list == 1) { W_CycleWeapon(this, this.weaponorder_byimpulse, -1, weaponentity); - else if(list == 2) + } else if (list == 2) { W_CycleWeapon(this, CS(this).cvar_cl_weaponpriority, -1, weaponentity); + } } // prev weapon void W_PreviousWeapon(entity this, float list, .entity weaponentity) { - if(list == 0) + if (list == 0) { W_CycleWeapon(this, weaponorder_byid, +1, weaponentity); - else if(list == 1) + } else if (list == 1) { W_CycleWeapon(this, this.weaponorder_byimpulse, +1, weaponentity); - else if(list == 2) + } else if (list == 2) { W_CycleWeapon(this, CS(this).cvar_cl_weaponpriority, +1, weaponentity); + } } // previously used if exists and has ammo, (second) best otherwise void W_LastWeapon(entity this, .entity weaponentity) { Weapon wep = Weapons_from(this.(weaponentity).cnt); - if (client_hasweapon(this, wep, weaponentity, true, false)) + if (client_hasweapon(this, wep, weaponentity, true, false)) { W_SwitchWeapon(this, wep, weaponentity); - else + } else { W_SwitchToOtherWeapon(this, weaponentity); + } } diff --git a/qcsrc/server/weapons/selection.qh b/qcsrc/server/weapons/selection.qh index eea33ddb7..16ceb2274 100644 --- a/qcsrc/server/weapons/selection.qh +++ b/qcsrc/server/weapons/selection.qh @@ -12,7 +12,7 @@ bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andam .int weaponcomplainindex; float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing, .entity weaponentity); -#define w_getbestweapon(ent,wepent) Weapons_from(W_GetCycleWeapon(ent, CS(ent).cvar_cl_weaponpriority, 0, -1, false, true, wepent)) +#define w_getbestweapon(ent, wepent) Weapons_from(W_GetCycleWeapon(ent, CS(ent).cvar_cl_weaponpriority, 0, -1, false, true, wepent)) void W_SwitchWeapon_Force(Player this, Weapon w, .entity weaponentity); diff --git a/qcsrc/server/weapons/tracing.qh b/qcsrc/server/weapons/tracing.qh index 3fa16d654..502f0ba85 100644 --- a/qcsrc/server/weapons/tracing.qh +++ b/qcsrc/server/weapons/tracing.qh @@ -12,11 +12,11 @@ vector w_shotend; // make sure you call makevectors first (FIXME?) void W_SetupShot_Dir_ProjectileSize_Range(entity ent, .entity weaponentity, vector s_forward, vector mi, vector ma, float antilag, float recoil, Sound snd, float chan, float maxdamage, float range); -#define W_SetupShot_Dir_ProjectileSize(ent,wepent,s_forward,mi,ma,antilag,recoil,snd,chan,maxdamage) W_SetupShot_Dir_ProjectileSize_Range(ent, wepent, s_forward, mi, ma, antilag, recoil, snd, chan, maxdamage, max_shot_distance) -#define W_SetupShot_ProjectileSize(ent,wepent,mi,ma,antilag,recoil,snd,chan,maxdamage) W_SetupShot_Dir_ProjectileSize(ent, wepent, v_forward, mi, ma, antilag, recoil, snd, chan, maxdamage) -#define W_SetupShot_Dir(ent,wepent,s_forward,antilag,recoil,snd,chan,maxdamage) W_SetupShot_Dir_ProjectileSize(ent, wepent, s_forward, '0 0 0', '0 0 0', antilag, recoil, snd, chan, maxdamage) -#define W_SetupShot(ent,wepent,antilag,recoil,snd,chan,maxdamage) W_SetupShot_ProjectileSize(ent, wepent, '0 0 0', '0 0 0', antilag, recoil, snd, chan, maxdamage) -#define W_SetupShot_Range(ent,wepent,antilag,recoil,snd,chan,maxdamage,range) W_SetupShot_Dir_ProjectileSize_Range(ent, wepent, v_forward, '0 0 0', '0 0 0', antilag, recoil, snd, chan, maxdamage, range) +#define W_SetupShot_Dir_ProjectileSize(ent, wepent, s_forward, mi, ma, antilag, recoil, snd, chan, maxdamage) W_SetupShot_Dir_ProjectileSize_Range(ent, wepent, s_forward, mi, ma, antilag, recoil, snd, chan, maxdamage, max_shot_distance) +#define W_SetupShot_ProjectileSize(ent, wepent, mi, ma, antilag, recoil, snd, chan, maxdamage) W_SetupShot_Dir_ProjectileSize(ent, wepent, v_forward, mi, ma, antilag, recoil, snd, chan, maxdamage) +#define W_SetupShot_Dir(ent, wepent, s_forward, antilag, recoil, snd, chan, maxdamage) W_SetupShot_Dir_ProjectileSize(ent, wepent, s_forward, '0 0 0', '0 0 0', antilag, recoil, snd, chan, maxdamage) +#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage) W_SetupShot_ProjectileSize(ent, wepent, '0 0 0', '0 0 0', antilag, recoil, snd, chan, maxdamage) +#define W_SetupShot_Range(ent, wepent, antilag, recoil, snd, chan, maxdamage, range) W_SetupShot_Dir_ProjectileSize_Range(ent, wepent, v_forward, '0 0 0', '0 0 0', antilag, recoil, snd, chan, maxdamage, range) vector W_CalculateProjectileVelocity(entity actor, vector pvelocity, vector mvelocity, float forceAbsolute); @@ -28,23 +28,21 @@ float mspercallcount; void W_SetupProjVelocity_Explicit(entity proj, vector dir, vector upDir, float pSpeed, float pUpSpeed, float pZSpeed, float spread, float forceAbsolute); -#define W_SetupProjVelocity_Basic(ent,pspeed,pspread) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, pspeed, 0, 0, pspread, false) +#define W_SetupProjVelocity_Basic(ent, pspeed, pspread) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, pspeed, 0, 0, pspread, false) -#define W_SetupProjVelocity_UP_PRE(ent,wepname,prefix) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR(wepname, prefix##speed), WEP_CVAR(wepname, prefix##speed_up), WEP_CVAR(wepname, prefix##speed_z), WEP_CVAR(wepname, prefix##spread), false) -#define W_SetupProjVelocity_UP_PRI(ent,wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_PRI(wepname, speed), WEP_CVAR_PRI(wepname, speed_up), WEP_CVAR_PRI(wepname, speed_z), WEP_CVAR_PRI(wepname, spread), false) -#define W_SetupProjVelocity_UP_SEC(ent,wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_SEC(wepname, speed), WEP_CVAR_SEC(wepname, speed_up), WEP_CVAR_SEC(wepname, speed_z), WEP_CVAR_SEC(wepname, spread), false) +#define W_SetupProjVelocity_UP_PRE(ent, wepname, prefix) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR(wepname, prefix##speed), WEP_CVAR(wepname, prefix##speed_up), WEP_CVAR(wepname, prefix##speed_z), WEP_CVAR(wepname, prefix##spread), false) +#define W_SetupProjVelocity_UP_PRI(ent, wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_PRI(wepname, speed), WEP_CVAR_PRI(wepname, speed_up), WEP_CVAR_PRI(wepname, speed_z), WEP_CVAR_PRI(wepname, spread), false) +#define W_SetupProjVelocity_UP_SEC(ent, wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_SEC(wepname, speed), WEP_CVAR_SEC(wepname, speed_up), WEP_CVAR_SEC(wepname, speed_z), WEP_CVAR_SEC(wepname, spread), false) -#define W_SetupProjVelocity_UP_BOTH(ent,wepname,isprimary) \ - if(isprimary) { W_SetupProjVelocity_UP_PRI(ent, wepname); } \ - else { W_SetupProjVelocity_UP_SEC(ent, wepname); } +#define W_SetupProjVelocity_UP_BOTH(ent, wepname, isprimary) \ + if (isprimary) { W_SetupProjVelocity_UP_PRI(ent, wepname); } else { W_SetupProjVelocity_UP_SEC(ent, wepname); } -#define W_SetupProjVelocity_PRE(ent,wepname,prefix) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR(wepname, prefix##speed), 0, 0, WEP_CVAR(wepname, prefix##spread), false) -#define W_SetupProjVelocity_PRI(ent,wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_PRI(wepname, speed), 0, 0, WEP_CVAR_PRI(wepname, spread), false) -#define W_SetupProjVelocity_SEC(ent,wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_SEC(wepname, speed), 0, 0, WEP_CVAR_SEC(wepname, spread), false) +#define W_SetupProjVelocity_PRE(ent, wepname, prefix) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR(wepname, prefix##speed), 0, 0, WEP_CVAR(wepname, prefix##spread), false) +#define W_SetupProjVelocity_PRI(ent, wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_PRI(wepname, speed), 0, 0, WEP_CVAR_PRI(wepname, spread), false) +#define W_SetupProjVelocity_SEC(ent, wepname) W_SetupProjVelocity_Explicit(ent, w_shotdir, v_up, WEP_CVAR_SEC(wepname, speed), 0, 0, WEP_CVAR_SEC(wepname, spread), false) -#define W_SetupProjVelocity_BOTH(ent,wepname,isprimary) \ - if(isprimary) { W_SetupProjVelocity_PRI(ent, wepname); } \ - else { W_SetupProjVelocity_SEC(ent, wepname); } +#define W_SetupProjVelocity_BOTH(ent, wepname, isprimary) \ + if (isprimary) { W_SetupProjVelocity_PRI(ent, wepname); } else { W_SetupProjVelocity_SEC(ent, wepname); } // ==================== // Ballistics Tracing @@ -52,7 +50,7 @@ void W_SetupProjVelocity_Explicit(entity proj, vector dir, vector upDir, float p .float railgundistance; .vector railgunforce; -void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector end, float bdamage, float bforce, float mindist, float maxdist, float halflifedist, float forcehalflifedist, int deathtype); +void FireRailgunBullet(entity this, .entity weaponentity, vector start, vector end, float bdamage, float bforce, float mindist, float maxdist, float halflifedist, float forcehalflifedist, int deathtype); entity fireBullet_trace_callback_eff; entity fireBullet_last_hit; diff --git a/qcsrc/server/weapons/weaponstats.qc b/qcsrc/server/weapons/weaponstats.qc index 296d10fa6..0130482d4 100644 --- a/qcsrc/server/weapons/weaponstats.qc +++ b/qcsrc/server/weapons/weaponstats.qc @@ -16,8 +16,7 @@ void WeaponStats_ready(entity fh, entity pass, float status) float i, j, n, ibot, jbot, idx; vector v; string prefix, s; - switch(status) - { + switch (status) { case URL_READY_CANWRITE: // we can write prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t"); @@ -29,20 +28,24 @@ void WeaponStats_ready(entity fh, entity pass, float status) url_fputs(fh, strcat("#config ", ftos(crc16(false, cvar_purechanges)), "\n")); url_fputs(fh, strcat("#cvar_purechanges ", ftos(cvar_purechanges_count), "\n")); n = tokenizebyseparator(cvar_purechanges, "\n"); - for(i = 0; i < n; ++i) + for (i = 0; i < n; ++i) { url_fputs(fh, strcat("#cvar_purechange ", argv(i), "\n")); - for(i = WEP_FIRST; i <= WEP_LAST; ++i) for(ibot = 0; ibot <= 1; ++ibot) - for(j = WEP_FIRST; j <= WEP_LAST; ++j) for(jbot = 0; jbot <= 1; ++jbot) - { - idx = WEAPONSTATS_GETINDEX(i, ibot, j, jbot); - v = stov(bufstr_get(weaponstats_buffer, idx)); - if(v != '0 0 0') - { - //vector is: kills hits damage - url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot)); - url_fputs(fh, sprintf("%d %d %g\n", v.x, v.y, v.z)); + } + for (i = WEP_FIRST; i <= WEP_LAST; ++i) { + for (ibot = 0; ibot <= 1; ++ibot) { + for (j = WEP_FIRST; j <= WEP_LAST; ++j) { + for (jbot = 0; jbot <= 1; ++jbot) { + idx = WEAPONSTATS_GETINDEX(i, ibot, j, jbot); + v = stov(bufstr_get(weaponstats_buffer, idx)); + if (v != '0 0 0') { + // vector is: kills hits damage + url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot)); + url_fputs(fh, sprintf("%d %d %g\n", v.x, v.y, v.z)); + } + } } } + } url_fputs(fh, "#end\n\n"); url_fclose(fh); break; @@ -50,8 +53,9 @@ void WeaponStats_ready(entity fh, entity pass, float status) // url_fclose is processing, we got a response for writing the data // this must come from HTTP LOG_INFO("Got response from weapon stats server:"); - while((s = url_fgets(fh))) + while ((s = url_fgets(fh))) { LOG_INFO(" ", s); + } LOG_INFO("End of response."); url_fclose(fh); break; @@ -72,14 +76,12 @@ void WeaponStats_ready(entity fh, entity pass, float status) void WeaponStats_Shutdown() { - if(weaponstats_buffer < 0) + if (weaponstats_buffer < 0) { return; - if(autocvar_sv_weaponstats_file != "") - { - url_multi_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, NULL); } - else - { + if (autocvar_sv_weaponstats_file != "") { + url_multi_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, NULL); + } else { buf_del(weaponstats_buffer); weaponstats_buffer = -1; } @@ -88,20 +90,24 @@ void WeaponStats_Shutdown() void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector item) { float idx; - if(weaponstats_buffer < 0) + if (weaponstats_buffer < 0) { return; - if(awep < WEP_FIRST || vwep < WEP_FIRST) + } + if (awep < WEP_FIRST || vwep < WEP_FIRST) { return; - if(awep > WEP_LAST || vwep > WEP_LAST) + } + if (awep > WEP_LAST || vwep > WEP_LAST) { return; - idx = WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot); + } + idx = WEAPONSTATS_GETINDEX(awep, abot, vwep, vbot); bufstr_set(weaponstats_buffer, idx, vtos(stov(bufstr_get(weaponstats_buffer, idx)) + item)); } void WeaponStats_LogDamage(float awep, float abot, float vwep, float vbot, float damage) { - if(damage < 0) + if (damage < 0) { error("negative damage?"); + } WeaponStats_LogItem(awep, abot, vwep, vbot, '0 0 1' * damage + '0 1 0'); } diff --git a/qcsrc/server/weapons/weaponstats.qh b/qcsrc/server/weapons/weaponstats.qh index f031223e7..8bb0a8b45 100644 --- a/qcsrc/server/weapons/weaponstats.qh +++ b/qcsrc/server/weapons/weaponstats.qh @@ -9,4 +9,4 @@ void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector void WeaponStats_LogDamage(float awep, float abot, float vwep, float vbot, float damage); void WeaponStats_LogKill(float awep, float abot, float vwep, float vbot); -#define WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot) (((vwep) + (awep) * (WEP_LAST - WEP_FIRST + 1) - (WEP_FIRST + WEP_FIRST * (WEP_LAST - WEP_FIRST + 1))) * 4 + (abot) * 2 + (vbot)) +#define WEAPONSTATS_GETINDEX(awep, abot, vwep, vbot) (((vwep) + (awep) * (WEP_LAST - WEP_FIRST + 1) - (WEP_FIRST + WEP_FIRST * (WEP_LAST - WEP_FIRST + 1))) * 4 + (abot) * 2 + (vbot)) -- 2.39.2