File size: 17,333 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
enum CookingMethodType
{
NONE = 0, //no cooking method available
BAKING = 1,
BOILING = 2,
DRYING = 3,
TIME = 4,
COUNT
}
class Cooking
{
static const float TIME_WITH_SUPPORT_MATERIAL_COEF = 1.0; //! time modifier used when not using support material
static const float TIME_WITHOUT_SUPPORT_MATERIAL_COEF = 2.0; //! time modifier used when using support material
static const float COOKING_FOOD_TIME_INC_VALUE = 2; //! time increase when cooking a food
static const float COOKING_LARD_DECREASE_COEF = 25; //! how many units from quantity of lard are remove at each stage
static const float COOKING_FOOD_QUANTITY_DECREASE_AMOUNT_NONE = 25; //! how many units from quantity of item are removed at each stage when support material is NOT used
static const float COOKING_FOOD_QUANTITY_DECREASE_AMOUNT_LARD = 0; //! NOT USED.
static const float DEFAULT_COOKING_TEMPERATURE = 150; //default temperature for cooking (e.g. cooking on stick)
static const float FOOD_MAX_COOKING_TEMPERATURE = 150; //
static const float PARAM_BURN_DAMAGE_COEF = 0.05; //value for calculating damage on items located in fireplace CargoGrid
static const float LIQUID_BOILING_POINT = 150; //boiling point for liquids
static const float LIQUID_VAPOR_QUANTITY = 2; //vapor quantity
typename COOKING_EQUIPMENT_POT = Pot;
typename COOKING_EQUIPMENT_FRYINGPAN = FryingPan;
typename COOKING_EQUIPMENT_CAULDRON = Cauldron;
typename COOKING_INGREDIENT_LARD = Lard;
void ProcessItemToCook(notnull ItemBase pItem, ItemBase cookingEquip, Param2<CookingMethodType, float> pCookingMethod, out Param2<bool, bool> pStateFlags)
{
Edible_Base item_to_cook = Edible_Base.Cast(pItem);
//! state flags are in order: is_done, is_burned
pStateFlags = new Param2<bool, bool>(false, false);
if (item_to_cook && item_to_cook.CanBeCooked())
{
//! enable cooking SoundEvent
item_to_cook.MakeSoundsOnClient(true, pCookingMethod.param1);
//! update food
UpdateCookingState(item_to_cook, pCookingMethod.param1, cookingEquip, pCookingMethod.param2);
//check for done state for boiling and drying
if (item_to_cook.IsFoodBoiled() || item_to_cook.IsFoodDried())
{
pStateFlags.param1 = true;
}
//! check for done state from baking (exclude Lard from baked items)
else if (item_to_cook.IsFoodBaked() && item_to_cook.Type() != Lard)
{
pStateFlags.param1 = true;
}
//! check for burned state
else if (item_to_cook.IsFoodBurned())
{
pStateFlags.param2 = true;
}
}
else
{
//damage item
pItem.DecreaseHealth("", "", PARAM_BURN_DAMAGE_COEF * 100);
//add temperature to item
AddTemperatureToItem(pItem, null, 0);
}
}
//COOKING PROCESS
//--- Cooking with equipment (pot)
//Returns 1 if the item changed its cooking stage, 0 if not
int CookWithEquipment(ItemBase cooking_equipment, float cooking_time_coef = 1)
{
bool is_empty;
//check cooking conditions
if (cooking_equipment == null)
{
return 0;
}
if (cooking_equipment.IsRuined())
{
return 0;
}
//manage items in cooking equipment
Param2<bool, bool> stateFlags = new Param2<bool, bool>(false, false); // 1st - done; 2nd - burned
Param2<CookingMethodType, float> cookingMethodWithTime = GetCookingMethodWithTimeOverride(cooking_equipment);
//! cooking time coef override
if (cooking_time_coef != 1)
{
cookingMethodWithTime.param2 = cooking_time_coef;
}
CargoBase cargo = cooking_equipment.GetInventory().GetCargo();
if (cargo)
{
is_empty = cargo.GetItemCount() == 0;
//process items
for (int i = 0; i < cargo.GetItemCount(); i++)
{
ProcessItemToCook(ItemBase.Cast(cargo.GetItem(i)), cooking_equipment, cookingMethodWithTime, stateFlags);
}
}
else
{
ProcessItemToCook(cooking_equipment, cooking_equipment, cookingMethodWithTime, stateFlags);
}
//manage cooking equipment
Bottle_Base bottle_base = Bottle_Base.Cast(cooking_equipment);
if (bottle_base)
{
float cookingEquipmentTemp = cooking_equipment.GetTemperature();
//handle water boiling
if (cookingEquipmentTemp >= LIQUID_BOILING_POINT)
{
//remove agents
cooking_equipment.RemoveAllAgents();
if (cooking_equipment.GetQuantity() > 0)
{
//vaporize liquid
cooking_equipment.AddQuantity(-LIQUID_VAPOR_QUANTITY);
}
}
//handle audio visuals
bottle_base.RefreshAudioVisualsOnClient(cookingMethodWithTime.param1, stateFlags.param1, is_empty, stateFlags.param2);
}
FryingPan frying_pan = FryingPan.Cast(cooking_equipment);
if (frying_pan && !bottle_base)
{
//handle audio visuals
frying_pan.RefreshAudioVisualsOnClient(cookingMethodWithTime.param1, stateFlags.param1, is_empty, stateFlags.param2);
}
return 1;
}
//Returns 1 if the item changed its cooking stage, 0 if not
int CookOnStick( Edible_Base item_to_cook, float cook_time_inc )
{
if ( item_to_cook && item_to_cook.CanBeCookedOnStick() )
{
//update food
return UpdateCookingStateOnStick( item_to_cook, cook_time_inc );
}
return 0;
}
//Returns 1 if the item changed its cooking stage, 0 if not
protected int UpdateCookingState(Edible_Base item_to_cook, CookingMethodType cooking_method, ItemBase cooking_equipment, float cooking_time_coef)
{
//food properties
float food_temperature = item_to_cook.GetTemperature();
//{min_temperature, time_to_cook, max_temperature (optional)}
//get next stage name - if next stage is not defined, next stage name will be empty "" and no cooking properties (food_min_temp, food_time_to_cook, food_max_temp) will be set
FoodStageType new_stage_type = item_to_cook.GetNextFoodStageType(cooking_method);
float food_min_temp = 0;
float food_time_to_cook = 0;
float food_max_temp = -1;
//Set next stage cooking properties if next stage possible
if (item_to_cook.CanChangeToNewStage(cooking_method)) // new_stage_type != NONE
{
array<float> next_stage_cooking_properties = new array<float>();
next_stage_cooking_properties = FoodStage.GetAllCookingPropertiesForStage(new_stage_type, null, item_to_cook.GetType());
food_min_temp = next_stage_cooking_properties.Get(eCookingPropertyIndices.MIN_TEMP);
food_time_to_cook = next_stage_cooking_properties.Get(eCookingPropertyIndices.COOK_TIME);
// The last element is optional and might not exist
if (next_stage_cooking_properties.Count() > 2)
{
food_max_temp = next_stage_cooking_properties.Get(eCookingPropertyIndices.MAX_TEMP);
}
}
//add temperature
AddTemperatureToItem(item_to_cook, cooking_equipment, food_min_temp);
//add cooking time if the food can be cooked by this method
if (food_min_temp > 0 && food_temperature >= food_min_temp)
{
float new_cooking_time = item_to_cook.GetCookingTime() + COOKING_FOOD_TIME_INC_VALUE * cooking_time_coef;
item_to_cook.SetCookingTime(new_cooking_time);
//progress to next stage
if (item_to_cook.GetCookingTime() >= food_time_to_cook)
{
//if max temp is defined check next food stage
if (food_max_temp >= 0)
{
if (food_temperature > food_max_temp && item_to_cook.GetFoodStageType() != FoodStageType.BURNED)
{
new_stage_type = FoodStageType.BURNED;
}
}
//! Change food stage
item_to_cook.ChangeFoodStage(new_stage_type);
//! Remove all modifiers
item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
if (cooking_equipment)
{
if (cooking_method == CookingMethodType.BAKING)
{
ItemBase lard = GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment);
if (lard)
{
//decrease lard quantity
float lardQuantity = lard.GetQuantity() - COOKING_LARD_DECREASE_COEF;
lardQuantity = Math.Clamp(lardQuantity, 0, lard.GetQuantityMax());
lard.SetQuantity(lardQuantity);
}
else
{
//! any foodstage without lard
DecreaseCookedItemQuantity(item_to_cook, COOKING_FOOD_QUANTITY_DECREASE_AMOUNT_NONE);
}
}
}
else
{
//! any foodstage without lard
DecreaseCookedItemQuantity(item_to_cook, COOKING_FOOD_QUANTITY_DECREASE_AMOUNT_NONE);
}
//reset cooking time
item_to_cook.SetCookingTime(0);
return 1;
}
}
return 0;
}
//Returns 1 if the item changed its cooking stage, 0 if not
protected int UpdateCookingStateOnStick( Edible_Base item_to_cook, float cook_time_inc )
{
//food properties
float food_temperature = item_to_cook.GetTemperature();
//{min_temperature, time_to_cook, max_temperature (optional)}
//get next stage name - if next stage is not defined, next stage name will be empty "" and no cooking properties (food_min_temp, food_time_to_cook, food_max_temp) will be set
FoodStageType new_stage_type = item_to_cook.GetNextFoodStageType( CookingMethodType.BAKING );
float food_min_temp = 0;
float food_time_to_cook = 0;
float food_max_temp = -1;
bool is_done = false; // baked
bool is_burned = false; // burned
//Set next stage cooking properties if next stage possible
if ( item_to_cook.CanChangeToNewStage( CookingMethodType.BAKING ) )
{
array<float> next_stage_cooking_properties = new array<float>;
next_stage_cooking_properties = FoodStage.GetAllCookingPropertiesForStage( new_stage_type, null, item_to_cook.GetType() );
food_min_temp = next_stage_cooking_properties.Get( eCookingPropertyIndices.MIN_TEMP );
food_time_to_cook = next_stage_cooking_properties.Get( eCookingPropertyIndices.COOK_TIME );
// The last element is optional and might not exist
if ( next_stage_cooking_properties.Count() > 2 )
food_max_temp = next_stage_cooking_properties.Get( eCookingPropertyIndices.MAX_TEMP );
}
// refresh audio
if (item_to_cook.GetInventory().IsAttachment())
{
item_to_cook.MakeSoundsOnClient(true, CookingMethodType.BAKING);
//add temperature
AddTemperatureToItem(item_to_cook, null, food_min_temp);
}
//add cooking time if the food can be cooked by this method
if ( food_min_temp > 0 && food_temperature >= food_min_temp )
{
float new_cooking_time = item_to_cook.GetCookingTime() + cook_time_inc;
item_to_cook.SetCookingTime( new_cooking_time );
//progress to next stage
if ( item_to_cook.GetCookingTime() >= food_time_to_cook )
{
//if max temp is defined check next food stage
if ( food_max_temp >= 0 )
{
if ( food_temperature > food_max_temp && item_to_cook.GetFoodStageType() != FoodStageType.BURNED )
{
new_stage_type = FoodStageType.BURNED;
}
}
//change food stage
item_to_cook.ChangeFoodStage( new_stage_type );
item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
DecreaseCookedItemQuantity(item_to_cook, COOKING_FOOD_QUANTITY_DECREASE_AMOUNT_NONE);
//reset cooking time
item_to_cook.SetCookingTime( 0 );
return 1;
}
}
return 0;
}
void SmokeItem(Edible_Base item_to_cook, float cook_time_inc)
{
if (item_to_cook)
{
float new_cook_time = item_to_cook.GetCookingTime() + cook_time_inc;
float drying_cook_time = FoodStage.GetCookingPropertyFromIndex(eCookingPropertyIndices.COOK_TIME, FoodStageType.DRIED, null, item_to_cook.GetType());
switch (item_to_cook.GetFoodStageType())
{
case FoodStageType.RAW:
item_to_cook.SetCookingTime(new_cook_time);
if (item_to_cook.GetCookingTime() >= drying_cook_time)
{
item_to_cook.ChangeFoodStage(FoodStageType.DRIED);
item_to_cook.RemoveAllAgentsExcept(eAgents.BRAIN);
item_to_cook.SetCookingTime(0);
}
break;
default:
item_to_cook.SetCookingTime(new_cook_time);
if (item_to_cook.GetCookingTime() >= drying_cook_time)
{
item_to_cook.ChangeFoodStage(FoodStageType.BURNED);
item_to_cook.RemoveAllAgents();
item_to_cook.SetCookingTime(0);
}
break;
}
}
}
void TerminateCookingSounds(ItemBase pItem)
{
Edible_Base edible;
if (pItem)
{
if (pItem.GetInventory()) // cookware
{
CargoBase cargo = pItem.GetInventory().GetCargo();
if (cargo)
{
for (int i = 0; i < cargo.GetItemCount(); i++)
{
edible = Edible_Base.Cast(cargo.GetItem(i));
if (edible)
{
edible.MakeSoundsOnClient(false);
}
}
}
}
else
{
edible = Edible_Base.Cast(pItem);
if (edible)
{
edible.MakeSoundsOnClient(false);
}
}
}
}
//! Cooking data
protected ItemBase GetItemTypeFromCargo( typename item_type, ItemBase cooking_equipment )
{
CargoBase cargo = cooking_equipment.GetInventory().GetCargo();
if (cargo)
{
for (int i = 0; i < cargo.GetItemCount(); i++)
{
EntityAI entity = cargo.GetItem(i);
if (entity.Type() == item_type)
{
ItemBase item = ItemBase.Cast(entity);
return item;
}
}
}
return null;
}
//! DEPREACTED
protected CookingMethodType GetCookingMethod(ItemBase cooking_equipment)
{
if (cooking_equipment.Type() == COOKING_EQUIPMENT_POT || cooking_equipment.Type() == COOKING_EQUIPMENT_CAULDRON)
{
//has water, but not petrol dammit X)
if (cooking_equipment.GetQuantity() > 0 && cooking_equipment.GetLiquidType() != LIQUID_GASOLINE)
{
return CookingMethodType.BOILING;
}
//has lard in cargo
if (GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment))
{
return CookingMethodType.BAKING;
}
return CookingMethodType.DRYING;
}
if (cooking_equipment.Type() == COOKING_EQUIPMENT_FRYINGPAN)
{
if (GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment))
{
return CookingMethodType.BAKING;
}
return CookingMethodType.DRYING;
}
return CookingMethodType.NONE;
}
protected Param2<CookingMethodType, float> GetCookingMethodWithTimeOverride(ItemBase cooking_equipment)
{
Param2<CookingMethodType, float> val = new Param2<CookingMethodType, float>(CookingMethodType.NONE, TIME_WITH_SUPPORT_MATERIAL_COEF);
switch (cooking_equipment.Type())
{
case COOKING_EQUIPMENT_POT:
case COOKING_EQUIPMENT_CAULDRON:
case COOKING_EQUIPMENT_FRYINGPAN:
if (cooking_equipment.GetQuantity() > 0)
{
if (cooking_equipment.GetLiquidType() == LIQUID_GASOLINE)
{
//! when cooking in gasoline, jump to drying state(will be burnt then)
val = new Param2<CookingMethodType, float>(CookingMethodType.DRYING, TIME_WITHOUT_SUPPORT_MATERIAL_COEF);
break;
}
val = new Param2<CookingMethodType, float>(CookingMethodType.BOILING, TIME_WITH_SUPPORT_MATERIAL_COEF);
break;
}
if (GetItemTypeFromCargo(COOKING_INGREDIENT_LARD, cooking_equipment))
{
//has lard in cargo, slower process
val = new Param2<CookingMethodType, float>(CookingMethodType.BAKING, TIME_WITH_SUPPORT_MATERIAL_COEF);
break;
}
if (cooking_equipment.GetInventory().GetCargo().GetItemCount() > 0)
{
val = new Param2<CookingMethodType, float>(CookingMethodType.BAKING, TIME_WITHOUT_SUPPORT_MATERIAL_COEF);
break;
}
val = new Param2<CookingMethodType, float>(CookingMethodType.NONE, TIME_WITHOUT_SUPPORT_MATERIAL_COEF);
break;
default:
val = new Param2<CookingMethodType, float>(CookingMethodType.BAKING, TIME_WITHOUT_SUPPORT_MATERIAL_COEF);
break;
}
return val;
}
Edible_Base GetFoodOnStick( ItemBase stick_item )
{
Edible_Base food_on_stick = Edible_Base.Cast( stick_item.GetAttachmentByType( Edible_Base ) );
return food_on_stick;
}
float GetTimeToCook( Edible_Base item_to_cook, CookingMethodType cooking_method )
{
FoodStageType food_stage_type = item_to_cook.GetNextFoodStageType( cooking_method );
return FoodStage.GetCookingPropertyFromIndex( eCookingPropertyIndices.COOK_TIME, food_stage_type, null, item_to_cook.GetType());
}
float GetMinTempToCook( Edible_Base item_to_cook, CookingMethodType cooking_method )
{
FoodStageType food_stage_type = item_to_cook.GetNextFoodStageType( cooking_method );
return FoodStage.GetCookingPropertyFromIndex( eCookingPropertyIndices.MIN_TEMP, food_stage_type, null, item_to_cook.GetType());
}
//add temperature to item
protected void AddTemperatureToItem( ItemBase cooked_item, ItemBase cooking_equipment, float min_temperature )
{
if ( cooked_item.GetTemperatureMax() >= FireplaceBase.PARAM_ITEM_HEAT_MIN_TEMP )
{
float item_temperature = cooked_item.GetTemperature();
//set actual cooking temperature
float actual_cooking_temp = DEFAULT_COOKING_TEMPERATURE; //default
if ( cooking_equipment )
{
actual_cooking_temp = cooking_equipment.GetTemperature();
}
//add temperature
if ( actual_cooking_temp > item_temperature )
{
item_temperature = actual_cooking_temp * 0.5;
item_temperature = Math.Clamp( item_temperature, min_temperature, FOOD_MAX_COOKING_TEMPERATURE );
//set new temperature
if ( GetGame() && GetGame().IsServer() )
{
cooked_item.SetTemperature( item_temperature );
}
}
}
}
protected void DecreaseCookedItemQuantity(notnull Edible_Base pItem, float pAmount = 0.0)
{
if (GetGame().IsServer())
{
float quantity = pItem.GetQuantity() - pAmount;
quantity = Math.Clamp(quantity, 0, pItem.GetQuantityMax());
pItem.SetQuantity(quantity);
}
}
}
|