# Set the title - this is not the line that causes the icon to be blanked
pygame.display.set_caption("Cute Knight Kingdom")

def hint(*args):
 global self
 global other
 global room
 global keyboard_string
 global score
 global lives
 args = py_PythonAutovivifyingArray(args)
 if (py_reserved_varnames["global"].autohints):
  htext=0
  sheight=0

  htext=py_reserved_varnames["global"].hints[int(args[0]),0]
  try:
   len(py_reserved_varnames["global"].hints)
   py_reserved_varnames["global"].hints[int(args[0]),1]=1.0
  except:
   if type(py_reserved_varnames["global"])==gm6.GM_Object:
    py_vivify_array_val=1.0
    for py_vivify_array_obj in tuple(py_reserved_varnames["global"]):
     print py_vivify_array_obj,py_vivify_array_obj.hints
     py_vivify_array_obj.hints=py_PythonAutovivifyingZeroArray2D()
     py_vivify_array_obj.hints[int(args[0]),1]=py_vivify_array_val
     print py_vivify_array_obj,py_vivify_array_obj.hints
   else:
    py_reserved_varnames["global"].hints=py_PythonAutovivifyingZeroArray2D()
    py_reserved_varnames["global"].hints[int(args[0]),1]=1.0

  draw_set_font(smallfont)
  draw_set_color(c_black)
  sheight=string_height_ext(htext,-1.0,480.0)
  gold_box(room.view_xview[0]+140.0,room.view_yview[0]+285.0-(sheight/2.0)-20.0,room.view_xview[int(0.0)]+660.0,room.view_yview[int(0.0)]+285.0+(sheight/2.0)+25.0)
  draw_text_ext(room.view_xview[int(0.0)]+160.0,room.view_yview[int(0.0)]+285.0-(sheight/2.0)-12.0,htext,-1.0,480.0)
  draw_set_color(c_white)
  draw_text_ext(room.view_xview[int(0.0)]+159.0,room.view_yview[int(0.0)]+285.0-(sheight/2.0)-13.0,htext,-1.0,480.0)
  gold_box(room.view_xview[int(0.0)]+340.0,room.view_yview[int(0.0)]+285.0+(sheight/2.0),room.view_xview[int(0.0)]+480.0,room.view_yview[int(0.0)]+285.0+(sheight/2.0)+33.0)
  draw_set_color(c_white)
  draw_text(room.view_xview[int(0.0)]+350.0,room.view_yview[int(0.0)]+285.0+(sheight/2.0)+4.0,py_reserved_varnames["global"].hints[0,0])
  screen_refresh()
  self.goon=0.0
  io_clear()
  sleep(30.0)
  while (self.goon==0.0):
   sleep(5.0)
   io_handle()
   if (mouse_check_button(mb_left) and mouse_between(room.view_xview[int(0.0)]+340.0,room.view_yview[int(0.0)]+285.0+(sheight/2.0),room.view_xview[int(0.0)]+480.0,room.view_yview[int(0.0)]+285.0+(sheight/2.0)+30.0)):
    self.goon=1.0
  transition()

def gold_box(x1,y1,x2,y2):
 # This is about 5% faster than the original gold_box.
 # ? 0.00948/call before turning all draw_sprites to draw_sprite_ext
 # 0.00783/call afterwards.
 x2 += 4
 color1=py_reserved_varname_1.topbrown[0]
 color2=py_reserved_varname_1.bottombrown[0]
 width=ceil((x2-x1-32.0)/4.0)*4.0+27.0
 height=ceil((y2-y1-32.0)/4.0)*4.0+28
 #draw_set_color(0)
 draw_set_alpha(0.85)
 draw_rectangle_color(x1,y1+1,x1+width+1,y1+height,color1,color1,color2,color2,0)
 draw_set_alpha(1)

 draw_sprite_ext(box_tl,0,x1-9,y1-9,1,1,0,(255,255,255),1)
 i=x1+17
 while i<x2-15:
  draw_sprite_ext(box_top,0,i,y1-9,1,1,0,(255,255,255),1)
  i+=4

 draw_sprite_ext(box_tr,0,i,y1-9,1,1,0,(255,255,255),1)
 j=y1+17
 while j<y2-15:
  draw_sprite_ext(box_left,0,x1-9,j,1,1,0,(255,255,255),1)
  draw_sprite_ext(box_right,0,i,j,1,1,0,(255,255,255),1)
  j+=4.0

 draw_sprite_ext(box_dl,0,x1-9,j,1,1,0,(255,255,255),1)
 i=x1+17
 while i<x2-15:
  draw_sprite_ext(box_bottom,0,i,j,1,1,0,(255,255,255),1)
  i+=4

 draw_sprite_ext(box_dr,0,i,j,1,1,0,(255,255,255),1)

