Code: Show/Hide local BOOL tryAttach(Player *p, tdvector *tdv)
{ int x; BOOL rv = FALSE; printf("[v] looking up players in proximity to %s. %d found\n",p->name,tdv->count); for (x = 0; x < tdv->count;++x) { Player* mounted = findPlayerWithName(tdv->data[x].name); if (mounted) { printf("[v] checking %s\n",mounted->name); int deltaX = p->position.x - mounted->position.x; int deltaY = p->position.y - mounted->position.y; int radius = getRadius(p->arena->cfg, tdv->data[x].ship) + 16; // plus one tile lee-way if (deltaX * deltaX + deltaY * deltaY < radius * radius) { // this is our turret!!! if (tdv->data[x].state == STATE_OCCUPIED) { if (strchr(tdv->data[x].disallowAttachShips,'1' + p->p_ship) != 0) { chat->SendMessage(p,"%ss are not allowed to attach to that vehicle.", shipNames[p->p_ship]); } else if (getNumAttached(mounted) >= tdv->data[x].maxTurrets) { chat->SendMessage(p,"There are too many turrets attached to %s.",mounted->name); } else { if (p->p_freq != mounted->p_freq && tdv->data[x].disallowEnemyAttach) chat->SendMessage(p,"Enemies are not allowed to attach to that vehicle.", shipNames[p->p_ship]); else { forceAttach(p, mounted); rv = TRUE; break; } } } } } } return rv; } |
Code: Show/Hide local void forceAttach(Player *p, Player* mounted)
{ int pid2 = mounted->pid; /* only send it if state has changed */ if (p->p_attached != pid2) { struct SimplePacket pkt = { S2C_TURRET, p->pid, pid2 }; net->SendToArena(p->arena, NULL, (byte*)&pkt, 5, NET_RELIABLE); p->p_attached = pid2; DO_CBS(CB_ATTACH, p->arena, AttachFunc, (p, mounted)); } } local Player* findPlayerWithName(const char* name) { Player* rv, *p; Link* link; pd->Lock(); FOR_EACH_PLAYER(p) { if (strcmp(p->name, name) == 0) { rv = p; break; } } pd->Unlock(); return rv; } |