From 3514dfab68ace0fd00b3df1993b8773868b1a6a3 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 6 Sep 2018 05:05:56 +1000 Subject: [PATCH] First part of a fix for untranslated item ammo names on drop: hack the item name handling into notifications system (not translated currently) --- qcsrc/common/notifications/all.inc | 4 ++-- qcsrc/common/notifications/all.qh | 23 ++++++++++++++++++-- qcsrc/server/miscfunctions.qh | 2 ++ qcsrc/server/weapons/throwing.qc | 34 +++++++++--------------------- qcsrc/server/weapons/throwing.qh | 4 ++-- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/qcsrc/common/notifications/all.inc b/qcsrc/common/notifications/all.inc index db0e0503f..a01718afd 100644 --- a/qcsrc/common/notifications/all.inc +++ b/qcsrc/common/notifications/all.inc @@ -380,7 +380,7 @@ MSG_INFO_NOTIF(ITEM_BUFF_GOT, N_CONSOLE, 0, 1, "item_buffname", "", "", _("^BGYou got the %s^BG buff!"), "") MSG_INFO_NOTIF(ITEM_WEAPON_DONTHAVE, N_DISABLE, 0, 1, "item_wepname", "", "", _("^BGYou do not have the ^F1%s"), "") - MSG_INFO_NOTIF(ITEM_WEAPON_DROP, N_DISABLE, 1, 1, "item_wepname item_wepammo", "", "", _("^BGYou dropped the ^F1%s^BG%s"), "") + MSG_INFO_NOTIF(ITEM_WEAPON_DROP, N_DISABLE, 0, 2, "item_wepname item_wepammo", "", "", _("^BGYou dropped the ^F1%s^BG%s"), "") MSG_INFO_NOTIF(ITEM_WEAPON_GOT, N_DISABLE, 0, 1, "item_wepname", "", "", _("^BGYou got the ^F1%s"), "") MSG_INFO_NOTIF(ITEM_WEAPON_NOAMMO, N_DISABLE, 0, 1, "item_wepname", "", "", _("^BGYou don't have enough ammo for the ^F1%s"), "") MSG_INFO_NOTIF(ITEM_WEAPON_PRIMORSEC, N_DISABLE, 0, 3, "item_wepname f2primsec f3primsec", "", "", _("^F1%s %s^BG is unable to fire, but its ^F1%s^BG can"), "") @@ -698,7 +698,7 @@ MSG_CENTER_NOTIF(ITEM_FUELREGEN_GOT, N_ENABLE, 0, 0, "", CPID_ITEM, "item_centime 0", _("^BGYou got the ^F1Fuel regenerator"), "") MSG_CENTER_NOTIF(ITEM_JETPACK_GOT, N_ENABLE, 0, 0, "", CPID_ITEM, "item_centime 0", _("^BGYou got the ^F1Jetpack"), "") MSG_CENTER_NOTIF(ITEM_WEAPON_DONTHAVE, N_ENABLE, 0, 1, "item_wepname", CPID_ITEM, "item_centime 0", _("^BGYou do not have the ^F1%s"), "") - MSG_CENTER_NOTIF(ITEM_WEAPON_DROP, N_ENABLE, 1, 1, "item_wepname item_wepammo", CPID_ITEM, "item_centime 0", _("^BGYou dropped the ^F1%s^BG%s"), "") + MSG_CENTER_NOTIF(ITEM_WEAPON_DROP, N_ENABLE, 0, 2, "item_wepname item_wepammo", CPID_ITEM, "item_centime 0", _("^BGYou dropped the ^F1%s^BG%s"), "") MSG_CENTER_NOTIF(ITEM_WEAPON_GOT, N_ENABLE, 0, 1, "item_wepname", CPID_ITEM, "item_centime 0", _("^BGYou got the ^F1%s"), "") MSG_CENTER_NOTIF(ITEM_WEAPON_NOAMMO, N_ENABLE, 0, 1, "item_wepname", CPID_ITEM, "item_centime 0", _("^BGYou don't have enough ammo for the ^F1%s"), "") MSG_CENTER_NOTIF(ITEM_WEAPON_PRIMORSEC, N_ENABLE, 0, 3, "item_wepname f2primsec f3primsec", CPID_ITEM, "item_centime 0", _("^F1%s %s^BG is unable to fire, but its ^F1%s^BG can"), "") diff --git a/qcsrc/common/notifications/all.qh b/qcsrc/common/notifications/all.qh index 7982ee01f..5a2adba1c 100644 --- a/qcsrc/common/notifications/all.qh +++ b/qcsrc/common/notifications/all.qh @@ -370,7 +370,7 @@ float autocvar_notification_show_sprees_center_specialonly = true; spree_end: placed at the end of murder messages to show ending of sprees spree_lost: placed at the end of suicide messages to show losing of sprees item_wepname: return full name of a weapon from weaponid - item_wepammo: ammo display for weapon from string + item_wepammo: ammo display for weapon from f1 item_centime: amount of time to display weapon message in centerprint item_buffname: return full name of a buff from buffid death_team: show the full name of the team a player is switching from @@ -433,7 +433,7 @@ string BUFF_NAME(int i); ARG_CASE(ARG_CS_SV, "item_wepname", Weapons_from(f1).m_name) \ ARG_CASE(ARG_CS_SV, "item_buffname", BUFF_NAME(f1)) \ ARG_CASE(ARG_CS_SV, "f3buffname", BUFF_NAME(f3)) \ - ARG_CASE(ARG_CS_SV, "item_wepammo", (s1 != "" ? sprintf(_(" with %s"), s1) : "")) \ + ARG_CASE(ARG_CS_SV, "item_wepammo", (f2 > 0 ? notif_arg_item_wepammo(f1, f2) : "")) \ ARG_CASE(ARG_DC, "item_centime", ftos(autocvar_notification_item_centerprinttime)) \ ARG_CASE(ARG_SV, "death_team", Team_ColoredFullName(f1)) \ ARG_CASE(ARG_CS, "death_team", Team_ColoredFullName(f1 - 1)) \ @@ -624,6 +624,25 @@ string notif_arg_spree_inf(float type, string input, string player, float spree) return ""; } +string notif_arg_item_wepammo(float f1, float f2) +{ + if(f2 <= 0) + return ""; + string ammoitems = ""; + Weapon wep = Weapons_from(f1); + switch (wep.ammo_type) + { + case RESOURCE_SHELLS: ammoitems = ITEM_Shells.m_name; break; + case RESOURCE_BULLETS: ammoitems = ITEM_Bullets.m_name; break; + case RESOURCE_ROCKETS: ammoitems = ITEM_Rockets.m_name; break; + case RESOURCE_CELLS: ammoitems = ITEM_Cells.m_name; break; + case RESOURCE_PLASMA: ammoitems = ITEM_Plasma.m_name; break; + case RESOURCE_FUEL: ammoitems = ITEM_JetpackFuel.m_name; break; + default: return ""; // doesn't use ammo + } + return sprintf(_(" with %d %s"), f2, ammoitems); +} + // ==================================== // Initialization/Create Declarations diff --git a/qcsrc/server/miscfunctions.qh b/qcsrc/server/miscfunctions.qh index ff62cd167..2374b4869 100644 --- a/qcsrc/server/miscfunctions.qh +++ b/qcsrc/server/miscfunctions.qh @@ -96,6 +96,8 @@ float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, f string NearestLocation(vector p); +string AmmoNameFromWeaponentity(Weapon wep); + void play2(entity e, string filename); string playername(entity p, bool team_colorize); diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 462af14d8..9aaabb05b 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -33,11 +33,9 @@ void thrown_wep_think(entity this) SUB_VanishOrRemove(this); } -// returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count -string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity) +// returns amount of ammo used, or -1 for failure, or 0 for no ammo count +float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity) { - float thisammo; - string s; Weapon info = Weapons_from(wpn); int ammotype = info.ammo_type; @@ -84,7 +82,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto weapon_defaultspawnfunc(wep, info); if(startitem_failed) - return string_null; + return -1; setthink(wep, thrown_wep_think); wep.savenextthink = wep.nextthink; wep.nextthink = min(wep.nextthink, time + 0.5); @@ -93,12 +91,10 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto //wa = W_AmmoItemCode(wpn); if(ammotype == RESOURCE_NONE) { - return ""; + return 0; } else { - s = ""; - if(doreduce && g_weapon_stay == 2) { // if our weapon is loaded, give its load back to the player @@ -121,23 +117,13 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto } float ownderammo = GetResourceAmount(own, ammotype); - thisammo = min(ownderammo, GetResourceAmount(wep, ammotype)); + float thisammo = min(ownderammo, GetResourceAmount(wep, ammotype)); SetResourceAmount(wep, ammotype, thisammo); SetResourceAmount(own, ammotype, ownderammo - thisammo); - switch (ammotype) - { - case RESOURCE_SHELLS: s = sprintf("%s and %d shells", s, thisammo); break; - case RESOURCE_BULLETS: s = sprintf("%s and %d nails", s, thisammo); break; - case RESOURCE_ROCKETS: s = sprintf("%s and %d rockets", s, thisammo); break; - case RESOURCE_CELLS: s = sprintf("%s and %d cells", s, thisammo); break; - case RESOURCE_PLASMA: s = sprintf("%s and %d plasma", s, thisammo); break; - case RESOURCE_FUEL: s = sprintf("%s and %d fuel", s, thisammo); break; - } - - s = substring(s, 5, -1); + return thisammo; } - return s; + return 0; } } @@ -175,10 +161,10 @@ void W_ThrowWeapon(entity this, .entity weaponentity, vector velo, vector delta, STAT(WEAPONS, this) &= ~set; W_SwitchWeapon_Force(this, w_getbestweapon(this, weaponentity), weaponentity); - string a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo, weaponentity); + float a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo, weaponentity); - if(!a) return; - Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, a, w.m_id); + if(a < 0) return; + Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, w.m_id, a); } void SpawnThrownWeapon(entity this, vector org, Weapon wep, .entity weaponentity) diff --git a/qcsrc/server/weapons/throwing.qh b/qcsrc/server/weapons/throwing.qh index 9ea5e5cb8..20732753e 100644 --- a/qcsrc/server/weapons/throwing.qh +++ b/qcsrc/server/weapons/throwing.qh @@ -6,8 +6,8 @@ .float savenextthink; void thrown_wep_think(entity this); -// returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count -string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity); +// returns amount of ammo used, or -1 for failure, or 0 for no ammo count +float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity); bool W_IsWeaponThrowable(entity this, int w); -- 2.39.2