havocx42

power

Nov 5th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. /proc/propagate_network(var/obj/O, var/datum/powernet/PN)
  2. var/list/P = list()
  3. if( istype(O,/obj/structure/cable) )
  4. var/obj/structure/cable/C = O
  5. if(C.powernet==PN)return
  6. C.powernet.cables-=C
  7. C.powernet = PN
  8. PN.cables+=C
  9. P = C.get_connections()
  10.  
  11. else if(O.anchored && istype(O,/obj/machinery/power))
  12. var/obj/machinery/power/M = O
  13. if(M.powernet==PN)return
  14. M.powernet.nodes-=C
  15. M.powernet = PN
  16. PN.nodes+=C
  17. P = M.get_connections()
  18.  
  19. else
  20. return
  21.  
  22. for(var/L in P)
  23. propagate_network(L, PN)
  24.  
  25. /datum/powernet/proc/denode(var/obj/structure/cable/C)
  26. var/turf/T1 = C.loc
  27. if(!T1) return
  28. var/list/powerlist = power_list(T1,C,0,0)
  29. var/datum/powernet/PN = new()
  30. propogate_network(powerlist[1],PN)
  31.  
  32. Hello, I want to get some feedback about something I'm working on.
  33. I discovered that there are some discrepancies in the code for cables and powernets . Essentially the problem boils down to this: There is a makepowernets procedure which admins can run which rebuilds the powernets, for performance reasons this isn't run every time a cable is changed. Instead the changes are made incrementally to the effected powernets when you change a cable. However these two processes provide different results causing confusion and bugs.
  34.  
  35. The makepowernets procedure builds the networks correctly and in the way described on the wiki here: [url]http://wiki.nanotrasen.com/index.php/Basic_construction#Wiring[/url]. The important thing to note is that two cables running "smoothly" perpendicular across the same tile do not connect. "Dotted" or "knotted" cables or "Nodes" on those two cables will cause them to connect. This is good, it allows the most functionality, multiple cables can connect or not connect on the same tile according to the users wishes. Unfortunately the incremental logic used when a cable is placed does not use this logic*, so that any cables will connect regardless of whether they have this "Node". This means two cables can never cross and not connect without running makepowernets again. This by itself is irritating but as I was digging into this I found that it causes more problems. The process for dealing with cutting cables uses the first set of rules so it can fail to detect that two cables are connected according to the rules of placing cables and not disconnect the two powernets. This means disconnected pieces of wire can according to the powernet system be connected and share power.
  36.  
  37. The solution is to pick one set of rules and stick with it.
  38. This is my proposed solution
  39. 1. When adding a cable to a tile only connect to other cables on the tile if they are connected or dotted
  40. 2. After adding a cable to a dotted cable causing it to become smooth do the following
  41. a. find another dotted cable on that tile(if there is none happy days)
  42. b. propagate a new powernet along the first cable we find, this will also propogate to any other cables dotted on that tile.
  43. c. If there was a loop this will actually completely replace the old powernet so remove it if it has no cables left
  44. Worst case this process requires traversing the entire graph once unnecessarily(In the case of a loop), which is better than the current code for cutting a cable which is an inefficient mess.
  45.  
  46. * I believe originally makepowernets was called everytime you placed a cable, this is ridiculous and some simple logic was added to replace this which did not take into account the complexity of dotted cable
Advertisement
Add Comment
Please, Sign In to add comment