improve filestructure

This commit is contained in:
ApfelTeeSaft
2026-05-03 18:27:13 +02:00
parent 304ced2ca3
commit 4e36bfd311
200 changed files with 142196 additions and 145469 deletions
-9
View File
@@ -1,9 +0,0 @@
[submodule "gameBase2"]
path = external/gameBase
url = https://github.com/devZoGok/gameBase
[submodule "external/vb01"]
path = external/vb01
url = https://github.com/devZoGok/vb01
[submodule "external/tinydir"]
path = external/tinydir
url = https://github.com/cxong/tinydir
+21 -22
View File
@@ -12,33 +12,32 @@ metadata = {
{
units = {
{id = 10, pos = {x = -105.929001, y = -0.110725, z = -404.756104}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
}
},
resourceDeposits = {}
},
{
units = {
{id = 10, pos = {x = -20.215218, y = 0.000000, z = 365.251648}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
}
},
{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = -20.215218, y = 0.000000, z = 365.251648}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
resourceDeposits = {}
}
},
civilianPlayer = {
resourceDeposits = {
{id = 0, pos = {x = -105.929001, y = -0.110725, z = -404.756104}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 111.306473, y = 0.000031, z = -413.114807}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 72.301971, y = 0.000023, z = -363.649902}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 15.789061, y = -0.010529, z = -308.128113}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 37.890579, y = 0.000076, z = -405.671021}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 39.080250, y = 0.000000, z = -367.778442}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 34.379860, y = 0.000015, z = 329.448395}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 31.606178, y = 0.000000, z = 352.831665}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 17.326164, y = 0.000046, z = 390.545441}, rot = {w = -0.770531, x = 0.000000, y = -0.637403, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -7.834114, y = 0.000000, z = 390.160706}, rot = {w = -0.251298, x = 0.000000, y = -0.967910, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 10.215218, y = 0.000000, z = 365.251648}, rot = {w = -0.251298, x = 0.000000, y = -0.967910, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 37.141624, y = 0.000031, z = 369.058044}, rot = {w = -0.251298, x = 0.000000, y = -0.967910, z = 0.000000}, initAmmount = 20000},
},
units = {},
resourceDeposits = {
{id = 0, pos = {x = -105.929001, y = -0.110725, z = -404.756104}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 111.306473, y = 0.000031, z = -413.114807}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 72.301971, y = 0.000023, z = -363.649902}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 15.789061, y = -0.010529, z = -308.128113}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 37.890579, y = 0.000076, z = -405.671021}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 39.080250, y = 0.000000, z = -367.778442}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 34.379860, y = 0.000015, z = 329.448395}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 31.606178, y = 0.000000, z = 352.831665}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 17.326164, y = 0.000046, z = 390.545441}, rot = {w = -0.770531, x = 0.000000, y = -0.637403, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -7.834114, y = 0.000000, z = 390.160706}, rot = {w = -0.251298, x = 0.000000, y = -0.967910, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 10.215218, y = 0.000000, z = 365.251648}, rot = {w = -0.251298, x = 0.000000, y = -0.967910, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 37.141624, y = 0.000031, z = 369.058044}, rot = {w = -0.251298, x = 0.000000, y = -0.967910, z = 0.000000}, initAmmount = 20000},
}
},
skybox = "Skybox1",
terrain = {model = "2lakes.xml", albedo = "2lakes.jpg"},
File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 837 B

After

Width:  |  Height:  |  Size: 9.5 KiB

+30 -33
View File
@@ -6,52 +6,49 @@ metadata = {
impassibleNodeValue = 65535,
spawnPoints = {
{x = 50.410851, y = 0.000046, z = -472.358398},
{x = 387.292053, y = 0.035400, z = 479.050964},
{x = -450.032196, y = 0.000031, z = 417.242737},
{x = 407.292053, y = 0.035400, z = 449.050964},
{x = -450.032196, y = 0.000031, z = 417.242737}
},
choosablePlayers = {
{
units = {
{id = 10, pos = {x = 50.410851, y = 0.000046, z = -472.358398}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = UnitId.ACS_TANK, pos = {x = -280.500000, y = 0, z = -496.500000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 24, pos = {x = 403.000000, y = -18.453316, z = -343.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
}
{id = UnitId.ACS_MECH, pos = {x = 50.410851, y = 0.000046, z = -472.358398}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
resourceDeposits = {}
},
{
units = {
{id = 0, pos = {x = 387.292053, y = 0.035400, z = 482.050964}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
}
{id = UnitId.ACS_MECH, pos = {x = 407.292053, y = 0.035400, z = 449.050964}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
resourceDeposits = {}
},
{
units = {
{id = 10, pos = {x = -450.032196, y = 0.000031, z = 417.242737}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
}
{id = UnitId.ACS_MECH, pos = {x = -450.032196, y = 0.000031, z = 417.242737}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
resourceDeposits = {}
},
},
civilianPlayer = {
resourceDeposits = {
{id = 0, pos = {x = 407.292053, y = 0.035400, z = 449.050964}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 388.774841, y = 0.028824, z = 448.299225}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 368.191223, y = 0.020782, z = 448.422272}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 347.570312, y = 0.008224, z = 407.701385}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 373.537720, y = 0.019989, z = 422.497559}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -450.032196, y = 0.000031, z = 417.242737}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -425.042511, y = 0.000031, z = 411.944916}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -400.767151, y = 0.000061, z = 391.045227}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -421.781281, y = 0.000046, z = 391.056610}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -438.017151, y = 0.000031, z = 402.490692}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -410.310394, y = 0.000061, z = 422.562714}, rot = {w = -0.969856, x = 0.000000, y = -0.243677, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 50.410851, y = 0.000046, z = -472.358398}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 31.740002, y = 0.000031, z = -463.164642}, rot = {w = 0.966213, x = 0.000000, y = 0.257746, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 39.761688, y = 0.000046, z = -436.009583}, rot = {w = 0.526699, x = 0.000000, y = -0.850052, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 57.385757, y = 0.000092, z = -451.965759}, rot = {w = -0.955132, x = 0.000000, y = -0.296180, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 72.339455, y = 0.000015, z = -473.400116}, rot = {w = -0.955132, x = 0.000000, y = -0.296180, z = 0.000000}, initAmmount = 20000},
},
units = {},
resourceDeposits = {
{id = 0, pos = {x = 407.292053, y = 0.035400, z = 449.050964}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 388.774841, y = 0.028824, z = 448.299225}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 368.191223, y = 0.020782, z = 448.422272}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 347.570312, y = 0.008224, z = 407.701385}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 373.537720, y = 0.019989, z = 422.497559}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -450.032196, y = 0.000031, z = 417.242737}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -425.042511, y = 0.000031, z = 411.944916}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -400.767151, y = 0.000061, z = 391.045227}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -421.781281, y = 0.000046, z = 391.056610}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -438.017151, y = 0.000031, z = 402.490692}, rot = {w = -0.275866, x = 0.000000, y = 0.961196, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -410.310394, y = 0.000061, z = 422.562714}, rot = {w = -0.969856, x = 0.000000, y = -0.243677, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 50.410851, y = 0.000046, z = -472.358398}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 31.740002, y = 0.000031, z = -463.164642}, rot = {w = 0.966213, x = 0.000000, y = 0.257746, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 39.761688, y = 0.000046, z = -436.009583}, rot = {w = 0.526699, x = 0.000000, y = -0.850052, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 57.385757, y = 0.000092, z = -451.965759}, rot = {w = -0.955132, x = 0.000000, y = -0.296180, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 72.339455, y = 0.000015, z = -473.400116}, rot = {w = -0.955132, x = 0.000000, y = -0.296180, z = 0.000000}, initAmmount = 20000},
},
},
skybox = "Skybox1",
File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 13 KiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