py_old_mask_sprites = mask_sprites
def mask_sprites():
 py_old_mask_sprites()
 global py_rightalign_button_spr
 global py_rightalign_button_spr_highlit
 py_rightalign_button_spr = pygame.Surface((155,52),pygame.SRCALPHA)
 py_rightalign_button_spr.blit(button_left_spr.subimages[0],(0,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(44,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(54,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(64,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(74,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(84,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(94,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(104,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(114,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(124,0))
 py_rightalign_button_spr.blit(button_middle_spr.subimages[0],(134,0))
 py_rightalign_button_spr.blit(button_right_spr.subimages[0],(144,0))
 py_rightalign_button_spr_highlit = pygame.Surface((155,52),pygame.SRCALPHA)
 py_rightalign_button_spr_highlit.blit(py_rightalign_button_spr,(0,0))
 py_tmp = pygame.Surface((155,52))
 py_tmp.blit(py_rightalign_button_spr,(0,0))
 py_tmp.set_alpha(0.15*255)
 py_rightalign_button_spr_highlit.blit(py_tmp,(0,0),None,pygame.BLEND_RGB_ADD)

def py_rightalign_button_draw():
 # XXX should actually set the draw-func.
 
 # Old had a cumulative per-call time of 0.00048; 
 # intermediary had a cumulative percall of 0.00042
 # new has a cumulutative percall of 0.00038
 # Optimizations: everything is now a local variable
 # Newest optimization: kill sw, takes it down to 0.00037/call
 # Bugfix brings it back up to 0.00038/call.
 # Highlit button drawing can be >doubled if I precalc additively-blent
 #   buttons.
 # Cum percall down to 0.00013 when a single blit of a prerendered button
 # is used.
 # 0.00008/call if I precompose the text onto the button.
 global self
 global room
 if room.view_current==0:
  # This needs to be here to keep the buttons onscreen in the worldmap.
  ystart = self.ystart
  xstart = self.xstart
  self.x = x = xstart+room.view_xview[0]
  self.y = y = ystart+room.view_yview[0]
  self.SetBoundingBox()
  self.active=py_GMVar(0)
  draw_set_font(myfont_med)

  if (mouse_between(x-130,y,x,y+50) and self.highlit==0):
   if (instance_exists(py_reserved_varname_1.highlit_clickable)):
    py_reserved_varname_1.highlit_clickable.highlit=py_GMVar(0)
   py_reserved_varname_1.highlit_clickable=self.id
   self.highlit=py_GMVar(1)

  if self.highlit:
   self.active=1
   if not self.py_highlit_spr:
    self.py_highlit_spr = py_rightalign_button_spr_highlit.copy()
    txt = __fontcache[py_draw_props.font].render(self.mytext[0],1,c_black)
    self.py_highlit_spr.blit(txt,(94-(txt.get_width()>>1),14))
    txt = __fontcache[py_draw_props.font].render(self.mytext[0],1,c_white)
    self.py_highlit_spr.blit(txt,(93-(txt.get_width()>>1),13))
   __pygame_screen.blit(self.py_highlit_spr,(xstart-154,ystart))
  else:
   if not self.py_normal_spr:
    self.py_normal_spr = py_rightalign_button_spr.copy()
    txt = __fontcache[py_draw_props.font].render(self.mytext[0],1,c_black)
    self.py_normal_spr.blit(txt,(94-(txt.get_width()>>1),14))
    txt = __fontcache[py_draw_props.font].render(self.mytext[0],1,c_white)
    self.py_normal_spr.blit(txt,(93-(txt.get_width()>>1),13))
   __pygame_screen.blit(self.py_normal_spr,(xstart-154,ystart))

  #draw_set_halign(fa_center)
  #draw_set_color(c_black)
  #draw_text(x-5-55,y+14,self.mytext)
  #draw_set_color(c_white)
  #draw_text(x-6-55,y+13,self.mytext)
  #draw_set_halign(fa_left)
  #draw_set_blend_mode(bm_normal)
  self.sw = 110
rightalign_button.py_objectdata.events[8][0].python = compile('py_rightalign_button_draw()','rightalign_button_draw caller','exec')

def draw_daytime():
 global self
 now = self.timeday
 if (now>4.0 and now<=6.0):
  alpha = ((now-4.0)/10.0)
  py_fasttint.fast_draw_gradients_vcv(__pygame_screen,0,0,800,300,
    __color_to_int(c_blue), __color_to_int((127,0,128)),alpha,
    __color_to_int(py_reserved_varname_1.darkblue),alpha,
    __color_to_int(c_purple), __color_to_int(c_yellow),alpha/2)
  py_fasttint.fast_draw_gradients_vcv(__pygame_screen,0,300,800,600,
     __color_to_int((128,0,127)),__color_to_int(c_red),alpha,
     __color_to_int(py_reserved_varname_1.darkblue), alpha,
     __color_to_int(c_yellow), __color_to_int(c_red),alpha/2)
 elif (now>6.0 and now<=8.0):
  alpha = 0.2-((now-6.0)/10.0)
  py_fasttint.fast_draw_gradients_vcvvc(__pygame_screen,0,0,800,300,
    __color_to_int(c_blue), __color_to_int((127,0,128)),alpha,
    __color_to_int(py_reserved_varname_1.darkblue),alpha,
    __color_to_int(c_purple), __color_to_int(c_yellow),alpha/2,
    __color_to_int(py_reserved_varname_1.darkblue), __color_to_int(merge_color(py_reserved_varname_1.darkblue,c_red,0.5)), (now-6.0)/10.0,
    0, (now-6.0)/8.0,
    )
  py_fasttint.fast_draw_gradients_vcvvc(__pygame_screen,0,300,800,600,
     __color_to_int((128,0,127)),__color_to_int(c_red),alpha,
     __color_to_int(py_reserved_varname_1.darkblue), alpha,
     __color_to_int(c_yellow), __color_to_int(c_red),alpha/2,
     __color_to_int(merge_color(py_reserved_varname_1.darkblue,c_red,0.5)), __color_to_int(c_red), (now-6.0)/10.0,
     0, (now-6.0)/8.0
     )
 elif (now>8.0 and now<=12.0):
  py_fasttint.fast_draw_gradients_vc(__pygame_screen,0,0,800,600,
    __color_to_int(py_reserved_varname_1.darkblue),__color_to_int(c_red),0.2,
    0, 0.25)
 elif (self.timeday>12.0 and self.timeday<16.0):
  py_fasttint.fast_draw_gradients_vv(__pygame_screen,0,0,800,600, 
   __color_to_int(c_blue),__color_to_int(c_red), 
   0.2-((self.timeday-12.0)*0.05), 
   __color_to_int(py_reserved_varname_1.darkblue),0,0.25-((self.timeday-12.0)*0.0625))
 elif (self.timeday>=16.0):
  day_advance()

def glow_obj_draw():
 # 0.0008/call, original is 0.00109
 global self
 if room.view_current:
  return
 draw_set_blend_mode(pygame.BLEND_RGBA_MULT)
 draw_sprite_ext(self.sprite_index,0.0,self.x,self.y,self.scale,self.scale,0.0,c_white,1.0)
 draw_set_blend_mode(bm_normal)
 vx = room.view_xview[0]
 vy = room.view_yview[0]
 y = round(self.y-vy)
 __pygame_screen.fill(0,(0,0,800,y-128))
 __pygame_screen.fill(0,(0,y+127,800,600-(y+127)))
 x = round(self.x-vx)
 __pygame_screen.fill(0,(0,y-128,x-128,255))
 x += 127
 __pygame_screen.fill(0,(x,y-128,800-x,255))

object_event_clear(glow_obj,8,0)
glow_obj.py_objectdata.AddEvent(8,0,' glow_obj_draw()')


class py_StationaryObstacleGrid(list):
    def __init__(self,w,h,cellw,cellh):
        list.__init__(self)
        x = 0
        self.cellw = cellw
        self.cellh = cellh
        while x<w:
            self.append([])
            y = 0
            while y<h:
                self[-1].append(0)
                y += 1
            x += 1
    def AddInstance(self,instance):
        x = instance.bbox_left
        xi = int(instance.bbox_left/self.cellw)
        yistart = int(instance.bbox_top/self.cellh)
        while x<instance.bbox_right:
            y = instance.bbox_top
            yi = yistart
            while y<instance.bbox_bottom:
                self[xi][yi] = 1
                y += self.cellh
                yi += 1
            x += self.cellw
            xi += 1

def dungeon_monster_HandleCollisions(instance, ev):
    # Orig instance HandleCollisions becomes 0.00006/call, while dungeon_monster_HandleCollisions is 0.00008/call
    # The original was 0.00099/call
    bb_l = instance.bbox_left
    bb_t = instance.bbox_top
    bb_r = instance.bbox_right
    bb_b = instance.bbox_bottom
    global self
    global other
    py_other_stack.append(other)
    py_self_stack.append(self)
    self = instance
    for i2 in girl_walker_village:
        if i2.bbox_left<bb_r and i2.bbox_right>=bb_l and i2.bbox_top<bb_b and i2.bbox_bottom>=bb_t:
            if i2.object_index.py_objectdata.solid:
                instance.x = instance.xprevious
                instance.y = instance.yprevious
                instance.SetBoundingBox()
            other = i2
            if py_other_stack[-1] is None:
                py_other_stack[-1] = i2
            gm6.RunActionGroupOn(dungeon_monster_Collision_girl_walker,instance)
            bb_l = instance.bbox_left
            bb_t = instance.bbox_top
            bb_r = instance.bbox_right
            bb_b = instance.bbox_bottom
    for i2 in obj_motion_wall.py_objectdata.NearbyObjects(self.x,self.y,2):
        if i2.bbox_left<bb_r and i2.bbox_right>=bb_l and i2.bbox_top<bb_b and i2.bbox_bottom>=bb_t:
            if i2.object_index.py_objectdata.solid:
                instance.x = instance.xprevious
                instance.y = instance.yprevious
                instance.SetBoundingBox()
            other = i2
            if py_other_stack[-1] is None:
                py_other_stack[-1] = i2
            gm6.RunActionGroupOn(dungeon_monster_Collision_wall,instance)
            bb_l = instance.bbox_left
            bb_t = instance.bbox_top
            bb_r = instance.bbox_right
            bb_b = instance.bbox_bottom

    self = py_self_stack.pop()
    other = py_other_stack.pop()

dungeon_monster_Collision_girl_walker = dungeon_monster.py_objectdata.events[4][0]
dungeon_monster_Collision_wall = dungeon_monster.py_objectdata.events[4][1]
dungeon_monster.py_objectdata.events[4] = [1]
wallgrid = None
dungeon_monster.py_objectdata.AddEvent(0,0,' self.HandleCollisions = type(self.HandleCollisions)(dungeon_monster_HandleCollisions,self,gm6.ObjectInstanceZero)')
#obj_motion_wall.py_objectdata.AddEvent(0,0,' global wallgrid\n wallgrid.AddInstance(self)')
cached_battle_master_window = None
# DO NOT ERASE - this is part of battle optimization.

def __gold_box_surf(x1,y1,x2,y2):
 xmax = int(x2-x1)
 ymax = int (y2-y1)
 surf = pygame.surface.Surface((xmax+15,int(y2-y1)+9),pygame.SRCALPHA)
 # Borders: x1-9, y1-9,
 #...  possibly should be +4 x as well?
 x2 += 4
 color2=py_reserved_varname_1.topbrown[0]
 color1=(0,0,0)#py_reserved_varname_1.bottombrown[0]
 width=ceil((x2-x1-32.0)/4.0)*4.0+27.0
 height=ceil((y2-y1-32.0)/4.0)*4.0+27.0
 draw_set_alpha(0.85)
 __draw_rectangle_color_to(surf,9,9,width+8,height+8,color1,color1,color2,color2,False)
 draw_set_alpha(1)
 surf.blit(box_tl.subimages[0],(0,0))
 i=26
 while i<xmax-4:
  surf.blit(box_top.subimages[0],(i,0))
  i+=4
 surf.blit(box_tr.subimages[0],(i,0))
 j=26
 # -8: Not enough
 while j<ymax-4:
  surf.blit(box_left.subimages[0],(0,j))
  surf.blit(box_right.subimages[0],(i,j))
  j+=4
 surf.blit(box_dl.subimages[0],(0,j))
 i=9+17
 while i<xmax-4:
  surf.blit(box_bottom.subimages[0],(i,j))
  i+=4
 surf.blit(box_dr.subimages[0],(i,j))
 return surf

def __gold_box_surf_trans(x1,y1,x2,y2):
 xmax = int(x2-x1)
 ymax = int (y2-y1)
 surf = pygame.surface.Surface((xmax+15,int(y2-y1)+11),pygame.SRCALPHA)
 # Borders: x1-9, y1-9,
 #...  possibly should be +4 x as well?
 x2 += 4
 color2=py_reserved_varname_1.topbrown[0]
 color1=(0,0,0)#py_reserved_varname_1.bottombrown[0]
 width=ceil((x2-x1-32.0)/4.0)*4.0+27.0
 height=ceil((y2-y1-32.0)/4.0)*4.0+27.0
 #draw_set_alpha(0.85)
 surf2 = pygame.surface.Surface((width+1,height+1))
 # May be between 9 and 19 for best results.
 surf2.blit(__pygame_screen.subsurface((x1+19,y1+19,width,height)),(0,0))
 draw_set_alpha(1.0)
 py_fasttint.fast_draw_gradient_v(surf2,0,0,
        width, 
        height,
        __color_to_int(color2),__color_to_int(color1),217)
 surf.blit(surf2,(9,9))
 #__draw_rectangle_color_to(surf,9,9,width+8,height+8,color1+(100,),color1+(100,),color2+(100,),color2+(100,),False)
 #surf2.set_alpha(int(0.85*255))
 #surf.blit(surf2,(0,0))
 #draw_set_alpha(1)
 surf.blit(box_tl.subimages[0],(0,0))
 i=26
 while i<xmax-4:
  surf.blit(box_top.subimages[0],(i,0))
  i+=4
 surf.blit(box_tr.subimages[0],(i,0))
 j=26
 # -8: Not enough
 while j<ymax-4:
  surf.blit(box_left.subimages[0],(0,j))
  surf.blit(box_right.subimages[0],(i,j))
  j+=4
 surf.blit(box_dl.subimages[0],(0,j))
 i=9+17
 while i<xmax-4:
  surf.blit(box_bottom.subimages[0],(i,j))
  i+=4
 surf.blit(box_dr.subimages[0],(i,j))
 return surf

def __draw_text_to(xpos,ypos,s,dest):
    if type(xpos) is py_GMVar:
        xpos = xpos[0]
    if type(ypos) is py_GMVar:
        ypos = ypos[0]
    # XXX is this mimicing GM alignment behavior?
    if type(s)!=py_string:
        s = string(s)
    s2 = __string_unescape(s)
    surfaces = []
    totalheight = 0
    widest = 0
    for line in s2:
        surf = __fontcache[py_draw_props.font].render(line,1,py_draw_props.color)
        totalheight += surf.get_height()
        widest = max(surf.get_width(),widest)
        surfaces.append(surf)
    x, starty = __apply_text_alignment(xpos,ypos,widest,totalheight)
    y = starty
    for surf in surfaces:
        dest.blit(surf,(x,y))
        y += surf.get_height()
    if py_draw_props.font.bold:
        y = starty
        for surf in surfaces:
            dest.blit(surf,(x+1,y))
            y += surf.get_height()


def draw_walkaround_battle(*args):
 global self
 global other
 global room
 global keyboard_string
 global score
 global lives
 global __pygame_screen
 args = py_PythonAutovivifyingArray(args)
 try:
  self.myx=room.view_xview[0]
  self.myy=room.view_yview[0]
 except:
  self.myx=room.view_xview
  self.myy=room.view_yview
 if (self.playerdamage>0.0):
  self.myx+=random(6.0)-3.0
  self.myy+=random(6.0)-3.0
  self.playerdamage-=1
 global cached_battle_master_window
 if (cached_battle_master_window is None) or self._cached_text!=self.mytext:
  self._cached_text = str(self.mytext)
  cached_battle_master_window = __gold_box_surf(self.myx+45, self.myy+415,self.myx+760,self.myy+585)
  draw_set_font(myfont_med)
  draw_set_color(c_black)
  surfaces = __render_text(self.mytext,700)
  y = 24
  for surf in surfaces:
   cached_battle_master_window.blit(surf,(29,y))
   y += surf.get_height()
  draw_set_color(c_white)
  surfaces = __render_text(self.mytext,700)
  y = 23
  for surf in surfaces:
   cached_battle_master_window.blit(surf,(28,y))
   y += surf.get_height()

 vx = room.view_xview[0]
 vy = room.view_yview[0]
 __pygame_screen.blit(cached_battle_master_window,(int((self.myx+45-9)-vx),(int(self.myy+415-9)-vy)))
 if not self.alldone:
  draw_sprite(self.mysprite,0.0,room.view_xview[0]+155.0,room.view_yview[0])
  if (self.damagedisplay>0.0):
   if (self.tc==0.0):
    draw_sprite_ext(self.mysprite,0.0,room.view_xview[0]+155.0,room.view_yview[0],1.0,1.0,0.0,c_red,0.75)
    self.tc=1.0
   else:
    self.tc=0.0
    draw_set_blend_mode(bm_add)
    draw_sprite_ext(self.mysprite,0.0,room.view_xview[0]+155.0,room.view_yview[0],1.0,1.0,0.0,c_red,0.75)
    draw_set_blend_mode(bm_normal)

   self.damagedisplay-=1.0

  gold_box(self.myx+8.0,self.myy+100.0,self.myx+220.0,self.myy+215.0)
  draw_set_font(myfont)
  draw_set_halign(fa_center)
  draw_set_color(c_black)
  draw_text(self.myx+110.0,self.myy+111.0,"Level "+string(self.level))
  draw_text(self.myx+115.0,self.myy+146.0,self.bname)
  draw_set_color(c_white)
  draw_text(self.myx+109.0,self.myy+110.0,"Level "+string(self.level))
  draw_text(self.myx+114.0,self.myy+145.0,self.bname)
  draw_set_halign(fa_left)
  draw_set_font(myfont_med)
  draw_set_color(c_black)
  draw_text(self.myx+35.0,self.myy+185.0,"HP:")
  draw_set_color(c_white)
  draw_text(self.myx+34.0,self.myy+184.0,"HP:")
  draw_set_color(c_black)
  draw_rectangle(self.myx+100.0,self.myy+188.0,self.myx+200.0,self.myy+202.0,0.0)
  draw_rectangle_color(self.myx+100.0,self.myy+188.0,self.myx+100.0+(100.0*self.hp/self.basehp),self.myy+202.0,c_red,c_red,py_reserved_varnames["global"].darkred,py_reserved_varnames["global"].darkred,0.0)
  draw_sprite(lilbar_spr,0.0,self.myx+97.0,self.myy+185.0)
  draw_set_color(c_white)
  draw_set_font(tinyfont)
  draw_set_halign(fa_right)
  draw_text(self.myx+197.0,self.myy+187.0,string(ceil(self.hp))+"/"+string(ceil(self.basehp)))
  if not self.cached_equipsurf:
   #draw_set_halign(fa_left)
   if room==world_map:
    surf = __gold_box_surf_trans(8,230,220,395)
   else:
    surf = __gold_box_surf(8,230,220,395)
   #self.myx+8, self.myy+230, self.myx+220, self.myy+395)
   #gold_box(self.myx+8.0,self.myy+230.0,self.myx+220.0,self.myy+395.0)
   draw_set_font(myfont_smaller)
   draw_set_halign(fa_center)
   draw_set_color(c_black)
   #draw_text_ext(self.myx+110.0,self.myy+240.0,"Equipped",-1.0,190.0)
   tmptxtsurf = __render_text("Equipped",190)
   surf.blit(tmptxtsurf[0],(111-(tmptxtsurf[0].get_width()/2),20))
   draw_set_color(c_white)
   tmptxtsurf = __render_text("Equipped",190)
   surf.blit(tmptxtsurf[0],(110-(tmptxtsurf[0].get_width()/2),19))
   self.cached_equipsurf = surf
   draw_set_halign(fa_left)
   draw_set_color(c_black)
   __draw_text_to(14,40,self.equiptext,surf)
   draw_set_color(c_white)
   __draw_text_to(13,39,self.equiptext,surf)
  draw_set_halign(fa_left)
  __pygame_screen.blit(self.cached_equipsurf,(self.myx-1-vx,self.myy+221.0-vy))
  #draw_text_ext(self.myx+109.0,self.myy+239.0,"Equipped",-1.0,190.0)
  #draw_set_halign(fa_left)
  #draw_set_color(c_black)
  #draw_text(self.myx+13.0,self.myy+260.0,self.equiptext)
  #draw_set_color(c_white)
  #draw_text(self.myx+12.0,self.myy+259.0,self.equiptext)

def battle_master_draw():
 global self
 if self.mytext!=self._cached_text:
  global cached_battle_master_window
  cached_battle_master_window = None
  draw_set_font(myfont_med)
  while (string_height_ext(self.mytext,-1.0,700.0)>140.0):
   lspot=string_pos("#",self.mytext)
   self.mytext=string_delete(self.mytext,1.0,lspot)
 draw_walkaround_battle()

# myfont: original was size 25, bold
# change to 35 regular not scale-checked.
# With new auto-bolding,size 34 bold seems to adequately simulate.
myfont.size = 34
# myfont_med: orig Prescript 22 bold. 
# 31 regular is almost right.  30 (non-ttf) bold is more right.
#myfont_med.bold = 0
myfont_med.size = 30
# myfont_smaller 16 bold
# change to 22 regular not scale-checked.
myfont_smaller.size=22
myfont_smaller.bold=0
# options_font 26 bold
# tinyfont 10 bold
tinyfont.size = 13
# smallfont 14 regular
# endfont 18 regular

object_event_clear(walkaround_battle_master,8,0)
walkaround_battle_master.py_objectdata.AddEvent(8,0,' battle_master_draw()')
object_event_clear(dungeon_battle_master,8,0)
dungeon_battle_master.py_objectdata.AddEvent(8,0,' battle_master_draw()')
object_event_clear(walkaround_battle_master,1,0)
object_event_clear(dungeon_battle_master,1,0)
def battle_master_destroy():
 global self
 global other
 py_self_stack.append(self)
 py_other_stack.append(other)
 py_objlist = (self.endb)
 other = self
 if type(py_objlist) is py_GMVar:
  py_objlist=py_objlist[0]
 if object_exists(py_objlist):
  for self in tuple(py_objlist):
   instance_destroy()
 elif instance_exists(py_objlist):
  py_loopcounter = 1
  self = py_objlist
  if type(self)==int:
   self = gm6.instances[self]
  while py_loopcounter:
   py_loopcounter=0
   instance_destroy()
 other = py_other_stack.pop()
 self = py_self_stack.pop()
 self.cached_equipsurf = None
 global cached_battle_master_window
 cached_battle_master_window = None
dungeon_battle_master.py_objectdata.AddEvent(1,0,' battle_master_destroy()')
walkaround_battle_master.py_objectdata.AddEvent(1,0,' battle_master_destroy()')

show_equipped.py_objectdata.py_GlobLeftPressedActionGroup = show_equipped.py_objectdata.py_GlobRightPressedActionGroup

py_old_hint_setup = hint_setup
def hint_setup(*args):
 global self
 global other
 global room
 global keyboard_string
 global score
 global lives
 py_old_hint_setup(*args)
 py_reserved_varname_1.hints[0,0]="Click Here to Continue"
 py_reserved_varname_1.hints[1,0]="To do well in a job, you need the right skills. Each day that you work, you may succeed or fail. You will only get paid for a day if you succeed. Your skill values determine your chance of success. The progress bar with a star under it will show you whether you've done enough to get paid. #                   Bright green = Success! Yellow = Try harder!# #You can put in extra effort in order to succeed. Click the Exertion button to spend HP and try harder physically. Click the Concentration button to spend MP and try harder mentally.# #Be careful! If you spend all your HP and MP, you'll exhaust yourself and take damage. It's safer to be patient and build your skills slowly. You will automatically improve at each job with  practice."
 py_reserved_varname_1.hints[2,0]="Studying improves your skills, but to get the most out of a class, you have to pay attention every day. If your Dream is low, it's easy to become distracted and not learn anything. Also, if your skill is already high, it can be hard to find new things to learn. The progress bar with a star under it will show you whether you are succeeding in class each day.#                   Bright green = Success! Yellow = Try harder!# #You can put in extra effort in order to succeed. Click the Exertion button to spend HP and try harder physically. Click the Concentration button to spend MP and try harder mentally.# #Be careful! If you spend all your HP and MP, you'll exhaust yourself and take damage. It's safer to build your skills slowly and make sure you get enough rest."
 py_reserved_varname_1.hints[3,0]="Take a look at your HP and MP display in the upper right corner. You've worked too hard and become exhausted. Every day that you continue to work or study while exhausted, you will lose Dream and your skills will become weaker. As soon as you can, stop and get some rest!"
 py_reserved_varname_1.hints[4,0]="Select any number of ingredients to add them to the mix, then click Cook. You can only use each ingredient once per recipe. Once an ingredient is added, it has to be cooked and cannot be removed.# #To make a food item, you need the right combination of ingredients and a good Cooking skill. If you cook a bad recipe or don't have enough Cooking skill, your ingredients will still be used up.# #Experiment with different ingredients you find and see what you can make."
 py_reserved_varname_1.hints[5,0]="Select any two components and click on Craft to combine them. You can combine two of the same item!# #If the components you select don't combine, or you don't have enough Crafting skill to combine them, the components will return to your inventory. So try everything! You never know what you might be able to make."
 py_reserved_varname_1.hints[6,0]="To use items, click the Outfit button to go to the inventory screen. # #Click on items to use or wear them. Click on items you're already wearing to remove them."
 py_reserved_varname_1.hints[7,0]="Use the arrow keys or left-click the mouse on the ground to walk around. The cursor will light up when it moves over places that you can walk, or people that you can talk to.# #Characters can chat with you, sell you items, and offer you jobs or places to sleep. People with something new to Chat about display a star over their heads. Click on characters to walk to them and begin a conversation.# #To leave the village, click on the To Map button, or walk to the right edge of the screen."
 py_reserved_varname_1.hints[8,0]="This screen displays all the spell symbols that your character currently knows. Each symbol affects one or more elements, such as Air or Water. Mouse over the symbols to see what elements they affect.# #Monsters have strengths and weaknesses against different elements, so try different symbols on different monsters to determine what's most effective.# #You start the game knowing the Candles symbol. You will have to discover the rest for yourself!"


#py_reserved_varnames['global'].hints[6][0] = "To use items, click the Outfit button to go to the inventory screen. # #Click on items to use or wear them. Click on items you're already wearing to remove them."

def monthname(*args):
 global self
 global other
 global room
 global keyboard_string
 global score
 global lives
 args = py_PythonAutovivifyingArray(args)
 datestring=''

 if args[0]==1.0:
  datestring="Beginnings"
 else:
  if args[0]==2.0:
   datestring="Changes"
  else:
   if args[0]==3.0:
    datestring="Grass"
   else:
    if args[0]==4.0:
     datestring="Planting"
    else:
     if args[0]==5.0:
      datestring="Sprouts"
     else:
      if args[0]==6.0:
       datestring="Water"
      else:
       if args[0]==7.0:
        datestring="Letters"
       else:
        if args[0]==8.0:
         datestring="Leaves"
        else:
         if args[0]==9.0:
          datestring="Autumn"
         else:
          if args[0]==10.0:
           datestring="Gods"
          else:
           if args[0]==11.0:
            datestring="Frost"
           else:
            if args[0]==12.0:
             datestring="Sleep"
 return datestring

def debug_log(*args):
    nargs = ['debug_log:']
    for arg in args:
        nargs.append(str(arg))
    nargs.append('\n')
    f = file('debug.log','a')
    f.writelines(nargs)
    f.close()

py_orig_game_setup = game_setup
def game_setup(*args):
    py_orig_game_setup(*args)
    py_reserved_varnames['global'].savedir = renpy_glue.write_directory+'saves/'
    renpy_glue.mkpath(py_reserved_varnames['global'].savedir)

def start_map_move_keyboard_DISABLED(*args):
 global self
 global other
 global room
 global keyboard_string
 global score
 global lives
 args = py_PythonAutovivifyingArray(args)
 xx=0
 yy=0
 ting=0

 xx=py_GMVar(floor(args[0]/40.0)*40.0+20.0)
 yy=py_GMVar(floor(args[1]/40.0)*40.0+20.0)
 girl_walker_village.setclick=py_GMVar(-1.0)
 if  not position_empty(xx,yy):
  if instance_position(xx,yy,obj_motion_wall):
   return

  ting=py_GMVar(instance_position(xx,yy,clickon_object))
  if ting!=noone:
   girl_walker_village.setclick=py_GMVar(ting)


 xdelt = xx-girl_walker_village.x
 ydelt = yy-girl_walker_village.y
 if abs(ydelt)>abs(xdelt):
  if ydelt>0:
   for i in girl_walker_village:
    i.SetDirection(270)
  else:
   for i in girl_walker_village:
    i.SetDirection(90)
 elif xdelt<0:
  for i in girl_walker_village:
   i.SetDirection(180)
 else:
  for i in girl_walker_village:
   i.SetDirection(0)

 py_self_stack.append(self)
 py_other_stack.append(other)
 py_objlist = (girl_walker_village)
 other = self
 if type(py_objlist) is py_GMVar:
  py_objlist=py_objlist[0]
 if object_exists(py_objlist):
  for self in tuple(py_objlist):
   self.destx=py_GMVar(xx)
   self.desty=py_GMVar(yy)
   if py_reserved_varname_1.speedy==1.0:
    self.SetSpeed(py_GMVar(8.0))
   else:
    self.SetSpeed(py_GMVar(4.0))

   plot_map_move()
 elif instance_exists(py_objlist):
  py_loopcounter = 1
  self = py_objlist
  if type(self)==int:
   self = gm6.instances[self]
  while py_loopcounter:
   py_loopcounter=0
   self.destx=py_GMVar(xx)
   self.desty=py_GMVar(yy)
   if py_reserved_varname_1.speedy==1.0:
    self.SetSpeed(py_GMVar(8.0))
   else:
    self.SetSpeed(py_GMVar(4.0))

   plot_map_move()
 other = py_other_stack.pop()
 self = py_self_stack.pop()

object_event_clear(exit_monitor,6,53)
object_event_add(exit_monitor,6,53,"""
if (cyclepos >= 0) {
  if (instance_exists(clickables[cyclepos])) {
    clickables[cyclepos].highlit = 0; 
  }
}
if (instance_exists(global.highlit_clickable)) { global.highlit_clickable.highlit = 0; global.highlit_clickable = -1; }""")
