|
| 1 | +/* |
| 2 | +=========================================================================== |
| 3 | +
|
| 4 | + Copyright (c) 2010-2015 Darkstar Dev Teams |
| 5 | +
|
| 6 | + This program is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation, either version 3 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + This program is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with this program. If not, see http://www.gnu.org/licenses/ |
| 18 | +
|
| 19 | +=========================================================================== |
| 20 | +*/ |
| 21 | + |
| 22 | +#include "item_flowerpot.h" |
| 23 | +#include "../map.h" |
| 24 | + |
| 25 | +// Flowerpot Extra data explained: |
| 26 | +// 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 |
| 27 | +// Example: 08 40 03 07 01 37 0A 00 17 00 00 00 E5 C8 9A 1F 88 1A 9F 1F 08 3C 04 08 |
| 28 | +// 00 - Flowerpot stage ID (FLOWERPOT_STAGE_TYPE). Plants do not necessarily follow this sequentially and will skip some stages based on seed type. |
| 29 | +// 01 - Tracks if displayed as well as if the plant has been dried |
| 30 | +// 02 - Crystal feed element ID (FLOWERPOT_ELEMENT_TYPE). 4095 + element ID is the crystal item ID. This one is only used by trees that take two feedings. |
| 31 | +// 03 - Same as 0x02 but is the common one used by all plants. |
| 32 | +// 04 - Seed type (FLOWERPOT_PLANT_TYPE) of the plant |
| 33 | +// 05 - Unknown |
| 34 | +// 06-0B - MH Display info used in CItemFurnishing |
| 35 | +// 0C-0F - Vanatime of when the seed was planted in the flowerpot |
| 36 | +// 10-13 - Vanatime of when the next plant stage will occur |
| 37 | + |
| 38 | +CItemFlowerpot::CItemFlowerpot(uint16 id) |
| 39 | +: CItemFurnishing(id) |
| 40 | +{ |
| 41 | +} |
| 42 | + |
| 43 | +CItemFlowerpot::~CItemFlowerpot() |
| 44 | +{ |
| 45 | +} |
| 46 | + |
| 47 | +void CItemFlowerpot::cleanPot() |
| 48 | +{ |
| 49 | + setDried(false); |
| 50 | + setPlant(FLOWERPOT_PLANT_NONE); |
| 51 | + setStage(FLOWERPOT_STAGE_EMPTY); |
| 52 | + setFirstCrystalFeed(FLOWERPOT_ELEMENT_NONE); |
| 53 | + setSecondCrystalFeed(FLOWERPOT_ELEMENT_NONE); |
| 54 | + setPlantTimestamp(0); |
| 55 | + setStageTimestamp(0); |
| 56 | +} |
| 57 | + |
| 58 | +bool CItemFlowerpot::isPlanted() |
| 59 | +{ |
| 60 | + return ref<uint8>(m_extra, 0x00) > 0; |
| 61 | +} |
| 62 | + |
| 63 | +bool CItemFlowerpot::isTree() |
| 64 | +{ |
| 65 | + switch (getPlant()) |
| 66 | + { |
| 67 | + case FLOWERPOT_PLANT_FRUIT_SEEDS: |
| 68 | + case FLOWERPOT_PLANT_CACTUS_STEMS: |
| 69 | + case FLOWERPOT_PLANT_TREE_CUTTINGS: |
| 70 | + case FLOWERPOT_PLANT_TREE_SAPLINGS: |
| 71 | + return true; |
| 72 | + case FLOWERPOT_PLANT_HERB_SEEDS: |
| 73 | + case FLOWERPOT_PLANT_GRAIN_SEEDS: |
| 74 | + case FLOWERPOT_PLANT_VEGETABLE_SEEDS: |
| 75 | + case FLOWERPOT_PLANT_WILDGRASS_SEEDS: |
| 76 | + default: |
| 77 | + return false; |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +void CItemFlowerpot::setDried(bool dried) |
| 82 | +{ |
| 83 | + if (dried) |
| 84 | + { |
| 85 | + ref<uint8>(m_extra, 0x01) |= 0x80; |
| 86 | + } |
| 87 | + else |
| 88 | + { |
| 89 | + ref<uint8>(m_extra, 0x01) &= ~0x80; |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +bool CItemFlowerpot::isDried() |
| 94 | +{ |
| 95 | + return ref<uint8>(m_extra, 0x01) & 0x80; |
| 96 | +} |
| 97 | + |
| 98 | +bool CItemFlowerpot::canGrow() |
| 99 | +{ |
| 100 | + uint8 stage = ref<uint8>(m_extra, 0x00); |
| 101 | + return stage >= FLOWERPOT_STAGE_INITIAL && stage <= FLOWERPOT_STAGE_THIRD_SPROUTS && !isDried(); |
| 102 | +} |
| 103 | + |
| 104 | +void CItemFlowerpot::setPlant(FLOWERPOT_PLANT_TYPE plant) |
| 105 | +{ |
| 106 | + ref<uint8>(m_extra, 0x04) = plant; |
| 107 | +} |
| 108 | + |
| 109 | +FLOWERPOT_PLANT_TYPE CItemFlowerpot::getPlant() |
| 110 | +{ |
| 111 | + return (FLOWERPOT_PLANT_TYPE)ref<uint8>(m_extra, 0x04); |
| 112 | +} |
| 113 | + |
| 114 | +uint16 CItemFlowerpot::getSeedID(FLOWERPOT_PLANT_TYPE plantType) |
| 115 | +{ |
| 116 | + switch (plantType) |
| 117 | + { |
| 118 | + case FLOWERPOT_PLANT_HERB_SEEDS: |
| 119 | + return 572; |
| 120 | + case FLOWERPOT_PLANT_GRAIN_SEEDS: |
| 121 | + return 575; |
| 122 | + case FLOWERPOT_PLANT_VEGETABLE_SEEDS: |
| 123 | + return 573; |
| 124 | + case FLOWERPOT_PLANT_FRUIT_SEEDS: |
| 125 | + return 574; |
| 126 | + case FLOWERPOT_PLANT_CACTUS_STEMS: |
| 127 | + return 1236; |
| 128 | + case FLOWERPOT_PLANT_TREE_CUTTINGS: |
| 129 | + return 1237; |
| 130 | + case FLOWERPOT_PLANT_TREE_SAPLINGS: |
| 131 | + return 1238; |
| 132 | + case FLOWERPOT_PLANT_WILDGRASS_SEEDS: |
| 133 | + return 2235; |
| 134 | + case FLOWERPOT_PLANT_NONE: |
| 135 | + default: |
| 136 | + return 0; |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +FLOWERPOT_PLANT_TYPE CItemFlowerpot::getPlantFromSeed(uint16 seedID) |
| 141 | +{ |
| 142 | + switch (seedID) |
| 143 | + { |
| 144 | + case 572: |
| 145 | + return FLOWERPOT_PLANT_HERB_SEEDS; |
| 146 | + case 575: |
| 147 | + return FLOWERPOT_PLANT_GRAIN_SEEDS; |
| 148 | + case 573: |
| 149 | + return FLOWERPOT_PLANT_VEGETABLE_SEEDS; |
| 150 | + case 574: |
| 151 | + return FLOWERPOT_PLANT_FRUIT_SEEDS; |
| 152 | + case 1236: |
| 153 | + return FLOWERPOT_PLANT_CACTUS_STEMS; |
| 154 | + case 1237: |
| 155 | + return FLOWERPOT_PLANT_TREE_CUTTINGS; |
| 156 | + case 1238: |
| 157 | + return FLOWERPOT_PLANT_TREE_SAPLINGS; |
| 158 | + case 2235: |
| 159 | + return FLOWERPOT_PLANT_WILDGRASS_SEEDS; |
| 160 | + default: |
| 161 | + return FLOWERPOT_PLANT_NONE; |
| 162 | + } |
| 163 | +} |
| 164 | + |
| 165 | +void CItemFlowerpot::setStage(FLOWERPOT_STAGE_TYPE stage) |
| 166 | +{ |
| 167 | + ref<uint8>(m_extra, 0x00) = stage; |
| 168 | +} |
| 169 | + |
| 170 | +FLOWERPOT_STAGE_TYPE CItemFlowerpot::getStage() |
| 171 | +{ |
| 172 | + return (FLOWERPOT_STAGE_TYPE)ref<uint8>(m_extra, 0x00); |
| 173 | +} |
| 174 | + |
| 175 | +void CItemFlowerpot::setFirstCrystalFeed(FLOWERPOT_ELEMENT_TYPE element) |
| 176 | +{ |
| 177 | + ref<uint8>(m_extra, 0x02) = element; |
| 178 | +} |
| 179 | + |
| 180 | +void CItemFlowerpot::setSecondCrystalFeed(FLOWERPOT_ELEMENT_TYPE element) |
| 181 | +{ |
| 182 | + ref<uint8>(m_extra, 0x03) = element; |
| 183 | +} |
| 184 | + |
| 185 | +FLOWERPOT_ELEMENT_TYPE CItemFlowerpot::getExtraCrystalFeed() |
| 186 | +{ |
| 187 | + return (FLOWERPOT_ELEMENT_TYPE)ref<uint8>(m_extra, 0x02); |
| 188 | +} |
| 189 | + |
| 190 | +FLOWERPOT_ELEMENT_TYPE CItemFlowerpot::getCommonCrystalFeed() |
| 191 | +{ |
| 192 | + return (FLOWERPOT_ELEMENT_TYPE)ref<uint8>(m_extra, 0x03); |
| 193 | +} |
| 194 | + |
| 195 | +int16 CItemFlowerpot::getItemFromElement(FLOWERPOT_ELEMENT_TYPE element) |
| 196 | +{ |
| 197 | + //Element and crystal item id ordering is the same with an offset |
| 198 | + return element + 4095; |
| 199 | +} |
| 200 | + |
| 201 | +FLOWERPOT_ELEMENT_TYPE CItemFlowerpot::getElementFromItem(int16 itemID) |
| 202 | +{ |
| 203 | + //Element and crystal item id ordering is the same with an offset |
| 204 | + return (FLOWERPOT_ELEMENT_TYPE)(itemID - 4095); |
| 205 | +} |
| 206 | + |
| 207 | +void CItemFlowerpot::setPlantTimestamp(uint32 vanatime) |
| 208 | +{ |
| 209 | + ref<uint32>(m_extra, 0x0C) = vanatime; |
| 210 | +} |
| 211 | + |
| 212 | +uint32 CItemFlowerpot::getPlantTimestamp() |
| 213 | +{ |
| 214 | + return ref<uint32>(m_extra, 0x0C); |
| 215 | +} |
| 216 | + |
| 217 | +void CItemFlowerpot::setStageTimestamp(uint32 vanatime) |
| 218 | +{ |
| 219 | + ref<uint32>(m_extra, 0x10) = vanatime; |
| 220 | +} |
| 221 | + |
| 222 | +uint32 CItemFlowerpot::getStageTimestamp() |
| 223 | +{ |
| 224 | + return ref<uint32>(m_extra, 0x10); |
| 225 | +} |
| 226 | + |
| 227 | +void CItemFlowerpot::clearExamined() |
| 228 | +{ |
| 229 | + ref<uint8>(m_extra, 0x05) &= ~1; |
| 230 | +} |
| 231 | + |
| 232 | +void CItemFlowerpot::markExamined() |
| 233 | +{ |
| 234 | + ref<uint8>(m_extra, 0x05) |= 1; |
| 235 | +} |
| 236 | + |
| 237 | +bool CItemFlowerpot::wasExamined() |
| 238 | +{ |
| 239 | + return ref<uint8>(m_extra, 0x05) & 1; |
| 240 | +} |
| 241 | + |
| 242 | +void CItemFlowerpot::setStrength(uint8 strength) |
| 243 | +{ |
| 244 | + ref<uint8>(m_extra, 0x05) = strength << 1; |
| 245 | +} |
| 246 | + |
| 247 | +uint8 CItemFlowerpot::getStrength() |
| 248 | +{ |
| 249 | + return ref<uint8>(m_extra, 0x05) >> 1; |
| 250 | +} |
0 commit comments