Anybody feel like cleaning up a mess? in Developer Help
|
|
Well I've been corrected by Garthor countless times while helping people on the developer forums, and I feel like my code could be improved on. It doesn't seem right, so I was wondering if someone could point out some revisions I could do to the code. Keep in mind, it works fine, but I don't think it's the most efficient way to achieve what I'm trying to do.
mob/proc Power_Supply(mob/Guild_Base/Power_Supplies/M) if(M.powerlevel <= 0) M.icon_state = "PS-Off-0" M.is_down = 1 Check_PS(M) else if(M.powerlevel <= 2000000) M.icon_state = "PS-On-0" else if(M.powerlevel <= 10000000) M.icon_state = "PS-On-10" else if(M.powerlevel <= 20000000) M.icon_state = "PS-On-20" else if(M.powerlevel <= 30000000) M.icon_state = "PS-On-30" else if(M.powerlevel <= 40000000) M.icon_state = "PS-On-40" else if(M.powerlevel <= 50000000) M.icon_state = "PS-On-50" else if(M.powerlevel <= 60000000) M.icon_state = "PS-On-60" else if(M.powerlevel <= 70000000) M.icon_state = "PS-On-70" else if(M.powerlevel <= 80000000) M.icon_state = "PS-On-80" else if(M.powerlevel <= 90000000) M.icon_state = "PS-On-90" Security_Terminal(mob/Guild_Base/Security_Terminals/M) if(M.powerlevel <= 0) M.icon_state = "SC-Off-0" M.is_down = 1 Check_SC(M) else if(M.powerlevel <= 5000000) M.icon_state = "SC-On-0" else if(M.powerlevel <= 10000000) M.icon_state = "SC-On-10" else if(M.powerlevel <= 15000000) M.icon_state = "SC-On-20" else if(M.powerlevel <= 20000000) M.icon_state = "SC-On-30" else if(M.powerlevel <= 25000000) M.icon_state = "SC-On-40" else if(M.powerlevel <= 30000000) M.icon_state = "SC-On-50" else if(M.powerlevel <= 35000000) M.icon_state = "SC-On-60" else if(M.powerlevel <= 40000000) M.icon_state = "SC-On-70" else if(M.powerlevel <= 45000000) M.icon_state = "SC-On-80" else if(M.powerlevel <= 50000000) M.icon_state = "SC-On-90" proc Check_PS(mob/Guild_Base/Power_Supplies/ps) if(istype(ps,/mob/Guild_Base/Power_Supplies/Power_Supply_1)) for(var/mob/Guild_Base/Power_Supplies/Power_Supply_2/ps_2 in world) if(ps_2.is_down && ps.is_down) world<<output("<font color=yellow>The guild base power supplies have been terminated","Chat") for(var/mob/Guild_Base_Console/gb in world) gb.ps_down = 1 else for(var/mob/Guild_Base/Power_Supplies/Power_Supply_1/ps_1 in world) if(ps_1.is_down && ps.is_down) world<<output("<font color=yellow>The guild base power supplies have been terminated","Chat") for(var/mob/Guild_Base_Console/gb in world) gb.ps_down = 1 return Check_SC(mob/Guild_Base/Security_Terminals/sc) if(istype(sc,/mob/Guild_Base/Security_Terminals/Security_Terminal_1)) for(var/mob/Guild_Base/Security_Terminals/Security_Terminal_2/sc_2 in world) if(sc_2.is_down && sc.is_down) world<<output("<font color=yellow>The guild base security terminals have been terminated","Chat") for(var/mob/Guild_Base_Console/gb in world) gb.sc_down = 1 gb.icon_state = "Terminal-Norm" else for(var/mob/Guild_Base/Security_Terminals/Security_Terminal_1/sc_1 in world) if(sc_1.is_down && sc.is_down) world<<output("<font color=yellow>The guild base security terminals have been terminated","Chat") for(var/mob/Guild_Base_Console/gb in world) gb.sc_down = 1 gb.icon_state = "Terminal-Norm" return
|
Basically we have a power supply that's icon state changes whenever its powerlevel drops by 10 million. If it hits 0, and the second power supply hits 0 as well, an alert is displayed that the supplies are both down, and the guild base's variable is set.
|
You could do something like that for the first one, perhaps that will show you what to do with the rest. I have a headache, and you told me to post if I could help, and I believe I did. You didn't have anything for powerlevels higher than a certain amount, and therefore I assumed that they couldn't go any higher.