/// <summary> /// /// </summary> /// <param name="count"></param> /// <returns></returns> protected Location pickPlace(int count) { while (count-- > 0) { Location loc = target.baseLocation; WorldDefinition w = WorldDefinition.World; int amp = F_PopAmpBase + (int)(Math.Pow(w[loc].LandPrice, F_PopAmpPower) * F_PopAmpScale); // then randomly pick nearby voxel loc.x = Rand(loc.x, amp); loc.y = Rand(loc.y, amp); loc.z = w.GetGroundLevel(loc); if (w.IsOutsideWorld(loc)) { continue; } if (loc.z < w.WaterLevel) { continue; // below water } Voxel v = w[loc]; if (v != null) { if (!IsReplaceable(v.Entity, v.LandPrice)) { continue; } } return(loc); } return(Location.Unplaced); }
/// <summary> /// Removes this platform from the world. /// </summary> public override void remove() { WorldDefinition world = WorldDefinition.World; onHostDisconnected(); foreach (YardRailRoad[] yrrs in lanes) { if (yrrs != null) { foreach (YardRailRoad yrr in yrrs) { // canRemove must be true before this method is called. Debug.Assert(yrr.Voxel.car == null); Location loc = yrr.Location; yrr.Voxel.railRoad = null; new SingleRailRoad( TrafficVoxel.getOrCreate(loc), RailPattern.get(direction, direction.opposite)); world.OnVoxelUpdated(loc); } } } // remove the platform itself foreach (FatPlatformVoxel pv in voxels) { world.remove(pv.Location); world.OnVoxelUpdated(pv.Location); } base.remove(); }
/// <summary> /// Builds normal RR between two specified locations /// </summary> /// <returns>false if the operation was unsuccessful</returns> public static bool Build(Location here, Location there) { // ensure that nothing is on our way between "from" and "to" WorldDefinition world = WorldDefinition.World; int cost; if (ComputeRoute(here, there, out cost) == null) { return(false); } Direction d = here.getDirectionTo(there); while (true) { TrafficVoxel v = TrafficVoxel.getOrCreate(here); if (v == null) { Voxel vv = WorldDefinition.World[here]; Debug.Assert(vv.Entity.isSilentlyReclaimable); vv.Entity.remove(); v = TrafficVoxel.getOrCreate(here); } Direction dd; if (here != there) { dd = here.getDirectionTo(there); } else { dd = d; } if (v.railRoad != null) { v.railRoad.Attach(here == there ? d.opposite : d); WorldDefinition.World.OnVoxelUpdated(here); } else { v.railRoad = new SingleRailRoad(v, RailPattern.get(d.opposite, dd)); // if this RR is elevated, elect a bridge support. // if((++cycle%2)==0) BridgePierVoxel.electBridgeSupport(here, typeof(BridgePierVoxel.DefaultImpl), v); } if (here == there) { break; } d = dd; here = here.toward(there); } Accounting.AccountGenre.RailService.Spend(cost); // charge the cost return(true); }
/// <summary> /// /// </summary> public MapViewWindow() { InitializeComponent(); WorldDefinition w = WorldDefinition.World; AutoScroll = true; // ( (X*32+16) -16 -16, Y*8 -8 -(8+16*Z) ) // the left edge of the world is shaggy, so we need to cut the left-most 16 pixels. // similarly we cut the right-most 16 pixels. // // for the same reason, cut the top-most 8 pixels. bottom 8 pixels. // 16*Z is further cut so that the user won't see the edge of the world // even if the bottom edge of the world is fully raised. Size sz = new Size( w.Size.x * 32 - 16, (w.Size.y - 2 * w.Size.z - 1) * 8); AutoScrollMinSize = sz; MaximumSize = sz; PictureManager.onSurfaceLost += new EventHandler(onSurfaceLost); // build height-cut MenuItems for (int i = WorldDefinition.World.Size.z - 1; i >= 0; i--) { menuItem_heightCut.MenuItems.Add(new HeightCutMenuItem(this, i)); } }
private void ParseClassDefinitionMetadata(XmlNode definition) { string worldName; WorldDefinition worldDefinition; if (definition.Attributes.GetNamedItem(XMLTags.worldAttribute) != null) { worldName = definition.Attributes[XMLTags.worldAttribute].Value; worldDefinition = new WorldDefinition(); foreach (XmlNode child in definition.ChildNodes) { if (child.Name == XMLTags.stateVarTag) { worldDefinition.AddStateVar(new StateVar(child)); } else if (child.Name == XMLTags.actionVarTag) { worldDefinition.AddActionVar(new ActionVar(child)); } else if (child.Name == XMLTags.constantTag) { worldDefinition.AddConstant(child.Attributes[XMLTags.nameAttribute].Value); } } m_worldDefinitions.Add(worldName, worldDefinition); } }
public void PreInit() { if (!_gameDefinitions.worldDefinition) { throw new Exception($"{nameof(WorldDefinition)} doesn't exists!"); } WorldDefinition worldDefinition = _gameDefinitions.worldDefinition; _worldService.WorldField = new HashSet <EcsEntity> [worldDefinition.SizeX][]; for (int xIndex = 0, xMax = worldDefinition.SizeX; xIndex < xMax; xIndex++) { var yFields = new HashSet <EcsEntity> [worldDefinition.SizeY]; for (int yIndex = 0, yMax = worldDefinition.SizeY; yIndex < yMax; yIndex++) { yFields[yIndex] = new HashSet <EcsEntity>(); } _worldService.WorldField[xIndex] = yFields; } #if DEBUG Vector3 finalX = Vector3.right * worldDefinition.SizeX; Vector3 finalY = Vector3.forward * worldDefinition.SizeY; Vector3 final = finalX + finalY; Debug.DrawLine(Vector3.zero, finalX, Color.yellow, 5000); Debug.DrawLine(Vector3.zero, finalY, Color.yellow, 5000); Debug.DrawLine(finalX, final, Color.yellow, 5000); Debug.DrawLine(finalY, final, Color.yellow, 5000); #endif }
/// <summary> /// /// </summary> /// <param name="minsizePixel"></param> /// <param name="options"></param> /// <returns></returns> public WorldDefinition CreatePreviewWorld(Size minsizePixel, IDictionary options) { WorldDefinition w = WorldDefinition.CreatePreviewWorld(minsizePixel, size); Location l = w.toXYZ((w.Size.x - size.x + size.y) / 2, w.Size.y - size.y - 2, 0); Create(new WorldLocator(w, l), false); return(w); }
private void checkForLocalizationChange(WorldDefinition currentWorld) { Localizer localizer = Service.Get <Localizer>(); if (currentWorld != null && localizer.Language != currentWorld.Language) { localizer.ChangeLanguage(currentWorld.Language); } }
public void SetWorldsFromManifest(Manifest manifest) { Worlds.Clear(); ScriptableObject[] assets = manifest.Assets; for (int i = 0; i < assets.Length; i++) { WorldDefinition item = (WorldDefinition)assets[i]; Worlds.Add(item); } }
public WorldDefinition BuildWorld() { int size = Random.Range(MinSize, MaxSize); WorldDefinition world = new WorldDefinition(size, size); BuildTilesRandom(world); cache[world.ID] = world; return(world); }
/// <summary> /// /// </summary> /// <param name="world"></param> /// <returns></returns> public static ISprite GetGroundChip(WorldDefinition world) { if (world.Clock.season != Season.Winter) { return(groundChips[0]); } else { return(groundChips[1]); } }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="loc"></param> /// <param name="ab"></param> public override void OnMouseMove(MapViewWindow view, Location loc, Point ab) { WorldDefinition w = WorldDefinition.World; if (baseLoc != loc) { // update the screen baseLoc = loc; // TODO: we need to correctly update the screen w.OnAllVoxelUpdated(); } }
/// <summary> /// /// </summary> /// <param name="minsizePixel"></param> /// <param name="options"></param> /// <returns></returns> public WorldDefinition CreatePreviewWorld(Size minsizePixel, IDictionary options) { Distance d = new Distance(size.Width * 2 + 1, size.Height * 2 + 1, maxHeight); WorldDefinition w = WorldDefinition.CreatePreviewWorld(minsizePixel, d); int v = w.Size.y - size.Height - 2; Location l = w.toXYZ((w.Size.x - size.Width - size.Height - 1) / 2, v, 0); Create(new WorldLocator(w, l), maxHeight, false); l = w.toXYZ((w.Size.x) / 2, v, 0); Create(new WorldLocator(w, l), minHeight, false); return(w); }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="loc"></param> /// <param name="ab"></param> public override void OnMouseMove(MapViewWindow view, Location loc, Point ab) { WorldDefinition w = WorldDefinition.World; if (baseLoc != loc) { // update the screen updateVoxels(); baseLoc = loc; updateVoxels(); } }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="loc"></param> /// <param name="ab"></param> public virtual void OnMouseMove(MapViewWindow view, Location loc, Point ab) { WorldDefinition w = WorldDefinition.World; if (anchor != unplaced && currentLoc != loc) { // the current location is moved. // update the screen currentLoc = loc; OnRectUpdated(this.LocationNW, this.LocationSE); w.OnAllVoxelUpdated(); } }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="loc"></param> /// <param name="ab"></param> public virtual void OnMouseMove(MapViewWindow view, Location loc, Point ab) { WorldDefinition w = WorldDefinition.World; if (location != loc) { // the current location is moved. // update the screen w.OnVoxelUpdated(CurrentCube); location = loc; w.OnVoxelUpdated(CurrentCube); } }
private void showJumpToFriendServerPrompt(PromptLoaderCMD promptLoader) { string i18nText = "-"; WorldDefinition world = Service.Get <ZoneTransitionService>().GetWorld(playerWorld); if (world != null) { i18nText = Service.Get <Localizer>().GetTokenTranslation(LocalizationLanguage.GetLanguageToken(world.Language)); } promptLoader.PromptData.SetText("Prompt.Text.World", playerWorld, isTranslated: true); promptLoader.PromptData.SetText("Prompt.Text.Language", i18nText, isTranslated: true); Service.Get <PromptManager>().ShowPrompt(promptLoader.PromptData, onJumpToFriendPromptButtonClicked, promptLoader.Prefab); }
/// <summary> /// /// </summary> public void Dispose() { if (world != null) { world.voxelOutlookListeners.Remove(this); } world = null; PictureManager.onSurfaceLost -= new EventHandler(onSurfaceLost); if (offscreenBuffer != null) { offscreenBuffer.Dispose(); offscreenBuffer = null; } }
void BuildTilesRandom(WorldDefinition world) { int width = world.Tiles.GetLength(0); int height = world.Tiles.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { world.Tiles[x, y] = ((x == 0 && y == 0) || Random.value > 0.3f) ? TileType.Land : TileType.Water; } } BuildObjects(world); }
/// <summary> /// /// </summary> public override void remove() { // just remove all the voxels WorldDefinition world = WorldDefinition.World; foreach (Voxel v in this.cube.Voxels) { world.remove(v); } if (onEntityRemoved != null) { onEntityRemoved(this, null); } }
/// <summary></summary> /// <param name="initialView"> /// the region that this object draws in the A,B axis. /// </param> /// <param name="_world"></param> public QuarterViewDrawer(WorldDefinition _world, Rectangle initialView) { this.world = _world; _heightCutHeight = world.Size.z - 1; //this.directDraw = directDraw; //offscreenBuffer = offscreen; RecreateDrawBuffer(initialView.Size, true); topLeft = new Point(initialView.X, initialView.Y); world.voxelOutlookListeners.Add(this); OnUpdateAllVoxels(); // initially all the rects are dirty //PictureManager.onSurfaceLost += new EventHandler(onSurfaceLost); }
/// <summary> /// Creates a new empty world as specified by the user. /// </summary> public WorldDefinition createWorld() { int x = int.Parse(sizeX.Text); int y = int.Parse(sizeY.Text); int z = int.Parse(sizeZ.Text); WorldDefinition w = new WorldDefinition(new Distance(x, y + z * 2, z), z / 4); w.Name = this.name.Text; if (w.Name == null || w.Name.Length == 0) { w.Name = "Terra Incognita"; } //! w.name = "ななしさん"; return(w); // TODO: Z dimension }
/// <summary> /// Creates a ULV of the specified surface. /// </summary> /// <param name="cube"> /// a surface specified as a cube. The height of the cube must be zero. /// </param> /// <returns> /// null if unable to to compute ULV or if any voxel in the cube is owned by /// the user. /// </returns> public static ULV create(Cube cube) { Debug.Assert(cube.SizeZ == 0); int mx = cube.x2; int my = cube.y2; int z = cube.z1; int landValue = 0, entityValue = 0; WorldDefinition world = WorldDefinition.World; Set s = new Set(); if (z < world.WaterLevel) { return(null); // underwater } for (int x = cube.x1; x < mx; x++) { for (int y = cube.y1; y < my; y++) { if (world.GetGroundLevel(x, y) != z) { return(null); // not on the ground } Voxel v = world[x, y, z]; if (v != null) { IEntity e = v.Entity; if (e.isOwned) // cannot reclaim this voxel. { return(null); } if (!s.Contains(e)) { // new entity s.Add(e); entityValue += e.EntityValue; } } landValue += world.LandValue[new Location(x, y, z)]; } } return(new ULV(landValue, entityValue)); }
/// <summary> /// Removes this platform from the world. /// </summary> public override void remove() { WorldDefinition world = WorldDefinition.World; onHostDisconnected(); Location loc = this.location; for (int i = 0; i < length; i++, loc += direction) { new SingleRailRoad( TrafficVoxel.get(loc), RailPattern.get(direction, direction.opposite)); } base.remove(); }
/// <summary> /// Raises the north-eastern corner of the specified voxel /// </summary> /// <returns>false if the operation was unsuccessful.</returns> private bool raise(Location loc) { WorldDefinition w = WorldDefinition.World; // make sure that four surrounding voxels can be raised, // and the ground levels of them are the same if (!canBeRaised(loc)) { return(false); } // then actually change the terrain for (int x = 0; x <= 1; x++) { for (int y = -1; y <= 0; y++) { Location l = new Location(loc.x + x, loc.y + y, loc.z); Voxel vx = w[l]; if (vx is WorldDefinition.OutOfWorldVoxel) { continue; // this is beyond the border } MountainVoxel v = vx as MountainVoxel; Direction d = Direction.get(1 - x * 2, -y * 2 - 1); // corner to modify if (v == null) { v = new MountainVoxel(l, 0, 0, 0, 0); } // raise the corner v.setHeight(d, v.getHeight(d) + 1); if (v.isSaturated) { // if the voxel is saturated, raise the ground level w.raiseGround(l); w.remove(l); // remove this voxel } } } return(true); }
/// <summary> /// /// </summary> public override void remove() { // just remove the voxels WorldDefinition world = WorldDefinition.World; world.remove(baseLocation); if (onEntityRemoved != null) { onEntityRemoved(this, null); } if (stationListener != null) { stationListener.OnRemoved(); } }
/// <summary> /// /// </summary> public override void remove() { if (stationListener != null) { stationListener.OnRemoved(); } if (onEntityRemoved != null) { onEntityRemoved(this, null); } WorldDefinition world = WorldDefinition.World; foreach (VoxelImpl v in voxels) { world.remove(v); } }
private bool onJoinPlayer(PlayerCardEvents.JoinPlayer evt) { PresenceData component = dataEntityCollection.GetComponent <PresenceData>(Handle); PresenceData component2 = dataEntityCollection.GetComponent <PresenceData>(dataEntityCollection.LocalPlayerHandle); if (component == null || component2 == null) { return(false); } if (isLocalAndRemoteInTheSameRoom(component, component2)) { eventChannel.AddListener <FriendsServiceEvents.FriendLocationInRoomReceived>(onFriendLocationReceived); eventChannel.AddListener <FriendsServiceEvents.FriendNotInRoom>(onFriendNotInRoom); Service.Get <INetworkServicesManager>().FriendsService.GetFriendLocationInRoom(dataEntityCollection.GetComponent <SwidData>(Handle).Swid); } else { SpawnAtPlayerData spawnAtPlayerData = dataEntityCollection.AddComponent <SpawnAtPlayerData>(dataEntityCollection.LocalPlayerHandle); spawnAtPlayerData.PlayerSWID = dataEntityCollection.GetComponent <SwidData>(Handle).Swid; string onJoinNotificationTag = string.Empty; if (component.World != component2.World) { onJoinNotificationTag = "GlobalUI.Notification.WorldSwitched"; } if (component.IsInInstancedRoom) { Language language = Service.Get <Localizer>().Language; WorldDefinition world = Service.Get <ZoneTransitionService>().GetWorld(component.World); if (world != null) { language = world.Language; } Service.Get <ZoneTransitionService>().LoadIgloo(component.InstanceRoom, language, SceneStateData.SceneState.Play, "Loading", onJoinNotificationTag); } else { Service.Get <ZoneTransitionService>().LoadZone(component.Room, "Loading", component.World, onJoinNotificationTag); } } Service.Get <ICPSwrveService>().Action("game.friends", "jump"); return(false); }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="loc"></param> /// <param name="ab"></param> public override void OnMouseMove(MapViewWindow view, Location loc, Point ab) { WorldDefinition w = WorldDefinition.World; if (isStair) { location = loc; w.OnAllVoxelUpdated(); } else if (anchor != UNPLACED) { loc = loc.align4To(anchor); if (loc != location) { location = loc; w.OnAllVoxelUpdated(); } } }
/// <summary> /// Gets 4*height + mountain height. /// /// This method computes the height of the given location in fine scale. /// It returns -1 if the given location is out of the world. /// </summary> public static int getTotalHeight(Location loc, Direction d) { WorldDefinition w = WorldDefinition.World; if (w.IsOutsideWorld(loc)) { return(-1); } int z = w.GetGroundLevel(loc); MountainVoxel mv = MountainVoxel.get(new Location(loc.x, loc.y, z)); if (mv == null) { return(z * 4); } else { return(z * 4 + mv.getHeight(d)); } }