Factory not showing icons for vehicle production - Page 2

Factory not showing icons for vehicle production

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

nightovizard
Posts: 24
Joined: 15 May 2014, 23:27

Re: Factory not showing icons for vehicle production

Post by nightovizard »

FLOZi wrote:Crashes due to

Code: Select all

currSlot=currSlot+1
using a variable which isn't initialised.. looks like it isn't actually used so you could just remove that line.
thanks a lot it works perfectly now.

I have been trying t make a mobile factory, but for some reason instead of being a factory its a builder unit, how do I change it to a mobile factory?

unitdef:

Code: Select all

local unitName = "carrier"

local unitDef = {
name = "carrier",
Description = "Aircraft carrier",
objectName = "carrier.s3o",
script = "carrier.lua",
BuildPic = "placeholder.png",
--cost
buildCostMetal = 100,
buildCostEnergy = 0,
buildTime = 5,
--Health
maxDamage = 15000,
idleAutoHeal = 0,
--Movement
Acceleration = 0.2,
BrakeRate = 0.3,
FootprintX = 10,
FootprintZ = 10,
MaxSlope = 15,
MaxVelocity = 4,
MaxWaterDepth = 20,
MovementClass = "Ship10x10",
TurnRate = 50,
cantBeTransported=true,
	ActivateWhenBuilt = true,

sightDistance = 1000,

TEDClass = "PLANT",
Builder = true,
CanAttack = true,
CanGuard = true,
CanMove = true,
CanPatrol = true,
CanStop = true,
LeaveTracks = false, 
minWaterDepth = 10.0,
subMarine = false,
    Reclaimable = false,
	ShowNanoSpray = true,
	CanBeAssisted = false,	
	workerTime = 1,
	buildoptions = 
	{
	"gunship",
	"fighter",
	"bomber",
	},

Category = [[SEA]],
mass                = 300,

weapons = {
[1]={name  = "minigun",
	onlyTargetCategory = [[AIR]],
	},
[2]={name  = "minigun",
	onlyTargetCategory = [[AIR]],
	},
},
}

return lowerkeys({ [unitName] = unitDef })
script

Code: Select all

--Define the pieces
local body = piece "body"
local turret1 = piece "turret1"
local gun1 = piece "gun1"
local flare1 = piece "flare1"
local turret2 = piece "turret1"
local gun2 = piece "gun2"
local flare2 = piece "flare2"
local buildspot = piece "buildspot"
local nano1 = piece "nano1"
local nano2 = piece "nano2"

function script.Create()
	
end

----driving animation
function script.StartMoving()

end

function script.StopMoving()

end

----aimining & fire weapon
function script.AimFromWeapon1() 
	return turret1
end

function script.QueryWeapon1() 
	return flare1
end

function script.AimWeapon1( heading, pitch )	
	--aiming animation: instantly turn the gun towards the enemy
	Turn(turret1, y_axis, heading)
	Turn(gun1, x_axis, -pitch)
	return true
end

function script.FireWeapon1()	
	
end

----aimining & fire weapon II
function script.AimFromWeapon2() 
	return turret2 
end

function script.QueryWeapon2() 
	return flare2
end

function script.AimWeapon2( heading, pitch )	
	--aiming animation: instantly turn the gun towards the enemy
	Turn(turret2, y_axis, heading)
	Turn(gun2, x_axis, -pitch)
	return true
end

function script.FireWeapon2()	
	
end


--------BUILDING---------
function script.QueryBuildInfo() 
	return buildspot	--the unit will be constructed at the position of this piece
end

function script.QueryNanoPiece()
	--create a new nano particle at one of the two "nano towers"
	local dice = math.random (1,2)
	if (dice == 1) then 
		return nano1
	else
		return nano2
	end
end

function script.Activate()
	SetUnitValue(COB.YARD_OPEN, 1)
	SetUnitValue(COB.INBUILDSTANCE, 1)
	SetUnitValue(COB.BUGGER_OFF, 1)
	return 1
end

