예제 #1
0
STDMETHODIMP loEnum<BASE,ITEM,IFACE>::Next(ULONG celt, ITEM *rgelt, ULONG *fetched)
{
 HRESULT hr;
 ULONG ii, cmax, cbase;
// UL_WARNING((LOGID, "IEnum::Next -> %u %p", celt, rgelt));

 if (fetched) *fetched = 0;
 else if (celt > 1) return E_INVALIDARG;
 if (!rgelt && celt) return E_INVALIDARG;
 cmax = total - (cbase = curpos);
 if (total < cbase) cmax = 0;
 if (cmax > celt) cmax = celt;
#if 0
 memset(rgelt, 0, celt * sizeof(*rgelt));
#endif
 for(ii = 0; ii < cmax; ii++)
   if (S_OK != (hr = clone_item(&rgelt[ii],
                                &list[cbase + ii])))
     {
      while(ii--) destroy_item(&rgelt[ii]);
      return hr;
     }
 if (fetched) *fetched = cmax;
 curpos = cbase + cmax;

 return celt == cmax? S_OK: S_FALSE;
}
예제 #2
0
HRESULT loEnum<BASE,ITEM,IFACE>::add_item(ITEM *src)
{
 HRESULT hr;
 if (base || total > count) return E_FAIL;
 if (!src) return E_INVALIDARG;
 if (total >= count && !grow_list(total + 1)) return E_OUTOFMEMORY;
 if (S_OK == (hr = clone_item(&list[total], src))) total++;
 return hr;
}
예제 #3
0
파일: player.c 프로젝트: Df458/Growgue
void player_act()
{
    switch(get_last_action()) {
        case ACTION_TILL:
            till(x, y, current_map);
            break;
        case ACTION_PICKUP: {
            item* it = get_item(items_at(x, y, current_map), item_count_at(x, y, current_map), PURPOSE_PICKUP, true);
            if(!it)
                break;
            printf_message(COLOR_DEFAULT, "Picked up %d %s", it->count, it->name);
            callback("picked_up", it->script_state);
            take_item(x, y, it, current_map);
            add_item(it);
        } break;
        case ACTION_DROP: {
            item* it = get_item(inventory, item_count, PURPOSE_DROP, false);
            if(!it)
                break;
            if(it->can_equip && equipment[it->slot] == it) {
                equipment[it->slot] = 0;
                printf_message(COLOR_DEFAULT, "You unequip the %s, and drop it on the ground.", it->name);
                callback("removed", it->script_state);
            }
            item* clone = clone_item(it);
            callback("dropped", clone->script_state);
            place_item(x, y, clone, current_map);
            remove_item(it, -1);
        } break;
        case ACTION_APPLY: {
            item* it = get_item(inventory, item_count, PURPOSE_APPLY, false);
            if(!it)
                break;
            callback("apply", it->script_state);
            remove_item(it, 1);
        } break;
        case ACTION_EQUIP: {
            item* it = get_item(inventory, item_count, PURPOSE_EQUIP, false);
            if(!it || it->slot == SLOT_INVALID)
                break;
            callback("equip", it->script_state);
            printf_message(COLOR_DEFAULT, "You equip the %s.", it->name);
            equipment[it->slot] = it;
        break; }
        case ACTION_REMOVE: {
            item* it = get_item(equipment, 3, PURPOSE_REMOVE, false);
            if(!it)
                break;
            callback("remove", it->script_state);
            equipment[it->slot] = 0;
            printf_message(COLOR_DEFAULT, "You unequip the %s.", it->name);
        break; }
        case ACTION_PLANT: {
            if(!can_plant(x, y, current_map, true))
                break;
            item* it = get_item(inventory, item_count, PURPOSE_PLANT, false);
            if(!it)
                break;
            if(spawn_plant(x, y, it->plant_id, current_map)) {
                printf_message(COLOR_DEFAULT, "You plant the %s in the tilled soil.", it->name);
                remove_item(it, 1);
            }
        break; }
        case ACTION_HARVEST: {
            add_item(harvest_plant(x, y, current_map));
        break; }
        case ACTION_HELP:
            show_controls();
            break;
        case ACTION_INVENTORY:
            get_item(inventory, item_count, PURPOSE_NONE, false);
            break;
        case ACTION_WATER:
            water_tile(x, y, current_map);
            break;
        case ACTION_EXAMINE: {
            int mx, my;
            get_last_mouse_position(&mx, &my);
            int xdiff = mx - pres_x;
            int ydiff = my - pres_y;
            if(mx < 1 || my < 1 || mx > 78 || my > 78)
                break;
            examine(x + xdiff, y +ydiff, current_map);
        } break;
    }
    if(ep_current <= 0)
        add_message(COLOR_EP_CRIT, "Out of energy, you fall to the ground.");
}