// This routine adds an item to the list. void add_list(int plr, OWN ** head, int op_sqr) { int val; OWN *tp, *last_tp; OWN *op; op = (OWN *) calloc(1, sizeof(OWN)); if (op == NULL) errx(1, "out of memory"); op->sqr = &board[op_sqr]; val = value(op->sqr); last_tp = NULL; for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next) if (val == value(tp->sqr)) { free(op); return; } else last_tp = tp; op->next = tp; if (last_tp != NULL) last_tp->next = op; else *head = op; if (!trading) set_ownlist(plr); }
/* * This routine does a switch from one player to another */ static void move_em(TRADE *from, TRADE *to) { PLAY *pl_fr, *pl_to; OWN *op; pl_fr = &play[from->trader]; pl_to = &play[to->trader]; pl_fr->money -= from->cash; pl_to->money += from->cash; pl_fr->num_gojf -= from->gojf; pl_to->num_gojf += from->gojf; for (op = from->prop_list; op; op = op->next) { add_list(to->trader, &(pl_to->own_list), sqnum(op->sqr)); op->sqr->owner = to->trader; del_list(from->trader, &(pl_fr->own_list), sqnum(op->sqr)); } set_ownlist(to->trader); }