/** ** GM: TAKE <unit> <int> <itemtype> ** requires: permission-key "gmtake" **/ static void gm_take(const void *tnext, struct unit *u, struct order *ord) { unit *to = findunit(getid()); int num = getint(); const item_type *itype = finditemtype(getstrtoken(), u->faction->locale); if (to == NULL || rplane(to->region) != rplane(u->region)) { /* unknown or in another plane */ ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", "")); } else if (itype == NULL || i_get(to->items, itype) == 0) { /* unknown or not enough */ mistake(u, ord, "invalid item or item not found."); } else { /* checking permissions */ attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !has_permission(permissions, atoi36("gmtake"))) { mistake(u, ord, "permission denied."); } else { int i = i_get(to->items, itype); if (i < num) num = i; if (num) { i_change(&to->items, itype, -num); i_change(&u->items, itype, num); } } } }
static void gm_create(const void *tnext, struct unit *u, struct order *ord) { int i; attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (permissions) permissions = (attrib *) permissions->data.v; if (!permissions) return; i = getint(); if (i > 0) { const char *iname = getstrtoken(); const item_type *itype = finditemtype(iname, u->faction->locale); if (itype == NULL) { mistake(u, ord, "unknown item."); } else { attrib *a = a_find(permissions, &at_gmcreate); while (a && a->type == &at_gmcreate && a->data.v != (void *)itype) a = a->next; if (a) i_change(&u->items, itype, i); else mistake(u, ord, "your faction cannot create this item."); } } }
void test_finditemtype(CuTest * tc) { const item_type *itype; const resource_type *rtype; struct locale * lang; test_cleanup(); test_create_world(); lang = get_locale("de"); locale_setstring(lang, "horse", "Pferd"); rtype = get_resourcetype(R_HORSE); itype = finditemtype("Pferd", lang); CuAssertPtrNotNull(tc, itype); CuAssertPtrEquals(tc, (void*)rtype->itype, (void*)itype); }