From: TimePath Date: Mon, 24 Aug 2015 01:43:44 +0000 (+1000) Subject: Move itemstime to mutator X-Git-Tag: xonotic-v0.8.2~2042^2~7 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7af7b9e6d43acfaaa00758bd18501e8fea888903;p=xonotic%2Fxonotic-data.pk3dir.git Move itemstime to mutator --- diff --git a/qcsrc/common/mutators/mutator/itemstime.qc b/qcsrc/common/mutators/mutator/itemstime.qc index 122212dc2..329db6d16 100644 --- a/qcsrc/common/mutators/mutator/itemstime.qc +++ b/qcsrc/common/mutators/mutator/itemstime.qc @@ -21,3 +21,177 @@ MUTATOR_HOOKFUNCTION(itemstime, CSQC_Parse_TempEntity) { return true; } #endif + +#ifdef SVQC +float it_armor_large_time; +float it_health_mega_time; +float it_invisible_time; +float it_speed_time; +float it_extralife_time; +float it_strength_time; +float it_shield_time; +float it_fuelregen_time; +float it_jetpack_time; +float it_superweapons_time; + +void Item_ItemsTime_Init() +{ + it_armor_large_time = -1; + it_health_mega_time = -1; + it_invisible_time = -1; + it_speed_time = -1; + it_extralife_time = -1; + it_strength_time = -1; + it_shield_time = -1; + it_fuelregen_time = -1; + it_jetpack_time = -1; + it_superweapons_time = -1; +} + +STATIC_INIT(ItemsTime_Init) { + // items time + Item_ItemsTime_Init(); +} + +void Item_ItemsTime_ResetTimes() +{ + it_armor_large_time = (it_armor_large_time == -1) ? -1 : 0; + it_health_mega_time = (it_health_mega_time == -1) ? -1 : 0; + it_invisible_time = (it_invisible_time == -1) ? -1 : 0; + it_speed_time = (it_speed_time == -1) ? -1 : 0; + it_extralife_time = (it_extralife_time == -1) ? -1 : 0; + it_strength_time = (it_strength_time == -1) ? -1 : 0; + it_shield_time = (it_shield_time == -1) ? -1 : 0; + it_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0; + it_jetpack_time = (it_jetpack_time == -1) ? -1 : 0; + it_superweapons_time = (it_superweapons_time == -1) ? -1 : 0; +} + +void Item_ItemsTime_ResetTimesForPlayer(entity e) +{ + IT_Write(e, item_armor_large_time , (it_armor_large_time == -1) ? -1 : 0); + IT_Write(e, item_health_mega_time , (it_health_mega_time == -1) ? -1 : 0); + IT_Write(e, item_invisible_time , (it_invisible_time == -1) ? -1 : 0); + IT_Write(e, item_speed_time , (it_speed_time == -1) ? -1 : 0); + IT_Write(e, item_extralife_time , (it_extralife_time == -1) ? -1 : 0); + IT_Write(e, item_strength_time , (it_strength_time == -1) ? -1 : 0); + IT_Write(e, item_shield_time , (it_shield_time == -1) ? -1 : 0); + IT_Write(e, item_fuelregen_time , (it_fuelregen_time == -1) ? -1 : 0); + IT_Write(e, item_jetpack_time , (it_jetpack_time == -1) ? -1 : 0); + IT_Write(e, item_superweapons_time, (it_superweapons_time == -1) ? -1 : 0); +} + +void Item_ItemsTime_SetTimesForPlayer(entity e) +{ + IT_Write(e, item_armor_large_time , it_armor_large_time ); + IT_Write(e, item_health_mega_time , it_health_mega_time ); + IT_Write(e, item_invisible_time , it_invisible_time ); + IT_Write(e, item_speed_time , it_speed_time ); + IT_Write(e, item_extralife_time , it_extralife_time ); + IT_Write(e, item_strength_time , it_strength_time ); + IT_Write(e, item_shield_time , it_shield_time ); + IT_Write(e, item_fuelregen_time , it_fuelregen_time ); + IT_Write(e, item_jetpack_time , it_jetpack_time ); + IT_Write(e, item_superweapons_time, it_superweapons_time); +} + +void Item_ItemsTime_SetTime(entity e, float t) +{ + if (!autocvar_sv_itemstime) + return; + + if (g_instagib) + { + switch (e.items) + { + case IT_STRENGTH://"item-invis" + it_invisible_time = t; + break; + case IT_NAILS://"item-extralife" + it_extralife_time = t; + break; + case IT_INVINCIBLE://"item-speed" + it_speed_time = t; + break; + } + } + else + { + switch (e.items) + { + case ITEM_HealthMega.m_itemid: + // if (e.itemdef == ITEM_HealthMega) // e.items == IT_HEALTH unequivocally identifies it + it_health_mega_time = t; + break; + case ITEM_ArmorMega.m_itemid: + if (e.itemdef == ITEM_ArmorMega) // e.items == IT_ARMOR doesn't unequivocally identifies it + it_armor_large_time = t; + break; + case IT_STRENGTH://"item-strength" + it_strength_time = t; + break; + case IT_INVINCIBLE://"item-shield" + it_shield_time = t; + break; + default: + if (e.weapons & WEPSET_SUPERWEAPONS) + it_superweapons_time = t; + } + } + switch (e.items) + { + case IT_FUEL_REGEN://"item-fuelregen" + it_fuelregen_time = t; + break; + case IT_JETPACK://"item-jetpack" + it_jetpack_time = t; + break; + } +} + +void Item_ItemsTime_SetTimesForAllPlayers() +{ + entity e; + FOR_EACH_REALCLIENT(e) if (warmup_stage || !IS_PLAYER(e)) + Item_ItemsTime_SetTimesForPlayer(e); +} + +float Item_ItemsTime_UpdateTime(entity e, float t) +{ + bool isavailable = (t == 0); + if (e.weapons & WEPSET_SUPERWEAPONS) + { + for (entity head = world; (head = nextent(head)); ) + { + if (clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.classname == "weapon_info") + continue; + if (e == head) + continue; + + if (head.scheduledrespawntime <= time) + isavailable = true; + else if (t == 0 || head.scheduledrespawntime < t) + t = head.scheduledrespawntime; + } + } + else + { + for (entity head = world; (head = nextent(head)); ) + { + if (head.itemdef != e.itemdef) + continue; + if (e == head) + continue; + + if (head.scheduledrespawntime <= time) + isavailable = true; + else if (t == 0 || head.scheduledrespawntime < t) + t = head.scheduledrespawntime; + } + } + if (isavailable) + t = -t; // let know the client there's another available item + return t; +} + +#endif diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 6ea03dd43..f9b8fae07 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -432,6 +432,8 @@ void ReadyRestart_think() return; } +void Item_ItemsTime_ResetTimes(); + // Forces a restart of the game without actually reloading the map // this is a mess... void ReadyRestart_force() { diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 0dd5c9c2b..747075812 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -412,186 +412,9 @@ void Item_Think() } } -float it_armor_large_time; -float it_health_mega_time; -float it_invisible_time; -float it_speed_time; -float it_extralife_time; -float it_strength_time; -float it_shield_time; -float it_fuelregen_time; -float it_jetpack_time; -float it_superweapons_time; - -void Item_ItemsTime_Init() -{ - it_armor_large_time = -1; - it_health_mega_time = -1; - it_invisible_time = -1; - it_speed_time = -1; - it_extralife_time = -1; - it_strength_time = -1; - it_shield_time = -1; - it_fuelregen_time = -1; - it_jetpack_time = -1; - it_superweapons_time = -1; -} - -STATIC_INIT(ItemsTime_Init) { - // items time - Item_ItemsTime_Init(); -} - -void Item_ItemsTime_ResetTimes() -{ - it_armor_large_time = (it_armor_large_time == -1) ? -1 : 0; - it_health_mega_time = (it_health_mega_time == -1) ? -1 : 0; - it_invisible_time = (it_invisible_time == -1) ? -1 : 0; - it_speed_time = (it_speed_time == -1) ? -1 : 0; - it_extralife_time = (it_extralife_time == -1) ? -1 : 0; - it_strength_time = (it_strength_time == -1) ? -1 : 0; - it_shield_time = (it_shield_time == -1) ? -1 : 0; - it_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0; - it_jetpack_time = (it_jetpack_time == -1) ? -1 : 0; - it_superweapons_time= (it_superweapons_time== -1) ? -1 : 0; -} -void IT_Write(entity, int, float); -void Item_ItemsTime_ResetTimesForPlayer(entity e) -{ - IT_Write(e, item_armor_large_time , (it_armor_large_time == -1) ? -1 : 0); - IT_Write(e, item_health_mega_time , (it_health_mega_time == -1) ? -1 : 0); - IT_Write(e, item_invisible_time , (it_invisible_time == -1) ? -1 : 0); - IT_Write(e, item_speed_time , (it_speed_time == -1) ? -1 : 0); - IT_Write(e, item_extralife_time , (it_extralife_time == -1) ? -1 : 0); - IT_Write(e, item_strength_time , (it_strength_time == -1) ? -1 : 0); - IT_Write(e, item_shield_time , (it_shield_time == -1) ? -1 : 0); - IT_Write(e, item_fuelregen_time , (it_fuelregen_time == -1) ? -1 : 0); - IT_Write(e, item_jetpack_time , (it_jetpack_time == -1) ? -1 : 0); - IT_Write(e, item_superweapons_time, (it_superweapons_time == -1) ? -1 : 0); -} -void Item_ItemsTime_SetTimesForPlayer(entity e) -{ - IT_Write(e, item_armor_large_time , it_armor_large_time ); - IT_Write(e, item_health_mega_time , it_health_mega_time ); - IT_Write(e, item_invisible_time , it_invisible_time ); - IT_Write(e, item_speed_time , it_speed_time ); - IT_Write(e, item_extralife_time , it_extralife_time ); - IT_Write(e, item_strength_time , it_strength_time ); - IT_Write(e, item_shield_time , it_shield_time ); - IT_Write(e, item_fuelregen_time , it_fuelregen_time ); - IT_Write(e, item_jetpack_time , it_jetpack_time ); - IT_Write(e, item_superweapons_time, it_superweapons_time); -} - -void Item_ItemsTime_SetTime(entity e, float t) -{ - if(!autocvar_sv_itemstime) - return; - - if(g_instagib) - { - switch(e.items) - { - case IT_STRENGTH://"item-invis" - it_invisible_time = t; - break; - case IT_NAILS://"item-extralife" - it_extralife_time = t; - break; - case IT_INVINCIBLE://"item-speed" - it_speed_time = t; - break; - } - } - else - { - switch(e.items) - { - case ITEM_HealthMega.m_itemid: - // if(e.itemdef == ITEM_HealthMega) // e.items == IT_HEALTH unequivocally identifies it - it_health_mega_time = t; - break; - case ITEM_ArmorMega.m_itemid: - if(e.itemdef == ITEM_ArmorMega) // e.items == IT_ARMOR doesn't unequivocally identifies it - it_armor_large_time = t; - break; - case IT_STRENGTH://"item-strength" - it_strength_time = t; - break; - case IT_INVINCIBLE://"item-shield" - it_shield_time = t; - break; - default: - if(e.weapons & WEPSET_SUPERWEAPONS) - it_superweapons_time = t; - } - } - switch(e.items) - { - case IT_FUEL_REGEN://"item-fuelregen" - it_fuelregen_time = t; - break; - case IT_JETPACK://"item-jetpack" - it_jetpack_time = t; - break; - } -} -void Item_ItemsTime_SetTimesForAllPlayers() -{ - entity e; - if(warmup_stage) - { - FOR_EACH_REALCLIENT(e) - Item_ItemsTime_SetTimesForPlayer(e); - } - else - { - FOR_EACH_REALCLIENT(e) - { - if(!IS_PLAYER(e)) - Item_ItemsTime_SetTimesForPlayer(e); - } - } -} - -float Item_ItemsTime_UpdateTime(entity e, float t) -{ - entity head; - bool isavailable = (t == 0); - if(e.weapons & WEPSET_SUPERWEAPONS) - { - for(head = world; (head = nextent(head)); ) - { - if(clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.classname == "weapon_info") - continue; - if(e == head) - continue; - - if(head.scheduledrespawntime <= time) - isavailable = true; - else if(t == 0 || head.scheduledrespawntime < t) - t = head.scheduledrespawntime; - } - } - else - { - for(head = world; (head = nextent(head)); ) - { - if(head.itemdef != e.itemdef) - continue; - if(e == head) - continue; - - if(head.scheduledrespawntime <= time) - isavailable = true; - else if(t == 0 || head.scheduledrespawntime < t) - t = head.scheduledrespawntime; - } - } - if(isavailable) - t = -t; // let know the client there's another available item - return t; -} +float Item_ItemsTime_UpdateTime(entity e, float t); +void Item_ItemsTime_SetTime(entity e, float t); +void Item_ItemsTime_SetTimesForAllPlayers(); void Item_Respawn (void) {