public GameEngineValues(byte[] data) { gameid = System.BitConverter.ToUInt64(data, 0); int pos = 8; order = new byte[6]; for (int i = 0; i < 6; i++) { order[i] = data[pos++]; } for (int i = 0; i < 6; i++) { actions[i].action = (ActionType)data[pos++]; actions[i].val1 = data[pos++]; actions[i].val2 = data[pos++]; } cities = new CityVals[9 * 6]; for (int i = 0; i < 9 * 6; i++) { CityVals cv = new CityVals(data, pos); if (cv.pos != 255) { cities[i] = cv; } pos += 14; } }
public CityVals(CityVals src) { pos = src.pos; population = src.population; status = src.status; owner = src.owner; improvementsBF = src.improvementsBF; }
public void SettleNewCity() { // Food should be at least 25 if (engine.mySelf.Resources[(int)ResourceType.Food, 0] < 25) { ShowMessage("Not enough food to settle a new city!", true); return; } for (int i = 0; i < engine.cityVals.Length; i++) { // Are we empty and do we have a city of ours (pop>1) around? CityVals c = engine.cityVals[i]; if (c.status == CityStatus.Owned || c.status == CityStatus.Radioactive) { continue; // Not empty } int x = i % 9; int y = i / 9; if (x > 0 && engine.cityVals[i - 1].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } else if (x < 8 && engine.cityVals[i + 1].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } else if (y > 0 && engine.cityVals[i - 9].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } else if (y < 5 && engine.cityVals[i + 9].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } else if (x > 0 && y > 0 && engine.cityVals[i - 1 - 9].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } else if (x > 0 && y < 5 && engine.cityVals[i - 1 + 9].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } else if (x < 8 && y > 0 && engine.cityVals[i + 1 - 9].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } else if (x < 8 && y < 5 && engine.cityVals[i + 1 + 9].owner == engine.mySelf.index) { cities[i].Highlight(CityHighlight.Settling); } } ShowMessage("Select where to settle a new city..."); }
private void PlayEndTurn() { // We call this function only if we receive a message from the engine telling that the turn is ended. // We just play all the actions that are happening, until completed. Then we go back to the normal user interaction status HideAllViews(); ShowMessage("Results of the turn..."); GD.DebugLog("Processing next turn", GD.LT.Debug); // First reset the messages and the completed and endturn foreach (Transform t in Players) { Enemy en = t.GetComponent <Enemy>(); if (en == null) { continue; } Transform completed = t.Find("TurnCompleted"); if (completed != null) { completed.GetComponent <Image>().color = ColorInvisible; } en.HideBalloon(); } // Next city increase/decrease for (int i = 0; i < turn.cities.Length; i++) { if (turn.cities[i] == null) { continue; } CityVals cv = turn.cities[i]; if (cv.pos == 255 || (cv.status != CityStatus.Owned && cv.status != CityStatus.Radioactive)) { continue; } cities[i].SetValues(cv); } // FIXME at this point we cannot do everything here. We may need to use the Update() and play all actions wtf = WhatTheFuckStatus.PlayReceivedActions; // -> Techs and Improvements done // -> GameActions // Then go in order for the players and run the action of each one, showing what is going on on a message // Check for win/loss // FIXME move to the processing of the turn }
public GameEngineValues(GameEngine engine) { gameid = engine.game.id; order = new byte[6]; actions = new GameAction[6]; cities = new CityVals[9 * 6]; for (int i = 0; i < 9 * 6; i++) { if (engine.cityVals[i].status != CityStatus.Empty) { cities[i] = new CityVals(engine.cityVals[i]); } } }
/* * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME * * I may want to see the current status of the techs and click the to check what they do * I may decide to research a tech, in this case I need to select one * * * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME * * * If click on view buttons, the action should be nothing * If clicking on actions buttons we set the action. * * */ public void ViewTechs() { if (wtf != WhatTheFuckStatus.GetLost) { return; } HideAllViews(); Technologies.SetActive(true); long allImprovements = 0; foreach (int idx in engine.mySelf.cities) { CityVals c = engine.cityVals[idx]; if (c.status == CityStatus.Owned || c.status == CityStatus.Radioactive) { allImprovements |= c.improvementsBF; } } for (int i = 0; i < TechButtons.Length; i++) { TechButtons[i].SetIsOnWithoutNotify(false); if (engine.mySelf.techs[i]) { TechButtons[i].GetComponent <Image>().color = AvailableTechColor; } else { // Are prerequisites met? (techs and imprs) if (IsItemValid(GD.instance.Technologies[i], allImprovements)) { TechButtons[i].GetComponent <Image>().color = PossibleTechColor; } else { TechButtons[i].GetComponent <Image>().color = NotgoodTechColor; } } } // Cleanup TechIcon.sprite = null; TechTitle.text = ""; TechDesription.text = ""; foreach (Transform t in TechDepsGrid.transform) { GameObject.Destroy(t.gameObject); } }
public void SetValues(CityVals cv) { vals.status = cv.status; vals.owner = cv.owner; if (vals.population != cv.population) { AddPopulation(cv.population - vals.population); } vals.improvementsBF |= cv.improvementsBF; for (int i = 0; i < improvements.Length; i++) { improvements[i] = (cv.improvementsBF & (1 << i)) != 0; } SetSprite(); }
public void ViewImps(int cityIndex) { if (wtf != WhatTheFuckStatus.GetLost) { return; } HideAllViews(); Improvements.SetActive(true); CityVals city = engine.cityVals[cityIndex]; for (int i = 0; i < ImpButtons.Length; i++) { ImpButtons[i].SetIsOnWithoutNotify(false); // If the improvement on the city is already done we just make it green and not selectable if ((city.improvementsBF & (1 << i)) != 0) { ImpButtons[i].GetComponent <Image>().color = AvailableTechColor; } else { // Can we have it? // Are prerequisites met? (techs and imprs) if (IsItemValid(GD.instance.Improvements[i], city.improvementsBF)) { ImpButtons[i].GetComponent <Image>().color = PossibleTechColor; } else { ImpButtons[i].GetComponent <Image>().color = NotgoodTechColor; } } } // Cleanup ImpIcon.sprite = null; ImpTitle.text = ""; ImpDesription.text = ""; foreach (Transform t in ImpDepsGrid.transform) { GameObject.Destroy(t.gameObject); } }
private bool IsItemAvailable(Item item) { if (item.type == ProductionType.Technology) { return(engine.mySelf.techs[(int)item.index]); } if (item.type == ProductionType.Improvement) { foreach (int idx in engine.mySelf.cities) { CityVals c = engine.cityVals[idx]; if (c.status == CityStatus.Owned || c.status == CityStatus.Radioactive) { if ((c.improvementsBF & (1 << (int)item.index)) != 0) { return(true); } } } } return(false); // FIXME check the resources or other stuff }
public City Init(CityVals src) { radiation.gameObject.SetActive(false); city.gameObject.SetActive(true); // FIXME set to false, but use it to debug the positions popText.text = ""; varText.text = ""; improvements = new bool[19]; for (int i = 0; i < 19; i++) { improvements[i] = false; Improvements[i].enabled = false; } vals = src; int px = src.pos % 9; int py = src.pos / 9; posx = 80 + px * 150 + 20 * (px / 3); posy = 735 - py * 115 - (py > 2 ? 55 : 0); transform.position = new Vector3(posx, posy, 0); SetSprite(); return(this); }
private Vector3 GetCenterSector(Player player) { // Find the sector with most cities int[] sectors = new int[6]; foreach (int city in player.cities) { int sector = (city % 9) / 3 + (city > 26 ? 3 : 0); sectors[sector]++; } int max = 0; int posS = -1; for (int i = 0; i < 6; i++) { if (sectors[i] > max) { max = sectors[i]; posS = i; } } // Find where is the biggest city. In case of top row or first column, move down/right, on all other cases place it on top-left int[] disp = new int[] { 0, 1, 2, 9, 10, 11, 18, 19, 20 }; int posC = 0; max = 0; int sectorStart = 0; if (posS == 1) { sectorStart = 3; } else if (posS == 2) { sectorStart = 6; } else if (posS == 3) { sectorStart = 28; } else if (posS == 4) { sectorStart = 31; } else if (posS == 5) { sectorStart = 34; } for (int i = 0; i < 9; i++) { CityVals cv = engine.cityVals[sectorStart + disp[i]]; if (cv.status == CityStatus.Owned && cv.owner == player.index) { if (max < cv.population) { max = cv.population; posC = sectorStart + disp[i]; } } } // We have the biggest city, fix the displacement depending if we are on first column or first row bool moveRight = (posC % 3 == 0); bool moveDown = (posC < 9 || (posC > 26 && posC < 36)); return(cities[posC].transform.position + 250 * (Vector3.right * (moveRight ? .5f : -.25f) - Vector3.up * (moveDown ? .5f : -.25f))); }
private void SharedInit() { for (byte i = 0; i < nump; i++) { if (players[i] == null) { Debug.LogError("Empty player found! SharedInit"); // FIXME } } byte[] sectors = new byte[6]; for (byte i = 0; i < 6; i++) { sectors[i] = i; } for (int i = 0; i < 1000; i++) { int a = GD.GetRandom(0, 6); int b = GD.GetRandom(0, 6); byte tmp = sectors[a]; sectors[a] = sectors[b]; sectors[b] = tmp; } // Assign the colors for (byte i = 0; i < nump; i++) { players[i].index = sectors[i]; players[i].color = GetPlayerColor(sectors[i]); } // Init the cities cityVals = new CityVals[9 * 6]; for (byte i = 0; i < cityVals.Length; i++) { cityVals[i] = new CityVals(i); } // Assign a single city (population proportional to the difficulty) to each player for (int i = 0; i < nump; i++) { Player ps = players[i]; int pos = 1 + 9 + (sectors[i] < 3 ? sectors[i] * 3 : sectors[i] * 3 + 9 * 2); if (ps.def.type == PlayerDef.Type.AI) { cityVals[pos].Set(5 + 5 * GD.difficulty, ps.index); } else { cityVals[pos].Set(10 - GD.difficulty, ps.index); } ps.cities.Add((byte)pos); } // FIXME add some extra cities to debug social activities for (int i = 0; i < 15; i++) { int a = UnityEngine.Random.Range(0, 9 * 6); if (cityVals[a].status == CityStatus.Empty) { cityVals[a].Set(UnityEngine.Random.Range(1, 50), players[i % 2].index); } players[i % 2].cities.Add((byte)a); } for (int i = 0; i < nump; i++) { completed[i] = false; } }
public void CalculatePopulation(Player p, GameEngineValues values) { // Find the place for the current player int pindex = -1; for (int i = 0; i < players.Length; i++) { if (players[i].def.id == p.def.id) { pindex = i; break; } } if (pindex == -1) { GD.DebugLog("CalculateResources: Cannot find the specified player id=" + p, GD.LT.Debug); return; } // FIXME // Increase the population in case there is enough food, in case the food is zero and the consumption is high, let people starve // The increase should be about *1.05 with at least 1 of increase if (players[pindex].Resources[(int)ResourceType.Food, 0] > 0 || players[pindex].Resources[(int)ResourceType.Food, 1] == players[pindex].Resources[(int)ResourceType.Food, 2]) { foreach (int cityIndex in p.cities) { CityVals src = cityVals[cityIndex]; CityVals dst = values.cities[cityIndex]; if (dst == null) { dst = new CityVals(src); values.cities[cityIndex] = dst; } int increase = (int)(src.population * 0.05f); if (increase == 0) { increase = 1; } if (src.status == CityStatus.Radioactive) { increase = -1; } else if (src.population + increase > 25 && !src.HasImprovement((int)ItemType.IHOUS - (int)ProductionType.Improvement)) { increase = 25 - src.population; if (increase < 0) { increase = 0; } } if (src.population != 0 && increase != 0) { dst.population += increase; } if (dst.population <= 0) { dst.population = 0; dst.status = src.status == CityStatus.Radioactive ? CityStatus.RadioWaste : CityStatus.Destroyed; } } } }