function script.Deactivate()
	SetUnitValue(COB.YARD_OPEN, 0)
	SetUnitValue(COB.INBUILDSTANCE, 0)
	SetUnitValue(COB.BUGGER_OFF, 0)
	return 0
end


function script.StartBuilding()	
	--animation
end

function script.StopBuilding()
	--animation
end
---------------------

---death animation
function script.Killed(recentDamage, maxHealth)
	Explode (body, SFX.SHATTER) 
end
movedef it uses:

Code: Select all

		{
	name = "Ship10x10",
	footprintX = 10,
	maxWaterDepth = 9999,
	minWaterDepth = 10,
	maxSlope = 20,
	crushStrength = 25,
	floater = true,
	waterline = 10,
	},
I already have a submarine and amphibious vehicle working. So now I only have to figure out how to make the mobile factory, the shield generator and the artiilery (shells, missiles/nukes/anti-nukes... for example giving a nuclear submarine the ability to produce and use nuclear missiles). after that everything will get easier as I probably won't have this ''newbie'' problems anymore xD.

The only thing I really don't know if I'm going to be able to do, is a cannon, that loads units, and launches them anywhere in the map. I suppose that can be done with lua?
mostly because I had this concept for the game and I would like to add all this features:
http://www.moddb.com/members/nightoviza ... t#imagebox
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Factory not showing icons for vehicle production

Post by FLOZi »

It is a limitation of Spring that a unit cannot (truly) be a factory and a mobile unit simultaneously, however there are workarounds. Perhaps the best person to ask is zwzsg if memory serves me correctly.
msafwan
Posts: 38
Joined: 16 Dec 2010, 14:44

Re: Factory not showing icons for vehicle production

Post by msafwan »

I have been trying t make a mobile factory, but for some reason instead of being a factory its a builder unit, how do I change it to a mobile factory?
Hello nightovizard,
Spring doesn't have mobile factory, but modder have tried a lot of hax to make mobile factory.

The following is my method,
First, you must intercept build command issued by player, this is done by Widget or probably in Gadget Unsynced (did not test the later), like this:

Code: Select all

function widget:CommandNotify(cmdID, cmdParams, cmdOptions)
	if haveRelevantUnit == 0 or cmdID >= 0 or (cmdParams[1] and cmdParams[2] and cmdParams[3]) then --can't handle other command.
		return false
	end
	local selectedUnits = Spring.GetSelectedUnits()
	for i=1, #selectedUnits do
		if constructionShipDef[Spring.GetUnitDefID(selectedUnits[i])] then
			BuildThisUnit(-1*cmdID)
			return true
		end
	end
	return false
end
*I copied pasted from my WIP Widget, some variable could be undefined in that code snippet, but the important thing is the concept*

The "BuildThisUnit()" function will send LUA message to Gadget which will spawn the unit, here's the detail:

Code: Select all

function widget:GameFrame()
	if haveRelevantUnit>0 then
		rmbG = rmbG2
		_,_, _, _, rmbG2 = Spring.GetMouseState()
	end
end

function BuildThisUnit(unitDefID)
	local alt, ctrl, meta, shift = Spring.GetModKeyState()
	local _,_, lmb, mmb, rmb = Spring.GetMouseState()
	local selectedUnits = Spring.GetSelectedUnits()
	if #selectedUnits == 0 then
		return
	end
	local selectedUnitsString = '{'
	for i=1,#selectedUnits do
		local mobile_factory = constructionShipDef[Spring.GetUnitDefID(selectedUnits[i])]
		if mobile_factory and mobile_factory.buildOptions[unitDefID] then
			selectedUnitsString = selectedUnitsString .. '[' .. i .. '] =' .. selectedUnits[i] .. ',' 
		end
	end
	selectedUnitsString = selectedUnitsString .. '}' --eg: {unitID1,unitID2,unitID3,}
	local options = '{'
	local count = 1
	if alt then options = options .. '[' .. count .. '] = \"alt\",'; count= count + 1 end
	if ctrl then options = options .. '[' .. count .. '] = \"ctrl\",'; count= count + 1 end
	if meta then options = options .. '[' .. count .. '] = \"meta\",'; count= count + 1 end
	if shift then options = options .. '[' .. count .. '] = \"shift\",'; count= count + 1 end
	if rmb or rmbG then options = options .. '[' .. count .. '] = \"right\",' end
	options = options .. '}'  --eg: {'shift','meta','ctrl',}
	
	Spring.SendLuaRulesMsg('mbfc' .. '{[1] =' .. selectedUnitsString .. ',[2] =' .. unitDefID .. ',[3] =' .. options .. ',}' )
	Spring.Echo('{'.. selectedUnitsString .. ',' .. unitDefID .. ',' .. options .. ',' .. '}' )
