
#line 1 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
#include "gui/dnd_loot_2.hpp"
#include "gui/guecstra.hpp"
#include "gui/uisystems.hpp"
#include <guecs/ui.hpp>
#include <fmt/core.h>
#include "dbc.hpp"

#define _log(M, F) {$cur_state = F; fmt::println("| {}:{} action={}, fcurs={}", __FILE_NAME__, __LINE__, #M, F);}



#line 131 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"



#line 14 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp"
static const char _DNDLoot_eof_actions[] = {
	0, 0, 0, 0, 0, 10, 0, 10
};

static const int DNDLoot_start = 1;
static const int DNDLoot_first_final = 8;
static const int DNDLoot_error = 0;

static const int DNDLoot_en_main = 1;
static const int DNDLoot_en_main_looting = 2;


#line 134 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"

namespace gui {
  sf::Vector2f DNDLoot2::mouse_position() {
    return $window.mapPixelToCoords($router.position);
  }

  void DNDLoot2::mouse_action(bool hover) {
    sf::Vector2f pos = mouse_position();
    $status_ui.mouse(pos.x, pos.y, hover);
    if($loot_ui.active) $loot_ui.mouse(pos.x, pos.y, hover);
  }

  DNDLoot2::DNDLoot2(StatusUI& status_ui, LootUI& loot_ui, sf::RenderWindow &window, routing::Router& router) :
    $status_ui(status_ui),
    $loot_ui(loot_ui),
    $window(window),
    $router(router)
  {
    
#line 43 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp"
	{
	cs = DNDLoot_start;
	}

#line 153 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"

    dbc::log("====================================");
    event(Event::STARTED);
    dbc::log("---------------- END CONSTRICT ------");
  }

  bool DNDLoot2::event(Event event, std::any data) {
    if(event == Event::TICK) return true;

    int *p = (int *)&event;
    int *pe = p+1;
    int *eof = pe;

    dbc::log(fmt::format(">>>> DND EVENT {}, state={}, cs={}, end={}",
          int(event), $cur_state, cs, $at_end));

    
#line 62 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp"
	{
	int _ps = 0;
	if ( cs == 0 )
		goto _out;
_resume:
	switch ( cs ) {
case 1:
	if ( (*p) == 0 )
		goto tr0;
	goto tr1;
case 0:
	goto _out;
case 2:
	switch( (*p) ) {
		case 14: goto tr2;
		case 17: goto tr4;
		case 19: goto tr5;
	}
	if ( (*p) < 20 ) {
		if ( 15 <= (*p) && (*p) <= 16 )
			goto tr3;
	} else if ( (*p) > 21 ) {
		if ( 22 <= (*p) && (*p) <= 23 )
			goto tr5;
	} else
		goto tr6;
	goto tr1;
case 3:
	switch( (*p) ) {
		case 14: goto tr7;
		case 16: goto tr8;
		case 17: goto tr9;
		case 19: goto tr10;
	}
	if ( (*p) > 21 ) {
		if ( 22 <= (*p) && (*p) <= 23 )
			goto tr10;
	} else if ( (*p) >= 20 )
		goto tr11;
	goto tr1;
case 4:
	switch( (*p) ) {
		case 14: goto tr12;
		case 15: goto tr13;
	}
	goto tr1;
case 5:
	switch( (*p) ) {
		case 14: goto tr15;
		case 17: goto tr17;
		case 19: goto tr18;
	}
	if ( (*p) < 20 ) {
		if ( 15 <= (*p) && (*p) <= 16 )
			goto tr16;
	} else if ( (*p) > 21 ) {
		if ( 22 <= (*p) && (*p) <= 23 )
			goto tr18;
	} else
		goto tr19;
	goto tr14;
case 6:
	switch( (*p) ) {
		case 14: goto tr20;
		case 16: goto tr21;
		case 17: goto tr22;
		case 19: goto tr23;
	}
	if ( (*p) > 21 ) {
		if ( 22 <= (*p) && (*p) <= 23 )
			goto tr23;
	} else if ( (*p) >= 20 )
		goto tr24;
	goto tr1;
case 7:
	switch( (*p) ) {
		case 14: goto tr25;
		case 16: goto tr26;
		case 17: goto tr27;
		case 19: goto tr28;
	}
	if ( (*p) > 21 ) {
		if ( 22 <= (*p) && (*p) <= 23 )
			goto tr28;
	} else if ( (*p) >= 20 )
		goto tr29;
	goto tr14;
	}

	tr1: cs = 0; goto _again;
	tr14: _ps = cs;cs = 0; goto f9;
	tr0: _ps = cs;cs = 2; goto f0;
	tr2: _ps = cs;cs = 2; goto f1;
	tr8: _ps = cs;cs = 2; goto f2;
	tr22: _ps = cs;cs = 2; goto f3;
	tr5: _ps = cs;cs = 2; goto f4;
	tr6: _ps = cs;cs = 2; goto f5;
	tr9: _ps = cs;cs = 2; goto f6;
	tr15: _ps = cs;cs = 2; goto f10;
	tr26: _ps = cs;cs = 2; goto f11;
	tr18: _ps = cs;cs = 2; goto f13;
	tr19: _ps = cs;cs = 2; goto f14;
	tr21: _ps = cs;cs = 2; goto f15;
	tr27: _ps = cs;cs = 2; goto f16;
	tr3: _ps = cs;cs = 3; goto f2;
	tr10: _ps = cs;cs = 3; goto f4;
	tr11: _ps = cs;cs = 3; goto f5;
	tr16: _ps = cs;cs = 3; goto f11;
	tr28: _ps = cs;cs = 3; goto f13;
	tr29: _ps = cs;cs = 3; goto f14;
	tr20: _ps = cs;cs = 4; goto f1;
	tr7: _ps = cs;cs = 4; goto f2;
	tr25: _ps = cs;cs = 4; goto f11;
	tr12: _ps = cs;cs = 5; goto f7;
	tr4: _ps = cs;cs = 6; goto f3;
	tr23: _ps = cs;cs = 6; goto f4;
	tr24: _ps = cs;cs = 6; goto f5;
	tr17: _ps = cs;cs = 6; goto f12;
	tr13: _ps = cs;cs = 7; goto f8;

f9:
#line 17 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    $cur_state = (_ps);
    fmt::println("!!! ERROR fcurs={}", (_ps));
  }
	goto _again;
f0:
#line 22 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(started, (_ps));
    {p++; goto _out; }
  }
	goto _again;
f1:
#line 27 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(loot_close, (_ps));
    $loot_ui.active = false;
    {p++; goto _out; }
  }
	goto _again;
