src/fsmblockmap.h
author richk
Sat, 11 Aug 2007 19:57:00 +0000
branchNewGRF_ports
changeset 6782 1d546cb63611
parent 6758 1545d187ab64
child 6783 cb68d9c92570
permissions -rw-r--r--
(svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
Fix: Terminals (and especially helipads) were being incorrectly selected. Terminals may now be selected if the vehicle already owns the terminal bit.
Add: Added SetAll function if 0xFF found in blocklist.
Fix: Corrections to large airport (mostly heli-related).
6751
08176dfe64b7 (svn r10790) [NewGRF_ports] -Codechange: constify the fsmblockmaps where possible.
rubidium
parents: 6739
diff changeset
     1
/* $Id$ */
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     2
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     3
/** @file FSMblockmap.h Definition of FSMblockmap class for use in state machines*/
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     4
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     5
#ifndef FSMBLOCKMAP_H
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     6
#define FSMBLOCKMAP_H
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     7
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     8
#include "stdafx.h"
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
     9
6751
08176dfe64b7 (svn r10790) [NewGRF_ports] -Codechange: constify the fsmblockmaps where possible.
rubidium
parents: 6739
diff changeset
    10
uint64 inline GetBlockAsBits(byte blocknumber)
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    11
{
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    12
	if (blocknumber == 0) return 0ULL;
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    13
	if (blocknumber > 63) blocknumber -= 64;
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    14
	uint64 result = 1ULL << blocknumber;
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    15
	return result;
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    16
}
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    17
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    18
/**
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    19
 * This class provides functions and internal storage for blockmaps used in Finite State Machine
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    20
 *
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    21
*/
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    22
struct FSMblockmap {
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    23
public:
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    24
	void inline ResetAll()
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    25
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    26
		blocks[0] = 0x0000000000000000;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    27
		blocks[1] = 0x0000000000000000;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    28
	};
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    29
6782
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    30
	void inline SetAll()
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    31
	{
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    32
		blocks[0] = 0xFFFFFFFFFFFFFFFF;
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    33
		blocks[1] = 0xFFFFFFFFFFFFFFFF;
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    34
	};
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    35
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    36
	void Initialise(const byte *blocklist, int num_bytes)
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    37
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    38
		ResetAll();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    39
		for (int i = 0; i < num_bytes; i++) {
6782
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    40
			if (blocklist[i] == 0xFF) {
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    41
				SetAll();
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    42
				break;
1d546cb63611 (svn r10853) [NewGRF_ports] -Feature: Added heliport to airportsbasic.grf. Added Heli-EndTakeoff stage.
richk
parents: 6758
diff changeset
    43
			}
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    44
			blocks[(blocklist[i] < 64) ? 0 : 1] |= GetBlockAsBits(blocklist[i]);
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    45
		}
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    46
	}
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    47
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    48
	uint64 inline GetLower() const
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    49
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    50
		return blocks[0];
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    51
	}
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    52
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    53
	uint64 inline GetUpper() const
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    54
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    55
		return blocks[1];
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    56
	}
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    57
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    58
	void inline ReserveBlocks(const FSMblockmap *blockmap)
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    59
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    60
		/* OR with blockmap to reserve blocks */
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    61
		blocks[0] |= blockmap->GetLower();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    62
		blocks[1] |= blockmap->GetUpper();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    63
	}
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
    64
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    65
	void inline ReleaseBlocks(const FSMblockmap *blockmap)
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    66
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    67
		/* AND with ones-complement to clear set bits in blockmap from block_lower and block_upper */
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    68
		blocks[0] &= ~blockmap->GetLower();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    69
		blocks[1] &= ~blockmap->GetUpper();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    70
	}
6751
08176dfe64b7 (svn r10790) [NewGRF_ports] -Codechange: constify the fsmblockmaps where possible.
rubidium
parents: 6739
diff changeset
    71
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    72
	bool inline BlocksAreFree(const FSMblockmap *blockmap) const
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    73
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    74
		uint64 test_lower = blockmap->GetLower();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    75
		uint64 test_upper = blockmap->GetUpper();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    76
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    77
		if ((~blocks[0] & test_lower) != test_lower)  return false;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    78
		if ((~blocks[1] & test_upper) != test_upper)  return false;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    79
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    80
		return true;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    81
	}
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    82
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    83
	bool inline HasBlocks(const FSMblockmap *blockmap) const
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    84
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    85
		uint64 test_lower = blockmap->GetLower();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    86
		uint64 test_upper = blockmap->GetUpper();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    87
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    88
		if ((blocks[0] & test_lower) != test_lower)  return false;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    89
		if ((blocks[1] & test_upper) != test_upper)  return false;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    90
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    91
		return true;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    92
	}
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    93
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    94
	bool inline HasBlock(byte blocknumber) const
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    95
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    96
		FSMblockmap test_blockmap;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    97
		test_blockmap.Initialise(&blocknumber, 1);
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    98
		return HasBlocks(&test_blockmap);
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
    99
	}
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   100
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   101
	//bool inline HasBlock(byte blocknumber)
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   102
	//{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   103
	//	uint64 test_block = GetBlockAsBits(blocknumber);
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   104
	//	if (blocknumber < 64) return ((block_lower & test_block) == test_block);
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   105
	//	return ((block_upper & test_block) == test_block);
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   106
	//}
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   107
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   108
	bool inline IsNotZero(void) const
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   109
	{
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   110
		return ((blocks[0] != 0) || (blocks[1] != 0));
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   111
	}
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   112
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   113
	void PrintBlock(bool newline = true) const;
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   114
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   115
	/**
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   116
	 * Needed for an ugly hack:
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   117
	 *  - vehicles and stations need to store fsmblocks, so they use FSMBlock as container
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   118
	 *  - this internals of the container should be protected, e.g. private (or protected) by C++
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   119
	 *  - for saving/loading we need to pass pointer to objects
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   120
	 *  -> so *if* the pointer to the FSMBlock is the same as the pointer to the blocks array
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   121
	 *     encapsulated in the FSMBlock, we can just pass the FSMBlock as "offset".
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   122
	 *     Normally we would then just add the offset of the blocks variable within the class
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   123
	 *     but that is not possible because the variable is private. Furthermore we are not sure
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   124
	 *     that this works on all platforms, we need to check whether the offset is actually 0.
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   125
	 *     This cannot be done compile time, because the variable is private. So we need to write
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   126
	 *     a function that does actually check the offset runtime and call it somewhere where it
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   127
	 *     is always called but it should not be called often.
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   128
	 */
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   129
	static void AssertOnWrongBlockOffset();
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   130
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   131
private:
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6751
diff changeset
   132
	uint64 blocks[2];
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
   133
};
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
   134
6751
08176dfe64b7 (svn r10790) [NewGRF_ports] -Codechange: constify the fsmblockmaps where possible.
rubidium
parents: 6739
diff changeset
   135
FSMblockmap* SetFSMSingleBlock(const byte *blocklist);
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
   136
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents:
diff changeset
   137
#endif /* FSMBLOCKMAP_H */