end
Then, the gadget must read this message, decipher it, and perform any synced action like spawning unit, or consume resources (to emulate mobile factory), like this: (NOTE this is in Synced portion of gadget)

Code: Select all

	function gadget:RecvLuaMsg(msg, playerID)
		if msg:sub(1,4) == 'mbfc' then
			local tableString = msg:sub(5)
			local chunk, err = loadstring("return "..tableString) --This code is from cawidgets.lua
			local cmdTable = chunk and chunk() or {}
			if #cmdTable == 3 and
			type(cmdTable[1]) == 'table' and
			type(cmdTable[2]) == 'number' and
			type(cmdTable[3]) == 'table' then
				local unitDefID = cmdTable[2]
				if UnitDefs[unitDefID] then --valid unitDefID
					local shift, meta, ctrl, alt, right
					local options = cmdTable[3]
					for i=1, #options do
						local option = options[i]
						if option == "shift" then
							shift = true
						elseif option == "alt" then
							alt = true
						elseif option == "ctrl" then
							ctrl = true
						elseif option == "right" then
							right = true
						elseif option == "meta" then
							meta = true
						end
					end
					local playerTeamID = select(4,Spring.GetPlayerInfo(playerID))
					local selectedUnits = cmdTable[1]
					for i=1, #selectedUnits do
						local unitID = selectedUnits[i]
						if Spring.GetUnitTeam(unitID) ~= playerTeamID then --is giving order to enemy unit?
							break;
						end
						local consShipData = constructionShipData[unitID]
						if consShipData and consShipData.typedata.buildOptions[unitDefID] then --buildable unitDefID
							if right then
								if shift then
									RemoveTargettedUnitDefIDFromQueue(unitDefID,consShipData,unitID,5)
								elseif ctrl then
									RemoveTargettedUnitDefIDFromQueue(unitDefID,consShipData,unitID,20)
								else
									RemoveTargettedUnitDefIDFromQueue(unitDefID,consShipData,unitID,1)
								end
							else
								local consShipQueue = consShipData.status.buildQueue
								if shift then
									local tableIndex = #consShipQueue
									for i=1,5 do
										consShipQueue[tableIndex+i] = unitDefID
									end
								elseif ctrl then
									local tableIndex = #consShipQueue
									for i=1,20 do
										consShipQueue[tableIndex+i] = unitDefID
									end
								else
									consShipQueue[#consShipQueue+1] = unitDefID
								end
							end
						end
					end
				end
			end
		end
	end

	function RemoveTargettedUnitDefIDFromQueue(unitDefID, consShipData,consShipID, count)
		Spring.Echo("REMOVING QUEUE " .. count)
		local consShipQueue = consShipData.status.buildQueue
		local isBuildingSame = (consShipData.status.isBuildingA[2] == unitDefID)
		local isBuildingIndex
		local countRemove = count
		local countTableIndex = 1
		local toRemoveIndex = {nil}
		--Remove all targetted UnitDefID excluding currently built unit:
		for j=1,#consShipQueue do
			if consShipQueue[j] ==unitDefID then
				if not isBuildingIndex and isBuildingSame then
					isBuildingIndex = j
					Spring.Echo("Current build to be cancelled")
				else
					toRemoveIndex[countTableIndex] = j
					countTableIndex = countTableIndex + 1
					countRemove = countRemove - 1
					if countRemove == 0 then
						break;
					end
				end
			end
		end
		for j=#toRemoveIndex, 1,-1 do  --remove from topmost index first
			table.remove(consShipQueue,toRemoveIndex[j])
		end
		--If not reached targetted quota, remove currently built unit too:
		if countRemove>0 and isBuildingIndex then
			table.remove(consShipQueue,isBuildingIndex)
			if constructionShipData[consShipID].status.isBuildingA[1] then
				CancelNanoframeConstruction(constructionShipData[consShipID].status.isBuildingA[1],consShipID)
			end
		end
	end
Note, the code added unitDefID to a table called "consShipQueue", this can be a global table (but in my case I put it in some other table to index it by UnitID), this table can be read later in "function gadget:GameFrame()" which loop every frame. Here you can do anything, like spawning unit or consume resource, like this:

Code: Select all

	function gadget:GameFrame(n)
....<some other messy stuff>.....
			for unitID,buildInfo in pairs(consShipStatus.unitsOnPadInfo) do
				local health,maxHealth,_,_,buildProgress = Spring.GetUnitHealth(unitID)
				if buildProgress and  buildProgress <1 then
					consShipStatus.isBuildingA[1] = unitID
					consShipStatus.isBuildingA[2] = buildInfo.unitDefID
					Spring.SetUnitRulesParam(consShipID,"currentlyBuilding",unitID) --hint widgets
					if isWait then
						break
					end
					local metalCost = consShipTypedata.buildOptions[buildInfo.unitDefID].metalCost
					local maxMetalPerFrame = (consShipTypedata.buildPower/30)
					local maxEnergyPerFrame = maxMetalPerFrame
					local buildProgressPerFrame = maxMetalPerFrame/metalCost
					local remainingBuildProgress = 1-buildProgress
					if remainingBuildProgress > buildProgressPerFrame then
							consShipStatus.constructing = true
						local healthPerFrame = buildProgressPerFrame*maxHealth
							Spring.SetUnitHealth(unitID,{ health = health+healthPerFrame, build = buildProgress+buildProgressPerFrame })
							Spring.UseUnitResource(consShipID, 'energy',  maxEnergyPerFrame)-- + energyMake - energyUse)
							Spring.UseUnitResource(consShipID, 'metal',  maxMetalPerFrame)-- + metalMake - metalUse)
							consShipStatus.unitsOnPadInfo[unitID].usedEnergy = maxEnergyPerFrame + buildInfo.usedEnergy
							consShipStatus.unitsOnPadInfo[unitID].usedMetal = maxMetalPerFrame + buildInfo.usedMetal
					else --FINISH BUILD:
						local remainingMetalToSpend = remainingBuildProgress*metalCost
						local remainingEnergyToSpend = remainingMetalToSpend
						local remainingHealthToAdd =  remainingBuildProgress*maxHealth
							Spring.SetUnitHealth(unitID,{ health = health+remainingHealthToAdd, build = 1.0 })
							Spring.UseUnitResource(consShipID, 'energy', remainingEnergyToSpend)-- + energyMake - energyUse)
							Spring.UseUnitResource(consShipID, 'metal', remainingMetalToSpend)-- + metalMake - metalUse)
							consShipStatus.unitsOnPadInfo[unitID].usedEnergy = remainingEnergyToSpend + buildInfo.usedEnergy
							consShipStatus.unitsOnPadInfo[unitID].usedMetal = remainingMetalToSpend + buildInfo.usedMetal
							GG.StopMiscPriorityResourcing(consShipID,teamID) --is using unit_priority.lua gadget to handle priority.
							consShipStatus.constructing = false
							consShipStatus.isBuildingA[1] = nil
							consShipStatus.isBuildingA[2] = nil
							local isRepeat = Spring.GetUnitStates(consShipID)["repeat"]
							if isRepeat then
								consShipStatus.buildQueue[#consShipStatus.buildQueue+1] = consShipStatus.buildQueue[1]
							end
							table.remove(consShipStatus.buildQueue,1)
							Spring.SetUnitRulesParam(consShipID,"currentlyBuilding",-1) --hint widgets
							if UnitDefs[buildInfo.unitDefID].canFly then --if unit can fly, then undock immediately..
								DetachUnit(unitID, consShipID)
								Spring.GiveOrderToUnit(unitID, CMD.IDLEMODE, {0}, {}) --fly away
							end
					end
					break; --only build 1 unit at a time
				end
			end
	end
There are other misc stuff to make mobile factory not look silly, like constantly repositioning nanoframe to appear on the unit and add command to allow undocking, that make a lot more codes. Currently my gadget is WIP, its not yet added to ZK mod (which I intended for)
-----

In summary, my method were:
a) intercept build command using widget
b) send build command to gadget using LUArule message
c) read LUArule message and spawn unit

