| 725 | } |
| 726 | |
| 727 | void findplayerstart(playerent *d, bool mapcenter, int arenaspawn) |
| 728 | { |
| 729 | int r = fixspawn-->0 ? 4 : rnd(10)+1; |
| 730 | entity *e = NULL; |
| 731 | if(!mapcenter) |
| 732 | { |
| 733 | int type = m_teammode ? team_base(d->team) : 100; |
| 734 | if(m_arena && arenaspawn >= 0) |
| 735 | { |
| 736 | int x = -1; |
| 737 | loopi(arenaspawn + 1) x = findentity(PLAYERSTART, x+1, type); |
| 738 | if(x >= 0) e = &ents[x]; |
| 739 | } |
| 740 | else if((m_teammode || m_arena) && !m_ktf) // ktf uses ffa spawns |
| 741 | { |
| 742 | loopi(r) spawncycle = findentity(PLAYERSTART, spawncycle+1, type); |
| 743 | if(spawncycle >= 0) e = &ents[spawncycle]; |
| 744 | } |
| 745 | else |
| 746 | { |
| 747 | float bestdist = -1; |
| 748 | |
| 749 | loopi(r) |
| 750 | { |
| 751 | spawncycle = clentstats.hasffaspawns ? findentity(PLAYERSTART, spawncycle+1, 100) : findentity(PLAYERSTART, spawncycle+1); // if not enough ffa-spawns are available, use all |
| 752 | if(spawncycle < 0) continue; |
| 753 | float dist = nearestenemy(vec(ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z), d->team); |
| 754 | if(!e || dist < 0 || (bestdist >= 0 && dist > bestdist)) { e = &ents[spawncycle]; bestdist = dist; } |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | if(e) |
| 760 | { |
| 761 | gotoplayerstart(d, e); |
| 762 | } |
| 763 | else |
| 764 | { |
| 765 | d->o.x = d->o.y = (float)ssize/2; |
| 766 | d->o.z = 4; |
| 767 | } |
| 768 | entinmap(d); |
| 769 | exechook(HOOK_SP, "onSpawn", "%d", d->clientnum); |
| 770 | } |
| 771 | |
| 772 | void spawnplayer(playerent *d) |
| 773 | { |
no test coverage detected