DayZ 1.24
Loading...
Searching...
No Matches
Edible_Base.c File Reference

Go to the source code of this file.

Classes

class  Edible_Base
 

Functions

Edible_Base ItemBase ReplaceEdibleWithNewLambda (EntityAI old_item, string new_item_type, PlayerBase player)
 
void Edible_Base ()
 
override void EEInit ()
 
override void EEDelete (EntityAI parent)
 
override void EEItemLocationChanged (notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
 
void UpdateVisuals ()
 
bool Consume (float amount, PlayerBase consumer)
 
void OnConsume (float amount, PlayerBase consumer)
 
override bool CanBeCooked ()
 
override bool CanBeCookedOnStick ()
 
void Synchronize ()
 
override void OnVariablesSynchronized ()
 
void MakeSoundsOnClient (bool soundstate, CookingMethodType cookingMethod=CookingMethodType.NONE)
 
void RefreshAudio ()
 
void RemoveAudio ()
 
override void OnStoreSave (ParamsWriteContext ctx)
 
override bool OnStoreLoad (ParamsReadContext ctx, int version)
 
override void AfterStoreLoad ()
 
FoodStage GetFoodStage ()
 
override bool IsMeat ()
 
override bool IsCorpse ()
 
override bool IsFruit ()
 
override bool IsMushroom ()
 
static float GetFoodTotalVolume (ItemBase item, string classname="", int food_stage=0)
 
static float GetFoodEnergy (ItemBase item, string classname="", int food_stage=0)
 
static float GetFoodWater (ItemBase item, string classname="", int food_stage=0)
 
static float GetFoodNutritionalIndex (ItemBase item, string classname="", int food_stage=0)
 
static float GetFoodToxicity (ItemBase item, string classname="", int food_stage=0)
 
static int GetFoodAgents (ItemBase item, string classname="", int food_stage=0)
 
static float GetFoodDigestibility (ItemBase item, string classname="", int food_stage=0)
 
static NutritionalProfile GetNutritionalProfile (ItemBase item, string classname="", int food_stage=0)
 
FoodStageType GetFoodStageType ()
 
bool IsFoodRaw ()
 
bool IsFoodBaked ()
 
bool IsFoodBoiled ()
 
bool IsFoodDried ()
 
bool IsFoodBurned ()
 
bool IsFoodRotten ()
 
void ChangeFoodStage (FoodStageType new_food_stage_type)
 
FoodStageType GetNextFoodStageType (CookingMethodType cooking_method)
 
string GetFoodStageName (FoodStageType food_stage_type)
 
bool CanChangeToNewStage (CookingMethodType cooking_method)
 
void TransferFoodStage (notnull Edible_Base source)
 
float GetCookingTime ()
 
void SetCookingTime (float time)
 
void ReplaceEdibleWithNew (string typeName)
 
override void SetActions ()
 
void SoundCookingStart (string sound_name)
 
void SoundCookingStop ()
 
override bool CanHaveTemperature ()
 
override bool CanDecay ()
 
override bool CanProcessDecay ()
 
override void ProcessDecay (float delta, bool hasRootAsPlayer)
 
override void GetDebugActions (out TSelectableActionInfoArrayEx outputList)
 
override bool OnAction (int action_id, Man player, ParamsReadContext ctx)
 
override string GetDebugText ()
 
float GetDecayTimer ()
 
float GetDecayDelta ()
 
FoodStageType GetLastDecayStage ()
 

Variables

const string DIRECT_COOKING_SLOT_NAME = "DirectCooking"
 
const string SOUND_BAKING_START = "Baking_SoundSet"
 
const string SOUND_BAKING_DONE = "Baking_Done_SoundSet"
 
const string SOUND_BURNING_DONE = "Food_Burning_SoundSet"
 
bool m_MakeCookingSounds
 
SoundOnVehicle m_SoundCooking
 
EffectSound m_SoundEffectCooking
 DEPRECATED.
 
string m_SoundPlaying
 
ref FoodStage m_FoodStage
 
float m_DecayTimer
 
float m_DecayDelta = 0.0
 
FoodStageType m_LastDecayStage = FoodStageType.NONE
 
CookingMethodType m_CookedByMethod
 

Function Documentation

◆ AfterStoreLoad()

override void ReplaceEdibleWithNewLambda::AfterStoreLoad ( )
protected

Definition at line 964 of file Edible_Base.c.

◆ CanBeCooked()

override bool ReplaceEdibleWithNewLambda::CanBeCooked ( )
private

Definition at line 843 of file Edible_Base.c.

843 : ItemBase
844{
845 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
846
847 const string SOUND_BAKING_START = "Baking_SoundSet";
848 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
849 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
850
851 protected bool m_MakeCookingSounds;
854 protected string m_SoundPlaying;
856 protected float m_DecayTimer;
857 protected float m_DecayDelta = 0.0;
859
861
862 void Edible_Base()
863 {
864 if (HasFoodStage())
865 {
866 m_FoodStage = new FoodStage(this);
867
868 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
869 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
870 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
871 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
872 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
873
874 m_SoundPlaying = "";
876 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
877 RegisterNetSyncVariableBool("m_MakeCookingSounds");
878 }
879 }
880
881 override void EEInit()
882 {
883 super.EEInit();
884
886 }
887
888 override void EEDelete(EntityAI parent)
889 {
890 super.EEDelete(parent);
891
892 RemoveAudio();
893 }
894
896 {
897 super.EEItemLocationChanged(oldLoc, newLoc);
898
900 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
901 {
902 switch (oldLoc.GetParent().GetType())
903 {
904 case "FryingPan":
905 case "Pot":
906 case "Cauldron":
907 case "SharpWoodenStick":
908 MakeSoundsOnClient(false);
909 break;
910 }
911
913 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
914 MakeSoundsOnClient(false);
915 }
916 }
917
918 void UpdateVisuals()
919 {
920 if (GetFoodStage())
921 GetFoodStage().UpdateVisuals();
922 }
923
924 bool Consume(float amount, PlayerBase consumer)
925 {
926 AddQuantity(-amount, false, false);
927 OnConsume(amount, consumer);
928
929 return true;
930 }
931
932 void OnConsume(float amount, PlayerBase consumer);
933
934 //food staging
935 override bool CanBeCooked()
936 {
937 return false;
938 }
939
940 override bool CanBeCookedOnStick()
941 {
942 return false;
943 }
944
945 //================================================================
946 // SYNCHRONIZATION
947 //================================================================
948 void Synchronize()
949 {
950 SetSynchDirty();
951
952 if (GetGame().IsMultiplayer())
954 }
955
956 override void OnVariablesSynchronized()
957 {
958 super.OnVariablesSynchronized();
959
961
962 //update audio
964 RefreshAudio();
965 else
966 RemoveAudio();
967 }
968
969 //================================================================
970 // AUDIO EFFECTS (WHEN ON DCS)
971 //================================================================
973 {
976
977 Synchronize();
978 }
979
980 protected void RefreshAudio()
981 {
982 string soundName = "";
983
985
986 switch (GetFoodStageType())
987 {
988 case FoodStageType.RAW:
990 if (nextFoodState == FoodStageType.BOILED)
991 soundName = "";
992 break;
993 case FoodStageType.BAKED:
995 break;
996 case FoodStageType.BURNED:
998 break;
999 default:
1000 soundName = "";
1001 break;
1002 }
1003
1005 }
1006
1007 protected void RemoveAudio()
1008 {
1009 m_MakeCookingSounds = false;
1011 }
1012
1013 //================================================================
1014 // SERIALIZATION
1015 //================================================================
1016 override void OnStoreSave(ParamsWriteContext ctx)
1017 {
1018 super.OnStoreSave(ctx);
1019
1020 if (GetFoodStage())
1021 GetFoodStage().OnStoreSave(ctx);
1022
1023 // food decay
1024 ctx.Write(m_DecayTimer);
1025 ctx.Write(m_LastDecayStage);
1026 }
1027
1028 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1029 {
1030 if (!super.OnStoreLoad(ctx, version))
1031 return false;
1032
1033 if (GetFoodStage())
1034 {
1035 if (!GetFoodStage().OnStoreLoad(ctx, version))
1036 return false;
1037 }
1038
1039 if (version >= 115)
1040 {
1041 if (!ctx.Read(m_DecayTimer))
1042 {
1043 m_DecayTimer = 0.0;
1044 return false;
1045 }
1046 if (!ctx.Read(m_LastDecayStage))
1047 {
1049 return false;
1050 }
1051 }
1052
1053 return true;
1054 }
1055
1056 override void AfterStoreLoad()
1057 {
1058 super.AfterStoreLoad();
1059
1060 Synchronize();
1061 }
1062
1063 //get food stage
1065 {
1066 return m_FoodStage;
1067 }
1068
1069 //food types
1070 override bool IsMeat()
1071 {
1072 return false;
1073 }
1074
1075 override bool IsCorpse()
1076 {
1077 return false;
1078 }
1079
1080 override bool IsFruit()
1081 {
1082 return false;
1083 }
1084
1085 override bool IsMushroom()
1086 {
1087 return false;
1088 }
1089
1090 //================================================================
1091 // NUTRITIONAL VALUES
1092 //================================================================
1093 //food properties
1094 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1095 {
1097 if (food_item && food_item.GetFoodStage())
1098 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1099 else if (classname != "" && food_stage)
1100 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1101 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1102 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1103
1104 }
1105
1106 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1107 {
1109 if (food_item && food_item.GetFoodStage())
1110 return FoodStage.GetEnergy(food_item.GetFoodStage());
1111 else if (classname != "" && food_stage)
1112 return FoodStage.GetEnergy(null, food_stage, classname);
1113 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1114 return GetGame().ConfigGetFloat(class_path + " energy");
1115 }
1116
1117 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1118 {
1120 if (food_item && food_item.GetFoodStage())
1121 return FoodStage.GetWater(food_item.GetFoodStage());
1122 else if (classname != "" && food_stage)
1123 return FoodStage.GetWater(null, food_stage, classname);
1124 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1125 return GetGame().ConfigGetFloat(class_path + " water");
1126 }
1127
1128 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1129 {
1131 if (food_item && food_item.GetFoodStage())
1132 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1133 else if (classname != "" && food_stage)
1134 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1135 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1136 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1137
1138 }
1139
1140 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1141 {
1143 if (food_item && food_item.GetFoodStage())
1144 return FoodStage.GetToxicity(food_item.GetFoodStage());
1145 else if (classname != "" && food_stage)
1146 return FoodStage.GetToxicity(null, food_stage, classname);
1147 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1148 return GetGame().ConfigGetFloat(class_path + " toxicity");
1149 }
1150
1151 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1152 {
1154 if (food_item && food_item.GetFoodStage())
1155 return FoodStage.GetAgents(food_item.GetFoodStage());
1156 else if (classname != "" && food_stage)
1157 return FoodStage.GetAgents(null, food_stage, classname);
1158 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1159 return GetGame().ConfigGetInt(class_path + " agents");
1160 }
1161
1162 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1163 {
1165 if (food_item && food_item.GetFoodStage())
1166 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1167 else if (classname != "" && food_stage)
1168 return FoodStage.GetDigestibility(null, food_stage, classname);
1169 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1170 return GetGame().ConfigGetInt(class_path + " digestibility");
1171 }
1172
1174 {
1176 }
1177
1178 //================================================================
1179 // FOOD STAGING
1180 //================================================================
1182 {
1183 return GetFoodStage().GetFoodStageType();
1184 }
1185
1186 //food stage states
1187 bool IsFoodRaw()
1188 {
1189 if (GetFoodStage())
1190 return GetFoodStage().IsFoodRaw();
1191
1192 return false;
1193 }
1194
1195 bool IsFoodBaked()
1196 {
1197 if (GetFoodStage())
1198 return GetFoodStage().IsFoodBaked();
1199
1200 return false;
1201 }
1202
1203 bool IsFoodBoiled()
1204 {
1205 if (GetFoodStage())
1206 return GetFoodStage().IsFoodBoiled();
1207
1208 return false;
1209 }
1210
1211 bool IsFoodDried()
1212 {
1213 if (GetFoodStage())
1214 return GetFoodStage().IsFoodDried();
1215
1216 return false;
1217 }
1218
1219 bool IsFoodBurned()
1220 {
1221 if (GetFoodStage())
1222 return GetFoodStage().IsFoodBurned();
1223
1224 return false;
1225 }
1226
1227 bool IsFoodRotten()
1228 {
1229 if (GetFoodStage())
1230 return GetFoodStage().IsFoodRotten();
1231
1232 return false;
1233 }
1234
1235 //food stage change
1237 {
1238 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1239 }
1240
1242 {
1243 return GetFoodStage().GetNextFoodStageType(cooking_method);
1244 }
1245
1247 {
1248 return GetFoodStage().GetFoodStageName(food_stage_type);
1249 }
1250
1252 {
1253 return GetFoodStage().CanChangeToNewStage(cooking_method);
1254 }
1255
1256 //Use this to receive food stage from another Edible_Base
1258 {
1259 if (!source.HasFoodStage())
1260 return;
1261 m_LastDecayStage = source.GetLastDecayStage();
1262 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1263 m_DecayTimer = source.GetDecayTimer();
1264 m_DecayDelta = source.GetDecayDelta();
1265 }
1266
1267 //================================================================
1268 // COOKING
1269 //================================================================
1270 //cooking time
1271 float GetCookingTime()
1272 {
1273 return GetFoodStage().GetCookingTime();
1274 }
1275
1276 void SetCookingTime(float time)
1277 {
1278 GetFoodStage().SetCookingTime(time);
1279
1280 //synchronize when calling on server
1281 Synchronize();
1282 }
1283
1284 //replace edible with new item (opening cans)
1285 void ReplaceEdibleWithNew(string typeName)
1286 {
1287 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1288 if (player)
1289 {
1291 player.ServerReplaceItemInHandsWithNew(lambda);
1292 }
1293 else
1294 Error("ReplaceEdibleWithNew - cannot use edible without player");
1295 }
1296
1297 override void SetActions()
1298 {
1299 super.SetActions();
1300
1301 AddAction(ActionAttach);
1303 }
1304
1305 protected void SoundCookingStart(string sound_name)
1306 {
1307#ifndef SERVER
1309 {
1311
1314 }
1315#endif
1316 }
1317
1318 protected void SoundCookingStop()
1319 {
1320#ifndef SERVER
1322 {
1325 m_SoundPlaying = "";
1326 }
1327#endif
1328 }
1329
1330 override bool CanHaveTemperature()
1331 {
1332 return true;
1333 }
1334
1335 override bool CanDecay()
1336 {
1337 return false;
1338 }
1339
1340 override bool CanProcessDecay()
1341 {
1342 return (GetFoodStageType() != FoodStageType.ROTTEN);
1343 }
1344
1345 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1346 {
1347 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1348 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1349 if (hasRootAsPlayer)
1351
1352 /*Print( "-------------------------" );
1353 Print( this );
1354 Print( m_DecayTimer );
1355 Print( m_DecayDelta );
1356 Print( m_LastDecayStage );*/
1357
1358 if (IsFruit() || IsMushroom())
1359 {
1360 // fruit, vegetables and mushrooms
1362 {
1363 switch (GetFoodStageType())
1364 {
1365 case FoodStageType.RAW:
1368 break;
1369
1370 case FoodStageType.BOILED:
1373 break;
1374
1375 case FoodStageType.BAKED:
1378 break;
1379
1380 case FoodStageType.DRIED:
1381 case FoodStageType.BURNED:
1382 case FoodStageType.ROTTEN:
1383 default:
1384 m_DecayTimer = -1;
1386 return;
1387 }
1388
1389 //m_DecayTimer = m_DecayTimer / 1000.0;
1390 }
1391
1393
1394 if (m_DecayTimer <= 0)
1395 {
1396 if (m_LastDecayStage != FoodStageType.NONE)
1397 {
1398 // switch to decayed stage
1399 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1402 {
1403 int rng = Math.RandomIntInclusive(0, 100);
1406 else
1407 {
1410 else
1412 }
1413 }
1414 }
1415 }
1416
1417 }
1418 else if (IsMeat())
1419 {
1420 // meat
1422 {
1423 switch (GetFoodStageType())
1424 {
1425 case FoodStageType.RAW:
1428 break;
1429
1430 case FoodStageType.BOILED:
1433 break;
1434
1435 case FoodStageType.BAKED:
1438 break;
1439
1440 case FoodStageType.DRIED:
1443 break;
1444
1445 case FoodStageType.BURNED:
1446 case FoodStageType.ROTTEN:
1447 default:
1448 m_DecayTimer = -1;
1450 return;
1451 }
1452 }
1453
1455
1456 if (m_DecayTimer <= 0)
1457 {
1458 if (m_LastDecayStage != FoodStageType.NONE)
1459 {
1460 // switch to decayed stage
1463 }
1464 }
1465 }
1466 else if (IsCorpse())
1467 {
1468 // corpse
1470 {
1471 switch (GetFoodStageType())
1472 {
1473 case FoodStageType.RAW:
1476 break;
1477
1478 case FoodStageType.BURNED:
1479 case FoodStageType.ROTTEN:
1480 default:
1481 m_DecayTimer = -1;
1483 return;
1484 }
1485 }
1486
1488
1489 if (m_DecayTimer <= 0)
1490 {
1491 if (m_LastDecayStage != FoodStageType.NONE)
1492 {
1493 // switch to decayed stage
1496 }
1497 }
1498 }
1499 else
1500 {
1501 // opened cans
1503
1504 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1505 {
1508 //m_DecayTimer = m_DecayTimer / 1000.0;
1509 }
1510 else
1511 {
1512 if (m_DecayTimer <= 0)
1513 {
1514 InsertAgent(eAgents.FOOD_POISON, 1);
1515 m_DecayTimer = -1;
1516 }
1517 }
1518 }
1519
1520 m_DecayDelta = 0.0;
1521 }
1522
1524 {
1525 super.GetDebugActions(outputList);
1526
1527 if (HasFoodStage())
1528 {
1529 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1530 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1531 }
1532 }
1533
1534 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1535 {
1536 super.OnAction(action_id, player, ctx);
1537
1538 if (GetGame().IsServer())
1539 {
1540 if (action_id == EActions.FOOD_STAGE_PREV)
1541 {
1543 if (food_stage_prev <= 0)
1544 food_stage_prev = FoodStageType.COUNT - 1;
1546 return true;
1547 }
1548 else if (action_id == EActions.FOOD_STAGE_NEXT)
1549 {
1551 if (food_stage_next >= FoodStageType.COUNT)
1554 return true;
1555 }
1556 }
1557 return false;
1558 }
1559
1560 override string GetDebugText()
1561 {
1562 string debug_output;
1563
1564 debug_output = super.GetDebugText();
1565
1566 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1567 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1568
1569 return debug_output;
1570 }
1571
1572 //================================================================
1573 // GENERAL GETTERS
1574 //================================================================
1575
1576 float GetDecayTimer()
1577 {
1578 return m_DecayTimer;
1579 }
1580
1581 float GetDecayDelta()
1582 {
1583 return m_DecayDelta;
1584 }
1585
1587 {
1588 return m_LastDecayStage;
1589 }
1590}
1591
1593{
1595};
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition EntityAI.c:97
void ActionDetach()
void AddAction(typename actionName)
CookingMethodType
Definition Cooking.c:2
EActions
Definition EActions.c:2
eAgents
Definition EAgents.c:3
void ReplaceEdibleWithNew(string typeName)
ref FoodStage m_FoodStage
bool IsFoodRotten()
static float GetFoodWater(ItemBase item, string classname="", int food_stage=0)
override bool CanBeCooked()
bool IsFoodBaked()
override string GetDebugText()
override void AfterStoreLoad()
string m_SoundPlaying
void Edible_Base()
float m_DecayDelta
void Synchronize()
override void OnVariablesSynchronized()
const string SOUND_BURNING_DONE
bool CanChangeToNewStage(CookingMethodType cooking_method)
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
void RemoveAudio()
float GetDecayDelta()
override void SetActions()
bool m_MakeCookingSounds
void SoundCookingStop()
const string DIRECT_COOKING_SLOT_NAME
FoodStageType GetNextFoodStageType(CookingMethodType cooking_method)
void ChangeFoodStage(FoodStageType new_food_stage_type)
void OnConsume(float amount, PlayerBase consumer)
FoodStage GetFoodStage()
static float GetFoodNutritionalIndex(ItemBase item, string classname="", int food_stage=0)
SoundOnVehicle m_SoundCooking
static float GetFoodToxicity(ItemBase item, string classname="", int food_stage=0)
override bool CanDecay()
const string SOUND_BAKING_DONE
static NutritionalProfile GetNutritionalProfile(ItemBase item, string classname="", int food_stage=0)
override void EEDelete(EntityAI parent)
FoodStageType m_LastDecayStage
override bool CanHaveTemperature()
float GetCookingTime()
override bool CanBeCookedOnStick()
override bool IsCorpse()
void UpdateVisuals()
float GetDecayTimer()
FoodStageType GetLastDecayStage()
string GetFoodStageName(FoodStageType food_stage_type)
static float GetFoodDigestibility(ItemBase item, string classname="", int food_stage=0)
void TransferFoodStage(notnull Edible_Base source)
override void ProcessDecay(float delta, bool hasRootAsPlayer)
void SetCookingTime(float time)
void SoundCookingStart(string sound_name)
override bool IsMeat()
const string SOUND_BAKING_START
static float GetFoodTotalVolume(ItemBase item, string classname="", int food_stage=0)
override bool IsFruit()
Edible_Base ItemBase ReplaceEdibleWithNewLambda(EntityAI old_item, string new_item_type, PlayerBase player)
bool Consume(float amount, PlayerBase consumer)
EffectSound m_SoundEffectCooking
DEPRECATED.
override bool OnStoreLoad(ParamsReadContext ctx, int version)
FoodStageType GetFoodStageType()
override bool CanProcessDecay()
void MakeSoundsOnClient(bool soundstate, CookingMethodType cookingMethod=CookingMethodType.NONE)
static int GetFoodAgents(ItemBase item, string classname="", int food_stage=0)
override bool IsMushroom()
static float GetFoodEnergy(ItemBase item, string classname="", int food_stage=0)
void RefreshAudio()
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
CookingMethodType m_CookedByMethod
bool IsFoodDried()
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
override void OnStoreSave(ParamsWriteContext ctx)
bool IsFoodRaw()
bool IsFoodBurned()
override void EEInit()
bool IsFoodBoiled()
float m_DecayTimer
FoodStageType
Definition FoodStage.c:2
InventoryLocationType
types of Inventory Location
override void InsertAgent(int agent, float count=1)
Definition ItemBase.c:8539
bool AddQuantity(float value, bool destroy_config=true, bool destroy_forced=false)
add item quantity[related to varQuantity... config entry], destroy_config = true > if the quantity re...
Definition ItemBase.c:7900
bool HasFoodStage()
Definition ItemBase.c:7038
class JsonUndergroundAreaTriggerData GetPosition
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
override void Stop()
Stops sound.
InventoryLocation.
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string
Definition EnMath.c:7
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
const float DECAY_FOOD_BAKED_FRVG
Definition constants.c:894
const float DECAY_FOOD_CAN_OPEN
Definition constants.c:896
const float DECAY_FOOD_RAW_FRVG
Definition constants.c:890
const int DECAY_TIMER_RANDOM_PERCENTAGE
Definition constants.c:898
const int DECAY_FOOD_FRVG_DRIED_CHANCE
Definition constants.c:897
const float DECAY_FOOD_RAW_MEAT
Definition constants.c:888
const float DECAY_FOOD_BAKED_MEAT
Definition constants.c:893
const float DECAY_FOOD_BOILED_MEAT
Definition constants.c:891
const float DECAY_FOOD_BOILED_FRVG
Definition constants.c:892
const float DECAY_FOOD_DRIED_MEAT
Definition constants.c:895
const float DECAY_FOOD_RAW_CORPSE
Definition constants.c:889
const float DECAY_RATE_ON_PLAYER
Definition constants.c:899
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:126
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54
const int SAT_DEBUG_ACTION
Definition constants.c:424

◆ CanBeCookedOnStick()

override bool ReplaceEdibleWithNewLambda::CanBeCookedOnStick ( )
private

Definition at line 848 of file Edible_Base.c.

848 : ItemBase
849{
850 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
851
852 const string SOUND_BAKING_START = "Baking_SoundSet";
853 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
854 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
855
856 protected bool m_MakeCookingSounds;
859 protected string m_SoundPlaying;
861 protected float m_DecayTimer;
862 protected float m_DecayDelta = 0.0;
864
866
867 void Edible_Base()
868 {
869 if (HasFoodStage())
870 {
871 m_FoodStage = new FoodStage(this);
872
873 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
874 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
875 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
876 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
877 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
878
879 m_SoundPlaying = "";
881 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
882 RegisterNetSyncVariableBool("m_MakeCookingSounds");
883 }
884 }
885
886 override void EEInit()
887 {
888 super.EEInit();
889
891 }
892
893 override void EEDelete(EntityAI parent)
894 {
895 super.EEDelete(parent);
896
897 RemoveAudio();
898 }
899
901 {
902 super.EEItemLocationChanged(oldLoc, newLoc);
903
905 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
906 {
907 switch (oldLoc.GetParent().GetType())
908 {
909 case "FryingPan":
910 case "Pot":
911 case "Cauldron":
912 case "SharpWoodenStick":
913 MakeSoundsOnClient(false);
914 break;
915 }
916
918 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
919 MakeSoundsOnClient(false);
920 }
921 }
922
923 void UpdateVisuals()
924 {
925 if (GetFoodStage())
926 GetFoodStage().UpdateVisuals();
927 }
928
929 bool Consume(float amount, PlayerBase consumer)
930 {
931 AddQuantity(-amount, false, false);
932 OnConsume(amount, consumer);
933
934 return true;
935 }
936
937 void OnConsume(float amount, PlayerBase consumer);
938
939 //food staging
940 override bool CanBeCooked()
941 {
942 return false;
943 }
944
945 override bool CanBeCookedOnStick()
946 {
947 return false;
948 }
949
950 //================================================================
951 // SYNCHRONIZATION
952 //================================================================
953 void Synchronize()
954 {
955 SetSynchDirty();
956
957 if (GetGame().IsMultiplayer())
959 }
960
961 override void OnVariablesSynchronized()
962 {
963 super.OnVariablesSynchronized();
964
966
967 //update audio
969 RefreshAudio();
970 else
971 RemoveAudio();
972 }
973
974 //================================================================
975 // AUDIO EFFECTS (WHEN ON DCS)
976 //================================================================
978 {
981
982 Synchronize();
983 }
984
985 protected void RefreshAudio()
986 {
987 string soundName = "";
988
990
991 switch (GetFoodStageType())
992 {
993 case FoodStageType.RAW:
995 if (nextFoodState == FoodStageType.BOILED)
996 soundName = "";
997 break;
998 case FoodStageType.BAKED:
1000 break;
1001 case FoodStageType.BURNED:
1003 break;
1004 default:
1005 soundName = "";
1006 break;
1007 }
1008
1010 }
1011
1012 protected void RemoveAudio()
1013 {
1014 m_MakeCookingSounds = false;
1016 }
1017
1018 //================================================================
1019 // SERIALIZATION
1020 //================================================================
1021 override void OnStoreSave(ParamsWriteContext ctx)
1022 {
1023 super.OnStoreSave(ctx);
1024
1025 if (GetFoodStage())
1026 GetFoodStage().OnStoreSave(ctx);
1027
1028 // food decay
1029 ctx.Write(m_DecayTimer);
1030 ctx.Write(m_LastDecayStage);
1031 }
1032
1033 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1034 {
1035 if (!super.OnStoreLoad(ctx, version))
1036 return false;
1037
1038 if (GetFoodStage())
1039 {
1040 if (!GetFoodStage().OnStoreLoad(ctx, version))
1041 return false;
1042 }
1043
1044 if (version >= 115)
1045 {
1046 if (!ctx.Read(m_DecayTimer))
1047 {
1048 m_DecayTimer = 0.0;
1049 return false;
1050 }
1051 if (!ctx.Read(m_LastDecayStage))
1052 {
1054 return false;
1055 }
1056 }
1057
1058 return true;
1059 }
1060
1061 override void AfterStoreLoad()
1062 {
1063 super.AfterStoreLoad();
1064
1065 Synchronize();
1066 }
1067
1068 //get food stage
1070 {
1071 return m_FoodStage;
1072 }
1073
1074 //food types
1075 override bool IsMeat()
1076 {
1077 return false;
1078 }
1079
1080 override bool IsCorpse()
1081 {
1082 return false;
1083 }
1084
1085 override bool IsFruit()
1086 {
1087 return false;
1088 }
1089
1090 override bool IsMushroom()
1091 {
1092 return false;
1093 }
1094
1095 //================================================================
1096 // NUTRITIONAL VALUES
1097 //================================================================
1098 //food properties
1099 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1100 {
1102 if (food_item && food_item.GetFoodStage())
1103 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1104 else if (classname != "" && food_stage)
1105 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1106 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1107 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1108
1109 }
1110
1111 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1112 {
1114 if (food_item && food_item.GetFoodStage())
1115 return FoodStage.GetEnergy(food_item.GetFoodStage());
1116 else if (classname != "" && food_stage)
1117 return FoodStage.GetEnergy(null, food_stage, classname);
1118 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1119 return GetGame().ConfigGetFloat(class_path + " energy");
1120 }
1121
1122 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1123 {
1125 if (food_item && food_item.GetFoodStage())
1126 return FoodStage.GetWater(food_item.GetFoodStage());
1127 else if (classname != "" && food_stage)
1128 return FoodStage.GetWater(null, food_stage, classname);
1129 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1130 return GetGame().ConfigGetFloat(class_path + " water");
1131 }
1132
1133 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1134 {
1136 if (food_item && food_item.GetFoodStage())
1137 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1138 else if (classname != "" && food_stage)
1139 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1140 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1141 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1142
1143 }
1144
1145 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1146 {
1148 if (food_item && food_item.GetFoodStage())
1149 return FoodStage.GetToxicity(food_item.GetFoodStage());
1150 else if (classname != "" && food_stage)
1151 return FoodStage.GetToxicity(null, food_stage, classname);
1152 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1153 return GetGame().ConfigGetFloat(class_path + " toxicity");
1154 }
1155
1156 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1157 {
1159 if (food_item && food_item.GetFoodStage())
1160 return FoodStage.GetAgents(food_item.GetFoodStage());
1161 else if (classname != "" && food_stage)
1162 return FoodStage.GetAgents(null, food_stage, classname);
1163 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1164 return GetGame().ConfigGetInt(class_path + " agents");
1165 }
1166
1167 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1168 {
1170 if (food_item && food_item.GetFoodStage())
1171 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1172 else if (classname != "" && food_stage)
1173 return FoodStage.GetDigestibility(null, food_stage, classname);
1174 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1175 return GetGame().ConfigGetInt(class_path + " digestibility");
1176 }
1177
1179 {
1181 }
1182
1183 //================================================================
1184 // FOOD STAGING
1185 //================================================================
1187 {
1188 return GetFoodStage().GetFoodStageType();
1189 }
1190
1191 //food stage states
1192 bool IsFoodRaw()
1193 {
1194 if (GetFoodStage())
1195 return GetFoodStage().IsFoodRaw();
1196
1197 return false;
1198 }
1199
1200 bool IsFoodBaked()
1201 {
1202 if (GetFoodStage())
1203 return GetFoodStage().IsFoodBaked();
1204
1205 return false;
1206 }
1207
1208 bool IsFoodBoiled()
1209 {
1210 if (GetFoodStage())
1211 return GetFoodStage().IsFoodBoiled();
1212
1213 return false;
1214 }
1215
1216 bool IsFoodDried()
1217 {
1218 if (GetFoodStage())
1219 return GetFoodStage().IsFoodDried();
1220
1221 return false;
1222 }
1223
1224 bool IsFoodBurned()
1225 {
1226 if (GetFoodStage())
1227 return GetFoodStage().IsFoodBurned();
1228
1229 return false;
1230 }
1231
1232 bool IsFoodRotten()
1233 {
1234 if (GetFoodStage())
1235 return GetFoodStage().IsFoodRotten();
1236
1237 return false;
1238 }
1239
1240 //food stage change
1242 {
1243 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1244 }
1245
1247 {
1248 return GetFoodStage().GetNextFoodStageType(cooking_method);
1249 }
1250
1252 {
1253 return GetFoodStage().GetFoodStageName(food_stage_type);
1254 }
1255
1257 {
1258 return GetFoodStage().CanChangeToNewStage(cooking_method);
1259 }
1260
1261 //Use this to receive food stage from another Edible_Base
1263 {
1264 if (!source.HasFoodStage())
1265 return;
1266 m_LastDecayStage = source.GetLastDecayStage();
1267 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1268 m_DecayTimer = source.GetDecayTimer();
1269 m_DecayDelta = source.GetDecayDelta();
1270 }
1271
1272 //================================================================
1273 // COOKING
1274 //================================================================
1275 //cooking time
1276 float GetCookingTime()
1277 {
1278 return GetFoodStage().GetCookingTime();
1279 }
1280
1281 void SetCookingTime(float time)
1282 {
1283 GetFoodStage().SetCookingTime(time);
1284
1285 //synchronize when calling on server
1286 Synchronize();
1287 }
1288
1289 //replace edible with new item (opening cans)
1290 void ReplaceEdibleWithNew(string typeName)
1291 {
1292 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1293 if (player)
1294 {
1296 player.ServerReplaceItemInHandsWithNew(lambda);
1297 }
1298 else
1299 Error("ReplaceEdibleWithNew - cannot use edible without player");
1300 }
1301
1302 override void SetActions()
1303 {
1304 super.SetActions();
1305
1306 AddAction(ActionAttach);
1308 }
1309
1310 protected void SoundCookingStart(string sound_name)
1311 {
1312#ifndef SERVER
1314 {
1316
1319 }
1320#endif
1321 }
1322
1323 protected void SoundCookingStop()
1324 {
1325#ifndef SERVER
1327 {
1330 m_SoundPlaying = "";
1331 }
1332#endif
1333 }
1334
1335 override bool CanHaveTemperature()
1336 {
1337 return true;
1338 }
1339
1340 override bool CanDecay()
1341 {
1342 return false;
1343 }
1344
1345 override bool CanProcessDecay()
1346 {
1347 return (GetFoodStageType() != FoodStageType.ROTTEN);
1348 }
1349
1350 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1351 {
1352 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1353 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1354 if (hasRootAsPlayer)
1356
1357 /*Print( "-------------------------" );
1358 Print( this );
1359 Print( m_DecayTimer );
1360 Print( m_DecayDelta );
1361 Print( m_LastDecayStage );*/
1362
1363 if (IsFruit() || IsMushroom())
1364 {
1365 // fruit, vegetables and mushrooms
1367 {
1368 switch (GetFoodStageType())
1369 {
1370 case FoodStageType.RAW:
1373 break;
1374
1375 case FoodStageType.BOILED:
1378 break;
1379
1380 case FoodStageType.BAKED:
1383 break;
1384
1385 case FoodStageType.DRIED:
1386 case FoodStageType.BURNED:
1387 case FoodStageType.ROTTEN:
1388 default:
1389 m_DecayTimer = -1;
1391 return;
1392 }
1393
1394 //m_DecayTimer = m_DecayTimer / 1000.0;
1395 }
1396
1398
1399 if (m_DecayTimer <= 0)
1400 {
1401 if (m_LastDecayStage != FoodStageType.NONE)
1402 {
1403 // switch to decayed stage
1404 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1407 {
1408 int rng = Math.RandomIntInclusive(0, 100);
1411 else
1412 {
1415 else
1417 }
1418 }
1419 }
1420 }
1421
1422 }
1423 else if (IsMeat())
1424 {
1425 // meat
1427 {
1428 switch (GetFoodStageType())
1429 {
1430 case FoodStageType.RAW:
1433 break;
1434
1435 case FoodStageType.BOILED:
1438 break;
1439
1440 case FoodStageType.BAKED:
1443 break;
1444
1445 case FoodStageType.DRIED:
1448 break;
1449
1450 case FoodStageType.BURNED:
1451 case FoodStageType.ROTTEN:
1452 default:
1453 m_DecayTimer = -1;
1455 return;
1456 }
1457 }
1458
1460
1461 if (m_DecayTimer <= 0)
1462 {
1463 if (m_LastDecayStage != FoodStageType.NONE)
1464 {
1465 // switch to decayed stage
1468 }
1469 }
1470 }
1471 else if (IsCorpse())
1472 {
1473 // corpse
1475 {
1476 switch (GetFoodStageType())
1477 {
1478 case FoodStageType.RAW:
1481 break;
1482
1483 case FoodStageType.BURNED:
1484 case FoodStageType.ROTTEN:
1485 default:
1486 m_DecayTimer = -1;
1488 return;
1489 }
1490 }
1491
1493
1494 if (m_DecayTimer <= 0)
1495 {
1496 if (m_LastDecayStage != FoodStageType.NONE)
1497 {
1498 // switch to decayed stage
1501 }
1502 }
1503 }
1504 else
1505 {
1506 // opened cans
1508
1509 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1510 {
1513 //m_DecayTimer = m_DecayTimer / 1000.0;
1514 }
1515 else
1516 {
1517 if (m_DecayTimer <= 0)
1518 {
1519 InsertAgent(eAgents.FOOD_POISON, 1);
1520 m_DecayTimer = -1;
1521 }
1522 }
1523 }
1524
1525 m_DecayDelta = 0.0;
1526 }
1527
1529 {
1530 super.GetDebugActions(outputList);
1531
1532 if (HasFoodStage())
1533 {
1534 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1535 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1536 }
1537 }
1538
1539 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1540 {
1541 super.OnAction(action_id, player, ctx);
1542
1543 if (GetGame().IsServer())
1544 {
1545 if (action_id == EActions.FOOD_STAGE_PREV)
1546 {
1548 if (food_stage_prev <= 0)
1549 food_stage_prev = FoodStageType.COUNT - 1;
1551 return true;
1552 }
1553 else if (action_id == EActions.FOOD_STAGE_NEXT)
1554 {
1556 if (food_stage_next >= FoodStageType.COUNT)
1559 return true;
1560 }
1561 }
1562 return false;
1563 }
1564
1565 override string GetDebugText()
1566 {
1567 string debug_output;
1568
1569 debug_output = super.GetDebugText();
1570
1571 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1572 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1573
1574 return debug_output;
1575 }
1576
1577 //================================================================
1578 // GENERAL GETTERS
1579 //================================================================
1580
1581 float GetDecayTimer()
1582 {
1583 return m_DecayTimer;
1584 }
1585
1586 float GetDecayDelta()
1587 {
1588 return m_DecayDelta;
1589 }
1590
1592 {
1593 return m_LastDecayStage;
1594 }
1595}
1596
1598{
1600};

◆ CanChangeToNewStage()

bool ReplaceEdibleWithNewLambda::CanChangeToNewStage ( CookingMethodType cooking_method)
protected

Definition at line 1159 of file Edible_Base.c.

1159 : ItemBase
1160{
1161 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1162
1163 const string SOUND_BAKING_START = "Baking_SoundSet";
1164 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1165 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1166
1167 protected bool m_MakeCookingSounds;
1168 protected SoundOnVehicle m_SoundCooking;
1170 protected string m_SoundPlaying;
1172 protected float m_DecayTimer;
1173 protected float m_DecayDelta = 0.0;
1175
1177
1178 void Edible_Base()
1179 {
1180 if (HasFoodStage())
1181 {
1182 m_FoodStage = new FoodStage(this);
1183
1184 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1185 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1186 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1187 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1188 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1189
1190 m_SoundPlaying = "";
1192 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1193 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1194 }
1195 }
1196
1197 override void EEInit()
1198 {
1199 super.EEInit();
1200
1201 UpdateVisuals();
1202 }
1203
1204 override void EEDelete(EntityAI parent)
1205 {
1206 super.EEDelete(parent);
1207
1208 RemoveAudio();
1209 }
1210
1212 {
1213 super.EEItemLocationChanged(oldLoc, newLoc);
1214
1216 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1217 {
1218 switch (oldLoc.GetParent().GetType())
1219 {
1220 case "FryingPan":
1221 case "Pot":
1222 case "Cauldron":
1223 case "SharpWoodenStick":
1224 MakeSoundsOnClient(false);
1225 break;
1226 }
1227
1229 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1230 MakeSoundsOnClient(false);
1231 }
1232 }
1233
1234 void UpdateVisuals()
1235 {
1236 if (GetFoodStage())
1237 GetFoodStage().UpdateVisuals();
1238 }
1239
1240 bool Consume(float amount, PlayerBase consumer)
1241 {
1242 AddQuantity(-amount, false, false);
1243 OnConsume(amount, consumer);
1244
1245 return true;
1246 }
1247
1248 void OnConsume(float amount, PlayerBase consumer);
1249
1250 //food staging
1251 override bool CanBeCooked()
1252 {
1253 return false;
1254 }
1255
1256 override bool CanBeCookedOnStick()
1257 {
1258 return false;
1259 }
1260
1261 //================================================================
1262 // SYNCHRONIZATION
1263 //================================================================
1264 void Synchronize()
1265 {
1266 SetSynchDirty();
1267
1268 if (GetGame().IsMultiplayer())
1269 UpdateVisuals();
1270 }
1271
1272 override void OnVariablesSynchronized()
1273 {
1274 super.OnVariablesSynchronized();
1275
1276 UpdateVisuals();
1277
1278 //update audio
1280 RefreshAudio();
1281 else
1282 RemoveAudio();
1283 }
1284
1285 //================================================================
1286 // AUDIO EFFECTS (WHEN ON DCS)
1287 //================================================================
1289 {
1292
1293 Synchronize();
1294 }
1295
1296 protected void RefreshAudio()
1297 {
1298 string soundName = "";
1299
1301
1302 switch (GetFoodStageType())
1303 {
1304 case FoodStageType.RAW:
1306 if (nextFoodState == FoodStageType.BOILED)
1307 soundName = "";
1308 break;
1309 case FoodStageType.BAKED:
1311 break;
1312 case FoodStageType.BURNED:
1314 break;
1315 default:
1316 soundName = "";
1317 break;
1318 }
1319
1321 }
1322
1323 protected void RemoveAudio()
1324 {
1325 m_MakeCookingSounds = false;
1327 }
1328
1329 //================================================================
1330 // SERIALIZATION
1331 //================================================================
1332 override void OnStoreSave(ParamsWriteContext ctx)
1333 {
1334 super.OnStoreSave(ctx);
1335
1336 if (GetFoodStage())
1337 GetFoodStage().OnStoreSave(ctx);
1338
1339 // food decay
1340 ctx.Write(m_DecayTimer);
1341 ctx.Write(m_LastDecayStage);
1342 }
1343
1344 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1345 {
1346 if (!super.OnStoreLoad(ctx, version))
1347 return false;
1348
1349 if (GetFoodStage())
1350 {
1351 if (!GetFoodStage().OnStoreLoad(ctx, version))
1352 return false;
1353 }
1354
1355 if (version >= 115)
1356 {
1357 if (!ctx.Read(m_DecayTimer))
1358 {
1359 m_DecayTimer = 0.0;
1360 return false;
1361 }
1362 if (!ctx.Read(m_LastDecayStage))
1363 {
1365 return false;
1366 }
1367 }
1368
1369 return true;
1370 }
1371
1372 override void AfterStoreLoad()
1373 {
1374 super.AfterStoreLoad();
1375
1376 Synchronize();
1377 }
1378
1379 //get food stage
1381 {
1382 return m_FoodStage;
1383 }
1384
1385 //food types
1386 override bool IsMeat()
1387 {
1388 return false;
1389 }
1390
1391 override bool IsCorpse()
1392 {
1393 return false;
1394 }
1395
1396 override bool IsFruit()
1397 {
1398 return false;
1399 }
1400
1401 override bool IsMushroom()
1402 {
1403 return false;
1404 }
1405
1406 //================================================================
1407 // NUTRITIONAL VALUES
1408 //================================================================
1409 //food properties
1410 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1411 {
1413 if (food_item && food_item.GetFoodStage())
1414 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1415 else if (classname != "" && food_stage)
1416 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1417 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1418 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1419
1420 }
1421
1422 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1423 {
1425 if (food_item && food_item.GetFoodStage())
1426 return FoodStage.GetEnergy(food_item.GetFoodStage());
1427 else if (classname != "" && food_stage)
1428 return FoodStage.GetEnergy(null, food_stage, classname);
1429 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1430 return GetGame().ConfigGetFloat(class_path + " energy");
1431 }
1432
1433 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1434 {
1436 if (food_item && food_item.GetFoodStage())
1437 return FoodStage.GetWater(food_item.GetFoodStage());
1438 else if (classname != "" && food_stage)
1439 return FoodStage.GetWater(null, food_stage, classname);
1440 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1441 return GetGame().ConfigGetFloat(class_path + " water");
1442 }
1443
1444 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1445 {
1447 if (food_item && food_item.GetFoodStage())
1448 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1449 else if (classname != "" && food_stage)
1450 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1451 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1452 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1453
1454 }
1455
1456 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1457 {
1459 if (food_item && food_item.GetFoodStage())
1460 return FoodStage.GetToxicity(food_item.GetFoodStage());
1461 else if (classname != "" && food_stage)
1462 return FoodStage.GetToxicity(null, food_stage, classname);
1463 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1464 return GetGame().ConfigGetFloat(class_path + " toxicity");
1465 }
1466
1467 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1468 {
1470 if (food_item && food_item.GetFoodStage())
1471 return FoodStage.GetAgents(food_item.GetFoodStage());
1472 else if (classname != "" && food_stage)
1473 return FoodStage.GetAgents(null, food_stage, classname);
1474 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1475 return GetGame().ConfigGetInt(class_path + " agents");
1476 }
1477
1478 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1479 {
1481 if (food_item && food_item.GetFoodStage())
1482 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1483 else if (classname != "" && food_stage)
1484 return FoodStage.GetDigestibility(null, food_stage, classname);
1485 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1486 return GetGame().ConfigGetInt(class_path + " digestibility");
1487 }
1488
1490 {
1492 }
1493
1494 //================================================================
1495 // FOOD STAGING
1496 //================================================================
1498 {
1499 return GetFoodStage().GetFoodStageType();
1500 }
1501
1502 //food stage states
1503 bool IsFoodRaw()
1504 {
1505 if (GetFoodStage())
1506 return GetFoodStage().IsFoodRaw();
1507
1508 return false;
1509 }
1510
1511 bool IsFoodBaked()
1512 {
1513 if (GetFoodStage())
1514 return GetFoodStage().IsFoodBaked();
1515
1516 return false;
1517 }
1518
1519 bool IsFoodBoiled()
1520 {
1521 if (GetFoodStage())
1522 return GetFoodStage().IsFoodBoiled();
1523
1524 return false;
1525 }
1526
1527 bool IsFoodDried()
1528 {
1529 if (GetFoodStage())
1530 return GetFoodStage().IsFoodDried();
1531
1532 return false;
1533 }
1534
1535 bool IsFoodBurned()
1536 {
1537 if (GetFoodStage())
1538 return GetFoodStage().IsFoodBurned();
1539
1540 return false;
1541 }
1542
1543 bool IsFoodRotten()
1544 {
1545 if (GetFoodStage())
1546 return GetFoodStage().IsFoodRotten();
1547
1548 return false;
1549 }
1550
1551 //food stage change
1553 {
1554 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1555 }
1556
1558 {
1559 return GetFoodStage().GetNextFoodStageType(cooking_method);
1560 }
1561
1563 {
1564 return GetFoodStage().GetFoodStageName(food_stage_type);
1565 }
1566
1568 {
1569 return GetFoodStage().CanChangeToNewStage(cooking_method);
1570 }
1571
1572 //Use this to receive food stage from another Edible_Base
1574 {
1575 if (!source.HasFoodStage())
1576 return;
1577 m_LastDecayStage = source.GetLastDecayStage();
1578 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1579 m_DecayTimer = source.GetDecayTimer();
1580 m_DecayDelta = source.GetDecayDelta();
1581 }
1582
1583 //================================================================
1584 // COOKING
1585 //================================================================
1586 //cooking time
1587 float GetCookingTime()
1588 {
1589 return GetFoodStage().GetCookingTime();
1590 }
1591
1592 void SetCookingTime(float time)
1593 {
1594 GetFoodStage().SetCookingTime(time);
1595
1596 //synchronize when calling on server
1597 Synchronize();
1598 }
1599
1600 //replace edible with new item (opening cans)
1601 void ReplaceEdibleWithNew(string typeName)
1602 {
1603 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1604 if (player)
1605 {
1607 player.ServerReplaceItemInHandsWithNew(lambda);
1608 }
1609 else
1610 Error("ReplaceEdibleWithNew - cannot use edible without player");
1611 }
1612
1613 override void SetActions()
1614 {
1615 super.SetActions();
1616
1617 AddAction(ActionAttach);
1619 }
1620
1621 protected void SoundCookingStart(string sound_name)
1622 {
1623#ifndef SERVER
1625 {
1627
1630 }
1631#endif
1632 }
1633
1634 protected void SoundCookingStop()
1635 {
1636#ifndef SERVER
1638 {
1641 m_SoundPlaying = "";
1642 }
1643#endif
1644 }
1645
1646 override bool CanHaveTemperature()
1647 {
1648 return true;
1649 }
1650
1651 override bool CanDecay()
1652 {
1653 return false;
1654 }
1655
1656 override bool CanProcessDecay()
1657 {
1658 return (GetFoodStageType() != FoodStageType.ROTTEN);
1659 }
1660
1661 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1662 {
1663 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1664 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1665 if (hasRootAsPlayer)
1667
1668 /*Print( "-------------------------" );
1669 Print( this );
1670 Print( m_DecayTimer );
1671 Print( m_DecayDelta );
1672 Print( m_LastDecayStage );*/
1673
1674 if (IsFruit() || IsMushroom())
1675 {
1676 // fruit, vegetables and mushrooms
1678 {
1679 switch (GetFoodStageType())
1680 {
1681 case FoodStageType.RAW:
1684 break;
1685
1686 case FoodStageType.BOILED:
1689 break;
1690
1691 case FoodStageType.BAKED:
1694 break;
1695
1696 case FoodStageType.DRIED:
1697 case FoodStageType.BURNED:
1698 case FoodStageType.ROTTEN:
1699 default:
1700 m_DecayTimer = -1;
1702 return;
1703 }
1704
1705 //m_DecayTimer = m_DecayTimer / 1000.0;
1706 }
1707
1709
1710 if (m_DecayTimer <= 0)
1711 {
1712 if (m_LastDecayStage != FoodStageType.NONE)
1713 {
1714 // switch to decayed stage
1715 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1718 {
1719 int rng = Math.RandomIntInclusive(0, 100);
1722 else
1723 {
1726 else
1728 }
1729 }
1730 }
1731 }
1732
1733 }
1734 else if (IsMeat())
1735 {
1736 // meat
1738 {
1739 switch (GetFoodStageType())
1740 {
1741 case FoodStageType.RAW:
1744 break;
1745
1746 case FoodStageType.BOILED:
1749 break;
1750
1751 case FoodStageType.BAKED:
1754 break;
1755
1756 case FoodStageType.DRIED:
1759 break;
1760
1761 case FoodStageType.BURNED:
1762 case FoodStageType.ROTTEN:
1763 default:
1764 m_DecayTimer = -1;
1766 return;
1767 }
1768 }
1769
1771
1772 if (m_DecayTimer <= 0)
1773 {
1774 if (m_LastDecayStage != FoodStageType.NONE)
1775 {
1776 // switch to decayed stage
1779 }
1780 }
1781 }
1782 else if (IsCorpse())
1783 {
1784 // corpse
1786 {
1787 switch (GetFoodStageType())
1788 {
1789 case FoodStageType.RAW:
1792 break;
1793
1794 case FoodStageType.BURNED:
1795 case FoodStageType.ROTTEN:
1796 default:
1797 m_DecayTimer = -1;
1799 return;
1800 }
1801 }
1802
1804
1805 if (m_DecayTimer <= 0)
1806 {
1807 if (m_LastDecayStage != FoodStageType.NONE)
1808 {
1809 // switch to decayed stage
1812 }
1813 }
1814 }
1815 else
1816 {
1817 // opened cans
1819
1820 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1821 {
1824 //m_DecayTimer = m_DecayTimer / 1000.0;
1825 }
1826 else
1827 {
1828 if (m_DecayTimer <= 0)
1829 {
1830 InsertAgent(eAgents.FOOD_POISON, 1);
1831 m_DecayTimer = -1;
1832 }
1833 }
1834 }
1835
1836 m_DecayDelta = 0.0;
1837 }
1838
1840 {
1841 super.GetDebugActions(outputList);
1842
1843 if (HasFoodStage())
1844 {
1845 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1846 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1847 }
1848 }
1849
1850 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1851 {
1852 super.OnAction(action_id, player, ctx);
1853
1854 if (GetGame().IsServer())
1855 {
1856 if (action_id == EActions.FOOD_STAGE_PREV)
1857 {
1859 if (food_stage_prev <= 0)
1860 food_stage_prev = FoodStageType.COUNT - 1;
1862 return true;
1863 }
1864 else if (action_id == EActions.FOOD_STAGE_NEXT)
1865 {
1867 if (food_stage_next >= FoodStageType.COUNT)
1870 return true;
1871 }
1872 }
1873 return false;
1874 }
1875
1876 override string GetDebugText()
1877 {
1878 string debug_output;
1879
1880 debug_output = super.GetDebugText();
1881
1882 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1883 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1884
1885 return debug_output;
1886 }
1887
1888 //================================================================
1889 // GENERAL GETTERS
1890 //================================================================
1891
1892 float GetDecayTimer()
1893 {
1894 return m_DecayTimer;
1895 }
1896
1897 float GetDecayDelta()
1898 {
1899 return m_DecayDelta;
1900 }
1901
1903 {
1904 return m_LastDecayStage;
1905 }
1906}
1907
1909{
1911};

◆ CanDecay()

override bool ReplaceEdibleWithNewLambda::CanDecay ( )
protected

Definition at line 1243 of file Edible_Base.c.

1243 : ItemBase
1244{
1245 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1246
1247 const string SOUND_BAKING_START = "Baking_SoundSet";
1248 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1249 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1250
1251 protected bool m_MakeCookingSounds;
1252 protected SoundOnVehicle m_SoundCooking;
1254 protected string m_SoundPlaying;
1256 protected float m_DecayTimer;
1257 protected float m_DecayDelta = 0.0;
1259
1261
1262 void Edible_Base()
1263 {
1264 if (HasFoodStage())
1265 {
1266 m_FoodStage = new FoodStage(this);
1267
1268 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1269 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1270 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1271 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1272 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1273
1274 m_SoundPlaying = "";
1276 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1277 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1278 }
1279 }
1280
1281 override void EEInit()
1282 {
1283 super.EEInit();
1284
1285 UpdateVisuals();
1286 }
1287
1288 override void EEDelete(EntityAI parent)
1289 {
1290 super.EEDelete(parent);
1291
1292 RemoveAudio();
1293 }
1294
1296 {
1297 super.EEItemLocationChanged(oldLoc, newLoc);
1298
1300 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1301 {
1302 switch (oldLoc.GetParent().GetType())
1303 {
1304 case "FryingPan":
1305 case "Pot":
1306 case "Cauldron":
1307 case "SharpWoodenStick":
1308 MakeSoundsOnClient(false);
1309 break;
1310 }
1311
1313 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1314 MakeSoundsOnClient(false);
1315 }
1316 }
1317
1318 void UpdateVisuals()
1319 {
1320 if (GetFoodStage())
1321 GetFoodStage().UpdateVisuals();
1322 }
1323
1324 bool Consume(float amount, PlayerBase consumer)
1325 {
1326 AddQuantity(-amount, false, false);
1327 OnConsume(amount, consumer);
1328
1329 return true;
1330 }
1331
1332 void OnConsume(float amount, PlayerBase consumer);
1333
1334 //food staging
1335 override bool CanBeCooked()
1336 {
1337 return false;
1338 }
1339
1340 override bool CanBeCookedOnStick()
1341 {
1342 return false;
1343 }
1344
1345 //================================================================
1346 // SYNCHRONIZATION
1347 //================================================================
1348 void Synchronize()
1349 {
1350 SetSynchDirty();
1351
1352 if (GetGame().IsMultiplayer())
1353 UpdateVisuals();
1354 }
1355
1356 override void OnVariablesSynchronized()
1357 {
1358 super.OnVariablesSynchronized();
1359
1360 UpdateVisuals();
1361
1362 //update audio
1364 RefreshAudio();
1365 else
1366 RemoveAudio();
1367 }
1368
1369 //================================================================
1370 // AUDIO EFFECTS (WHEN ON DCS)
1371 //================================================================
1373 {
1376
1377 Synchronize();
1378 }
1379
1380 protected void RefreshAudio()
1381 {
1382 string soundName = "";
1383
1385
1386 switch (GetFoodStageType())
1387 {
1388 case FoodStageType.RAW:
1390 if (nextFoodState == FoodStageType.BOILED)
1391 soundName = "";
1392 break;
1393 case FoodStageType.BAKED:
1395 break;
1396 case FoodStageType.BURNED:
1398 break;
1399 default:
1400 soundName = "";
1401 break;
1402 }
1403
1405 }
1406
1407 protected void RemoveAudio()
1408 {
1409 m_MakeCookingSounds = false;
1411 }
1412
1413 //================================================================
1414 // SERIALIZATION
1415 //================================================================
1416 override void OnStoreSave(ParamsWriteContext ctx)
1417 {
1418 super.OnStoreSave(ctx);
1419
1420 if (GetFoodStage())
1421 GetFoodStage().OnStoreSave(ctx);
1422
1423 // food decay
1424 ctx.Write(m_DecayTimer);
1425 ctx.Write(m_LastDecayStage);
1426 }
1427
1428 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1429 {
1430 if (!super.OnStoreLoad(ctx, version))
1431 return false;
1432
1433 if (GetFoodStage())
1434 {
1435 if (!GetFoodStage().OnStoreLoad(ctx, version))
1436 return false;
1437 }
1438
1439 if (version >= 115)
1440 {
1441 if (!ctx.Read(m_DecayTimer))
1442 {
1443 m_DecayTimer = 0.0;
1444 return false;
1445 }
1446 if (!ctx.Read(m_LastDecayStage))
1447 {
1449 return false;
1450 }
1451 }
1452
1453 return true;
1454 }
1455
1456 override void AfterStoreLoad()
1457 {
1458 super.AfterStoreLoad();
1459
1460 Synchronize();
1461 }
1462
1463 //get food stage
1465 {
1466 return m_FoodStage;
1467 }
1468
1469 //food types
1470 override bool IsMeat()
1471 {
1472 return false;
1473 }
1474
1475 override bool IsCorpse()
1476 {
1477 return false;
1478 }
1479
1480 override bool IsFruit()
1481 {
1482 return false;
1483 }
1484
1485 override bool IsMushroom()
1486 {
1487 return false;
1488 }
1489
1490 //================================================================
1491 // NUTRITIONAL VALUES
1492 //================================================================
1493 //food properties
1494 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1495 {
1497 if (food_item && food_item.GetFoodStage())
1498 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1499 else if (classname != "" && food_stage)
1500 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1501 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1502 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1503
1504 }
1505
1506 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1507 {
1509 if (food_item && food_item.GetFoodStage())
1510 return FoodStage.GetEnergy(food_item.GetFoodStage());
1511 else if (classname != "" && food_stage)
1512 return FoodStage.GetEnergy(null, food_stage, classname);
1513 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1514 return GetGame().ConfigGetFloat(class_path + " energy");
1515 }
1516
1517 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1518 {
1520 if (food_item && food_item.GetFoodStage())
1521 return FoodStage.GetWater(food_item.GetFoodStage());
1522 else if (classname != "" && food_stage)
1523 return FoodStage.GetWater(null, food_stage, classname);
1524 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1525 return GetGame().ConfigGetFloat(class_path + " water");
1526 }
1527
1528 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1529 {
1531 if (food_item && food_item.GetFoodStage())
1532 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1533 else if (classname != "" && food_stage)
1534 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1535 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1536 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1537
1538 }
1539
1540 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1541 {
1543 if (food_item && food_item.GetFoodStage())
1544 return FoodStage.GetToxicity(food_item.GetFoodStage());
1545 else if (classname != "" && food_stage)
1546 return FoodStage.GetToxicity(null, food_stage, classname);
1547 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1548 return GetGame().ConfigGetFloat(class_path + " toxicity");
1549 }
1550
1551 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1552 {
1554 if (food_item && food_item.GetFoodStage())
1555 return FoodStage.GetAgents(food_item.GetFoodStage());
1556 else if (classname != "" && food_stage)
1557 return FoodStage.GetAgents(null, food_stage, classname);
1558 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1559 return GetGame().ConfigGetInt(class_path + " agents");
1560 }
1561
1562 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1563 {
1565 if (food_item && food_item.GetFoodStage())
1566 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1567 else if (classname != "" && food_stage)
1568 return FoodStage.GetDigestibility(null, food_stage, classname);
1569 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1570 return GetGame().ConfigGetInt(class_path + " digestibility");
1571 }
1572
1574 {
1576 }
1577
1578 //================================================================
1579 // FOOD STAGING
1580 //================================================================
1582 {
1583 return GetFoodStage().GetFoodStageType();
1584 }
1585
1586 //food stage states
1587 bool IsFoodRaw()
1588 {
1589 if (GetFoodStage())
1590 return GetFoodStage().IsFoodRaw();
1591
1592 return false;
1593 }
1594
1595 bool IsFoodBaked()
1596 {
1597 if (GetFoodStage())
1598 return GetFoodStage().IsFoodBaked();
1599
1600 return false;
1601 }
1602
1603 bool IsFoodBoiled()
1604 {
1605 if (GetFoodStage())
1606 return GetFoodStage().IsFoodBoiled();
1607
1608 return false;
1609 }
1610
1611 bool IsFoodDried()
1612 {
1613 if (GetFoodStage())
1614 return GetFoodStage().IsFoodDried();
1615
1616 return false;
1617 }
1618
1619 bool IsFoodBurned()
1620 {
1621 if (GetFoodStage())
1622 return GetFoodStage().IsFoodBurned();
1623
1624 return false;
1625 }
1626
1627 bool IsFoodRotten()
1628 {
1629 if (GetFoodStage())
1630 return GetFoodStage().IsFoodRotten();
1631
1632 return false;
1633 }
1634
1635 //food stage change
1637 {
1638 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1639 }
1640
1642 {
1643 return GetFoodStage().GetNextFoodStageType(cooking_method);
1644 }
1645
1647 {
1648 return GetFoodStage().GetFoodStageName(food_stage_type);
1649 }
1650
1652 {
1653 return GetFoodStage().CanChangeToNewStage(cooking_method);
1654 }
1655
1656 //Use this to receive food stage from another Edible_Base
1658 {
1659 if (!source.HasFoodStage())
1660 return;
1661 m_LastDecayStage = source.GetLastDecayStage();
1662 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1663 m_DecayTimer = source.GetDecayTimer();
1664 m_DecayDelta = source.GetDecayDelta();
1665 }
1666
1667 //================================================================
1668 // COOKING
1669 //================================================================
1670 //cooking time
1671 float GetCookingTime()
1672 {
1673 return GetFoodStage().GetCookingTime();
1674 }
1675
1676 void SetCookingTime(float time)
1677 {
1678 GetFoodStage().SetCookingTime(time);
1679
1680 //synchronize when calling on server
1681 Synchronize();
1682 }
1683
1684 //replace edible with new item (opening cans)
1685 void ReplaceEdibleWithNew(string typeName)
1686 {
1687 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1688 if (player)
1689 {
1691 player.ServerReplaceItemInHandsWithNew(lambda);
1692 }
1693 else
1694 Error("ReplaceEdibleWithNew - cannot use edible without player");
1695 }
1696
1697 override void SetActions()
1698 {
1699 super.SetActions();
1700
1701 AddAction(ActionAttach);
1703 }
1704
1705 protected void SoundCookingStart(string sound_name)
1706 {
1707#ifndef SERVER
1709 {
1711
1714 }
1715#endif
1716 }
1717
1718 protected void SoundCookingStop()
1719 {
1720#ifndef SERVER
1722 {
1725 m_SoundPlaying = "";
1726 }
1727#endif
1728 }
1729
1730 override bool CanHaveTemperature()
1731 {
1732 return true;
1733 }
1734
1735 override bool CanDecay()
1736 {
1737 return false;
1738 }
1739
1740 override bool CanProcessDecay()
1741 {
1742 return (GetFoodStageType() != FoodStageType.ROTTEN);
1743 }
1744
1745 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1746 {
1747 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1748 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1749 if (hasRootAsPlayer)
1751
1752 /*Print( "-------------------------" );
1753 Print( this );
1754 Print( m_DecayTimer );
1755 Print( m_DecayDelta );
1756 Print( m_LastDecayStage );*/
1757
1758 if (IsFruit() || IsMushroom())
1759 {
1760 // fruit, vegetables and mushrooms
1762 {
1763 switch (GetFoodStageType())
1764 {
1765 case FoodStageType.RAW:
1768 break;
1769
1770 case FoodStageType.BOILED:
1773 break;
1774
1775 case FoodStageType.BAKED:
1778 break;
1779
1780 case FoodStageType.DRIED:
1781 case FoodStageType.BURNED:
1782 case FoodStageType.ROTTEN:
1783 default:
1784 m_DecayTimer = -1;
1786 return;
1787 }
1788
1789 //m_DecayTimer = m_DecayTimer / 1000.0;
1790 }
1791
1793
1794 if (m_DecayTimer <= 0)
1795 {
1796 if (m_LastDecayStage != FoodStageType.NONE)
1797 {
1798 // switch to decayed stage
1799 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1802 {
1803 int rng = Math.RandomIntInclusive(0, 100);
1806 else
1807 {
1810 else
1812 }
1813 }
1814 }
1815 }
1816
1817 }
1818 else if (IsMeat())
1819 {
1820 // meat
1822 {
1823 switch (GetFoodStageType())
1824 {
1825 case FoodStageType.RAW:
1828 break;
1829
1830 case FoodStageType.BOILED:
1833 break;
1834
1835 case FoodStageType.BAKED:
1838 break;
1839
1840 case FoodStageType.DRIED:
1843 break;
1844
1845 case FoodStageType.BURNED:
1846 case FoodStageType.ROTTEN:
1847 default:
1848 m_DecayTimer = -1;
1850 return;
1851 }
1852 }
1853
1855
1856 if (m_DecayTimer <= 0)
1857 {
1858 if (m_LastDecayStage != FoodStageType.NONE)
1859 {
1860 // switch to decayed stage
1863 }
1864 }
1865 }
1866 else if (IsCorpse())
1867 {
1868 // corpse
1870 {
1871 switch (GetFoodStageType())
1872 {
1873 case FoodStageType.RAW:
1876 break;
1877
1878 case FoodStageType.BURNED:
1879 case FoodStageType.ROTTEN:
1880 default:
1881 m_DecayTimer = -1;
1883 return;
1884 }
1885 }
1886
1888
1889 if (m_DecayTimer <= 0)
1890 {
1891 if (m_LastDecayStage != FoodStageType.NONE)
1892 {
1893 // switch to decayed stage
1896 }
1897 }
1898 }
1899 else
1900 {
1901 // opened cans
1903
1904 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1905 {
1908 //m_DecayTimer = m_DecayTimer / 1000.0;
1909 }
1910 else
1911 {
1912 if (m_DecayTimer <= 0)
1913 {
1914 InsertAgent(eAgents.FOOD_POISON, 1);
1915 m_DecayTimer = -1;
1916 }
1917 }
1918 }
1919
1920 m_DecayDelta = 0.0;
1921 }
1922
1924 {
1925 super.GetDebugActions(outputList);
1926
1927 if (HasFoodStage())
1928 {
1929 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1930 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1931 }
1932 }
1933
1934 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1935 {
1936 super.OnAction(action_id, player, ctx);
1937
1938 if (GetGame().IsServer())
1939 {
1940 if (action_id == EActions.FOOD_STAGE_PREV)
1941 {
1943 if (food_stage_prev <= 0)
1944 food_stage_prev = FoodStageType.COUNT - 1;
1946 return true;
1947 }
1948 else if (action_id == EActions.FOOD_STAGE_NEXT)
1949 {
1951 if (food_stage_next >= FoodStageType.COUNT)
1954 return true;
1955 }
1956 }
1957 return false;
1958 }
1959
1960 override string GetDebugText()
1961 {
1962 string debug_output;
1963
1964 debug_output = super.GetDebugText();
1965
1966 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1967 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1968
1969 return debug_output;
1970 }
1971
1972 //================================================================
1973 // GENERAL GETTERS
1974 //================================================================
1975
1976 float GetDecayTimer()
1977 {
1978 return m_DecayTimer;
1979 }
1980
1981 float GetDecayDelta()
1982 {
1983 return m_DecayDelta;
1984 }
1985
1987 {
1988 return m_LastDecayStage;
1989 }
1990}
1991
1993{
1995};

◆ CanHaveTemperature()

override bool ReplaceEdibleWithNewLambda::CanHaveTemperature ( )
protected

Definition at line 1238 of file Edible_Base.c.

1238 : ItemBase
1239{
1240 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1241
1242 const string SOUND_BAKING_START = "Baking_SoundSet";
1243 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1244 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1245
1246 protected bool m_MakeCookingSounds;
1247 protected SoundOnVehicle m_SoundCooking;
1249 protected string m_SoundPlaying;
1251 protected float m_DecayTimer;
1252 protected float m_DecayDelta = 0.0;
1254
1256
1257 void Edible_Base()
1258 {
1259 if (HasFoodStage())
1260 {
1261 m_FoodStage = new FoodStage(this);
1262
1263 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1264 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1265 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1266 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1267 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1268
1269 m_SoundPlaying = "";
1271 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1272 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1273 }
1274 }
1275
1276 override void EEInit()
1277 {
1278 super.EEInit();
1279
1280 UpdateVisuals();
1281 }
1282
1283 override void EEDelete(EntityAI parent)
1284 {
1285 super.EEDelete(parent);
1286
1287 RemoveAudio();
1288 }
1289
1291 {
1292 super.EEItemLocationChanged(oldLoc, newLoc);
1293
1295 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1296 {
1297 switch (oldLoc.GetParent().GetType())
1298 {
1299 case "FryingPan":
1300 case "Pot":
1301 case "Cauldron":
1302 case "SharpWoodenStick":
1303 MakeSoundsOnClient(false);
1304 break;
1305 }
1306
1308 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1309 MakeSoundsOnClient(false);
1310 }
1311 }
1312
1313 void UpdateVisuals()
1314 {
1315 if (GetFoodStage())
1316 GetFoodStage().UpdateVisuals();
1317 }
1318
1319 bool Consume(float amount, PlayerBase consumer)
1320 {
1321 AddQuantity(-amount, false, false);
1322 OnConsume(amount, consumer);
1323
1324 return true;
1325 }
1326
1327 void OnConsume(float amount, PlayerBase consumer);
1328
1329 //food staging
1330 override bool CanBeCooked()
1331 {
1332 return false;
1333 }
1334
1335 override bool CanBeCookedOnStick()
1336 {
1337 return false;
1338 }
1339
1340 //================================================================
1341 // SYNCHRONIZATION
1342 //================================================================
1343 void Synchronize()
1344 {
1345 SetSynchDirty();
1346
1347 if (GetGame().IsMultiplayer())
1348 UpdateVisuals();
1349 }
1350
1351 override void OnVariablesSynchronized()
1352 {
1353 super.OnVariablesSynchronized();
1354
1355 UpdateVisuals();
1356
1357 //update audio
1359 RefreshAudio();
1360 else
1361 RemoveAudio();
1362 }
1363
1364 //================================================================
1365 // AUDIO EFFECTS (WHEN ON DCS)
1366 //================================================================
1368 {
1371
1372 Synchronize();
1373 }
1374
1375 protected void RefreshAudio()
1376 {
1377 string soundName = "";
1378
1380
1381 switch (GetFoodStageType())
1382 {
1383 case FoodStageType.RAW:
1385 if (nextFoodState == FoodStageType.BOILED)
1386 soundName = "";
1387 break;
1388 case FoodStageType.BAKED:
1390 break;
1391 case FoodStageType.BURNED:
1393 break;
1394 default:
1395 soundName = "";
1396 break;
1397 }
1398
1400 }
1401
1402 protected void RemoveAudio()
1403 {
1404 m_MakeCookingSounds = false;
1406 }
1407
1408 //================================================================
1409 // SERIALIZATION
1410 //================================================================
1411 override void OnStoreSave(ParamsWriteContext ctx)
1412 {
1413 super.OnStoreSave(ctx);
1414
1415 if (GetFoodStage())
1416 GetFoodStage().OnStoreSave(ctx);
1417
1418 // food decay
1419 ctx.Write(m_DecayTimer);
1420 ctx.Write(m_LastDecayStage);
1421 }
1422
1423 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1424 {
1425 if (!super.OnStoreLoad(ctx, version))
1426 return false;
1427
1428 if (GetFoodStage())
1429 {
1430 if (!GetFoodStage().OnStoreLoad(ctx, version))
1431 return false;
1432 }
1433
1434 if (version >= 115)
1435 {
1436 if (!ctx.Read(m_DecayTimer))
1437 {
1438 m_DecayTimer = 0.0;
1439 return false;
1440 }
1441 if (!ctx.Read(m_LastDecayStage))
1442 {
1444 return false;
1445 }
1446 }
1447
1448 return true;
1449 }
1450
1451 override void AfterStoreLoad()
1452 {
1453 super.AfterStoreLoad();
1454
1455 Synchronize();
1456 }
1457
1458 //get food stage
1460 {
1461 return m_FoodStage;
1462 }
1463
1464 //food types
1465 override bool IsMeat()
1466 {
1467 return false;
1468 }
1469
1470 override bool IsCorpse()
1471 {
1472 return false;
1473 }
1474
1475 override bool IsFruit()
1476 {
1477 return false;
1478 }
1479
1480 override bool IsMushroom()
1481 {
1482 return false;
1483 }
1484
1485 //================================================================
1486 // NUTRITIONAL VALUES
1487 //================================================================
1488 //food properties
1489 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1490 {
1492 if (food_item && food_item.GetFoodStage())
1493 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1494 else if (classname != "" && food_stage)
1495 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1496 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1497 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1498
1499 }
1500
1501 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1502 {
1504 if (food_item && food_item.GetFoodStage())
1505 return FoodStage.GetEnergy(food_item.GetFoodStage());
1506 else if (classname != "" && food_stage)
1507 return FoodStage.GetEnergy(null, food_stage, classname);
1508 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1509 return GetGame().ConfigGetFloat(class_path + " energy");
1510 }
1511
1512 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1513 {
1515 if (food_item && food_item.GetFoodStage())
1516 return FoodStage.GetWater(food_item.GetFoodStage());
1517 else if (classname != "" && food_stage)
1518 return FoodStage.GetWater(null, food_stage, classname);
1519 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1520 return GetGame().ConfigGetFloat(class_path + " water");
1521 }
1522
1523 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1524 {
1526 if (food_item && food_item.GetFoodStage())
1527 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1528 else if (classname != "" && food_stage)
1529 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1530 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1531 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1532
1533 }
1534
1535 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1536 {
1538 if (food_item && food_item.GetFoodStage())
1539 return FoodStage.GetToxicity(food_item.GetFoodStage());
1540 else if (classname != "" && food_stage)
1541 return FoodStage.GetToxicity(null, food_stage, classname);
1542 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1543 return GetGame().ConfigGetFloat(class_path + " toxicity");
1544 }
1545
1546 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1547 {
1549 if (food_item && food_item.GetFoodStage())
1550 return FoodStage.GetAgents(food_item.GetFoodStage());
1551 else if (classname != "" && food_stage)
1552 return FoodStage.GetAgents(null, food_stage, classname);
1553 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1554 return GetGame().ConfigGetInt(class_path + " agents");
1555 }
1556
1557 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1558 {
1560 if (food_item && food_item.GetFoodStage())
1561 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1562 else if (classname != "" && food_stage)
1563 return FoodStage.GetDigestibility(null, food_stage, classname);
1564 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1565 return GetGame().ConfigGetInt(class_path + " digestibility");
1566 }
1567
1569 {
1571 }
1572
1573 //================================================================
1574 // FOOD STAGING
1575 //================================================================
1577 {
1578 return GetFoodStage().GetFoodStageType();
1579 }
1580
1581 //food stage states
1582 bool IsFoodRaw()
1583 {
1584 if (GetFoodStage())
1585 return GetFoodStage().IsFoodRaw();
1586
1587 return false;
1588 }
1589
1590 bool IsFoodBaked()
1591 {
1592 if (GetFoodStage())
1593 return GetFoodStage().IsFoodBaked();
1594
1595 return false;
1596 }
1597
1598 bool IsFoodBoiled()
1599 {
1600 if (GetFoodStage())
1601 return GetFoodStage().IsFoodBoiled();
1602
1603 return false;
1604 }
1605
1606 bool IsFoodDried()
1607 {
1608 if (GetFoodStage())
1609 return GetFoodStage().IsFoodDried();
1610
1611 return false;
1612 }
1613
1614 bool IsFoodBurned()
1615 {
1616 if (GetFoodStage())
1617 return GetFoodStage().IsFoodBurned();
1618
1619 return false;
1620 }
1621
1622 bool IsFoodRotten()
1623 {
1624 if (GetFoodStage())
1625 return GetFoodStage().IsFoodRotten();
1626
1627 return false;
1628 }
1629
1630 //food stage change
1632 {
1633 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1634 }
1635
1637 {
1638 return GetFoodStage().GetNextFoodStageType(cooking_method);
1639 }
1640
1642 {
1643 return GetFoodStage().GetFoodStageName(food_stage_type);
1644 }
1645
1647 {
1648 return GetFoodStage().CanChangeToNewStage(cooking_method);
1649 }
1650
1651 //Use this to receive food stage from another Edible_Base
1653 {
1654 if (!source.HasFoodStage())
1655 return;
1656 m_LastDecayStage = source.GetLastDecayStage();
1657 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1658 m_DecayTimer = source.GetDecayTimer();
1659 m_DecayDelta = source.GetDecayDelta();
1660 }
1661
1662 //================================================================
1663 // COOKING
1664 //================================================================
1665 //cooking time
1666 float GetCookingTime()
1667 {
1668 return GetFoodStage().GetCookingTime();
1669 }
1670
1671 void SetCookingTime(float time)
1672 {
1673 GetFoodStage().SetCookingTime(time);
1674
1675 //synchronize when calling on server
1676 Synchronize();
1677 }
1678
1679 //replace edible with new item (opening cans)
1680 void ReplaceEdibleWithNew(string typeName)
1681 {
1682 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1683 if (player)
1684 {
1686 player.ServerReplaceItemInHandsWithNew(lambda);
1687 }
1688 else
1689 Error("ReplaceEdibleWithNew - cannot use edible without player");
1690 }
1691
1692 override void SetActions()
1693 {
1694 super.SetActions();
1695
1696 AddAction(ActionAttach);
1698 }
1699
1700 protected void SoundCookingStart(string sound_name)
1701 {
1702#ifndef SERVER
1704 {
1706
1709 }
1710#endif
1711 }
1712
1713 protected void SoundCookingStop()
1714 {
1715#ifndef SERVER
1717 {
1720 m_SoundPlaying = "";
1721 }
1722#endif
1723 }
1724
1725 override bool CanHaveTemperature()
1726 {
1727 return true;
1728 }
1729
1730 override bool CanDecay()
1731 {
1732 return false;
1733 }
1734
1735 override bool CanProcessDecay()
1736 {
1737 return (GetFoodStageType() != FoodStageType.ROTTEN);
1738 }
1739
1740 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1741 {
1742 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1743 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1744 if (hasRootAsPlayer)
1746
1747 /*Print( "-------------------------" );
1748 Print( this );
1749 Print( m_DecayTimer );
1750 Print( m_DecayDelta );
1751 Print( m_LastDecayStage );*/
1752
1753 if (IsFruit() || IsMushroom())
1754 {
1755 // fruit, vegetables and mushrooms
1757 {
1758 switch (GetFoodStageType())
1759 {
1760 case FoodStageType.RAW:
1763 break;
1764
1765 case FoodStageType.BOILED:
1768 break;
1769
1770 case FoodStageType.BAKED:
1773 break;
1774
1775 case FoodStageType.DRIED:
1776 case FoodStageType.BURNED:
1777 case FoodStageType.ROTTEN:
1778 default:
1779 m_DecayTimer = -1;
1781 return;
1782 }
1783
1784 //m_DecayTimer = m_DecayTimer / 1000.0;
1785 }
1786
1788
1789 if (m_DecayTimer <= 0)
1790 {
1791 if (m_LastDecayStage != FoodStageType.NONE)
1792 {
1793 // switch to decayed stage
1794 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1797 {
1798 int rng = Math.RandomIntInclusive(0, 100);
1801 else
1802 {
1805 else
1807 }
1808 }
1809 }
1810 }
1811
1812 }
1813 else if (IsMeat())
1814 {
1815 // meat
1817 {
1818 switch (GetFoodStageType())
1819 {
1820 case FoodStageType.RAW:
1823 break;
1824
1825 case FoodStageType.BOILED:
1828 break;
1829
1830 case FoodStageType.BAKED:
1833 break;
1834
1835 case FoodStageType.DRIED:
1838 break;
1839
1840 case FoodStageType.BURNED:
1841 case FoodStageType.ROTTEN:
1842 default:
1843 m_DecayTimer = -1;
1845 return;
1846 }
1847 }
1848
1850
1851 if (m_DecayTimer <= 0)
1852 {
1853 if (m_LastDecayStage != FoodStageType.NONE)
1854 {
1855 // switch to decayed stage
1858 }
1859 }
1860 }
1861 else if (IsCorpse())
1862 {
1863 // corpse
1865 {
1866 switch (GetFoodStageType())
1867 {
1868 case FoodStageType.RAW:
1871 break;
1872
1873 case FoodStageType.BURNED:
1874 case FoodStageType.ROTTEN:
1875 default:
1876 m_DecayTimer = -1;
1878 return;
1879 }
1880 }
1881
1883
1884 if (m_DecayTimer <= 0)
1885 {
1886 if (m_LastDecayStage != FoodStageType.NONE)
1887 {
1888 // switch to decayed stage
1891 }
1892 }
1893 }
1894 else
1895 {
1896 // opened cans
1898
1899 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1900 {
1903 //m_DecayTimer = m_DecayTimer / 1000.0;
1904 }
1905 else
1906 {
1907 if (m_DecayTimer <= 0)
1908 {
1909 InsertAgent(eAgents.FOOD_POISON, 1);
1910 m_DecayTimer = -1;
1911 }
1912 }
1913 }
1914
1915 m_DecayDelta = 0.0;
1916 }
1917
1919 {
1920 super.GetDebugActions(outputList);
1921
1922 if (HasFoodStage())
1923 {
1924 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1925 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1926 }
1927 }
1928
1929 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1930 {
1931 super.OnAction(action_id, player, ctx);
1932
1933 if (GetGame().IsServer())
1934 {
1935 if (action_id == EActions.FOOD_STAGE_PREV)
1936 {
1938 if (food_stage_prev <= 0)
1939 food_stage_prev = FoodStageType.COUNT - 1;
1941 return true;
1942 }
1943 else if (action_id == EActions.FOOD_STAGE_NEXT)
1944 {
1946 if (food_stage_next >= FoodStageType.COUNT)
1949 return true;
1950 }
1951 }
1952 return false;
1953 }
1954
1955 override string GetDebugText()
1956 {
1957 string debug_output;
1958
1959 debug_output = super.GetDebugText();
1960
1961 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1962 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1963
1964 return debug_output;
1965 }
1966
1967 //================================================================
1968 // GENERAL GETTERS
1969 //================================================================
1970
1971 float GetDecayTimer()
1972 {
1973 return m_DecayTimer;
1974 }
1975
1976 float GetDecayDelta()
1977 {
1978 return m_DecayDelta;
1979 }
1980
1982 {
1983 return m_LastDecayStage;
1984 }
1985}
1986
1988{
1990};

◆ CanProcessDecay()

override bool ReplaceEdibleWithNewLambda::CanProcessDecay ( )
protected

Definition at line 1248 of file Edible_Base.c.

1248 : ItemBase
1249{
1250 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1251
1252 const string SOUND_BAKING_START = "Baking_SoundSet";
1253 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1254 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1255
1256 protected bool m_MakeCookingSounds;
1257 protected SoundOnVehicle m_SoundCooking;
1259 protected string m_SoundPlaying;
1261 protected float m_DecayTimer;
1262 protected float m_DecayDelta = 0.0;
1264
1266
1267 void Edible_Base()
1268 {
1269 if (HasFoodStage())
1270 {
1271 m_FoodStage = new FoodStage(this);
1272
1273 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1274 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1275 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1276 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1277 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1278
1279 m_SoundPlaying = "";
1281 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1282 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1283 }
1284 }
1285
1286 override void EEInit()
1287 {
1288 super.EEInit();
1289
1290 UpdateVisuals();
1291 }
1292
1293 override void EEDelete(EntityAI parent)
1294 {
1295 super.EEDelete(parent);
1296
1297 RemoveAudio();
1298 }
1299
1301 {
1302 super.EEItemLocationChanged(oldLoc, newLoc);
1303
1305 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1306 {
1307 switch (oldLoc.GetParent().GetType())
1308 {
1309 case "FryingPan":
1310 case "Pot":
1311 case "Cauldron":
1312 case "SharpWoodenStick":
1313 MakeSoundsOnClient(false);
1314 break;
1315 }
1316
1318 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1319 MakeSoundsOnClient(false);
1320 }
1321 }
1322
1323 void UpdateVisuals()
1324 {
1325 if (GetFoodStage())
1326 GetFoodStage().UpdateVisuals();
1327 }
1328
1329 bool Consume(float amount, PlayerBase consumer)
1330 {
1331 AddQuantity(-amount, false, false);
1332 OnConsume(amount, consumer);
1333
1334 return true;
1335 }
1336
1337 void OnConsume(float amount, PlayerBase consumer);
1338
1339 //food staging
1340 override bool CanBeCooked()
1341 {
1342 return false;
1343 }
1344
1345 override bool CanBeCookedOnStick()
1346 {
1347 return false;
1348 }
1349
1350 //================================================================
1351 // SYNCHRONIZATION
1352 //================================================================
1353 void Synchronize()
1354 {
1355 SetSynchDirty();
1356
1357 if (GetGame().IsMultiplayer())
1358 UpdateVisuals();
1359 }
1360
1361 override void OnVariablesSynchronized()
1362 {
1363 super.OnVariablesSynchronized();
1364
1365 UpdateVisuals();
1366
1367 //update audio
1369 RefreshAudio();
1370 else
1371 RemoveAudio();
1372 }
1373
1374 //================================================================
1375 // AUDIO EFFECTS (WHEN ON DCS)
1376 //================================================================
1378 {
1381
1382 Synchronize();
1383 }
1384
1385 protected void RefreshAudio()
1386 {
1387 string soundName = "";
1388
1390
1391 switch (GetFoodStageType())
1392 {
1393 case FoodStageType.RAW:
1395 if (nextFoodState == FoodStageType.BOILED)
1396 soundName = "";
1397 break;
1398 case FoodStageType.BAKED:
1400 break;
1401 case FoodStageType.BURNED:
1403 break;
1404 default:
1405 soundName = "";
1406 break;
1407 }
1408
1410 }
1411
1412 protected void RemoveAudio()
1413 {
1414 m_MakeCookingSounds = false;
1416 }
1417
1418 //================================================================
1419 // SERIALIZATION
1420 //================================================================
1421 override void OnStoreSave(ParamsWriteContext ctx)
1422 {
1423 super.OnStoreSave(ctx);
1424
1425 if (GetFoodStage())
1426 GetFoodStage().OnStoreSave(ctx);
1427
1428 // food decay
1429 ctx.Write(m_DecayTimer);
1430 ctx.Write(m_LastDecayStage);
1431 }
1432
1433 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1434 {
1435 if (!super.OnStoreLoad(ctx, version))
1436 return false;
1437
1438 if (GetFoodStage())
1439 {
1440 if (!GetFoodStage().OnStoreLoad(ctx, version))
1441 return false;
1442 }
1443
1444 if (version >= 115)
1445 {
1446 if (!ctx.Read(m_DecayTimer))
1447 {
1448 m_DecayTimer = 0.0;
1449 return false;
1450 }
1451 if (!ctx.Read(m_LastDecayStage))
1452 {
1454 return false;
1455 }
1456 }
1457
1458 return true;
1459 }
1460
1461 override void AfterStoreLoad()
1462 {
1463 super.AfterStoreLoad();
1464
1465 Synchronize();
1466 }
1467
1468 //get food stage
1470 {
1471 return m_FoodStage;
1472 }
1473
1474 //food types
1475 override bool IsMeat()
1476 {
1477 return false;
1478 }
1479
1480 override bool IsCorpse()
1481 {
1482 return false;
1483 }
1484
1485 override bool IsFruit()
1486 {
1487 return false;
1488 }
1489
1490 override bool IsMushroom()
1491 {
1492 return false;
1493 }
1494
1495 //================================================================
1496 // NUTRITIONAL VALUES
1497 //================================================================
1498 //food properties
1499 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1500 {
1502 if (food_item && food_item.GetFoodStage())
1503 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1504 else if (classname != "" && food_stage)
1505 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1506 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1507 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1508
1509 }
1510
1511 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1512 {
1514 if (food_item && food_item.GetFoodStage())
1515 return FoodStage.GetEnergy(food_item.GetFoodStage());
1516 else if (classname != "" && food_stage)
1517 return FoodStage.GetEnergy(null, food_stage, classname);
1518 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1519 return GetGame().ConfigGetFloat(class_path + " energy");
1520 }
1521
1522 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1523 {
1525 if (food_item && food_item.GetFoodStage())
1526 return FoodStage.GetWater(food_item.GetFoodStage());
1527 else if (classname != "" && food_stage)
1528 return FoodStage.GetWater(null, food_stage, classname);
1529 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1530 return GetGame().ConfigGetFloat(class_path + " water");
1531 }
1532
1533 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1534 {
1536 if (food_item && food_item.GetFoodStage())
1537 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1538 else if (classname != "" && food_stage)
1539 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1540 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1541 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1542
1543 }
1544
1545 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1546 {
1548 if (food_item && food_item.GetFoodStage())
1549 return FoodStage.GetToxicity(food_item.GetFoodStage());
1550 else if (classname != "" && food_stage)
1551 return FoodStage.GetToxicity(null, food_stage, classname);
1552 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1553 return GetGame().ConfigGetFloat(class_path + " toxicity");
1554 }
1555
1556 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1557 {
1559 if (food_item && food_item.GetFoodStage())
1560 return FoodStage.GetAgents(food_item.GetFoodStage());
1561 else if (classname != "" && food_stage)
1562 return FoodStage.GetAgents(null, food_stage, classname);
1563 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1564 return GetGame().ConfigGetInt(class_path + " agents");
1565 }
1566
1567 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1568 {
1570 if (food_item && food_item.GetFoodStage())
1571 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1572 else if (classname != "" && food_stage)
1573 return FoodStage.GetDigestibility(null, food_stage, classname);
1574 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1575 return GetGame().ConfigGetInt(class_path + " digestibility");
1576 }
1577
1579 {
1581 }
1582
1583 //================================================================
1584 // FOOD STAGING
1585 //================================================================
1587 {
1588 return GetFoodStage().GetFoodStageType();
1589 }
1590
1591 //food stage states
1592 bool IsFoodRaw()
1593 {
1594 if (GetFoodStage())
1595 return GetFoodStage().IsFoodRaw();
1596
1597 return false;
1598 }
1599
1600 bool IsFoodBaked()
1601 {
1602 if (GetFoodStage())
1603 return GetFoodStage().IsFoodBaked();
1604
1605 return false;
1606 }
1607
1608 bool IsFoodBoiled()
1609 {
1610 if (GetFoodStage())
1611 return GetFoodStage().IsFoodBoiled();
1612
1613 return false;
1614 }
1615
1616 bool IsFoodDried()
1617 {
1618 if (GetFoodStage())
1619 return GetFoodStage().IsFoodDried();
1620
1621 return false;
1622 }
1623
1624 bool IsFoodBurned()
1625 {
1626 if (GetFoodStage())
1627 return GetFoodStage().IsFoodBurned();
1628
1629 return false;
1630 }
1631
1632 bool IsFoodRotten()
1633 {
1634 if (GetFoodStage())
1635 return GetFoodStage().IsFoodRotten();
1636
1637 return false;
1638 }
1639
1640 //food stage change
1642 {
1643 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1644 }
1645
1647 {
1648 return GetFoodStage().GetNextFoodStageType(cooking_method);
1649 }
1650
1652 {
1653 return GetFoodStage().GetFoodStageName(food_stage_type);
1654 }
1655
1657 {
1658 return GetFoodStage().CanChangeToNewStage(cooking_method);
1659 }
1660
1661 //Use this to receive food stage from another Edible_Base
1663 {
1664 if (!source.HasFoodStage())
1665 return;
1666 m_LastDecayStage = source.GetLastDecayStage();
1667 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1668 m_DecayTimer = source.GetDecayTimer();
1669 m_DecayDelta = source.GetDecayDelta();
1670 }
1671
1672 //================================================================
1673 // COOKING
1674 //================================================================
1675 //cooking time
1676 float GetCookingTime()
1677 {
1678 return GetFoodStage().GetCookingTime();
1679 }
1680
1681 void SetCookingTime(float time)
1682 {
1683 GetFoodStage().SetCookingTime(time);
1684
1685 //synchronize when calling on server
1686 Synchronize();
1687 }
1688
1689 //replace edible with new item (opening cans)
1690 void ReplaceEdibleWithNew(string typeName)
1691 {
1692 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1693 if (player)
1694 {
1696 player.ServerReplaceItemInHandsWithNew(lambda);
1697 }
1698 else
1699 Error("ReplaceEdibleWithNew - cannot use edible without player");
1700 }
1701
1702 override void SetActions()
1703 {
1704 super.SetActions();
1705
1706 AddAction(ActionAttach);
1708 }
1709
1710 protected void SoundCookingStart(string sound_name)
1711 {
1712#ifndef SERVER
1714 {
1716
1719 }
1720#endif
1721 }
1722
1723 protected void SoundCookingStop()
1724 {
1725#ifndef SERVER
1727 {
1730 m_SoundPlaying = "";
1731 }
1732#endif
1733 }
1734
1735 override bool CanHaveTemperature()
1736 {
1737 return true;
1738 }
1739
1740 override bool CanDecay()
1741 {
1742 return false;
1743 }
1744
1745 override bool CanProcessDecay()
1746 {
1747 return (GetFoodStageType() != FoodStageType.ROTTEN);
1748 }
1749
1750 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1751 {
1752 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1753 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1754 if (hasRootAsPlayer)
1756
1757 /*Print( "-------------------------" );
1758 Print( this );
1759 Print( m_DecayTimer );
1760 Print( m_DecayDelta );
1761 Print( m_LastDecayStage );*/
1762
1763 if (IsFruit() || IsMushroom())
1764 {
1765 // fruit, vegetables and mushrooms
1767 {
1768 switch (GetFoodStageType())
1769 {
1770 case FoodStageType.RAW:
1773 break;
1774
1775 case FoodStageType.BOILED:
1778 break;
1779
1780 case FoodStageType.BAKED:
1783 break;
1784
1785 case FoodStageType.DRIED:
1786 case FoodStageType.BURNED:
1787 case FoodStageType.ROTTEN:
1788 default:
1789 m_DecayTimer = -1;
1791 return;
1792 }
1793
1794 //m_DecayTimer = m_DecayTimer / 1000.0;
1795 }
1796
1798
1799 if (m_DecayTimer <= 0)
1800 {
1801 if (m_LastDecayStage != FoodStageType.NONE)
1802 {
1803 // switch to decayed stage
1804 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1807 {
1808 int rng = Math.RandomIntInclusive(0, 100);
1811 else
1812 {
1815 else
1817 }
1818 }
1819 }
1820 }
1821
1822 }
1823 else if (IsMeat())
1824 {
1825 // meat
1827 {
1828 switch (GetFoodStageType())
1829 {
1830 case FoodStageType.RAW:
1833 break;
1834
1835 case FoodStageType.BOILED:
1838 break;
1839
1840 case FoodStageType.BAKED:
1843 break;
1844
1845 case FoodStageType.DRIED:
1848 break;
1849
1850 case FoodStageType.BURNED:
1851 case FoodStageType.ROTTEN:
1852 default:
1853 m_DecayTimer = -1;
1855 return;
1856 }
1857 }
1858
1860
1861 if (m_DecayTimer <= 0)
1862 {
1863 if (m_LastDecayStage != FoodStageType.NONE)
1864 {
1865 // switch to decayed stage
1868 }
1869 }
1870 }
1871 else if (IsCorpse())
1872 {
1873 // corpse
1875 {
1876 switch (GetFoodStageType())
1877 {
1878 case FoodStageType.RAW:
1881 break;
1882
1883 case FoodStageType.BURNED:
1884 case FoodStageType.ROTTEN:
1885 default:
1886 m_DecayTimer = -1;
1888 return;
1889 }
1890 }
1891
1893
1894 if (m_DecayTimer <= 0)
1895 {
1896 if (m_LastDecayStage != FoodStageType.NONE)
1897 {
1898 // switch to decayed stage
1901 }
1902 }
1903 }
1904 else
1905 {
1906 // opened cans
1908
1909 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1910 {
1913 //m_DecayTimer = m_DecayTimer / 1000.0;
1914 }
1915 else
1916 {
1917 if (m_DecayTimer <= 0)
1918 {
1919 InsertAgent(eAgents.FOOD_POISON, 1);
1920 m_DecayTimer = -1;
1921 }
1922 }
1923 }
1924
1925 m_DecayDelta = 0.0;
1926 }
1927
1929 {
1930 super.GetDebugActions(outputList);
1931
1932 if (HasFoodStage())
1933 {
1934 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1935 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1936 }
1937 }
1938
1939 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1940 {
1941 super.OnAction(action_id, player, ctx);
1942
1943 if (GetGame().IsServer())
1944 {
1945 if (action_id == EActions.FOOD_STAGE_PREV)
1946 {
1948 if (food_stage_prev <= 0)
1949 food_stage_prev = FoodStageType.COUNT - 1;
1951 return true;
1952 }
1953 else if (action_id == EActions.FOOD_STAGE_NEXT)
1954 {
1956 if (food_stage_next >= FoodStageType.COUNT)
1959 return true;
1960 }
1961 }
1962 return false;
1963 }
1964
1965 override string GetDebugText()
1966 {
1967 string debug_output;
1968
1969 debug_output = super.GetDebugText();
1970
1971 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1972 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1973
1974 return debug_output;
1975 }
1976
1977 //================================================================
1978 // GENERAL GETTERS
1979 //================================================================
1980
1981 float GetDecayTimer()
1982 {
1983 return m_DecayTimer;
1984 }
1985
1986 float GetDecayDelta()
1987 {
1988 return m_DecayDelta;
1989 }
1990
1992 {
1993 return m_LastDecayStage;
1994 }
1995}
1996
1998{
2000};

◆ ChangeFoodStage()

void ReplaceEdibleWithNewLambda::ChangeFoodStage ( FoodStageType new_food_stage_type)
protected

Definition at line 1144 of file Edible_Base.c.

1144 : ItemBase
1145{
1146 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1147
1148 const string SOUND_BAKING_START = "Baking_SoundSet";
1149 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1150 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1151
1152 protected bool m_MakeCookingSounds;
1153 protected SoundOnVehicle m_SoundCooking;
1155 protected string m_SoundPlaying;
1157 protected float m_DecayTimer;
1158 protected float m_DecayDelta = 0.0;
1160
1162
1163 void Edible_Base()
1164 {
1165 if (HasFoodStage())
1166 {
1167 m_FoodStage = new FoodStage(this);
1168
1169 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1170 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1171 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1172 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1173 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1174
1175 m_SoundPlaying = "";
1177 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1178 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1179 }
1180 }
1181
1182 override void EEInit()
1183 {
1184 super.EEInit();
1185
1186 UpdateVisuals();
1187 }
1188
1189 override void EEDelete(EntityAI parent)
1190 {
1191 super.EEDelete(parent);
1192
1193 RemoveAudio();
1194 }
1195
1197 {
1198 super.EEItemLocationChanged(oldLoc, newLoc);
1199
1201 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1202 {
1203 switch (oldLoc.GetParent().GetType())
1204 {
1205 case "FryingPan":
1206 case "Pot":
1207 case "Cauldron":
1208 case "SharpWoodenStick":
1209 MakeSoundsOnClient(false);
1210 break;
1211 }
1212
1214 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1215 MakeSoundsOnClient(false);
1216 }
1217 }
1218
1219 void UpdateVisuals()
1220 {
1221 if (GetFoodStage())
1222 GetFoodStage().UpdateVisuals();
1223 }
1224
1225 bool Consume(float amount, PlayerBase consumer)
1226 {
1227 AddQuantity(-amount, false, false);
1228 OnConsume(amount, consumer);
1229
1230 return true;
1231 }
1232
1233 void OnConsume(float amount, PlayerBase consumer);
1234
1235 //food staging
1236 override bool CanBeCooked()
1237 {
1238 return false;
1239 }
1240
1241 override bool CanBeCookedOnStick()
1242 {
1243 return false;
1244 }
1245
1246 //================================================================
1247 // SYNCHRONIZATION
1248 //================================================================
1249 void Synchronize()
1250 {
1251 SetSynchDirty();
1252
1253 if (GetGame().IsMultiplayer())
1254 UpdateVisuals();
1255 }
1256
1257 override void OnVariablesSynchronized()
1258 {
1259 super.OnVariablesSynchronized();
1260
1261 UpdateVisuals();
1262
1263 //update audio
1265 RefreshAudio();
1266 else
1267 RemoveAudio();
1268 }
1269
1270 //================================================================
1271 // AUDIO EFFECTS (WHEN ON DCS)
1272 //================================================================
1274 {
1277
1278 Synchronize();
1279 }
1280
1281 protected void RefreshAudio()
1282 {
1283 string soundName = "";
1284
1286
1287 switch (GetFoodStageType())
1288 {
1289 case FoodStageType.RAW:
1291 if (nextFoodState == FoodStageType.BOILED)
1292 soundName = "";
1293 break;
1294 case FoodStageType.BAKED:
1296 break;
1297 case FoodStageType.BURNED:
1299 break;
1300 default:
1301 soundName = "";
1302 break;
1303 }
1304
1306 }
1307
1308 protected void RemoveAudio()
1309 {
1310 m_MakeCookingSounds = false;
1312 }
1313
1314 //================================================================
1315 // SERIALIZATION
1316 //================================================================
1317 override void OnStoreSave(ParamsWriteContext ctx)
1318 {
1319 super.OnStoreSave(ctx);
1320
1321 if (GetFoodStage())
1322 GetFoodStage().OnStoreSave(ctx);
1323
1324 // food decay
1325 ctx.Write(m_DecayTimer);
1326 ctx.Write(m_LastDecayStage);
1327 }
1328
1329 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1330 {
1331 if (!super.OnStoreLoad(ctx, version))
1332 return false;
1333
1334 if (GetFoodStage())
1335 {
1336 if (!GetFoodStage().OnStoreLoad(ctx, version))
1337 return false;
1338 }
1339
1340 if (version >= 115)
1341 {
1342 if (!ctx.Read(m_DecayTimer))
1343 {
1344 m_DecayTimer = 0.0;
1345 return false;
1346 }
1347 if (!ctx.Read(m_LastDecayStage))
1348 {
1350 return false;
1351 }
1352 }
1353
1354 return true;
1355 }
1356
1357 override void AfterStoreLoad()
1358 {
1359 super.AfterStoreLoad();
1360
1361 Synchronize();
1362 }
1363
1364 //get food stage
1366 {
1367 return m_FoodStage;
1368 }
1369
1370 //food types
1371 override bool IsMeat()
1372 {
1373 return false;
1374 }
1375
1376 override bool IsCorpse()
1377 {
1378 return false;
1379 }
1380
1381 override bool IsFruit()
1382 {
1383 return false;
1384 }
1385
1386 override bool IsMushroom()
1387 {
1388 return false;
1389 }
1390
1391 //================================================================
1392 // NUTRITIONAL VALUES
1393 //================================================================
1394 //food properties
1395 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1396 {
1398 if (food_item && food_item.GetFoodStage())
1399 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1400 else if (classname != "" && food_stage)
1401 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1402 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1403 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1404
1405 }
1406
1407 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1408 {
1410 if (food_item && food_item.GetFoodStage())
1411 return FoodStage.GetEnergy(food_item.GetFoodStage());
1412 else if (classname != "" && food_stage)
1413 return FoodStage.GetEnergy(null, food_stage, classname);
1414 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1415 return GetGame().ConfigGetFloat(class_path + " energy");
1416 }
1417
1418 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1419 {
1421 if (food_item && food_item.GetFoodStage())
1422 return FoodStage.GetWater(food_item.GetFoodStage());
1423 else if (classname != "" && food_stage)
1424 return FoodStage.GetWater(null, food_stage, classname);
1425 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1426 return GetGame().ConfigGetFloat(class_path + " water");
1427 }
1428
1429 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1430 {
1432 if (food_item && food_item.GetFoodStage())
1433 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1434 else if (classname != "" && food_stage)
1435 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1436 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1437 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1438
1439 }
1440
1441 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1442 {
1444 if (food_item && food_item.GetFoodStage())
1445 return FoodStage.GetToxicity(food_item.GetFoodStage());
1446 else if (classname != "" && food_stage)
1447 return FoodStage.GetToxicity(null, food_stage, classname);
1448 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1449 return GetGame().ConfigGetFloat(class_path + " toxicity");
1450 }
1451
1452 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1453 {
1455 if (food_item && food_item.GetFoodStage())
1456 return FoodStage.GetAgents(food_item.GetFoodStage());
1457 else if (classname != "" && food_stage)
1458 return FoodStage.GetAgents(null, food_stage, classname);
1459 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1460 return GetGame().ConfigGetInt(class_path + " agents");
1461 }
1462
1463 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1464 {
1466 if (food_item && food_item.GetFoodStage())
1467 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1468 else if (classname != "" && food_stage)
1469 return FoodStage.GetDigestibility(null, food_stage, classname);
1470 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1471 return GetGame().ConfigGetInt(class_path + " digestibility");
1472 }
1473
1475 {
1477 }
1478
1479 //================================================================
1480 // FOOD STAGING
1481 //================================================================
1483 {
1484 return GetFoodStage().GetFoodStageType();
1485 }
1486
1487 //food stage states
1488 bool IsFoodRaw()
1489 {
1490 if (GetFoodStage())
1491 return GetFoodStage().IsFoodRaw();
1492
1493 return false;
1494 }
1495
1496 bool IsFoodBaked()
1497 {
1498 if (GetFoodStage())
1499 return GetFoodStage().IsFoodBaked();
1500
1501 return false;
1502 }
1503
1504 bool IsFoodBoiled()
1505 {
1506 if (GetFoodStage())
1507 return GetFoodStage().IsFoodBoiled();
1508
1509 return false;
1510 }
1511
1512 bool IsFoodDried()
1513 {
1514 if (GetFoodStage())
1515 return GetFoodStage().IsFoodDried();
1516
1517 return false;
1518 }
1519
1520 bool IsFoodBurned()
1521 {
1522 if (GetFoodStage())
1523 return GetFoodStage().IsFoodBurned();
1524
1525 return false;
1526 }
1527
1528 bool IsFoodRotten()
1529 {
1530 if (GetFoodStage())
1531 return GetFoodStage().IsFoodRotten();
1532
1533 return false;
1534 }
1535
1536 //food stage change
1538 {
1539 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1540 }
1541
1543 {
1544 return GetFoodStage().GetNextFoodStageType(cooking_method);
1545 }
1546
1548 {
1549 return GetFoodStage().GetFoodStageName(food_stage_type);
1550 }
1551
1553 {
1554 return GetFoodStage().CanChangeToNewStage(cooking_method);
1555 }
1556
1557 //Use this to receive food stage from another Edible_Base
1559 {
1560 if (!source.HasFoodStage())
1561 return;
1562 m_LastDecayStage = source.GetLastDecayStage();
1563 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1564 m_DecayTimer = source.GetDecayTimer();
1565 m_DecayDelta = source.GetDecayDelta();
1566 }
1567
1568 //================================================================
1569 // COOKING
1570 //================================================================
1571 //cooking time
1572 float GetCookingTime()
1573 {
1574 return GetFoodStage().GetCookingTime();
1575 }
1576
1577 void SetCookingTime(float time)
1578 {
1579 GetFoodStage().SetCookingTime(time);
1580
1581 //synchronize when calling on server
1582 Synchronize();
1583 }
1584
1585 //replace edible with new item (opening cans)
1586 void ReplaceEdibleWithNew(string typeName)
1587 {
1588 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1589 if (player)
1590 {
1592 player.ServerReplaceItemInHandsWithNew(lambda);
1593 }
1594 else
1595 Error("ReplaceEdibleWithNew - cannot use edible without player");
1596 }
1597
1598 override void SetActions()
1599 {
1600 super.SetActions();
1601
1602 AddAction(ActionAttach);
1604 }
1605
1606 protected void SoundCookingStart(string sound_name)
1607 {
1608#ifndef SERVER
1610 {
1612
1615 }
1616#endif
1617 }
1618
1619 protected void SoundCookingStop()
1620 {
1621#ifndef SERVER
1623 {
1626 m_SoundPlaying = "";
1627 }
1628#endif
1629 }
1630
1631 override bool CanHaveTemperature()
1632 {
1633 return true;
1634 }
1635
1636 override bool CanDecay()
1637 {
1638 return false;
1639 }
1640
1641 override bool CanProcessDecay()
1642 {
1643 return (GetFoodStageType() != FoodStageType.ROTTEN);
1644 }
1645
1646 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1647 {
1648 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1649 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1650 if (hasRootAsPlayer)
1652
1653 /*Print( "-------------------------" );
1654 Print( this );
1655 Print( m_DecayTimer );
1656 Print( m_DecayDelta );
1657 Print( m_LastDecayStage );*/
1658
1659 if (IsFruit() || IsMushroom())
1660 {
1661 // fruit, vegetables and mushrooms
1663 {
1664 switch (GetFoodStageType())
1665 {
1666 case FoodStageType.RAW:
1669 break;
1670
1671 case FoodStageType.BOILED:
1674 break;
1675
1676 case FoodStageType.BAKED:
1679 break;
1680
1681 case FoodStageType.DRIED:
1682 case FoodStageType.BURNED:
1683 case FoodStageType.ROTTEN:
1684 default:
1685 m_DecayTimer = -1;
1687 return;
1688 }
1689
1690 //m_DecayTimer = m_DecayTimer / 1000.0;
1691 }
1692
1694
1695 if (m_DecayTimer <= 0)
1696 {
1697 if (m_LastDecayStage != FoodStageType.NONE)
1698 {
1699 // switch to decayed stage
1700 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1703 {
1704 int rng = Math.RandomIntInclusive(0, 100);
1707 else
1708 {
1711 else
1713 }
1714 }
1715 }
1716 }
1717
1718 }
1719 else if (IsMeat())
1720 {
1721 // meat
1723 {
1724 switch (GetFoodStageType())
1725 {
1726 case FoodStageType.RAW:
1729 break;
1730
1731 case FoodStageType.BOILED:
1734 break;
1735
1736 case FoodStageType.BAKED:
1739 break;
1740
1741 case FoodStageType.DRIED:
1744 break;
1745
1746 case FoodStageType.BURNED:
1747 case FoodStageType.ROTTEN:
1748 default:
1749 m_DecayTimer = -1;
1751 return;
1752 }
1753 }
1754
1756
1757 if (m_DecayTimer <= 0)
1758 {
1759 if (m_LastDecayStage != FoodStageType.NONE)
1760 {
1761 // switch to decayed stage
1764 }
1765 }
1766 }
1767 else if (IsCorpse())
1768 {
1769 // corpse
1771 {
1772 switch (GetFoodStageType())
1773 {
1774 case FoodStageType.RAW:
1777 break;
1778
1779 case FoodStageType.BURNED:
1780 case FoodStageType.ROTTEN:
1781 default:
1782 m_DecayTimer = -1;
1784 return;
1785 }
1786 }
1787
1789
1790 if (m_DecayTimer <= 0)
1791 {
1792 if (m_LastDecayStage != FoodStageType.NONE)
1793 {
1794 // switch to decayed stage
1797 }
1798 }
1799 }
1800 else
1801 {
1802 // opened cans
1804
1805 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1806 {
1809 //m_DecayTimer = m_DecayTimer / 1000.0;
1810 }
1811 else
1812 {
1813 if (m_DecayTimer <= 0)
1814 {
1815 InsertAgent(eAgents.FOOD_POISON, 1);
1816 m_DecayTimer = -1;
1817 }
1818 }
1819 }
1820
1821 m_DecayDelta = 0.0;
1822 }
1823
1825 {
1826 super.GetDebugActions(outputList);
1827
1828 if (HasFoodStage())
1829 {
1830 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1831 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1832 }
1833 }
1834
1835 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1836 {
1837 super.OnAction(action_id, player, ctx);
1838
1839 if (GetGame().IsServer())
1840 {
1841 if (action_id == EActions.FOOD_STAGE_PREV)
1842 {
1844 if (food_stage_prev <= 0)
1845 food_stage_prev = FoodStageType.COUNT - 1;
1847 return true;
1848 }
1849 else if (action_id == EActions.FOOD_STAGE_NEXT)
1850 {
1852 if (food_stage_next >= FoodStageType.COUNT)
1855 return true;
1856 }
1857 }
1858 return false;
1859 }
1860
1861 override string GetDebugText()
1862 {
1863 string debug_output;
1864
1865 debug_output = super.GetDebugText();
1866
1867 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1868 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1869
1870 return debug_output;
1871 }
1872
1873 //================================================================
1874 // GENERAL GETTERS
1875 //================================================================
1876
1877 float GetDecayTimer()
1878 {
1879 return m_DecayTimer;
1880 }
1881
1882 float GetDecayDelta()
1883 {
1884 return m_DecayDelta;
1885 }
1886
1888 {
1889 return m_LastDecayStage;
1890 }
1891}
1892
1894{
1896};

◆ Consume()

bool ReplaceEdibleWithNewLambda::Consume ( float amount,
PlayerBase consumer )
private

Definition at line 832 of file Edible_Base.c.

832 : ItemBase
833{
834 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
835
836 const string SOUND_BAKING_START = "Baking_SoundSet";
837 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
838 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
839
840 protected bool m_MakeCookingSounds;
843 protected string m_SoundPlaying;
845 protected float m_DecayTimer;
846 protected float m_DecayDelta = 0.0;
848
850
851 void Edible_Base()
852 {
853 if (HasFoodStage())
854 {
855 m_FoodStage = new FoodStage(this);
856
857 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
858 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
859 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
860 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
861 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
862
863 m_SoundPlaying = "";
865 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
866 RegisterNetSyncVariableBool("m_MakeCookingSounds");
867 }
868 }
869
870 override void EEInit()
871 {
872 super.EEInit();
873
875 }
876
877 override void EEDelete(EntityAI parent)
878 {
879 super.EEDelete(parent);
880
881 RemoveAudio();
882 }
883
885 {
886 super.EEItemLocationChanged(oldLoc, newLoc);
887
889 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
890 {
891 switch (oldLoc.GetParent().GetType())
892 {
893 case "FryingPan":
894 case "Pot":
895 case "Cauldron":
896 case "SharpWoodenStick":
897 MakeSoundsOnClient(false);
898 break;
899 }
900
902 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
903 MakeSoundsOnClient(false);
904 }
905 }
906
907 void UpdateVisuals()
908 {
909 if (GetFoodStage())
910 GetFoodStage().UpdateVisuals();
911 }
912
913 bool Consume(float amount, PlayerBase consumer)
914 {
915 AddQuantity(-amount, false, false);
916 OnConsume(amount, consumer);
917
918 return true;
919 }
920
921 void OnConsume(float amount, PlayerBase consumer);
922
923 //food staging
924 override bool CanBeCooked()
925 {
926 return false;
927 }
928
929 override bool CanBeCookedOnStick()
930 {
931 return false;
932 }
933
934 //================================================================
935 // SYNCHRONIZATION
936 //================================================================
937 void Synchronize()
938 {
939 SetSynchDirty();
940
941 if (GetGame().IsMultiplayer())
943 }
944
945 override void OnVariablesSynchronized()
946 {
947 super.OnVariablesSynchronized();
948
950
951 //update audio
953 RefreshAudio();
954 else
955 RemoveAudio();
956 }
957
958 //================================================================
959 // AUDIO EFFECTS (WHEN ON DCS)
960 //================================================================
962 {
965
966 Synchronize();
967 }
968
969 protected void RefreshAudio()
970 {
971 string soundName = "";
972
974
975 switch (GetFoodStageType())
976 {
977 case FoodStageType.RAW:
979 if (nextFoodState == FoodStageType.BOILED)
980 soundName = "";
981 break;
982 case FoodStageType.BAKED:
984 break;
985 case FoodStageType.BURNED:
987 break;
988 default:
989 soundName = "";
990 break;
991 }
992
994 }
995
996 protected void RemoveAudio()
997 {
998 m_MakeCookingSounds = false;
1000 }
1001
1002 //================================================================
1003 // SERIALIZATION
1004 //================================================================
1005 override void OnStoreSave(ParamsWriteContext ctx)
1006 {
1007 super.OnStoreSave(ctx);
1008
1009 if (GetFoodStage())
1010 GetFoodStage().OnStoreSave(ctx);
1011
1012 // food decay
1013 ctx.Write(m_DecayTimer);
1014 ctx.Write(m_LastDecayStage);
1015 }
1016
1017 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1018 {
1019 if (!super.OnStoreLoad(ctx, version))
1020 return false;
1021
1022 if (GetFoodStage())
1023 {
1024 if (!GetFoodStage().OnStoreLoad(ctx, version))
1025 return false;
1026 }
1027
1028 if (version >= 115)
1029 {
1030 if (!ctx.Read(m_DecayTimer))
1031 {
1032 m_DecayTimer = 0.0;
1033 return false;
1034 }
1035 if (!ctx.Read(m_LastDecayStage))
1036 {
1038 return false;
1039 }
1040 }
1041
1042 return true;
1043 }
1044
1045 override void AfterStoreLoad()
1046 {
1047 super.AfterStoreLoad();
1048
1049 Synchronize();
1050 }
1051
1052 //get food stage
1054 {
1055 return m_FoodStage;
1056 }
1057
1058 //food types
1059 override bool IsMeat()
1060 {
1061 return false;
1062 }
1063
1064 override bool IsCorpse()
1065 {
1066 return false;
1067 }
1068
1069 override bool IsFruit()
1070 {
1071 return false;
1072 }
1073
1074 override bool IsMushroom()
1075 {
1076 return false;
1077 }
1078
1079 //================================================================
1080 // NUTRITIONAL VALUES
1081 //================================================================
1082 //food properties
1083 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1084 {
1086 if (food_item && food_item.GetFoodStage())
1087 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1088 else if (classname != "" && food_stage)
1089 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1090 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1091 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1092
1093 }
1094
1095 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1096 {
1098 if (food_item && food_item.GetFoodStage())
1099 return FoodStage.GetEnergy(food_item.GetFoodStage());
1100 else if (classname != "" && food_stage)
1101 return FoodStage.GetEnergy(null, food_stage, classname);
1102 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1103 return GetGame().ConfigGetFloat(class_path + " energy");
1104 }
1105
1106 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1107 {
1109 if (food_item && food_item.GetFoodStage())
1110 return FoodStage.GetWater(food_item.GetFoodStage());
1111 else if (classname != "" && food_stage)
1112 return FoodStage.GetWater(null, food_stage, classname);
1113 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1114 return GetGame().ConfigGetFloat(class_path + " water");
1115 }
1116
1117 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1118 {
1120 if (food_item && food_item.GetFoodStage())
1121 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1122 else if (classname != "" && food_stage)
1123 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1124 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1125 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1126
1127 }
1128
1129 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1130 {
1132 if (food_item && food_item.GetFoodStage())
1133 return FoodStage.GetToxicity(food_item.GetFoodStage());
1134 else if (classname != "" && food_stage)
1135 return FoodStage.GetToxicity(null, food_stage, classname);
1136 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1137 return GetGame().ConfigGetFloat(class_path + " toxicity");
1138 }
1139
1140 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1141 {
1143 if (food_item && food_item.GetFoodStage())
1144 return FoodStage.GetAgents(food_item.GetFoodStage());
1145 else if (classname != "" && food_stage)
1146 return FoodStage.GetAgents(null, food_stage, classname);
1147 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1148 return GetGame().ConfigGetInt(class_path + " agents");
1149 }
1150
1151 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1152 {
1154 if (food_item && food_item.GetFoodStage())
1155 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1156 else if (classname != "" && food_stage)
1157 return FoodStage.GetDigestibility(null, food_stage, classname);
1158 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1159 return GetGame().ConfigGetInt(class_path + " digestibility");
1160 }
1161
1163 {
1165 }
1166
1167 //================================================================
1168 // FOOD STAGING
1169 //================================================================
1171 {
1172 return GetFoodStage().GetFoodStageType();
1173 }
1174
1175 //food stage states
1176 bool IsFoodRaw()
1177 {
1178 if (GetFoodStage())
1179 return GetFoodStage().IsFoodRaw();
1180
1181 return false;
1182 }
1183
1184 bool IsFoodBaked()
1185 {
1186 if (GetFoodStage())
1187 return GetFoodStage().IsFoodBaked();
1188
1189 return false;
1190 }
1191
1192 bool IsFoodBoiled()
1193 {
1194 if (GetFoodStage())
1195 return GetFoodStage().IsFoodBoiled();
1196
1197 return false;
1198 }
1199
1200 bool IsFoodDried()
1201 {
1202 if (GetFoodStage())
1203 return GetFoodStage().IsFoodDried();
1204
1205 return false;
1206 }
1207
1208 bool IsFoodBurned()
1209 {
1210 if (GetFoodStage())
1211 return GetFoodStage().IsFoodBurned();
1212
1213 return false;
1214 }
1215
1216 bool IsFoodRotten()
1217 {
1218 if (GetFoodStage())
1219 return GetFoodStage().IsFoodRotten();
1220
1221 return false;
1222 }
1223
1224 //food stage change
1226 {
1227 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1228 }
1229
1231 {
1232 return GetFoodStage().GetNextFoodStageType(cooking_method);
1233 }
1234
1236 {
1237 return GetFoodStage().GetFoodStageName(food_stage_type);
1238 }
1239
1241 {
1242 return GetFoodStage().CanChangeToNewStage(cooking_method);
1243 }
1244
1245 //Use this to receive food stage from another Edible_Base
1247 {
1248 if (!source.HasFoodStage())
1249 return;
1250 m_LastDecayStage = source.GetLastDecayStage();
1251 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1252 m_DecayTimer = source.GetDecayTimer();
1253 m_DecayDelta = source.GetDecayDelta();
1254 }
1255
1256 //================================================================
1257 // COOKING
1258 //================================================================
1259 //cooking time
1260 float GetCookingTime()
1261 {
1262 return GetFoodStage().GetCookingTime();
1263 }
1264
1265 void SetCookingTime(float time)
1266 {
1267 GetFoodStage().SetCookingTime(time);
1268
1269 //synchronize when calling on server
1270 Synchronize();
1271 }
1272
1273 //replace edible with new item (opening cans)
1274 void ReplaceEdibleWithNew(string typeName)
1275 {
1276 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1277 if (player)
1278 {
1280 player.ServerReplaceItemInHandsWithNew(lambda);
1281 }
1282 else
1283 Error("ReplaceEdibleWithNew - cannot use edible without player");
1284 }
1285
1286 override void SetActions()
1287 {
1288 super.SetActions();
1289
1290 AddAction(ActionAttach);
1292 }
1293
1294 protected void SoundCookingStart(string sound_name)
1295 {
1296#ifndef SERVER
1298 {
1300
1303 }
1304#endif
1305 }
1306
1307 protected void SoundCookingStop()
1308 {
1309#ifndef SERVER
1311 {
1314 m_SoundPlaying = "";
1315 }
1316#endif
1317 }
1318
1319 override bool CanHaveTemperature()
1320 {
1321 return true;
1322 }
1323
1324 override bool CanDecay()
1325 {
1326 return false;
1327 }
1328
1329 override bool CanProcessDecay()
1330 {
1331 return (GetFoodStageType() != FoodStageType.ROTTEN);
1332 }
1333
1334 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1335 {
1336 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1337 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1338 if (hasRootAsPlayer)
1340
1341 /*Print( "-------------------------" );
1342 Print( this );
1343 Print( m_DecayTimer );
1344 Print( m_DecayDelta );
1345 Print( m_LastDecayStage );*/
1346
1347 if (IsFruit() || IsMushroom())
1348 {
1349 // fruit, vegetables and mushrooms
1351 {
1352 switch (GetFoodStageType())
1353 {
1354 case FoodStageType.RAW:
1357 break;
1358
1359 case FoodStageType.BOILED:
1362 break;
1363
1364 case FoodStageType.BAKED:
1367 break;
1368
1369 case FoodStageType.DRIED:
1370 case FoodStageType.BURNED:
1371 case FoodStageType.ROTTEN:
1372 default:
1373 m_DecayTimer = -1;
1375 return;
1376 }
1377
1378 //m_DecayTimer = m_DecayTimer / 1000.0;
1379 }
1380
1382
1383 if (m_DecayTimer <= 0)
1384 {
1385 if (m_LastDecayStage != FoodStageType.NONE)
1386 {
1387 // switch to decayed stage
1388 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1391 {
1392 int rng = Math.RandomIntInclusive(0, 100);
1395 else
1396 {
1399 else
1401 }
1402 }
1403 }
1404 }
1405
1406 }
1407 else if (IsMeat())
1408 {
1409 // meat
1411 {
1412 switch (GetFoodStageType())
1413 {
1414 case FoodStageType.RAW:
1417 break;
1418
1419 case FoodStageType.BOILED:
1422 break;
1423
1424 case FoodStageType.BAKED:
1427 break;
1428
1429 case FoodStageType.DRIED:
1432 break;
1433
1434 case FoodStageType.BURNED:
1435 case FoodStageType.ROTTEN:
1436 default:
1437 m_DecayTimer = -1;
1439 return;
1440 }
1441 }
1442
1444
1445 if (m_DecayTimer <= 0)
1446 {
1447 if (m_LastDecayStage != FoodStageType.NONE)
1448 {
1449 // switch to decayed stage
1452 }
1453 }
1454 }
1455 else if (IsCorpse())
1456 {
1457 // corpse
1459 {
1460 switch (GetFoodStageType())
1461 {
1462 case FoodStageType.RAW:
1465 break;
1466
1467 case FoodStageType.BURNED:
1468 case FoodStageType.ROTTEN:
1469 default:
1470 m_DecayTimer = -1;
1472 return;
1473 }
1474 }
1475
1477
1478 if (m_DecayTimer <= 0)
1479 {
1480 if (m_LastDecayStage != FoodStageType.NONE)
1481 {
1482 // switch to decayed stage
1485 }
1486 }
1487 }
1488 else
1489 {
1490 // opened cans
1492
1493 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1494 {
1497 //m_DecayTimer = m_DecayTimer / 1000.0;
1498 }
1499 else
1500 {
1501 if (m_DecayTimer <= 0)
1502 {
1503 InsertAgent(eAgents.FOOD_POISON, 1);
1504 m_DecayTimer = -1;
1505 }
1506 }
1507 }
1508
1509 m_DecayDelta = 0.0;
1510 }
1511
1513 {
1514 super.GetDebugActions(outputList);
1515
1516 if (HasFoodStage())
1517 {
1518 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1519 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1520 }
1521 }
1522
1523 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1524 {
1525 super.OnAction(action_id, player, ctx);
1526
1527 if (GetGame().IsServer())
1528 {
1529 if (action_id == EActions.FOOD_STAGE_PREV)
1530 {
1532 if (food_stage_prev <= 0)
1533 food_stage_prev = FoodStageType.COUNT - 1;
1535 return true;
1536 }
1537 else if (action_id == EActions.FOOD_STAGE_NEXT)
1538 {
1540 if (food_stage_next >= FoodStageType.COUNT)
1543 return true;
1544 }
1545 }
1546 return false;
1547 }
1548
1549 override string GetDebugText()
1550 {
1551 string debug_output;
1552
1553 debug_output = super.GetDebugText();
1554
1555 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1556 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1557
1558 return debug_output;
1559 }
1560
1561 //================================================================
1562 // GENERAL GETTERS
1563 //================================================================
1564
1565 float GetDecayTimer()
1566 {
1567 return m_DecayTimer;
1568 }
1569
1570 float GetDecayDelta()
1571 {
1572 return m_DecayDelta;
1573 }
1574
1576 {
1577 return m_LastDecayStage;
1578 }
1579}
1580
1582{
1584};

◆ Edible_Base()

void ReplaceEdibleWithNewLambda::Edible_Base ( )
private

Definition at line 770 of file Edible_Base.c.

770 : ItemBase
771{
772 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
773
774 const string SOUND_BAKING_START = "Baking_SoundSet";
775 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
776 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
777
778 protected bool m_MakeCookingSounds;
781 protected string m_SoundPlaying;
783 protected float m_DecayTimer;
784 protected float m_DecayDelta = 0.0;
786
788
789 void Edible_Base()
790 {
791 if (HasFoodStage())
792 {
793 m_FoodStage = new FoodStage(this);
794
795 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
796 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
797 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
798 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
799 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
800
801 m_SoundPlaying = "";
803 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
804 RegisterNetSyncVariableBool("m_MakeCookingSounds");
805 }
806 }
807
808 override void EEInit()
809 {
810 super.EEInit();
811
813 }
814
815 override void EEDelete(EntityAI parent)
816 {
817 super.EEDelete(parent);
818
819 RemoveAudio();
820 }
821
823 {
824 super.EEItemLocationChanged(oldLoc, newLoc);
825
827 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
828 {
829 switch (oldLoc.GetParent().GetType())
830 {
831 case "FryingPan":
832 case "Pot":
833 case "Cauldron":
834 case "SharpWoodenStick":
835 MakeSoundsOnClient(false);
836 break;
837 }
838
840 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
841 MakeSoundsOnClient(false);
842 }
843 }
844
845 void UpdateVisuals()
846 {
847 if (GetFoodStage())
848 GetFoodStage().UpdateVisuals();
849 }
850
851 bool Consume(float amount, PlayerBase consumer)
852 {
853 AddQuantity(-amount, false, false);
854 OnConsume(amount, consumer);
855
856 return true;
857 }
858
859 void OnConsume(float amount, PlayerBase consumer);
860
861 //food staging
862 override bool CanBeCooked()
863 {
864 return false;
865 }
866
867 override bool CanBeCookedOnStick()
868 {
869 return false;
870 }
871
872 //================================================================
873 // SYNCHRONIZATION
874 //================================================================
875 void Synchronize()
876 {
877 SetSynchDirty();
878
879 if (GetGame().IsMultiplayer())
881 }
882
883 override void OnVariablesSynchronized()
884 {
885 super.OnVariablesSynchronized();
886
888
889 //update audio
891 RefreshAudio();
892 else
893 RemoveAudio();
894 }
895
896 //================================================================
897 // AUDIO EFFECTS (WHEN ON DCS)
898 //================================================================
900 {
903
904 Synchronize();
905 }
906
907 protected void RefreshAudio()
908 {
909 string soundName = "";
910
912
913 switch (GetFoodStageType())
914 {
915 case FoodStageType.RAW:
917 if (nextFoodState == FoodStageType.BOILED)
918 soundName = "";
919 break;
920 case FoodStageType.BAKED:
922 break;
923 case FoodStageType.BURNED:
925 break;
926 default:
927 soundName = "";
928 break;
929 }
930
932 }
933
934 protected void RemoveAudio()
935 {
936 m_MakeCookingSounds = false;
938 }
939
940 //================================================================
941 // SERIALIZATION
942 //================================================================
943 override void OnStoreSave(ParamsWriteContext ctx)
944 {
945 super.OnStoreSave(ctx);
946
947 if (GetFoodStage())
948 GetFoodStage().OnStoreSave(ctx);
949
950 // food decay
951 ctx.Write(m_DecayTimer);
952 ctx.Write(m_LastDecayStage);
953 }
954
955 override bool OnStoreLoad(ParamsReadContext ctx, int version)
956 {
957 if (!super.OnStoreLoad(ctx, version))
958 return false;
959
960 if (GetFoodStage())
961 {
962 if (!GetFoodStage().OnStoreLoad(ctx, version))
963 return false;
964 }
965
966 if (version >= 115)
967 {
968 if (!ctx.Read(m_DecayTimer))
969 {
970 m_DecayTimer = 0.0;
971 return false;
972 }
973 if (!ctx.Read(m_LastDecayStage))
974 {
976 return false;
977 }
978 }
979
980 return true;
981 }
982
983 override void AfterStoreLoad()
984 {
985 super.AfterStoreLoad();
986
987 Synchronize();
988 }
989
990 //get food stage
992 {
993 return m_FoodStage;
994 }
995
996 //food types
997 override bool IsMeat()
998 {
999 return false;
1000 }
1001
1002 override bool IsCorpse()
1003 {
1004 return false;
1005 }
1006
1007 override bool IsFruit()
1008 {
1009 return false;
1010 }
1011
1012 override bool IsMushroom()
1013 {
1014 return false;
1015 }
1016
1017 //================================================================
1018 // NUTRITIONAL VALUES
1019 //================================================================
1020 //food properties
1021 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1022 {
1024 if (food_item && food_item.GetFoodStage())
1025 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1026 else if (classname != "" && food_stage)
1027 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1028 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1029 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1030
1031 }
1032
1033 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1034 {
1036 if (food_item && food_item.GetFoodStage())
1037 return FoodStage.GetEnergy(food_item.GetFoodStage());
1038 else if (classname != "" && food_stage)
1039 return FoodStage.GetEnergy(null, food_stage, classname);
1040 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1041 return GetGame().ConfigGetFloat(class_path + " energy");
1042 }
1043
1044 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1045 {
1047 if (food_item && food_item.GetFoodStage())
1048 return FoodStage.GetWater(food_item.GetFoodStage());
1049 else if (classname != "" && food_stage)
1050 return FoodStage.GetWater(null, food_stage, classname);
1051 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1052 return GetGame().ConfigGetFloat(class_path + " water");
1053 }
1054
1055 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1056 {
1058 if (food_item && food_item.GetFoodStage())
1059 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1060 else if (classname != "" && food_stage)
1061 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1062 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1063 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1064
1065 }
1066
1067 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1068 {
1070 if (food_item && food_item.GetFoodStage())
1071 return FoodStage.GetToxicity(food_item.GetFoodStage());
1072 else if (classname != "" && food_stage)
1073 return FoodStage.GetToxicity(null, food_stage, classname);
1074 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1075 return GetGame().ConfigGetFloat(class_path + " toxicity");
1076 }
1077
1078 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1079 {
1081 if (food_item && food_item.GetFoodStage())
1082 return FoodStage.GetAgents(food_item.GetFoodStage());
1083 else if (classname != "" && food_stage)
1084 return FoodStage.GetAgents(null, food_stage, classname);
1085 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1086 return GetGame().ConfigGetInt(class_path + " agents");
1087 }
1088
1089 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1090 {
1092 if (food_item && food_item.GetFoodStage())
1093 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1094 else if (classname != "" && food_stage)
1095 return FoodStage.GetDigestibility(null, food_stage, classname);
1096 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1097 return GetGame().ConfigGetInt(class_path + " digestibility");
1098 }
1099
1101 {
1103 }
1104
1105 //================================================================
1106 // FOOD STAGING
1107 //================================================================
1109 {
1110 return GetFoodStage().GetFoodStageType();
1111 }
1112
1113 //food stage states
1114 bool IsFoodRaw()
1115 {
1116 if (GetFoodStage())
1117 return GetFoodStage().IsFoodRaw();
1118
1119 return false;
1120 }
1121
1122 bool IsFoodBaked()
1123 {
1124 if (GetFoodStage())
1125 return GetFoodStage().IsFoodBaked();
1126
1127 return false;
1128 }
1129
1130 bool IsFoodBoiled()
1131 {
1132 if (GetFoodStage())
1133 return GetFoodStage().IsFoodBoiled();
1134
1135 return false;
1136 }
1137
1138 bool IsFoodDried()
1139 {
1140 if (GetFoodStage())
1141 return GetFoodStage().IsFoodDried();
1142
1143 return false;
1144 }
1145
1146 bool IsFoodBurned()
1147 {
1148 if (GetFoodStage())
1149 return GetFoodStage().IsFoodBurned();
1150
1151 return false;
1152 }
1153
1154 bool IsFoodRotten()
1155 {
1156 if (GetFoodStage())
1157 return GetFoodStage().IsFoodRotten();
1158
1159 return false;
1160 }
1161
1162 //food stage change
1164 {
1165 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1166 }
1167
1169 {
1170 return GetFoodStage().GetNextFoodStageType(cooking_method);
1171 }
1172
1174 {
1175 return GetFoodStage().GetFoodStageName(food_stage_type);
1176 }
1177
1179 {
1180 return GetFoodStage().CanChangeToNewStage(cooking_method);
1181 }
1182
1183 //Use this to receive food stage from another Edible_Base
1185 {
1186 if (!source.HasFoodStage())
1187 return;
1188 m_LastDecayStage = source.GetLastDecayStage();
1189 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1190 m_DecayTimer = source.GetDecayTimer();
1191 m_DecayDelta = source.GetDecayDelta();
1192 }
1193
1194 //================================================================
1195 // COOKING
1196 //================================================================
1197 //cooking time
1198 float GetCookingTime()
1199 {
1200 return GetFoodStage().GetCookingTime();
1201 }
1202
1203 void SetCookingTime(float time)
1204 {
1205 GetFoodStage().SetCookingTime(time);
1206
1207 //synchronize when calling on server
1208 Synchronize();
1209 }
1210
1211 //replace edible with new item (opening cans)
1212 void ReplaceEdibleWithNew(string typeName)
1213 {
1214 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1215 if (player)
1216 {
1218 player.ServerReplaceItemInHandsWithNew(lambda);
1219 }
1220 else
1221 Error("ReplaceEdibleWithNew - cannot use edible without player");
1222 }
1223
1224 override void SetActions()
1225 {
1226 super.SetActions();
1227
1228 AddAction(ActionAttach);
1230 }
1231
1232 protected void SoundCookingStart(string sound_name)
1233 {
1234#ifndef SERVER
1236 {
1238
1241 }
1242#endif
1243 }
1244
1245 protected void SoundCookingStop()
1246 {
1247#ifndef SERVER
1249 {
1252 m_SoundPlaying = "";
1253 }
1254#endif
1255 }
1256
1257 override bool CanHaveTemperature()
1258 {
1259 return true;
1260 }
1261
1262 override bool CanDecay()
1263 {
1264 return false;
1265 }
1266
1267 override bool CanProcessDecay()
1268 {
1269 return (GetFoodStageType() != FoodStageType.ROTTEN);
1270 }
1271
1272 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1273 {
1274 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1275 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1276 if (hasRootAsPlayer)
1278
1279 /*Print( "-------------------------" );
1280 Print( this );
1281 Print( m_DecayTimer );
1282 Print( m_DecayDelta );
1283 Print( m_LastDecayStage );*/
1284
1285 if (IsFruit() || IsMushroom())
1286 {
1287 // fruit, vegetables and mushrooms
1289 {
1290 switch (GetFoodStageType())
1291 {
1292 case FoodStageType.RAW:
1295 break;
1296
1297 case FoodStageType.BOILED:
1300 break;
1301
1302 case FoodStageType.BAKED:
1305 break;
1306
1307 case FoodStageType.DRIED:
1308 case FoodStageType.BURNED:
1309 case FoodStageType.ROTTEN:
1310 default:
1311 m_DecayTimer = -1;
1313 return;
1314 }
1315
1316 //m_DecayTimer = m_DecayTimer / 1000.0;
1317 }
1318
1320
1321 if (m_DecayTimer <= 0)
1322 {
1323 if (m_LastDecayStage != FoodStageType.NONE)
1324 {
1325 // switch to decayed stage
1326 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1329 {
1330 int rng = Math.RandomIntInclusive(0, 100);
1333 else
1334 {
1337 else
1339 }
1340 }
1341 }
1342 }
1343
1344 }
1345 else if (IsMeat())
1346 {
1347 // meat
1349 {
1350 switch (GetFoodStageType())
1351 {
1352 case FoodStageType.RAW:
1355 break;
1356
1357 case FoodStageType.BOILED:
1360 break;
1361
1362 case FoodStageType.BAKED:
1365 break;
1366
1367 case FoodStageType.DRIED:
1370 break;
1371
1372 case FoodStageType.BURNED:
1373 case FoodStageType.ROTTEN:
1374 default:
1375 m_DecayTimer = -1;
1377 return;
1378 }
1379 }
1380
1382
1383 if (m_DecayTimer <= 0)
1384 {
1385 if (m_LastDecayStage != FoodStageType.NONE)
1386 {
1387 // switch to decayed stage
1390 }
1391 }
1392 }
1393 else if (IsCorpse())
1394 {
1395 // corpse
1397 {
1398 switch (GetFoodStageType())
1399 {
1400 case FoodStageType.RAW:
1403 break;
1404
1405 case FoodStageType.BURNED:
1406 case FoodStageType.ROTTEN:
1407 default:
1408 m_DecayTimer = -1;
1410 return;
1411 }
1412 }
1413
1415
1416 if (m_DecayTimer <= 0)
1417 {
1418 if (m_LastDecayStage != FoodStageType.NONE)
1419 {
1420 // switch to decayed stage
1423 }
1424 }
1425 }
1426 else
1427 {
1428 // opened cans
1430
1431 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1432 {
1435 //m_DecayTimer = m_DecayTimer / 1000.0;
1436 }
1437 else
1438 {
1439 if (m_DecayTimer <= 0)
1440 {
1441 InsertAgent(eAgents.FOOD_POISON, 1);
1442 m_DecayTimer = -1;
1443 }
1444 }
1445 }
1446
1447 m_DecayDelta = 0.0;
1448 }
1449
1451 {
1452 super.GetDebugActions(outputList);
1453
1454 if (HasFoodStage())
1455 {
1456 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1457 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1458 }
1459 }
1460
1461 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1462 {
1463 super.OnAction(action_id, player, ctx);
1464
1465 if (GetGame().IsServer())
1466 {
1467 if (action_id == EActions.FOOD_STAGE_PREV)
1468 {
1470 if (food_stage_prev <= 0)
1471 food_stage_prev = FoodStageType.COUNT - 1;
1473 return true;
1474 }
1475 else if (action_id == EActions.FOOD_STAGE_NEXT)
1476 {
1478 if (food_stage_next >= FoodStageType.COUNT)
1481 return true;
1482 }
1483 }
1484 return false;
1485 }
1486
1487 override string GetDebugText()
1488 {
1489 string debug_output;
1490
1491 debug_output = super.GetDebugText();
1492
1493 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1494 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1495
1496 return debug_output;
1497 }
1498
1499 //================================================================
1500 // GENERAL GETTERS
1501 //================================================================
1502
1503 float GetDecayTimer()
1504 {
1505 return m_DecayTimer;
1506 }
1507
1508 float GetDecayDelta()
1509 {
1510 return m_DecayDelta;
1511 }
1512
1514 {
1515 return m_LastDecayStage;
1516 }
1517}
1518
1520{
1522};

◆ EEDelete()

override void ReplaceEdibleWithNewLambda::EEDelete ( EntityAI parent)
private

Definition at line 796 of file Edible_Base.c.

796 : ItemBase
797{
798 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
799
800 const string SOUND_BAKING_START = "Baking_SoundSet";
801 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
802 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
803
804 protected bool m_MakeCookingSounds;
807 protected string m_SoundPlaying;
809 protected float m_DecayTimer;
810 protected float m_DecayDelta = 0.0;
812
814
815 void Edible_Base()
816 {
817 if (HasFoodStage())
818 {
819 m_FoodStage = new FoodStage(this);
820
821 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
822 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
823 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
824 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
825 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
826
827 m_SoundPlaying = "";
829 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
830 RegisterNetSyncVariableBool("m_MakeCookingSounds");
831 }
832 }
833
834 override void EEInit()
835 {
836 super.EEInit();
837
839 }
840
841 override void EEDelete(EntityAI parent)
842 {
843 super.EEDelete(parent);
844
845 RemoveAudio();
846 }
847
849 {
850 super.EEItemLocationChanged(oldLoc, newLoc);
851
853 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
854 {
855 switch (oldLoc.GetParent().GetType())
856 {
857 case "FryingPan":
858 case "Pot":
859 case "Cauldron":
860 case "SharpWoodenStick":
861 MakeSoundsOnClient(false);
862 break;
863 }
864
866 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
867 MakeSoundsOnClient(false);
868 }
869 }
870
871 void UpdateVisuals()
872 {
873 if (GetFoodStage())
874 GetFoodStage().UpdateVisuals();
875 }
876
877 bool Consume(float amount, PlayerBase consumer)
878 {
879 AddQuantity(-amount, false, false);
880 OnConsume(amount, consumer);
881
882 return true;
883 }
884
885 void OnConsume(float amount, PlayerBase consumer);
886
887 //food staging
888 override bool CanBeCooked()
889 {
890 return false;
891 }
892
893 override bool CanBeCookedOnStick()
894 {
895 return false;
896 }
897
898 //================================================================
899 // SYNCHRONIZATION
900 //================================================================
901 void Synchronize()
902 {
903 SetSynchDirty();
904
905 if (GetGame().IsMultiplayer())
907 }
908
909 override void OnVariablesSynchronized()
910 {
911 super.OnVariablesSynchronized();
912
914
915 //update audio
917 RefreshAudio();
918 else
919 RemoveAudio();
920 }
921
922 //================================================================
923 // AUDIO EFFECTS (WHEN ON DCS)
924 //================================================================
926 {
929
930 Synchronize();
931 }
932
933 protected void RefreshAudio()
934 {
935 string soundName = "";
936
938
939 switch (GetFoodStageType())
940 {
941 case FoodStageType.RAW:
943 if (nextFoodState == FoodStageType.BOILED)
944 soundName = "";
945 break;
946 case FoodStageType.BAKED:
948 break;
949 case FoodStageType.BURNED:
951 break;
952 default:
953 soundName = "";
954 break;
955 }
956
958 }
959
960 protected void RemoveAudio()
961 {
962 m_MakeCookingSounds = false;
964 }
965
966 //================================================================
967 // SERIALIZATION
968 //================================================================
969 override void OnStoreSave(ParamsWriteContext ctx)
970 {
971 super.OnStoreSave(ctx);
972
973 if (GetFoodStage())
974 GetFoodStage().OnStoreSave(ctx);
975
976 // food decay
977 ctx.Write(m_DecayTimer);
978 ctx.Write(m_LastDecayStage);
979 }
980
981 override bool OnStoreLoad(ParamsReadContext ctx, int version)
982 {
983 if (!super.OnStoreLoad(ctx, version))
984 return false;
985
986 if (GetFoodStage())
987 {
988 if (!GetFoodStage().OnStoreLoad(ctx, version))
989 return false;
990 }
991
992 if (version >= 115)
993 {
994 if (!ctx.Read(m_DecayTimer))
995 {
996 m_DecayTimer = 0.0;
997 return false;
998 }
999 if (!ctx.Read(m_LastDecayStage))
1000 {
1002 return false;
1003 }
1004 }
1005
1006 return true;
1007 }
1008
1009 override void AfterStoreLoad()
1010 {
1011 super.AfterStoreLoad();
1012
1013 Synchronize();
1014 }
1015
1016 //get food stage
1018 {
1019 return m_FoodStage;
1020 }
1021
1022 //food types
1023 override bool IsMeat()
1024 {
1025 return false;
1026 }
1027
1028 override bool IsCorpse()
1029 {
1030 return false;
1031 }
1032
1033 override bool IsFruit()
1034 {
1035 return false;
1036 }
1037
1038 override bool IsMushroom()
1039 {
1040 return false;
1041 }
1042
1043 //================================================================
1044 // NUTRITIONAL VALUES
1045 //================================================================
1046 //food properties
1047 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1048 {
1050 if (food_item && food_item.GetFoodStage())
1051 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1052 else if (classname != "" && food_stage)
1053 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1054 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1055 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1056
1057 }
1058
1059 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1060 {
1062 if (food_item && food_item.GetFoodStage())
1063 return FoodStage.GetEnergy(food_item.GetFoodStage());
1064 else if (classname != "" && food_stage)
1065 return FoodStage.GetEnergy(null, food_stage, classname);
1066 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1067 return GetGame().ConfigGetFloat(class_path + " energy");
1068 }
1069
1070 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1071 {
1073 if (food_item && food_item.GetFoodStage())
1074 return FoodStage.GetWater(food_item.GetFoodStage());
1075 else if (classname != "" && food_stage)
1076 return FoodStage.GetWater(null, food_stage, classname);
1077 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1078 return GetGame().ConfigGetFloat(class_path + " water");
1079 }
1080
1081 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1082 {
1084 if (food_item && food_item.GetFoodStage())
1085 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1086 else if (classname != "" && food_stage)
1087 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1088 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1089 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1090
1091 }
1092
1093 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1094 {
1096 if (food_item && food_item.GetFoodStage())
1097 return FoodStage.GetToxicity(food_item.GetFoodStage());
1098 else if (classname != "" && food_stage)
1099 return FoodStage.GetToxicity(null, food_stage, classname);
1100 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1101 return GetGame().ConfigGetFloat(class_path + " toxicity");
1102 }
1103
1104 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1105 {
1107 if (food_item && food_item.GetFoodStage())
1108 return FoodStage.GetAgents(food_item.GetFoodStage());
1109 else if (classname != "" && food_stage)
1110 return FoodStage.GetAgents(null, food_stage, classname);
1111 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1112 return GetGame().ConfigGetInt(class_path + " agents");
1113 }
1114
1115 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1116 {
1118 if (food_item && food_item.GetFoodStage())
1119 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1120 else if (classname != "" && food_stage)
1121 return FoodStage.GetDigestibility(null, food_stage, classname);
1122 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1123 return GetGame().ConfigGetInt(class_path + " digestibility");
1124 }
1125
1127 {
1129 }
1130
1131 //================================================================
1132 // FOOD STAGING
1133 //================================================================
1135 {
1136 return GetFoodStage().GetFoodStageType();
1137 }
1138
1139 //food stage states
1140 bool IsFoodRaw()
1141 {
1142 if (GetFoodStage())
1143 return GetFoodStage().IsFoodRaw();
1144
1145 return false;
1146 }
1147
1148 bool IsFoodBaked()
1149 {
1150 if (GetFoodStage())
1151 return GetFoodStage().IsFoodBaked();
1152
1153 return false;
1154 }
1155
1156 bool IsFoodBoiled()
1157 {
1158 if (GetFoodStage())
1159 return GetFoodStage().IsFoodBoiled();
1160
1161 return false;
1162 }
1163
1164 bool IsFoodDried()
1165 {
1166 if (GetFoodStage())
1167 return GetFoodStage().IsFoodDried();
1168
1169 return false;
1170 }
1171
1172 bool IsFoodBurned()
1173 {
1174 if (GetFoodStage())
1175 return GetFoodStage().IsFoodBurned();
1176
1177 return false;
1178 }
1179
1180 bool IsFoodRotten()
1181 {
1182 if (GetFoodStage())
1183 return GetFoodStage().IsFoodRotten();
1184
1185 return false;
1186 }
1187
1188 //food stage change
1190 {
1191 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1192 }
1193
1195 {
1196 return GetFoodStage().GetNextFoodStageType(cooking_method);
1197 }
1198
1200 {
1201 return GetFoodStage().GetFoodStageName(food_stage_type);
1202 }
1203
1205 {
1206 return GetFoodStage().CanChangeToNewStage(cooking_method);
1207 }
1208
1209 //Use this to receive food stage from another Edible_Base
1211 {
1212 if (!source.HasFoodStage())
1213 return;
1214 m_LastDecayStage = source.GetLastDecayStage();
1215 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1216 m_DecayTimer = source.GetDecayTimer();
1217 m_DecayDelta = source.GetDecayDelta();
1218 }
1219
1220 //================================================================
1221 // COOKING
1222 //================================================================
1223 //cooking time
1224 float GetCookingTime()
1225 {
1226 return GetFoodStage().GetCookingTime();
1227 }
1228
1229 void SetCookingTime(float time)
1230 {
1231 GetFoodStage().SetCookingTime(time);
1232
1233 //synchronize when calling on server
1234 Synchronize();
1235 }
1236
1237 //replace edible with new item (opening cans)
1238 void ReplaceEdibleWithNew(string typeName)
1239 {
1240 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1241 if (player)
1242 {
1244 player.ServerReplaceItemInHandsWithNew(lambda);
1245 }
1246 else
1247 Error("ReplaceEdibleWithNew - cannot use edible without player");
1248 }
1249
1250 override void SetActions()
1251 {
1252 super.SetActions();
1253
1254 AddAction(ActionAttach);
1256 }
1257
1258 protected void SoundCookingStart(string sound_name)
1259 {
1260#ifndef SERVER
1262 {
1264
1267 }
1268#endif
1269 }
1270
1271 protected void SoundCookingStop()
1272 {
1273#ifndef SERVER
1275 {
1278 m_SoundPlaying = "";
1279 }
1280#endif
1281 }
1282
1283 override bool CanHaveTemperature()
1284 {
1285 return true;
1286 }
1287
1288 override bool CanDecay()
1289 {
1290 return false;
1291 }
1292
1293 override bool CanProcessDecay()
1294 {
1295 return (GetFoodStageType() != FoodStageType.ROTTEN);
1296 }
1297
1298 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1299 {
1300 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1301 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1302 if (hasRootAsPlayer)
1304
1305 /*Print( "-------------------------" );
1306 Print( this );
1307 Print( m_DecayTimer );
1308 Print( m_DecayDelta );
1309 Print( m_LastDecayStage );*/
1310
1311 if (IsFruit() || IsMushroom())
1312 {
1313 // fruit, vegetables and mushrooms
1315 {
1316 switch (GetFoodStageType())
1317 {
1318 case FoodStageType.RAW:
1321 break;
1322
1323 case FoodStageType.BOILED:
1326 break;
1327
1328 case FoodStageType.BAKED:
1331 break;
1332
1333 case FoodStageType.DRIED:
1334 case FoodStageType.BURNED:
1335 case FoodStageType.ROTTEN:
1336 default:
1337 m_DecayTimer = -1;
1339 return;
1340 }
1341
1342 //m_DecayTimer = m_DecayTimer / 1000.0;
1343 }
1344
1346
1347 if (m_DecayTimer <= 0)
1348 {
1349 if (m_LastDecayStage != FoodStageType.NONE)
1350 {
1351 // switch to decayed stage
1352 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1355 {
1356 int rng = Math.RandomIntInclusive(0, 100);
1359 else
1360 {
1363 else
1365 }
1366 }
1367 }
1368 }
1369
1370 }
1371 else if (IsMeat())
1372 {
1373 // meat
1375 {
1376 switch (GetFoodStageType())
1377 {
1378 case FoodStageType.RAW:
1381 break;
1382
1383 case FoodStageType.BOILED:
1386 break;
1387
1388 case FoodStageType.BAKED:
1391 break;
1392
1393 case FoodStageType.DRIED:
1396 break;
1397
1398 case FoodStageType.BURNED:
1399 case FoodStageType.ROTTEN:
1400 default:
1401 m_DecayTimer = -1;
1403 return;
1404 }
1405 }
1406
1408
1409 if (m_DecayTimer <= 0)
1410 {
1411 if (m_LastDecayStage != FoodStageType.NONE)
1412 {
1413 // switch to decayed stage
1416 }
1417 }
1418 }
1419 else if (IsCorpse())
1420 {
1421 // corpse
1423 {
1424 switch (GetFoodStageType())
1425 {
1426 case FoodStageType.RAW:
1429 break;
1430
1431 case FoodStageType.BURNED:
1432 case FoodStageType.ROTTEN:
1433 default:
1434 m_DecayTimer = -1;
1436 return;
1437 }
1438 }
1439
1441
1442 if (m_DecayTimer <= 0)
1443 {
1444 if (m_LastDecayStage != FoodStageType.NONE)
1445 {
1446 // switch to decayed stage
1449 }
1450 }
1451 }
1452 else
1453 {
1454 // opened cans
1456
1457 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1458 {
1461 //m_DecayTimer = m_DecayTimer / 1000.0;
1462 }
1463 else
1464 {
1465 if (m_DecayTimer <= 0)
1466 {
1467 InsertAgent(eAgents.FOOD_POISON, 1);
1468 m_DecayTimer = -1;
1469 }
1470 }
1471 }
1472
1473 m_DecayDelta = 0.0;
1474 }
1475
1477 {
1478 super.GetDebugActions(outputList);
1479
1480 if (HasFoodStage())
1481 {
1482 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1483 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1484 }
1485 }
1486
1487 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1488 {
1489 super.OnAction(action_id, player, ctx);
1490
1491 if (GetGame().IsServer())
1492 {
1493 if (action_id == EActions.FOOD_STAGE_PREV)
1494 {
1496 if (food_stage_prev <= 0)
1497 food_stage_prev = FoodStageType.COUNT - 1;
1499 return true;
1500 }
1501 else if (action_id == EActions.FOOD_STAGE_NEXT)
1502 {
1504 if (food_stage_next >= FoodStageType.COUNT)
1507 return true;
1508 }
1509 }
1510 return false;
1511 }
1512
1513 override string GetDebugText()
1514 {
1515 string debug_output;
1516
1517 debug_output = super.GetDebugText();
1518
1519 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1520 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1521
1522 return debug_output;
1523 }
1524
1525 //================================================================
1526 // GENERAL GETTERS
1527 //================================================================
1528
1529 float GetDecayTimer()
1530 {
1531 return m_DecayTimer;
1532 }
1533
1534 float GetDecayDelta()
1535 {
1536 return m_DecayDelta;
1537 }
1538
1540 {
1541 return m_LastDecayStage;
1542 }
1543}
1544
1546{
1548};

◆ EEInit()

override void ReplaceEdibleWithNewLambda::EEInit ( )
private

Definition at line 789 of file Edible_Base.c.

789 : ItemBase
790{
791 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
792
793 const string SOUND_BAKING_START = "Baking_SoundSet";
794 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
795 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
796
797 protected bool m_MakeCookingSounds;
800 protected string m_SoundPlaying;
802 protected float m_DecayTimer;
803 protected float m_DecayDelta = 0.0;
805
807
808 void Edible_Base()
809 {
810 if (HasFoodStage())
811 {
812 m_FoodStage = new FoodStage(this);
813
814 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
815 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
816 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
817 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
818 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
819
820 m_SoundPlaying = "";
822 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
823 RegisterNetSyncVariableBool("m_MakeCookingSounds");
824 }
825 }
826
827 override void EEInit()
828 {
829 super.EEInit();
830
832 }
833
834 override void EEDelete(EntityAI parent)
835 {
836 super.EEDelete(parent);
837
838 RemoveAudio();
839 }
840
842 {
843 super.EEItemLocationChanged(oldLoc, newLoc);
844
846 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
847 {
848 switch (oldLoc.GetParent().GetType())
849 {
850 case "FryingPan":
851 case "Pot":
852 case "Cauldron":
853 case "SharpWoodenStick":
854 MakeSoundsOnClient(false);
855 break;
856 }
857
859 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
860 MakeSoundsOnClient(false);
861 }
862 }
863
864 void UpdateVisuals()
865 {
866 if (GetFoodStage())
867 GetFoodStage().UpdateVisuals();
868 }
869
870 bool Consume(float amount, PlayerBase consumer)
871 {
872 AddQuantity(-amount, false, false);
873 OnConsume(amount, consumer);
874
875 return true;
876 }
877
878 void OnConsume(float amount, PlayerBase consumer);
879
880 //food staging
881 override bool CanBeCooked()
882 {
883 return false;
884 }
885
886 override bool CanBeCookedOnStick()
887 {
888 return false;
889 }
890
891 //================================================================
892 // SYNCHRONIZATION
893 //================================================================
894 void Synchronize()
895 {
896 SetSynchDirty();
897
898 if (GetGame().IsMultiplayer())
900 }
901
902 override void OnVariablesSynchronized()
903 {
904 super.OnVariablesSynchronized();
905
907
908 //update audio
910 RefreshAudio();
911 else
912 RemoveAudio();
913 }
914
915 //================================================================
916 // AUDIO EFFECTS (WHEN ON DCS)
917 //================================================================
919 {
922
923 Synchronize();
924 }
925
926 protected void RefreshAudio()
927 {
928 string soundName = "";
929
931
932 switch (GetFoodStageType())
933 {
934 case FoodStageType.RAW:
936 if (nextFoodState == FoodStageType.BOILED)
937 soundName = "";
938 break;
939 case FoodStageType.BAKED:
941 break;
942 case FoodStageType.BURNED:
944 break;
945 default:
946 soundName = "";
947 break;
948 }
949
951 }
952
953 protected void RemoveAudio()
954 {
955 m_MakeCookingSounds = false;
957 }
958
959 //================================================================
960 // SERIALIZATION
961 //================================================================
962 override void OnStoreSave(ParamsWriteContext ctx)
963 {
964 super.OnStoreSave(ctx);
965
966 if (GetFoodStage())
967 GetFoodStage().OnStoreSave(ctx);
968
969 // food decay
970 ctx.Write(m_DecayTimer);
971 ctx.Write(m_LastDecayStage);
972 }
973
974 override bool OnStoreLoad(ParamsReadContext ctx, int version)
975 {
976 if (!super.OnStoreLoad(ctx, version))
977 return false;
978
979 if (GetFoodStage())
980 {
981 if (!GetFoodStage().OnStoreLoad(ctx, version))
982 return false;
983 }
984
985 if (version >= 115)
986 {
987 if (!ctx.Read(m_DecayTimer))
988 {
989 m_DecayTimer = 0.0;
990 return false;
991 }
992 if (!ctx.Read(m_LastDecayStage))
993 {
995 return false;
996 }
997 }
998
999 return true;
1000 }
1001
1002 override void AfterStoreLoad()
1003 {
1004 super.AfterStoreLoad();
1005
1006 Synchronize();
1007 }
1008
1009 //get food stage
1011 {
1012 return m_FoodStage;
1013 }
1014
1015 //food types
1016 override bool IsMeat()
1017 {
1018 return false;
1019 }
1020
1021 override bool IsCorpse()
1022 {
1023 return false;
1024 }
1025
1026 override bool IsFruit()
1027 {
1028 return false;
1029 }
1030
1031 override bool IsMushroom()
1032 {
1033 return false;
1034 }
1035
1036 //================================================================
1037 // NUTRITIONAL VALUES
1038 //================================================================
1039 //food properties
1040 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1041 {
1043 if (food_item && food_item.GetFoodStage())
1044 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1045 else if (classname != "" && food_stage)
1046 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1047 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1048 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1049
1050 }
1051
1052 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1053 {
1055 if (food_item && food_item.GetFoodStage())
1056 return FoodStage.GetEnergy(food_item.GetFoodStage());
1057 else if (classname != "" && food_stage)
1058 return FoodStage.GetEnergy(null, food_stage, classname);
1059 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1060 return GetGame().ConfigGetFloat(class_path + " energy");
1061 }
1062
1063 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1064 {
1066 if (food_item && food_item.GetFoodStage())
1067 return FoodStage.GetWater(food_item.GetFoodStage());
1068 else if (classname != "" && food_stage)
1069 return FoodStage.GetWater(null, food_stage, classname);
1070 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1071 return GetGame().ConfigGetFloat(class_path + " water");
1072 }
1073
1074 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1075 {
1077 if (food_item && food_item.GetFoodStage())
1078 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1079 else if (classname != "" && food_stage)
1080 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1081 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1082 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1083
1084 }
1085
1086 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1087 {
1089 if (food_item && food_item.GetFoodStage())
1090 return FoodStage.GetToxicity(food_item.GetFoodStage());
1091 else if (classname != "" && food_stage)
1092 return FoodStage.GetToxicity(null, food_stage, classname);
1093 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1094 return GetGame().ConfigGetFloat(class_path + " toxicity");
1095 }
1096
1097 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1098 {
1100 if (food_item && food_item.GetFoodStage())
1101 return FoodStage.GetAgents(food_item.GetFoodStage());
1102 else if (classname != "" && food_stage)
1103 return FoodStage.GetAgents(null, food_stage, classname);
1104 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1105 return GetGame().ConfigGetInt(class_path + " agents");
1106 }
1107
1108 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1109 {
1111 if (food_item && food_item.GetFoodStage())
1112 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1113 else if (classname != "" && food_stage)
1114 return FoodStage.GetDigestibility(null, food_stage, classname);
1115 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1116 return GetGame().ConfigGetInt(class_path + " digestibility");
1117 }
1118
1120 {
1122 }
1123
1124 //================================================================
1125 // FOOD STAGING
1126 //================================================================
1128 {
1129 return GetFoodStage().GetFoodStageType();
1130 }
1131
1132 //food stage states
1133 bool IsFoodRaw()
1134 {
1135 if (GetFoodStage())
1136 return GetFoodStage().IsFoodRaw();
1137
1138 return false;
1139 }
1140
1141 bool IsFoodBaked()
1142 {
1143 if (GetFoodStage())
1144 return GetFoodStage().IsFoodBaked();
1145
1146 return false;
1147 }
1148
1149 bool IsFoodBoiled()
1150 {
1151 if (GetFoodStage())
1152 return GetFoodStage().IsFoodBoiled();
1153
1154 return false;
1155 }
1156
1157 bool IsFoodDried()
1158 {
1159 if (GetFoodStage())
1160 return GetFoodStage().IsFoodDried();
1161
1162 return false;
1163 }
1164
1165 bool IsFoodBurned()
1166 {
1167 if (GetFoodStage())
1168 return GetFoodStage().IsFoodBurned();
1169
1170 return false;
1171 }
1172
1173 bool IsFoodRotten()
1174 {
1175 if (GetFoodStage())
1176 return GetFoodStage().IsFoodRotten();
1177
1178 return false;
1179 }
1180
1181 //food stage change
1183 {
1184 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1185 }
1186
1188 {
1189 return GetFoodStage().GetNextFoodStageType(cooking_method);
1190 }
1191
1193 {
1194 return GetFoodStage().GetFoodStageName(food_stage_type);
1195 }
1196
1198 {
1199 return GetFoodStage().CanChangeToNewStage(cooking_method);
1200 }
1201
1202 //Use this to receive food stage from another Edible_Base
1204 {
1205 if (!source.HasFoodStage())
1206 return;
1207 m_LastDecayStage = source.GetLastDecayStage();
1208 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1209 m_DecayTimer = source.GetDecayTimer();
1210 m_DecayDelta = source.GetDecayDelta();
1211 }
1212
1213 //================================================================
1214 // COOKING
1215 //================================================================
1216 //cooking time
1217 float GetCookingTime()
1218 {
1219 return GetFoodStage().GetCookingTime();
1220 }
1221
1222 void SetCookingTime(float time)
1223 {
1224 GetFoodStage().SetCookingTime(time);
1225
1226 //synchronize when calling on server
1227 Synchronize();
1228 }
1229
1230 //replace edible with new item (opening cans)
1231 void ReplaceEdibleWithNew(string typeName)
1232 {
1233 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1234 if (player)
1235 {
1237 player.ServerReplaceItemInHandsWithNew(lambda);
1238 }
1239 else
1240 Error("ReplaceEdibleWithNew - cannot use edible without player");
1241 }
1242
1243 override void SetActions()
1244 {
1245 super.SetActions();
1246
1247 AddAction(ActionAttach);
1249 }
1250
1251 protected void SoundCookingStart(string sound_name)
1252 {
1253#ifndef SERVER
1255 {
1257
1260 }
1261#endif
1262 }
1263
1264 protected void SoundCookingStop()
1265 {
1266#ifndef SERVER
1268 {
1271 m_SoundPlaying = "";
1272 }
1273#endif
1274 }
1275
1276 override bool CanHaveTemperature()
1277 {
1278 return true;
1279 }
1280
1281 override bool CanDecay()
1282 {
1283 return false;
1284 }
1285
1286 override bool CanProcessDecay()
1287 {
1288 return (GetFoodStageType() != FoodStageType.ROTTEN);
1289 }
1290
1291 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1292 {
1293 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1294 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1295 if (hasRootAsPlayer)
1297
1298 /*Print( "-------------------------" );
1299 Print( this );
1300 Print( m_DecayTimer );
1301 Print( m_DecayDelta );
1302 Print( m_LastDecayStage );*/
1303
1304 if (IsFruit() || IsMushroom())
1305 {
1306 // fruit, vegetables and mushrooms
1308 {
1309 switch (GetFoodStageType())
1310 {
1311 case FoodStageType.RAW:
1314 break;
1315
1316 case FoodStageType.BOILED:
1319 break;
1320
1321 case FoodStageType.BAKED:
1324 break;
1325
1326 case FoodStageType.DRIED:
1327 case FoodStageType.BURNED:
1328 case FoodStageType.ROTTEN:
1329 default:
1330 m_DecayTimer = -1;
1332 return;
1333 }
1334
1335 //m_DecayTimer = m_DecayTimer / 1000.0;
1336 }
1337
1339
1340 if (m_DecayTimer <= 0)
1341 {
1342 if (m_LastDecayStage != FoodStageType.NONE)
1343 {
1344 // switch to decayed stage
1345 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1348 {
1349 int rng = Math.RandomIntInclusive(0, 100);
1352 else
1353 {
1356 else
1358 }
1359 }
1360 }
1361 }
1362
1363 }
1364 else if (IsMeat())
1365 {
1366 // meat
1368 {
1369 switch (GetFoodStageType())
1370 {
1371 case FoodStageType.RAW:
1374 break;
1375
1376 case FoodStageType.BOILED:
1379 break;
1380
1381 case FoodStageType.BAKED:
1384 break;
1385
1386 case FoodStageType.DRIED:
1389 break;
1390
1391 case FoodStageType.BURNED:
1392 case FoodStageType.ROTTEN:
1393 default:
1394 m_DecayTimer = -1;
1396 return;
1397 }
1398 }
1399
1401
1402 if (m_DecayTimer <= 0)
1403 {
1404 if (m_LastDecayStage != FoodStageType.NONE)
1405 {
1406 // switch to decayed stage
1409 }
1410 }
1411 }
1412 else if (IsCorpse())
1413 {
1414 // corpse
1416 {
1417 switch (GetFoodStageType())
1418 {
1419 case FoodStageType.RAW:
1422 break;
1423
1424 case FoodStageType.BURNED:
1425 case FoodStageType.ROTTEN:
1426 default:
1427 m_DecayTimer = -1;
1429 return;
1430 }
1431 }
1432
1434
1435 if (m_DecayTimer <= 0)
1436 {
1437 if (m_LastDecayStage != FoodStageType.NONE)
1438 {
1439 // switch to decayed stage
1442 }
1443 }
1444 }
1445 else
1446 {
1447 // opened cans
1449
1450 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1451 {
1454 //m_DecayTimer = m_DecayTimer / 1000.0;
1455 }
1456 else
1457 {
1458 if (m_DecayTimer <= 0)
1459 {
1460 InsertAgent(eAgents.FOOD_POISON, 1);
1461 m_DecayTimer = -1;
1462 }
1463 }
1464 }
1465
1466 m_DecayDelta = 0.0;
1467 }
1468
1470 {
1471 super.GetDebugActions(outputList);
1472
1473 if (HasFoodStage())
1474 {
1475 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1476 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1477 }
1478 }
1479
1480 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1481 {
1482 super.OnAction(action_id, player, ctx);
1483
1484 if (GetGame().IsServer())
1485 {
1486 if (action_id == EActions.FOOD_STAGE_PREV)
1487 {
1489 if (food_stage_prev <= 0)
1490 food_stage_prev = FoodStageType.COUNT - 1;
1492 return true;
1493 }
1494 else if (action_id == EActions.FOOD_STAGE_NEXT)
1495 {
1497 if (food_stage_next >= FoodStageType.COUNT)
1500 return true;
1501 }
1502 }
1503 return false;
1504 }
1505
1506 override string GetDebugText()
1507 {
1508 string debug_output;
1509
1510 debug_output = super.GetDebugText();
1511
1512 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1513 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1514
1515 return debug_output;
1516 }
1517
1518 //================================================================
1519 // GENERAL GETTERS
1520 //================================================================
1521
1522 float GetDecayTimer()
1523 {
1524 return m_DecayTimer;
1525 }
1526
1527 float GetDecayDelta()
1528 {
1529 return m_DecayDelta;
1530 }
1531
1533 {
1534 return m_LastDecayStage;
1535 }
1536}
1537
1539{
1541};

◆ EEItemLocationChanged()

override void ReplaceEdibleWithNewLambda::EEItemLocationChanged ( notnull InventoryLocation oldLoc,
notnull InventoryLocation newLoc )
private

disable sounds (from cooking)

check for DirectCooking slot name

Definition at line 803 of file Edible_Base.c.

803 : ItemBase
804{
805 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
806
807 const string SOUND_BAKING_START = "Baking_SoundSet";
808 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
809 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
810
811 protected bool m_MakeCookingSounds;
814 protected string m_SoundPlaying;
816 protected float m_DecayTimer;
817 protected float m_DecayDelta = 0.0;
819
821
822 void Edible_Base()
823 {
824 if (HasFoodStage())
825 {
826 m_FoodStage = new FoodStage(this);
827
828 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
829 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
830 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
831 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
832 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
833
834 m_SoundPlaying = "";
836 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
837 RegisterNetSyncVariableBool("m_MakeCookingSounds");
838 }
839 }
840
841 override void EEInit()
842 {
843 super.EEInit();
844
846 }
847
848 override void EEDelete(EntityAI parent)
849 {
850 super.EEDelete(parent);
851
852 RemoveAudio();
853 }
854
856 {
857 super.EEItemLocationChanged(oldLoc, newLoc);
858
860 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
861 {
862 switch (oldLoc.GetParent().GetType())
863 {
864 case "FryingPan":
865 case "Pot":
866 case "Cauldron":
867 case "SharpWoodenStick":
868 MakeSoundsOnClient(false);
869 break;
870 }
871
873 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
874 MakeSoundsOnClient(false);
875 }
876 }
877
878 void UpdateVisuals()
879 {
880 if (GetFoodStage())
881 GetFoodStage().UpdateVisuals();
882 }
883
884 bool Consume(float amount, PlayerBase consumer)
885 {
886 AddQuantity(-amount, false, false);
887 OnConsume(amount, consumer);
888
889 return true;
890 }
891
892 void OnConsume(float amount, PlayerBase consumer);
893
894 //food staging
895 override bool CanBeCooked()
896 {
897 return false;
898 }
899
900 override bool CanBeCookedOnStick()
901 {
902 return false;
903 }
904
905 //================================================================
906 // SYNCHRONIZATION
907 //================================================================
908 void Synchronize()
909 {
910 SetSynchDirty();
911
912 if (GetGame().IsMultiplayer())
914 }
915
916 override void OnVariablesSynchronized()
917 {
918 super.OnVariablesSynchronized();
919
921
922 //update audio
924 RefreshAudio();
925 else
926 RemoveAudio();
927 }
928
929 //================================================================
930 // AUDIO EFFECTS (WHEN ON DCS)
931 //================================================================
933 {
936
937 Synchronize();
938 }
939
940 protected void RefreshAudio()
941 {
942 string soundName = "";
943
945
946 switch (GetFoodStageType())
947 {
948 case FoodStageType.RAW:
950 if (nextFoodState == FoodStageType.BOILED)
951 soundName = "";
952 break;
953 case FoodStageType.BAKED:
955 break;
956 case FoodStageType.BURNED:
958 break;
959 default:
960 soundName = "";
961 break;
962 }
963
965 }
966
967 protected void RemoveAudio()
968 {
969 m_MakeCookingSounds = false;
971 }
972
973 //================================================================
974 // SERIALIZATION
975 //================================================================
976 override void OnStoreSave(ParamsWriteContext ctx)
977 {
978 super.OnStoreSave(ctx);
979
980 if (GetFoodStage())
981 GetFoodStage().OnStoreSave(ctx);
982
983 // food decay
984 ctx.Write(m_DecayTimer);
985 ctx.Write(m_LastDecayStage);
986 }
987
988 override bool OnStoreLoad(ParamsReadContext ctx, int version)
989 {
990 if (!super.OnStoreLoad(ctx, version))
991 return false;
992
993 if (GetFoodStage())
994 {
995 if (!GetFoodStage().OnStoreLoad(ctx, version))
996 return false;
997 }
998
999 if (version >= 115)
1000 {
1001 if (!ctx.Read(m_DecayTimer))
1002 {
1003 m_DecayTimer = 0.0;
1004 return false;
1005 }
1006 if (!ctx.Read(m_LastDecayStage))
1007 {
1009 return false;
1010 }
1011 }
1012
1013 return true;
1014 }
1015
1016 override void AfterStoreLoad()
1017 {
1018 super.AfterStoreLoad();
1019
1020 Synchronize();
1021 }
1022
1023 //get food stage
1025 {
1026 return m_FoodStage;
1027 }
1028
1029 //food types
1030 override bool IsMeat()
1031 {
1032 return false;
1033 }
1034
1035 override bool IsCorpse()
1036 {
1037 return false;
1038 }
1039
1040 override bool IsFruit()
1041 {
1042 return false;
1043 }
1044
1045 override bool IsMushroom()
1046 {
1047 return false;
1048 }
1049
1050 //================================================================
1051 // NUTRITIONAL VALUES
1052 //================================================================
1053 //food properties
1054 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1055 {
1057 if (food_item && food_item.GetFoodStage())
1058 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1059 else if (classname != "" && food_stage)
1060 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1061 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1062 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1063
1064 }
1065
1066 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1067 {
1069 if (food_item && food_item.GetFoodStage())
1070 return FoodStage.GetEnergy(food_item.GetFoodStage());
1071 else if (classname != "" && food_stage)
1072 return FoodStage.GetEnergy(null, food_stage, classname);
1073 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1074 return GetGame().ConfigGetFloat(class_path + " energy");
1075 }
1076
1077 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1078 {
1080 if (food_item && food_item.GetFoodStage())
1081 return FoodStage.GetWater(food_item.GetFoodStage());
1082 else if (classname != "" && food_stage)
1083 return FoodStage.GetWater(null, food_stage, classname);
1084 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1085 return GetGame().ConfigGetFloat(class_path + " water");
1086 }
1087
1088 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1089 {
1091 if (food_item && food_item.GetFoodStage())
1092 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1093 else if (classname != "" && food_stage)
1094 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1095 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1096 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1097
1098 }
1099
1100 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1101 {
1103 if (food_item && food_item.GetFoodStage())
1104 return FoodStage.GetToxicity(food_item.GetFoodStage());
1105 else if (classname != "" && food_stage)
1106 return FoodStage.GetToxicity(null, food_stage, classname);
1107 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1108 return GetGame().ConfigGetFloat(class_path + " toxicity");
1109 }
1110
1111 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1112 {
1114 if (food_item && food_item.GetFoodStage())
1115 return FoodStage.GetAgents(food_item.GetFoodStage());
1116 else if (classname != "" && food_stage)
1117 return FoodStage.GetAgents(null, food_stage, classname);
1118 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1119 return GetGame().ConfigGetInt(class_path + " agents");
1120 }
1121
1122 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1123 {
1125 if (food_item && food_item.GetFoodStage())
1126 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1127 else if (classname != "" && food_stage)
1128 return FoodStage.GetDigestibility(null, food_stage, classname);
1129 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1130 return GetGame().ConfigGetInt(class_path + " digestibility");
1131 }
1132
1134 {
1136 }
1137
1138 //================================================================
1139 // FOOD STAGING
1140 //================================================================
1142 {
1143 return GetFoodStage().GetFoodStageType();
1144 }
1145
1146 //food stage states
1147 bool IsFoodRaw()
1148 {
1149 if (GetFoodStage())
1150 return GetFoodStage().IsFoodRaw();
1151
1152 return false;
1153 }
1154
1155 bool IsFoodBaked()
1156 {
1157 if (GetFoodStage())
1158 return GetFoodStage().IsFoodBaked();
1159
1160 return false;
1161 }
1162
1163 bool IsFoodBoiled()
1164 {
1165 if (GetFoodStage())
1166 return GetFoodStage().IsFoodBoiled();
1167
1168 return false;
1169 }
1170
1171 bool IsFoodDried()
1172 {
1173 if (GetFoodStage())
1174 return GetFoodStage().IsFoodDried();
1175
1176 return false;
1177 }
1178
1179 bool IsFoodBurned()
1180 {
1181 if (GetFoodStage())
1182 return GetFoodStage().IsFoodBurned();
1183
1184 return false;
1185 }
1186
1187 bool IsFoodRotten()
1188 {
1189 if (GetFoodStage())
1190 return GetFoodStage().IsFoodRotten();
1191
1192 return false;
1193 }
1194
1195 //food stage change
1197 {
1198 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1199 }
1200
1202 {
1203 return GetFoodStage().GetNextFoodStageType(cooking_method);
1204 }
1205
1207 {
1208 return GetFoodStage().GetFoodStageName(food_stage_type);
1209 }
1210
1212 {
1213 return GetFoodStage().CanChangeToNewStage(cooking_method);
1214 }
1215
1216 //Use this to receive food stage from another Edible_Base
1218 {
1219 if (!source.HasFoodStage())
1220 return;
1221 m_LastDecayStage = source.GetLastDecayStage();
1222 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1223 m_DecayTimer = source.GetDecayTimer();
1224 m_DecayDelta = source.GetDecayDelta();
1225 }
1226
1227 //================================================================
1228 // COOKING
1229 //================================================================
1230 //cooking time
1231 float GetCookingTime()
1232 {
1233 return GetFoodStage().GetCookingTime();
1234 }
1235
1236 void SetCookingTime(float time)
1237 {
1238 GetFoodStage().SetCookingTime(time);
1239
1240 //synchronize when calling on server
1241 Synchronize();
1242 }
1243
1244 //replace edible with new item (opening cans)
1245 void ReplaceEdibleWithNew(string typeName)
1246 {
1247 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1248 if (player)
1249 {
1251 player.ServerReplaceItemInHandsWithNew(lambda);
1252 }
1253 else
1254 Error("ReplaceEdibleWithNew - cannot use edible without player");
1255 }
1256
1257 override void SetActions()
1258 {
1259 super.SetActions();
1260
1261 AddAction(ActionAttach);
1263 }
1264
1265 protected void SoundCookingStart(string sound_name)
1266 {
1267#ifndef SERVER
1269 {
1271
1274 }
1275#endif
1276 }
1277
1278 protected void SoundCookingStop()
1279 {
1280#ifndef SERVER
1282 {
1285 m_SoundPlaying = "";
1286 }
1287#endif
1288 }
1289
1290 override bool CanHaveTemperature()
1291 {
1292 return true;
1293 }
1294
1295 override bool CanDecay()
1296 {
1297 return false;
1298 }
1299
1300 override bool CanProcessDecay()
1301 {
1302 return (GetFoodStageType() != FoodStageType.ROTTEN);
1303 }
1304
1305 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1306 {
1307 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1308 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1309 if (hasRootAsPlayer)
1311
1312 /*Print( "-------------------------" );
1313 Print( this );
1314 Print( m_DecayTimer );
1315 Print( m_DecayDelta );
1316 Print( m_LastDecayStage );*/
1317
1318 if (IsFruit() || IsMushroom())
1319 {
1320 // fruit, vegetables and mushrooms
1322 {
1323 switch (GetFoodStageType())
1324 {
1325 case FoodStageType.RAW:
1328 break;
1329
1330 case FoodStageType.BOILED:
1333 break;
1334
1335 case FoodStageType.BAKED:
1338 break;
1339
1340 case FoodStageType.DRIED:
1341 case FoodStageType.BURNED:
1342 case FoodStageType.ROTTEN:
1343 default:
1344 m_DecayTimer = -1;
1346 return;
1347 }
1348
1349 //m_DecayTimer = m_DecayTimer / 1000.0;
1350 }
1351
1353
1354 if (m_DecayTimer <= 0)
1355 {
1356 if (m_LastDecayStage != FoodStageType.NONE)
1357 {
1358 // switch to decayed stage
1359 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1362 {
1363 int rng = Math.RandomIntInclusive(0, 100);
1366 else
1367 {
1370 else
1372 }
1373 }
1374 }
1375 }
1376
1377 }
1378 else if (IsMeat())
1379 {
1380 // meat
1382 {
1383 switch (GetFoodStageType())
1384 {
1385 case FoodStageType.RAW:
1388 break;
1389
1390 case FoodStageType.BOILED:
1393 break;
1394
1395 case FoodStageType.BAKED:
1398 break;
1399
1400 case FoodStageType.DRIED:
1403 break;
1404
1405 case FoodStageType.BURNED:
1406 case FoodStageType.ROTTEN:
1407 default:
1408 m_DecayTimer = -1;
1410 return;
1411 }
1412 }
1413
1415
1416 if (m_DecayTimer <= 0)
1417 {
1418 if (m_LastDecayStage != FoodStageType.NONE)
1419 {
1420 // switch to decayed stage
1423 }
1424 }
1425 }
1426 else if (IsCorpse())
1427 {
1428 // corpse
1430 {
1431 switch (GetFoodStageType())
1432 {
1433 case FoodStageType.RAW:
1436 break;
1437
1438 case FoodStageType.BURNED:
1439 case FoodStageType.ROTTEN:
1440 default:
1441 m_DecayTimer = -1;
1443 return;
1444 }
1445 }
1446
1448
1449 if (m_DecayTimer <= 0)
1450 {
1451 if (m_LastDecayStage != FoodStageType.NONE)
1452 {
1453 // switch to decayed stage
1456 }
1457 }
1458 }
1459 else
1460 {
1461 // opened cans
1463
1464 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1465 {
1468 //m_DecayTimer = m_DecayTimer / 1000.0;
1469 }
1470 else
1471 {
1472 if (m_DecayTimer <= 0)
1473 {
1474 InsertAgent(eAgents.FOOD_POISON, 1);
1475 m_DecayTimer = -1;
1476 }
1477 }
1478 }
1479
1480 m_DecayDelta = 0.0;
1481 }
1482
1484 {
1485 super.GetDebugActions(outputList);
1486
1487 if (HasFoodStage())
1488 {
1489 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1490 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1491 }
1492 }
1493
1494 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1495 {
1496 super.OnAction(action_id, player, ctx);
1497
1498 if (GetGame().IsServer())
1499 {
1500 if (action_id == EActions.FOOD_STAGE_PREV)
1501 {
1503 if (food_stage_prev <= 0)
1504 food_stage_prev = FoodStageType.COUNT - 1;
1506 return true;
1507 }
1508 else if (action_id == EActions.FOOD_STAGE_NEXT)
1509 {
1511 if (food_stage_next >= FoodStageType.COUNT)
1514 return true;
1515 }
1516 }
1517 return false;
1518 }
1519
1520 override string GetDebugText()
1521 {
1522 string debug_output;
1523
1524 debug_output = super.GetDebugText();
1525
1526 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1527 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1528
1529 return debug_output;
1530 }
1531
1532 //================================================================
1533 // GENERAL GETTERS
1534 //================================================================
1535
1536 float GetDecayTimer()
1537 {
1538 return m_DecayTimer;
1539 }
1540
1541 float GetDecayDelta()
1542 {
1543 return m_DecayDelta;
1544 }
1545
1547 {
1548 return m_LastDecayStage;
1549 }
1550}
1551
1553{
1555};

◆ GetCookingTime()

float ReplaceEdibleWithNewLambda::GetCookingTime ( )
protected

Definition at line 1179 of file Edible_Base.c.

1179 : ItemBase
1180{
1181 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1182
1183 const string SOUND_BAKING_START = "Baking_SoundSet";
1184 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1185 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1186
1187 protected bool m_MakeCookingSounds;
1188 protected SoundOnVehicle m_SoundCooking;
1190 protected string m_SoundPlaying;
1192 protected float m_DecayTimer;
1193 protected float m_DecayDelta = 0.0;
1195
1197
1198 void Edible_Base()
1199 {
1200 if (HasFoodStage())
1201 {
1202 m_FoodStage = new FoodStage(this);
1203
1204 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1205 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1206 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1207 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1208 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1209
1210 m_SoundPlaying = "";
1212 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1213 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1214 }
1215 }
1216
1217 override void EEInit()
1218 {
1219 super.EEInit();
1220
1221 UpdateVisuals();
1222 }
1223
1224 override void EEDelete(EntityAI parent)
1225 {
1226 super.EEDelete(parent);
1227
1228 RemoveAudio();
1229 }
1230
1232 {
1233 super.EEItemLocationChanged(oldLoc, newLoc);
1234
1236 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1237 {
1238 switch (oldLoc.GetParent().GetType())
1239 {
1240 case "FryingPan":
1241 case "Pot":
1242 case "Cauldron":
1243 case "SharpWoodenStick":
1244 MakeSoundsOnClient(false);
1245 break;
1246 }
1247
1249 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1250 MakeSoundsOnClient(false);
1251 }
1252 }
1253
1254 void UpdateVisuals()
1255 {
1256 if (GetFoodStage())
1257 GetFoodStage().UpdateVisuals();
1258 }
1259
1260 bool Consume(float amount, PlayerBase consumer)
1261 {
1262 AddQuantity(-amount, false, false);
1263 OnConsume(amount, consumer);
1264
1265 return true;
1266 }
1267
1268 void OnConsume(float amount, PlayerBase consumer);
1269
1270 //food staging
1271 override bool CanBeCooked()
1272 {
1273 return false;
1274 }
1275
1276 override bool CanBeCookedOnStick()
1277 {
1278 return false;
1279 }
1280
1281 //================================================================
1282 // SYNCHRONIZATION
1283 //================================================================
1284 void Synchronize()
1285 {
1286 SetSynchDirty();
1287
1288 if (GetGame().IsMultiplayer())
1289 UpdateVisuals();
1290 }
1291
1292 override void OnVariablesSynchronized()
1293 {
1294 super.OnVariablesSynchronized();
1295
1296 UpdateVisuals();
1297
1298 //update audio
1300 RefreshAudio();
1301 else
1302 RemoveAudio();
1303 }
1304
1305 //================================================================
1306 // AUDIO EFFECTS (WHEN ON DCS)
1307 //================================================================
1309 {
1312
1313 Synchronize();
1314 }
1315
1316 protected void RefreshAudio()
1317 {
1318 string soundName = "";
1319
1321
1322 switch (GetFoodStageType())
1323 {
1324 case FoodStageType.RAW:
1326 if (nextFoodState == FoodStageType.BOILED)
1327 soundName = "";
1328 break;
1329 case FoodStageType.BAKED:
1331 break;
1332 case FoodStageType.BURNED:
1334 break;
1335 default:
1336 soundName = "";
1337 break;
1338 }
1339
1341 }
1342
1343 protected void RemoveAudio()
1344 {
1345 m_MakeCookingSounds = false;
1347 }
1348
1349 //================================================================
1350 // SERIALIZATION
1351 //================================================================
1352 override void OnStoreSave(ParamsWriteContext ctx)
1353 {
1354 super.OnStoreSave(ctx);
1355
1356 if (GetFoodStage())
1357 GetFoodStage().OnStoreSave(ctx);
1358
1359 // food decay
1360 ctx.Write(m_DecayTimer);
1361 ctx.Write(m_LastDecayStage);
1362 }
1363
1364 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1365 {
1366 if (!super.OnStoreLoad(ctx, version))
1367 return false;
1368
1369 if (GetFoodStage())
1370 {
1371 if (!GetFoodStage().OnStoreLoad(ctx, version))
1372 return false;
1373 }
1374
1375 if (version >= 115)
1376 {
1377 if (!ctx.Read(m_DecayTimer))
1378 {
1379 m_DecayTimer = 0.0;
1380 return false;
1381 }
1382 if (!ctx.Read(m_LastDecayStage))
1383 {
1385 return false;
1386 }
1387 }
1388
1389 return true;
1390 }
1391
1392 override void AfterStoreLoad()
1393 {
1394 super.AfterStoreLoad();
1395
1396 Synchronize();
1397 }
1398
1399 //get food stage
1401 {
1402 return m_FoodStage;
1403 }
1404
1405 //food types
1406 override bool IsMeat()
1407 {
1408 return false;
1409 }
1410
1411 override bool IsCorpse()
1412 {
1413 return false;
1414 }
1415
1416 override bool IsFruit()
1417 {
1418 return false;
1419 }
1420
1421 override bool IsMushroom()
1422 {
1423 return false;
1424 }
1425
1426 //================================================================
1427 // NUTRITIONAL VALUES
1428 //================================================================
1429 //food properties
1430 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1431 {
1433 if (food_item && food_item.GetFoodStage())
1434 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1435 else if (classname != "" && food_stage)
1436 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1437 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1438 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1439
1440 }
1441
1442 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1443 {
1445 if (food_item && food_item.GetFoodStage())
1446 return FoodStage.GetEnergy(food_item.GetFoodStage());
1447 else if (classname != "" && food_stage)
1448 return FoodStage.GetEnergy(null, food_stage, classname);
1449 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1450 return GetGame().ConfigGetFloat(class_path + " energy");
1451 }
1452
1453 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1454 {
1456 if (food_item && food_item.GetFoodStage())
1457 return FoodStage.GetWater(food_item.GetFoodStage());
1458 else if (classname != "" && food_stage)
1459 return FoodStage.GetWater(null, food_stage, classname);
1460 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1461 return GetGame().ConfigGetFloat(class_path + " water");
1462 }
1463
1464 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1465 {
1467 if (food_item && food_item.GetFoodStage())
1468 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1469 else if (classname != "" && food_stage)
1470 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1471 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1472 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1473
1474 }
1475
1476 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1477 {
1479 if (food_item && food_item.GetFoodStage())
1480 return FoodStage.GetToxicity(food_item.GetFoodStage());
1481 else if (classname != "" && food_stage)
1482 return FoodStage.GetToxicity(null, food_stage, classname);
1483 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1484 return GetGame().ConfigGetFloat(class_path + " toxicity");
1485 }
1486
1487 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1488 {
1490 if (food_item && food_item.GetFoodStage())
1491 return FoodStage.GetAgents(food_item.GetFoodStage());
1492 else if (classname != "" && food_stage)
1493 return FoodStage.GetAgents(null, food_stage, classname);
1494 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1495 return GetGame().ConfigGetInt(class_path + " agents");
1496 }
1497
1498 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1499 {
1501 if (food_item && food_item.GetFoodStage())
1502 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1503 else if (classname != "" && food_stage)
1504 return FoodStage.GetDigestibility(null, food_stage, classname);
1505 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1506 return GetGame().ConfigGetInt(class_path + " digestibility");
1507 }
1508
1510 {
1512 }
1513
1514 //================================================================
1515 // FOOD STAGING
1516 //================================================================
1518 {
1519 return GetFoodStage().GetFoodStageType();
1520 }
1521
1522 //food stage states
1523 bool IsFoodRaw()
1524 {
1525 if (GetFoodStage())
1526 return GetFoodStage().IsFoodRaw();
1527
1528 return false;
1529 }
1530
1531 bool IsFoodBaked()
1532 {
1533 if (GetFoodStage())
1534 return GetFoodStage().IsFoodBaked();
1535
1536 return false;
1537 }
1538
1539 bool IsFoodBoiled()
1540 {
1541 if (GetFoodStage())
1542 return GetFoodStage().IsFoodBoiled();
1543
1544 return false;
1545 }
1546
1547 bool IsFoodDried()
1548 {
1549 if (GetFoodStage())
1550 return GetFoodStage().IsFoodDried();
1551
1552 return false;
1553 }
1554
1555 bool IsFoodBurned()
1556 {
1557 if (GetFoodStage())
1558 return GetFoodStage().IsFoodBurned();
1559
1560 return false;
1561 }
1562
1563 bool IsFoodRotten()
1564 {
1565 if (GetFoodStage())
1566 return GetFoodStage().IsFoodRotten();
1567
1568 return false;
1569 }
1570
1571 //food stage change
1573 {
1574 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1575 }
1576
1578 {
1579 return GetFoodStage().GetNextFoodStageType(cooking_method);
1580 }
1581
1583 {
1584 return GetFoodStage().GetFoodStageName(food_stage_type);
1585 }
1586
1588 {
1589 return GetFoodStage().CanChangeToNewStage(cooking_method);
1590 }
1591
1592 //Use this to receive food stage from another Edible_Base
1594 {
1595 if (!source.HasFoodStage())
1596 return;
1597 m_LastDecayStage = source.GetLastDecayStage();
1598 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1599 m_DecayTimer = source.GetDecayTimer();
1600 m_DecayDelta = source.GetDecayDelta();
1601 }
1602
1603 //================================================================
1604 // COOKING
1605 //================================================================
1606 //cooking time
1607 float GetCookingTime()
1608 {
1609 return GetFoodStage().GetCookingTime();
1610 }
1611
1612 void SetCookingTime(float time)
1613 {
1614 GetFoodStage().SetCookingTime(time);
1615
1616 //synchronize when calling on server
1617 Synchronize();
1618 }
1619
1620 //replace edible with new item (opening cans)
1621 void ReplaceEdibleWithNew(string typeName)
1622 {
1623 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1624 if (player)
1625 {
1627 player.ServerReplaceItemInHandsWithNew(lambda);
1628 }
1629 else
1630 Error("ReplaceEdibleWithNew - cannot use edible without player");
1631 }
1632
1633 override void SetActions()
1634 {
1635 super.SetActions();
1636
1637 AddAction(ActionAttach);
1639 }
1640
1641 protected void SoundCookingStart(string sound_name)
1642 {
1643#ifndef SERVER
1645 {
1647
1650 }
1651#endif
1652 }
1653
1654 protected void SoundCookingStop()
1655 {
1656#ifndef SERVER
1658 {
1661 m_SoundPlaying = "";
1662 }
1663#endif
1664 }
1665
1666 override bool CanHaveTemperature()
1667 {
1668 return true;
1669 }
1670
1671 override bool CanDecay()
1672 {
1673 return false;
1674 }
1675
1676 override bool CanProcessDecay()
1677 {
1678 return (GetFoodStageType() != FoodStageType.ROTTEN);
1679 }
1680
1681 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1682 {
1683 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1684 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1685 if (hasRootAsPlayer)
1687
1688 /*Print( "-------------------------" );
1689 Print( this );
1690 Print( m_DecayTimer );
1691 Print( m_DecayDelta );
1692 Print( m_LastDecayStage );*/
1693
1694 if (IsFruit() || IsMushroom())
1695 {
1696 // fruit, vegetables and mushrooms
1698 {
1699 switch (GetFoodStageType())
1700 {
1701 case FoodStageType.RAW:
1704 break;
1705
1706 case FoodStageType.BOILED:
1709 break;
1710
1711 case FoodStageType.BAKED:
1714 break;
1715
1716 case FoodStageType.DRIED:
1717 case FoodStageType.BURNED:
1718 case FoodStageType.ROTTEN:
1719 default:
1720 m_DecayTimer = -1;
1722 return;
1723 }
1724
1725 //m_DecayTimer = m_DecayTimer / 1000.0;
1726 }
1727
1729
1730 if (m_DecayTimer <= 0)
1731 {
1732 if (m_LastDecayStage != FoodStageType.NONE)
1733 {
1734 // switch to decayed stage
1735 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1738 {
1739 int rng = Math.RandomIntInclusive(0, 100);
1742 else
1743 {
1746 else
1748 }
1749 }
1750 }
1751 }
1752
1753 }
1754 else if (IsMeat())
1755 {
1756 // meat
1758 {
1759 switch (GetFoodStageType())
1760 {
1761 case FoodStageType.RAW:
1764 break;
1765
1766 case FoodStageType.BOILED:
1769 break;
1770
1771 case FoodStageType.BAKED:
1774 break;
1775
1776 case FoodStageType.DRIED:
1779 break;
1780
1781 case FoodStageType.BURNED:
1782 case FoodStageType.ROTTEN:
1783 default:
1784 m_DecayTimer = -1;
1786 return;
1787 }
1788 }
1789
1791
1792 if (m_DecayTimer <= 0)
1793 {
1794 if (m_LastDecayStage != FoodStageType.NONE)
1795 {
1796 // switch to decayed stage
1799 }
1800 }
1801 }
1802 else if (IsCorpse())
1803 {
1804 // corpse
1806 {
1807 switch (GetFoodStageType())
1808 {
1809 case FoodStageType.RAW:
1812 break;
1813
1814 case FoodStageType.BURNED:
1815 case FoodStageType.ROTTEN:
1816 default:
1817 m_DecayTimer = -1;
1819 return;
1820 }
1821 }
1822
1824
1825 if (m_DecayTimer <= 0)
1826 {
1827 if (m_LastDecayStage != FoodStageType.NONE)
1828 {
1829 // switch to decayed stage
1832 }
1833 }
1834 }
1835 else
1836 {
1837 // opened cans
1839
1840 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1841 {
1844 //m_DecayTimer = m_DecayTimer / 1000.0;
1845 }
1846 else
1847 {
1848 if (m_DecayTimer <= 0)
1849 {
1850 InsertAgent(eAgents.FOOD_POISON, 1);
1851 m_DecayTimer = -1;
1852 }
1853 }
1854 }
1855
1856 m_DecayDelta = 0.0;
1857 }
1858
1860 {
1861 super.GetDebugActions(outputList);
1862
1863 if (HasFoodStage())
1864 {
1865 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1866 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1867 }
1868 }
1869
1870 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1871 {
1872 super.OnAction(action_id, player, ctx);
1873
1874 if (GetGame().IsServer())
1875 {
1876 if (action_id == EActions.FOOD_STAGE_PREV)
1877 {
1879 if (food_stage_prev <= 0)
1880 food_stage_prev = FoodStageType.COUNT - 1;
1882 return true;
1883 }
1884 else if (action_id == EActions.FOOD_STAGE_NEXT)
1885 {
1887 if (food_stage_next >= FoodStageType.COUNT)
1890 return true;
1891 }
1892 }
1893 return false;
1894 }
1895
1896 override string GetDebugText()
1897 {
1898 string debug_output;
1899
1900 debug_output = super.GetDebugText();
1901
1902 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1903 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1904
1905 return debug_output;
1906 }
1907
1908 //================================================================
1909 // GENERAL GETTERS
1910 //================================================================
1911
1912 float GetDecayTimer()
1913 {
1914 return m_DecayTimer;
1915 }
1916
1917 float GetDecayDelta()
1918 {
1919 return m_DecayDelta;
1920 }
1921
1923 {
1924 return m_LastDecayStage;
1925 }
1926}
1927
1929{
1931};

◆ GetDebugActions()

override void ReplaceEdibleWithNewLambda::GetDebugActions ( out TSelectableActionInfoArrayEx outputList)
protected

Definition at line 1431 of file Edible_Base.c.

1431 : ItemBase
1432{
1433 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1434
1435 const string SOUND_BAKING_START = "Baking_SoundSet";
1436 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1437 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1438
1439 protected bool m_MakeCookingSounds;
1440 protected SoundOnVehicle m_SoundCooking;
1442 protected string m_SoundPlaying;
1444 protected float m_DecayTimer;
1445 protected float m_DecayDelta = 0.0;
1447
1449
1450 void Edible_Base()
1451 {
1452 if (HasFoodStage())
1453 {
1454 m_FoodStage = new FoodStage(this);
1455
1456 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1457 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1458 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1459 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1460 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1461
1462 m_SoundPlaying = "";
1464 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1465 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1466 }
1467 }
1468
1469 override void EEInit()
1470 {
1471 super.EEInit();
1472
1473 UpdateVisuals();
1474 }
1475
1476 override void EEDelete(EntityAI parent)
1477 {
1478 super.EEDelete(parent);
1479
1480 RemoveAudio();
1481 }
1482
1484 {
1485 super.EEItemLocationChanged(oldLoc, newLoc);
1486
1488 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1489 {
1490 switch (oldLoc.GetParent().GetType())
1491 {
1492 case "FryingPan":
1493 case "Pot":
1494 case "Cauldron":
1495 case "SharpWoodenStick":
1496 MakeSoundsOnClient(false);
1497 break;
1498 }
1499
1501 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1502 MakeSoundsOnClient(false);
1503 }
1504 }
1505
1506 void UpdateVisuals()
1507 {
1508 if (GetFoodStage())
1509 GetFoodStage().UpdateVisuals();
1510 }
1511
1512 bool Consume(float amount, PlayerBase consumer)
1513 {
1514 AddQuantity(-amount, false, false);
1515 OnConsume(amount, consumer);
1516
1517 return true;
1518 }
1519
1520 void OnConsume(float amount, PlayerBase consumer);
1521
1522 //food staging
1523 override bool CanBeCooked()
1524 {
1525 return false;
1526 }
1527
1528 override bool CanBeCookedOnStick()
1529 {
1530 return false;
1531 }
1532
1533 //================================================================
1534 // SYNCHRONIZATION
1535 //================================================================
1536 void Synchronize()
1537 {
1538 SetSynchDirty();
1539
1540 if (GetGame().IsMultiplayer())
1541 UpdateVisuals();
1542 }
1543
1544 override void OnVariablesSynchronized()
1545 {
1546 super.OnVariablesSynchronized();
1547
1548 UpdateVisuals();
1549
1550 //update audio
1552 RefreshAudio();
1553 else
1554 RemoveAudio();
1555 }
1556
1557 //================================================================
1558 // AUDIO EFFECTS (WHEN ON DCS)
1559 //================================================================
1561 {
1564
1565 Synchronize();
1566 }
1567
1568 protected void RefreshAudio()
1569 {
1570 string soundName = "";
1571
1573
1574 switch (GetFoodStageType())
1575 {
1576 case FoodStageType.RAW:
1578 if (nextFoodState == FoodStageType.BOILED)
1579 soundName = "";
1580 break;
1581 case FoodStageType.BAKED:
1583 break;
1584 case FoodStageType.BURNED:
1586 break;
1587 default:
1588 soundName = "";
1589 break;
1590 }
1591
1593 }
1594
1595 protected void RemoveAudio()
1596 {
1597 m_MakeCookingSounds = false;
1599 }
1600
1601 //================================================================
1602 // SERIALIZATION
1603 //================================================================
1604 override void OnStoreSave(ParamsWriteContext ctx)
1605 {
1606 super.OnStoreSave(ctx);
1607
1608 if (GetFoodStage())
1609 GetFoodStage().OnStoreSave(ctx);
1610
1611 // food decay
1612 ctx.Write(m_DecayTimer);
1613 ctx.Write(m_LastDecayStage);
1614 }
1615
1616 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1617 {
1618 if (!super.OnStoreLoad(ctx, version))
1619 return false;
1620
1621 if (GetFoodStage())
1622 {
1623 if (!GetFoodStage().OnStoreLoad(ctx, version))
1624 return false;
1625 }
1626
1627 if (version >= 115)
1628 {
1629 if (!ctx.Read(m_DecayTimer))
1630 {
1631 m_DecayTimer = 0.0;
1632 return false;
1633 }
1634 if (!ctx.Read(m_LastDecayStage))
1635 {
1637 return false;
1638 }
1639 }
1640
1641 return true;
1642 }
1643
1644 override void AfterStoreLoad()
1645 {
1646 super.AfterStoreLoad();
1647
1648 Synchronize();
1649 }
1650
1651 //get food stage
1653 {
1654 return m_FoodStage;
1655 }
1656
1657 //food types
1658 override bool IsMeat()
1659 {
1660 return false;
1661 }
1662
1663 override bool IsCorpse()
1664 {
1665 return false;
1666 }
1667
1668 override bool IsFruit()
1669 {
1670 return false;
1671 }
1672
1673 override bool IsMushroom()
1674 {
1675 return false;
1676 }
1677
1678 //================================================================
1679 // NUTRITIONAL VALUES
1680 //================================================================
1681 //food properties
1682 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1683 {
1685 if (food_item && food_item.GetFoodStage())
1686 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1687 else if (classname != "" && food_stage)
1688 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1689 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1690 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1691
1692 }
1693
1694 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1695 {
1697 if (food_item && food_item.GetFoodStage())
1698 return FoodStage.GetEnergy(food_item.GetFoodStage());
1699 else if (classname != "" && food_stage)
1700 return FoodStage.GetEnergy(null, food_stage, classname);
1701 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1702 return GetGame().ConfigGetFloat(class_path + " energy");
1703 }
1704
1705 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1706 {
1708 if (food_item && food_item.GetFoodStage())
1709 return FoodStage.GetWater(food_item.GetFoodStage());
1710 else if (classname != "" && food_stage)
1711 return FoodStage.GetWater(null, food_stage, classname);
1712 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1713 return GetGame().ConfigGetFloat(class_path + " water");
1714 }
1715
1716 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1717 {
1719 if (food_item && food_item.GetFoodStage())
1720 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1721 else if (classname != "" && food_stage)
1722 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1723 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1724 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1725
1726 }
1727
1728 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1729 {
1731 if (food_item && food_item.GetFoodStage())
1732 return FoodStage.GetToxicity(food_item.GetFoodStage());
1733 else if (classname != "" && food_stage)
1734 return FoodStage.GetToxicity(null, food_stage, classname);
1735 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1736 return GetGame().ConfigGetFloat(class_path + " toxicity");
1737 }
1738
1739 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1740 {
1742 if (food_item && food_item.GetFoodStage())
1743 return FoodStage.GetAgents(food_item.GetFoodStage());
1744 else if (classname != "" && food_stage)
1745 return FoodStage.GetAgents(null, food_stage, classname);
1746 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1747 return GetGame().ConfigGetInt(class_path + " agents");
1748 }
1749
1750 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1751 {
1753 if (food_item && food_item.GetFoodStage())
1754 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1755 else if (classname != "" && food_stage)
1756 return FoodStage.GetDigestibility(null, food_stage, classname);
1757 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1758 return GetGame().ConfigGetInt(class_path + " digestibility");
1759 }
1760
1762 {
1764 }
1765
1766 //================================================================
1767 // FOOD STAGING
1768 //================================================================
1770 {
1771 return GetFoodStage().GetFoodStageType();
1772 }
1773
1774 //food stage states
1775 bool IsFoodRaw()
1776 {
1777 if (GetFoodStage())
1778 return GetFoodStage().IsFoodRaw();
1779
1780 return false;
1781 }
1782
1783 bool IsFoodBaked()
1784 {
1785 if (GetFoodStage())
1786 return GetFoodStage().IsFoodBaked();
1787
1788 return false;
1789 }
1790
1791 bool IsFoodBoiled()
1792 {
1793 if (GetFoodStage())
1794 return GetFoodStage().IsFoodBoiled();
1795
1796 return false;
1797 }
1798
1799 bool IsFoodDried()
1800 {
1801 if (GetFoodStage())
1802 return GetFoodStage().IsFoodDried();
1803
1804 return false;
1805 }
1806
1807 bool IsFoodBurned()
1808 {
1809 if (GetFoodStage())
1810 return GetFoodStage().IsFoodBurned();
1811
1812 return false;
1813 }
1814
1815 bool IsFoodRotten()
1816 {
1817 if (GetFoodStage())
1818 return GetFoodStage().IsFoodRotten();
1819
1820 return false;
1821 }
1822
1823 //food stage change
1825 {
1826 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1827 }
1828
1830 {
1831 return GetFoodStage().GetNextFoodStageType(cooking_method);
1832 }
1833
1835 {
1836 return GetFoodStage().GetFoodStageName(food_stage_type);
1837 }
1838
1840 {
1841 return GetFoodStage().CanChangeToNewStage(cooking_method);
1842 }
1843
1844 //Use this to receive food stage from another Edible_Base
1846 {
1847 if (!source.HasFoodStage())
1848 return;
1849 m_LastDecayStage = source.GetLastDecayStage();
1850 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1851 m_DecayTimer = source.GetDecayTimer();
1852 m_DecayDelta = source.GetDecayDelta();
1853 }
1854
1855 //================================================================
1856 // COOKING
1857 //================================================================
1858 //cooking time
1859 float GetCookingTime()
1860 {
1861 return GetFoodStage().GetCookingTime();
1862 }
1863
1864 void SetCookingTime(float time)
1865 {
1866 GetFoodStage().SetCookingTime(time);
1867
1868 //synchronize when calling on server
1869 Synchronize();
1870 }
1871
1872 //replace edible with new item (opening cans)
1873 void ReplaceEdibleWithNew(string typeName)
1874 {
1875 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1876 if (player)
1877 {
1879 player.ServerReplaceItemInHandsWithNew(lambda);
1880 }
1881 else
1882 Error("ReplaceEdibleWithNew - cannot use edible without player");
1883 }
1884
1885 override void SetActions()
1886 {
1887 super.SetActions();
1888
1889 AddAction(ActionAttach);
1891 }
1892
1893 protected void SoundCookingStart(string sound_name)
1894 {
1895#ifndef SERVER
1897 {
1899
1902 }
1903#endif
1904 }
1905
1906 protected void SoundCookingStop()
1907 {
1908#ifndef SERVER
1910 {
1913 m_SoundPlaying = "";
1914 }
1915#endif
1916 }
1917
1918 override bool CanHaveTemperature()
1919 {
1920 return true;
1921 }
1922
1923 override bool CanDecay()
1924 {
1925 return false;
1926 }
1927
1928 override bool CanProcessDecay()
1929 {
1930 return (GetFoodStageType() != FoodStageType.ROTTEN);
1931 }
1932
1933 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1934 {
1935 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1936 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1937 if (hasRootAsPlayer)
1939
1940 /*Print( "-------------------------" );
1941 Print( this );
1942 Print( m_DecayTimer );
1943 Print( m_DecayDelta );
1944 Print( m_LastDecayStage );*/
1945
1946 if (IsFruit() || IsMushroom())
1947 {
1948 // fruit, vegetables and mushrooms
1950 {
1951 switch (GetFoodStageType())
1952 {
1953 case FoodStageType.RAW:
1956 break;
1957
1958 case FoodStageType.BOILED:
1961 break;
1962
1963 case FoodStageType.BAKED:
1966 break;
1967
1968 case FoodStageType.DRIED:
1969 case FoodStageType.BURNED:
1970 case FoodStageType.ROTTEN:
1971 default:
1972 m_DecayTimer = -1;
1974 return;
1975 }
1976
1977 //m_DecayTimer = m_DecayTimer / 1000.0;
1978 }
1979
1981
1982 if (m_DecayTimer <= 0)
1983 {
1984 if (m_LastDecayStage != FoodStageType.NONE)
1985 {
1986 // switch to decayed stage
1987 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1990 {
1991 int rng = Math.RandomIntInclusive(0, 100);
1994 else
1995 {
1998 else
2000 }
2001 }
2002 }
2003 }
2004
2005 }
2006 else if (IsMeat())
2007 {
2008 // meat
2010 {
2011 switch (GetFoodStageType())
2012 {
2013 case FoodStageType.RAW:
2016 break;
2017
2018 case FoodStageType.BOILED:
2021 break;
2022
2023 case FoodStageType.BAKED:
2026 break;
2027
2028 case FoodStageType.DRIED:
2031 break;
2032
2033 case FoodStageType.BURNED:
2034 case FoodStageType.ROTTEN:
2035 default:
2036 m_DecayTimer = -1;
2038 return;
2039 }
2040 }
2041
2043
2044 if (m_DecayTimer <= 0)
2045 {
2046 if (m_LastDecayStage != FoodStageType.NONE)
2047 {
2048 // switch to decayed stage
2051 }
2052 }
2053 }
2054 else if (IsCorpse())
2055 {
2056 // corpse
2058 {
2059 switch (GetFoodStageType())
2060 {
2061 case FoodStageType.RAW:
2064 break;
2065
2066 case FoodStageType.BURNED:
2067 case FoodStageType.ROTTEN:
2068 default:
2069 m_DecayTimer = -1;
2071 return;
2072 }
2073 }
2074
2076
2077 if (m_DecayTimer <= 0)
2078 {
2079 if (m_LastDecayStage != FoodStageType.NONE)
2080 {
2081 // switch to decayed stage
2084 }
2085 }
2086 }
2087 else
2088 {
2089 // opened cans
2091
2092 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
2093 {
2096 //m_DecayTimer = m_DecayTimer / 1000.0;
2097 }
2098 else
2099 {
2100 if (m_DecayTimer <= 0)
2101 {
2102 InsertAgent(eAgents.FOOD_POISON, 1);
2103 m_DecayTimer = -1;
2104 }
2105 }
2106 }
2107
2108 m_DecayDelta = 0.0;
2109 }
2110
2112 {
2113 super.GetDebugActions(outputList);
2114
2115 if (HasFoodStage())
2116 {
2117 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
2118 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
2119 }
2120 }
2121
2122 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
2123 {
2124 super.OnAction(action_id, player, ctx);
2125
2126 if (GetGame().IsServer())
2127 {
2128 if (action_id == EActions.FOOD_STAGE_PREV)
2129 {
2131 if (food_stage_prev <= 0)
2132 food_stage_prev = FoodStageType.COUNT - 1;
2134 return true;
2135 }
2136 else if (action_id == EActions.FOOD_STAGE_NEXT)
2137 {
2139 if (food_stage_next >= FoodStageType.COUNT)
2142 return true;
2143 }
2144 }
2145 return false;
2146 }
2147
2148 override string GetDebugText()
2149 {
2150 string debug_output;
2151
2152 debug_output = super.GetDebugText();
2153
2154 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
2155 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
2156
2157 return debug_output;
2158 }
2159
2160 //================================================================
2161 // GENERAL GETTERS
2162 //================================================================
2163
2164 float GetDecayTimer()
2165 {
2166 return m_DecayTimer;
2167 }
2168
2169 float GetDecayDelta()
2170 {
2171 return m_DecayDelta;
2172 }
2173
2175 {
2176 return m_LastDecayStage;
2177 }
2178}
2179
2181{
2183};

◆ GetDebugText()

override string ReplaceEdibleWithNewLambda::GetDebugText ( )
protected

Definition at line 1468 of file Edible_Base.c.

1468 : ItemBase
1469{
1470 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1471
1472 const string SOUND_BAKING_START = "Baking_SoundSet";
1473 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1474 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1475
1476 protected bool m_MakeCookingSounds;
1477 protected SoundOnVehicle m_SoundCooking;
1479 protected string m_SoundPlaying;
1481 protected float m_DecayTimer;
1482 protected float m_DecayDelta = 0.0;
1484
1486
1487 void Edible_Base()
1488 {
1489 if (HasFoodStage())
1490 {
1491 m_FoodStage = new FoodStage(this);
1492
1493 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1494 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1495 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1496 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1497 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1498
1499 m_SoundPlaying = "";
1501 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1502 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1503 }
1504 }
1505
1506 override void EEInit()
1507 {
1508 super.EEInit();
1509
1510 UpdateVisuals();
1511 }
1512
1513 override void EEDelete(EntityAI parent)
1514 {
1515 super.EEDelete(parent);
1516
1517 RemoveAudio();
1518 }
1519
1521 {
1522 super.EEItemLocationChanged(oldLoc, newLoc);
1523
1525 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1526 {
1527 switch (oldLoc.GetParent().GetType())
1528 {
1529 case "FryingPan":
1530 case "Pot":
1531 case "Cauldron":
1532 case "SharpWoodenStick":
1533 MakeSoundsOnClient(false);
1534 break;
1535 }
1536
1538 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1539 MakeSoundsOnClient(false);
1540 }
1541 }
1542
1543 void UpdateVisuals()
1544 {
1545 if (GetFoodStage())
1546 GetFoodStage().UpdateVisuals();
1547 }
1548
1549 bool Consume(float amount, PlayerBase consumer)
1550 {
1551 AddQuantity(-amount, false, false);
1552 OnConsume(amount, consumer);
1553
1554 return true;
1555 }
1556
1557 void OnConsume(float amount, PlayerBase consumer);
1558
1559 //food staging
1560 override bool CanBeCooked()
1561 {
1562 return false;
1563 }
1564
1565 override bool CanBeCookedOnStick()
1566 {
1567 return false;
1568 }
1569
1570 //================================================================
1571 // SYNCHRONIZATION
1572 //================================================================
1573 void Synchronize()
1574 {
1575 SetSynchDirty();
1576
1577 if (GetGame().IsMultiplayer())
1578 UpdateVisuals();
1579 }
1580
1581 override void OnVariablesSynchronized()
1582 {
1583 super.OnVariablesSynchronized();
1584
1585 UpdateVisuals();
1586
1587 //update audio
1589 RefreshAudio();
1590 else
1591 RemoveAudio();
1592 }
1593
1594 //================================================================
1595 // AUDIO EFFECTS (WHEN ON DCS)
1596 //================================================================
1598 {
1601
1602 Synchronize();
1603 }
1604
1605 protected void RefreshAudio()
1606 {
1607 string soundName = "";
1608
1610
1611 switch (GetFoodStageType())
1612 {
1613 case FoodStageType.RAW:
1615 if (nextFoodState == FoodStageType.BOILED)
1616 soundName = "";
1617 break;
1618 case FoodStageType.BAKED:
1620 break;
1621 case FoodStageType.BURNED:
1623 break;
1624 default:
1625 soundName = "";
1626 break;
1627 }
1628
1630 }
1631
1632 protected void RemoveAudio()
1633 {
1634 m_MakeCookingSounds = false;
1636 }
1637
1638 //================================================================
1639 // SERIALIZATION
1640 //================================================================
1641 override void OnStoreSave(ParamsWriteContext ctx)
1642 {
1643 super.OnStoreSave(ctx);
1644
1645 if (GetFoodStage())
1646 GetFoodStage().OnStoreSave(ctx);
1647
1648 // food decay
1649 ctx.Write(m_DecayTimer);
1650 ctx.Write(m_LastDecayStage);
1651 }
1652
1653 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1654 {
1655 if (!super.OnStoreLoad(ctx, version))
1656 return false;
1657
1658 if (GetFoodStage())
1659 {
1660 if (!GetFoodStage().OnStoreLoad(ctx, version))
1661 return false;
1662 }
1663
1664 if (version >= 115)
1665 {
1666 if (!ctx.Read(m_DecayTimer))
1667 {
1668 m_DecayTimer = 0.0;
1669 return false;
1670 }
1671 if (!ctx.Read(m_LastDecayStage))
1672 {
1674 return false;
1675 }
1676 }
1677
1678 return true;
1679 }
1680
1681 override void AfterStoreLoad()
1682 {
1683 super.AfterStoreLoad();
1684
1685 Synchronize();
1686 }
1687
1688 //get food stage
1690 {
1691 return m_FoodStage;
1692 }
1693
1694 //food types
1695 override bool IsMeat()
1696 {
1697 return false;
1698 }
1699
1700 override bool IsCorpse()
1701 {
1702 return false;
1703 }
1704
1705 override bool IsFruit()
1706 {
1707 return false;
1708 }
1709
1710 override bool IsMushroom()
1711 {
1712 return false;
1713 }
1714
1715 //================================================================
1716 // NUTRITIONAL VALUES
1717 //================================================================
1718 //food properties
1719 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1720 {
1722 if (food_item && food_item.GetFoodStage())
1723 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1724 else if (classname != "" && food_stage)
1725 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1726 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1727 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1728
1729 }
1730
1731 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1732 {
1734 if (food_item && food_item.GetFoodStage())
1735 return FoodStage.GetEnergy(food_item.GetFoodStage());
1736 else if (classname != "" && food_stage)
1737 return FoodStage.GetEnergy(null, food_stage, classname);
1738 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1739 return GetGame().ConfigGetFloat(class_path + " energy");
1740 }
1741
1742 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1743 {
1745 if (food_item && food_item.GetFoodStage())
1746 return FoodStage.GetWater(food_item.GetFoodStage());
1747 else if (classname != "" && food_stage)
1748 return FoodStage.GetWater(null, food_stage, classname);
1749 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1750 return GetGame().ConfigGetFloat(class_path + " water");
1751 }
1752
1753 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1754 {
1756 if (food_item && food_item.GetFoodStage())
1757 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1758 else if (classname != "" && food_stage)
1759 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1760 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1761 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1762
1763 }
1764
1765 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1766 {
1768 if (food_item && food_item.GetFoodStage())
1769 return FoodStage.GetToxicity(food_item.GetFoodStage());
1770 else if (classname != "" && food_stage)
1771 return FoodStage.GetToxicity(null, food_stage, classname);
1772 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1773 return GetGame().ConfigGetFloat(class_path + " toxicity");
1774 }
1775
1776 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1777 {
1779 if (food_item && food_item.GetFoodStage())
1780 return FoodStage.GetAgents(food_item.GetFoodStage());
1781 else if (classname != "" && food_stage)
1782 return FoodStage.GetAgents(null, food_stage, classname);
1783 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1784 return GetGame().ConfigGetInt(class_path + " agents");
1785 }
1786
1787 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1788 {
1790 if (food_item && food_item.GetFoodStage())
1791 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1792 else if (classname != "" && food_stage)
1793 return FoodStage.GetDigestibility(null, food_stage, classname);
1794 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1795 return GetGame().ConfigGetInt(class_path + " digestibility");
1796 }
1797
1799 {
1801 }
1802
1803 //================================================================
1804 // FOOD STAGING
1805 //================================================================
1807 {
1808 return GetFoodStage().GetFoodStageType();
1809 }
1810
1811 //food stage states
1812 bool IsFoodRaw()
1813 {
1814 if (GetFoodStage())
1815 return GetFoodStage().IsFoodRaw();
1816
1817 return false;
1818 }
1819
1820 bool IsFoodBaked()
1821 {
1822 if (GetFoodStage())
1823 return GetFoodStage().IsFoodBaked();
1824
1825 return false;
1826 }
1827
1828 bool IsFoodBoiled()
1829 {
1830 if (GetFoodStage())
1831 return GetFoodStage().IsFoodBoiled();
1832
1833 return false;
1834 }
1835
1836 bool IsFoodDried()
1837 {
1838 if (GetFoodStage())
1839 return GetFoodStage().IsFoodDried();
1840
1841 return false;
1842 }
1843
1844 bool IsFoodBurned()
1845 {
1846 if (GetFoodStage())
1847 return GetFoodStage().IsFoodBurned();
1848
1849 return false;
1850 }
1851
1852 bool IsFoodRotten()
1853 {
1854 if (GetFoodStage())
1855 return GetFoodStage().IsFoodRotten();
1856
1857 return false;
1858 }
1859
1860 //food stage change
1862 {
1863 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1864 }
1865
1867 {
1868 return GetFoodStage().GetNextFoodStageType(cooking_method);
1869 }
1870
1872 {
1873 return GetFoodStage().GetFoodStageName(food_stage_type);
1874 }
1875
1877 {
1878 return GetFoodStage().CanChangeToNewStage(cooking_method);
1879 }
1880
1881 //Use this to receive food stage from another Edible_Base
1883 {
1884 if (!source.HasFoodStage())
1885 return;
1886 m_LastDecayStage = source.GetLastDecayStage();
1887 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1888 m_DecayTimer = source.GetDecayTimer();
1889 m_DecayDelta = source.GetDecayDelta();
1890 }
1891
1892 //================================================================
1893 // COOKING
1894 //================================================================
1895 //cooking time
1896 float GetCookingTime()
1897 {
1898 return GetFoodStage().GetCookingTime();
1899 }
1900
1901 void SetCookingTime(float time)
1902 {
1903 GetFoodStage().SetCookingTime(time);
1904
1905 //synchronize when calling on server
1906 Synchronize();
1907 }
1908
1909 //replace edible with new item (opening cans)
1910 void ReplaceEdibleWithNew(string typeName)
1911 {
1912 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1913 if (player)
1914 {
1916 player.ServerReplaceItemInHandsWithNew(lambda);
1917 }
1918 else
1919 Error("ReplaceEdibleWithNew - cannot use edible without player");
1920 }
1921
1922 override void SetActions()
1923 {
1924 super.SetActions();
1925
1926 AddAction(ActionAttach);
1928 }
1929
1930 protected void SoundCookingStart(string sound_name)
1931 {
1932#ifndef SERVER
1934 {
1936
1939 }
1940#endif
1941 }
1942
1943 protected void SoundCookingStop()
1944 {
1945#ifndef SERVER
1947 {
1950 m_SoundPlaying = "";
1951 }
1952#endif
1953 }
1954
1955 override bool CanHaveTemperature()
1956 {
1957 return true;
1958 }
1959
1960 override bool CanDecay()
1961 {
1962 return false;
1963 }
1964
1965 override bool CanProcessDecay()
1966 {
1967 return (GetFoodStageType() != FoodStageType.ROTTEN);
1968 }
1969
1970 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1971 {
1972 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1973 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1974 if (hasRootAsPlayer)
1976
1977 /*Print( "-------------------------" );
1978 Print( this );
1979 Print( m_DecayTimer );
1980 Print( m_DecayDelta );
1981 Print( m_LastDecayStage );*/
1982
1983 if (IsFruit() || IsMushroom())
1984 {
1985 // fruit, vegetables and mushrooms
1987 {
1988 switch (GetFoodStageType())
1989 {
1990 case FoodStageType.RAW:
1993 break;
1994
1995 case FoodStageType.BOILED:
1998 break;
1999
2000 case FoodStageType.BAKED:
2003 break;
2004
2005 case FoodStageType.DRIED:
2006 case FoodStageType.BURNED:
2007 case FoodStageType.ROTTEN:
2008 default:
2009 m_DecayTimer = -1;
2011 return;
2012 }
2013
2014 //m_DecayTimer = m_DecayTimer / 1000.0;
2015 }
2016
2018
2019 if (m_DecayTimer <= 0)
2020 {
2021 if (m_LastDecayStage != FoodStageType.NONE)
2022 {
2023 // switch to decayed stage
2024 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
2027 {
2028 int rng = Math.RandomIntInclusive(0, 100);
2031 else
2032 {
2035 else
2037 }
2038 }
2039 }
2040 }
2041
2042 }
2043 else if (IsMeat())
2044 {
2045 // meat
2047 {
2048 switch (GetFoodStageType())
2049 {
2050 case FoodStageType.RAW:
2053 break;
2054
2055 case FoodStageType.BOILED:
2058 break;
2059
2060 case FoodStageType.BAKED:
2063 break;
2064
2065 case FoodStageType.DRIED:
2068 break;
2069
2070 case FoodStageType.BURNED:
2071 case FoodStageType.ROTTEN:
2072 default:
2073 m_DecayTimer = -1;
2075 return;
2076 }
2077 }
2078
2080
2081 if (m_DecayTimer <= 0)
2082 {
2083 if (m_LastDecayStage != FoodStageType.NONE)
2084 {
2085 // switch to decayed stage
2088 }
2089 }
2090 }
2091 else if (IsCorpse())
2092 {
2093 // corpse
2095 {
2096 switch (GetFoodStageType())
2097 {
2098 case FoodStageType.RAW:
2101 break;
2102
2103 case FoodStageType.BURNED:
2104 case FoodStageType.ROTTEN:
2105 default:
2106 m_DecayTimer = -1;
2108 return;
2109 }
2110 }
2111
2113
2114 if (m_DecayTimer <= 0)
2115 {
2116 if (m_LastDecayStage != FoodStageType.NONE)
2117 {
2118 // switch to decayed stage
2121 }
2122 }
2123 }
2124 else
2125 {
2126 // opened cans
2128
2129 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
2130 {
2133 //m_DecayTimer = m_DecayTimer / 1000.0;
2134 }
2135 else
2136 {
2137 if (m_DecayTimer <= 0)
2138 {
2139 InsertAgent(eAgents.FOOD_POISON, 1);
2140 m_DecayTimer = -1;
2141 }
2142 }
2143 }
2144
2145 m_DecayDelta = 0.0;
2146 }
2147
2149 {
2150 super.GetDebugActions(outputList);
2151
2152 if (HasFoodStage())
2153 {
2154 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
2155 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
2156 }
2157 }
2158
2159 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
2160 {
2161 super.OnAction(action_id, player, ctx);
2162
2163 if (GetGame().IsServer())
2164 {
2165 if (action_id == EActions.FOOD_STAGE_PREV)
2166 {
2168 if (food_stage_prev <= 0)
2169 food_stage_prev = FoodStageType.COUNT - 1;
2171 return true;
2172 }
2173 else if (action_id == EActions.FOOD_STAGE_NEXT)
2174 {
2176 if (food_stage_next >= FoodStageType.COUNT)
2179 return true;
2180 }
2181 }
2182 return false;
2183 }
2184
2185 override string GetDebugText()
2186 {
2187 string debug_output;
2188
2189 debug_output = super.GetDebugText();
2190
2191 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
2192 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
2193
2194 return debug_output;
2195 }
2196
2197 //================================================================
2198 // GENERAL GETTERS
2199 //================================================================
2200
2201 float GetDecayTimer()
2202 {
2203 return m_DecayTimer;
2204 }
2205
2206 float GetDecayDelta()
2207 {
2208 return m_DecayDelta;
2209 }
2210
2212 {
2213 return m_LastDecayStage;
2214 }
2215}
2216
2218{
2220};

◆ GetDecayDelta()

float ReplaceEdibleWithNewLambda::GetDecayDelta ( )
protected

Definition at line 1489 of file Edible_Base.c.

1489 : ItemBase
1490{
1491 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1492
1493 const string SOUND_BAKING_START = "Baking_SoundSet";
1494 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1495 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1496
1497 protected bool m_MakeCookingSounds;
1498 protected SoundOnVehicle m_SoundCooking;
1500 protected string m_SoundPlaying;
1502 protected float m_DecayTimer;
1503 protected float m_DecayDelta = 0.0;
1505
1507
1508 void Edible_Base()
1509 {
1510 if (HasFoodStage())
1511 {
1512 m_FoodStage = new FoodStage(this);
1513
1514 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1515 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1516 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1517 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1518 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1519
1520 m_SoundPlaying = "";
1522 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1523 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1524 }
1525 }
1526
1527 override void EEInit()
1528 {
1529 super.EEInit();
1530
1531 UpdateVisuals();
1532 }
1533
1534 override void EEDelete(EntityAI parent)
1535 {
1536 super.EEDelete(parent);
1537
1538 RemoveAudio();
1539 }
1540
1542 {
1543 super.EEItemLocationChanged(oldLoc, newLoc);
1544
1546 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1547 {
1548 switch (oldLoc.GetParent().GetType())
1549 {
1550 case "FryingPan":
1551 case "Pot":
1552 case "Cauldron":
1553 case "SharpWoodenStick":
1554 MakeSoundsOnClient(false);
1555 break;
1556 }
1557
1559 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1560 MakeSoundsOnClient(false);
1561 }
1562 }
1563
1564 void UpdateVisuals()
1565 {
1566 if (GetFoodStage())
1567 GetFoodStage().UpdateVisuals();
1568 }
1569
1570 bool Consume(float amount, PlayerBase consumer)
1571 {
1572 AddQuantity(-amount, false, false);
1573 OnConsume(amount, consumer);
1574
1575 return true;
1576 }
1577
1578 void OnConsume(float amount, PlayerBase consumer);
1579
1580 //food staging
1581 override bool CanBeCooked()
1582 {
1583 return false;
1584 }
1585
1586 override bool CanBeCookedOnStick()
1587 {
1588 return false;
1589 }
1590
1591 //================================================================
1592 // SYNCHRONIZATION
1593 //================================================================
1594 void Synchronize()
1595 {
1596 SetSynchDirty();
1597
1598 if (GetGame().IsMultiplayer())
1599 UpdateVisuals();
1600 }
1601
1602 override void OnVariablesSynchronized()
1603 {
1604 super.OnVariablesSynchronized();
1605
1606 UpdateVisuals();
1607
1608 //update audio
1610 RefreshAudio();
1611 else
1612 RemoveAudio();
1613 }
1614
1615 //================================================================
1616 // AUDIO EFFECTS (WHEN ON DCS)
1617 //================================================================
1619 {
1622
1623 Synchronize();
1624 }
1625
1626 protected void RefreshAudio()
1627 {
1628 string soundName = "";
1629
1631
1632 switch (GetFoodStageType())
1633 {
1634 case FoodStageType.RAW:
1636 if (nextFoodState == FoodStageType.BOILED)
1637 soundName = "";
1638 break;
1639 case FoodStageType.BAKED:
1641 break;
1642 case FoodStageType.BURNED:
1644 break;
1645 default:
1646 soundName = "";
1647 break;
1648 }
1649
1651 }
1652
1653 protected void RemoveAudio()
1654 {
1655 m_MakeCookingSounds = false;
1657 }
1658
1659 //================================================================
1660 // SERIALIZATION
1661 //================================================================
1662 override void OnStoreSave(ParamsWriteContext ctx)
1663 {
1664 super.OnStoreSave(ctx);
1665
1666 if (GetFoodStage())
1667 GetFoodStage().OnStoreSave(ctx);
1668
1669 // food decay
1670 ctx.Write(m_DecayTimer);
1671 ctx.Write(m_LastDecayStage);
1672 }
1673
1674 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1675 {
1676 if (!super.OnStoreLoad(ctx, version))
1677 return false;
1678
1679 if (GetFoodStage())
1680 {
1681 if (!GetFoodStage().OnStoreLoad(ctx, version))
1682 return false;
1683 }
1684
1685 if (version >= 115)
1686 {
1687 if (!ctx.Read(m_DecayTimer))
1688 {
1689 m_DecayTimer = 0.0;
1690 return false;
1691 }
1692 if (!ctx.Read(m_LastDecayStage))
1693 {
1695 return false;
1696 }
1697 }
1698
1699 return true;
1700 }
1701
1702 override void AfterStoreLoad()
1703 {
1704 super.AfterStoreLoad();
1705
1706 Synchronize();
1707 }
1708
1709 //get food stage
1711 {
1712 return m_FoodStage;
1713 }
1714
1715 //food types
1716 override bool IsMeat()
1717 {
1718 return false;
1719 }
1720
1721 override bool IsCorpse()
1722 {
1723 return false;
1724 }
1725
1726 override bool IsFruit()
1727 {
1728 return false;
1729 }
1730
1731 override bool IsMushroom()
1732 {
1733 return false;
1734 }
1735
1736 //================================================================
1737 // NUTRITIONAL VALUES
1738 //================================================================
1739 //food properties
1740 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1741 {
1743 if (food_item && food_item.GetFoodStage())
1744 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1745 else if (classname != "" && food_stage)
1746 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1747 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1748 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1749
1750 }
1751
1752 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1753 {
1755 if (food_item && food_item.GetFoodStage())
1756 return FoodStage.GetEnergy(food_item.GetFoodStage());
1757 else if (classname != "" && food_stage)
1758 return FoodStage.GetEnergy(null, food_stage, classname);
1759 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1760 return GetGame().ConfigGetFloat(class_path + " energy");
1761 }
1762
1763 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1764 {
1766 if (food_item && food_item.GetFoodStage())
1767 return FoodStage.GetWater(food_item.GetFoodStage());
1768 else if (classname != "" && food_stage)
1769 return FoodStage.GetWater(null, food_stage, classname);
1770 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1771 return GetGame().ConfigGetFloat(class_path + " water");
1772 }
1773
1774 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1775 {
1777 if (food_item && food_item.GetFoodStage())
1778 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1779 else if (classname != "" && food_stage)
1780 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1781 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1782 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1783
1784 }
1785
1786 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1787 {
1789 if (food_item && food_item.GetFoodStage())
1790 return FoodStage.GetToxicity(food_item.GetFoodStage());
1791 else if (classname != "" && food_stage)
1792 return FoodStage.GetToxicity(null, food_stage, classname);
1793 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1794 return GetGame().ConfigGetFloat(class_path + " toxicity");
1795 }
1796
1797 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1798 {
1800 if (food_item && food_item.GetFoodStage())
1801 return FoodStage.GetAgents(food_item.GetFoodStage());
1802 else if (classname != "" && food_stage)
1803 return FoodStage.GetAgents(null, food_stage, classname);
1804 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1805 return GetGame().ConfigGetInt(class_path + " agents");
1806 }
1807
1808 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1809 {
1811 if (food_item && food_item.GetFoodStage())
1812 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1813 else if (classname != "" && food_stage)
1814 return FoodStage.GetDigestibility(null, food_stage, classname);
1815 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1816 return GetGame().ConfigGetInt(class_path + " digestibility");
1817 }
1818
1820 {
1822 }
1823
1824 //================================================================
1825 // FOOD STAGING
1826 //================================================================
1828 {
1829 return GetFoodStage().GetFoodStageType();
1830 }
1831
1832 //food stage states
1833 bool IsFoodRaw()
1834 {
1835 if (GetFoodStage())
1836 return GetFoodStage().IsFoodRaw();
1837
1838 return false;
1839 }
1840
1841 bool IsFoodBaked()
1842 {
1843 if (GetFoodStage())
1844 return GetFoodStage().IsFoodBaked();
1845
1846 return false;
1847 }
1848
1849 bool IsFoodBoiled()
1850 {
1851 if (GetFoodStage())
1852 return GetFoodStage().IsFoodBoiled();
1853
1854 return false;
1855 }
1856
1857 bool IsFoodDried()
1858 {
1859 if (GetFoodStage())
1860 return GetFoodStage().IsFoodDried();
1861
1862 return false;
1863 }
1864
1865 bool IsFoodBurned()
1866 {
1867 if (GetFoodStage())
1868 return GetFoodStage().IsFoodBurned();
1869
1870 return false;
1871 }
1872
1873 bool IsFoodRotten()
1874 {
1875 if (GetFoodStage())
1876 return GetFoodStage().IsFoodRotten();
1877
1878 return false;
1879 }
1880
1881 //food stage change
1883 {
1884 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1885 }
1886
1888 {
1889 return GetFoodStage().GetNextFoodStageType(cooking_method);
1890 }
1891
1893 {
1894 return GetFoodStage().GetFoodStageName(food_stage_type);
1895 }
1896
1898 {
1899 return GetFoodStage().CanChangeToNewStage(cooking_method);
1900 }
1901
1902 //Use this to receive food stage from another Edible_Base
1904 {
1905 if (!source.HasFoodStage())
1906 return;
1907 m_LastDecayStage = source.GetLastDecayStage();
1908 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1909 m_DecayTimer = source.GetDecayTimer();
1910 m_DecayDelta = source.GetDecayDelta();
1911 }
1912
1913 //================================================================
1914 // COOKING
1915 //================================================================
1916 //cooking time
1917 float GetCookingTime()
1918 {
1919 return GetFoodStage().GetCookingTime();
1920 }
1921
1922 void SetCookingTime(float time)
1923 {
1924 GetFoodStage().SetCookingTime(time);
1925
1926 //synchronize when calling on server
1927 Synchronize();
1928 }
1929
1930 //replace edible with new item (opening cans)
1931 void ReplaceEdibleWithNew(string typeName)
1932 {
1933 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1934 if (player)
1935 {
1937 player.ServerReplaceItemInHandsWithNew(lambda);
1938 }
1939 else
1940 Error("ReplaceEdibleWithNew - cannot use edible without player");
1941 }
1942
1943 override void SetActions()
1944 {
1945 super.SetActions();
1946
1947 AddAction(ActionAttach);
1949 }
1950
1951 protected void SoundCookingStart(string sound_name)
1952 {
1953#ifndef SERVER
1955 {
1957
1960 }
1961#endif
1962 }
1963
1964 protected void SoundCookingStop()
1965 {
1966#ifndef SERVER
1968 {
1971 m_SoundPlaying = "";
1972 }
1973#endif
1974 }
1975
1976 override bool CanHaveTemperature()
1977 {
1978 return true;
1979 }
1980
1981 override bool CanDecay()
1982 {
1983 return false;
1984 }
1985
1986 override bool CanProcessDecay()
1987 {
1988 return (GetFoodStageType() != FoodStageType.ROTTEN);
1989 }
1990
1991 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1992 {
1993 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1994 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1995 if (hasRootAsPlayer)
1997
1998 /*Print( "-------------------------" );
1999 Print( this );
2000 Print( m_DecayTimer );
2001 Print( m_DecayDelta );
2002 Print( m_LastDecayStage );*/
2003
2004 if (IsFruit() || IsMushroom())
2005 {
2006 // fruit, vegetables and mushrooms
2008 {
2009 switch (GetFoodStageType())
2010 {
2011 case FoodStageType.RAW:
2014 break;
2015
2016 case FoodStageType.BOILED:
2019 break;
2020
2021 case FoodStageType.BAKED:
2024 break;
2025
2026 case FoodStageType.DRIED:
2027 case FoodStageType.BURNED:
2028 case FoodStageType.ROTTEN:
2029 default:
2030 m_DecayTimer = -1;
2032 return;
2033 }
2034
2035 //m_DecayTimer = m_DecayTimer / 1000.0;
2036 }
2037
2039
2040 if (m_DecayTimer <= 0)
2041 {
2042 if (m_LastDecayStage != FoodStageType.NONE)
2043 {
2044 // switch to decayed stage
2045 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
2048 {
2049 int rng = Math.RandomIntInclusive(0, 100);
2052 else
2053 {
2056 else
2058 }
2059 }
2060 }
2061 }
2062
2063 }
2064 else if (IsMeat())
2065 {
2066 // meat
2068 {
2069 switch (GetFoodStageType())
2070 {
2071 case FoodStageType.RAW:
2074 break;
2075
2076 case FoodStageType.BOILED:
2079 break;
2080
2081 case FoodStageType.BAKED:
2084 break;
2085
2086 case FoodStageType.DRIED:
2089 break;
2090
2091 case FoodStageType.BURNED:
2092 case FoodStageType.ROTTEN:
2093 default:
2094 m_DecayTimer = -1;
2096 return;
2097 }
2098 }
2099
2101
2102 if (m_DecayTimer <= 0)
2103 {
2104 if (m_LastDecayStage != FoodStageType.NONE)
2105 {
2106 // switch to decayed stage
2109 }
2110 }
2111 }
2112 else if (IsCorpse())
2113 {
2114 // corpse
2116 {
2117 switch (GetFoodStageType())
2118 {
2119 case FoodStageType.RAW:
2122 break;
2123
2124 case FoodStageType.BURNED:
2125 case FoodStageType.ROTTEN:
2126 default:
2127 m_DecayTimer = -1;
2129 return;
2130 }
2131 }
2132
2134
2135 if (m_DecayTimer <= 0)
2136 {
2137 if (m_LastDecayStage != FoodStageType.NONE)
2138 {
2139 // switch to decayed stage
2142 }
2143 }
2144 }
2145 else
2146 {
2147 // opened cans
2149
2150 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
2151 {
2154 //m_DecayTimer = m_DecayTimer / 1000.0;
2155 }
2156 else
2157 {
2158 if (m_DecayTimer <= 0)
2159 {
2160 InsertAgent(eAgents.FOOD_POISON, 1);
2161 m_DecayTimer = -1;
2162 }
2163 }
2164 }
2165
2166 m_DecayDelta = 0.0;
2167 }
2168
2170 {
2171 super.GetDebugActions(outputList);
2172
2173 if (HasFoodStage())
2174 {
2175 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
2176 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
2177 }
2178 }
2179
2180 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
2181 {
2182 super.OnAction(action_id, player, ctx);
2183
2184 if (GetGame().IsServer())
2185 {
2186 if (action_id == EActions.FOOD_STAGE_PREV)
2187 {
2189 if (food_stage_prev <= 0)
2190 food_stage_prev = FoodStageType.COUNT - 1;
2192 return true;
2193 }
2194 else if (action_id == EActions.FOOD_STAGE_NEXT)
2195 {
2197 if (food_stage_next >= FoodStageType.COUNT)
2200 return true;
2201 }
2202 }
2203 return false;
2204 }
2205
2206 override string GetDebugText()
2207 {
2208 string debug_output;
2209
2210 debug_output = super.GetDebugText();
2211
2212 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
2213 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
2214
2215 return debug_output;
2216 }
2217
2218 //================================================================
2219 // GENERAL GETTERS
2220 //================================================================
2221
2222 float GetDecayTimer()
2223 {
2224 return m_DecayTimer;
2225 }
2226
2227 float GetDecayDelta()
2228 {
2229 return m_DecayDelta;
2230 }
2231
2233 {
2234 return m_LastDecayStage;
2235 }
2236}
2237
2239{
2241};

◆ GetDecayTimer()

float ReplaceEdibleWithNewLambda::GetDecayTimer ( )
protected

Definition at line 1484 of file Edible_Base.c.

1484 : ItemBase
1485{
1486 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1487
1488 const string SOUND_BAKING_START = "Baking_SoundSet";
1489 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1490 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1491
1492 protected bool m_MakeCookingSounds;
1493 protected SoundOnVehicle m_SoundCooking;
1495 protected string m_SoundPlaying;
1497 protected float m_DecayTimer;
1498 protected float m_DecayDelta = 0.0;
1500
1502
1503 void Edible_Base()
1504 {
1505 if (HasFoodStage())
1506 {
1507 m_FoodStage = new FoodStage(this);
1508
1509 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1510 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1511 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1512 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1513 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1514
1515 m_SoundPlaying = "";
1517 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1518 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1519 }
1520 }
1521
1522 override void EEInit()
1523 {
1524 super.EEInit();
1525
1526 UpdateVisuals();
1527 }
1528
1529 override void EEDelete(EntityAI parent)
1530 {
1531 super.EEDelete(parent);
1532
1533 RemoveAudio();
1534 }
1535
1537 {
1538 super.EEItemLocationChanged(oldLoc, newLoc);
1539
1541 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1542 {
1543 switch (oldLoc.GetParent().GetType())
1544 {
1545 case "FryingPan":
1546 case "Pot":
1547 case "Cauldron":
1548 case "SharpWoodenStick":
1549 MakeSoundsOnClient(false);
1550 break;
1551 }
1552
1554 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1555 MakeSoundsOnClient(false);
1556 }
1557 }
1558
1559 void UpdateVisuals()
1560 {
1561 if (GetFoodStage())
1562 GetFoodStage().UpdateVisuals();
1563 }
1564
1565 bool Consume(float amount, PlayerBase consumer)
1566 {
1567 AddQuantity(-amount, false, false);
1568 OnConsume(amount, consumer);
1569
1570 return true;
1571 }
1572
1573 void OnConsume(float amount, PlayerBase consumer);
1574
1575 //food staging
1576 override bool CanBeCooked()
1577 {
1578 return false;
1579 }
1580
1581 override bool CanBeCookedOnStick()
1582 {
1583 return false;
1584 }
1585
1586 //================================================================
1587 // SYNCHRONIZATION
1588 //================================================================
1589 void Synchronize()
1590 {
1591 SetSynchDirty();
1592
1593 if (GetGame().IsMultiplayer())
1594 UpdateVisuals();
1595 }
1596
1597 override void OnVariablesSynchronized()
1598 {
1599 super.OnVariablesSynchronized();
1600
1601 UpdateVisuals();
1602
1603 //update audio
1605 RefreshAudio();
1606 else
1607 RemoveAudio();
1608 }
1609
1610 //================================================================
1611 // AUDIO EFFECTS (WHEN ON DCS)
1612 //================================================================
1614 {
1617
1618 Synchronize();
1619 }
1620
1621 protected void RefreshAudio()
1622 {
1623 string soundName = "";
1624
1626
1627 switch (GetFoodStageType())
1628 {
1629 case FoodStageType.RAW:
1631 if (nextFoodState == FoodStageType.BOILED)
1632 soundName = "";
1633 break;
1634 case FoodStageType.BAKED:
1636 break;
1637 case FoodStageType.BURNED:
1639 break;
1640 default:
1641 soundName = "";
1642 break;
1643 }
1644
1646 }
1647
1648 protected void RemoveAudio()
1649 {
1650 m_MakeCookingSounds = false;
1652 }
1653
1654 //================================================================
1655 // SERIALIZATION
1656 //================================================================
1657 override void OnStoreSave(ParamsWriteContext ctx)
1658 {
1659 super.OnStoreSave(ctx);
1660
1661 if (GetFoodStage())
1662 GetFoodStage().OnStoreSave(ctx);
1663
1664 // food decay
1665 ctx.Write(m_DecayTimer);
1666 ctx.Write(m_LastDecayStage);
1667 }
1668
1669 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1670 {
1671 if (!super.OnStoreLoad(ctx, version))
1672 return false;
1673
1674 if (GetFoodStage())
1675 {
1676 if (!GetFoodStage().OnStoreLoad(ctx, version))
1677 return false;
1678 }
1679
1680 if (version >= 115)
1681 {
1682 if (!ctx.Read(m_DecayTimer))
1683 {
1684 m_DecayTimer = 0.0;
1685 return false;
1686 }
1687 if (!ctx.Read(m_LastDecayStage))
1688 {
1690 return false;
1691 }
1692 }
1693
1694 return true;
1695 }
1696
1697 override void AfterStoreLoad()
1698 {
1699 super.AfterStoreLoad();
1700
1701 Synchronize();
1702 }
1703
1704 //get food stage
1706 {
1707 return m_FoodStage;
1708 }
1709
1710 //food types
1711 override bool IsMeat()
1712 {
1713 return false;
1714 }
1715
1716 override bool IsCorpse()
1717 {
1718 return false;
1719 }
1720
1721 override bool IsFruit()
1722 {
1723 return false;
1724 }
1725
1726 override bool IsMushroom()
1727 {
1728 return false;
1729 }
1730
1731 //================================================================
1732 // NUTRITIONAL VALUES
1733 //================================================================
1734 //food properties
1735 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1736 {
1738 if (food_item && food_item.GetFoodStage())
1739 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1740 else if (classname != "" && food_stage)
1741 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1742 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1743 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1744
1745 }
1746
1747 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1748 {
1750 if (food_item && food_item.GetFoodStage())
1751 return FoodStage.GetEnergy(food_item.GetFoodStage());
1752 else if (classname != "" && food_stage)
1753 return FoodStage.GetEnergy(null, food_stage, classname);
1754 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1755 return GetGame().ConfigGetFloat(class_path + " energy");
1756 }
1757
1758 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1759 {
1761 if (food_item && food_item.GetFoodStage())
1762 return FoodStage.GetWater(food_item.GetFoodStage());
1763 else if (classname != "" && food_stage)
1764 return FoodStage.GetWater(null, food_stage, classname);
1765 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1766 return GetGame().ConfigGetFloat(class_path + " water");
1767 }
1768
1769 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1770 {
1772 if (food_item && food_item.GetFoodStage())
1773 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1774 else if (classname != "" && food_stage)
1775 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1776 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1777 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1778
1779 }
1780
1781 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1782 {
1784 if (food_item && food_item.GetFoodStage())
1785 return FoodStage.GetToxicity(food_item.GetFoodStage());
1786 else if (classname != "" && food_stage)
1787 return FoodStage.GetToxicity(null, food_stage, classname);
1788 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1789 return GetGame().ConfigGetFloat(class_path + " toxicity");
1790 }
1791
1792 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1793 {
1795 if (food_item && food_item.GetFoodStage())
1796 return FoodStage.GetAgents(food_item.GetFoodStage());
1797 else if (classname != "" && food_stage)
1798 return FoodStage.GetAgents(null, food_stage, classname);
1799 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1800 return GetGame().ConfigGetInt(class_path + " agents");
1801 }
1802
1803 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1804 {
1806 if (food_item && food_item.GetFoodStage())
1807 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1808 else if (classname != "" && food_stage)
1809 return FoodStage.GetDigestibility(null, food_stage, classname);
1810 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1811 return GetGame().ConfigGetInt(class_path + " digestibility");
1812 }
1813
1815 {
1817 }
1818
1819 //================================================================
1820 // FOOD STAGING
1821 //================================================================
1823 {
1824 return GetFoodStage().GetFoodStageType();
1825 }
1826
1827 //food stage states
1828 bool IsFoodRaw()
1829 {
1830 if (GetFoodStage())
1831 return GetFoodStage().IsFoodRaw();
1832
1833 return false;
1834 }
1835
1836 bool IsFoodBaked()
1837 {
1838 if (GetFoodStage())
1839 return GetFoodStage().IsFoodBaked();
1840
1841 return false;
1842 }
1843
1844 bool IsFoodBoiled()
1845 {
1846 if (GetFoodStage())
1847 return GetFoodStage().IsFoodBoiled();
1848
1849 return false;
1850 }
1851
1852 bool IsFoodDried()
1853 {
1854 if (GetFoodStage())
1855 return GetFoodStage().IsFoodDried();
1856
1857 return false;
1858 }
1859
1860 bool IsFoodBurned()
1861 {
1862 if (GetFoodStage())
1863 return GetFoodStage().IsFoodBurned();
1864
1865 return false;
1866 }
1867
1868 bool IsFoodRotten()
1869 {
1870 if (GetFoodStage())
1871 return GetFoodStage().IsFoodRotten();
1872
1873 return false;
1874 }
1875
1876 //food stage change
1878 {
1879 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1880 }
1881
1883 {
1884 return GetFoodStage().GetNextFoodStageType(cooking_method);
1885 }
1886
1888 {
1889 return GetFoodStage().GetFoodStageName(food_stage_type);
1890 }
1891
1893 {
1894 return GetFoodStage().CanChangeToNewStage(cooking_method);
1895 }
1896
1897 //Use this to receive food stage from another Edible_Base
1899 {
1900 if (!source.HasFoodStage())
1901 return;
1902 m_LastDecayStage = source.GetLastDecayStage();
1903 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1904 m_DecayTimer = source.GetDecayTimer();
1905 m_DecayDelta = source.GetDecayDelta();
1906 }
1907
1908 //================================================================
1909 // COOKING
1910 //================================================================
1911 //cooking time
1912 float GetCookingTime()
1913 {
1914 return GetFoodStage().GetCookingTime();
1915 }
1916
1917 void SetCookingTime(float time)
1918 {
1919 GetFoodStage().SetCookingTime(time);
1920
1921 //synchronize when calling on server
1922 Synchronize();
1923 }
1924
1925 //replace edible with new item (opening cans)
1926 void ReplaceEdibleWithNew(string typeName)
1927 {
1928 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1929 if (player)
1930 {
1932 player.ServerReplaceItemInHandsWithNew(lambda);
1933 }
1934 else
1935 Error("ReplaceEdibleWithNew - cannot use edible without player");
1936 }
1937
1938 override void SetActions()
1939 {
1940 super.SetActions();
1941
1942 AddAction(ActionAttach);
1944 }
1945
1946 protected void SoundCookingStart(string sound_name)
1947 {
1948#ifndef SERVER
1950 {
1952
1955 }
1956#endif
1957 }
1958
1959 protected void SoundCookingStop()
1960 {
1961#ifndef SERVER
1963 {
1966 m_SoundPlaying = "";
1967 }
1968#endif
1969 }
1970
1971 override bool CanHaveTemperature()
1972 {
1973 return true;
1974 }
1975
1976 override bool CanDecay()
1977 {
1978 return false;
1979 }
1980
1981 override bool CanProcessDecay()
1982 {
1983 return (GetFoodStageType() != FoodStageType.ROTTEN);
1984 }
1985
1986 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1987 {
1988 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1989 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1990 if (hasRootAsPlayer)
1992
1993 /*Print( "-------------------------" );
1994 Print( this );
1995 Print( m_DecayTimer );
1996 Print( m_DecayDelta );
1997 Print( m_LastDecayStage );*/
1998
1999 if (IsFruit() || IsMushroom())
2000 {
2001 // fruit, vegetables and mushrooms
2003 {
2004 switch (GetFoodStageType())
2005 {
2006 case FoodStageType.RAW:
2009 break;
2010
2011 case FoodStageType.BOILED:
2014 break;
2015
2016 case FoodStageType.BAKED:
2019 break;
2020
2021 case FoodStageType.DRIED:
2022 case FoodStageType.BURNED:
2023 case FoodStageType.ROTTEN:
2024 default:
2025 m_DecayTimer = -1;
2027 return;
2028 }
2029
2030 //m_DecayTimer = m_DecayTimer / 1000.0;
2031 }
2032
2034
2035 if (m_DecayTimer <= 0)
2036 {
2037 if (m_LastDecayStage != FoodStageType.NONE)
2038 {
2039 // switch to decayed stage
2040 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
2043 {
2044 int rng = Math.RandomIntInclusive(0, 100);
2047 else
2048 {
2051 else
2053 }
2054 }
2055 }
2056 }
2057
2058 }
2059 else if (IsMeat())
2060 {
2061 // meat
2063 {
2064 switch (GetFoodStageType())
2065 {
2066 case FoodStageType.RAW:
2069 break;
2070
2071 case FoodStageType.BOILED:
2074 break;
2075
2076 case FoodStageType.BAKED:
2079 break;
2080
2081 case FoodStageType.DRIED:
2084 break;
2085
2086 case FoodStageType.BURNED:
2087 case FoodStageType.ROTTEN:
2088 default:
2089 m_DecayTimer = -1;
2091 return;
2092 }
2093 }
2094
2096
2097 if (m_DecayTimer <= 0)
2098 {
2099 if (m_LastDecayStage != FoodStageType.NONE)
2100 {
2101 // switch to decayed stage
2104 }
2105 }
2106 }
2107 else if (IsCorpse())
2108 {
2109 // corpse
2111 {
2112 switch (GetFoodStageType())
2113 {
2114 case FoodStageType.RAW:
2117 break;
2118
2119 case FoodStageType.BURNED:
2120 case FoodStageType.ROTTEN:
2121 default:
2122 m_DecayTimer = -1;
2124 return;
2125 }
2126 }
2127
2129
2130 if (m_DecayTimer <= 0)
2131 {
2132 if (m_LastDecayStage != FoodStageType.NONE)
2133 {
2134 // switch to decayed stage
2137 }
2138 }
2139 }
2140 else
2141 {
2142 // opened cans
2144
2145 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
2146 {
2149 //m_DecayTimer = m_DecayTimer / 1000.0;
2150 }
2151 else
2152 {
2153 if (m_DecayTimer <= 0)
2154 {
2155 InsertAgent(eAgents.FOOD_POISON, 1);
2156 m_DecayTimer = -1;
2157 }
2158 }
2159 }
2160
2161 m_DecayDelta = 0.0;
2162 }
2163
2165 {
2166 super.GetDebugActions(outputList);
2167
2168 if (HasFoodStage())
2169 {
2170 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
2171 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
2172 }
2173 }
2174
2175 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
2176 {
2177 super.OnAction(action_id, player, ctx);
2178
2179 if (GetGame().IsServer())
2180 {
2181 if (action_id == EActions.FOOD_STAGE_PREV)
2182 {
2184 if (food_stage_prev <= 0)
2185 food_stage_prev = FoodStageType.COUNT - 1;
2187 return true;
2188 }
2189 else if (action_id == EActions.FOOD_STAGE_NEXT)
2190 {
2192 if (food_stage_next >= FoodStageType.COUNT)
2195 return true;
2196 }
2197 }
2198 return false;
2199 }
2200
2201 override string GetDebugText()
2202 {
2203 string debug_output;
2204
2205 debug_output = super.GetDebugText();
2206
2207 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
2208 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
2209
2210 return debug_output;
2211 }
2212
2213 //================================================================
2214 // GENERAL GETTERS
2215 //================================================================
2216
2217 float GetDecayTimer()
2218 {
2219 return m_DecayTimer;
2220 }
2221
2222 float GetDecayDelta()
2223 {
2224 return m_DecayDelta;
2225 }
2226
2228 {
2229 return m_LastDecayStage;
2230 }
2231}
2232
2234{
2236};

◆ GetFoodAgents()

static int ReplaceEdibleWithNewLambda::GetFoodAgents ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1059 of file Edible_Base.c.

1059 : ItemBase
1060{
1061 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1062
1063 const string SOUND_BAKING_START = "Baking_SoundSet";
1064 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1065 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1066
1067 protected bool m_MakeCookingSounds;
1068 protected SoundOnVehicle m_SoundCooking;
1070 protected string m_SoundPlaying;
1072 protected float m_DecayTimer;
1073 protected float m_DecayDelta = 0.0;
1075
1077
1078 void Edible_Base()
1079 {
1080 if (HasFoodStage())
1081 {
1082 m_FoodStage = new FoodStage(this);
1083
1084 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1085 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1086 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1087 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1088 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1089
1090 m_SoundPlaying = "";
1092 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1093 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1094 }
1095 }
1096
1097 override void EEInit()
1098 {
1099 super.EEInit();
1100
1101 UpdateVisuals();
1102 }
1103
1104 override void EEDelete(EntityAI parent)
1105 {
1106 super.EEDelete(parent);
1107
1108 RemoveAudio();
1109 }
1110
1112 {
1113 super.EEItemLocationChanged(oldLoc, newLoc);
1114
1116 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1117 {
1118 switch (oldLoc.GetParent().GetType())
1119 {
1120 case "FryingPan":
1121 case "Pot":
1122 case "Cauldron":
1123 case "SharpWoodenStick":
1124 MakeSoundsOnClient(false);
1125 break;
1126 }
1127
1129 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1130 MakeSoundsOnClient(false);
1131 }
1132 }
1133
1134 void UpdateVisuals()
1135 {
1136 if (GetFoodStage())
1137 GetFoodStage().UpdateVisuals();
1138 }
1139
1140 bool Consume(float amount, PlayerBase consumer)
1141 {
1142 AddQuantity(-amount, false, false);
1143 OnConsume(amount, consumer);
1144
1145 return true;
1146 }
1147
1148 void OnConsume(float amount, PlayerBase consumer);
1149
1150 //food staging
1151 override bool CanBeCooked()
1152 {
1153 return false;
1154 }
1155
1156 override bool CanBeCookedOnStick()
1157 {
1158 return false;
1159 }
1160
1161 //================================================================
1162 // SYNCHRONIZATION
1163 //================================================================
1164 void Synchronize()
1165 {
1166 SetSynchDirty();
1167
1168 if (GetGame().IsMultiplayer())
1169 UpdateVisuals();
1170 }
1171
1172 override void OnVariablesSynchronized()
1173 {
1174 super.OnVariablesSynchronized();
1175
1176 UpdateVisuals();
1177
1178 //update audio
1180 RefreshAudio();
1181 else
1182 RemoveAudio();
1183 }
1184
1185 //================================================================
1186 // AUDIO EFFECTS (WHEN ON DCS)
1187 //================================================================
1189 {
1192
1193 Synchronize();
1194 }
1195
1196 protected void RefreshAudio()
1197 {
1198 string soundName = "";
1199
1201
1202 switch (GetFoodStageType())
1203 {
1204 case FoodStageType.RAW:
1206 if (nextFoodState == FoodStageType.BOILED)
1207 soundName = "";
1208 break;
1209 case FoodStageType.BAKED:
1211 break;
1212 case FoodStageType.BURNED:
1214 break;
1215 default:
1216 soundName = "";
1217 break;
1218 }
1219
1221 }
1222
1223 protected void RemoveAudio()
1224 {
1225 m_MakeCookingSounds = false;
1227 }
1228
1229 //================================================================
1230 // SERIALIZATION
1231 //================================================================
1232 override void OnStoreSave(ParamsWriteContext ctx)
1233 {
1234 super.OnStoreSave(ctx);
1235
1236 if (GetFoodStage())
1237 GetFoodStage().OnStoreSave(ctx);
1238
1239 // food decay
1240 ctx.Write(m_DecayTimer);
1241 ctx.Write(m_LastDecayStage);
1242 }
1243
1244 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1245 {
1246 if (!super.OnStoreLoad(ctx, version))
1247 return false;
1248
1249 if (GetFoodStage())
1250 {
1251 if (!GetFoodStage().OnStoreLoad(ctx, version))
1252 return false;
1253 }
1254
1255 if (version >= 115)
1256 {
1257 if (!ctx.Read(m_DecayTimer))
1258 {
1259 m_DecayTimer = 0.0;
1260 return false;
1261 }
1262 if (!ctx.Read(m_LastDecayStage))
1263 {
1265 return false;
1266 }
1267 }
1268
1269 return true;
1270 }
1271
1272 override void AfterStoreLoad()
1273 {
1274 super.AfterStoreLoad();
1275
1276 Synchronize();
1277 }
1278
1279 //get food stage
1281 {
1282 return m_FoodStage;
1283 }
1284
1285 //food types
1286 override bool IsMeat()
1287 {
1288 return false;
1289 }
1290
1291 override bool IsCorpse()
1292 {
1293 return false;
1294 }
1295
1296 override bool IsFruit()
1297 {
1298 return false;
1299 }
1300
1301 override bool IsMushroom()
1302 {
1303 return false;
1304 }
1305
1306 //================================================================
1307 // NUTRITIONAL VALUES
1308 //================================================================
1309 //food properties
1310 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1311 {
1313 if (food_item && food_item.GetFoodStage())
1314 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1315 else if (classname != "" && food_stage)
1316 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1317 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1318 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1319
1320 }
1321
1322 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1323 {
1325 if (food_item && food_item.GetFoodStage())
1326 return FoodStage.GetEnergy(food_item.GetFoodStage());
1327 else if (classname != "" && food_stage)
1328 return FoodStage.GetEnergy(null, food_stage, classname);
1329 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1330 return GetGame().ConfigGetFloat(class_path + " energy");
1331 }
1332
1333 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1334 {
1336 if (food_item && food_item.GetFoodStage())
1337 return FoodStage.GetWater(food_item.GetFoodStage());
1338 else if (classname != "" && food_stage)
1339 return FoodStage.GetWater(null, food_stage, classname);
1340 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1341 return GetGame().ConfigGetFloat(class_path + " water");
1342 }
1343
1344 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1345 {
1347 if (food_item && food_item.GetFoodStage())
1348 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1349 else if (classname != "" && food_stage)
1350 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1351 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1352 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1353
1354 }
1355
1356 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1357 {
1359 if (food_item && food_item.GetFoodStage())
1360 return FoodStage.GetToxicity(food_item.GetFoodStage());
1361 else if (classname != "" && food_stage)
1362 return FoodStage.GetToxicity(null, food_stage, classname);
1363 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1364 return GetGame().ConfigGetFloat(class_path + " toxicity");
1365 }
1366
1367 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1368 {
1370 if (food_item && food_item.GetFoodStage())
1371 return FoodStage.GetAgents(food_item.GetFoodStage());
1372 else if (classname != "" && food_stage)
1373 return FoodStage.GetAgents(null, food_stage, classname);
1374 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1375 return GetGame().ConfigGetInt(class_path + " agents");
1376 }
1377
1378 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1379 {
1381 if (food_item && food_item.GetFoodStage())
1382 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1383 else if (classname != "" && food_stage)
1384 return FoodStage.GetDigestibility(null, food_stage, classname);
1385 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1386 return GetGame().ConfigGetInt(class_path + " digestibility");
1387 }
1388
1390 {
1392 }
1393
1394 //================================================================
1395 // FOOD STAGING
1396 //================================================================
1398 {
1399 return GetFoodStage().GetFoodStageType();
1400 }
1401
1402 //food stage states
1403 bool IsFoodRaw()
1404 {
1405 if (GetFoodStage())
1406 return GetFoodStage().IsFoodRaw();
1407
1408 return false;
1409 }
1410
1411 bool IsFoodBaked()
1412 {
1413 if (GetFoodStage())
1414 return GetFoodStage().IsFoodBaked();
1415
1416 return false;
1417 }
1418
1419 bool IsFoodBoiled()
1420 {
1421 if (GetFoodStage())
1422 return GetFoodStage().IsFoodBoiled();
1423
1424 return false;
1425 }
1426
1427 bool IsFoodDried()
1428 {
1429 if (GetFoodStage())
1430 return GetFoodStage().IsFoodDried();
1431
1432 return false;
1433 }
1434
1435 bool IsFoodBurned()
1436 {
1437 if (GetFoodStage())
1438 return GetFoodStage().IsFoodBurned();
1439
1440 return false;
1441 }
1442
1443 bool IsFoodRotten()
1444 {
1445 if (GetFoodStage())
1446 return GetFoodStage().IsFoodRotten();
1447
1448 return false;
1449 }
1450
1451 //food stage change
1453 {
1454 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1455 }
1456
1458 {
1459 return GetFoodStage().GetNextFoodStageType(cooking_method);
1460 }
1461
1463 {
1464 return GetFoodStage().GetFoodStageName(food_stage_type);
1465 }
1466
1468 {
1469 return GetFoodStage().CanChangeToNewStage(cooking_method);
1470 }
1471
1472 //Use this to receive food stage from another Edible_Base
1474 {
1475 if (!source.HasFoodStage())
1476 return;
1477 m_LastDecayStage = source.GetLastDecayStage();
1478 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1479 m_DecayTimer = source.GetDecayTimer();
1480 m_DecayDelta = source.GetDecayDelta();
1481 }
1482
1483 //================================================================
1484 // COOKING
1485 //================================================================
1486 //cooking time
1487 float GetCookingTime()
1488 {
1489 return GetFoodStage().GetCookingTime();
1490 }
1491
1492 void SetCookingTime(float time)
1493 {
1494 GetFoodStage().SetCookingTime(time);
1495
1496 //synchronize when calling on server
1497 Synchronize();
1498 }
1499
1500 //replace edible with new item (opening cans)
1501 void ReplaceEdibleWithNew(string typeName)
1502 {
1503 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1504 if (player)
1505 {
1507 player.ServerReplaceItemInHandsWithNew(lambda);
1508 }
1509 else
1510 Error("ReplaceEdibleWithNew - cannot use edible without player");
1511 }
1512
1513 override void SetActions()
1514 {
1515 super.SetActions();
1516
1517 AddAction(ActionAttach);
1519 }
1520
1521 protected void SoundCookingStart(string sound_name)
1522 {
1523#ifndef SERVER
1525 {
1527
1530 }
1531#endif
1532 }
1533
1534 protected void SoundCookingStop()
1535 {
1536#ifndef SERVER
1538 {
1541 m_SoundPlaying = "";
1542 }
1543#endif
1544 }
1545
1546 override bool CanHaveTemperature()
1547 {
1548 return true;
1549 }
1550
1551 override bool CanDecay()
1552 {
1553 return false;
1554 }
1555
1556 override bool CanProcessDecay()
1557 {
1558 return (GetFoodStageType() != FoodStageType.ROTTEN);
1559 }
1560
1561 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1562 {
1563 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1564 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1565 if (hasRootAsPlayer)
1567
1568 /*Print( "-------------------------" );
1569 Print( this );
1570 Print( m_DecayTimer );
1571 Print( m_DecayDelta );
1572 Print( m_LastDecayStage );*/
1573
1574 if (IsFruit() || IsMushroom())
1575 {
1576 // fruit, vegetables and mushrooms
1578 {
1579 switch (GetFoodStageType())
1580 {
1581 case FoodStageType.RAW:
1584 break;
1585
1586 case FoodStageType.BOILED:
1589 break;
1590
1591 case FoodStageType.BAKED:
1594 break;
1595
1596 case FoodStageType.DRIED:
1597 case FoodStageType.BURNED:
1598 case FoodStageType.ROTTEN:
1599 default:
1600 m_DecayTimer = -1;
1602 return;
1603 }
1604
1605 //m_DecayTimer = m_DecayTimer / 1000.0;
1606 }
1607
1609
1610 if (m_DecayTimer <= 0)
1611 {
1612 if (m_LastDecayStage != FoodStageType.NONE)
1613 {
1614 // switch to decayed stage
1615 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1618 {
1619 int rng = Math.RandomIntInclusive(0, 100);
1622 else
1623 {
1626 else
1628 }
1629 }
1630 }
1631 }
1632
1633 }
1634 else if (IsMeat())
1635 {
1636 // meat
1638 {
1639 switch (GetFoodStageType())
1640 {
1641 case FoodStageType.RAW:
1644 break;
1645
1646 case FoodStageType.BOILED:
1649 break;
1650
1651 case FoodStageType.BAKED:
1654 break;
1655
1656 case FoodStageType.DRIED:
1659 break;
1660
1661 case FoodStageType.BURNED:
1662 case FoodStageType.ROTTEN:
1663 default:
1664 m_DecayTimer = -1;
1666 return;
1667 }
1668 }
1669
1671
1672 if (m_DecayTimer <= 0)
1673 {
1674 if (m_LastDecayStage != FoodStageType.NONE)
1675 {
1676 // switch to decayed stage
1679 }
1680 }
1681 }
1682 else if (IsCorpse())
1683 {
1684 // corpse
1686 {
1687 switch (GetFoodStageType())
1688 {
1689 case FoodStageType.RAW:
1692 break;
1693
1694 case FoodStageType.BURNED:
1695 case FoodStageType.ROTTEN:
1696 default:
1697 m_DecayTimer = -1;
1699 return;
1700 }
1701 }
1702
1704
1705 if (m_DecayTimer <= 0)
1706 {
1707 if (m_LastDecayStage != FoodStageType.NONE)
1708 {
1709 // switch to decayed stage
1712 }
1713 }
1714 }
1715 else
1716 {
1717 // opened cans
1719
1720 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1721 {
1724 //m_DecayTimer = m_DecayTimer / 1000.0;
1725 }
1726 else
1727 {
1728 if (m_DecayTimer <= 0)
1729 {
1730 InsertAgent(eAgents.FOOD_POISON, 1);
1731 m_DecayTimer = -1;
1732 }
1733 }
1734 }
1735
1736 m_DecayDelta = 0.0;
1737 }
1738
1740 {
1741 super.GetDebugActions(outputList);
1742
1743 if (HasFoodStage())
1744 {
1745 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1746 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1747 }
1748 }
1749
1750 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1751 {
1752 super.OnAction(action_id, player, ctx);
1753
1754 if (GetGame().IsServer())
1755 {
1756 if (action_id == EActions.FOOD_STAGE_PREV)
1757 {
1759 if (food_stage_prev <= 0)
1760 food_stage_prev = FoodStageType.COUNT - 1;
1762 return true;
1763 }
1764 else if (action_id == EActions.FOOD_STAGE_NEXT)
1765 {
1767 if (food_stage_next >= FoodStageType.COUNT)
1770 return true;
1771 }
1772 }
1773 return false;
1774 }
1775
1776 override string GetDebugText()
1777 {
1778 string debug_output;
1779
1780 debug_output = super.GetDebugText();
1781
1782 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1783 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1784
1785 return debug_output;
1786 }
1787
1788 //================================================================
1789 // GENERAL GETTERS
1790 //================================================================
1791
1792 float GetDecayTimer()
1793 {
1794 return m_DecayTimer;
1795 }
1796
1797 float GetDecayDelta()
1798 {
1799 return m_DecayDelta;
1800 }
1801
1803 {
1804 return m_LastDecayStage;
1805 }
1806}
1807
1809{
1811};

◆ GetFoodDigestibility()

static float ReplaceEdibleWithNewLambda::GetFoodDigestibility ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1070 of file Edible_Base.c.

1070 : ItemBase
1071{
1072 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1073
1074 const string SOUND_BAKING_START = "Baking_SoundSet";
1075 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1076 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1077
1078 protected bool m_MakeCookingSounds;
1079 protected SoundOnVehicle m_SoundCooking;
1081 protected string m_SoundPlaying;
1083 protected float m_DecayTimer;
1084 protected float m_DecayDelta = 0.0;
1086
1088
1089 void Edible_Base()
1090 {
1091 if (HasFoodStage())
1092 {
1093 m_FoodStage = new FoodStage(this);
1094
1095 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1096 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1097 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1098 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1099 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1100
1101 m_SoundPlaying = "";
1103 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1104 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1105 }
1106 }
1107
1108 override void EEInit()
1109 {
1110 super.EEInit();
1111
1112 UpdateVisuals();
1113 }
1114
1115 override void EEDelete(EntityAI parent)
1116 {
1117 super.EEDelete(parent);
1118
1119 RemoveAudio();
1120 }
1121
1123 {
1124 super.EEItemLocationChanged(oldLoc, newLoc);
1125
1127 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1128 {
1129 switch (oldLoc.GetParent().GetType())
1130 {
1131 case "FryingPan":
1132 case "Pot":
1133 case "Cauldron":
1134 case "SharpWoodenStick":
1135 MakeSoundsOnClient(false);
1136 break;
1137 }
1138
1140 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1141 MakeSoundsOnClient(false);
1142 }
1143 }
1144
1145 void UpdateVisuals()
1146 {
1147 if (GetFoodStage())
1148 GetFoodStage().UpdateVisuals();
1149 }
1150
1151 bool Consume(float amount, PlayerBase consumer)
1152 {
1153 AddQuantity(-amount, false, false);
1154 OnConsume(amount, consumer);
1155
1156 return true;
1157 }
1158
1159 void OnConsume(float amount, PlayerBase consumer);
1160
1161 //food staging
1162 override bool CanBeCooked()
1163 {
1164 return false;
1165 }
1166
1167 override bool CanBeCookedOnStick()
1168 {
1169 return false;
1170 }
1171
1172 //================================================================
1173 // SYNCHRONIZATION
1174 //================================================================
1175 void Synchronize()
1176 {
1177 SetSynchDirty();
1178
1179 if (GetGame().IsMultiplayer())
1180 UpdateVisuals();
1181 }
1182
1183 override void OnVariablesSynchronized()
1184 {
1185 super.OnVariablesSynchronized();
1186
1187 UpdateVisuals();
1188
1189 //update audio
1191 RefreshAudio();
1192 else
1193 RemoveAudio();
1194 }
1195
1196 //================================================================
1197 // AUDIO EFFECTS (WHEN ON DCS)
1198 //================================================================
1200 {
1203
1204 Synchronize();
1205 }
1206
1207 protected void RefreshAudio()
1208 {
1209 string soundName = "";
1210
1212
1213 switch (GetFoodStageType())
1214 {
1215 case FoodStageType.RAW:
1217 if (nextFoodState == FoodStageType.BOILED)
1218 soundName = "";
1219 break;
1220 case FoodStageType.BAKED:
1222 break;
1223 case FoodStageType.BURNED:
1225 break;
1226 default:
1227 soundName = "";
1228 break;
1229 }
1230
1232 }
1233
1234 protected void RemoveAudio()
1235 {
1236 m_MakeCookingSounds = false;
1238 }
1239
1240 //================================================================
1241 // SERIALIZATION
1242 //================================================================
1243 override void OnStoreSave(ParamsWriteContext ctx)
1244 {
1245 super.OnStoreSave(ctx);
1246
1247 if (GetFoodStage())
1248 GetFoodStage().OnStoreSave(ctx);
1249
1250 // food decay
1251 ctx.Write(m_DecayTimer);
1252 ctx.Write(m_LastDecayStage);
1253 }
1254
1255 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1256 {
1257 if (!super.OnStoreLoad(ctx, version))
1258 return false;
1259
1260 if (GetFoodStage())
1261 {
1262 if (!GetFoodStage().OnStoreLoad(ctx, version))
1263 return false;
1264 }
1265
1266 if (version >= 115)
1267 {
1268 if (!ctx.Read(m_DecayTimer))
1269 {
1270 m_DecayTimer = 0.0;
1271 return false;
1272 }
1273 if (!ctx.Read(m_LastDecayStage))
1274 {
1276 return false;
1277 }
1278 }
1279
1280 return true;
1281 }
1282
1283 override void AfterStoreLoad()
1284 {
1285 super.AfterStoreLoad();
1286
1287 Synchronize();
1288 }
1289
1290 //get food stage
1292 {
1293 return m_FoodStage;
1294 }
1295
1296 //food types
1297 override bool IsMeat()
1298 {
1299 return false;
1300 }
1301
1302 override bool IsCorpse()
1303 {
1304 return false;
1305 }
1306
1307 override bool IsFruit()
1308 {
1309 return false;
1310 }
1311
1312 override bool IsMushroom()
1313 {
1314 return false;
1315 }
1316
1317 //================================================================
1318 // NUTRITIONAL VALUES
1319 //================================================================
1320 //food properties
1321 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1322 {
1324 if (food_item && food_item.GetFoodStage())
1325 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1326 else if (classname != "" && food_stage)
1327 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1328 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1329 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1330
1331 }
1332
1333 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1334 {
1336 if (food_item && food_item.GetFoodStage())
1337 return FoodStage.GetEnergy(food_item.GetFoodStage());
1338 else if (classname != "" && food_stage)
1339 return FoodStage.GetEnergy(null, food_stage, classname);
1340 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1341 return GetGame().ConfigGetFloat(class_path + " energy");
1342 }
1343
1344 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1345 {
1347 if (food_item && food_item.GetFoodStage())
1348 return FoodStage.GetWater(food_item.GetFoodStage());
1349 else if (classname != "" && food_stage)
1350 return FoodStage.GetWater(null, food_stage, classname);
1351 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1352 return GetGame().ConfigGetFloat(class_path + " water");
1353 }
1354
1355 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1356 {
1358 if (food_item && food_item.GetFoodStage())
1359 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1360 else if (classname != "" && food_stage)
1361 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1362 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1363 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1364
1365 }
1366
1367 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1368 {
1370 if (food_item && food_item.GetFoodStage())
1371 return FoodStage.GetToxicity(food_item.GetFoodStage());
1372 else if (classname != "" && food_stage)
1373 return FoodStage.GetToxicity(null, food_stage, classname);
1374 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1375 return GetGame().ConfigGetFloat(class_path + " toxicity");
1376 }
1377
1378 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1379 {
1381 if (food_item && food_item.GetFoodStage())
1382 return FoodStage.GetAgents(food_item.GetFoodStage());
1383 else if (classname != "" && food_stage)
1384 return FoodStage.GetAgents(null, food_stage, classname);
1385 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1386 return GetGame().ConfigGetInt(class_path + " agents");
1387 }
1388
1389 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1390 {
1392 if (food_item && food_item.GetFoodStage())
1393 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1394 else if (classname != "" && food_stage)
1395 return FoodStage.GetDigestibility(null, food_stage, classname);
1396 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1397 return GetGame().ConfigGetInt(class_path + " digestibility");
1398 }
1399
1401 {
1403 }
1404
1405 //================================================================
1406 // FOOD STAGING
1407 //================================================================
1409 {
1410 return GetFoodStage().GetFoodStageType();
1411 }
1412
1413 //food stage states
1414 bool IsFoodRaw()
1415 {
1416 if (GetFoodStage())
1417 return GetFoodStage().IsFoodRaw();
1418
1419 return false;
1420 }
1421
1422 bool IsFoodBaked()
1423 {
1424 if (GetFoodStage())
1425 return GetFoodStage().IsFoodBaked();
1426
1427 return false;
1428 }
1429
1430 bool IsFoodBoiled()
1431 {
1432 if (GetFoodStage())
1433 return GetFoodStage().IsFoodBoiled();
1434
1435 return false;
1436 }
1437
1438 bool IsFoodDried()
1439 {
1440 if (GetFoodStage())
1441 return GetFoodStage().IsFoodDried();
1442
1443 return false;
1444 }
1445
1446 bool IsFoodBurned()
1447 {
1448 if (GetFoodStage())
1449 return GetFoodStage().IsFoodBurned();
1450
1451 return false;
1452 }
1453
1454 bool IsFoodRotten()
1455 {
1456 if (GetFoodStage())
1457 return GetFoodStage().IsFoodRotten();
1458
1459 return false;
1460 }
1461
1462 //food stage change
1464 {
1465 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1466 }
1467
1469 {
1470 return GetFoodStage().GetNextFoodStageType(cooking_method);
1471 }
1472
1474 {
1475 return GetFoodStage().GetFoodStageName(food_stage_type);
1476 }
1477
1479 {
1480 return GetFoodStage().CanChangeToNewStage(cooking_method);
1481 }
1482
1483 //Use this to receive food stage from another Edible_Base
1485 {
1486 if (!source.HasFoodStage())
1487 return;
1488 m_LastDecayStage = source.GetLastDecayStage();
1489 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1490 m_DecayTimer = source.GetDecayTimer();
1491 m_DecayDelta = source.GetDecayDelta();
1492 }
1493
1494 //================================================================
1495 // COOKING
1496 //================================================================
1497 //cooking time
1498 float GetCookingTime()
1499 {
1500 return GetFoodStage().GetCookingTime();
1501 }
1502
1503 void SetCookingTime(float time)
1504 {
1505 GetFoodStage().SetCookingTime(time);
1506
1507 //synchronize when calling on server
1508 Synchronize();
1509 }
1510
1511 //replace edible with new item (opening cans)
1512 void ReplaceEdibleWithNew(string typeName)
1513 {
1514 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1515 if (player)
1516 {
1518 player.ServerReplaceItemInHandsWithNew(lambda);
1519 }
1520 else
1521 Error("ReplaceEdibleWithNew - cannot use edible without player");
1522 }
1523
1524 override void SetActions()
1525 {
1526 super.SetActions();
1527
1528 AddAction(ActionAttach);
1530 }
1531
1532 protected void SoundCookingStart(string sound_name)
1533 {
1534#ifndef SERVER
1536 {
1538
1541 }
1542#endif
1543 }
1544
1545 protected void SoundCookingStop()
1546 {
1547#ifndef SERVER
1549 {
1552 m_SoundPlaying = "";
1553 }
1554#endif
1555 }
1556
1557 override bool CanHaveTemperature()
1558 {
1559 return true;
1560 }
1561
1562 override bool CanDecay()
1563 {
1564 return false;
1565 }
1566
1567 override bool CanProcessDecay()
1568 {
1569 return (GetFoodStageType() != FoodStageType.ROTTEN);
1570 }
1571
1572 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1573 {
1574 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1575 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1576 if (hasRootAsPlayer)
1578
1579 /*Print( "-------------------------" );
1580 Print( this );
1581 Print( m_DecayTimer );
1582 Print( m_DecayDelta );
1583 Print( m_LastDecayStage );*/
1584
1585 if (IsFruit() || IsMushroom())
1586 {
1587 // fruit, vegetables and mushrooms
1589 {
1590 switch (GetFoodStageType())
1591 {
1592 case FoodStageType.RAW:
1595 break;
1596
1597 case FoodStageType.BOILED:
1600 break;
1601
1602 case FoodStageType.BAKED:
1605 break;
1606
1607 case FoodStageType.DRIED:
1608 case FoodStageType.BURNED:
1609 case FoodStageType.ROTTEN:
1610 default:
1611 m_DecayTimer = -1;
1613 return;
1614 }
1615
1616 //m_DecayTimer = m_DecayTimer / 1000.0;
1617 }
1618
1620
1621 if (m_DecayTimer <= 0)
1622 {
1623 if (m_LastDecayStage != FoodStageType.NONE)
1624 {
1625 // switch to decayed stage
1626 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1629 {
1630 int rng = Math.RandomIntInclusive(0, 100);
1633 else
1634 {
1637 else
1639 }
1640 }
1641 }
1642 }
1643
1644 }
1645 else if (IsMeat())
1646 {
1647 // meat
1649 {
1650 switch (GetFoodStageType())
1651 {
1652 case FoodStageType.RAW:
1655 break;
1656
1657 case FoodStageType.BOILED:
1660 break;
1661
1662 case FoodStageType.BAKED:
1665 break;
1666
1667 case FoodStageType.DRIED:
1670 break;
1671
1672 case FoodStageType.BURNED:
1673 case FoodStageType.ROTTEN:
1674 default:
1675 m_DecayTimer = -1;
1677 return;
1678 }
1679 }
1680
1682
1683 if (m_DecayTimer <= 0)
1684 {
1685 if (m_LastDecayStage != FoodStageType.NONE)
1686 {
1687 // switch to decayed stage
1690 }
1691 }
1692 }
1693 else if (IsCorpse())
1694 {
1695 // corpse
1697 {
1698 switch (GetFoodStageType())
1699 {
1700 case FoodStageType.RAW:
1703 break;
1704
1705 case FoodStageType.BURNED:
1706 case FoodStageType.ROTTEN:
1707 default:
1708 m_DecayTimer = -1;
1710 return;
1711 }
1712 }
1713
1715
1716 if (m_DecayTimer <= 0)
1717 {
1718 if (m_LastDecayStage != FoodStageType.NONE)
1719 {
1720 // switch to decayed stage
1723 }
1724 }
1725 }
1726 else
1727 {
1728 // opened cans
1730
1731 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1732 {
1735 //m_DecayTimer = m_DecayTimer / 1000.0;
1736 }
1737 else
1738 {
1739 if (m_DecayTimer <= 0)
1740 {
1741 InsertAgent(eAgents.FOOD_POISON, 1);
1742 m_DecayTimer = -1;
1743 }
1744 }
1745 }
1746
1747 m_DecayDelta = 0.0;
1748 }
1749
1751 {
1752 super.GetDebugActions(outputList);
1753
1754 if (HasFoodStage())
1755 {
1756 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1757 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1758 }
1759 }
1760
1761 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1762 {
1763 super.OnAction(action_id, player, ctx);
1764
1765 if (GetGame().IsServer())
1766 {
1767 if (action_id == EActions.FOOD_STAGE_PREV)
1768 {
1770 if (food_stage_prev <= 0)
1771 food_stage_prev = FoodStageType.COUNT - 1;
1773 return true;
1774 }
1775 else if (action_id == EActions.FOOD_STAGE_NEXT)
1776 {
1778 if (food_stage_next >= FoodStageType.COUNT)
1781 return true;
1782 }
1783 }
1784 return false;
1785 }
1786
1787 override string GetDebugText()
1788 {
1789 string debug_output;
1790
1791 debug_output = super.GetDebugText();
1792
1793 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1794 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1795
1796 return debug_output;
1797 }
1798
1799 //================================================================
1800 // GENERAL GETTERS
1801 //================================================================
1802
1803 float GetDecayTimer()
1804 {
1805 return m_DecayTimer;
1806 }
1807
1808 float GetDecayDelta()
1809 {
1810 return m_DecayDelta;
1811 }
1812
1814 {
1815 return m_LastDecayStage;
1816 }
1817}
1818
1820{
1822};

◆ GetFoodEnergy()

static float ReplaceEdibleWithNewLambda::GetFoodEnergy ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1014 of file Edible_Base.c.

1014 : ItemBase
1015{
1016 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1017
1018 const string SOUND_BAKING_START = "Baking_SoundSet";
1019 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1020 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1021
1022 protected bool m_MakeCookingSounds;
1023 protected SoundOnVehicle m_SoundCooking;
1025 protected string m_SoundPlaying;
1027 protected float m_DecayTimer;
1028 protected float m_DecayDelta = 0.0;
1030
1032
1033 void Edible_Base()
1034 {
1035 if (HasFoodStage())
1036 {
1037 m_FoodStage = new FoodStage(this);
1038
1039 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1040 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1041 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1042 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1043 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1044
1045 m_SoundPlaying = "";
1047 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1048 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1049 }
1050 }
1051
1052 override void EEInit()
1053 {
1054 super.EEInit();
1055
1056 UpdateVisuals();
1057 }
1058
1059 override void EEDelete(EntityAI parent)
1060 {
1061 super.EEDelete(parent);
1062
1063 RemoveAudio();
1064 }
1065
1067 {
1068 super.EEItemLocationChanged(oldLoc, newLoc);
1069
1071 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1072 {
1073 switch (oldLoc.GetParent().GetType())
1074 {
1075 case "FryingPan":
1076 case "Pot":
1077 case "Cauldron":
1078 case "SharpWoodenStick":
1079 MakeSoundsOnClient(false);
1080 break;
1081 }
1082
1084 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1085 MakeSoundsOnClient(false);
1086 }
1087 }
1088
1089 void UpdateVisuals()
1090 {
1091 if (GetFoodStage())
1092 GetFoodStage().UpdateVisuals();
1093 }
1094
1095 bool Consume(float amount, PlayerBase consumer)
1096 {
1097 AddQuantity(-amount, false, false);
1098 OnConsume(amount, consumer);
1099
1100 return true;
1101 }
1102
1103 void OnConsume(float amount, PlayerBase consumer);
1104
1105 //food staging
1106 override bool CanBeCooked()
1107 {
1108 return false;
1109 }
1110
1111 override bool CanBeCookedOnStick()
1112 {
1113 return false;
1114 }
1115
1116 //================================================================
1117 // SYNCHRONIZATION
1118 //================================================================
1119 void Synchronize()
1120 {
1121 SetSynchDirty();
1122
1123 if (GetGame().IsMultiplayer())
1124 UpdateVisuals();
1125 }
1126
1127 override void OnVariablesSynchronized()
1128 {
1129 super.OnVariablesSynchronized();
1130
1131 UpdateVisuals();
1132
1133 //update audio
1135 RefreshAudio();
1136 else
1137 RemoveAudio();
1138 }
1139
1140 //================================================================
1141 // AUDIO EFFECTS (WHEN ON DCS)
1142 //================================================================
1144 {
1147
1148 Synchronize();
1149 }
1150
1151 protected void RefreshAudio()
1152 {
1153 string soundName = "";
1154
1156
1157 switch (GetFoodStageType())
1158 {
1159 case FoodStageType.RAW:
1161 if (nextFoodState == FoodStageType.BOILED)
1162 soundName = "";
1163 break;
1164 case FoodStageType.BAKED:
1166 break;
1167 case FoodStageType.BURNED:
1169 break;
1170 default:
1171 soundName = "";
1172 break;
1173 }
1174
1176 }
1177
1178 protected void RemoveAudio()
1179 {
1180 m_MakeCookingSounds = false;
1182 }
1183
1184 //================================================================
1185 // SERIALIZATION
1186 //================================================================
1187 override void OnStoreSave(ParamsWriteContext ctx)
1188 {
1189 super.OnStoreSave(ctx);
1190
1191 if (GetFoodStage())
1192 GetFoodStage().OnStoreSave(ctx);
1193
1194 // food decay
1195 ctx.Write(m_DecayTimer);
1196 ctx.Write(m_LastDecayStage);
1197 }
1198
1199 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1200 {
1201 if (!super.OnStoreLoad(ctx, version))
1202 return false;
1203
1204 if (GetFoodStage())
1205 {
1206 if (!GetFoodStage().OnStoreLoad(ctx, version))
1207 return false;
1208 }
1209
1210 if (version >= 115)
1211 {
1212 if (!ctx.Read(m_DecayTimer))
1213 {
1214 m_DecayTimer = 0.0;
1215 return false;
1216 }
1217 if (!ctx.Read(m_LastDecayStage))
1218 {
1220 return false;
1221 }
1222 }
1223
1224 return true;
1225 }
1226
1227 override void AfterStoreLoad()
1228 {
1229 super.AfterStoreLoad();
1230
1231 Synchronize();
1232 }
1233
1234 //get food stage
1236 {
1237 return m_FoodStage;
1238 }
1239
1240 //food types
1241 override bool IsMeat()
1242 {
1243 return false;
1244 }
1245
1246 override bool IsCorpse()
1247 {
1248 return false;
1249 }
1250
1251 override bool IsFruit()
1252 {
1253 return false;
1254 }
1255
1256 override bool IsMushroom()
1257 {
1258 return false;
1259 }
1260
1261 //================================================================
1262 // NUTRITIONAL VALUES
1263 //================================================================
1264 //food properties
1265 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1266 {
1268 if (food_item && food_item.GetFoodStage())
1269 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1270 else if (classname != "" && food_stage)
1271 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1272 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1273 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1274
1275 }
1276
1277 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1278 {
1280 if (food_item && food_item.GetFoodStage())
1281 return FoodStage.GetEnergy(food_item.GetFoodStage());
1282 else if (classname != "" && food_stage)
1283 return FoodStage.GetEnergy(null, food_stage, classname);
1284 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1285 return GetGame().ConfigGetFloat(class_path + " energy");
1286 }
1287
1288 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1289 {
1291 if (food_item && food_item.GetFoodStage())
1292 return FoodStage.GetWater(food_item.GetFoodStage());
1293 else if (classname != "" && food_stage)
1294 return FoodStage.GetWater(null, food_stage, classname);
1295 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1296 return GetGame().ConfigGetFloat(class_path + " water");
1297 }
1298
1299 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1300 {
1302 if (food_item && food_item.GetFoodStage())
1303 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1304 else if (classname != "" && food_stage)
1305 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1306 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1307 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1308
1309 }
1310
1311 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1312 {
1314 if (food_item && food_item.GetFoodStage())
1315 return FoodStage.GetToxicity(food_item.GetFoodStage());
1316 else if (classname != "" && food_stage)
1317 return FoodStage.GetToxicity(null, food_stage, classname);
1318 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1319 return GetGame().ConfigGetFloat(class_path + " toxicity");
1320 }
1321
1322 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1323 {
1325 if (food_item && food_item.GetFoodStage())
1326 return FoodStage.GetAgents(food_item.GetFoodStage());
1327 else if (classname != "" && food_stage)
1328 return FoodStage.GetAgents(null, food_stage, classname);
1329 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1330 return GetGame().ConfigGetInt(class_path + " agents");
1331 }
1332
1333 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1334 {
1336 if (food_item && food_item.GetFoodStage())
1337 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1338 else if (classname != "" && food_stage)
1339 return FoodStage.GetDigestibility(null, food_stage, classname);
1340 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1341 return GetGame().ConfigGetInt(class_path + " digestibility");
1342 }
1343
1345 {
1347 }
1348
1349 //================================================================
1350 // FOOD STAGING
1351 //================================================================
1353 {
1354 return GetFoodStage().GetFoodStageType();
1355 }
1356
1357 //food stage states
1358 bool IsFoodRaw()
1359 {
1360 if (GetFoodStage())
1361 return GetFoodStage().IsFoodRaw();
1362
1363 return false;
1364 }
1365
1366 bool IsFoodBaked()
1367 {
1368 if (GetFoodStage())
1369 return GetFoodStage().IsFoodBaked();
1370
1371 return false;
1372 }
1373
1374 bool IsFoodBoiled()
1375 {
1376 if (GetFoodStage())
1377 return GetFoodStage().IsFoodBoiled();
1378
1379 return false;
1380 }
1381
1382 bool IsFoodDried()
1383 {
1384 if (GetFoodStage())
1385 return GetFoodStage().IsFoodDried();
1386
1387 return false;
1388 }
1389
1390 bool IsFoodBurned()
1391 {
1392 if (GetFoodStage())
1393 return GetFoodStage().IsFoodBurned();
1394
1395 return false;
1396 }
1397
1398 bool IsFoodRotten()
1399 {
1400 if (GetFoodStage())
1401 return GetFoodStage().IsFoodRotten();
1402
1403 return false;
1404 }
1405
1406 //food stage change
1408 {
1409 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1410 }
1411
1413 {
1414 return GetFoodStage().GetNextFoodStageType(cooking_method);
1415 }
1416
1418 {
1419 return GetFoodStage().GetFoodStageName(food_stage_type);
1420 }
1421
1423 {
1424 return GetFoodStage().CanChangeToNewStage(cooking_method);
1425 }
1426
1427 //Use this to receive food stage from another Edible_Base
1429 {
1430 if (!source.HasFoodStage())
1431 return;
1432 m_LastDecayStage = source.GetLastDecayStage();
1433 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1434 m_DecayTimer = source.GetDecayTimer();
1435 m_DecayDelta = source.GetDecayDelta();
1436 }
1437
1438 //================================================================
1439 // COOKING
1440 //================================================================
1441 //cooking time
1442 float GetCookingTime()
1443 {
1444 return GetFoodStage().GetCookingTime();
1445 }
1446
1447 void SetCookingTime(float time)
1448 {
1449 GetFoodStage().SetCookingTime(time);
1450
1451 //synchronize when calling on server
1452 Synchronize();
1453 }
1454
1455 //replace edible with new item (opening cans)
1456 void ReplaceEdibleWithNew(string typeName)
1457 {
1458 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1459 if (player)
1460 {
1462 player.ServerReplaceItemInHandsWithNew(lambda);
1463 }
1464 else
1465 Error("ReplaceEdibleWithNew - cannot use edible without player");
1466 }
1467
1468 override void SetActions()
1469 {
1470 super.SetActions();
1471
1472 AddAction(ActionAttach);
1474 }
1475
1476 protected void SoundCookingStart(string sound_name)
1477 {
1478#ifndef SERVER
1480 {
1482
1485 }
1486#endif
1487 }
1488
1489 protected void SoundCookingStop()
1490 {
1491#ifndef SERVER
1493 {
1496 m_SoundPlaying = "";
1497 }
1498#endif
1499 }
1500
1501 override bool CanHaveTemperature()
1502 {
1503 return true;
1504 }
1505
1506 override bool CanDecay()
1507 {
1508 return false;
1509 }
1510
1511 override bool CanProcessDecay()
1512 {
1513 return (GetFoodStageType() != FoodStageType.ROTTEN);
1514 }
1515
1516 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1517 {
1518 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1519 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1520 if (hasRootAsPlayer)
1522
1523 /*Print( "-------------------------" );
1524 Print( this );
1525 Print( m_DecayTimer );
1526 Print( m_DecayDelta );
1527 Print( m_LastDecayStage );*/
1528
1529 if (IsFruit() || IsMushroom())
1530 {
1531 // fruit, vegetables and mushrooms
1533 {
1534 switch (GetFoodStageType())
1535 {
1536 case FoodStageType.RAW:
1539 break;
1540
1541 case FoodStageType.BOILED:
1544 break;
1545
1546 case FoodStageType.BAKED:
1549 break;
1550
1551 case FoodStageType.DRIED:
1552 case FoodStageType.BURNED:
1553 case FoodStageType.ROTTEN:
1554 default:
1555 m_DecayTimer = -1;
1557 return;
1558 }
1559
1560 //m_DecayTimer = m_DecayTimer / 1000.0;
1561 }
1562
1564
1565 if (m_DecayTimer <= 0)
1566 {
1567 if (m_LastDecayStage != FoodStageType.NONE)
1568 {
1569 // switch to decayed stage
1570 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1573 {
1574 int rng = Math.RandomIntInclusive(0, 100);
1577 else
1578 {
1581 else
1583 }
1584 }
1585 }
1586 }
1587
1588 }
1589 else if (IsMeat())
1590 {
1591 // meat
1593 {
1594 switch (GetFoodStageType())
1595 {
1596 case FoodStageType.RAW:
1599 break;
1600
1601 case FoodStageType.BOILED:
1604 break;
1605
1606 case FoodStageType.BAKED:
1609 break;
1610
1611 case FoodStageType.DRIED:
1614 break;
1615
1616 case FoodStageType.BURNED:
1617 case FoodStageType.ROTTEN:
1618 default:
1619 m_DecayTimer = -1;
1621 return;
1622 }
1623 }
1624
1626
1627 if (m_DecayTimer <= 0)
1628 {
1629 if (m_LastDecayStage != FoodStageType.NONE)
1630 {
1631 // switch to decayed stage
1634 }
1635 }
1636 }
1637 else if (IsCorpse())
1638 {
1639 // corpse
1641 {
1642 switch (GetFoodStageType())
1643 {
1644 case FoodStageType.RAW:
1647 break;
1648
1649 case FoodStageType.BURNED:
1650 case FoodStageType.ROTTEN:
1651 default:
1652 m_DecayTimer = -1;
1654 return;
1655 }
1656 }
1657
1659
1660 if (m_DecayTimer <= 0)
1661 {
1662 if (m_LastDecayStage != FoodStageType.NONE)
1663 {
1664 // switch to decayed stage
1667 }
1668 }
1669 }
1670 else
1671 {
1672 // opened cans
1674
1675 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1676 {
1679 //m_DecayTimer = m_DecayTimer / 1000.0;
1680 }
1681 else
1682 {
1683 if (m_DecayTimer <= 0)
1684 {
1685 InsertAgent(eAgents.FOOD_POISON, 1);
1686 m_DecayTimer = -1;
1687 }
1688 }
1689 }
1690
1691 m_DecayDelta = 0.0;
1692 }
1693
1695 {
1696 super.GetDebugActions(outputList);
1697
1698 if (HasFoodStage())
1699 {
1700 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1701 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1702 }
1703 }
1704
1705 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1706 {
1707 super.OnAction(action_id, player, ctx);
1708
1709 if (GetGame().IsServer())
1710 {
1711 if (action_id == EActions.FOOD_STAGE_PREV)
1712 {
1714 if (food_stage_prev <= 0)
1715 food_stage_prev = FoodStageType.COUNT - 1;
1717 return true;
1718 }
1719 else if (action_id == EActions.FOOD_STAGE_NEXT)
1720 {
1722 if (food_stage_next >= FoodStageType.COUNT)
1725 return true;
1726 }
1727 }
1728 return false;
1729 }
1730
1731 override string GetDebugText()
1732 {
1733 string debug_output;
1734
1735 debug_output = super.GetDebugText();
1736
1737 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1738 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1739
1740 return debug_output;
1741 }
1742
1743 //================================================================
1744 // GENERAL GETTERS
1745 //================================================================
1746
1747 float GetDecayTimer()
1748 {
1749 return m_DecayTimer;
1750 }
1751
1752 float GetDecayDelta()
1753 {
1754 return m_DecayDelta;
1755 }
1756
1758 {
1759 return m_LastDecayStage;
1760 }
1761}
1762
1764{
1766};

◆ GetFoodNutritionalIndex()

static float ReplaceEdibleWithNewLambda::GetFoodNutritionalIndex ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1036 of file Edible_Base.c.

1036 : ItemBase
1037{
1038 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1039
1040 const string SOUND_BAKING_START = "Baking_SoundSet";
1041 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1042 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1043
1044 protected bool m_MakeCookingSounds;
1045 protected SoundOnVehicle m_SoundCooking;
1047 protected string m_SoundPlaying;
1049 protected float m_DecayTimer;
1050 protected float m_DecayDelta = 0.0;
1052
1054
1055 void Edible_Base()
1056 {
1057 if (HasFoodStage())
1058 {
1059 m_FoodStage = new FoodStage(this);
1060
1061 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1062 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1063 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1064 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1065 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1066
1067 m_SoundPlaying = "";
1069 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1070 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1071 }
1072 }
1073
1074 override void EEInit()
1075 {
1076 super.EEInit();
1077
1078 UpdateVisuals();
1079 }
1080
1081 override void EEDelete(EntityAI parent)
1082 {
1083 super.EEDelete(parent);
1084
1085 RemoveAudio();
1086 }
1087
1089 {
1090 super.EEItemLocationChanged(oldLoc, newLoc);
1091
1093 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1094 {
1095 switch (oldLoc.GetParent().GetType())
1096 {
1097 case "FryingPan":
1098 case "Pot":
1099 case "Cauldron":
1100 case "SharpWoodenStick":
1101 MakeSoundsOnClient(false);
1102 break;
1103 }
1104
1106 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1107 MakeSoundsOnClient(false);
1108 }
1109 }
1110
1111 void UpdateVisuals()
1112 {
1113 if (GetFoodStage())
1114 GetFoodStage().UpdateVisuals();
1115 }
1116
1117 bool Consume(float amount, PlayerBase consumer)
1118 {
1119 AddQuantity(-amount, false, false);
1120 OnConsume(amount, consumer);
1121
1122 return true;
1123 }
1124
1125 void OnConsume(float amount, PlayerBase consumer);
1126
1127 //food staging
1128 override bool CanBeCooked()
1129 {
1130 return false;
1131 }
1132
1133 override bool CanBeCookedOnStick()
1134 {
1135 return false;
1136 }
1137
1138 //================================================================
1139 // SYNCHRONIZATION
1140 //================================================================
1141 void Synchronize()
1142 {
1143 SetSynchDirty();
1144
1145 if (GetGame().IsMultiplayer())
1146 UpdateVisuals();
1147 }
1148
1149 override void OnVariablesSynchronized()
1150 {
1151 super.OnVariablesSynchronized();
1152
1153 UpdateVisuals();
1154
1155 //update audio
1157 RefreshAudio();
1158 else
1159 RemoveAudio();
1160 }
1161
1162 //================================================================
1163 // AUDIO EFFECTS (WHEN ON DCS)
1164 //================================================================
1166 {
1169
1170 Synchronize();
1171 }
1172
1173 protected void RefreshAudio()
1174 {
1175 string soundName = "";
1176
1178
1179 switch (GetFoodStageType())
1180 {
1181 case FoodStageType.RAW:
1183 if (nextFoodState == FoodStageType.BOILED)
1184 soundName = "";
1185 break;
1186 case FoodStageType.BAKED:
1188 break;
1189 case FoodStageType.BURNED:
1191 break;
1192 default:
1193 soundName = "";
1194 break;
1195 }
1196
1198 }
1199
1200 protected void RemoveAudio()
1201 {
1202 m_MakeCookingSounds = false;
1204 }
1205
1206 //================================================================
1207 // SERIALIZATION
1208 //================================================================
1209 override void OnStoreSave(ParamsWriteContext ctx)
1210 {
1211 super.OnStoreSave(ctx);
1212
1213 if (GetFoodStage())
1214 GetFoodStage().OnStoreSave(ctx);
1215
1216 // food decay
1217 ctx.Write(m_DecayTimer);
1218 ctx.Write(m_LastDecayStage);
1219 }
1220
1221 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1222 {
1223 if (!super.OnStoreLoad(ctx, version))
1224 return false;
1225
1226 if (GetFoodStage())
1227 {
1228 if (!GetFoodStage().OnStoreLoad(ctx, version))
1229 return false;
1230 }
1231
1232 if (version >= 115)
1233 {
1234 if (!ctx.Read(m_DecayTimer))
1235 {
1236 m_DecayTimer = 0.0;
1237 return false;
1238 }
1239 if (!ctx.Read(m_LastDecayStage))
1240 {
1242 return false;
1243 }
1244 }
1245
1246 return true;
1247 }
1248
1249 override void AfterStoreLoad()
1250 {
1251 super.AfterStoreLoad();
1252
1253 Synchronize();
1254 }
1255
1256 //get food stage
1258 {
1259 return m_FoodStage;
1260 }
1261
1262 //food types
1263 override bool IsMeat()
1264 {
1265 return false;
1266 }
1267
1268 override bool IsCorpse()
1269 {
1270 return false;
1271 }
1272
1273 override bool IsFruit()
1274 {
1275 return false;
1276 }
1277
1278 override bool IsMushroom()
1279 {
1280 return false;
1281 }
1282
1283 //================================================================
1284 // NUTRITIONAL VALUES
1285 //================================================================
1286 //food properties
1287 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1288 {
1290 if (food_item && food_item.GetFoodStage())
1291 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1292 else if (classname != "" && food_stage)
1293 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1294 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1295 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1296
1297 }
1298
1299 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1300 {
1302 if (food_item && food_item.GetFoodStage())
1303 return FoodStage.GetEnergy(food_item.GetFoodStage());
1304 else if (classname != "" && food_stage)
1305 return FoodStage.GetEnergy(null, food_stage, classname);
1306 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1307 return GetGame().ConfigGetFloat(class_path + " energy");
1308 }
1309
1310 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1311 {
1313 if (food_item && food_item.GetFoodStage())
1314 return FoodStage.GetWater(food_item.GetFoodStage());
1315 else if (classname != "" && food_stage)
1316 return FoodStage.GetWater(null, food_stage, classname);
1317 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1318 return GetGame().ConfigGetFloat(class_path + " water");
1319 }
1320
1321 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1322 {
1324 if (food_item && food_item.GetFoodStage())
1325 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1326 else if (classname != "" && food_stage)
1327 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1328 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1329 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1330
1331 }
1332
1333 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1334 {
1336 if (food_item && food_item.GetFoodStage())
1337 return FoodStage.GetToxicity(food_item.GetFoodStage());
1338 else if (classname != "" && food_stage)
1339 return FoodStage.GetToxicity(null, food_stage, classname);
1340 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1341 return GetGame().ConfigGetFloat(class_path + " toxicity");
1342 }
1343
1344 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1345 {
1347 if (food_item && food_item.GetFoodStage())
1348 return FoodStage.GetAgents(food_item.GetFoodStage());
1349 else if (classname != "" && food_stage)
1350 return FoodStage.GetAgents(null, food_stage, classname);
1351 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1352 return GetGame().ConfigGetInt(class_path + " agents");
1353 }
1354
1355 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1356 {
1358 if (food_item && food_item.GetFoodStage())
1359 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1360 else if (classname != "" && food_stage)
1361 return FoodStage.GetDigestibility(null, food_stage, classname);
1362 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1363 return GetGame().ConfigGetInt(class_path + " digestibility");
1364 }
1365
1367 {
1369 }
1370
1371 //================================================================
1372 // FOOD STAGING
1373 //================================================================
1375 {
1376 return GetFoodStage().GetFoodStageType();
1377 }
1378
1379 //food stage states
1380 bool IsFoodRaw()
1381 {
1382 if (GetFoodStage())
1383 return GetFoodStage().IsFoodRaw();
1384
1385 return false;
1386 }
1387
1388 bool IsFoodBaked()
1389 {
1390 if (GetFoodStage())
1391 return GetFoodStage().IsFoodBaked();
1392
1393 return false;
1394 }
1395
1396 bool IsFoodBoiled()
1397 {
1398 if (GetFoodStage())
1399 return GetFoodStage().IsFoodBoiled();
1400
1401 return false;
1402 }
1403
1404 bool IsFoodDried()
1405 {
1406 if (GetFoodStage())
1407 return GetFoodStage().IsFoodDried();
1408
1409 return false;
1410 }
1411
1412 bool IsFoodBurned()
1413 {
1414 if (GetFoodStage())
1415 return GetFoodStage().IsFoodBurned();
1416
1417 return false;
1418 }
1419
1420 bool IsFoodRotten()
1421 {
1422 if (GetFoodStage())
1423 return GetFoodStage().IsFoodRotten();
1424
1425 return false;
1426 }
1427
1428 //food stage change
1430 {
1431 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1432 }
1433
1435 {
1436 return GetFoodStage().GetNextFoodStageType(cooking_method);
1437 }
1438
1440 {
1441 return GetFoodStage().GetFoodStageName(food_stage_type);
1442 }
1443
1445 {
1446 return GetFoodStage().CanChangeToNewStage(cooking_method);
1447 }
1448
1449 //Use this to receive food stage from another Edible_Base
1451 {
1452 if (!source.HasFoodStage())
1453 return;
1454 m_LastDecayStage = source.GetLastDecayStage();
1455 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1456 m_DecayTimer = source.GetDecayTimer();
1457 m_DecayDelta = source.GetDecayDelta();
1458 }
1459
1460 //================================================================
1461 // COOKING
1462 //================================================================
1463 //cooking time
1464 float GetCookingTime()
1465 {
1466 return GetFoodStage().GetCookingTime();
1467 }
1468
1469 void SetCookingTime(float time)
1470 {
1471 GetFoodStage().SetCookingTime(time);
1472
1473 //synchronize when calling on server
1474 Synchronize();
1475 }
1476
1477 //replace edible with new item (opening cans)
1478 void ReplaceEdibleWithNew(string typeName)
1479 {
1480 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1481 if (player)
1482 {
1484 player.ServerReplaceItemInHandsWithNew(lambda);
1485 }
1486 else
1487 Error("ReplaceEdibleWithNew - cannot use edible without player");
1488 }
1489
1490 override void SetActions()
1491 {
1492 super.SetActions();
1493
1494 AddAction(ActionAttach);
1496 }
1497
1498 protected void SoundCookingStart(string sound_name)
1499 {
1500#ifndef SERVER
1502 {
1504
1507 }
1508#endif
1509 }
1510
1511 protected void SoundCookingStop()
1512 {
1513#ifndef SERVER
1515 {
1518 m_SoundPlaying = "";
1519 }
1520#endif
1521 }
1522
1523 override bool CanHaveTemperature()
1524 {
1525 return true;
1526 }
1527
1528 override bool CanDecay()
1529 {
1530 return false;
1531 }
1532
1533 override bool CanProcessDecay()
1534 {
1535 return (GetFoodStageType() != FoodStageType.ROTTEN);
1536 }
1537
1538 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1539 {
1540 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1541 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1542 if (hasRootAsPlayer)
1544
1545 /*Print( "-------------------------" );
1546 Print( this );
1547 Print( m_DecayTimer );
1548 Print( m_DecayDelta );
1549 Print( m_LastDecayStage );*/
1550
1551 if (IsFruit() || IsMushroom())
1552 {
1553 // fruit, vegetables and mushrooms
1555 {
1556 switch (GetFoodStageType())
1557 {
1558 case FoodStageType.RAW:
1561 break;
1562
1563 case FoodStageType.BOILED:
1566 break;
1567
1568 case FoodStageType.BAKED:
1571 break;
1572
1573 case FoodStageType.DRIED:
1574 case FoodStageType.BURNED:
1575 case FoodStageType.ROTTEN:
1576 default:
1577 m_DecayTimer = -1;
1579 return;
1580 }
1581
1582 //m_DecayTimer = m_DecayTimer / 1000.0;
1583 }
1584
1586
1587 if (m_DecayTimer <= 0)
1588 {
1589 if (m_LastDecayStage != FoodStageType.NONE)
1590 {
1591 // switch to decayed stage
1592 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1595 {
1596 int rng = Math.RandomIntInclusive(0, 100);
1599 else
1600 {
1603 else
1605 }
1606 }
1607 }
1608 }
1609
1610 }
1611 else if (IsMeat())
1612 {
1613 // meat
1615 {
1616 switch (GetFoodStageType())
1617 {
1618 case FoodStageType.RAW:
1621 break;
1622
1623 case FoodStageType.BOILED:
1626 break;
1627
1628 case FoodStageType.BAKED:
1631 break;
1632
1633 case FoodStageType.DRIED:
1636 break;
1637
1638 case FoodStageType.BURNED:
1639 case FoodStageType.ROTTEN:
1640 default:
1641 m_DecayTimer = -1;
1643 return;
1644 }
1645 }
1646
1648
1649 if (m_DecayTimer <= 0)
1650 {
1651 if (m_LastDecayStage != FoodStageType.NONE)
1652 {
1653 // switch to decayed stage
1656 }
1657 }
1658 }
1659 else if (IsCorpse())
1660 {
1661 // corpse
1663 {
1664 switch (GetFoodStageType())
1665 {
1666 case FoodStageType.RAW:
1669 break;
1670
1671 case FoodStageType.BURNED:
1672 case FoodStageType.ROTTEN:
1673 default:
1674 m_DecayTimer = -1;
1676 return;
1677 }
1678 }
1679
1681
1682 if (m_DecayTimer <= 0)
1683 {
1684 if (m_LastDecayStage != FoodStageType.NONE)
1685 {
1686 // switch to decayed stage
1689 }
1690 }
1691 }
1692 else
1693 {
1694 // opened cans
1696
1697 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1698 {
1701 //m_DecayTimer = m_DecayTimer / 1000.0;
1702 }
1703 else
1704 {
1705 if (m_DecayTimer <= 0)
1706 {
1707 InsertAgent(eAgents.FOOD_POISON, 1);
1708 m_DecayTimer = -1;
1709 }
1710 }
1711 }
1712
1713 m_DecayDelta = 0.0;
1714 }
1715
1717 {
1718 super.GetDebugActions(outputList);
1719
1720 if (HasFoodStage())
1721 {
1722 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1723 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1724 }
1725 }
1726
1727 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1728 {
1729 super.OnAction(action_id, player, ctx);
1730
1731 if (GetGame().IsServer())
1732 {
1733 if (action_id == EActions.FOOD_STAGE_PREV)
1734 {
1736 if (food_stage_prev <= 0)
1737 food_stage_prev = FoodStageType.COUNT - 1;
1739 return true;
1740 }
1741 else if (action_id == EActions.FOOD_STAGE_NEXT)
1742 {
1744 if (food_stage_next >= FoodStageType.COUNT)
1747 return true;
1748 }
1749 }
1750 return false;
1751 }
1752
1753 override string GetDebugText()
1754 {
1755 string debug_output;
1756
1757 debug_output = super.GetDebugText();
1758
1759 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1760 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1761
1762 return debug_output;
1763 }
1764
1765 //================================================================
1766 // GENERAL GETTERS
1767 //================================================================
1768
1769 float GetDecayTimer()
1770 {
1771 return m_DecayTimer;
1772 }
1773
1774 float GetDecayDelta()
1775 {
1776 return m_DecayDelta;
1777 }
1778
1780 {
1781 return m_LastDecayStage;
1782 }
1783}
1784
1786{
1788};

◆ GetFoodStage()

FoodStage ReplaceEdibleWithNewLambda::GetFoodStage ( )
protected

Definition at line 972 of file Edible_Base.c.

972 : ItemBase
973{
974 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
975
976 const string SOUND_BAKING_START = "Baking_SoundSet";
977 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
978 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
979
980 protected bool m_MakeCookingSounds;
983 protected string m_SoundPlaying;
985 protected float m_DecayTimer;
986 protected float m_DecayDelta = 0.0;
988
990
991 void Edible_Base()
992 {
993 if (HasFoodStage())
994 {
995 m_FoodStage = new FoodStage(this);
996
997 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
998 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
999 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1000 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1001 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1002
1003 m_SoundPlaying = "";
1005 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1006 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1007 }
1008 }
1009
1010 override void EEInit()
1011 {
1012 super.EEInit();
1013
1014 UpdateVisuals();
1015 }
1016
1017 override void EEDelete(EntityAI parent)
1018 {
1019 super.EEDelete(parent);
1020
1021 RemoveAudio();
1022 }
1023
1025 {
1026 super.EEItemLocationChanged(oldLoc, newLoc);
1027
1029 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1030 {
1031 switch (oldLoc.GetParent().GetType())
1032 {
1033 case "FryingPan":
1034 case "Pot":
1035 case "Cauldron":
1036 case "SharpWoodenStick":
1037 MakeSoundsOnClient(false);
1038 break;
1039 }
1040
1042 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1043 MakeSoundsOnClient(false);
1044 }
1045 }
1046
1047 void UpdateVisuals()
1048 {
1049 if (GetFoodStage())
1050 GetFoodStage().UpdateVisuals();
1051 }
1052
1053 bool Consume(float amount, PlayerBase consumer)
1054 {
1055 AddQuantity(-amount, false, false);
1056 OnConsume(amount, consumer);
1057
1058 return true;
1059 }
1060
1061 void OnConsume(float amount, PlayerBase consumer);
1062
1063 //food staging
1064 override bool CanBeCooked()
1065 {
1066 return false;
1067 }
1068
1069 override bool CanBeCookedOnStick()
1070 {
1071 return false;
1072 }
1073
1074 //================================================================
1075 // SYNCHRONIZATION
1076 //================================================================
1077 void Synchronize()
1078 {
1079 SetSynchDirty();
1080
1081 if (GetGame().IsMultiplayer())
1082 UpdateVisuals();
1083 }
1084
1085 override void OnVariablesSynchronized()
1086 {
1087 super.OnVariablesSynchronized();
1088
1089 UpdateVisuals();
1090
1091 //update audio
1093 RefreshAudio();
1094 else
1095 RemoveAudio();
1096 }
1097
1098 //================================================================
1099 // AUDIO EFFECTS (WHEN ON DCS)
1100 //================================================================
1102 {
1105
1106 Synchronize();
1107 }
1108
1109 protected void RefreshAudio()
1110 {
1111 string soundName = "";
1112
1114
1115 switch (GetFoodStageType())
1116 {
1117 case FoodStageType.RAW:
1119 if (nextFoodState == FoodStageType.BOILED)
1120 soundName = "";
1121 break;
1122 case FoodStageType.BAKED:
1124 break;
1125 case FoodStageType.BURNED:
1127 break;
1128 default:
1129 soundName = "";
1130 break;
1131 }
1132
1134 }
1135
1136 protected void RemoveAudio()
1137 {
1138 m_MakeCookingSounds = false;
1140 }
1141
1142 //================================================================
1143 // SERIALIZATION
1144 //================================================================
1145 override void OnStoreSave(ParamsWriteContext ctx)
1146 {
1147 super.OnStoreSave(ctx);
1148
1149 if (GetFoodStage())
1150 GetFoodStage().OnStoreSave(ctx);
1151
1152 // food decay
1153 ctx.Write(m_DecayTimer);
1154 ctx.Write(m_LastDecayStage);
1155 }
1156
1157 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1158 {
1159 if (!super.OnStoreLoad(ctx, version))
1160 return false;
1161
1162 if (GetFoodStage())
1163 {
1164 if (!GetFoodStage().OnStoreLoad(ctx, version))
1165 return false;
1166 }
1167
1168 if (version >= 115)
1169 {
1170 if (!ctx.Read(m_DecayTimer))
1171 {
1172 m_DecayTimer = 0.0;
1173 return false;
1174 }
1175 if (!ctx.Read(m_LastDecayStage))
1176 {
1178 return false;
1179 }
1180 }
1181
1182 return true;
1183 }
1184
1185 override void AfterStoreLoad()
1186 {
1187 super.AfterStoreLoad();
1188
1189 Synchronize();
1190 }
1191
1192 //get food stage
1194 {
1195 return m_FoodStage;
1196 }
1197
1198 //food types
1199 override bool IsMeat()
1200 {
1201 return false;
1202 }
1203
1204 override bool IsCorpse()
1205 {
1206 return false;
1207 }
1208
1209 override bool IsFruit()
1210 {
1211 return false;
1212 }
1213
1214 override bool IsMushroom()
1215 {
1216 return false;
1217 }
1218
1219 //================================================================
1220 // NUTRITIONAL VALUES
1221 //================================================================
1222 //food properties
1223 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1224 {
1226 if (food_item && food_item.GetFoodStage())
1227 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1228 else if (classname != "" && food_stage)
1229 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1230 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1231 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1232
1233 }
1234
1235 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1236 {
1238 if (food_item && food_item.GetFoodStage())
1239 return FoodStage.GetEnergy(food_item.GetFoodStage());
1240 else if (classname != "" && food_stage)
1241 return FoodStage.GetEnergy(null, food_stage, classname);
1242 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1243 return GetGame().ConfigGetFloat(class_path + " energy");
1244 }
1245
1246 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1247 {
1249 if (food_item && food_item.GetFoodStage())
1250 return FoodStage.GetWater(food_item.GetFoodStage());
1251 else if (classname != "" && food_stage)
1252 return FoodStage.GetWater(null, food_stage, classname);
1253 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1254 return GetGame().ConfigGetFloat(class_path + " water");
1255 }
1256
1257 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1258 {
1260 if (food_item && food_item.GetFoodStage())
1261 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1262 else if (classname != "" && food_stage)
1263 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1264 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1265 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1266
1267 }
1268
1269 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1270 {
1272 if (food_item && food_item.GetFoodStage())
1273 return FoodStage.GetToxicity(food_item.GetFoodStage());
1274 else if (classname != "" && food_stage)
1275 return FoodStage.GetToxicity(null, food_stage, classname);
1276 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1277 return GetGame().ConfigGetFloat(class_path + " toxicity");
1278 }
1279
1280 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1281 {
1283 if (food_item && food_item.GetFoodStage())
1284 return FoodStage.GetAgents(food_item.GetFoodStage());
1285 else if (classname != "" && food_stage)
1286 return FoodStage.GetAgents(null, food_stage, classname);
1287 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1288 return GetGame().ConfigGetInt(class_path + " agents");
1289 }
1290
1291 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1292 {
1294 if (food_item && food_item.GetFoodStage())
1295 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1296 else if (classname != "" && food_stage)
1297 return FoodStage.GetDigestibility(null, food_stage, classname);
1298 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1299 return GetGame().ConfigGetInt(class_path + " digestibility");
1300 }
1301
1303 {
1305 }
1306
1307 //================================================================
1308 // FOOD STAGING
1309 //================================================================
1311 {
1312 return GetFoodStage().GetFoodStageType();
1313 }
1314
1315 //food stage states
1316 bool IsFoodRaw()
1317 {
1318 if (GetFoodStage())
1319 return GetFoodStage().IsFoodRaw();
1320
1321 return false;
1322 }
1323
1324 bool IsFoodBaked()
1325 {
1326 if (GetFoodStage())
1327 return GetFoodStage().IsFoodBaked();
1328
1329 return false;
1330 }
1331
1332 bool IsFoodBoiled()
1333 {
1334 if (GetFoodStage())
1335 return GetFoodStage().IsFoodBoiled();
1336
1337 return false;
1338 }
1339
1340 bool IsFoodDried()
1341 {
1342 if (GetFoodStage())
1343 return GetFoodStage().IsFoodDried();
1344
1345 return false;
1346 }
1347
1348 bool IsFoodBurned()
1349 {
1350 if (GetFoodStage())
1351 return GetFoodStage().IsFoodBurned();
1352
1353 return false;
1354 }
1355
1356 bool IsFoodRotten()
1357 {
1358 if (GetFoodStage())
1359 return GetFoodStage().IsFoodRotten();
1360
1361 return false;
1362 }
1363
1364 //food stage change
1366 {
1367 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1368 }
1369
1371 {
1372 return GetFoodStage().GetNextFoodStageType(cooking_method);
1373 }
1374
1376 {
1377 return GetFoodStage().GetFoodStageName(food_stage_type);
1378 }
1379
1381 {
1382 return GetFoodStage().CanChangeToNewStage(cooking_method);
1383 }
1384
1385 //Use this to receive food stage from another Edible_Base
1387 {
1388 if (!source.HasFoodStage())
1389 return;
1390 m_LastDecayStage = source.GetLastDecayStage();
1391 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1392 m_DecayTimer = source.GetDecayTimer();
1393 m_DecayDelta = source.GetDecayDelta();
1394 }
1395
1396 //================================================================
1397 // COOKING
1398 //================================================================
1399 //cooking time
1400 float GetCookingTime()
1401 {
1402 return GetFoodStage().GetCookingTime();
1403 }
1404
1405 void SetCookingTime(float time)
1406 {
1407 GetFoodStage().SetCookingTime(time);
1408
1409 //synchronize when calling on server
1410 Synchronize();
1411 }
1412
1413 //replace edible with new item (opening cans)
1414 void ReplaceEdibleWithNew(string typeName)
1415 {
1416 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1417 if (player)
1418 {
1420 player.ServerReplaceItemInHandsWithNew(lambda);
1421 }
1422 else
1423 Error("ReplaceEdibleWithNew - cannot use edible without player");
1424 }
1425
1426 override void SetActions()
1427 {
1428 super.SetActions();
1429
1430 AddAction(ActionAttach);
1432 }
1433
1434 protected void SoundCookingStart(string sound_name)
1435 {
1436#ifndef SERVER
1438 {
1440
1443 }
1444#endif
1445 }
1446
1447 protected void SoundCookingStop()
1448 {
1449#ifndef SERVER
1451 {
1454 m_SoundPlaying = "";
1455 }
1456#endif
1457 }
1458
1459 override bool CanHaveTemperature()
1460 {
1461 return true;
1462 }
1463
1464 override bool CanDecay()
1465 {
1466 return false;
1467 }
1468
1469 override bool CanProcessDecay()
1470 {
1471 return (GetFoodStageType() != FoodStageType.ROTTEN);
1472 }
1473
1474 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1475 {
1476 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1477 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1478 if (hasRootAsPlayer)
1480
1481 /*Print( "-------------------------" );
1482 Print( this );
1483 Print( m_DecayTimer );
1484 Print( m_DecayDelta );
1485 Print( m_LastDecayStage );*/
1486
1487 if (IsFruit() || IsMushroom())
1488 {
1489 // fruit, vegetables and mushrooms
1491 {
1492 switch (GetFoodStageType())
1493 {
1494 case FoodStageType.RAW:
1497 break;
1498
1499 case FoodStageType.BOILED:
1502 break;
1503
1504 case FoodStageType.BAKED:
1507 break;
1508
1509 case FoodStageType.DRIED:
1510 case FoodStageType.BURNED:
1511 case FoodStageType.ROTTEN:
1512 default:
1513 m_DecayTimer = -1;
1515 return;
1516 }
1517
1518 //m_DecayTimer = m_DecayTimer / 1000.0;
1519 }
1520
1522
1523 if (m_DecayTimer <= 0)
1524 {
1525 if (m_LastDecayStage != FoodStageType.NONE)
1526 {
1527 // switch to decayed stage
1528 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1531 {
1532 int rng = Math.RandomIntInclusive(0, 100);
1535 else
1536 {
1539 else
1541 }
1542 }
1543 }
1544 }
1545
1546 }
1547 else if (IsMeat())
1548 {
1549 // meat
1551 {
1552 switch (GetFoodStageType())
1553 {
1554 case FoodStageType.RAW:
1557 break;
1558
1559 case FoodStageType.BOILED:
1562 break;
1563
1564 case FoodStageType.BAKED:
1567 break;
1568
1569 case FoodStageType.DRIED:
1572 break;
1573
1574 case FoodStageType.BURNED:
1575 case FoodStageType.ROTTEN:
1576 default:
1577 m_DecayTimer = -1;
1579 return;
1580 }
1581 }
1582
1584
1585 if (m_DecayTimer <= 0)
1586 {
1587 if (m_LastDecayStage != FoodStageType.NONE)
1588 {
1589 // switch to decayed stage
1592 }
1593 }
1594 }
1595 else if (IsCorpse())
1596 {
1597 // corpse
1599 {
1600 switch (GetFoodStageType())
1601 {
1602 case FoodStageType.RAW:
1605 break;
1606
1607 case FoodStageType.BURNED:
1608 case FoodStageType.ROTTEN:
1609 default:
1610 m_DecayTimer = -1;
1612 return;
1613 }
1614 }
1615
1617
1618 if (m_DecayTimer <= 0)
1619 {
1620 if (m_LastDecayStage != FoodStageType.NONE)
1621 {
1622 // switch to decayed stage
1625 }
1626 }
1627 }
1628 else
1629 {
1630 // opened cans
1632
1633 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1634 {
1637 //m_DecayTimer = m_DecayTimer / 1000.0;
1638 }
1639 else
1640 {
1641 if (m_DecayTimer <= 0)
1642 {
1643 InsertAgent(eAgents.FOOD_POISON, 1);
1644 m_DecayTimer = -1;
1645 }
1646 }
1647 }
1648
1649 m_DecayDelta = 0.0;
1650 }
1651
1653 {
1654 super.GetDebugActions(outputList);
1655
1656 if (HasFoodStage())
1657 {
1658 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1659 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1660 }
1661 }
1662
1663 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1664 {
1665 super.OnAction(action_id, player, ctx);
1666
1667 if (GetGame().IsServer())
1668 {
1669 if (action_id == EActions.FOOD_STAGE_PREV)
1670 {
1672 if (food_stage_prev <= 0)
1673 food_stage_prev = FoodStageType.COUNT - 1;
1675 return true;
1676 }
1677 else if (action_id == EActions.FOOD_STAGE_NEXT)
1678 {
1680 if (food_stage_next >= FoodStageType.COUNT)
1683 return true;
1684 }
1685 }
1686 return false;
1687 }
1688
1689 override string GetDebugText()
1690 {
1691 string debug_output;
1692
1693 debug_output = super.GetDebugText();
1694
1695 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1696 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1697
1698 return debug_output;
1699 }
1700
1701 //================================================================
1702 // GENERAL GETTERS
1703 //================================================================
1704
1705 float GetDecayTimer()
1706 {
1707 return m_DecayTimer;
1708 }
1709
1710 float GetDecayDelta()
1711 {
1712 return m_DecayDelta;
1713 }
1714
1716 {
1717 return m_LastDecayStage;
1718 }
1719}
1720
1722{
1724};

◆ GetFoodStageName()

string ReplaceEdibleWithNewLambda::GetFoodStageName ( FoodStageType food_stage_type)
protected

Definition at line 1154 of file Edible_Base.c.

1154 : ItemBase
1155{
1156 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1157
1158 const string SOUND_BAKING_START = "Baking_SoundSet";
1159 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1160 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1161
1162 protected bool m_MakeCookingSounds;
1163 protected SoundOnVehicle m_SoundCooking;
1165 protected string m_SoundPlaying;
1167 protected float m_DecayTimer;
1168 protected float m_DecayDelta = 0.0;
1170
1172
1173 void Edible_Base()
1174 {
1175 if (HasFoodStage())
1176 {
1177 m_FoodStage = new FoodStage(this);
1178
1179 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1180 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1181 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1182 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1183 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1184
1185 m_SoundPlaying = "";
1187 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1188 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1189 }
1190 }
1191
1192 override void EEInit()
1193 {
1194 super.EEInit();
1195
1196 UpdateVisuals();
1197 }
1198
1199 override void EEDelete(EntityAI parent)
1200 {
1201 super.EEDelete(parent);
1202
1203 RemoveAudio();
1204 }
1205
1207 {
1208 super.EEItemLocationChanged(oldLoc, newLoc);
1209
1211 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1212 {
1213 switch (oldLoc.GetParent().GetType())
1214 {
1215 case "FryingPan":
1216 case "Pot":
1217 case "Cauldron":
1218 case "SharpWoodenStick":
1219 MakeSoundsOnClient(false);
1220 break;
1221 }
1222
1224 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1225 MakeSoundsOnClient(false);
1226 }
1227 }
1228
1229 void UpdateVisuals()
1230 {
1231 if (GetFoodStage())
1232 GetFoodStage().UpdateVisuals();
1233 }
1234
1235 bool Consume(float amount, PlayerBase consumer)
1236 {
1237 AddQuantity(-amount, false, false);
1238 OnConsume(amount, consumer);
1239
1240 return true;
1241 }
1242
1243 void OnConsume(float amount, PlayerBase consumer);
1244
1245 //food staging
1246 override bool CanBeCooked()
1247 {
1248 return false;
1249 }
1250
1251 override bool CanBeCookedOnStick()
1252 {
1253 return false;
1254 }
1255
1256 //================================================================
1257 // SYNCHRONIZATION
1258 //================================================================
1259 void Synchronize()
1260 {
1261 SetSynchDirty();
1262
1263 if (GetGame().IsMultiplayer())
1264 UpdateVisuals();
1265 }
1266
1267 override void OnVariablesSynchronized()
1268 {
1269 super.OnVariablesSynchronized();
1270
1271 UpdateVisuals();
1272
1273 //update audio
1275 RefreshAudio();
1276 else
1277 RemoveAudio();
1278 }
1279
1280 //================================================================
1281 // AUDIO EFFECTS (WHEN ON DCS)
1282 //================================================================
1284 {
1287
1288 Synchronize();
1289 }
1290
1291 protected void RefreshAudio()
1292 {
1293 string soundName = "";
1294
1296
1297 switch (GetFoodStageType())
1298 {
1299 case FoodStageType.RAW:
1301 if (nextFoodState == FoodStageType.BOILED)
1302 soundName = "";
1303 break;
1304 case FoodStageType.BAKED:
1306 break;
1307 case FoodStageType.BURNED:
1309 break;
1310 default:
1311 soundName = "";
1312 break;
1313 }
1314
1316 }
1317
1318 protected void RemoveAudio()
1319 {
1320 m_MakeCookingSounds = false;
1322 }
1323
1324 //================================================================
1325 // SERIALIZATION
1326 //================================================================
1327 override void OnStoreSave(ParamsWriteContext ctx)
1328 {
1329 super.OnStoreSave(ctx);
1330
1331 if (GetFoodStage())
1332 GetFoodStage().OnStoreSave(ctx);
1333
1334 // food decay
1335 ctx.Write(m_DecayTimer);
1336 ctx.Write(m_LastDecayStage);
1337 }
1338
1339 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1340 {
1341 if (!super.OnStoreLoad(ctx, version))
1342 return false;
1343
1344 if (GetFoodStage())
1345 {
1346 if (!GetFoodStage().OnStoreLoad(ctx, version))
1347 return false;
1348 }
1349
1350 if (version >= 115)
1351 {
1352 if (!ctx.Read(m_DecayTimer))
1353 {
1354 m_DecayTimer = 0.0;
1355 return false;
1356 }
1357 if (!ctx.Read(m_LastDecayStage))
1358 {
1360 return false;
1361 }
1362 }
1363
1364 return true;
1365 }
1366
1367 override void AfterStoreLoad()
1368 {
1369 super.AfterStoreLoad();
1370
1371 Synchronize();
1372 }
1373
1374 //get food stage
1376 {
1377 return m_FoodStage;
1378 }
1379
1380 //food types
1381 override bool IsMeat()
1382 {
1383 return false;
1384 }
1385
1386 override bool IsCorpse()
1387 {
1388 return false;
1389 }
1390
1391 override bool IsFruit()
1392 {
1393 return false;
1394 }
1395
1396 override bool IsMushroom()
1397 {
1398 return false;
1399 }
1400
1401 //================================================================
1402 // NUTRITIONAL VALUES
1403 //================================================================
1404 //food properties
1405 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1406 {
1408 if (food_item && food_item.GetFoodStage())
1409 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1410 else if (classname != "" && food_stage)
1411 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1412 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1413 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1414
1415 }
1416
1417 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1418 {
1420 if (food_item && food_item.GetFoodStage())
1421 return FoodStage.GetEnergy(food_item.GetFoodStage());
1422 else if (classname != "" && food_stage)
1423 return FoodStage.GetEnergy(null, food_stage, classname);
1424 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1425 return GetGame().ConfigGetFloat(class_path + " energy");
1426 }
1427
1428 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1429 {
1431 if (food_item && food_item.GetFoodStage())
1432 return FoodStage.GetWater(food_item.GetFoodStage());
1433 else if (classname != "" && food_stage)
1434 return FoodStage.GetWater(null, food_stage, classname);
1435 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1436 return GetGame().ConfigGetFloat(class_path + " water");
1437 }
1438
1439 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1440 {
1442 if (food_item && food_item.GetFoodStage())
1443 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1444 else if (classname != "" && food_stage)
1445 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1446 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1447 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1448
1449 }
1450
1451 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1452 {
1454 if (food_item && food_item.GetFoodStage())
1455 return FoodStage.GetToxicity(food_item.GetFoodStage());
1456 else if (classname != "" && food_stage)
1457 return FoodStage.GetToxicity(null, food_stage, classname);
1458 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1459 return GetGame().ConfigGetFloat(class_path + " toxicity");
1460 }
1461
1462 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1463 {
1465 if (food_item && food_item.GetFoodStage())
1466 return FoodStage.GetAgents(food_item.GetFoodStage());
1467 else if (classname != "" && food_stage)
1468 return FoodStage.GetAgents(null, food_stage, classname);
1469 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1470 return GetGame().ConfigGetInt(class_path + " agents");
1471 }
1472
1473 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1474 {
1476 if (food_item && food_item.GetFoodStage())
1477 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1478 else if (classname != "" && food_stage)
1479 return FoodStage.GetDigestibility(null, food_stage, classname);
1480 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1481 return GetGame().ConfigGetInt(class_path + " digestibility");
1482 }
1483
1485 {
1487 }
1488
1489 //================================================================
1490 // FOOD STAGING
1491 //================================================================
1493 {
1494 return GetFoodStage().GetFoodStageType();
1495 }
1496
1497 //food stage states
1498 bool IsFoodRaw()
1499 {
1500 if (GetFoodStage())
1501 return GetFoodStage().IsFoodRaw();
1502
1503 return false;
1504 }
1505
1506 bool IsFoodBaked()
1507 {
1508 if (GetFoodStage())
1509 return GetFoodStage().IsFoodBaked();
1510
1511 return false;
1512 }
1513
1514 bool IsFoodBoiled()
1515 {
1516 if (GetFoodStage())
1517 return GetFoodStage().IsFoodBoiled();
1518
1519 return false;
1520 }
1521
1522 bool IsFoodDried()
1523 {
1524 if (GetFoodStage())
1525 return GetFoodStage().IsFoodDried();
1526
1527 return false;
1528 }
1529
1530 bool IsFoodBurned()
1531 {
1532 if (GetFoodStage())
1533 return GetFoodStage().IsFoodBurned();
1534
1535 return false;
1536 }
1537
1538 bool IsFoodRotten()
1539 {
1540 if (GetFoodStage())
1541 return GetFoodStage().IsFoodRotten();
1542
1543 return false;
1544 }
1545
1546 //food stage change
1548 {
1549 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1550 }
1551
1553 {
1554 return GetFoodStage().GetNextFoodStageType(cooking_method);
1555 }
1556
1558 {
1559 return GetFoodStage().GetFoodStageName(food_stage_type);
1560 }
1561
1563 {
1564 return GetFoodStage().CanChangeToNewStage(cooking_method);
1565 }
1566
1567 //Use this to receive food stage from another Edible_Base
1569 {
1570 if (!source.HasFoodStage())
1571 return;
1572 m_LastDecayStage = source.GetLastDecayStage();
1573 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1574 m_DecayTimer = source.GetDecayTimer();
1575 m_DecayDelta = source.GetDecayDelta();
1576 }
1577
1578 //================================================================
1579 // COOKING
1580 //================================================================
1581 //cooking time
1582 float GetCookingTime()
1583 {
1584 return GetFoodStage().GetCookingTime();
1585 }
1586
1587 void SetCookingTime(float time)
1588 {
1589 GetFoodStage().SetCookingTime(time);
1590
1591 //synchronize when calling on server
1592 Synchronize();
1593 }
1594
1595 //replace edible with new item (opening cans)
1596 void ReplaceEdibleWithNew(string typeName)
1597 {
1598 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1599 if (player)
1600 {
1602 player.ServerReplaceItemInHandsWithNew(lambda);
1603 }
1604 else
1605 Error("ReplaceEdibleWithNew - cannot use edible without player");
1606 }
1607
1608 override void SetActions()
1609 {
1610 super.SetActions();
1611
1612 AddAction(ActionAttach);
1614 }
1615
1616 protected void SoundCookingStart(string sound_name)
1617 {
1618#ifndef SERVER
1620 {
1622
1625 }
1626#endif
1627 }
1628
1629 protected void SoundCookingStop()
1630 {
1631#ifndef SERVER
1633 {
1636 m_SoundPlaying = "";
1637 }
1638#endif
1639 }
1640
1641 override bool CanHaveTemperature()
1642 {
1643 return true;
1644 }
1645
1646 override bool CanDecay()
1647 {
1648 return false;
1649 }
1650
1651 override bool CanProcessDecay()
1652 {
1653 return (GetFoodStageType() != FoodStageType.ROTTEN);
1654 }
1655
1656 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1657 {
1658 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1659 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1660 if (hasRootAsPlayer)
1662
1663 /*Print( "-------------------------" );
1664 Print( this );
1665 Print( m_DecayTimer );
1666 Print( m_DecayDelta );
1667 Print( m_LastDecayStage );*/
1668
1669 if (IsFruit() || IsMushroom())
1670 {
1671 // fruit, vegetables and mushrooms
1673 {
1674 switch (GetFoodStageType())
1675 {
1676 case FoodStageType.RAW:
1679 break;
1680
1681 case FoodStageType.BOILED:
1684 break;
1685
1686 case FoodStageType.BAKED:
1689 break;
1690
1691 case FoodStageType.DRIED:
1692 case FoodStageType.BURNED:
1693 case FoodStageType.ROTTEN:
1694 default:
1695 m_DecayTimer = -1;
1697 return;
1698 }
1699
1700 //m_DecayTimer = m_DecayTimer / 1000.0;
1701 }
1702
1704
1705 if (m_DecayTimer <= 0)
1706 {
1707 if (m_LastDecayStage != FoodStageType.NONE)
1708 {
1709 // switch to decayed stage
1710 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1713 {
1714 int rng = Math.RandomIntInclusive(0, 100);
1717 else
1718 {
1721 else
1723 }
1724 }
1725 }
1726 }
1727
1728 }
1729 else if (IsMeat())
1730 {
1731 // meat
1733 {
1734 switch (GetFoodStageType())
1735 {
1736 case FoodStageType.RAW:
1739 break;
1740
1741 case FoodStageType.BOILED:
1744 break;
1745
1746 case FoodStageType.BAKED:
1749 break;
1750
1751 case FoodStageType.DRIED:
1754 break;
1755
1756 case FoodStageType.BURNED:
1757 case FoodStageType.ROTTEN:
1758 default:
1759 m_DecayTimer = -1;
1761 return;
1762 }
1763 }
1764
1766
1767 if (m_DecayTimer <= 0)
1768 {
1769 if (m_LastDecayStage != FoodStageType.NONE)
1770 {
1771 // switch to decayed stage
1774 }
1775 }
1776 }
1777 else if (IsCorpse())
1778 {
1779 // corpse
1781 {
1782 switch (GetFoodStageType())
1783 {
1784 case FoodStageType.RAW:
1787 break;
1788
1789 case FoodStageType.BURNED:
1790 case FoodStageType.ROTTEN:
1791 default:
1792 m_DecayTimer = -1;
1794 return;
1795 }
1796 }
1797
1799
1800 if (m_DecayTimer <= 0)
1801 {
1802 if (m_LastDecayStage != FoodStageType.NONE)
1803 {
1804 // switch to decayed stage
1807 }
1808 }
1809 }
1810 else
1811 {
1812 // opened cans
1814
1815 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1816 {
1819 //m_DecayTimer = m_DecayTimer / 1000.0;
1820 }
1821 else
1822 {
1823 if (m_DecayTimer <= 0)
1824 {
1825 InsertAgent(eAgents.FOOD_POISON, 1);
1826 m_DecayTimer = -1;
1827 }
1828 }
1829 }
1830
1831 m_DecayDelta = 0.0;
1832 }
1833
1835 {
1836 super.GetDebugActions(outputList);
1837
1838 if (HasFoodStage())
1839 {
1840 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1841 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1842 }
1843 }
1844
1845 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1846 {
1847 super.OnAction(action_id, player, ctx);
1848
1849 if (GetGame().IsServer())
1850 {
1851 if (action_id == EActions.FOOD_STAGE_PREV)
1852 {
1854 if (food_stage_prev <= 0)
1855 food_stage_prev = FoodStageType.COUNT - 1;
1857 return true;
1858 }
1859 else if (action_id == EActions.FOOD_STAGE_NEXT)
1860 {
1862 if (food_stage_next >= FoodStageType.COUNT)
1865 return true;
1866 }
1867 }
1868 return false;
1869 }
1870
1871 override string GetDebugText()
1872 {
1873 string debug_output;
1874
1875 debug_output = super.GetDebugText();
1876
1877 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1878 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1879
1880 return debug_output;
1881 }
1882
1883 //================================================================
1884 // GENERAL GETTERS
1885 //================================================================
1886
1887 float GetDecayTimer()
1888 {
1889 return m_DecayTimer;
1890 }
1891
1892 float GetDecayDelta()
1893 {
1894 return m_DecayDelta;
1895 }
1896
1898 {
1899 return m_LastDecayStage;
1900 }
1901}
1902
1904{
1906};

◆ GetFoodStageType()

FoodStageType ReplaceEdibleWithNewLambda::GetFoodStageType ( )
protected

Definition at line 1089 of file Edible_Base.c.

1089 : ItemBase
1090{
1091 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1092
1093 const string SOUND_BAKING_START = "Baking_SoundSet";
1094 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1095 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1096
1097 protected bool m_MakeCookingSounds;
1098 protected SoundOnVehicle m_SoundCooking;
1100 protected string m_SoundPlaying;
1102 protected float m_DecayTimer;
1103 protected float m_DecayDelta = 0.0;
1105
1107
1108 void Edible_Base()
1109 {
1110 if (HasFoodStage())
1111 {
1112 m_FoodStage = new FoodStage(this);
1113
1114 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1115 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1116 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1117 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1118 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1119
1120 m_SoundPlaying = "";
1122 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1123 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1124 }
1125 }
1126
1127 override void EEInit()
1128 {
1129 super.EEInit();
1130
1131 UpdateVisuals();
1132 }
1133
1134 override void EEDelete(EntityAI parent)
1135 {
1136 super.EEDelete(parent);
1137
1138 RemoveAudio();
1139 }
1140
1142 {
1143 super.EEItemLocationChanged(oldLoc, newLoc);
1144
1146 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1147 {
1148 switch (oldLoc.GetParent().GetType())
1149 {
1150 case "FryingPan":
1151 case "Pot":
1152 case "Cauldron":
1153 case "SharpWoodenStick":
1154 MakeSoundsOnClient(false);
1155 break;
1156 }
1157
1159 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1160 MakeSoundsOnClient(false);
1161 }
1162 }
1163
1164 void UpdateVisuals()
1165 {
1166 if (GetFoodStage())
1167 GetFoodStage().UpdateVisuals();
1168 }
1169
1170 bool Consume(float amount, PlayerBase consumer)
1171 {
1172 AddQuantity(-amount, false, false);
1173 OnConsume(amount, consumer);
1174
1175 return true;
1176 }
1177
1178 void OnConsume(float amount, PlayerBase consumer);
1179
1180 //food staging
1181 override bool CanBeCooked()
1182 {
1183 return false;
1184 }
1185
1186 override bool CanBeCookedOnStick()
1187 {
1188 return false;
1189 }
1190
1191 //================================================================
1192 // SYNCHRONIZATION
1193 //================================================================
1194 void Synchronize()
1195 {
1196 SetSynchDirty();
1197
1198 if (GetGame().IsMultiplayer())
1199 UpdateVisuals();
1200 }
1201
1202 override void OnVariablesSynchronized()
1203 {
1204 super.OnVariablesSynchronized();
1205
1206 UpdateVisuals();
1207
1208 //update audio
1210 RefreshAudio();
1211 else
1212 RemoveAudio();
1213 }
1214
1215 //================================================================
1216 // AUDIO EFFECTS (WHEN ON DCS)
1217 //================================================================
1219 {
1222
1223 Synchronize();
1224 }
1225
1226 protected void RefreshAudio()
1227 {
1228 string soundName = "";
1229
1231
1232 switch (GetFoodStageType())
1233 {
1234 case FoodStageType.RAW:
1236 if (nextFoodState == FoodStageType.BOILED)
1237 soundName = "";
1238 break;
1239 case FoodStageType.BAKED:
1241 break;
1242 case FoodStageType.BURNED:
1244 break;
1245 default:
1246 soundName = "";
1247 break;
1248 }
1249
1251 }
1252
1253 protected void RemoveAudio()
1254 {
1255 m_MakeCookingSounds = false;
1257 }
1258
1259 //================================================================
1260 // SERIALIZATION
1261 //================================================================
1262 override void OnStoreSave(ParamsWriteContext ctx)
1263 {
1264 super.OnStoreSave(ctx);
1265
1266 if (GetFoodStage())
1267 GetFoodStage().OnStoreSave(ctx);
1268
1269 // food decay
1270 ctx.Write(m_DecayTimer);
1271 ctx.Write(m_LastDecayStage);
1272 }
1273
1274 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1275 {
1276 if (!super.OnStoreLoad(ctx, version))
1277 return false;
1278
1279 if (GetFoodStage())
1280 {
1281 if (!GetFoodStage().OnStoreLoad(ctx, version))
1282 return false;
1283 }
1284
1285 if (version >= 115)
1286 {
1287 if (!ctx.Read(m_DecayTimer))
1288 {
1289 m_DecayTimer = 0.0;
1290 return false;
1291 }
1292 if (!ctx.Read(m_LastDecayStage))
1293 {
1295 return false;
1296 }
1297 }
1298
1299 return true;
1300 }
1301
1302 override void AfterStoreLoad()
1303 {
1304 super.AfterStoreLoad();
1305
1306 Synchronize();
1307 }
1308
1309 //get food stage
1311 {
1312 return m_FoodStage;
1313 }
1314
1315 //food types
1316 override bool IsMeat()
1317 {
1318 return false;
1319 }
1320
1321 override bool IsCorpse()
1322 {
1323 return false;
1324 }
1325
1326 override bool IsFruit()
1327 {
1328 return false;
1329 }
1330
1331 override bool IsMushroom()
1332 {
1333 return false;
1334 }
1335
1336 //================================================================
1337 // NUTRITIONAL VALUES
1338 //================================================================
1339 //food properties
1340 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1341 {
1343 if (food_item && food_item.GetFoodStage())
1344 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1345 else if (classname != "" && food_stage)
1346 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1347 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1348 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1349
1350 }
1351
1352 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1353 {
1355 if (food_item && food_item.GetFoodStage())
1356 return FoodStage.GetEnergy(food_item.GetFoodStage());
1357 else if (classname != "" && food_stage)
1358 return FoodStage.GetEnergy(null, food_stage, classname);
1359 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1360 return GetGame().ConfigGetFloat(class_path + " energy");
1361 }
1362
1363 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1364 {
1366 if (food_item && food_item.GetFoodStage())
1367 return FoodStage.GetWater(food_item.GetFoodStage());
1368 else if (classname != "" && food_stage)
1369 return FoodStage.GetWater(null, food_stage, classname);
1370 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1371 return GetGame().ConfigGetFloat(class_path + " water");
1372 }
1373
1374 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1375 {
1377 if (food_item && food_item.GetFoodStage())
1378 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1379 else if (classname != "" && food_stage)
1380 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1381 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1382 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1383
1384 }
1385
1386 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1387 {
1389 if (food_item && food_item.GetFoodStage())
1390 return FoodStage.GetToxicity(food_item.GetFoodStage());
1391 else if (classname != "" && food_stage)
1392 return FoodStage.GetToxicity(null, food_stage, classname);
1393 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1394 return GetGame().ConfigGetFloat(class_path + " toxicity");
1395 }
1396
1397 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1398 {
1400 if (food_item && food_item.GetFoodStage())
1401 return FoodStage.GetAgents(food_item.GetFoodStage());
1402 else if (classname != "" && food_stage)
1403 return FoodStage.GetAgents(null, food_stage, classname);
1404 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1405 return GetGame().ConfigGetInt(class_path + " agents");
1406 }
1407
1408 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1409 {
1411 if (food_item && food_item.GetFoodStage())
1412 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1413 else if (classname != "" && food_stage)
1414 return FoodStage.GetDigestibility(null, food_stage, classname);
1415 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1416 return GetGame().ConfigGetInt(class_path + " digestibility");
1417 }
1418
1420 {
1422 }
1423
1424 //================================================================
1425 // FOOD STAGING
1426 //================================================================
1428 {
1429 return GetFoodStage().GetFoodStageType();
1430 }
1431
1432 //food stage states
1433 bool IsFoodRaw()
1434 {
1435 if (GetFoodStage())
1436 return GetFoodStage().IsFoodRaw();
1437
1438 return false;
1439 }
1440
1441 bool IsFoodBaked()
1442 {
1443 if (GetFoodStage())
1444 return GetFoodStage().IsFoodBaked();
1445
1446 return false;
1447 }
1448
1449 bool IsFoodBoiled()
1450 {
1451 if (GetFoodStage())
1452 return GetFoodStage().IsFoodBoiled();
1453
1454 return false;
1455 }
1456
1457 bool IsFoodDried()
1458 {
1459 if (GetFoodStage())
1460 return GetFoodStage().IsFoodDried();
1461
1462 return false;
1463 }
1464
1465 bool IsFoodBurned()
1466 {
1467 if (GetFoodStage())
1468 return GetFoodStage().IsFoodBurned();
1469
1470 return false;
1471 }
1472
1473 bool IsFoodRotten()
1474 {
1475 if (GetFoodStage())
1476 return GetFoodStage().IsFoodRotten();
1477
1478 return false;
1479 }
1480
1481 //food stage change
1483 {
1484 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1485 }
1486
1488 {
1489 return GetFoodStage().GetNextFoodStageType(cooking_method);
1490 }
1491
1493 {
1494 return GetFoodStage().GetFoodStageName(food_stage_type);
1495 }
1496
1498 {
1499 return GetFoodStage().CanChangeToNewStage(cooking_method);
1500 }
1501
1502 //Use this to receive food stage from another Edible_Base
1504 {
1505 if (!source.HasFoodStage())
1506 return;
1507 m_LastDecayStage = source.GetLastDecayStage();
1508 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1509 m_DecayTimer = source.GetDecayTimer();
1510 m_DecayDelta = source.GetDecayDelta();
1511 }
1512
1513 //================================================================
1514 // COOKING
1515 //================================================================
1516 //cooking time
1517 float GetCookingTime()
1518 {
1519 return GetFoodStage().GetCookingTime();
1520 }
1521
1522 void SetCookingTime(float time)
1523 {
1524 GetFoodStage().SetCookingTime(time);
1525
1526 //synchronize when calling on server
1527 Synchronize();
1528 }
1529
1530 //replace edible with new item (opening cans)
1531 void ReplaceEdibleWithNew(string typeName)
1532 {
1533 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1534 if (player)
1535 {
1537 player.ServerReplaceItemInHandsWithNew(lambda);
1538 }
1539 else
1540 Error("ReplaceEdibleWithNew - cannot use edible without player");
1541 }
1542
1543 override void SetActions()
1544 {
1545 super.SetActions();
1546
1547 AddAction(ActionAttach);
1549 }
1550
1551 protected void SoundCookingStart(string sound_name)
1552 {
1553#ifndef SERVER
1555 {
1557
1560 }
1561#endif
1562 }
1563
1564 protected void SoundCookingStop()
1565 {
1566#ifndef SERVER
1568 {
1571 m_SoundPlaying = "";
1572 }
1573#endif
1574 }
1575
1576 override bool CanHaveTemperature()
1577 {
1578 return true;
1579 }
1580
1581 override bool CanDecay()
1582 {
1583 return false;
1584 }
1585
1586 override bool CanProcessDecay()
1587 {
1588 return (GetFoodStageType() != FoodStageType.ROTTEN);
1589 }
1590
1591 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1592 {
1593 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1594 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1595 if (hasRootAsPlayer)
1597
1598 /*Print( "-------------------------" );
1599 Print( this );
1600 Print( m_DecayTimer );
1601 Print( m_DecayDelta );
1602 Print( m_LastDecayStage );*/
1603
1604 if (IsFruit() || IsMushroom())
1605 {
1606 // fruit, vegetables and mushrooms
1608 {
1609 switch (GetFoodStageType())
1610 {
1611 case FoodStageType.RAW:
1614 break;
1615
1616 case FoodStageType.BOILED:
1619 break;
1620
1621 case FoodStageType.BAKED:
1624 break;
1625
1626 case FoodStageType.DRIED:
1627 case FoodStageType.BURNED:
1628 case FoodStageType.ROTTEN:
1629 default:
1630 m_DecayTimer = -1;
1632 return;
1633 }
1634
1635 //m_DecayTimer = m_DecayTimer / 1000.0;
1636 }
1637
1639
1640 if (m_DecayTimer <= 0)
1641 {
1642 if (m_LastDecayStage != FoodStageType.NONE)
1643 {
1644 // switch to decayed stage
1645 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1648 {
1649 int rng = Math.RandomIntInclusive(0, 100);
1652 else
1653 {
1656 else
1658 }
1659 }
1660 }
1661 }
1662
1663 }
1664 else if (IsMeat())
1665 {
1666 // meat
1668 {
1669 switch (GetFoodStageType())
1670 {
1671 case FoodStageType.RAW:
1674 break;
1675
1676 case FoodStageType.BOILED:
1679 break;
1680
1681 case FoodStageType.BAKED:
1684 break;
1685
1686 case FoodStageType.DRIED:
1689 break;
1690
1691 case FoodStageType.BURNED:
1692 case FoodStageType.ROTTEN:
1693 default:
1694 m_DecayTimer = -1;
1696 return;
1697 }
1698 }
1699
1701
1702 if (m_DecayTimer <= 0)
1703 {
1704 if (m_LastDecayStage != FoodStageType.NONE)
1705 {
1706 // switch to decayed stage
1709 }
1710 }
1711 }
1712 else if (IsCorpse())
1713 {
1714 // corpse
1716 {
1717 switch (GetFoodStageType())
1718 {
1719 case FoodStageType.RAW:
1722 break;
1723
1724 case FoodStageType.BURNED:
1725 case FoodStageType.ROTTEN:
1726 default:
1727 m_DecayTimer = -1;
1729 return;
1730 }
1731 }
1732
1734
1735 if (m_DecayTimer <= 0)
1736 {
1737 if (m_LastDecayStage != FoodStageType.NONE)
1738 {
1739 // switch to decayed stage
1742 }
1743 }
1744 }
1745 else
1746 {
1747 // opened cans
1749
1750 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1751 {
1754 //m_DecayTimer = m_DecayTimer / 1000.0;
1755 }
1756 else
1757 {
1758 if (m_DecayTimer <= 0)
1759 {
1760 InsertAgent(eAgents.FOOD_POISON, 1);
1761 m_DecayTimer = -1;
1762 }
1763 }
1764 }
1765
1766 m_DecayDelta = 0.0;
1767 }
1768
1770 {
1771 super.GetDebugActions(outputList);
1772
1773 if (HasFoodStage())
1774 {
1775 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1776 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1777 }
1778 }
1779
1780 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1781 {
1782 super.OnAction(action_id, player, ctx);
1783
1784 if (GetGame().IsServer())
1785 {
1786 if (action_id == EActions.FOOD_STAGE_PREV)
1787 {
1789 if (food_stage_prev <= 0)
1790 food_stage_prev = FoodStageType.COUNT - 1;
1792 return true;
1793 }
1794 else if (action_id == EActions.FOOD_STAGE_NEXT)
1795 {
1797 if (food_stage_next >= FoodStageType.COUNT)
1800 return true;
1801 }
1802 }
1803 return false;
1804 }
1805
1806 override string GetDebugText()
1807 {
1808 string debug_output;
1809
1810 debug_output = super.GetDebugText();
1811
1812 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1813 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1814
1815 return debug_output;
1816 }
1817
1818 //================================================================
1819 // GENERAL GETTERS
1820 //================================================================
1821
1822 float GetDecayTimer()
1823 {
1824 return m_DecayTimer;
1825 }
1826
1827 float GetDecayDelta()
1828 {
1829 return m_DecayDelta;
1830 }
1831
1833 {
1834 return m_LastDecayStage;
1835 }
1836}
1837
1839{
1841};

◆ GetFoodTotalVolume()

static float ReplaceEdibleWithNewLambda::GetFoodTotalVolume ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1002 of file Edible_Base.c.

1002 : ItemBase
1003{
1004 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1005
1006 const string SOUND_BAKING_START = "Baking_SoundSet";
1007 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1008 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1009
1010 protected bool m_MakeCookingSounds;
1011 protected SoundOnVehicle m_SoundCooking;
1013 protected string m_SoundPlaying;
1015 protected float m_DecayTimer;
1016 protected float m_DecayDelta = 0.0;
1018
1020
1021 void Edible_Base()
1022 {
1023 if (HasFoodStage())
1024 {
1025 m_FoodStage = new FoodStage(this);
1026
1027 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1028 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1029 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1030 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1031 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1032
1033 m_SoundPlaying = "";
1035 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1036 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1037 }
1038 }
1039
1040 override void EEInit()
1041 {
1042 super.EEInit();
1043
1044 UpdateVisuals();
1045 }
1046
1047 override void EEDelete(EntityAI parent)
1048 {
1049 super.EEDelete(parent);
1050
1051 RemoveAudio();
1052 }
1053
1055 {
1056 super.EEItemLocationChanged(oldLoc, newLoc);
1057
1059 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1060 {
1061 switch (oldLoc.GetParent().GetType())
1062 {
1063 case "FryingPan":
1064 case "Pot":
1065 case "Cauldron":
1066 case "SharpWoodenStick":
1067 MakeSoundsOnClient(false);
1068 break;
1069 }
1070
1072 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1073 MakeSoundsOnClient(false);
1074 }
1075 }
1076
1077 void UpdateVisuals()
1078 {
1079 if (GetFoodStage())
1080 GetFoodStage().UpdateVisuals();
1081 }
1082
1083 bool Consume(float amount, PlayerBase consumer)
1084 {
1085 AddQuantity(-amount, false, false);
1086 OnConsume(amount, consumer);
1087
1088 return true;
1089 }
1090
1091 void OnConsume(float amount, PlayerBase consumer);
1092
1093 //food staging
1094 override bool CanBeCooked()
1095 {
1096 return false;
1097 }
1098
1099 override bool CanBeCookedOnStick()
1100 {
1101 return false;
1102 }
1103
1104 //================================================================
1105 // SYNCHRONIZATION
1106 //================================================================
1107 void Synchronize()
1108 {
1109 SetSynchDirty();
1110
1111 if (GetGame().IsMultiplayer())
1112 UpdateVisuals();
1113 }
1114
1115 override void OnVariablesSynchronized()
1116 {
1117 super.OnVariablesSynchronized();
1118
1119 UpdateVisuals();
1120
1121 //update audio
1123 RefreshAudio();
1124 else
1125 RemoveAudio();
1126 }
1127
1128 //================================================================
1129 // AUDIO EFFECTS (WHEN ON DCS)
1130 //================================================================
1132 {
1135
1136 Synchronize();
1137 }
1138
1139 protected void RefreshAudio()
1140 {
1141 string soundName = "";
1142
1144
1145 switch (GetFoodStageType())
1146 {
1147 case FoodStageType.RAW:
1149 if (nextFoodState == FoodStageType.BOILED)
1150 soundName = "";
1151 break;
1152 case FoodStageType.BAKED:
1154 break;
1155 case FoodStageType.BURNED:
1157 break;
1158 default:
1159 soundName = "";
1160 break;
1161 }
1162
1164 }
1165
1166 protected void RemoveAudio()
1167 {
1168 m_MakeCookingSounds = false;
1170 }
1171
1172 //================================================================
1173 // SERIALIZATION
1174 //================================================================
1175 override void OnStoreSave(ParamsWriteContext ctx)
1176 {
1177 super.OnStoreSave(ctx);
1178
1179 if (GetFoodStage())
1180 GetFoodStage().OnStoreSave(ctx);
1181
1182 // food decay
1183 ctx.Write(m_DecayTimer);
1184 ctx.Write(m_LastDecayStage);
1185 }
1186
1187 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1188 {
1189 if (!super.OnStoreLoad(ctx, version))
1190 return false;
1191
1192 if (GetFoodStage())
1193 {
1194 if (!GetFoodStage().OnStoreLoad(ctx, version))
1195 return false;
1196 }
1197
1198 if (version >= 115)
1199 {
1200 if (!ctx.Read(m_DecayTimer))
1201 {
1202 m_DecayTimer = 0.0;
1203 return false;
1204 }
1205 if (!ctx.Read(m_LastDecayStage))
1206 {
1208 return false;
1209 }
1210 }
1211
1212 return true;
1213 }
1214
1215 override void AfterStoreLoad()
1216 {
1217 super.AfterStoreLoad();
1218
1219 Synchronize();
1220 }
1221
1222 //get food stage
1224 {
1225 return m_FoodStage;
1226 }
1227
1228 //food types
1229 override bool IsMeat()
1230 {
1231 return false;
1232 }
1233
1234 override bool IsCorpse()
1235 {
1236 return false;
1237 }
1238
1239 override bool IsFruit()
1240 {
1241 return false;
1242 }
1243
1244 override bool IsMushroom()
1245 {
1246 return false;
1247 }
1248
1249 //================================================================
1250 // NUTRITIONAL VALUES
1251 //================================================================
1252 //food properties
1253 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1254 {
1256 if (food_item && food_item.GetFoodStage())
1257 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1258 else if (classname != "" && food_stage)
1259 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1260 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1261 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1262
1263 }
1264
1265 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1266 {
1268 if (food_item && food_item.GetFoodStage())
1269 return FoodStage.GetEnergy(food_item.GetFoodStage());
1270 else if (classname != "" && food_stage)
1271 return FoodStage.GetEnergy(null, food_stage, classname);
1272 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1273 return GetGame().ConfigGetFloat(class_path + " energy");
1274 }
1275
1276 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1277 {
1279 if (food_item && food_item.GetFoodStage())
1280 return FoodStage.GetWater(food_item.GetFoodStage());
1281 else if (classname != "" && food_stage)
1282 return FoodStage.GetWater(null, food_stage, classname);
1283 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1284 return GetGame().ConfigGetFloat(class_path + " water");
1285 }
1286
1287 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1288 {
1290 if (food_item && food_item.GetFoodStage())
1291 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1292 else if (classname != "" && food_stage)
1293 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1294 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1295 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1296
1297 }
1298
1299 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1300 {
1302 if (food_item && food_item.GetFoodStage())
1303 return FoodStage.GetToxicity(food_item.GetFoodStage());
1304 else if (classname != "" && food_stage)
1305 return FoodStage.GetToxicity(null, food_stage, classname);
1306 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1307 return GetGame().ConfigGetFloat(class_path + " toxicity");
1308 }
1309
1310 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1311 {
1313 if (food_item && food_item.GetFoodStage())
1314 return FoodStage.GetAgents(food_item.GetFoodStage());
1315 else if (classname != "" && food_stage)
1316 return FoodStage.GetAgents(null, food_stage, classname);
1317 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1318 return GetGame().ConfigGetInt(class_path + " agents");
1319 }
1320
1321 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1322 {
1324 if (food_item && food_item.GetFoodStage())
1325 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1326 else if (classname != "" && food_stage)
1327 return FoodStage.GetDigestibility(null, food_stage, classname);
1328 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1329 return GetGame().ConfigGetInt(class_path + " digestibility");
1330 }
1331
1333 {
1335 }
1336
1337 //================================================================
1338 // FOOD STAGING
1339 //================================================================
1341 {
1342 return GetFoodStage().GetFoodStageType();
1343 }
1344
1345 //food stage states
1346 bool IsFoodRaw()
1347 {
1348 if (GetFoodStage())
1349 return GetFoodStage().IsFoodRaw();
1350
1351 return false;
1352 }
1353
1354 bool IsFoodBaked()
1355 {
1356 if (GetFoodStage())
1357 return GetFoodStage().IsFoodBaked();
1358
1359 return false;
1360 }
1361
1362 bool IsFoodBoiled()
1363 {
1364 if (GetFoodStage())
1365 return GetFoodStage().IsFoodBoiled();
1366
1367 return false;
1368 }
1369
1370 bool IsFoodDried()
1371 {
1372 if (GetFoodStage())
1373 return GetFoodStage().IsFoodDried();
1374
1375 return false;
1376 }
1377
1378 bool IsFoodBurned()
1379 {
1380 if (GetFoodStage())
1381 return GetFoodStage().IsFoodBurned();
1382
1383 return false;
1384 }
1385
1386 bool IsFoodRotten()
1387 {
1388 if (GetFoodStage())
1389 return GetFoodStage().IsFoodRotten();
1390
1391 return false;
1392 }
1393
1394 //food stage change
1396 {
1397 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1398 }
1399
1401 {
1402 return GetFoodStage().GetNextFoodStageType(cooking_method);
1403 }
1404
1406 {
1407 return GetFoodStage().GetFoodStageName(food_stage_type);
1408 }
1409
1411 {
1412 return GetFoodStage().CanChangeToNewStage(cooking_method);
1413 }
1414
1415 //Use this to receive food stage from another Edible_Base
1417 {
1418 if (!source.HasFoodStage())
1419 return;
1420 m_LastDecayStage = source.GetLastDecayStage();
1421 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1422 m_DecayTimer = source.GetDecayTimer();
1423 m_DecayDelta = source.GetDecayDelta();
1424 }
1425
1426 //================================================================
1427 // COOKING
1428 //================================================================
1429 //cooking time
1430 float GetCookingTime()
1431 {
1432 return GetFoodStage().GetCookingTime();
1433 }
1434
1435 void SetCookingTime(float time)
1436 {
1437 GetFoodStage().SetCookingTime(time);
1438
1439 //synchronize when calling on server
1440 Synchronize();
1441 }
1442
1443 //replace edible with new item (opening cans)
1444 void ReplaceEdibleWithNew(string typeName)
1445 {
1446 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1447 if (player)
1448 {
1450 player.ServerReplaceItemInHandsWithNew(lambda);
1451 }
1452 else
1453 Error("ReplaceEdibleWithNew - cannot use edible without player");
1454 }
1455
1456 override void SetActions()
1457 {
1458 super.SetActions();
1459
1460 AddAction(ActionAttach);
1462 }
1463
1464 protected void SoundCookingStart(string sound_name)
1465 {
1466#ifndef SERVER
1468 {
1470
1473 }
1474#endif
1475 }
1476
1477 protected void SoundCookingStop()
1478 {
1479#ifndef SERVER
1481 {
1484 m_SoundPlaying = "";
1485 }
1486#endif
1487 }
1488
1489 override bool CanHaveTemperature()
1490 {
1491 return true;
1492 }
1493
1494 override bool CanDecay()
1495 {
1496 return false;
1497 }
1498
1499 override bool CanProcessDecay()
1500 {
1501 return (GetFoodStageType() != FoodStageType.ROTTEN);
1502 }
1503
1504 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1505 {
1506 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1507 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1508 if (hasRootAsPlayer)
1510
1511 /*Print( "-------------------------" );
1512 Print( this );
1513 Print( m_DecayTimer );
1514 Print( m_DecayDelta );
1515 Print( m_LastDecayStage );*/
1516
1517 if (IsFruit() || IsMushroom())
1518 {
1519 // fruit, vegetables and mushrooms
1521 {
1522 switch (GetFoodStageType())
1523 {
1524 case FoodStageType.RAW:
1527 break;
1528
1529 case FoodStageType.BOILED:
1532 break;
1533
1534 case FoodStageType.BAKED:
1537 break;
1538
1539 case FoodStageType.DRIED:
1540 case FoodStageType.BURNED:
1541 case FoodStageType.ROTTEN:
1542 default:
1543 m_DecayTimer = -1;
1545 return;
1546 }
1547
1548 //m_DecayTimer = m_DecayTimer / 1000.0;
1549 }
1550
1552
1553 if (m_DecayTimer <= 0)
1554 {
1555 if (m_LastDecayStage != FoodStageType.NONE)
1556 {
1557 // switch to decayed stage
1558 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1561 {
1562 int rng = Math.RandomIntInclusive(0, 100);
1565 else
1566 {
1569 else
1571 }
1572 }
1573 }
1574 }
1575
1576 }
1577 else if (IsMeat())
1578 {
1579 // meat
1581 {
1582 switch (GetFoodStageType())
1583 {
1584 case FoodStageType.RAW:
1587 break;
1588
1589 case FoodStageType.BOILED:
1592 break;
1593
1594 case FoodStageType.BAKED:
1597 break;
1598
1599 case FoodStageType.DRIED:
1602 break;
1603
1604 case FoodStageType.BURNED:
1605 case FoodStageType.ROTTEN:
1606 default:
1607 m_DecayTimer = -1;
1609 return;
1610 }
1611 }
1612
1614
1615 if (m_DecayTimer <= 0)
1616 {
1617 if (m_LastDecayStage != FoodStageType.NONE)
1618 {
1619 // switch to decayed stage
1622 }
1623 }
1624 }
1625 else if (IsCorpse())
1626 {
1627 // corpse
1629 {
1630 switch (GetFoodStageType())
1631 {
1632 case FoodStageType.RAW:
1635 break;
1636
1637 case FoodStageType.BURNED:
1638 case FoodStageType.ROTTEN:
1639 default:
1640 m_DecayTimer = -1;
1642 return;
1643 }
1644 }
1645
1647
1648 if (m_DecayTimer <= 0)
1649 {
1650 if (m_LastDecayStage != FoodStageType.NONE)
1651 {
1652 // switch to decayed stage
1655 }
1656 }
1657 }
1658 else
1659 {
1660 // opened cans
1662
1663 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1664 {
1667 //m_DecayTimer = m_DecayTimer / 1000.0;
1668 }
1669 else
1670 {
1671 if (m_DecayTimer <= 0)
1672 {
1673 InsertAgent(eAgents.FOOD_POISON, 1);
1674 m_DecayTimer = -1;
1675 }
1676 }
1677 }
1678
1679 m_DecayDelta = 0.0;
1680 }
1681
1683 {
1684 super.GetDebugActions(outputList);
1685
1686 if (HasFoodStage())
1687 {
1688 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1689 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1690 }
1691 }
1692
1693 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1694 {
1695 super.OnAction(action_id, player, ctx);
1696
1697 if (GetGame().IsServer())
1698 {
1699 if (action_id == EActions.FOOD_STAGE_PREV)
1700 {
1702 if (food_stage_prev <= 0)
1703 food_stage_prev = FoodStageType.COUNT - 1;
1705 return true;
1706 }
1707 else if (action_id == EActions.FOOD_STAGE_NEXT)
1708 {
1710 if (food_stage_next >= FoodStageType.COUNT)
1713 return true;
1714 }
1715 }
1716 return false;
1717 }
1718
1719 override string GetDebugText()
1720 {
1721 string debug_output;
1722
1723 debug_output = super.GetDebugText();
1724
1725 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1726 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1727
1728 return debug_output;
1729 }
1730
1731 //================================================================
1732 // GENERAL GETTERS
1733 //================================================================
1734
1735 float GetDecayTimer()
1736 {
1737 return m_DecayTimer;
1738 }
1739
1740 float GetDecayDelta()
1741 {
1742 return m_DecayDelta;
1743 }
1744
1746 {
1747 return m_LastDecayStage;
1748 }
1749}
1750
1752{
1754};

◆ GetFoodToxicity()

static float ReplaceEdibleWithNewLambda::GetFoodToxicity ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1048 of file Edible_Base.c.

1048 : ItemBase
1049{
1050 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1051
1052 const string SOUND_BAKING_START = "Baking_SoundSet";
1053 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1054 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1055
1056 protected bool m_MakeCookingSounds;
1057 protected SoundOnVehicle m_SoundCooking;
1059 protected string m_SoundPlaying;
1061 protected float m_DecayTimer;
1062 protected float m_DecayDelta = 0.0;
1064
1066
1067 void Edible_Base()
1068 {
1069 if (HasFoodStage())
1070 {
1071 m_FoodStage = new FoodStage(this);
1072
1073 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1074 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1075 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1076 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1077 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1078
1079 m_SoundPlaying = "";
1081 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1082 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1083 }
1084 }
1085
1086 override void EEInit()
1087 {
1088 super.EEInit();
1089
1090 UpdateVisuals();
1091 }
1092
1093 override void EEDelete(EntityAI parent)
1094 {
1095 super.EEDelete(parent);
1096
1097 RemoveAudio();
1098 }
1099
1101 {
1102 super.EEItemLocationChanged(oldLoc, newLoc);
1103
1105 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1106 {
1107 switch (oldLoc.GetParent().GetType())
1108 {
1109 case "FryingPan":
1110 case "Pot":
1111 case "Cauldron":
1112 case "SharpWoodenStick":
1113 MakeSoundsOnClient(false);
1114 break;
1115 }
1116
1118 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1119 MakeSoundsOnClient(false);
1120 }
1121 }
1122
1123 void UpdateVisuals()
1124 {
1125 if (GetFoodStage())
1126 GetFoodStage().UpdateVisuals();
1127 }
1128
1129 bool Consume(float amount, PlayerBase consumer)
1130 {
1131 AddQuantity(-amount, false, false);
1132 OnConsume(amount, consumer);
1133
1134 return true;
1135 }
1136
1137 void OnConsume(float amount, PlayerBase consumer);
1138
1139 //food staging
1140 override bool CanBeCooked()
1141 {
1142 return false;
1143 }
1144
1145 override bool CanBeCookedOnStick()
1146 {
1147 return false;
1148 }
1149
1150 //================================================================
1151 // SYNCHRONIZATION
1152 //================================================================
1153 void Synchronize()
1154 {
1155 SetSynchDirty();
1156
1157 if (GetGame().IsMultiplayer())
1158 UpdateVisuals();
1159 }
1160
1161 override void OnVariablesSynchronized()
1162 {
1163 super.OnVariablesSynchronized();
1164
1165 UpdateVisuals();
1166
1167 //update audio
1169 RefreshAudio();
1170 else
1171 RemoveAudio();
1172 }
1173
1174 //================================================================
1175 // AUDIO EFFECTS (WHEN ON DCS)
1176 //================================================================
1178 {
1181
1182 Synchronize();
1183 }
1184
1185 protected void RefreshAudio()
1186 {
1187 string soundName = "";
1188
1190
1191 switch (GetFoodStageType())
1192 {
1193 case FoodStageType.RAW:
1195 if (nextFoodState == FoodStageType.BOILED)
1196 soundName = "";
1197 break;
1198 case FoodStageType.BAKED:
1200 break;
1201 case FoodStageType.BURNED:
1203 break;
1204 default:
1205 soundName = "";
1206 break;
1207 }
1208
1210 }
1211
1212 protected void RemoveAudio()
1213 {
1214 m_MakeCookingSounds = false;
1216 }
1217
1218 //================================================================
1219 // SERIALIZATION
1220 //================================================================
1221 override void OnStoreSave(ParamsWriteContext ctx)
1222 {
1223 super.OnStoreSave(ctx);
1224
1225 if (GetFoodStage())
1226 GetFoodStage().OnStoreSave(ctx);
1227
1228 // food decay
1229 ctx.Write(m_DecayTimer);
1230 ctx.Write(m_LastDecayStage);
1231 }
1232
1233 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1234 {
1235 if (!super.OnStoreLoad(ctx, version))
1236 return false;
1237
1238 if (GetFoodStage())
1239 {
1240 if (!GetFoodStage().OnStoreLoad(ctx, version))
1241 return false;
1242 }
1243
1244 if (version >= 115)
1245 {
1246 if (!ctx.Read(m_DecayTimer))
1247 {
1248 m_DecayTimer = 0.0;
1249 return false;
1250 }
1251 if (!ctx.Read(m_LastDecayStage))
1252 {
1254 return false;
1255 }
1256 }
1257
1258 return true;
1259 }
1260
1261 override void AfterStoreLoad()
1262 {
1263 super.AfterStoreLoad();
1264
1265 Synchronize();
1266 }
1267
1268 //get food stage
1270 {
1271 return m_FoodStage;
1272 }
1273
1274 //food types
1275 override bool IsMeat()
1276 {
1277 return false;
1278 }
1279
1280 override bool IsCorpse()
1281 {
1282 return false;
1283 }
1284
1285 override bool IsFruit()
1286 {
1287 return false;
1288 }
1289
1290 override bool IsMushroom()
1291 {
1292 return false;
1293 }
1294
1295 //================================================================
1296 // NUTRITIONAL VALUES
1297 //================================================================
1298 //food properties
1299 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1300 {
1302 if (food_item && food_item.GetFoodStage())
1303 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1304 else if (classname != "" && food_stage)
1305 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1306 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1307 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1308
1309 }
1310
1311 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1312 {
1314 if (food_item && food_item.GetFoodStage())
1315 return FoodStage.GetEnergy(food_item.GetFoodStage());
1316 else if (classname != "" && food_stage)
1317 return FoodStage.GetEnergy(null, food_stage, classname);
1318 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1319 return GetGame().ConfigGetFloat(class_path + " energy");
1320 }
1321
1322 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1323 {
1325 if (food_item && food_item.GetFoodStage())
1326 return FoodStage.GetWater(food_item.GetFoodStage());
1327 else if (classname != "" && food_stage)
1328 return FoodStage.GetWater(null, food_stage, classname);
1329 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1330 return GetGame().ConfigGetFloat(class_path + " water");
1331 }
1332
1333 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1334 {
1336 if (food_item && food_item.GetFoodStage())
1337 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1338 else if (classname != "" && food_stage)
1339 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1340 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1341 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1342
1343 }
1344
1345 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1346 {
1348 if (food_item && food_item.GetFoodStage())
1349 return FoodStage.GetToxicity(food_item.GetFoodStage());
1350 else if (classname != "" && food_stage)
1351 return FoodStage.GetToxicity(null, food_stage, classname);
1352 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1353 return GetGame().ConfigGetFloat(class_path + " toxicity");
1354 }
1355
1356 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1357 {
1359 if (food_item && food_item.GetFoodStage())
1360 return FoodStage.GetAgents(food_item.GetFoodStage());
1361 else if (classname != "" && food_stage)
1362 return FoodStage.GetAgents(null, food_stage, classname);
1363 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1364 return GetGame().ConfigGetInt(class_path + " agents");
1365 }
1366
1367 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1368 {
1370 if (food_item && food_item.GetFoodStage())
1371 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1372 else if (classname != "" && food_stage)
1373 return FoodStage.GetDigestibility(null, food_stage, classname);
1374 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1375 return GetGame().ConfigGetInt(class_path + " digestibility");
1376 }
1377
1379 {
1381 }
1382
1383 //================================================================
1384 // FOOD STAGING
1385 //================================================================
1387 {
1388 return GetFoodStage().GetFoodStageType();
1389 }
1390
1391 //food stage states
1392 bool IsFoodRaw()
1393 {
1394 if (GetFoodStage())
1395 return GetFoodStage().IsFoodRaw();
1396
1397 return false;
1398 }
1399
1400 bool IsFoodBaked()
1401 {
1402 if (GetFoodStage())
1403 return GetFoodStage().IsFoodBaked();
1404
1405 return false;
1406 }
1407
1408 bool IsFoodBoiled()
1409 {
1410 if (GetFoodStage())
1411 return GetFoodStage().IsFoodBoiled();
1412
1413 return false;
1414 }
1415
1416 bool IsFoodDried()
1417 {
1418 if (GetFoodStage())
1419 return GetFoodStage().IsFoodDried();
1420
1421 return false;
1422 }
1423
1424 bool IsFoodBurned()
1425 {
1426 if (GetFoodStage())
1427 return GetFoodStage().IsFoodBurned();
1428
1429 return false;
1430 }
1431
1432 bool IsFoodRotten()
1433 {
1434 if (GetFoodStage())
1435 return GetFoodStage().IsFoodRotten();
1436
1437 return false;
1438 }
1439
1440 //food stage change
1442 {
1443 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1444 }
1445
1447 {
1448 return GetFoodStage().GetNextFoodStageType(cooking_method);
1449 }
1450
1452 {
1453 return GetFoodStage().GetFoodStageName(food_stage_type);
1454 }
1455
1457 {
1458 return GetFoodStage().CanChangeToNewStage(cooking_method);
1459 }
1460
1461 //Use this to receive food stage from another Edible_Base
1463 {
1464 if (!source.HasFoodStage())
1465 return;
1466 m_LastDecayStage = source.GetLastDecayStage();
1467 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1468 m_DecayTimer = source.GetDecayTimer();
1469 m_DecayDelta = source.GetDecayDelta();
1470 }
1471
1472 //================================================================
1473 // COOKING
1474 //================================================================
1475 //cooking time
1476 float GetCookingTime()
1477 {
1478 return GetFoodStage().GetCookingTime();
1479 }
1480
1481 void SetCookingTime(float time)
1482 {
1483 GetFoodStage().SetCookingTime(time);
1484
1485 //synchronize when calling on server
1486 Synchronize();
1487 }
1488
1489 //replace edible with new item (opening cans)
1490 void ReplaceEdibleWithNew(string typeName)
1491 {
1492 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1493 if (player)
1494 {
1496 player.ServerReplaceItemInHandsWithNew(lambda);
1497 }
1498 else
1499 Error("ReplaceEdibleWithNew - cannot use edible without player");
1500 }
1501
1502 override void SetActions()
1503 {
1504 super.SetActions();
1505
1506 AddAction(ActionAttach);
1508 }
1509
1510 protected void SoundCookingStart(string sound_name)
1511 {
1512#ifndef SERVER
1514 {
1516
1519 }
1520#endif
1521 }
1522
1523 protected void SoundCookingStop()
1524 {
1525#ifndef SERVER
1527 {
1530 m_SoundPlaying = "";
1531 }
1532#endif
1533 }
1534
1535 override bool CanHaveTemperature()
1536 {
1537 return true;
1538 }
1539
1540 override bool CanDecay()
1541 {
1542 return false;
1543 }
1544
1545 override bool CanProcessDecay()
1546 {
1547 return (GetFoodStageType() != FoodStageType.ROTTEN);
1548 }
1549
1550 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1551 {
1552 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1553 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1554 if (hasRootAsPlayer)
1556
1557 /*Print( "-------------------------" );
1558 Print( this );
1559 Print( m_DecayTimer );
1560 Print( m_DecayDelta );
1561 Print( m_LastDecayStage );*/
1562
1563 if (IsFruit() || IsMushroom())
1564 {
1565 // fruit, vegetables and mushrooms
1567 {
1568 switch (GetFoodStageType())
1569 {
1570 case FoodStageType.RAW:
1573 break;
1574
1575 case FoodStageType.BOILED:
1578 break;
1579
1580 case FoodStageType.BAKED:
1583 break;
1584
1585 case FoodStageType.DRIED:
1586 case FoodStageType.BURNED:
1587 case FoodStageType.ROTTEN:
1588 default:
1589 m_DecayTimer = -1;
1591 return;
1592 }
1593
1594 //m_DecayTimer = m_DecayTimer / 1000.0;
1595 }
1596
1598
1599 if (m_DecayTimer <= 0)
1600 {
1601 if (m_LastDecayStage != FoodStageType.NONE)
1602 {
1603 // switch to decayed stage
1604 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1607 {
1608 int rng = Math.RandomIntInclusive(0, 100);
1611 else
1612 {
1615 else
1617 }
1618 }
1619 }
1620 }
1621
1622 }
1623 else if (IsMeat())
1624 {
1625 // meat
1627 {
1628 switch (GetFoodStageType())
1629 {
1630 case FoodStageType.RAW:
1633 break;
1634
1635 case FoodStageType.BOILED:
1638 break;
1639
1640 case FoodStageType.BAKED:
1643 break;
1644
1645 case FoodStageType.DRIED:
1648 break;
1649
1650 case FoodStageType.BURNED:
1651 case FoodStageType.ROTTEN:
1652 default:
1653 m_DecayTimer = -1;
1655 return;
1656 }
1657 }
1658
1660
1661 if (m_DecayTimer <= 0)
1662 {
1663 if (m_LastDecayStage != FoodStageType.NONE)
1664 {
1665 // switch to decayed stage
1668 }
1669 }
1670 }
1671 else if (IsCorpse())
1672 {
1673 // corpse
1675 {
1676 switch (GetFoodStageType())
1677 {
1678 case FoodStageType.RAW:
1681 break;
1682
1683 case FoodStageType.BURNED:
1684 case FoodStageType.ROTTEN:
1685 default:
1686 m_DecayTimer = -1;
1688 return;
1689 }
1690 }
1691
1693
1694 if (m_DecayTimer <= 0)
1695 {
1696 if (m_LastDecayStage != FoodStageType.NONE)
1697 {
1698 // switch to decayed stage
1701 }
1702 }
1703 }
1704 else
1705 {
1706 // opened cans
1708
1709 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1710 {
1713 //m_DecayTimer = m_DecayTimer / 1000.0;
1714 }
1715 else
1716 {
1717 if (m_DecayTimer <= 0)
1718 {
1719 InsertAgent(eAgents.FOOD_POISON, 1);
1720 m_DecayTimer = -1;
1721 }
1722 }
1723 }
1724
1725 m_DecayDelta = 0.0;
1726 }
1727
1729 {
1730 super.GetDebugActions(outputList);
1731
1732 if (HasFoodStage())
1733 {
1734 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1735 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1736 }
1737 }
1738
1739 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1740 {
1741 super.OnAction(action_id, player, ctx);
1742
1743 if (GetGame().IsServer())
1744 {
1745 if (action_id == EActions.FOOD_STAGE_PREV)
1746 {
1748 if (food_stage_prev <= 0)
1749 food_stage_prev = FoodStageType.COUNT - 1;
1751 return true;
1752 }
1753 else if (action_id == EActions.FOOD_STAGE_NEXT)
1754 {
1756 if (food_stage_next >= FoodStageType.COUNT)
1759 return true;
1760 }
1761 }
1762 return false;
1763 }
1764
1765 override string GetDebugText()
1766 {
1767 string debug_output;
1768
1769 debug_output = super.GetDebugText();
1770
1771 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1772 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1773
1774 return debug_output;
1775 }
1776
1777 //================================================================
1778 // GENERAL GETTERS
1779 //================================================================
1780
1781 float GetDecayTimer()
1782 {
1783 return m_DecayTimer;
1784 }
1785
1786 float GetDecayDelta()
1787 {
1788 return m_DecayDelta;
1789 }
1790
1792 {
1793 return m_LastDecayStage;
1794 }
1795}
1796
1798{
1800};

◆ GetFoodWater()

static float ReplaceEdibleWithNewLambda::GetFoodWater ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1025 of file Edible_Base.c.

1025 : ItemBase
1026{
1027 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1028
1029 const string SOUND_BAKING_START = "Baking_SoundSet";
1030 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1031 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1032
1033 protected bool m_MakeCookingSounds;
1034 protected SoundOnVehicle m_SoundCooking;
1036 protected string m_SoundPlaying;
1038 protected float m_DecayTimer;
1039 protected float m_DecayDelta = 0.0;
1041
1043
1044 void Edible_Base()
1045 {
1046 if (HasFoodStage())
1047 {
1048 m_FoodStage = new FoodStage(this);
1049
1050 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1051 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1052 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1053 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1054 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1055
1056 m_SoundPlaying = "";
1058 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1059 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1060 }
1061 }
1062
1063 override void EEInit()
1064 {
1065 super.EEInit();
1066
1067 UpdateVisuals();
1068 }
1069
1070 override void EEDelete(EntityAI parent)
1071 {
1072 super.EEDelete(parent);
1073
1074 RemoveAudio();
1075 }
1076
1078 {
1079 super.EEItemLocationChanged(oldLoc, newLoc);
1080
1082 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1083 {
1084 switch (oldLoc.GetParent().GetType())
1085 {
1086 case "FryingPan":
1087 case "Pot":
1088 case "Cauldron":
1089 case "SharpWoodenStick":
1090 MakeSoundsOnClient(false);
1091 break;
1092 }
1093
1095 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1096 MakeSoundsOnClient(false);
1097 }
1098 }
1099
1100 void UpdateVisuals()
1101 {
1102 if (GetFoodStage())
1103 GetFoodStage().UpdateVisuals();
1104 }
1105
1106 bool Consume(float amount, PlayerBase consumer)
1107 {
1108 AddQuantity(-amount, false, false);
1109 OnConsume(amount, consumer);
1110
1111 return true;
1112 }
1113
1114 void OnConsume(float amount, PlayerBase consumer);
1115
1116 //food staging
1117 override bool CanBeCooked()
1118 {
1119 return false;
1120 }
1121
1122 override bool CanBeCookedOnStick()
1123 {
1124 return false;
1125 }
1126
1127 //================================================================
1128 // SYNCHRONIZATION
1129 //================================================================
1130 void Synchronize()
1131 {
1132 SetSynchDirty();
1133
1134 if (GetGame().IsMultiplayer())
1135 UpdateVisuals();
1136 }
1137
1138 override void OnVariablesSynchronized()
1139 {
1140 super.OnVariablesSynchronized();
1141
1142 UpdateVisuals();
1143
1144 //update audio
1146 RefreshAudio();
1147 else
1148 RemoveAudio();
1149 }
1150
1151 //================================================================
1152 // AUDIO EFFECTS (WHEN ON DCS)
1153 //================================================================
1155 {
1158
1159 Synchronize();
1160 }
1161
1162 protected void RefreshAudio()
1163 {
1164 string soundName = "";
1165
1167
1168 switch (GetFoodStageType())
1169 {
1170 case FoodStageType.RAW:
1172 if (nextFoodState == FoodStageType.BOILED)
1173 soundName = "";
1174 break;
1175 case FoodStageType.BAKED:
1177 break;
1178 case FoodStageType.BURNED:
1180 break;
1181 default:
1182 soundName = "";
1183 break;
1184 }
1185
1187 }
1188
1189 protected void RemoveAudio()
1190 {
1191 m_MakeCookingSounds = false;
1193 }
1194
1195 //================================================================
1196 // SERIALIZATION
1197 //================================================================
1198 override void OnStoreSave(ParamsWriteContext ctx)
1199 {
1200 super.OnStoreSave(ctx);
1201
1202 if (GetFoodStage())
1203 GetFoodStage().OnStoreSave(ctx);
1204
1205 // food decay
1206 ctx.Write(m_DecayTimer);
1207 ctx.Write(m_LastDecayStage);
1208 }
1209
1210 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1211 {
1212 if (!super.OnStoreLoad(ctx, version))
1213 return false;
1214
1215 if (GetFoodStage())
1216 {
1217 if (!GetFoodStage().OnStoreLoad(ctx, version))
1218 return false;
1219 }
1220
1221 if (version >= 115)
1222 {
1223 if (!ctx.Read(m_DecayTimer))
1224 {
1225 m_DecayTimer = 0.0;
1226 return false;
1227 }
1228 if (!ctx.Read(m_LastDecayStage))
1229 {
1231 return false;
1232 }
1233 }
1234
1235 return true;
1236 }
1237
1238 override void AfterStoreLoad()
1239 {
1240 super.AfterStoreLoad();
1241
1242 Synchronize();
1243 }
1244
1245 //get food stage
1247 {
1248 return m_FoodStage;
1249 }
1250
1251 //food types
1252 override bool IsMeat()
1253 {
1254 return false;
1255 }
1256
1257 override bool IsCorpse()
1258 {
1259 return false;
1260 }
1261
1262 override bool IsFruit()
1263 {
1264 return false;
1265 }
1266
1267 override bool IsMushroom()
1268 {
1269 return false;
1270 }
1271
1272 //================================================================
1273 // NUTRITIONAL VALUES
1274 //================================================================
1275 //food properties
1276 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1277 {
1279 if (food_item && food_item.GetFoodStage())
1280 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1281 else if (classname != "" && food_stage)
1282 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1283 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1284 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1285
1286 }
1287
1288 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1289 {
1291 if (food_item && food_item.GetFoodStage())
1292 return FoodStage.GetEnergy(food_item.GetFoodStage());
1293 else if (classname != "" && food_stage)
1294 return FoodStage.GetEnergy(null, food_stage, classname);
1295 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1296 return GetGame().ConfigGetFloat(class_path + " energy");
1297 }
1298
1299 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1300 {
1302 if (food_item && food_item.GetFoodStage())
1303 return FoodStage.GetWater(food_item.GetFoodStage());
1304 else if (classname != "" && food_stage)
1305 return FoodStage.GetWater(null, food_stage, classname);
1306 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1307 return GetGame().ConfigGetFloat(class_path + " water");
1308 }
1309
1310 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1311 {
1313 if (food_item && food_item.GetFoodStage())
1314 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1315 else if (classname != "" && food_stage)
1316 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1317 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1318 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1319
1320 }
1321
1322 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1323 {
1325 if (food_item && food_item.GetFoodStage())
1326 return FoodStage.GetToxicity(food_item.GetFoodStage());
1327 else if (classname != "" && food_stage)
1328 return FoodStage.GetToxicity(null, food_stage, classname);
1329 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1330 return GetGame().ConfigGetFloat(class_path + " toxicity");
1331 }
1332
1333 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1334 {
1336 if (food_item && food_item.GetFoodStage())
1337 return FoodStage.GetAgents(food_item.GetFoodStage());
1338 else if (classname != "" && food_stage)
1339 return FoodStage.GetAgents(null, food_stage, classname);
1340 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1341 return GetGame().ConfigGetInt(class_path + " agents");
1342 }
1343
1344 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1345 {
1347 if (food_item && food_item.GetFoodStage())
1348 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1349 else if (classname != "" && food_stage)
1350 return FoodStage.GetDigestibility(null, food_stage, classname);
1351 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1352 return GetGame().ConfigGetInt(class_path + " digestibility");
1353 }
1354
1356 {
1358 }
1359
1360 //================================================================
1361 // FOOD STAGING
1362 //================================================================
1364 {
1365 return GetFoodStage().GetFoodStageType();
1366 }
1367
1368 //food stage states
1369 bool IsFoodRaw()
1370 {
1371 if (GetFoodStage())
1372 return GetFoodStage().IsFoodRaw();
1373
1374 return false;
1375 }
1376
1377 bool IsFoodBaked()
1378 {
1379 if (GetFoodStage())
1380 return GetFoodStage().IsFoodBaked();
1381
1382 return false;
1383 }
1384
1385 bool IsFoodBoiled()
1386 {
1387 if (GetFoodStage())
1388 return GetFoodStage().IsFoodBoiled();
1389
1390 return false;
1391 }
1392
1393 bool IsFoodDried()
1394 {
1395 if (GetFoodStage())
1396 return GetFoodStage().IsFoodDried();
1397
1398 return false;
1399 }
1400
1401 bool IsFoodBurned()
1402 {
1403 if (GetFoodStage())
1404 return GetFoodStage().IsFoodBurned();
1405
1406 return false;
1407 }
1408
1409 bool IsFoodRotten()
1410 {
1411 if (GetFoodStage())
1412 return GetFoodStage().IsFoodRotten();
1413
1414 return false;
1415 }
1416
1417 //food stage change
1419 {
1420 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1421 }
1422
1424 {
1425 return GetFoodStage().GetNextFoodStageType(cooking_method);
1426 }
1427
1429 {
1430 return GetFoodStage().GetFoodStageName(food_stage_type);
1431 }
1432
1434 {
1435 return GetFoodStage().CanChangeToNewStage(cooking_method);
1436 }
1437
1438 //Use this to receive food stage from another Edible_Base
1440 {
1441 if (!source.HasFoodStage())
1442 return;
1443 m_LastDecayStage = source.GetLastDecayStage();
1444 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1445 m_DecayTimer = source.GetDecayTimer();
1446 m_DecayDelta = source.GetDecayDelta();
1447 }
1448
1449 //================================================================
1450 // COOKING
1451 //================================================================
1452 //cooking time
1453 float GetCookingTime()
1454 {
1455 return GetFoodStage().GetCookingTime();
1456 }
1457
1458 void SetCookingTime(float time)
1459 {
1460 GetFoodStage().SetCookingTime(time);
1461
1462 //synchronize when calling on server
1463 Synchronize();
1464 }
1465
1466 //replace edible with new item (opening cans)
1467 void ReplaceEdibleWithNew(string typeName)
1468 {
1469 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1470 if (player)
1471 {
1473 player.ServerReplaceItemInHandsWithNew(lambda);
1474 }
1475 else
1476 Error("ReplaceEdibleWithNew - cannot use edible without player");
1477 }
1478
1479 override void SetActions()
1480 {
1481 super.SetActions();
1482
1483 AddAction(ActionAttach);
1485 }
1486
1487 protected void SoundCookingStart(string sound_name)
1488 {
1489#ifndef SERVER
1491 {
1493
1496 }
1497#endif
1498 }
1499
1500 protected void SoundCookingStop()
1501 {
1502#ifndef SERVER
1504 {
1507 m_SoundPlaying = "";
1508 }
1509#endif
1510 }
1511
1512 override bool CanHaveTemperature()
1513 {
1514 return true;
1515 }
1516
1517 override bool CanDecay()
1518 {
1519 return false;
1520 }
1521
1522 override bool CanProcessDecay()
1523 {
1524 return (GetFoodStageType() != FoodStageType.ROTTEN);
1525 }
1526
1527 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1528 {
1529 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1530 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1531 if (hasRootAsPlayer)
1533
1534 /*Print( "-------------------------" );
1535 Print( this );
1536 Print( m_DecayTimer );
1537 Print( m_DecayDelta );
1538 Print( m_LastDecayStage );*/
1539
1540 if (IsFruit() || IsMushroom())
1541 {
1542 // fruit, vegetables and mushrooms
1544 {
1545 switch (GetFoodStageType())
1546 {
1547 case FoodStageType.RAW:
1550 break;
1551
1552 case FoodStageType.BOILED:
1555 break;
1556
1557 case FoodStageType.BAKED:
1560 break;
1561
1562 case FoodStageType.DRIED:
1563 case FoodStageType.BURNED:
1564 case FoodStageType.ROTTEN:
1565 default:
1566 m_DecayTimer = -1;
1568 return;
1569 }
1570
1571 //m_DecayTimer = m_DecayTimer / 1000.0;
1572 }
1573
1575
1576 if (m_DecayTimer <= 0)
1577 {
1578 if (m_LastDecayStage != FoodStageType.NONE)
1579 {
1580 // switch to decayed stage
1581 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1584 {
1585 int rng = Math.RandomIntInclusive(0, 100);
1588 else
1589 {
1592 else
1594 }
1595 }
1596 }
1597 }
1598
1599 }
1600 else if (IsMeat())
1601 {
1602 // meat
1604 {
1605 switch (GetFoodStageType())
1606 {
1607 case FoodStageType.RAW:
1610 break;
1611
1612 case FoodStageType.BOILED:
1615 break;
1616
1617 case FoodStageType.BAKED:
1620 break;
1621
1622 case FoodStageType.DRIED:
1625 break;
1626
1627 case FoodStageType.BURNED:
1628 case FoodStageType.ROTTEN:
1629 default:
1630 m_DecayTimer = -1;
1632 return;
1633 }
1634 }
1635
1637
1638 if (m_DecayTimer <= 0)
1639 {
1640 if (m_LastDecayStage != FoodStageType.NONE)
1641 {
1642 // switch to decayed stage
1645 }
1646 }
1647 }
1648 else if (IsCorpse())
1649 {
1650 // corpse
1652 {
1653 switch (GetFoodStageType())
1654 {
1655 case FoodStageType.RAW:
1658 break;
1659
1660 case FoodStageType.BURNED:
1661 case FoodStageType.ROTTEN:
1662 default:
1663 m_DecayTimer = -1;
1665 return;
1666 }
1667 }
1668
1670
1671 if (m_DecayTimer <= 0)
1672 {
1673 if (m_LastDecayStage != FoodStageType.NONE)
1674 {
1675 // switch to decayed stage
1678 }
1679 }
1680 }
1681 else
1682 {
1683 // opened cans
1685
1686 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1687 {
1690 //m_DecayTimer = m_DecayTimer / 1000.0;
1691 }
1692 else
1693 {
1694 if (m_DecayTimer <= 0)
1695 {
1696 InsertAgent(eAgents.FOOD_POISON, 1);
1697 m_DecayTimer = -1;
1698 }
1699 }
1700 }
1701
1702 m_DecayDelta = 0.0;
1703 }
1704
1706 {
1707 super.GetDebugActions(outputList);
1708
1709 if (HasFoodStage())
1710 {
1711 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1712 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1713 }
1714 }
1715
1716 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1717 {
1718 super.OnAction(action_id, player, ctx);
1719
1720 if (GetGame().IsServer())
1721 {
1722 if (action_id == EActions.FOOD_STAGE_PREV)
1723 {
1725 if (food_stage_prev <= 0)
1726 food_stage_prev = FoodStageType.COUNT - 1;
1728 return true;
1729 }
1730 else if (action_id == EActions.FOOD_STAGE_NEXT)
1731 {
1733 if (food_stage_next >= FoodStageType.COUNT)
1736 return true;
1737 }
1738 }
1739 return false;
1740 }
1741
1742 override string GetDebugText()
1743 {
1744 string debug_output;
1745
1746 debug_output = super.GetDebugText();
1747
1748 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1749 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1750
1751 return debug_output;
1752 }
1753
1754 //================================================================
1755 // GENERAL GETTERS
1756 //================================================================
1757
1758 float GetDecayTimer()
1759 {
1760 return m_DecayTimer;
1761 }
1762
1763 float GetDecayDelta()
1764 {
1765 return m_DecayDelta;
1766 }
1767
1769 {
1770 return m_LastDecayStage;
1771 }
1772}
1773
1775{
1777};

◆ GetLastDecayStage()

FoodStageType ReplaceEdibleWithNewLambda::GetLastDecayStage ( )
protected

Definition at line 1494 of file Edible_Base.c.

1494 : ItemBase
1495{
1496 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1497
1498 const string SOUND_BAKING_START = "Baking_SoundSet";
1499 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1500 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1501
1502 protected bool m_MakeCookingSounds;
1503 protected SoundOnVehicle m_SoundCooking;
1505 protected string m_SoundPlaying;
1507 protected float m_DecayTimer;
1508 protected float m_DecayDelta = 0.0;
1510
1512
1513 void Edible_Base()
1514 {
1515 if (HasFoodStage())
1516 {
1517 m_FoodStage = new FoodStage(this);
1518
1519 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1520 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1521 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1522 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1523 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1524
1525 m_SoundPlaying = "";
1527 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1528 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1529 }
1530 }
1531
1532 override void EEInit()
1533 {
1534 super.EEInit();
1535
1536 UpdateVisuals();
1537 }
1538
1539 override void EEDelete(EntityAI parent)
1540 {
1541 super.EEDelete(parent);
1542
1543 RemoveAudio();
1544 }
1545
1547 {
1548 super.EEItemLocationChanged(oldLoc, newLoc);
1549
1551 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1552 {
1553 switch (oldLoc.GetParent().GetType())
1554 {
1555 case "FryingPan":
1556 case "Pot":
1557 case "Cauldron":
1558 case "SharpWoodenStick":
1559 MakeSoundsOnClient(false);
1560 break;
1561 }
1562
1564 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1565 MakeSoundsOnClient(false);
1566 }
1567 }
1568
1569 void UpdateVisuals()
1570 {
1571 if (GetFoodStage())
1572 GetFoodStage().UpdateVisuals();
1573 }
1574
1575 bool Consume(float amount, PlayerBase consumer)
1576 {
1577 AddQuantity(-amount, false, false);
1578 OnConsume(amount, consumer);
1579
1580 return true;
1581 }
1582
1583 void OnConsume(float amount, PlayerBase consumer);
1584
1585 //food staging
1586 override bool CanBeCooked()
1587 {
1588 return false;
1589 }
1590
1591 override bool CanBeCookedOnStick()
1592 {
1593 return false;
1594 }
1595
1596 //================================================================
1597 // SYNCHRONIZATION
1598 //================================================================
1599 void Synchronize()
1600 {
1601 SetSynchDirty();
1602
1603 if (GetGame().IsMultiplayer())
1604 UpdateVisuals();
1605 }
1606
1607 override void OnVariablesSynchronized()
1608 {
1609 super.OnVariablesSynchronized();
1610
1611 UpdateVisuals();
1612
1613 //update audio
1615 RefreshAudio();
1616 else
1617 RemoveAudio();
1618 }
1619
1620 //================================================================
1621 // AUDIO EFFECTS (WHEN ON DCS)
1622 //================================================================
1624 {
1627
1628 Synchronize();
1629 }
1630
1631 protected void RefreshAudio()
1632 {
1633 string soundName = "";
1634
1636
1637 switch (GetFoodStageType())
1638 {
1639 case FoodStageType.RAW:
1641 if (nextFoodState == FoodStageType.BOILED)
1642 soundName = "";
1643 break;
1644 case FoodStageType.BAKED:
1646 break;
1647 case FoodStageType.BURNED:
1649 break;
1650 default:
1651 soundName = "";
1652 break;
1653 }
1654
1656 }
1657
1658 protected void RemoveAudio()
1659 {
1660 m_MakeCookingSounds = false;
1662 }
1663
1664 //================================================================
1665 // SERIALIZATION
1666 //================================================================
1667 override void OnStoreSave(ParamsWriteContext ctx)
1668 {
1669 super.OnStoreSave(ctx);
1670
1671 if (GetFoodStage())
1672 GetFoodStage().OnStoreSave(ctx);
1673
1674 // food decay
1675 ctx.Write(m_DecayTimer);
1676 ctx.Write(m_LastDecayStage);
1677 }
1678
1679 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1680 {
1681 if (!super.OnStoreLoad(ctx, version))
1682 return false;
1683
1684 if (GetFoodStage())
1685 {
1686 if (!GetFoodStage().OnStoreLoad(ctx, version))
1687 return false;
1688 }
1689
1690 if (version >= 115)
1691 {
1692 if (!ctx.Read(m_DecayTimer))
1693 {
1694 m_DecayTimer = 0.0;
1695 return false;
1696 }
1697 if (!ctx.Read(m_LastDecayStage))
1698 {
1700 return false;
1701 }
1702 }
1703
1704 return true;
1705 }
1706
1707 override void AfterStoreLoad()
1708 {
1709 super.AfterStoreLoad();
1710
1711 Synchronize();
1712 }
1713
1714 //get food stage
1716 {
1717 return m_FoodStage;
1718 }
1719
1720 //food types
1721 override bool IsMeat()
1722 {
1723 return false;
1724 }
1725
1726 override bool IsCorpse()
1727 {
1728 return false;
1729 }
1730
1731 override bool IsFruit()
1732 {
1733 return false;
1734 }
1735
1736 override bool IsMushroom()
1737 {
1738 return false;
1739 }
1740
1741 //================================================================
1742 // NUTRITIONAL VALUES
1743 //================================================================
1744 //food properties
1745 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1746 {
1748 if (food_item && food_item.GetFoodStage())
1749 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1750 else if (classname != "" && food_stage)
1751 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1752 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1753 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1754
1755 }
1756
1757 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1758 {
1760 if (food_item && food_item.GetFoodStage())
1761 return FoodStage.GetEnergy(food_item.GetFoodStage());
1762 else if (classname != "" && food_stage)
1763 return FoodStage.GetEnergy(null, food_stage, classname);
1764 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1765 return GetGame().ConfigGetFloat(class_path + " energy");
1766 }
1767
1768 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1769 {
1771 if (food_item && food_item.GetFoodStage())
1772 return FoodStage.GetWater(food_item.GetFoodStage());
1773 else if (classname != "" && food_stage)
1774 return FoodStage.GetWater(null, food_stage, classname);
1775 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1776 return GetGame().ConfigGetFloat(class_path + " water");
1777 }
1778
1779 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1780 {
1782 if (food_item && food_item.GetFoodStage())
1783 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1784 else if (classname != "" && food_stage)
1785 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1786 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1787 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1788
1789 }
1790
1791 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1792 {
1794 if (food_item && food_item.GetFoodStage())
1795 return FoodStage.GetToxicity(food_item.GetFoodStage());
1796 else if (classname != "" && food_stage)
1797 return FoodStage.GetToxicity(null, food_stage, classname);
1798 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1799 return GetGame().ConfigGetFloat(class_path + " toxicity");
1800 }
1801
1802 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1803 {
1805 if (food_item && food_item.GetFoodStage())
1806 return FoodStage.GetAgents(food_item.GetFoodStage());
1807 else if (classname != "" && food_stage)
1808 return FoodStage.GetAgents(null, food_stage, classname);
1809 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1810 return GetGame().ConfigGetInt(class_path + " agents");
1811 }
1812
1813 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1814 {
1816 if (food_item && food_item.GetFoodStage())
1817 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1818 else if (classname != "" && food_stage)
1819 return FoodStage.GetDigestibility(null, food_stage, classname);
1820 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1821 return GetGame().ConfigGetInt(class_path + " digestibility");
1822 }
1823
1825 {
1827 }
1828
1829 //================================================================
1830 // FOOD STAGING
1831 //================================================================
1833 {
1834 return GetFoodStage().GetFoodStageType();
1835 }
1836
1837 //food stage states
1838 bool IsFoodRaw()
1839 {
1840 if (GetFoodStage())
1841 return GetFoodStage().IsFoodRaw();
1842
1843 return false;
1844 }
1845
1846 bool IsFoodBaked()
1847 {
1848 if (GetFoodStage())
1849 return GetFoodStage().IsFoodBaked();
1850
1851 return false;
1852 }
1853
1854 bool IsFoodBoiled()
1855 {
1856 if (GetFoodStage())
1857 return GetFoodStage().IsFoodBoiled();
1858
1859 return false;
1860 }
1861
1862 bool IsFoodDried()
1863 {
1864 if (GetFoodStage())
1865 return GetFoodStage().IsFoodDried();
1866
1867 return false;
1868 }
1869
1870 bool IsFoodBurned()
1871 {
1872 if (GetFoodStage())
1873 return GetFoodStage().IsFoodBurned();
1874
1875 return false;
1876 }
1877
1878 bool IsFoodRotten()
1879 {
1880 if (GetFoodStage())
1881 return GetFoodStage().IsFoodRotten();
1882
1883 return false;
1884 }
1885
1886 //food stage change
1888 {
1889 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1890 }
1891
1893 {
1894 return GetFoodStage().GetNextFoodStageType(cooking_method);
1895 }
1896
1898 {
1899 return GetFoodStage().GetFoodStageName(food_stage_type);
1900 }
1901
1903 {
1904 return GetFoodStage().CanChangeToNewStage(cooking_method);
1905 }
1906
1907 //Use this to receive food stage from another Edible_Base
1909 {
1910 if (!source.HasFoodStage())
1911 return;
1912 m_LastDecayStage = source.GetLastDecayStage();
1913 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1914 m_DecayTimer = source.GetDecayTimer();
1915 m_DecayDelta = source.GetDecayDelta();
1916 }
1917
1918 //================================================================
1919 // COOKING
1920 //================================================================
1921 //cooking time
1922 float GetCookingTime()
1923 {
1924 return GetFoodStage().GetCookingTime();
1925 }
1926
1927 void SetCookingTime(float time)
1928 {
1929 GetFoodStage().SetCookingTime(time);
1930
1931 //synchronize when calling on server
1932 Synchronize();
1933 }
1934
1935 //replace edible with new item (opening cans)
1936 void ReplaceEdibleWithNew(string typeName)
1937 {
1938 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1939 if (player)
1940 {
1942 player.ServerReplaceItemInHandsWithNew(lambda);
1943 }
1944 else
1945 Error("ReplaceEdibleWithNew - cannot use edible without player");
1946 }
1947
1948 override void SetActions()
1949 {
1950 super.SetActions();
1951
1952 AddAction(ActionAttach);
1954 }
1955
1956 protected void SoundCookingStart(string sound_name)
1957 {
1958#ifndef SERVER
1960 {
1962
1965 }
1966#endif
1967 }
1968
1969 protected void SoundCookingStop()
1970 {
1971#ifndef SERVER
1973 {
1976 m_SoundPlaying = "";
1977 }
1978#endif
1979 }
1980
1981 override bool CanHaveTemperature()
1982 {
1983 return true;
1984 }
1985
1986 override bool CanDecay()
1987 {
1988 return false;
1989 }
1990
1991 override bool CanProcessDecay()
1992 {
1993 return (GetFoodStageType() != FoodStageType.ROTTEN);
1994 }
1995
1996 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1997 {
1998 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1999 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
2000 if (hasRootAsPlayer)
2002
2003 /*Print( "-------------------------" );
2004 Print( this );
2005 Print( m_DecayTimer );
2006 Print( m_DecayDelta );
2007 Print( m_LastDecayStage );*/
2008
2009 if (IsFruit() || IsMushroom())
2010 {
2011 // fruit, vegetables and mushrooms
2013 {
2014 switch (GetFoodStageType())
2015 {
2016 case FoodStageType.RAW:
2019 break;
2020
2021 case FoodStageType.BOILED:
2024 break;
2025
2026 case FoodStageType.BAKED:
2029 break;
2030
2031 case FoodStageType.DRIED:
2032 case FoodStageType.BURNED:
2033 case FoodStageType.ROTTEN:
2034 default:
2035 m_DecayTimer = -1;
2037 return;
2038 }
2039
2040 //m_DecayTimer = m_DecayTimer / 1000.0;
2041 }
2042
2044
2045 if (m_DecayTimer <= 0)
2046 {
2047 if (m_LastDecayStage != FoodStageType.NONE)
2048 {
2049 // switch to decayed stage
2050 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
2053 {
2054 int rng = Math.RandomIntInclusive(0, 100);
2057 else
2058 {
2061 else
2063 }
2064 }
2065 }
2066 }
2067
2068 }
2069 else if (IsMeat())
2070 {
2071 // meat
2073 {
2074 switch (GetFoodStageType())
2075 {
2076 case FoodStageType.RAW:
2079 break;
2080
2081 case FoodStageType.BOILED:
2084 break;
2085
2086 case FoodStageType.BAKED:
2089 break;
2090
2091 case FoodStageType.DRIED:
2094 break;
2095
2096 case FoodStageType.BURNED:
2097 case FoodStageType.ROTTEN:
2098 default:
2099 m_DecayTimer = -1;
2101 return;
2102 }
2103 }
2104
2106
2107 if (m_DecayTimer <= 0)
2108 {
2109 if (m_LastDecayStage != FoodStageType.NONE)
2110 {
2111 // switch to decayed stage
2114 }
2115 }
2116 }
2117 else if (IsCorpse())
2118 {
2119 // corpse
2121 {
2122 switch (GetFoodStageType())
2123 {
2124 case FoodStageType.RAW:
2127 break;
2128
2129 case FoodStageType.BURNED:
2130 case FoodStageType.ROTTEN:
2131 default:
2132 m_DecayTimer = -1;
2134 return;
2135 }
2136 }
2137
2139
2140 if (m_DecayTimer <= 0)
2141 {
2142 if (m_LastDecayStage != FoodStageType.NONE)
2143 {
2144 // switch to decayed stage
2147 }
2148 }
2149 }
2150 else
2151 {
2152 // opened cans
2154
2155 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
2156 {
2159 //m_DecayTimer = m_DecayTimer / 1000.0;
2160 }
2161 else
2162 {
2163 if (m_DecayTimer <= 0)
2164 {
2165 InsertAgent(eAgents.FOOD_POISON, 1);
2166 m_DecayTimer = -1;
2167 }
2168 }
2169 }
2170
2171 m_DecayDelta = 0.0;
2172 }
2173
2175 {
2176 super.GetDebugActions(outputList);
2177
2178 if (HasFoodStage())
2179 {
2180 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
2181 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
2182 }
2183 }
2184
2185 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
2186 {
2187 super.OnAction(action_id, player, ctx);
2188
2189 if (GetGame().IsServer())
2190 {
2191 if (action_id == EActions.FOOD_STAGE_PREV)
2192 {
2194 if (food_stage_prev <= 0)
2195 food_stage_prev = FoodStageType.COUNT - 1;
2197 return true;
2198 }
2199 else if (action_id == EActions.FOOD_STAGE_NEXT)
2200 {
2202 if (food_stage_next >= FoodStageType.COUNT)
2205 return true;
2206 }
2207 }
2208 return false;
2209 }
2210
2211 override string GetDebugText()
2212 {
2213 string debug_output;
2214
2215 debug_output = super.GetDebugText();
2216
2217 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
2218 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
2219
2220 return debug_output;
2221 }
2222
2223 //================================================================
2224 // GENERAL GETTERS
2225 //================================================================
2226
2227 float GetDecayTimer()
2228 {
2229 return m_DecayTimer;
2230 }
2231
2232 float GetDecayDelta()
2233 {
2234 return m_DecayDelta;
2235 }
2236
2238 {
2239 return m_LastDecayStage;
2240 }
2241}
2242
2244{
2246};

◆ GetNextFoodStageType()

FoodStageType ReplaceEdibleWithNewLambda::GetNextFoodStageType ( CookingMethodType cooking_method)
protected

Definition at line 1149 of file Edible_Base.c.

1149 : ItemBase
1150{
1151 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1152
1153 const string SOUND_BAKING_START = "Baking_SoundSet";
1154 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1155 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1156
1157 protected bool m_MakeCookingSounds;
1158 protected SoundOnVehicle m_SoundCooking;
1160 protected string m_SoundPlaying;
1162 protected float m_DecayTimer;
1163 protected float m_DecayDelta = 0.0;
1165
1167
1168 void Edible_Base()
1169 {
1170 if (HasFoodStage())
1171 {
1172 m_FoodStage = new FoodStage(this);
1173
1174 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1175 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1176 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1177 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1178 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1179
1180 m_SoundPlaying = "";
1182 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1183 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1184 }
1185 }
1186
1187 override void EEInit()
1188 {
1189 super.EEInit();
1190
1191 UpdateVisuals();
1192 }
1193
1194 override void EEDelete(EntityAI parent)
1195 {
1196 super.EEDelete(parent);
1197
1198 RemoveAudio();
1199 }
1200
1202 {
1203 super.EEItemLocationChanged(oldLoc, newLoc);
1204
1206 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1207 {
1208 switch (oldLoc.GetParent().GetType())
1209 {
1210 case "FryingPan":
1211 case "Pot":
1212 case "Cauldron":
1213 case "SharpWoodenStick":
1214 MakeSoundsOnClient(false);
1215 break;
1216 }
1217
1219 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1220 MakeSoundsOnClient(false);
1221 }
1222 }
1223
1224 void UpdateVisuals()
1225 {
1226 if (GetFoodStage())
1227 GetFoodStage().UpdateVisuals();
1228 }
1229
1230 bool Consume(float amount, PlayerBase consumer)
1231 {
1232 AddQuantity(-amount, false, false);
1233 OnConsume(amount, consumer);
1234
1235 return true;
1236 }
1237
1238 void OnConsume(float amount, PlayerBase consumer);
1239
1240 //food staging
1241 override bool CanBeCooked()
1242 {
1243 return false;
1244 }
1245
1246 override bool CanBeCookedOnStick()
1247 {
1248 return false;
1249 }
1250
1251 //================================================================
1252 // SYNCHRONIZATION
1253 //================================================================
1254 void Synchronize()
1255 {
1256 SetSynchDirty();
1257
1258 if (GetGame().IsMultiplayer())
1259 UpdateVisuals();
1260 }
1261
1262 override void OnVariablesSynchronized()
1263 {
1264 super.OnVariablesSynchronized();
1265
1266 UpdateVisuals();
1267
1268 //update audio
1270 RefreshAudio();
1271 else
1272 RemoveAudio();
1273 }
1274
1275 //================================================================
1276 // AUDIO EFFECTS (WHEN ON DCS)
1277 //================================================================
1279 {
1282
1283 Synchronize();
1284 }
1285
1286 protected void RefreshAudio()
1287 {
1288 string soundName = "";
1289
1291
1292 switch (GetFoodStageType())
1293 {
1294 case FoodStageType.RAW:
1296 if (nextFoodState == FoodStageType.BOILED)
1297 soundName = "";
1298 break;
1299 case FoodStageType.BAKED:
1301 break;
1302 case FoodStageType.BURNED:
1304 break;
1305 default:
1306 soundName = "";
1307 break;
1308 }
1309
1311 }
1312
1313 protected void RemoveAudio()
1314 {
1315 m_MakeCookingSounds = false;
1317 }
1318
1319 //================================================================
1320 // SERIALIZATION
1321 //================================================================
1322 override void OnStoreSave(ParamsWriteContext ctx)
1323 {
1324 super.OnStoreSave(ctx);
1325
1326 if (GetFoodStage())
1327 GetFoodStage().OnStoreSave(ctx);
1328
1329 // food decay
1330 ctx.Write(m_DecayTimer);
1331 ctx.Write(m_LastDecayStage);
1332 }
1333
1334 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1335 {
1336 if (!super.OnStoreLoad(ctx, version))
1337 return false;
1338
1339 if (GetFoodStage())
1340 {
1341 if (!GetFoodStage().OnStoreLoad(ctx, version))
1342 return false;
1343 }
1344
1345 if (version >= 115)
1346 {
1347 if (!ctx.Read(m_DecayTimer))
1348 {
1349 m_DecayTimer = 0.0;
1350 return false;
1351 }
1352 if (!ctx.Read(m_LastDecayStage))
1353 {
1355 return false;
1356 }
1357 }
1358
1359 return true;
1360 }
1361
1362 override void AfterStoreLoad()
1363 {
1364 super.AfterStoreLoad();
1365
1366 Synchronize();
1367 }
1368
1369 //get food stage
1371 {
1372 return m_FoodStage;
1373 }
1374
1375 //food types
1376 override bool IsMeat()
1377 {
1378 return false;
1379 }
1380
1381 override bool IsCorpse()
1382 {
1383 return false;
1384 }
1385
1386 override bool IsFruit()
1387 {
1388 return false;
1389 }
1390
1391 override bool IsMushroom()
1392 {
1393 return false;
1394 }
1395
1396 //================================================================
1397 // NUTRITIONAL VALUES
1398 //================================================================
1399 //food properties
1400 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1401 {
1403 if (food_item && food_item.GetFoodStage())
1404 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1405 else if (classname != "" && food_stage)
1406 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1407 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1408 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1409
1410 }
1411
1412 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1413 {
1415 if (food_item && food_item.GetFoodStage())
1416 return FoodStage.GetEnergy(food_item.GetFoodStage());
1417 else if (classname != "" && food_stage)
1418 return FoodStage.GetEnergy(null, food_stage, classname);
1419 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1420 return GetGame().ConfigGetFloat(class_path + " energy");
1421 }
1422
1423 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1424 {
1426 if (food_item && food_item.GetFoodStage())
1427 return FoodStage.GetWater(food_item.GetFoodStage());
1428 else if (classname != "" && food_stage)
1429 return FoodStage.GetWater(null, food_stage, classname);
1430 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1431 return GetGame().ConfigGetFloat(class_path + " water");
1432 }
1433
1434 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1435 {
1437 if (food_item && food_item.GetFoodStage())
1438 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1439 else if (classname != "" && food_stage)
1440 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1441 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1442 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1443
1444 }
1445
1446 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1447 {
1449 if (food_item && food_item.GetFoodStage())
1450 return FoodStage.GetToxicity(food_item.GetFoodStage());
1451 else if (classname != "" && food_stage)
1452 return FoodStage.GetToxicity(null, food_stage, classname);
1453 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1454 return GetGame().ConfigGetFloat(class_path + " toxicity");
1455 }
1456
1457 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1458 {
1460 if (food_item && food_item.GetFoodStage())
1461 return FoodStage.GetAgents(food_item.GetFoodStage());
1462 else if (classname != "" && food_stage)
1463 return FoodStage.GetAgents(null, food_stage, classname);
1464 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1465 return GetGame().ConfigGetInt(class_path + " agents");
1466 }
1467
1468 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1469 {
1471 if (food_item && food_item.GetFoodStage())
1472 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1473 else if (classname != "" && food_stage)
1474 return FoodStage.GetDigestibility(null, food_stage, classname);
1475 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1476 return GetGame().ConfigGetInt(class_path + " digestibility");
1477 }
1478
1480 {
1482 }
1483
1484 //================================================================
1485 // FOOD STAGING
1486 //================================================================
1488 {
1489 return GetFoodStage().GetFoodStageType();
1490 }
1491
1492 //food stage states
1493 bool IsFoodRaw()
1494 {
1495 if (GetFoodStage())
1496 return GetFoodStage().IsFoodRaw();
1497
1498 return false;
1499 }
1500
1501 bool IsFoodBaked()
1502 {
1503 if (GetFoodStage())
1504 return GetFoodStage().IsFoodBaked();
1505
1506 return false;
1507 }
1508
1509 bool IsFoodBoiled()
1510 {
1511 if (GetFoodStage())
1512 return GetFoodStage().IsFoodBoiled();
1513
1514 return false;
1515 }
1516
1517 bool IsFoodDried()
1518 {
1519 if (GetFoodStage())
1520 return GetFoodStage().IsFoodDried();
1521
1522 return false;
1523 }
1524
1525 bool IsFoodBurned()
1526 {
1527 if (GetFoodStage())
1528 return GetFoodStage().IsFoodBurned();
1529
1530 return false;
1531 }
1532
1533 bool IsFoodRotten()
1534 {
1535 if (GetFoodStage())
1536 return GetFoodStage().IsFoodRotten();
1537
1538 return false;
1539 }
1540
1541 //food stage change
1543 {
1544 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1545 }
1546
1548 {
1549 return GetFoodStage().GetNextFoodStageType(cooking_method);
1550 }
1551
1553 {
1554 return GetFoodStage().GetFoodStageName(food_stage_type);
1555 }
1556
1558 {
1559 return GetFoodStage().CanChangeToNewStage(cooking_method);
1560 }
1561
1562 //Use this to receive food stage from another Edible_Base
1564 {
1565 if (!source.HasFoodStage())
1566 return;
1567 m_LastDecayStage = source.GetLastDecayStage();
1568 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1569 m_DecayTimer = source.GetDecayTimer();
1570 m_DecayDelta = source.GetDecayDelta();
1571 }
1572
1573 //================================================================
1574 // COOKING
1575 //================================================================
1576 //cooking time
1577 float GetCookingTime()
1578 {
1579 return GetFoodStage().GetCookingTime();
1580 }
1581
1582 void SetCookingTime(float time)
1583 {
1584 GetFoodStage().SetCookingTime(time);
1585
1586 //synchronize when calling on server
1587 Synchronize();
1588 }
1589
1590 //replace edible with new item (opening cans)
1591 void ReplaceEdibleWithNew(string typeName)
1592 {
1593 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1594 if (player)
1595 {
1597 player.ServerReplaceItemInHandsWithNew(lambda);
1598 }
1599 else
1600 Error("ReplaceEdibleWithNew - cannot use edible without player");
1601 }
1602
1603 override void SetActions()
1604 {
1605 super.SetActions();
1606
1607 AddAction(ActionAttach);
1609 }
1610
1611 protected void SoundCookingStart(string sound_name)
1612 {
1613#ifndef SERVER
1615 {
1617
1620 }
1621#endif
1622 }
1623
1624 protected void SoundCookingStop()
1625 {
1626#ifndef SERVER
1628 {
1631 m_SoundPlaying = "";
1632 }
1633#endif
1634 }
1635
1636 override bool CanHaveTemperature()
1637 {
1638 return true;
1639 }
1640
1641 override bool CanDecay()
1642 {
1643 return false;
1644 }
1645
1646 override bool CanProcessDecay()
1647 {
1648 return (GetFoodStageType() != FoodStageType.ROTTEN);
1649 }
1650
1651 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1652 {
1653 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1654 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1655 if (hasRootAsPlayer)
1657
1658 /*Print( "-------------------------" );
1659 Print( this );
1660 Print( m_DecayTimer );
1661 Print( m_DecayDelta );
1662 Print( m_LastDecayStage );*/
1663
1664 if (IsFruit() || IsMushroom())
1665 {
1666 // fruit, vegetables and mushrooms
1668 {
1669 switch (GetFoodStageType())
1670 {
1671 case FoodStageType.RAW:
1674 break;
1675
1676 case FoodStageType.BOILED:
1679 break;
1680
1681 case FoodStageType.BAKED:
1684 break;
1685
1686 case FoodStageType.DRIED:
1687 case FoodStageType.BURNED:
1688 case FoodStageType.ROTTEN:
1689 default:
1690 m_DecayTimer = -1;
1692 return;
1693 }
1694
1695 //m_DecayTimer = m_DecayTimer / 1000.0;
1696 }
1697
1699
1700 if (m_DecayTimer <= 0)
1701 {
1702 if (m_LastDecayStage != FoodStageType.NONE)
1703 {
1704 // switch to decayed stage
1705 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1708 {
1709 int rng = Math.RandomIntInclusive(0, 100);
1712 else
1713 {
1716 else
1718 }
1719 }
1720 }
1721 }
1722
1723 }
1724 else if (IsMeat())
1725 {
1726 // meat
1728 {
1729 switch (GetFoodStageType())
1730 {
1731 case FoodStageType.RAW:
1734 break;
1735
1736 case FoodStageType.BOILED:
1739 break;
1740
1741 case FoodStageType.BAKED:
1744 break;
1745
1746 case FoodStageType.DRIED:
1749 break;
1750
1751 case FoodStageType.BURNED:
1752 case FoodStageType.ROTTEN:
1753 default:
1754 m_DecayTimer = -1;
1756 return;
1757 }
1758 }
1759
1761
1762 if (m_DecayTimer <= 0)
1763 {
1764 if (m_LastDecayStage != FoodStageType.NONE)
1765 {
1766 // switch to decayed stage
1769 }
1770 }
1771 }
1772 else if (IsCorpse())
1773 {
1774 // corpse
1776 {
1777 switch (GetFoodStageType())
1778 {
1779 case FoodStageType.RAW:
1782 break;
1783
1784 case FoodStageType.BURNED:
1785 case FoodStageType.ROTTEN:
1786 default:
1787 m_DecayTimer = -1;
1789 return;
1790 }
1791 }
1792
1794
1795 if (m_DecayTimer <= 0)
1796 {
1797 if (m_LastDecayStage != FoodStageType.NONE)
1798 {
1799 // switch to decayed stage
1802 }
1803 }
1804 }
1805 else
1806 {
1807 // opened cans
1809
1810 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1811 {
1814 //m_DecayTimer = m_DecayTimer / 1000.0;
1815 }
1816 else
1817 {
1818 if (m_DecayTimer <= 0)
1819 {
1820 InsertAgent(eAgents.FOOD_POISON, 1);
1821 m_DecayTimer = -1;
1822 }
1823 }
1824 }
1825
1826 m_DecayDelta = 0.0;
1827 }
1828
1830 {
1831 super.GetDebugActions(outputList);
1832
1833 if (HasFoodStage())
1834 {
1835 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1836 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1837 }
1838 }
1839
1840 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1841 {
1842 super.OnAction(action_id, player, ctx);
1843
1844 if (GetGame().IsServer())
1845 {
1846 if (action_id == EActions.FOOD_STAGE_PREV)
1847 {
1849 if (food_stage_prev <= 0)
1850 food_stage_prev = FoodStageType.COUNT - 1;
1852 return true;
1853 }
1854 else if (action_id == EActions.FOOD_STAGE_NEXT)
1855 {
1857 if (food_stage_next >= FoodStageType.COUNT)
1860 return true;
1861 }
1862 }
1863 return false;
1864 }
1865
1866 override string GetDebugText()
1867 {
1868 string debug_output;
1869
1870 debug_output = super.GetDebugText();
1871
1872 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1873 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1874
1875 return debug_output;
1876 }
1877
1878 //================================================================
1879 // GENERAL GETTERS
1880 //================================================================
1881
1882 float GetDecayTimer()
1883 {
1884 return m_DecayTimer;
1885 }
1886
1887 float GetDecayDelta()
1888 {
1889 return m_DecayDelta;
1890 }
1891
1893 {
1894 return m_LastDecayStage;
1895 }
1896}
1897
1899{
1901};

◆ GetNutritionalProfile()

static NutritionalProfile ReplaceEdibleWithNewLambda::GetNutritionalProfile ( ItemBase item,
string classname = "",
int food_stage = 0 )
staticprotected

Definition at line 1081 of file Edible_Base.c.

1081 : ItemBase
1082{
1083 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1084
1085 const string SOUND_BAKING_START = "Baking_SoundSet";
1086 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1087 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1088
1089 protected bool m_MakeCookingSounds;
1090 protected SoundOnVehicle m_SoundCooking;
1092 protected string m_SoundPlaying;
1094 protected float m_DecayTimer;
1095 protected float m_DecayDelta = 0.0;
1097
1099
1100 void Edible_Base()
1101 {
1102 if (HasFoodStage())
1103 {
1104 m_FoodStage = new FoodStage(this);
1105
1106 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1107 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1108 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1109 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1110 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1111
1112 m_SoundPlaying = "";
1114 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1115 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1116 }
1117 }
1118
1119 override void EEInit()
1120 {
1121 super.EEInit();
1122
1123 UpdateVisuals();
1124 }
1125
1126 override void EEDelete(EntityAI parent)
1127 {
1128 super.EEDelete(parent);
1129
1130 RemoveAudio();
1131 }
1132
1134 {
1135 super.EEItemLocationChanged(oldLoc, newLoc);
1136
1138 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1139 {
1140 switch (oldLoc.GetParent().GetType())
1141 {
1142 case "FryingPan":
1143 case "Pot":
1144 case "Cauldron":
1145 case "SharpWoodenStick":
1146 MakeSoundsOnClient(false);
1147 break;
1148 }
1149
1151 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1152 MakeSoundsOnClient(false);
1153 }
1154 }
1155
1156 void UpdateVisuals()
1157 {
1158 if (GetFoodStage())
1159 GetFoodStage().UpdateVisuals();
1160 }
1161
1162 bool Consume(float amount, PlayerBase consumer)
1163 {
1164 AddQuantity(-amount, false, false);
1165 OnConsume(amount, consumer);
1166
1167 return true;
1168 }
1169
1170 void OnConsume(float amount, PlayerBase consumer);
1171
1172 //food staging
1173 override bool CanBeCooked()
1174 {
1175 return false;
1176 }
1177
1178 override bool CanBeCookedOnStick()
1179 {
1180 return false;
1181 }
1182
1183 //================================================================
1184 // SYNCHRONIZATION
1185 //================================================================
1186 void Synchronize()
1187 {
1188 SetSynchDirty();
1189
1190 if (GetGame().IsMultiplayer())
1191 UpdateVisuals();
1192 }
1193
1194 override void OnVariablesSynchronized()
1195 {
1196 super.OnVariablesSynchronized();
1197
1198 UpdateVisuals();
1199
1200 //update audio
1202 RefreshAudio();
1203 else
1204 RemoveAudio();
1205 }
1206
1207 //================================================================
1208 // AUDIO EFFECTS (WHEN ON DCS)
1209 //================================================================
1211 {
1214
1215 Synchronize();
1216 }
1217
1218 protected void RefreshAudio()
1219 {
1220 string soundName = "";
1221
1223
1224 switch (GetFoodStageType())
1225 {
1226 case FoodStageType.RAW:
1228 if (nextFoodState == FoodStageType.BOILED)
1229 soundName = "";
1230 break;
1231 case FoodStageType.BAKED:
1233 break;
1234 case FoodStageType.BURNED:
1236 break;
1237 default:
1238 soundName = "";
1239 break;
1240 }
1241
1243 }
1244
1245 protected void RemoveAudio()
1246 {
1247 m_MakeCookingSounds = false;
1249 }
1250
1251 //================================================================
1252 // SERIALIZATION
1253 //================================================================
1254 override void OnStoreSave(ParamsWriteContext ctx)
1255 {
1256 super.OnStoreSave(ctx);
1257
1258 if (GetFoodStage())
1259 GetFoodStage().OnStoreSave(ctx);
1260
1261 // food decay
1262 ctx.Write(m_DecayTimer);
1263 ctx.Write(m_LastDecayStage);
1264 }
1265
1266 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1267 {
1268 if (!super.OnStoreLoad(ctx, version))
1269 return false;
1270
1271 if (GetFoodStage())
1272 {
1273 if (!GetFoodStage().OnStoreLoad(ctx, version))
1274 return false;
1275 }
1276
1277 if (version >= 115)
1278 {
1279 if (!ctx.Read(m_DecayTimer))
1280 {
1281 m_DecayTimer = 0.0;
1282 return false;
1283 }
1284 if (!ctx.Read(m_LastDecayStage))
1285 {
1287 return false;
1288 }
1289 }
1290
1291 return true;
1292 }
1293
1294 override void AfterStoreLoad()
1295 {
1296 super.AfterStoreLoad();
1297
1298 Synchronize();
1299 }
1300
1301 //get food stage
1303 {
1304 return m_FoodStage;
1305 }
1306
1307 //food types
1308 override bool IsMeat()
1309 {
1310 return false;
1311 }
1312
1313 override bool IsCorpse()
1314 {
1315 return false;
1316 }
1317
1318 override bool IsFruit()
1319 {
1320 return false;
1321 }
1322
1323 override bool IsMushroom()
1324 {
1325 return false;
1326 }
1327
1328 //================================================================
1329 // NUTRITIONAL VALUES
1330 //================================================================
1331 //food properties
1332 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1333 {
1335 if (food_item && food_item.GetFoodStage())
1336 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1337 else if (classname != "" && food_stage)
1338 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1339 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1340 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1341
1342 }
1343
1344 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1345 {
1347 if (food_item && food_item.GetFoodStage())
1348 return FoodStage.GetEnergy(food_item.GetFoodStage());
1349 else if (classname != "" && food_stage)
1350 return FoodStage.GetEnergy(null, food_stage, classname);
1351 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1352 return GetGame().ConfigGetFloat(class_path + " energy");
1353 }
1354
1355 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1356 {
1358 if (food_item && food_item.GetFoodStage())
1359 return FoodStage.GetWater(food_item.GetFoodStage());
1360 else if (classname != "" && food_stage)
1361 return FoodStage.GetWater(null, food_stage, classname);
1362 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1363 return GetGame().ConfigGetFloat(class_path + " water");
1364 }
1365
1366 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1367 {
1369 if (food_item && food_item.GetFoodStage())
1370 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1371 else if (classname != "" && food_stage)
1372 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1373 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1374 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1375
1376 }
1377
1378 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1379 {
1381 if (food_item && food_item.GetFoodStage())
1382 return FoodStage.GetToxicity(food_item.GetFoodStage());
1383 else if (classname != "" && food_stage)
1384 return FoodStage.GetToxicity(null, food_stage, classname);
1385 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1386 return GetGame().ConfigGetFloat(class_path + " toxicity");
1387 }
1388
1389 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1390 {
1392 if (food_item && food_item.GetFoodStage())
1393 return FoodStage.GetAgents(food_item.GetFoodStage());
1394 else if (classname != "" && food_stage)
1395 return FoodStage.GetAgents(null, food_stage, classname);
1396 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1397 return GetGame().ConfigGetInt(class_path + " agents");
1398 }
1399
1400 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1401 {
1403 if (food_item && food_item.GetFoodStage())
1404 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1405 else if (classname != "" && food_stage)
1406 return FoodStage.GetDigestibility(null, food_stage, classname);
1407 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1408 return GetGame().ConfigGetInt(class_path + " digestibility");
1409 }
1410
1412 {
1414 }
1415
1416 //================================================================
1417 // FOOD STAGING
1418 //================================================================
1420 {
1421 return GetFoodStage().GetFoodStageType();
1422 }
1423
1424 //food stage states
1425 bool IsFoodRaw()
1426 {
1427 if (GetFoodStage())
1428 return GetFoodStage().IsFoodRaw();
1429
1430 return false;
1431 }
1432
1433 bool IsFoodBaked()
1434 {
1435 if (GetFoodStage())
1436 return GetFoodStage().IsFoodBaked();
1437
1438 return false;
1439 }
1440
1441 bool IsFoodBoiled()
1442 {
1443 if (GetFoodStage())
1444 return GetFoodStage().IsFoodBoiled();
1445
1446 return false;
1447 }
1448
1449 bool IsFoodDried()
1450 {
1451 if (GetFoodStage())
1452 return GetFoodStage().IsFoodDried();
1453
1454 return false;
1455 }
1456
1457 bool IsFoodBurned()
1458 {
1459 if (GetFoodStage())
1460 return GetFoodStage().IsFoodBurned();
1461
1462 return false;
1463 }
1464
1465 bool IsFoodRotten()
1466 {
1467 if (GetFoodStage())
1468 return GetFoodStage().IsFoodRotten();
1469
1470 return false;
1471 }
1472
1473 //food stage change
1475 {
1476 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1477 }
1478
1480 {
1481 return GetFoodStage().GetNextFoodStageType(cooking_method);
1482 }
1483
1485 {
1486 return GetFoodStage().GetFoodStageName(food_stage_type);
1487 }
1488
1490 {
1491 return GetFoodStage().CanChangeToNewStage(cooking_method);
1492 }
1493
1494 //Use this to receive food stage from another Edible_Base
1496 {
1497 if (!source.HasFoodStage())
1498 return;
1499 m_LastDecayStage = source.GetLastDecayStage();
1500 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1501 m_DecayTimer = source.GetDecayTimer();
1502 m_DecayDelta = source.GetDecayDelta();
1503 }
1504
1505 //================================================================
1506 // COOKING
1507 //================================================================
1508 //cooking time
1509 float GetCookingTime()
1510 {
1511 return GetFoodStage().GetCookingTime();
1512 }
1513
1514 void SetCookingTime(float time)
1515 {
1516 GetFoodStage().SetCookingTime(time);
1517
1518 //synchronize when calling on server
1519 Synchronize();
1520 }
1521
1522 //replace edible with new item (opening cans)
1523 void ReplaceEdibleWithNew(string typeName)
1524 {
1525 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1526 if (player)
1527 {
1529 player.ServerReplaceItemInHandsWithNew(lambda);
1530 }
1531 else
1532 Error("ReplaceEdibleWithNew - cannot use edible without player");
1533 }
1534
1535 override void SetActions()
1536 {
1537 super.SetActions();
1538
1539 AddAction(ActionAttach);
1541 }
1542
1543 protected void SoundCookingStart(string sound_name)
1544 {
1545#ifndef SERVER
1547 {
1549
1552 }
1553#endif
1554 }
1555
1556 protected void SoundCookingStop()
1557 {
1558#ifndef SERVER
1560 {
1563 m_SoundPlaying = "";
1564 }
1565#endif
1566 }
1567
1568 override bool CanHaveTemperature()
1569 {
1570 return true;
1571 }
1572
1573 override bool CanDecay()
1574 {
1575 return false;
1576 }
1577
1578 override bool CanProcessDecay()
1579 {
1580 return (GetFoodStageType() != FoodStageType.ROTTEN);
1581 }
1582
1583 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1584 {
1585 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1586 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1587 if (hasRootAsPlayer)
1589
1590 /*Print( "-------------------------" );
1591 Print( this );
1592 Print( m_DecayTimer );
1593 Print( m_DecayDelta );
1594 Print( m_LastDecayStage );*/
1595
1596 if (IsFruit() || IsMushroom())
1597 {
1598 // fruit, vegetables and mushrooms
1600 {
1601 switch (GetFoodStageType())
1602 {
1603 case FoodStageType.RAW:
1606 break;
1607
1608 case FoodStageType.BOILED:
1611 break;
1612
1613 case FoodStageType.BAKED:
1616 break;
1617
1618 case FoodStageType.DRIED:
1619 case FoodStageType.BURNED:
1620 case FoodStageType.ROTTEN:
1621 default:
1622 m_DecayTimer = -1;
1624 return;
1625 }
1626
1627 //m_DecayTimer = m_DecayTimer / 1000.0;
1628 }
1629
1631
1632 if (m_DecayTimer <= 0)
1633 {
1634 if (m_LastDecayStage != FoodStageType.NONE)
1635 {
1636 // switch to decayed stage
1637 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1640 {
1641 int rng = Math.RandomIntInclusive(0, 100);
1644 else
1645 {
1648 else
1650 }
1651 }
1652 }
1653 }
1654
1655 }
1656 else if (IsMeat())
1657 {
1658 // meat
1660 {
1661 switch (GetFoodStageType())
1662 {
1663 case FoodStageType.RAW:
1666 break;
1667
1668 case FoodStageType.BOILED:
1671 break;
1672
1673 case FoodStageType.BAKED:
1676 break;
1677
1678 case FoodStageType.DRIED:
1681 break;
1682
1683 case FoodStageType.BURNED:
1684 case FoodStageType.ROTTEN:
1685 default:
1686 m_DecayTimer = -1;
1688 return;
1689 }
1690 }
1691
1693
1694 if (m_DecayTimer <= 0)
1695 {
1696 if (m_LastDecayStage != FoodStageType.NONE)
1697 {
1698 // switch to decayed stage
1701 }
1702 }
1703 }
1704 else if (IsCorpse())
1705 {
1706 // corpse
1708 {
1709 switch (GetFoodStageType())
1710 {
1711 case FoodStageType.RAW:
1714 break;
1715
1716 case FoodStageType.BURNED:
1717 case FoodStageType.ROTTEN:
1718 default:
1719 m_DecayTimer = -1;
1721 return;
1722 }
1723 }
1724
1726
1727 if (m_DecayTimer <= 0)
1728 {
1729 if (m_LastDecayStage != FoodStageType.NONE)
1730 {
1731 // switch to decayed stage
1734 }
1735 }
1736 }
1737 else
1738 {
1739 // opened cans
1741
1742 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1743 {
1746 //m_DecayTimer = m_DecayTimer / 1000.0;
1747 }
1748 else
1749 {
1750 if (m_DecayTimer <= 0)
1751 {
1752 InsertAgent(eAgents.FOOD_POISON, 1);
1753 m_DecayTimer = -1;
1754 }
1755 }
1756 }
1757
1758 m_DecayDelta = 0.0;
1759 }
1760
1762 {
1763 super.GetDebugActions(outputList);
1764
1765 if (HasFoodStage())
1766 {
1767 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1768 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1769 }
1770 }
1771
1772 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1773 {
1774 super.OnAction(action_id, player, ctx);
1775
1776 if (GetGame().IsServer())
1777 {
1778 if (action_id == EActions.FOOD_STAGE_PREV)
1779 {
1781 if (food_stage_prev <= 0)
1782 food_stage_prev = FoodStageType.COUNT - 1;
1784 return true;
1785 }
1786 else if (action_id == EActions.FOOD_STAGE_NEXT)
1787 {
1789 if (food_stage_next >= FoodStageType.COUNT)
1792 return true;
1793 }
1794 }
1795 return false;
1796 }
1797
1798 override string GetDebugText()
1799 {
1800 string debug_output;
1801
1802 debug_output = super.GetDebugText();
1803
1804 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1805 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1806
1807 return debug_output;
1808 }
1809
1810 //================================================================
1811 // GENERAL GETTERS
1812 //================================================================
1813
1814 float GetDecayTimer()
1815 {
1816 return m_DecayTimer;
1817 }
1818
1819 float GetDecayDelta()
1820 {
1821 return m_DecayDelta;
1822 }
1823
1825 {
1826 return m_LastDecayStage;
1827 }
1828}
1829
1831{
1833};

◆ IsCorpse()

override bool ReplaceEdibleWithNewLambda::IsCorpse ( )
protected

Definition at line 983 of file Edible_Base.c.

983 : ItemBase
984{
985 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
986
987 const string SOUND_BAKING_START = "Baking_SoundSet";
988 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
989 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
990
991 protected bool m_MakeCookingSounds;
994 protected string m_SoundPlaying;
996 protected float m_DecayTimer;
997 protected float m_DecayDelta = 0.0;
999
1001
1002 void Edible_Base()
1003 {
1004 if (HasFoodStage())
1005 {
1006 m_FoodStage = new FoodStage(this);
1007
1008 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1009 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1010 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1011 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1012 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1013
1014 m_SoundPlaying = "";
1016 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1017 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1018 }
1019 }
1020
1021 override void EEInit()
1022 {
1023 super.EEInit();
1024
1025 UpdateVisuals();
1026 }
1027
1028 override void EEDelete(EntityAI parent)
1029 {
1030 super.EEDelete(parent);
1031
1032 RemoveAudio();
1033 }
1034
1036 {
1037 super.EEItemLocationChanged(oldLoc, newLoc);
1038
1040 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1041 {
1042 switch (oldLoc.GetParent().GetType())
1043 {
1044 case "FryingPan":
1045 case "Pot":
1046 case "Cauldron":
1047 case "SharpWoodenStick":
1048 MakeSoundsOnClient(false);
1049 break;
1050 }
1051
1053 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1054 MakeSoundsOnClient(false);
1055 }
1056 }
1057
1058 void UpdateVisuals()
1059 {
1060 if (GetFoodStage())
1061 GetFoodStage().UpdateVisuals();
1062 }
1063
1064 bool Consume(float amount, PlayerBase consumer)
1065 {
1066 AddQuantity(-amount, false, false);
1067 OnConsume(amount, consumer);
1068
1069 return true;
1070 }
1071
1072 void OnConsume(float amount, PlayerBase consumer);
1073
1074 //food staging
1075 override bool CanBeCooked()
1076 {
1077 return false;
1078 }
1079
1080 override bool CanBeCookedOnStick()
1081 {
1082 return false;
1083 }
1084
1085 //================================================================
1086 // SYNCHRONIZATION
1087 //================================================================
1088 void Synchronize()
1089 {
1090 SetSynchDirty();
1091
1092 if (GetGame().IsMultiplayer())
1093 UpdateVisuals();
1094 }
1095
1096 override void OnVariablesSynchronized()
1097 {
1098 super.OnVariablesSynchronized();
1099
1100 UpdateVisuals();
1101
1102 //update audio
1104 RefreshAudio();
1105 else
1106 RemoveAudio();
1107 }
1108
1109 //================================================================
1110 // AUDIO EFFECTS (WHEN ON DCS)
1111 //================================================================
1113 {
1116
1117 Synchronize();
1118 }
1119
1120 protected void RefreshAudio()
1121 {
1122 string soundName = "";
1123
1125
1126 switch (GetFoodStageType())
1127 {
1128 case FoodStageType.RAW:
1130 if (nextFoodState == FoodStageType.BOILED)
1131 soundName = "";
1132 break;
1133 case FoodStageType.BAKED:
1135 break;
1136 case FoodStageType.BURNED:
1138 break;
1139 default:
1140 soundName = "";
1141 break;
1142 }
1143
1145 }
1146
1147 protected void RemoveAudio()
1148 {
1149 m_MakeCookingSounds = false;
1151 }
1152
1153 //================================================================
1154 // SERIALIZATION
1155 //================================================================
1156 override void OnStoreSave(ParamsWriteContext ctx)
1157 {
1158 super.OnStoreSave(ctx);
1159
1160 if (GetFoodStage())
1161 GetFoodStage().OnStoreSave(ctx);
1162
1163 // food decay
1164 ctx.Write(m_DecayTimer);
1165 ctx.Write(m_LastDecayStage);
1166 }
1167
1168 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1169 {
1170 if (!super.OnStoreLoad(ctx, version))
1171 return false;
1172
1173 if (GetFoodStage())
1174 {
1175 if (!GetFoodStage().OnStoreLoad(ctx, version))
1176 return false;
1177 }
1178
1179 if (version >= 115)
1180 {
1181 if (!ctx.Read(m_DecayTimer))
1182 {
1183 m_DecayTimer = 0.0;
1184 return false;
1185 }
1186 if (!ctx.Read(m_LastDecayStage))
1187 {
1189 return false;
1190 }
1191 }
1192
1193 return true;
1194 }
1195
1196 override void AfterStoreLoad()
1197 {
1198 super.AfterStoreLoad();
1199
1200 Synchronize();
1201 }
1202
1203 //get food stage
1205 {
1206 return m_FoodStage;
1207 }
1208
1209 //food types
1210 override bool IsMeat()
1211 {
1212 return false;
1213 }
1214
1215 override bool IsCorpse()
1216 {
1217 return false;
1218 }
1219
1220 override bool IsFruit()
1221 {
1222 return false;
1223 }
1224
1225 override bool IsMushroom()
1226 {
1227 return false;
1228 }
1229
1230 //================================================================
1231 // NUTRITIONAL VALUES
1232 //================================================================
1233 //food properties
1234 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1235 {
1237 if (food_item && food_item.GetFoodStage())
1238 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1239 else if (classname != "" && food_stage)
1240 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1241 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1242 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1243
1244 }
1245
1246 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1247 {
1249 if (food_item && food_item.GetFoodStage())
1250 return FoodStage.GetEnergy(food_item.GetFoodStage());
1251 else if (classname != "" && food_stage)
1252 return FoodStage.GetEnergy(null, food_stage, classname);
1253 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1254 return GetGame().ConfigGetFloat(class_path + " energy");
1255 }
1256
1257 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1258 {
1260 if (food_item && food_item.GetFoodStage())
1261 return FoodStage.GetWater(food_item.GetFoodStage());
1262 else if (classname != "" && food_stage)
1263 return FoodStage.GetWater(null, food_stage, classname);
1264 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1265 return GetGame().ConfigGetFloat(class_path + " water");
1266 }
1267
1268 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1269 {
1271 if (food_item && food_item.GetFoodStage())
1272 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1273 else if (classname != "" && food_stage)
1274 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1275 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1276 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1277
1278 }
1279
1280 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1281 {
1283 if (food_item && food_item.GetFoodStage())
1284 return FoodStage.GetToxicity(food_item.GetFoodStage());
1285 else if (classname != "" && food_stage)
1286 return FoodStage.GetToxicity(null, food_stage, classname);
1287 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1288 return GetGame().ConfigGetFloat(class_path + " toxicity");
1289 }
1290
1291 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1292 {
1294 if (food_item && food_item.GetFoodStage())
1295 return FoodStage.GetAgents(food_item.GetFoodStage());
1296 else if (classname != "" && food_stage)
1297 return FoodStage.GetAgents(null, food_stage, classname);
1298 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1299 return GetGame().ConfigGetInt(class_path + " agents");
1300 }
1301
1302 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1303 {
1305 if (food_item && food_item.GetFoodStage())
1306 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1307 else if (classname != "" && food_stage)
1308 return FoodStage.GetDigestibility(null, food_stage, classname);
1309 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1310 return GetGame().ConfigGetInt(class_path + " digestibility");
1311 }
1312
1314 {
1316 }
1317
1318 //================================================================
1319 // FOOD STAGING
1320 //================================================================
1322 {
1323 return GetFoodStage().GetFoodStageType();
1324 }
1325
1326 //food stage states
1327 bool IsFoodRaw()
1328 {
1329 if (GetFoodStage())
1330 return GetFoodStage().IsFoodRaw();
1331
1332 return false;
1333 }
1334
1335 bool IsFoodBaked()
1336 {
1337 if (GetFoodStage())
1338 return GetFoodStage().IsFoodBaked();
1339
1340 return false;
1341 }
1342
1343 bool IsFoodBoiled()
1344 {
1345 if (GetFoodStage())
1346 return GetFoodStage().IsFoodBoiled();
1347
1348 return false;
1349 }
1350
1351 bool IsFoodDried()
1352 {
1353 if (GetFoodStage())
1354 return GetFoodStage().IsFoodDried();
1355
1356 return false;
1357 }
1358
1359 bool IsFoodBurned()
1360 {
1361 if (GetFoodStage())
1362 return GetFoodStage().IsFoodBurned();
1363
1364 return false;
1365 }
1366
1367 bool IsFoodRotten()
1368 {
1369 if (GetFoodStage())
1370 return GetFoodStage().IsFoodRotten();
1371
1372 return false;
1373 }
1374
1375 //food stage change
1377 {
1378 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1379 }
1380
1382 {
1383 return GetFoodStage().GetNextFoodStageType(cooking_method);
1384 }
1385
1387 {
1388 return GetFoodStage().GetFoodStageName(food_stage_type);
1389 }
1390
1392 {
1393 return GetFoodStage().CanChangeToNewStage(cooking_method);
1394 }
1395
1396 //Use this to receive food stage from another Edible_Base
1398 {
1399 if (!source.HasFoodStage())
1400 return;
1401 m_LastDecayStage = source.GetLastDecayStage();
1402 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1403 m_DecayTimer = source.GetDecayTimer();
1404 m_DecayDelta = source.GetDecayDelta();
1405 }
1406
1407 //================================================================
1408 // COOKING
1409 //================================================================
1410 //cooking time
1411 float GetCookingTime()
1412 {
1413 return GetFoodStage().GetCookingTime();
1414 }
1415
1416 void SetCookingTime(float time)
1417 {
1418 GetFoodStage().SetCookingTime(time);
1419
1420 //synchronize when calling on server
1421 Synchronize();
1422 }
1423
1424 //replace edible with new item (opening cans)
1425 void ReplaceEdibleWithNew(string typeName)
1426 {
1427 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1428 if (player)
1429 {
1431 player.ServerReplaceItemInHandsWithNew(lambda);
1432 }
1433 else
1434 Error("ReplaceEdibleWithNew - cannot use edible without player");
1435 }
1436
1437 override void SetActions()
1438 {
1439 super.SetActions();
1440
1441 AddAction(ActionAttach);
1443 }
1444
1445 protected void SoundCookingStart(string sound_name)
1446 {
1447#ifndef SERVER
1449 {
1451
1454 }
1455#endif
1456 }
1457
1458 protected void SoundCookingStop()
1459 {
1460#ifndef SERVER
1462 {
1465 m_SoundPlaying = "";
1466 }
1467#endif
1468 }
1469
1470 override bool CanHaveTemperature()
1471 {
1472 return true;
1473 }
1474
1475 override bool CanDecay()
1476 {
1477 return false;
1478 }
1479
1480 override bool CanProcessDecay()
1481 {
1482 return (GetFoodStageType() != FoodStageType.ROTTEN);
1483 }
1484
1485 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1486 {
1487 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1488 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1489 if (hasRootAsPlayer)
1491
1492 /*Print( "-------------------------" );
1493 Print( this );
1494 Print( m_DecayTimer );
1495 Print( m_DecayDelta );
1496 Print( m_LastDecayStage );*/
1497
1498 if (IsFruit() || IsMushroom())
1499 {
1500 // fruit, vegetables and mushrooms
1502 {
1503 switch (GetFoodStageType())
1504 {
1505 case FoodStageType.RAW:
1508 break;
1509
1510 case FoodStageType.BOILED:
1513 break;
1514
1515 case FoodStageType.BAKED:
1518 break;
1519
1520 case FoodStageType.DRIED:
1521 case FoodStageType.BURNED:
1522 case FoodStageType.ROTTEN:
1523 default:
1524 m_DecayTimer = -1;
1526 return;
1527 }
1528
1529 //m_DecayTimer = m_DecayTimer / 1000.0;
1530 }
1531
1533
1534 if (m_DecayTimer <= 0)
1535 {
1536 if (m_LastDecayStage != FoodStageType.NONE)
1537 {
1538 // switch to decayed stage
1539 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1542 {
1543 int rng = Math.RandomIntInclusive(0, 100);
1546 else
1547 {
1550 else
1552 }
1553 }
1554 }
1555 }
1556
1557 }
1558 else if (IsMeat())
1559 {
1560 // meat
1562 {
1563 switch (GetFoodStageType())
1564 {
1565 case FoodStageType.RAW:
1568 break;
1569
1570 case FoodStageType.BOILED:
1573 break;
1574
1575 case FoodStageType.BAKED:
1578 break;
1579
1580 case FoodStageType.DRIED:
1583 break;
1584
1585 case FoodStageType.BURNED:
1586 case FoodStageType.ROTTEN:
1587 default:
1588 m_DecayTimer = -1;
1590 return;
1591 }
1592 }
1593
1595
1596 if (m_DecayTimer <= 0)
1597 {
1598 if (m_LastDecayStage != FoodStageType.NONE)
1599 {
1600 // switch to decayed stage
1603 }
1604 }
1605 }
1606 else if (IsCorpse())
1607 {
1608 // corpse
1610 {
1611 switch (GetFoodStageType())
1612 {
1613 case FoodStageType.RAW:
1616 break;
1617
1618 case FoodStageType.BURNED:
1619 case FoodStageType.ROTTEN:
1620 default:
1621 m_DecayTimer = -1;
1623 return;
1624 }
1625 }
1626
1628
1629 if (m_DecayTimer <= 0)
1630 {
1631 if (m_LastDecayStage != FoodStageType.NONE)
1632 {
1633 // switch to decayed stage
1636 }
1637 }
1638 }
1639 else
1640 {
1641 // opened cans
1643
1644 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1645 {
1648 //m_DecayTimer = m_DecayTimer / 1000.0;
1649 }
1650 else
1651 {
1652 if (m_DecayTimer <= 0)
1653 {
1654 InsertAgent(eAgents.FOOD_POISON, 1);
1655 m_DecayTimer = -1;
1656 }
1657 }
1658 }
1659
1660 m_DecayDelta = 0.0;
1661 }
1662
1664 {
1665 super.GetDebugActions(outputList);
1666
1667 if (HasFoodStage())
1668 {
1669 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1670 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1671 }
1672 }
1673
1674 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1675 {
1676 super.OnAction(action_id, player, ctx);
1677
1678 if (GetGame().IsServer())
1679 {
1680 if (action_id == EActions.FOOD_STAGE_PREV)
1681 {
1683 if (food_stage_prev <= 0)
1684 food_stage_prev = FoodStageType.COUNT - 1;
1686 return true;
1687 }
1688 else if (action_id == EActions.FOOD_STAGE_NEXT)
1689 {
1691 if (food_stage_next >= FoodStageType.COUNT)
1694 return true;
1695 }
1696 }
1697 return false;
1698 }
1699
1700 override string GetDebugText()
1701 {
1702 string debug_output;
1703
1704 debug_output = super.GetDebugText();
1705
1706 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1707 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1708
1709 return debug_output;
1710 }
1711
1712 //================================================================
1713 // GENERAL GETTERS
1714 //================================================================
1715
1716 float GetDecayTimer()
1717 {
1718 return m_DecayTimer;
1719 }
1720
1721 float GetDecayDelta()
1722 {
1723 return m_DecayDelta;
1724 }
1725
1727 {
1728 return m_LastDecayStage;
1729 }
1730}
1731
1733{
1735};

Referenced by IEntity::IsFood().

◆ IsFoodBaked()

bool ReplaceEdibleWithNewLambda::IsFoodBaked ( )
protected

Definition at line 1103 of file Edible_Base.c.

1103 : ItemBase
1104{
1105 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1106
1107 const string SOUND_BAKING_START = "Baking_SoundSet";
1108 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1109 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1110
1111 protected bool m_MakeCookingSounds;
1112 protected SoundOnVehicle m_SoundCooking;
1114 protected string m_SoundPlaying;
1116 protected float m_DecayTimer;
1117 protected float m_DecayDelta = 0.0;
1119
1121
1122 void Edible_Base()
1123 {
1124 if (HasFoodStage())
1125 {
1126 m_FoodStage = new FoodStage(this);
1127
1128 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1129 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1130 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1131 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1132 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1133
1134 m_SoundPlaying = "";
1136 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1137 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1138 }
1139 }
1140
1141 override void EEInit()
1142 {
1143 super.EEInit();
1144
1145 UpdateVisuals();
1146 }
1147
1148 override void EEDelete(EntityAI parent)
1149 {
1150 super.EEDelete(parent);
1151
1152 RemoveAudio();
1153 }
1154
1156 {
1157 super.EEItemLocationChanged(oldLoc, newLoc);
1158
1160 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1161 {
1162 switch (oldLoc.GetParent().GetType())
1163 {
1164 case "FryingPan":
1165 case "Pot":
1166 case "Cauldron":
1167 case "SharpWoodenStick":
1168 MakeSoundsOnClient(false);
1169 break;
1170 }
1171
1173 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1174 MakeSoundsOnClient(false);
1175 }
1176 }
1177
1178 void UpdateVisuals()
1179 {
1180 if (GetFoodStage())
1181 GetFoodStage().UpdateVisuals();
1182 }
1183
1184 bool Consume(float amount, PlayerBase consumer)
1185 {
1186 AddQuantity(-amount, false, false);
1187 OnConsume(amount, consumer);
1188
1189 return true;
1190 }
1191
1192 void OnConsume(float amount, PlayerBase consumer);
1193
1194 //food staging
1195 override bool CanBeCooked()
1196 {
1197 return false;
1198 }
1199
1200 override bool CanBeCookedOnStick()
1201 {
1202 return false;
1203 }
1204
1205 //================================================================
1206 // SYNCHRONIZATION
1207 //================================================================
1208 void Synchronize()
1209 {
1210 SetSynchDirty();
1211
1212 if (GetGame().IsMultiplayer())
1213 UpdateVisuals();
1214 }
1215
1216 override void OnVariablesSynchronized()
1217 {
1218 super.OnVariablesSynchronized();
1219
1220 UpdateVisuals();
1221
1222 //update audio
1224 RefreshAudio();
1225 else
1226 RemoveAudio();
1227 }
1228
1229 //================================================================
1230 // AUDIO EFFECTS (WHEN ON DCS)
1231 //================================================================
1233 {
1236
1237 Synchronize();
1238 }
1239
1240 protected void RefreshAudio()
1241 {
1242 string soundName = "";
1243
1245
1246 switch (GetFoodStageType())
1247 {
1248 case FoodStageType.RAW:
1250 if (nextFoodState == FoodStageType.BOILED)
1251 soundName = "";
1252 break;
1253 case FoodStageType.BAKED:
1255 break;
1256 case FoodStageType.BURNED:
1258 break;
1259 default:
1260 soundName = "";
1261 break;
1262 }
1263
1265 }
1266
1267 protected void RemoveAudio()
1268 {
1269 m_MakeCookingSounds = false;
1271 }
1272
1273 //================================================================
1274 // SERIALIZATION
1275 //================================================================
1276 override void OnStoreSave(ParamsWriteContext ctx)
1277 {
1278 super.OnStoreSave(ctx);
1279
1280 if (GetFoodStage())
1281 GetFoodStage().OnStoreSave(ctx);
1282
1283 // food decay
1284 ctx.Write(m_DecayTimer);
1285 ctx.Write(m_LastDecayStage);
1286 }
1287
1288 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1289 {
1290 if (!super.OnStoreLoad(ctx, version))
1291 return false;
1292
1293 if (GetFoodStage())
1294 {
1295 if (!GetFoodStage().OnStoreLoad(ctx, version))
1296 return false;
1297 }
1298
1299 if (version >= 115)
1300 {
1301 if (!ctx.Read(m_DecayTimer))
1302 {
1303 m_DecayTimer = 0.0;
1304 return false;
1305 }
1306 if (!ctx.Read(m_LastDecayStage))
1307 {
1309 return false;
1310 }
1311 }
1312
1313 return true;
1314 }
1315
1316 override void AfterStoreLoad()
1317 {
1318 super.AfterStoreLoad();
1319
1320 Synchronize();
1321 }
1322
1323 //get food stage
1325 {
1326 return m_FoodStage;
1327 }
1328
1329 //food types
1330 override bool IsMeat()
1331 {
1332 return false;
1333 }
1334
1335 override bool IsCorpse()
1336 {
1337 return false;
1338 }
1339
1340 override bool IsFruit()
1341 {
1342 return false;
1343 }
1344
1345 override bool IsMushroom()
1346 {
1347 return false;
1348 }
1349
1350 //================================================================
1351 // NUTRITIONAL VALUES
1352 //================================================================
1353 //food properties
1354 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1355 {
1357 if (food_item && food_item.GetFoodStage())
1358 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1359 else if (classname != "" && food_stage)
1360 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1361 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1362 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1363
1364 }
1365
1366 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1367 {
1369 if (food_item && food_item.GetFoodStage())
1370 return FoodStage.GetEnergy(food_item.GetFoodStage());
1371 else if (classname != "" && food_stage)
1372 return FoodStage.GetEnergy(null, food_stage, classname);
1373 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1374 return GetGame().ConfigGetFloat(class_path + " energy");
1375 }
1376
1377 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1378 {
1380 if (food_item && food_item.GetFoodStage())
1381 return FoodStage.GetWater(food_item.GetFoodStage());
1382 else if (classname != "" && food_stage)
1383 return FoodStage.GetWater(null, food_stage, classname);
1384 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1385 return GetGame().ConfigGetFloat(class_path + " water");
1386 }
1387
1388 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1389 {
1391 if (food_item && food_item.GetFoodStage())
1392 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1393 else if (classname != "" && food_stage)
1394 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1395 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1396 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1397
1398 }
1399
1400 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1401 {
1403 if (food_item && food_item.GetFoodStage())
1404 return FoodStage.GetToxicity(food_item.GetFoodStage());
1405 else if (classname != "" && food_stage)
1406 return FoodStage.GetToxicity(null, food_stage, classname);
1407 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1408 return GetGame().ConfigGetFloat(class_path + " toxicity");
1409 }
1410
1411 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1412 {
1414 if (food_item && food_item.GetFoodStage())
1415 return FoodStage.GetAgents(food_item.GetFoodStage());
1416 else if (classname != "" && food_stage)
1417 return FoodStage.GetAgents(null, food_stage, classname);
1418 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1419 return GetGame().ConfigGetInt(class_path + " agents");
1420 }
1421
1422 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1423 {
1425 if (food_item && food_item.GetFoodStage())
1426 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1427 else if (classname != "" && food_stage)
1428 return FoodStage.GetDigestibility(null, food_stage, classname);
1429 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1430 return GetGame().ConfigGetInt(class_path + " digestibility");
1431 }
1432
1434 {
1436 }
1437
1438 //================================================================
1439 // FOOD STAGING
1440 //================================================================
1442 {
1443 return GetFoodStage().GetFoodStageType();
1444 }
1445
1446 //food stage states
1447 bool IsFoodRaw()
1448 {
1449 if (GetFoodStage())
1450 return GetFoodStage().IsFoodRaw();
1451
1452 return false;
1453 }
1454
1455 bool IsFoodBaked()
1456 {
1457 if (GetFoodStage())
1458 return GetFoodStage().IsFoodBaked();
1459
1460 return false;
1461 }
1462
1463 bool IsFoodBoiled()
1464 {
1465 if (GetFoodStage())
1466 return GetFoodStage().IsFoodBoiled();
1467
1468 return false;
1469 }
1470
1471 bool IsFoodDried()
1472 {
1473 if (GetFoodStage())
1474 return GetFoodStage().IsFoodDried();
1475
1476 return false;
1477 }
1478
1479 bool IsFoodBurned()
1480 {
1481 if (GetFoodStage())
1482 return GetFoodStage().IsFoodBurned();
1483
1484 return false;
1485 }
1486
1487 bool IsFoodRotten()
1488 {
1489 if (GetFoodStage())
1490 return GetFoodStage().IsFoodRotten();
1491
1492 return false;
1493 }
1494
1495 //food stage change
1497 {
1498 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1499 }
1500
1502 {
1503 return GetFoodStage().GetNextFoodStageType(cooking_method);
1504 }
1505
1507 {
1508 return GetFoodStage().GetFoodStageName(food_stage_type);
1509 }
1510
1512 {
1513 return GetFoodStage().CanChangeToNewStage(cooking_method);
1514 }
1515
1516 //Use this to receive food stage from another Edible_Base
1518 {
1519 if (!source.HasFoodStage())
1520 return;
1521 m_LastDecayStage = source.GetLastDecayStage();
1522 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1523 m_DecayTimer = source.GetDecayTimer();
1524 m_DecayDelta = source.GetDecayDelta();
1525 }
1526
1527 //================================================================
1528 // COOKING
1529 //================================================================
1530 //cooking time
1531 float GetCookingTime()
1532 {
1533 return GetFoodStage().GetCookingTime();
1534 }
1535
1536 void SetCookingTime(float time)
1537 {
1538 GetFoodStage().SetCookingTime(time);
1539
1540 //synchronize when calling on server
1541 Synchronize();
1542 }
1543
1544 //replace edible with new item (opening cans)
1545 void ReplaceEdibleWithNew(string typeName)
1546 {
1547 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1548 if (player)
1549 {
1551 player.ServerReplaceItemInHandsWithNew(lambda);
1552 }
1553 else
1554 Error("ReplaceEdibleWithNew - cannot use edible without player");
1555 }
1556
1557 override void SetActions()
1558 {
1559 super.SetActions();
1560
1561 AddAction(ActionAttach);
1563 }
1564
1565 protected void SoundCookingStart(string sound_name)
1566 {
1567#ifndef SERVER
1569 {
1571
1574 }
1575#endif
1576 }
1577
1578 protected void SoundCookingStop()
1579 {
1580#ifndef SERVER
1582 {
1585 m_SoundPlaying = "";
1586 }
1587#endif
1588 }
1589
1590 override bool CanHaveTemperature()
1591 {
1592 return true;
1593 }
1594
1595 override bool CanDecay()
1596 {
1597 return false;
1598 }
1599
1600 override bool CanProcessDecay()
1601 {
1602 return (GetFoodStageType() != FoodStageType.ROTTEN);
1603 }
1604
1605 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1606 {
1607 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1608 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1609 if (hasRootAsPlayer)
1611
1612 /*Print( "-------------------------" );
1613 Print( this );
1614 Print( m_DecayTimer );
1615 Print( m_DecayDelta );
1616 Print( m_LastDecayStage );*/
1617
1618 if (IsFruit() || IsMushroom())
1619 {
1620 // fruit, vegetables and mushrooms
1622 {
1623 switch (GetFoodStageType())
1624 {
1625 case FoodStageType.RAW:
1628 break;
1629
1630 case FoodStageType.BOILED:
1633 break;
1634
1635 case FoodStageType.BAKED:
1638 break;
1639
1640 case FoodStageType.DRIED:
1641 case FoodStageType.BURNED:
1642 case FoodStageType.ROTTEN:
1643 default:
1644 m_DecayTimer = -1;
1646 return;
1647 }
1648
1649 //m_DecayTimer = m_DecayTimer / 1000.0;
1650 }
1651
1653
1654 if (m_DecayTimer <= 0)
1655 {
1656 if (m_LastDecayStage != FoodStageType.NONE)
1657 {
1658 // switch to decayed stage
1659 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1662 {
1663 int rng = Math.RandomIntInclusive(0, 100);
1666 else
1667 {
1670 else
1672 }
1673 }
1674 }
1675 }
1676
1677 }
1678 else if (IsMeat())
1679 {
1680 // meat
1682 {
1683 switch (GetFoodStageType())
1684 {
1685 case FoodStageType.RAW:
1688 break;
1689
1690 case FoodStageType.BOILED:
1693 break;
1694
1695 case FoodStageType.BAKED:
1698 break;
1699
1700 case FoodStageType.DRIED:
1703 break;
1704
1705 case FoodStageType.BURNED:
1706 case FoodStageType.ROTTEN:
1707 default:
1708 m_DecayTimer = -1;
1710 return;
1711 }
1712 }
1713
1715
1716 if (m_DecayTimer <= 0)
1717 {
1718 if (m_LastDecayStage != FoodStageType.NONE)
1719 {
1720 // switch to decayed stage
1723 }
1724 }
1725 }
1726 else if (IsCorpse())
1727 {
1728 // corpse
1730 {
1731 switch (GetFoodStageType())
1732 {
1733 case FoodStageType.RAW:
1736 break;
1737
1738 case FoodStageType.BURNED:
1739 case FoodStageType.ROTTEN:
1740 default:
1741 m_DecayTimer = -1;
1743 return;
1744 }
1745 }
1746
1748
1749 if (m_DecayTimer <= 0)
1750 {
1751 if (m_LastDecayStage != FoodStageType.NONE)
1752 {
1753 // switch to decayed stage
1756 }
1757 }
1758 }
1759 else
1760 {
1761 // opened cans
1763
1764 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1765 {
1768 //m_DecayTimer = m_DecayTimer / 1000.0;
1769 }
1770 else
1771 {
1772 if (m_DecayTimer <= 0)
1773 {
1774 InsertAgent(eAgents.FOOD_POISON, 1);
1775 m_DecayTimer = -1;
1776 }
1777 }
1778 }
1779
1780 m_DecayDelta = 0.0;
1781 }
1782
1784 {
1785 super.GetDebugActions(outputList);
1786
1787 if (HasFoodStage())
1788 {
1789 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1790 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1791 }
1792 }
1793
1794 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1795 {
1796 super.OnAction(action_id, player, ctx);
1797
1798 if (GetGame().IsServer())
1799 {
1800 if (action_id == EActions.FOOD_STAGE_PREV)
1801 {
1803 if (food_stage_prev <= 0)
1804 food_stage_prev = FoodStageType.COUNT - 1;
1806 return true;
1807 }
1808 else if (action_id == EActions.FOOD_STAGE_NEXT)
1809 {
1811 if (food_stage_next >= FoodStageType.COUNT)
1814 return true;
1815 }
1816 }
1817 return false;
1818 }
1819
1820 override string GetDebugText()
1821 {
1822 string debug_output;
1823
1824 debug_output = super.GetDebugText();
1825
1826 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1827 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1828
1829 return debug_output;
1830 }
1831
1832 //================================================================
1833 // GENERAL GETTERS
1834 //================================================================
1835
1836 float GetDecayTimer()
1837 {
1838 return m_DecayTimer;
1839 }
1840
1841 float GetDecayDelta()
1842 {
1843 return m_DecayDelta;
1844 }
1845
1847 {
1848 return m_LastDecayStage;
1849 }
1850}
1851
1853{
1855};

◆ IsFoodBoiled()

bool ReplaceEdibleWithNewLambda::IsFoodBoiled ( )
protected

Definition at line 1111 of file Edible_Base.c.

1111 : ItemBase
1112{
1113 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1114
1115 const string SOUND_BAKING_START = "Baking_SoundSet";
1116 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1117 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1118
1119 protected bool m_MakeCookingSounds;
1120 protected SoundOnVehicle m_SoundCooking;
1122 protected string m_SoundPlaying;
1124 protected float m_DecayTimer;
1125 protected float m_DecayDelta = 0.0;
1127
1129
1130 void Edible_Base()
1131 {
1132 if (HasFoodStage())
1133 {
1134 m_FoodStage = new FoodStage(this);
1135
1136 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1137 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1138 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1139 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1140 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1141
1142 m_SoundPlaying = "";
1144 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1145 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1146 }
1147 }
1148
1149 override void EEInit()
1150 {
1151 super.EEInit();
1152
1153 UpdateVisuals();
1154 }
1155
1156 override void EEDelete(EntityAI parent)
1157 {
1158 super.EEDelete(parent);
1159
1160 RemoveAudio();
1161 }
1162
1164 {
1165 super.EEItemLocationChanged(oldLoc, newLoc);
1166
1168 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1169 {
1170 switch (oldLoc.GetParent().GetType())
1171 {
1172 case "FryingPan":
1173 case "Pot":
1174 case "Cauldron":
1175 case "SharpWoodenStick":
1176 MakeSoundsOnClient(false);
1177 break;
1178 }
1179
1181 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1182 MakeSoundsOnClient(false);
1183 }
1184 }
1185
1186 void UpdateVisuals()
1187 {
1188 if (GetFoodStage())
1189 GetFoodStage().UpdateVisuals();
1190 }
1191
1192 bool Consume(float amount, PlayerBase consumer)
1193 {
1194 AddQuantity(-amount, false, false);
1195 OnConsume(amount, consumer);
1196
1197 return true;
1198 }
1199
1200 void OnConsume(float amount, PlayerBase consumer);
1201
1202 //food staging
1203 override bool CanBeCooked()
1204 {
1205 return false;
1206 }
1207
1208 override bool CanBeCookedOnStick()
1209 {
1210 return false;
1211 }
1212
1213 //================================================================
1214 // SYNCHRONIZATION
1215 //================================================================
1216 void Synchronize()
1217 {
1218 SetSynchDirty();
1219
1220 if (GetGame().IsMultiplayer())
1221 UpdateVisuals();
1222 }
1223
1224 override void OnVariablesSynchronized()
1225 {
1226 super.OnVariablesSynchronized();
1227
1228 UpdateVisuals();
1229
1230 //update audio
1232 RefreshAudio();
1233 else
1234 RemoveAudio();
1235 }
1236
1237 //================================================================
1238 // AUDIO EFFECTS (WHEN ON DCS)
1239 //================================================================
1241 {
1244
1245 Synchronize();
1246 }
1247
1248 protected void RefreshAudio()
1249 {
1250 string soundName = "";
1251
1253
1254 switch (GetFoodStageType())
1255 {
1256 case FoodStageType.RAW:
1258 if (nextFoodState == FoodStageType.BOILED)
1259 soundName = "";
1260 break;
1261 case FoodStageType.BAKED:
1263 break;
1264 case FoodStageType.BURNED:
1266 break;
1267 default:
1268 soundName = "";
1269 break;
1270 }
1271
1273 }
1274
1275 protected void RemoveAudio()
1276 {
1277 m_MakeCookingSounds = false;
1279 }
1280
1281 //================================================================
1282 // SERIALIZATION
1283 //================================================================
1284 override void OnStoreSave(ParamsWriteContext ctx)
1285 {
1286 super.OnStoreSave(ctx);
1287
1288 if (GetFoodStage())
1289 GetFoodStage().OnStoreSave(ctx);
1290
1291 // food decay
1292 ctx.Write(m_DecayTimer);
1293 ctx.Write(m_LastDecayStage);
1294 }
1295
1296 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1297 {
1298 if (!super.OnStoreLoad(ctx, version))
1299 return false;
1300
1301 if (GetFoodStage())
1302 {
1303 if (!GetFoodStage().OnStoreLoad(ctx, version))
1304 return false;
1305 }
1306
1307 if (version >= 115)
1308 {
1309 if (!ctx.Read(m_DecayTimer))
1310 {
1311 m_DecayTimer = 0.0;
1312 return false;
1313 }
1314 if (!ctx.Read(m_LastDecayStage))
1315 {
1317 return false;
1318 }
1319 }
1320
1321 return true;
1322 }
1323
1324 override void AfterStoreLoad()
1325 {
1326 super.AfterStoreLoad();
1327
1328 Synchronize();
1329 }
1330
1331 //get food stage
1333 {
1334 return m_FoodStage;
1335 }
1336
1337 //food types
1338 override bool IsMeat()
1339 {
1340 return false;
1341 }
1342
1343 override bool IsCorpse()
1344 {
1345 return false;
1346 }
1347
1348 override bool IsFruit()
1349 {
1350 return false;
1351 }
1352
1353 override bool IsMushroom()
1354 {
1355 return false;
1356 }
1357
1358 //================================================================
1359 // NUTRITIONAL VALUES
1360 //================================================================
1361 //food properties
1362 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1363 {
1365 if (food_item && food_item.GetFoodStage())
1366 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1367 else if (classname != "" && food_stage)
1368 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1369 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1370 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1371
1372 }
1373
1374 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1375 {
1377 if (food_item && food_item.GetFoodStage())
1378 return FoodStage.GetEnergy(food_item.GetFoodStage());
1379 else if (classname != "" && food_stage)
1380 return FoodStage.GetEnergy(null, food_stage, classname);
1381 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1382 return GetGame().ConfigGetFloat(class_path + " energy");
1383 }
1384
1385 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1386 {
1388 if (food_item && food_item.GetFoodStage())
1389 return FoodStage.GetWater(food_item.GetFoodStage());
1390 else if (classname != "" && food_stage)
1391 return FoodStage.GetWater(null, food_stage, classname);
1392 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1393 return GetGame().ConfigGetFloat(class_path + " water");
1394 }
1395
1396 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1397 {
1399 if (food_item && food_item.GetFoodStage())
1400 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1401 else if (classname != "" && food_stage)
1402 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1403 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1404 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1405
1406 }
1407
1408 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1409 {
1411 if (food_item && food_item.GetFoodStage())
1412 return FoodStage.GetToxicity(food_item.GetFoodStage());
1413 else if (classname != "" && food_stage)
1414 return FoodStage.GetToxicity(null, food_stage, classname);
1415 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1416 return GetGame().ConfigGetFloat(class_path + " toxicity");
1417 }
1418
1419 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1420 {
1422 if (food_item && food_item.GetFoodStage())
1423 return FoodStage.GetAgents(food_item.GetFoodStage());
1424 else if (classname != "" && food_stage)
1425 return FoodStage.GetAgents(null, food_stage, classname);
1426 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1427 return GetGame().ConfigGetInt(class_path + " agents");
1428 }
1429
1430 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1431 {
1433 if (food_item && food_item.GetFoodStage())
1434 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1435 else if (classname != "" && food_stage)
1436 return FoodStage.GetDigestibility(null, food_stage, classname);
1437 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1438 return GetGame().ConfigGetInt(class_path + " digestibility");
1439 }
1440
1442 {
1444 }
1445
1446 //================================================================
1447 // FOOD STAGING
1448 //================================================================
1450 {
1451 return GetFoodStage().GetFoodStageType();
1452 }
1453
1454 //food stage states
1455 bool IsFoodRaw()
1456 {
1457 if (GetFoodStage())
1458 return GetFoodStage().IsFoodRaw();
1459
1460 return false;
1461 }
1462
1463 bool IsFoodBaked()
1464 {
1465 if (GetFoodStage())
1466 return GetFoodStage().IsFoodBaked();
1467
1468 return false;
1469 }
1470
1471 bool IsFoodBoiled()
1472 {
1473 if (GetFoodStage())
1474 return GetFoodStage().IsFoodBoiled();
1475
1476 return false;
1477 }
1478
1479 bool IsFoodDried()
1480 {
1481 if (GetFoodStage())
1482 return GetFoodStage().IsFoodDried();
1483
1484 return false;
1485 }
1486
1487 bool IsFoodBurned()
1488 {
1489 if (GetFoodStage())
1490 return GetFoodStage().IsFoodBurned();
1491
1492 return false;
1493 }
1494
1495 bool IsFoodRotten()
1496 {
1497 if (GetFoodStage())
1498 return GetFoodStage().IsFoodRotten();
1499
1500 return false;
1501 }
1502
1503 //food stage change
1505 {
1506 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1507 }
1508
1510 {
1511 return GetFoodStage().GetNextFoodStageType(cooking_method);
1512 }
1513
1515 {
1516 return GetFoodStage().GetFoodStageName(food_stage_type);
1517 }
1518
1520 {
1521 return GetFoodStage().CanChangeToNewStage(cooking_method);
1522 }
1523
1524 //Use this to receive food stage from another Edible_Base
1526 {
1527 if (!source.HasFoodStage())
1528 return;
1529 m_LastDecayStage = source.GetLastDecayStage();
1530 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1531 m_DecayTimer = source.GetDecayTimer();
1532 m_DecayDelta = source.GetDecayDelta();
1533 }
1534
1535 //================================================================
1536 // COOKING
1537 //================================================================
1538 //cooking time
1539 float GetCookingTime()
1540 {
1541 return GetFoodStage().GetCookingTime();
1542 }
1543
1544 void SetCookingTime(float time)
1545 {
1546 GetFoodStage().SetCookingTime(time);
1547
1548 //synchronize when calling on server
1549 Synchronize();
1550 }
1551
1552 //replace edible with new item (opening cans)
1553 void ReplaceEdibleWithNew(string typeName)
1554 {
1555 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1556 if (player)
1557 {
1559 player.ServerReplaceItemInHandsWithNew(lambda);
1560 }
1561 else
1562 Error("ReplaceEdibleWithNew - cannot use edible without player");
1563 }
1564
1565 override void SetActions()
1566 {
1567 super.SetActions();
1568
1569 AddAction(ActionAttach);
1571 }
1572
1573 protected void SoundCookingStart(string sound_name)
1574 {
1575#ifndef SERVER
1577 {
1579
1582 }
1583#endif
1584 }
1585
1586 protected void SoundCookingStop()
1587 {
1588#ifndef SERVER
1590 {
1593 m_SoundPlaying = "";
1594 }
1595#endif
1596 }
1597
1598 override bool CanHaveTemperature()
1599 {
1600 return true;
1601 }
1602
1603 override bool CanDecay()
1604 {
1605 return false;
1606 }
1607
1608 override bool CanProcessDecay()
1609 {
1610 return (GetFoodStageType() != FoodStageType.ROTTEN);
1611 }
1612
1613 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1614 {
1615 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1616 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1617 if (hasRootAsPlayer)
1619
1620 /*Print( "-------------------------" );
1621 Print( this );
1622 Print( m_DecayTimer );
1623 Print( m_DecayDelta );
1624 Print( m_LastDecayStage );*/
1625
1626 if (IsFruit() || IsMushroom())
1627 {
1628 // fruit, vegetables and mushrooms
1630 {
1631 switch (GetFoodStageType())
1632 {
1633 case FoodStageType.RAW:
1636 break;
1637
1638 case FoodStageType.BOILED:
1641 break;
1642
1643 case FoodStageType.BAKED:
1646 break;
1647
1648 case FoodStageType.DRIED:
1649 case FoodStageType.BURNED:
1650 case FoodStageType.ROTTEN:
1651 default:
1652 m_DecayTimer = -1;
1654 return;
1655 }
1656
1657 //m_DecayTimer = m_DecayTimer / 1000.0;
1658 }
1659
1661
1662 if (m_DecayTimer <= 0)
1663 {
1664 if (m_LastDecayStage != FoodStageType.NONE)
1665 {
1666 // switch to decayed stage
1667 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1670 {
1671 int rng = Math.RandomIntInclusive(0, 100);
1674 else
1675 {
1678 else
1680 }
1681 }
1682 }
1683 }
1684
1685 }
1686 else if (IsMeat())
1687 {
1688 // meat
1690 {
1691 switch (GetFoodStageType())
1692 {
1693 case FoodStageType.RAW:
1696 break;
1697
1698 case FoodStageType.BOILED:
1701 break;
1702
1703 case FoodStageType.BAKED:
1706 break;
1707
1708 case FoodStageType.DRIED:
1711 break;
1712
1713 case FoodStageType.BURNED:
1714 case FoodStageType.ROTTEN:
1715 default:
1716 m_DecayTimer = -1;
1718 return;
1719 }
1720 }
1721
1723
1724 if (m_DecayTimer <= 0)
1725 {
1726 if (m_LastDecayStage != FoodStageType.NONE)
1727 {
1728 // switch to decayed stage
1731 }
1732 }
1733 }
1734 else if (IsCorpse())
1735 {
1736 // corpse
1738 {
1739 switch (GetFoodStageType())
1740 {
1741 case FoodStageType.RAW:
1744 break;
1745
1746 case FoodStageType.BURNED:
1747 case FoodStageType.ROTTEN:
1748 default:
1749 m_DecayTimer = -1;
1751 return;
1752 }
1753 }
1754
1756
1757 if (m_DecayTimer <= 0)
1758 {
1759 if (m_LastDecayStage != FoodStageType.NONE)
1760 {
1761 // switch to decayed stage
1764 }
1765 }
1766 }
1767 else
1768 {
1769 // opened cans
1771
1772 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1773 {
1776 //m_DecayTimer = m_DecayTimer / 1000.0;
1777 }
1778 else
1779 {
1780 if (m_DecayTimer <= 0)
1781 {
1782 InsertAgent(eAgents.FOOD_POISON, 1);
1783 m_DecayTimer = -1;
1784 }
1785 }
1786 }
1787
1788 m_DecayDelta = 0.0;
1789 }
1790
1792 {
1793 super.GetDebugActions(outputList);
1794
1795 if (HasFoodStage())
1796 {
1797 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1798 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1799 }
1800 }
1801
1802 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1803 {
1804 super.OnAction(action_id, player, ctx);
1805
1806 if (GetGame().IsServer())
1807 {
1808 if (action_id == EActions.FOOD_STAGE_PREV)
1809 {
1811 if (food_stage_prev <= 0)
1812 food_stage_prev = FoodStageType.COUNT - 1;
1814 return true;
1815 }
1816 else if (action_id == EActions.FOOD_STAGE_NEXT)
1817 {
1819 if (food_stage_next >= FoodStageType.COUNT)
1822 return true;
1823 }
1824 }
1825 return false;
1826 }
1827
1828 override string GetDebugText()
1829 {
1830 string debug_output;
1831
1832 debug_output = super.GetDebugText();
1833
1834 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1835 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1836
1837 return debug_output;
1838 }
1839
1840 //================================================================
1841 // GENERAL GETTERS
1842 //================================================================
1843
1844 float GetDecayTimer()
1845 {
1846 return m_DecayTimer;
1847 }
1848
1849 float GetDecayDelta()
1850 {
1851 return m_DecayDelta;
1852 }
1853
1855 {
1856 return m_LastDecayStage;
1857 }
1858}
1859
1861{
1863};

◆ IsFoodBurned()

bool ReplaceEdibleWithNewLambda::IsFoodBurned ( )
protected

Definition at line 1127 of file Edible_Base.c.

1127 : ItemBase
1128{
1129 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1130
1131 const string SOUND_BAKING_START = "Baking_SoundSet";
1132 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1133 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1134
1135 protected bool m_MakeCookingSounds;
1136 protected SoundOnVehicle m_SoundCooking;
1138 protected string m_SoundPlaying;
1140 protected float m_DecayTimer;
1141 protected float m_DecayDelta = 0.0;
1143
1145
1146 void Edible_Base()
1147 {
1148 if (HasFoodStage())
1149 {
1150 m_FoodStage = new FoodStage(this);
1151
1152 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1153 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1154 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1155 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1156 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1157
1158 m_SoundPlaying = "";
1160 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1161 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1162 }
1163 }
1164
1165 override void EEInit()
1166 {
1167 super.EEInit();
1168
1169 UpdateVisuals();
1170 }
1171
1172 override void EEDelete(EntityAI parent)
1173 {
1174 super.EEDelete(parent);
1175
1176 RemoveAudio();
1177 }
1178
1180 {
1181 super.EEItemLocationChanged(oldLoc, newLoc);
1182
1184 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1185 {
1186 switch (oldLoc.GetParent().GetType())
1187 {
1188 case "FryingPan":
1189 case "Pot":
1190 case "Cauldron":
1191 case "SharpWoodenStick":
1192 MakeSoundsOnClient(false);
1193 break;
1194 }
1195
1197 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1198 MakeSoundsOnClient(false);
1199 }
1200 }
1201
1202 void UpdateVisuals()
1203 {
1204 if (GetFoodStage())
1205 GetFoodStage().UpdateVisuals();
1206 }
1207
1208 bool Consume(float amount, PlayerBase consumer)
1209 {
1210 AddQuantity(-amount, false, false);
1211 OnConsume(amount, consumer);
1212
1213 return true;
1214 }
1215
1216 void OnConsume(float amount, PlayerBase consumer);
1217
1218 //food staging
1219 override bool CanBeCooked()
1220 {
1221 return false;
1222 }
1223
1224 override bool CanBeCookedOnStick()
1225 {
1226 return false;
1227 }
1228
1229 //================================================================
1230 // SYNCHRONIZATION
1231 //================================================================
1232 void Synchronize()
1233 {
1234 SetSynchDirty();
1235
1236 if (GetGame().IsMultiplayer())
1237 UpdateVisuals();
1238 }
1239
1240 override void OnVariablesSynchronized()
1241 {
1242 super.OnVariablesSynchronized();
1243
1244 UpdateVisuals();
1245
1246 //update audio
1248 RefreshAudio();
1249 else
1250 RemoveAudio();
1251 }
1252
1253 //================================================================
1254 // AUDIO EFFECTS (WHEN ON DCS)
1255 //================================================================
1257 {
1260
1261 Synchronize();
1262 }
1263
1264 protected void RefreshAudio()
1265 {
1266 string soundName = "";
1267
1269
1270 switch (GetFoodStageType())
1271 {
1272 case FoodStageType.RAW:
1274 if (nextFoodState == FoodStageType.BOILED)
1275 soundName = "";
1276 break;
1277 case FoodStageType.BAKED:
1279 break;
1280 case FoodStageType.BURNED:
1282 break;
1283 default:
1284 soundName = "";
1285 break;
1286 }
1287
1289 }
1290
1291 protected void RemoveAudio()
1292 {
1293 m_MakeCookingSounds = false;
1295 }
1296
1297 //================================================================
1298 // SERIALIZATION
1299 //================================================================
1300 override void OnStoreSave(ParamsWriteContext ctx)
1301 {
1302 super.OnStoreSave(ctx);
1303
1304 if (GetFoodStage())
1305 GetFoodStage().OnStoreSave(ctx);
1306
1307 // food decay
1308 ctx.Write(m_DecayTimer);
1309 ctx.Write(m_LastDecayStage);
1310 }
1311
1312 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1313 {
1314 if (!super.OnStoreLoad(ctx, version))
1315 return false;
1316
1317 if (GetFoodStage())
1318 {
1319 if (!GetFoodStage().OnStoreLoad(ctx, version))
1320 return false;
1321 }
1322
1323 if (version >= 115)
1324 {
1325 if (!ctx.Read(m_DecayTimer))
1326 {
1327 m_DecayTimer = 0.0;
1328 return false;
1329 }
1330 if (!ctx.Read(m_LastDecayStage))
1331 {
1333 return false;
1334 }
1335 }
1336
1337 return true;
1338 }
1339
1340 override void AfterStoreLoad()
1341 {
1342 super.AfterStoreLoad();
1343
1344 Synchronize();
1345 }
1346
1347 //get food stage
1349 {
1350 return m_FoodStage;
1351 }
1352
1353 //food types
1354 override bool IsMeat()
1355 {
1356 return false;
1357 }
1358
1359 override bool IsCorpse()
1360 {
1361 return false;
1362 }
1363
1364 override bool IsFruit()
1365 {
1366 return false;
1367 }
1368
1369 override bool IsMushroom()
1370 {
1371 return false;
1372 }
1373
1374 //================================================================
1375 // NUTRITIONAL VALUES
1376 //================================================================
1377 //food properties
1378 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1379 {
1381 if (food_item && food_item.GetFoodStage())
1382 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1383 else if (classname != "" && food_stage)
1384 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1385 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1386 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1387
1388 }
1389
1390 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1391 {
1393 if (food_item && food_item.GetFoodStage())
1394 return FoodStage.GetEnergy(food_item.GetFoodStage());
1395 else if (classname != "" && food_stage)
1396 return FoodStage.GetEnergy(null, food_stage, classname);
1397 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1398 return GetGame().ConfigGetFloat(class_path + " energy");
1399 }
1400
1401 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1402 {
1404 if (food_item && food_item.GetFoodStage())
1405 return FoodStage.GetWater(food_item.GetFoodStage());
1406 else if (classname != "" && food_stage)
1407 return FoodStage.GetWater(null, food_stage, classname);
1408 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1409 return GetGame().ConfigGetFloat(class_path + " water");
1410 }
1411
1412 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1413 {
1415 if (food_item && food_item.GetFoodStage())
1416 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1417 else if (classname != "" && food_stage)
1418 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1419 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1420 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1421
1422 }
1423
1424 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1425 {
1427 if (food_item && food_item.GetFoodStage())
1428 return FoodStage.GetToxicity(food_item.GetFoodStage());
1429 else if (classname != "" && food_stage)
1430 return FoodStage.GetToxicity(null, food_stage, classname);
1431 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1432 return GetGame().ConfigGetFloat(class_path + " toxicity");
1433 }
1434
1435 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1436 {
1438 if (food_item && food_item.GetFoodStage())
1439 return FoodStage.GetAgents(food_item.GetFoodStage());
1440 else if (classname != "" && food_stage)
1441 return FoodStage.GetAgents(null, food_stage, classname);
1442 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1443 return GetGame().ConfigGetInt(class_path + " agents");
1444 }
1445
1446 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1447 {
1449 if (food_item && food_item.GetFoodStage())
1450 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1451 else if (classname != "" && food_stage)
1452 return FoodStage.GetDigestibility(null, food_stage, classname);
1453 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1454 return GetGame().ConfigGetInt(class_path + " digestibility");
1455 }
1456
1458 {
1460 }
1461
1462 //================================================================
1463 // FOOD STAGING
1464 //================================================================
1466 {
1467 return GetFoodStage().GetFoodStageType();
1468 }
1469
1470 //food stage states
1471 bool IsFoodRaw()
1472 {
1473 if (GetFoodStage())
1474 return GetFoodStage().IsFoodRaw();
1475
1476 return false;
1477 }
1478
1479 bool IsFoodBaked()
1480 {
1481 if (GetFoodStage())
1482 return GetFoodStage().IsFoodBaked();
1483
1484 return false;
1485 }
1486
1487 bool IsFoodBoiled()
1488 {
1489 if (GetFoodStage())
1490 return GetFoodStage().IsFoodBoiled();
1491
1492 return false;
1493 }
1494
1495 bool IsFoodDried()
1496 {
1497 if (GetFoodStage())
1498 return GetFoodStage().IsFoodDried();
1499
1500 return false;
1501 }
1502
1503 bool IsFoodBurned()
1504 {
1505 if (GetFoodStage())
1506 return GetFoodStage().IsFoodBurned();
1507
1508 return false;
1509 }
1510
1511 bool IsFoodRotten()
1512 {
1513 if (GetFoodStage())
1514 return GetFoodStage().IsFoodRotten();
1515
1516 return false;
1517 }
1518
1519 //food stage change
1521 {
1522 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1523 }
1524
1526 {
1527 return GetFoodStage().GetNextFoodStageType(cooking_method);
1528 }
1529
1531 {
1532 return GetFoodStage().GetFoodStageName(food_stage_type);
1533 }
1534
1536 {
1537 return GetFoodStage().CanChangeToNewStage(cooking_method);
1538 }
1539
1540 //Use this to receive food stage from another Edible_Base
1542 {
1543 if (!source.HasFoodStage())
1544 return;
1545 m_LastDecayStage = source.GetLastDecayStage();
1546 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1547 m_DecayTimer = source.GetDecayTimer();
1548 m_DecayDelta = source.GetDecayDelta();
1549 }
1550
1551 //================================================================
1552 // COOKING
1553 //================================================================
1554 //cooking time
1555 float GetCookingTime()
1556 {
1557 return GetFoodStage().GetCookingTime();
1558 }
1559
1560 void SetCookingTime(float time)
1561 {
1562 GetFoodStage().SetCookingTime(time);
1563
1564 //synchronize when calling on server
1565 Synchronize();
1566 }
1567
1568 //replace edible with new item (opening cans)
1569 void ReplaceEdibleWithNew(string typeName)
1570 {
1571 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1572 if (player)
1573 {
1575 player.ServerReplaceItemInHandsWithNew(lambda);
1576 }
1577 else
1578 Error("ReplaceEdibleWithNew - cannot use edible without player");
1579 }
1580
1581 override void SetActions()
1582 {
1583 super.SetActions();
1584
1585 AddAction(ActionAttach);
1587 }
1588
1589 protected void SoundCookingStart(string sound_name)
1590 {
1591#ifndef SERVER
1593 {
1595
1598 }
1599#endif
1600 }
1601
1602 protected void SoundCookingStop()
1603 {
1604#ifndef SERVER
1606 {
1609 m_SoundPlaying = "";
1610 }
1611#endif
1612 }
1613
1614 override bool CanHaveTemperature()
1615 {
1616 return true;
1617 }
1618
1619 override bool CanDecay()
1620 {
1621 return false;
1622 }
1623
1624 override bool CanProcessDecay()
1625 {
1626 return (GetFoodStageType() != FoodStageType.ROTTEN);
1627 }
1628
1629 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1630 {
1631 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1632 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1633 if (hasRootAsPlayer)
1635
1636 /*Print( "-------------------------" );
1637 Print( this );
1638 Print( m_DecayTimer );
1639 Print( m_DecayDelta );
1640 Print( m_LastDecayStage );*/
1641
1642 if (IsFruit() || IsMushroom())
1643 {
1644 // fruit, vegetables and mushrooms
1646 {
1647 switch (GetFoodStageType())
1648 {
1649 case FoodStageType.RAW:
1652 break;
1653
1654 case FoodStageType.BOILED:
1657 break;
1658
1659 case FoodStageType.BAKED:
1662 break;
1663
1664 case FoodStageType.DRIED:
1665 case FoodStageType.BURNED:
1666 case FoodStageType.ROTTEN:
1667 default:
1668 m_DecayTimer = -1;
1670 return;
1671 }
1672
1673 //m_DecayTimer = m_DecayTimer / 1000.0;
1674 }
1675
1677
1678 if (m_DecayTimer <= 0)
1679 {
1680 if (m_LastDecayStage != FoodStageType.NONE)
1681 {
1682 // switch to decayed stage
1683 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1686 {
1687 int rng = Math.RandomIntInclusive(0, 100);
1690 else
1691 {
1694 else
1696 }
1697 }
1698 }
1699 }
1700
1701 }
1702 else if (IsMeat())
1703 {
1704 // meat
1706 {
1707 switch (GetFoodStageType())
1708 {
1709 case FoodStageType.RAW:
1712 break;
1713
1714 case FoodStageType.BOILED:
1717 break;
1718
1719 case FoodStageType.BAKED:
1722 break;
1723
1724 case FoodStageType.DRIED:
1727 break;
1728
1729 case FoodStageType.BURNED:
1730 case FoodStageType.ROTTEN:
1731 default:
1732 m_DecayTimer = -1;
1734 return;
1735 }
1736 }
1737
1739
1740 if (m_DecayTimer <= 0)
1741 {
1742 if (m_LastDecayStage != FoodStageType.NONE)
1743 {
1744 // switch to decayed stage
1747 }
1748 }
1749 }
1750 else if (IsCorpse())
1751 {
1752 // corpse
1754 {
1755 switch (GetFoodStageType())
1756 {
1757 case FoodStageType.RAW:
1760 break;
1761
1762 case FoodStageType.BURNED:
1763 case FoodStageType.ROTTEN:
1764 default:
1765 m_DecayTimer = -1;
1767 return;
1768 }
1769 }
1770
1772
1773 if (m_DecayTimer <= 0)
1774 {
1775 if (m_LastDecayStage != FoodStageType.NONE)
1776 {
1777 // switch to decayed stage
1780 }
1781 }
1782 }
1783 else
1784 {
1785 // opened cans
1787
1788 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1789 {
1792 //m_DecayTimer = m_DecayTimer / 1000.0;
1793 }
1794 else
1795 {
1796 if (m_DecayTimer <= 0)
1797 {
1798 InsertAgent(eAgents.FOOD_POISON, 1);
1799 m_DecayTimer = -1;
1800 }
1801 }
1802 }
1803
1804 m_DecayDelta = 0.0;
1805 }
1806
1808 {
1809 super.GetDebugActions(outputList);
1810
1811 if (HasFoodStage())
1812 {
1813 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1814 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1815 }
1816 }
1817
1818 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1819 {
1820 super.OnAction(action_id, player, ctx);
1821
1822 if (GetGame().IsServer())
1823 {
1824 if (action_id == EActions.FOOD_STAGE_PREV)
1825 {
1827 if (food_stage_prev <= 0)
1828 food_stage_prev = FoodStageType.COUNT - 1;
1830 return true;
1831 }
1832 else if (action_id == EActions.FOOD_STAGE_NEXT)
1833 {
1835 if (food_stage_next >= FoodStageType.COUNT)
1838 return true;
1839 }
1840 }
1841 return false;
1842 }
1843
1844 override string GetDebugText()
1845 {
1846 string debug_output;
1847
1848 debug_output = super.GetDebugText();
1849
1850 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1851 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1852
1853 return debug_output;
1854 }
1855
1856 //================================================================
1857 // GENERAL GETTERS
1858 //================================================================
1859
1860 float GetDecayTimer()
1861 {
1862 return m_DecayTimer;
1863 }
1864
1865 float GetDecayDelta()
1866 {
1867 return m_DecayDelta;
1868 }
1869
1871 {
1872 return m_LastDecayStage;
1873 }
1874}
1875
1877{
1879};

◆ IsFoodDried()

bool ReplaceEdibleWithNewLambda::IsFoodDried ( )
protected

Definition at line 1119 of file Edible_Base.c.

1119 : ItemBase
1120{
1121 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1122
1123 const string SOUND_BAKING_START = "Baking_SoundSet";
1124 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1125 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1126
1127 protected bool m_MakeCookingSounds;
1128 protected SoundOnVehicle m_SoundCooking;
1130 protected string m_SoundPlaying;
1132 protected float m_DecayTimer;
1133 protected float m_DecayDelta = 0.0;
1135
1137
1138 void Edible_Base()
1139 {
1140 if (HasFoodStage())
1141 {
1142 m_FoodStage = new FoodStage(this);
1143
1144 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1145 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1146 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1147 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1148 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1149
1150 m_SoundPlaying = "";
1152 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1153 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1154 }
1155 }
1156
1157 override void EEInit()
1158 {
1159 super.EEInit();
1160
1161 UpdateVisuals();
1162 }
1163
1164 override void EEDelete(EntityAI parent)
1165 {
1166 super.EEDelete(parent);
1167
1168 RemoveAudio();
1169 }
1170
1172 {
1173 super.EEItemLocationChanged(oldLoc, newLoc);
1174
1176 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1177 {
1178 switch (oldLoc.GetParent().GetType())
1179 {
1180 case "FryingPan":
1181 case "Pot":
1182 case "Cauldron":
1183 case "SharpWoodenStick":
1184 MakeSoundsOnClient(false);
1185 break;
1186 }
1187
1189 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1190 MakeSoundsOnClient(false);
1191 }
1192 }
1193
1194 void UpdateVisuals()
1195 {
1196 if (GetFoodStage())
1197 GetFoodStage().UpdateVisuals();
1198 }
1199
1200 bool Consume(float amount, PlayerBase consumer)
1201 {
1202 AddQuantity(-amount, false, false);
1203 OnConsume(amount, consumer);
1204
1205 return true;
1206 }
1207
1208 void OnConsume(float amount, PlayerBase consumer);
1209
1210 //food staging
1211 override bool CanBeCooked()
1212 {
1213 return false;
1214 }
1215
1216 override bool CanBeCookedOnStick()
1217 {
1218 return false;
1219 }
1220
1221 //================================================================
1222 // SYNCHRONIZATION
1223 //================================================================
1224 void Synchronize()
1225 {
1226 SetSynchDirty();
1227
1228 if (GetGame().IsMultiplayer())
1229 UpdateVisuals();
1230 }
1231
1232 override void OnVariablesSynchronized()
1233 {
1234 super.OnVariablesSynchronized();
1235
1236 UpdateVisuals();
1237
1238 //update audio
1240 RefreshAudio();
1241 else
1242 RemoveAudio();
1243 }
1244
1245 //================================================================
1246 // AUDIO EFFECTS (WHEN ON DCS)
1247 //================================================================
1249 {
1252
1253 Synchronize();
1254 }
1255
1256 protected void RefreshAudio()
1257 {
1258 string soundName = "";
1259
1261
1262 switch (GetFoodStageType())
1263 {
1264 case FoodStageType.RAW:
1266 if (nextFoodState == FoodStageType.BOILED)
1267 soundName = "";
1268 break;
1269 case FoodStageType.BAKED:
1271 break;
1272 case FoodStageType.BURNED:
1274 break;
1275 default:
1276 soundName = "";
1277 break;
1278 }
1279
1281 }
1282
1283 protected void RemoveAudio()
1284 {
1285 m_MakeCookingSounds = false;
1287 }
1288
1289 //================================================================
1290 // SERIALIZATION
1291 //================================================================
1292 override void OnStoreSave(ParamsWriteContext ctx)
1293 {
1294 super.OnStoreSave(ctx);
1295
1296 if (GetFoodStage())
1297 GetFoodStage().OnStoreSave(ctx);
1298
1299 // food decay
1300 ctx.Write(m_DecayTimer);
1301 ctx.Write(m_LastDecayStage);
1302 }
1303
1304 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1305 {
1306 if (!super.OnStoreLoad(ctx, version))
1307 return false;
1308
1309 if (GetFoodStage())
1310 {
1311 if (!GetFoodStage().OnStoreLoad(ctx, version))
1312 return false;
1313 }
1314
1315 if (version >= 115)
1316 {
1317 if (!ctx.Read(m_DecayTimer))
1318 {
1319 m_DecayTimer = 0.0;
1320 return false;
1321 }
1322 if (!ctx.Read(m_LastDecayStage))
1323 {
1325 return false;
1326 }
1327 }
1328
1329 return true;
1330 }
1331
1332 override void AfterStoreLoad()
1333 {
1334 super.AfterStoreLoad();
1335
1336 Synchronize();
1337 }
1338
1339 //get food stage
1341 {
1342 return m_FoodStage;
1343 }
1344
1345 //food types
1346 override bool IsMeat()
1347 {
1348 return false;
1349 }
1350
1351 override bool IsCorpse()
1352 {
1353 return false;
1354 }
1355
1356 override bool IsFruit()
1357 {
1358 return false;
1359 }
1360
1361 override bool IsMushroom()
1362 {
1363 return false;
1364 }
1365
1366 //================================================================
1367 // NUTRITIONAL VALUES
1368 //================================================================
1369 //food properties
1370 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1371 {
1373 if (food_item && food_item.GetFoodStage())
1374 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1375 else if (classname != "" && food_stage)
1376 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1377 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1378 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1379
1380 }
1381
1382 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1383 {
1385 if (food_item && food_item.GetFoodStage())
1386 return FoodStage.GetEnergy(food_item.GetFoodStage());
1387 else if (classname != "" && food_stage)
1388 return FoodStage.GetEnergy(null, food_stage, classname);
1389 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1390 return GetGame().ConfigGetFloat(class_path + " energy");
1391 }
1392
1393 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1394 {
1396 if (food_item && food_item.GetFoodStage())
1397 return FoodStage.GetWater(food_item.GetFoodStage());
1398 else if (classname != "" && food_stage)
1399 return FoodStage.GetWater(null, food_stage, classname);
1400 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1401 return GetGame().ConfigGetFloat(class_path + " water");
1402 }
1403
1404 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1405 {
1407 if (food_item && food_item.GetFoodStage())
1408 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1409 else if (classname != "" && food_stage)
1410 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1411 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1412 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1413
1414 }
1415
1416 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1417 {
1419 if (food_item && food_item.GetFoodStage())
1420 return FoodStage.GetToxicity(food_item.GetFoodStage());
1421 else if (classname != "" && food_stage)
1422 return FoodStage.GetToxicity(null, food_stage, classname);
1423 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1424 return GetGame().ConfigGetFloat(class_path + " toxicity");
1425 }
1426
1427 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1428 {
1430 if (food_item && food_item.GetFoodStage())
1431 return FoodStage.GetAgents(food_item.GetFoodStage());
1432 else if (classname != "" && food_stage)
1433 return FoodStage.GetAgents(null, food_stage, classname);
1434 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1435 return GetGame().ConfigGetInt(class_path + " agents");
1436 }
1437
1438 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1439 {
1441 if (food_item && food_item.GetFoodStage())
1442 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1443 else if (classname != "" && food_stage)
1444 return FoodStage.GetDigestibility(null, food_stage, classname);
1445 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1446 return GetGame().ConfigGetInt(class_path + " digestibility");
1447 }
1448
1450 {
1452 }
1453
1454 //================================================================
1455 // FOOD STAGING
1456 //================================================================
1458 {
1459 return GetFoodStage().GetFoodStageType();
1460 }
1461
1462 //food stage states
1463 bool IsFoodRaw()
1464 {
1465 if (GetFoodStage())
1466 return GetFoodStage().IsFoodRaw();
1467
1468 return false;
1469 }
1470
1471 bool IsFoodBaked()
1472 {
1473 if (GetFoodStage())
1474 return GetFoodStage().IsFoodBaked();
1475
1476 return false;
1477 }
1478
1479 bool IsFoodBoiled()
1480 {
1481 if (GetFoodStage())
1482 return GetFoodStage().IsFoodBoiled();
1483
1484 return false;
1485 }
1486
1487 bool IsFoodDried()
1488 {
1489 if (GetFoodStage())
1490 return GetFoodStage().IsFoodDried();
1491
1492 return false;
1493 }
1494
1495 bool IsFoodBurned()
1496 {
1497 if (GetFoodStage())
1498 return GetFoodStage().IsFoodBurned();
1499
1500 return false;
1501 }
1502
1503 bool IsFoodRotten()
1504 {
1505 if (GetFoodStage())
1506 return GetFoodStage().IsFoodRotten();
1507
1508 return false;
1509 }
1510
1511 //food stage change
1513 {
1514 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1515 }
1516
1518 {
1519 return GetFoodStage().GetNextFoodStageType(cooking_method);
1520 }
1521
1523 {
1524 return GetFoodStage().GetFoodStageName(food_stage_type);
1525 }
1526
1528 {
1529 return GetFoodStage().CanChangeToNewStage(cooking_method);
1530 }
1531
1532 //Use this to receive food stage from another Edible_Base
1534 {
1535 if (!source.HasFoodStage())
1536 return;
1537 m_LastDecayStage = source.GetLastDecayStage();
1538 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1539 m_DecayTimer = source.GetDecayTimer();
1540 m_DecayDelta = source.GetDecayDelta();
1541 }
1542
1543 //================================================================
1544 // COOKING
1545 //================================================================
1546 //cooking time
1547 float GetCookingTime()
1548 {
1549 return GetFoodStage().GetCookingTime();
1550 }
1551
1552 void SetCookingTime(float time)
1553 {
1554 GetFoodStage().SetCookingTime(time);
1555
1556 //synchronize when calling on server
1557 Synchronize();
1558 }
1559
1560 //replace edible with new item (opening cans)
1561 void ReplaceEdibleWithNew(string typeName)
1562 {
1563 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1564 if (player)
1565 {
1567 player.ServerReplaceItemInHandsWithNew(lambda);
1568 }
1569 else
1570 Error("ReplaceEdibleWithNew - cannot use edible without player");
1571 }
1572
1573 override void SetActions()
1574 {
1575 super.SetActions();
1576
1577 AddAction(ActionAttach);
1579 }
1580
1581 protected void SoundCookingStart(string sound_name)
1582 {
1583#ifndef SERVER
1585 {
1587
1590 }
1591#endif
1592 }
1593
1594 protected void SoundCookingStop()
1595 {
1596#ifndef SERVER
1598 {
1601 m_SoundPlaying = "";
1602 }
1603#endif
1604 }
1605
1606 override bool CanHaveTemperature()
1607 {
1608 return true;
1609 }
1610
1611 override bool CanDecay()
1612 {
1613 return false;
1614 }
1615
1616 override bool CanProcessDecay()
1617 {
1618 return (GetFoodStageType() != FoodStageType.ROTTEN);
1619 }
1620
1621 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1622 {
1623 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1624 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1625 if (hasRootAsPlayer)
1627
1628 /*Print( "-------------------------" );
1629 Print( this );
1630 Print( m_DecayTimer );
1631 Print( m_DecayDelta );
1632 Print( m_LastDecayStage );*/
1633
1634 if (IsFruit() || IsMushroom())
1635 {
1636 // fruit, vegetables and mushrooms
1638 {
1639 switch (GetFoodStageType())
1640 {
1641 case FoodStageType.RAW:
1644 break;
1645
1646 case FoodStageType.BOILED:
1649 break;
1650
1651 case FoodStageType.BAKED:
1654 break;
1655
1656 case FoodStageType.DRIED:
1657 case FoodStageType.BURNED:
1658 case FoodStageType.ROTTEN:
1659 default:
1660 m_DecayTimer = -1;
1662 return;
1663 }
1664
1665 //m_DecayTimer = m_DecayTimer / 1000.0;
1666 }
1667
1669
1670 if (m_DecayTimer <= 0)
1671 {
1672 if (m_LastDecayStage != FoodStageType.NONE)
1673 {
1674 // switch to decayed stage
1675 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1678 {
1679 int rng = Math.RandomIntInclusive(0, 100);
1682 else
1683 {
1686 else
1688 }
1689 }
1690 }
1691 }
1692
1693 }
1694 else if (IsMeat())
1695 {
1696 // meat
1698 {
1699 switch (GetFoodStageType())
1700 {
1701 case FoodStageType.RAW:
1704 break;
1705
1706 case FoodStageType.BOILED:
1709 break;
1710
1711 case FoodStageType.BAKED:
1714 break;
1715
1716 case FoodStageType.DRIED:
1719 break;
1720
1721 case FoodStageType.BURNED:
1722 case FoodStageType.ROTTEN:
1723 default:
1724 m_DecayTimer = -1;
1726 return;
1727 }
1728 }
1729
1731
1732 if (m_DecayTimer <= 0)
1733 {
1734 if (m_LastDecayStage != FoodStageType.NONE)
1735 {
1736 // switch to decayed stage
1739 }
1740 }
1741 }
1742 else if (IsCorpse())
1743 {
1744 // corpse
1746 {
1747 switch (GetFoodStageType())
1748 {
1749 case FoodStageType.RAW:
1752 break;
1753
1754 case FoodStageType.BURNED:
1755 case FoodStageType.ROTTEN:
1756 default:
1757 m_DecayTimer = -1;
1759 return;
1760 }
1761 }
1762
1764
1765 if (m_DecayTimer <= 0)
1766 {
1767 if (m_LastDecayStage != FoodStageType.NONE)
1768 {
1769 // switch to decayed stage
1772 }
1773 }
1774 }
1775 else
1776 {
1777 // opened cans
1779
1780 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1781 {
1784 //m_DecayTimer = m_DecayTimer / 1000.0;
1785 }
1786 else
1787 {
1788 if (m_DecayTimer <= 0)
1789 {
1790 InsertAgent(eAgents.FOOD_POISON, 1);
1791 m_DecayTimer = -1;
1792 }
1793 }
1794 }
1795
1796 m_DecayDelta = 0.0;
1797 }
1798
1800 {
1801 super.GetDebugActions(outputList);
1802
1803 if (HasFoodStage())
1804 {
1805 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1806 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1807 }
1808 }
1809
1810 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1811 {
1812 super.OnAction(action_id, player, ctx);
1813
1814 if (GetGame().IsServer())
1815 {
1816 if (action_id == EActions.FOOD_STAGE_PREV)
1817 {
1819 if (food_stage_prev <= 0)
1820 food_stage_prev = FoodStageType.COUNT - 1;
1822 return true;
1823 }
1824 else if (action_id == EActions.FOOD_STAGE_NEXT)
1825 {
1827 if (food_stage_next >= FoodStageType.COUNT)
1830 return true;
1831 }
1832 }
1833 return false;
1834 }
1835
1836 override string GetDebugText()
1837 {
1838 string debug_output;
1839
1840 debug_output = super.GetDebugText();
1841
1842 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1843 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1844
1845 return debug_output;
1846 }
1847
1848 //================================================================
1849 // GENERAL GETTERS
1850 //================================================================
1851
1852 float GetDecayTimer()
1853 {
1854 return m_DecayTimer;
1855 }
1856
1857 float GetDecayDelta()
1858 {
1859 return m_DecayDelta;
1860 }
1861
1863 {
1864 return m_LastDecayStage;
1865 }
1866}
1867
1869{
1871};

◆ IsFoodRaw()

bool ReplaceEdibleWithNewLambda::IsFoodRaw ( )
protected

Definition at line 1095 of file Edible_Base.c.

1095 : ItemBase
1096{
1097 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1098
1099 const string SOUND_BAKING_START = "Baking_SoundSet";
1100 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1101 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1102
1103 protected bool m_MakeCookingSounds;
1104 protected SoundOnVehicle m_SoundCooking;
1106 protected string m_SoundPlaying;
1108 protected float m_DecayTimer;
1109 protected float m_DecayDelta = 0.0;
1111
1113
1114 void Edible_Base()
1115 {
1116 if (HasFoodStage())
1117 {
1118 m_FoodStage = new FoodStage(this);
1119
1120 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1121 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1122 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1123 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1124 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1125
1126 m_SoundPlaying = "";
1128 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1129 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1130 }
1131 }
1132
1133 override void EEInit()
1134 {
1135 super.EEInit();
1136
1137 UpdateVisuals();
1138 }
1139
1140 override void EEDelete(EntityAI parent)
1141 {
1142 super.EEDelete(parent);
1143
1144 RemoveAudio();
1145 }
1146
1148 {
1149 super.EEItemLocationChanged(oldLoc, newLoc);
1150
1152 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1153 {
1154 switch (oldLoc.GetParent().GetType())
1155 {
1156 case "FryingPan":
1157 case "Pot":
1158 case "Cauldron":
1159 case "SharpWoodenStick":
1160 MakeSoundsOnClient(false);
1161 break;
1162 }
1163
1165 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1166 MakeSoundsOnClient(false);
1167 }
1168 }
1169
1170 void UpdateVisuals()
1171 {
1172 if (GetFoodStage())
1173 GetFoodStage().UpdateVisuals();
1174 }
1175
1176 bool Consume(float amount, PlayerBase consumer)
1177 {
1178 AddQuantity(-amount, false, false);
1179 OnConsume(amount, consumer);
1180
1181 return true;
1182 }
1183
1184 void OnConsume(float amount, PlayerBase consumer);
1185
1186 //food staging
1187 override bool CanBeCooked()
1188 {
1189 return false;
1190 }
1191
1192 override bool CanBeCookedOnStick()
1193 {
1194 return false;
1195 }
1196
1197 //================================================================
1198 // SYNCHRONIZATION
1199 //================================================================
1200 void Synchronize()
1201 {
1202 SetSynchDirty();
1203
1204 if (GetGame().IsMultiplayer())
1205 UpdateVisuals();
1206 }
1207
1208 override void OnVariablesSynchronized()
1209 {
1210 super.OnVariablesSynchronized();
1211
1212 UpdateVisuals();
1213
1214 //update audio
1216 RefreshAudio();
1217 else
1218 RemoveAudio();
1219 }
1220
1221 //================================================================
1222 // AUDIO EFFECTS (WHEN ON DCS)
1223 //================================================================
1225 {
1228
1229 Synchronize();
1230 }
1231
1232 protected void RefreshAudio()
1233 {
1234 string soundName = "";
1235
1237
1238 switch (GetFoodStageType())
1239 {
1240 case FoodStageType.RAW:
1242 if (nextFoodState == FoodStageType.BOILED)
1243 soundName = "";
1244 break;
1245 case FoodStageType.BAKED:
1247 break;
1248 case FoodStageType.BURNED:
1250 break;
1251 default:
1252 soundName = "";
1253 break;
1254 }
1255
1257 }
1258
1259 protected void RemoveAudio()
1260 {
1261 m_MakeCookingSounds = false;
1263 }
1264
1265 //================================================================
1266 // SERIALIZATION
1267 //================================================================
1268 override void OnStoreSave(ParamsWriteContext ctx)
1269 {
1270 super.OnStoreSave(ctx);
1271
1272 if (GetFoodStage())
1273 GetFoodStage().OnStoreSave(ctx);
1274
1275 // food decay
1276 ctx.Write(m_DecayTimer);
1277 ctx.Write(m_LastDecayStage);
1278 }
1279
1280 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1281 {
1282 if (!super.OnStoreLoad(ctx, version))
1283 return false;
1284
1285 if (GetFoodStage())
1286 {
1287 if (!GetFoodStage().OnStoreLoad(ctx, version))
1288 return false;
1289 }
1290
1291 if (version >= 115)
1292 {
1293 if (!ctx.Read(m_DecayTimer))
1294 {
1295 m_DecayTimer = 0.0;
1296 return false;
1297 }
1298 if (!ctx.Read(m_LastDecayStage))
1299 {
1301 return false;
1302 }
1303 }
1304
1305 return true;
1306 }
1307
1308 override void AfterStoreLoad()
1309 {
1310 super.AfterStoreLoad();
1311
1312 Synchronize();
1313 }
1314
1315 //get food stage
1317 {
1318 return m_FoodStage;
1319 }
1320
1321 //food types
1322 override bool IsMeat()
1323 {
1324 return false;
1325 }
1326
1327 override bool IsCorpse()
1328 {
1329 return false;
1330 }
1331
1332 override bool IsFruit()
1333 {
1334 return false;
1335 }
1336
1337 override bool IsMushroom()
1338 {
1339 return false;
1340 }
1341
1342 //================================================================
1343 // NUTRITIONAL VALUES
1344 //================================================================
1345 //food properties
1346 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1347 {
1349 if (food_item && food_item.GetFoodStage())
1350 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1351 else if (classname != "" && food_stage)
1352 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1353 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1354 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1355
1356 }
1357
1358 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1359 {
1361 if (food_item && food_item.GetFoodStage())
1362 return FoodStage.GetEnergy(food_item.GetFoodStage());
1363 else if (classname != "" && food_stage)
1364 return FoodStage.GetEnergy(null, food_stage, classname);
1365 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1366 return GetGame().ConfigGetFloat(class_path + " energy");
1367 }
1368
1369 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1370 {
1372 if (food_item && food_item.GetFoodStage())
1373 return FoodStage.GetWater(food_item.GetFoodStage());
1374 else if (classname != "" && food_stage)
1375 return FoodStage.GetWater(null, food_stage, classname);
1376 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1377 return GetGame().ConfigGetFloat(class_path + " water");
1378 }
1379
1380 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1381 {
1383 if (food_item && food_item.GetFoodStage())
1384 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1385 else if (classname != "" && food_stage)
1386 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1387 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1388 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1389
1390 }
1391
1392 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1393 {
1395 if (food_item && food_item.GetFoodStage())
1396 return FoodStage.GetToxicity(food_item.GetFoodStage());
1397 else if (classname != "" && food_stage)
1398 return FoodStage.GetToxicity(null, food_stage, classname);
1399 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1400 return GetGame().ConfigGetFloat(class_path + " toxicity");
1401 }
1402
1403 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1404 {
1406 if (food_item && food_item.GetFoodStage())
1407 return FoodStage.GetAgents(food_item.GetFoodStage());
1408 else if (classname != "" && food_stage)
1409 return FoodStage.GetAgents(null, food_stage, classname);
1410 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1411 return GetGame().ConfigGetInt(class_path + " agents");
1412 }
1413
1414 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1415 {
1417 if (food_item && food_item.GetFoodStage())
1418 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1419 else if (classname != "" && food_stage)
1420 return FoodStage.GetDigestibility(null, food_stage, classname);
1421 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1422 return GetGame().ConfigGetInt(class_path + " digestibility");
1423 }
1424
1426 {
1428 }
1429
1430 //================================================================
1431 // FOOD STAGING
1432 //================================================================
1434 {
1435 return GetFoodStage().GetFoodStageType();
1436 }
1437
1438 //food stage states
1439 bool IsFoodRaw()
1440 {
1441 if (GetFoodStage())
1442 return GetFoodStage().IsFoodRaw();
1443
1444 return false;
1445 }
1446
1447 bool IsFoodBaked()
1448 {
1449 if (GetFoodStage())
1450 return GetFoodStage().IsFoodBaked();
1451
1452 return false;
1453 }
1454
1455 bool IsFoodBoiled()
1456 {
1457 if (GetFoodStage())
1458 return GetFoodStage().IsFoodBoiled();
1459
1460 return false;
1461 }
1462
1463 bool IsFoodDried()
1464 {
1465 if (GetFoodStage())
1466 return GetFoodStage().IsFoodDried();
1467
1468 return false;
1469 }
1470
1471 bool IsFoodBurned()
1472 {
1473 if (GetFoodStage())
1474 return GetFoodStage().IsFoodBurned();
1475
1476 return false;
1477 }
1478
1479 bool IsFoodRotten()
1480 {
1481 if (GetFoodStage())
1482 return GetFoodStage().IsFoodRotten();
1483
1484 return false;
1485 }
1486
1487 //food stage change
1489 {
1490 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1491 }
1492
1494 {
1495 return GetFoodStage().GetNextFoodStageType(cooking_method);
1496 }
1497
1499 {
1500 return GetFoodStage().GetFoodStageName(food_stage_type);
1501 }
1502
1504 {
1505 return GetFoodStage().CanChangeToNewStage(cooking_method);
1506 }
1507
1508 //Use this to receive food stage from another Edible_Base
1510 {
1511 if (!source.HasFoodStage())
1512 return;
1513 m_LastDecayStage = source.GetLastDecayStage();
1514 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1515 m_DecayTimer = source.GetDecayTimer();
1516 m_DecayDelta = source.GetDecayDelta();
1517 }
1518
1519 //================================================================
1520 // COOKING
1521 //================================================================
1522 //cooking time
1523 float GetCookingTime()
1524 {
1525 return GetFoodStage().GetCookingTime();
1526 }
1527
1528 void SetCookingTime(float time)
1529 {
1530 GetFoodStage().SetCookingTime(time);
1531
1532 //synchronize when calling on server
1533 Synchronize();
1534 }
1535
1536 //replace edible with new item (opening cans)
1537 void ReplaceEdibleWithNew(string typeName)
1538 {
1539 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1540 if (player)
1541 {
1543 player.ServerReplaceItemInHandsWithNew(lambda);
1544 }
1545 else
1546 Error("ReplaceEdibleWithNew - cannot use edible without player");
1547 }
1548
1549 override void SetActions()
1550 {
1551 super.SetActions();
1552
1553 AddAction(ActionAttach);
1555 }
1556
1557 protected void SoundCookingStart(string sound_name)
1558 {
1559#ifndef SERVER
1561 {
1563
1566 }
1567#endif
1568 }
1569
1570 protected void SoundCookingStop()
1571 {
1572#ifndef SERVER
1574 {
1577 m_SoundPlaying = "";
1578 }
1579#endif
1580 }
1581
1582 override bool CanHaveTemperature()
1583 {
1584 return true;
1585 }
1586
1587 override bool CanDecay()
1588 {
1589 return false;
1590 }
1591
1592 override bool CanProcessDecay()
1593 {
1594 return (GetFoodStageType() != FoodStageType.ROTTEN);
1595 }
1596
1597 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1598 {
1599 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1600 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1601 if (hasRootAsPlayer)
1603
1604 /*Print( "-------------------------" );
1605 Print( this );
1606 Print( m_DecayTimer );
1607 Print( m_DecayDelta );
1608 Print( m_LastDecayStage );*/
1609
1610 if (IsFruit() || IsMushroom())
1611 {
1612 // fruit, vegetables and mushrooms
1614 {
1615 switch (GetFoodStageType())
1616 {
1617 case FoodStageType.RAW:
1620 break;
1621
1622 case FoodStageType.BOILED:
1625 break;
1626
1627 case FoodStageType.BAKED:
1630 break;
1631
1632 case FoodStageType.DRIED:
1633 case FoodStageType.BURNED:
1634 case FoodStageType.ROTTEN:
1635 default:
1636 m_DecayTimer = -1;
1638 return;
1639 }
1640
1641 //m_DecayTimer = m_DecayTimer / 1000.0;
1642 }
1643
1645
1646 if (m_DecayTimer <= 0)
1647 {
1648 if (m_LastDecayStage != FoodStageType.NONE)
1649 {
1650 // switch to decayed stage
1651 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1654 {
1655 int rng = Math.RandomIntInclusive(0, 100);
1658 else
1659 {
1662 else
1664 }
1665 }
1666 }
1667 }
1668
1669 }
1670 else if (IsMeat())
1671 {
1672 // meat
1674 {
1675 switch (GetFoodStageType())
1676 {
1677 case FoodStageType.RAW:
1680 break;
1681
1682 case FoodStageType.BOILED:
1685 break;
1686
1687 case FoodStageType.BAKED:
1690 break;
1691
1692 case FoodStageType.DRIED:
1695 break;
1696
1697 case FoodStageType.BURNED:
1698 case FoodStageType.ROTTEN:
1699 default:
1700 m_DecayTimer = -1;
1702 return;
1703 }
1704 }
1705
1707
1708 if (m_DecayTimer <= 0)
1709 {
1710 if (m_LastDecayStage != FoodStageType.NONE)
1711 {
1712 // switch to decayed stage
1715 }
1716 }
1717 }
1718 else if (IsCorpse())
1719 {
1720 // corpse
1722 {
1723 switch (GetFoodStageType())
1724 {
1725 case FoodStageType.RAW:
1728 break;
1729
1730 case FoodStageType.BURNED:
1731 case FoodStageType.ROTTEN:
1732 default:
1733 m_DecayTimer = -1;
1735 return;
1736 }
1737 }
1738
1740
1741 if (m_DecayTimer <= 0)
1742 {
1743 if (m_LastDecayStage != FoodStageType.NONE)
1744 {
1745 // switch to decayed stage
1748 }
1749 }
1750 }
1751 else
1752 {
1753 // opened cans
1755
1756 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1757 {
1760 //m_DecayTimer = m_DecayTimer / 1000.0;
1761 }
1762 else
1763 {
1764 if (m_DecayTimer <= 0)
1765 {
1766 InsertAgent(eAgents.FOOD_POISON, 1);
1767 m_DecayTimer = -1;
1768 }
1769 }
1770 }
1771
1772 m_DecayDelta = 0.0;
1773 }
1774
1776 {
1777 super.GetDebugActions(outputList);
1778
1779 if (HasFoodStage())
1780 {
1781 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1782 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1783 }
1784 }
1785
1786 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1787 {
1788 super.OnAction(action_id, player, ctx);
1789
1790 if (GetGame().IsServer())
1791 {
1792 if (action_id == EActions.FOOD_STAGE_PREV)
1793 {
1795 if (food_stage_prev <= 0)
1796 food_stage_prev = FoodStageType.COUNT - 1;
1798 return true;
1799 }
1800 else if (action_id == EActions.FOOD_STAGE_NEXT)
1801 {
1803 if (food_stage_next >= FoodStageType.COUNT)
1806 return true;
1807 }
1808 }
1809 return false;
1810 }
1811
1812 override string GetDebugText()
1813 {
1814 string debug_output;
1815
1816 debug_output = super.GetDebugText();
1817
1818 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1819 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1820
1821 return debug_output;
1822 }
1823
1824 //================================================================
1825 // GENERAL GETTERS
1826 //================================================================
1827
1828 float GetDecayTimer()
1829 {
1830 return m_DecayTimer;
1831 }
1832
1833 float GetDecayDelta()
1834 {
1835 return m_DecayDelta;
1836 }
1837
1839 {
1840 return m_LastDecayStage;
1841 }
1842}
1843
1845{
1847};

◆ IsFoodRotten()

bool ReplaceEdibleWithNewLambda::IsFoodRotten ( )
protected

Definition at line 1135 of file Edible_Base.c.

1135 : ItemBase
1136{
1137 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1138
1139 const string SOUND_BAKING_START = "Baking_SoundSet";
1140 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1141 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1142
1143 protected bool m_MakeCookingSounds;
1144 protected SoundOnVehicle m_SoundCooking;
1146 protected string m_SoundPlaying;
1148 protected float m_DecayTimer;
1149 protected float m_DecayDelta = 0.0;
1151
1153
1154 void Edible_Base()
1155 {
1156 if (HasFoodStage())
1157 {
1158 m_FoodStage = new FoodStage(this);
1159
1160 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1161 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1162 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1163 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1164 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1165
1166 m_SoundPlaying = "";
1168 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1169 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1170 }
1171 }
1172
1173 override void EEInit()
1174 {
1175 super.EEInit();
1176
1177 UpdateVisuals();
1178 }
1179
1180 override void EEDelete(EntityAI parent)
1181 {
1182 super.EEDelete(parent);
1183
1184 RemoveAudio();
1185 }
1186
1188 {
1189 super.EEItemLocationChanged(oldLoc, newLoc);
1190
1192 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1193 {
1194 switch (oldLoc.GetParent().GetType())
1195 {
1196 case "FryingPan":
1197 case "Pot":
1198 case "Cauldron":
1199 case "SharpWoodenStick":
1200 MakeSoundsOnClient(false);
1201 break;
1202 }
1203
1205 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1206 MakeSoundsOnClient(false);
1207 }
1208 }
1209
1210 void UpdateVisuals()
1211 {
1212 if (GetFoodStage())
1213 GetFoodStage().UpdateVisuals();
1214 }
1215
1216 bool Consume(float amount, PlayerBase consumer)
1217 {
1218 AddQuantity(-amount, false, false);
1219 OnConsume(amount, consumer);
1220
1221 return true;
1222 }
1223
1224 void OnConsume(float amount, PlayerBase consumer);
1225
1226 //food staging
1227 override bool CanBeCooked()
1228 {
1229 return false;
1230 }
1231
1232 override bool CanBeCookedOnStick()
1233 {
1234 return false;
1235 }
1236
1237 //================================================================
1238 // SYNCHRONIZATION
1239 //================================================================
1240 void Synchronize()
1241 {
1242 SetSynchDirty();
1243
1244 if (GetGame().IsMultiplayer())
1245 UpdateVisuals();
1246 }
1247
1248 override void OnVariablesSynchronized()
1249 {
1250 super.OnVariablesSynchronized();
1251
1252 UpdateVisuals();
1253
1254 //update audio
1256 RefreshAudio();
1257 else
1258 RemoveAudio();
1259 }
1260
1261 //================================================================
1262 // AUDIO EFFECTS (WHEN ON DCS)
1263 //================================================================
1265 {
1268
1269 Synchronize();
1270 }
1271
1272 protected void RefreshAudio()
1273 {
1274 string soundName = "";
1275
1277
1278 switch (GetFoodStageType())
1279 {
1280 case FoodStageType.RAW:
1282 if (nextFoodState == FoodStageType.BOILED)
1283 soundName = "";
1284 break;
1285 case FoodStageType.BAKED:
1287 break;
1288 case FoodStageType.BURNED:
1290 break;
1291 default:
1292 soundName = "";
1293 break;
1294 }
1295
1297 }
1298
1299 protected void RemoveAudio()
1300 {
1301 m_MakeCookingSounds = false;
1303 }
1304
1305 //================================================================
1306 // SERIALIZATION
1307 //================================================================
1308 override void OnStoreSave(ParamsWriteContext ctx)
1309 {
1310 super.OnStoreSave(ctx);
1311
1312 if (GetFoodStage())
1313 GetFoodStage().OnStoreSave(ctx);
1314
1315 // food decay
1316 ctx.Write(m_DecayTimer);
1317 ctx.Write(m_LastDecayStage);
1318 }
1319
1320 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1321 {
1322 if (!super.OnStoreLoad(ctx, version))
1323 return false;
1324
1325 if (GetFoodStage())
1326 {
1327 if (!GetFoodStage().OnStoreLoad(ctx, version))
1328 return false;
1329 }
1330
1331 if (version >= 115)
1332 {
1333 if (!ctx.Read(m_DecayTimer))
1334 {
1335 m_DecayTimer = 0.0;
1336 return false;
1337 }
1338 if (!ctx.Read(m_LastDecayStage))
1339 {
1341 return false;
1342 }
1343 }
1344
1345 return true;
1346 }
1347
1348 override void AfterStoreLoad()
1349 {
1350 super.AfterStoreLoad();
1351
1352 Synchronize();
1353 }
1354
1355 //get food stage
1357 {
1358 return m_FoodStage;
1359 }
1360
1361 //food types
1362 override bool IsMeat()
1363 {
1364 return false;
1365 }
1366
1367 override bool IsCorpse()
1368 {
1369 return false;
1370 }
1371
1372 override bool IsFruit()
1373 {
1374 return false;
1375 }
1376
1377 override bool IsMushroom()
1378 {
1379 return false;
1380 }
1381
1382 //================================================================
1383 // NUTRITIONAL VALUES
1384 //================================================================
1385 //food properties
1386 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1387 {
1389 if (food_item && food_item.GetFoodStage())
1390 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1391 else if (classname != "" && food_stage)
1392 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1393 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1394 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1395
1396 }
1397
1398 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1399 {
1401 if (food_item && food_item.GetFoodStage())
1402 return FoodStage.GetEnergy(food_item.GetFoodStage());
1403 else if (classname != "" && food_stage)
1404 return FoodStage.GetEnergy(null, food_stage, classname);
1405 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1406 return GetGame().ConfigGetFloat(class_path + " energy");
1407 }
1408
1409 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1410 {
1412 if (food_item && food_item.GetFoodStage())
1413 return FoodStage.GetWater(food_item.GetFoodStage());
1414 else if (classname != "" && food_stage)
1415 return FoodStage.GetWater(null, food_stage, classname);
1416 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1417 return GetGame().ConfigGetFloat(class_path + " water");
1418 }
1419
1420 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1421 {
1423 if (food_item && food_item.GetFoodStage())
1424 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1425 else if (classname != "" && food_stage)
1426 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1427 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1428 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1429
1430 }
1431
1432 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1433 {
1435 if (food_item && food_item.GetFoodStage())
1436 return FoodStage.GetToxicity(food_item.GetFoodStage());
1437 else if (classname != "" && food_stage)
1438 return FoodStage.GetToxicity(null, food_stage, classname);
1439 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1440 return GetGame().ConfigGetFloat(class_path + " toxicity");
1441 }
1442
1443 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1444 {
1446 if (food_item && food_item.GetFoodStage())
1447 return FoodStage.GetAgents(food_item.GetFoodStage());
1448 else if (classname != "" && food_stage)
1449 return FoodStage.GetAgents(null, food_stage, classname);
1450 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1451 return GetGame().ConfigGetInt(class_path + " agents");
1452 }
1453
1454 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1455 {
1457 if (food_item && food_item.GetFoodStage())
1458 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1459 else if (classname != "" && food_stage)
1460 return FoodStage.GetDigestibility(null, food_stage, classname);
1461 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1462 return GetGame().ConfigGetInt(class_path + " digestibility");
1463 }
1464
1466 {
1468 }
1469
1470 //================================================================
1471 // FOOD STAGING
1472 //================================================================
1474 {
1475 return GetFoodStage().GetFoodStageType();
1476 }
1477
1478 //food stage states
1479 bool IsFoodRaw()
1480 {
1481 if (GetFoodStage())
1482 return GetFoodStage().IsFoodRaw();
1483
1484 return false;
1485 }
1486
1487 bool IsFoodBaked()
1488 {
1489 if (GetFoodStage())
1490 return GetFoodStage().IsFoodBaked();
1491
1492 return false;
1493 }
1494
1495 bool IsFoodBoiled()
1496 {
1497 if (GetFoodStage())
1498 return GetFoodStage().IsFoodBoiled();
1499
1500 return false;
1501 }
1502
1503 bool IsFoodDried()
1504 {
1505 if (GetFoodStage())
1506 return GetFoodStage().IsFoodDried();
1507
1508 return false;
1509 }
1510
1511 bool IsFoodBurned()
1512 {
1513 if (GetFoodStage())
1514 return GetFoodStage().IsFoodBurned();
1515
1516 return false;
1517 }
1518
1519 bool IsFoodRotten()
1520 {
1521 if (GetFoodStage())
1522 return GetFoodStage().IsFoodRotten();
1523
1524 return false;
1525 }
1526
1527 //food stage change
1529 {
1530 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1531 }
1532
1534 {
1535 return GetFoodStage().GetNextFoodStageType(cooking_method);
1536 }
1537
1539 {
1540 return GetFoodStage().GetFoodStageName(food_stage_type);
1541 }
1542
1544 {
1545 return GetFoodStage().CanChangeToNewStage(cooking_method);
1546 }
1547
1548 //Use this to receive food stage from another Edible_Base
1550 {
1551 if (!source.HasFoodStage())
1552 return;
1553 m_LastDecayStage = source.GetLastDecayStage();
1554 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1555 m_DecayTimer = source.GetDecayTimer();
1556 m_DecayDelta = source.GetDecayDelta();
1557 }
1558
1559 //================================================================
1560 // COOKING
1561 //================================================================
1562 //cooking time
1563 float GetCookingTime()
1564 {
1565 return GetFoodStage().GetCookingTime();
1566 }
1567
1568 void SetCookingTime(float time)
1569 {
1570 GetFoodStage().SetCookingTime(time);
1571
1572 //synchronize when calling on server
1573 Synchronize();
1574 }
1575
1576 //replace edible with new item (opening cans)
1577 void ReplaceEdibleWithNew(string typeName)
1578 {
1579 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1580 if (player)
1581 {
1583 player.ServerReplaceItemInHandsWithNew(lambda);
1584 }
1585 else
1586 Error("ReplaceEdibleWithNew - cannot use edible without player");
1587 }
1588
1589 override void SetActions()
1590 {
1591 super.SetActions();
1592
1593 AddAction(ActionAttach);
1595 }
1596
1597 protected void SoundCookingStart(string sound_name)
1598 {
1599#ifndef SERVER
1601 {
1603
1606 }
1607#endif
1608 }
1609
1610 protected void SoundCookingStop()
1611 {
1612#ifndef SERVER
1614 {
1617 m_SoundPlaying = "";
1618 }
1619#endif
1620 }
1621
1622 override bool CanHaveTemperature()
1623 {
1624 return true;
1625 }
1626
1627 override bool CanDecay()
1628 {
1629 return false;
1630 }
1631
1632 override bool CanProcessDecay()
1633 {
1634 return (GetFoodStageType() != FoodStageType.ROTTEN);
1635 }
1636
1637 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1638 {
1639 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1640 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1641 if (hasRootAsPlayer)
1643
1644 /*Print( "-------------------------" );
1645 Print( this );
1646 Print( m_DecayTimer );
1647 Print( m_DecayDelta );
1648 Print( m_LastDecayStage );*/
1649
1650 if (IsFruit() || IsMushroom())
1651 {
1652 // fruit, vegetables and mushrooms
1654 {
1655 switch (GetFoodStageType())
1656 {
1657 case FoodStageType.RAW:
1660 break;
1661
1662 case FoodStageType.BOILED:
1665 break;
1666
1667 case FoodStageType.BAKED:
1670 break;
1671
1672 case FoodStageType.DRIED:
1673 case FoodStageType.BURNED:
1674 case FoodStageType.ROTTEN:
1675 default:
1676 m_DecayTimer = -1;
1678 return;
1679 }
1680
1681 //m_DecayTimer = m_DecayTimer / 1000.0;
1682 }
1683
1685
1686 if (m_DecayTimer <= 0)
1687 {
1688 if (m_LastDecayStage != FoodStageType.NONE)
1689 {
1690 // switch to decayed stage
1691 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1694 {
1695 int rng = Math.RandomIntInclusive(0, 100);
1698 else
1699 {
1702 else
1704 }
1705 }
1706 }
1707 }
1708
1709 }
1710 else if (IsMeat())
1711 {
1712 // meat
1714 {
1715 switch (GetFoodStageType())
1716 {
1717 case FoodStageType.RAW:
1720 break;
1721
1722 case FoodStageType.BOILED:
1725 break;
1726
1727 case FoodStageType.BAKED:
1730 break;
1731
1732 case FoodStageType.DRIED:
1735 break;
1736
1737 case FoodStageType.BURNED:
1738 case FoodStageType.ROTTEN:
1739 default:
1740 m_DecayTimer = -1;
1742 return;
1743 }
1744 }
1745
1747
1748 if (m_DecayTimer <= 0)
1749 {
1750 if (m_LastDecayStage != FoodStageType.NONE)
1751 {
1752 // switch to decayed stage
1755 }
1756 }
1757 }
1758 else if (IsCorpse())
1759 {
1760 // corpse
1762 {
1763 switch (GetFoodStageType())
1764 {
1765 case FoodStageType.RAW:
1768 break;
1769
1770 case FoodStageType.BURNED:
1771 case FoodStageType.ROTTEN:
1772 default:
1773 m_DecayTimer = -1;
1775 return;
1776 }
1777 }
1778
1780
1781 if (m_DecayTimer <= 0)
1782 {
1783 if (m_LastDecayStage != FoodStageType.NONE)
1784 {
1785 // switch to decayed stage
1788 }
1789 }
1790 }
1791 else
1792 {
1793 // opened cans
1795
1796 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1797 {
1800 //m_DecayTimer = m_DecayTimer / 1000.0;
1801 }
1802 else
1803 {
1804 if (m_DecayTimer <= 0)
1805 {
1806 InsertAgent(eAgents.FOOD_POISON, 1);
1807 m_DecayTimer = -1;
1808 }
1809 }
1810 }
1811
1812 m_DecayDelta = 0.0;
1813 }
1814
1816 {
1817 super.GetDebugActions(outputList);
1818
1819 if (HasFoodStage())
1820 {
1821 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1822 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1823 }
1824 }
1825
1826 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1827 {
1828 super.OnAction(action_id, player, ctx);
1829
1830 if (GetGame().IsServer())
1831 {
1832 if (action_id == EActions.FOOD_STAGE_PREV)
1833 {
1835 if (food_stage_prev <= 0)
1836 food_stage_prev = FoodStageType.COUNT - 1;
1838 return true;
1839 }
1840 else if (action_id == EActions.FOOD_STAGE_NEXT)
1841 {
1843 if (food_stage_next >= FoodStageType.COUNT)
1846 return true;
1847 }
1848 }
1849 return false;
1850 }
1851
1852 override string GetDebugText()
1853 {
1854 string debug_output;
1855
1856 debug_output = super.GetDebugText();
1857
1858 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1859 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1860
1861 return debug_output;
1862 }
1863
1864 //================================================================
1865 // GENERAL GETTERS
1866 //================================================================
1867
1868 float GetDecayTimer()
1869 {
1870 return m_DecayTimer;
1871 }
1872
1873 float GetDecayDelta()
1874 {
1875 return m_DecayDelta;
1876 }
1877
1879 {
1880 return m_LastDecayStage;
1881 }
1882}
1883
1885{
1887};

◆ IsFruit()

override bool ReplaceEdibleWithNewLambda::IsFruit ( )
protected

Definition at line 988 of file Edible_Base.c.

988 : ItemBase
989{
990 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
991
992 const string SOUND_BAKING_START = "Baking_SoundSet";
993 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
994 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
995
996 protected bool m_MakeCookingSounds;
999 protected string m_SoundPlaying;
1001 protected float m_DecayTimer;
1002 protected float m_DecayDelta = 0.0;
1004
1006
1007 void Edible_Base()
1008 {
1009 if (HasFoodStage())
1010 {
1011 m_FoodStage = new FoodStage(this);
1012
1013 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1014 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1015 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1016 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1017 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1018
1019 m_SoundPlaying = "";
1021 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1022 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1023 }
1024 }
1025
1026 override void EEInit()
1027 {
1028 super.EEInit();
1029
1030 UpdateVisuals();
1031 }
1032
1033 override void EEDelete(EntityAI parent)
1034 {
1035 super.EEDelete(parent);
1036
1037 RemoveAudio();
1038 }
1039
1041 {
1042 super.EEItemLocationChanged(oldLoc, newLoc);
1043
1045 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1046 {
1047 switch (oldLoc.GetParent().GetType())
1048 {
1049 case "FryingPan":
1050 case "Pot":
1051 case "Cauldron":
1052 case "SharpWoodenStick":
1053 MakeSoundsOnClient(false);
1054 break;
1055 }
1056
1058 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1059 MakeSoundsOnClient(false);
1060 }
1061 }
1062
1063 void UpdateVisuals()
1064 {
1065 if (GetFoodStage())
1066 GetFoodStage().UpdateVisuals();
1067 }
1068
1069 bool Consume(float amount, PlayerBase consumer)
1070 {
1071 AddQuantity(-amount, false, false);
1072 OnConsume(amount, consumer);
1073
1074 return true;
1075 }
1076
1077 void OnConsume(float amount, PlayerBase consumer);
1078
1079 //food staging
1080 override bool CanBeCooked()
1081 {
1082 return false;
1083 }
1084
1085 override bool CanBeCookedOnStick()
1086 {
1087 return false;
1088 }
1089
1090 //================================================================
1091 // SYNCHRONIZATION
1092 //================================================================
1093 void Synchronize()
1094 {
1095 SetSynchDirty();
1096
1097 if (GetGame().IsMultiplayer())
1098 UpdateVisuals();
1099 }
1100
1101 override void OnVariablesSynchronized()
1102 {
1103 super.OnVariablesSynchronized();
1104
1105 UpdateVisuals();
1106
1107 //update audio
1109 RefreshAudio();
1110 else
1111 RemoveAudio();
1112 }
1113
1114 //================================================================
1115 // AUDIO EFFECTS (WHEN ON DCS)
1116 //================================================================
1118 {
1121
1122 Synchronize();
1123 }
1124
1125 protected void RefreshAudio()
1126 {
1127 string soundName = "";
1128
1130
1131 switch (GetFoodStageType())
1132 {
1133 case FoodStageType.RAW:
1135 if (nextFoodState == FoodStageType.BOILED)
1136 soundName = "";
1137 break;
1138 case FoodStageType.BAKED:
1140 break;
1141 case FoodStageType.BURNED:
1143 break;
1144 default:
1145 soundName = "";
1146 break;
1147 }
1148
1150 }
1151
1152 protected void RemoveAudio()
1153 {
1154 m_MakeCookingSounds = false;
1156 }
1157
1158 //================================================================
1159 // SERIALIZATION
1160 //================================================================
1161 override void OnStoreSave(ParamsWriteContext ctx)
1162 {
1163 super.OnStoreSave(ctx);
1164
1165 if (GetFoodStage())
1166 GetFoodStage().OnStoreSave(ctx);
1167
1168 // food decay
1169 ctx.Write(m_DecayTimer);
1170 ctx.Write(m_LastDecayStage);
1171 }
1172
1173 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1174 {
1175 if (!super.OnStoreLoad(ctx, version))
1176 return false;
1177
1178 if (GetFoodStage())
1179 {
1180 if (!GetFoodStage().OnStoreLoad(ctx, version))
1181 return false;
1182 }
1183
1184 if (version >= 115)
1185 {
1186 if (!ctx.Read(m_DecayTimer))
1187 {
1188 m_DecayTimer = 0.0;
1189 return false;
1190 }
1191 if (!ctx.Read(m_LastDecayStage))
1192 {
1194 return false;
1195 }
1196 }
1197
1198 return true;
1199 }
1200
1201 override void AfterStoreLoad()
1202 {
1203 super.AfterStoreLoad();
1204
1205 Synchronize();
1206 }
1207
1208 //get food stage
1210 {
1211 return m_FoodStage;
1212 }
1213
1214 //food types
1215 override bool IsMeat()
1216 {
1217 return false;
1218 }
1219
1220 override bool IsCorpse()
1221 {
1222 return false;
1223 }
1224
1225 override bool IsFruit()
1226 {
1227 return false;
1228 }
1229
1230 override bool IsMushroom()
1231 {
1232 return false;
1233 }
1234
1235 //================================================================
1236 // NUTRITIONAL VALUES
1237 //================================================================
1238 //food properties
1239 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1240 {
1242 if (food_item && food_item.GetFoodStage())
1243 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1244 else if (classname != "" && food_stage)
1245 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1246 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1247 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1248
1249 }
1250
1251 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1252 {
1254 if (food_item && food_item.GetFoodStage())
1255 return FoodStage.GetEnergy(food_item.GetFoodStage());
1256 else if (classname != "" && food_stage)
1257 return FoodStage.GetEnergy(null, food_stage, classname);
1258 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1259 return GetGame().ConfigGetFloat(class_path + " energy");
1260 }
1261
1262 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1263 {
1265 if (food_item && food_item.GetFoodStage())
1266 return FoodStage.GetWater(food_item.GetFoodStage());
1267 else if (classname != "" && food_stage)
1268 return FoodStage.GetWater(null, food_stage, classname);
1269 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1270 return GetGame().ConfigGetFloat(class_path + " water");
1271 }
1272
1273 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1274 {
1276 if (food_item && food_item.GetFoodStage())
1277 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1278 else if (classname != "" && food_stage)
1279 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1280 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1281 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1282
1283 }
1284
1285 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1286 {
1288 if (food_item && food_item.GetFoodStage())
1289 return FoodStage.GetToxicity(food_item.GetFoodStage());
1290 else if (classname != "" && food_stage)
1291 return FoodStage.GetToxicity(null, food_stage, classname);
1292 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1293 return GetGame().ConfigGetFloat(class_path + " toxicity");
1294 }
1295
1296 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1297 {
1299 if (food_item && food_item.GetFoodStage())
1300 return FoodStage.GetAgents(food_item.GetFoodStage());
1301 else if (classname != "" && food_stage)
1302 return FoodStage.GetAgents(null, food_stage, classname);
1303 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1304 return GetGame().ConfigGetInt(class_path + " agents");
1305 }
1306
1307 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1308 {
1310 if (food_item && food_item.GetFoodStage())
1311 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1312 else if (classname != "" && food_stage)
1313 return FoodStage.GetDigestibility(null, food_stage, classname);
1314 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1315 return GetGame().ConfigGetInt(class_path + " digestibility");
1316 }
1317
1319 {
1321 }
1322
1323 //================================================================
1324 // FOOD STAGING
1325 //================================================================
1327 {
1328 return GetFoodStage().GetFoodStageType();
1329 }
1330
1331 //food stage states
1332 bool IsFoodRaw()
1333 {
1334 if (GetFoodStage())
1335 return GetFoodStage().IsFoodRaw();
1336
1337 return false;
1338 }
1339
1340 bool IsFoodBaked()
1341 {
1342 if (GetFoodStage())
1343 return GetFoodStage().IsFoodBaked();
1344
1345 return false;
1346 }
1347
1348 bool IsFoodBoiled()
1349 {
1350 if (GetFoodStage())
1351 return GetFoodStage().IsFoodBoiled();
1352
1353 return false;
1354 }
1355
1356 bool IsFoodDried()
1357 {
1358 if (GetFoodStage())
1359 return GetFoodStage().IsFoodDried();
1360
1361 return false;
1362 }
1363
1364 bool IsFoodBurned()
1365 {
1366 if (GetFoodStage())
1367 return GetFoodStage().IsFoodBurned();
1368
1369 return false;
1370 }
1371
1372 bool IsFoodRotten()
1373 {
1374 if (GetFoodStage())
1375 return GetFoodStage().IsFoodRotten();
1376
1377 return false;
1378 }
1379
1380 //food stage change
1382 {
1383 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1384 }
1385
1387 {
1388 return GetFoodStage().GetNextFoodStageType(cooking_method);
1389 }
1390
1392 {
1393 return GetFoodStage().GetFoodStageName(food_stage_type);
1394 }
1395
1397 {
1398 return GetFoodStage().CanChangeToNewStage(cooking_method);
1399 }
1400
1401 //Use this to receive food stage from another Edible_Base
1403 {
1404 if (!source.HasFoodStage())
1405 return;
1406 m_LastDecayStage = source.GetLastDecayStage();
1407 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1408 m_DecayTimer = source.GetDecayTimer();
1409 m_DecayDelta = source.GetDecayDelta();
1410 }
1411
1412 //================================================================
1413 // COOKING
1414 //================================================================
1415 //cooking time
1416 float GetCookingTime()
1417 {
1418 return GetFoodStage().GetCookingTime();
1419 }
1420
1421 void SetCookingTime(float time)
1422 {
1423 GetFoodStage().SetCookingTime(time);
1424
1425 //synchronize when calling on server
1426 Synchronize();
1427 }
1428
1429 //replace edible with new item (opening cans)
1430 void ReplaceEdibleWithNew(string typeName)
1431 {
1432 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1433 if (player)
1434 {
1436 player.ServerReplaceItemInHandsWithNew(lambda);
1437 }
1438 else
1439 Error("ReplaceEdibleWithNew - cannot use edible without player");
1440 }
1441
1442 override void SetActions()
1443 {
1444 super.SetActions();
1445
1446 AddAction(ActionAttach);
1448 }
1449
1450 protected void SoundCookingStart(string sound_name)
1451 {
1452#ifndef SERVER
1454 {
1456
1459 }
1460#endif
1461 }
1462
1463 protected void SoundCookingStop()
1464 {
1465#ifndef SERVER
1467 {
1470 m_SoundPlaying = "";
1471 }
1472#endif
1473 }
1474
1475 override bool CanHaveTemperature()
1476 {
1477 return true;
1478 }
1479
1480 override bool CanDecay()
1481 {
1482 return false;
1483 }
1484
1485 override bool CanProcessDecay()
1486 {
1487 return (GetFoodStageType() != FoodStageType.ROTTEN);
1488 }
1489
1490 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1491 {
1492 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1493 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1494 if (hasRootAsPlayer)
1496
1497 /*Print( "-------------------------" );
1498 Print( this );
1499 Print( m_DecayTimer );
1500 Print( m_DecayDelta );
1501 Print( m_LastDecayStage );*/
1502
1503 if (IsFruit() || IsMushroom())
1504 {
1505 // fruit, vegetables and mushrooms
1507 {
1508 switch (GetFoodStageType())
1509 {
1510 case FoodStageType.RAW:
1513 break;
1514
1515 case FoodStageType.BOILED:
1518 break;
1519
1520 case FoodStageType.BAKED:
1523 break;
1524
1525 case FoodStageType.DRIED:
1526 case FoodStageType.BURNED:
1527 case FoodStageType.ROTTEN:
1528 default:
1529 m_DecayTimer = -1;
1531 return;
1532 }
1533
1534 //m_DecayTimer = m_DecayTimer / 1000.0;
1535 }
1536
1538
1539 if (m_DecayTimer <= 0)
1540 {
1541 if (m_LastDecayStage != FoodStageType.NONE)
1542 {
1543 // switch to decayed stage
1544 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1547 {
1548 int rng = Math.RandomIntInclusive(0, 100);
1551 else
1552 {
1555 else
1557 }
1558 }
1559 }
1560 }
1561
1562 }
1563 else if (IsMeat())
1564 {
1565 // meat
1567 {
1568 switch (GetFoodStageType())
1569 {
1570 case FoodStageType.RAW:
1573 break;
1574
1575 case FoodStageType.BOILED:
1578 break;
1579
1580 case FoodStageType.BAKED:
1583 break;
1584
1585 case FoodStageType.DRIED:
1588 break;
1589
1590 case FoodStageType.BURNED:
1591 case FoodStageType.ROTTEN:
1592 default:
1593 m_DecayTimer = -1;
1595 return;
1596 }
1597 }
1598
1600
1601 if (m_DecayTimer <= 0)
1602 {
1603 if (m_LastDecayStage != FoodStageType.NONE)
1604 {
1605 // switch to decayed stage
1608 }
1609 }
1610 }
1611 else if (IsCorpse())
1612 {
1613 // corpse
1615 {
1616 switch (GetFoodStageType())
1617 {
1618 case FoodStageType.RAW:
1621 break;
1622
1623 case FoodStageType.BURNED:
1624 case FoodStageType.ROTTEN:
1625 default:
1626 m_DecayTimer = -1;
1628 return;
1629 }
1630 }
1631
1633
1634 if (m_DecayTimer <= 0)
1635 {
1636 if (m_LastDecayStage != FoodStageType.NONE)
1637 {
1638 // switch to decayed stage
1641 }
1642 }
1643 }
1644 else
1645 {
1646 // opened cans
1648
1649 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1650 {
1653 //m_DecayTimer = m_DecayTimer / 1000.0;
1654 }
1655 else
1656 {
1657 if (m_DecayTimer <= 0)
1658 {
1659 InsertAgent(eAgents.FOOD_POISON, 1);
1660 m_DecayTimer = -1;
1661 }
1662 }
1663 }
1664
1665 m_DecayDelta = 0.0;
1666 }
1667
1669 {
1670 super.GetDebugActions(outputList);
1671
1672 if (HasFoodStage())
1673 {
1674 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1675 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1676 }
1677 }
1678
1679 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1680 {
1681 super.OnAction(action_id, player, ctx);
1682
1683 if (GetGame().IsServer())
1684 {
1685 if (action_id == EActions.FOOD_STAGE_PREV)
1686 {
1688 if (food_stage_prev <= 0)
1689 food_stage_prev = FoodStageType.COUNT - 1;
1691 return true;
1692 }
1693 else if (action_id == EActions.FOOD_STAGE_NEXT)
1694 {
1696 if (food_stage_next >= FoodStageType.COUNT)
1699 return true;
1700 }
1701 }
1702 return false;
1703 }
1704
1705 override string GetDebugText()
1706 {
1707 string debug_output;
1708
1709 debug_output = super.GetDebugText();
1710
1711 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1712 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1713
1714 return debug_output;
1715 }
1716
1717 //================================================================
1718 // GENERAL GETTERS
1719 //================================================================
1720
1721 float GetDecayTimer()
1722 {
1723 return m_DecayTimer;
1724 }
1725
1726 float GetDecayDelta()
1727 {
1728 return m_DecayDelta;
1729 }
1730
1732 {
1733 return m_LastDecayStage;
1734 }
1735}
1736
1738{
1740};

Referenced by IEntity::IsFood().

◆ IsMeat()

override bool ReplaceEdibleWithNewLambda::IsMeat ( )
protected

Definition at line 978 of file Edible_Base.c.

978 : ItemBase
979{
980 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
981
982 const string SOUND_BAKING_START = "Baking_SoundSet";
983 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
984 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
985
986 protected bool m_MakeCookingSounds;
989 protected string m_SoundPlaying;
991 protected float m_DecayTimer;
992 protected float m_DecayDelta = 0.0;
994
996
997 void Edible_Base()
998 {
999 if (HasFoodStage())
1000 {
1001 m_FoodStage = new FoodStage(this);
1002
1003 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1004 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1005 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1006 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1007 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1008
1009 m_SoundPlaying = "";
1011 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1012 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1013 }
1014 }
1015
1016 override void EEInit()
1017 {
1018 super.EEInit();
1019
1020 UpdateVisuals();
1021 }
1022
1023 override void EEDelete(EntityAI parent)
1024 {
1025 super.EEDelete(parent);
1026
1027 RemoveAudio();
1028 }
1029
1031 {
1032 super.EEItemLocationChanged(oldLoc, newLoc);
1033
1035 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1036 {
1037 switch (oldLoc.GetParent().GetType())
1038 {
1039 case "FryingPan":
1040 case "Pot":
1041 case "Cauldron":
1042 case "SharpWoodenStick":
1043 MakeSoundsOnClient(false);
1044 break;
1045 }
1046
1048 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1049 MakeSoundsOnClient(false);
1050 }
1051 }
1052
1053 void UpdateVisuals()
1054 {
1055 if (GetFoodStage())
1056 GetFoodStage().UpdateVisuals();
1057 }
1058
1059 bool Consume(float amount, PlayerBase consumer)
1060 {
1061 AddQuantity(-amount, false, false);
1062 OnConsume(amount, consumer);
1063
1064 return true;
1065 }
1066
1067 void OnConsume(float amount, PlayerBase consumer);
1068
1069 //food staging
1070 override bool CanBeCooked()
1071 {
1072 return false;
1073 }
1074
1075 override bool CanBeCookedOnStick()
1076 {
1077 return false;
1078 }
1079
1080 //================================================================
1081 // SYNCHRONIZATION
1082 //================================================================
1083 void Synchronize()
1084 {
1085 SetSynchDirty();
1086
1087 if (GetGame().IsMultiplayer())
1088 UpdateVisuals();
1089 }
1090
1091 override void OnVariablesSynchronized()
1092 {
1093 super.OnVariablesSynchronized();
1094
1095 UpdateVisuals();
1096
1097 //update audio
1099 RefreshAudio();
1100 else
1101 RemoveAudio();
1102 }
1103
1104 //================================================================
1105 // AUDIO EFFECTS (WHEN ON DCS)
1106 //================================================================
1108 {
1111
1112 Synchronize();
1113 }
1114
1115 protected void RefreshAudio()
1116 {
1117 string soundName = "";
1118
1120
1121 switch (GetFoodStageType())
1122 {
1123 case FoodStageType.RAW:
1125 if (nextFoodState == FoodStageType.BOILED)
1126 soundName = "";
1127 break;
1128 case FoodStageType.BAKED:
1130 break;
1131 case FoodStageType.BURNED:
1133 break;
1134 default:
1135 soundName = "";
1136 break;
1137 }
1138
1140 }
1141
1142 protected void RemoveAudio()
1143 {
1144 m_MakeCookingSounds = false;
1146 }
1147
1148 //================================================================
1149 // SERIALIZATION
1150 //================================================================
1151 override void OnStoreSave(ParamsWriteContext ctx)
1152 {
1153 super.OnStoreSave(ctx);
1154
1155 if (GetFoodStage())
1156 GetFoodStage().OnStoreSave(ctx);
1157
1158 // food decay
1159 ctx.Write(m_DecayTimer);
1160 ctx.Write(m_LastDecayStage);
1161 }
1162
1163 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1164 {
1165 if (!super.OnStoreLoad(ctx, version))
1166 return false;
1167
1168 if (GetFoodStage())
1169 {
1170 if (!GetFoodStage().OnStoreLoad(ctx, version))
1171 return false;
1172 }
1173
1174 if (version >= 115)
1175 {
1176 if (!ctx.Read(m_DecayTimer))
1177 {
1178 m_DecayTimer = 0.0;
1179 return false;
1180 }
1181 if (!ctx.Read(m_LastDecayStage))
1182 {
1184 return false;
1185 }
1186 }
1187
1188 return true;
1189 }
1190
1191 override void AfterStoreLoad()
1192 {
1193 super.AfterStoreLoad();
1194
1195 Synchronize();
1196 }
1197
1198 //get food stage
1200 {
1201 return m_FoodStage;
1202 }
1203
1204 //food types
1205 override bool IsMeat()
1206 {
1207 return false;
1208 }
1209
1210 override bool IsCorpse()
1211 {
1212 return false;
1213 }
1214
1215 override bool IsFruit()
1216 {
1217 return false;
1218 }
1219
1220 override bool IsMushroom()
1221 {
1222 return false;
1223 }
1224
1225 //================================================================
1226 // NUTRITIONAL VALUES
1227 //================================================================
1228 //food properties
1229 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1230 {
1232 if (food_item && food_item.GetFoodStage())
1233 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1234 else if (classname != "" && food_stage)
1235 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1236 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1237 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1238
1239 }
1240
1241 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1242 {
1244 if (food_item && food_item.GetFoodStage())
1245 return FoodStage.GetEnergy(food_item.GetFoodStage());
1246 else if (classname != "" && food_stage)
1247 return FoodStage.GetEnergy(null, food_stage, classname);
1248 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1249 return GetGame().ConfigGetFloat(class_path + " energy");
1250 }
1251
1252 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1253 {
1255 if (food_item && food_item.GetFoodStage())
1256 return FoodStage.GetWater(food_item.GetFoodStage());
1257 else if (classname != "" && food_stage)
1258 return FoodStage.GetWater(null, food_stage, classname);
1259 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1260 return GetGame().ConfigGetFloat(class_path + " water");
1261 }
1262
1263 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1264 {
1266 if (food_item && food_item.GetFoodStage())
1267 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1268 else if (classname != "" && food_stage)
1269 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1270 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1271 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1272
1273 }
1274
1275 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1276 {
1278 if (food_item && food_item.GetFoodStage())
1279 return FoodStage.GetToxicity(food_item.GetFoodStage());
1280 else if (classname != "" && food_stage)
1281 return FoodStage.GetToxicity(null, food_stage, classname);
1282 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1283 return GetGame().ConfigGetFloat(class_path + " toxicity");
1284 }
1285
1286 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1287 {
1289 if (food_item && food_item.GetFoodStage())
1290 return FoodStage.GetAgents(food_item.GetFoodStage());
1291 else if (classname != "" && food_stage)
1292 return FoodStage.GetAgents(null, food_stage, classname);
1293 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1294 return GetGame().ConfigGetInt(class_path + " agents");
1295 }
1296
1297 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1298 {
1300 if (food_item && food_item.GetFoodStage())
1301 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1302 else if (classname != "" && food_stage)
1303 return FoodStage.GetDigestibility(null, food_stage, classname);
1304 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1305 return GetGame().ConfigGetInt(class_path + " digestibility");
1306 }
1307
1309 {
1311 }
1312
1313 //================================================================
1314 // FOOD STAGING
1315 //================================================================
1317 {
1318 return GetFoodStage().GetFoodStageType();
1319 }
1320
1321 //food stage states
1322 bool IsFoodRaw()
1323 {
1324 if (GetFoodStage())
1325 return GetFoodStage().IsFoodRaw();
1326
1327 return false;
1328 }
1329
1330 bool IsFoodBaked()
1331 {
1332 if (GetFoodStage())
1333 return GetFoodStage().IsFoodBaked();
1334
1335 return false;
1336 }
1337
1338 bool IsFoodBoiled()
1339 {
1340 if (GetFoodStage())
1341 return GetFoodStage().IsFoodBoiled();
1342
1343 return false;
1344 }
1345
1346 bool IsFoodDried()
1347 {
1348 if (GetFoodStage())
1349 return GetFoodStage().IsFoodDried();
1350
1351 return false;
1352 }
1353
1354 bool IsFoodBurned()
1355 {
1356 if (GetFoodStage())
1357 return GetFoodStage().IsFoodBurned();
1358
1359 return false;
1360 }
1361
1362 bool IsFoodRotten()
1363 {
1364 if (GetFoodStage())
1365 return GetFoodStage().IsFoodRotten();
1366
1367 return false;
1368 }
1369
1370 //food stage change
1372 {
1373 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1374 }
1375
1377 {
1378 return GetFoodStage().GetNextFoodStageType(cooking_method);
1379 }
1380
1382 {
1383 return GetFoodStage().GetFoodStageName(food_stage_type);
1384 }
1385
1387 {
1388 return GetFoodStage().CanChangeToNewStage(cooking_method);
1389 }
1390
1391 //Use this to receive food stage from another Edible_Base
1393 {
1394 if (!source.HasFoodStage())
1395 return;
1396 m_LastDecayStage = source.GetLastDecayStage();
1397 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1398 m_DecayTimer = source.GetDecayTimer();
1399 m_DecayDelta = source.GetDecayDelta();
1400 }
1401
1402 //================================================================
1403 // COOKING
1404 //================================================================
1405 //cooking time
1406 float GetCookingTime()
1407 {
1408 return GetFoodStage().GetCookingTime();
1409 }
1410
1411 void SetCookingTime(float time)
1412 {
1413 GetFoodStage().SetCookingTime(time);
1414
1415 //synchronize when calling on server
1416 Synchronize();
1417 }
1418
1419 //replace edible with new item (opening cans)
1420 void ReplaceEdibleWithNew(string typeName)
1421 {
1422 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1423 if (player)
1424 {
1426 player.ServerReplaceItemInHandsWithNew(lambda);
1427 }
1428 else
1429 Error("ReplaceEdibleWithNew - cannot use edible without player");
1430 }
1431
1432 override void SetActions()
1433 {
1434 super.SetActions();
1435
1436 AddAction(ActionAttach);
1438 }
1439
1440 protected void SoundCookingStart(string sound_name)
1441 {
1442#ifndef SERVER
1444 {
1446
1449 }
1450#endif
1451 }
1452
1453 protected void SoundCookingStop()
1454 {
1455#ifndef SERVER
1457 {
1460 m_SoundPlaying = "";
1461 }
1462#endif
1463 }
1464
1465 override bool CanHaveTemperature()
1466 {
1467 return true;
1468 }
1469
1470 override bool CanDecay()
1471 {
1472 return false;
1473 }
1474
1475 override bool CanProcessDecay()
1476 {
1477 return (GetFoodStageType() != FoodStageType.ROTTEN);
1478 }
1479
1480 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1481 {
1482 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1483 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1484 if (hasRootAsPlayer)
1486
1487 /*Print( "-------------------------" );
1488 Print( this );
1489 Print( m_DecayTimer );
1490 Print( m_DecayDelta );
1491 Print( m_LastDecayStage );*/
1492
1493 if (IsFruit() || IsMushroom())
1494 {
1495 // fruit, vegetables and mushrooms
1497 {
1498 switch (GetFoodStageType())
1499 {
1500 case FoodStageType.RAW:
1503 break;
1504
1505 case FoodStageType.BOILED:
1508 break;
1509
1510 case FoodStageType.BAKED:
1513 break;
1514
1515 case FoodStageType.DRIED:
1516 case FoodStageType.BURNED:
1517 case FoodStageType.ROTTEN:
1518 default:
1519 m_DecayTimer = -1;
1521 return;
1522 }
1523
1524 //m_DecayTimer = m_DecayTimer / 1000.0;
1525 }
1526
1528
1529 if (m_DecayTimer <= 0)
1530 {
1531 if (m_LastDecayStage != FoodStageType.NONE)
1532 {
1533 // switch to decayed stage
1534 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1537 {
1538 int rng = Math.RandomIntInclusive(0, 100);
1541 else
1542 {
1545 else
1547 }
1548 }
1549 }
1550 }
1551
1552 }
1553 else if (IsMeat())
1554 {
1555 // meat
1557 {
1558 switch (GetFoodStageType())
1559 {
1560 case FoodStageType.RAW:
1563 break;
1564
1565 case FoodStageType.BOILED:
1568 break;
1569
1570 case FoodStageType.BAKED:
1573 break;
1574
1575 case FoodStageType.DRIED:
1578 break;
1579
1580 case FoodStageType.BURNED:
1581 case FoodStageType.ROTTEN:
1582 default:
1583 m_DecayTimer = -1;
1585 return;
1586 }
1587 }
1588
1590
1591 if (m_DecayTimer <= 0)
1592 {
1593 if (m_LastDecayStage != FoodStageType.NONE)
1594 {
1595 // switch to decayed stage
1598 }
1599 }
1600 }
1601 else if (IsCorpse())
1602 {
1603 // corpse
1605 {
1606 switch (GetFoodStageType())
1607 {
1608 case FoodStageType.RAW:
1611 break;
1612
1613 case FoodStageType.BURNED:
1614 case FoodStageType.ROTTEN:
1615 default:
1616 m_DecayTimer = -1;
1618 return;
1619 }
1620 }
1621
1623
1624 if (m_DecayTimer <= 0)
1625 {
1626 if (m_LastDecayStage != FoodStageType.NONE)
1627 {
1628 // switch to decayed stage
1631 }
1632 }
1633 }
1634 else
1635 {
1636 // opened cans
1638
1639 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1640 {
1643 //m_DecayTimer = m_DecayTimer / 1000.0;
1644 }
1645 else
1646 {
1647 if (m_DecayTimer <= 0)
1648 {
1649 InsertAgent(eAgents.FOOD_POISON, 1);
1650 m_DecayTimer = -1;
1651 }
1652 }
1653 }
1654
1655 m_DecayDelta = 0.0;
1656 }
1657
1659 {
1660 super.GetDebugActions(outputList);
1661
1662 if (HasFoodStage())
1663 {
1664 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1665 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1666 }
1667 }
1668
1669 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1670 {
1671 super.OnAction(action_id, player, ctx);
1672
1673 if (GetGame().IsServer())
1674 {
1675 if (action_id == EActions.FOOD_STAGE_PREV)
1676 {
1678 if (food_stage_prev <= 0)
1679 food_stage_prev = FoodStageType.COUNT - 1;
1681 return true;
1682 }
1683 else if (action_id == EActions.FOOD_STAGE_NEXT)
1684 {
1686 if (food_stage_next >= FoodStageType.COUNT)
1689 return true;
1690 }
1691 }
1692 return false;
1693 }
1694
1695 override string GetDebugText()
1696 {
1697 string debug_output;
1698
1699 debug_output = super.GetDebugText();
1700
1701 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1702 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1703
1704 return debug_output;
1705 }
1706
1707 //================================================================
1708 // GENERAL GETTERS
1709 //================================================================
1710
1711 float GetDecayTimer()
1712 {
1713 return m_DecayTimer;
1714 }
1715
1716 float GetDecayDelta()
1717 {
1718 return m_DecayDelta;
1719 }
1720
1722 {
1723 return m_LastDecayStage;
1724 }
1725}
1726
1728{
1730};

Referenced by IEntity::IsFood().

◆ IsMushroom()

override bool ReplaceEdibleWithNewLambda::IsMushroom ( )
protected

Definition at line 993 of file Edible_Base.c.

993 : ItemBase
994{
995 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
996
997 const string SOUND_BAKING_START = "Baking_SoundSet";
998 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
999 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1000
1001 protected bool m_MakeCookingSounds;
1002 protected SoundOnVehicle m_SoundCooking;
1004 protected string m_SoundPlaying;
1006 protected float m_DecayTimer;
1007 protected float m_DecayDelta = 0.0;
1009
1011
1012 void Edible_Base()
1013 {
1014 if (HasFoodStage())
1015 {
1016 m_FoodStage = new FoodStage(this);
1017
1018 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1019 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1020 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1021 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1022 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1023
1024 m_SoundPlaying = "";
1026 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1027 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1028 }
1029 }
1030
1031 override void EEInit()
1032 {
1033 super.EEInit();
1034
1035 UpdateVisuals();
1036 }
1037
1038 override void EEDelete(EntityAI parent)
1039 {
1040 super.EEDelete(parent);
1041
1042 RemoveAudio();
1043 }
1044
1046 {
1047 super.EEItemLocationChanged(oldLoc, newLoc);
1048
1050 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1051 {
1052 switch (oldLoc.GetParent().GetType())
1053 {
1054 case "FryingPan":
1055 case "Pot":
1056 case "Cauldron":
1057 case "SharpWoodenStick":
1058 MakeSoundsOnClient(false);
1059 break;
1060 }
1061
1063 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1064 MakeSoundsOnClient(false);
1065 }
1066 }
1067
1068 void UpdateVisuals()
1069 {
1070 if (GetFoodStage())
1071 GetFoodStage().UpdateVisuals();
1072 }
1073
1074 bool Consume(float amount, PlayerBase consumer)
1075 {
1076 AddQuantity(-amount, false, false);
1077 OnConsume(amount, consumer);
1078
1079 return true;
1080 }
1081
1082 void OnConsume(float amount, PlayerBase consumer);
1083
1084 //food staging
1085 override bool CanBeCooked()
1086 {
1087 return false;
1088 }
1089
1090 override bool CanBeCookedOnStick()
1091 {
1092 return false;
1093 }
1094
1095 //================================================================
1096 // SYNCHRONIZATION
1097 //================================================================
1098 void Synchronize()
1099 {
1100 SetSynchDirty();
1101
1102 if (GetGame().IsMultiplayer())
1103 UpdateVisuals();
1104 }
1105
1106 override void OnVariablesSynchronized()
1107 {
1108 super.OnVariablesSynchronized();
1109
1110 UpdateVisuals();
1111
1112 //update audio
1114 RefreshAudio();
1115 else
1116 RemoveAudio();
1117 }
1118
1119 //================================================================
1120 // AUDIO EFFECTS (WHEN ON DCS)
1121 //================================================================
1123 {
1126
1127 Synchronize();
1128 }
1129
1130 protected void RefreshAudio()
1131 {
1132 string soundName = "";
1133
1135
1136 switch (GetFoodStageType())
1137 {
1138 case FoodStageType.RAW:
1140 if (nextFoodState == FoodStageType.BOILED)
1141 soundName = "";
1142 break;
1143 case FoodStageType.BAKED:
1145 break;
1146 case FoodStageType.BURNED:
1148 break;
1149 default:
1150 soundName = "";
1151 break;
1152 }
1153
1155 }
1156
1157 protected void RemoveAudio()
1158 {
1159 m_MakeCookingSounds = false;
1161 }
1162
1163 //================================================================
1164 // SERIALIZATION
1165 //================================================================
1166 override void OnStoreSave(ParamsWriteContext ctx)
1167 {
1168 super.OnStoreSave(ctx);
1169
1170 if (GetFoodStage())
1171 GetFoodStage().OnStoreSave(ctx);
1172
1173 // food decay
1174 ctx.Write(m_DecayTimer);
1175 ctx.Write(m_LastDecayStage);
1176 }
1177
1178 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1179 {
1180 if (!super.OnStoreLoad(ctx, version))
1181 return false;
1182
1183 if (GetFoodStage())
1184 {
1185 if (!GetFoodStage().OnStoreLoad(ctx, version))
1186 return false;
1187 }
1188
1189 if (version >= 115)
1190 {
1191 if (!ctx.Read(m_DecayTimer))
1192 {
1193 m_DecayTimer = 0.0;
1194 return false;
1195 }
1196 if (!ctx.Read(m_LastDecayStage))
1197 {
1199 return false;
1200 }
1201 }
1202
1203 return true;
1204 }
1205
1206 override void AfterStoreLoad()
1207 {
1208 super.AfterStoreLoad();
1209
1210 Synchronize();
1211 }
1212
1213 //get food stage
1215 {
1216 return m_FoodStage;
1217 }
1218
1219 //food types
1220 override bool IsMeat()
1221 {
1222 return false;
1223 }
1224
1225 override bool IsCorpse()
1226 {
1227 return false;
1228 }
1229
1230 override bool IsFruit()
1231 {
1232 return false;
1233 }
1234
1235 override bool IsMushroom()
1236 {
1237 return false;
1238 }
1239
1240 //================================================================
1241 // NUTRITIONAL VALUES
1242 //================================================================
1243 //food properties
1244 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1245 {
1247 if (food_item && food_item.GetFoodStage())
1248 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1249 else if (classname != "" && food_stage)
1250 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1251 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1252 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1253
1254 }
1255
1256 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1257 {
1259 if (food_item && food_item.GetFoodStage())
1260 return FoodStage.GetEnergy(food_item.GetFoodStage());
1261 else if (classname != "" && food_stage)
1262 return FoodStage.GetEnergy(null, food_stage, classname);
1263 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1264 return GetGame().ConfigGetFloat(class_path + " energy");
1265 }
1266
1267 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1268 {
1270 if (food_item && food_item.GetFoodStage())
1271 return FoodStage.GetWater(food_item.GetFoodStage());
1272 else if (classname != "" && food_stage)
1273 return FoodStage.GetWater(null, food_stage, classname);
1274 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1275 return GetGame().ConfigGetFloat(class_path + " water");
1276 }
1277
1278 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1279 {
1281 if (food_item && food_item.GetFoodStage())
1282 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1283 else if (classname != "" && food_stage)
1284 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1285 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1286 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1287
1288 }
1289
1290 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1291 {
1293 if (food_item && food_item.GetFoodStage())
1294 return FoodStage.GetToxicity(food_item.GetFoodStage());
1295 else if (classname != "" && food_stage)
1296 return FoodStage.GetToxicity(null, food_stage, classname);
1297 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1298 return GetGame().ConfigGetFloat(class_path + " toxicity");
1299 }
1300
1301 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1302 {
1304 if (food_item && food_item.GetFoodStage())
1305 return FoodStage.GetAgents(food_item.GetFoodStage());
1306 else if (classname != "" && food_stage)
1307 return FoodStage.GetAgents(null, food_stage, classname);
1308 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1309 return GetGame().ConfigGetInt(class_path + " agents");
1310 }
1311
1312 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1313 {
1315 if (food_item && food_item.GetFoodStage())
1316 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1317 else if (classname != "" && food_stage)
1318 return FoodStage.GetDigestibility(null, food_stage, classname);
1319 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1320 return GetGame().ConfigGetInt(class_path + " digestibility");
1321 }
1322
1324 {
1326 }
1327
1328 //================================================================
1329 // FOOD STAGING
1330 //================================================================
1332 {
1333 return GetFoodStage().GetFoodStageType();
1334 }
1335
1336 //food stage states
1337 bool IsFoodRaw()
1338 {
1339 if (GetFoodStage())
1340 return GetFoodStage().IsFoodRaw();
1341
1342 return false;
1343 }
1344
1345 bool IsFoodBaked()
1346 {
1347 if (GetFoodStage())
1348 return GetFoodStage().IsFoodBaked();
1349
1350 return false;
1351 }
1352
1353 bool IsFoodBoiled()
1354 {
1355 if (GetFoodStage())
1356 return GetFoodStage().IsFoodBoiled();
1357
1358 return false;
1359 }
1360
1361 bool IsFoodDried()
1362 {
1363 if (GetFoodStage())
1364 return GetFoodStage().IsFoodDried();
1365
1366 return false;
1367 }
1368
1369 bool IsFoodBurned()
1370 {
1371 if (GetFoodStage())
1372 return GetFoodStage().IsFoodBurned();
1373
1374 return false;
1375 }
1376
1377 bool IsFoodRotten()
1378 {
1379 if (GetFoodStage())
1380 return GetFoodStage().IsFoodRotten();
1381
1382 return false;
1383 }
1384
1385 //food stage change
1387 {
1388 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1389 }
1390
1392 {
1393 return GetFoodStage().GetNextFoodStageType(cooking_method);
1394 }
1395
1397 {
1398 return GetFoodStage().GetFoodStageName(food_stage_type);
1399 }
1400
1402 {
1403 return GetFoodStage().CanChangeToNewStage(cooking_method);
1404 }
1405
1406 //Use this to receive food stage from another Edible_Base
1408 {
1409 if (!source.HasFoodStage())
1410 return;
1411 m_LastDecayStage = source.GetLastDecayStage();
1412 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1413 m_DecayTimer = source.GetDecayTimer();
1414 m_DecayDelta = source.GetDecayDelta();
1415 }
1416
1417 //================================================================
1418 // COOKING
1419 //================================================================
1420 //cooking time
1421 float GetCookingTime()
1422 {
1423 return GetFoodStage().GetCookingTime();
1424 }
1425
1426 void SetCookingTime(float time)
1427 {
1428 GetFoodStage().SetCookingTime(time);
1429
1430 //synchronize when calling on server
1431 Synchronize();
1432 }
1433
1434 //replace edible with new item (opening cans)
1435 void ReplaceEdibleWithNew(string typeName)
1436 {
1437 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1438 if (player)
1439 {
1441 player.ServerReplaceItemInHandsWithNew(lambda);
1442 }
1443 else
1444 Error("ReplaceEdibleWithNew - cannot use edible without player");
1445 }
1446
1447 override void SetActions()
1448 {
1449 super.SetActions();
1450
1451 AddAction(ActionAttach);
1453 }
1454
1455 protected void SoundCookingStart(string sound_name)
1456 {
1457#ifndef SERVER
1459 {
1461
1464 }
1465#endif
1466 }
1467
1468 protected void SoundCookingStop()
1469 {
1470#ifndef SERVER
1472 {
1475 m_SoundPlaying = "";
1476 }
1477#endif
1478 }
1479
1480 override bool CanHaveTemperature()
1481 {
1482 return true;
1483 }
1484
1485 override bool CanDecay()
1486 {
1487 return false;
1488 }
1489
1490 override bool CanProcessDecay()
1491 {
1492 return (GetFoodStageType() != FoodStageType.ROTTEN);
1493 }
1494
1495 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1496 {
1497 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1498 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1499 if (hasRootAsPlayer)
1501
1502 /*Print( "-------------------------" );
1503 Print( this );
1504 Print( m_DecayTimer );
1505 Print( m_DecayDelta );
1506 Print( m_LastDecayStage );*/
1507
1508 if (IsFruit() || IsMushroom())
1509 {
1510 // fruit, vegetables and mushrooms
1512 {
1513 switch (GetFoodStageType())
1514 {
1515 case FoodStageType.RAW:
1518 break;
1519
1520 case FoodStageType.BOILED:
1523 break;
1524
1525 case FoodStageType.BAKED:
1528 break;
1529
1530 case FoodStageType.DRIED:
1531 case FoodStageType.BURNED:
1532 case FoodStageType.ROTTEN:
1533 default:
1534 m_DecayTimer = -1;
1536 return;
1537 }
1538
1539 //m_DecayTimer = m_DecayTimer / 1000.0;
1540 }
1541
1543
1544 if (m_DecayTimer <= 0)
1545 {
1546 if (m_LastDecayStage != FoodStageType.NONE)
1547 {
1548 // switch to decayed stage
1549 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1552 {
1553 int rng = Math.RandomIntInclusive(0, 100);
1556 else
1557 {
1560 else
1562 }
1563 }
1564 }
1565 }
1566
1567 }
1568 else if (IsMeat())
1569 {
1570 // meat
1572 {
1573 switch (GetFoodStageType())
1574 {
1575 case FoodStageType.RAW:
1578 break;
1579
1580 case FoodStageType.BOILED:
1583 break;
1584
1585 case FoodStageType.BAKED:
1588 break;
1589
1590 case FoodStageType.DRIED:
1593 break;
1594
1595 case FoodStageType.BURNED:
1596 case FoodStageType.ROTTEN:
1597 default:
1598 m_DecayTimer = -1;
1600 return;
1601 }
1602 }
1603
1605
1606 if (m_DecayTimer <= 0)
1607 {
1608 if (m_LastDecayStage != FoodStageType.NONE)
1609 {
1610 // switch to decayed stage
1613 }
1614 }
1615 }
1616 else if (IsCorpse())
1617 {
1618 // corpse
1620 {
1621 switch (GetFoodStageType())
1622 {
1623 case FoodStageType.RAW:
1626 break;
1627
1628 case FoodStageType.BURNED:
1629 case FoodStageType.ROTTEN:
1630 default:
1631 m_DecayTimer = -1;
1633 return;
1634 }
1635 }
1636
1638
1639 if (m_DecayTimer <= 0)
1640 {
1641 if (m_LastDecayStage != FoodStageType.NONE)
1642 {
1643 // switch to decayed stage
1646 }
1647 }
1648 }
1649 else
1650 {
1651 // opened cans
1653
1654 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1655 {
1658 //m_DecayTimer = m_DecayTimer / 1000.0;
1659 }
1660 else
1661 {
1662 if (m_DecayTimer <= 0)
1663 {
1664 InsertAgent(eAgents.FOOD_POISON, 1);
1665 m_DecayTimer = -1;
1666 }
1667 }
1668 }
1669
1670 m_DecayDelta = 0.0;
1671 }
1672
1674 {
1675 super.GetDebugActions(outputList);
1676
1677 if (HasFoodStage())
1678 {
1679 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1680 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1681 }
1682 }
1683
1684 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1685 {
1686 super.OnAction(action_id, player, ctx);
1687
1688 if (GetGame().IsServer())
1689 {
1690 if (action_id == EActions.FOOD_STAGE_PREV)
1691 {
1693 if (food_stage_prev <= 0)
1694 food_stage_prev = FoodStageType.COUNT - 1;
1696 return true;
1697 }
1698 else if (action_id == EActions.FOOD_STAGE_NEXT)
1699 {
1701 if (food_stage_next >= FoodStageType.COUNT)
1704 return true;
1705 }
1706 }
1707 return false;
1708 }
1709
1710 override string GetDebugText()
1711 {
1712 string debug_output;
1713
1714 debug_output = super.GetDebugText();
1715
1716 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1717 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1718
1719 return debug_output;
1720 }
1721
1722 //================================================================
1723 // GENERAL GETTERS
1724 //================================================================
1725
1726 float GetDecayTimer()
1727 {
1728 return m_DecayTimer;
1729 }
1730
1731 float GetDecayDelta()
1732 {
1733 return m_DecayDelta;
1734 }
1735
1737 {
1738 return m_LastDecayStage;
1739 }
1740}
1741
1743{
1745};

Referenced by IEntity::IsFood().

◆ MakeSoundsOnClient()

void ReplaceEdibleWithNewLambda::MakeSoundsOnClient ( bool soundstate,
CookingMethodType cookingMethod = CookingMethodType.NONE )
private

Definition at line 880 of file Edible_Base.c.

880 : ItemBase
881{
882 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
883
884 const string SOUND_BAKING_START = "Baking_SoundSet";
885 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
886 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
887
888 protected bool m_MakeCookingSounds;
891 protected string m_SoundPlaying;
893 protected float m_DecayTimer;
894 protected float m_DecayDelta = 0.0;
896
898
899 void Edible_Base()
900 {
901 if (HasFoodStage())
902 {
903 m_FoodStage = new FoodStage(this);
904
905 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
906 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
907 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
908 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
909 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
910
911 m_SoundPlaying = "";
913 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
914 RegisterNetSyncVariableBool("m_MakeCookingSounds");
915 }
916 }
917
918 override void EEInit()
919 {
920 super.EEInit();
921
923 }
924
925 override void EEDelete(EntityAI parent)
926 {
927 super.EEDelete(parent);
928
929 RemoveAudio();
930 }
931
933 {
934 super.EEItemLocationChanged(oldLoc, newLoc);
935
937 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
938 {
939 switch (oldLoc.GetParent().GetType())
940 {
941 case "FryingPan":
942 case "Pot":
943 case "Cauldron":
944 case "SharpWoodenStick":
945 MakeSoundsOnClient(false);
946 break;
947 }
948
950 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
951 MakeSoundsOnClient(false);
952 }
953 }
954
955 void UpdateVisuals()
956 {
957 if (GetFoodStage())
958 GetFoodStage().UpdateVisuals();
959 }
960
961 bool Consume(float amount, PlayerBase consumer)
962 {
963 AddQuantity(-amount, false, false);
964 OnConsume(amount, consumer);
965
966 return true;
967 }
968
969 void OnConsume(float amount, PlayerBase consumer);
970
971 //food staging
972 override bool CanBeCooked()
973 {
974 return false;
975 }
976
977 override bool CanBeCookedOnStick()
978 {
979 return false;
980 }
981
982 //================================================================
983 // SYNCHRONIZATION
984 //================================================================
985 void Synchronize()
986 {
987 SetSynchDirty();
988
989 if (GetGame().IsMultiplayer())
991 }
992
993 override void OnVariablesSynchronized()
994 {
995 super.OnVariablesSynchronized();
996
998
999 //update audio
1001 RefreshAudio();
1002 else
1003 RemoveAudio();
1004 }
1005
1006 //================================================================
1007 // AUDIO EFFECTS (WHEN ON DCS)
1008 //================================================================
1010 {
1013
1014 Synchronize();
1015 }
1016
1017 protected void RefreshAudio()
1018 {
1019 string soundName = "";
1020
1022
1023 switch (GetFoodStageType())
1024 {
1025 case FoodStageType.RAW:
1027 if (nextFoodState == FoodStageType.BOILED)
1028 soundName = "";
1029 break;
1030 case FoodStageType.BAKED:
1032 break;
1033 case FoodStageType.BURNED:
1035 break;
1036 default:
1037 soundName = "";
1038 break;
1039 }
1040
1042 }
1043
1044 protected void RemoveAudio()
1045 {
1046 m_MakeCookingSounds = false;
1048 }
1049
1050 //================================================================
1051 // SERIALIZATION
1052 //================================================================
1053 override void OnStoreSave(ParamsWriteContext ctx)
1054 {
1055 super.OnStoreSave(ctx);
1056
1057 if (GetFoodStage())
1058 GetFoodStage().OnStoreSave(ctx);
1059
1060 // food decay
1061 ctx.Write(m_DecayTimer);
1062 ctx.Write(m_LastDecayStage);
1063 }
1064
1065 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1066 {
1067 if (!super.OnStoreLoad(ctx, version))
1068 return false;
1069
1070 if (GetFoodStage())
1071 {
1072 if (!GetFoodStage().OnStoreLoad(ctx, version))
1073 return false;
1074 }
1075
1076 if (version >= 115)
1077 {
1078 if (!ctx.Read(m_DecayTimer))
1079 {
1080 m_DecayTimer = 0.0;
1081 return false;
1082 }
1083 if (!ctx.Read(m_LastDecayStage))
1084 {
1086 return false;
1087 }
1088 }
1089
1090 return true;
1091 }
1092
1093 override void AfterStoreLoad()
1094 {
1095 super.AfterStoreLoad();
1096
1097 Synchronize();
1098 }
1099
1100 //get food stage
1102 {
1103 return m_FoodStage;
1104 }
1105
1106 //food types
1107 override bool IsMeat()
1108 {
1109 return false;
1110 }
1111
1112 override bool IsCorpse()
1113 {
1114 return false;
1115 }
1116
1117 override bool IsFruit()
1118 {
1119 return false;
1120 }
1121
1122 override bool IsMushroom()
1123 {
1124 return false;
1125 }
1126
1127 //================================================================
1128 // NUTRITIONAL VALUES
1129 //================================================================
1130 //food properties
1131 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1132 {
1134 if (food_item && food_item.GetFoodStage())
1135 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1136 else if (classname != "" && food_stage)
1137 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1138 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1139 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1140
1141 }
1142
1143 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1144 {
1146 if (food_item && food_item.GetFoodStage())
1147 return FoodStage.GetEnergy(food_item.GetFoodStage());
1148 else if (classname != "" && food_stage)
1149 return FoodStage.GetEnergy(null, food_stage, classname);
1150 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1151 return GetGame().ConfigGetFloat(class_path + " energy");
1152 }
1153
1154 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1155 {
1157 if (food_item && food_item.GetFoodStage())
1158 return FoodStage.GetWater(food_item.GetFoodStage());
1159 else if (classname != "" && food_stage)
1160 return FoodStage.GetWater(null, food_stage, classname);
1161 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1162 return GetGame().ConfigGetFloat(class_path + " water");
1163 }
1164
1165 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1166 {
1168 if (food_item && food_item.GetFoodStage())
1169 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1170 else if (classname != "" && food_stage)
1171 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1172 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1173 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1174
1175 }
1176
1177 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1178 {
1180 if (food_item && food_item.GetFoodStage())
1181 return FoodStage.GetToxicity(food_item.GetFoodStage());
1182 else if (classname != "" && food_stage)
1183 return FoodStage.GetToxicity(null, food_stage, classname);
1184 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1185 return GetGame().ConfigGetFloat(class_path + " toxicity");
1186 }
1187
1188 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1189 {
1191 if (food_item && food_item.GetFoodStage())
1192 return FoodStage.GetAgents(food_item.GetFoodStage());
1193 else if (classname != "" && food_stage)
1194 return FoodStage.GetAgents(null, food_stage, classname);
1195 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1196 return GetGame().ConfigGetInt(class_path + " agents");
1197 }
1198
1199 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1200 {
1202 if (food_item && food_item.GetFoodStage())
1203 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1204 else if (classname != "" && food_stage)
1205 return FoodStage.GetDigestibility(null, food_stage, classname);
1206 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1207 return GetGame().ConfigGetInt(class_path + " digestibility");
1208 }
1209
1211 {
1213 }
1214
1215 //================================================================
1216 // FOOD STAGING
1217 //================================================================
1219 {
1220 return GetFoodStage().GetFoodStageType();
1221 }
1222
1223 //food stage states
1224 bool IsFoodRaw()
1225 {
1226 if (GetFoodStage())
1227 return GetFoodStage().IsFoodRaw();
1228
1229 return false;
1230 }
1231
1232 bool IsFoodBaked()
1233 {
1234 if (GetFoodStage())
1235 return GetFoodStage().IsFoodBaked();
1236
1237 return false;
1238 }
1239
1240 bool IsFoodBoiled()
1241 {
1242 if (GetFoodStage())
1243 return GetFoodStage().IsFoodBoiled();
1244
1245 return false;
1246 }
1247
1248 bool IsFoodDried()
1249 {
1250 if (GetFoodStage())
1251 return GetFoodStage().IsFoodDried();
1252
1253 return false;
1254 }
1255
1256 bool IsFoodBurned()
1257 {
1258 if (GetFoodStage())
1259 return GetFoodStage().IsFoodBurned();
1260
1261 return false;
1262 }
1263
1264 bool IsFoodRotten()
1265 {
1266 if (GetFoodStage())
1267 return GetFoodStage().IsFoodRotten();
1268
1269 return false;
1270 }
1271
1272 //food stage change
1274 {
1275 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1276 }
1277
1279 {
1280 return GetFoodStage().GetNextFoodStageType(cooking_method);
1281 }
1282
1284 {
1285 return GetFoodStage().GetFoodStageName(food_stage_type);
1286 }
1287
1289 {
1290 return GetFoodStage().CanChangeToNewStage(cooking_method);
1291 }
1292
1293 //Use this to receive food stage from another Edible_Base
1295 {
1296 if (!source.HasFoodStage())
1297 return;
1298 m_LastDecayStage = source.GetLastDecayStage();
1299 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1300 m_DecayTimer = source.GetDecayTimer();
1301 m_DecayDelta = source.GetDecayDelta();
1302 }
1303
1304 //================================================================
1305 // COOKING
1306 //================================================================
1307 //cooking time
1308 float GetCookingTime()
1309 {
1310 return GetFoodStage().GetCookingTime();
1311 }
1312
1313 void SetCookingTime(float time)
1314 {
1315 GetFoodStage().SetCookingTime(time);
1316
1317 //synchronize when calling on server
1318 Synchronize();
1319 }
1320
1321 //replace edible with new item (opening cans)
1322 void ReplaceEdibleWithNew(string typeName)
1323 {
1324 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1325 if (player)
1326 {
1328 player.ServerReplaceItemInHandsWithNew(lambda);
1329 }
1330 else
1331 Error("ReplaceEdibleWithNew - cannot use edible without player");
1332 }
1333
1334 override void SetActions()
1335 {
1336 super.SetActions();
1337
1338 AddAction(ActionAttach);
1340 }
1341
1342 protected void SoundCookingStart(string sound_name)
1343 {
1344#ifndef SERVER
1346 {
1348
1351 }
1352#endif
1353 }
1354
1355 protected void SoundCookingStop()
1356 {
1357#ifndef SERVER
1359 {
1362 m_SoundPlaying = "";
1363 }
1364#endif
1365 }
1366
1367 override bool CanHaveTemperature()
1368 {
1369 return true;
1370 }
1371
1372 override bool CanDecay()
1373 {
1374 return false;
1375 }
1376
1377 override bool CanProcessDecay()
1378 {
1379 return (GetFoodStageType() != FoodStageType.ROTTEN);
1380 }
1381
1382 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1383 {
1384 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1385 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1386 if (hasRootAsPlayer)
1388
1389 /*Print( "-------------------------" );
1390 Print( this );
1391 Print( m_DecayTimer );
1392 Print( m_DecayDelta );
1393 Print( m_LastDecayStage );*/
1394
1395 if (IsFruit() || IsMushroom())
1396 {
1397 // fruit, vegetables and mushrooms
1399 {
1400 switch (GetFoodStageType())
1401 {
1402 case FoodStageType.RAW:
1405 break;
1406
1407 case FoodStageType.BOILED:
1410 break;
1411
1412 case FoodStageType.BAKED:
1415 break;
1416
1417 case FoodStageType.DRIED:
1418 case FoodStageType.BURNED:
1419 case FoodStageType.ROTTEN:
1420 default:
1421 m_DecayTimer = -1;
1423 return;
1424 }
1425
1426 //m_DecayTimer = m_DecayTimer / 1000.0;
1427 }
1428
1430
1431 if (m_DecayTimer <= 0)
1432 {
1433 if (m_LastDecayStage != FoodStageType.NONE)
1434 {
1435 // switch to decayed stage
1436 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1439 {
1440 int rng = Math.RandomIntInclusive(0, 100);
1443 else
1444 {
1447 else
1449 }
1450 }
1451 }
1452 }
1453
1454 }
1455 else if (IsMeat())
1456 {
1457 // meat
1459 {
1460 switch (GetFoodStageType())
1461 {
1462 case FoodStageType.RAW:
1465 break;
1466
1467 case FoodStageType.BOILED:
1470 break;
1471
1472 case FoodStageType.BAKED:
1475 break;
1476
1477 case FoodStageType.DRIED:
1480 break;
1481
1482 case FoodStageType.BURNED:
1483 case FoodStageType.ROTTEN:
1484 default:
1485 m_DecayTimer = -1;
1487 return;
1488 }
1489 }
1490
1492
1493 if (m_DecayTimer <= 0)
1494 {
1495 if (m_LastDecayStage != FoodStageType.NONE)
1496 {
1497 // switch to decayed stage
1500 }
1501 }
1502 }
1503 else if (IsCorpse())
1504 {
1505 // corpse
1507 {
1508 switch (GetFoodStageType())
1509 {
1510 case FoodStageType.RAW:
1513 break;
1514
1515 case FoodStageType.BURNED:
1516 case FoodStageType.ROTTEN:
1517 default:
1518 m_DecayTimer = -1;
1520 return;
1521 }
1522 }
1523
1525
1526 if (m_DecayTimer <= 0)
1527 {
1528 if (m_LastDecayStage != FoodStageType.NONE)
1529 {
1530 // switch to decayed stage
1533 }
1534 }
1535 }
1536 else
1537 {
1538 // opened cans
1540
1541 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1542 {
1545 //m_DecayTimer = m_DecayTimer / 1000.0;
1546 }
1547 else
1548 {
1549 if (m_DecayTimer <= 0)
1550 {
1551 InsertAgent(eAgents.FOOD_POISON, 1);
1552 m_DecayTimer = -1;
1553 }
1554 }
1555 }
1556
1557 m_DecayDelta = 0.0;
1558 }
1559
1561 {
1562 super.GetDebugActions(outputList);
1563
1564 if (HasFoodStage())
1565 {
1566 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1567 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1568 }
1569 }
1570
1571 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1572 {
1573 super.OnAction(action_id, player, ctx);
1574
1575 if (GetGame().IsServer())
1576 {
1577 if (action_id == EActions.FOOD_STAGE_PREV)
1578 {
1580 if (food_stage_prev <= 0)
1581 food_stage_prev = FoodStageType.COUNT - 1;
1583 return true;
1584 }
1585 else if (action_id == EActions.FOOD_STAGE_NEXT)
1586 {
1588 if (food_stage_next >= FoodStageType.COUNT)
1591 return true;
1592 }
1593 }
1594 return false;
1595 }
1596
1597 override string GetDebugText()
1598 {
1599 string debug_output;
1600
1601 debug_output = super.GetDebugText();
1602
1603 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1604 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1605
1606 return debug_output;
1607 }
1608
1609 //================================================================
1610 // GENERAL GETTERS
1611 //================================================================
1612
1613 float GetDecayTimer()
1614 {
1615 return m_DecayTimer;
1616 }
1617
1618 float GetDecayDelta()
1619 {
1620 return m_DecayDelta;
1621 }
1622
1624 {
1625 return m_LastDecayStage;
1626 }
1627}
1628
1630{
1632};

◆ OnAction()

override bool ReplaceEdibleWithNewLambda::OnAction ( int action_id,
Man player,
ParamsReadContext ctx )
protected

Definition at line 1442 of file Edible_Base.c.

1442 : ItemBase
1443{
1444 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1445
1446 const string SOUND_BAKING_START = "Baking_SoundSet";
1447 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1448 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1449
1450 protected bool m_MakeCookingSounds;
1451 protected SoundOnVehicle m_SoundCooking;
1453 protected string m_SoundPlaying;
1455 protected float m_DecayTimer;
1456 protected float m_DecayDelta = 0.0;
1458
1460
1461 void Edible_Base()
1462 {
1463 if (HasFoodStage())
1464 {
1465 m_FoodStage = new FoodStage(this);
1466
1467 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1468 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1469 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1470 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1471 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1472
1473 m_SoundPlaying = "";
1475 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1476 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1477 }
1478 }
1479
1480 override void EEInit()
1481 {
1482 super.EEInit();
1483
1484 UpdateVisuals();
1485 }
1486
1487 override void EEDelete(EntityAI parent)
1488 {
1489 super.EEDelete(parent);
1490
1491 RemoveAudio();
1492 }
1493
1495 {
1496 super.EEItemLocationChanged(oldLoc, newLoc);
1497
1499 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1500 {
1501 switch (oldLoc.GetParent().GetType())
1502 {
1503 case "FryingPan":
1504 case "Pot":
1505 case "Cauldron":
1506 case "SharpWoodenStick":
1507 MakeSoundsOnClient(false);
1508 break;
1509 }
1510
1512 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1513 MakeSoundsOnClient(false);
1514 }
1515 }
1516
1517 void UpdateVisuals()
1518 {
1519 if (GetFoodStage())
1520 GetFoodStage().UpdateVisuals();
1521 }
1522
1523 bool Consume(float amount, PlayerBase consumer)
1524 {
1525 AddQuantity(-amount, false, false);
1526 OnConsume(amount, consumer);
1527
1528 return true;
1529 }
1530
1531 void OnConsume(float amount, PlayerBase consumer);
1532
1533 //food staging
1534 override bool CanBeCooked()
1535 {
1536 return false;
1537 }
1538
1539 override bool CanBeCookedOnStick()
1540 {
1541 return false;
1542 }
1543
1544 //================================================================
1545 // SYNCHRONIZATION
1546 //================================================================
1547 void Synchronize()
1548 {
1549 SetSynchDirty();
1550
1551 if (GetGame().IsMultiplayer())
1552 UpdateVisuals();
1553 }
1554
1555 override void OnVariablesSynchronized()
1556 {
1557 super.OnVariablesSynchronized();
1558
1559 UpdateVisuals();
1560
1561 //update audio
1563 RefreshAudio();
1564 else
1565 RemoveAudio();
1566 }
1567
1568 //================================================================
1569 // AUDIO EFFECTS (WHEN ON DCS)
1570 //================================================================
1572 {
1575
1576 Synchronize();
1577 }
1578
1579 protected void RefreshAudio()
1580 {
1581 string soundName = "";
1582
1584
1585 switch (GetFoodStageType())
1586 {
1587 case FoodStageType.RAW:
1589 if (nextFoodState == FoodStageType.BOILED)
1590 soundName = "";
1591 break;
1592 case FoodStageType.BAKED:
1594 break;
1595 case FoodStageType.BURNED:
1597 break;
1598 default:
1599 soundName = "";
1600 break;
1601 }
1602
1604 }
1605
1606 protected void RemoveAudio()
1607 {
1608 m_MakeCookingSounds = false;
1610 }
1611
1612 //================================================================
1613 // SERIALIZATION
1614 //================================================================
1615 override void OnStoreSave(ParamsWriteContext ctx)
1616 {
1617 super.OnStoreSave(ctx);
1618
1619 if (GetFoodStage())
1620 GetFoodStage().OnStoreSave(ctx);
1621
1622 // food decay
1623 ctx.Write(m_DecayTimer);
1624 ctx.Write(m_LastDecayStage);
1625 }
1626
1627 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1628 {
1629 if (!super.OnStoreLoad(ctx, version))
1630 return false;
1631
1632 if (GetFoodStage())
1633 {
1634 if (!GetFoodStage().OnStoreLoad(ctx, version))
1635 return false;
1636 }
1637
1638 if (version >= 115)
1639 {
1640 if (!ctx.Read(m_DecayTimer))
1641 {
1642 m_DecayTimer = 0.0;
1643 return false;
1644 }
1645 if (!ctx.Read(m_LastDecayStage))
1646 {
1648 return false;
1649 }
1650 }
1651
1652 return true;
1653 }
1654
1655 override void AfterStoreLoad()
1656 {
1657 super.AfterStoreLoad();
1658
1659 Synchronize();
1660 }
1661
1662 //get food stage
1664 {
1665 return m_FoodStage;
1666 }
1667
1668 //food types
1669 override bool IsMeat()
1670 {
1671 return false;
1672 }
1673
1674 override bool IsCorpse()
1675 {
1676 return false;
1677 }
1678
1679 override bool IsFruit()
1680 {
1681 return false;
1682 }
1683
1684 override bool IsMushroom()
1685 {
1686 return false;
1687 }
1688
1689 //================================================================
1690 // NUTRITIONAL VALUES
1691 //================================================================
1692 //food properties
1693 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1694 {
1696 if (food_item && food_item.GetFoodStage())
1697 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1698 else if (classname != "" && food_stage)
1699 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1700 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1701 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1702
1703 }
1704
1705 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1706 {
1708 if (food_item && food_item.GetFoodStage())
1709 return FoodStage.GetEnergy(food_item.GetFoodStage());
1710 else if (classname != "" && food_stage)
1711 return FoodStage.GetEnergy(null, food_stage, classname);
1712 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1713 return GetGame().ConfigGetFloat(class_path + " energy");
1714 }
1715
1716 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1717 {
1719 if (food_item && food_item.GetFoodStage())
1720 return FoodStage.GetWater(food_item.GetFoodStage());
1721 else if (classname != "" && food_stage)
1722 return FoodStage.GetWater(null, food_stage, classname);
1723 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1724 return GetGame().ConfigGetFloat(class_path + " water");
1725 }
1726
1727 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1728 {
1730 if (food_item && food_item.GetFoodStage())
1731 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1732 else if (classname != "" && food_stage)
1733 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1734 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1735 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1736
1737 }
1738
1739 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1740 {
1742 if (food_item && food_item.GetFoodStage())
1743 return FoodStage.GetToxicity(food_item.GetFoodStage());
1744 else if (classname != "" && food_stage)
1745 return FoodStage.GetToxicity(null, food_stage, classname);
1746 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1747 return GetGame().ConfigGetFloat(class_path + " toxicity");
1748 }
1749
1750 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1751 {
1753 if (food_item && food_item.GetFoodStage())
1754 return FoodStage.GetAgents(food_item.GetFoodStage());
1755 else if (classname != "" && food_stage)
1756 return FoodStage.GetAgents(null, food_stage, classname);
1757 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1758 return GetGame().ConfigGetInt(class_path + " agents");
1759 }
1760
1761 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1762 {
1764 if (food_item && food_item.GetFoodStage())
1765 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1766 else if (classname != "" && food_stage)
1767 return FoodStage.GetDigestibility(null, food_stage, classname);
1768 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1769 return GetGame().ConfigGetInt(class_path + " digestibility");
1770 }
1771
1773 {
1775 }
1776
1777 //================================================================
1778 // FOOD STAGING
1779 //================================================================
1781 {
1782 return GetFoodStage().GetFoodStageType();
1783 }
1784
1785 //food stage states
1786 bool IsFoodRaw()
1787 {
1788 if (GetFoodStage())
1789 return GetFoodStage().IsFoodRaw();
1790
1791 return false;
1792 }
1793
1794 bool IsFoodBaked()
1795 {
1796 if (GetFoodStage())
1797 return GetFoodStage().IsFoodBaked();
1798
1799 return false;
1800 }
1801
1802 bool IsFoodBoiled()
1803 {
1804 if (GetFoodStage())
1805 return GetFoodStage().IsFoodBoiled();
1806
1807 return false;
1808 }
1809
1810 bool IsFoodDried()
1811 {
1812 if (GetFoodStage())
1813 return GetFoodStage().IsFoodDried();
1814
1815 return false;
1816 }
1817
1818 bool IsFoodBurned()
1819 {
1820 if (GetFoodStage())
1821 return GetFoodStage().IsFoodBurned();
1822
1823 return false;
1824 }
1825
1826 bool IsFoodRotten()
1827 {
1828 if (GetFoodStage())
1829 return GetFoodStage().IsFoodRotten();
1830
1831 return false;
1832 }
1833
1834 //food stage change
1836 {
1837 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1838 }
1839
1841 {
1842 return GetFoodStage().GetNextFoodStageType(cooking_method);
1843 }
1844
1846 {
1847 return GetFoodStage().GetFoodStageName(food_stage_type);
1848 }
1849
1851 {
1852 return GetFoodStage().CanChangeToNewStage(cooking_method);
1853 }
1854
1855 //Use this to receive food stage from another Edible_Base
1857 {
1858 if (!source.HasFoodStage())
1859 return;
1860 m_LastDecayStage = source.GetLastDecayStage();
1861 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1862 m_DecayTimer = source.GetDecayTimer();
1863 m_DecayDelta = source.GetDecayDelta();
1864 }
1865
1866 //================================================================
1867 // COOKING
1868 //================================================================
1869 //cooking time
1870 float GetCookingTime()
1871 {
1872 return GetFoodStage().GetCookingTime();
1873 }
1874
1875 void SetCookingTime(float time)
1876 {
1877 GetFoodStage().SetCookingTime(time);
1878
1879 //synchronize when calling on server
1880 Synchronize();
1881 }
1882
1883 //replace edible with new item (opening cans)
1884 void ReplaceEdibleWithNew(string typeName)
1885 {
1886 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1887 if (player)
1888 {
1890 player.ServerReplaceItemInHandsWithNew(lambda);
1891 }
1892 else
1893 Error("ReplaceEdibleWithNew - cannot use edible without player");
1894 }
1895
1896 override void SetActions()
1897 {
1898 super.SetActions();
1899
1900 AddAction(ActionAttach);
1902 }
1903
1904 protected void SoundCookingStart(string sound_name)
1905 {
1906#ifndef SERVER
1908 {
1910
1913 }
1914#endif
1915 }
1916
1917 protected void SoundCookingStop()
1918 {
1919#ifndef SERVER
1921 {
1924 m_SoundPlaying = "";
1925 }
1926#endif
1927 }
1928
1929 override bool CanHaveTemperature()
1930 {
1931 return true;
1932 }
1933
1934 override bool CanDecay()
1935 {
1936 return false;
1937 }
1938
1939 override bool CanProcessDecay()
1940 {
1941 return (GetFoodStageType() != FoodStageType.ROTTEN);
1942 }
1943
1944 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1945 {
1946 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1947 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1948 if (hasRootAsPlayer)
1950
1951 /*Print( "-------------------------" );
1952 Print( this );
1953 Print( m_DecayTimer );
1954 Print( m_DecayDelta );
1955 Print( m_LastDecayStage );*/
1956
1957 if (IsFruit() || IsMushroom())
1958 {
1959 // fruit, vegetables and mushrooms
1961 {
1962 switch (GetFoodStageType())
1963 {
1964 case FoodStageType.RAW:
1967 break;
1968
1969 case FoodStageType.BOILED:
1972 break;
1973
1974 case FoodStageType.BAKED:
1977 break;
1978
1979 case FoodStageType.DRIED:
1980 case FoodStageType.BURNED:
1981 case FoodStageType.ROTTEN:
1982 default:
1983 m_DecayTimer = -1;
1985 return;
1986 }
1987
1988 //m_DecayTimer = m_DecayTimer / 1000.0;
1989 }
1990
1992
1993 if (m_DecayTimer <= 0)
1994 {
1995 if (m_LastDecayStage != FoodStageType.NONE)
1996 {
1997 // switch to decayed stage
1998 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
2001 {
2002 int rng = Math.RandomIntInclusive(0, 100);
2005 else
2006 {
2009 else
2011 }
2012 }
2013 }
2014 }
2015
2016 }
2017 else if (IsMeat())
2018 {
2019 // meat
2021 {
2022 switch (GetFoodStageType())
2023 {
2024 case FoodStageType.RAW:
2027 break;
2028
2029 case FoodStageType.BOILED:
2032 break;
2033
2034 case FoodStageType.BAKED:
2037 break;
2038
2039 case FoodStageType.DRIED:
2042 break;
2043
2044 case FoodStageType.BURNED:
2045 case FoodStageType.ROTTEN:
2046 default:
2047 m_DecayTimer = -1;
2049 return;
2050 }
2051 }
2052
2054
2055 if (m_DecayTimer <= 0)
2056 {
2057 if (m_LastDecayStage != FoodStageType.NONE)
2058 {
2059 // switch to decayed stage
2062 }
2063 }
2064 }
2065 else if (IsCorpse())
2066 {
2067 // corpse
2069 {
2070 switch (GetFoodStageType())
2071 {
2072 case FoodStageType.RAW:
2075 break;
2076
2077 case FoodStageType.BURNED:
2078 case FoodStageType.ROTTEN:
2079 default:
2080 m_DecayTimer = -1;
2082 return;
2083 }
2084 }
2085
2087
2088 if (m_DecayTimer <= 0)
2089 {
2090 if (m_LastDecayStage != FoodStageType.NONE)
2091 {
2092 // switch to decayed stage
2095 }
2096 }
2097 }
2098 else
2099 {
2100 // opened cans
2102
2103 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
2104 {
2107 //m_DecayTimer = m_DecayTimer / 1000.0;
2108 }
2109 else
2110 {
2111 if (m_DecayTimer <= 0)
2112 {
2113 InsertAgent(eAgents.FOOD_POISON, 1);
2114 m_DecayTimer = -1;
2115 }
2116 }
2117 }
2118
2119 m_DecayDelta = 0.0;
2120 }
2121
2123 {
2124 super.GetDebugActions(outputList);
2125
2126 if (HasFoodStage())
2127 {
2128 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
2129 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
2130 }
2131 }
2132
2133 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
2134 {
2135 super.OnAction(action_id, player, ctx);
2136
2137 if (GetGame().IsServer())
2138 {
2139 if (action_id == EActions.FOOD_STAGE_PREV)
2140 {
2142 if (food_stage_prev <= 0)
2143 food_stage_prev = FoodStageType.COUNT - 1;
2145 return true;
2146 }
2147 else if (action_id == EActions.FOOD_STAGE_NEXT)
2148 {
2150 if (food_stage_next >= FoodStageType.COUNT)
2153 return true;
2154 }
2155 }
2156 return false;
2157 }
2158
2159 override string GetDebugText()
2160 {
2161 string debug_output;
2162
2163 debug_output = super.GetDebugText();
2164
2165 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
2166 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
2167
2168 return debug_output;
2169 }
2170
2171 //================================================================
2172 // GENERAL GETTERS
2173 //================================================================
2174
2175 float GetDecayTimer()
2176 {
2177 return m_DecayTimer;
2178 }
2179
2180 float GetDecayDelta()
2181 {
2182 return m_DecayDelta;
2183 }
2184
2186 {
2187 return m_LastDecayStage;
2188 }
2189}
2190
2192{
2194};

◆ OnConsume()

void ReplaceEdibleWithNewLambda::OnConsume ( float amount,
PlayerBase consumer )
private

◆ OnStoreLoad()

override bool ReplaceEdibleWithNewLambda::OnStoreLoad ( ParamsReadContext ctx,
int version )
protected

Definition at line 936 of file Edible_Base.c.

936 : ItemBase
937{
938 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
939
940 const string SOUND_BAKING_START = "Baking_SoundSet";
941 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
942 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
943
944 protected bool m_MakeCookingSounds;
947 protected string m_SoundPlaying;
949 protected float m_DecayTimer;
950 protected float m_DecayDelta = 0.0;
952
954
955 void Edible_Base()
956 {
957 if (HasFoodStage())
958 {
959 m_FoodStage = new FoodStage(this);
960
961 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
962 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
963 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
964 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
965 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
966
967 m_SoundPlaying = "";
969 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
970 RegisterNetSyncVariableBool("m_MakeCookingSounds");
971 }
972 }
973
974 override void EEInit()
975 {
976 super.EEInit();
977
979 }
980
981 override void EEDelete(EntityAI parent)
982 {
983 super.EEDelete(parent);
984
985 RemoveAudio();
986 }
987
989 {
990 super.EEItemLocationChanged(oldLoc, newLoc);
991
993 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
994 {
995 switch (oldLoc.GetParent().GetType())
996 {
997 case "FryingPan":
998 case "Pot":
999 case "Cauldron":
1000 case "SharpWoodenStick":
1001 MakeSoundsOnClient(false);
1002 break;
1003 }
1004
1006 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1007 MakeSoundsOnClient(false);
1008 }
1009 }
1010
1011 void UpdateVisuals()
1012 {
1013 if (GetFoodStage())
1014 GetFoodStage().UpdateVisuals();
1015 }
1016
1017 bool Consume(float amount, PlayerBase consumer)
1018 {
1019 AddQuantity(-amount, false, false);
1020 OnConsume(amount, consumer);
1021
1022 return true;
1023 }
1024
1025 void OnConsume(float amount, PlayerBase consumer);
1026
1027 //food staging
1028 override bool CanBeCooked()
1029 {
1030 return false;
1031 }
1032
1033 override bool CanBeCookedOnStick()
1034 {
1035 return false;
1036 }
1037
1038 //================================================================
1039 // SYNCHRONIZATION
1040 //================================================================
1041 void Synchronize()
1042 {
1043 SetSynchDirty();
1044
1045 if (GetGame().IsMultiplayer())
1046 UpdateVisuals();
1047 }
1048
1049 override void OnVariablesSynchronized()
1050 {
1051 super.OnVariablesSynchronized();
1052
1053 UpdateVisuals();
1054
1055 //update audio
1057 RefreshAudio();
1058 else
1059 RemoveAudio();
1060 }
1061
1062 //================================================================
1063 // AUDIO EFFECTS (WHEN ON DCS)
1064 //================================================================
1066 {
1069
1070 Synchronize();
1071 }
1072
1073 protected void RefreshAudio()
1074 {
1075 string soundName = "";
1076
1078
1079 switch (GetFoodStageType())
1080 {
1081 case FoodStageType.RAW:
1083 if (nextFoodState == FoodStageType.BOILED)
1084 soundName = "";
1085 break;
1086 case FoodStageType.BAKED:
1088 break;
1089 case FoodStageType.BURNED:
1091 break;
1092 default:
1093 soundName = "";
1094 break;
1095 }
1096
1098 }
1099
1100 protected void RemoveAudio()
1101 {
1102 m_MakeCookingSounds = false;
1104 }
1105
1106 //================================================================
1107 // SERIALIZATION
1108 //================================================================
1109 override void OnStoreSave(ParamsWriteContext ctx)
1110 {
1111 super.OnStoreSave(ctx);
1112
1113 if (GetFoodStage())
1114 GetFoodStage().OnStoreSave(ctx);
1115
1116 // food decay
1117 ctx.Write(m_DecayTimer);
1118 ctx.Write(m_LastDecayStage);
1119 }
1120
1121 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1122 {
1123 if (!super.OnStoreLoad(ctx, version))
1124 return false;
1125
1126 if (GetFoodStage())
1127 {
1128 if (!GetFoodStage().OnStoreLoad(ctx, version))
1129 return false;
1130 }
1131
1132 if (version >= 115)
1133 {
1134 if (!ctx.Read(m_DecayTimer))
1135 {
1136 m_DecayTimer = 0.0;
1137 return false;
1138 }
1139 if (!ctx.Read(m_LastDecayStage))
1140 {
1142 return false;
1143 }
1144 }
1145
1146 return true;
1147 }
1148
1149 override void AfterStoreLoad()
1150 {
1151 super.AfterStoreLoad();
1152
1153 Synchronize();
1154 }
1155
1156 //get food stage
1158 {
1159 return m_FoodStage;
1160 }
1161
1162 //food types
1163 override bool IsMeat()
1164 {
1165 return false;
1166 }
1167
1168 override bool IsCorpse()
1169 {
1170 return false;
1171 }
1172
1173 override bool IsFruit()
1174 {
1175 return false;
1176 }
1177
1178 override bool IsMushroom()
1179 {
1180 return false;
1181 }
1182
1183 //================================================================
1184 // NUTRITIONAL VALUES
1185 //================================================================
1186 //food properties
1187 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1188 {
1190 if (food_item && food_item.GetFoodStage())
1191 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1192 else if (classname != "" && food_stage)
1193 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1194 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1195 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1196
1197 }
1198
1199 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1200 {
1202 if (food_item && food_item.GetFoodStage())
1203 return FoodStage.GetEnergy(food_item.GetFoodStage());
1204 else if (classname != "" && food_stage)
1205 return FoodStage.GetEnergy(null, food_stage, classname);
1206 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1207 return GetGame().ConfigGetFloat(class_path + " energy");
1208 }
1209
1210 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1211 {
1213 if (food_item && food_item.GetFoodStage())
1214 return FoodStage.GetWater(food_item.GetFoodStage());
1215 else if (classname != "" && food_stage)
1216 return FoodStage.GetWater(null, food_stage, classname);
1217 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1218 return GetGame().ConfigGetFloat(class_path + " water");
1219 }
1220
1221 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1222 {
1224 if (food_item && food_item.GetFoodStage())
1225 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1226 else if (classname != "" && food_stage)
1227 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1228 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1229 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1230
1231 }
1232
1233 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1234 {
1236 if (food_item && food_item.GetFoodStage())
1237 return FoodStage.GetToxicity(food_item.GetFoodStage());
1238 else if (classname != "" && food_stage)
1239 return FoodStage.GetToxicity(null, food_stage, classname);
1240 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1241 return GetGame().ConfigGetFloat(class_path + " toxicity");
1242 }
1243
1244 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1245 {
1247 if (food_item && food_item.GetFoodStage())
1248 return FoodStage.GetAgents(food_item.GetFoodStage());
1249 else if (classname != "" && food_stage)
1250 return FoodStage.GetAgents(null, food_stage, classname);
1251 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1252 return GetGame().ConfigGetInt(class_path + " agents");
1253 }
1254
1255 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1256 {
1258 if (food_item && food_item.GetFoodStage())
1259 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1260 else if (classname != "" && food_stage)
1261 return FoodStage.GetDigestibility(null, food_stage, classname);
1262 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1263 return GetGame().ConfigGetInt(class_path + " digestibility");
1264 }
1265
1267 {
1269 }
1270
1271 //================================================================
1272 // FOOD STAGING
1273 //================================================================
1275 {
1276 return GetFoodStage().GetFoodStageType();
1277 }
1278
1279 //food stage states
1280 bool IsFoodRaw()
1281 {
1282 if (GetFoodStage())
1283 return GetFoodStage().IsFoodRaw();
1284
1285 return false;
1286 }
1287
1288 bool IsFoodBaked()
1289 {
1290 if (GetFoodStage())
1291 return GetFoodStage().IsFoodBaked();
1292
1293 return false;
1294 }
1295
1296 bool IsFoodBoiled()
1297 {
1298 if (GetFoodStage())
1299 return GetFoodStage().IsFoodBoiled();
1300
1301 return false;
1302 }
1303
1304 bool IsFoodDried()
1305 {
1306 if (GetFoodStage())
1307 return GetFoodStage().IsFoodDried();
1308
1309 return false;
1310 }
1311
1312 bool IsFoodBurned()
1313 {
1314 if (GetFoodStage())
1315 return GetFoodStage().IsFoodBurned();
1316
1317 return false;
1318 }
1319
1320 bool IsFoodRotten()
1321 {
1322 if (GetFoodStage())
1323 return GetFoodStage().IsFoodRotten();
1324
1325 return false;
1326 }
1327
1328 //food stage change
1330 {
1331 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1332 }
1333
1335 {
1336 return GetFoodStage().GetNextFoodStageType(cooking_method);
1337 }
1338
1340 {
1341 return GetFoodStage().GetFoodStageName(food_stage_type);
1342 }
1343
1345 {
1346 return GetFoodStage().CanChangeToNewStage(cooking_method);
1347 }
1348
1349 //Use this to receive food stage from another Edible_Base
1351 {
1352 if (!source.HasFoodStage())
1353 return;
1354 m_LastDecayStage = source.GetLastDecayStage();
1355 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1356 m_DecayTimer = source.GetDecayTimer();
1357 m_DecayDelta = source.GetDecayDelta();
1358 }
1359
1360 //================================================================
1361 // COOKING
1362 //================================================================
1363 //cooking time
1364 float GetCookingTime()
1365 {
1366 return GetFoodStage().GetCookingTime();
1367 }
1368
1369 void SetCookingTime(float time)
1370 {
1371 GetFoodStage().SetCookingTime(time);
1372
1373 //synchronize when calling on server
1374 Synchronize();
1375 }
1376
1377 //replace edible with new item (opening cans)
1378 void ReplaceEdibleWithNew(string typeName)
1379 {
1380 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1381 if (player)
1382 {
1384 player.ServerReplaceItemInHandsWithNew(lambda);
1385 }
1386 else
1387 Error("ReplaceEdibleWithNew - cannot use edible without player");
1388 }
1389
1390 override void SetActions()
1391 {
1392 super.SetActions();
1393
1394 AddAction(ActionAttach);
1396 }
1397
1398 protected void SoundCookingStart(string sound_name)
1399 {
1400#ifndef SERVER
1402 {
1404
1407 }
1408#endif
1409 }
1410
1411 protected void SoundCookingStop()
1412 {
1413#ifndef SERVER
1415 {
1418 m_SoundPlaying = "";
1419 }
1420#endif
1421 }
1422
1423 override bool CanHaveTemperature()
1424 {
1425 return true;
1426 }
1427
1428 override bool CanDecay()
1429 {
1430 return false;
1431 }
1432
1433 override bool CanProcessDecay()
1434 {
1435 return (GetFoodStageType() != FoodStageType.ROTTEN);
1436 }
1437
1438 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1439 {
1440 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1441 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1442 if (hasRootAsPlayer)
1444
1445 /*Print( "-------------------------" );
1446 Print( this );
1447 Print( m_DecayTimer );
1448 Print( m_DecayDelta );
1449 Print( m_LastDecayStage );*/
1450
1451 if (IsFruit() || IsMushroom())
1452 {
1453 // fruit, vegetables and mushrooms
1455 {
1456 switch (GetFoodStageType())
1457 {
1458 case FoodStageType.RAW:
1461 break;
1462
1463 case FoodStageType.BOILED:
1466 break;
1467
1468 case FoodStageType.BAKED:
1471 break;
1472
1473 case FoodStageType.DRIED:
1474 case FoodStageType.BURNED:
1475 case FoodStageType.ROTTEN:
1476 default:
1477 m_DecayTimer = -1;
1479 return;
1480 }
1481
1482 //m_DecayTimer = m_DecayTimer / 1000.0;
1483 }
1484
1486
1487 if (m_DecayTimer <= 0)
1488 {
1489 if (m_LastDecayStage != FoodStageType.NONE)
1490 {
1491 // switch to decayed stage
1492 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1495 {
1496 int rng = Math.RandomIntInclusive(0, 100);
1499 else
1500 {
1503 else
1505 }
1506 }
1507 }
1508 }
1509
1510 }
1511 else if (IsMeat())
1512 {
1513 // meat
1515 {
1516 switch (GetFoodStageType())
1517 {
1518 case FoodStageType.RAW:
1521 break;
1522
1523 case FoodStageType.BOILED:
1526 break;
1527
1528 case FoodStageType.BAKED:
1531 break;
1532
1533 case FoodStageType.DRIED:
1536 break;
1537
1538 case FoodStageType.BURNED:
1539 case FoodStageType.ROTTEN:
1540 default:
1541 m_DecayTimer = -1;
1543 return;
1544 }
1545 }
1546
1548
1549 if (m_DecayTimer <= 0)
1550 {
1551 if (m_LastDecayStage != FoodStageType.NONE)
1552 {
1553 // switch to decayed stage
1556 }
1557 }
1558 }
1559 else if (IsCorpse())
1560 {
1561 // corpse
1563 {
1564 switch (GetFoodStageType())
1565 {
1566 case FoodStageType.RAW:
1569 break;
1570
1571 case FoodStageType.BURNED:
1572 case FoodStageType.ROTTEN:
1573 default:
1574 m_DecayTimer = -1;
1576 return;
1577 }
1578 }
1579
1581
1582 if (m_DecayTimer <= 0)
1583 {
1584 if (m_LastDecayStage != FoodStageType.NONE)
1585 {
1586 // switch to decayed stage
1589 }
1590 }
1591 }
1592 else
1593 {
1594 // opened cans
1596
1597 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1598 {
1601 //m_DecayTimer = m_DecayTimer / 1000.0;
1602 }
1603 else
1604 {
1605 if (m_DecayTimer <= 0)
1606 {
1607 InsertAgent(eAgents.FOOD_POISON, 1);
1608 m_DecayTimer = -1;
1609 }
1610 }
1611 }
1612
1613 m_DecayDelta = 0.0;
1614 }
1615
1617 {
1618 super.GetDebugActions(outputList);
1619
1620 if (HasFoodStage())
1621 {
1622 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1623 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1624 }
1625 }
1626
1627 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1628 {
1629 super.OnAction(action_id, player, ctx);
1630
1631 if (GetGame().IsServer())
1632 {
1633 if (action_id == EActions.FOOD_STAGE_PREV)
1634 {
1636 if (food_stage_prev <= 0)
1637 food_stage_prev = FoodStageType.COUNT - 1;
1639 return true;
1640 }
1641 else if (action_id == EActions.FOOD_STAGE_NEXT)
1642 {
1644 if (food_stage_next >= FoodStageType.COUNT)
1647 return true;
1648 }
1649 }
1650 return false;
1651 }
1652
1653 override string GetDebugText()
1654 {
1655 string debug_output;
1656
1657 debug_output = super.GetDebugText();
1658
1659 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1660 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1661
1662 return debug_output;
1663 }
1664
1665 //================================================================
1666 // GENERAL GETTERS
1667 //================================================================
1668
1669 float GetDecayTimer()
1670 {
1671 return m_DecayTimer;
1672 }
1673
1674 float GetDecayDelta()
1675 {
1676 return m_DecayDelta;
1677 }
1678
1680 {
1681 return m_LastDecayStage;
1682 }
1683}
1684
1686{
1688};

◆ OnStoreSave()

override void ReplaceEdibleWithNewLambda::OnStoreSave ( ParamsWriteContext ctx)
protected

Definition at line 924 of file Edible_Base.c.

924 : ItemBase
925{
926 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
927
928 const string SOUND_BAKING_START = "Baking_SoundSet";
929 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
930 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
931
932 protected bool m_MakeCookingSounds;
935 protected string m_SoundPlaying;
937 protected float m_DecayTimer;
938 protected float m_DecayDelta = 0.0;
940
942
943 void Edible_Base()
944 {
945 if (HasFoodStage())
946 {
947 m_FoodStage = new FoodStage(this);
948
949 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
950 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
951 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
952 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
953 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
954
955 m_SoundPlaying = "";
957 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
958 RegisterNetSyncVariableBool("m_MakeCookingSounds");
959 }
960 }
961
962 override void EEInit()
963 {
964 super.EEInit();
965
967 }
968
969 override void EEDelete(EntityAI parent)
970 {
971 super.EEDelete(parent);
972
973 RemoveAudio();
974 }
975
977 {
978 super.EEItemLocationChanged(oldLoc, newLoc);
979
981 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
982 {
983 switch (oldLoc.GetParent().GetType())
984 {
985 case "FryingPan":
986 case "Pot":
987 case "Cauldron":
988 case "SharpWoodenStick":
989 MakeSoundsOnClient(false);
990 break;
991 }
992
994 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
995 MakeSoundsOnClient(false);
996 }
997 }
998
999 void UpdateVisuals()
1000 {
1001 if (GetFoodStage())
1002 GetFoodStage().UpdateVisuals();
1003 }
1004
1005 bool Consume(float amount, PlayerBase consumer)
1006 {
1007 AddQuantity(-amount, false, false);
1008 OnConsume(amount, consumer);
1009
1010 return true;
1011 }
1012
1013 void OnConsume(float amount, PlayerBase consumer);
1014
1015 //food staging
1016 override bool CanBeCooked()
1017 {
1018 return false;
1019 }
1020
1021 override bool CanBeCookedOnStick()
1022 {
1023 return false;
1024 }
1025
1026 //================================================================
1027 // SYNCHRONIZATION
1028 //================================================================
1029 void Synchronize()
1030 {
1031 SetSynchDirty();
1032
1033 if (GetGame().IsMultiplayer())
1034 UpdateVisuals();
1035 }
1036
1037 override void OnVariablesSynchronized()
1038 {
1039 super.OnVariablesSynchronized();
1040
1041 UpdateVisuals();
1042
1043 //update audio
1045 RefreshAudio();
1046 else
1047 RemoveAudio();
1048 }
1049
1050 //================================================================
1051 // AUDIO EFFECTS (WHEN ON DCS)
1052 //================================================================
1054 {
1057
1058 Synchronize();
1059 }
1060
1061 protected void RefreshAudio()
1062 {
1063 string soundName = "";
1064
1066
1067 switch (GetFoodStageType())
1068 {
1069 case FoodStageType.RAW:
1071 if (nextFoodState == FoodStageType.BOILED)
1072 soundName = "";
1073 break;
1074 case FoodStageType.BAKED:
1076 break;
1077 case FoodStageType.BURNED:
1079 break;
1080 default:
1081 soundName = "";
1082 break;
1083 }
1084
1086 }
1087
1088 protected void RemoveAudio()
1089 {
1090 m_MakeCookingSounds = false;
1092 }
1093
1094 //================================================================
1095 // SERIALIZATION
1096 //================================================================
1097 override void OnStoreSave(ParamsWriteContext ctx)
1098 {
1099 super.OnStoreSave(ctx);
1100
1101 if (GetFoodStage())
1102 GetFoodStage().OnStoreSave(ctx);
1103
1104 // food decay
1105 ctx.Write(m_DecayTimer);
1106 ctx.Write(m_LastDecayStage);
1107 }
1108
1109 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1110 {
1111 if (!super.OnStoreLoad(ctx, version))
1112 return false;
1113
1114 if (GetFoodStage())
1115 {
1116 if (!GetFoodStage().OnStoreLoad(ctx, version))
1117 return false;
1118 }
1119
1120 if (version >= 115)
1121 {
1122 if (!ctx.Read(m_DecayTimer))
1123 {
1124 m_DecayTimer = 0.0;
1125 return false;
1126 }
1127 if (!ctx.Read(m_LastDecayStage))
1128 {
1130 return false;
1131 }
1132 }
1133
1134 return true;
1135 }
1136
1137 override void AfterStoreLoad()
1138 {
1139 super.AfterStoreLoad();
1140
1141 Synchronize();
1142 }
1143
1144 //get food stage
1146 {
1147 return m_FoodStage;
1148 }
1149
1150 //food types
1151 override bool IsMeat()
1152 {
1153 return false;
1154 }
1155
1156 override bool IsCorpse()
1157 {
1158 return false;
1159 }
1160
1161 override bool IsFruit()
1162 {
1163 return false;
1164 }
1165
1166 override bool IsMushroom()
1167 {
1168 return false;
1169 }
1170
1171 //================================================================
1172 // NUTRITIONAL VALUES
1173 //================================================================
1174 //food properties
1175 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1176 {
1178 if (food_item && food_item.GetFoodStage())
1179 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1180 else if (classname != "" && food_stage)
1181 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1182 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1183 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1184
1185 }
1186
1187 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1188 {
1190 if (food_item && food_item.GetFoodStage())
1191 return FoodStage.GetEnergy(food_item.GetFoodStage());
1192 else if (classname != "" && food_stage)
1193 return FoodStage.GetEnergy(null, food_stage, classname);
1194 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1195 return GetGame().ConfigGetFloat(class_path + " energy");
1196 }
1197
1198 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1199 {
1201 if (food_item && food_item.GetFoodStage())
1202 return FoodStage.GetWater(food_item.GetFoodStage());
1203 else if (classname != "" && food_stage)
1204 return FoodStage.GetWater(null, food_stage, classname);
1205 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1206 return GetGame().ConfigGetFloat(class_path + " water");
1207 }
1208
1209 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1210 {
1212 if (food_item && food_item.GetFoodStage())
1213 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1214 else if (classname != "" && food_stage)
1215 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1216 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1217 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1218
1219 }
1220
1221 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1222 {
1224 if (food_item && food_item.GetFoodStage())
1225 return FoodStage.GetToxicity(food_item.GetFoodStage());
1226 else if (classname != "" && food_stage)
1227 return FoodStage.GetToxicity(null, food_stage, classname);
1228 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1229 return GetGame().ConfigGetFloat(class_path + " toxicity");
1230 }
1231
1232 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1233 {
1235 if (food_item && food_item.GetFoodStage())
1236 return FoodStage.GetAgents(food_item.GetFoodStage());
1237 else if (classname != "" && food_stage)
1238 return FoodStage.GetAgents(null, food_stage, classname);
1239 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1240 return GetGame().ConfigGetInt(class_path + " agents");
1241 }
1242
1243 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1244 {
1246 if (food_item && food_item.GetFoodStage())
1247 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1248 else if (classname != "" && food_stage)
1249 return FoodStage.GetDigestibility(null, food_stage, classname);
1250 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1251 return GetGame().ConfigGetInt(class_path + " digestibility");
1252 }
1253
1255 {
1257 }
1258
1259 //================================================================
1260 // FOOD STAGING
1261 //================================================================
1263 {
1264 return GetFoodStage().GetFoodStageType();
1265 }
1266
1267 //food stage states
1268 bool IsFoodRaw()
1269 {
1270 if (GetFoodStage())
1271 return GetFoodStage().IsFoodRaw();
1272
1273 return false;
1274 }
1275
1276 bool IsFoodBaked()
1277 {
1278 if (GetFoodStage())
1279 return GetFoodStage().IsFoodBaked();
1280
1281 return false;
1282 }
1283
1284 bool IsFoodBoiled()
1285 {
1286 if (GetFoodStage())
1287 return GetFoodStage().IsFoodBoiled();
1288
1289 return false;
1290 }
1291
1292 bool IsFoodDried()
1293 {
1294 if (GetFoodStage())
1295 return GetFoodStage().IsFoodDried();
1296
1297 return false;
1298 }
1299
1300 bool IsFoodBurned()
1301 {
1302 if (GetFoodStage())
1303 return GetFoodStage().IsFoodBurned();
1304
1305 return false;
1306 }
1307
1308 bool IsFoodRotten()
1309 {
1310 if (GetFoodStage())
1311 return GetFoodStage().IsFoodRotten();
1312
1313 return false;
1314 }
1315
1316 //food stage change
1318 {
1319 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1320 }
1321
1323 {
1324 return GetFoodStage().GetNextFoodStageType(cooking_method);
1325 }
1326
1328 {
1329 return GetFoodStage().GetFoodStageName(food_stage_type);
1330 }
1331
1333 {
1334 return GetFoodStage().CanChangeToNewStage(cooking_method);
1335 }
1336
1337 //Use this to receive food stage from another Edible_Base
1339 {
1340 if (!source.HasFoodStage())
1341 return;
1342 m_LastDecayStage = source.GetLastDecayStage();
1343 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1344 m_DecayTimer = source.GetDecayTimer();
1345 m_DecayDelta = source.GetDecayDelta();
1346 }
1347
1348 //================================================================
1349 // COOKING
1350 //================================================================
1351 //cooking time
1352 float GetCookingTime()
1353 {
1354 return GetFoodStage().GetCookingTime();
1355 }
1356
1357 void SetCookingTime(float time)
1358 {
1359 GetFoodStage().SetCookingTime(time);
1360
1361 //synchronize when calling on server
1362 Synchronize();
1363 }
1364
1365 //replace edible with new item (opening cans)
1366 void ReplaceEdibleWithNew(string typeName)
1367 {
1368 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1369 if (player)
1370 {
1372 player.ServerReplaceItemInHandsWithNew(lambda);
1373 }
1374 else
1375 Error("ReplaceEdibleWithNew - cannot use edible without player");
1376 }
1377
1378 override void SetActions()
1379 {
1380 super.SetActions();
1381
1382 AddAction(ActionAttach);
1384 }
1385
1386 protected void SoundCookingStart(string sound_name)
1387 {
1388#ifndef SERVER
1390 {
1392
1395 }
1396#endif
1397 }
1398
1399 protected void SoundCookingStop()
1400 {
1401#ifndef SERVER
1403 {
1406 m_SoundPlaying = "";
1407 }
1408#endif
1409 }
1410
1411 override bool CanHaveTemperature()
1412 {
1413 return true;
1414 }
1415
1416 override bool CanDecay()
1417 {
1418 return false;
1419 }
1420
1421 override bool CanProcessDecay()
1422 {
1423 return (GetFoodStageType() != FoodStageType.ROTTEN);
1424 }
1425
1426 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1427 {
1428 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1429 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1430 if (hasRootAsPlayer)
1432
1433 /*Print( "-------------------------" );
1434 Print( this );
1435 Print( m_DecayTimer );
1436 Print( m_DecayDelta );
1437 Print( m_LastDecayStage );*/
1438
1439 if (IsFruit() || IsMushroom())
1440 {
1441 // fruit, vegetables and mushrooms
1443 {
1444 switch (GetFoodStageType())
1445 {
1446 case FoodStageType.RAW:
1449 break;
1450
1451 case FoodStageType.BOILED:
1454 break;
1455
1456 case FoodStageType.BAKED:
1459 break;
1460
1461 case FoodStageType.DRIED:
1462 case FoodStageType.BURNED:
1463 case FoodStageType.ROTTEN:
1464 default:
1465 m_DecayTimer = -1;
1467 return;
1468 }
1469
1470 //m_DecayTimer = m_DecayTimer / 1000.0;
1471 }
1472
1474
1475 if (m_DecayTimer <= 0)
1476 {
1477 if (m_LastDecayStage != FoodStageType.NONE)
1478 {
1479 // switch to decayed stage
1480 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1483 {
1484 int rng = Math.RandomIntInclusive(0, 100);
1487 else
1488 {
1491 else
1493 }
1494 }
1495 }
1496 }
1497
1498 }
1499 else if (IsMeat())
1500 {
1501 // meat
1503 {
1504 switch (GetFoodStageType())
1505 {
1506 case FoodStageType.RAW:
1509 break;
1510
1511 case FoodStageType.BOILED:
1514 break;
1515
1516 case FoodStageType.BAKED:
1519 break;
1520
1521 case FoodStageType.DRIED:
1524 break;
1525
1526 case FoodStageType.BURNED:
1527 case FoodStageType.ROTTEN:
1528 default:
1529 m_DecayTimer = -1;
1531 return;
1532 }
1533 }
1534
1536
1537 if (m_DecayTimer <= 0)
1538 {
1539 if (m_LastDecayStage != FoodStageType.NONE)
1540 {
1541 // switch to decayed stage
1544 }
1545 }
1546 }
1547 else if (IsCorpse())
1548 {
1549 // corpse
1551 {
1552 switch (GetFoodStageType())
1553 {
1554 case FoodStageType.RAW:
1557 break;
1558
1559 case FoodStageType.BURNED:
1560 case FoodStageType.ROTTEN:
1561 default:
1562 m_DecayTimer = -1;
1564 return;
1565 }
1566 }
1567
1569
1570 if (m_DecayTimer <= 0)
1571 {
1572 if (m_LastDecayStage != FoodStageType.NONE)
1573 {
1574 // switch to decayed stage
1577 }
1578 }
1579 }
1580 else
1581 {
1582 // opened cans
1584
1585 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1586 {
1589 //m_DecayTimer = m_DecayTimer / 1000.0;
1590 }
1591 else
1592 {
1593 if (m_DecayTimer <= 0)
1594 {
1595 InsertAgent(eAgents.FOOD_POISON, 1);
1596 m_DecayTimer = -1;
1597 }
1598 }
1599 }
1600
1601 m_DecayDelta = 0.0;
1602 }
1603
1605 {
1606 super.GetDebugActions(outputList);
1607
1608 if (HasFoodStage())
1609 {
1610 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1611 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1612 }
1613 }
1614
1615 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1616 {
1617 super.OnAction(action_id, player, ctx);
1618
1619 if (GetGame().IsServer())
1620 {
1621 if (action_id == EActions.FOOD_STAGE_PREV)
1622 {
1624 if (food_stage_prev <= 0)
1625 food_stage_prev = FoodStageType.COUNT - 1;
1627 return true;
1628 }
1629 else if (action_id == EActions.FOOD_STAGE_NEXT)
1630 {
1632 if (food_stage_next >= FoodStageType.COUNT)
1635 return true;
1636 }
1637 }
1638 return false;
1639 }
1640
1641 override string GetDebugText()
1642 {
1643 string debug_output;
1644
1645 debug_output = super.GetDebugText();
1646
1647 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1648 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1649
1650 return debug_output;
1651 }
1652
1653 //================================================================
1654 // GENERAL GETTERS
1655 //================================================================
1656
1657 float GetDecayTimer()
1658 {
1659 return m_DecayTimer;
1660 }
1661
1662 float GetDecayDelta()
1663 {
1664 return m_DecayDelta;
1665 }
1666
1668 {
1669 return m_LastDecayStage;
1670 }
1671}
1672
1674{
1676};

◆ OnVariablesSynchronized()

override void ReplaceEdibleWithNewLambda::OnVariablesSynchronized ( )
private

Definition at line 864 of file Edible_Base.c.

864 : ItemBase
865{
866 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
867
868 const string SOUND_BAKING_START = "Baking_SoundSet";
869 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
870 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
871
872 protected bool m_MakeCookingSounds;
875 protected string m_SoundPlaying;
877 protected float m_DecayTimer;
878 protected float m_DecayDelta = 0.0;
880
882
883 void Edible_Base()
884 {
885 if (HasFoodStage())
886 {
887 m_FoodStage = new FoodStage(this);
888
889 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
890 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
891 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
892 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
893 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
894
895 m_SoundPlaying = "";
897 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
898 RegisterNetSyncVariableBool("m_MakeCookingSounds");
899 }
900 }
901
902 override void EEInit()
903 {
904 super.EEInit();
905
907 }
908
909 override void EEDelete(EntityAI parent)
910 {
911 super.EEDelete(parent);
912
913 RemoveAudio();
914 }
915
917 {
918 super.EEItemLocationChanged(oldLoc, newLoc);
919
921 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
922 {
923 switch (oldLoc.GetParent().GetType())
924 {
925 case "FryingPan":
926 case "Pot":
927 case "Cauldron":
928 case "SharpWoodenStick":
929 MakeSoundsOnClient(false);
930 break;
931 }
932
934 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
935 MakeSoundsOnClient(false);
936 }
937 }
938
939 void UpdateVisuals()
940 {
941 if (GetFoodStage())
942 GetFoodStage().UpdateVisuals();
943 }
944
945 bool Consume(float amount, PlayerBase consumer)
946 {
947 AddQuantity(-amount, false, false);
948 OnConsume(amount, consumer);
949
950 return true;
951 }
952
953 void OnConsume(float amount, PlayerBase consumer);
954
955 //food staging
956 override bool CanBeCooked()
957 {
958 return false;
959 }
960
961 override bool CanBeCookedOnStick()
962 {
963 return false;
964 }
965
966 //================================================================
967 // SYNCHRONIZATION
968 //================================================================
969 void Synchronize()
970 {
971 SetSynchDirty();
972
973 if (GetGame().IsMultiplayer())
975 }
976
977 override void OnVariablesSynchronized()
978 {
979 super.OnVariablesSynchronized();
980
982
983 //update audio
985 RefreshAudio();
986 else
987 RemoveAudio();
988 }
989
990 //================================================================
991 // AUDIO EFFECTS (WHEN ON DCS)
992 //================================================================
994 {
997
998 Synchronize();
999 }
1000
1001 protected void RefreshAudio()
1002 {
1003 string soundName = "";
1004
1006
1007 switch (GetFoodStageType())
1008 {
1009 case FoodStageType.RAW:
1011 if (nextFoodState == FoodStageType.BOILED)
1012 soundName = "";
1013 break;
1014 case FoodStageType.BAKED:
1016 break;
1017 case FoodStageType.BURNED:
1019 break;
1020 default:
1021 soundName = "";
1022 break;
1023 }
1024
1026 }
1027
1028 protected void RemoveAudio()
1029 {
1030 m_MakeCookingSounds = false;
1032 }
1033
1034 //================================================================
1035 // SERIALIZATION
1036 //================================================================
1037 override void OnStoreSave(ParamsWriteContext ctx)
1038 {
1039 super.OnStoreSave(ctx);
1040
1041 if (GetFoodStage())
1042 GetFoodStage().OnStoreSave(ctx);
1043
1044 // food decay
1045 ctx.Write(m_DecayTimer);
1046 ctx.Write(m_LastDecayStage);
1047 }
1048
1049 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1050 {
1051 if (!super.OnStoreLoad(ctx, version))
1052 return false;
1053
1054 if (GetFoodStage())
1055 {
1056 if (!GetFoodStage().OnStoreLoad(ctx, version))
1057 return false;
1058 }
1059
1060 if (version >= 115)
1061 {
1062 if (!ctx.Read(m_DecayTimer))
1063 {
1064 m_DecayTimer = 0.0;
1065 return false;
1066 }
1067 if (!ctx.Read(m_LastDecayStage))
1068 {
1070 return false;
1071 }
1072 }
1073
1074 return true;
1075 }
1076
1077 override void AfterStoreLoad()
1078 {
1079 super.AfterStoreLoad();
1080
1081 Synchronize();
1082 }
1083
1084 //get food stage
1086 {
1087 return m_FoodStage;
1088 }
1089
1090 //food types
1091 override bool IsMeat()
1092 {
1093 return false;
1094 }
1095
1096 override bool IsCorpse()
1097 {
1098 return false;
1099 }
1100
1101 override bool IsFruit()
1102 {
1103 return false;
1104 }
1105
1106 override bool IsMushroom()
1107 {
1108 return false;
1109 }
1110
1111 //================================================================
1112 // NUTRITIONAL VALUES
1113 //================================================================
1114 //food properties
1115 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1116 {
1118 if (food_item && food_item.GetFoodStage())
1119 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1120 else if (classname != "" && food_stage)
1121 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1122 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1123 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1124
1125 }
1126
1127 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1128 {
1130 if (food_item && food_item.GetFoodStage())
1131 return FoodStage.GetEnergy(food_item.GetFoodStage());
1132 else if (classname != "" && food_stage)
1133 return FoodStage.GetEnergy(null, food_stage, classname);
1134 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1135 return GetGame().ConfigGetFloat(class_path + " energy");
1136 }
1137
1138 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1139 {
1141 if (food_item && food_item.GetFoodStage())
1142 return FoodStage.GetWater(food_item.GetFoodStage());
1143 else if (classname != "" && food_stage)
1144 return FoodStage.GetWater(null, food_stage, classname);
1145 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1146 return GetGame().ConfigGetFloat(class_path + " water");
1147 }
1148
1149 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1150 {
1152 if (food_item && food_item.GetFoodStage())
1153 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1154 else if (classname != "" && food_stage)
1155 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1156 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1157 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1158
1159 }
1160
1161 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1162 {
1164 if (food_item && food_item.GetFoodStage())
1165 return FoodStage.GetToxicity(food_item.GetFoodStage());
1166 else if (classname != "" && food_stage)
1167 return FoodStage.GetToxicity(null, food_stage, classname);
1168 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1169 return GetGame().ConfigGetFloat(class_path + " toxicity");
1170 }
1171
1172 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1173 {
1175 if (food_item && food_item.GetFoodStage())
1176 return FoodStage.GetAgents(food_item.GetFoodStage());
1177 else if (classname != "" && food_stage)
1178 return FoodStage.GetAgents(null, food_stage, classname);
1179 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1180 return GetGame().ConfigGetInt(class_path + " agents");
1181 }
1182
1183 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1184 {
1186 if (food_item && food_item.GetFoodStage())
1187 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1188 else if (classname != "" && food_stage)
1189 return FoodStage.GetDigestibility(null, food_stage, classname);
1190 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1191 return GetGame().ConfigGetInt(class_path + " digestibility");
1192 }
1193
1195 {
1197 }
1198
1199 //================================================================
1200 // FOOD STAGING
1201 //================================================================
1203 {
1204 return GetFoodStage().GetFoodStageType();
1205 }
1206
1207 //food stage states
1208 bool IsFoodRaw()
1209 {
1210 if (GetFoodStage())
1211 return GetFoodStage().IsFoodRaw();
1212
1213 return false;
1214 }
1215
1216 bool IsFoodBaked()
1217 {
1218 if (GetFoodStage())
1219 return GetFoodStage().IsFoodBaked();
1220
1221 return false;
1222 }
1223
1224 bool IsFoodBoiled()
1225 {
1226 if (GetFoodStage())
1227 return GetFoodStage().IsFoodBoiled();
1228
1229 return false;
1230 }
1231
1232 bool IsFoodDried()
1233 {
1234 if (GetFoodStage())
1235 return GetFoodStage().IsFoodDried();
1236
1237 return false;
1238 }
1239
1240 bool IsFoodBurned()
1241 {
1242 if (GetFoodStage())
1243 return GetFoodStage().IsFoodBurned();
1244
1245 return false;
1246 }
1247
1248 bool IsFoodRotten()
1249 {
1250 if (GetFoodStage())
1251 return GetFoodStage().IsFoodRotten();
1252
1253 return false;
1254 }
1255
1256 //food stage change
1258 {
1259 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1260 }
1261
1263 {
1264 return GetFoodStage().GetNextFoodStageType(cooking_method);
1265 }
1266
1268 {
1269 return GetFoodStage().GetFoodStageName(food_stage_type);
1270 }
1271
1273 {
1274 return GetFoodStage().CanChangeToNewStage(cooking_method);
1275 }
1276
1277 //Use this to receive food stage from another Edible_Base
1279 {
1280 if (!source.HasFoodStage())
1281 return;
1282 m_LastDecayStage = source.GetLastDecayStage();
1283 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1284 m_DecayTimer = source.GetDecayTimer();
1285 m_DecayDelta = source.GetDecayDelta();
1286 }
1287
1288 //================================================================
1289 // COOKING
1290 //================================================================
1291 //cooking time
1292 float GetCookingTime()
1293 {
1294 return GetFoodStage().GetCookingTime();
1295 }
1296
1297 void SetCookingTime(float time)
1298 {
1299 GetFoodStage().SetCookingTime(time);
1300
1301 //synchronize when calling on server
1302 Synchronize();
1303 }
1304
1305 //replace edible with new item (opening cans)
1306 void ReplaceEdibleWithNew(string typeName)
1307 {
1308 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1309 if (player)
1310 {
1312 player.ServerReplaceItemInHandsWithNew(lambda);
1313 }
1314 else
1315 Error("ReplaceEdibleWithNew - cannot use edible without player");
1316 }
1317
1318 override void SetActions()
1319 {
1320 super.SetActions();
1321
1322 AddAction(ActionAttach);
1324 }
1325
1326 protected void SoundCookingStart(string sound_name)
1327 {
1328#ifndef SERVER
1330 {
1332
1335 }
1336#endif
1337 }
1338
1339 protected void SoundCookingStop()
1340 {
1341#ifndef SERVER
1343 {
1346 m_SoundPlaying = "";
1347 }
1348#endif
1349 }
1350
1351 override bool CanHaveTemperature()
1352 {
1353 return true;
1354 }
1355
1356 override bool CanDecay()
1357 {
1358 return false;
1359 }
1360
1361 override bool CanProcessDecay()
1362 {
1363 return (GetFoodStageType() != FoodStageType.ROTTEN);
1364 }
1365
1366 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1367 {
1368 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1369 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1370 if (hasRootAsPlayer)
1372
1373 /*Print( "-------------------------" );
1374 Print( this );
1375 Print( m_DecayTimer );
1376 Print( m_DecayDelta );
1377 Print( m_LastDecayStage );*/
1378
1379 if (IsFruit() || IsMushroom())
1380 {
1381 // fruit, vegetables and mushrooms
1383 {
1384 switch (GetFoodStageType())
1385 {
1386 case FoodStageType.RAW:
1389 break;
1390
1391 case FoodStageType.BOILED:
1394 break;
1395
1396 case FoodStageType.BAKED:
1399 break;
1400
1401 case FoodStageType.DRIED:
1402 case FoodStageType.BURNED:
1403 case FoodStageType.ROTTEN:
1404 default:
1405 m_DecayTimer = -1;
1407 return;
1408 }
1409
1410 //m_DecayTimer = m_DecayTimer / 1000.0;
1411 }
1412
1414
1415 if (m_DecayTimer <= 0)
1416 {
1417 if (m_LastDecayStage != FoodStageType.NONE)
1418 {
1419 // switch to decayed stage
1420 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1423 {
1424 int rng = Math.RandomIntInclusive(0, 100);
1427 else
1428 {
1431 else
1433 }
1434 }
1435 }
1436 }
1437
1438 }
1439 else if (IsMeat())
1440 {
1441 // meat
1443 {
1444 switch (GetFoodStageType())
1445 {
1446 case FoodStageType.RAW:
1449 break;
1450
1451 case FoodStageType.BOILED:
1454 break;
1455
1456 case FoodStageType.BAKED:
1459 break;
1460
1461 case FoodStageType.DRIED:
1464 break;
1465
1466 case FoodStageType.BURNED:
1467 case FoodStageType.ROTTEN:
1468 default:
1469 m_DecayTimer = -1;
1471 return;
1472 }
1473 }
1474
1476
1477 if (m_DecayTimer <= 0)
1478 {
1479 if (m_LastDecayStage != FoodStageType.NONE)
1480 {
1481 // switch to decayed stage
1484 }
1485 }
1486 }
1487 else if (IsCorpse())
1488 {
1489 // corpse
1491 {
1492 switch (GetFoodStageType())
1493 {
1494 case FoodStageType.RAW:
1497 break;
1498
1499 case FoodStageType.BURNED:
1500 case FoodStageType.ROTTEN:
1501 default:
1502 m_DecayTimer = -1;
1504 return;
1505 }
1506 }
1507
1509
1510 if (m_DecayTimer <= 0)
1511 {
1512 if (m_LastDecayStage != FoodStageType.NONE)
1513 {
1514 // switch to decayed stage
1517 }
1518 }
1519 }
1520 else
1521 {
1522 // opened cans
1524
1525 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1526 {
1529 //m_DecayTimer = m_DecayTimer / 1000.0;
1530 }
1531 else
1532 {
1533 if (m_DecayTimer <= 0)
1534 {
1535 InsertAgent(eAgents.FOOD_POISON, 1);
1536 m_DecayTimer = -1;
1537 }
1538 }
1539 }
1540
1541 m_DecayDelta = 0.0;
1542 }
1543
1545 {
1546 super.GetDebugActions(outputList);
1547
1548 if (HasFoodStage())
1549 {
1550 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1551 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1552 }
1553 }
1554
1555 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1556 {
1557 super.OnAction(action_id, player, ctx);
1558
1559 if (GetGame().IsServer())
1560 {
1561 if (action_id == EActions.FOOD_STAGE_PREV)
1562 {
1564 if (food_stage_prev <= 0)
1565 food_stage_prev = FoodStageType.COUNT - 1;
1567 return true;
1568 }
1569 else if (action_id == EActions.FOOD_STAGE_NEXT)
1570 {
1572 if (food_stage_next >= FoodStageType.COUNT)
1575 return true;
1576 }
1577 }
1578 return false;
1579 }
1580
1581 override string GetDebugText()
1582 {
1583 string debug_output;
1584
1585 debug_output = super.GetDebugText();
1586
1587 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1588 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1589
1590 return debug_output;
1591 }
1592
1593 //================================================================
1594 // GENERAL GETTERS
1595 //================================================================
1596
1597 float GetDecayTimer()
1598 {
1599 return m_DecayTimer;
1600 }
1601
1602 float GetDecayDelta()
1603 {
1604 return m_DecayDelta;
1605 }
1606
1608 {
1609 return m_LastDecayStage;
1610 }
1611}
1612
1614{
1616};

◆ ProcessDecay()

override void ReplaceEdibleWithNewLambda::ProcessDecay ( float delta,
bool hasRootAsPlayer )
protected

Definition at line 1253 of file Edible_Base.c.

1253 : ItemBase
1254{
1255 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1256
1257 const string SOUND_BAKING_START = "Baking_SoundSet";
1258 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1259 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1260
1261 protected bool m_MakeCookingSounds;
1262 protected SoundOnVehicle m_SoundCooking;
1264 protected string m_SoundPlaying;
1266 protected float m_DecayTimer;
1267 protected float m_DecayDelta = 0.0;
1269
1271
1272 void Edible_Base()
1273 {
1274 if (HasFoodStage())
1275 {
1276 m_FoodStage = new FoodStage(this);
1277
1278 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1279 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1280 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1281 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1282 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1283
1284 m_SoundPlaying = "";
1286 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1287 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1288 }
1289 }
1290
1291 override void EEInit()
1292 {
1293 super.EEInit();
1294
1295 UpdateVisuals();
1296 }
1297
1298 override void EEDelete(EntityAI parent)
1299 {
1300 super.EEDelete(parent);
1301
1302 RemoveAudio();
1303 }
1304
1306 {
1307 super.EEItemLocationChanged(oldLoc, newLoc);
1308
1310 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1311 {
1312 switch (oldLoc.GetParent().GetType())
1313 {
1314 case "FryingPan":
1315 case "Pot":
1316 case "Cauldron":
1317 case "SharpWoodenStick":
1318 MakeSoundsOnClient(false);
1319 break;
1320 }
1321
1323 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1324 MakeSoundsOnClient(false);
1325 }
1326 }
1327
1328 void UpdateVisuals()
1329 {
1330 if (GetFoodStage())
1331 GetFoodStage().UpdateVisuals();
1332 }
1333
1334 bool Consume(float amount, PlayerBase consumer)
1335 {
1336 AddQuantity(-amount, false, false);
1337 OnConsume(amount, consumer);
1338
1339 return true;
1340 }
1341
1342 void OnConsume(float amount, PlayerBase consumer);
1343
1344 //food staging
1345 override bool CanBeCooked()
1346 {
1347 return false;
1348 }
1349
1350 override bool CanBeCookedOnStick()
1351 {
1352 return false;
1353 }
1354
1355 //================================================================
1356 // SYNCHRONIZATION
1357 //================================================================
1358 void Synchronize()
1359 {
1360 SetSynchDirty();
1361
1362 if (GetGame().IsMultiplayer())
1363 UpdateVisuals();
1364 }
1365
1366 override void OnVariablesSynchronized()
1367 {
1368 super.OnVariablesSynchronized();
1369
1370 UpdateVisuals();
1371
1372 //update audio
1374 RefreshAudio();
1375 else
1376 RemoveAudio();
1377 }
1378
1379 //================================================================
1380 // AUDIO EFFECTS (WHEN ON DCS)
1381 //================================================================
1383 {
1386
1387 Synchronize();
1388 }
1389
1390 protected void RefreshAudio()
1391 {
1392 string soundName = "";
1393
1395
1396 switch (GetFoodStageType())
1397 {
1398 case FoodStageType.RAW:
1400 if (nextFoodState == FoodStageType.BOILED)
1401 soundName = "";
1402 break;
1403 case FoodStageType.BAKED:
1405 break;
1406 case FoodStageType.BURNED:
1408 break;
1409 default:
1410 soundName = "";
1411 break;
1412 }
1413
1415 }
1416
1417 protected void RemoveAudio()
1418 {
1419 m_MakeCookingSounds = false;
1421 }
1422
1423 //================================================================
1424 // SERIALIZATION
1425 //================================================================
1426 override void OnStoreSave(ParamsWriteContext ctx)
1427 {
1428 super.OnStoreSave(ctx);
1429
1430 if (GetFoodStage())
1431 GetFoodStage().OnStoreSave(ctx);
1432
1433 // food decay
1434 ctx.Write(m_DecayTimer);
1435 ctx.Write(m_LastDecayStage);
1436 }
1437
1438 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1439 {
1440 if (!super.OnStoreLoad(ctx, version))
1441 return false;
1442
1443 if (GetFoodStage())
1444 {
1445 if (!GetFoodStage().OnStoreLoad(ctx, version))
1446 return false;
1447 }
1448
1449 if (version >= 115)
1450 {
1451 if (!ctx.Read(m_DecayTimer))
1452 {
1453 m_DecayTimer = 0.0;
1454 return false;
1455 }
1456 if (!ctx.Read(m_LastDecayStage))
1457 {
1459 return false;
1460 }
1461 }
1462
1463 return true;
1464 }
1465
1466 override void AfterStoreLoad()
1467 {
1468 super.AfterStoreLoad();
1469
1470 Synchronize();
1471 }
1472
1473 //get food stage
1475 {
1476 return m_FoodStage;
1477 }
1478
1479 //food types
1480 override bool IsMeat()
1481 {
1482 return false;
1483 }
1484
1485 override bool IsCorpse()
1486 {
1487 return false;
1488 }
1489
1490 override bool IsFruit()
1491 {
1492 return false;
1493 }
1494
1495 override bool IsMushroom()
1496 {
1497 return false;
1498 }
1499
1500 //================================================================
1501 // NUTRITIONAL VALUES
1502 //================================================================
1503 //food properties
1504 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1505 {
1507 if (food_item && food_item.GetFoodStage())
1508 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1509 else if (classname != "" && food_stage)
1510 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1511 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1512 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1513
1514 }
1515
1516 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1517 {
1519 if (food_item && food_item.GetFoodStage())
1520 return FoodStage.GetEnergy(food_item.GetFoodStage());
1521 else if (classname != "" && food_stage)
1522 return FoodStage.GetEnergy(null, food_stage, classname);
1523 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1524 return GetGame().ConfigGetFloat(class_path + " energy");
1525 }
1526
1527 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1528 {
1530 if (food_item && food_item.GetFoodStage())
1531 return FoodStage.GetWater(food_item.GetFoodStage());
1532 else if (classname != "" && food_stage)
1533 return FoodStage.GetWater(null, food_stage, classname);
1534 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1535 return GetGame().ConfigGetFloat(class_path + " water");
1536 }
1537
1538 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1539 {
1541 if (food_item && food_item.GetFoodStage())
1542 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1543 else if (classname != "" && food_stage)
1544 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1545 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1546 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1547
1548 }
1549
1550 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1551 {
1553 if (food_item && food_item.GetFoodStage())
1554 return FoodStage.GetToxicity(food_item.GetFoodStage());
1555 else if (classname != "" && food_stage)
1556 return FoodStage.GetToxicity(null, food_stage, classname);
1557 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1558 return GetGame().ConfigGetFloat(class_path + " toxicity");
1559 }
1560
1561 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1562 {
1564 if (food_item && food_item.GetFoodStage())
1565 return FoodStage.GetAgents(food_item.GetFoodStage());
1566 else if (classname != "" && food_stage)
1567 return FoodStage.GetAgents(null, food_stage, classname);
1568 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1569 return GetGame().ConfigGetInt(class_path + " agents");
1570 }
1571
1572 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1573 {
1575 if (food_item && food_item.GetFoodStage())
1576 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1577 else if (classname != "" && food_stage)
1578 return FoodStage.GetDigestibility(null, food_stage, classname);
1579 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1580 return GetGame().ConfigGetInt(class_path + " digestibility");
1581 }
1582
1584 {
1586 }
1587
1588 //================================================================
1589 // FOOD STAGING
1590 //================================================================
1592 {
1593 return GetFoodStage().GetFoodStageType();
1594 }
1595
1596 //food stage states
1597 bool IsFoodRaw()
1598 {
1599 if (GetFoodStage())
1600 return GetFoodStage().IsFoodRaw();
1601
1602 return false;
1603 }
1604
1605 bool IsFoodBaked()
1606 {
1607 if (GetFoodStage())
1608 return GetFoodStage().IsFoodBaked();
1609
1610 return false;
1611 }
1612
1613 bool IsFoodBoiled()
1614 {
1615 if (GetFoodStage())
1616 return GetFoodStage().IsFoodBoiled();
1617
1618 return false;
1619 }
1620
1621 bool IsFoodDried()
1622 {
1623 if (GetFoodStage())
1624 return GetFoodStage().IsFoodDried();
1625
1626 return false;
1627 }
1628
1629 bool IsFoodBurned()
1630 {
1631 if (GetFoodStage())
1632 return GetFoodStage().IsFoodBurned();
1633
1634 return false;
1635 }
1636
1637 bool IsFoodRotten()
1638 {
1639 if (GetFoodStage())
1640 return GetFoodStage().IsFoodRotten();
1641
1642 return false;
1643 }
1644
1645 //food stage change
1647 {
1648 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1649 }
1650
1652 {
1653 return GetFoodStage().GetNextFoodStageType(cooking_method);
1654 }
1655
1657 {
1658 return GetFoodStage().GetFoodStageName(food_stage_type);
1659 }
1660
1662 {
1663 return GetFoodStage().CanChangeToNewStage(cooking_method);
1664 }
1665
1666 //Use this to receive food stage from another Edible_Base
1668 {
1669 if (!source.HasFoodStage())
1670 return;
1671 m_LastDecayStage = source.GetLastDecayStage();
1672 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1673 m_DecayTimer = source.GetDecayTimer();
1674 m_DecayDelta = source.GetDecayDelta();
1675 }
1676
1677 //================================================================
1678 // COOKING
1679 //================================================================
1680 //cooking time
1681 float GetCookingTime()
1682 {
1683 return GetFoodStage().GetCookingTime();
1684 }
1685
1686 void SetCookingTime(float time)
1687 {
1688 GetFoodStage().SetCookingTime(time);
1689
1690 //synchronize when calling on server
1691 Synchronize();
1692 }
1693
1694 //replace edible with new item (opening cans)
1695 void ReplaceEdibleWithNew(string typeName)
1696 {
1697 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1698 if (player)
1699 {
1701 player.ServerReplaceItemInHandsWithNew(lambda);
1702 }
1703 else
1704 Error("ReplaceEdibleWithNew - cannot use edible without player");
1705 }
1706
1707 override void SetActions()
1708 {
1709 super.SetActions();
1710
1711 AddAction(ActionAttach);
1713 }
1714
1715 protected void SoundCookingStart(string sound_name)
1716 {
1717#ifndef SERVER
1719 {
1721
1724 }
1725#endif
1726 }
1727
1728 protected void SoundCookingStop()
1729 {
1730#ifndef SERVER
1732 {
1735 m_SoundPlaying = "";
1736 }
1737#endif
1738 }
1739
1740 override bool CanHaveTemperature()
1741 {
1742 return true;
1743 }
1744
1745 override bool CanDecay()
1746 {
1747 return false;
1748 }
1749
1750 override bool CanProcessDecay()
1751 {
1752 return (GetFoodStageType() != FoodStageType.ROTTEN);
1753 }
1754
1755 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1756 {
1757 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1758 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1759 if (hasRootAsPlayer)
1761
1762 /*Print( "-------------------------" );
1763 Print( this );
1764 Print( m_DecayTimer );
1765 Print( m_DecayDelta );
1766 Print( m_LastDecayStage );*/
1767
1768 if (IsFruit() || IsMushroom())
1769 {
1770 // fruit, vegetables and mushrooms
1772 {
1773 switch (GetFoodStageType())
1774 {
1775 case FoodStageType.RAW:
1778 break;
1779
1780 case FoodStageType.BOILED:
1783 break;
1784
1785 case FoodStageType.BAKED:
1788 break;
1789
1790 case FoodStageType.DRIED:
1791 case FoodStageType.BURNED:
1792 case FoodStageType.ROTTEN:
1793 default:
1794 m_DecayTimer = -1;
1796 return;
1797 }
1798
1799 //m_DecayTimer = m_DecayTimer / 1000.0;
1800 }
1801
1803
1804 if (m_DecayTimer <= 0)
1805 {
1806 if (m_LastDecayStage != FoodStageType.NONE)
1807 {
1808 // switch to decayed stage
1809 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1812 {
1813 int rng = Math.RandomIntInclusive(0, 100);
1816 else
1817 {
1820 else
1822 }
1823 }
1824 }
1825 }
1826
1827 }
1828 else if (IsMeat())
1829 {
1830 // meat
1832 {
1833 switch (GetFoodStageType())
1834 {
1835 case FoodStageType.RAW:
1838 break;
1839
1840 case FoodStageType.BOILED:
1843 break;
1844
1845 case FoodStageType.BAKED:
1848 break;
1849
1850 case FoodStageType.DRIED:
1853 break;
1854
1855 case FoodStageType.BURNED:
1856 case FoodStageType.ROTTEN:
1857 default:
1858 m_DecayTimer = -1;
1860 return;
1861 }
1862 }
1863
1865
1866 if (m_DecayTimer <= 0)
1867 {
1868 if (m_LastDecayStage != FoodStageType.NONE)
1869 {
1870 // switch to decayed stage
1873 }
1874 }
1875 }
1876 else if (IsCorpse())
1877 {
1878 // corpse
1880 {
1881 switch (GetFoodStageType())
1882 {
1883 case FoodStageType.RAW:
1886 break;
1887
1888 case FoodStageType.BURNED:
1889 case FoodStageType.ROTTEN:
1890 default:
1891 m_DecayTimer = -1;
1893 return;
1894 }
1895 }
1896
1898
1899 if (m_DecayTimer <= 0)
1900 {
1901 if (m_LastDecayStage != FoodStageType.NONE)
1902 {
1903 // switch to decayed stage
1906 }
1907 }
1908 }
1909 else
1910 {
1911 // opened cans
1913
1914 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1915 {
1918 //m_DecayTimer = m_DecayTimer / 1000.0;
1919 }
1920 else
1921 {
1922 if (m_DecayTimer <= 0)
1923 {
1924 InsertAgent(eAgents.FOOD_POISON, 1);
1925 m_DecayTimer = -1;
1926 }
1927 }
1928 }
1929
1930 m_DecayDelta = 0.0;
1931 }
1932
1934 {
1935 super.GetDebugActions(outputList);
1936
1937 if (HasFoodStage())
1938 {
1939 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1940 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1941 }
1942 }
1943
1944 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1945 {
1946 super.OnAction(action_id, player, ctx);
1947
1948 if (GetGame().IsServer())
1949 {
1950 if (action_id == EActions.FOOD_STAGE_PREV)
1951 {
1953 if (food_stage_prev <= 0)
1954 food_stage_prev = FoodStageType.COUNT - 1;
1956 return true;
1957 }
1958 else if (action_id == EActions.FOOD_STAGE_NEXT)
1959 {
1961 if (food_stage_next >= FoodStageType.COUNT)
1964 return true;
1965 }
1966 }
1967 return false;
1968 }
1969
1970 override string GetDebugText()
1971 {
1972 string debug_output;
1973
1974 debug_output = super.GetDebugText();
1975
1976 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1977 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1978
1979 return debug_output;
1980 }
1981
1982 //================================================================
1983 // GENERAL GETTERS
1984 //================================================================
1985
1986 float GetDecayTimer()
1987 {
1988 return m_DecayTimer;
1989 }
1990
1991 float GetDecayDelta()
1992 {
1993 return m_DecayDelta;
1994 }
1995
1997 {
1998 return m_LastDecayStage;
1999 }
2000}
2001
2003{
2005};

◆ RefreshAudio()

void ReplaceEdibleWithNewLambda::RefreshAudio ( )
protected

Definition at line 888 of file Edible_Base.c.

888 : ItemBase
889{
890 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
891
892 const string SOUND_BAKING_START = "Baking_SoundSet";
893 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
894 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
895
896 protected bool m_MakeCookingSounds;
899 protected string m_SoundPlaying;
901 protected float m_DecayTimer;
902 protected float m_DecayDelta = 0.0;
904
906
907 void Edible_Base()
908 {
909 if (HasFoodStage())
910 {
911 m_FoodStage = new FoodStage(this);
912
913 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
914 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
915 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
916 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
917 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
918
919 m_SoundPlaying = "";
921 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
922 RegisterNetSyncVariableBool("m_MakeCookingSounds");
923 }
924 }
925
926 override void EEInit()
927 {
928 super.EEInit();
929
931 }
932
933 override void EEDelete(EntityAI parent)
934 {
935 super.EEDelete(parent);
936
937 RemoveAudio();
938 }
939
941 {
942 super.EEItemLocationChanged(oldLoc, newLoc);
943
945 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
946 {
947 switch (oldLoc.GetParent().GetType())
948 {
949 case "FryingPan":
950 case "Pot":
951 case "Cauldron":
952 case "SharpWoodenStick":
953 MakeSoundsOnClient(false);
954 break;
955 }
956
958 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
959 MakeSoundsOnClient(false);
960 }
961 }
962
963 void UpdateVisuals()
964 {
965 if (GetFoodStage())
966 GetFoodStage().UpdateVisuals();
967 }
968
969 bool Consume(float amount, PlayerBase consumer)
970 {
971 AddQuantity(-amount, false, false);
972 OnConsume(amount, consumer);
973
974 return true;
975 }
976
977 void OnConsume(float amount, PlayerBase consumer);
978
979 //food staging
980 override bool CanBeCooked()
981 {
982 return false;
983 }
984
985 override bool CanBeCookedOnStick()
986 {
987 return false;
988 }
989
990 //================================================================
991 // SYNCHRONIZATION
992 //================================================================
993 void Synchronize()
994 {
995 SetSynchDirty();
996
997 if (GetGame().IsMultiplayer())
999 }
1000
1001 override void OnVariablesSynchronized()
1002 {
1003 super.OnVariablesSynchronized();
1004
1005 UpdateVisuals();
1006
1007 //update audio
1009 RefreshAudio();
1010 else
1011 RemoveAudio();
1012 }
1013
1014 //================================================================
1015 // AUDIO EFFECTS (WHEN ON DCS)
1016 //================================================================
1018 {
1021
1022 Synchronize();
1023 }
1024
1025 protected void RefreshAudio()
1026 {
1027 string soundName = "";
1028
1030
1031 switch (GetFoodStageType())
1032 {
1033 case FoodStageType.RAW:
1035 if (nextFoodState == FoodStageType.BOILED)
1036 soundName = "";
1037 break;
1038 case FoodStageType.BAKED:
1040 break;
1041 case FoodStageType.BURNED:
1043 break;
1044 default:
1045 soundName = "";
1046 break;
1047 }
1048
1050 }
1051
1052 protected void RemoveAudio()
1053 {
1054 m_MakeCookingSounds = false;
1056 }
1057
1058 //================================================================
1059 // SERIALIZATION
1060 //================================================================
1061 override void OnStoreSave(ParamsWriteContext ctx)
1062 {
1063 super.OnStoreSave(ctx);
1064
1065 if (GetFoodStage())
1066 GetFoodStage().OnStoreSave(ctx);
1067
1068 // food decay
1069 ctx.Write(m_DecayTimer);
1070 ctx.Write(m_LastDecayStage);
1071 }
1072
1073 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1074 {
1075 if (!super.OnStoreLoad(ctx, version))
1076 return false;
1077
1078 if (GetFoodStage())
1079 {
1080 if (!GetFoodStage().OnStoreLoad(ctx, version))
1081 return false;
1082 }
1083
1084 if (version >= 115)
1085 {
1086 if (!ctx.Read(m_DecayTimer))
1087 {
1088 m_DecayTimer = 0.0;
1089 return false;
1090 }
1091 if (!ctx.Read(m_LastDecayStage))
1092 {
1094 return false;
1095 }
1096 }
1097
1098 return true;
1099 }
1100
1101 override void AfterStoreLoad()
1102 {
1103 super.AfterStoreLoad();
1104
1105 Synchronize();
1106 }
1107
1108 //get food stage
1110 {
1111 return m_FoodStage;
1112 }
1113
1114 //food types
1115 override bool IsMeat()
1116 {
1117 return false;
1118 }
1119
1120 override bool IsCorpse()
1121 {
1122 return false;
1123 }
1124
1125 override bool IsFruit()
1126 {
1127 return false;
1128 }
1129
1130 override bool IsMushroom()
1131 {
1132 return false;
1133 }
1134
1135 //================================================================
1136 // NUTRITIONAL VALUES
1137 //================================================================
1138 //food properties
1139 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1140 {
1142 if (food_item && food_item.GetFoodStage())
1143 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1144 else if (classname != "" && food_stage)
1145 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1146 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1147 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1148
1149 }
1150
1151 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1152 {
1154 if (food_item && food_item.GetFoodStage())
1155 return FoodStage.GetEnergy(food_item.GetFoodStage());
1156 else if (classname != "" && food_stage)
1157 return FoodStage.GetEnergy(null, food_stage, classname);
1158 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1159 return GetGame().ConfigGetFloat(class_path + " energy");
1160 }
1161
1162 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1163 {
1165 if (food_item && food_item.GetFoodStage())
1166 return FoodStage.GetWater(food_item.GetFoodStage());
1167 else if (classname != "" && food_stage)
1168 return FoodStage.GetWater(null, food_stage, classname);
1169 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1170 return GetGame().ConfigGetFloat(class_path + " water");
1171 }
1172
1173 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1174 {
1176 if (food_item && food_item.GetFoodStage())
1177 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1178 else if (classname != "" && food_stage)
1179 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1180 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1181 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1182
1183 }
1184
1185 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1186 {
1188 if (food_item && food_item.GetFoodStage())
1189 return FoodStage.GetToxicity(food_item.GetFoodStage());
1190 else if (classname != "" && food_stage)
1191 return FoodStage.GetToxicity(null, food_stage, classname);
1192 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1193 return GetGame().ConfigGetFloat(class_path + " toxicity");
1194 }
1195
1196 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1197 {
1199 if (food_item && food_item.GetFoodStage())
1200 return FoodStage.GetAgents(food_item.GetFoodStage());
1201 else if (classname != "" && food_stage)
1202 return FoodStage.GetAgents(null, food_stage, classname);
1203 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1204 return GetGame().ConfigGetInt(class_path + " agents");
1205 }
1206
1207 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1208 {
1210 if (food_item && food_item.GetFoodStage())
1211 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1212 else if (classname != "" && food_stage)
1213 return FoodStage.GetDigestibility(null, food_stage, classname);
1214 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1215 return GetGame().ConfigGetInt(class_path + " digestibility");
1216 }
1217
1219 {
1221 }
1222
1223 //================================================================
1224 // FOOD STAGING
1225 //================================================================
1227 {
1228 return GetFoodStage().GetFoodStageType();
1229 }
1230
1231 //food stage states
1232 bool IsFoodRaw()
1233 {
1234 if (GetFoodStage())
1235 return GetFoodStage().IsFoodRaw();
1236
1237 return false;
1238 }
1239
1240 bool IsFoodBaked()
1241 {
1242 if (GetFoodStage())
1243 return GetFoodStage().IsFoodBaked();
1244
1245 return false;
1246 }
1247
1248 bool IsFoodBoiled()
1249 {
1250 if (GetFoodStage())
1251 return GetFoodStage().IsFoodBoiled();
1252
1253 return false;
1254 }
1255
1256 bool IsFoodDried()
1257 {
1258 if (GetFoodStage())
1259 return GetFoodStage().IsFoodDried();
1260
1261 return false;
1262 }
1263
1264 bool IsFoodBurned()
1265 {
1266 if (GetFoodStage())
1267 return GetFoodStage().IsFoodBurned();
1268
1269 return false;
1270 }
1271
1272 bool IsFoodRotten()
1273 {
1274 if (GetFoodStage())
1275 return GetFoodStage().IsFoodRotten();
1276
1277 return false;
1278 }
1279
1280 //food stage change
1282 {
1283 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1284 }
1285
1287 {
1288 return GetFoodStage().GetNextFoodStageType(cooking_method);
1289 }
1290
1292 {
1293 return GetFoodStage().GetFoodStageName(food_stage_type);
1294 }
1295
1297 {
1298 return GetFoodStage().CanChangeToNewStage(cooking_method);
1299 }
1300
1301 //Use this to receive food stage from another Edible_Base
1303 {
1304 if (!source.HasFoodStage())
1305 return;
1306 m_LastDecayStage = source.GetLastDecayStage();
1307 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1308 m_DecayTimer = source.GetDecayTimer();
1309 m_DecayDelta = source.GetDecayDelta();
1310 }
1311
1312 //================================================================
1313 // COOKING
1314 //================================================================
1315 //cooking time
1316 float GetCookingTime()
1317 {
1318 return GetFoodStage().GetCookingTime();
1319 }
1320
1321 void SetCookingTime(float time)
1322 {
1323 GetFoodStage().SetCookingTime(time);
1324
1325 //synchronize when calling on server
1326 Synchronize();
1327 }
1328
1329 //replace edible with new item (opening cans)
1330 void ReplaceEdibleWithNew(string typeName)
1331 {
1332 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1333 if (player)
1334 {
1336 player.ServerReplaceItemInHandsWithNew(lambda);
1337 }
1338 else
1339 Error("ReplaceEdibleWithNew - cannot use edible without player");
1340 }
1341
1342 override void SetActions()
1343 {
1344 super.SetActions();
1345
1346 AddAction(ActionAttach);
1348 }
1349
1350 protected void SoundCookingStart(string sound_name)
1351 {
1352#ifndef SERVER
1354 {
1356
1359 }
1360#endif
1361 }
1362
1363 protected void SoundCookingStop()
1364 {
1365#ifndef SERVER
1367 {
1370 m_SoundPlaying = "";
1371 }
1372#endif
1373 }
1374
1375 override bool CanHaveTemperature()
1376 {
1377 return true;
1378 }
1379
1380 override bool CanDecay()
1381 {
1382 return false;
1383 }
1384
1385 override bool CanProcessDecay()
1386 {
1387 return (GetFoodStageType() != FoodStageType.ROTTEN);
1388 }
1389
1390 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1391 {
1392 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1393 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1394 if (hasRootAsPlayer)
1396
1397 /*Print( "-------------------------" );
1398 Print( this );
1399 Print( m_DecayTimer );
1400 Print( m_DecayDelta );
1401 Print( m_LastDecayStage );*/
1402
1403 if (IsFruit() || IsMushroom())
1404 {
1405 // fruit, vegetables and mushrooms
1407 {
1408 switch (GetFoodStageType())
1409 {
1410 case FoodStageType.RAW:
1413 break;
1414
1415 case FoodStageType.BOILED:
1418 break;
1419
1420 case FoodStageType.BAKED:
1423 break;
1424
1425 case FoodStageType.DRIED:
1426 case FoodStageType.BURNED:
1427 case FoodStageType.ROTTEN:
1428 default:
1429 m_DecayTimer = -1;
1431 return;
1432 }
1433
1434 //m_DecayTimer = m_DecayTimer / 1000.0;
1435 }
1436
1438
1439 if (m_DecayTimer <= 0)
1440 {
1441 if (m_LastDecayStage != FoodStageType.NONE)
1442 {
1443 // switch to decayed stage
1444 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1447 {
1448 int rng = Math.RandomIntInclusive(0, 100);
1451 else
1452 {
1455 else
1457 }
1458 }
1459 }
1460 }
1461
1462 }
1463 else if (IsMeat())
1464 {
1465 // meat
1467 {
1468 switch (GetFoodStageType())
1469 {
1470 case FoodStageType.RAW:
1473 break;
1474
1475 case FoodStageType.BOILED:
1478 break;
1479
1480 case FoodStageType.BAKED:
1483 break;
1484
1485 case FoodStageType.DRIED:
1488 break;
1489
1490 case FoodStageType.BURNED:
1491 case FoodStageType.ROTTEN:
1492 default:
1493 m_DecayTimer = -1;
1495 return;
1496 }
1497 }
1498
1500
1501 if (m_DecayTimer <= 0)
1502 {
1503 if (m_LastDecayStage != FoodStageType.NONE)
1504 {
1505 // switch to decayed stage
1508 }
1509 }
1510 }
1511 else if (IsCorpse())
1512 {
1513 // corpse
1515 {
1516 switch (GetFoodStageType())
1517 {
1518 case FoodStageType.RAW:
1521 break;
1522
1523 case FoodStageType.BURNED:
1524 case FoodStageType.ROTTEN:
1525 default:
1526 m_DecayTimer = -1;
1528 return;
1529 }
1530 }
1531
1533
1534 if (m_DecayTimer <= 0)
1535 {
1536 if (m_LastDecayStage != FoodStageType.NONE)
1537 {
1538 // switch to decayed stage
1541 }
1542 }
1543 }
1544 else
1545 {
1546 // opened cans
1548
1549 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1550 {
1553 //m_DecayTimer = m_DecayTimer / 1000.0;
1554 }
1555 else
1556 {
1557 if (m_DecayTimer <= 0)
1558 {
1559 InsertAgent(eAgents.FOOD_POISON, 1);
1560 m_DecayTimer = -1;
1561 }
1562 }
1563 }
1564
1565 m_DecayDelta = 0.0;
1566 }
1567
1569 {
1570 super.GetDebugActions(outputList);
1571
1572 if (HasFoodStage())
1573 {
1574 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1575 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1576 }
1577 }
1578
1579 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1580 {
1581 super.OnAction(action_id, player, ctx);
1582
1583 if (GetGame().IsServer())
1584 {
1585 if (action_id == EActions.FOOD_STAGE_PREV)
1586 {
1588 if (food_stage_prev <= 0)
1589 food_stage_prev = FoodStageType.COUNT - 1;
1591 return true;
1592 }
1593 else if (action_id == EActions.FOOD_STAGE_NEXT)
1594 {
1596 if (food_stage_next >= FoodStageType.COUNT)
1599 return true;
1600 }
1601 }
1602 return false;
1603 }
1604
1605 override string GetDebugText()
1606 {
1607 string debug_output;
1608
1609 debug_output = super.GetDebugText();
1610
1611 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1612 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1613
1614 return debug_output;
1615 }
1616
1617 //================================================================
1618 // GENERAL GETTERS
1619 //================================================================
1620
1621 float GetDecayTimer()
1622 {
1623 return m_DecayTimer;
1624 }
1625
1626 float GetDecayDelta()
1627 {
1628 return m_DecayDelta;
1629 }
1630
1632 {
1633 return m_LastDecayStage;
1634 }
1635}
1636
1638{
1640};

◆ RemoveAudio()

void ReplaceEdibleWithNewLambda::RemoveAudio ( )
protected

Definition at line 915 of file Edible_Base.c.

915 : ItemBase
916{
917 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
918
919 const string SOUND_BAKING_START = "Baking_SoundSet";
920 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
921 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
922
923 protected bool m_MakeCookingSounds;
926 protected string m_SoundPlaying;
928 protected float m_DecayTimer;
929 protected float m_DecayDelta = 0.0;
931
933
934 void Edible_Base()
935 {
936 if (HasFoodStage())
937 {
938 m_FoodStage = new FoodStage(this);
939
940 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
941 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
942 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
943 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
944 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
945
946 m_SoundPlaying = "";
948 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
949 RegisterNetSyncVariableBool("m_MakeCookingSounds");
950 }
951 }
952
953 override void EEInit()
954 {
955 super.EEInit();
956
958 }
959
960 override void EEDelete(EntityAI parent)
961 {
962 super.EEDelete(parent);
963
964 RemoveAudio();
965 }
966
968 {
969 super.EEItemLocationChanged(oldLoc, newLoc);
970
972 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
973 {
974 switch (oldLoc.GetParent().GetType())
975 {
976 case "FryingPan":
977 case "Pot":
978 case "Cauldron":
979 case "SharpWoodenStick":
980 MakeSoundsOnClient(false);
981 break;
982 }
983
985 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
986 MakeSoundsOnClient(false);
987 }
988 }
989
990 void UpdateVisuals()
991 {
992 if (GetFoodStage())
993 GetFoodStage().UpdateVisuals();
994 }
995
996 bool Consume(float amount, PlayerBase consumer)
997 {
998 AddQuantity(-amount, false, false);
999 OnConsume(amount, consumer);
1000
1001 return true;
1002 }
1003
1004 void OnConsume(float amount, PlayerBase consumer);
1005
1006 //food staging
1007 override bool CanBeCooked()
1008 {
1009 return false;
1010 }
1011
1012 override bool CanBeCookedOnStick()
1013 {
1014 return false;
1015 }
1016
1017 //================================================================
1018 // SYNCHRONIZATION
1019 //================================================================
1020 void Synchronize()
1021 {
1022 SetSynchDirty();
1023
1024 if (GetGame().IsMultiplayer())
1025 UpdateVisuals();
1026 }
1027
1028 override void OnVariablesSynchronized()
1029 {
1030 super.OnVariablesSynchronized();
1031
1032 UpdateVisuals();
1033
1034 //update audio
1036 RefreshAudio();
1037 else
1038 RemoveAudio();
1039 }
1040
1041 //================================================================
1042 // AUDIO EFFECTS (WHEN ON DCS)
1043 //================================================================
1045 {
1048
1049 Synchronize();
1050 }
1051
1052 protected void RefreshAudio()
1053 {
1054 string soundName = "";
1055
1057
1058 switch (GetFoodStageType())
1059 {
1060 case FoodStageType.RAW:
1062 if (nextFoodState == FoodStageType.BOILED)
1063 soundName = "";
1064 break;
1065 case FoodStageType.BAKED:
1067 break;
1068 case FoodStageType.BURNED:
1070 break;
1071 default:
1072 soundName = "";
1073 break;
1074 }
1075
1077 }
1078
1079 protected void RemoveAudio()
1080 {
1081 m_MakeCookingSounds = false;
1083 }
1084
1085 //================================================================
1086 // SERIALIZATION
1087 //================================================================
1088 override void OnStoreSave(ParamsWriteContext ctx)
1089 {
1090 super.OnStoreSave(ctx);
1091
1092 if (GetFoodStage())
1093 GetFoodStage().OnStoreSave(ctx);
1094
1095 // food decay
1096 ctx.Write(m_DecayTimer);
1097 ctx.Write(m_LastDecayStage);
1098 }
1099
1100 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1101 {
1102 if (!super.OnStoreLoad(ctx, version))
1103 return false;
1104
1105 if (GetFoodStage())
1106 {
1107 if (!GetFoodStage().OnStoreLoad(ctx, version))
1108 return false;
1109 }
1110
1111 if (version >= 115)
1112 {
1113 if (!ctx.Read(m_DecayTimer))
1114 {
1115 m_DecayTimer = 0.0;
1116 return false;
1117 }
1118 if (!ctx.Read(m_LastDecayStage))
1119 {
1121 return false;
1122 }
1123 }
1124
1125 return true;
1126 }
1127
1128 override void AfterStoreLoad()
1129 {
1130 super.AfterStoreLoad();
1131
1132 Synchronize();
1133 }
1134
1135 //get food stage
1137 {
1138 return m_FoodStage;
1139 }
1140
1141 //food types
1142 override bool IsMeat()
1143 {
1144 return false;
1145 }
1146
1147 override bool IsCorpse()
1148 {
1149 return false;
1150 }
1151
1152 override bool IsFruit()
1153 {
1154 return false;
1155 }
1156
1157 override bool IsMushroom()
1158 {
1159 return false;
1160 }
1161
1162 //================================================================
1163 // NUTRITIONAL VALUES
1164 //================================================================
1165 //food properties
1166 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1167 {
1169 if (food_item && food_item.GetFoodStage())
1170 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1171 else if (classname != "" && food_stage)
1172 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1173 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1174 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1175
1176 }
1177
1178 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1179 {
1181 if (food_item && food_item.GetFoodStage())
1182 return FoodStage.GetEnergy(food_item.GetFoodStage());
1183 else if (classname != "" && food_stage)
1184 return FoodStage.GetEnergy(null, food_stage, classname);
1185 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1186 return GetGame().ConfigGetFloat(class_path + " energy");
1187 }
1188
1189 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1190 {
1192 if (food_item && food_item.GetFoodStage())
1193 return FoodStage.GetWater(food_item.GetFoodStage());
1194 else if (classname != "" && food_stage)
1195 return FoodStage.GetWater(null, food_stage, classname);
1196 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1197 return GetGame().ConfigGetFloat(class_path + " water");
1198 }
1199
1200 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1201 {
1203 if (food_item && food_item.GetFoodStage())
1204 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1205 else if (classname != "" && food_stage)
1206 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1207 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1208 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1209
1210 }
1211
1212 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1213 {
1215 if (food_item && food_item.GetFoodStage())
1216 return FoodStage.GetToxicity(food_item.GetFoodStage());
1217 else if (classname != "" && food_stage)
1218 return FoodStage.GetToxicity(null, food_stage, classname);
1219 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1220 return GetGame().ConfigGetFloat(class_path + " toxicity");
1221 }
1222
1223 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1224 {
1226 if (food_item && food_item.GetFoodStage())
1227 return FoodStage.GetAgents(food_item.GetFoodStage());
1228 else if (classname != "" && food_stage)
1229 return FoodStage.GetAgents(null, food_stage, classname);
1230 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1231 return GetGame().ConfigGetInt(class_path + " agents");
1232 }
1233
1234 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1235 {
1237 if (food_item && food_item.GetFoodStage())
1238 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1239 else if (classname != "" && food_stage)
1240 return FoodStage.GetDigestibility(null, food_stage, classname);
1241 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1242 return GetGame().ConfigGetInt(class_path + " digestibility");
1243 }
1244
1246 {
1248 }
1249
1250 //================================================================
1251 // FOOD STAGING
1252 //================================================================
1254 {
1255 return GetFoodStage().GetFoodStageType();
1256 }
1257
1258 //food stage states
1259 bool IsFoodRaw()
1260 {
1261 if (GetFoodStage())
1262 return GetFoodStage().IsFoodRaw();
1263
1264 return false;
1265 }
1266
1267 bool IsFoodBaked()
1268 {
1269 if (GetFoodStage())
1270 return GetFoodStage().IsFoodBaked();
1271
1272 return false;
1273 }
1274
1275 bool IsFoodBoiled()
1276 {
1277 if (GetFoodStage())
1278 return GetFoodStage().IsFoodBoiled();
1279
1280 return false;
1281 }
1282
1283 bool IsFoodDried()
1284 {
1285 if (GetFoodStage())
1286 return GetFoodStage().IsFoodDried();
1287
1288 return false;
1289 }
1290
1291 bool IsFoodBurned()
1292 {
1293 if (GetFoodStage())
1294 return GetFoodStage().IsFoodBurned();
1295
1296 return false;
1297 }
1298
1299 bool IsFoodRotten()
1300 {
1301 if (GetFoodStage())
1302 return GetFoodStage().IsFoodRotten();
1303
1304 return false;
1305 }
1306
1307 //food stage change
1309 {
1310 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1311 }
1312
1314 {
1315 return GetFoodStage().GetNextFoodStageType(cooking_method);
1316 }
1317
1319 {
1320 return GetFoodStage().GetFoodStageName(food_stage_type);
1321 }
1322
1324 {
1325 return GetFoodStage().CanChangeToNewStage(cooking_method);
1326 }
1327
1328 //Use this to receive food stage from another Edible_Base
1330 {
1331 if (!source.HasFoodStage())
1332 return;
1333 m_LastDecayStage = source.GetLastDecayStage();
1334 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1335 m_DecayTimer = source.GetDecayTimer();
1336 m_DecayDelta = source.GetDecayDelta();
1337 }
1338
1339 //================================================================
1340 // COOKING
1341 //================================================================
1342 //cooking time
1343 float GetCookingTime()
1344 {
1345 return GetFoodStage().GetCookingTime();
1346 }
1347
1348 void SetCookingTime(float time)
1349 {
1350 GetFoodStage().SetCookingTime(time);
1351
1352 //synchronize when calling on server
1353 Synchronize();
1354 }
1355
1356 //replace edible with new item (opening cans)
1357 void ReplaceEdibleWithNew(string typeName)
1358 {
1359 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1360 if (player)
1361 {
1363 player.ServerReplaceItemInHandsWithNew(lambda);
1364 }
1365 else
1366 Error("ReplaceEdibleWithNew - cannot use edible without player");
1367 }
1368
1369 override void SetActions()
1370 {
1371 super.SetActions();
1372
1373 AddAction(ActionAttach);
1375 }
1376
1377 protected void SoundCookingStart(string sound_name)
1378 {
1379#ifndef SERVER
1381 {
1383
1386 }
1387#endif
1388 }
1389
1390 protected void SoundCookingStop()
1391 {
1392#ifndef SERVER
1394 {
1397 m_SoundPlaying = "";
1398 }
1399#endif
1400 }
1401
1402 override bool CanHaveTemperature()
1403 {
1404 return true;
1405 }
1406
1407 override bool CanDecay()
1408 {
1409 return false;
1410 }
1411
1412 override bool CanProcessDecay()
1413 {
1414 return (GetFoodStageType() != FoodStageType.ROTTEN);
1415 }
1416
1417 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1418 {
1419 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1420 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1421 if (hasRootAsPlayer)
1423
1424 /*Print( "-------------------------" );
1425 Print( this );
1426 Print( m_DecayTimer );
1427 Print( m_DecayDelta );
1428 Print( m_LastDecayStage );*/
1429
1430 if (IsFruit() || IsMushroom())
1431 {
1432 // fruit, vegetables and mushrooms
1434 {
1435 switch (GetFoodStageType())
1436 {
1437 case FoodStageType.RAW:
1440 break;
1441
1442 case FoodStageType.BOILED:
1445 break;
1446
1447 case FoodStageType.BAKED:
1450 break;
1451
1452 case FoodStageType.DRIED:
1453 case FoodStageType.BURNED:
1454 case FoodStageType.ROTTEN:
1455 default:
1456 m_DecayTimer = -1;
1458 return;
1459 }
1460
1461 //m_DecayTimer = m_DecayTimer / 1000.0;
1462 }
1463
1465
1466 if (m_DecayTimer <= 0)
1467 {
1468 if (m_LastDecayStage != FoodStageType.NONE)
1469 {
1470 // switch to decayed stage
1471 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1474 {
1475 int rng = Math.RandomIntInclusive(0, 100);
1478 else
1479 {
1482 else
1484 }
1485 }
1486 }
1487 }
1488
1489 }
1490 else if (IsMeat())
1491 {
1492 // meat
1494 {
1495 switch (GetFoodStageType())
1496 {
1497 case FoodStageType.RAW:
1500 break;
1501
1502 case FoodStageType.BOILED:
1505 break;
1506
1507 case FoodStageType.BAKED:
1510 break;
1511
1512 case FoodStageType.DRIED:
1515 break;
1516
1517 case FoodStageType.BURNED:
1518 case FoodStageType.ROTTEN:
1519 default:
1520 m_DecayTimer = -1;
1522 return;
1523 }
1524 }
1525
1527
1528 if (m_DecayTimer <= 0)
1529 {
1530 if (m_LastDecayStage != FoodStageType.NONE)
1531 {
1532 // switch to decayed stage
1535 }
1536 }
1537 }
1538 else if (IsCorpse())
1539 {
1540 // corpse
1542 {
1543 switch (GetFoodStageType())
1544 {
1545 case FoodStageType.RAW:
1548 break;
1549
1550 case FoodStageType.BURNED:
1551 case FoodStageType.ROTTEN:
1552 default:
1553 m_DecayTimer = -1;
1555 return;
1556 }
1557 }
1558
1560
1561 if (m_DecayTimer <= 0)
1562 {
1563 if (m_LastDecayStage != FoodStageType.NONE)
1564 {
1565 // switch to decayed stage
1568 }
1569 }
1570 }
1571 else
1572 {
1573 // opened cans
1575
1576 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1577 {
1580 //m_DecayTimer = m_DecayTimer / 1000.0;
1581 }
1582 else
1583 {
1584 if (m_DecayTimer <= 0)
1585 {
1586 InsertAgent(eAgents.FOOD_POISON, 1);
1587 m_DecayTimer = -1;
1588 }
1589 }
1590 }
1591
1592 m_DecayDelta = 0.0;
1593 }
1594
1596 {
1597 super.GetDebugActions(outputList);
1598
1599 if (HasFoodStage())
1600 {
1601 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1602 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1603 }
1604 }
1605
1606 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1607 {
1608 super.OnAction(action_id, player, ctx);
1609
1610 if (GetGame().IsServer())
1611 {
1612 if (action_id == EActions.FOOD_STAGE_PREV)
1613 {
1615 if (food_stage_prev <= 0)
1616 food_stage_prev = FoodStageType.COUNT - 1;
1618 return true;
1619 }
1620 else if (action_id == EActions.FOOD_STAGE_NEXT)
1621 {
1623 if (food_stage_next >= FoodStageType.COUNT)
1626 return true;
1627 }
1628 }
1629 return false;
1630 }
1631
1632 override string GetDebugText()
1633 {
1634 string debug_output;
1635
1636 debug_output = super.GetDebugText();
1637
1638 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1639 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1640
1641 return debug_output;
1642 }
1643
1644 //================================================================
1645 // GENERAL GETTERS
1646 //================================================================
1647
1648 float GetDecayTimer()
1649 {
1650 return m_DecayTimer;
1651 }
1652
1653 float GetDecayDelta()
1654 {
1655 return m_DecayDelta;
1656 }
1657
1659 {
1660 return m_LastDecayStage;
1661 }
1662}
1663
1665{
1667};

◆ ReplaceEdibleWithNew()

void ReplaceEdibleWithNewLambda::ReplaceEdibleWithNew ( string typeName)
protected

Definition at line 1193 of file Edible_Base.c.

1193 : ItemBase
1194{
1195 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1196
1197 const string SOUND_BAKING_START = "Baking_SoundSet";
1198 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1199 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1200
1201 protected bool m_MakeCookingSounds;
1202 protected SoundOnVehicle m_SoundCooking;
1204 protected string m_SoundPlaying;
1206 protected float m_DecayTimer;
1207 protected float m_DecayDelta = 0.0;
1209
1211
1212 void Edible_Base()
1213 {
1214 if (HasFoodStage())
1215 {
1216 m_FoodStage = new FoodStage(this);
1217
1218 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1219 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1220 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1221 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1222 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1223
1224 m_SoundPlaying = "";
1226 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1227 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1228 }
1229 }
1230
1231 override void EEInit()
1232 {
1233 super.EEInit();
1234
1235 UpdateVisuals();
1236 }
1237
1238 override void EEDelete(EntityAI parent)
1239 {
1240 super.EEDelete(parent);
1241
1242 RemoveAudio();
1243 }
1244
1246 {
1247 super.EEItemLocationChanged(oldLoc, newLoc);
1248
1250 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1251 {
1252 switch (oldLoc.GetParent().GetType())
1253 {
1254 case "FryingPan":
1255 case "Pot":
1256 case "Cauldron":
1257 case "SharpWoodenStick":
1258 MakeSoundsOnClient(false);
1259 break;
1260 }
1261
1263 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1264 MakeSoundsOnClient(false);
1265 }
1266 }
1267
1268 void UpdateVisuals()
1269 {
1270 if (GetFoodStage())
1271 GetFoodStage().UpdateVisuals();
1272 }
1273
1274 bool Consume(float amount, PlayerBase consumer)
1275 {
1276 AddQuantity(-amount, false, false);
1277 OnConsume(amount, consumer);
1278
1279 return true;
1280 }
1281
1282 void OnConsume(float amount, PlayerBase consumer);
1283
1284 //food staging
1285 override bool CanBeCooked()
1286 {
1287 return false;
1288 }
1289
1290 override bool CanBeCookedOnStick()
1291 {
1292 return false;
1293 }
1294
1295 //================================================================
1296 // SYNCHRONIZATION
1297 //================================================================
1298 void Synchronize()
1299 {
1300 SetSynchDirty();
1301
1302 if (GetGame().IsMultiplayer())
1303 UpdateVisuals();
1304 }
1305
1306 override void OnVariablesSynchronized()
1307 {
1308 super.OnVariablesSynchronized();
1309
1310 UpdateVisuals();
1311
1312 //update audio
1314 RefreshAudio();
1315 else
1316 RemoveAudio();
1317 }
1318
1319 //================================================================
1320 // AUDIO EFFECTS (WHEN ON DCS)
1321 //================================================================
1323 {
1326
1327 Synchronize();
1328 }
1329
1330 protected void RefreshAudio()
1331 {
1332 string soundName = "";
1333
1335
1336 switch (GetFoodStageType())
1337 {
1338 case FoodStageType.RAW:
1340 if (nextFoodState == FoodStageType.BOILED)
1341 soundName = "";
1342 break;
1343 case FoodStageType.BAKED:
1345 break;
1346 case FoodStageType.BURNED:
1348 break;
1349 default:
1350 soundName = "";
1351 break;
1352 }
1353
1355 }
1356
1357 protected void RemoveAudio()
1358 {
1359 m_MakeCookingSounds = false;
1361 }
1362
1363 //================================================================
1364 // SERIALIZATION
1365 //================================================================
1366 override void OnStoreSave(ParamsWriteContext ctx)
1367 {
1368 super.OnStoreSave(ctx);
1369
1370 if (GetFoodStage())
1371 GetFoodStage().OnStoreSave(ctx);
1372
1373 // food decay
1374 ctx.Write(m_DecayTimer);
1375 ctx.Write(m_LastDecayStage);
1376 }
1377
1378 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1379 {
1380 if (!super.OnStoreLoad(ctx, version))
1381 return false;
1382
1383 if (GetFoodStage())
1384 {
1385 if (!GetFoodStage().OnStoreLoad(ctx, version))
1386 return false;
1387 }
1388
1389 if (version >= 115)
1390 {
1391 if (!ctx.Read(m_DecayTimer))
1392 {
1393 m_DecayTimer = 0.0;
1394 return false;
1395 }
1396 if (!ctx.Read(m_LastDecayStage))
1397 {
1399 return false;
1400 }
1401 }
1402
1403 return true;
1404 }
1405
1406 override void AfterStoreLoad()
1407 {
1408 super.AfterStoreLoad();
1409
1410 Synchronize();
1411 }
1412
1413 //get food stage
1415 {
1416 return m_FoodStage;
1417 }
1418
1419 //food types
1420 override bool IsMeat()
1421 {
1422 return false;
1423 }
1424
1425 override bool IsCorpse()
1426 {
1427 return false;
1428 }
1429
1430 override bool IsFruit()
1431 {
1432 return false;
1433 }
1434
1435 override bool IsMushroom()
1436 {
1437 return false;
1438 }
1439
1440 //================================================================
1441 // NUTRITIONAL VALUES
1442 //================================================================
1443 //food properties
1444 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1445 {
1447 if (food_item && food_item.GetFoodStage())
1448 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1449 else if (classname != "" && food_stage)
1450 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1451 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1452 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1453
1454 }
1455
1456 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1457 {
1459 if (food_item && food_item.GetFoodStage())
1460 return FoodStage.GetEnergy(food_item.GetFoodStage());
1461 else if (classname != "" && food_stage)
1462 return FoodStage.GetEnergy(null, food_stage, classname);
1463 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1464 return GetGame().ConfigGetFloat(class_path + " energy");
1465 }
1466
1467 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1468 {
1470 if (food_item && food_item.GetFoodStage())
1471 return FoodStage.GetWater(food_item.GetFoodStage());
1472 else if (classname != "" && food_stage)
1473 return FoodStage.GetWater(null, food_stage, classname);
1474 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1475 return GetGame().ConfigGetFloat(class_path + " water");
1476 }
1477
1478 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1479 {
1481 if (food_item && food_item.GetFoodStage())
1482 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1483 else if (classname != "" && food_stage)
1484 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1485 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1486 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1487
1488 }
1489
1490 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1491 {
1493 if (food_item && food_item.GetFoodStage())
1494 return FoodStage.GetToxicity(food_item.GetFoodStage());
1495 else if (classname != "" && food_stage)
1496 return FoodStage.GetToxicity(null, food_stage, classname);
1497 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1498 return GetGame().ConfigGetFloat(class_path + " toxicity");
1499 }
1500
1501 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1502 {
1504 if (food_item && food_item.GetFoodStage())
1505 return FoodStage.GetAgents(food_item.GetFoodStage());
1506 else if (classname != "" && food_stage)
1507 return FoodStage.GetAgents(null, food_stage, classname);
1508 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1509 return GetGame().ConfigGetInt(class_path + " agents");
1510 }
1511
1512 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1513 {
1515 if (food_item && food_item.GetFoodStage())
1516 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1517 else if (classname != "" && food_stage)
1518 return FoodStage.GetDigestibility(null, food_stage, classname);
1519 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1520 return GetGame().ConfigGetInt(class_path + " digestibility");
1521 }
1522
1524 {
1526 }
1527
1528 //================================================================
1529 // FOOD STAGING
1530 //================================================================
1532 {
1533 return GetFoodStage().GetFoodStageType();
1534 }
1535
1536 //food stage states
1537 bool IsFoodRaw()
1538 {
1539 if (GetFoodStage())
1540 return GetFoodStage().IsFoodRaw();
1541
1542 return false;
1543 }
1544
1545 bool IsFoodBaked()
1546 {
1547 if (GetFoodStage())
1548 return GetFoodStage().IsFoodBaked();
1549
1550 return false;
1551 }
1552
1553 bool IsFoodBoiled()
1554 {
1555 if (GetFoodStage())
1556 return GetFoodStage().IsFoodBoiled();
1557
1558 return false;
1559 }
1560
1561 bool IsFoodDried()
1562 {
1563 if (GetFoodStage())
1564 return GetFoodStage().IsFoodDried();
1565
1566 return false;
1567 }
1568
1569 bool IsFoodBurned()
1570 {
1571 if (GetFoodStage())
1572 return GetFoodStage().IsFoodBurned();
1573
1574 return false;
1575 }
1576
1577 bool IsFoodRotten()
1578 {
1579 if (GetFoodStage())
1580 return GetFoodStage().IsFoodRotten();
1581
1582 return false;
1583 }
1584
1585 //food stage change
1587 {
1588 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1589 }
1590
1592 {
1593 return GetFoodStage().GetNextFoodStageType(cooking_method);
1594 }
1595
1597 {
1598 return GetFoodStage().GetFoodStageName(food_stage_type);
1599 }
1600
1602 {
1603 return GetFoodStage().CanChangeToNewStage(cooking_method);
1604 }
1605
1606 //Use this to receive food stage from another Edible_Base
1608 {
1609 if (!source.HasFoodStage())
1610 return;
1611 m_LastDecayStage = source.GetLastDecayStage();
1612 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1613 m_DecayTimer = source.GetDecayTimer();
1614 m_DecayDelta = source.GetDecayDelta();
1615 }
1616
1617 //================================================================
1618 // COOKING
1619 //================================================================
1620 //cooking time
1621 float GetCookingTime()
1622 {
1623 return GetFoodStage().GetCookingTime();
1624 }
1625
1626 void SetCookingTime(float time)
1627 {
1628 GetFoodStage().SetCookingTime(time);
1629
1630 //synchronize when calling on server
1631 Synchronize();
1632 }
1633
1634 //replace edible with new item (opening cans)
1635 void ReplaceEdibleWithNew(string typeName)
1636 {
1637 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1638 if (player)
1639 {
1641 player.ServerReplaceItemInHandsWithNew(lambda);
1642 }
1643 else
1644 Error("ReplaceEdibleWithNew - cannot use edible without player");
1645 }
1646
1647 override void SetActions()
1648 {
1649 super.SetActions();
1650
1651 AddAction(ActionAttach);
1653 }
1654
1655 protected void SoundCookingStart(string sound_name)
1656 {
1657#ifndef SERVER
1659 {
1661
1664 }
1665#endif
1666 }
1667
1668 protected void SoundCookingStop()
1669 {
1670#ifndef SERVER
1672 {
1675 m_SoundPlaying = "";
1676 }
1677#endif
1678 }
1679
1680 override bool CanHaveTemperature()
1681 {
1682 return true;
1683 }
1684
1685 override bool CanDecay()
1686 {
1687 return false;
1688 }
1689
1690 override bool CanProcessDecay()
1691 {
1692 return (GetFoodStageType() != FoodStageType.ROTTEN);
1693 }
1694
1695 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1696 {
1697 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1698 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1699 if (hasRootAsPlayer)
1701
1702 /*Print( "-------------------------" );
1703 Print( this );
1704 Print( m_DecayTimer );
1705 Print( m_DecayDelta );
1706 Print( m_LastDecayStage );*/
1707
1708 if (IsFruit() || IsMushroom())
1709 {
1710 // fruit, vegetables and mushrooms
1712 {
1713 switch (GetFoodStageType())
1714 {
1715 case FoodStageType.RAW:
1718 break;
1719
1720 case FoodStageType.BOILED:
1723 break;
1724
1725 case FoodStageType.BAKED:
1728 break;
1729
1730 case FoodStageType.DRIED:
1731 case FoodStageType.BURNED:
1732 case FoodStageType.ROTTEN:
1733 default:
1734 m_DecayTimer = -1;
1736 return;
1737 }
1738
1739 //m_DecayTimer = m_DecayTimer / 1000.0;
1740 }
1741
1743
1744 if (m_DecayTimer <= 0)
1745 {
1746 if (m_LastDecayStage != FoodStageType.NONE)
1747 {
1748 // switch to decayed stage
1749 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1752 {
1753 int rng = Math.RandomIntInclusive(0, 100);
1756 else
1757 {
1760 else
1762 }
1763 }
1764 }
1765 }
1766
1767 }
1768 else if (IsMeat())
1769 {
1770 // meat
1772 {
1773 switch (GetFoodStageType())
1774 {
1775 case FoodStageType.RAW:
1778 break;
1779
1780 case FoodStageType.BOILED:
1783 break;
1784
1785 case FoodStageType.BAKED:
1788 break;
1789
1790 case FoodStageType.DRIED:
1793 break;
1794
1795 case FoodStageType.BURNED:
1796 case FoodStageType.ROTTEN:
1797 default:
1798 m_DecayTimer = -1;
1800 return;
1801 }
1802 }
1803
1805
1806 if (m_DecayTimer <= 0)
1807 {
1808 if (m_LastDecayStage != FoodStageType.NONE)
1809 {
1810 // switch to decayed stage
1813 }
1814 }
1815 }
1816 else if (IsCorpse())
1817 {
1818 // corpse
1820 {
1821 switch (GetFoodStageType())
1822 {
1823 case FoodStageType.RAW:
1826 break;
1827
1828 case FoodStageType.BURNED:
1829 case FoodStageType.ROTTEN:
1830 default:
1831 m_DecayTimer = -1;
1833 return;
1834 }
1835 }
1836
1838
1839 if (m_DecayTimer <= 0)
1840 {
1841 if (m_LastDecayStage != FoodStageType.NONE)
1842 {
1843 // switch to decayed stage
1846 }
1847 }
1848 }
1849 else
1850 {
1851 // opened cans
1853
1854 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1855 {
1858 //m_DecayTimer = m_DecayTimer / 1000.0;
1859 }
1860 else
1861 {
1862 if (m_DecayTimer <= 0)
1863 {
1864 InsertAgent(eAgents.FOOD_POISON, 1);
1865 m_DecayTimer = -1;
1866 }
1867 }
1868 }
1869
1870 m_DecayDelta = 0.0;
1871 }
1872
1874 {
1875 super.GetDebugActions(outputList);
1876
1877 if (HasFoodStage())
1878 {
1879 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1880 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1881 }
1882 }
1883
1884 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1885 {
1886 super.OnAction(action_id, player, ctx);
1887
1888 if (GetGame().IsServer())
1889 {
1890 if (action_id == EActions.FOOD_STAGE_PREV)
1891 {
1893 if (food_stage_prev <= 0)
1894 food_stage_prev = FoodStageType.COUNT - 1;
1896 return true;
1897 }
1898 else if (action_id == EActions.FOOD_STAGE_NEXT)
1899 {
1901 if (food_stage_next >= FoodStageType.COUNT)
1904 return true;
1905 }
1906 }
1907 return false;
1908 }
1909
1910 override string GetDebugText()
1911 {
1912 string debug_output;
1913
1914 debug_output = super.GetDebugText();
1915
1916 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1917 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1918
1919 return debug_output;
1920 }
1921
1922 //================================================================
1923 // GENERAL GETTERS
1924 //================================================================
1925
1926 float GetDecayTimer()
1927 {
1928 return m_DecayTimer;
1929 }
1930
1931 float GetDecayDelta()
1932 {
1933 return m_DecayDelta;
1934 }
1935
1937 {
1938 return m_LastDecayStage;
1939 }
1940}
1941
1943{
1945};

◆ ReplaceEdibleWithNewLambda()

Edible_Base ItemBase ReplaceEdibleWithNewLambda ( EntityAI old_item,
string new_item_type,
PlayerBase player )

Definition at line 1 of file Edible_Base.c.

752{ }

Referenced by Edible_Base::ReplaceEdibleWithNew().

◆ SetActions()

override void ReplaceEdibleWithNewLambda::SetActions ( )
protected

Definition at line 1205 of file Edible_Base.c.

1205 : ItemBase
1206{
1207 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1208
1209 const string SOUND_BAKING_START = "Baking_SoundSet";
1210 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1211 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1212
1213 protected bool m_MakeCookingSounds;
1214 protected SoundOnVehicle m_SoundCooking;
1216 protected string m_SoundPlaying;
1218 protected float m_DecayTimer;
1219 protected float m_DecayDelta = 0.0;
1221
1223
1224 void Edible_Base()
1225 {
1226 if (HasFoodStage())
1227 {
1228 m_FoodStage = new FoodStage(this);
1229
1230 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1231 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1232 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1233 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1234 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1235
1236 m_SoundPlaying = "";
1238 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1239 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1240 }
1241 }
1242
1243 override void EEInit()
1244 {
1245 super.EEInit();
1246
1247 UpdateVisuals();
1248 }
1249
1250 override void EEDelete(EntityAI parent)
1251 {
1252 super.EEDelete(parent);
1253
1254 RemoveAudio();
1255 }
1256
1258 {
1259 super.EEItemLocationChanged(oldLoc, newLoc);
1260
1262 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1263 {
1264 switch (oldLoc.GetParent().GetType())
1265 {
1266 case "FryingPan":
1267 case "Pot":
1268 case "Cauldron":
1269 case "SharpWoodenStick":
1270 MakeSoundsOnClient(false);
1271 break;
1272 }
1273
1275 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1276 MakeSoundsOnClient(false);
1277 }
1278 }
1279
1280 void UpdateVisuals()
1281 {
1282 if (GetFoodStage())
1283 GetFoodStage().UpdateVisuals();
1284 }
1285
1286 bool Consume(float amount, PlayerBase consumer)
1287 {
1288 AddQuantity(-amount, false, false);
1289 OnConsume(amount, consumer);
1290
1291 return true;
1292 }
1293
1294 void OnConsume(float amount, PlayerBase consumer);
1295
1296 //food staging
1297 override bool CanBeCooked()
1298 {
1299 return false;
1300 }
1301
1302 override bool CanBeCookedOnStick()
1303 {
1304 return false;
1305 }
1306
1307 //================================================================
1308 // SYNCHRONIZATION
1309 //================================================================
1310 void Synchronize()
1311 {
1312 SetSynchDirty();
1313
1314 if (GetGame().IsMultiplayer())
1315 UpdateVisuals();
1316 }
1317
1318 override void OnVariablesSynchronized()
1319 {
1320 super.OnVariablesSynchronized();
1321
1322 UpdateVisuals();
1323
1324 //update audio
1326 RefreshAudio();
1327 else
1328 RemoveAudio();
1329 }
1330
1331 //================================================================
1332 // AUDIO EFFECTS (WHEN ON DCS)
1333 //================================================================
1335 {
1338
1339 Synchronize();
1340 }
1341
1342 protected void RefreshAudio()
1343 {
1344 string soundName = "";
1345
1347
1348 switch (GetFoodStageType())
1349 {
1350 case FoodStageType.RAW:
1352 if (nextFoodState == FoodStageType.BOILED)
1353 soundName = "";
1354 break;
1355 case FoodStageType.BAKED:
1357 break;
1358 case FoodStageType.BURNED:
1360 break;
1361 default:
1362 soundName = "";
1363 break;
1364 }
1365
1367 }
1368
1369 protected void RemoveAudio()
1370 {
1371 m_MakeCookingSounds = false;
1373 }
1374
1375 //================================================================
1376 // SERIALIZATION
1377 //================================================================
1378 override void OnStoreSave(ParamsWriteContext ctx)
1379 {
1380 super.OnStoreSave(ctx);
1381
1382 if (GetFoodStage())
1383 GetFoodStage().OnStoreSave(ctx);
1384
1385 // food decay
1386 ctx.Write(m_DecayTimer);
1387 ctx.Write(m_LastDecayStage);
1388 }
1389
1390 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1391 {
1392 if (!super.OnStoreLoad(ctx, version))
1393 return false;
1394
1395 if (GetFoodStage())
1396 {
1397 if (!GetFoodStage().OnStoreLoad(ctx, version))
1398 return false;
1399 }
1400
1401 if (version >= 115)
1402 {
1403 if (!ctx.Read(m_DecayTimer))
1404 {
1405 m_DecayTimer = 0.0;
1406 return false;
1407 }
1408 if (!ctx.Read(m_LastDecayStage))
1409 {
1411 return false;
1412 }
1413 }
1414
1415 return true;
1416 }
1417
1418 override void AfterStoreLoad()
1419 {
1420 super.AfterStoreLoad();
1421
1422 Synchronize();
1423 }
1424
1425 //get food stage
1427 {
1428 return m_FoodStage;
1429 }
1430
1431 //food types
1432 override bool IsMeat()
1433 {
1434 return false;
1435 }
1436
1437 override bool IsCorpse()
1438 {
1439 return false;
1440 }
1441
1442 override bool IsFruit()
1443 {
1444 return false;
1445 }
1446
1447 override bool IsMushroom()
1448 {
1449 return false;
1450 }
1451
1452 //================================================================
1453 // NUTRITIONAL VALUES
1454 //================================================================
1455 //food properties
1456 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1457 {
1459 if (food_item && food_item.GetFoodStage())
1460 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1461 else if (classname != "" && food_stage)
1462 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1463 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1464 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1465
1466 }
1467
1468 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1469 {
1471 if (food_item && food_item.GetFoodStage())
1472 return FoodStage.GetEnergy(food_item.GetFoodStage());
1473 else if (classname != "" && food_stage)
1474 return FoodStage.GetEnergy(null, food_stage, classname);
1475 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1476 return GetGame().ConfigGetFloat(class_path + " energy");
1477 }
1478
1479 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1480 {
1482 if (food_item && food_item.GetFoodStage())
1483 return FoodStage.GetWater(food_item.GetFoodStage());
1484 else if (classname != "" && food_stage)
1485 return FoodStage.GetWater(null, food_stage, classname);
1486 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1487 return GetGame().ConfigGetFloat(class_path + " water");
1488 }
1489
1490 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1491 {
1493 if (food_item && food_item.GetFoodStage())
1494 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1495 else if (classname != "" && food_stage)
1496 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1497 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1498 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1499
1500 }
1501
1502 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1503 {
1505 if (food_item && food_item.GetFoodStage())
1506 return FoodStage.GetToxicity(food_item.GetFoodStage());
1507 else if (classname != "" && food_stage)
1508 return FoodStage.GetToxicity(null, food_stage, classname);
1509 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1510 return GetGame().ConfigGetFloat(class_path + " toxicity");
1511 }
1512
1513 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1514 {
1516 if (food_item && food_item.GetFoodStage())
1517 return FoodStage.GetAgents(food_item.GetFoodStage());
1518 else if (classname != "" && food_stage)
1519 return FoodStage.GetAgents(null, food_stage, classname);
1520 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1521 return GetGame().ConfigGetInt(class_path + " agents");
1522 }
1523
1524 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1525 {
1527 if (food_item && food_item.GetFoodStage())
1528 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1529 else if (classname != "" && food_stage)
1530 return FoodStage.GetDigestibility(null, food_stage, classname);
1531 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1532 return GetGame().ConfigGetInt(class_path + " digestibility");
1533 }
1534
1536 {
1538 }
1539
1540 //================================================================
1541 // FOOD STAGING
1542 //================================================================
1544 {
1545 return GetFoodStage().GetFoodStageType();
1546 }
1547
1548 //food stage states
1549 bool IsFoodRaw()
1550 {
1551 if (GetFoodStage())
1552 return GetFoodStage().IsFoodRaw();
1553
1554 return false;
1555 }
1556
1557 bool IsFoodBaked()
1558 {
1559 if (GetFoodStage())
1560 return GetFoodStage().IsFoodBaked();
1561
1562 return false;
1563 }
1564
1565 bool IsFoodBoiled()
1566 {
1567 if (GetFoodStage())
1568 return GetFoodStage().IsFoodBoiled();
1569
1570 return false;
1571 }
1572
1573 bool IsFoodDried()
1574 {
1575 if (GetFoodStage())
1576 return GetFoodStage().IsFoodDried();
1577
1578 return false;
1579 }
1580
1581 bool IsFoodBurned()
1582 {
1583 if (GetFoodStage())
1584 return GetFoodStage().IsFoodBurned();
1585
1586 return false;
1587 }
1588
1589 bool IsFoodRotten()
1590 {
1591 if (GetFoodStage())
1592 return GetFoodStage().IsFoodRotten();
1593
1594 return false;
1595 }
1596
1597 //food stage change
1599 {
1600 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1601 }
1602
1604 {
1605 return GetFoodStage().GetNextFoodStageType(cooking_method);
1606 }
1607
1609 {
1610 return GetFoodStage().GetFoodStageName(food_stage_type);
1611 }
1612
1614 {
1615 return GetFoodStage().CanChangeToNewStage(cooking_method);
1616 }
1617
1618 //Use this to receive food stage from another Edible_Base
1620 {
1621 if (!source.HasFoodStage())
1622 return;
1623 m_LastDecayStage = source.GetLastDecayStage();
1624 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1625 m_DecayTimer = source.GetDecayTimer();
1626 m_DecayDelta = source.GetDecayDelta();
1627 }
1628
1629 //================================================================
1630 // COOKING
1631 //================================================================
1632 //cooking time
1633 float GetCookingTime()
1634 {
1635 return GetFoodStage().GetCookingTime();
1636 }
1637
1638 void SetCookingTime(float time)
1639 {
1640 GetFoodStage().SetCookingTime(time);
1641
1642 //synchronize when calling on server
1643 Synchronize();
1644 }
1645
1646 //replace edible with new item (opening cans)
1647 void ReplaceEdibleWithNew(string typeName)
1648 {
1649 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1650 if (player)
1651 {
1653 player.ServerReplaceItemInHandsWithNew(lambda);
1654 }
1655 else
1656 Error("ReplaceEdibleWithNew - cannot use edible without player");
1657 }
1658
1659 override void SetActions()
1660 {
1661 super.SetActions();
1662
1663 AddAction(ActionAttach);
1665 }
1666
1667 protected void SoundCookingStart(string sound_name)
1668 {
1669#ifndef SERVER
1671 {
1673
1676 }
1677#endif
1678 }
1679
1680 protected void SoundCookingStop()
1681 {
1682#ifndef SERVER
1684 {
1687 m_SoundPlaying = "";
1688 }
1689#endif
1690 }
1691
1692 override bool CanHaveTemperature()
1693 {
1694 return true;
1695 }
1696
1697 override bool CanDecay()
1698 {
1699 return false;
1700 }
1701
1702 override bool CanProcessDecay()
1703 {
1704 return (GetFoodStageType() != FoodStageType.ROTTEN);
1705 }
1706
1707 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1708 {
1709 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1710 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1711 if (hasRootAsPlayer)
1713
1714 /*Print( "-------------------------" );
1715 Print( this );
1716 Print( m_DecayTimer );
1717 Print( m_DecayDelta );
1718 Print( m_LastDecayStage );*/
1719
1720 if (IsFruit() || IsMushroom())
1721 {
1722 // fruit, vegetables and mushrooms
1724 {
1725 switch (GetFoodStageType())
1726 {
1727 case FoodStageType.RAW:
1730 break;
1731
1732 case FoodStageType.BOILED:
1735 break;
1736
1737 case FoodStageType.BAKED:
1740 break;
1741
1742 case FoodStageType.DRIED:
1743 case FoodStageType.BURNED:
1744 case FoodStageType.ROTTEN:
1745 default:
1746 m_DecayTimer = -1;
1748 return;
1749 }
1750
1751 //m_DecayTimer = m_DecayTimer / 1000.0;
1752 }
1753
1755
1756 if (m_DecayTimer <= 0)
1757 {
1758 if (m_LastDecayStage != FoodStageType.NONE)
1759 {
1760 // switch to decayed stage
1761 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1764 {
1765 int rng = Math.RandomIntInclusive(0, 100);
1768 else
1769 {
1772 else
1774 }
1775 }
1776 }
1777 }
1778
1779 }
1780 else if (IsMeat())
1781 {
1782 // meat
1784 {
1785 switch (GetFoodStageType())
1786 {
1787 case FoodStageType.RAW:
1790 break;
1791
1792 case FoodStageType.BOILED:
1795 break;
1796
1797 case FoodStageType.BAKED:
1800 break;
1801
1802 case FoodStageType.DRIED:
1805 break;
1806
1807 case FoodStageType.BURNED:
1808 case FoodStageType.ROTTEN:
1809 default:
1810 m_DecayTimer = -1;
1812 return;
1813 }
1814 }
1815
1817
1818 if (m_DecayTimer <= 0)
1819 {
1820 if (m_LastDecayStage != FoodStageType.NONE)
1821 {
1822 // switch to decayed stage
1825 }
1826 }
1827 }
1828 else if (IsCorpse())
1829 {
1830 // corpse
1832 {
1833 switch (GetFoodStageType())
1834 {
1835 case FoodStageType.RAW:
1838 break;
1839
1840 case FoodStageType.BURNED:
1841 case FoodStageType.ROTTEN:
1842 default:
1843 m_DecayTimer = -1;
1845 return;
1846 }
1847 }
1848
1850
1851 if (m_DecayTimer <= 0)
1852 {
1853 if (m_LastDecayStage != FoodStageType.NONE)
1854 {
1855 // switch to decayed stage
1858 }
1859 }
1860 }
1861 else
1862 {
1863 // opened cans
1865
1866 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1867 {
1870 //m_DecayTimer = m_DecayTimer / 1000.0;
1871 }
1872 else
1873 {
1874 if (m_DecayTimer <= 0)
1875 {
1876 InsertAgent(eAgents.FOOD_POISON, 1);
1877 m_DecayTimer = -1;
1878 }
1879 }
1880 }
1881
1882 m_DecayDelta = 0.0;
1883 }
1884
1886 {
1887 super.GetDebugActions(outputList);
1888
1889 if (HasFoodStage())
1890 {
1891 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1892 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1893 }
1894 }
1895
1896 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1897 {
1898 super.OnAction(action_id, player, ctx);
1899
1900 if (GetGame().IsServer())
1901 {
1902 if (action_id == EActions.FOOD_STAGE_PREV)
1903 {
1905 if (food_stage_prev <= 0)
1906 food_stage_prev = FoodStageType.COUNT - 1;
1908 return true;
1909 }
1910 else if (action_id == EActions.FOOD_STAGE_NEXT)
1911 {
1913 if (food_stage_next >= FoodStageType.COUNT)
1916 return true;
1917 }
1918 }
1919 return false;
1920 }
1921
1922 override string GetDebugText()
1923 {
1924 string debug_output;
1925
1926 debug_output = super.GetDebugText();
1927
1928 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1929 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1930
1931 return debug_output;
1932 }
1933
1934 //================================================================
1935 // GENERAL GETTERS
1936 //================================================================
1937
1938 float GetDecayTimer()
1939 {
1940 return m_DecayTimer;
1941 }
1942
1943 float GetDecayDelta()
1944 {
1945 return m_DecayDelta;
1946 }
1947
1949 {
1950 return m_LastDecayStage;
1951 }
1952}
1953
1955{
1957};

◆ SetCookingTime()

void ReplaceEdibleWithNewLambda::SetCookingTime ( float time)
protected

Definition at line 1184 of file Edible_Base.c.

1184 : ItemBase
1185{
1186 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1187
1188 const string SOUND_BAKING_START = "Baking_SoundSet";
1189 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1190 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1191
1192 protected bool m_MakeCookingSounds;
1193 protected SoundOnVehicle m_SoundCooking;
1195 protected string m_SoundPlaying;
1197 protected float m_DecayTimer;
1198 protected float m_DecayDelta = 0.0;
1200
1202
1203 void Edible_Base()
1204 {
1205 if (HasFoodStage())
1206 {
1207 m_FoodStage = new FoodStage(this);
1208
1209 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1210 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1211 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1212 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1213 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1214
1215 m_SoundPlaying = "";
1217 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1218 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1219 }
1220 }
1221
1222 override void EEInit()
1223 {
1224 super.EEInit();
1225
1226 UpdateVisuals();
1227 }
1228
1229 override void EEDelete(EntityAI parent)
1230 {
1231 super.EEDelete(parent);
1232
1233 RemoveAudio();
1234 }
1235
1237 {
1238 super.EEItemLocationChanged(oldLoc, newLoc);
1239
1241 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1242 {
1243 switch (oldLoc.GetParent().GetType())
1244 {
1245 case "FryingPan":
1246 case "Pot":
1247 case "Cauldron":
1248 case "SharpWoodenStick":
1249 MakeSoundsOnClient(false);
1250 break;
1251 }
1252
1254 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1255 MakeSoundsOnClient(false);
1256 }
1257 }
1258
1259 void UpdateVisuals()
1260 {
1261 if (GetFoodStage())
1262 GetFoodStage().UpdateVisuals();
1263 }
1264
1265 bool Consume(float amount, PlayerBase consumer)
1266 {
1267 AddQuantity(-amount, false, false);
1268 OnConsume(amount, consumer);
1269
1270 return true;
1271 }
1272
1273 void OnConsume(float amount, PlayerBase consumer);
1274
1275 //food staging
1276 override bool CanBeCooked()
1277 {
1278 return false;
1279 }
1280
1281 override bool CanBeCookedOnStick()
1282 {
1283 return false;
1284 }
1285
1286 //================================================================
1287 // SYNCHRONIZATION
1288 //================================================================
1289 void Synchronize()
1290 {
1291 SetSynchDirty();
1292
1293 if (GetGame().IsMultiplayer())
1294 UpdateVisuals();
1295 }
1296
1297 override void OnVariablesSynchronized()
1298 {
1299 super.OnVariablesSynchronized();
1300
1301 UpdateVisuals();
1302
1303 //update audio
1305 RefreshAudio();
1306 else
1307 RemoveAudio();
1308 }
1309
1310 //================================================================
1311 // AUDIO EFFECTS (WHEN ON DCS)
1312 //================================================================
1314 {
1317
1318 Synchronize();
1319 }
1320
1321 protected void RefreshAudio()
1322 {
1323 string soundName = "";
1324
1326
1327 switch (GetFoodStageType())
1328 {
1329 case FoodStageType.RAW:
1331 if (nextFoodState == FoodStageType.BOILED)
1332 soundName = "";
1333 break;
1334 case FoodStageType.BAKED:
1336 break;
1337 case FoodStageType.BURNED:
1339 break;
1340 default:
1341 soundName = "";
1342 break;
1343 }
1344
1346 }
1347
1348 protected void RemoveAudio()
1349 {
1350 m_MakeCookingSounds = false;
1352 }
1353
1354 //================================================================
1355 // SERIALIZATION
1356 //================================================================
1357 override void OnStoreSave(ParamsWriteContext ctx)
1358 {
1359 super.OnStoreSave(ctx);
1360
1361 if (GetFoodStage())
1362 GetFoodStage().OnStoreSave(ctx);
1363
1364 // food decay
1365 ctx.Write(m_DecayTimer);
1366 ctx.Write(m_LastDecayStage);
1367 }
1368
1369 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1370 {
1371 if (!super.OnStoreLoad(ctx, version))
1372 return false;
1373
1374 if (GetFoodStage())
1375 {
1376 if (!GetFoodStage().OnStoreLoad(ctx, version))
1377 return false;
1378 }
1379
1380 if (version >= 115)
1381 {
1382 if (!ctx.Read(m_DecayTimer))
1383 {
1384 m_DecayTimer = 0.0;
1385 return false;
1386 }
1387 if (!ctx.Read(m_LastDecayStage))
1388 {
1390 return false;
1391 }
1392 }
1393
1394 return true;
1395 }
1396
1397 override void AfterStoreLoad()
1398 {
1399 super.AfterStoreLoad();
1400
1401 Synchronize();
1402 }
1403
1404 //get food stage
1406 {
1407 return m_FoodStage;
1408 }
1409
1410 //food types
1411 override bool IsMeat()
1412 {
1413 return false;
1414 }
1415
1416 override bool IsCorpse()
1417 {
1418 return false;
1419 }
1420
1421 override bool IsFruit()
1422 {
1423 return false;
1424 }
1425
1426 override bool IsMushroom()
1427 {
1428 return false;
1429 }
1430
1431 //================================================================
1432 // NUTRITIONAL VALUES
1433 //================================================================
1434 //food properties
1435 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1436 {
1438 if (food_item && food_item.GetFoodStage())
1439 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1440 else if (classname != "" && food_stage)
1441 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1442 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1443 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1444
1445 }
1446
1447 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1448 {
1450 if (food_item && food_item.GetFoodStage())
1451 return FoodStage.GetEnergy(food_item.GetFoodStage());
1452 else if (classname != "" && food_stage)
1453 return FoodStage.GetEnergy(null, food_stage, classname);
1454 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1455 return GetGame().ConfigGetFloat(class_path + " energy");
1456 }
1457
1458 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1459 {
1461 if (food_item && food_item.GetFoodStage())
1462 return FoodStage.GetWater(food_item.GetFoodStage());
1463 else if (classname != "" && food_stage)
1464 return FoodStage.GetWater(null, food_stage, classname);
1465 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1466 return GetGame().ConfigGetFloat(class_path + " water");
1467 }
1468
1469 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1470 {
1472 if (food_item && food_item.GetFoodStage())
1473 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1474 else if (classname != "" && food_stage)
1475 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1476 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1477 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1478
1479 }
1480
1481 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1482 {
1484 if (food_item && food_item.GetFoodStage())
1485 return FoodStage.GetToxicity(food_item.GetFoodStage());
1486 else if (classname != "" && food_stage)
1487 return FoodStage.GetToxicity(null, food_stage, classname);
1488 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1489 return GetGame().ConfigGetFloat(class_path + " toxicity");
1490 }
1491
1492 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1493 {
1495 if (food_item && food_item.GetFoodStage())
1496 return FoodStage.GetAgents(food_item.GetFoodStage());
1497 else if (classname != "" && food_stage)
1498 return FoodStage.GetAgents(null, food_stage, classname);
1499 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1500 return GetGame().ConfigGetInt(class_path + " agents");
1501 }
1502
1503 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1504 {
1506 if (food_item && food_item.GetFoodStage())
1507 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1508 else if (classname != "" && food_stage)
1509 return FoodStage.GetDigestibility(null, food_stage, classname);
1510 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1511 return GetGame().ConfigGetInt(class_path + " digestibility");
1512 }
1513
1515 {
1517 }
1518
1519 //================================================================
1520 // FOOD STAGING
1521 //================================================================
1523 {
1524 return GetFoodStage().GetFoodStageType();
1525 }
1526
1527 //food stage states
1528 bool IsFoodRaw()
1529 {
1530 if (GetFoodStage())
1531 return GetFoodStage().IsFoodRaw();
1532
1533 return false;
1534 }
1535
1536 bool IsFoodBaked()
1537 {
1538 if (GetFoodStage())
1539 return GetFoodStage().IsFoodBaked();
1540
1541 return false;
1542 }
1543
1544 bool IsFoodBoiled()
1545 {
1546 if (GetFoodStage())
1547 return GetFoodStage().IsFoodBoiled();
1548
1549 return false;
1550 }
1551
1552 bool IsFoodDried()
1553 {
1554 if (GetFoodStage())
1555 return GetFoodStage().IsFoodDried();
1556
1557 return false;
1558 }
1559
1560 bool IsFoodBurned()
1561 {
1562 if (GetFoodStage())
1563 return GetFoodStage().IsFoodBurned();
1564
1565 return false;
1566 }
1567
1568 bool IsFoodRotten()
1569 {
1570 if (GetFoodStage())
1571 return GetFoodStage().IsFoodRotten();
1572
1573 return false;
1574 }
1575
1576 //food stage change
1578 {
1579 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1580 }
1581
1583 {
1584 return GetFoodStage().GetNextFoodStageType(cooking_method);
1585 }
1586
1588 {
1589 return GetFoodStage().GetFoodStageName(food_stage_type);
1590 }
1591
1593 {
1594 return GetFoodStage().CanChangeToNewStage(cooking_method);
1595 }
1596
1597 //Use this to receive food stage from another Edible_Base
1599 {
1600 if (!source.HasFoodStage())
1601 return;
1602 m_LastDecayStage = source.GetLastDecayStage();
1603 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1604 m_DecayTimer = source.GetDecayTimer();
1605 m_DecayDelta = source.GetDecayDelta();
1606 }
1607
1608 //================================================================
1609 // COOKING
1610 //================================================================
1611 //cooking time
1612 float GetCookingTime()
1613 {
1614 return GetFoodStage().GetCookingTime();
1615 }
1616
1617 void SetCookingTime(float time)
1618 {
1619 GetFoodStage().SetCookingTime(time);
1620
1621 //synchronize when calling on server
1622 Synchronize();
1623 }
1624
1625 //replace edible with new item (opening cans)
1626 void ReplaceEdibleWithNew(string typeName)
1627 {
1628 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1629 if (player)
1630 {
1632 player.ServerReplaceItemInHandsWithNew(lambda);
1633 }
1634 else
1635 Error("ReplaceEdibleWithNew - cannot use edible without player");
1636 }
1637
1638 override void SetActions()
1639 {
1640 super.SetActions();
1641
1642 AddAction(ActionAttach);
1644 }
1645
1646 protected void SoundCookingStart(string sound_name)
1647 {
1648#ifndef SERVER
1650 {
1652
1655 }
1656#endif
1657 }
1658
1659 protected void SoundCookingStop()
1660 {
1661#ifndef SERVER
1663 {
1666 m_SoundPlaying = "";
1667 }
1668#endif
1669 }
1670
1671 override bool CanHaveTemperature()
1672 {
1673 return true;
1674 }
1675
1676 override bool CanDecay()
1677 {
1678 return false;
1679 }
1680
1681 override bool CanProcessDecay()
1682 {
1683 return (GetFoodStageType() != FoodStageType.ROTTEN);
1684 }
1685
1686 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1687 {
1688 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1689 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1690 if (hasRootAsPlayer)
1692
1693 /*Print( "-------------------------" );
1694 Print( this );
1695 Print( m_DecayTimer );
1696 Print( m_DecayDelta );
1697 Print( m_LastDecayStage );*/
1698
1699 if (IsFruit() || IsMushroom())
1700 {
1701 // fruit, vegetables and mushrooms
1703 {
1704 switch (GetFoodStageType())
1705 {
1706 case FoodStageType.RAW:
1709 break;
1710
1711 case FoodStageType.BOILED:
1714 break;
1715
1716 case FoodStageType.BAKED:
1719 break;
1720
1721 case FoodStageType.DRIED:
1722 case FoodStageType.BURNED:
1723 case FoodStageType.ROTTEN:
1724 default:
1725 m_DecayTimer = -1;
1727 return;
1728 }
1729
1730 //m_DecayTimer = m_DecayTimer / 1000.0;
1731 }
1732
1734
1735 if (m_DecayTimer <= 0)
1736 {
1737 if (m_LastDecayStage != FoodStageType.NONE)
1738 {
1739 // switch to decayed stage
1740 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1743 {
1744 int rng = Math.RandomIntInclusive(0, 100);
1747 else
1748 {
1751 else
1753 }
1754 }
1755 }
1756 }
1757
1758 }
1759 else if (IsMeat())
1760 {
1761 // meat
1763 {
1764 switch (GetFoodStageType())
1765 {
1766 case FoodStageType.RAW:
1769 break;
1770
1771 case FoodStageType.BOILED:
1774 break;
1775
1776 case FoodStageType.BAKED:
1779 break;
1780
1781 case FoodStageType.DRIED:
1784 break;
1785
1786 case FoodStageType.BURNED:
1787 case FoodStageType.ROTTEN:
1788 default:
1789 m_DecayTimer = -1;
1791 return;
1792 }
1793 }
1794
1796
1797 if (m_DecayTimer <= 0)
1798 {
1799 if (m_LastDecayStage != FoodStageType.NONE)
1800 {
1801 // switch to decayed stage
1804 }
1805 }
1806 }
1807 else if (IsCorpse())
1808 {
1809 // corpse
1811 {
1812 switch (GetFoodStageType())
1813 {
1814 case FoodStageType.RAW:
1817 break;
1818
1819 case FoodStageType.BURNED:
1820 case FoodStageType.ROTTEN:
1821 default:
1822 m_DecayTimer = -1;
1824 return;
1825 }
1826 }
1827
1829
1830 if (m_DecayTimer <= 0)
1831 {
1832 if (m_LastDecayStage != FoodStageType.NONE)
1833 {
1834 // switch to decayed stage
1837 }
1838 }
1839 }
1840 else
1841 {
1842 // opened cans
1844
1845 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1846 {
1849 //m_DecayTimer = m_DecayTimer / 1000.0;
1850 }
1851 else
1852 {
1853 if (m_DecayTimer <= 0)
1854 {
1855 InsertAgent(eAgents.FOOD_POISON, 1);
1856 m_DecayTimer = -1;
1857 }
1858 }
1859 }
1860
1861 m_DecayDelta = 0.0;
1862 }
1863
1865 {
1866 super.GetDebugActions(outputList);
1867
1868 if (HasFoodStage())
1869 {
1870 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1871 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1872 }
1873 }
1874
1875 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1876 {
1877 super.OnAction(action_id, player, ctx);
1878
1879 if (GetGame().IsServer())
1880 {
1881 if (action_id == EActions.FOOD_STAGE_PREV)
1882 {
1884 if (food_stage_prev <= 0)
1885 food_stage_prev = FoodStageType.COUNT - 1;
1887 return true;
1888 }
1889 else if (action_id == EActions.FOOD_STAGE_NEXT)
1890 {
1892 if (food_stage_next >= FoodStageType.COUNT)
1895 return true;
1896 }
1897 }
1898 return false;
1899 }
1900
1901 override string GetDebugText()
1902 {
1903 string debug_output;
1904
1905 debug_output = super.GetDebugText();
1906
1907 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1908 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1909
1910 return debug_output;
1911 }
1912
1913 //================================================================
1914 // GENERAL GETTERS
1915 //================================================================
1916
1917 float GetDecayTimer()
1918 {
1919 return m_DecayTimer;
1920 }
1921
1922 float GetDecayDelta()
1923 {
1924 return m_DecayDelta;
1925 }
1926
1928 {
1929 return m_LastDecayStage;
1930 }
1931}
1932
1934{
1936};

◆ SoundCookingStart()

void ReplaceEdibleWithNewLambda::SoundCookingStart ( string sound_name)
protected

Definition at line 1213 of file Edible_Base.c.

1213 : ItemBase
1214{
1215 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1216
1217 const string SOUND_BAKING_START = "Baking_SoundSet";
1218 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1219 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1220
1221 protected bool m_MakeCookingSounds;
1222 protected SoundOnVehicle m_SoundCooking;
1224 protected string m_SoundPlaying;
1226 protected float m_DecayTimer;
1227 protected float m_DecayDelta = 0.0;
1229
1231
1232 void Edible_Base()
1233 {
1234 if (HasFoodStage())
1235 {
1236 m_FoodStage = new FoodStage(this);
1237
1238 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1239 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1240 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1241 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1242 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1243
1244 m_SoundPlaying = "";
1246 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1247 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1248 }
1249 }
1250
1251 override void EEInit()
1252 {
1253 super.EEInit();
1254
1255 UpdateVisuals();
1256 }
1257
1258 override void EEDelete(EntityAI parent)
1259 {
1260 super.EEDelete(parent);
1261
1262 RemoveAudio();
1263 }
1264
1266 {
1267 super.EEItemLocationChanged(oldLoc, newLoc);
1268
1270 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1271 {
1272 switch (oldLoc.GetParent().GetType())
1273 {
1274 case "FryingPan":
1275 case "Pot":
1276 case "Cauldron":
1277 case "SharpWoodenStick":
1278 MakeSoundsOnClient(false);
1279 break;
1280 }
1281
1283 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1284 MakeSoundsOnClient(false);
1285 }
1286 }
1287
1288 void UpdateVisuals()
1289 {
1290 if (GetFoodStage())
1291 GetFoodStage().UpdateVisuals();
1292 }
1293
1294 bool Consume(float amount, PlayerBase consumer)
1295 {
1296 AddQuantity(-amount, false, false);
1297 OnConsume(amount, consumer);
1298
1299 return true;
1300 }
1301
1302 void OnConsume(float amount, PlayerBase consumer);
1303
1304 //food staging
1305 override bool CanBeCooked()
1306 {
1307 return false;
1308 }
1309
1310 override bool CanBeCookedOnStick()
1311 {
1312 return false;
1313 }
1314
1315 //================================================================
1316 // SYNCHRONIZATION
1317 //================================================================
1318 void Synchronize()
1319 {
1320 SetSynchDirty();
1321
1322 if (GetGame().IsMultiplayer())
1323 UpdateVisuals();
1324 }
1325
1326 override void OnVariablesSynchronized()
1327 {
1328 super.OnVariablesSynchronized();
1329
1330 UpdateVisuals();
1331
1332 //update audio
1334 RefreshAudio();
1335 else
1336 RemoveAudio();
1337 }
1338
1339 //================================================================
1340 // AUDIO EFFECTS (WHEN ON DCS)
1341 //================================================================
1343 {
1346
1347 Synchronize();
1348 }
1349
1350 protected void RefreshAudio()
1351 {
1352 string soundName = "";
1353
1355
1356 switch (GetFoodStageType())
1357 {
1358 case FoodStageType.RAW:
1360 if (nextFoodState == FoodStageType.BOILED)
1361 soundName = "";
1362 break;
1363 case FoodStageType.BAKED:
1365 break;
1366 case FoodStageType.BURNED:
1368 break;
1369 default:
1370 soundName = "";
1371 break;
1372 }
1373
1375 }
1376
1377 protected void RemoveAudio()
1378 {
1379 m_MakeCookingSounds = false;
1381 }
1382
1383 //================================================================
1384 // SERIALIZATION
1385 //================================================================
1386 override void OnStoreSave(ParamsWriteContext ctx)
1387 {
1388 super.OnStoreSave(ctx);
1389
1390 if (GetFoodStage())
1391 GetFoodStage().OnStoreSave(ctx);
1392
1393 // food decay
1394 ctx.Write(m_DecayTimer);
1395 ctx.Write(m_LastDecayStage);
1396 }
1397
1398 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1399 {
1400 if (!super.OnStoreLoad(ctx, version))
1401 return false;
1402
1403 if (GetFoodStage())
1404 {
1405 if (!GetFoodStage().OnStoreLoad(ctx, version))
1406 return false;
1407 }
1408
1409 if (version >= 115)
1410 {
1411 if (!ctx.Read(m_DecayTimer))
1412 {
1413 m_DecayTimer = 0.0;
1414 return false;
1415 }
1416 if (!ctx.Read(m_LastDecayStage))
1417 {
1419 return false;
1420 }
1421 }
1422
1423 return true;
1424 }
1425
1426 override void AfterStoreLoad()
1427 {
1428 super.AfterStoreLoad();
1429
1430 Synchronize();
1431 }
1432
1433 //get food stage
1435 {
1436 return m_FoodStage;
1437 }
1438
1439 //food types
1440 override bool IsMeat()
1441 {
1442 return false;
1443 }
1444
1445 override bool IsCorpse()
1446 {
1447 return false;
1448 }
1449
1450 override bool IsFruit()
1451 {
1452 return false;
1453 }
1454
1455 override bool IsMushroom()
1456 {
1457 return false;
1458 }
1459
1460 //================================================================
1461 // NUTRITIONAL VALUES
1462 //================================================================
1463 //food properties
1464 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1465 {
1467 if (food_item && food_item.GetFoodStage())
1468 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1469 else if (classname != "" && food_stage)
1470 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1471 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1472 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1473
1474 }
1475
1476 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1477 {
1479 if (food_item && food_item.GetFoodStage())
1480 return FoodStage.GetEnergy(food_item.GetFoodStage());
1481 else if (classname != "" && food_stage)
1482 return FoodStage.GetEnergy(null, food_stage, classname);
1483 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1484 return GetGame().ConfigGetFloat(class_path + " energy");
1485 }
1486
1487 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1488 {
1490 if (food_item && food_item.GetFoodStage())
1491 return FoodStage.GetWater(food_item.GetFoodStage());
1492 else if (classname != "" && food_stage)
1493 return FoodStage.GetWater(null, food_stage, classname);
1494 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1495 return GetGame().ConfigGetFloat(class_path + " water");
1496 }
1497
1498 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1499 {
1501 if (food_item && food_item.GetFoodStage())
1502 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1503 else if (classname != "" && food_stage)
1504 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1505 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1506 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1507
1508 }
1509
1510 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1511 {
1513 if (food_item && food_item.GetFoodStage())
1514 return FoodStage.GetToxicity(food_item.GetFoodStage());
1515 else if (classname != "" && food_stage)
1516 return FoodStage.GetToxicity(null, food_stage, classname);
1517 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1518 return GetGame().ConfigGetFloat(class_path + " toxicity");
1519 }
1520
1521 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1522 {
1524 if (food_item && food_item.GetFoodStage())
1525 return FoodStage.GetAgents(food_item.GetFoodStage());
1526 else if (classname != "" && food_stage)
1527 return FoodStage.GetAgents(null, food_stage, classname);
1528 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1529 return GetGame().ConfigGetInt(class_path + " agents");
1530 }
1531
1532 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1533 {
1535 if (food_item && food_item.GetFoodStage())
1536 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1537 else if (classname != "" && food_stage)
1538 return FoodStage.GetDigestibility(null, food_stage, classname);
1539 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1540 return GetGame().ConfigGetInt(class_path + " digestibility");
1541 }
1542
1544 {
1546 }
1547
1548 //================================================================
1549 // FOOD STAGING
1550 //================================================================
1552 {
1553 return GetFoodStage().GetFoodStageType();
1554 }
1555
1556 //food stage states
1557 bool IsFoodRaw()
1558 {
1559 if (GetFoodStage())
1560 return GetFoodStage().IsFoodRaw();
1561
1562 return false;
1563 }
1564
1565 bool IsFoodBaked()
1566 {
1567 if (GetFoodStage())
1568 return GetFoodStage().IsFoodBaked();
1569
1570 return false;
1571 }
1572
1573 bool IsFoodBoiled()
1574 {
1575 if (GetFoodStage())
1576 return GetFoodStage().IsFoodBoiled();
1577
1578 return false;
1579 }
1580
1581 bool IsFoodDried()
1582 {
1583 if (GetFoodStage())
1584 return GetFoodStage().IsFoodDried();
1585
1586 return false;
1587 }
1588
1589 bool IsFoodBurned()
1590 {
1591 if (GetFoodStage())
1592 return GetFoodStage().IsFoodBurned();
1593
1594 return false;
1595 }
1596
1597 bool IsFoodRotten()
1598 {
1599 if (GetFoodStage())
1600 return GetFoodStage().IsFoodRotten();
1601
1602 return false;
1603 }
1604
1605 //food stage change
1607 {
1608 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1609 }
1610
1612 {
1613 return GetFoodStage().GetNextFoodStageType(cooking_method);
1614 }
1615
1617 {
1618 return GetFoodStage().GetFoodStageName(food_stage_type);
1619 }
1620
1622 {
1623 return GetFoodStage().CanChangeToNewStage(cooking_method);
1624 }
1625
1626 //Use this to receive food stage from another Edible_Base
1628 {
1629 if (!source.HasFoodStage())
1630 return;
1631 m_LastDecayStage = source.GetLastDecayStage();
1632 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1633 m_DecayTimer = source.GetDecayTimer();
1634 m_DecayDelta = source.GetDecayDelta();
1635 }
1636
1637 //================================================================
1638 // COOKING
1639 //================================================================
1640 //cooking time
1641 float GetCookingTime()
1642 {
1643 return GetFoodStage().GetCookingTime();
1644 }
1645
1646 void SetCookingTime(float time)
1647 {
1648 GetFoodStage().SetCookingTime(time);
1649
1650 //synchronize when calling on server
1651 Synchronize();
1652 }
1653
1654 //replace edible with new item (opening cans)
1655 void ReplaceEdibleWithNew(string typeName)
1656 {
1657 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1658 if (player)
1659 {
1661 player.ServerReplaceItemInHandsWithNew(lambda);
1662 }
1663 else
1664 Error("ReplaceEdibleWithNew - cannot use edible without player");
1665 }
1666
1667 override void SetActions()
1668 {
1669 super.SetActions();
1670
1671 AddAction(ActionAttach);
1673 }
1674
1675 protected void SoundCookingStart(string sound_name)
1676 {
1677#ifndef SERVER
1679 {
1681
1684 }
1685#endif
1686 }
1687
1688 protected void SoundCookingStop()
1689 {
1690#ifndef SERVER
1692 {
1695 m_SoundPlaying = "";
1696 }
1697#endif
1698 }
1699
1700 override bool CanHaveTemperature()
1701 {
1702 return true;
1703 }
1704
1705 override bool CanDecay()
1706 {
1707 return false;
1708 }
1709
1710 override bool CanProcessDecay()
1711 {
1712 return (GetFoodStageType() != FoodStageType.ROTTEN);
1713 }
1714
1715 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1716 {
1717 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1718 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1719 if (hasRootAsPlayer)
1721
1722 /*Print( "-------------------------" );
1723 Print( this );
1724 Print( m_DecayTimer );
1725 Print( m_DecayDelta );
1726 Print( m_LastDecayStage );*/
1727
1728 if (IsFruit() || IsMushroom())
1729 {
1730 // fruit, vegetables and mushrooms
1732 {
1733 switch (GetFoodStageType())
1734 {
1735 case FoodStageType.RAW:
1738 break;
1739
1740 case FoodStageType.BOILED:
1743 break;
1744
1745 case FoodStageType.BAKED:
1748 break;
1749
1750 case FoodStageType.DRIED:
1751 case FoodStageType.BURNED:
1752 case FoodStageType.ROTTEN:
1753 default:
1754 m_DecayTimer = -1;
1756 return;
1757 }
1758
1759 //m_DecayTimer = m_DecayTimer / 1000.0;
1760 }
1761
1763
1764 if (m_DecayTimer <= 0)
1765 {
1766 if (m_LastDecayStage != FoodStageType.NONE)
1767 {
1768 // switch to decayed stage
1769 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1772 {
1773 int rng = Math.RandomIntInclusive(0, 100);
1776 else
1777 {
1780 else
1782 }
1783 }
1784 }
1785 }
1786
1787 }
1788 else if (IsMeat())
1789 {
1790 // meat
1792 {
1793 switch (GetFoodStageType())
1794 {
1795 case FoodStageType.RAW:
1798 break;
1799
1800 case FoodStageType.BOILED:
1803 break;
1804
1805 case FoodStageType.BAKED:
1808 break;
1809
1810 case FoodStageType.DRIED:
1813 break;
1814
1815 case FoodStageType.BURNED:
1816 case FoodStageType.ROTTEN:
1817 default:
1818 m_DecayTimer = -1;
1820 return;
1821 }
1822 }
1823
1825
1826 if (m_DecayTimer <= 0)
1827 {
1828 if (m_LastDecayStage != FoodStageType.NONE)
1829 {
1830 // switch to decayed stage
1833 }
1834 }
1835 }
1836 else if (IsCorpse())
1837 {
1838 // corpse
1840 {
1841 switch (GetFoodStageType())
1842 {
1843 case FoodStageType.RAW:
1846 break;
1847
1848 case FoodStageType.BURNED:
1849 case FoodStageType.ROTTEN:
1850 default:
1851 m_DecayTimer = -1;
1853 return;
1854 }
1855 }
1856
1858
1859 if (m_DecayTimer <= 0)
1860 {
1861 if (m_LastDecayStage != FoodStageType.NONE)
1862 {
1863 // switch to decayed stage
1866 }
1867 }
1868 }
1869 else
1870 {
1871 // opened cans
1873
1874 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1875 {
1878 //m_DecayTimer = m_DecayTimer / 1000.0;
1879 }
1880 else
1881 {
1882 if (m_DecayTimer <= 0)
1883 {
1884 InsertAgent(eAgents.FOOD_POISON, 1);
1885 m_DecayTimer = -1;
1886 }
1887 }
1888 }
1889
1890 m_DecayDelta = 0.0;
1891 }
1892
1894 {
1895 super.GetDebugActions(outputList);
1896
1897 if (HasFoodStage())
1898 {
1899 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1900 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1901 }
1902 }
1903
1904 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1905 {
1906 super.OnAction(action_id, player, ctx);
1907
1908 if (GetGame().IsServer())
1909 {
1910 if (action_id == EActions.FOOD_STAGE_PREV)
1911 {
1913 if (food_stage_prev <= 0)
1914 food_stage_prev = FoodStageType.COUNT - 1;
1916 return true;
1917 }
1918 else if (action_id == EActions.FOOD_STAGE_NEXT)
1919 {
1921 if (food_stage_next >= FoodStageType.COUNT)
1924 return true;
1925 }
1926 }
1927 return false;
1928 }
1929
1930 override string GetDebugText()
1931 {
1932 string debug_output;
1933
1934 debug_output = super.GetDebugText();
1935
1936 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1937 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1938
1939 return debug_output;
1940 }
1941
1942 //================================================================
1943 // GENERAL GETTERS
1944 //================================================================
1945
1946 float GetDecayTimer()
1947 {
1948 return m_DecayTimer;
1949 }
1950
1951 float GetDecayDelta()
1952 {
1953 return m_DecayDelta;
1954 }
1955
1957 {
1958 return m_LastDecayStage;
1959 }
1960}
1961
1963{
1965};

Referenced by RefreshAudioVisuals().

◆ SoundCookingStop()

void ReplaceEdibleWithNewLambda::SoundCookingStop ( )
protected

Definition at line 1226 of file Edible_Base.c.

1226 : ItemBase
1227{
1228 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1229
1230 const string SOUND_BAKING_START = "Baking_SoundSet";
1231 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1232 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1233
1234 protected bool m_MakeCookingSounds;
1235 protected SoundOnVehicle m_SoundCooking;
1237 protected string m_SoundPlaying;
1239 protected float m_DecayTimer;
1240 protected float m_DecayDelta = 0.0;
1242
1244
1245 void Edible_Base()
1246 {
1247 if (HasFoodStage())
1248 {
1249 m_FoodStage = new FoodStage(this);
1250
1251 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1252 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1253 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1254 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1255 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1256
1257 m_SoundPlaying = "";
1259 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1260 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1261 }
1262 }
1263
1264 override void EEInit()
1265 {
1266 super.EEInit();
1267
1268 UpdateVisuals();
1269 }
1270
1271 override void EEDelete(EntityAI parent)
1272 {
1273 super.EEDelete(parent);
1274
1275 RemoveAudio();
1276 }
1277
1279 {
1280 super.EEItemLocationChanged(oldLoc, newLoc);
1281
1283 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1284 {
1285 switch (oldLoc.GetParent().GetType())
1286 {
1287 case "FryingPan":
1288 case "Pot":
1289 case "Cauldron":
1290 case "SharpWoodenStick":
1291 MakeSoundsOnClient(false);
1292 break;
1293 }
1294
1296 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1297 MakeSoundsOnClient(false);
1298 }
1299 }
1300
1301 void UpdateVisuals()
1302 {
1303 if (GetFoodStage())
1304 GetFoodStage().UpdateVisuals();
1305 }
1306
1307 bool Consume(float amount, PlayerBase consumer)
1308 {
1309 AddQuantity(-amount, false, false);
1310 OnConsume(amount, consumer);
1311
1312 return true;
1313 }
1314
1315 void OnConsume(float amount, PlayerBase consumer);
1316
1317 //food staging
1318 override bool CanBeCooked()
1319 {
1320 return false;
1321 }
1322
1323 override bool CanBeCookedOnStick()
1324 {
1325 return false;
1326 }
1327
1328 //================================================================
1329 // SYNCHRONIZATION
1330 //================================================================
1331 void Synchronize()
1332 {
1333 SetSynchDirty();
1334
1335 if (GetGame().IsMultiplayer())
1336 UpdateVisuals();
1337 }
1338
1339 override void OnVariablesSynchronized()
1340 {
1341 super.OnVariablesSynchronized();
1342
1343 UpdateVisuals();
1344
1345 //update audio
1347 RefreshAudio();
1348 else
1349 RemoveAudio();
1350 }
1351
1352 //================================================================
1353 // AUDIO EFFECTS (WHEN ON DCS)
1354 //================================================================
1356 {
1359
1360 Synchronize();
1361 }
1362
1363 protected void RefreshAudio()
1364 {
1365 string soundName = "";
1366
1368
1369 switch (GetFoodStageType())
1370 {
1371 case FoodStageType.RAW:
1373 if (nextFoodState == FoodStageType.BOILED)
1374 soundName = "";
1375 break;
1376 case FoodStageType.BAKED:
1378 break;
1379 case FoodStageType.BURNED:
1381 break;
1382 default:
1383 soundName = "";
1384 break;
1385 }
1386
1388 }
1389
1390 protected void RemoveAudio()
1391 {
1392 m_MakeCookingSounds = false;
1394 }
1395
1396 //================================================================
1397 // SERIALIZATION
1398 //================================================================
1399 override void OnStoreSave(ParamsWriteContext ctx)
1400 {
1401 super.OnStoreSave(ctx);
1402
1403 if (GetFoodStage())
1404 GetFoodStage().OnStoreSave(ctx);
1405
1406 // food decay
1407 ctx.Write(m_DecayTimer);
1408 ctx.Write(m_LastDecayStage);
1409 }
1410
1411 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1412 {
1413 if (!super.OnStoreLoad(ctx, version))
1414 return false;
1415
1416 if (GetFoodStage())
1417 {
1418 if (!GetFoodStage().OnStoreLoad(ctx, version))
1419 return false;
1420 }
1421
1422 if (version >= 115)
1423 {
1424 if (!ctx.Read(m_DecayTimer))
1425 {
1426 m_DecayTimer = 0.0;
1427 return false;
1428 }
1429 if (!ctx.Read(m_LastDecayStage))
1430 {
1432 return false;
1433 }
1434 }
1435
1436 return true;
1437 }
1438
1439 override void AfterStoreLoad()
1440 {
1441 super.AfterStoreLoad();
1442
1443 Synchronize();
1444 }
1445
1446 //get food stage
1448 {
1449 return m_FoodStage;
1450 }
1451
1452 //food types
1453 override bool IsMeat()
1454 {
1455 return false;
1456 }
1457
1458 override bool IsCorpse()
1459 {
1460 return false;
1461 }
1462
1463 override bool IsFruit()
1464 {
1465 return false;
1466 }
1467
1468 override bool IsMushroom()
1469 {
1470 return false;
1471 }
1472
1473 //================================================================
1474 // NUTRITIONAL VALUES
1475 //================================================================
1476 //food properties
1477 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1478 {
1480 if (food_item && food_item.GetFoodStage())
1481 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1482 else if (classname != "" && food_stage)
1483 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1484 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1485 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1486
1487 }
1488
1489 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1490 {
1492 if (food_item && food_item.GetFoodStage())
1493 return FoodStage.GetEnergy(food_item.GetFoodStage());
1494 else if (classname != "" && food_stage)
1495 return FoodStage.GetEnergy(null, food_stage, classname);
1496 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1497 return GetGame().ConfigGetFloat(class_path + " energy");
1498 }
1499
1500 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1501 {
1503 if (food_item && food_item.GetFoodStage())
1504 return FoodStage.GetWater(food_item.GetFoodStage());
1505 else if (classname != "" && food_stage)
1506 return FoodStage.GetWater(null, food_stage, classname);
1507 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1508 return GetGame().ConfigGetFloat(class_path + " water");
1509 }
1510
1511 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1512 {
1514 if (food_item && food_item.GetFoodStage())
1515 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1516 else if (classname != "" && food_stage)
1517 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1518 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1519 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1520
1521 }
1522
1523 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1524 {
1526 if (food_item && food_item.GetFoodStage())
1527 return FoodStage.GetToxicity(food_item.GetFoodStage());
1528 else if (classname != "" && food_stage)
1529 return FoodStage.GetToxicity(null, food_stage, classname);
1530 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1531 return GetGame().ConfigGetFloat(class_path + " toxicity");
1532 }
1533
1534 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1535 {
1537 if (food_item && food_item.GetFoodStage())
1538 return FoodStage.GetAgents(food_item.GetFoodStage());
1539 else if (classname != "" && food_stage)
1540 return FoodStage.GetAgents(null, food_stage, classname);
1541 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1542 return GetGame().ConfigGetInt(class_path + " agents");
1543 }
1544
1545 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1546 {
1548 if (food_item && food_item.GetFoodStage())
1549 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1550 else if (classname != "" && food_stage)
1551 return FoodStage.GetDigestibility(null, food_stage, classname);
1552 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1553 return GetGame().ConfigGetInt(class_path + " digestibility");
1554 }
1555
1557 {
1559 }
1560
1561 //================================================================
1562 // FOOD STAGING
1563 //================================================================
1565 {
1566 return GetFoodStage().GetFoodStageType();
1567 }
1568
1569 //food stage states
1570 bool IsFoodRaw()
1571 {
1572 if (GetFoodStage())
1573 return GetFoodStage().IsFoodRaw();
1574
1575 return false;
1576 }
1577
1578 bool IsFoodBaked()
1579 {
1580 if (GetFoodStage())
1581 return GetFoodStage().IsFoodBaked();
1582
1583 return false;
1584 }
1585
1586 bool IsFoodBoiled()
1587 {
1588 if (GetFoodStage())
1589 return GetFoodStage().IsFoodBoiled();
1590
1591 return false;
1592 }
1593
1594 bool IsFoodDried()
1595 {
1596 if (GetFoodStage())
1597 return GetFoodStage().IsFoodDried();
1598
1599 return false;
1600 }
1601
1602 bool IsFoodBurned()
1603 {
1604 if (GetFoodStage())
1605 return GetFoodStage().IsFoodBurned();
1606
1607 return false;
1608 }
1609
1610 bool IsFoodRotten()
1611 {
1612 if (GetFoodStage())
1613 return GetFoodStage().IsFoodRotten();
1614
1615 return false;
1616 }
1617
1618 //food stage change
1620 {
1621 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1622 }
1623
1625 {
1626 return GetFoodStage().GetNextFoodStageType(cooking_method);
1627 }
1628
1630 {
1631 return GetFoodStage().GetFoodStageName(food_stage_type);
1632 }
1633
1635 {
1636 return GetFoodStage().CanChangeToNewStage(cooking_method);
1637 }
1638
1639 //Use this to receive food stage from another Edible_Base
1641 {
1642 if (!source.HasFoodStage())
1643 return;
1644 m_LastDecayStage = source.GetLastDecayStage();
1645 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1646 m_DecayTimer = source.GetDecayTimer();
1647 m_DecayDelta = source.GetDecayDelta();
1648 }
1649
1650 //================================================================
1651 // COOKING
1652 //================================================================
1653 //cooking time
1654 float GetCookingTime()
1655 {
1656 return GetFoodStage().GetCookingTime();
1657 }
1658
1659 void SetCookingTime(float time)
1660 {
1661 GetFoodStage().SetCookingTime(time);
1662
1663 //synchronize when calling on server
1664 Synchronize();
1665 }
1666
1667 //replace edible with new item (opening cans)
1668 void ReplaceEdibleWithNew(string typeName)
1669 {
1670 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1671 if (player)
1672 {
1674 player.ServerReplaceItemInHandsWithNew(lambda);
1675 }
1676 else
1677 Error("ReplaceEdibleWithNew - cannot use edible without player");
1678 }
1679
1680 override void SetActions()
1681 {
1682 super.SetActions();
1683
1684 AddAction(ActionAttach);
1686 }
1687
1688 protected void SoundCookingStart(string sound_name)
1689 {
1690#ifndef SERVER
1692 {
1694
1697 }
1698#endif
1699 }
1700
1701 protected void SoundCookingStop()
1702 {
1703#ifndef SERVER
1705 {
1708 m_SoundPlaying = "";
1709 }
1710#endif
1711 }
1712
1713 override bool CanHaveTemperature()
1714 {
1715 return true;
1716 }
1717
1718 override bool CanDecay()
1719 {
1720 return false;
1721 }
1722
1723 override bool CanProcessDecay()
1724 {
1725 return (GetFoodStageType() != FoodStageType.ROTTEN);
1726 }
1727
1728 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1729 {
1730 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1731 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1732 if (hasRootAsPlayer)
1734
1735 /*Print( "-------------------------" );
1736 Print( this );
1737 Print( m_DecayTimer );
1738 Print( m_DecayDelta );
1739 Print( m_LastDecayStage );*/
1740
1741 if (IsFruit() || IsMushroom())
1742 {
1743 // fruit, vegetables and mushrooms
1745 {
1746 switch (GetFoodStageType())
1747 {
1748 case FoodStageType.RAW:
1751 break;
1752
1753 case FoodStageType.BOILED:
1756 break;
1757
1758 case FoodStageType.BAKED:
1761 break;
1762
1763 case FoodStageType.DRIED:
1764 case FoodStageType.BURNED:
1765 case FoodStageType.ROTTEN:
1766 default:
1767 m_DecayTimer = -1;
1769 return;
1770 }
1771
1772 //m_DecayTimer = m_DecayTimer / 1000.0;
1773 }
1774
1776
1777 if (m_DecayTimer <= 0)
1778 {
1779 if (m_LastDecayStage != FoodStageType.NONE)
1780 {
1781 // switch to decayed stage
1782 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1785 {
1786 int rng = Math.RandomIntInclusive(0, 100);
1789 else
1790 {
1793 else
1795 }
1796 }
1797 }
1798 }
1799
1800 }
1801 else if (IsMeat())
1802 {
1803 // meat
1805 {
1806 switch (GetFoodStageType())
1807 {
1808 case FoodStageType.RAW:
1811 break;
1812
1813 case FoodStageType.BOILED:
1816 break;
1817
1818 case FoodStageType.BAKED:
1821 break;
1822
1823 case FoodStageType.DRIED:
1826 break;
1827
1828 case FoodStageType.BURNED:
1829 case FoodStageType.ROTTEN:
1830 default:
1831 m_DecayTimer = -1;
1833 return;
1834 }
1835 }
1836
1838
1839 if (m_DecayTimer <= 0)
1840 {
1841 if (m_LastDecayStage != FoodStageType.NONE)
1842 {
1843 // switch to decayed stage
1846 }
1847 }
1848 }
1849 else if (IsCorpse())
1850 {
1851 // corpse
1853 {
1854 switch (GetFoodStageType())
1855 {
1856 case FoodStageType.RAW:
1859 break;
1860
1861 case FoodStageType.BURNED:
1862 case FoodStageType.ROTTEN:
1863 default:
1864 m_DecayTimer = -1;
1866 return;
1867 }
1868 }
1869
1871
1872 if (m_DecayTimer <= 0)
1873 {
1874 if (m_LastDecayStage != FoodStageType.NONE)
1875 {
1876 // switch to decayed stage
1879 }
1880 }
1881 }
1882 else
1883 {
1884 // opened cans
1886
1887 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1888 {
1891 //m_DecayTimer = m_DecayTimer / 1000.0;
1892 }
1893 else
1894 {
1895 if (m_DecayTimer <= 0)
1896 {
1897 InsertAgent(eAgents.FOOD_POISON, 1);
1898 m_DecayTimer = -1;
1899 }
1900 }
1901 }
1902
1903 m_DecayDelta = 0.0;
1904 }
1905
1907 {
1908 super.GetDebugActions(outputList);
1909
1910 if (HasFoodStage())
1911 {
1912 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1913 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1914 }
1915 }
1916
1917 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1918 {
1919 super.OnAction(action_id, player, ctx);
1920
1921 if (GetGame().IsServer())
1922 {
1923 if (action_id == EActions.FOOD_STAGE_PREV)
1924 {
1926 if (food_stage_prev <= 0)
1927 food_stage_prev = FoodStageType.COUNT - 1;
1929 return true;
1930 }
1931 else if (action_id == EActions.FOOD_STAGE_NEXT)
1932 {
1934 if (food_stage_next >= FoodStageType.COUNT)
1937 return true;
1938 }
1939 }
1940 return false;
1941 }
1942
1943 override string GetDebugText()
1944 {
1945 string debug_output;
1946
1947 debug_output = super.GetDebugText();
1948
1949 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1950 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1951
1952 return debug_output;
1953 }
1954
1955 //================================================================
1956 // GENERAL GETTERS
1957 //================================================================
1958
1959 float GetDecayTimer()
1960 {
1961 return m_DecayTimer;
1962 }
1963
1964 float GetDecayDelta()
1965 {
1966 return m_DecayDelta;
1967 }
1968
1970 {
1971 return m_LastDecayStage;
1972 }
1973}
1974
1976{
1978};

Referenced by RemoveAudioVisuals().

◆ Synchronize()

void ReplaceEdibleWithNewLambda::Synchronize ( )
private

Definition at line 856 of file Edible_Base.c.

856 : ItemBase
857{
858 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
859
860 const string SOUND_BAKING_START = "Baking_SoundSet";
861 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
862 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
863
864 protected bool m_MakeCookingSounds;
867 protected string m_SoundPlaying;
869 protected float m_DecayTimer;
870 protected float m_DecayDelta = 0.0;
872
874
875 void Edible_Base()
876 {
877 if (HasFoodStage())
878 {
879 m_FoodStage = new FoodStage(this);
880
881 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
882 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
883 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
884 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
885 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
886
887 m_SoundPlaying = "";
889 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
890 RegisterNetSyncVariableBool("m_MakeCookingSounds");
891 }
892 }
893
894 override void EEInit()
895 {
896 super.EEInit();
897
899 }
900
901 override void EEDelete(EntityAI parent)
902 {
903 super.EEDelete(parent);
904
905 RemoveAudio();
906 }
907
909 {
910 super.EEItemLocationChanged(oldLoc, newLoc);
911
913 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
914 {
915 switch (oldLoc.GetParent().GetType())
916 {
917 case "FryingPan":
918 case "Pot":
919 case "Cauldron":
920 case "SharpWoodenStick":
921 MakeSoundsOnClient(false);
922 break;
923 }
924
926 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
927 MakeSoundsOnClient(false);
928 }
929 }
930
931 void UpdateVisuals()
932 {
933 if (GetFoodStage())
934 GetFoodStage().UpdateVisuals();
935 }
936
937 bool Consume(float amount, PlayerBase consumer)
938 {
939 AddQuantity(-amount, false, false);
940 OnConsume(amount, consumer);
941
942 return true;
943 }
944
945 void OnConsume(float amount, PlayerBase consumer);
946
947 //food staging
948 override bool CanBeCooked()
949 {
950 return false;
951 }
952
953 override bool CanBeCookedOnStick()
954 {
955 return false;
956 }
957
958 //================================================================
959 // SYNCHRONIZATION
960 //================================================================
961 void Synchronize()
962 {
963 SetSynchDirty();
964
965 if (GetGame().IsMultiplayer())
967 }
968
969 override void OnVariablesSynchronized()
970 {
971 super.OnVariablesSynchronized();
972
974
975 //update audio
977 RefreshAudio();
978 else
979 RemoveAudio();
980 }
981
982 //================================================================
983 // AUDIO EFFECTS (WHEN ON DCS)
984 //================================================================
986 {
989
990 Synchronize();
991 }
992
993 protected void RefreshAudio()
994 {
995 string soundName = "";
996
998
999 switch (GetFoodStageType())
1000 {
1001 case FoodStageType.RAW:
1003 if (nextFoodState == FoodStageType.BOILED)
1004 soundName = "";
1005 break;
1006 case FoodStageType.BAKED:
1008 break;
1009 case FoodStageType.BURNED:
1011 break;
1012 default:
1013 soundName = "";
1014 break;
1015 }
1016
1018 }
1019
1020 protected void RemoveAudio()
1021 {
1022 m_MakeCookingSounds = false;
1024 }
1025
1026 //================================================================
1027 // SERIALIZATION
1028 //================================================================
1029 override void OnStoreSave(ParamsWriteContext ctx)
1030 {
1031 super.OnStoreSave(ctx);
1032
1033 if (GetFoodStage())
1034 GetFoodStage().OnStoreSave(ctx);
1035
1036 // food decay
1037 ctx.Write(m_DecayTimer);
1038 ctx.Write(m_LastDecayStage);
1039 }
1040
1041 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1042 {
1043 if (!super.OnStoreLoad(ctx, version))
1044 return false;
1045
1046 if (GetFoodStage())
1047 {
1048 if (!GetFoodStage().OnStoreLoad(ctx, version))
1049 return false;
1050 }
1051
1052 if (version >= 115)
1053 {
1054 if (!ctx.Read(m_DecayTimer))
1055 {
1056 m_DecayTimer = 0.0;
1057 return false;
1058 }
1059 if (!ctx.Read(m_LastDecayStage))
1060 {
1062 return false;
1063 }
1064 }
1065
1066 return true;
1067 }
1068
1069 override void AfterStoreLoad()
1070 {
1071 super.AfterStoreLoad();
1072
1073 Synchronize();
1074 }
1075
1076 //get food stage
1078 {
1079 return m_FoodStage;
1080 }
1081
1082 //food types
1083 override bool IsMeat()
1084 {
1085 return false;
1086 }
1087
1088 override bool IsCorpse()
1089 {
1090 return false;
1091 }
1092
1093 override bool IsFruit()
1094 {
1095 return false;
1096 }
1097
1098 override bool IsMushroom()
1099 {
1100 return false;
1101 }
1102
1103 //================================================================
1104 // NUTRITIONAL VALUES
1105 //================================================================
1106 //food properties
1107 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1108 {
1110 if (food_item && food_item.GetFoodStage())
1111 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1112 else if (classname != "" && food_stage)
1113 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1114 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1115 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1116
1117 }
1118
1119 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1120 {
1122 if (food_item && food_item.GetFoodStage())
1123 return FoodStage.GetEnergy(food_item.GetFoodStage());
1124 else if (classname != "" && food_stage)
1125 return FoodStage.GetEnergy(null, food_stage, classname);
1126 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1127 return GetGame().ConfigGetFloat(class_path + " energy");
1128 }
1129
1130 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1131 {
1133 if (food_item && food_item.GetFoodStage())
1134 return FoodStage.GetWater(food_item.GetFoodStage());
1135 else if (classname != "" && food_stage)
1136 return FoodStage.GetWater(null, food_stage, classname);
1137 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1138 return GetGame().ConfigGetFloat(class_path + " water");
1139 }
1140
1141 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1142 {
1144 if (food_item && food_item.GetFoodStage())
1145 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1146 else if (classname != "" && food_stage)
1147 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1148 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1149 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1150
1151 }
1152
1153 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1154 {
1156 if (food_item && food_item.GetFoodStage())
1157 return FoodStage.GetToxicity(food_item.GetFoodStage());
1158 else if (classname != "" && food_stage)
1159 return FoodStage.GetToxicity(null, food_stage, classname);
1160 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1161 return GetGame().ConfigGetFloat(class_path + " toxicity");
1162 }
1163
1164 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1165 {
1167 if (food_item && food_item.GetFoodStage())
1168 return FoodStage.GetAgents(food_item.GetFoodStage());
1169 else if (classname != "" && food_stage)
1170 return FoodStage.GetAgents(null, food_stage, classname);
1171 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1172 return GetGame().ConfigGetInt(class_path + " agents");
1173 }
1174
1175 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1176 {
1178 if (food_item && food_item.GetFoodStage())
1179 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1180 else if (classname != "" && food_stage)
1181 return FoodStage.GetDigestibility(null, food_stage, classname);
1182 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1183 return GetGame().ConfigGetInt(class_path + " digestibility");
1184 }
1185
1187 {
1189 }
1190
1191 //================================================================
1192 // FOOD STAGING
1193 //================================================================
1195 {
1196 return GetFoodStage().GetFoodStageType();
1197 }
1198
1199 //food stage states
1200 bool IsFoodRaw()
1201 {
1202 if (GetFoodStage())
1203 return GetFoodStage().IsFoodRaw();
1204
1205 return false;
1206 }
1207
1208 bool IsFoodBaked()
1209 {
1210 if (GetFoodStage())
1211 return GetFoodStage().IsFoodBaked();
1212
1213 return false;
1214 }
1215
1216 bool IsFoodBoiled()
1217 {
1218 if (GetFoodStage())
1219 return GetFoodStage().IsFoodBoiled();
1220
1221 return false;
1222 }
1223
1224 bool IsFoodDried()
1225 {
1226 if (GetFoodStage())
1227 return GetFoodStage().IsFoodDried();
1228
1229 return false;
1230 }
1231
1232 bool IsFoodBurned()
1233 {
1234 if (GetFoodStage())
1235 return GetFoodStage().IsFoodBurned();
1236
1237 return false;
1238 }
1239
1240 bool IsFoodRotten()
1241 {
1242 if (GetFoodStage())
1243 return GetFoodStage().IsFoodRotten();
1244
1245 return false;
1246 }
1247
1248 //food stage change
1250 {
1251 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1252 }
1253
1255 {
1256 return GetFoodStage().GetNextFoodStageType(cooking_method);
1257 }
1258
1260 {
1261 return GetFoodStage().GetFoodStageName(food_stage_type);
1262 }
1263
1265 {
1266 return GetFoodStage().CanChangeToNewStage(cooking_method);
1267 }
1268
1269 //Use this to receive food stage from another Edible_Base
1271 {
1272 if (!source.HasFoodStage())
1273 return;
1274 m_LastDecayStage = source.GetLastDecayStage();
1275 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1276 m_DecayTimer = source.GetDecayTimer();
1277 m_DecayDelta = source.GetDecayDelta();
1278 }
1279
1280 //================================================================
1281 // COOKING
1282 //================================================================
1283 //cooking time
1284 float GetCookingTime()
1285 {
1286 return GetFoodStage().GetCookingTime();
1287 }
1288
1289 void SetCookingTime(float time)
1290 {
1291 GetFoodStage().SetCookingTime(time);
1292
1293 //synchronize when calling on server
1294 Synchronize();
1295 }
1296
1297 //replace edible with new item (opening cans)
1298 void ReplaceEdibleWithNew(string typeName)
1299 {
1300 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1301 if (player)
1302 {
1304 player.ServerReplaceItemInHandsWithNew(lambda);
1305 }
1306 else
1307 Error("ReplaceEdibleWithNew - cannot use edible without player");
1308 }
1309
1310 override void SetActions()
1311 {
1312 super.SetActions();
1313
1314 AddAction(ActionAttach);
1316 }
1317
1318 protected void SoundCookingStart(string sound_name)
1319 {
1320#ifndef SERVER
1322 {
1324
1327 }
1328#endif
1329 }
1330
1331 protected void SoundCookingStop()
1332 {
1333#ifndef SERVER
1335 {
1338 m_SoundPlaying = "";
1339 }
1340#endif
1341 }
1342
1343 override bool CanHaveTemperature()
1344 {
1345 return true;
1346 }
1347
1348 override bool CanDecay()
1349 {
1350 return false;
1351 }
1352
1353 override bool CanProcessDecay()
1354 {
1355 return (GetFoodStageType() != FoodStageType.ROTTEN);
1356 }
1357
1358 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1359 {
1360 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1361 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1362 if (hasRootAsPlayer)
1364
1365 /*Print( "-------------------------" );
1366 Print( this );
1367 Print( m_DecayTimer );
1368 Print( m_DecayDelta );
1369 Print( m_LastDecayStage );*/
1370
1371 if (IsFruit() || IsMushroom())
1372 {
1373 // fruit, vegetables and mushrooms
1375 {
1376 switch (GetFoodStageType())
1377 {
1378 case FoodStageType.RAW:
1381 break;
1382
1383 case FoodStageType.BOILED:
1386 break;
1387
1388 case FoodStageType.BAKED:
1391 break;
1392
1393 case FoodStageType.DRIED:
1394 case FoodStageType.BURNED:
1395 case FoodStageType.ROTTEN:
1396 default:
1397 m_DecayTimer = -1;
1399 return;
1400 }
1401
1402 //m_DecayTimer = m_DecayTimer / 1000.0;
1403 }
1404
1406
1407 if (m_DecayTimer <= 0)
1408 {
1409 if (m_LastDecayStage != FoodStageType.NONE)
1410 {
1411 // switch to decayed stage
1412 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1415 {
1416 int rng = Math.RandomIntInclusive(0, 100);
1419 else
1420 {
1423 else
1425 }
1426 }
1427 }
1428 }
1429
1430 }
1431 else if (IsMeat())
1432 {
1433 // meat
1435 {
1436 switch (GetFoodStageType())
1437 {
1438 case FoodStageType.RAW:
1441 break;
1442
1443 case FoodStageType.BOILED:
1446 break;
1447
1448 case FoodStageType.BAKED:
1451 break;
1452
1453 case FoodStageType.DRIED:
1456 break;
1457
1458 case FoodStageType.BURNED:
1459 case FoodStageType.ROTTEN:
1460 default:
1461 m_DecayTimer = -1;
1463 return;
1464 }
1465 }
1466
1468
1469 if (m_DecayTimer <= 0)
1470 {
1471 if (m_LastDecayStage != FoodStageType.NONE)
1472 {
1473 // switch to decayed stage
1476 }
1477 }
1478 }
1479 else if (IsCorpse())
1480 {
1481 // corpse
1483 {
1484 switch (GetFoodStageType())
1485 {
1486 case FoodStageType.RAW:
1489 break;
1490
1491 case FoodStageType.BURNED:
1492 case FoodStageType.ROTTEN:
1493 default:
1494 m_DecayTimer = -1;
1496 return;
1497 }
1498 }
1499
1501
1502 if (m_DecayTimer <= 0)
1503 {
1504 if (m_LastDecayStage != FoodStageType.NONE)
1505 {
1506 // switch to decayed stage
1509 }
1510 }
1511 }
1512 else
1513 {
1514 // opened cans
1516
1517 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1518 {
1521 //m_DecayTimer = m_DecayTimer / 1000.0;
1522 }
1523 else
1524 {
1525 if (m_DecayTimer <= 0)
1526 {
1527 InsertAgent(eAgents.FOOD_POISON, 1);
1528 m_DecayTimer = -1;
1529 }
1530 }
1531 }
1532
1533 m_DecayDelta = 0.0;
1534 }
1535
1537 {
1538 super.GetDebugActions(outputList);
1539
1540 if (HasFoodStage())
1541 {
1542 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1543 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1544 }
1545 }
1546
1547 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1548 {
1549 super.OnAction(action_id, player, ctx);
1550
1551 if (GetGame().IsServer())
1552 {
1553 if (action_id == EActions.FOOD_STAGE_PREV)
1554 {
1556 if (food_stage_prev <= 0)
1557 food_stage_prev = FoodStageType.COUNT - 1;
1559 return true;
1560 }
1561 else if (action_id == EActions.FOOD_STAGE_NEXT)
1562 {
1564 if (food_stage_next >= FoodStageType.COUNT)
1567 return true;
1568 }
1569 }
1570 return false;
1571 }
1572
1573 override string GetDebugText()
1574 {
1575 string debug_output;
1576
1577 debug_output = super.GetDebugText();
1578
1579 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1580 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1581
1582 return debug_output;
1583 }
1584
1585 //================================================================
1586 // GENERAL GETTERS
1587 //================================================================
1588
1589 float GetDecayTimer()
1590 {
1591 return m_DecayTimer;
1592 }
1593
1594 float GetDecayDelta()
1595 {
1596 return m_DecayDelta;
1597 }
1598
1600 {
1601 return m_LastDecayStage;
1602 }
1603}
1604
1606{
1608};

◆ TransferFoodStage()

void ReplaceEdibleWithNewLambda::TransferFoodStage ( notnull Edible_Base source)
protected

Definition at line 1165 of file Edible_Base.c.

1165 : ItemBase
1166{
1167 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
1168
1169 const string SOUND_BAKING_START = "Baking_SoundSet";
1170 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
1171 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
1172
1173 protected bool m_MakeCookingSounds;
1174 protected SoundOnVehicle m_SoundCooking;
1176 protected string m_SoundPlaying;
1178 protected float m_DecayTimer;
1179 protected float m_DecayDelta = 0.0;
1181
1183
1184 void Edible_Base()
1185 {
1186 if (HasFoodStage())
1187 {
1188 m_FoodStage = new FoodStage(this);
1189
1190 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
1191 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
1192 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
1193 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
1194 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
1195
1196 m_SoundPlaying = "";
1198 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
1199 RegisterNetSyncVariableBool("m_MakeCookingSounds");
1200 }
1201 }
1202
1203 override void EEInit()
1204 {
1205 super.EEInit();
1206
1207 UpdateVisuals();
1208 }
1209
1210 override void EEDelete(EntityAI parent)
1211 {
1212 super.EEDelete(parent);
1213
1214 RemoveAudio();
1215 }
1216
1218 {
1219 super.EEItemLocationChanged(oldLoc, newLoc);
1220
1222 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
1223 {
1224 switch (oldLoc.GetParent().GetType())
1225 {
1226 case "FryingPan":
1227 case "Pot":
1228 case "Cauldron":
1229 case "SharpWoodenStick":
1230 MakeSoundsOnClient(false);
1231 break;
1232 }
1233
1235 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
1236 MakeSoundsOnClient(false);
1237 }
1238 }
1239
1240 void UpdateVisuals()
1241 {
1242 if (GetFoodStage())
1243 GetFoodStage().UpdateVisuals();
1244 }
1245
1246 bool Consume(float amount, PlayerBase consumer)
1247 {
1248 AddQuantity(-amount, false, false);
1249 OnConsume(amount, consumer);
1250
1251 return true;
1252 }
1253
1254 void OnConsume(float amount, PlayerBase consumer);
1255
1256 //food staging
1257 override bool CanBeCooked()
1258 {
1259 return false;
1260 }
1261
1262 override bool CanBeCookedOnStick()
1263 {
1264 return false;
1265 }
1266
1267 //================================================================
1268 // SYNCHRONIZATION
1269 //================================================================
1270 void Synchronize()
1271 {
1272 SetSynchDirty();
1273
1274 if (GetGame().IsMultiplayer())
1275 UpdateVisuals();
1276 }
1277
1278 override void OnVariablesSynchronized()
1279 {
1280 super.OnVariablesSynchronized();
1281
1282 UpdateVisuals();
1283
1284 //update audio
1286 RefreshAudio();
1287 else
1288 RemoveAudio();
1289 }
1290
1291 //================================================================
1292 // AUDIO EFFECTS (WHEN ON DCS)
1293 //================================================================
1295 {
1298
1299 Synchronize();
1300 }
1301
1302 protected void RefreshAudio()
1303 {
1304 string soundName = "";
1305
1307
1308 switch (GetFoodStageType())
1309 {
1310 case FoodStageType.RAW:
1312 if (nextFoodState == FoodStageType.BOILED)
1313 soundName = "";
1314 break;
1315 case FoodStageType.BAKED:
1317 break;
1318 case FoodStageType.BURNED:
1320 break;
1321 default:
1322 soundName = "";
1323 break;
1324 }
1325
1327 }
1328
1329 protected void RemoveAudio()
1330 {
1331 m_MakeCookingSounds = false;
1333 }
1334
1335 //================================================================
1336 // SERIALIZATION
1337 //================================================================
1338 override void OnStoreSave(ParamsWriteContext ctx)
1339 {
1340 super.OnStoreSave(ctx);
1341
1342 if (GetFoodStage())
1343 GetFoodStage().OnStoreSave(ctx);
1344
1345 // food decay
1346 ctx.Write(m_DecayTimer);
1347 ctx.Write(m_LastDecayStage);
1348 }
1349
1350 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1351 {
1352 if (!super.OnStoreLoad(ctx, version))
1353 return false;
1354
1355 if (GetFoodStage())
1356 {
1357 if (!GetFoodStage().OnStoreLoad(ctx, version))
1358 return false;
1359 }
1360
1361 if (version >= 115)
1362 {
1363 if (!ctx.Read(m_DecayTimer))
1364 {
1365 m_DecayTimer = 0.0;
1366 return false;
1367 }
1368 if (!ctx.Read(m_LastDecayStage))
1369 {
1371 return false;
1372 }
1373 }
1374
1375 return true;
1376 }
1377
1378 override void AfterStoreLoad()
1379 {
1380 super.AfterStoreLoad();
1381
1382 Synchronize();
1383 }
1384
1385 //get food stage
1387 {
1388 return m_FoodStage;
1389 }
1390
1391 //food types
1392 override bool IsMeat()
1393 {
1394 return false;
1395 }
1396
1397 override bool IsCorpse()
1398 {
1399 return false;
1400 }
1401
1402 override bool IsFruit()
1403 {
1404 return false;
1405 }
1406
1407 override bool IsMushroom()
1408 {
1409 return false;
1410 }
1411
1412 //================================================================
1413 // NUTRITIONAL VALUES
1414 //================================================================
1415 //food properties
1416 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1417 {
1419 if (food_item && food_item.GetFoodStage())
1420 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1421 else if (classname != "" && food_stage)
1422 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1423 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1424 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1425
1426 }
1427
1428 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1429 {
1431 if (food_item && food_item.GetFoodStage())
1432 return FoodStage.GetEnergy(food_item.GetFoodStage());
1433 else if (classname != "" && food_stage)
1434 return FoodStage.GetEnergy(null, food_stage, classname);
1435 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1436 return GetGame().ConfigGetFloat(class_path + " energy");
1437 }
1438
1439 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1440 {
1442 if (food_item && food_item.GetFoodStage())
1443 return FoodStage.GetWater(food_item.GetFoodStage());
1444 else if (classname != "" && food_stage)
1445 return FoodStage.GetWater(null, food_stage, classname);
1446 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1447 return GetGame().ConfigGetFloat(class_path + " water");
1448 }
1449
1450 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1451 {
1453 if (food_item && food_item.GetFoodStage())
1454 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1455 else if (classname != "" && food_stage)
1456 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1457 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1458 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1459
1460 }
1461
1462 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1463 {
1465 if (food_item && food_item.GetFoodStage())
1466 return FoodStage.GetToxicity(food_item.GetFoodStage());
1467 else if (classname != "" && food_stage)
1468 return FoodStage.GetToxicity(null, food_stage, classname);
1469 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1470 return GetGame().ConfigGetFloat(class_path + " toxicity");
1471 }
1472
1473 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1474 {
1476 if (food_item && food_item.GetFoodStage())
1477 return FoodStage.GetAgents(food_item.GetFoodStage());
1478 else if (classname != "" && food_stage)
1479 return FoodStage.GetAgents(null, food_stage, classname);
1480 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1481 return GetGame().ConfigGetInt(class_path + " agents");
1482 }
1483
1484 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1485 {
1487 if (food_item && food_item.GetFoodStage())
1488 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1489 else if (classname != "" && food_stage)
1490 return FoodStage.GetDigestibility(null, food_stage, classname);
1491 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1492 return GetGame().ConfigGetInt(class_path + " digestibility");
1493 }
1494
1496 {
1498 }
1499
1500 //================================================================
1501 // FOOD STAGING
1502 //================================================================
1504 {
1505 return GetFoodStage().GetFoodStageType();
1506 }
1507
1508 //food stage states
1509 bool IsFoodRaw()
1510 {
1511 if (GetFoodStage())
1512 return GetFoodStage().IsFoodRaw();
1513
1514 return false;
1515 }
1516
1517 bool IsFoodBaked()
1518 {
1519 if (GetFoodStage())
1520 return GetFoodStage().IsFoodBaked();
1521
1522 return false;
1523 }
1524
1525 bool IsFoodBoiled()
1526 {
1527 if (GetFoodStage())
1528 return GetFoodStage().IsFoodBoiled();
1529
1530 return false;
1531 }
1532
1533 bool IsFoodDried()
1534 {
1535 if (GetFoodStage())
1536 return GetFoodStage().IsFoodDried();
1537
1538 return false;
1539 }
1540
1541 bool IsFoodBurned()
1542 {
1543 if (GetFoodStage())
1544 return GetFoodStage().IsFoodBurned();
1545
1546 return false;
1547 }
1548
1549 bool IsFoodRotten()
1550 {
1551 if (GetFoodStage())
1552 return GetFoodStage().IsFoodRotten();
1553
1554 return false;
1555 }
1556
1557 //food stage change
1559 {
1560 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1561 }
1562
1564 {
1565 return GetFoodStage().GetNextFoodStageType(cooking_method);
1566 }
1567
1569 {
1570 return GetFoodStage().GetFoodStageName(food_stage_type);
1571 }
1572
1574 {
1575 return GetFoodStage().CanChangeToNewStage(cooking_method);
1576 }
1577
1578 //Use this to receive food stage from another Edible_Base
1580 {
1581 if (!source.HasFoodStage())
1582 return;
1583 m_LastDecayStage = source.GetLastDecayStage();
1584 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1585 m_DecayTimer = source.GetDecayTimer();
1586 m_DecayDelta = source.GetDecayDelta();
1587 }
1588
1589 //================================================================
1590 // COOKING
1591 //================================================================
1592 //cooking time
1593 float GetCookingTime()
1594 {
1595 return GetFoodStage().GetCookingTime();
1596 }
1597
1598 void SetCookingTime(float time)
1599 {
1600 GetFoodStage().SetCookingTime(time);
1601
1602 //synchronize when calling on server
1603 Synchronize();
1604 }
1605
1606 //replace edible with new item (opening cans)
1607 void ReplaceEdibleWithNew(string typeName)
1608 {
1609 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1610 if (player)
1611 {
1613 player.ServerReplaceItemInHandsWithNew(lambda);
1614 }
1615 else
1616 Error("ReplaceEdibleWithNew - cannot use edible without player");
1617 }
1618
1619 override void SetActions()
1620 {
1621 super.SetActions();
1622
1623 AddAction(ActionAttach);
1625 }
1626
1627 protected void SoundCookingStart(string sound_name)
1628 {
1629#ifndef SERVER
1631 {
1633
1636 }
1637#endif
1638 }
1639
1640 protected void SoundCookingStop()
1641 {
1642#ifndef SERVER
1644 {
1647 m_SoundPlaying = "";
1648 }
1649#endif
1650 }
1651
1652 override bool CanHaveTemperature()
1653 {
1654 return true;
1655 }
1656
1657 override bool CanDecay()
1658 {
1659 return false;
1660 }
1661
1662 override bool CanProcessDecay()
1663 {
1664 return (GetFoodStageType() != FoodStageType.ROTTEN);
1665 }
1666
1667 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1668 {
1669 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1670 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1671 if (hasRootAsPlayer)
1673
1674 /*Print( "-------------------------" );
1675 Print( this );
1676 Print( m_DecayTimer );
1677 Print( m_DecayDelta );
1678 Print( m_LastDecayStage );*/
1679
1680 if (IsFruit() || IsMushroom())
1681 {
1682 // fruit, vegetables and mushrooms
1684 {
1685 switch (GetFoodStageType())
1686 {
1687 case FoodStageType.RAW:
1690 break;
1691
1692 case FoodStageType.BOILED:
1695 break;
1696
1697 case FoodStageType.BAKED:
1700 break;
1701
1702 case FoodStageType.DRIED:
1703 case FoodStageType.BURNED:
1704 case FoodStageType.ROTTEN:
1705 default:
1706 m_DecayTimer = -1;
1708 return;
1709 }
1710
1711 //m_DecayTimer = m_DecayTimer / 1000.0;
1712 }
1713
1715
1716 if (m_DecayTimer <= 0)
1717 {
1718 if (m_LastDecayStage != FoodStageType.NONE)
1719 {
1720 // switch to decayed stage
1721 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1724 {
1725 int rng = Math.RandomIntInclusive(0, 100);
1728 else
1729 {
1732 else
1734 }
1735 }
1736 }
1737 }
1738
1739 }
1740 else if (IsMeat())
1741 {
1742 // meat
1744 {
1745 switch (GetFoodStageType())
1746 {
1747 case FoodStageType.RAW:
1750 break;
1751
1752 case FoodStageType.BOILED:
1755 break;
1756
1757 case FoodStageType.BAKED:
1760 break;
1761
1762 case FoodStageType.DRIED:
1765 break;
1766
1767 case FoodStageType.BURNED:
1768 case FoodStageType.ROTTEN:
1769 default:
1770 m_DecayTimer = -1;
1772 return;
1773 }
1774 }
1775
1777
1778 if (m_DecayTimer <= 0)
1779 {
1780 if (m_LastDecayStage != FoodStageType.NONE)
1781 {
1782 // switch to decayed stage
1785 }
1786 }
1787 }
1788 else if (IsCorpse())
1789 {
1790 // corpse
1792 {
1793 switch (GetFoodStageType())
1794 {
1795 case FoodStageType.RAW:
1798 break;
1799
1800 case FoodStageType.BURNED:
1801 case FoodStageType.ROTTEN:
1802 default:
1803 m_DecayTimer = -1;
1805 return;
1806 }
1807 }
1808
1810
1811 if (m_DecayTimer <= 0)
1812 {
1813 if (m_LastDecayStage != FoodStageType.NONE)
1814 {
1815 // switch to decayed stage
1818 }
1819 }
1820 }
1821 else
1822 {
1823 // opened cans
1825
1826 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1827 {
1830 //m_DecayTimer = m_DecayTimer / 1000.0;
1831 }
1832 else
1833 {
1834 if (m_DecayTimer <= 0)
1835 {
1836 InsertAgent(eAgents.FOOD_POISON, 1);
1837 m_DecayTimer = -1;
1838 }
1839 }
1840 }
1841
1842 m_DecayDelta = 0.0;
1843 }
1844
1846 {
1847 super.GetDebugActions(outputList);
1848
1849 if (HasFoodStage())
1850 {
1851 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1852 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1853 }
1854 }
1855
1856 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1857 {
1858 super.OnAction(action_id, player, ctx);
1859
1860 if (GetGame().IsServer())
1861 {
1862 if (action_id == EActions.FOOD_STAGE_PREV)
1863 {
1865 if (food_stage_prev <= 0)
1866 food_stage_prev = FoodStageType.COUNT - 1;
1868 return true;
1869 }
1870 else if (action_id == EActions.FOOD_STAGE_NEXT)
1871 {
1873 if (food_stage_next >= FoodStageType.COUNT)
1876 return true;
1877 }
1878 }
1879 return false;
1880 }
1881
1882 override string GetDebugText()
1883 {
1884 string debug_output;
1885
1886 debug_output = super.GetDebugText();
1887
1888 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1889 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1890
1891 return debug_output;
1892 }
1893
1894 //================================================================
1895 // GENERAL GETTERS
1896 //================================================================
1897
1898 float GetDecayTimer()
1899 {
1900 return m_DecayTimer;
1901 }
1902
1903 float GetDecayDelta()
1904 {
1905 return m_DecayDelta;
1906 }
1907
1909 {
1910 return m_LastDecayStage;
1911 }
1912}
1913
1915{
1917};

◆ UpdateVisuals()

void ReplaceEdibleWithNewLambda::UpdateVisuals ( )
private

Definition at line 826 of file Edible_Base.c.

826 : ItemBase
827{
828 const string DIRECT_COOKING_SLOT_NAME = "DirectCooking";
829
830 const string SOUND_BAKING_START = "Baking_SoundSet";
831 const string SOUND_BAKING_DONE = "Baking_Done_SoundSet";
832 const string SOUND_BURNING_DONE = "Food_Burning_SoundSet";
833
834 protected bool m_MakeCookingSounds;
837 protected string m_SoundPlaying;
839 protected float m_DecayTimer;
840 protected float m_DecayDelta = 0.0;
842
844
845 void Edible_Base()
846 {
847 if (HasFoodStage())
848 {
849 m_FoodStage = new FoodStage(this);
850
851 RegisterNetSyncVariableInt("m_FoodStage.m_FoodStageType", FoodStageType.NONE, FoodStageType.COUNT);
852 RegisterNetSyncVariableInt("m_FoodStage.m_SelectionIndex", 0, 6);
853 RegisterNetSyncVariableInt("m_FoodStage.m_TextureIndex", 0, 6);
854 RegisterNetSyncVariableInt("m_FoodStage.m_MaterialIndex", 0, 6);
855 RegisterNetSyncVariableFloat("m_FoodStage.m_CookingTime", 0, 600, 0);
856
857 m_SoundPlaying = "";
859 RegisterNetSyncVariableInt("m_CookedByMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
860 RegisterNetSyncVariableBool("m_MakeCookingSounds");
861 }
862 }
863
864 override void EEInit()
865 {
866 super.EEInit();
867
869 }
870
871 override void EEDelete(EntityAI parent)
872 {
873 super.EEDelete(parent);
874
875 RemoveAudio();
876 }
877
879 {
880 super.EEItemLocationChanged(oldLoc, newLoc);
881
883 if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT || oldLoc.GetType() == InventoryLocationType.CARGO)
884 {
885 switch (oldLoc.GetParent().GetType())
886 {
887 case "FryingPan":
888 case "Pot":
889 case "Cauldron":
890 case "SharpWoodenStick":
891 MakeSoundsOnClient(false);
892 break;
893 }
894
896 if (oldLoc.GetSlot() > -1 && InventorySlots.GetSlotName(oldLoc.GetSlot()).Contains(DIRECT_COOKING_SLOT_NAME))
897 MakeSoundsOnClient(false);
898 }
899 }
900
901 void UpdateVisuals()
902 {
903 if (GetFoodStage())
904 GetFoodStage().UpdateVisuals();
905 }
906
907 bool Consume(float amount, PlayerBase consumer)
908 {
909 AddQuantity(-amount, false, false);
910 OnConsume(amount, consumer);
911
912 return true;
913 }
914
915 void OnConsume(float amount, PlayerBase consumer);
916
917 //food staging
918 override bool CanBeCooked()
919 {
920 return false;
921 }
922
923 override bool CanBeCookedOnStick()
924 {
925 return false;
926 }
927
928 //================================================================
929 // SYNCHRONIZATION
930 //================================================================
931 void Synchronize()
932 {
933 SetSynchDirty();
934
935 if (GetGame().IsMultiplayer())
937 }
938
939 override void OnVariablesSynchronized()
940 {
941 super.OnVariablesSynchronized();
942
944
945 //update audio
947 RefreshAudio();
948 else
949 RemoveAudio();
950 }
951
952 //================================================================
953 // AUDIO EFFECTS (WHEN ON DCS)
954 //================================================================
956 {
959
960 Synchronize();
961 }
962
963 protected void RefreshAudio()
964 {
965 string soundName = "";
966
968
969 switch (GetFoodStageType())
970 {
971 case FoodStageType.RAW:
973 if (nextFoodState == FoodStageType.BOILED)
974 soundName = "";
975 break;
976 case FoodStageType.BAKED:
978 break;
979 case FoodStageType.BURNED:
981 break;
982 default:
983 soundName = "";
984 break;
985 }
986
988 }
989
990 protected void RemoveAudio()
991 {
992 m_MakeCookingSounds = false;
994 }
995
996 //================================================================
997 // SERIALIZATION
998 //================================================================
999 override void OnStoreSave(ParamsWriteContext ctx)
1000 {
1001 super.OnStoreSave(ctx);
1002
1003 if (GetFoodStage())
1004 GetFoodStage().OnStoreSave(ctx);
1005
1006 // food decay
1007 ctx.Write(m_DecayTimer);
1008 ctx.Write(m_LastDecayStage);
1009 }
1010
1011 override bool OnStoreLoad(ParamsReadContext ctx, int version)
1012 {
1013 if (!super.OnStoreLoad(ctx, version))
1014 return false;
1015
1016 if (GetFoodStage())
1017 {
1018 if (!GetFoodStage().OnStoreLoad(ctx, version))
1019 return false;
1020 }
1021
1022 if (version >= 115)
1023 {
1024 if (!ctx.Read(m_DecayTimer))
1025 {
1026 m_DecayTimer = 0.0;
1027 return false;
1028 }
1029 if (!ctx.Read(m_LastDecayStage))
1030 {
1032 return false;
1033 }
1034 }
1035
1036 return true;
1037 }
1038
1039 override void AfterStoreLoad()
1040 {
1041 super.AfterStoreLoad();
1042
1043 Synchronize();
1044 }
1045
1046 //get food stage
1048 {
1049 return m_FoodStage;
1050 }
1051
1052 //food types
1053 override bool IsMeat()
1054 {
1055 return false;
1056 }
1057
1058 override bool IsCorpse()
1059 {
1060 return false;
1061 }
1062
1063 override bool IsFruit()
1064 {
1065 return false;
1066 }
1067
1068 override bool IsMushroom()
1069 {
1070 return false;
1071 }
1072
1073 //================================================================
1074 // NUTRITIONAL VALUES
1075 //================================================================
1076 //food properties
1077 static float GetFoodTotalVolume(ItemBase item, string classname = "", int food_stage = 0)
1078 {
1080 if (food_item && food_item.GetFoodStage())
1081 return FoodStage.GetFullnessIndex(food_item.GetFoodStage());
1082 else if (classname != "" && food_stage)
1083 return FoodStage.GetFullnessIndex(null, food_stage, classname);
1084 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1085 return GetGame().ConfigGetFloat(class_path + " fullnessIndex");
1086
1087 }
1088
1089 static float GetFoodEnergy(ItemBase item, string classname = "", int food_stage = 0)
1090 {
1092 if (food_item && food_item.GetFoodStage())
1093 return FoodStage.GetEnergy(food_item.GetFoodStage());
1094 else if (classname != "" && food_stage)
1095 return FoodStage.GetEnergy(null, food_stage, classname);
1096 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1097 return GetGame().ConfigGetFloat(class_path + " energy");
1098 }
1099
1100 static float GetFoodWater(ItemBase item, string classname = "", int food_stage = 0)
1101 {
1103 if (food_item && food_item.GetFoodStage())
1104 return FoodStage.GetWater(food_item.GetFoodStage());
1105 else if (classname != "" && food_stage)
1106 return FoodStage.GetWater(null, food_stage, classname);
1107 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1108 return GetGame().ConfigGetFloat(class_path + " water");
1109 }
1110
1111 static float GetFoodNutritionalIndex(ItemBase item, string classname = "", int food_stage = 0)
1112 {
1114 if (food_item && food_item.GetFoodStage())
1115 return FoodStage.GetNutritionalIndex(food_item.GetFoodStage());
1116 else if (classname != "" && food_stage)
1117 return FoodStage.GetNutritionalIndex(null, food_stage, classname);
1118 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1119 return GetGame().ConfigGetFloat(class_path + " nutritionalIndex");
1120
1121 }
1122
1123 static float GetFoodToxicity(ItemBase item, string classname = "", int food_stage = 0)
1124 {
1126 if (food_item && food_item.GetFoodStage())
1127 return FoodStage.GetToxicity(food_item.GetFoodStage());
1128 else if (classname != "" && food_stage)
1129 return FoodStage.GetToxicity(null, food_stage, classname);
1130 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1131 return GetGame().ConfigGetFloat(class_path + " toxicity");
1132 }
1133
1134 static int GetFoodAgents(ItemBase item, string classname = "", int food_stage = 0)
1135 {
1137 if (food_item && food_item.GetFoodStage())
1138 return FoodStage.GetAgents(food_item.GetFoodStage());
1139 else if (classname != "" && food_stage)
1140 return FoodStage.GetAgents(null, food_stage, classname);
1141 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1142 return GetGame().ConfigGetInt(class_path + " agents");
1143 }
1144
1145 static float GetFoodDigestibility(ItemBase item, string classname = "", int food_stage = 0)
1146 {
1148 if (food_item && food_item.GetFoodStage())
1149 return FoodStage.GetDigestibility(food_item.GetFoodStage());
1150 else if (classname != "" && food_stage)
1151 return FoodStage.GetDigestibility(null, food_stage, classname);
1152 string class_path = string.Format("cfgVehicles %1 Nutrition", classname);
1153 return GetGame().ConfigGetInt(class_path + " digestibility");
1154 }
1155
1157 {
1159 }
1160
1161 //================================================================
1162 // FOOD STAGING
1163 //================================================================
1165 {
1166 return GetFoodStage().GetFoodStageType();
1167 }
1168
1169 //food stage states
1170 bool IsFoodRaw()
1171 {
1172 if (GetFoodStage())
1173 return GetFoodStage().IsFoodRaw();
1174
1175 return false;
1176 }
1177
1178 bool IsFoodBaked()
1179 {
1180 if (GetFoodStage())
1181 return GetFoodStage().IsFoodBaked();
1182
1183 return false;
1184 }
1185
1186 bool IsFoodBoiled()
1187 {
1188 if (GetFoodStage())
1189 return GetFoodStage().IsFoodBoiled();
1190
1191 return false;
1192 }
1193
1194 bool IsFoodDried()
1195 {
1196 if (GetFoodStage())
1197 return GetFoodStage().IsFoodDried();
1198
1199 return false;
1200 }
1201
1202 bool IsFoodBurned()
1203 {
1204 if (GetFoodStage())
1205 return GetFoodStage().IsFoodBurned();
1206
1207 return false;
1208 }
1209
1210 bool IsFoodRotten()
1211 {
1212 if (GetFoodStage())
1213 return GetFoodStage().IsFoodRotten();
1214
1215 return false;
1216 }
1217
1218 //food stage change
1220 {
1221 GetFoodStage().ChangeFoodStage(new_food_stage_type);
1222 }
1223
1225 {
1226 return GetFoodStage().GetNextFoodStageType(cooking_method);
1227 }
1228
1230 {
1231 return GetFoodStage().GetFoodStageName(food_stage_type);
1232 }
1233
1235 {
1236 return GetFoodStage().CanChangeToNewStage(cooking_method);
1237 }
1238
1239 //Use this to receive food stage from another Edible_Base
1241 {
1242 if (!source.HasFoodStage())
1243 return;
1244 m_LastDecayStage = source.GetLastDecayStage();
1245 ChangeFoodStage(source.GetFoodStage().GetFoodStageType());
1246 m_DecayTimer = source.GetDecayTimer();
1247 m_DecayDelta = source.GetDecayDelta();
1248 }
1249
1250 //================================================================
1251 // COOKING
1252 //================================================================
1253 //cooking time
1254 float GetCookingTime()
1255 {
1256 return GetFoodStage().GetCookingTime();
1257 }
1258
1259 void SetCookingTime(float time)
1260 {
1261 GetFoodStage().SetCookingTime(time);
1262
1263 //synchronize when calling on server
1264 Synchronize();
1265 }
1266
1267 //replace edible with new item (opening cans)
1268 void ReplaceEdibleWithNew(string typeName)
1269 {
1270 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
1271 if (player)
1272 {
1274 player.ServerReplaceItemInHandsWithNew(lambda);
1275 }
1276 else
1277 Error("ReplaceEdibleWithNew - cannot use edible without player");
1278 }
1279
1280 override void SetActions()
1281 {
1282 super.SetActions();
1283
1284 AddAction(ActionAttach);
1286 }
1287
1288 protected void SoundCookingStart(string sound_name)
1289 {
1290#ifndef SERVER
1292 {
1294
1297 }
1298#endif
1299 }
1300
1301 protected void SoundCookingStop()
1302 {
1303#ifndef SERVER
1305 {
1308 m_SoundPlaying = "";
1309 }
1310#endif
1311 }
1312
1313 override bool CanHaveTemperature()
1314 {
1315 return true;
1316 }
1317
1318 override bool CanDecay()
1319 {
1320 return false;
1321 }
1322
1323 override bool CanProcessDecay()
1324 {
1325 return (GetFoodStageType() != FoodStageType.ROTTEN);
1326 }
1327
1328 override void ProcessDecay(float delta, bool hasRootAsPlayer)
1329 {
1330 delta *= DayZGame.Cast(GetGame()).GetFoodDecayModifier();
1331 m_DecayDelta += (1 + (1 - GetHealth01("", "")));
1332 if (hasRootAsPlayer)
1334
1335 /*Print( "-------------------------" );
1336 Print( this );
1337 Print( m_DecayTimer );
1338 Print( m_DecayDelta );
1339 Print( m_LastDecayStage );*/
1340
1341 if (IsFruit() || IsMushroom())
1342 {
1343 // fruit, vegetables and mushrooms
1345 {
1346 switch (GetFoodStageType())
1347 {
1348 case FoodStageType.RAW:
1351 break;
1352
1353 case FoodStageType.BOILED:
1356 break;
1357
1358 case FoodStageType.BAKED:
1361 break;
1362
1363 case FoodStageType.DRIED:
1364 case FoodStageType.BURNED:
1365 case FoodStageType.ROTTEN:
1366 default:
1367 m_DecayTimer = -1;
1369 return;
1370 }
1371
1372 //m_DecayTimer = m_DecayTimer / 1000.0;
1373 }
1374
1376
1377 if (m_DecayTimer <= 0)
1378 {
1379 if (m_LastDecayStage != FoodStageType.NONE)
1380 {
1381 // switch to decayed stage
1382 if ((m_LastDecayStage == FoodStageType.BOILED) || (m_LastDecayStage == FoodStageType.BAKED))
1385 {
1386 int rng = Math.RandomIntInclusive(0, 100);
1389 else
1390 {
1393 else
1395 }
1396 }
1397 }
1398 }
1399
1400 }
1401 else if (IsMeat())
1402 {
1403 // meat
1405 {
1406 switch (GetFoodStageType())
1407 {
1408 case FoodStageType.RAW:
1411 break;
1412
1413 case FoodStageType.BOILED:
1416 break;
1417
1418 case FoodStageType.BAKED:
1421 break;
1422
1423 case FoodStageType.DRIED:
1426 break;
1427
1428 case FoodStageType.BURNED:
1429 case FoodStageType.ROTTEN:
1430 default:
1431 m_DecayTimer = -1;
1433 return;
1434 }
1435 }
1436
1438
1439 if (m_DecayTimer <= 0)
1440 {
1441 if (m_LastDecayStage != FoodStageType.NONE)
1442 {
1443 // switch to decayed stage
1446 }
1447 }
1448 }
1449 else if (IsCorpse())
1450 {
1451 // corpse
1453 {
1454 switch (GetFoodStageType())
1455 {
1456 case FoodStageType.RAW:
1459 break;
1460
1461 case FoodStageType.BURNED:
1462 case FoodStageType.ROTTEN:
1463 default:
1464 m_DecayTimer = -1;
1466 return;
1467 }
1468 }
1469
1471
1472 if (m_DecayTimer <= 0)
1473 {
1474 if (m_LastDecayStage != FoodStageType.NONE)
1475 {
1476 // switch to decayed stage
1479 }
1480 }
1481 }
1482 else
1483 {
1484 // opened cans
1486
1487 if ((m_DecayTimer <= 0) && (m_LastDecayStage == FoodStageType.NONE))
1488 {
1491 //m_DecayTimer = m_DecayTimer / 1000.0;
1492 }
1493 else
1494 {
1495 if (m_DecayTimer <= 0)
1496 {
1497 InsertAgent(eAgents.FOOD_POISON, 1);
1498 m_DecayTimer = -1;
1499 }
1500 }
1501 }
1502
1503 m_DecayDelta = 0.0;
1504 }
1505
1507 {
1508 super.GetDebugActions(outputList);
1509
1510 if (HasFoodStage())
1511 {
1512 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_PREV, "Food Stage Prev", FadeColors.WHITE));
1513 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FOOD_STAGE_NEXT, "Food Stage Next", FadeColors.WHITE));
1514 }
1515 }
1516
1517 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
1518 {
1519 super.OnAction(action_id, player, ctx);
1520
1521 if (GetGame().IsServer())
1522 {
1523 if (action_id == EActions.FOOD_STAGE_PREV)
1524 {
1526 if (food_stage_prev <= 0)
1527 food_stage_prev = FoodStageType.COUNT - 1;
1529 return true;
1530 }
1531 else if (action_id == EActions.FOOD_STAGE_NEXT)
1532 {
1534 if (food_stage_next >= FoodStageType.COUNT)
1537 return true;
1538 }
1539 }
1540 return false;
1541 }
1542
1543 override string GetDebugText()
1544 {
1545 string debug_output;
1546
1547 debug_output = super.GetDebugText();
1548
1549 debug_output += "m_CookedByMethod:" + m_CookedByMethod + "\n";
1550 debug_output += "m_MakeCookingSounds:" + m_MakeCookingSounds + "\n";
1551
1552 return debug_output;
1553 }
1554
1555 //================================================================
1556 // GENERAL GETTERS
1557 //================================================================
1558
1559 float GetDecayTimer()
1560 {
1561 return m_DecayTimer;
1562 }
1563
1564 float GetDecayDelta()
1565 {
1566 return m_DecayDelta;
1567 }
1568
1570 {
1571 return m_LastDecayStage;
1572 }
1573}
1574
1576{
1578};

Variable Documentation

◆ DIRECT_COOKING_SLOT_NAME

const string DIRECT_COOKING_SLOT_NAME = "DirectCooking"

Definition at line 753 of file Edible_Base.c.

◆ m_CookedByMethod

CookingMethodType m_CookedByMethod
private

Definition at line 768 of file Edible_Base.c.

◆ m_DecayDelta

float m_DecayDelta = 0.0
protected

Definition at line 765 of file Edible_Base.c.

◆ m_DecayTimer

float m_DecayTimer
protected

Definition at line 764 of file Edible_Base.c.

Referenced by PluginBase::PluginObjectsInteractionManager().

◆ m_FoodStage

ref FoodStage m_FoodStage
protected

Definition at line 763 of file Edible_Base.c.

◆ m_LastDecayStage

FoodStageType m_LastDecayStage = FoodStageType.NONE
protected

Definition at line 766 of file Edible_Base.c.

◆ m_MakeCookingSounds

bool m_MakeCookingSounds
protected

Definition at line 759 of file Edible_Base.c.

◆ m_SoundCooking

SoundOnVehicle m_SoundCooking
protected

Definition at line 760 of file Edible_Base.c.

◆ m_SoundEffectCooking

EffectSound m_SoundEffectCooking
protected

DEPRECATED.

Definition at line 761 of file Edible_Base.c.

◆ m_SoundPlaying

string m_SoundPlaying
protected

Definition at line 762 of file Edible_Base.c.

◆ SOUND_BAKING_DONE

const string SOUND_BAKING_DONE = "Baking_Done_SoundSet"

Definition at line 756 of file Edible_Base.c.

Referenced by RefreshAudioVisuals().

◆ SOUND_BAKING_START

const string SOUND_BAKING_START = "Baking_SoundSet"

Definition at line 755 of file Edible_Base.c.

Referenced by RefreshAudioVisuals().

◆ SOUND_BURNING_DONE

const string SOUND_BURNING_DONE = "Food_Burning_SoundSet"

Definition at line 757 of file Edible_Base.c.

Referenced by RefreshAudioVisuals().