EDIT:
Knorker method is to attach factory to a unit, this could work too!
Instead of spawning unit, just give build order to the factory attached to a mobile unit.
nightovizard
Posts: 24
Joined: 15 May 2014, 23:27

Re: Factory not showing icons for vehicle production

Post by nightovizard »

oh, is it possible to attach units to other units? how can that be done? (But health acts like a single entity, or are they separated in 2 different entities?)

I'm going to try with the widgets for now, I hope I can get it to work.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Factory not showing icons for vehicle production

Post by FLOZi »

Knorke's method is, imo, vastly superior.

Attaching units is done via the transport tags and AttachUnit that you have already familiarised yourself with :wink:
nightovizard
Posts: 24
Joined: 15 May 2014, 23:27

Re: Factory not showing icons for vehicle production

Post by nightovizard »

FLOZi wrote:Knorke's method is, imo, vastly superior.

Attaching units is done via the transport tags and AttachUnit that you have already familiarised yourself with :wink:
oh I understand now!, I always thought I only could transport vehicle and units that move, never considered structures. That could be interesting, Imagine being able to move your entire base to another position. Or placing quickly turrets and shield generators that way.

About the cannon that launches units, that's possible? I hope so. Another solution could be using the same method as nukes are made.:
Theres a building that produces drop pods (StarburstLauncher), these drop pods can load units. Then as if it was a nuke you would launch it anywhere in the map, and when it hits ground instead of exploding and doing damage, it would unload the units.

