in do_powerup added check for distance of other players to powerup object to make redundant pickups less likely

This commit is contained in:
zicodxx 2010-11-28 12:08:14 +01:00
parent 2b02639bd2
commit 8f349cfdc5
2 changed files with 24 additions and 1 deletions

View file

@ -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
--------

View file

@ -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++;