2using System.Collections.Generic;
5using System.Runtime.Serialization;
14 public static HashSet<int>
sunMap =
new HashSet<int>();
28 public Dictionary<string, int>
cellWidths =
new Dictionary<string, int>();
55 public List<Thing>
things =
new List<Thing>();
61 public List<int>
_plDay =
new List<int>();
67 public Dictionary<int, int>
gatherCounts =
new Dictionary<int, int>();
70 public Dictionary<int, CellEffect>
cellEffects =
new Dictionary<int, CellEffect>();
73 public Dictionary<int, int>
backerObjs =
new Dictionary<int, int>();
76 public Dictionary<int, PlantData>
plants =
new Dictionary<int, PlantData>();
87 public List<Chara>
charas =
new List<Chara>();
99 public FloodSpiller
flood =
new FloodSpiller();
113 private HashSet<int>
roomHash =
new HashSet<int>();
115 private List<Thing>
_things =
new List<Thing>();
143 public IEnumerable<Card>
Cards => ((IEnumerable<Card>)
things).Concat((IEnumerable<Card>)
charas);
158 bits.Bits = (uint)
_bits;
161 public void CreateNew(
int size,
bool setReference =
true)
163 Debug.Log(
"Map CreateNew:");
205 Fov.map = (Cell.map = (Wall.map = (Point.map = (CellDetail.map =
this))));
210 pathfinder.
Init(
this, weightMap,
Size);
221 c.currentZone =
zone;
239 if (thing.
pos.
x >= newSize || thing.
pos.
z >= newSize)
246 if (chara.
pos.
x >= newSize || chara.
pos.
z >= newSize)
251 Size = (bounds.Size = newSize);
262 public void Shift(Vector2Int offset)
264 TweenUtil.Tween(0.1f,
null, delegate
268 item.pos.x += offset.x;
269 item.pos.z += offset.y;
273 for (
int i = 0; i <
Size; i++)
275 int num = i - offset.y;
276 for (
int j = 0; j <
Size; j++)
278 int num2 = j - offset.
x;
279 if (num2 >= 0 && num2 < Size && num >= 0 && num <
Size)
281 array[j, i] =
cells[num2, num];
285 array[j, i] =
new Cell
294 bounds.x += offset.
x;
295 bounds.z += offset.y;
296 bounds.maxX += offset.x;
297 bounds.maxZ += offset.y;
327 TweenUtil.Tween(0.1f,
null, delegate
335 List<Thing> list =
new List<Thing>();
355 for (
int i = 0; i <
Size; i++)
357 for (
int j = 0; j <
Size; j++)
387 Debug.Log(
"#io saving map:" + path);
388 IO.CreateDirectory(path);
395 num = partial.offsetX;
396 num2 = partial.offsetZ;
400 int num5 = num3 * num4;
401 byte[] array =
new byte[num5];
402 int[] array2 =
new int[num5];
403 int[] array3 =
new int[num5];
404 int[] array4 =
new int[num5];
405 int[] array5 =
new int[num5];
406 int[] array6 =
new int[num5];
407 int[] array7 =
new int[num5];
408 byte[] array8 =
new byte[num5];
409 byte[] array9 =
new byte[num5];
410 byte[] array10 =
new byte[num5];
411 byte[] array11 =
new byte[num5];
412 byte[] array12 =
new byte[num5];
413 int[] array13 =
new int[num5];
414 int[] array14 =
new int[num5];
415 byte[] array15 =
new byte[num5];
416 int[] array16 =
new int[num5];
417 byte[] array17 =
new byte[num5];
418 int[] array18 =
new int[num5];
419 int[] array19 =
new int[num5];
420 int[] array20 =
new int[num5];
421 int[] array21 =
new int[num5];
424 for (
int i = num; i < num + num3; i++)
426 for (
int j = num2; j < num2 + num4; j++)
429 array[num6] = cell.
objVal;
431 array2[num6] = cell.
_block;
433 array4[num6] = cell.
_floor;
434 array6[num6] = cell.
obj;
435 array20[num6] = cell.
_deco;
437 array7[num6] = cell.
objMat;
438 array8[num6] = cell.
decal;
439 array9[num6] = cell.
_dirs;
440 array12[num6] = cell.
height;
448 array10[num6] = array10[num6].SetBit(1, cell.
isSeen);
449 array10[num6] = array10[num6].SetBit(2, cell.
isHarvested);
450 array10[num6] = array10[num6].SetBit(3, cell.
impassable);
451 array10[num6] = array10[num6].SetBit(4, cell.
isModified);
452 array10[num6] = array10[num6].SetBit(5, cell.
isClearSnow);
453 array10[num6] = array10[num6].SetBit(6, cell.
isForceFloat);
455 array11[num6] = array11[num6].SetBit(0, cell.
isWatered);
456 array11[num6] = array11[num6].SetBit(1, cell.
isObjDyed);
457 array11[num6] = array11[num6].SetBit(2, cell.
crossWall);
458 array11[num6] = array11[num6].SetBit(3, cell.
hidePillar);
469 Write(
"objVals", array);
470 WriteIds(
"blocks", array2);
471 WriteIds(
"blockMats", array3);
472 WriteIds(
"floors", array4);
473 WriteIds(
"floorMats", array5);
474 WriteIds(
"objs", array6);
475 WriteIds(
"objMats", array7);
476 Write(
"decal", array8);
477 Write(
"flags", array10);
478 Write(
"flags2", array11);
479 Write(
"dirs", array9);
480 Write(
"heights", array12);
481 WriteIds(
"bridges", array13);
482 WriteIds(
"bridgeMats", array14);
483 Write(
"bridgeHeights", array15);
484 WriteIds(
"bridgePillars", array16);
485 WriteIds(
"roofBlocks", array18);
486 WriteIds(
"roofBlockMats", array19);
487 Write(
"roofBlockDirs", array17);
488 WriteIds(
"decos", array20);
489 WriteIds(
"decoMats", array21);
511 export.serializedCards.cards.Clear();
521 export.serializedCards.Add(chara2);
526 export.serializedCards.Add(chara2);
533 export.serializedCards.Add(thing);
543 export.serializedCards.Add(thing2);
547 List<Thing> list =
things;
548 things =
new List<Thing>();
553 void Write(
string name,
byte[] bytes)
557 void WriteIds(
string name,
int[] ids)
569 byte[] array = IO.ReadLZ4(path + s, size,
compression);
572 Debug.Log(
"Couldn't load:" + s);
573 return new byte[size];
582 return path +
".w" + width;
591 foreach (
int b
in array)
593 num = Mathf.Max(num, b);
595 int num2 = ((num <= 255) ? 1 : ((num <= 65535) ? 2 : 4));
596 byte[] array2 =
new byte[ids.Length * num2];
597 for (
int j = 0; j < ids.Length; j++)
599 for (
int k = 0; k < num2; k++)
601 array2[j * num2 + k] = (byte)(ids[j] >> 8 * k);
606 foreach (
int num3
in array)
612 for (
int l = 1; l < 5; l++)
614 IO.DeleteFile(text +
".b" + l);
621 private int[]
ReadCellIds(
string file,
string s,
int size,
int width)
623 byte[] array = IO.ReadLZ4(file, size * width,
compression);
628 if ((width != 1 && width != 2 && width != 4) || array.Length != (
long)size * (
long)width)
630 Debug.Log(
"Couldn't load:" + s);
633 int[] array2 =
new int[size];
634 for (
int i = 0; i < size; i++)
636 for (
int j = 0; j < width; j++)
638 array2[i] |= array[i * width + j] << 8 * j;
658 int size = num * num2;
665 byte[] data = TryLoad(
"objVals");
666 int[] data2 = TryLoadIds(
"blockMats");
667 int[] data3 = TryLoadIds(
"blocks");
668 int[] data4 = TryLoadIds(
"floorMats");
669 int[] data5 = TryLoadIds(
"floors");
670 int[] data6 = TryLoadIds(
"objs");
671 int[] data7 = TryLoadIds(
"objMats");
672 byte[] data8 = TryLoad(
"decal");
673 int[] data9 = TryLoadIds(
"decos");
674 int[] data10 = TryLoadIds(
"decoMats");
675 byte[] data11 = TryLoad(
"dirs");
676 byte[] data12 = TryLoad(
"flags");
677 byte[] data13 = TryLoad(
"flags2");
678 byte[] data14 = TryLoad(
"heights");
679 int[] data15 = TryLoadIds(
"bridges");
680 int[] data16 = TryLoadIds(
"bridgeMats");
681 byte[] data17 = TryLoad(
"bridgeHeights");
682 int[] data18 = TryLoadIds(
"bridgePillars");
683 int[] data19 = TryLoadIds(
"roofBlocks");
684 int[] data20 = TryLoadIds(
"roofBlockMats");
685 byte[] data21 = TryLoad(
"roofBlockDirs");
686 if (data18.Length < size)
688 data18 =
new int[size];
690 if (data.Length < size)
692 data =
new byte[size];
694 if (data13.Length < size)
696 data13 =
new byte[size];
698 Validate<byte>(ref data,
"objVals");
699 Validate<int>(ref data2,
"blockMats");
700 Validate<int>(ref data3,
"blocks");
701 Validate<int>(ref data4,
"floorMats");
702 Validate<int>(ref data5,
"floors");
703 Validate<int>(ref data6,
"objs");
704 Validate<int>(ref data7,
"objMats");
705 Validate<byte>(ref data8,
"decal");
706 Validate<int>(ref data9,
"decos");
707 Validate<int>(ref data10,
"decoMats");
708 Validate<byte>(ref data11,
"dirs");
709 Validate<byte>(ref data12,
"flags");
710 Validate<byte>(ref data13,
"flags2");
711 Validate<byte>(ref data14,
"heights");
712 Validate<int>(ref data15,
"bridges");
713 Validate<int>(ref data16,
"bridgeMats");
714 Validate<byte>(ref data17,
"bridgeHeights");
715 Validate<int>(ref data18,
"bridgePillars");
716 Validate<int>(ref data19,
"roofBlocks");
717 Validate<int>(ref data20,
"roofBlockMats");
718 Validate<byte>(ref data21,
"roofBlockDirs");
720 for (
int i = 0; i < num; i++)
722 for (
int j = 0; j < num2; j++)
729 _blockMat = data2[num3],
730 _block = data3[num3],
731 _floorMat = data4[num3],
732 _floor = data5[num3],
734 objMat = data7[num3],
737 _decoMat = data10[num3],
738 _dirs = data11[num3],
739 height = data14[num3],
740 _bridge = data15[num3],
741 _bridgeMat = data16[num3],
742 bridgeHeight = data17[num3],
743 bridgePillar = data18[num3],
744 _roofBlock = data19[num3],
745 _roofBlockMat = data20[num3],
746 _roofBlockDir = data21[num3],
747 isSeen = data12[num3].GetBit(1),
748 isHarvested = data12[num3].GetBit(2),
749 impassable = data12[num3].GetBit(3),
750 isModified = data12[num3].GetBit(4),
751 isClearSnow = data12[num3].GetBit(5),
752 isForceFloat = data12[num3].GetBit(6),
753 isToggleWallPillar = data12[num3].GetBit(7),
754 isWatered = data13[num3].GetBit(0),
755 isObjDyed = data13[num3].GetBit(1),
756 crossWall = data13[num3].GetBit(2),
757 hidePillar = data13[num3].GetBit(3),
758 toggleOcclusion = data13[num3].GetBit(4)
762 cell.bridgePillar = 0;
763 cell.hidePillar =
true;
785 foreach (KeyValuePair<int, CellEffect> cellEffect
in cellEffects)
787 int key = cellEffect.Key;
788 int num4 = key %
Size;
789 int num5 = key /
Size;
791 if (cellEffect.Value.IsFire)
798 byte[] TryLoad(
string s)
802 int[] TryLoadIds(
string s)
808 void Validate<T>(ref T[] reference,
string id)
810 if (reference.Length < size)
812 Debug.LogError(
"exception: size invalid:" +
id +
" " + reference.Length +
"/" + size);
813 reference =
new T[size];
849 custom.id = (mapMetaData.id = id);
850 IO.SaveFile(_path +
"meta", mapMetaData);
857 using ZipFile zipFile = ZipFile.Read(pathZip);
858 ZipEntry zipEntry = zipFile[
"meta"];
859 if (zipEntry !=
null)
861 using (MemoryStream stream =
new MemoryStream())
863 zipEntry.Extract(stream);
865 mapMetaData.path = pathZip;
870 catch (Exception message)
872 if (Application.isEditor)
882 IO.CreateTempDirectory();
883 ZipFile zipFile = ZipFile.Read(pathZip);
884 zipFile.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
885 zipFile.ExtractAll(IO.TempPath);
888 using (zipFile =
new ZipFile())
890 zipFile.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
891 zipFile.AddDirectory(IO.TempPath);
892 zipFile.Save(pathZip);
895 IO.DeleteTempDirectory();
1008 public void SetSeen(
int x,
int z,
bool seen =
true,
bool refresh =
true)
1010 if (
cells[
x,
z].isSeen != seen)
1023 for (
int i = 0; i <
Size; i++)
1025 for (
int j = 0; j <
Size; j++)
1040 EClass._map.SetSeen(p.x, p.z);
1045 public void RefreshFOV(
int x,
int z,
int radius = 6,
bool recalculate =
false)
1058 thing.RecalculateFOV();
1062 thing.CalculateFOV();
1065 foreach (
Chara chara
in detail.charas)
1069 chara.RecalculateFOV();
1073 chara.CalculateFOV();
1083 item.RecalculateFOV();
1087 public void SetFloor(
int x,
int z,
int idMat = 0,
int idFloor = 0)
1089 SetFloor(x, z, idMat, idFloor, 0);
1092 public void SetFloor(
int x,
int z,
int idMat,
int idFloor,
int dir)
1094 Cell cell = cells[x, z];
1095 cell._floorMat = idMat;
1096 cell._floor = idFloor;
1097 cell.floorDir = dir;
1098 cell.isWatered =
false;
1100 RefreshNeighborTiles(x, z);
1103 public void SetDeco(
int x,
int z,
int idMat,
int idDeco)
1105 Cell cell = cells[x, z];
1106 cell._decoMat = idMat;
1107 cell._deco = idDeco;
1108 RefreshNeighborTiles(x, z);
1111 public void SetBridge(
int x,
int z,
int height = 0,
int idMat = 0,
int idBridge = 0,
int dir = 0,
int idPillar = 0,
bool hidePillar =
false)
1113 Cell cell = cells[x, z];
1114 cell.bridgeHeight = (byte)height;
1115 cell._bridgeMat = idMat;
1116 cell._bridge = idBridge;
1117 cell.bridgePillar = idPillar;
1118 cell.hidePillar = hidePillar;
1119 cell.floorDir = dir;
1120 if (cell.
room !=
null)
1124 RefreshNeighborTiles(x, z);
1127 public void SetRoofBlock(
int x,
int z,
int idMat,
int idBlock,
int dir,
int height)
1129 Cell cell = cells[x, z];
1130 cell._roofBlockMat = idMat;
1131 cell._roofBlock = idBlock;
1132 cell._roofBlockDir = (byte)(dir + height * 4);
1133 RefreshSingleTile(x, z);
1136 public void SetBlock(
int x,
int z,
int idMat = 0,
int idBlock = 0)
1138 SetBlock(x, z, idMat, idBlock, 0);
1141 public void SetBlock(
int x,
int z,
int idMat,
int idBlock,
int dir)
1143 Cell cell = cells[x, z];
1145 cell._blockMat = idMat;
1146 cell._block = idBlock;
1147 cell.blockDir = dir;
1152 cell.isToggleWallPillar =
false;
1153 if (cell.
room !=
null)
1159 OnSetBlockOrDoor(x, z);
1161 RefreshNeighborTiles(x, z);
1167 TryRemoveRoom(x, z);
1170 TryRemoveRoom(x - 1, z);
1174 TryRemoveRoom(x + 1, z);
1178 TryRemoveRoom(x, z - 1);
1182 TryRemoveRoom(x, z + 1);
1184 if (x > 0 && z < Size - 1)
1186 TryRemoveRoom(x - 1, z + 1);
1192 TryAddRoom(x - 1, z);
1196 TryAddRoom(x + 1, z);
1200 TryAddRoom(x, z - 1);
1204 TryAddRoom(x, z + 1);
1206 if (x > 0 && z < Size - 1)
1208 TryAddRoom(x - 1, z + 1);
1214 if (!cells[x, z].HasFloodBlock)
1230 FloodSpiller floodSpiller = flood;
1231 IFloodCell[,] array = cells;
1232 FloodSpiller.Result result = floodSpiller.SpillFlood(array, x, z);
1233 if (!result.IsValid)
1238 foreach (IFloodCell
item in result.visited)
1252 if (!flag && IsIndoor)
1254 foreach (IFloodCell item2
in result.visited)
1280 foreach (IFloodCell item3
in result.visited)
1285 room.AddPoint(
new Point(b, b2));
1286 roomHash.Add(b + b2 * Size);
1289 room.AddPoint(
new Point(b, b2 - 1));
1290 roomHash.Add(b + (b2 - 1) * Size);
1294 room.AddPoint(
new Point(b + 1, b2));
1295 roomHash.Add(b + 1 + b2 * Size);
1299 room.AddPoint(
new Point(b + 1, b2 - 1));
1300 roomHash.Add(b + 1 + (b2 - 1) * Size);
1307 Cell cell = cells[x, z];
1309 cell.blockDir = dir;
1314 Cell cell = cells[x, z];
1317 if (cell.
effect ==
null && amount > 0)
1343 if (CC !=
null && CC.IsPCFactionOrMinion && (CC.HasElement(1651) ||
EClass.
pc.
Evalue(1651) >= 2))
1348 List<Card> list =
new List<Card>();
1349 bool fire = ele == 910;
1350 bool cold = ele == 911;
1367 if (
item.IsPCFactionOrMinion)
1372 else if (!CanCook(
item))
1379 Card rootCard =
item.GetRootCard();
1389 if (
item.isThing &&
item.things.Count == 0)
1395 if (ele == 911 &&
item.HasElement(1236))
1403 Card rootCard2 =
item.GetRootCard();
1406 Msg.
Say((
item.isChara ?
"blanketInv_" :
"blanketGround_") + element.source.alias, thing,
item);
1418 foreach (
Thing item2
in item.things.List((
Thing a) => a.things.Count == 0))
1431 foreach (
Card item3
in list)
1438 if (item3.IsEquipmentOrRangedOrAmmo && (
EClass.
rnd(4) != 0 || ((item3.IsRangedWeapon || item3.Thing.isEquipped) && rootCard3.
IsPCFaction &&
EClass.
rnd(4) != 0)))
1445 if (item3.isFireproof || (!item3.category.IsChildOf(
"book") &&
EClass.
rnd(2) == 0))
1451 if (!item3.category.IsChildOf(
"drink") &&
EClass.
rnd(5) == 0)
1461 bool flag3 = CanCook(item3);
1470 if (!(item4.
row is
SourceThing.
Row { isOrigin: false, chance: not 0 } row) || row.components.IsEmpty() || (row.components.Length >= 3 && !row.components[2].StartsWith(
'+')) || !row.Category.IsChildOf(
"meal") || (row.HasTag(
CTAG.dish_fail) && power >
EClass.
rnd(500)))
1474 if (!row.factory.IsEmpty())
1476 switch (row.factory[0])
1485 if (row.components[0].Split(
'|').Contains(item3.id) || row.components[0].Split(
'|').Contains(item3.sourceCard._origin))
1490 if (list3.Count > 0)
1492 text = list3.RandomItemWeighted((
SourceThing.
Row r) => r.chance)?.
id;
1500 if (flag3 && !text.IsEmpty())
1503 List<Thing> list4 =
new List<Thing>();
1510 Msg.
Say(((rootCard3 == item3) ?
"cook_groundItem" :
"cook_invItem") + (fire ?
"" :
"_cold"), thing2, rootCard3, thing3.
Name);
1512 if (rootCard3 == item3)
1518 rootCard3.
Chara.
Pick(thing3, msg:
false);
1528 int num2 =
EClass.
rnd(item3.Num) / 2 + 1;
1529 if (item3.Num > num2)
1534 Msg.
Say((rootCard3 == item3) ?
"damage_groundItem" :
"damage_invItem", thing4, rootCard3);
1557 pos.PlayEffect(fire ?
"Element/eleFire" :
"Element/eleCold");
1562 _ValidateInstalled(pos.x, pos.z);
1563 bool CanCook(
Card c)
1565 if ((fire || cold) && c.
IsFood)
1567 return c.
category.IsChildOf(
"foodstuff");
1573 public void Burn(
int x,
int z,
bool instant =
false)
1575 Cell cell = cells[x, z];
1603 if (cell.
room !=
null)
1607 RefreshNeighborTiles(x, z);
1620 foreach (
Card item in sharedPoint.ListCards())
1631 item.DamageHP(30L, 910);
1643 Cell cell = cells[x, z];
1646 cell.effect = effect;
1652 Cell cell = cells[x, z];
1674 cells[x, z].
effect = effect;
1679 Cell cell = cells[x, z];
1682 cell.effect.amount += amount;
1692 ForeachCell(delegate(
Cell c)
1699 public void SetObj(
int x,
int z,
int id = 0,
int value = 1,
int dir = 0)
1704 public void SetObj(
int x,
int z,
int idMat,
int idObj,
int value,
int dir,
bool ignoreRandomMat =
false)
1706 Cell cell = cells[x, z];
1707 if (cell.
sourceObj.id == 118 || idObj == 118)
1709 EClass._zone.dirtyElectricity =
true;
1712 cell.objVal = (byte)value;
1713 cell.objMat = idMat;
1715 cell.isHarvested =
false;
1716 cell.isObjDyed =
false;
1718 if (!ignoreRandomMat && !sourceObj.
matCategory.IsEmpty())
1721 if (sourceObj.
tag.Contains(
"spot"))
1727 if (backerObjs.ContainsKey(cell.
index))
1729 backerObjs.Remove(cell.
index);
1731 if (plants.ContainsKey(cell.
index))
1733 plants.Remove(cell.
index);
1737 RefreshNeighborTiles(x, z);
1743 int num = ((!draw) ? 1 : 2);
1758 if (!backerObjs.ContainsKey(p.
index))
1771 bool flag = p.sourceObj.id == 82;
1782 p.cell.objDir = row.
skin;
1787 backerObjs.Remove(p.
index);
1810 if (recipeSource ==
null)
1815 if (iDIngredient ==
null)
1828 TrySmoothPick(point, thing, c);
1840 int num = (flag ? point.cell._roofBlock : point.
cell.
_block);
1847 bool flag2 = c ==
null || c.IsAgent || c.IsPCFactionOrMinion;
1854 point.cell._roofBlock = 0;
1855 RefreshSingleTile(point.
x, point.
z);
1861 RemoveLonelyRamps(point.
cell);
1864 if (flag2 && point.
sourceObj.tileType.IsBlockMount && mineObj)
1866 MineObj(point,
null, c);
1871 DropBlockComponent(point, row2, row, recoverBlock, isPlatform:
false, c);
1873 RefreshShadow(point.
x, point.
z);
1874 RefreshShadow(point.
x, point.
z - 1);
1875 ValidateInstalled(point);
1876 RefreshFOV(point.
x, point.
z);
1895 point.cell.isModified =
true;
1910 RemoveLonelyRamps(point.
cell);
1927 MineObj(point,
null, c);
1941 SetFloor(point.
x, point.
z, 0, 90);
1952 TrySmoothPick(point, thing, c);
1956 DropBlockComponent(point, point.
sourceFloor, row, recoverBlock, isPlatform:
false, c);
1970 TrySmoothPick(cell.
GetPoint(), t, c);
2012 if (c ==
null && task !=
null)
2016 bool num = c ==
null || c.IsAgent || c.IsPCFactionOrMinion;
2026 if (soilCost > maxSoil)
2028 num2 -=
EClass.
rnd(2 + (soilCost - maxSoil) / 10);
2041 cell.isHarvested =
true;
2051 if (cell.
HasBlock && (sourceObj.
id == 18 || sourceObj.
id == 19))
2053 MineBlock(point, recoverBlock:
false, c, mineObj:
false);
2064 switch (sourceObj.
alias)
2074 string[] array = sourceObj.
components[num3].Split(
'/');
2076 if (array.Length > 1)
2083 SetObj(point.
x, point.
z);
2084 cell.gatherCount = 0;
2085 void Pop(
Thing thing2)
2095 TrySmoothPick(point, thing2, c);
2108 return plants.TryGetValue(p.
index);
2113 return plants.TryGetValue(c.
index);
2122 plants[pos.
index] = plantData;
2128 plants.Remove(pos.
index);
2133 _ValidateInstalled(p.
x, p.
z);
2134 _ValidateInstalled(p.
x + 1, p.
z);
2135 _ValidateInstalled(p.
x - 1, p.
z);
2136 _ValidateInstalled(p.
x, p.
z + 1);
2137 _ValidateInstalled(p.
x, p.
z - 1);
2155 if (!
item.isThing || !
item.trait.CanBeDestroyed || !
item.IsInstalled)
2159 HitResult hitResult =
item.TileType._HitTest(point,
item.Thing, canIgnore:
false);
2160 if (
item.Thing.stackOrder != detail.things.IndexOf(
item.Thing) || (hitResult !=
HitResult.Valid && hitResult !=
HitResult.Warning))
2176 for (
int i = 0; i < 4; i++)
2178 Cell dependedRamp = GetDependedRamp(cell);
2179 if (dependedRamp !=
null)
2181 MineBlock(dependedRamp.
GetPoint());
2193 public void AddDecal(
int x,
int z,
int id,
int amount = 1,
bool refresh =
true)
2195 if (x < 0 || z < 0 || x >= Size || z >= Size)
2199 Cell cell = cells[x, z];
2202 if (cell.
decal / 8 !=
id && cell.
decal % 8 == 0)
2206 int num = Mathf.Clamp(((cell.
decal / 8 ==
id) ? (cell.
decal % 8) : 0) + amount, 0, 7);
2207 cell.decal = (byte)(
id * 8 + num);
2210 RefreshNeighborTiles(x, z);
2215 public void SetDecal(
int x,
int z,
int id = 0,
int amount = 1,
bool refresh =
true)
2217 cells[x, z].
decal = (byte)((
id != 0 && amount != 0) ? ((uint)(
id * 8 + amount)) : 0u);
2220 RefreshNeighborTiles(x, z);
2227 int tile = AngleToIndex(angle) + offset;
2234 footmarks.Add(footmark);
2274 for (
int i = 0; i < Size; i++)
2276 for (
int j = 0; j < Size; j++)
2286 for (
int i = x - 2; i < x + 3; i++)
2288 if (i < 0 || i >= Size)
2292 for (
int j = z - 2; j < z + 3; j++)
2294 if (j >= 0 && j < Size && (x != i || z != j))
2304 Cell cell = cells[x, z];
2306 Cell cell3 = ((x + 1 < Size) ? cells[x + 1, z] :
Cell.
Void);
2308 Cell cell5 = ((z + 1 < Size) ? cells[x, z + 1] :
Cell.
Void);
2309 Cell cell6 = ((x > 0 && z > 0) ? cells[x - 1, z - 1] :
Cell.
Void);
2310 Cell cell7 = ((x + 1 < Size && z > 0) ? cells[x + 1, z - 1] :
Cell.
Void);
2311 Cell cell8 = ((x > 0 && z + 1 < Size) ? cells[x - 1, z + 1] :
Cell.
Void);
2312 Cell cell9 = ((x + 1 < Size && z + 1 < Size) ? cells[x + 1, z + 1] :
Cell.
Void);
2313 cell.isSurrounded4d = cell2.HasFullBlock && cell3.HasFullBlock && cell4.HasFullBlock && cell5.
HasFullBlock;
2314 cell.isSurrounded = cell.isSurrounded4d && cell6.HasFullBlock && cell7.HasFullBlock && cell8.HasFullBlock && cell9.
HasFullBlock;
2319 Cell cell = cells[x, z];
2322 if (blockType ==
null)
2346 if (!blockType.IsRamp)
2367 if (
left.HasRamp && !
left.HasStairs &&
left.blockDir == 3)
2372 if (
back.HasRamp && !
back.HasStairs &&
back.blockDir == 2)
2382 for (
int i = 0; i < tries; i++)
2384 point.x = center.x +
EClass.
rnd(radius * 2 + 1) - radius;
2385 point.z = center.z +
EClass.
rnd(radius * 2 + 1) - radius;
2392 Debug.Log(
"GetRandomPoint failed center:" + center?.ToString() +
" rad:" + radius);
2393 point.IsValid =
false;
2401 for (
int i = 0; i < 10000; i++)
2413 Point surface = GetSurface(num, num2, walkable:
false);
2419 return GetSurface(Size / 2, Size / 2, walkable:
false);
2425 int num = ((
EClass.
rnd(2) == 0) ? 1 : (-1));
2426 int num2 = ((
EClass.
rnd(2) == 0) ? 1 : (-1));
2427 for (
int i = 0; i < 3; i++)
2429 point.x = center.x - num + i * num;
2430 for (
int j = 0; j < 3; j++)
2432 point.z = center.z - num2 + j * num2;
2444 List<Point> list =
new List<Point>();
2445 ForeachSphere(center.
x, center.
z, radius, delegate(
Point p)
2457 List<Point> list =
new List<Point>();
2458 ForeachSquare(center.
x, center.
z, radius, delegate(
Point p)
2470 List<Point> list =
new List<Point>();
2471 ForeachSphere(center.
x, center.
z, destDist, delegate(
Point p)
2483 List<Chara> list =
new List<Chara>();
2484 foreach (
Point item in ListPointsInCircle(center, radius, mustBeWalkable:
false, los))
2487 if (detail ==
null || detail.
charas.Count <= 0)
2491 foreach (
Chara chara
in item.detail.charas)
2501 Point to2 =
new Point((to.
x > center.
x) ? 1 : ((to.
x < center.
x) ? (-1) : 0), (to.
z > center.
z) ? 1 : ((to.
z < center.
z) ? (-1) : 0));
2503 List<Point> list =
new List<Point>();
2505 ForeachSphere(center.
x, center.
z, radius, delegate(
Point p)
2508 if ((Mathf.Abs(diff - angle2) < angle || Mathf.Abs(diff - angle2 + 360f) < angle || Mathf.Abs(360f - diff + angle2) < angle) &&
Los.
IsVisible(center, p) && !p.
IsBlocked)
2518 return Los.
ListVisible(center, to, radius,
null, returnOnBlocked);
2523 if (size > Size / 2 + 1)
2525 size = Size / 2 - 1;
2527 bounds.
SetBounds(Size / 2 - size, Size / 2 - size, Size / 2 + size, Size / 2 + size);
2533 bounds.Size = b.
Size;
2538 for (
int i = 0; i < Size; i++)
2540 for (
int j = 0; j < Size; j++)
2542 action(cells[i, j]);
2550 for (
int i = 0; i < Size; i++)
2552 for (
int j = 0; j < Size; j++)
2554 action(point.
Set(i, j));
2561 for (
int i = 0; i < Size; i++)
2563 for (
int j = 0; j < Size; j++)
2573 int num = (int)Mathf.Ceil(r);
2574 for (
int i = _x - num; i < _x + num + 1; i++)
2576 if (i < 0 || i >= Size)
2580 for (
int j = _z - num; j < _z + num + 1; j++)
2582 if (j >= 0 && j < Size && (
float)((i - _x) * (i - _x) + (j - _z) * (j - _z)) < r * r)
2594 for (
int i = _x - r; i < _x + r + 1; i++)
2596 if (i < 0 || i >= Size)
2600 for (
int j = _z - r; j < _z + r + 1; j++)
2602 if (j >= 0 && j < Size)
2614 int num2 = center.
z;
2616 for (
int i = num - 1; i < num + 2; i++)
2618 if (i < 0 || i >= Size)
2622 for (
int j = num2 - 1; j < num2 + 2; j++)
2624 if (j >= 0 && j < Size)
2637 for (num = 0; num < Size; num++)
2640 for (num2 = 0; num2 < Size; num2++)
2654 foreach (
Chara chara
in charas)
2667 foreach (
Chara chara
in charas)
2680 foreach (
Chara chara
in charas)
2693 foreach (
Chara chara
in charas)
2706 foreach (
Chara chara
in charas)
2718 List<Chara> list =
new List<Chara>();
2719 foreach (
Chara chara
in charas)
2729 public List<Thing> ListThing<T>() where T :
Trait
2731 List<Thing> list =
new List<Thing>();
2732 foreach (
Thing thing
in things)
2758 if (thing.
parent !=
null)
2762 thing.isMasked =
false;
2763 thing.isRoofItem =
false;
2780 foreach (
Chara chara
in charas)
2792 foreach (
Chara chara
in charas)
2794 if (chara.
uid == uid)
2804 foreach (
Thing thing
in things)
2816 foreach (
Thing thing
in things)
2818 if (thing.
uid == uid)
2828 foreach (
Thing thing
in things)
2830 if (thing.
trait is T)
2832 return thing.trait as T;
2852 if (_things.Count <= 0)
2856 return _things.RandomItem();
2861 if (type ==
null || (area1 ==
null && area2 ==
null))
2865 Thing thing = Find(area1);
2866 if (thing ==
null && area2 !=
null)
2868 thing = Find(area2);
2878 _things.
Add(thing2);
2881 if (_things.Count <= 0)
2885 return _things.RandomItem();
2891 if (area1 ==
null && area2 ==
null)
2900 if (enumerable.Count() > 0)
2902 thing = enumerable.RandomItem() as
Thing;
2905 if (thing ==
null && area2 !=
null)
2908 if (enumerable2.Count() > 0)
2910 thing = enumerable2.RandomItem() as
Thing;
2918 Thing result =
null;
2920 where a.pos.IsPublicSpace()
2922 if (enumerable.Count() > 0)
2924 result = enumerable.RandomItem() as
Thing;
2931 return (from a in ((IEnumerable<BaseArea>)rooms.
listArea).Concat((IEnumerable<BaseArea>)rooms.
listRoom)
2932 where a.type.IsPublicArea
2933 select a).RandomItem();
2947 sunMap.Add(
item.index);
2950 isDirtySunMap =
false;
static bool not(DramaManager dm, Dictionary< string, string > line, params string[] parameters)
override bool IsRoofEditMode(Card c=null)
void Add(Act a, string s="")
Thing TryMakeRandomItem(int lv=-1, TryMakeRandomItemSource itemSource=TryMakeRandomItemSource.Default, Chara crafter=null)
void SetPlaceState(PlaceState newState, bool byPlayer=false)
ElementContainerCard elements
virtual void Die(Element e=null, Card origin=null, AttackSource attackSource=AttackSource.None, Chara originalTarget=null)
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Thing AddThing(string id, int lv=-1)
void Kick(Point p, bool ignoreSelf=false, bool checkWall=true)
void ForeachPoint(Action< Point, bool > action)
void ModCharge(int a, bool destroy=false)
bool HasEditorTag(EditorTag tag)
Thing Add(string id, int num=1, int lv=1)
SourceCategory.Row category
SourceBlock.Row sourceBlock
bool CanBuildRamp(int dir)
SourceFloor.Row sourceFloor
SourceMaterial.Row matObj
CellDetail GetOrCreateDetail()
SourceMaterial.Row matObj_fixed
void PickOrDrop(Point p, string idThing, int idMat=-1, int num=1, bool msg=true)
override bool IsPCFaction
Thing Pick(Thing t, bool msg=true, bool tryStack=true)
bool ignoreBackerDestoryFlag
Thing GetOrCreateDebugContainer()
static void MakeDish(Thing food, int lv, Chara crafter=null, int seed=-1)
static void RebuildCritter(Cell cell)
static int curve(long _a, int start, int step, int rate=75)
static SourceManager sources
static FactionBranch Branch
static Effect Get(Effect original)
void Play(float delay, Point from, float fixY=0f, Point to=null, Sprite sprite=null)
Element ModBase(int ele, int v)
static Element Create(int id, int v=0)
static FowProfile Load(string id)
static void SaveFile(string path, object obj)
bool disableUsermapBenefit
static void Load(string id, bool cloud)
bool Save(bool isAutoSave=false, bool silent=false)
void PopMineObj(Chara c=null)
LogicalPoint GetOrCreate(Point point)
static List< Point > ListVisible(Point p1, Point p2, int radius, Action< Point, bool > _onVisit=null, bool returnOnBlocked=true)
static bool IsVisible(Point p1, Point p2, Action< Point, bool > _onVisit=null)
static SourceMaterial.Row GetRandomMaterialFromCategory(int lv, string cat, SourceMaterial.Row fallback)
void SetBounds(int _x, int _z, int _maxX, int _maxZ)
void ForeachCell(Action< Cell > action)
new void ForeachXYZ(Action< int, int > action)
new void ForeachCell(Action< Cell > action)
void TrySmoothPick(Point p, Thing t, Chara c)
Thing FindThing(Type type, BaseArea area1, BaseArea area2=null)
void RefreshNeighborTiles(int x, int z)
Thing FindThing(Func< Thing, bool > func)
PlantData TryGetPlant(Point p)
void ForeachSphere(int _x, int _z, float r, Action< Point > action)
Dictionary< int, int > gatherCounts
void SetBridge(int x, int z, int height=0, int idMat=0, int idBridge=0, int dir=0, int idPillar=0, bool hidePillar=false)
static readonly int[] CellIdWidths
void Shift(Vector2Int offset)
Thing FindThing(Type type, Chara c=null)
void ExportMetaData(string _path, string id, PartialMap partial=null)
Chara FindChara(string id)
IEnumerable< Card > Cards
int[] ReadCellIds(string file, string s, int size, int width)
void RefreshSingleTile(int x, int z)
Point GetRandomPoint(Point center, int radius, int tries=100, bool mustBeWalkable=true, bool requireLos=true)
void RemovePlant(Point pos)
BaseArea FindPublicArea()
static void UpdateMetaData(string pathZip, PartialMap partial=null)
void DestroyObj(Point point)
void Save(string path, ZoneExportData export=null, PartialMap partial=null)
void TrySmoothPick(Cell cell, Thing t, Chara c)
Dictionary< string, int > cellWidths
void AddCardOnActivate(Card c)
Dictionary< int, CellEffect > cellEffects
void RefreshFOV(int x, int z, int radius=6, bool recalculate=false)
List< Point > ListPointsInArc(Point center, Point to, int radius, float angle)
void MoveCard(Point p, Card t)
Thing FindThing(string workTag, Chara c)
void AddBackerTree(bool draw)
void Reveal(Point center, int power=100)
void SetBlockDir(int x, int z, int dir)
void MineObj(Point point, Task task=null, Chara c=null)
void SetLiquid(int x, int z, CellEffect effect=null)
void OnCardRemovedFromZone(Card t)
Point GetNearbyResourcePoint(Point center)
void SetDecal(int x, int z, int id=0, int amount=1, bool refresh=true)
PlantData TryGetPlant(Cell c)
int CountChara(Faction faction)
void MineBlock(Point point, bool recoverBlock=false, Chara c=null, bool mineObj=true)
List< Chara > ListCharasInCircle(Point center, float radius, bool los=true)
void SetFloor(int x, int z, int idMat, int idFloor, int dir)
void OnDeserialized(StreamingContext context)
void SetFoormark(Point pos, int id, int angle, int offset=0)
byte[] TryLoadFile(string path, string s, int size)
void _ValidateInstalled(int x, int y)
int GetRampDir(int x, int z, TileType blockType=null)
Dictionary< int, int > backerObjs
void ModFire(int x, int z, int amount)
void SetDeco(int x, int z, int idMat, int idDeco)
void _AddCard(int x, int z, Card t, bool onAddToZone)
List< Chara > deadCharasShort
void Burn(int x, int z, bool instant=false)
void MineObjSound(Point point)
void OnSerializing(StreamingContext context)
void SetSeen(int x, int z, bool seen=true, bool refresh=true)
void ModLiquid(int x, int z, int amount)
void MineFloor(Point point, Chara c=null, bool recoverBlock=false, bool removePlatform=true)
void SetFloor(int x, int z, int idMat=0, int idFloor=0)
void SetBounds(MapBounds b)
void TryShatter(Point pos, int ele, int power, Card CC=null)
void SetBlock(int x, int z, int idMat=0, int idBlock=0)
PlantData AddPlant(Point pos, Thing seed)
void ForeachSquare(int _x, int _z, int r, Action< Point > action)
void TryRemoveRoom(int x, int z)
List< Footmark > footmarks
void SetRoofBlock(int x, int z, int idMat, int idBlock, int dir, int height)
new Point GetRandomEdge(int r=3)
void OnImport(ZoneExportData data)
List< Point > ListPointsInSquare(Point center, int radius, bool mustBeWalkable=true, bool los=true)
new void ForeachPoint(Action< Point > action)
void TryAddRoom(int x, int z)
void DestroyBlock(int x, int z)
void QuickRefreshTile(int x, int z)
List< Chara > serializedCharas
static bool isDirtySunMap
static MapMetaData GetMetaData(string pathZip)
virtual void OnSerializing()
static int WriteCellIds(string path, int[] ids, IO.Compression compression)
void RemoveLonelyRamps(Cell cell)
void SetBlock(int x, int z, int idMat, int idBlock, int dir)
void SetLiquid(int x, int z, int id, int value=1)
void ValidateInstalled(Point p)
void DropBlockComponent(Point point, TileRow r, SourceMaterial.Row mat, bool recoverBlock, bool isPlatform=false, Chara c=null)
MapExportSetting exportSetting
void SetEffect(int x, int z, CellEffect effect=null)
void OnCardAddedToZone(Card t, int x, int z)
Thing FindThing(string workTag, BaseArea area1=null, BaseArea area2=null)
void ForeachNeighbor(Point center, Action< Point > action)
void OnSetBlockOrDoor(int x, int z)
void Load(string path, bool import=false, PartialMap partial=null)
CellEffectManager effectManager
List< Point > ListPointsOnEdge(Point center, int destDist, bool mustBeWalkable=true, bool los=true)
List< Point > ListPointsInLine(Point center, Point to, int radius, bool returnOnBlocked=true)
Cell GetDependedRamp(Cell cell)
void MineRamp(Point point, int ramp, bool recoverBlock=false)
List< Point > ListPointsInCircle(Point center, float radius, bool mustBeWalkable=true, bool los=true)
void CreateNew(int size, bool setReference=true)
void AddDecal(int x, int z, int id, int amount=1, bool refresh=true)
void RevealAll(bool reveal=true)
IO.Compression compression
void SetObj(int x, int z, int idMat, int idObj, int value, int dir, bool ignoreRandomMat=false)
Dictionary< int, PlantData > plants
List< Chara > ListChara(Faction faction)
List< TransAnime > pointAnimes
void RefreshShadow(int x, int z)
void ApplyBackerObj(Point p, int id=-1)
void SetObj(int x, int z, int id=0, int value=1, int dir=0)
SourceBacker.Row GetBackerObj(Point p)
static string CellIdPath(string path, int width)
static HashSet< int > sunMap
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
static PathManager Instance
HashSet< int > doneBackers
void ClearMapHighlights()
SourceMaterial.Row matBlock
SourceMaterial.Row matFloor
List< Card > ListCards(bool includeMasked=false)
Point Set(int _x, int _z)
SourceMaterial.Row matBridge
void SetFloor(int idMat=0, int idFloor=0)
SoundSource PlaySound(string id, bool synced=true, float v=1f, bool spatial=true)
bool Equals(int _x, int _z)
SourceFloor.Row sourceFloor
void SetBlock(int idMat=0, int idBlock=0)
bool HasRoomOrArea(BaseArea a)
Point Clamp(bool useBounds=false)
float GetAngle2(Point to)
void Animate(AnimeID id, bool animeBlock=false)
SourceFloor.Row sourceBridge
void OnCardAddedToZone(Card c)
Dictionary< string, PropSet > workMap
static void SetSeed(int a=-1)
static List< RecipeSource > list
static RecipeSource Get(string id)
static SceneProfile Load(string id)
void AddActorEx(Card c, Action< ActorEx > onBeforeSetOwner=null)
void Restore(Map map, Map orgMap, bool addToZone, PartialMap partial=null)
void AddBlood(Point p, int a=1)
string GetSoundDead(RenderRow c=null)
bool OnMineWreck(Point point)
static Thing CreateRawMaterial(SourceMaterial.Row m)
static Thing CreateBlock(int id, int idMat)
static Thing CreateFloor(int id, int idMat, bool platform=false)
static Thing Create(string id, int idMat=-1, int lv=-1)
static Thing MakeSeed(string idSource)
virtual void OnAddedToZone()
virtual bool CanCopyInBlueprint
virtual void OnRemovedFromZone()
virtual List< Point > ListPoints(Point center=null, bool onlyPassable=true, bool allowChara=true)
virtual bool CanOnlyCarry
static void Say(string text, FontColor fontColor=FontColor.Default, Sprite sprite=null)
SerializedCards serializedCards
virtual bool DisableRooms
virtual bool IsUnderwater
Card AddCard(Card t, Point point)
void Init(IPathfindGrid _grid, WeightCell[,] _weightMap, int size)
bool IsBelow(int _major, int _minor, int _batch)