unit *addplayer(region * r, faction * f) { unit *u; const char * name; assert(r->land); if (rpeasants(r) < PEASANT_MIN) { rsetpeasants(r, PEASANT_MIN + rng_int() % (PEASANT_MAX - PEASANT_MIN)); } assert(f->units == NULL); faction_setorigin(f, 0, r->x, r->y); u = create_unit(r, f, 1, f->race, 0, NULL, NULL); u->thisorder = default_order(f->locale); unit_addorder(u, copy_order(u->thisorder)); name = config_get("rules.equip_first"); if (!equip_unit(u, name ? name : "first_unit")) { /* give every unit enough money to survive the first turn */ i_change(&u->items, get_resourcetype(R_SILVER)->itype, maintenance_cost(u)); } u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); if (f->race == get_race(RC_DAEMON)) { race_t urc; const race *rc; do { urc = (race_t)(rng_int() % MAXRACES); rc = get_race(urc); } while (rc == NULL || urc == RC_DAEMON || !playerrace(rc)); u->irace = rc; } f->lastorders = 0; return u; }
void init_links(Dllist *dll, int const LNK) { switch (LNK) { case LEX: copy_order(dll, STD, LEX); sort(dll->root, dll->length[LEX], dll, LEX); break; case POL: if (dll->up2date[LEX]) { copy_order(dll, LEX, POL); sort(dll->root->links[POL][FWD], dll->length[POL]-1, dll, POL); } else { init_links(dll, LEX); init_links(dll, POL); } break; case GRA: if (dll->up2date[POL]) graham(dll); else { init_links(dll, POL); init_links(dll, GRA); } break; case JAR: if (dll->up2date[POL]) jarvis(dll); else { init_links(dll, POL); init_links(dll, JAR); } break; default: printf("Error in init_links function\n"); break; } }