f2:
#line 33 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(loot_grab, (_ps));
    // NOTE: when grab_source could work to do the if that was here
    $grab_source = UISystem::loot_grab($loot_ui.$gui, data);
    {p++; goto _out; }
  }
	goto _again;
f3:
#line 40 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(inv_grab, (_ps));
    $grab_source = UISystem::loot_grab($status_ui.$gui, data);
    {p++; goto _out; }
  }
	goto _again;
f15:
#line 46 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(loot_drop, (_ps));
    if(UISystem::loot_drop($status_ui.$gui,
          $loot_ui.$gui, $grab_source, data))
    {
      cs = 2;
    }

    {p++; goto _out; }
  }
	goto _again;
f6:
#line 57 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(inv_drop, (_ps));
    if(UISystem::loot_drop($loot_ui.$gui,
          $status_ui.$gui, $grab_source, data))
    {
      cs = 2;
    }

    {p++; goto _out; }
  }
	goto _again;
f7:
#line 68 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(at_end, (_ps));
    fmt::println("> AT END");
    $grab_source = std::nullopt;
    $at_end = true;
    {p++; goto _out; }
  }
	goto _again;
f4:
#line 83 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(mouse_click, (_ps));
    mouse_action(false);
    {p++; goto _out; }
  }
	goto _again;
f5:
#line 89 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(mouse_move, (_ps));
    if($grab_source) {
      auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
      source.move($window.mapPixelToCoords($router.position));
    }
    mouse_action(true);
    {p++; goto _out; }
  }
	goto _again;
f10:
#line 27 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(loot_close, (_ps));
    $loot_ui.active = false;
    {p++; goto _out; }
  }
#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(not_end, (_ps));
    fmt::println("% NOT_END");
    $at_end = false;
    {p++; goto _out; }
  }
	goto _again;
f11:
#line 33 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(loot_grab, (_ps));
    // NOTE: when grab_source could work to do the if that was here
    $grab_source = UISystem::loot_grab($loot_ui.$gui, data);
    {p++; goto _out; }
  }
#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(not_end, (_ps));
    fmt::println("% NOT_END");
    $at_end = false;
    {p++; goto _out; }
  }
	goto _again;
f12:
#line 40 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(inv_grab, (_ps));
    $grab_source = UISystem::loot_grab($status_ui.$gui, data);
    {p++; goto _out; }
  }
#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(not_end, (_ps));
    fmt::println("% NOT_END");
    $at_end = false;
    {p++; goto _out; }
  }
	goto _again;
f16:
#line 57 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(inv_drop, (_ps));
    if(UISystem::loot_drop($loot_ui.$gui,
          $status_ui.$gui, $grab_source, data))
    {
      cs = 2;
    }

    {p++; goto _out; }
  }
#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(not_end, (_ps));
    fmt::println("% NOT_END");
    $at_end = false;
    {p++; goto _out; }
  }
	goto _again;
f8:
#line 68 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(at_end, (_ps));
    fmt::println("> AT END");
    $grab_source = std::nullopt;
    $at_end = true;
    {p++; goto _out; }
  }
#line 33 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(loot_grab, (_ps));
    // NOTE: when grab_source could work to do the if that was here
    $grab_source = UISystem::loot_grab($loot_ui.$gui, data);
    {p++; goto _out; }
  }
	goto _again;
f13:
#line 83 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(mouse_click, (_ps));
    mouse_action(false);
    {p++; goto _out; }
  }
#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(not_end, (_ps));
    fmt::println("% NOT_END");
    $at_end = false;
    {p++; goto _out; }
  }
	goto _again;
f14:
#line 89 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(mouse_move, (_ps));
    if($grab_source) {
      auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
      source.move($window.mapPixelToCoords($router.position));
    }
    mouse_action(true);
    {p++; goto _out; }
  }
#line 76 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    _log(not_end, (_ps));
    fmt::println("% NOT_END");
    $at_end = false;
    {p++; goto _out; }
  }
	goto _again;

_again:
	if ( cs == 0 )
		goto _out;
	p += 1;
	goto _resume;
	if ( p == eof )
	{
	switch ( _DNDLoot_eof_actions[cs] ) {
	case 10:
#line 17 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"
	{
    $cur_state = (_ps);
    fmt::println("!!! ERROR fcurs={}", (_ps));
  }
	break;
#line 385 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.cpp"
	}
	}

	_out: {}
	}

#line 170 "C:/Users/lcthw/Projects/raycaster//gui/dnd_loot_2.rl"

    dbc::log(fmt::format("<<<< DND EVENT {}, state={}, cs={}, end={}",
          int(event), $cur_state, cs, $at_end));
    return $at_end;
  }
}
