Passable building

Passable building

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Passable building

Post by code_man »

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?
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Passable building

Post by Beherith »

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). 
From: http://springrts.com/wiki/Gamedev:UnitD ... _Placement
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Passable building

Post by code_man »

Oh overlooked that.
Thanks, tough why doesnt yardmap "y" do the same?
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Passable building

Post by Kloot »

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.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Passable building

Post by code_man »

Sorry for the holdup, i got caught up in my stuff again.

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 })
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?
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Passable building

Post by Anarchid »

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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Passable building

Post by FLOZi »

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.
Read the wiki:

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.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Passable building

Post by Jools »

Wiki doesn't mention any "f" yardmap letter. What does "f" mean?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Passable building

Post by knorke »

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.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Passable building

Post by jK »

o - 'Obstacle' - Always closed, blocking, all other chars are treated the same way.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Passable building

Post by code_man »

Right, out of curiosity, what did 'f" used to mean?
Sureley atari didnt likely use multiple letters for the same meaning.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Passable building

Post by FLOZi »

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.
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Passable building

Post by code_man »

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.

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 })
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Passable building

Post by FLOZi »

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.
Post Reply

Return to “Game Development”