[Code...]
turf
icon = 'Sectors.dmi';
var/contains[0]
New()
..()
contains["1"] = list()
contains["2"] = list()
[Code...]
[Code...]
Entered(obj/units/A, atom/B)
if(!istype(A, /obj/units))return 1
contains["[A.color]"] += A//***************LINE: 119***************/
world<<"Debug: [contains[1]], [contains[2]], [A.color]"
if(A.prev_loc)
var/turf/t = A.prev_loc
var/list/L = t.contains["[A.color]"]
if(L == null)
var/turf/r = locate(x, y, z)
for(var/c in colors_in_use)r.contains[c] = list()
for(var/obj/units/o in r)
world<<"Debug: [r.contains[1]], [r.contains[2]], [o.color]"
r.contains["[o.color]"] += o//***************LINE: 129***************/
//world<<"NULL!"
return 1
L -= A//***************LINE: 132***************/
t.contains["[A.color]"] = L
//else world<<"ADGGAD"
A.prev_loc = src
..()
ideally turf/Entered() would look like this:
Entered(obj/units/A, atom/B)
if(!istype(A, /obj/units))return 1
contains["[A.color]"] += A
A.prev_loc.contains["[A.color]"] -= A
A.prev_loc = src
Problem description:
This code works most of the time but every now and again it gets an error that makes the list think it's an obj/unit1 obj.
It happens in a few places. I've tried everything I can think of to fix it. I even remake the lists just above line 129.
Here are the errors:
runtime error: type mismatch: the unit1 (/obj/units/unit1) += the unit1 (/obj/units/unit1)
proc name: Entered (/turf/Entered)
source file: Sectors.dm,119
usr: 0
src: the turf (6,7,1) (/turf)
call stack:
the turf (6,7,1) (/turf): Entered(the unit1 (/obj/units/unit1), the turf (7,7,1) (/turf))
gameTimer()
: New()
runtime error: type mismatch: the unit1 (/obj/units/unit1) -= the unit1 (/obj/units/unit1)
proc name: Entered (/turf/Entered)
source file: Sectors.dm,132
usr: 0
src: the turf (6,9,1) (/turf)
call stack:
the turf (6,9,1) (/turf): Entered(the unit1 (/obj/units/unit1), the turf (6,8,1) (/turf))
gameTimer()
: New()
runtime error: type mismatch: the unit1 (/obj/units/unit1) += the unit1 (/obj/units/unit1)
proc name: Entered (/turf/Entered)
source file: Sectors.dm,129
usr: 0
src: the turf (6,7,1) (/turf)
call stack:
the turf (6,7,1) (/turf): Entered(the unit1 (/obj/units/unit1), the turf (7,7,1) (/turf))
gameTimer()
: New()
Here is some code that is called when I create a new units using turf.MouseDown():
[Code...]
if(rand(1, 2) == 1)
o.icon_state = "Unit1"
o.color = 1
else
o.color = 2
o.icon_state = "Unit2"
o.loc = locate(x, y, z)
o.prev_loc = src
o.destination = null
o.step_x = rand(10, 54)
o.step_y = rand(10, 54)
usr.units += o
var/turf/t = locate(x, y, z)
t.contains["[o.color]"] += o
When I remove lines 264 through 286 from GameTimer I don't get any of those errors. I need those lines for units to be able to combat each other. I don't see how those lines are messing things up.
Here is GameTimer, it is called once when the games starts:
proc/gameTimer()
set background = 1
//var/count = 0
while(1)
//count++
for(var/obj/units/o in active_units)
//if(count % 10 == 0)o.direction = pick(NORTH, EAST, SOUTH, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST)
if(o.destination)
if(o.loc == o.destination)
var/list/dirs = list()
if(o.step_y > 32)
if(o.step_x > 10)dirs += SOUTHWEST
if(o.step_x < 54)dirs += SOUTHEAST
if(o.step_x > 10 && o.step_x < 54)dirs += SOUTH
if(o.step_y < 32)
if(o.step_x > 10)dirs += NORTHWEST
if(o.step_x < 54)dirs += NORTHEAST
if(o.step_x > 10 && o.step_x < 54)dirs += NORTH
if(o.step_x > 32)
if(o.step_y > 10 && o.step_y < 54)dirs += WEST
if(o.step_x < 32)
if(o.step_y > 10 && o.step_y < 54)dirs += EAST
if(dirs.len > 0)
o.direction = pick(dirs)
o.destination = null
else step_towards(o, o.destination, rand(o.spd - 1, o.spd + 1))
else
step(o, o.direction, o.spd)
var/move_on = FALSE
for(var/c in colors_in_use)if("[o.color]" != c)//***************Line: 264******************/
if(move_on)break
for(var/obj/units/A in o.prev_loc.contains["[c]"])if(o.color > 0 && A.color > 0 && o.color != A.color)
o.hp -= A.atk
A.hp -= o.atk
if(A.hp <= 0)
A.prev_loc.contains["[A.color]"] -= A
A.color = 0
A.icon_state = ""
if(A.owner)
A.owner.units -= A
A.owner = null
inactive_units += A
active_units -= A
if(o.hp <= 0)
o.prev_loc.contains["[o.color]"] -= o
o.icon_state = ""
o.color = 0
if(o.owner)
o.owner.units -= o
o.owner = null
inactive_units += o
active_units -= o
move_on = TRUE
break//***************Line: 289******************/
sleep(5)
I didn't have time to read much beyond this snippet, but see if the following modification helps any. If not I'll try to analyze it more later when I actually have time:
The checks I added are indeed a lot of overhead for normal operation but if they fix it then it just shows the lists are being built or destroyed improperly somewhere.