MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / OnServerCollide

Function OnServerCollide

netgames/entropy/EntropyBase.cpp:776–851  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

774}
775
776void OnServerCollide(object *me_obj, object *it_obj) {
777 if (!me_obj || !it_obj)
778 return;
779
780 if (virus_id == -1) {
781 FatalError("Unable to find Virus Object");
782 return;
783 }
784
785 if ((me_obj->type == OBJ_PLAYER) && (it_obj->type == OBJ_POWERUP) && (it_obj->id == virus_id)) {
786 // determine what to do with this collision
787 int virus_objnum = it_obj - dObjects;
788 int virus_team = -1;
789 int virus_index = -1;
790 int player_num = me_obj->id;
791
792 // find which team the virus belongs to
793 for (int v = 0; v < MAX_VIRII; v++) {
794 if (virus_objnum == TeamVirii[RED_TEAM][v]) {
795 virus_team = RED_TEAM;
796 virus_index = v;
797 break;
798 }
799 if (virus_objnum == TeamVirii[BLUE_TEAM][v]) {
800 virus_team = BLUE_TEAM;
801 virus_index = v;
802 break;
803 }
804 }
805 if (virus_team == -1) {
806 // hey! we hit a virus that doesn't belong to any team!!
807 DLLmprintf(0, "Virus (%d) doesn't belong to any team, removing...\n", virus_objnum);
808 DMFCBase->OnServerCollide(me_obj, it_obj);
809 DLLSetObjectDeadFlag(it_obj, true, false);
810 return;
811 }
812
813 int curr_count = DLLInvGetTypeIDCount(player_num, OBJ_POWERUP, it_obj->id);
814 if (dPlayers[player_num].team == virus_team) {
815 // a player has collided with a virus from his team
816 // see if the player has enough kills to pick up this virus
817 int max_carry = NumberOfKillsSinceLastDeath[player_num] * VIRUS_PER_KILL;
818 if (curr_count + 1 > max_carry) {
819 // the player can't carry another virii yet
820 if (player_num == DMFCBase->GetPlayerNum()) {
821 DLLAddHUDMessage(TXT_CANTCARRY);
822 } else {
823 DMFCBase->SendControlMessageToPlayer(player_num, VIRUS_NOTENOUGHKILLS);
824 }
825 } else {
826 // pick this guy up
827 TeamVirii[virus_team][virus_index] = -1;
828 SendClientPickupVirus(player_num);
829 DLLSetObjectDeadFlag(it_obj, true, true);
830 if (snd_virus_pickup != -1) {
831 DLLPlay2dSound(snd_virus_pickup, MAX_GAME_VOLUME);
832 }
833 }

Callers

nothing calls this directly

Calls 4

SendClientPickupVirusFunction · 0.85
GetPlayerNumMethod · 0.80
OnServerCollideMethod · 0.45

Tested by

no test coverage detected