protected override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            body2Shoot = MerillUtil.getPlanet(node.GetValue("body"));

            situationForShoot = (ExperimentSituations)System.Enum.Parse(typeof(ExperimentSituations), node.GetValue("situation"));

            useKerbal = node.GetValue("withKerbal").Equals("true");
        }
        protected override void OnLoad(ConfigNode node)
        {
            //MerillData.log(" contract photo OnLoad ");
            base.OnLoad(node);
            if (node.GetValue("body2Shoot") == "null")
            {
                body2Shoot = null;
                //MerillData.log(" contract photo body null ");
            }
            else
            {
                body2Shoot = MerillUtil.getPlanet(node.GetValue("body2Shoot"));
            }

            situationForShoot = (ExperimentSituations)System.Enum.Parse(typeof(ExperimentSituations), node.GetValue("situation"));

            useKerbal = node.GetValue("withKerbal").Equals("true");
        }
        public bool tryTakePicture(Part camera)
        {
            //MerillData.log("takePicture! " + camera.vessel.situation + " at " + MerillUtil.getDetailedSituation(camera.vessel) + " == " + situationForShoot +
            //	" && " + camera.vessel.mainBody.name + " == " + body2Shoot.name + " use kerbal?"+useKerbal
            //	+ ", state:" + base.state);
            if (MerillUtil.getDetailedSituation(camera.vessel) == situationForShoot &&
                camera.vessel.mainBody == body2Shoot && base.state == ParameterState.Incomplete)
            {
                //IsControllable?
                //MerillData.log("camera isCommandable=" + camera.vessel.isCommandable);
                //MerillData.log("camera IsControllable=" + camera.vessel.IsControllable);
                if (!camera.vessel.IsControllable)
                {
                    return(false);
                }
                //manned?
                if (useKerbal)
                {
                    MerillData.log("camera manned=" + (camera.vessel.GetCrewCount() > 0));
                    if (camera.vessel.GetCrewCount() == 0)
                    {
                        return(false);
                    }
                }
                //else
                //{
                //}
                //consume all scienceSlot
                bool findAtLeastASlot = false;
                if (camera.parent != null)
                {
                    MerillData.log("cameraparameter : parent for science slot is " + camera.parent.name);
                    while (camera.parent.RequestResource("ScienceSlot", 1) == 1)
                    {
                        findAtLeastASlot = true;
                        MerillData.log("cameraparameter : find a slot, consumed it " + findAtLeastASlot);
                    }
                }
                MerillData.log("cameraparameter : slot? " + findAtLeastASlot);

                float energyReceived = 0;
                //consume elctricity
                if (!findAtLeastASlot)
                {
                    energyReceived = camera.RequestResource("ElectricCharge", 800);
                    MerillData.log("cameraparameter : find elec charge of " + energyReceived);
                    if (energyReceived < 790)
                    {
                        ScreenMessages.PostScreenMessage(MerillData.str_camera_noEnergy, 10f, ScreenMessageStyle.UPPER_LEFT);
                        return(false);
                    }
                }

                //error: can't fins at least a slot
                if (!findAtLeastASlot)
                {
                    ScreenMessages.PostScreenMessage(MerillData.str_camera_noSlot, 10f, ScreenMessageStyle.UPPER_LEFT);
                    return(false);
                }

                MerillData.log("takePicture! OKKKKK " + ReputationCompletion);
                //todo: check antenna

                //add build point upgrade
                if (ReputationCompletion > 0)
                {
                    KerbalConstructionTime.KCT_GameStates.TotalUpgradePoints += (int)ReputationCompletion;
                }
                ScreenMessages.PostScreenMessage("[KCT] " + (int)ReputationCompletion + " Upgrade Point Added!", 4.0f, ScreenMessageStyle.UPPER_LEFT);
                SetComplete();
                return(true);
            }
            return(false);
        }
 public bool isSituationOk(Part camera)
 {
     return(MerillUtil.getDetailedSituation(camera.vessel) == situationForShoot &&
            camera.vessel.mainBody == body2Shoot && base.state == ParameterState.Incomplete);
 }
        //omg, it's called a big amount of time
        protected override bool Generate()
        {
            //if (base.Prestige != ContractPrestige.Significant)
            //{
            //	return false;
            //}
            //MerillData.log("camera mission generate");

            //TODO use/create 'KTV' (KerbalTV)
            if (Contracts.Agents.AgentList.Instance != null)
            {
                agent = Contracts.Agents.AgentList.Instance.GetAgent(MerillData.str_agent_secretary);
            }


            //1 human day in kerbal days
            //SetDeadlineDays(4);
            base.deadlineType = DeadlineType.None;
            base.expiryType   = DeadlineType.None;

            //choose a body
            this.body2Shoot = MerillUtil.getPlanet("Mun");
            //default (erase latter)
            this.useKerbal         = false;
            this.situationForShoot = ExperimentSituations.InSpaceLow;

            //check if a contract of this type with a kerbal is already taken
            bool alreadyHereKerbal = false;
            bool alreadyHereProbe  = false;

            foreach (MerillContractUseCamera oldContract in ContractSystem.Instance.GetCompletedContracts <MerillContractUseCamera>())
            {
                if (oldContract.body2Shoot == body2Shoot && oldContract.useKerbal)
                {
                    alreadyHereKerbal = true;
                    MerillData.log("camera mission manned already done / here");
                }
                if (oldContract.body2Shoot == body2Shoot && !oldContract.useKerbal)
                {
                    alreadyHereProbe = true;
                    MerillData.log("camera mission probe already done / here");
                }
            }
            //check if it's in available contract
            if (!alreadyHereKerbal || !alreadyHereProbe)
            {
                //MerillData.log("camera mission generated? " + ContractSystem.Instance.Contracts.Count);
                foreach (Contract tempContract in ContractSystem.Instance.Contracts)
                {
                    if (tempContract is MerillContractUseCamera)
                    {
                        if (((MerillContractUseCamera)tempContract).body2Shoot == body2Shoot &&
                            ((MerillContractUseCamera)tempContract).useKerbal)
                        {
                            MerillData.log("camera mission kerbal generated? true! ");
                            alreadyHereKerbal = true;
                        }
                        if (((MerillContractUseCamera)tempContract).body2Shoot == body2Shoot &&
                            !((MerillContractUseCamera)tempContract).useKerbal)
                        {
                            MerillData.log("camera mission probe generated? true! ");
                            alreadyHereProbe = true;
                        }
                    }
                }
            }

            if (!alreadyHereKerbal)
            {
                situationForShoot = ExperimentSituations.InSpaceLow;
                useKerbal         = true;
                ContractParameter parameter = AddParameter(new MerillContractParameterCameraFooting(body2Shoot, situationForShoot, true));
                //MerillData.log("camera mission generate manned "+GetTitle());
                parameter.SetReputation(20);

                //advance, reward, failure
                //BTSM fly by mission:160k total needed: 200k
                SetFunds(0, 30000, 0);

                //reward, failure
                SetReputation(0, 0);
            }
            else if (!alreadyHereProbe)
            {
                useKerbal = false;
                //MerillData.log("camera mission generate unmanned");
                //is highorbit?
                //0 : none, 1= HO, 2=LO , 3 = landed
                //int situation = 0;
                //foreach (MerillContractUseCamera oldContract in ContractSystem.Instance.GetCompletedContracts<MerillContractUseCamera>())
                //{
                //	if(oldContract.body2Shoot == body2Shoot){
                //		if(oldContract.situationForShoot == ExperimentSituations.InSpaceHigh)
                //		{
                //			situation = Math.Max(situation, 1);
                //			coeff = 1;
                //		}
                //		else if(oldContract.situationForShoot == ExperimentSituations.InSpaceLow)
                //		{
                //			situation = Math.Max(situation, 2);
                //			coeff = 1;
                //		}
                //		else if(oldContract.situationForShoot == ExperimentSituations.SrfLanded)
                //		{
                //			situation = Math.Max(situation, 3);
                //			coeff = 2;
                //		}
                //	}
                //}
                //if(situation == 0){
                //	situationForShoot = ExperimentSituations.InSpaceHigh;
                //}else if(situation == 1){
                //	situationForShoot = ExperimentSituations.InSpaceLow;
                //}else if(situation == 2){
                //	situationForShoot = ExperimentSituations.SrfLanded;
                //}else{
                //	//all are done
                //	return false;
                //}
                ////MerillData.log("camera mission generate UNmanned " + string.Format(GetTitle(), body2Shoot.name, situationForShoot.ToString()) );

                ////is already active?
                //foreach (MerillContractUseCamera currentContract in ContractSystem.Instance.GetCurrentContracts<MerillContractUseCamera>())
                //{
                //	//MerillData.log("camera mission find current " + currentContract.useKerbal + ", " + currentContract.body2Shoot + ", " + currentContract.situationForShoot);
                //	if (!currentContract.useKerbal && currentContract.body2Shoot == body2Shoot && currentContract.situationForShoot == situationForShoot)
                //	{
                //		//MerillData.log("camera mission return false");
                //		return false;
                //	}
                //}

                //all green : generate parameter
                ContractParameter parameter1 = AddParameter(new MerillContractParameterCameraFooting(body2Shoot, ExperimentSituations.InSpaceHigh, false));
                ContractParameter parameter2 = AddParameter(new MerillContractParameterCameraFooting(body2Shoot, ExperimentSituations.InSpaceLow, false));
                ContractParameter parameter3 = AddParameter(new MerillContractParameterCameraFooting(body2Shoot, ExperimentSituations.SrfLanded, false));

                //130k via btsm "explore body"
                parameter3.SetFunds(30000);
                //parameter3.SetReputation(10);

                //18k for btsm " explore body" -> need 50k
                parameter1.SetFunds(30000);
                parameter2.SetFunds(30000);

                //reputation
                parameter1.SetReputation(5);
                parameter2.SetReputation(5);
                parameter3.SetReputation(10);

                //already done via "expore body" contract
                SetFunds(0, 30000, 0);

                //reward, failure
                SetReputation(00, 00);
            }
            else
            {
                MerillData.log(" end generate camera: false");
                return(false);
            }

            //no science, use experiment for that (and if !=0, need to add "BTSM" at the begining of this class name)
            SetScience(0);

            MerillData.log(" end generate camera: true");
            return(true);
        }