Commit c3d0abdd authored by Joe Libipl's avatar Joe Libipl

Finished (for now) converting NPCs to CellLoc.

parent b8f78f0a
......@@ -12,3 +12,4 @@
sanctuary
ste-reez-muvi.v12.suo
......@@ -92,8 +92,8 @@ public class CameraControlScript : MonoBehaviour {
angle -= 360F;
}
public void lookAtNpc(Vector3 npcCoords) {
transform.position = new Vector3((-1f) * npcCoords.x, (-1f) * npcCoords.y, (0.1f * npcCoords.z) + 15f);
transform.LookAt(new Vector3((-1f) * npcCoords.x, (-1f) * npcCoords.y, npcCoords.z));
public void lookAtNpc(Vector3 npcPos) {
transform.position = new Vector3(npcPos.x, npcPos.y, npcPos.z - 15f);
transform.LookAt(npcPos);
}
}
......@@ -21,7 +21,7 @@ namespace DragonsSpine.DAL
public static SqlConnection GetSQLConnection()
{
// string sConnStr = "User ID='db1_readonly';Password='IMakeMaps';Initial Catalog='DSpineBackup';Data Source='AQUALUNG\\SQLEXPRESS';Connect Timeout=15";
string sConnStr = "User ID='db1_readonly';Password='IMakeMaps';Initial Catalog='dragonsspine';Data Source='localhost\\MYTESTSQL';Connect Timeout=15";
string sConnStr = "User ID='db1_readonly';Password='IMakeMaps';Initial Catalog='dragonsspine';Data Source='localhost\\MYTESTSQL';Connect Timeout=30";
Utils.Log(sConnStr, Utils.LogType.SystemFailure);
try
{
......
Assets/Images/arrow_red.png

9.88 KB | W: | H:

Assets/Images/arrow_red.png

9.76 KB | W: | H:

Assets/Images/arrow_red.png
Assets/Images/arrow_red.png
Assets/Images/arrow_red.png
Assets/Images/arrow_red.png
  • 2-up
  • Swipe
  • Onion skin
using UnityEngine;
using System.Text;
public class GUIManager : MonoBehaviour {
private static GUIManager instance;
public MapManager mapManager;
public NpcManager npcManager;
public CameraControlScript mainCamera;
void Start () {
instance = this;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Z)) {
mapManager.CycleZ(false);
}
if (Input.GetKeyDown (KeyCode.A)) {
mapManager.CycleZ(true);
}
if (Input.GetKeyDown (KeyCode.Space)) {
mainCamera.ReturnToHome();
}
if (Input.GetKeyDown (KeyCode.N)) {
using UnityEngine;
using System.Text;
public class GUIManager : MonoBehaviour {
private static GUIManager instance;
public MapManager mapManager;
public NpcManager npcManager;
public CameraControlScript mainCamera;
void Start () {
instance = this;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Z)) {
mapManager.CycleZ(false);
}
if (Input.GetKeyDown (KeyCode.A)) {
mapManager.CycleZ(true);
}
if (Input.GetKeyDown (KeyCode.Space)) {
mainCamera.ReturnToHome();
}
if (Input.GetKeyDown (KeyCode.N)) {
CellLoc randomNpcCell = npcManager.locateRandomNpc();
Vector3 randomNpcPos = CLUtils.CellLocToVector3(randomNpcCell, 1);
mainCamera.lookAtNpc(randomNpcPos);
mapManager.UpdateZ(randomNpcPos.z + 1f);
}
}
void OnGUI(){
GUI.Box (new Rect (0,0,100,50), "# of cells\n" + mapManager.num_cells);
GUI.Box (new Rect (100,0,100,50), "NPC Instances\n" + npcManager.NumNpcScripts);
GUI.Box (new Rect (200,0,100,50), "Active NPC Insts\n" + npcManager.NumActiveNpcScripts);
GUI.Box (new Rect (300,0,100,50), "NPCs in DB\n" + npcManager.NumNpcsInDb);
GUI.Box (new Rect (Screen.width - 100,0,100,50), "# of blocks\n" + mapManager.num_blocks);
GUI.Box (new Rect (0,Screen.height - 50,100,50), "Z top\n" + mapManager.zTop);
StringBuilder builder = new StringBuilder();
foreach (int gameRound in npcManager.activeGameRounds)
builder.Append(gameRound).Append(" ");
GUI.Box (new Rect (Screen.width - 100,Screen.height - 50,100,50), "Game Round\n" + builder.ToString());
}
}
Vector3 randomNpcPos = CLUtils.CellLocToVector3(randomNpcCell, 1);
mainCamera.lookAtNpc(randomNpcPos);
mapManager.UpdateZ(randomNpcCell.z);
}
}
void OnGUI(){
GUI.Box (new Rect (0,0,100,50), "# of cells\n" + mapManager.num_cells);
GUI.Box (new Rect (100,0,100,50), "NPC Instances\n" + npcManager.NumNpcScripts);
GUI.Box (new Rect (200,0,100,50), "Active NPC Insts\n" + npcManager.NumActiveNpcScripts);
GUI.Box (new Rect (300,0,100,50), "NPCs in DB\n" + npcManager.NumNpcsInDb);
GUI.Box (new Rect (Screen.width - 100,0,100,50), "# of blocks\n" + mapManager.num_blocks);
GUI.Box (new Rect (0,Screen.height - 50,100,50), "Z top\n" + mapManager.zTop);
StringBuilder builder = new StringBuilder();
foreach (int gameRound in npcManager.activeGameRounds)
builder.Append(gameRound).Append(" ");
GUI.Box (new Rect (Screen.width - 100,Screen.height - 50,100,50), "Game Round\n" + builder.ToString());
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using DragonsSpine;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
public class MapManager : MonoBehaviour {
public NpcManager npcManager;
public int num_cells = 0;
public int num_blocks = 0;
public float zTop = 0;
public Transform prefab;
public Transform portalPrefab;
public Map ourMap;
public int[] zPlanes; // Array of elevations of Z planes, as copied from Map
public int currentZTopIdx; // Index into zPlanes for highest elevation currently visible
private Dictionary<CellLoc, Transform> cell_transforms;
public float nextDBUpdate;
public float dbUpdateDelta = 5f;
private List<string> cellKeyList;
private Dictionary<CellLoc, CellLite> cells;
private List<CellLoc> cellsKeys;
private Dictionary<CellLoc,Transform> portalTransforms;
System.Random myRandom = new System.Random();
void Awake() {
cells = new Dictionary<CellLoc, CellLite>();
}
void Start () {
nextDBUpdate = Time.time + dbUpdateDelta;
ourMap = new Map();
ourMap.Name = "Island of Kesmai";
if (LoadMapCells("Assets/IoKesmai.txt")) {
print ("Loaded map. " + ourMap.cells.Count + " cells loaded.");
} else {
print ("Failed to load map!");
Application.Quit();
}
currentZTopIdx = zPlanes.Length - 1;
portalTransforms = new Dictionary<CellLoc,Transform>();
Dictionary<CellLoc, bool> cellNeedsTransform = new Dictionary<CellLoc, bool>();
foreach (string k in cellKeyList) {
CellLoc mapPosition = new CellLoc(ourMap.cells[k].X, ourMap.cells[k].Y, ourMap.cells[k].Z);
cellNeedsTransform[mapPosition] = true; // Every cell needs a transform by default
}
// Make a list of the cells sorted by coordinates:
cellsKeys = new List<CellLoc>(cells.Keys);
cellsKeys.Sort(
delegate(CellLoc p1, CellLoc p2) {
int compareV = p1.z.CompareTo(p2.z);
if (compareV == 0) {
compareV = p1.y.CompareTo(p2.y);
if (compareV == 0) {
compareV = p1.x.CompareTo(p2.x);
}
}
return compareV;
}
);
// Look through and only create the transforms we need
cell_transforms = new Dictionary<CellLoc, Transform>();
var cellMaterials = new Dictionary<String,Material>();
foreach (CellLoc c in cellsKeys) {
num_cells++;
if (cellNeedsTransform[c]) {
// Instantiate this one
Vector3 position = CLUtils.CellLocToVector3(new CellLoc(cells[c].x, cells[c].y, cells[c].z), 0);
Transform tempts = Instantiate(prefab,
position,
Quaternion.identity) as Transform;
cell_transforms[c] = tempts;
Renderer rend = tempts.GetComponent<Renderer>();
rend.enabled = false;
if (!cellMaterials.ContainsKey(cells[c].displayGraphic)) {
String materialName = StringToAsciiHex(cells[c].displayGraphic);
Material cellMaterial = Resources.Load("Materials/Cells/" + materialName, typeof(Material)) as Material;
if (cellMaterial == null) {
print("Couldn't find material " + materialName + " for display graphic \"" + cells[c].displayGraphic + "\"!");
Debug.Break();
} else {
cellMaterials[cells[c].displayGraphic] = cellMaterial;
}
}
rend.material = cellMaterials[cells[c].displayGraphic];
rend.enabled = true;
// Now check to find the best chunk:
short bestXSize = 1, bestYSize = 1, currXSize = 1, currYSize = 1;
// 1. Find the maximum X size we could possible be
CellLoc nextCell = c; nextCell.x += 1;
while (cells.ContainsKey(nextCell) && cellNeedsTransform[nextCell] && cells[nextCell].displayGraphic == cells[c].displayGraphic) {
currXSize++;
nextCell.x += 1;
}
// 2. Work down from the maximum possible X, evaluating the max possible Y at each X size
while (currXSize >= 1) {
bool nextYGood = true;
while (nextYGood) {
for (short xOffset = 0; xOffset < currXSize; xOffset++) {
nextCell = c; nextCell.x += xOffset; nextCell.y += currYSize;
if (!(cells.ContainsKey(nextCell) && cellNeedsTransform[nextCell] && cells[nextCell].displayGraphic == cells[c].displayGraphic)) {
nextYGood = false;
}
}
if (nextYGood) currYSize++;
}
// 3. Keep track of the highest X*Y we've found so far
if (currXSize * currYSize > bestXSize * bestYSize) {
bestXSize = currXSize; bestYSize = currYSize;
}
currXSize--;
}
// Uncomment me for no grouping:
// bestXSize = 1; bestYSize = 1;
// print("Best size for cell " + v + " is " + bestXSize + "x, " + bestYSize + "y.");
// 4. Mark each cell we're absorbing
for (short yOffset = 0; yOffset < bestYSize; yOffset++) {
for (short xOffset = 0; xOffset < bestXSize; xOffset++) {
if (xOffset == 0 && yOffset == 0) continue;
cellNeedsTransform[new CellLoc(c.x + xOffset, c.y + yOffset, c.z)] = false;
}
}
// 5. Update the position, scale, and texture scale.
Vector3 firstCellPosition = CLUtils.CellLocToVector3(c, 0);
Vector3 lastCellPosition = CLUtils.CellLocToVector3(new CellLoc(c.x + (bestXSize - 1), c.y + (bestYSize - 1), c.z), 0);
tempts.position = (firstCellPosition + lastCellPosition) / 2f;
// tempts.position += new Vector3(-0.5f * (bestXSize - 1), -0.5f * (bestYSize - 1), 0f);
tempts.localScale += new Vector3((float) (bestXSize - 1), (float) (bestYSize - 1), 0f);
// Uncomment for borders between the blocks:
// tempts.localScale -= new Vector3(0.1f, 0.1f, 0f);
rend.material.mainTextureScale = new Vector2((-1f) * tempts.localScale.x, (-1f) * tempts.localScale.y);
}
if (cells[c].isMapPortal) {
Vector3 position = CLUtils.CellLocToVector3(new CellLoc(cells[c].x, cells[c].y, cells[c].z), 0);
position.z += 0.5f;
Transform tempts = Instantiate(portalPrefab,
position,
Quaternion.identity) as Transform;
portalTransforms[c] = tempts;
}
}
num_blocks = cell_transforms.Count;
print("Instantiated " + num_cells + " cells in " + cell_transforms.Count + " transforms.");
enabled = true;
}
void Update () {
if (Time.time > nextDBUpdate) {
print("Time to read from the DB! " + Time.time);
nextDBUpdate = Time.time + dbUpdateDelta;
UpdateCellContents();
}
}
public void UpdateZ(float z) {
Renderer currRend;
foreach (CellLoc c in cell_transforms.Keys) {
currRend = cell_transforms[c].GetComponent<Renderer>();
currRend.enabled = (c.z <= z);
}
npcManager.UpdateZ(z);
foreach (CellLoc c in portalTransforms.Keys) {
currRend = portalTransforms[c].GetComponent<Renderer>();
currRend.enabled = (c.z <= z);
}
zTop = z;
}
public void CycleZ(bool up) {
currentZTopIdx += (up ? 1 : -1);
if (currentZTopIdx < 0) currentZTopIdx = 0;
if (currentZTopIdx >= zPlanes.Length) currentZTopIdx = zPlanes.Length - 1;
UpdateZ(zPlanes[currentZTopIdx]);
}
private bool CoinFlip () {
return (UnityEngine.Random.Range(0f,1f) >= 0.5);
}
private void GameStart () {
enabled = true;
}
private void GameOver () {
enabled = false;
}
bool LoadMapCells(string filename) {
if (File.Exists(filename)) {
print ("Map file " + filename + " does exist.");
} else {
print ("Map file " + filename + " does not exist.");
}
if (ourMap.LoadMap(filename, 0, 0, 0)) {
print ("Loaded map. " + ourMap.cells.Count + " cells loaded.");
ourMap.ZPlanes.Sort();
zPlanes = ourMap.ZPlanes.ToArray();
cellKeyList = new List<string>(ourMap.cells.Keys);
cells.Clear();
foreach (string k in cellKeyList) {
CellLoc mapPosition = new CellLoc(ourMap.cells[k].X, ourMap.cells[k].Y, ourMap.cells[k].Z);
CellLite newCell;
newCell.displayGraphic = ourMap.cells[k].DisplayGraphic;
newCell.isMapPortal = ourMap.cells[k].IsMapPortal;
newCell.x = ourMap.cells[k].X;
newCell.y = ourMap.cells[k].Y;
newCell.z = ourMap.cells[k].Z;
cells.Add(mapPosition, newCell);
}
return true;
} else {
print ("Failed to load map!");
return false;
}
}
void UpdateCellContents() {
ourMap.UpdateCells();
}
String StringToAsciiHex(String s) {
byte[] ASCIIValues = Encoding.Convert(Encoding.Unicode, Encoding.ASCII, (Encoding.Unicode).GetBytes(s));
return BitConverter.ToString(ASCIIValues);
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using DragonsSpine;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
public class MapManager : MonoBehaviour {
public NpcManager npcManager;
public int num_cells = 0;
public int num_blocks = 0;
public float zTop = 0;
public Transform prefab;
public Transform portalPrefab;
public Map ourMap;
public int[] zPlanes; // Array of elevations of Z planes, as copied from Map
public int currentZTopIdx; // Index into zPlanes for highest elevation currently visible
private Dictionary<CellLoc, Transform> cell_transforms;
public float nextDBUpdate;
public float dbUpdateDelta = 5f;
private List<string> cellKeyList;
private Dictionary<CellLoc, CellLite> cells;
private List<CellLoc> cellsKeys;
private Dictionary<CellLoc,Transform> portalTransforms;
System.Random myRandom = new System.Random();
void Awake() {
cells = new Dictionary<CellLoc, CellLite>();
}
void Start () {
nextDBUpdate = Time.time + dbUpdateDelta;
ourMap = new Map();
ourMap.Name = "Island of Kesmai";
if (LoadMapCells("Assets/IoKesmai.txt")) {
print ("Loaded map. " + ourMap.cells.Count + " cells loaded.");
} else {
print ("Failed to load map!");
Application.Quit();
}
currentZTopIdx = zPlanes.Length - 1;
portalTransforms = new Dictionary<CellLoc,Transform>();
Dictionary<CellLoc, bool> cellNeedsTransform = new Dictionary<CellLoc, bool>();
foreach (string k in cellKeyList) {
CellLoc mapPosition = new CellLoc(ourMap.cells[k].X, ourMap.cells[k].Y, ourMap.cells[k].Z);
cellNeedsTransform[mapPosition] = true; // Every cell needs a transform by default
}
// Make a list of the cells sorted by coordinates:
cellsKeys = new List<CellLoc>(cells.Keys);
cellsKeys.Sort(
delegate(CellLoc p1, CellLoc p2) {
int compareV = p1.z.CompareTo(p2.z);
if (compareV == 0) {
compareV = p1.y.CompareTo(p2.y);
if (compareV == 0) {
compareV = p1.x.CompareTo(p2.x);
}
}
return compareV;
}
);
// Look through and only create the transforms we need
cell_transforms = new Dictionary<CellLoc, Transform>();
var cellMaterials = new Dictionary<String,Material>();
foreach (CellLoc c in cellsKeys) {
num_cells++;
if (cellNeedsTransform[c]) {
// Instantiate this one
Vector3 position = CLUtils.CellLocToVector3(new CellLoc(cells[c].x, cells[c].y, cells[c].z), 0);
Transform tempts = Instantiate(prefab,
position,
Quaternion.identity) as Transform;
cell_transforms[c] = tempts;
Renderer rend = tempts.GetComponent<Renderer>();
rend.enabled = false;
if (!cellMaterials.ContainsKey(cells[c].displayGraphic)) {
String materialName = StringToAsciiHex(cells[c].displayGraphic);
Material cellMaterial = Resources.Load("Materials/Cells/" + materialName, typeof(Material)) as Material;
if (cellMaterial == null) {
print("Couldn't find material " + materialName + " for display graphic \"" + cells[c].displayGraphic + "\"!");
Debug.Break();
} else {
cellMaterials[cells[c].displayGraphic] = cellMaterial;
}
}
rend.material = cellMaterials[cells[c].displayGraphic];
rend.enabled = true;
// Now check to find the best chunk:
short bestXSize = 1, bestYSize = 1, currXSize = 1, currYSize = 1;
// 1. Find the maximum X size we could possible be
CellLoc nextCell = c; nextCell.x += 1;
while (cells.ContainsKey(nextCell) && cellNeedsTransform[nextCell] && cells[nextCell].displayGraphic == cells[c].displayGraphic) {
currXSize++;
nextCell.x += 1;
}
// 2. Work down from the maximum possible X, evaluating the max possible Y at each X size
while (currXSize >= 1) {
bool nextYGood = true;
while (nextYGood) {
for (short xOffset = 0; xOffset < currXSize; xOffset++) {
nextCell = c; nextCell.x += xOffset; nextCell.y += currYSize;
if (!(cells.ContainsKey(nextCell) && cellNeedsTransform[nextCell] && cells[nextCell].displayGraphic == cells[c].displayGraphic)) {
nextYGood = false;
}
}
if (nextYGood) currYSize++;
}
// 3. Keep track of the highest X*Y we've found so far
if (currXSize * currYSize > bestXSize * bestYSize) {
bestXSize = currXSize; bestYSize = currYSize;
}
currXSize--;
}
// Uncomment me for no grouping:
// bestXSize = 1; bestYSize = 1;
// print("Best size for cell " + v + " is " + bestXSize + "x, " + bestYSize + "y.");
// 4. Mark each cell we're absorbing
for (short yOffset = 0; yOffset < bestYSize; yOffset++) {
for (short xOffset = 0; xOffset < bestXSize; xOffset++) {
if (xOffset == 0 && yOffset == 0) continue;
cellNeedsTransform[new CellLoc(c.x + xOffset, c.y + yOffset, c.z)] = false;
}
}
// 5. Update the position, scale, and texture scale.
Vector3 firstCellPosition = CLUtils.CellLocToVector3(c, 0);
Vector3 lastCellPosition = CLUtils.CellLocToVector3(new CellLoc(c.x + (bestXSize - 1), c.y + (bestYSize - 1), c.z), 0);
tempts.position = (firstCellPosition + lastCellPosition) / 2f;
// tempts.position += new Vector3(-0.5f * (bestXSize - 1), -0.5f * (bestYSize - 1), 0f);
tempts.localScale += new Vector3((float) (bestXSize - 1), (float) (bestYSize - 1), 0f);
// Uncomment for borders between the blocks:
// tempts.localScale -= new Vector3(0.1f, 0.1f, 0f);
rend.material.mainTextureScale = new Vector2((-1f) * tempts.localScale.x, (-1f) * tempts.localScale.y);
}
if (cells[c].isMapPortal) {
Vector3 position = CLUtils.CellLocToVector3(new CellLoc(cells[c].x, cells[c].y, cells[c].z), 0);
position.z += 0.5f;
Transform tempts = Instantiate(portalPrefab,
position,
Quaternion.identity) as Transform;
portalTransforms[c] = tempts;
}
}
num_blocks = cell_transforms.Count;
print("Instantiated " + num_cells + " cells in " + cell_transforms.Count + " transforms.");
enabled = true;
}
void Update () {
if (Time.time > nextDBUpdate) {
print("Time to read from the DB! " + Time.time);
nextDBUpdate = Time.time + dbUpdateDelta;
UpdateCellContents();
}
}
public void UpdateZ(float z) {
Renderer currRend;
foreach (CellLoc c in cell_transforms.Keys) {
currRend = cell_transforms[c].GetComponent<Renderer>();
currRend.enabled = (c.z <= z);
}
npcManager.UpdateZ(z);
foreach (CellLoc c in portalTransforms.Keys) {
currRend = portalTransforms[c].GetComponent<Renderer>();
currRend.enabled = (c.z <= z);
}
zTop = z;
}
public void CycleZ(bool up) {
currentZTopIdx += (up ? 1 : -1);
if (currentZTopIdx < 0) currentZTopIdx = 0;
if (currentZTopIdx >= zPlanes.Length) currentZTopIdx = zPlanes.Length - 1;
UpdateZ(zPlanes[currentZTopIdx]);
}
private bool CoinFlip () {
return (UnityEngine.Random.Range(0f,1f) >= 0.5);
}
private void GameStart () {
enabled = true;
}