aboutsummaryrefslogtreecommitdiff
path: root/party.c
diff options
context:
space:
mode:
Diffstat (limited to 'party.c')
-rw-r--r--party.c103
1 files changed, 95 insertions, 8 deletions
diff --git a/party.c b/party.c
index 6199b87..87cf1f8 100644
--- a/party.c
+++ b/party.c
@@ -8,16 +8,19 @@
#include "dat.h"
#include "fns.h"
+/* Party */
+
Party *
-newparty(Party *p, Player *players)
+newparty(Party *p, Player *player0, Player *player1)
{
Party *np;
np = emalloc(sizeof(Party));
- np->players[0] = players[0];
- np->players[1] = players[1];
+ np->players[0] = player0;
+ np->players[1] = player1;
np->u = newuniverse();
+ inituniverse(np->u);
addparty(p, np);
@@ -34,12 +37,12 @@ delparty(Party *p)
}
void
-addparty(Party *theparty, Party *p)
+addparty(Party *p, Party *np)
{
- p->prev = theparty->prev;
- p->next = theparty;
- theparty->prev->next = p;
- theparty->prev = p;
+ np->prev = p->prev;
+ np->next = p;
+ p->prev->next = np;
+ p->prev = np;
}
void
@@ -47,3 +50,87 @@ initparty(Party *p)
{
p->next = p->prev = p;
}
+
+/* Player */
+
+Player *
+newplayer(char *name, NetConn *nc)
+{
+ Player *p;
+
+ p = emalloc(sizeof(Player));
+ p->name = name? strdup(name): nil;
+ p->conn = nc;
+ p->oldkdown = p->kdown = 0;
+ p->next = nil;
+
+ return p;
+}
+
+void
+delplayer(Player *p)
+{
+ free(p->name);
+ free(p);
+}
+
+/* Player queue */
+
+static void
+playerq_put(Playerq *pq, Player *p)
+{
+ if(pq->tail == nil)
+ pq->head = pq->tail = p;
+ else{
+ pq->tail->next = p;
+ pq->tail = p;
+ }
+ pq->len++;
+}
+
+static Player *
+playerq_get(Playerq *pq)
+{
+ Player *p;
+
+ if(pq->head == nil)
+ return nil;
+
+ p = pq->head;
+ if(pq->head == pq->tail)
+ pq->head = pq->tail = nil;
+ else{
+ pq->head = p->next;
+ p->next = nil;
+ }
+ pq->len--;
+ return p;
+}
+
+static void
+playerq_del(Playerq *pq, Player *p)
+{
+ Player *np;
+
+ if(pq->head == p){
+ pq->pop(pq);
+ return;
+ }
+
+ for(np = pq->head; np->next != nil; np = np->next)
+ if(np->next == p){
+ np->next = np->next->next;
+ p->next = nil;
+ pq->len--;
+ }
+}
+
+void
+initplayerq(Playerq *pq)
+{
+ pq->head = pq->tail = nil;
+ pq->len = 0;
+ pq->put = playerq_put;
+ pq->get = playerq_get;
+ pq->del = playerq_del;
+}