FieldHeapLoadSettingsEvent = {};
FieldHeapLoadSettingsEvent_mt = Class(FieldHeapLoadSettingsEvent, Event);
InitEventClass(FieldHeapLoadSettingsEvent, "FieldHeapLoadSettingsEvent");

FieldHeapLoadSettingsEvent.NUM_BITS_SETTINGS_MINMAX = 1;

---Create instance of Event class
function FieldHeapLoadSettingsEvent.emptyNew()
    local self = Event.new(FieldHeapLoadSettingsEvent_mt);
    return self;
end;

---Create new instance of event
function FieldHeapLoadSettingsEvent.new(minMax)
    local self = FieldHeapLoadSettingsEvent.emptyNew();
    self.minMax = minMax;
    return self;
end;

---Called on client side on join
function FieldHeapLoadSettingsEvent:readStream(streamId, connection)
    if g_server == nil then        
        self.minMax = streamReadInt8(streamId, FieldHeapLoadSettingsEvent.NUM_BITS_SETTINGS_MINMAX);
        
        self:run(connection);
    end;
end;

---Called on server side on join
function FieldHeapLoadSettingsEvent:writeStream(streamId, connection)
	if g_additionalContractTypes.settings["fieldHeapMission_minMax"] ~= nil then
		streamWriteInt8(streamId, g_additionalContractTypes.settings["fieldHeapMission_minMax"], FieldHeapLoadSettingsEvent.NUM_BITS_SETTINGS_MINMAX);
	end;	
end;

---Run action on receiving side
function FieldHeapLoadSettingsEvent:run(connection)
	if g_server ~= nil then
		g_server:broadcastEvent(FieldHeapLoadSettingsEvent.new(g_additionalContractTypes.settings["fieldHeapMission_minMax"]), false);				
		return;
	end;
	if self.minMax ~= nil then
		g_additionalContractTypes.typ["fieldHeapMission"]:setMaxNumInstance(self.minMax);			
	end;
end;


