Home World Forum
Stars! AutoHost web forums

Jump to Stars! AutoHost


 
 
Home » Stars! 2.6/7 » Questions about Stars! AutoHost » Can we still play when autohost freezes?
Re: Can we still play when autohost freezes? Sat, 28 July 2007 13:31 Go to previous messageGo to previous message
PaulCr

 
Chief Warrant Officer 3
Stars! V.I.P

Messages: 187
Registered: February 2007
Location: An Island that kinda look...
Ron wrote on Sat, 28 July 2007 03:06


As for scheduling... its a mess. Considering the different factors involved, I think it doesn't work too bad. If anyone can provide pseudo code that handles scheduling (and all the different cases that can come up) better, please post it.



I threw something together for fledging admirals 2 which kept causing SAH to crash, it only does scheduled generations though, it basically has a function that calculates the next scheduled time when given the hour the game normally generates, the days of the week it does so and the date/time to get the next generation after. When everyone turns in it calls it with the current date/time to find when the next generation would have taken place and then calls it again using that time to find the next + 1, doing it that way rather than calling it once with the existing next generation time stops it from accummulating if everyone turns in early multiple times. A scheduled generation just calls it with the current time, as does a forced generation since the host carries that out they can change the schedule temporarily if they needed to.

The routine is pretty short and clean so I've included it at the end since you may find it useful. The code for adding a set number of hours would be a simple addition to the current date/time. I'm not sure if you have any other possibilities I'm not aware of though.

function GetNextGenerationTime(GenDays,GenHour,TimeToUse)
  dim a,NextGeneration
  if GenDays>0 then
    if genhour<=hour(TimeToUse) then
      for a=0 to 7
        if (gendays and (2^(weekday(dateadd("d",a+1,TimeToUse),1)-1)))< >0 then
          NextGeneration=cdate(format(dateadd("d",a+1,TimeTo Use),"dd MMM yyyy " & genhour & ":00:00"))
          exit for
        end if
      next
    else
      for a=0 to 7
        if (gendays and (2^(weekday(dateadd("d",a,TimeToUse),1)-1)))<&g t;0 then
          NextGeneration=cdate(format(dateadd("d",a,TimeToUs e),"dd MMM yyyy " & genhour & ":00:00"))
          exit for
        end if
      next
    end if
  else
    NextGeneration="null"
  end if
  return NextGeneration
end function

GenDays is a bitmask of the days of the week, Sundays being 1, Mondays 2, Tuesdays 4 etc so Mondays, Wednesdays and Fridays would be 2+8+32=42

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Player status indicator
Next Topic: Recent SQL forum errors.
Goto Forum:
  


Current Time: Tue May 14 04:45:06 EDT 2024