void GenerateImmigrationCase(CitizenClass _class) { //for each citizen class: //generate citizen. //assign home. //assign work. Citizen newCitizen = GenerateCitizen(_class); ResidentialBuilding home = GameManager.buildingsMan.GetResidentialBuildingWithEmptySlot(_class); if (home != null) //this shouldn't fail. { newCitizen.homeAddress = home; home.AddResident(newCitizen); } else { print("ERROR! Could not assign home to a citizen"); } WorkPlace workPlace = GameManager.buildingsMan.GetEmptyWorkSlot(newCitizen.educationalLevel); if (workPlace != null) //contrary to the home case, this is a possibility. { newCitizen.workAddress = workPlace; workPlace.AssignEmployee(newCitizen); } population.Add(newCitizen); }
/// <summary> /// 批量删除数据(启用事务 /// </summary> /// <param name="json"></param> /// <returns></returns> public bool DeleteBatchResidentialBuilding(string json) { ResidentialBuilding bll = new ResidentialBuilding(); IList <object> list = (IList <object>)JsonConvert.DeserializeObject(json); return(bll.DeleteBatch(list)); }
public void Build_TheSameBuildingCannotBeBuiltTwice_ExceptionThrown() { var b = new ResidentialBuilding("FI MUNI"); w.Build(new Coordinates(5, 10), b); w.Build(new Coordinates(6, 10), b); }
public static void Rehomed(Settler settler, ResidentialBuilding home) { var contents = "{0} moved into {1}"; contents = string.Format(contents, Console.Color(settler.Name, SettlerColor), home.Name); EventManager.AddEvent(new Event(contents, EventType.SettlerRehomed)); }
public ApartmentsStopRentingPage(ResidentialBuilding apartment) { InitializeComponent(); BindingContext = model = new ApartmentsStopRentingViewModel() { Apartment = apartment }; }
public override void SetExtendedData(Building building) { ResidentialBuilding residence = building.gameObject.GetComponent <ResidentialBuilding>(); residenceClass.text = GetClassString(residence.ResidentClass()); capacity.text = residence.HousingCapacity().ToString(); occupancy.text = residence.ResidentsCount().ToString(); quality.text = residence.housingQuality.ToString(); rent.text = residence.Rent().ToString(); }
/// <summary> /// 获取满足当前条件的数据列表 /// </summary> /// <param name="sqlWhere"></param> /// <param name="cmdParms"></param> /// <returns></returns> public string GetResidentialBuildingList(string sqlWhere, params SqlParameter[] cmdParms) { ResidentialBuilding bll = new ResidentialBuilding(); List <ResidentialBuildingInfo> list = bll.GetList(sqlWhere, cmdParms); if (list == null || list.Count == 0) { return("[]"); } return(JsonConvert.SerializeObject(list)); }
/// <summary> /// 获取数据分页列表,并返回所有记录数 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalRecords"></param> /// <param name="sqlWhere"></param> /// <param name="cmdParms"></param> /// <returns></returns> public string GetResidentialBuildingList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms) { ResidentialBuilding bll = new ResidentialBuilding(); List <ResidentialBuildingInfo> list = bll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, cmdParms); if (list == null || list.Count == 0) { return("[]"); } return(JsonConvert.SerializeObject(list)); }
/// <summary> /// 获取数据列表 /// </summary> /// <returns></returns> public string GetResidentialBuildingList() { ResidentialBuilding bll = new ResidentialBuilding(); List <ResidentialBuildingInfo> list = bll.GetList(); if (list == null || list.Count == 0) { return("[]"); } return(JsonConvert.SerializeObject(list)); }
private void GetJsonForDatagrid(HttpContext context) { int totalRecords = 0; int pageIndex = 1; int pageSize = 10; int.TryParse(context.Request.QueryString["page"], out pageIndex); int.TryParse(context.Request.QueryString["rows"], out pageSize); string sqlWhere = string.Empty; ParamsHelper parms = null; if (!string.IsNullOrEmpty(context.Request.QueryString["buildingCode"])) { sqlWhere = "and BuildingCode like @BuildingCode "; SqlParameter parm = new SqlParameter("@BuildingCode", SqlDbType.VarChar, 50); parm.Value = "%" + context.Request.QueryString["buildingCode"].Trim() + "%"; if (parms == null) { parms = new ParamsHelper(); } parms.Add(parm); } if (!string.IsNullOrEmpty(context.Request.QueryString["communityId"])) { Guid communityId = Guid.Parse(context.Request.QueryString["communityId"]); sqlWhere = "and ResidenceCommunityId = @ResidenceCommunityId "; SqlParameter parm = new SqlParameter("@ResidenceCommunityId", SqlDbType.UniqueIdentifier); parm.Value = communityId; if (parms == null) { parms = new ParamsHelper(); } parms.Add(parm); } ResidentialBuilding bll = new ResidentialBuilding(); var list = bll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms != null ? parms.ToArray() : null); if (list == null || list.Count == 0) { context.Response.Write("{\"total\":0,\"rows\":[]}"); return; } StringBuilder sb = new StringBuilder(); foreach (var model in list) { sb.Append("{\"Id\":\"" + model.Id + "\",\"BuildingCode\":\"" + model.BuildingCode + "\"},"); } context.Response.Write("{\"total\":" + totalRecords + ",\"rows\":[" + sb.ToString().Trim(',') + "]}"); }
public void CalculateLandTax_BuildingBuilt_ReturnsValidVariableTax() { World w = new World(50, 50); w.Build(new Coordinates(2, 5), b); Assert.AreEqual((decimal)25.5, b.CalculateLandTax(), "Invalid land tax returned"); var b2 = new ResidentialBuilding(COMPANY_NAME); w.Build(new Coordinates(2, 10), b2); Assert.AreEqual((decimal)31, b2.CalculateLandTax(), "Invalid land tax returned"); }
public void GetBuildingLocation_BuildingExists_ReturnsCorrectResult() { var b1 = new ResidentialBuilding("FI MUNI"); var b2 = new IndustrialBuilding("FI MUNI"); var c1 = new Coordinates(2, 5); var c2 = new Coordinates(5, 5); w.Build(c1, b1); w.Build(c2, b2); Assert.AreEqual(c1, w.GetBuildingLocation(b1), "Incorrect location of building was returned"); Assert.AreEqual(c2, w.GetBuildingLocation(b2), "Incorrect location of building was returned"); }
private void Bind(ref string myDataAppend) { if (!Id.Equals(Guid.Empty)) { Page.Title = "编辑楼信息"; ResidentialBuilding bll = new ResidentialBuilding(); ResidentialBuildingInfo model = bll.GetModelByJoin(Id); if (model != null) { txtName.Value = model.BuildingCode; txtCoveredArea.Value = model.CoveredArea.ToString(); txtaRemark.Value = model.Remark; myDataAppend += "{ \"Id\":\"" + model.Id + "\",\"PropertyCompanyId\":\"" + model.PropertyCompanyId + "\",\"ResidenceCommunityId\":\"" + model.ResidenceCommunityId + "\",\"CompanyName\":\"" + model.CompanyName + "\",\"CommunityName\":\"" + model.CommunityName + "\"}"; } } }
private void Bind() { //查询条件 GetSearchItem(); List <ResidentialBuildingInfo> list = null; int totalRecords = 0; ResidentialBuilding bll = new ResidentialBuilding(); if (parms != null && parms.Count() > 0) { list = bll.GetListByJoin(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray()); } else { list = bll.GetListByJoin(pageIndex, pageSize, out totalRecords, "", null); } rpData.DataSource = list; rpData.DataBind(); myDataAppend += "<div id=\"myDataForPage\" style=\"display:none;\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\",\"QueryStr\":\"" + queryStr + "\"}]</div>"; }
public Fire(int cycle, ResidentialBuilding target) : base(cycle, target) { _cycle = cycle; _target = target; }
public void SetUp() { b = new ResidentialBuilding(COMPANY_NAME); }
/// <summary> /// 获取对应的数据 /// </summary> /// <param name="Id"></param> /// <returns></returns> public ResidentialBuildingInfo GetResidentialBuildingModel(object Id) { ResidentialBuilding bll = new ResidentialBuilding(); return(bll.GetModel(Id)); }
/// <summary> /// 删除对应数据 /// </summary> /// <param name="Id"></param> /// <returns></returns> public int DeleteResidentialBuilding(object Id) { ResidentialBuilding bll = new ResidentialBuilding(); return(bll.Delete(Id)); }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateResidentialBuilding(ResidentialBuildingInfo model) { ResidentialBuilding bll = new ResidentialBuilding(); return(bll.Update(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int InsertResidentialBuilding(ResidentialBuildingInfo model) { ResidentialBuilding bll = new ResidentialBuilding(); return(bll.Insert(model)); }
public void Rehome(ResidentialBuilding home) { Home = home; SettlerEvents.Rehomed(this, Home); }
//Simulation runs coroutines. IEnumerator BuildingsSimRun() //the current logic assigns available resources prioritizing older buildings (those coming first in buildingsMan.constructedBuildings list) { //Current issue with this logic: It's expensive! Most buildings won't have their operational status and parameters changed each sim update cycle, yet we would still compute //productions and consumptions for all buildings at every sim update. A better approach would be to let each building process changes on its own by updating global values //or registering itself for processing by a central manager. Downside of this approach would be checking against race conditions, and a more complicated code. while (true) { if (isRunning) { //General Buildings float totalWaterDemand = 0.0f; float totalPowerDemand = 0.0f; HousingSlots totalHousingSlots = new HousingSlots(); HousingSlots occuppiedHousingSlots = new HousingSlots(); //To avoid having multiple loops, the loop bellow will cover several, building-specific calls depending on building types. Some exceptions will have their //own loops bellow, but in theory could also be merged with this loop. //TODO consider merging into a single loop with if-statements. foreach (Building building in GameManager.buildingsMan.constructedBuildings) { //Fill requirement resources //TODO consider moving this to a function that only updates when its state changes (e.g. new building constructed, stats changed, etc). Would complicate //the code elsewhere though. totalWaterDemand += building.GetStats().requiredResources.water; totalPowerDemand += building.GetStats().requiredResources.power; //update building effect on natural resources and environment building.UpdateEffectOnNature(dateUpdateRateHours); building.CheckAndShowResourceShortages(); //for residential buildings, if (building.GetStats().type == BuildingType.residential) { ResidentialBuilding residentialBuilding = building.gameObject.GetComponent <ResidentialBuilding>(); //update housing slots totalHousingSlots.IncrementSlotValue(residentialBuilding.HousingCapacity(), residentialBuilding.ResidentClass()); occuppiedHousingSlots.IncrementSlotValue(residentialBuilding.ResidentsCount(), residentialBuilding.ResidentClass()); residentialBuilding.UpdateHousingQuality(); } } //Update ResourceManager GameManager.resourceMan.UpdateWaterDemand(totalWaterDemand); GameManager.resourceMan.UpdatePowerDemand(totalPowerDemand); GameManager.resourceMan.UpdateTotalHousingSlots(totalHousingSlots); GameManager.resourceMan.UpdateOccupiedHousingSlots(occuppiedHousingSlots); //Computing production of infraStructure buildings float totalWaterProduction = 0.0f; float totalPowerProduction = 0.0f; //Compute production for all infra buildings foreach (InfrastructureBuilding building in GameManager.buildingsMan.powerProductionBuildings) { building.ComputeProduction(); totalPowerProduction += building.GetMaxProduction(); } foreach (InfrastructureBuilding building in GameManager.buildingsMan.waterProductionBuildings) { building.ComputeProduction(); totalWaterProduction += building.GetMaxProduction(); } //Update ResourcesManager GameManager.resourceMan.UpdateAvailableWater(totalWaterProduction); GameManager.resourceMan.UpdateAvailablePower(totalPowerProduction); //Allocate resources to buildings based on production and priority float totalWaterConsumption = 0.0f; float totalPowerConsumption = 0.0f; foreach (Building building in GameManager.buildingsMan.constructedBuildings) { BasicResources resources = new BasicResources(); resources.power = Mathf.Clamp(building.GetStats().requiredResources.power, 0.0f, totalPowerProduction - totalPowerConsumption); resources.water = Mathf.Clamp(building.GetStats().requiredResources.water, 0.0f, totalWaterProduction - totalWaterConsumption); totalPowerConsumption += resources.power; totalWaterConsumption += resources.water; building.AllocateResources(resources); } //update ResourceManager GameManager.resourceMan.UpdateWaterConsumption(totalWaterConsumption); GameManager.resourceMan.UpdatePowerConsumption(totalPowerConsumption); //Divide load on infrastructure buildings and assign it float powerDemandToMaxProductionRatio = Mathf.Min(totalPowerDemand / totalPowerProduction, 1.0f); float waterDemandToMaxProductionRatio = Mathf.Min(totalWaterDemand / totalWaterProduction, 1.0f); foreach (InfrastructureBuilding building in GameManager.buildingsMan.powerProductionBuildings) { building.SetLoad(powerDemandToMaxProductionRatio); } foreach (InfrastructureBuilding building in GameManager.buildingsMan.waterProductionBuildings) { building.SetLoad(waterDemandToMaxProductionRatio); } yield return(new WaitForSeconds(timeBetweenUpdates)); } else { yield return(new WaitForFixedUpdate()); } } }