Any good option? I think this could be a nice and fastest way to transport units without using transports that can be taken down by AA easily. This way you could attack from the rearguard too and surround the enemy. You could even load it with builders. Not aircrafts or ships though.

EDIT:

Can't figure out how to make that when I create a carrier, the attached factory gets attached to it to, and cant be unattached.

the other problem I have are sounds, for some reason some sounds can barely be heard, and some others are way too loud.

it's been a while since I last posted the files so here we go again:
Attachments
Projectsupremacy.sdz
take nto consideration that I haven't been able to port all the nuits I have done yet because I have been stuck tying to figure out how to fix all the issues and problems. also there is not any harbor, so you will need the /give command to spawn sea units.
(2.73 MiB) Downloaded 5 times
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Factory not showing icons for vehicle production

Post by zwzsg »

FLOZi wrote:It is a limitation of Spring that a unit cannot (truly) be a factory and a mobile unit simultaneously, however there are workarounds. Perhaps the best person to ask is zwzsg if memory serves me correctly.
It was done by glueing a factory unit to a mobile unit. But it was nine years ago. Spring had no Lua in those time. Yardmap and transport had different limitations, etc...

I'd say mobile factory is somewhat possible, but still rather complicated. Would be best to stick with immobile factories and mobile builders until you get enough experience with Spring.


nightovizard wrote:Theres a building that produces drop pods (StarburstLauncher), these drop pods can load units. Then as if it was a nuke you would launch it anywhere in the map, and when it hits ground instead of exploding and doing damage, it would unload the units.
Creating a unit where the pod hit the ground would be easier and less buggy.

With a little Lua you can even read and store characteristics of a unit (like health, xp, etc..) so as to recreate a faithful copy of a unit despawned at the launcher.
nightovizard
Posts: 24
Joined: 15 May 2014, 23:27

