-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColdStorageSimulator.cpp
More file actions
115 lines (112 loc) · 3.25 KB
/
ColdStorageSimulator.cpp
File metadata and controls
115 lines (112 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "stdafx.h"
#include "ColdStorageSimulator.h"
#include "Colony.h"
#include "Egg.h"
#include "Queen.h"
#include "WeatherEvents.h"
//////////////////////////////////////////////////////////////////////
// CColdStorageSimulator Member Functions
//////////////////////////////////////////////////////////////////////
double CColdStorageSimulator::GetTemp(CEvent& p_Event) const
{
double temperature = p_Event.GetTemp(*this);
if (IsActive()) temperature = m_Temperature;
return temperature;
}
double CColdStorageSimulator::GetMaxTemp(CEvent& p_Event) const
{
double temperature = p_Event.GetMaxTemp(*this);
if (IsActive()) temperature = m_Temperature;
return temperature;
}
double CColdStorageSimulator::GetMinTemp(CEvent& p_Event) const
{
double temperature = p_Event.GetMinTemp(*this);
if (IsActive()) temperature = m_Temperature;
return temperature;
}
double CColdStorageSimulator::GetForageInc(CEvent& p_Event) const
{
double forageInc = p_Event.GetForageInc(*this);
if (IsActive()) forageInc = 0.0;
return forageInc;
}
bool CColdStorageSimulator::IsForageDay(CEvent& p_Event) const
{
bool forageDay = p_Event.IsForageDay(*this);
if (IsActive()) forageDay = false;
return forageDay;
}
void CColdStorageSimulator::SetStartDate(const COleDateTime& startDate)
{
m_StartDate = startDate;
m_StartDateStr = m_StartDate.Format("%m%d");
}
void CColdStorageSimulator::SetEndDate(const COleDateTime& endDate)
{
m_EndDate = endDate;
m_EndDateStr = m_EndDate.Format("%m%d");
}
void CColdStorageSimulator::Update(CEvent& p_Event, CColony& p_Colony)
{
bool isActive = IsEnabled() && (IsOn() || IsColdStoragePeriod(p_Event));
if (!m_IsActive && isActive)
{
m_IsStarting = true;
}
// Starting phase is when the bees are placed in cold storage
// and there are still brood that needs to become Adult
if (m_IsStarting)
{
const bool starting =
p_Colony.queen.GetTeggs() > 0 || p_Colony.CapDrn.GetQuantity() > 0 || p_Colony.CapWkr.GetQuantity() > 0;
m_IsStarting = starting;
}
// Ending phase is when the queen starts to lay eggs again while in cold storage
if (isActive && !m_IsStarting && p_Colony.queen.GetTeggs() > 0)
{
m_IsEnding = true;
}
if (!isActive)
{
m_IsStarting = false;
m_IsEnding = false;
}
m_IsActive = isActive;
}
void CColdStorageSimulator::Reset()
{
m_Enabled = false;
m_StartDate = COleDateTime();
m_EndDate = COleDateTime();
m_On = false;
m_Temperature = GetDefaultColdStorageTemperature();
m_StartDateStr = "";
m_EndDateStr = "";
m_IsActive = false;
m_IsStarting = false;
m_IsEnding = false;
}
bool CColdStorageSimulator::IsActive() const
{
return m_IsActive;
}
bool CColdStorageSimulator::IsStarting() const
{
return IsActive() && m_IsStarting;
}
bool CColdStorageSimulator::IsEnding() const
{
return IsActive() && m_IsEnding;
}
bool CColdStorageSimulator::IsColdStoragePeriod(CEvent& p_Event) const
{
// check that SetStartDate and SetEndDate were called
if (m_StartDateStr.empty() || m_EndDateStr.empty())
{
return false;
}
const std::string currentDateStr = (const char*)p_Event.GetTime().Format("%m%d");
return (m_StartDateStr >= m_EndDateStr && (currentDateStr >= m_StartDateStr || currentDateStr <= m_EndDateStr)) ||
(m_StartDateStr <= m_EndDateStr && currentDateStr >= m_StartDateStr && currentDateStr <= m_EndDateStr);
}