+8 -41
View File
@@ -6,62 +6,29 @@ metadata = {
impassibleNodeValue = 65535,
spawnPoints = {
{x = -396.000000, y = 0.000000, z = -374.000000},
{x = 300.000000, y = 0.000000, z = 400.000000},
{x = 360.000000, y = 0.000000, z = 400.000000},
{x = -326.000000, y = 0.000000, z = 374.000000},
},
choosablePlayers = {
{
units = {
{id = 10, pos = {x = -20.000000, y = 0.000000, z = -20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 300.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 345.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
resourceDeposits = {}
},
{
units = {
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 445.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_NAVAL_FACTORY, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = 280.000000, y = 0.000000, z = 450.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_LAND_FACTORY, pos = {x = 305.000000, y = 0.000000, z = 445.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
--{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = 280.000000, y = 0.000000, z = 445.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = 280.000000, y = 0.000000, z = 440.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = 280.000000, y = 0.000000, z = 435.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = 280.000000, y = 0.000000, z = 430.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 460.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 465.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 450.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 455.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 440.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 445.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 430.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 435.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_MECH, pos = {x = 325.000000, y = 0.000000, z = 420.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 425.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 410.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 415.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 410.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 405.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TANK, pos = {x = 325.000000, y = 0.000000, z = 400.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_ARTILLERY, pos = {x = 325.000000, y = 0.000000, z = 355.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_ARTILLERY, pos = {x = 325.000000, y = 0.000000, z = 350.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_ARTILLERY, pos = {x = 325.000000, y = 0.000000, z = 355.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_ARTILLERY, pos = {x = 325.000000, y = 0.000000, z = 350.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_ARTILLERY, pos = {x = 325.000000, y = 0.000000, z = 355.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_ANTI_SUB_CRUISER, pos = {x = -20.000000, y = 0.000000, z = -20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TRANSPORT, pos = {x = -20.000000, y = 0.000000, z = -20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_TRANSPORT, pos = {x = -20.000000, y = 0.000000, z = -20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = 325.000000, y = 0.000000, z = 445.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = 325.000000, y = 0.000000, z = 445.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
resourceDeposits = {}
},
{
units = {
{id = UnitId.ACS_CYBORG_ENGINEER, pos = {x = -325.000000, y = 0.000000, z = 415.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = UnitId.AINC_CYBORG_ENGINEER, pos = {x = -325.000000, y = 0.000000, z = 415.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
resourceDeposits = {}
},
--[[
]]--
},
civilianPlayer = {
resourceDeposits = {
@@ -69,10 +36,10 @@ metadata = {
{id = 0, pos = {x = 450.000000, y = 0.000000, z = 430.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 450.000000, y = 0.000000, z = 410.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = 450.000000, y = 0.000000, z = 390.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
--{id = 0, pos = {x = -450.000000, y = 0.000000, z = 350.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
--{id = 0, pos = {x = -450.000000, y = 0.000000, z = 360.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
--{id = 0, pos = {x = -450.000000, y = 0.000000, z = 370.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
--{id = 0, pos = {x = -450.000000, y = 0.000000, z = 380.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -450.000000, y = 0.000000, z = 350.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -450.000000, y = 0.000000, z = 360.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -450.000000, y = 0.000000, z = 370.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
{id = 0, pos = {x = -450.000000, y = 0.000000, z = 380.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 20000},
},
},
File diff suppressed because it is too large Load Diff
+23 -33
View File
@@ -126,41 +126,33 @@ function Player:landRouteToSpawnpoint_(mapPoint)
source = map:getCellId(map:getSpawnPoint(self:getSpawnPointId()), false)
pf = Pathfinder.getSingleton()
forwClampedDest = pf:clampDestToSourceRegion(source, dest)
cells = map:getCells()
heurs = pf:calcHeuristics(cells, dest)
path = pf:findPath(cells, heurs, source, dest, UnitType.HOVER)
if dest ~= forwClampedDest then
cells = map:getCells()
embarkCellId = nil
disembarkCellId = nil
navalSupportCellId = nil
navalRallyCellId = nil
embarkCellId = nil
navalRallyCellId = nil
embarkCellId = forwClampedDest
for i = 1, #cells[embarkCellId + 1].edges do
destCellId = cells[embarkCellId + 1].edges[i].destCellId
if cells[destCellId + 1].type == 1 then
if not self.navalFactoryCellId then self.navalFactoryCellId = destCellId end
navalRallyCellId = destCellId
break
end
for i = 1, #path do
if map:getCell(path[i]).type == 1 then
navalRallyCellId = path[i]
embarkCellId = path[i - 1]
if not self.navalFactoryCellId then self.navalFactoryCellId = path[i] end
break;
end
end
disembarkCellId = nil
navalSupportCellId = nil
backwClampedDest = pf:clampDestToSourceRegion(dest, embarkCellId)
disembarkCellId = backwClampedDest
for i = 1, #cells[disembarkCellId + 1].edges do
destCellId = cells[disembarkCellId + 1].edges[i].destCellId
if cells[destCellId + 1].type == 1 then
navalSupportCellId = destCellId
break
end
for i = #path, 1, -1 do
if map:getCell(path[i]).type == 1 then
navalSupportCellId = path[i]
disembarkCellId = path[i + 1]
break;
end
end
if embarkCellId or disembarkCellId then
return {
reachable = false,
embarkCellId = embarkCellId,
@@ -168,9 +160,7 @@ function Player:landRouteToSpawnpoint_(mapPoint)
navalSupportCellId = navalSupportCellId,
disembarkCellId = disembarkCellId
}
else
return {reachable = true}
end
else return {reachable = true} end
end
function Player:landRouteToSpawnpoint(arguments)
-88
View File
@@ -1,88 +0,0 @@
cmake_minimum_required(VERSION 3.5)
set(GAME_NAME battleship)
project(${GAME_NAME})
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pedantic")
endif()
set(CMAKE_CXX_STANDART 17)
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
set(CMAKE_BUILD_TYPE Debug)
set(BUILD_TESTS OFF)
set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED)
cmake_policy(SET CMP0015 NEW)
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp loadingAppState.cpp)
set(UNIT_BUTTONS unitButton.cpp tradeButton.cpp buildButton.cpp trainButton.cpp researchButton.cpp orderButton.cpp stateToggleButton.cpp)
set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp)
set(TRADING_BUTTONS activeStateBackButton.cpp playerTradeButton.cpp tradingScreenButton.cpp offerButton.cpp resourceAmmountButton.cpp)
set(MENU_BUTTONS mainMenuButton.cpp singlePlayerButton.cpp exitButton.cpp backButton.cpp playButton.cpp)
set(MAP_EDITOR_BUTTONS mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp exportButton.cpp)
set(BUTTONS statsButton.cpp activeStateButton.cpp minimapButton.cpp ${TRADING_BUTTONS} ${OPTIONS_BUTTONS} ${MENU_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS})
set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp mapListbox.cpp)
set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp)
set(CORE gameManager.cpp game.cpp pathfinder.cpp environment.cpp fxManager.cpp defConfigs.cpp player.cpp trader.cpp ${CONSOLE} ${CONTROLLERS})
set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp depthCharge.cpp torpedo.cpp torpedo.h)
set(VEHICLES vehicle.cpp submarine.cpp engineer.cpp resourceRover.cpp freezer.cpp)
set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp iceSheet.cpp)
set(WEAPONS weapon.cpp)
set(UNITS unit.cpp ${WEAPONS} ${STRUCTURES} ${VEHICLES})
set(CONTENT map.cpp gameObject.cpp destructable.cpp gameObjectFrame.h gameObjectFactory.cpp resourceDeposit.cpp ${UNITS} ${PROJECTILES})
set(UTIL util.cpp binds.h)
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
set(SFML_DIR external/gameBase/external/SFML)
set(VB01_DIR external/vb01)
set(VB01_GUI_DIR external/vb01Gui)
set(GAME_BASE_DIR external/gameBase)
add_executable(${GAME_NAME} main.cpp ${GAME_SRC})
include_directories(external/tinydir)
include_directories(external/vb01/external/glm)
include_directories(external/vb01/external/glm/glm)
include_directories(external/gameBase/external/SFML/include)
add_subdirectory(${VB01_DIR})
set(VB01_LIB_DIR ${VB01_DIR}/build)
target_include_directories(${GAME_NAME} PUBLIC ${VB01_DIR})
target_link_directories(${GAME_NAME} PUBLIC ${VB01_LIB_DIR})
add_subdirectory(${GAME_BASE_DIR})
set(GAME_BASE_LIB_DIR build/${GAME_BASE_DIR}/src)
target_include_directories(${GAME_NAME} PUBLIC ${GAME_BASE_DIR})
target_link_directories(${GAME_NAME} PUBLIC ${GAME_BASE_LIB_DIR})
set(DEPS vb01 gameBase)
target_link_libraries(${GAME_NAME} ${DEPS})
if(BUILD_TESTS)
if(UNIX)
include_directories(/usr/include/cppunit)
link_directories(/usr/lib)
elseif(WIN32)
include_directories(C:/Program\ Files\ \(x86\)/cppunit/include)
link_directories(C:/Program\ Files\ \(x86\)/cppunit/lib)
endif()
set(TEST_SRC testMain.cpp pathfinderTest.cpp ${GAME_SRC})
set(TEST_NAME battleshipTests)
add_executable(${TEST_NAME} ${TEST_SRC})
target_include_directories(${TEST_NAME} PUBLIC ${VB01_DIR})
target_include_directories(${TEST_NAME} PUBLIC ${VB01_GUI_DIR})
target_include_directories(${TEST_NAME} PUBLIC ${GAME_BASE_DIR})
target_link_libraries(${TEST_NAME} ${DEPS} cppunit)
endif()
-37
View File
@@ -1,37 +0,0 @@
# Battleship
## Build guide
### UNIX
- `git clone <battleship_url>`
- `cd Battteship`
- `git submodule update --init --recursive`
- `cmake -S . -B build`
- `cd build`
- `make`
### Windows
- `git clone <battleship_url>`
- `cd Battteship`
- `git submodule update --init --recursive`
- `cmake -S . -B <build_dir> [-G <present_visual_studio_version>] -DSFML_BUILD_GRAPHICS=0`
- open `build\ALL_BUILD.vcxproj`
- build the solution (in case of the fatal error C1128, use, for example, the `RelWithDebInfo` build configuration)
- copy and paste `battleship.exe` into `<build_dir>`
## Contrib guide
The Gitflow shall be used.
1. create an issue, representing a change you wish to implement using one of these labels:
* `feature`
* `improvement`
* `bugfix`
2. create a branch off the `develop` branch, named using this scheme:
* `feature` label -> `ft-<issue_number>-<short_description>`
* `improvement` label -> `imp-<issue_number>-<short_description>`
* `bugfix` label -> `bf-<issue_number>-<short_description>`
3. create a PR with a short description of changes and evidence of the issue resolved, such as:
* reference to an automatic test(s) to run
* steps to manually verify the issue is resolved
* screenshots or screencasts
4. await the repo admin's approval
-32
View File
@@ -1,32 +0,0 @@
#ifndef ABILITY_H
#define ABILITY_H
#include <vector>
namespace battleship{
struct Ability{
enum class Type{
SPEED,
HEALTH,
LINE_OF_SIGHT,
MAX_TURN_ANGLE,
DIRECT_HIT_DAMAGE,
EXPLOSION_RADIUS,
EXPLOSION_DAMAGE,
CAPACITY,
LOAD_RATE,
LOAD_SPEED,
DRAW_RATE,
DRAW_SPEED,
HACK_RANGE,
UNIT_UNLOCK
};
Type type;
float ammount;
int gameObjType;
std::vector<int> gameObjIds;
};
}
#endif
-33
View File
@@ -1,33 +0,0 @@
#include "abstractCommand.h"
#include <cmath>
#include <vector.h>
namespace battleship{
using namespace std;
void AbstractCommand::handle(){
if(cmdStr.find(" ") == -1)
return;
vector<int> spaceIds;
arguments.clear();
for(int i = 0; i < cmdStr.length(); i++)
if(cmdStr[i] == ' ')
spaceIds.push_back(i);
arguments.push_back(cmdStr.substr(0, spaceIds[0]));
for(int i = 0; i < spaceIds.size(); i++){
bool lastSpace = (i == spaceIds.size() - 1);
string argument = cmdStr.substr(spaceIds[i] + 1, lastSpace ? string::npos : spaceIds[i + 1] - spaceIds[i] - 1);
arguments.push_back(argument);
}
}
void AbstractCommand::execute(){
handle();
validate();
}
}
-20
View File
@@ -1,20 +0,0 @@
#ifndef ABSTRACT_COMMAND_H
#define ABSTRACT_COMMAND_H
#include <string>
#include <vector>
namespace battleship{
class AbstractCommand{
protected:
AbstractCommand(std::string str) : cmdStr(str){}
virtual void handle();
virtual void validate(){}
virtual void execute();
std::string cmdStr;
std::vector<std::string> arguments;
};
}
#endif
-857
View File
@@ -1,857 +0,0 @@
#include <root.h>
#include <quaternion.h>
#include <model.h>
#include <material.h>
#include <texture.h>
#include <quad.h>
#include <box.h>
#include <text.h>
#include <assetManager.h>
#include <imageAsset.h>
#include <stateManager.h>
#include <solUtil.h>
#include <algorithm>
#include <ctype.h>
#include <stdlib.h>
#include <map>
#include "activeGameState.h"
#include "inGameAppState.h"
#include "defConfigs.h"
#include "structure.h"
#include "game.h"
#include "util.h"
#include "tooltip.h"
#include "gameObjectFrameController.h"
#include "gameObjectFactory.h"
#include "cameraController.h"
#include "unitButton.h"
#include "extractor.h"
#include "resourceDeposit.h"
#include "resourceRover.h"
#include "concreteGuiManager.h"
using namespace vb01;
using namespace vb01Gui;
using namespace std;
namespace battleship{
using namespace configData;
using namespace gameBase;
ActiveGameState::ActiveGameState(GuiAppState *gs, int plId) : AbstractAppState(
AppStateType::ACTIVE_STATE,
configData::calcSumBinds(AppStateType::ACTIVE_STATE, true),
configData::calcSumBinds(AppStateType::ACTIVE_STATE, false),
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]), guiState(gs), playerId(plId), depth(1){
initDragbox();
mainPlayer = Game::getSingleton()->getPlayer(playerId);
}
ActiveGameState::~ActiveGameState() {
removeDragbox();
}
void ActiveGameState::initDragbox(){
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "gui");
mat->addBoolUniform("texturingEnabled", false);
mat->addBoolUniform("diffuseColorEnabled", false);
mat->addVec4Uniform("diffuseColor", Vector4(.5, .5, .5, .5));
Quad *dragbox = new Quad(Vector3::VEC_ZERO, false);
dragbox->setMaterial(mat);
dragboxNode = new Node();
dragboxNode->attachMesh(dragbox);
root->getGuiNode()->attachChild(dragboxNode);
}
void ActiveGameState::initCursor(){
string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Cursors/";
sol::state_view SOL_LUA_VIEW = generateView();
string pt = SOL_LUA_VIEW["pointerTex"],
at = SOL_LUA_VIEW["attackTex"],
gt = SOL_LUA_VIEW["garrisonTex"],
st = SOL_LUA_VIEW["supplyTex"],
ht = SOL_LUA_VIEW["hackTex"],
ngt = SOL_LUA_VIEW["noGarrisonTex"],
nst = SOL_LUA_VIEW["noSupplyTex"],
nht = SOL_LUA_VIEW["noHackTex"],
p1[]{basePath + pt},
p2[]{basePath + at},
p3[]{basePath + gt},
p4[]{basePath + st},
p5[]{basePath + ht},
p6[]{basePath + ngt},
p7[]{basePath + nst},
p8[]{basePath + nht};
pointerTex = new Texture(p1, 1, false);
attackTex = new Texture(p2, 1, false);
garrisonTex = new Texture(p3, 1, false);
supplyTex = new Texture(p4, 1, false);
hackTex = new Texture(p5, 1, false);
noGarrisonTex = new Texture(p6, 1, false);
noSupplyTex = new Texture(p7, 1, false);
noHackTex = new Texture(p8, 1, false);
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "gui");
mat->addBoolUniform("texturingEnabled", true);
mat->addTexUniform("diffuseMap", pointerTex, false);
Quad *quad = new Quad(Vector3(20, 20, 0), false);
quad->setMaterial(mat);
cursorNode = new Node();
cursorNode->attachMesh(quad);
root->getGuiNode()->attachChild(cursorNode);
}
void ActiveGameState::removeDragbox(){
Root::getSingleton()->getRootNode()->dettachChild(dragboxNode);
delete dragboxNode;
}
void ActiveGameState::onAttached() {
AbstractAppState::onAttached();
vector<Button*> buttons = guiButtons;
buttons.insert(buttons.end(), unitButtons.begin(), unitButtons.end());
ConcreteGuiManager::getSingleton()->readLuaScreenScript(
"activeGameState.lua",
buttons,
vector<Listbox*>{},
vector<Checkbox*>{},
vector<Slider*>{},
vector<Textbox*>{},
guiRects,
guiTexts,
"music = generateFactionMusic(" + to_string(mainPlayer->getFaction()) + ")"
);
if(!cursorNode) initCursor();
}
void ActiveGameState::onDettached() {
AbstractAppState::onDettached();
}
void ActiveGameState::updateCursor(){
Vector2 cursorPos = getCursorPos();
cursorNode->setPosition(Vector3(cursorPos.x, cursorPos.y, .8));
if(mainPlayer->getNumSelectedUnits() > 0){
bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer() == mainPlayer);
bool alliedGameObj = (gameObjHoveredOn && !ownGameObj && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam());
bool gameObjUnit = (gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT);
bool gameObjTransport = (gameObjUnit && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0);
bool canGarrison = true;
if(gameObjUnit && gameObjTransport)
for(int i = 0; i < mainPlayer->getNumSelectedUnits(); i++)
if(!((Unit*)gameObjHoveredOn)->canGarrison((Vehicle*)mainPlayer->getSelectedUnit(i))){
canGarrison = false;
break;
}
vector<TradeOffer*> offers = (gameObjHoveredOn && alliedGameObj ? mainPlayer->getTradeOffers(gameObjHoveredOn->getPlayer()) : vector<TradeOffer*>{});
bool tradeResource[NUM_RESOURCES][2], trade = false;
for(int i = 0; i < NUM_RESOURCES; i++)
for(int j = 0; j < 2; j++){
if(!offers.empty() && offers[0]->tradeResources[i][j] > 0){
tradeResource[i][j] = true;
trade = true;
}
else tradeResource[i][j] = false;
}
int objClass = (gameObjUnit ? int(((Unit*)gameObjHoveredOn)->getUnitClass()) : -1);
bool tradeCenter = ((UnitClass)objClass == UnitClass::TRADE_CENTER);
bool refinery = ((UnitClass)objClass == UnitClass::REFINERY);
bool lab = ((UnitClass)objClass == UnitClass::LAB);
bool ownExtractor = (ownGameObj && (UnitClass)objClass == UnitClass::EXTRACTOR);
bool roverSelected = (mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::RESOURCE_ROVER);
ResourceRover *rover = (roverSelected ? (ResourceRover*)mainPlayer->getSelectedUnit(0) : nullptr);
int unloadFlag = (int)shiftPressed;
if(!forceCursorState){
if(gameObjUnit && gameObjTransport){
orderPossible = (ownGameObj && canGarrison);
cursorState = CursorState::GARRISON;
}
else if(roverSelected && ownExtractor){
orderPossible = (((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount() > 0);
cursorState = CursorState::SUPPLY;
}
else if(roverSelected && (tradeCenter || refinery || lab) && (ownGameObj || (alliedGameObj && trade))){
bool tradeRes = false;
int resId;
switch((UnitClass)objClass){
case UnitClass::TRADE_CENTER:
tradeRes = tradeResource[(int)ResourceType::WEALTH][unloadFlag];
resId = (int)ResourceType::WEALTH;
break;
case UnitClass::REFINERY:
tradeRes = tradeResource[(int)ResourceType::REFINEDS][unloadFlag];
resId = (int)ResourceType::REFINEDS;
break;
case UnitClass::LAB:
tradeRes = tradeResource[(int)ResourceType::RESEARCH][unloadFlag];
resId = (int)ResourceType::RESEARCH;
break;
}
bool canLoad = (rover && rover->calcTotalLoad() < rover->getCapacity());
orderPossible = (unloadFlag ? rover->getLoad(resId) > 0 : canLoad);
if(alliedGameObj) orderPossible = tradeRes && orderPossible;
cursorState = (unloadFlag ? CursorState::UNLOAD : CursorState::LOAD);
}
else if(gameObjUnit && !(ownGameObj || alliedGameObj)){
orderPossible = true;
cursorState = CursorState::ATTACK;
}
else
cursorState = CursorState::NORMAL;
}
else{
if(cursorState == CursorState::GARRISON)
orderPossible = (ownGameObj && gameObjTransport && canGarrison);
else if(cursorState == CursorState::SUPPLY)
orderPossible = (roverSelected && ownExtractor);
else if(cursorState == CursorState::LOAD || cursorState == CursorState::UNLOAD){
int ulf = int(cursorState == CursorState::UNLOAD);
bool tradeRefs = tradeResource[(int)ResourceType::REFINEDS][ulf];
bool tradeWealth = tradeResource[(int)ResourceType::WEALTH][ulf];
bool tradeTech = tradeResource[(int)ResourceType::RESEARCH][ulf];
bool canLoad = (rover->calcTotalLoad() < rover->getCapacity());
bool loadResource = (
cursorState == CursorState::LOAD ? canLoad : (
rover->getLoad((int)ResourceType::REFINEDS) > 0 ||
rover->getLoad((int)ResourceType::WEALTH) > 0 ||
rover->getLoad((int)ResourceType::RESEARCH) > 0
)
);
bool transferResource = (
(refinery && loadResource && (ownGameObj || (alliedGameObj && tradeRefs))) ||
(tradeCenter && loadResource && (ownGameObj || (alliedGameObj && tradeWealth))) ||
(lab && loadResource && (ownGameObj || (alliedGameObj && tradeTech)))
);
orderPossible = (roverSelected && transferResource);
}
else if(cursorState == CursorState::HACK)
orderPossible = (!ownGameObj && gameObjUnit && mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::CYBORG_ENGINEER);
else if(controlPressed)
cursorState = CursorState::ATTACK;
else
cursorState = CursorState::NORMAL;
}
}
cursorNode->setVisible(cursorState != CursorState::NORMAL);
Texture *tex = nullptr;
switch(cursorState){
case CursorState::ATTACK:
tex = attackTex;
break;
case CursorState::GARRISON:
tex = (orderPossible ? garrisonTex : noGarrisonTex);
break;
case CursorState::SUPPLY:
case CursorState::LOAD:
case CursorState::UNLOAD:
tex = (orderPossible ? supplyTex : noSupplyTex);
break;
case CursorState::HACK:
tex = (orderPossible ? hackTex : noHackTex);
break;
}
cursorNode->getMesh(0)->getMaterial()->setTexUniform("diffuseMap", tex, false);
}
void ActiveGameState::update() {
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
guiManager->getText("refineds")->setText(to_wstring(mainPlayer->getResource(ResourceType::REFINEDS)));
guiManager->getText("wealth")->setText(to_wstring(mainPlayer->getResource(ResourceType::WEALTH)));
guiManager->getText("research")->setText(to_wstring(mainPlayer->getResource(ResourceType::RESEARCH)));
updateCursor();
Vector2 cursorPos = getCursorPos();
float eps = .01;
if(!isSelectionBox && selectMouseClicked && (fabs(clickPoint.x - cursorPos.x) > eps || fabs(clickPoint.y - cursorPos.y) > eps) && getTime() - lastSelectMouseClicked > 10)
isSelectionBox = true;
else if (isSelectionBox)
updateDragBox();
dragboxNode->setVisible(isSelectionBox);
updateGameObjHoveredOn();
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
GameObjectFrameController *fc = GameObjectFrameController::getSingleton();
if(!selectingDestOrient && orderMouseClicked && !selectedUnits.empty() && getTime() - lastOrderMouseClicked > 100){
if(targets.empty()) castRayToTerrain();
if(!buildableStructSelected)
for(int i = 0; i < selectedUnits.size(); i++)
fc->addGameObjectFrame(GameObjectFrame(selectedUnits[i]->getId(), GameObject::Type::UNIT, mainPlayer, selectedUnits[i], targets[0].pos));
selectingDestOrient = true;
fc->setRotating(true);
}
else if(selectingDestOrient && !orderMouseClicked){
selectingDestOrient = false;
fc->toggleFrameTransformations(false, false, false);
fc->removeGameObjectFrames();
}
if(!tradingScreen){
guiTexts = guiManager->getTexts();
guiRects = guiManager->getGuiRectangles();
guiButtons = guiManager->getButtons();
}
renderUnits();
vector<Unit*> currSelectedUnits = mainPlayer->getSelectedUnits();
if(prevSelectedUnits != currSelectedUnits){
addUnitGui();
prevSelectedUnits = currSelectedUnits;
}
if(fc->isRotating() || fc->isPlacingOnSurface() || fc->isPlacingVertically())
fc->update();
CameraController *camCtr = CameraController::getSingleton();
if(!camCtr->isLookingAround())
camCtr->updateCameraPosition();
}
void ActiveGameState::updateGameObjHoveredOn(){
vector<GameObject*> gameObjs;
vector<Player*> players = Game::getSingleton()->getPlayers(true);
for(Player *pl : players){
vector<ResourceDeposit*> resDeps = pl->getResourceDeposits();
vector<Unit*> units = pl->getUnits();
for(ResourceDeposit *rd : resDeps)
gameObjs.push_back((GameObject*)rd);
for(Unit *u : units)
gameObjs.push_back((GameObject*)u);
}
for(GameObject *gameObj : gameObjs)
if(isGameObjSelectable(gameObj, false)){
gameObjHoveredOn = gameObj;
return;
}
gameObjHoveredOn = nullptr;
}
void ActiveGameState::deselectUnits(){
mainPlayer->deselectUnits();
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
ufCtr->removeGameObjectFrames();
ufCtr->toggleFrameTransformations(false, false, false);
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
}
bool ActiveGameState::selectedUnitsAmongst(vector<Unit*> units){
vector<Unit*> selUnits = mainPlayer->getSelectedUnits();
for(Unit *unit : units)
if(find(selUnits.begin(), selUnits.end(), unit) != selUnits.end())
return true;
return false;
}
bool ActiveGameState::isGameObjSelectable(GameObject *obj, bool useDragBox){
if(!obj->getModel()->isVisible()) return false;
Node *hitboxNode = obj->getHitbox();
Box *hitbox = (Box*)hitboxNode->getMesh(0);
Vector3 hitboxSize = hitbox->getSize();
float width = hitboxSize.x, height = hitboxSize.y, length = hitboxSize.z;
const int NUM_CORNERS = 8;
Vector3 corners[NUM_CORNERS]{
Vector3(-.5 * width, -.5 * height, -.5 * length),
Vector3(-.5 * width, -.5 * height, .5 * length),
Vector3(.5 * width, -.5 * height, .5 * length),
Vector3(.5 * width, -.5 * height, -.5 * length),
Vector3(-.5 * width, .5 * height, -.5 * length),
Vector3(-.5 * width, .5 * height, .5 * length),
Vector3(.5 * width, .5 * height, .5 * length),
Vector3(.5 * width, .5 * height, -.5 * length),
};
Vector2 cornersOnScreen[NUM_CORNERS];
Vector3 hitboxOffset = hitboxNode->getPosition();
for(int i = 0; i < NUM_CORNERS; i++){
Vector3 cornerInWorld =
obj->getPos() +
obj->getLeftVec() * (corners[i].x + hitboxOffset.x) +
obj->getUpVec() * (corners[i].y + hitboxOffset.y) +
obj->getDirVec() * (corners[i].z + hitboxOffset.z);
Vector3 screenSpace3d = spaceToScreen3d(cornerInWorld);
if(fabs(screenSpace3d.z) > 1) return false;
cornersOnScreen[i] = Vector2(screenSpace3d.x, screenSpace3d.y);
}
vector<Vector2> selectionPoints;
Vector3 dragboxOrigin = Vector3::VEC_ZERO, dragboxSize = Vector3::VEC_ZERO;
if(useDragBox){
dragboxOrigin = dragboxNode->getPosition();
dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize();
Vector2 objScreenPos = spaceToScreen(obj->getPos());
if(
(dragboxOrigin.x < objScreenPos.x && objScreenPos.x < dragboxOrigin.x + dragboxSize.x) &&
(dragboxOrigin.y < objScreenPos.y && objScreenPos.y < dragboxOrigin.y + dragboxSize.y)
)
return true;
selectionPoints = vector<Vector2>{
Vector2(dragboxOrigin.x, dragboxOrigin.y),
Vector2(dragboxOrigin.x + dragboxSize.x, dragboxOrigin.y),
Vector2(dragboxOrigin.x + dragboxSize.x, dragboxOrigin.y + dragboxSize.y),
Vector2(dragboxOrigin.x, dragboxOrigin.y + dragboxSize.y)
};
}
else
selectionPoints = vector<Vector2>{getCursorPos()};
int numAboveEdges = 0, numBelowEdges = 0;
for(int i = 0; i < selectionPoints.size(); i++){
const int NUM_EDGES = 12;
int edges[NUM_EDGES][2]{{0, 1}, {1, 2}, {2, 3}, {3, 0}, {4, 5}, {5, 6}, {6, 7}, {7, 4}, {0, 4}, {1, 5}, {2, 6}, {3, 7}};
for(int j = 0; j < NUM_EDGES && (numAboveEdges == 0 || numBelowEdges == 0); j++){
Vector2 vertA = cornersOnScreen[edges[j][0]], vertB = cornersOnScreen[edges[j][1]];
float edgeHorLen = fabs(vertA.x - vertB.x), edgeVertLen = fabs(vertA.y - vertB.y);
if(fabs(selectionPoints[i].x - vertA.x) < edgeHorLen && fabs(selectionPoints[i].x - vertB.x) < edgeHorLen){
if(vertA.x > selectionPoints[i].x) swap(vertA, vertB);
float horOffset = (selectionPoints[i].x - vertA.x) / edgeHorLen;
float height = vertA.y + (vertA.y < vertB.y ? 1 : -1) * horOffset * edgeVertLen;
(selectionPoints[i].y > height ? numAboveEdges : numBelowEdges)++;
}
}
}
return (numAboveEdges > 0 && numBelowEdges > 0);
}
void ActiveGameState::renderUnits() {
vector<Unit*> friendlyUnits = mainPlayer->getFriendlyUnits();
Game *game = Game::getSingleton();
for (Player *p : game->getPlayers(true)){
vector<Unit*> units = p->getUnits();
for (Unit *u : units) {
if(u->isVehicle() && ((Vehicle*)u)->getGarrisonable()) continue;
bool unitVisible = (game->isDebug() || mainPlayer->isObjectVisible((GameObject*)u, friendlyUnits));
u->getModel()->setVisible(unitVisible);
}
}
}
void ActiveGameState::updateDragBox() {
Vector2 mousePos = getCursorPos(), dragBoxOrigin, dragBoxEnd;
if (mousePos.x >= clickPoint.x && mousePos.y >= clickPoint.y) {
dragBoxOrigin = Vector2(clickPoint.x, clickPoint.y);
dragBoxEnd = Vector2(mousePos.x, mousePos.y);
}
else if (mousePos.x < clickPoint.x && mousePos.y > clickPoint.y) {
dragBoxOrigin = Vector2(mousePos.x, clickPoint.y);
dragBoxEnd = Vector2(clickPoint.x, mousePos.y);
}
else if (mousePos.x >= clickPoint.x && mousePos.y < clickPoint.y) {
dragBoxOrigin = Vector2(clickPoint.x, mousePos.y);
dragBoxEnd = Vector2(mousePos.x, clickPoint.y);
}
else {
dragBoxOrigin = Vector2(mousePos.x, mousePos.y);
dragBoxEnd = Vector2(clickPoint.x, clickPoint.y);
}
Vector3 size = Vector3(dragBoxEnd.x - dragBoxOrigin.x, dragBoxEnd.y - dragBoxOrigin.y, 0);
Quad *dragbox = (Quad*)dragboxNode->getMesh(0);
dragbox->setSize(size);
dragbox->updateVerts(dragbox->getMeshBase());
dragboxNode->setPosition(Vector3(dragBoxOrigin.x, dragBoxOrigin.y, 0));
}
//TODO fix ejectable unit selection with multiple transports selected
//TODO replace shiftPressed with a dedicated buy flag
void ActiveGameState::issueOrder(Order::TYPE type, vector<Order::Target> targets, bool addOrder) {
depth = 1;
Vector3 destDir = Vector3::VEC_ZERO;
if(selectingDestOrient){
GameObjectFrame &objFrame = GameObjectFrameController::getSingleton()->getGameObjectFrame(0);
destDir = objFrame.getDirVec();
targets[0].pos = objFrame.getPos();
}
mainPlayer->issueOrder(type, destDir, targets, addOrder);
this->targets.clear();
if(cursorState != CursorState::ATTACK)
forceCursorState = false;
}
void ActiveGameState::castRayToTerrain() {
Camera *cam = Root::getSingleton()->getCamera();
Vector3 camPos = cam->getPosition();
Vector3 endPos = screenToSpace(getCursorPos());
Vector3 rayDir = (endPos - camPos).norm();
Map *map = Map::getSingleton();
vector<RayCaster::CollisionResult> results = map->raycastTerrain(camPos, rayDir, true);
if(!results.empty())
targets.push_back(Order::Target(nullptr, results[0].pos));
}
void ActiveGameState::enableUnitState(Unit::State state){
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
for(Unit *unit : selectedUnits)
unit->setState(state);
}
void ActiveGameState::addUnitGui(){
vector<Unit*> currSelectedUnits = mainPlayer->getSelectedUnits();
if(currSelectedUnits.empty()) return;
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
sol::state_view SOL_LUA_VIEW = generateView();
SOL_LUA_VIEW.script("_mainUnitId = " + to_string(currSelectedUnits[0]->getId()));
guiManager->readLuaScreenScriptDel("unitGui.lua", unitButtons);
SOL_LUA_VIEW.script("numGui = #gui");
int numButtons = SOL_LUA_VIEW["numGui"];
for(int i = 0; i < numButtons; i++)
unitButtons.push_back(guiManager->getButtons()[guiManager->getButtons().size() - (i + 1)]);
}
void ActiveGameState::onAction(int bind, bool isPressed) {
if(tradingScreen || !ConcreteGuiManager::getSingleton()->findClickedButtons().empty()) return;
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
switch((Bind)bind){
case Bind::DRAG_BOX:
selectMouseClicked = isPressed;
if(isPressed){
clickPoint = getCursorPos();
lastSelectMouseClicked = getTime();
}
else{
if(!shiftPressed) deselectUnits();
if(canSelectHoveredOnGameObj())
mainPlayer->selectUnit((Unit*)gameObjHoveredOn);
selectingDestOrient = false;
if(isSelectionBox){
if(!shiftPressed) deselectUnits();
vector<Unit*> units = mainPlayer->getUnits();
for(Unit *un : units)
if(isGameObjSelectable(un, true))
mainPlayer->selectUnit(un);
}
isSelectionBox = false;
Quad *quad = (Quad*)dragboxNode->getMesh(0);
quad->setSize(Vector3::VEC_ZERO);
quad->updateVerts(quad->getMeshBase());
ufCtr->toggleFrameTransformations(false, false, false);
ufCtr->removeGameObjectFrames();
}
break;
case Bind::ROTATE_OBJ_FRAME:
orderMouseClicked = isPressed;
if(isPressed)
lastOrderMouseClicked = getTime();
else if(!(isPressed || selectedUnits.empty())){
if(selectingPatrolPoints){
castRayToTerrain();
if(!(targets.empty() || selectingPatrolPoints)){
Order::TYPE type = Order::TYPE::MOVE;
if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam()))
type = Order::TYPE::ATTACK;
else if(ufCtr->isPlacingOnSurface() && !selectingDestOrient)
type = Order::TYPE::BUILD;
issueOrder(type, targets, shiftPressed);
}
}
else if(!isSelectionBox){
bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam());
if(cursorState == CursorState::GARRISON){
if(orderPossible) issueOrder(Order::TYPE::GARRISON, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
}
else if(cursorState == CursorState::SUPPLY){
if(orderPossible) issueOrder(Order::TYPE::SUPPLY, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
}
else if(cursorState == CursorState::LOAD){
if(orderPossible) issueOrder(Order::TYPE::LOAD, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
}
else if(cursorState == CursorState::UNLOAD){
if(orderPossible) issueOrder(Order::TYPE::UNLOAD, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
}
else if(cursorState == CursorState::ATTACK){
if(controlPressed && !gameObjHoveredOn){
castRayToTerrain();
issueOrder(Order::TYPE::ATTACK, targets, shiftPressed);
}
else{
if(orderPossible) issueOrder(Order::TYPE::ATTACK, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
}
}
else if(cursorState == CursorState::HACK){
if(orderPossible) issueOrder(Order::TYPE::HACK, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
}
else if(ufCtr->isPlacingOnSurface()){
Order::TYPE type;
switch(selectedUnits[0]->getUnitClass()){
case UnitClass::ROBO_ENGINEER:
case UnitClass::CYBORG_ENGINEER:
case UnitClass::FREEZER:
type = Order::TYPE::BUILD;
break;
default:
return;
}
targets.clear();
for(int i = 0; i < ufCtr->getNumGameObjectFrames(); i++){
GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(i);
if(gmObjFr.status == GameObjectFrame::BLOCKED_BY_DIFF_TERR) continue;
Unit *buildStruct = GameObjectFactory::createUnit(mainPlayer, gmObjFr.getId(), gmObjFr.getPos(), gmObjFr.getRot());
issueOrder(type, vector<Order::Target>{Order::Target(buildStruct, gmObjFr.getPos())}, shiftPressed);
}
buildableStructSelected = false;
}
else{
if(targets.empty()) castRayToTerrain();
issueOrder(Order::TYPE::MOVE, targets, shiftPressed);
}
}
}
break;
case Bind::MOVE_CAMERA:
break;
case Bind::ENABLE_CHASE_STATE:
if(isPressed) enableUnitState(Unit::State::CHASE);
break;
case Bind::ENABLE_STAND_GROUND_STATE:
if(isPressed) enableUnitState(Unit::State::STAND_GROUND);
break;
case Bind::ENABLE_HOLD_FIRE_STATE:
if(isPressed) enableUnitState(Unit::State::HOLD_FIRE);
break;
case Bind::EJECT_GARRISON:
if(isPressed) issueOrder(Order::TYPE::EJECT, vector<Order::Target>{}, shiftPressed);
break;
case Bind::LAUNCH:
if(isPressed){
castRayToTerrain();
issueOrder(Order::TYPE::LAUNCH, targets, shiftPressed);
}
break;
/*
case Bind::HACK:
if(isPressed){
if(gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT && gameObjHoveredOn->getPlayer()->getTeam() != mainPlayer->getTeam())
issueOrder(Order::TYPE::HACK, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
break;
}
*/
case Bind::SHIFT_SUB_DEPTH:
ufCtr->toggleFrameTransformations(false, false, isPressed);
break;
case Bind::ZOOM_IN:
if (zooms > -NUM_MAX_ZOOMS) {
Camera *cam = Root::getSingleton()->getCamera();
cam->setPosition(cam->getPosition() + cam->getDirection().norm() * .5f);
zooms--;
}
break;
case Bind::ZOOM_OUT:
if (zooms < NUM_MAX_ZOOMS) {
Camera *cam = Root::getSingleton()->getCamera();
cam->setPosition(cam->getPosition() - (cam->getDirection().norm() * .5f));
zooms++;
}
break;
case Bind::LOOK_AROUND:
if(!ufCtr->isPlacingOnSurface())
CameraController::getSingleton()->setLookingAround(isPressed);
break;
case Bind::HALT:
if(isPressed) mainPlayer->haltUnits();
break;
//TODO reimplement submarine diving mechanic
case Bind::LEFT_CONTROL:
if(isPressed) cursorState = CursorState::ATTACK;
forceCursorState = isPressed;
controlPressed = isPressed;
orderPossible = isPressed;
break;
case Bind::LEFT_SHIFT:
{
shiftPressed = isPressed;
ufCtr->setPaintSelecting(shiftPressed);
if(isPressed){
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true);
if(!results.empty())
ufCtr->setPaintSelectRowStart(results[0].pos);
}
}
break;
case Bind::SELECT_PATROL_POINTS:
/*
if(isPressed && mainPlayer->getNumSelectedUnits() > 0){
targets.push_back(Order::Target(nullptr, mainPlayer->getSelectedUnit(0)->getPos()));
selectingPatrolPoints = isPressed;
}
*/
break;
case Bind::GROUP_0:
case Bind::GROUP_1:
case Bind::GROUP_2:
case Bind::GROUP_3:
case Bind::GROUP_4:
case Bind::GROUP_5:
case Bind::GROUP_6:
case Bind::GROUP_7:
case Bind::GROUP_8:
case Bind::GROUP_9:
if(isPressed){
int group = bind - Bind::GROUP_0;
if(controlPressed)
unitGroups[group] = mainPlayer->getSelectedUnits();
else{
if(!shiftPressed)
mainPlayer->selectUnits(unitGroups[group]);
else
for(Unit *u : unitGroups[group])
mainPlayer->selectUnit(u);
}
}
break;
case Bind::DESELECT_STRUCTURE:
forceCursorState = false;
buildableStructSelected = false;
ufCtr->toggleFrameTransformations(false, false, false);
ufCtr->removeGameObjectFrames();
break;
}
}
void ActiveGameState::onAnalog(int bind, float strength) {
CameraController *camCtr = CameraController::getSingleton();
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
switch((Bind)bind){
case Bind::LOOK_UP:
case Bind::LOOK_DOWN:
if(camCtr->isLookingAround()) {
Vector3 dirProj = Root::getSingleton()->getCamera()->getDirection();
dirProj = Vector3(dirProj.x, 0, dirProj.z).norm();
CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0).cross(dirProj), strength);
}
else if(ufCtr->isPlacingVertically()){
depth -= .2 * strength;
if(depth < 0) depth = 0;
else if(depth > 1) depth = 1;
}
break;
case Bind::LOOK_LEFT:
case Bind::LOOK_RIGHT:
if(camCtr->isLookingAround())
CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0), strength);
else if(ufCtr->isRotating())
ufCtr->rotateGameObjectFrames(100 * strength);
break;
}
}
void ActiveGameState::onRawMouseWheelScroll(bool up){
CameraController::getSingleton()->zoomCamera(up);
}
}
-112
View File
@@ -1,112 +0,0 @@
#ifndef ACTIVE_GAME_STATE_H
#define ACTIVE_GAME_STATE_H
#include "guiAppState.h"
#include "player.h"
#include "map.h"
#include "unit.h"
#include <util.h>
namespace vb01{
class Node;
class Texture;
}
namespace vb01Gui{
class Button;
}
namespace battleship{
class GameObject;
class Unit;
class UnitButton;
class ActiveGameState : public gameBase::AbstractAppState {
public:
enum CursorState{
NORMAL,
ATTACK,
GARRISON,
SUPPLY,
LOAD,
UNLOAD,
HACK
};
ActiveGameState(GuiAppState*, int);
~ActiveGameState();
void onAttached();
void onDettached();
void update();
void onAction(int, bool);
void onAnalog(int, float);
void onRawMouseWheelScroll(bool);
inline CursorState getCursorState(){return cursorState;}
inline void setCursorState(CursorState cs){this->cursorState = cs;}
inline void addButton(vb01Gui::Button *b){guiButtons.push_back(b);}
inline std::vector<vb01Gui::Button*> getGuiButtons(){return guiButtons;}
inline std::vector<vb01::Node*> getGuiRects(){return guiRects;}
inline std::vector<vb01::Text*> getGuiTexts(){return guiTexts;}
inline Player* getPlayer(){return mainPlayer;}
inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];}
inline void setBuildableStructSelected(bool bss){this->buildableStructSelected = bss;}
inline bool isBuildableStructSelected(){return buildableStructSelected;}
inline float getDepth(){return depth;}
inline void setForceCursorState(bool force){this->forceCursorState = force;}
inline bool isForceCursorState(){return forceCursorState;}
inline void setTradingScreen(bool ts){this->tradingScreen = ts;}
inline bool isTradingScreen(){return tradingScreen;}
inline void setOfferScreen(bool os){this->offerScreen = os;}
inline bool isOfferScreen(){return offerScreen;}
private:
bool selectedUnitsAmongst(std::vector<Unit*>);
void updateGameObjHoveredOn();
void initCursor();
void updateCursor();
void initDragbox();
void removeDragbox();
bool isGameObjSelectable(GameObject*, bool);
void deselectUnits();
void renderUnits();
void updateDragBox();
void updateStructureFrames();
void castRayToTerrain();
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
void enableUnitState(Unit::State);
void addUnitGui();
inline bool canSelectHoveredOnGameObj(){return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer;}
CursorState cursorState = CursorState::NORMAL;
Player *mainPlayer;
GuiAppState *guiState;
GameObject *gameObjHoveredOn = nullptr;
vb01::Vector2 clickPoint;
std::vector<Unit*> unitGroups[9], prevSelectedUnits;
std::vector<Order::Target> targets;
vb01::Node *dragboxNode = nullptr;
std::vector<vb01::Node*> guiRects;
std::vector<vb01::Text*> guiTexts;
std::vector<vb01Gui::Button*> guiButtons, unitButtons;
bool isSelectionBox = false;
bool shiftPressed = false;
bool controlPressed = false;
bool selectMouseClicked = false;
bool orderMouseClicked = false;
bool buildableStructSelected = false;
bool selectingPatrolPoints = false;
bool selectingDestOrient = false;
bool forceCursorState = false;
bool orderPossible = false;
bool tradingScreen = false;
bool offerScreen = false;
int playerId, zooms = 0;
const int NUM_MAX_ZOOMS = 10;
float depth = 1;
vb01::s64 lastSelectMouseClicked = 0, lastOrderMouseClicked = 0;
vb01::Node *cursorNode = nullptr;
vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr, *noGarrisonTex = nullptr, *supplyTex = nullptr, *noSupplyTex = nullptr, *hackTex = nullptr, *noHackTex = nullptr;
};
}
#endif
-21
View File
@@ -1,21 +0,0 @@
#include "activeStateBackButton.h"
#include "activeGameState.h"
#include "gameManager.h"
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
ActiveStateBackButton::ActiveStateBackButton(Vector3 pos, Vector2 size, string name) : BackButton(pos, size, name, "activeGameState.lua"){}
void ActiveStateBackButton::onClick(){
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
activeState->setTradingScreen(false);
BackButton::onClick();
}
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef ACTIVE_STATE_BACK_BUTTON_H
#define ACTIVE_STATE_BACK_BUTTON_H
#include "backButton.h"
namespace battleship{
class ActiveStateBackButton : public BackButton{
public:
ActiveStateBackButton(vb01::Vector3, vb01::Vector2, std::string);
void onClick();
private:
};
}
#endif
-45
View File
@@ -1,45 +0,0 @@
#include "activeStateButton.h"
#include "gameManager.h"
#include "activeGameState.h"
#include "concreteGuiManager.h"
#include <listbox.h>
#include <checkbox.h>
#include <slider.h>
#include <textbox.h>
#include <text.h>
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
ActiveStateButton::ActiveStateButton(Vector3 pos, Vector2 size, string gs, string name, string fontPath, int trigger, string imagePath) :
Button(pos, size, name, fontPath, trigger, true, imagePath), guiScreen(gs){}
void ActiveStateButton::onClick(){
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
vector<Button*> buttons = activeState->getGuiButtons();
buttons.push_back(this);
vector<Node*> rects = activeState->getGuiRects();
vector<Text*> texts = activeState->getGuiTexts();
ConcreteGuiManager::getSingleton()->readLuaScreenScript(
guiScreen,
buttons,
vector<Listbox*>{},
vector<Checkbox*>{},
vector<Slider*>{},
vector<Textbox*>{},
rects,
texts
);
}
}
-18
View File
@@ -1,18 +0,0 @@
#ifndef ACTIVE_STATE_BUTTON_H
#define ACTIVE_STATE_BUTTON_H
#include <button.h>
namespace battleship{
class ActiveStateButton : public vb01Gui::Button{
public:
ActiveStateButton(vb01::Vector3, vb01::Vector2, std::string, std::string, std::string, int = -1, std::string = "");
void onClick();
private:
std::string guiScreen = "";
protected:
std::vector<vb01Gui::Button*> buttons;
};
}
#endif
-30
View File
@@ -1,30 +0,0 @@
#include "addResourceCommand.h"
#include "game.h"
#include "player.h"
#include "trader.h"
namespace battleship{
void AddResourceCommand::validate(){
if(arguments.size() != 3)
return;
playerId = atoi(arguments[0].c_str());
if(playerId != 0 && playerId != 1)
return;
resourceId = atoi(arguments[1].c_str());
if(!(0 <= resourceId && resourceId <= 2))
return;
resourceAmmount = atoi(arguments[2].c_str());
}
void AddResourceCommand::execute(){
AbstractCommand::execute();
Player *player = Game::getSingleton()->getPlayer(playerId);
player->updateResource(ResourceType(resourceId), resourceAmmount, true);
}
}
-18
View File
@@ -1,18 +0,0 @@
#ifndef ADD_RESOURCE_COMMAND_H
#define ADD_RESOURCE_COMMAND_H
#include "abstractCommand.h"
namespace battleship{
class AddResourceCommand : public AbstractCommand{
public:
AddResourceCommand(std::string argsStr) : AbstractCommand(argsStr){}
void execute();
private:
void validate();
int playerId, resourceId, resourceAmmount;
};
}
#endif
-37
View File
@@ -1,37 +0,0 @@
#include "addTechnologyCommand.h"
#include "game.h"
#include "player.h"
#include <solUtil.h>
#include <algorithm>
namespace battleship{
using namespace std;
using namespace gameBase;
void AddTechnologyCommand::validate(){
if(arguments.size() != 2)
return;
playerId = atoi(arguments[0].c_str());
int numPlayers = Game::getSingleton()->getNumPlayers();
if(!(0 <= playerId && playerId < numPlayers))
return;
sol::state_view SOL_LUA_VIEW = generateView();
SOL_LUA_VIEW.script("numTechs = #technologies");
int numTechs = SOL_LUA_VIEW["numTechs"];
techId = atoi(arguments[1].c_str());
if(!(0 <= techId && techId < numTechs))
return;
}
void AddTechnologyCommand::execute(){
AbstractCommand::execute();
Game::getSingleton()->getPlayer(playerId)->addTechnology(techId);
}
}
-18
View File
@@ -1,18 +0,0 @@
#ifndef ADD_TECHNOLOGY_H
#define ADD_TECHNOLOGY_H
#include "abstractCommand.h"
namespace battleship{
class AddTechnologyCommand : public AbstractCommand{
public:
AddTechnologyCommand(std::string argsStr) : AbstractCommand(argsStr){}
void execute();
private:
void validate();
int playerId, techId;
};
}
#endif
-63
View File
@@ -1,63 +0,0 @@
#include <solUtil.h>
#include <stateManager.h>
#include "addUnitCommand.h"
#include "console.h"
#include "addUnitCommand.h"
#include "inGameAppState.h"
#include "game.h"
#include "player.h"
#include "gameObjectFactory.h"
namespace battleship{
using namespace gameBase;
using namespace vb01;
using namespace std;
//TODO implement structure build status argument
void AddUnitCommand::validate(){
if(!(arguments.size() == 2 || arguments.size() == 5 || arguments.size() == 9))
return;
playerId = atoi(arguments[0].c_str());
if(playerId != 0 && playerId != 1)
return;
unitId = atoi(arguments[1].c_str());
sol::state_view SOL_LUA_VIEW = generateView();
string varName = "numUnits";
SOL_LUA_VIEW.script(varName + " = #units");
int numUnits = SOL_LUA_VIEW[varName];
if(!(0 <= unitId && unitId <= numUnits))
return;
if(arguments.size() >= 5){
float x = atoi(arguments[2].c_str());
float y = atoi(arguments[3].c_str());
float z = atoi(arguments[4].c_str());
pos = Vector3(x, y, z);
}
else if(2 < arguments.size() && arguments.size() < 5)
return;
if(arguments.size() == 9){
float w = atoi(arguments[5].c_str());
float x = atoi(arguments[6].c_str());
float y = atoi(arguments[7].c_str());
float z = atoi(arguments[8].c_str());
rot = Quaternion(w, x, y, z);
}
else if(5 < arguments.size() && arguments.size() < 9)
return;
}
void AddUnitCommand::execute(){
AbstractCommand::execute();
Player* player = Game::getSingleton()->getPlayer(playerId);
player->addUnit(GameObjectFactory::createUnit(player, unitId, pos, rot, 100));
}
}
-23
View File
@@ -1,23 +0,0 @@
#ifndef ADD_UNIT_COMMAND_H
#define ADD_UNIT_COMMAND_H
#include "abstractCommand.h"
#include <vector.h>
#include <quaternion.h>
namespace battleship{
class AddUnitCommand : public AbstractCommand{
public:
AddUnitCommand(std::string argsStr) : AbstractCommand(argsStr){}
void validate();
void execute();
private:
int playerId, unitId;
bool posEnabled, rotEnabled;
vb01::Vector3 pos = vb01::Vector3::VEC_ZERO;
vb01::Quaternion rot = vb01::Quaternion::QUAT_W;
};
}
#endif
-17
View File
@@ -1,17 +0,0 @@
#include "backButton.h"
#include "gameManager.h"
#include "concreteGuiManager.h"
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
BackButton::BackButton(Vector3 pos, Vector2 size, string name, string scr) :
Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true),
screen(scr){}
void BackButton::onClick() {
ConcreteGuiManager::getSingleton()->readLuaScreenScript(screen);
}
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef BACK_BUTTON_H
#define BACK_BUTTON_H
#include <button.h>
namespace battleship{
class BackButton : public vb01Gui::Button{
public:
BackButton(vb01::Vector3, vb01::Vector2, std::string, std::string);
void onClick();
private:
std::string screen;
};
}
#endif
-62
View File
@@ -1,62 +0,0 @@
#ifndef BINDS_H
#define BINDS_H
namespace battleship{
enum Bind{
LEFT_CLICK,
SCROLLING_UP,
SCROLLING_DOWN,
LEFT,
RIGHT,
DELETE_CHAR,
TOGGLE_MAIN_MENU,
LOOK_UP,
LOOK_DOWN,
LOOK_LEFT,
LOOK_RIGHT,
LOOK_AROUND,
DRAG_BOX,
ROTATE_OBJ_FRAME,
HALT,
ZOOM_IN,
ZOOM_OUT,
LEFT_CONTROL,
LEFT_SHIFT,
SELECT_PATROL_POINTS,
LAUNCH,
SHIFT_SUB_DEPTH,
GROUP_0,
GROUP_1,
GROUP_2,
GROUP_3,
GROUP_4,
GROUP_5,
GROUP_6,
GROUP_7,
GROUP_8,
GROUP_9,
SELECT_STRUCTURE,
DESELECT_STRUCTURE,
DECREASE_RADIUS,
INCREASE_RADIUS,
PUSH_VERTS_UP,
PUSH_VERTS_DOWN,
MOVE_TERR_OBJ,
SCALE_TERR_OBJ,
STOP_TERR_OBJ,
ENABLE_X_AXIS,
ENABLE_Y_AXIS,
ENABLE_Z_AXIS,
CREATE_WATERBODY,
GENERATE_WEIGHTS,
TOGGLE_CELL_MARKERS,
EJECT_GARRISON,
ENABLE_CHASE_STATE,
ENABLE_STAND_GROUND_STATE,
ENABLE_HOLD_FIRE_STATE,
HACK,
MOVE_CAMERA
};
}
#endif
-25
View File
@@ -1,25 +0,0 @@
basePath=$(pwd)
file="Assets/Scripts/defPaths.lua"
touch $file
echo "PATH = \"$basePath/Assets/\"" > $file
cd external
git submodule update --init --recursive
deps=("gameBase" "vb01" "vb01Gui")
ind=${!deps[@]}
for i in $ind
do
cd ${deps[$i]}
git checkout develop
cd external
git submodule update --init --recursive
cd ../..
done
cd ..
buildDir="build"
cmake -S . -B $buildDir
cd $buildDir
make -j8
-37
View File
@@ -1,37 +0,0 @@
#include "buildButton.h"
#include "gameManager.h"
#include "gameObject.h"
#include "unit.h"
#include "activeGameState.h"
#include "buildableUnit.h"
#include "gameObjectFrameController.h"
#include <stateManager.h>
#include <solUtil.h>
namespace battleship{
using namespace sol;
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
BuildButton::BuildButton(Vector3 pos, Vector2 size, string name, int trigger, string imagePath, int slId) :
UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath), slotId(slId){}
void BuildButton::onClick(){
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
Player *player = activeState->getPlayer();
sol::state_view SOL_LUA_VIEW = generateView();
int unitId = SOL_LUA_VIEW["_mainUnitId"];
Unit* builder = player->getUnitsById(unitId)[0];
if(builder->getBuildableUnit(slotId).buildable){
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
ufCtr->addGameObjectFrame(GameObjectFrame(builder->getBuildableUnit(slotId).id, GameObject::Type::UNIT, player));
ufCtr->setPlacingOnSurface(true);
activeState->setBuildableStructSelected(true);
}
}
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef BUILD_BUTTON_H
#define BUILD_BUTTON_H
#include "unitButton.h"
namespace battleship{
class BuildButton : public UnitButton{
public:
BuildButton(vb01::Vector3, vb01::Vector2, std::string, int, std::string, int);
void onClick();
private:
int slotId;
};
}
#endif
-13
View File
@@ -1,13 +0,0 @@
#ifndef BUILDABLE_UNIT_H
#define BUILDABLE_UNIT_H
namespace battleship{
struct BuildableUnit{
int id;
bool buildable;
BuildableUnit(int i, bool build) : id(i), buildable(build){}
};
}
#endif
-72
View File
@@ -1,72 +0,0 @@
#include "cameraController.h"
#include "defConfigs.h"
#include <quaternion.h>
#include <root.h>
#include <camera.h>
namespace battleship{
using namespace vb01;
using namespace configData;
static CameraController *cameraController = nullptr;
CameraController* CameraController::getSingleton(){
if(!cameraController)
cameraController = new CameraController();
return cameraController;
}
void CameraController::updateCameraPosition() {
GameManager *gm = GameManager::getSingleton();
Vector2 cursorPos = getCursorPos();
Camera *cam = Root::getSingleton()->getCamera();
Vector3 camDir = cam->getDirection();
Vector3 forwVec = Vector3(camDir.x, 0, camDir.z).norm();
Vector3 camLeft = cam->getLeft();
camLeft = Vector3(camLeft.x, 0, camLeft.z).norm();
int width, height;
glfwGetWindowSize(Root::getSingleton()->getWindow(), &width, &height);
if (cursorPos.x <= 0 && 0 < cursorPos.y && cursorPos.y < height)
cam->setPosition(cam->getPosition() - camLeft * camPanSpeed);
if (cursorPos.x >= width && 0 < cursorPos.y && cursorPos.y < height)
cam->setPosition(cam->getPosition() + camLeft * camPanSpeed);
if (cursorPos.y <= 0 && 0 < cursorPos.x && cursorPos.x < width)
cam->setPosition(cam->getPosition() + forwVec * camPanSpeed);
if (cursorPos.y >= height && 0 < cursorPos.x && cursorPos.x < width)
cam->setPosition(cam->getPosition() - forwVec * camPanSpeed);
}
void CameraController::orientCamera(Vector3 rotAxis, double str){
Quaternion rotQuat = Quaternion(.025 * str, rotAxis);
Camera *cam = Root::getSingleton()->getCamera();
Vector3 dir = rotQuat * cam->getDirection(), up = rotQuat * cam->getUp();
cam->lookAt(dir, up);
}
void CameraController::zoomCamera(bool zoomIn){
if((zoomIn && numZooms > configData::NUM_MAX_ZOOMS) || (!zoomIn && numZooms < -configData::NUM_MAX_ZOOMS)) return;
Vector3 newPos;
float offset;
if(zoomIn){
numZooms++;
offset = configData::CAMERA_ZOOM_INCREMENT;
}
else{
numZooms--;
offset = -configData::CAMERA_ZOOM_INCREMENT;
}
Camera *cam = Root::getSingleton()->getCamera();
cam->setPosition(cam->getPosition() + cam->getDirection() * offset);
}
}
-23
View File
@@ -1,23 +0,0 @@
#ifndef CAMERA_CONTROLLER_H
#define CAMERA_CONTROLLER_H
#include <vector.h>
namespace battleship{
class CameraController{
public:
static CameraController* getSingleton();
void updateCameraPosition();
void orientCamera(vb01::Vector3, double);
void zoomCamera(bool);
inline bool isLookingAround(){return lookingAround;}
inline void setLookingAround(bool l){lookingAround = l;}
private:
CameraController(){}
bool lookingAround = false;
int numZooms = 0;
};
}
#endif
-652
View File
@@ -1,652 +0,0 @@
#include <solUtil.h>
#include <soundManager.h>
#include <quad.h>
#include "concreteGuiManager.h"
#include "unit.h"
#include "gameManager.h"
#include "singlePlayerButton.h"
#include "mapEditorButton.h"
#include "optionsButton.h"
#include "exitButton.h"
#include "tabButton.h"
#include "okButton.h"
#include "defaultsButton.h"
#include "backButton.h"
#include "newMapButton.h"
#include "loadMapButton.h"
#include "exportButton.h"
#include "mapListbox.h"
#include "skyboxTextureListbox.h"
#include "landTextureListbox.h"
#include "gameObjectListbox.h"
#include "playButton.h"
#include "inGameAppState.h"
#include "mainMenuButton.h"
#include "buildButton.h"
#include "trainButton.h"
#include "statsButton.h"
#include "researchButton.h"
#include "tradeButton.h"
#include "activeStateButton.h"
#include "playerTradeButton.h"
#include "tradingScreenButton.h"
#include "offerButton.h"
#include "resourceAmmountButton.h"
#include "orderButton.h"
#include "stateToggleButton.h"
#include "minimapButton.h"
#include "activeStateBackButton.h"
namespace battleship{
using namespace std;
using namespace gameBase;
using namespace vb01;
using namespace vb01Gui;
static ConcreteGuiManager *concreteGuiManager = nullptr;
ConcreteGuiManager::ConcreteGuiManager(){
string assetPath = GameManager::getSingleton()->getPath();
texBasePath = assetPath + "Textures/";
fontBasePath = assetPath + "Fonts/";
}
ConcreteGuiManager* ConcreteGuiManager::getSingleton(){
if(!concreteGuiManager)
concreteGuiManager = new ConcreteGuiManager();
return concreteGuiManager;
}
//TODO refactor player difficulty and faction listbox selection
//TODO remove hardcoded font path values
//TODO use configurable map path values
Button* ConcreteGuiManager::parseButton(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
sol::table posTable = guiTable["pos"];
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
sol::table sizeTable = guiTable["size"];
Vector2 size = Vector2(sizeTable["x"], sizeTable["y"]);
//TODO factor out repetetive optional lua key checks
string name = "", nk = "name";
sol::optional<string> nameOpt = guiTable[nk];
if(nameOpt != sol::nullopt) name = guiTable[nk];
ButtonType type = (ButtonType)guiTable["buttonType"];
string imagePath = "", ipk = "imagePath";
sol::optional<string> pathOpt = guiTable[ipk];
bool texturingEnabled = false;
if(pathOpt != sol::nullopt){
imagePath = texBasePath;
imagePath += guiTable[ipk];
bool texturingEnabled = true;
}
Button *button = nullptr;
string guiScreen = "";
switch(type){
case SINGLE_PLAYER:
button = new SinglePlayerButton(pos, size, name);
break;
case EDITOR:
button = new MapEditorButton(pos, size);
break;
case OPTIONS:
button = new OptionsButton(pos, size, name, true);
break;
case EXIT:
button = new ExitButton(pos, size);
break;
case OK:
button = new OkButton(pos, size, name);
break;
case DEFAULTS:
button = new DefaultsButton(pos, size, name);
break;
case BACK: {
string screen = guiTable["screen"];
button = new BackButton(pos, size, name, screen);
break;
}
case CONTROLS_TAB:
case MOUSE_TAB:
case VIDEO_TAB:
case AUDIO_TAB:
case MULTIPLAYER_TAB: {
string screens[]{
"controlsTab.lua",
"mouseTab.lua",
"videoTab.lua",
"audioTab.lua",
"multiplayerTab.lua"
};
int diff = ((int)type - (int)CONTROLS_TAB);
button = new TabButton(pos, size, name, screens[diff]);
break;
}
case NEW_MAP:
button = new NewMapButton(pos, size);
break;
case NEW_MAP_OK:{
int numTextboxes = guiTable["numDependencies"];
vector<Textbox*> t;
for(int i = 0; i < numTextboxes; i++){
int tid = guiTable["dependencies"][i + 1]["id"];
t.push_back((Textbox*)guiElements[tid].second);
}
button = new NewMapButton::OkButton(pos, size, t[0], t[1], t[2]);
break;
}
case LOAD_MAP:
button = new LoadMapButton(pos, size);
break;
case LOAD_MAP_OK:{
int lid = guiTable["dependencies"][1]["id"];
button = new LoadMapButton::OkButton(pos, size, (Listbox*)guiElements[lid].second);
break;
}
case EXPORT:
button = new ExportButton(pos, size);
break;
case PLAY:{
int mid = guiTable["dependencies"][1]["id"];
Listbox *mapListbox = (MapListbox*)guiElements[mid].second;
button = new PlayButton(mapListbox, pos, size, name, true);
break;
}
case RESUME:
button = new InGameAppState::ResumeButton(pos, size);
break;
case CONSOLE_SCREEN:
button = new InGameAppState::ConsoleButton(pos, size);
break;
case MAIN_MENU:
button = new MainMenuButton(pos, size, name);
break;
case CONSOLE_COMMAND_OK:{
int lid = guiTable["dependencies"][1]["id"];
Listbox *listbox = (Listbox*)guiElements[lid].second;
int tid = guiTable["dependencies"][2]["id"];
Textbox *textbox = (Textbox*)guiElements[tid].second;
button = new InGameAppState::ConsoleButton::ConsoleCommandEntryButton(textbox, listbox, pos, size, name);
break;
}
case BUILD:
button = new BuildButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["slotId"]);
break;
case TRAIN:
button = new TrainButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["slotId"]);
break;
case STATISTICS:
button = new StatsButton(pos, size, name, (int)guiTable["trigger"], imagePath);
break;
case RESEARCH:
button = new ResearchButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["techId"]);
break;
case BUY_REFINEDS:
button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::BUY_REFINEDS);
break;
case SELL_REFINEDS:
button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::SELL_REFINEDS);
break;
case BUY_RESEARCH:
button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::BUY_RESEARCH);
break;
case SELL_RESEARCH:
button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, TradeButton::Type::SELL_RESEARCH);
break;
case ACTIVE_STATE_BUTTON:
button = new ActiveStateButton(pos, size, guiTable["guiScreen"], name, fontBasePath + "batang.ttf", (int)guiTable["trigger"], imagePath);
break;
case ACTIVE_STATE_BACK:
button = new ActiveStateBackButton(pos, size, name);
break;
case PLAYER_TRADE:
guiScreen = guiTable["guiScreen"];
button = new PlayerTradeButton(pos, size, guiScreen, name, (int)guiTable["trigger"], imagePath);
break;
case TRADING_SCREEN:{
int lid = guiTable["dependencies"][1]["id"];
Listbox *listbox = (Listbox*)guiElements[lid].second;
guiScreen = guiTable["guiScreen"];
button = new TradingScreenButton(pos, size, listbox, (int)SOL_LUA_STATE["playerId"], guiScreen, name, (int)guiTable["trigger"], imagePath);
break;
}
case TRADE_OFFER:
button = new OfferButton(pos, size, (int)SOL_LUA_STATE["playerId"], name, (int)guiTable["trigger"], imagePath);
break;
case RESOURCE_AMMOUNT:
button = new ResourceAmmountButton(pos, size, name, (int)guiTable["ammount"], (int)guiTable["trigger"], imagePath);
break;
case ORDER:
button = new OrderButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)guiTable["orderType"]);
break;
case UNIT_STATE:
button = new StateToggleButton(pos, size, name, (int)guiTable["trigger"], imagePath);
break;
case MINIMAP:{
string minimapPath = GameManager::getSingleton()->getPath() + "Models/Maps/" + Map::getSingleton()->getMapName() + "/minimap.jpg";
button = new MinimapButton(pos, size, minimapPath);
break;
}
}
int typeArr[2]{(int)GuiElementType::BUTTON, (int)type};
guiElements.push_back(make_pair(typeArr, (void*)button));
return button;
}
Listbox* ConcreteGuiManager::parseGameObjectListbox(){
return nullptr;
}
Listbox* ConcreteGuiManager::parseListbox(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string posTable = "pos";
Vector3 pos = Vector3(guiTable[posTable]["x"], guiTable[posTable]["y"], guiTable[posTable]["z"]);
string sizeTable = "size";
Vector2 size = Vector2(guiTable[sizeTable]["x"], guiTable[sizeTable]["y"]);
int numMaxDisplay = guiTable["numMaxDisplay"];
ListboxType listboxType = (ListboxType)guiTable["listboxType"];
int maxDisplay, numLines;
bool closable;
vector<string> lines;
sol::optional<sol::table> linesOpt = guiTable["lines"];
if(linesOpt != sol::nullopt){
sol::table linesTbl = guiTable["lines"];
for(int i = 0; i < linesTbl.size(); i++)
lines.push_back(guiTable["lines"][i + 1]);
}
Listbox *listbox = nullptr;
string fontPath = fontBasePath + "batang.ttf";
sol::optional<string> nameOpt = guiTable["name"];
string name = "";
if(nameOpt != sol::nullopt) name = guiTable["name"];
switch(listboxType){
case CONTROLS:{
numLines = 6;
closable = false;
for(int i = 0; i < numLines; i++)
lines.push_back(to_string(i));
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
break;
}
case RESOLUTION:{
numLines = guiTable["numLines"];
for(int i = 0; i < numLines; i++)
lines.push_back(guiTable["lines"][i + 1]);
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
break;
}
case MAPS:{
lines = readDir(GameManager::getSingleton()->getPath() + "Models/Maps/", true);
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
bool addPlayers = guiTable["addPlayerGui"];
listbox = new MapListbox(pos, size, lines, maxDisplay, addPlayers, fontPath, closable);
break;
}
case VEHICLES:
case STRUCTURES:
case RESOURCE_DEPOSITS:{
bool resources = (listboxType == RESOURCE_DEPOSITS);
sol::table gameObjTable = SOL_LUA_STATE[resources ? "resources" : "units"];
int numGameObjs = gameObjTable.size();
std::vector<int> gameObjIds;
for(int i = 0; i < numGameObjs; i++){
bool canAdd = true;
if(!resources){
bool vehicles = (listboxType == VEHICLES);
bool v = gameObjTable[i + 1]["isVehicle"];
canAdd = (v == vehicles);
}
if(canAdd){
lines.push_back(gameObjTable[i + 1]["name"]);
gameObjIds.push_back(i);
}
}
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new GameObjectListbox(!resources, pos, size, lines, gameObjIds, maxDisplay, fontPath);
break;
}
case SKYBOX_TEXTURES:
lines = readDir(texBasePath + "Skyboxes", true);
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new SkyboxTextureListbox(pos, size, lines, maxDisplay, fontPath);
break;
case LAND_TEXTURES:
lines = readDir(texBasePath + "Landmass", false);
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new LandTextureListbox(pos, size, lines, maxDisplay, fontPath);
break;
case CPU_DIFFICULTIES:
case FACTIONS:
case COLORS:
case TEAMS:
numLines = lines.size();
closable = true;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath);
break;
case CONSOLE:{
for(int i = 0; i < numMaxDisplay; i++)
lines.push_back("");
closable = false;
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
listbox = new Listbox(pos, size, lines, maxDisplay, fontPath, closable);
}
break;
case TRADE_OFFERS:
closable = true;
listbox = new Listbox(pos, size, lines, numMaxDisplay, fontPath, closable);
break;
}
int typeArr[2]{(int)GuiElementType::LISTBOX, (int)listboxType};
guiElements.push_back(make_pair(typeArr, (void*)listbox));
listbox->setName(name);
return listbox;
}
Checkbox* ConcreteGuiManager::parseCheckbox(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string posTable = "pos";
Vector3 pos = Vector3(guiTable[posTable]["x"], guiTable[posTable]["y"], guiTable[posTable]["z"]);
Checkbox *checkbox = new Checkbox(pos, fontBasePath + "batang.ttf");
int typeArr[2]{(int)GuiElementType::CHECKBOX, -1};
guiElements.push_back(make_pair(typeArr, (void*)checkbox));
return checkbox;
}
Slider* ConcreteGuiManager::parseSlider(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string posTable = "pos", sizeTable = "size";
Vector3 pos = Vector3(guiTable[posTable]["x"], guiTable[posTable]["y"], guiTable[posTable]["z"]);
Vector2 size = Vector2(guiTable[sizeTable]["x"], guiTable[sizeTable]["y"]);
Slider *slider = new Slider(pos, size, guiTable["minValue"], guiTable["maxValue"]);
int typeArr[2]{(int)GuiElementType::SLIDER, -1};
guiElements.push_back(make_pair(typeArr, (void*)slider));
return slider;
}
Textbox* ConcreteGuiManager::parseTextbox(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
string posTable = "pos", sizeTable = "size";
Vector3 pos = Vector3(guiTable[posTable]["x"], guiTable[posTable]["y"], guiTable[posTable]["z"]);
Vector2 size = Vector2(guiTable[sizeTable]["x"], guiTable[sizeTable]["y"]);
Textbox *textbox = new Textbox(pos, size, fontBasePath + "batang.ttf");
int typeArr[2]{(int)GuiElementType::TEXTBOX, -1};
guiElements.push_back(make_pair(typeArr, (void*)textbox));
return textbox;
}
//TODO factor out checking for optional lua values
Node* ConcreteGuiManager::parseGuiRectangle(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "gui");
mat->setTransparent(true);
bool texturingEnabled = false;
string imagePath = "", ipk = "imagePath";
sol::optional<string> pathOpt = guiTable[ipk];
if(pathOpt != sol::nullopt){
imagePath = guiTable[ipk];
texturingEnabled = true;
}
string name = "", nk = "name";
sol::optional<string> nameOpt = guiTable[nk];
if(nameOpt != sol::nullopt) name = guiTable[nk];
mat->addBoolUniform("texturingEnabled", texturingEnabled);
if(texturingEnabled){
string p[]{texBasePath + imagePath};
Texture *tex = new Texture(p, 1, false);
mat->addTexUniform("diffuseMap", tex, false);
}
else{
sol::table colorTable = guiTable["color"];
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["w"]));
}
sol::table sizeTable = guiTable["size"];
Quad *quad = new Quad(Vector3(sizeTable["x"], sizeTable["y"], 1), false);
quad->setMaterial(mat);
sol::table posTable = guiTable["pos"];
Node *guiRectangle = new Node(Vector3(posTable["x"], posTable["y"], posTable["z"]), Quaternion::QUAT_W, Vector3::VEC_IJK, name);
guiRectangle->attachMesh(quad);
root->getGuiNode()->attachChild(guiRectangle);
int typeArr[2]{(int)GuiElementType::GUI_RECTANGLE, -1};
guiElements.push_back(make_pair(typeArr, (void*)guiRectangle));
return guiRectangle;
}
//TODO distinguish between floats and vector-like tables for scale
Text* ConcreteGuiManager::parseText(int guiId){
sol::state_view SOL_LUA_STATE = generateView();
sol::table guiTable = SOL_LUA_STATE["gui"][guiId + 1];
sol::table posTable = guiTable["pos"];
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "text");
mat->addBoolUniform("texturingEnabled", false);
sol::table colorTable = guiTable["color"];
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["w"]));
string font = guiTable["font"];
wstring entry = guiTable["text"];
Text *text = new Text(fontBasePath + font, entry, guiTable["fontFirstChar"], guiTable["fontLastChar"]);
text->setMaterial(mat);
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
SOL_LUA_STATE.script("tp = type(gui[" + to_string(guiId + 1) + "].scale)");
string st = SOL_LUA_STATE["tp"];
Vector3 scale;
if(st == "table"){
sol::table scaleTable = guiTable["scale"];
scale = Vector3(scaleTable["x"], scaleTable["y"], 1);
}
else if(st == "number"){
float sc = guiTable["scale"];
scale = Vector3(sc, sc, 1);
}
Node *node = new Node(pos, Quaternion::QUAT_W, scale, guiTable["name"]);
node->addText(text);
root->getGuiNode()->attachChild(node);
int typeArr[2]{(int)GuiElementType::TEXT, -1};
guiElements.push_back(make_pair(typeArr, (void*)text));
return text;
}
void ConcreteGuiManager::parseMusic(){
sol::state_view SOL_STATE_VIEW = generateView();
sol::optional<sol::table> musicTblOpt = SOL_STATE_VIEW["music"];
if(musicTblOpt == sol::nullopt) return;
sol::table musicTbl = SOL_STATE_VIEW["music"], tracksTbl = musicTbl["tracks"];
SoundManager *sm = SoundManager::getSingleton();
if(tracksTbl.size() == 0){
sm->clearPlaylist();
return;
}
bool loop = musicTbl["loop"], shuffle = musicTbl["shuffle"];
int delay = musicTbl["delay"].get_or(0);
int numTracks = tracksTbl.size();
vector<string> trackPaths;
for(int i = 0; i < numTracks; i++){
string track = tracksTbl[i + 1];
trackPaths.push_back(GameManager::getSingleton()->getPath() + "Sounds/Music/" + track);
}
sm->play(trackPaths, 100, delay, loop, shuffle);
}
void ConcreteGuiManager::readLuaScreenScript(
string script,
vector<Button*> buttonExceptions,
vector<Listbox*> listboxExceptions,
vector<Checkbox*> checkboxExceptions,
vector<Slider*> sliderExceptions,
vector<Textbox*> textboxExceptions,
vector<Node*> guiRectboxExceptions,
vector<Text*> textExceptions,
string luaCode
){
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRectboxExceptions, textExceptions);
parseLuaScript(script, luaCode);
}
void ConcreteGuiManager::readLuaScreenScriptDel(
string script,
vector<Button*> buttons,
vector<Listbox*> listboxs,
vector<Checkbox*> checkboxs,
vector<Slider*> sliders,
vector<Textbox*> textboxs,
vector<Node*> guiRectboxs,
vector<Text*> texts
){
for(Button *b : buttons) removeButton(b);
for(Listbox *l : listboxs) removeListbox(l);
for(Checkbox *c : checkboxs) removeCheckbox(c);
for(Slider *s : sliders) removeSlider(s);
for(Textbox *t : textboxs) removeTextbox(t);
for(Node *r : guiRectboxs) removeGuiRectangle(r);
for(Text *t : texts) removeText(t);
parseLuaScript(script);
}
void ConcreteGuiManager::parseLuaScript(string script, string luaCode){
guiElements.clear();
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
sol::state_view SOL_LUA_VIEW = generateView();
SOL_LUA_VIEW.script("music = nil");
SOL_LUA_VIEW.script_file(basePath + script);
if(luaCode != "") SOL_LUA_VIEW.script(luaCode);
SOL_LUA_VIEW.script("numGui = #gui");
int numGuiElements = SOL_LUA_VIEW["numGui"];
for(int i = 0; i < numGuiElements; i++){
int guiTypeId = SOL_LUA_VIEW["gui"][i + 1]["guiType"];
switch((GuiElementType)guiTypeId){
case BUTTON:
addButton(parseButton(i));
break;
case LISTBOX:
addListbox(parseListbox(i));
break;
case CHECKBOX:
addCheckbox(parseCheckbox(i));
break;
case SLIDER:
addSlider(parseSlider(i));
break;
case TEXTBOX:
addTextbox(parseTextbox(i));
break;
case GUI_RECTANGLE:
addGuiRectangle(parseGuiRectangle(i));
break;
case TEXT:
addText(parseText(i));
break;
}
}
parseMusic();
}
}
-117
View File
@@ -1,117 +0,0 @@
#ifndef CONCRETE_GUI_MANAGER_H
#define CONCRETE_GUI_MANAGER_H
#include <abstractGuiManager.h>
#include <string>
#include <utility>
#include <vector>
namespace vb01{
class Node;
class Text;
}
namespace battleship{
enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX, GUI_RECTANGLE, TEXT, MUSIC};
enum ButtonType {
SINGLE_PLAYER,
EDITOR,
OPTIONS,
EXIT,
OK,
DEFAULTS,
BACK,
CONTROLS_TAB,
MOUSE_TAB,
VIDEO_TAB,
AUDIO_TAB,
MULTIPLAYER_TAB,
NEW_MAP,
NEW_MAP_OK,
LOAD_MAP,
LOAD_MAP_OK,
EXPORT,
PLAY,
RESUME,
CONSOLE_SCREEN,
MAIN_MENU,
CONSOLE_COMMAND_OK,
BUILD,
TRAIN,
STATISTICS,
RESEARCH,
BUY_REFINEDS,
SELL_REFINEDS,
BUY_RESEARCH,
SELL_RESEARCH,
ACTIVE_STATE_BUTTON,
ACTIVE_STATE_BACK,
PLAYER_TRADE,
TRADING_SCREEN,
TRADE_OFFER,
RESOURCE_AMMOUNT,
UNIT_STATE,
ORDER,
MINIMAP,
};
enum ListboxType {
CONTROLS,
RESOLUTION,
MAPS,
VEHICLES,
STRUCTURES,
RESOURCE_DEPOSITS,
SKYBOX_TEXTURES,
LAND_TEXTURES,
CPU_DIFFICULTIES,
FACTIONS,
COLORS,
TEAMS,
CONSOLE,
TRADE_OFFERS
};
class ConcreteGuiManager : public vb01Gui::AbstractGuiManager{
public:
static ConcreteGuiManager* getSingleton();
void readLuaScreenScript(
std::string,
std::vector<vb01Gui::Button*> = std::vector<vb01Gui::Button*>{},
std::vector<vb01Gui::Listbox*> = std::vector<vb01Gui::Listbox*>{},
std::vector<vb01Gui::Checkbox*> = std::vector<vb01Gui::Checkbox*>{},
std::vector<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{},
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{},
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
std::vector<vb01::Text*> = std::vector<vb01::Text*>{},
std::string = ""
);
void readLuaScreenScriptDel(
std::string,
std::vector<vb01Gui::Button*> = std::vector<vb01Gui::Button*>{},
std::vector<vb01Gui::Listbox*> = std::vector<vb01Gui::Listbox*>{},
std::vector<vb01Gui::Checkbox*> = std::vector<vb01Gui::Checkbox*>{},
std::vector<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{},
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{},
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
);
void parseLuaScript(std::string, std::string = "");
private:
ConcreteGuiManager();
vb01Gui::Button* parseButton(int);
vb01Gui::Listbox* parseGameObjectListbox();
vb01Gui::Listbox* parseListbox(int);
vb01Gui::Checkbox* parseCheckbox(int);
vb01Gui::Slider* parseSlider(int);
vb01Gui::Textbox* parseTextbox(int);
vb01::Node* parseGuiRectangle(int);
vb01::Text* parseText(int);
void parseMusic();
std::vector<std::pair<int*, void*>> guiElements;
std::string texBasePath, fontBasePath;
};
}
#endif
-28
View File
@@ -1,28 +0,0 @@
#include "console.h"
#include "addUnitCommand.h"
#include "addResourceCommand.h"
#include "addTechnologyCommand.h"
#include "toggleDebugCommand.h"
using namespace std;
namespace battleship{
void Console::execute(string cmdStr) {
int space = cmdStr.find(" ");
string cmdName = cmdStr, argsStr = "";
if(space != -1){
cmdName = cmdStr.substr(0, space);
argsStr = cmdStr.substr(space + 1, string::npos);
}
if(cmdName == "add-unit")
AddUnitCommand(argsStr).execute();
else if(cmdName == "add-resource")
AddResourceCommand(argsStr).execute();
else if(cmdName == "add-technology")
AddTechnologyCommand(argsStr).execute();
else if(cmdName == "toggle-debug")
ToggleDebugCommand(argsStr).execute();
}
}
-13
View File
@@ -1,13 +0,0 @@
#ifndef CONSOLE_COMMAND_H
#define CONSOLE_COMMAND_H
#include <string>
namespace battleship{
class Console{
public:
static void execute(std::string);
};
}
#endif
-81
View File
@@ -1,81 +0,0 @@
#include "cruiseMissile.h"
#include "destructable.h"
#include "player.h"
#include "unit.h"
#include "map.h"
#include "game.h"
#include <util.h>
#include <cmath>
namespace battleship{
using namespace std;
using namespace vb01;
CruiseMissile::CruiseMissile(Unit *unit, int id, Vector3 tp, Vector3 pos, Quaternion rot) :
Projectile(unit, id, pos, rot),
targetPoint(tp),
flightStage(FlightStage::ASCENT)
{
destructable = new Destructable(this);
Vector3 unitDir = unit->getDirVec();
Vector3 leftDir = unit->getLeftVec();
Vector3 targDir = (Vector3(targetPoint.x, pos.y, targetPoint.z) - pos).norm();
bool left = (leftDir.getAngleBetween(targDir) < PI / 2);
float angle = unitDir.getAngleBetween(targDir) * (left ? 1 : -1);
orientAt(Quaternion(angle, Vector3::VEC_J) * rot);
}
CruiseMissile::~CruiseMissile(){delete destructable;}
void CruiseMissile::pitch(float rotAngle, Vector3 compVec){
float minHeight = 20;
float angleToCompVec = Projectile::dirVec.getAngleBetween(compVec);
float angle = (angleToCompVec > rotAngle ? rotAngle : angleToCompVec);
if(flightStage == FlightStage::ASCENT && Projectile::pos.y - initPos.y > minHeight){
Projectile::orientAt(Quaternion(angle, Projectile::leftVec) * Projectile::rot);
if(Projectile::dirVec.y <= .001) flightStage = FlightStage::CRUISE;
}
else if(flightStage == FlightStage::DESCENT){
Vector3 targDir = (Vector3(targetPoint.x, initPos.y, targetPoint.z) - initPos).norm();
if(Projectile::dirVec.getAngleBetween(targDir) < PI / 2)
Projectile::orientAt(Quaternion(angle, Projectile::leftVec) * Projectile::rot);
}
}
void CruiseMissile::cruise(){
float minDist = 6;
float initDist = Vector3(targetPoint.x, initPos.y, targetPoint.z).getDistanceFrom(initPos);
if(Projectile::pos.getDistanceFrom(Vector3(targetPoint.x, Projectile::pos.y, targetPoint.z)) < minDist)
flightStage = FlightStage::DESCENT;
}
void CruiseMissile::update(){
Projectile::update();
destructable->update();
switch(flightStage){
case FlightStage::ASCENT:
pitch(rotAngle, Vector3(Projectile::dirVec.x, 0, Projectile::dirVec.z).norm());
break;
case FlightStage::DESCENT:
pitch(rotAngle, -Vector3::VEC_J);
break;
case FlightStage::CRUISE:
cruise();
break;
}
if(flightStage == FlightStage::DESCENT && !remove){
checkSurfaceCollision(false);
if(remove) return;
checkUnitCollision();
}
}
}
-22
View File
@@ -1,22 +0,0 @@
#ifndef CRUISE_MISSILE_H
#define CRUISE_MISSILE_H
#include "projectile.h"
namespace battleship{
class CruiseMissile : public Projectile{
public:
CruiseMissile(Unit*, int, vb01::Vector3, vb01::Vector3, vb01::Quaternion);
~CruiseMissile();
void update();
private:
enum class FlightStage{ASCENT, CRUISE, DESCENT};
FlightStage flightStage;
vb01::Vector3 targetPoint;
void pitch(float, vb01::Vector3);
void cruise();
};
}
#endif
-33
View File
@@ -1,33 +0,0 @@
#include "defConfigs.h"
namespace battleship{
namespace configData{
int calcSumStaticBinds(int id, bool calcPrev){
int numBinds = 0;
if(calcPrev)
for(int i = 0; i < id; i++)
numBinds += numStaticBinds[i];
else
numBinds = numStaticBinds[id];
return numBinds;
}
int calcSumConfBinds(int id, bool calcPrev){
int numBinds = 0;
if(calcPrev)
for(int i = 0; i < id; i++)
numBinds += numConfBinds[i];
else
numBinds = numConfBinds[id];
return numBinds;
}
int calcSumBinds(int id, bool calcPrev){
return calcSumStaticBinds(id, calcPrev) + calcSumConfBinds(id, calcPrev);
}
}
}
-214
View File
@@ -1,214 +0,0 @@
#ifndef DEF_CONFIGS_H
#define DEF_CONFIGS_H
#define SOL_ALL_SAFETIES_ON 1
#include <string>
#include <vector>
#include <util.h>
#include <glfw3.h>
#include <mapping.h>
#include <sol/sol.hpp>
#include "binds.h"
#include "gameManager.h"
namespace battleship{
namespace configData{
using namespace gameBase;
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg";
const double camPanSpeed = .5, CAMERA_DISTANCE = 100, CAMERA_ZOOM_INCREMENT = 1, cellLength = 7, cellWidth = 7, cellDepth = 7, DIST_FROM_RAY = 15;
const int maxNumGroups = 10, NUM_MAX_ZOOMS = 300, NUM_SUBDIVS = 100;
const vb01::u32 IMPASS_NODE_VAL = 65535;
const static int numAppStates = 5;
const static int numStaticBinds[numAppStates]{6, 0, 5, 19, 0};
const static int numConfBinds[numAppStates]{0, 1, 27, 0, 0};
const static int maxStaticBinds = 19;
const static int maxConfBinds = 23;
const static int numScripts = 5;
const static std::string scriptPathBase = "Scripts/";
enum ScriptFiles{
CORE_MAIN,
GUI_MAIN,
OPTIONS,
RESOURCE_DATA,
PROJECTILE_DATA,
UNIT_DATA,
AI_AGENT,
PLAYER
};
const static std::vector<std::string> scripts = std::vector<std::string>{
"Scripts/Core/main.lua",
"Scripts/Gui/main.lua",
"Scripts/Core/options.lua",
"Scripts/GameObjects/resourceData.lua",
"Scripts/GameObjects/Projectiles/projectileData.lua",
"Scripts/GameObjects/Units/unitData.lua",
"Scripts/aiAgent.lua",
"Scripts/Core/player.lua",
"Scripts/Technologies/technologyData.lua",
"Scripts/Abilities/abilityData.lua",
"Scripts/Trading/traderData.lua"
};
const static Bind staticBinds[numAppStates][maxStaticBinds]{
{
Bind::LEFT_CLICK,
Bind::SCROLLING_UP,
Bind::SCROLLING_DOWN,
Bind::LEFT,
Bind::RIGHT,
Bind::DELETE_CHAR,
},
{},
{
Bind::LOOK_UP,
Bind::LOOK_DOWN,
Bind::LOOK_LEFT,
Bind::LOOK_RIGHT,
Bind::LOOK_AROUND,
},
{
Bind::LOOK_UP,
Bind::LOOK_DOWN,
Bind::LOOK_LEFT,
Bind::LOOK_RIGHT,
Bind::LOOK_AROUND,
},
{}
};
const static Bind confBinds[numAppStates][maxConfBinds]{
{},
{
Bind::TOGGLE_MAIN_MENU
},
{
Bind::DRAG_BOX,
Bind::MOVE_CAMERA,
Bind::ROTATE_OBJ_FRAME,
Bind::HALT,
Bind::ZOOM_IN,
Bind::ZOOM_OUT,
Bind::LEFT_CONTROL,
Bind::LEFT_SHIFT,
Bind::SELECT_PATROL_POINTS,
Bind::LAUNCH,
Bind::SHIFT_SUB_DEPTH,
Bind::GROUP_0,
Bind::GROUP_1,
Bind::GROUP_2,
Bind::GROUP_3,
Bind::GROUP_4,
Bind::GROUP_5,
Bind::GROUP_6,
Bind::GROUP_7,
Bind::GROUP_8,
Bind::GROUP_9,
Bind::SELECT_STRUCTURE,
Bind::DESELECT_STRUCTURE
},
{},
{}
};
const static int staticTriggers[numAppStates][maxStaticBinds]{
{
0,
GLFW_KEY_W,
GLFW_KEY_S,
GLFW_KEY_LEFT,
GLFW_KEY_RIGHT,
GLFW_KEY_BACKSPACE
},
{},
{
Mapping::MOUSE_AXIS_UP,
Mapping::MOUSE_AXIS_DOWN,
Mapping::MOUSE_AXIS_LEFT,
Mapping::MOUSE_AXIS_RIGHT,
0
},
{
Mapping::MOUSE_AXIS_UP,
Mapping::MOUSE_AXIS_DOWN,
Mapping::MOUSE_AXIS_LEFT,
Mapping::MOUSE_AXIS_RIGHT,
0
},
{}
};
const static int confTriggers[numAppStates][maxConfBinds]{
{},
{
GLFW_KEY_ESCAPE
},
{
GLFW_KEY_LEFT,
GLFW_KEY_RIGHT,
GLFW_KEY_H,
3,
4,
GLFW_KEY_LEFT_CONTROL,
GLFW_KEY_LEFT_SHIFT,
GLFW_KEY_P,
GLFW_KEY_C,
GLFW_KEY_S,
GLFW_KEY_0,
GLFW_KEY_1,
GLFW_KEY_2,
GLFW_KEY_3,
GLFW_KEY_4,
GLFW_KEY_5,
GLFW_KEY_6,
GLFW_KEY_7,
GLFW_KEY_8,
GLFW_KEY_9,
GLFW_KEY_B,
GLFW_KEY_ESCAPE
},
{},
{}
};
const static bool isStaticKey[numAppStates][maxStaticBinds]{
{0, 1, 1, 1, 1, 1},
{},
{0, 0, 0, 0, 1},
{0, 0, 0, 0, 1},
{}
};
const static bool isConfKey[numAppStates][maxConfBinds]{
{},
{1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{},
{}
};
const static bool isStaticAction[numAppStates][maxStaticBinds]{
{1, 1, 1, 1, 1, 1},
{},
{0, 0, 0, 0, 1},
{0, 0, 0, 0, 1},
{}
};
const static bool isConfAction[numAppStates][maxConfBinds]{
{},
{1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{},
{}
};
int calcSumStaticBinds(int, bool);
int calcSumConfBinds(int, bool);
int calcSumBinds(int, bool);
}
}
#endif
-12
View File
@@ -1,12 +0,0 @@
#include "defaultsButton.h"
#include "gameManager.h"
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
DefaultsButton::DefaultsButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
void DefaultsButton::onClick() {}
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef DEFAULTS_BUTTON_H
#define DEFAULTS_BUTTON_H
#include <button.h>
namespace battleship{
class DefaultsButton : public vb01Gui::Button{
public:
DefaultsButton(vb01::Vector3, vb01::Vector2, std::string);
void onClick();
private:
};
}
#endif
-17
View File
@@ -1,17 +0,0 @@
#include "depthCharge.h"
namespace battleship{
using namespace vb01;
DepthCharge::DepthCharge(Unit *un, int id, Vector3 pos, Quaternion rot) : Projectile(un, id, pos, rot){}
void DepthCharge::update(){
Projectile::update();
if(!remove){
checkSurfaceCollision(true);
if(remove) return;
checkUnitCollision();
}
}
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef DEPTH_CHARGE_H
#define DEPTH_CHARGE_H
#include "projectile.h"
namespace battleship{
class DepthCharge : public Projectile{
public:
DepthCharge(Unit*, int, vb01::Vector3, vb01::Quaternion);
void update();
private:
};
}
#endif
-107
View File
@@ -1,107 +0,0 @@
#include "destructable.h"
#include "environment.h"
#include "player.h"
#include "game.h"
#include <root.h>
#include <node.h>
#include <quad.h>
#include <material.h>
#include <solUtil.h>
#include <vector>
using namespace std;
using namespace vb01;
using namespace gameBase;
namespace battleship{
Destructable::Destructable(GameObject *obj) : gameObject(obj){
initProperties();
}
void Destructable::initProperties(){
int id = gameObject->getId();
sol::state_view SOL_LUA_VIEW = generateView();
string objType = gameObject->getGameObjTableName();
sol::table objTable = SOL_LUA_VIEW[objType][gameObject->getId() + 1];
vector<int> currTechs = gameObject->getPlayer()->getTechnologies();
health += Game::getSingleton()->calcAbilFromTech(Ability::Type::HEALTH, currTechs, (int)gameObject->getType(), id);
maxHealth = objTable["health"];
if(health == 0) health = maxHealth;
string tblName = "armor";
sol::optional<sol::table> at = objTable[tblName];
if(at != sol::nullopt){
string varName = "numArmorTypes";
SOL_LUA_VIEW.script(varName + " = #" + objType + "[" + to_string(id + 1) + "]." + tblName);
int numArmorTypes = SOL_LUA_VIEW[varName];
for(int i = 0; i < numArmorTypes; i++){
Armor arm = (Armor)objTable[tblName][i + 1];
armorTypes.push_back(arm);
}
}
}
void Destructable::update(){
if (health <= DEATH_HP){
gameObject->setRemove(true);
sol::optional<sol::table> tblOpt = generateView()[gameObject->getGameObjTableName()][gameObject->getId() + 1]["deathFx"];
if(tblOpt == sol::nullopt) return;
Vector3 pos = gameObject->getPos();
sol::table tbl = generateView()[gameObject->getGameObjTableName()][gameObject->getId() + 1]["deathFx"];
FxManager::Fx *fx = FxManager::getSingleton()->initFx(tbl, gameObject->getModel(), false, pos);
Environment::explode(fx, Environment::Detonation::EXPLOSION, pos);
}
}
Node* Destructable::createBar(Vector2 pos, Vector2 size, Vector4 color){
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "gui");
mat->addBoolUniform("texturingEnabled", false);
mat->addVec4Uniform("diffuseColor", color);
Quad *quad = new Quad(Vector3(size.x, size.y, 0), false);
quad->setMaterial(mat);
Node *node = new Node(Vector3(pos.x, pos.y, 0));
node->attachMesh(quad);
node->setVisible(false);
root->getGuiNode()->attachChild(node);
return node;
}
void Destructable::displayStats(Node *foreground, Node *background, int currVal, int maxVal, bool render, Vector2 offset) {
foreground->setVisible(render);
background->setVisible(render);
if(render){
Vector3 offset3d = Vector3(offset.x, offset.y, 0);
Vector2 screenPos = gameObject->getScreenPos();
Quad *bgQuad = (Quad*)background->getMesh(0);
Vector3 size = bgQuad->getSize();
float shiftedX = screenPos.x - 0.5 * size.x;
background->setPosition(Vector3(shiftedX, screenPos.y, 0) + offset3d);
Quad *fgQuad = (Quad*)foreground->getMesh(0);
fgQuad->setSize(Vector3((float)currVal / maxVal * size.x, size.y, 0));
fgQuad->updateVerts(fgQuad->getMeshBase());
foreground->setPosition(Vector3(shiftedX, screenPos.y, .01) + offset3d);
}
}
void Destructable::removeBar(Node *node){
Root::getSingleton()->getGuiNode()->dettachChild(node);
delete node;
}
}
-43
View File
@@ -1,43 +0,0 @@
#ifndef DESTRUCTABLE_H
#define DESTRUCTABLE_H
#include <vector.h>
#include <vector>
#include <algorithm>
namespace vb01{
class Node;
}
namespace battleship{
enum class Armor {CAST, COMBINED, MECHANIC, SHELL, STEEL};
class GameObject;
class Destructable{
public:
Destructable(GameObject*);
void update();
void removeBar(vb01::Node*);
vb01::Node* createBar(vb01::Vector2, vb01::Vector2, vb01::Vector4);
void displayStats(vb01::Node*, vb01::Node*, int, int, bool, vb01::Vector2 offset = vb01::Vector2::VEC_ZERO);
inline int getHealth(){return health;}
inline int getMaxHealth(){return maxHealth;}
inline int getDeathHp(){return DEATH_HP;}
inline void takeDamage(int damage) {health -= damage * (1 + (freezeDmgFactor - 1) * freezeStatus * .01f);}
inline GameObject* getGameObject(){return gameObject;}
inline std::vector<Armor> getArmorTypes(){return armorTypes;}
inline void setFreezeStatus(int fs){this->freezeStatus = std::clamp(fs, 0, 100);}
inline int getFreezeStatus(){return freezeStatus;}
private:
std::vector<Armor> armorTypes;
const int DEATH_HP = 0;
int health = 0, maxHealth, freezeStatus = 0, freezeDmgFactor = 10;
GameObject *gameObject = nullptr;
void initProperties();
};
}
#endif
-81
View File
@@ -1,81 +0,0 @@
#include "engineer.h"
#include "activeGameState.h"
#include "destructable.h"
#include "structure.h"
#include "player.h"
#include "game.h"
#include "map.h"
#include <solUtil.h>
#include <stateManager.h>
#include <vector>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
Engineer::Engineer(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state){
Game *game = Game::getSingleton();
vector<int> currTechs = player->getTechnologies();
hackRange = generateView()["units"][id + 1]["hackRange"]; hackRange += game->calcAbilFromTech(Ability::Type::HACK_RANGE, currTechs, (int)GameObject::type, id);
Vector2 size = Vector2(lenHpBar, 10);
hackStatusBackground = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
hackStatusForeground = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(1, 0, 1, 1));
}
Engineer::~Engineer(){
destructable->removeBar(hackStatusBackground);
destructable->removeBar(hackStatusForeground);
}
void Engineer::update(){
Vehicle::update();
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
vector<Player*> selectingPlayers = Unit::getSelectingPlayers();
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
if(hackStatus < 100)
destructable->displayStats(hackStatusForeground, hackStatusBackground, hackStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
else{
hackStatusBackground->setVisible(false);
hackStatusForeground->setVisible(false);
}
if(orders.empty() || orders[0].type != Order::TYPE::HACK)
hackStatus = 0;
}
//TODO change unit colors after faction change
void Engineer::hack(Order order){
Unit *targUnit = (Unit*)order.targets[0].unit;
bool withinRange = (targUnit->getPos().getDistanceFrom(pos) < hackRange);
int hackRate = int(generateView()["units"][id + 1]["hackTime"]) / 100;
bool canHack = (getTime() - lastHackTime > hackRate);
if(withinRange && canHack){
hackStatus++;
pursuingTarget = false;
}
else if(!withinRange){
hackStatus = 0;
if(!pursuingTarget){
preparePathpoints(order, targUnit->getPos());
pursuingTarget = true;
}
else
navigateToTarget(.9 * hackRange);
}
if(hackStatus >= 100){
order.targets[0].unit->changePlayer(player);
removeOrder(0);
}
}
}
-30
View File
@@ -1,30 +0,0 @@
#ifndef ENGINEER_H
#define ENGINEER_H
#include <util.h>
#include "vehicle.h"
namespace vb01{
class Node;
}
namespace battleship{
class Structure;
class Engineer : public Vehicle{
public:
Engineer(Player*, int, vb01::Vector3, vb01::Quaternion, Unit::State);
~Engineer();
void update();
private:
int hackStatus = 0;
float hackRange;
vb01::s64 lastHackTime = 0;
vb01::Node *hackStatusBackground = nullptr, *hackStatusForeground = nullptr;
void hack(Order);
};
}
#endif
-50
View File
@@ -1,50 +0,0 @@
#include "environment.h"
#include "fxManager.h"
#include "player.h"
#include "unit.h"
#include "game.h"
#include "destructable.h"
#include <root.h>
#include <node.h>
#include <material.h>
#include <texture.h>
#include <particleEmitter.h>
namespace battleship{
using namespace std;
using namespace vb01;
static Environment *environment = nullptr;
Environment* Environment::getSingleton(){
if(!environment)
environment = new Environment();
return environment;
}
//TODO use the pos argument from the fx
void Environment::explode(FxManager::Fx *fx, Detonation det, Vector3 pos, int damage, float radius){
FxManager::getSingleton()->addFx(fx);
if(radius == 0) return;
for(Player *pl : Game::getSingleton()->getPlayers()){
for(Unit *un : pl->getUnits()){
float distance = un->getPos().getDistanceFrom(pos);
if(distance < radius){
switch(det){
case Detonation::EXPLOSION:
un->getDestructable()->takeDamage(int(damage * (1.f - distance / radius)));
break;
case Detonation::EMP:
un->setCondition(Unit::Condition::EM_JAMMED);
break;
}
}
}
}
}
}
-20
View File
@@ -1,20 +0,0 @@
#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H
#include <vector.h>
#include "fxManager.h"
namespace battleship{
class Environment{
public:
enum class Detonation{EXPLOSION, EMP, CRYO};
static Environment* getSingleton();
static void explode(FxManager::Fx*, Detonation, vb01::Vector3, int = 0, float = 0);
private:
Environment(){}
};
}
#endif
-13
View File
@@ -1,13 +0,0 @@
#include "exitButton.h"
#include "gameManager.h"
using namespace std;
using namespace vb01;
namespace battleship{
ExitButton::ExitButton(Vector3 pos, Vector2 size) : Button(pos, size, "Exit", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
void ExitButton::onClick() {
GameManager::getSingleton()->setRunning(false);
}
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef EXIT_BUTTON_H
#define EXIT_BUTTON_H
#include <button.h>
#include <vector.h>
namespace battleship {
class ExitButton : public vb01Gui::Button {
public:
ExitButton(vb01::Vector3, vb01::Vector2);
void onClick();
};
}
#endif
-50
View File
@@ -1,50 +0,0 @@
#include <SFML/Audio.hpp>
#include "explosion.h"
#include "util.h"
#include "inGameAppState.h"
#include "game.h"
using namespace std;
using namespace vb01;
namespace battleship{
void detonate(string p){
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
sf::Sound *sfx = nullptr;
string p = GameManager::getSingleton()->getPath() + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg";
if(sfxBuffer->loadFromFile(p.c_str())){
sfx = new sf::Sound(*sfxBuffer);
sfx->play();
}
Game::getSingleton()->addFx(Fx(sfx, 2500));
}
void detonateDepthCharge(){
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
sf::Sound *sfx = nullptr;
string p = GameManager::getSingleton()->getPath() + "Sounds/Destroyers/depthCharge.ogg";
if(sfxBuffer->loadFromFile(p.c_str())){
sfx = new sf::Sound(*sfxBuffer);
sfx->play();
}
Game::getSingleton()->addFx(Fx(sfx, 2000));
}
void detonateTorpedo(){
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
sf::Sound *sfx = nullptr;
string p = GameManager::getSingleton()->getPath() + "Sounds/Submarines/torpedo.ogg";
if(sfxBuffer->loadFromFile(p.c_str())){
sfx = new sf::Sound(*sfxBuffer);
sfx->play();
}
Game::getSingleton()->addFx(Fx(sfx, 250));
}
}
-10
View File
@@ -1,10 +0,0 @@
#ifndef EXPLOSION_H
#define EXPLOSION_H
#include <string>
namespace battleship{
void detonate(std::string);
}
#endif
-20
View File
@@ -1,20 +0,0 @@
#include "exportButton.h"
#include "gameManager.h"
#include "mapEditorAppState.h"
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
ExportButton::ExportButton(Vector3 pos, Vector2 size) : Button(pos, size, "Export", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){}
void ExportButton::onClick(){
StateManager *sm = GameManager::getSingleton()->getStateManager();
MapEditorAppState::MapEditor *mapEditor = ((MapEditorAppState*)sm->getAppStateByType((int)AppStateType::MAP_EDITOR))->getMapEditor();
mapEditor->exportMap();
}
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef EXPORT_BUTTON_H
#define EXPORT_BUTTON_H
#include <button.h>
namespace battleship{
class ExportButton : public vb01Gui::Button{
public:
ExportButton(vb01::Vector3 pos, vb01::Vector2 size);
void onClick();
};
}
#endif
Submodule external/gameBase deleted from 0002879d41
-1
Submodule external/tinydir deleted from 9f866c1ec0
-1
Submodule external/vb01 deleted from 7f8b6fe03a
-70
View File
@@ -1,70 +0,0 @@
#include "extractor.h"
#include "player.h"
#include "game.h"
#include "destructable.h"
#include "activeGameState.h"
#include "resourceDeposit.h"
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state){
Vector2 size = Vector2(lenHpBar, 10);
ammountBackground = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
ammountForeground = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1));
if(rd) return;
initProperties();
for(ResourceDeposit *dep : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits())
if(dep->getPos().getDistanceFrom(pos) < .001){
deposit = dep;
deposit->setExtractor(this);
break;
}
}
Extractor::~Extractor(){
if(deposit) deposit->setExtractor(nullptr);
destructable->removeBar(ammountForeground);
destructable->removeBar(ammountBackground);
}
void Extractor::initProperties(){
Game *game = Game::getSingleton();
vector<int> currTechs = player->getTechnologies();
sol::table unitTable = generateView()["units"][id + 1];
drawRate = unitTable["drawRate"]; drawRate += game->calcAbilFromTech(Ability::Type::DRAW_RATE, currTechs, (int)GameObject::type, id);
drawSpeed = unitTable["drawSpeed"]; drawSpeed += game->calcAbilFromTech(Ability::Type::DRAW_SPEED, currTechs, (int)GameObject::type, id);
}
void Extractor::update(){
Structure::update();
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
vector<Player*> selectingPlayers = getSelectingPlayers();
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
int ammount = 0, initAmmount = 0;
if(deposit){
ammount = deposit->getAmmount();
initAmmount = deposit->getInitAmmount();
}
destructable->displayStats(ammountForeground, ammountBackground, ammount, initAmmount, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
}
void Extractor::draw(){
deposit->decreaseAmmount(drawSpeed);
lastDrawTime = getTime();
}
}
-30
View File
@@ -1,30 +0,0 @@
#ifndef EXTRACTOR_H
#define EXTRACTOR_H
#include "structure.h"
#include <util.h>
namespace battleship{
class ResourceDeposit;
class Extractor : public Structure{
public:
Extractor(Player*, int, vb01::Vector3, vb01::Quaternion, int, ResourceDeposit *rd = nullptr, Unit::State = Unit::State::STAND_GROUND);
~Extractor();
void update();
void draw();
bool canDraw(){return vb01::getTime() - lastDrawTime > drawRate;}
inline ResourceDeposit* getDeposit(){return deposit;}
private:
void initProperties();
int drawSpeed, drawRate;
vb01::s64 lastDrawTime = 0;
vb01::Node *ammountBackground = nullptr, *ammountForeground = nullptr;
ResourceDeposit *deposit = nullptr;
};
}
#endif
-82
View File
@@ -1,82 +0,0 @@
#include "factory.h"
#include "player.h"
#include "game.h"
#include "destructable.h"
#include "gameObjectFactory.h"
#include "activeGameState.h"
#include <stateManager.h>
#include <solUtil.h>
#include <vector>
namespace battleship{
using namespace vb01;
using namespace std;
using namespace gameBase;
Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state), rallyPoint(pos + 30 * dirVec){}
void Factory::update(){
Structure::update();
if(!isComplete()) return;
if(!unitQueue.empty()) train();
}
//TODO replace repetetive string literals
void Factory::initProperties(){
Structure::initProperties();
}
int Factory::getNumQueueUnitsById(int unitId){
int numUnits = 0;
for(int qu : unitQueue)
if(qu == unitId)
numUnits++;
return numUnits;
}
void Factory::appendToQueue(int buId){
if(buId < buildableUnits.size() && buildableUnits[buId].buildable)
unitQueue.push_back(buildableUnits[buId].id);
}
void Factory::train(){
bool training = !unitQueue.empty();
buildStatusForeground->setVisible(training);
buildStatusBackground->setVisible(training);
if(training){
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
vector<Player*> selectingPlayers = getSelectingPlayers();
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
destructable->displayStats(buildStatusForeground, buildStatusBackground, trainingStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
sol::table targTable = generateView()["units"][unitQueue[0] + 1];
int costRate = (int)targTable["cost"] / 100, trainRate = (int)targTable["buildTime"] / 100;
if(player->getResource(ResourceType::REFINEDS) >= costRate && getTime() - lastTrainTime > trainRate){
trainingStatus++;
player->updateResource(ResourceType::REFINEDS, -costRate, true);
lastTrainTime = getTime();
}
if(trainingStatus >= 100){
Unit *unit = GameObjectFactory::createUnit(player, unitQueue[0], pos, rot);
player->addUnit(unit);
unit->receiveOrder(Order(Order::TYPE::MOVE, vector<Order::Target>{Order::Target(nullptr, rallyPoint)}, Vector3::VEC_ZERO), false);
unitQueue.erase(unitQueue.begin());
trainingStatus = 0;
player->incVehiclesBuilt();
}
}
}
}
-37
View File
@@ -1,37 +0,0 @@
#ifndef FACTORY_H
#define FACTORY_H
#include "structure.h"
#include <vector>
#include <util.h>
namespace vb01{
class Node;
}
namespace battleship{
class Player;
class Factory : public Structure{
public:
Factory(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND);
~Factory(){}
void update();
int getNumQueueUnitsById(int);
void appendToQueue(int);
inline void setRallyPoint(vb01::Vector3 rp){this->rallyPoint = rp;}
inline vb01::Vector3 getRallyPoint(){return rallyPoint;}
inline std::vector<int> getQueue(){return unitQueue;}
private:
std::vector<int> unitQueue;
int maxLenQueue, trainingStatus = 0;
vb01::s64 lastTrainTime = 0;
vb01::Vector3 rallyPoint;
void initProperties();
void train();
};
}
#endif
-39
View File
@@ -1,39 +0,0 @@
#include "freezer.h"
#include "weapon.h"
#include "structure.h"
#include "destructable.h"
#include <vector>
namespace battleship{
using namespace vb01;
using namespace std;
//TODO rename the class to a more generic name
Freezer::Freezer(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state){}
void Freezer::attack(Order order){
Vehicle::attack(order);
Destructable *target = order.targets[0].unit->getDestructable();
if(target && target->getFreezeStatus() >= 100)
removeOrder(0);
}
void Freezer::build(Order order){
vector<Weapon*> weapons = getWeaponsByType((int)Weapon::Type::FREEZER);
if(weapons.empty()) return;
Unit *targ = (Unit*)order.targets[0].unit;
for(Weapon *w : weapons)
w->trackTarget(targ->getPos());
Vehicle::build(order);
if(targ->getUnitClass() == UnitClass::ICE_SHEET && ((Structure*)targ)->isComplete())
removeOrder(0);
}
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef FREEZER_H
#define FREEZER_H
#include "vehicle.h"
namespace battleship{
class Freezer : public Vehicle{
public:
Freezer(Player*, int, vb01::Vector3, vb01::Quaternion, Unit::State);
private:
void attack(Order);
void build(Order);
};
}
#endif
-232
View File
@@ -1,232 +0,0 @@
#include "fxManager.h"
#include "gameObject.h"
#include <root.h>
#include <model.h>
#include <box.h>
#include <material.h>
#include <vector.h>
#include <particleEmitter.h>
#include <SFML/Audio.hpp>
namespace battleship{
using namespace std;
using namespace vb01;
FxManager::Fx::Component::Component(void *c, bool v, s64 dur, vb01::Vector3 p, s64 ot) : comp(c), vfx(v), duration(dur), pos(p), offsetTime(ot) {
if(v) ((vb01::Node*)c)->setVisible(false);
}
FxManager::Fx::Fx(std::vector<FxManager::Fx::Component> comps, bool re) : components(comps), reuse(re){
toggleComponents(!re);
}
FxManager::Fx* FxManager::initFx(sol::table fxTbl, Node *baseNode, bool attached, Vector3 cp){
int numComponents = fxTbl.size();
if(numComponents == 0) return nullptr;
vector<FxManager::Fx::Component> fxComponents;
for(int i = 0; i < numComponents; i++){
sol::table compTbl = fxTbl[i + 1];
bool vfx = compTbl["vfx"];
s64 duration = compTbl["duration"], offset = compTbl["offset"].get_or(0);
if(vfx){
sol::table meshTbl = compTbl["mesh"];
string meshPath = "";
Material *mat = nullptr;
Node *flashNode = nullptr;
sol::optional<sol::table> posOpt = compTbl["pos"], rotOpt = compTbl["rot"];
Vector3 compPos = cp;
Quaternion compRot = Quaternion::QUAT_W;
float sc = compTbl["scale"].get_or(1);
if(posOpt != sol::nullopt){
sol::table posTable = compTbl["pos"];
compPos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
}
if(rotOpt != sol::nullopt){
sol::table rotTable = compTbl["rot"];
compRot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
}
sol::optional<string> pathOpt = meshTbl["path"];
sol::optional<int> numPartOpt = meshTbl["numParticles"];
if(pathOpt != sol::nullopt){
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
meshPath = meshTbl["path"];
flashNode = new Model(meshPath);
((Model*)flashNode)->setMaterial(mat);
flashNode->setPosition(compPos);
flashNode->setOrientation(compRot);
flashNode->setScale(Vector3(sc, sc, sc));
}
else if(numPartOpt != sol::nullopt){
mat = new Material(Root::getSingleton()->getLibPath() + "particle");
int numParticles = meshTbl["numParticles"];
ParticleEmitter *pe = new ParticleEmitter(numParticles);
pe->setMaterial(mat);
pe->setLowLife(meshTbl["lowLife"]);
pe->setHighLife(meshTbl["highLife"]);
pe->setSpeed(0);
sol::table sizeTbl = meshTbl["size"];
pe->setSize(Vector2(sizeTbl["x"], sizeTbl["y"]));
flashNode = new Node(compPos + Vector3(0, 2, 0), compRot, Vector3(sc, sc, sc));
flashNode->attachParticleEmitter(pe);
flashNode->lookAt(Vector3::VEC_J, Vector3::VEC_K);
}
else{
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
sol::table sizeTbl = meshTbl["size"];
Box *box = new Box(Vector3(sizeTbl["x"], sizeTbl["y"], 0));
box->setMaterial(mat);
flashNode = new Node(compPos, compRot, Vector3(sc, sc, sc), "laser");
flashNode->attachMesh(box);
}
sol::optional<string> texOpt = meshTbl["texture"];
if(texOpt != sol::nullopt){
string p[]{meshTbl["texture"]};
Texture *tex = new Texture(p, 1, false);
mat->addBoolUniform("texturingEnabled", true);
mat->addTexUniform("diffuseMap[0]", tex, false);
}
else{
sol::table colorTable = meshTbl["color"];
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["a"]));
mat->addBoolUniform("texturingEnabled", false);
}
flashNode->setVisible(false);
Node *parNode = (attached ? baseNode : Root::getSingleton()->getRootNode());
sol::optional<string> parNameOpt = compTbl["parent"];
if(parNameOpt != sol::nullopt){
string parName = compTbl["parent"];
parNode = baseNode->findDescendant(parName, true);
}
parNode->attachChild(flashNode);
fxComponents.push_back(FxManager::Fx::Component((void*)flashNode, vfx, duration, compPos, offset));
}
else{
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
sf::Sound *sfx = GameObject::prepareSfx(sfxBuffer, compTbl["path"]);
fxComponents.push_back(FxManager::Fx::Component((void*)sfx, vfx, duration, Vector3::VEC_ZERO, offset));
}
}
return new FxManager::Fx(fxComponents, attached);
}
void FxManager::Fx::toggleComponents(bool active){
for(Component &component : components){
component.active = active;
component.initTime = getTime();
}
}
static FxManager *fxManager = nullptr;
FxManager* FxManager::getSingleton(){
if(!fxManager)
fxManager = new FxManager();
return fxManager;
}
void FxManager::update(){
for(int i = 0; i < fxs.size(); i++){
s64 currTime = getTime();
Fx *fx = fxs[i];
for(int j = 0; j < fx->components.size(); j++){
Fx::Component &comp = fx->components[j];
s64 currTime = getTime();
if(comp.comp && currTime - comp.initTime > comp.offsetTime){
if(comp.active){
if(comp.vfx)
((Node*)comp.comp)->setVisible(true);
else
((sf::Sound*)comp.comp)->play();
comp.active = false;
comp.initTime = getTime();
}
else if(!comp.active && currTime - comp.initTime > comp.duration){
if(fx->reuse){
if(comp.vfx)
((Node*)comp.comp)->setVisible(false);
else
((sf::Sound*)comp.comp)->stop();
}
else{
destroyFxComponent(i, j);
fx->components.erase(fx->components.begin() + j);
j--;
}
}
}
}
if(fx->components.empty()){
delete fx;
fxs.erase(fxs.begin() + i);
i--;
}
}
}
void FxManager::destroyFxComponent(int fid, int cid){
Fx *fx = fxs[fid];
if(fx->components[cid].vfx){
Node *vfxNode = (Node*)fx->components[cid].comp, *parNode = vfxNode->getParent();
parNode->dettachChild(vfxNode);
delete vfxNode;
}
else{
sf::Sound *sfx = (sf::Sound*)fx->components[cid].comp;
const sf::SoundBuffer *buffer = &sfx->getBuffer();
sfx->stop();
delete sfx;
delete buffer;
}
fx->components[cid].comp = nullptr;
}
void FxManager::removeFx(Fx *fx){
int id = -1;
for(int i = 0; i < fxs.size(); i++)
if(fxs[i] == fx){
id = i;
break;
}
for(int i = 0; i < fx->components.size(); i++)
destroyFxComponent(id, i);
fxs.erase(fxs.begin() + id);
delete fx;
}
}
-44
View File
@@ -1,44 +0,0 @@
#ifndef FX_MANAGER_H
#define FX_MANAGER_H
#include <util.h>
#include <solUtil.h>
namespace vb01{
class Node;
}
namespace battleship{
class FxManager{
public:
struct Fx {
struct Component{
vb01::s64 duration, initTime = 0, offsetTime = 0;
vb01::Vector3 pos = vb01::Vector3::VEC_ZERO;
bool vfx, active = false;
void *comp = nullptr;
Component(void*, bool, vb01::s64, vb01::Vector3 = vb01::Vector3::VEC_ZERO, vb01::s64 = 0);
};
bool reuse;
std::vector<Component> components;
Fx(std::vector<Component>, bool = false);
void toggleComponents(bool);
};
static FxManager* getSingleton();
FxManager::Fx* initFx(sol::table, vb01::Node*, bool, vb01::Vector3 = vb01::Vector3::VEC_ZERO);
void update();
void removeFx(Fx*);
inline void addFx(Fx *fx){fxs.push_back(fx);}
private:
FxManager(){}
void destroyFxComponent(int, int);
std::vector<Fx*> fxs;
};
}
#endif
-247
View File
@@ -1,247 +0,0 @@
#include "game.h"
#include "player.h"
#include "projectile.h"
#include "gameManager.h"
#include "activeGameState.h"
#include "inGameAppState.h"
#include "concreteGuiManager.h"
#include "fxManager.h"
#include "factory.h"
#include "defConfigs.h"
#include <algorithm>
#include <assetManager.h>
#include <particleEmitter.h>
#include <stateManager.h>
#include <solUtil.h>
#include <SFML/Audio.hpp>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
static Game *game = nullptr;
Game* Game::getSingleton(){
if(!game)
game = new Game();
return game;
}
void Game::endGame(bool victory){
ended = true;
StateManager *sm = GameManager::getSingleton()->getStateManager();
sm->dettachAppState(sm->getAppStateByType(AppStateType::ACTIVE_STATE));
ConcreteGuiManager::getSingleton()->parseLuaScript(victory ? "victory.lua" : "defeat.lua");
}
void Game::update(){
sol::state_view SOL_LUA_VIEW = generateView();
for(int i = 0; i < getCpuPlayers().size(); i++) {
string plStr = "game.cpuPlayers[" + to_string(i + 1) + "]";
SOL_LUA_VIEW.script("executeBtNode(" + plStr + ", " + plStr + ".behaviour)");
SOL_LUA_VIEW.collect_garbage();
}
int numPlayersWithUnits = 0;
for(int i = 0; i < players.size(); i++){
players[i]->update();
if(players[i]->getNumUnits() > 0)
numPlayersWithUnits++;
}
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
if(mainPlayer && !ended){
int numMainPlayerUnits = mainPlayer->getNumUnits();
if(numMainPlayerUnits > 0 && numPlayersWithUnits == 1)
endGame(true);
else if(numMainPlayerUnits == 0)
endGame(false);
}
FxManager::getSingleton()->update();
}
void Game::initLuaPlayers(){
sol::state_view SOL_LUA_VIEW = generateView();
vector<Player*> cpuPlayers = getCpuPlayers();
for(int i = 0; i < cpuPlayers.size(); i++)
SOL_LUA_VIEW["game"]["cpuPlayers"][i + 1] = cpuPlayers[i];
SOL_LUA_VIEW.script_file(GameManager::getSingleton()->getPath() + "Scripts/Core/playerInit.lua");
}
void Game::removeAllElements(){
generateView().script("game.cpuPlayers = {}");
while(!players.empty()){
delete players[0];
players.erase(players.begin());
}
ended = false;
paused = false;
}
void Game::togglePause(){
GameManager *gm = GameManager::getSingleton();
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
ActiveGameState *activeState = ((InGameAppState*)gm->getStateManager()->getAppStateByType(AppStateType::IN_GAME_STATE))->getActiveState();
if (!paused) {
gm->getStateManager()->dettachAppState(activeState);
guiManager->parseLuaScript("gamePaused.lua");
}
else {
guiManager->readLuaScreenScript("inGame.lua", activeState->getGuiButtons());
if(debug){
sol::state_view SOL_LUA_VIEW = generateView();
for(string f : configData::scripts)
SOL_LUA_VIEW.script_file(gm->getPath() + f);
initLuaPlayers();
vector<GameObject*> gameObjs;
for(Player *pl : Game::getSingleton()->getPlayers()){
for(Unit *u : pl->getUnits())
gameObjs.push_back((GameObject*)u);
for(Projectile *proj : pl->getProjectiles())
gameObjs.push_back((GameObject*)proj);
}
for(ResourceDeposit *dep : civilianPlayer->getResourceDeposits())
gameObjs.push_back((GameObject*)dep);
string gop = SOL_LUA_VIEW["gameObjPrefix"], vfxp = SOL_LUA_VIEW["vfxPrefix"];
AssetManager::getSingleton()->load(gm->getPath() + gop, true);
AssetManager::getSingleton()->load(gm->getPath() + vfxp, true);
for(GameObject *obj : gameObjs)
obj->reinit();
}
gm->getStateManager()->attachAppState(activeState);
}
paused = !paused;
}
vector<int> Game::parseTechTable(int tid, string key, string numVarKey, string varKey){
sol::state_view SOL_LUA_VIEW = generateView();
SOL_LUA_VIEW.script(numVarKey + " = #" + key + "[" + to_string(tid + 1) + "]." + varKey);
int numVar = SOL_LUA_VIEW[numVarKey];
sol::table techTable = SOL_LUA_VIEW[key][tid + 1];
vector<int> varVec;
for(int i = 0; i < numVar; i++)
varVec.push_back(techTable[varKey][i + 1]);
return varVec;
}
//TODO clean this method up
void Game::initTechnologies(){
technologies.clear();
sol::state_view SOL_LUA_VIEW = generateView();
string techKey = "technologies";
SOL_LUA_VIEW.script("numTechs = #" + techKey);
int numTechs = SOL_LUA_VIEW["numTechs"];
for(int i = 0; i < numTechs; i++){
sol::table techTable = SOL_LUA_VIEW[techKey][i + 1];
Technology t;
t.cost = techTable["cost"];
t.name = techTable["name"];
t.icon = techTable["icon"];
t.description = techTable["description"];
t.parents = parseTechTable(i, techKey, "numParents", "parents");
t.abilities = parseTechTable(i, techKey, "numAbilities", "abilities");
technologies.push_back(t);
}
techKey = "abilities";
SOL_LUA_VIEW.script("numAbilities = #" + techKey);
int numAbilities = SOL_LUA_VIEW["numAbilities"];
for(int i = 0; i < numAbilities; i++){
sol::table techTable = SOL_LUA_VIEW[techKey][i + 1];
Ability ability;
ability.type = techTable["type"];
ability.ammount = techTable["ammount"].get_or(0.0);
ability.gameObjType = techTable["gameObjType"];
ability.gameObjIds = parseTechTable(i, techKey, "numGameObjIds", "gameObjIds");
abilities.push_back(ability);
}
}
float Game::calcAbilFromTech(Ability::Type type, vector<int> techResearch, int gameObjType, int unitId){
float ammount = 0;
for(int techId : techResearch)
for(int abilId : technologies[techId].abilities)
if(
abilities[abilId].type == type &&
abilities[abilId].gameObjType == gameObjType &&
find(abilities[abilId].gameObjIds.begin(), abilities[abilId].gameObjIds.end(), unitId) != abilities[abilId].gameObjIds.end()
){
ammount += abilities[abilId].ammount;
}
return ammount;
}
bool Game::isUnitUnlocked(vector<int> techResearch, int unitId){
for(int techId : techResearch){
for(int abilId : technologies[techId].abilities){
vector<int> ids = abilities[abilId].gameObjIds;
if(find(ids.begin(), ids.end(), unitId) != ids.end())
return true;
}
}
return false;
}
vector<Player*> Game::getPlayers(bool civPl){
vector<Player*> playersVec = players;
if(civPl) playersVec.push_back(civilianPlayer);
return playersVec;
}
vector<Player*> Game::getCpuPlayers(){
vector<Player*> playersVec;
for(Player *pl : players)
if(pl->isCpuPlayer())
playersVec.push_back(pl);
return playersVec;
}
}
-53
View File
@@ -1,53 +0,0 @@
#ifndef GAME_H
#define GAME_H
#include "technology.h"
#include "ability.h"
#include "tradeOffer.h"
#include <vector>
namespace sf{
class Sound;
}
namespace battleship{
class Unit;
class Player;
class Projectile;
class Game{
public:
static Game* getSingleton();
void update();
void initLuaPlayers();
void togglePause();
void removeAllElements();
void initTechnologies();
float calcAbilFromTech(Ability::Type, std::vector<int>, int, int);
bool isUnitUnlocked(std::vector<int>, int);
std::vector<Player*> getPlayers(bool = false);
std::vector<Player*> getCpuPlayers();
inline void setDebug(bool d){this->debug = d;}
inline void addPlayer(Player *pl){players.push_back(pl);}
inline bool isDebug(){return debug;}
inline Player* getPlayer(int id){return players[id];}
inline void setCivilianPlayer(Player *pl){this->civilianPlayer = pl;}
inline Player* getCivilianPlayer(){return civilianPlayer;}
inline int getNumPlayers(){return players.size();}
inline Technology getTechnology(int id){return technologies[id];}
inline Ability getAbility(int id){return abilities[id];}
private:
Game(){}
void endGame(bool);
std::vector<int> parseTechTable(int, std::string, std::string, std::string);
bool paused = false, ended = false, debug = false;
std::vector<Technology> technologies;
std::vector<Ability> abilities;
std::vector<Player*> players;
Player *civilianPlayer = nullptr;
};
}
#endif
-286
View File
@@ -1,286 +0,0 @@
#include <algorithm>
#include <stateManager.h>
#include <inputManager.h>
#include <soundManager.h>
#include <assetManager.h>
#include <root.h>
#include "gameManager.h"
#include "gameObjectFrameController.h"
#include "gameObjectFactory.h"
#include "map.h"
#include "game.h"
#include "guiAppState.h"
#include "defConfigs.h"
#include "player.h"
#include "extractor.h"
#include "factory.h"
#include "vehicle.h"
#include "engineer.h"
#include "destructable.h"
#include "pointDefense.h"
#include "pathfinder.h"
#include "resourceDeposit.h"
using namespace std;
using namespace vb01;
using namespace gameBase;
namespace battleship{
static GameManager *gameManager = nullptr;
GameManager* GameManager::getSingleton(){
if(!gameManager)
gameManager = new GameManager();
return gameManager;
}
void GameManager::registerMembers(){
sol::state_view SOL_LUA_STATE = generateView();
SOL_LUA_STATE.new_usertype<Order>(
"Order", sol::constructors<Order(), Order(Order::TYPE, vector<Order::Target>, Vector3, int)>(),
"type", &Order::type,
"direction", &Order::direction,
"targets", &Order::targets
);
SOL_LUA_STATE.new_usertype<Order::Target>(
"Target", sol::constructors<Order::Target(), Order::Target(GameObject*, Vector3)>(),
"unit", &Order::Target::unit,
"pos", &Order::Target::pos
);
SOL_LUA_STATE.new_usertype<GameObjectFactory>(
"GameObjectFactory",
"createUnit", &GameObjectFactory::createUnit,
"createResourceDeposit", &GameObjectFactory::createResourceDeposit
);
SOL_LUA_STATE.new_usertype<Unit::GarrisonSlot>(
"GarrisonSlot",
"vehicle", &Unit::GarrisonSlot::vehicle,
"category", &Unit::GarrisonSlot::category
);
SOL_LUA_STATE.new_usertype<Unit>(
"Unit", sol::constructors<Unit(Player*, int, Vector3, Quaternion)>(),
"setState", &Unit::setState,
"getDestructable", &Unit::getDestructable,
"getGarrisonSlots", &Unit::getGarrisonSlots,
"getNumFreeGarrisonSlots", &Unit::getNumFreeGarrisonSlots,
"getNumGarrisonSlots", &Unit::getNumGarrisonSlots,
"isGarrisonEmpty", &Unit::isGarrisonEmpty,
"getOrder", &Unit::getOrder,
"getNumOrders", &Unit::getNumOrders,
"getDirVec", &GameObject::getDirVec,
"getLeftVec", &GameObject::getLeftVec,
"getPos", &GameObject::getPos,
"getUnitClass", &Unit::getUnitClass,
"getLineOfSight", &Unit::getLineOfSight,
"getBuildableUnit", &Unit::getBuildableUnit,
"getBuildableUnits", &Unit::getBuildableUnits,
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
"toGameObject", [](Unit *u){return (GameObject*)u;},
"toVehicle", [](Unit *u){return (Vehicle*)u;},
"toEngineer", [](Unit *u){return (Engineer*)u;},
"toStructure", [](Unit *u){return (Structure*)u;},
"toFactory", [](Unit *u){return (Factory*)u;},
"toExtractor", [](Unit *u){return (Extractor*)u;},
"toPointDefense", [](Unit *u){return (PointDefense*)u;}
);
SOL_LUA_STATE.new_usertype<Vehicle>(
"Engineer", sol::constructors<Vehicle(Player*, int, Vector3, Quaternion, Unit::State)>(),
"getGarrisonable", &Vehicle::getGarrisonable
);
SOL_LUA_STATE.new_usertype<Engineer>(
"Engineer", sol::constructors<Engineer(Player*, int, Vector3, Quaternion, Unit::State)>(),
"getBuildableUnit", &Unit::getBuildableUnit,
"getBuildableUnits", &Unit::getBuildableUnits,
"getNumBuildableUnits", &Unit::getNumBuildableUnits
);
SOL_LUA_STATE.new_usertype<Structure>(
"Structure", sol::constructors<Structure(Player*, int, Vector3, Quaternion, int)>(),
"getPos", &GameObject::getPos,
"isComplete", &Structure::isComplete,
"getBuildStatus", &Structure::getBuildStatus
);
SOL_LUA_STATE.new_usertype<BuildableUnit>(
"BuildableUnit", sol::constructors<BuildableUnit(int, bool)>(),
"id", &BuildableUnit::id,
"buildable", &BuildableUnit::buildable
);
SOL_LUA_STATE.new_usertype<Factory>(
"Factory", sol::constructors<Factory(Player*, int, Vector3, Quaternion, int)>(),
"getBuildableUnit", &Unit::getBuildableUnit,
"getBuildableUnits", &Unit::getBuildableUnits,
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
"getDirVec", &GameObject::getDirVec,
"getLeftVec", &GameObject::getLeftVec,
"getPos", &GameObject::getPos,
"appendToQueue", &Factory::appendToQueue,
"getBuildStatus", &Structure::getBuildStatus,
"getNumQueueUnitsById", &Factory::getNumQueueUnitsById,
"getRallyPoint", &Factory::getRallyPoint,
"setRallyPoint", &Factory::setRallyPoint,
"getQueue", &Factory::getQueue
);
SOL_LUA_STATE.new_usertype<Player>(
"Player", sol::constructors<Player(int, int, int, Vector3, bool, int, string)>(),
"getSelectedUnits", &Player::getSelectedUnits,
"haltUnits", &Player::haltUnits,
"addUnit", &Player::addUnit,
"getUnit", &Player::getUnit,
"getNumUnits", &Player::getNumUnits,
"getResourceDeposits", &Player::getResourceDeposits,
"issueOrder", &Player::issueOrder,
"selectUnits", &Player::selectUnits,
"deselectUnits", &Player::deselectUnits,
"getSpawnPointId", &Player::getSpawnPointId,
"getFaction", &Player::getFaction,
"getTeam", &Player::getTeam,
"getUnits", &Player::getUnits,
"getHostileUnits", &Player::getHostileUnits,
"getFriendlyUnits", &Player::getFriendlyUnits,
"getUnitsById", &Player::getUnitsById,
"getUnitsByClass", &Player::getUnitsByClass,
"isObjectVisible", &Player::isObjectVisible
);
SOL_LUA_STATE.new_usertype<Extractor>(
"Extractor", sol::constructors<Extractor(Player*, int, Vector3, Quaternion, int, ResourceDeposit*, Unit::State)>(),
"getDeposit", &Extractor::getDeposit
);
SOL_LUA_STATE.new_usertype<ResourceDeposit>(
"ResourceDeposit", sol::constructors<ResourceDeposit(Player*, int, Vector3, Quaternion, int)>(),
"getExtractor", &ResourceDeposit::getExtractor,
"getAmmount", &ResourceDeposit::getAmmount,
"getPos", &GameObject::getPos,
"toGameObject", [](ResourceDeposit *rd){return (GameObject*)rd;}
);
SOL_LUA_STATE.new_usertype<Game>(
"Game",
"getSingleton", &Game::getSingleton,
"getPlayers", &Game::getPlayers
);
SOL_LUA_STATE.new_usertype<Vector3>(
"Vector3", sol::constructors<Vector3(), Vector3(float, float, float)>(),
"x", &Vector3::x,
"y", &Vector3::y,
"z", &Vector3::z,
"norm", &Vector3::norm,
"getAngleBetween", &Vector3::getAngleBetween,
"getDistanceFrom", &Vector3::getDistanceFrom,
"neg", [](Vector3 v){return -v;},
"add", [](Vector3 v1, Vector3 v2){return v1 + v2;},
"subtr", [](Vector3 v1, Vector3 v2){return v1 - v2;},
"mult", [](Vector3 v1, float s){return v1 * s;},
"div", [](Vector3 v1, float s){return v1 / s;}
);
SOL_LUA_STATE.new_usertype<Quaternion>(
"Quaternion", sol::constructors<Quaternion(), Quaternion(float, float, float, float), Quaternion(float, Vector3)>(),
"w", &Quaternion::w,
"x", &Quaternion::x,
"y", &Quaternion::y,
"z", &Quaternion::z,
"getAngle", &Quaternion::getAngle,
"getAxis", &Quaternion::getAxis,
"multVec", [](Quaternion q, Vector3 v){return q * v;}
);
SOL_LUA_STATE.new_usertype<Map::Edge>(
"Edge",
"destCellId", &Map::Edge::destCellId
);
SOL_LUA_STATE.new_usertype<Map::Cell>(
"Cell",
"pos", &Map::Cell::pos,
"type", &Map::Cell::type,
"edges", &Map::Cell::edges
);
SOL_LUA_STATE.new_usertype<Map>(
"Map",
"getSingleton", &Map::getSingleton,
"getCell", &Map::getCell,
"getCells", &Map::getCells,
"getCellId", &Map::getCellId,
"getMapSize", &Map::getMapSize,
"getSpawnPoint", &Map::getSpawnPoint,
"getNumSpawnPoints", &Map::getNumSpawnPoints
);
SOL_LUA_STATE.new_usertype<Pathfinder>(
"Pathfinder",
"getSingleton", &Pathfinder::getSingleton,
"clampDestToSourceRegion", &Pathfinder::clampDestToSourceRegion,
"calcHeuristics", &Pathfinder::calcHeuristics,
"findPath", &Pathfinder::findPath
);
SOL_LUA_STATE.new_usertype<GameObjectFrame>(
"GameObjectFrame", sol::constructors<GameObjectFrame(int, GameObject::Type, Player*, Unit*, Vector3, Quaternion)>(),
"getOriginalUnit", &GameObjectFrame::getOriginalUnit,
"destroy", &GameObjectFrame::destroy,
"placeAt", &GameObjectFrame::placeAt,
"getDirVec", &GameObjectFrame::getDirVec,
"getLeftVec", &GameObjectFrame::getLeftVec,
"getLength", &GameObjectFrame::getLength,
"getWidth", &GameObjectFrame::getWidth,
"status", &GameObjectFrame::status
);
SOL_LUA_STATE.new_usertype<GameObjectFrameController>(
"GameObjectFrameController",
"getSingleton", &GameObjectFrameController::getSingleton,
"checkPlacement", &GameObjectFrameController::checkPlacement
);
}
void GameManager::initLua(string gameDir){
sol::state_view SOL_LUA_STATE = generateView();
path = gameDir + "Assets/";
SOL_LUA_STATE.script("PATH = \"" + path + "\";");
for(string f : configData::scripts)
SOL_LUA_STATE.script_file(path + f);
sol::table resTable = SOL_LUA_STATE["graphics"]["resolution"];
width = resTable["x"];
height = resTable["y"];
}
void GameManager::start(string gameDir) {
running = true;
registerMembers();
initLua(gameDir);
Root *root = Root::getSingleton();
root->start(width, height, path + "../external/vb01/", "Battleship");
stateManager = new StateManager();
inputManager = new InputManager(stateManager, root->getWindow());
}
void GameManager::update() {
Root::getSingleton()->update();
SoundManager::getSingleton()->update();
inputManager->update();
stateManager->update();
}
}
-46
View File
@@ -1,46 +0,0 @@
#pragma once
#ifndef GAME_MANAGER_H
#define GAME_MANAGER_H
#include "util.h"
#include <mapping.h>
#include <vector>
#include <string>
namespace gameBase{
class InputManager;
class StateManager;
}
namespace battleship{
class GameManager {
public:
static GameManager* getSingleton();
void start(std::string);
void update();
inline int getWidth(){return width;}
inline int getHeight(){return height;}
inline std::string getPath(){return path;}
inline gameBase::InputManager* getInputManager(){return inputManager;}
inline bool isServerSide(){return serverSide;}
inline bool isRunning(){return running;}
inline void setRunning(bool r){this->running = r;}
inline gameBase::StateManager* getStateManager(){return stateManager;}
private:
GameManager(){}
~GameManager(){}
void registerMembers();
void initLua(std::string);
gameBase::StateManager *stateManager = nullptr;
gameBase::InputManager *inputManager = nullptr;
int width, height;
std::string path = "";
bool serverSide, running = false;
};
}
#endif
-226
View File
@@ -1,226 +0,0 @@
#include "gameObject.h"
#include "gameManager.h"
#include "destructable.h"
#include "defConfigs.h"
#include "player.h"
#include "game.h"
#include "unit.h"
#include <solUtil.h>
#include <material.h>
#include <box.h>
#include <SFML/Audio.hpp>
#include <string>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
using namespace configData;
GameObject::GameObject(Type t, int i, Player *pl, vb01::Vector3 vec, vb01::Quaternion quat) : type(t), id(i), player(pl), pos(vec), rot(quat){}
void GameObject::reinit(){
placeAt(pos);
orientAt(rot);
if(hitbox){
Box *hbMesh = (Box*)hitbox->getMesh(0);
hbMesh->setSize(Vector3(width, height, length));
hbMesh->updateVerts(hbMesh->getMeshBase());
hitbox->setVisible(Game::getSingleton()->isDebug());
}
}
void GameObject::update(){
leftVec = model->getGlobalAxis(0);
upVec = model->getGlobalAxis(1);
dirVec = model->getGlobalAxis(2);
screenPos = spaceToScreen(pos);
}
void GameObject::placeAt(Vector3 p) {
model->setPosition(p);
pos = p;
}
void GameObject::orientAt(Quaternion rotQuat){
rot = rotQuat;
model->setOrientation(rotQuat);
leftVec = model->getGlobalAxis(0);
upVec = model->getGlobalAxis(1);
dirVec = model->getGlobalAxis(2);
}
//TODO remove neccessity to create a material for an invisible mesh
void GameObject::initHitbox(){
Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture");
mat->addBoolUniform("texturingEnabled", false);
mat->addBoolUniform("lightingEnabled", false);
mat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1));
Box *box = new Box(Vector3(width, height, length));
box->setWireframe(true);
box->setMaterial(mat);
sol::table gameObjTable = generateView()[GameObject::getGameObjTableName()][id + 1];
sol::table offsetPosTable = gameObjTable["hitboxOffset"];
hitbox = new Node(Vector3(offsetPosTable["x"], offsetPosTable["y"], offsetPosTable["z"]));
hitbox->attachMesh(box);
hitbox->setVisible(Game::getSingleton()->isDebug());
model->attachChild(hitbox);
}
void GameObject::destroyHitbox(){
model->dettachChild(hitbox);
delete hitbox;
hitbox = nullptr;
}
//TODO use a vector for the color nodes
void GameObject::useColor(Material *colorMat){
if(hitbox) model->dettachChild(hitbox);
model->setMaterial(model->getMaterial());
if(hitbox) model->attachChild(hitbox);
sol::table gameObjTable = generateView()[GameObject::getGameObjTableName()][id + 1];
sol::table colNodeTbl = gameObjTable["colorNodes"];
int numColorNodes = colNodeTbl.size();
for(int i = 0; i < numColorNodes; i++){
string name = colNodeTbl[i + 1];
Node *node = model->findDescendant(name, true);
if(!node) continue;
vector<Mesh*> meshes = node->getMeshes();
for(Mesh *mesh : meshes)
mesh->setMaterial(colorMat);
}
}
void GameObject::initProperties(){
sol::table objTable = generateView()[GameObject::getGameObjTableName()][id + 1];
sol::optional<float> maxUnevOpt = objTable["maxUnevenness"];
if(maxUnevOpt != sol::nullopt) maxUnevenness = objTable["maxUnevenness"];
sol::table sizeTable = objTable["size"];
width = sizeTable["x"];
height = sizeTable["y"];
length = sizeTable["z"];
}
void GameObject::destroyModel(){
if(model->getMaterial())
delete model->getMaterial();
Root::getSingleton()->getRootNode()->dettachChild(model);
delete model;
}
//TODO improve DEFAULT_TEXTURE handling
void GameObject::initModel(bool textured){
sol::table gameObjTable = generateView()[GameObject::getGameObjTableName()][id + 1];
string basePath = gameObjTable["basePath"], meshPath = gameObjTable["meshPath"];
model = new Model(basePath + meshPath);
Root *root = Root::getSingleton();
Material *mat = new Material(root->getLibPath() + "texture");
if(textured){
string albedoPath = gameObjTable["albedoPath"].get_or(configData::DEFAULT_TEXTURE);
string f[]{albedoPath == configData::DEFAULT_TEXTURE ? GameManager::getSingleton()->getPath() + albedoPath : basePath + albedoPath};
Texture *diffuseTexture = new Texture(f, 1, false);
mat->addBoolUniform("texturingEnabled", true);
mat->addBoolUniform("lightingEnabled", true);
mat->addBoolUniform("constLightingEnabled", false);
mat->addTexUniform("textures[0]", diffuseTexture, true);
}
else{
mat->addBoolUniform("texturingEnabled", false);
mat->addBoolUniform("lightingEnabled", false);
mat->addVec4Uniform("diffuseColor", Vector4::VEC_ZERO);
model->setWireframe(true);
}
model->setMaterial(mat);
sol::optional<sol::table> colNodeOpt = gameObjTable["colorNodes"];
if(!(model->isWireframe() || colNodeOpt == sol::nullopt))
useColor(player->getColorMaterial());
root->getRootNode()->attachChild(model);
}
//TODO implement death SFX destruction
void GameObject::destroySound(){
}
sf::Sound* GameObject::prepareSfx(sf::SoundBuffer *buffer, string sfxPath){
sf::Sound *sfx = nullptr;
if(buffer->loadFromFile(sfxPath.c_str())){
sfx = new sf::Sound(*buffer);
sfx->setBuffer(*buffer);
}
return sfx;
}
bool GameObject::pointWithinObj(Vector3 point, float deltaLength, float deltaWidth, bool useHeight, float deltaHeight){
Vector3 pointDir = point - pos;
bool within = true;
float forwAngle = std::min(dirVec.getAngleBetween(pointDir.norm()), (-dirVec).getAngleBetween(pointDir.norm()));
float forwDist = pointDir.getLength() * cos(forwAngle);
within &= (forwDist < .5 * (length + deltaLength));
float leftAngle = std::min(leftVec.getAngleBetween(pointDir.norm()), (-leftVec).getAngleBetween(pointDir.norm()));
float leftDist = pointDir.getLength() * cos(leftAngle);
within &= (leftDist < .5 * (width + deltaWidth));
if(useHeight){
float upAngle = std::min(upVec.getAngleBetween(pointDir.norm()), (-upVec).getAngleBetween(pointDir.norm()));
float upDist = pointDir.getLength() * cos(upAngle);
within &= (upDist < .5 * (height + deltaHeight));
}
return within;
}
//TODO improve for other game objs, too
void GameObject::changePlayer(Player *newPlayer){
vector<Unit*> &oldPlayerUnits = player->getUnits();
int oldId = -1;
for(int i = 0; i < oldPlayerUnits.size(); i++)
if(oldPlayerUnits[i] == (Unit*)this){
oldId = i;
break;
}
oldPlayerUnits.erase(oldPlayerUnits.begin() + oldId);
newPlayer->addUnit((Unit*)this);
setPlayer(newPlayer);
useColor(newPlayer->getColorMaterial());
((Unit*)this)->halt();
}
string GameObject::getGameObjTableName(){
switch(type){
case GameObject::Type::UNIT:
return "units";
case GameObject::Type::PROJECTILE:
return "projectiles";
case GameObject::Type::RESOURCE_DEPOSIT:
return "resources";
}
}
}
-80
View File
@@ -1,80 +0,0 @@
#ifndef GAME_OBJECT_H
#define GAME_OBJECT_H
#include <vector.h>
#include <quaternion.h>
#include <model.h>
namespace sf{
class SoundBuffer;
class Sound;
}
namespace battleship{
class Player;
class Unit;
class Destructable;
class GameObject{
public:
enum class Type{UNIT, PROJECTILE, RESOURCE_DEPOSIT};
GameObject(Type, int, Player*, vb01::Vector3, vb01::Quaternion);
~GameObject(){}
virtual void reinit();
virtual void update();
virtual void select(){}
virtual void placeAt(vb01::Vector3);
void orientAt(vb01::Quaternion);
std::string getGameObjTableName();
static sf::Sound* prepareSfx(sf::SoundBuffer*, std::string);
bool pointWithinObj(vb01::Vector3, float = 0, float = 0, bool = false, float = 0);
void changePlayer(Player *newPlayer);
inline float getMaxUnevenness(){return maxUnevenness;}
inline vb01::Vector2 getScreenPos(){return screenPos;}
inline vb01::Vector3 getCorner(int i){return corners[i];}
inline bool isSelectable(){return selectable;}
inline bool isDebuggable(){return debugging;}
inline vb01::Vector3 getPos() {return pos;}
inline vb01::Quaternion getRot(){return rot;}
inline float getWidth() {return width;}
inline float getHeight() {return height;}
inline float getLength() {return length;}
inline vb01::Model* getModel() {return model;}
inline void setPlayer(Player *pl){player = pl;}
inline Player* getPlayer(){return player;}
inline void toggleDebugging(bool d){this->debugging=d;}
inline vb01::Vector3 getDirVec() {return dirVec;}
inline vb01::Vector3 getLeftVec() {return leftVec;}
inline vb01::Vector3 getUpVec() {return upVec;}
inline int getId() {return id;}
inline Type getType(){return type;}
inline vb01::Node* getHitbox(){return hitbox;}
inline void setRemove(bool rm){this->remove = rm;}
inline bool isRemove(){return remove;}
inline Destructable* getDestructable(){return destructable;}
protected:
virtual void useColor(vb01::Material*);
virtual void initProperties();
virtual void destroyModel();
virtual void initModel(bool = true);
virtual void initHitbox();
virtual void destroyHitbox();
virtual void destroySound();
virtual void initSound(){}
Type type;
int id;
Player *player;
Destructable *destructable = nullptr;
vb01::Model *model = nullptr;
vb01::Node *hitbox = nullptr;
vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, 1), leftVec = vb01::Vector3(1, 0, 0), corners[8];
vb01::Vector2 screenPos;
vb01::Quaternion rot;
bool selectable = false, debugging = false, remove = false;
float width, height, length, maxUnevenness;
};
}
#endif
-94
View File
@@ -1,94 +0,0 @@
#include "gameObjectFactory.h"
#include "player.h"
#include "factory.h"
#include "engineer.h"
#include "submarine.h"
#include "resourceRover.h"
#include "projectile.h"
#include "resourceDeposit.h"
#include "pointDefense.h"
#include "extractor.h"
#include "freezer.h"
#include "researchStruct.h"
#include "missile.h"
#include "cruiseMissile.h"
#include "iceSheet.h"
#include "shell.h"
#include "torpedo.h"
#include "depthCharge.h"
#include "defConfigs.h"
#include <solUtil.h>
#include <vector>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
Unit* GameObjectFactory::createUnit(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus){
sol::state_view SOL_LUA_VIEW = generateView();
int unitClass = SOL_LUA_VIEW["units"][id + 1]["unitClass"];
bool vehicle = SOL_LUA_VIEW["units"][id + 1]["isVehicle"];
if(vehicle)
switch((UnitClass)unitClass){
case UnitClass::ROBO_ENGINEER:
case UnitClass::CYBORG_ENGINEER:
return new Engineer(player, id, pos, rot, Unit::State::STAND_GROUND);
case UnitClass::RESOURCE_ROVER:
return new ResourceRover(player, id, pos, rot, Unit::State::STAND_GROUND);
case UnitClass::SUBMARINE:
case UnitClass::MISSILE_SUBMARINE:
return new Submarine(player, id, pos, rot, Unit::State::STAND_GROUND);
case UnitClass::FREEZER:
return new Freezer(player, id, pos, rot, Unit::State::STAND_GROUND);
default:
return new Vehicle(player, id, pos, rot, Unit::State::STAND_GROUND);
}
else
switch((UnitClass)unitClass){
case UnitClass::LAND_FACTORY:
case UnitClass::NAVAL_FACTORY:
return new Factory(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND);
case UnitClass::POINT_DEFENSE:
return new PointDefense(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND);
case UnitClass::EXTRACTOR:
return new Extractor(player, id, pos, rot, buildStatus);
case UnitClass::LAB:
return new ResearchStruct(player, id, pos, rot, buildStatus);
case UnitClass::ICE_SHEET:
return new IceSheet(player, id, pos, rot, buildStatus);
default:
return new Structure(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND);
}
}
Projectile* GameObjectFactory::createProjectile(Unit *unit, int id, Vector3 pos, Quaternion rot){
sol::state_view SOL_LUA_VIEW = generateView();
int projectileClass = SOL_LUA_VIEW["projectiles"][id + 1]["projectileClass"];
Order::Target target = unit->getOrder(0).targets[0];
Vector3 targetPos = (target.unit ? target.unit->getPos() : target.pos);
switch((ProjectileClass)projectileClass){
case ProjectileClass::SHELL:
return new Shell(unit, id, pos, rot);
case ProjectileClass::CRUISE_MISSILE:
return new CruiseMissile(unit, id, targetPos, pos, rot);
case ProjectileClass::MISSILE:
return new Missile(unit, id, targetPos, pos, rot);
case ProjectileClass::TORPEDO:
return new Torpedo(unit, id, pos, rot);
case ProjectileClass::DEPTH_CHARGE:
return new DepthCharge(unit, id, pos, rot);
default:
return new Projectile(unit, id, pos, rot);
}
}
ResourceDeposit* GameObjectFactory::createResourceDeposit(Player *player, int id, Vector3 pos, Quaternion rot, int initAmmount){
return new ResourceDeposit(player, id, pos, rot, initAmmount);
}
}
-23
View File
@@ -1,23 +0,0 @@
#ifndef GAME_OBJECT_FACTORY_H
#define GAME_OBJECT_FACTORY_H
#include <vector.h>
#include <quaternion.h>
namespace battleship{
class Unit;
class Projectile;
class ResourceDeposit;
class Player;
class GameObjectFactory{
public:
enum GameObjectType{UNIT, PROJECTILE, RESOURCE_DEPOSIT};
static Unit* createUnit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
static Projectile* createProjectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
static ResourceDeposit* createResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
private:
};
}
#endif
-4
View File
@@ -1,4 +0,0 @@
#include "gameObjectFrame.h"
namespace battleship{
}
-38
View File
@@ -1,38 +0,0 @@
#ifndef GAME_OBJECT_FRAME_H
#define GAME_OBJECT_FRAME_H
#include "gameObject.h"
#include <vector.h>
#include <quaternion.h>
namespace battleship{
struct GameObjectFrame : public GameObject{
enum Status{
PLACEABLE,
BLOCKED_BY_FOG_OF_WAR,
BLOCKED_BY_UNIT,
BLOCKED_BY_MAP_BOUNDS,
BLOCKED_BY_DIFF_TERR,
BLOCKED_BY_BUMPY_TERR
};
GameObjectFrame(int i, GameObject::Type t, Player *pl, Unit *ou = nullptr, vb01::Vector3 pos = vb01::Vector3::VEC_ZERO, vb01::Quaternion rot = vb01::Quaternion::QUAT_W) :
originalUnit(ou),
GameObject(t, i, pl, pos, rot)
{
initModel(false);
initProperties();
placeAt(pos);
orientAt(rot);
}
~GameObjectFrame(){}
void destroy(){destroyModel();}
inline Unit* getOriginalUnit(){return originalUnit;}
Status status;
Unit *originalUnit = nullptr;
};
}
#endif
-296
View File
@@ -1,296 +0,0 @@
#include <solUtil.h>
#include "gameObjectFrameController.h"
#include "activeGameState.h"
#include "resourceDeposit.h"
#include "defConfigs.h"
#include "player.h"
#include "game.h"
#include "unit.h"
#include "util.h"
#include "map.h"
#include <material.h>
#include <meshData.h>
#include <quad.h>
#include <model.h>
#include <root.h>
#include <stateManager.h>
#include <solUtil.h>
#include <string>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace gameBase;
static GameObjectFrameController *gameObjectFrameController = nullptr;
GameObjectFrameController* GameObjectFrameController::getSingleton(){
if(!gameObjectFrameController)
gameObjectFrameController = new GameObjectFrameController();
return gameObjectFrameController;
}
void GameObjectFrameController::paintSelect(Vector3 rowEnd){
Vector3 rowDir = rowEnd - paintSelectRowStart;
float lenRow = rowDir.getLength();
float width = gameObjectFrames[0].getWidth();
float length = gameObjectFrames[0].getLength();
float hypothenuse = sqrt(width * width + length * length);
int numStructsInRow = int(lenRow / hypothenuse);
while(gameObjectFrames.size() > numStructsInRow && gameObjectFrames.size() > 1)
removeGameObjectFrame(gameObjectFrames.size() - 1);
if(gameObjectFrames.size() < numStructsInRow){
int structureId = gameObjectFrames[0].getId();
Vector3 buildDir = rowDir;
if(gameObjectFrames.size() > 1)
buildDir = gameObjectFrames[1].getModel()->getPosition() - gameObjectFrames[0].getModel()->getPosition();
Vector3 pos = paintSelectRowStart + buildDir.norm() * hypothenuse * gameObjectFrames.size();
addGameObjectFrame(GameObjectFrame(structureId, GameObject::Type::UNIT, gameObjectFrames[0].getPlayer(), nullptr, pos));
}
}
void GameObjectFrameController::snapToObj(GameObjectFrame &s, vector<GameObject*> snapTargets, float maxDist){
s.status = GameObjectFrame::BLOCKED_BY_DIFF_TERR;
for(GameObject *st : snapTargets){
Vector3 stPos = st->getPos();
if(s.getPos().getDistanceFrom(stPos) < maxDist){
s.status = GameObjectFrame::PLACEABLE;
s.placeAt(stPos);
checkPlacement(s);
break;
}
}
}
//TODO include checking if frame is outside of line of sight
void GameObjectFrameController::checkPlacement(GameObjectFrame &s){
s.status = GameObjectFrame::PLACEABLE;
Map *map = Map::getSingleton();
Vector3 mapSize = map->getMapSize();
Vector3 cellSize = map->getCellSize();
int dirMult[][2]{{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
vector<Map::Cell> &cells = map->getCells();
sol::table tbl = generateView()["units"][s.getId() + 1];
UnitType ut = (UnitType)tbl["unitType"];
vector<Unit*> friendlyUnits = (s.getPlayer() ? s.getPlayer()->getFriendlyUnits() : vector<Unit*>{});
bool withinLos = false;
for(int i = 0; i < 4; i++){
Vector3 cornerPos = (s.getPos() + s.getDirVec() * .5 * dirMult[i][0] * s.getLength() + s.getLeftVec() * .5 * dirMult[i][1] * s.getWidth());
int cellId = map->getCellId(cornerPos, false);
if(cellId < 0 || !(fabs(cornerPos.x) <= .5 * mapSize.x && fabs(cornerPos.z) <= .5 * mapSize.z)){
s.status = GameObjectFrame::BLOCKED_BY_MAP_BOUNDS;
return;
}
Map::Cell cell = cells[cellId];
bool landUnitOnWater = (ut == UnitType::LAND && cell.type == Map::Cell::Type::WATER);
bool waterUnitOnLand = ((ut == UnitType::SEA_LEVEL || ut == UnitType::UNDERWATER) && cell.type == Map::Cell::Type::LAND);
bool withinCell = (fabs(cell.pos.x - cornerPos.x) < .5 * cellSize.x && fabs(cell.pos.z - cornerPos.z) < .5 * cellSize.z);
if((landUnitOnWater || waterUnitOnLand) && withinCell){
s.status = GameObjectFrame::BLOCKED_BY_DIFF_TERR;
return;
}
if(!withinLos)
for(Unit *fu : friendlyUnits)
if(fu->getPos().getDistanceFrom(s.getPos()) < fu->getLineOfSight()){
withinLos = true;
break;
}
}
if(!withinLos){
s.status = GameObjectFrame::BLOCKED_BY_FOG_OF_WAR;
return;
}
MeshData meshData = map->getNodeParent()->getChild(0)->getMesh(0)->getMeshBase();
MeshData::Vertex *verts = meshData.vertices;
int numVerts = 3 * meshData.numTris;
if(s.getMaxUnevenness() > 0)
for(int i = 0; i < numVerts; i++){
float diffX = fabs(s.getPos().x - verts[i].pos->x);
float diffY = fabs(s.getPos().y - verts[i].pos->y);
float diffZ = fabs(s.getPos().z - verts[i].pos->z);
if(diffX < 0.5 * s.getWidth() && diffZ < 0.5 * s.getLength() && diffY > s.getMaxUnevenness()){
s.status = GameObjectFrame::BLOCKED_BY_BUMPY_TERR;
return;
}
}
vector<Unit*> units;
for(Player *player : Game::getSingleton()->getPlayers(true)){
vector<Unit*> u = player->getUnits();
units.insert(units.end(), u.begin(), u.end());
}
for(Unit *unit : units){
if(unit == s.getOriginalUnit()) continue;
Vector3 gm1Pos = s.getPos();
Vector3 gm1Dir = s.getDirVec();
gm1Dir = Vector3(gm1Dir.x, 0, gm1Dir.z).norm();
Vector3 gm1Left = s.getLeftVec();
gm1Left = Vector3(gm1Left.x, 0, gm1Left.z).norm();
Vector3 gm2Pos = unit->getPos();
Vector3 gm2Dir = unit->getDirVec();
gm2Dir = Vector3(gm2Dir.x, 0, gm2Dir.z).norm();
Vector3 gm2Left = unit->getLeftVec();
gm2Left = Vector3(gm2Left.x, 0, gm2Left.z).norm();
bool intersects = rectanglesIntersect(
Vector2(gm1Pos.x, gm1Pos.z),
Vector2(gm1Dir.x, gm1Dir.z),
Vector2(gm1Left.x, gm1Left.z),
Vector2(s.getWidth(), s.getLength()),
Vector2(gm2Pos.x, gm2Pos.z),
Vector2(gm2Dir.x, gm2Dir.z),
Vector2(gm2Left.x, gm2Left.z),
Vector2(unit->getWidth(), unit->getLength())
);
if(intersects){
s.status = GameObjectFrame::BLOCKED_BY_UNIT;
return;
}
}
}
//TODO replace the magic number for ray casting height
void GameObjectFrameController::shiftVerticalPlacement(){
if(!minDepthCalculated){
Map *map = Map::getSingleton();
Node *nodeParent = map->getNodeParent();
Vector3 cellSize = map->getCellSize(), waterBodyPos;
bool inWater = false;
for(int i = 1; i < nodeParent->getNumChildren(); i++){
Vector3 wPos = nodeParent->getChild(i)->getPosition();
Vector3 wSize = ((Quad*)nodeParent->getChild(i)->getMesh(0))->getSize();
if(fabs(wPos.x - placementPos.x) < .5 * wSize.x && fabs(wPos.z - placementPos.z) < .5 * wSize.y){
waterBodyPos = wPos;
inWater = true;
break;
}
}
if(!inWater) return;
vector<RayCaster::CollisionResult> res = map->raycastTerrain(
Vector3(placementPos.x, 100, placementPos.z),
-Vector3::VEC_J,
false
);
vector<Map::Cell> &cells = map->getCells();
int cid = map->getCellId(placementPos, false);
int numSubmarineCells = cells[cid].underWaterCellIds.size();
maxDepth = cells[cid].pos.y;
minDepth = (numSubmarineCells > 0 ? cells[cells[cid].underWaterCellIds[numSubmarineCells - 1]].pos.y : maxDepth) - .5 * cellSize.y;
minDepthCalculated = true;
}
else{
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
float newDepth = minDepth + activeState->getDepth() * (maxDepth - minDepth);
placementPos.y = newDepth;
}
}
void GameObjectFrameController::update(){
Map *map = Map::getSingleton();
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
Vector3 endPos = screenToSpace(getCursorPos());
vector<RayCaster::CollisionResult> results = map->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true);
if(results.empty()) return;
if(paintSelecting) paintSelect(results[0].pos);
if(placingVertically) shiftVerticalPlacement();
else if(placingOnSurface) placementPos = results[0].pos;
vector<GameObject*> deposits;
for(ResourceDeposit *rd : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits())
deposits.push_back((GameObject*)rd);
for(int i = 0; i < gameObjectFrames.size(); i++){
gameObjectFrames[i].update();
if(paintSelecting){
float width = gameObjectFrames[0].getWidth();
float length = gameObjectFrames[0].getLength();
float hypothenuse = sqrt(width * width + length * length);
Vector3 dir = (results[0].pos - paintSelectRowStart).norm();
placementPos = paintSelectRowStart + dir * hypothenuse * i;
}
if(!rotating && (placingOnSurface || placingVertically))
gameObjectFrames[i].placeAt(placementPos);
bool extractor = false;
if(gameObjectFrames[i].getType() == GameObject::Type::UNIT){
sol::table tbl = generateView()["units"][gameObjectFrames[i].getId() + 1];
extractor = ((UnitClass)tbl["unitClass"] == UnitClass::EXTRACTOR);
}
if(extractor)
snapToObj(gameObjectFrames[i], deposits, 20);
else
checkPlacement(gameObjectFrames[i]);
bool placeable = (gameObjectFrames[i].status == GameObjectFrame::PLACEABLE);
Vector4 color = (placeable ? Vector4(0, 1, 0, 1) : Vector4(1, 0, 0, 1));
gameObjectFrames[i].getModel()->getMaterial()->setVec4Uniform("diffuseColor", color);
}
if(!placingVertically) minDepthCalculated = false;
}
void GameObjectFrameController::addGameObjectFrame(GameObjectFrame u){
gameObjectFrames.push_back(u);
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(u.getPos(), -Vector3::VEC_J, true);
if(!results.empty()) placementPos = results[0].pos;
}
void GameObjectFrameController::removeGameObjectFrame(int i){
gameObjectFrames[i].destroy();
gameObjectFrames.erase(gameObjectFrames.begin() + i);
}
void GameObjectFrameController::removeGameObjectFrames(){
while(gameObjectFrames.size() > 0)
removeGameObjectFrame(0);
}
void GameObjectFrameController::rotateGameObjectFrames(float angle){
for(GameObjectFrame &s : gameObjectFrames)
s.orientAt(Quaternion(angle, Vector3::VEC_J) * s.getRot());
}
}
-55
View File
@@ -1,55 +0,0 @@
#ifndef GAME_OBJECT_FRAME_CONTROLLER_H
#define GAME_OBJECT_FRAME_CONTROLLER_H
#include <vector>
#include <string>
#include <vector.h>
#include <quaternion.h>
#include "gameObjectFrame.h"
namespace vb01{
class Model;
}
namespace battleship{
class GameObjectFrameController{
public:
static GameObjectFrameController* getSingleton();
void update();
void removeGameObjectFrame(int);
void removeGameObjectFrames();
void rotateGameObjectFrames(float);
void checkPlacement(GameObjectFrame&);
void addGameObjectFrame(GameObjectFrame);
inline int getNumGameObjectFrames(){return gameObjectFrames.size();}
inline GameObjectFrame& getGameObjectFrame(int i){return gameObjectFrames[i];}
inline bool isPaintSelecting(){return paintSelecting;}
inline void setPaintSelecting(bool ps){paintSelecting = ps;}
inline bool isRotating(){return rotating;}
inline void setRotating(bool rs){rotating = rs;}
inline bool isPlacingOnSurface(){return placingOnSurface;}
inline void setPlacingOnSurface(bool ps){placingOnSurface = ps;}
inline bool isPlacingVertically(){return placingVertically;}
inline void setPlacingVertically(bool v){this->placingVertically = v;}
inline void setPaintSelectRowStart(vb01::Vector3 st){paintSelectRowStart = st;}
inline void toggleFrameTransformations(bool rot, bool pos, bool pv){
setRotating(rot);
setPlacingOnSurface(pos);
setPlacingVertically(pv);
}
private:
GameObjectFrameController(){}
void paintSelect(vb01::Vector3);
void snapToObj(GameObjectFrame&, std::vector<GameObject*>, float);
void shiftVerticalPlacement();
std::vector<GameObjectFrame> gameObjectFrames;
vb01::Vector3 paintSelectRowStart, placementPos;
float minDepth, maxDepth;
bool paintSelecting = false, rotating = false, placingOnSurface = false, placingVertically = false, minDepthCalculated = false;
};
}
#endif
-24
View File
@@ -1,24 +0,0 @@
#include <solUtil.h>
#include "gameObject.h"
#include "gameObjectListbox.h"
#include "gameObjectFrameController.h"
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
GameObjectListbox::GameObjectListbox(bool ul, Vector3 pos, Vector2 size, vector<string> lines, vector<int> objIds, int maxDisplay, string fontPath) :
Listbox(pos, size, lines, maxDisplay, fontPath),
unitListbox(ul),
gameObjIds(objIds) {}
void GameObjectListbox::onClose(){
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
GameObject::Type type = (unitListbox ? GameObject::Type::UNIT : GameObject::Type::RESOURCE_DEPOSIT);
ufCtr->addGameObjectFrame(GameObjectFrame(gameObjIds[selectedOption], type, nullptr));
ufCtr->setPlacingOnSurface(true);
}
}
-17
View File
@@ -1,17 +0,0 @@
#ifndef UNIT_LISTBOX_H
#define UNIT_LISTBOX_H
#include <listbox.h>
namespace battleship{
class GameObjectListbox : public vb01Gui::Listbox{
public:
GameObjectListbox(bool, vb01::Vector3, vb01::Vector2, std::vector<std::string>, std::vector<int>, int, std::string);
void onClose();
private:
bool unitListbox;
std::vector<int> gameObjIds;
};
}
#endif
-23
View File
@@ -1,23 +0,0 @@
#include "garrisonable.h"
#include "unit.h"
#include <node.h>
namespace battleship{
using namespace vb01;
void Garrisonable::update(){
}
void Garrisonable::ejectVehicle(int id){
}
void Garrisonable::prepareGarrisonSlots(){
for(int i = 0; i < capacity; i++){
Vector2 size = 10 * Vector2::VEC_IJ;
Vector2 pos = Vector2(0, 10 * (i));
garrisonSlotBackgrounds.push_back(Unit::createBar(pos, size, Vector4(0, 0, 0, 1)));
garrisonSlotForegrounds.push_back(Unit::createBar(pos, size, Vector4(0, 1, 0, 1)));
}
}
}
-30
View File
@@ -1,30 +0,0 @@
#ifndef GARRISONABLE_H
#define GARRISONABLE_H
#include <vector>
#include "unit.h"
namespace vb01{
class Node;
}
namespace battleship{
class Vehicle;
class Garrisonable{
public:
Garrisonable(){}
~Garrisonable(){}
void update();
void ejectVehicle(int);
protected:
int capacity;
std::vector<Vehicle*> garrisonedVehicles;
std::vector<vb01::Node*> garrisonSlotForegrounds, garrisonSlotBackgrounds;
void prepareGarrisonSlots();
};
}
#endif
-119
View File
@@ -1,119 +0,0 @@
#include <sstream>
#include <algorithm>
#include <vector.h>
#include <util.h>
#include "util.h"
#include "defConfigs.h"
#include "gameManager.h"
#include "concreteGuiManager.h"
#include "guiAppState.h"
using namespace gameBase;
using namespace vb01;
using namespace vb01Gui;
using namespace std;
namespace battleship{
using namespace configData;
GuiAppState::GuiAppState() : AbstractAppState(
AppStateType::GUI_STATE,
configData::calcSumBinds(AppStateType::GUI_STATE, true),
configData::calcSumBinds(AppStateType::GUI_STATE, false),
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]){
}
GuiAppState::~GuiAppState() {}
void GuiAppState::update() {
ConcreteGuiManager::getSingleton()->update();
}
void GuiAppState::onAttached() {
AbstractAppState::onAttached();
}
void GuiAppState::onDettached() {
AbstractAppState::onDettached();
}
void GuiAppState::onAction(int bind, bool isPressed) {
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
switch((Bind)bind){
case Bind::LEFT_CLICK:
leftMousePressed = isPressed;
if(isPressed)
guiManager->updateGui();
break;
case Bind::SCROLLING_UP:{
Listbox *l = getOpenListbox();
if(l) l->scrollUp();
break;
}
case Bind::SCROLLING_DOWN:{
Listbox *l = getOpenListbox();
if(l) l->scrollDown();
break;
}
case Bind::DELETE_CHAR:{
Textbox *t = getOpenTextbox();
if(t)t->setDeleteCharacters(isPressed);
break;
}
}
}
void GuiAppState::onRawKeyPress(int ch){
for(Button *b : ConcreteGuiManager::getSingleton()->getButtons())
if(b->getTrigger() == ch){
b->onClick();
break;
}
}
void GuiAppState::onRawCharPress(u32 codepoint){
Textbox *currentTextbox = getOpenTextbox();
if(currentTextbox)
currentTextbox->type(codepoint);
}
void GuiAppState::onRawMousePress(int trigger){
}
Textbox* GuiAppState::getOpenTextbox() {
vector<Textbox*> textboxes = ConcreteGuiManager::getSingleton()->getTextboxes();
for (int i = 0; i < textboxes.size(); i++)
if (textboxes[i]->isEnabled())
return textboxes[i];
return nullptr;
}
Listbox* GuiAppState::getOpenListbox() {
vector<Listbox*> listboxes = ConcreteGuiManager::getSingleton()->getListboxes();
for (int i = 0; i < listboxes.size(); i++)
if (listboxes[i]->isOpen())
return listboxes[i];
return nullptr;
}
void GuiAppState::onAnalog(int bind, float strength) {}
void GuiAppState::onRawMouseWheelScroll(bool up){
Listbox *openListbox = getOpenListbox();
if(!openListbox) return;
if(up) openListbox->scrollUp();
else openListbox->scrollDown();
}
}
-42
View File
@@ -1,42 +0,0 @@
#pragma once
#ifndef GUI_APP_STATE_H
#define GUI_APP_STATE_H
#include <button.h>
#include <listbox.h>
#include <checkbox.h>
#include <textbox.h>
#include <slider.h>
#include <vector>
#include <abstractAppState.h>
#include "binds.h"
#include "tooltip.h"
namespace battleship{
class GuiAppState : public gameBase::AbstractAppState {
public:
GuiAppState();
~GuiAppState();
void onAttached();
void onDettached();
void update();
inline bool isLeftMousePressed(){return leftMousePressed;}
private:
virtual void onAction(int, bool);
virtual void onAnalog(int, float);
virtual void onRawKeyPress(int);
virtual void onRawCharPress(vb01::u32);
virtual void onRawMousePress(int);
virtual void onRawMouseWheelScroll(bool);
vb01Gui::Textbox* getOpenTextbox();
vb01Gui::Listbox* getOpenListbox();
bool leftMousePressed = false, backspacePressed = false;
protected:
};
}
#endif
-27
View File
@@ -1,27 +0,0 @@
#include "iceSheet.h"
#include "player.h"
#include "game.h"
namespace battleship{
using namespace vb01;
using namespace std;
IceSheet::IceSheet(Player *player, int id, Vector3 pos, Quaternion rot, int bldSt) : Structure(player, id, pos, rot, bldSt, Unit::State::STAND_GROUND){}
void IceSheet::update(){
Structure::update();
if(buildStatus < 100)
model->getChild(0)->setScale(.01 * buildStatus * Vector3::VEC_IJK);
for(Player *pl : Game::getSingleton()->getPlayers(true)){
vector<Unit*> icebreakers = pl->getUnitsByClass(UnitClass::ICEBREAKER);
for(Unit *icebreaker : icebreakers)
if(icebreaker->pointWithinObj(pos)){
player->removeUnit(this);
return;
}
}
}
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef ICE_SHEET_H
#define ICE_SHEET_H
#include "structure.h"
namespace battleship{
class IceSheet : public Structure{
public:
IceSheet(Player*, int, vb01::Vector3, vb01::Quaternion, int);
void update();
private:
};
}
#endif
-103
View File
@@ -1,103 +0,0 @@
#include <algorithm>
#include <button.h>
#include <util.h>
#include <root.h>
#include <camera.h>
#include <assetManager.h>
#include <stateManager.h>
#include "defConfigs.h"
#include "inGameAppState.h"
#include "game.h"
#include "console.h"
#include "gameObjectFrameController.h"
#include "concreteGuiManager.h"
#include "vessel.h"
#include <solUtil.h>
using namespace vb01;
using namespace vb01Gui;
using namespace std;
namespace battleship{
using namespace configData;
using namespace gameBase;
InGameAppState::ResumeButton::ResumeButton(Vector3 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
void InGameAppState::ResumeButton::onClick() {
Game::getSingleton()->togglePause();
}
InGameAppState::ConsoleButton::ConsoleButton(Vector3 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { }
void InGameAppState::ConsoleButton::onClick() {
ConcreteGuiManager::getSingleton()->readLuaScreenScript("console.lua");
}
InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", 257, true) {
textbox = t;
listbox = l;
}
void InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::onClick() {
Console::execute(wstringToString(textbox->getText()));
}
InGameAppState::InGameAppState(std::string mn) : AbstractAppState(
AppStateType::IN_GAME_STATE,
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
configData::calcSumBinds(AppStateType::IN_GAME_STATE, false),
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
),
mapName(mn),
playerId(0){}
void InGameAppState::onAttached() {
AbstractAppState::onAttached();
Map *map = Map::getSingleton();
map->load(mapName);
map->loadPlayersGameObjects();
Camera *cam = Root::getSingleton()->getCamera();
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
GameManager *gm = GameManager::getSingleton();
StateManager *stateManager = gm->getStateManager();
GuiAppState *guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE));
activeState = new ActiveGameState(guiState, playerId);
stateManager->attachAppState(activeState);
Game::getSingleton()->initLuaPlayers();
//Map::Minimap::getSingleton()->updateImage();
}
void InGameAppState::onDettached() {
StateManager *sm = GameManager::getSingleton()->getStateManager();
ActiveGameState *activeState = (ActiveGameState*)sm->getAppStateByType(int(AppStateType::ACTIVE_STATE));
sm->dettachAppState(activeState);
delete activeState;
}
void InGameAppState::update() {
Game::getSingleton()->update();
Map::getSingleton()->update();
}
void InGameAppState::onAction(int bind, bool isPressed) {
switch((Bind)bind){
case Bind::TOGGLE_MAIN_MENU:
if(isPressed && !(GameObjectFrameController::getSingleton()->isPlacingOnSurface() || activeState->isForceCursorState()))
Game::getSingleton()->togglePause();
break;
}
}
void InGameAppState::onAnalog(int bind, float str) {}
}
-60
View File
@@ -1,60 +0,0 @@
#pragma once
#ifndef IN_GAME_APP_STATE_H
#define IN_GAME_APP_STATE_H
#include "gameManager.h"
#include "player.h"
#include "map.h"
#include "activeGameState.h"
#include "guiAppState.h"
#include "exitButton.h"
#include "optionsButton.h"
#include <vector>
//TODO refactor dependence on ActiveGameState
namespace battleship{
class InGameAppState : public gameBase::AbstractAppState {
public:
class ResumeButton : public vb01Gui::Button {
public:
ResumeButton(vb01::Vector3, vb01::Vector2);
void onClick();
private:
};
class ConsoleButton : public vb01Gui::Button {
public:
class ConsoleCommandEntryButton : public Button {
public:
ConsoleCommandEntryButton(vb01Gui::Textbox*, vb01Gui::Listbox*, vb01::Vector3, vb01::Vector2, std::string);
void onClick();
private:
vb01Gui::Textbox *textbox;
vb01Gui::Listbox *listbox;
};
ConsoleButton(vb01::Vector3, vb01::Vector2);
void onClick();
private:
};
InGameAppState(std::string);
~InGameAppState(){}
void onAttached();
void onDettached();
void update();
void onAction(int, bool);
void onAnalog(int, float);
std::vector<Unit*> getSelectedUnits(Player*);
inline ActiveGameState* getActiveState(){return activeState;}
private:
bool isMainMenuActive = false;
std::vector<std::string> modelPaths;
int playerId;
std::string mapName = "";
ActiveGameState* activeState;
};
}
#endif
-37
View File
@@ -1,37 +0,0 @@
#include "landTextureListbox.h"
#include "mapEditorAppState.h"
#include "gameManager.h"
#include <material.h>
#include <texture.h>
#include <node.h>
#include <mesh.h>
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
LandTextureListbox::LandTextureListbox(Vector3 pos, Vector2 size, vector<string> lines, int maxDisplay, std::string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath){}
void LandTextureListbox::onClose(){
StateManager *sm = GameManager::getSingleton()->getStateManager();
MapEditorAppState::MapEditor *mapEditor = ((MapEditorAppState*)sm->getAppStateByType((int)AppStateType::MAP_EDITOR))->getMapEditor();
Map *map = Map::getSingleton();
Material *mat = map->getNodeParent()->getChild(0)->getMesh(0)->getMaterial();
Material::BoolUniform *texturingUniform = (Material::BoolUniform*)mat->getUniform("texturingEnabled");
Texture *landTex = mapEditor->getLandmassTexture(selectedOption);
string texUni = "textures[0]";
if(!texturingUniform->value){
texturingUniform->value = true;
mat->addTexUniform(texUni, landTex, false);
}
else
mat->setTexUniform(texUni, landTex, false);
}
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef LAND_TEXTURE_LISTBOX_H
#define LAND_TEXTURE_LISTBOX_H
#include <listbox.h>
namespace battleship{
class LandTextureListbox : public vb01Gui::Listbox{
public:
LandTextureListbox(vb01::Vector3, vb01::Vector2, std::vector<std::string>, int, std::string);
void onClose();
private:
};
}
#endif
-28
View File
@@ -1,28 +0,0 @@
#include "loadMapButton.h"
#include "concreteGuiManager.h"
#include "gameManager.h"
#include "mapEditorAppState.h"
#include "loadingAppState.h"
#include <stateManager.h>
namespace battleship{
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace gameBase;
LoadMapButton::OkButton::OkButton(vb01::Vector3 pos, vb01::Vector2 size, vb01Gui::Listbox *listbox) : Button(pos, size, "Ok", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){ this->listbox = listbox; }
void LoadMapButton::OkButton::onClick(){
StateManager *sm = GameManager::getSingleton()->getStateManager();
string name = wstringToString(listbox->getContents()[listbox->getSelectedOption()]);
handleLoadingGui(new LoadingAppState(new MapEditorAppState(name, Vector2::VEC_ZERO, false), "mapEditor.lua"));
}
LoadMapButton::LoadMapButton(Vector3 pos, Vector2 size) : Button(pos, size, "Load map", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf"){}
void LoadMapButton::onClick(){
ConcreteGuiManager::getSingleton()->readLuaScreenScript("loadMap.lua");
}
}
-27
View File
@@ -1,27 +0,0 @@
#ifndef LOAD_MAP_BUTTON_H
#define LOAD_MAP_BUTTON_H
#include <button.h>
namespace vb01Gui{
class Listbox;
}
namespace battleship{
class LoadMapButton : public vb01Gui::Button{
public:
class OkButton : public vb01Gui::Button{
public:
OkButton(vb01::Vector3, vb01::Vector2, vb01Gui::Listbox*);
void onClick();
private:
vb01Gui::Listbox *listbox;
};
LoadMapButton(vb01::Vector3, vb01::Vector2);
void onClick();
private:
};
}
#endif
-51
View File
@@ -1,51 +0,0 @@
#include "loadingAppState.h"
#include "concreteGuiManager.h"
#include "gameManager.h"
#include "defConfigs.h"
#include <quad.h>
#include <node.h>
#include <vector.h>
#include <assetManager.h>
#include <stateManager.h>
namespace battleship{
using namespace configData;
using namespace gameBase;
using namespace vb01;
using namespace std;
LoadingAppState::LoadingAppState(AbstractAppState *newSt, string newScr) : AbstractAppState(
AppStateType::LOADING_STATE,
configData::calcSumBinds(AppStateType::LOADING_STATE, true),
configData::calcSumBinds(AppStateType::LOADING_STATE, false),
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
),
newState(newSt),
newScreen(newScr)
{}
void LoadingAppState::onDettached(){
ConcreteGuiManager::getSingleton()->readLuaScreenScript(newScreen);
GameManager::getSingleton()->getStateManager()->attachAppState(newState);
AbstractAppState::onDettached();
}
void LoadingAppState::update(){
Node *loadingBar = ConcreteGuiManager::getSingleton()->getGuiRectangle("_loadingBar");
Quad *quad = (Quad*)loadingBar->getMesh(0);
quad->setSize(Vector3((1 - (float)loadableAssets.size() / initNumAssets) * 200.f, 20, 0));
quad->updateVerts(quad->getMeshBase());
if(getTime() - lastUpdateTime > 5){
AssetManager::getSingleton()->load(loadableAssets[0]);
loadableAssets.erase(loadableAssets.begin());
if(loadableAssets.empty()) GameManager::getSingleton()->getStateManager()->dettachAppState(this);
lastUpdateTime = getTime();
}
}
}

Some files were not shown because too many files have changed in this diff Show More