Passable building
Moderator: Moderators
Passable building
For my C&C recreation i wanted to make a repair depot that units can drive on, despite specifying a yardmap of all y's, the units still colide with the building.
Id already be happy if units can just pass inside it, instead of on it.
How would i go about this?
Id already be happy if units can just pass inside it, instead of on it.
How would i go about this?
Re: Passable building
Code: Select all
bool blocking Default: true
Does the unit block the movement of other units? (Mines, i.e. non-mobile units with the kamikaze tag default to false).
Re: Passable building
Oh overlooked that.
Thanks, tough why doesnt yardmap "y" do the same?
Thanks, tough why doesnt yardmap "y" do the same?
Re: Passable building
It does.
'blocking' is simply a higher-level flag that lets the engine skip yardmap tests (in the case of buildings) entirely.
Units will not collide against a structure with an all-y yardmap, so your building probably isn't recognized as a static object. Paste the unitdef so we can take a look.
'blocking' is simply a higher-level flag that lets the engine skip yardmap tests (in the case of buildings) entirely.
Units will not collide against a structure with an all-y yardmap, so your building probably isn't recognized as a static object. Paste the unitdef so we can take a look.
Re: Passable building
Sorry for the holdup, i got caught up in my stuff again.
Anyway here it is:
The "blocking = false" was added after this thread.
Now i have another slight problem, i want that clicking on the pad will order a unit to move onto it instead of guarding it.
I assume i would have write a widget for this yes?
Also in simbase i noticed there is an 'f' yardmap char, but its not documented what does it do?
Anyway here it is:
Code: Select all
local unitName = "repair_depot"
local unitDef = {
buildPic = "repair_depot.png",
category = "STRUCTURE SMALL NOTAIR NOTSUB",
objectName = "structures/repair_depot.dae",
name = "Repair depot",
tEDClass = "TANK",
unitName = "repair_depot",
script = "depot.lua",
buildTime = 150,
description = "Repairs vehicles",
maxDamage = 750,
radarDistance = 0,
sightDistance = 100,
soundCategory = "TANK",
buildCostMetal = 1500,
footprintX = 8,
footprintZ = 8,
blocking = false,
yardmap = "yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy",
canMove = false,
canStop = false,
leaveTracks = false,
reclaimable = false,
canAttack = 0,
canGuard = 0,
canFight = 0,
canPatrol = 0,
energyMake = -1,
explodeAs = "TANKDEATH",
}
return lowerkeys({ [unitName] = unitDef })
Now i have another slight problem, i want that clicking on the pad will order a unit to move onto it instead of guarding it.
I assume i would have write a widget for this yes?
Also in simbase i noticed there is an 'f' yardmap char, but its not documented what does it do?
Re: Passable building
1) There are afaik at least three types of yardmap characters: y for yard (passable when "on", impassable when "off"), o for obstruction, and i think f is for always passable.
2) You're looking for DefaultCommand and/or CommandFallback callins. It will require a widget as far as i know.
2) You're looking for DefaultCommand and/or CommandFallback callins. It will require a widget as far as i know.
Re: Passable building
Read the wiki:Anarchid wrote:1) There are afaik at least three types of yardmap characters: y for yard (passable when "on", impassable when "off"), o for obstruction, and i think f is for always passable.
2) You're looking for DefaultCommand and/or CommandFallback callins. It will require a widget as far as i know.
http://springrts.com/wiki/Gamedev:UnitDefs#Tag:yardmap
There are 5, +o which is commonly used as obstacle (but all other non-whitespace chars work afaik - certainly 'f' will act as blocking)
y is always open, c is the one that changes on/off for construction, and I was introduced to be off/on for construction.
Re: Passable building
Wiki doesn't mention any "f" yardmap letter. What does "f" mean?
Re: Passable building
https://github.com/spring/spring/blob/9 ... f.cpp#L776
Code: Select all
YardMapStatus ys = YARDMAP_BLOCKED;
switch (c) {
case 'g': ys = YARDMAP_GEO; needGeo = true; break;
case 'y': ys = YARDMAP_OPEN; break;
case 'c': ys = YARDMAP_YARD; break;
case 'i': ys = YARDMAP_YARDINV; break;
//case 'w': { ys = YARDMAP_WALKABLE; } break; //FIXME
case 'w':
case 'x':
case 'f':
case 'o': ys = YARDMAP_BLOCKED; break;
default:
Last edited by knorke on 17 Jun 2014, 18:14, edited 1 time in total.
Re: Passable building
o - 'Obstacle' - Always closed, blocking, all other chars are treated the same way.
Re: Passable building
Right, out of curiosity, what did 'f" used to mean?
Sureley atari didnt likely use multiple letters for the same meaning.
Sureley atari didnt likely use multiple letters for the same meaning.
Re: Passable building
Don't recall what f meant in OTA, but OTA did have additional tags to specify parts of the yardmap which had to be on water, (as g specified parts which had to cover geo - in Spring a single g acts a flag to say the whole unit must be on a geo) iirc there was also some difference between capitalisations.
Re: Passable building
Sry for old bump.
But it turned out that for some reason the bulding cant repair with the yardmap param and strangly blocking is ignored entitrly, im not sure if this is a 98 bug since i cant recall if this was in 96 the same way.
Also here is the new unitdef, since the only one seems non-functional.
But it turned out that for some reason the bulding cant repair with the yardmap param and strangly blocking is ignored entitrly, im not sure if this is a 98 bug since i cant recall if this was in 96 the same way.
Also here is the new unitdef, since the only one seems non-functional.
Code: Select all
local unitName = "repair_depot"
local unitDef = {
name = "Repair depot",
description = "Repairs vehicles",
objectName = "structures/repair_depot.dae",
category = "STRUCTURE SMALL NOTAIR NOTSUB",
maxDamage = 750,
footprintX = 8,
footprintZ = 8,
collisionVolumeType = "box",
collisionVolumeScales = {125, 25, 125},
script = "repair_depot.lua",
sightDistance = 150,
buildPic = "repair_depot.png",
buildTime = 150,
buildCostMetal = 1500,
blocking = false,
canMove = false,
canAttack = false,
canGuard = false,
canFight = false,
canPatrol = false,
builder = true,
canRepair = true,
canBeAssisted = false,
canAssist = false,
workerTime = 1.0,
buildDistance = 45,
repairSpeed = 1.0,
canRestore = false,
canReclaim = false,
showNanoSpray = false,
maxSlope = 20,
--yardmap = "yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy yyyyy yyy", -- BORKS IT!
energyMake = -1,
explodeAs = "building_death",
}
return lowerkeys({ [unitName] = unitDef })
Re: Passable building
If it has a yardmap and is a builder, it is a factory. Factories cannot repair.
I did this with a transport in MCL:
[code]function Repair(passengerID)
local curHP, maxHP = GetUnitHealth(passengerID)
while curHP ~= maxHP do
local newHP = math.min(curHP + maxHP * REPAIR_RATE, maxHP)
SetUnitHealth(passengerID, newHP)
curHP, maxHP = GetUnitHealth(passengerID)
curHP, maxHP = GetUnitHealth(passengerID)
Sleep(1000)
end
repaired = true
if resupplied and restored then -- I'm the last task to finish, move out!
script.TransportDrop(passengerID)
end
end
function Restore(passengerID)
local limbHPs = passengerInfo.limbHPs
if passengerEnv.limbHPControl then -- N.B. currently this runs for all mechs
for limb, maxHP in pairs(limbHPs) do
local curHP = passengerEnv.limbHPControl(limb, 0)
while curHP ~= maxHP do
curHP = passengerEnv.limbHPControl(limb, -maxHP * LIMB_REPAIR_RATE)
Sleep(1000)
end
end
end
restored = true
if repaired and resupplied then -- I'm the last task to finish, move out!
script.TransportDrop(passengerID)
end
end
function Resupply(passengerID)
local ammoTypes = passengerInfo.ammoTypes
if passengerEnv.ChangeAmmo then -- N.B. currently this runs for all mechs regardless of whether they have any ammo using weapons...
while true do
local moreToDo = false
for weaponNum, ammoType in pairs(ammoTypes) do --... but this loop will finish immediatly in that case
local amount = passengerInfo.burstLengths[weaponNum]
local supplied = passengerEnv.ChangeAmmo(ammoType, amount)
--if supplied then Spring.Echo("Deduct " .. amount .. " " .. ammoType) end
moreToDo = moreToDo or supplied
end
if not moreToDo then break end
Sleep(1000)
end
end
resupplied = true
if repaired and restored then -- I'm the last task to finish, move out!
script.TransportDrop(passengerID)
end
end
function script.TransportPickup (passengerID)
passengerDefID = GetUnitDefID(passengerID)
passengerInfo = GG.lusHelper[passengerDefID]
passengerEnv = Spring.UnitScript.GetScriptEnv(passengerID)
-- TODO: pickup animation
Spring.UnitScript.AttachUnit(base, passengerID)
StartThread(Repair, passengerID)
StartThread(Resupply, passengerID)
StartThread(Restore, passengerID)
end
function script.TransportDrop (passengerID, x, y, z)
local isTransporting = Spring.GetUnitIsTransporting(unitID)
if isTransporting and #isTransporting > 0 then
Spring.SetUnitBlocking(unitID, false, false) -- make it easy to get out
Spring.UnitScript.DropUnit(passengerID)
Spring.SetUnitMoveGoal(passengerID, UNLOAD_X, 0, UNLOAD_Z, 50) -- bug out over here
-- reset states
repaired = false
resupplied = false
restored = false
-- wait for current passenger to get out
Sleep(1000)
Spring.SetUnitBlocking(unitID, true, true)
end
end
[/code]
Sorry for giant code post, SourceForge is down otherwise I'd just link the relevant file.
I did this with a transport in MCL:
[code]function Repair(passengerID)
local curHP, maxHP = GetUnitHealth(passengerID)
while curHP ~= maxHP do
local newHP = math.min(curHP + maxHP * REPAIR_RATE, maxHP)
SetUnitHealth(passengerID, newHP)
curHP, maxHP = GetUnitHealth(passengerID)
curHP, maxHP = GetUnitHealth(passengerID)
Sleep(1000)
end
repaired = true
if resupplied and restored then -- I'm the last task to finish, move out!
script.TransportDrop(passengerID)
end
end
function Restore(passengerID)
local limbHPs = passengerInfo.limbHPs
if passengerEnv.limbHPControl then -- N.B. currently this runs for all mechs
for limb, maxHP in pairs(limbHPs) do
local curHP = passengerEnv.limbHPControl(limb, 0)
while curHP ~= maxHP do
curHP = passengerEnv.limbHPControl(limb, -maxHP * LIMB_REPAIR_RATE)
Sleep(1000)
end
end
end
restored = true
if repaired and resupplied then -- I'm the last task to finish, move out!
script.TransportDrop(passengerID)
end
end
function Resupply(passengerID)
local ammoTypes = passengerInfo.ammoTypes
if passengerEnv.ChangeAmmo then -- N.B. currently this runs for all mechs regardless of whether they have any ammo using weapons...
while true do
local moreToDo = false
for weaponNum, ammoType in pairs(ammoTypes) do --... but this loop will finish immediatly in that case
local amount = passengerInfo.burstLengths[weaponNum]
local supplied = passengerEnv.ChangeAmmo(ammoType, amount)
--if supplied then Spring.Echo("Deduct " .. amount .. " " .. ammoType) end
moreToDo = moreToDo or supplied
end
if not moreToDo then break end
Sleep(1000)
end
end
resupplied = true
if repaired and restored then -- I'm the last task to finish, move out!
script.TransportDrop(passengerID)
end
end
function script.TransportPickup (passengerID)
passengerDefID = GetUnitDefID(passengerID)
passengerInfo = GG.lusHelper[passengerDefID]
passengerEnv = Spring.UnitScript.GetScriptEnv(passengerID)
-- TODO: pickup animation
Spring.UnitScript.AttachUnit(base, passengerID)
StartThread(Repair, passengerID)
StartThread(Resupply, passengerID)
StartThread(Restore, passengerID)
end
function script.TransportDrop (passengerID, x, y, z)
local isTransporting = Spring.GetUnitIsTransporting(unitID)
if isTransporting and #isTransporting > 0 then
Spring.SetUnitBlocking(unitID, false, false) -- make it easy to get out
Spring.UnitScript.DropUnit(passengerID)
Spring.SetUnitMoveGoal(passengerID, UNLOAD_X, 0, UNLOAD_Z, 50) -- bug out over here
-- reset states
repaired = false
resupplied = false
restored = false
-- wait for current passenger to get out
Sleep(1000)
Spring.SetUnitBlocking(unitID, true, true)
end
end
[/code]
Sorry for giant code post, SourceForge is down otherwise I'd just link the relevant file.