示例#1
0
        public static Unit Read(MyData.Reader reader, Map theMap, string name)
        {
            Unit  u    = null;
            Types type = (Types)reader.UInt(name + "_Type");

            switch (type)
            {
            case Types.PlayerChar: u = new Units.PlayerChar(theMap); break;

            case Types.Bed: u = new Units.Bed(theMap); break;

            case Types.LizardMan: u = new Units.LizardMan(theMap); break;

            default: throw new NotImplementedException(type.ToString());
            }

            reader.Structure(u, name + "_Value");

            return(u);
        }
示例#2
0
        //These are the callbacks are for the currently-active job.
        private void Callback_JobOwnerChanged(Player_Char.Job job, PlayerChar oldP, PlayerChar newP)
        {
            UnityEngine.Assertions.Assert.IsTrue(currentlyDoing == job);

            StopDoingJob(Localization.Get("INTERRUPT_JOB_UNKNOWN", job.ToString()));
        }
示例#3
0
        public override IEnumerable TakeTurn()
        {
            //Gain stats for everybody in bed.
            foreach (ulong unitID in SleepingUnitsByID)
            {
                var pChar = (PlayerChar)TheMap.GetUnit(unitID);
                pChar.Energy.Value +=
                    Player_Char.Consts.EnergyIncreaseFromBedPerTurn(SleepingUnitsByID.Count,
                                                                    pChar.AdultMultiplier);
                pChar.Health.Value +=
                    Player_Char.Consts.HealthIncreaseFromBedPerTurn(SleepingUnitsByID.Count,
                                                                    pChar.AdultMultiplier);
            }

            //Count the number of male/female pairs.
            int nMales   = 0,
                nFemales = 0;

            foreach (Unit unit in SleepingUnitsByID.Select(id => TheMap.GetUnit(id)))
            {
                PlayerChar pChar = (PlayerChar)unit;
                if (pChar.IsAdult)
                {
                    switch (pChar.Personality.Gender.Value)
                    {
                    case Player_Char.Personality.Genders.Male:
                        nMales += 1;
                        break;

                    case Player_Char.Personality.Genders.Female:
                        nFemales += 1;
                        break;

                    default:
                        throw new NotImplementedException(((PlayerChar)unit).Personality.Gender.ToString());
                    }
                }
            }
            int nPairs = Math.Min(nMales, nFemales);

            //For each pair, give them a chance to make a baby.
            for (int i = 0; i < nPairs; ++i)
            {
                if (UnityEngine.Random.value < Player_Char.Consts.ReproductionChance)
                {
                    //Get the father and mother.
                    ulong fatherID = SleepingUnitsByID.Where(id =>
                    {
                        PlayerChar pc = (PlayerChar)TheMap.GetUnit(id);
                        return(pc.Personality.Gender.Value == Player_Char.Personality.Genders.Male);
                    }).ElementAt(i);
                    ulong motherID = SleepingUnitsByID.Where(id =>
                    {
                        PlayerChar pc = (PlayerChar)TheMap.GetUnit(id);
                        return(pc.Personality.Gender.Value == Player_Char.Personality.Genders.Female);
                    }).ElementAt(i);

                    PlayerChar father = (PlayerChar)TheMap.GetUnit(fatherID),
                               mother = (PlayerChar)TheMap.GetUnit(motherID);

                    //Create the baby.
                    var gender = (UnityEngine.Random.value > 0.5f ?
                                  Player_Char.Personality.Genders.Male :
                                  Player_Char.Personality.Genders.Female);
                    int        seed = UnityEngine.Random.Range(0, int.MaxValue);
                    string     name = Player_Char.Personality.GenerateName(gender, seed);
                    PlayerChar baby =
                        new PlayerChar(TheMap, father.MyGroupID,
                                       UnityEngine.Mathf.Lerp(Player_Char.Consts.MinStart_Food,
                                                              Player_Char.Consts.MaxStart_Food,
                                                              UnityEngine.Random.value),
                                       UnityEngine.Mathf.Lerp(Player_Char.Consts.MinStart_Energy,
                                                              Player_Char.Consts.MaxStart_Energy,
                                                              UnityEngine.Random.value),
                                       UnityEngine.Mathf.Lerp(Player_Char.Consts.MinStart_Strength,
                                                              Player_Char.Consts.MaxStart_Strength,
                                                              UnityEngine.Random.value),
                                       0.0f, name, gender);
                    TheMap.AddUnit(baby);
                    baby.Pos.Value = Pos;

                    if (OnMakeBaby != null)
                    {
                        OnMakeBaby(this, father, mother, baby);
                    }
                }
            }

            yield break;
        }