1 #include "resource.h" 2 3 #include "building/type.h" 4 #include "scenario/building.h" 5 resource_image_offset(resource_type resource,resource_image_type type)6int resource_image_offset(resource_type resource, resource_image_type type) 7 { 8 if (resource == RESOURCE_MEAT && scenario_building_allowed(BUILDING_WHARF)) { 9 switch (type) { 10 case RESOURCE_IMAGE_STORAGE: return 40; 11 case RESOURCE_IMAGE_CART: return 648; 12 case RESOURCE_IMAGE_FOOD_CART: return 8; 13 case RESOURCE_IMAGE_ICON: return 11; 14 default: return 0; 15 } 16 } else { 17 return 0; 18 } 19 } 20 resource_is_food(resource_type resource)21int resource_is_food(resource_type resource) 22 { 23 return resource == RESOURCE_WHEAT || resource == RESOURCE_VEGETABLES || 24 resource == RESOURCE_FRUIT || resource == RESOURCE_MEAT; 25 } 26 resource_to_workshop_type(resource_type resource)27workshop_type resource_to_workshop_type(resource_type resource) 28 { 29 switch (resource) { 30 case RESOURCE_OLIVES: 31 return WORKSHOP_OLIVES_TO_OIL; 32 case RESOURCE_VINES: 33 return WORKSHOP_VINES_TO_WINE; 34 case RESOURCE_IRON: 35 return WORKSHOP_IRON_TO_WEAPONS; 36 case RESOURCE_TIMBER: 37 return WORKSHOP_TIMBER_TO_FURNITURE; 38 case RESOURCE_CLAY: 39 return WORKSHOP_CLAY_TO_POTTERY; 40 default: 41 return WORKSHOP_NONE; 42 } 43 } 44 inventory_is_set(int inventory,int flag)45int inventory_is_set(int inventory, int flag) 46 { 47 return (inventory >> flag) & 1; 48 } 49 inventory_set(int * inventory,int flag)50void inventory_set(int *inventory, int flag) 51 { 52 *inventory |= 1 << flag; 53 } 54 resource_from_inventory(int inventory_id)55int resource_from_inventory(int inventory_id) 56 { 57 switch (inventory_id) { 58 case INVENTORY_WHEAT: return RESOURCE_WHEAT; 59 case INVENTORY_VEGETABLES: return RESOURCE_VEGETABLES; 60 case INVENTORY_FRUIT: return RESOURCE_FRUIT; 61 case INVENTORY_MEAT: return RESOURCE_MEAT; 62 case INVENTORY_POTTERY: return RESOURCE_POTTERY; 63 case INVENTORY_FURNITURE: return RESOURCE_FURNITURE; 64 case INVENTORY_OIL: return RESOURCE_OIL; 65 case INVENTORY_WINE: return RESOURCE_WINE; 66 default: return RESOURCE_NONE; 67 } 68 } 69 resource_to_inventory(resource_type resource)70int resource_to_inventory(resource_type resource) 71 { 72 switch (resource) { 73 case RESOURCE_WHEAT: return INVENTORY_WHEAT; 74 case RESOURCE_VEGETABLES: return INVENTORY_VEGETABLES; 75 case RESOURCE_FRUIT: return INVENTORY_FRUIT; 76 case RESOURCE_MEAT: return INVENTORY_MEAT; 77 case RESOURCE_POTTERY: return INVENTORY_POTTERY; 78 case RESOURCE_FURNITURE: return INVENTORY_FURNITURE; 79 case RESOURCE_OIL: return INVENTORY_OIL; 80 case RESOURCE_WINE: return INVENTORY_WINE; 81 default: return INVENTORY_NONE; 82 } 83 } 84