ID:159808
 
I'm sorry for asking a "How to code" question, but for some reason I can't seem to think of a way to code this efficiently. I've tried a few things, but they all seem to need debugging, and don't work correctly; I fear i'm prolly doing it completely wrong.

Okay, so.. I have:

Water Turf:
Consumes 3 movement

Forest Turf:
Consumes 2 movement

Mountain Turf:
Consumes 3 movement

Grass Turf:
Consumes 1 movement

City Turf:
Consumes 2 movement, except by Vehicles.

I have a Selection proc working fine, it selects the unit, ect. What i'm trying to do is make it so the game will determine which turfs that unit can move to with it's remaining "Movement", and clicking that turf will move to it. All the turfs it can move too should probably go in a List, I know that much, but I can't figure out a good way to figure out how far it can move.
You can use a simple proc that returns how much restriction a turf has.
mob
proc/checkTerrain()if(isturf(loc)) //Check if your loc is a turf.
//***Turfs is a list containing all the types of turf
//considered to be that type of turf. You could use
//typesof() if they are in unique types, such as
// /turf/WaterTurf/...
if(loc.type in WaterTurfs)return 3
else if(loc.type in ForestTurfs)return 2
else if(loc.type in MountainTurfs)return 3
else if(loc.type in GrassTurfs)return 1
else if(loc.type in CityTurfs)return istype(src,/mob/Vehicle)?0 : 1
//The return value is the number of movement consumed.
//Because this proc returns a number, you can use a variable containing it, like this:
//var/movementLoss = checkTerrain()
Thank you, this was very useful. Can't believe I didn't think of that xD It's fairly simple too.
You can simply implement it as a variable on the turfs, a sufficient and well object-oriented method. Pretty simple. >_> This is how it could look:
turf
var/move_penalty = 1
water/move_penalty = 3
forest/move_penalty = 2
city
/*this one could be implemented by a number of ways,
including setting a flag, checking for this turf type,
or perhaps setting up a terrain type system altogether,
where road types give boosts to ground vehicles' movement.*/

move_penalty = -2
mob/proc/move_to(turf/Loc)
var/penalty = 0
if(Loc.move_penalty < 0)
if(!src.IsUsingVehicle())
penalty = abs(Loc.move_penalty)
//if using a vehicle, we leave penalty at 0
else penalty = Loc.move_penalty
src.IncurPenalty(penalty)
//...