From 8f349cfdc5dd0bc283096cae5f60ad0bf88e9477 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Sun, 28 Nov 2010 12:08:14 +0100 Subject: [PATCH] in do_powerup added check for distance of other players to powerup object to make redundant pickups less likely --- CHANGELOG.txt | 1 + main/powerup.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index a9916d9a0..95cfdf6c4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20101128 -------- main/multi.c: In multi_new_game when initializing Players structures, also correctly init connected variable which is highly important for spreading pdata to clients and should be set correctly anyways (Thanks to Gold Leader and Flip for help with debugging/testing recent Multiplayer bugs) +main/powerup.c: in do_powerup added check for distance of other players to powerup object to make redundant pickups less likely 20101126 -------- diff --git a/main/powerup.c b/main/powerup.c index 5dc19ec90..eb93b6029 100644 --- a/main/powerup.c +++ b/main/powerup.c @@ -212,9 +212,31 @@ int do_powerup(object *obj) int used=0; int vulcan_ammo_to_add_with_cannon; - if ((Player_is_dead) || (ConsoleObject->type == OBJ_GHOST)) + if ((Player_is_dead) || (ConsoleObject->type == OBJ_GHOST) || (Players[Player_num].shields < 0)) return 0; + if (Game_mode & GM_MULTI) + { + /* + * The fact: Collecting a powerup is decided Client-side and due to PING it takes time for other players to know if one collected a powerup actually. This may lead to the case two players collect the same powerup! + * The solution: Let us check if someone else is closer to a powerup and if so, do not collect it. + * NOTE: Player positions computed by 'shortpos' and PING can still cause a small margin of error. + */ + int i = 0; + vms_vector tvec; + fix mydist = vm_vec_normalized_dir(&tvec, &obj->pos, &ConsoleObject->pos); + + for (i = 0; i < MAX_PLAYERS; i++) + { + if (i == Player_num || Players[i].connected != CONNECT_PLAYING) + continue; + if (Objects[Players[i].objnum].type == OBJ_GHOST || Players[i].shields < 0) + continue; + if (mydist > vm_vec_normalized_dir(&tvec, &obj->pos, &Objects[Players[i].objnum].pos)) + return 0; + } + } + switch (obj->id) { case POW_EXTRA_LIFE: Players[Player_num].lives++;