Re: Factory not showing icons for vehicle production

Post by nightovizard »

Something I was considering is if there is any way to counter the missiles form missileLauncher type of weapon? I know that can be done with nukes and anti-nukes, but those are other types of weapons.

Basically what I wanted is the AA minigun weapon to be able both to take down aircrafts, and other types of missiles:
https://www.youtube.com/watch?v=NWfNLsBWPSI
https://www.youtube.com/watch?v=QSSgvLOCFU0
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Factory not showing icons for vehicle production

Post by FLOZi »

All weapons are now interceptable. For example, MCL has both cannon and laser based anti-missile systems which target long range missiles.

See http://springrts.com/wiki/Gamedev:Weapo ... targetable and the next 3 tags below it
nightovizard
Posts: 24
Joined: 15 May 2014, 23:27

Re: Factory not showing icons for vehicle production

Post by nightovizard »

FLOZi wrote:All weapons are now interceptable. For example, MCL has both cannon and laser based anti-missile systems which target long range missiles.

See http://springrts.com/wiki/Gamedev:Weapo ... targetable and the next 3 tags below it
Nice! so how is this done?

minigun
interceptor: 010, 011

missile launcher
interceptor: 010, 011

rocket
targetable: 010

Bomb
targetable: 011

is that how it works? also:

coverage: 1000
Is it the distance that the interceptor weapon will start firing when the targetable approaches?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Factory not showing icons for vehicle production

Post by FLOZi »

tags are assigned as ints and interpreted as bitmasks i.e. use 2 to represent 10
nightovizard
Posts: 24
Joined: 15 May 2014, 23:27

Re: Factory not showing icons for vehicle production

Post by nightovizard »

FLOZi wrote:tags are assigned as ints and interpreted as bitmasks i.e. use 2 to represent 10
I have managed to make that it can take down missiles, but for some reason it is not attacking aircrafts anymore.

Another thing I have no idea how to fix is that units are pushing way too much each other, some units even fly.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Factory not showing icons for vehicle production

Post by FLOZi »

Ah - interceptor weapons can only target weapons.

As for pushing, I can't remember really but you can try assigning units a (larger) mass, and check footprint sizes vs. movedef sizes.
nightovizard
Posts: 24
Joined: 15 May 2014, 23:27

Re: Factory not showing icons for vehicle production

Post by nightovizard »

thank you

its been a while, I just wanted to know how to get the AI working, as it seems that none of the default ones work.
http://springrts.com/wiki/AI:Skirmish:List
http://springrts.com/wiki/AI:Development

I have to write my own AI? or is it because of some error in the scripting that the AI cant handle?

and I have no idea about how nukes are done. you know make that the building produces nukes, then it launches them anywhere in the map. this is different form a produced vehicle or a building.
User avatar
Karl
Panzerstahl Developer
Posts: 746
Joined: 01 Apr 2010, 21:05

Re: Factory not showing icons for vehicle production

Post by Karl »

nightovizard wrote: its been a while, I just wanted to know how to get the AI working, as it seems that none of the default ones work..
RAI is a general purpose AI that works on any games with no lua gameplay feature,
most of other AI needs just configuration like some sort of build list to make it work with your game

like E323,Shard or the obsolute NTAI one needed configs
nightovizard wrote: and I have no idea about how nukes are done. you know make that the building produces nukes, then it launches them anywhere in the map. this is different form a produced vehicle or a building.
you do it by giving the nuke alot of damage/AoE, optionaly as a starburst weapon (aka vertical rocket)
http://pastebin.com/dCSnMEDy XTA nuke weapon in TDF format

you can give that weapon to a Unit or Building it doesnt matter, eventually for unit it should be made to use manual firing

http://springrts.com/wiki/Gamedev:WeaponDefs
should explain everything weapon related
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Factory not showing icons for vehicle production

Post by FLOZi »

Ignore Karl, the weapon just needs to have this tag set to true:

http://springrts.com/wiki/Gamedev:Weapo ... :stockpile
Post Reply

Return to “Game Development”