diff --git a/programs/games/kosilka/History.txt b/programs/games/kosilka/History.txt new file mode 100644 index 0000000000..5816a76782 --- /dev/null +++ b/programs/games/kosilka/History.txt @@ -0,0 +1,11 @@ +17.12.08 -- v1.1 -- Leency +- избавление от полных перерисовок окна; +- устранение мерцания. + + +24.09.07 -- v1.05 -- diamond +- уменьшение размера программы, оптимизации. + + +22.09.07 -- v1.00 -- Andrey Mihaylovich (Dron2004) +- стабильная версия. \ No newline at end of file diff --git a/programs/games/kosilka/KosFile.cpp b/programs/games/kosilka/KosFile.cpp new file mode 100644 index 0000000000..1bf8c33fcd --- /dev/null +++ b/programs/games/kosilka/KosFile.cpp @@ -0,0 +1,131 @@ +#include "kosSyst.h" +#include "kosfile.h" + + +CKosFile::CKosFile(char *fileName) +{ + // + this->fileInfo.bufferPtr = new Byte[FILE_BUFFER_SIZE]; + // + this->filePointer = 0; + this->bufferPointer = 0; + this->validBuffer = false; + // + strcpy( this->fileInfo.fileURL, fileName ); +} + + +CKosFile::~CKosFile(void) +{ + // + delete this->fileInfo.bufferPtr; +} + + +void CKosFile::ValidateBuffer() +{ + // + if ( this->validBuffer ) + { + // + if ( this->filePointer < this->bufferPointer + || this->filePointer >= (this->bufferPointer + FILE_BUFFER_SIZE) ) + { + // + this->validBuffer = false; + } + } +} + + +void CKosFile::UpdateBuffer(void) +{ + // + if ( ! this->validBuffer ) + { + // + this->fileInfo.OffsetLow = this->filePointer / OS_BLOCK_SIZE; + this->fileInfo.OffsetHigh = 0; + // + this->bufferPointer = this->fileInfo.OffsetLow * OS_BLOCK_SIZE; + // + this->fileInfo.dataCount = FILE_BUFFER_BLOCKS; + // + this->fileInfo.rwMode = 0; + // + Dword rr = kos_FileSystemAccess( &(this->fileInfo) ); + this->validBuffer = ( rr == 0 ); + } +} + + +int CKosFile::Seek(int seekFrom, int seekStep) +{ + // + switch ( seekFrom ) + { + // + case SEEK_SET: + // + this->filePointer = seekStep; + break; + // + case SEEK_CUR: + // + this->filePointer += seekStep; + break; + } + // + this->ValidateBuffer(); + // + return this->filePointer; +} + + +int CKosFile::Read(Byte *targetPtr, int readCount) +{ + int bufferLeast, result; + + // + result = 0; + // + do + { + // + this->UpdateBuffer(); + // + if ( ! this->validBuffer ) return result; + // + bufferLeast = FILE_BUFFER_SIZE - (this->filePointer - this->bufferPointer); + // + if ( bufferLeast > readCount ) bufferLeast = readCount; + // + if ( bufferLeast ) + { + // + memcpy( + targetPtr, + this->fileInfo.bufferPtr + (this->filePointer - this->bufferPointer), + bufferLeast + ); + // + targetPtr += bufferLeast; + readCount -= bufferLeast; + this->filePointer += bufferLeast; + // + result += bufferLeast; + } + // + this->ValidateBuffer(); + } + while ( readCount > 0 ); + // + return result; +} + + +int CKosFile::Write(Byte *sourcePtr, int writeCount) +{ + return 0; +} + diff --git a/programs/games/kosilka/KosFile.h b/programs/games/kosilka/KosFile.h new file mode 100644 index 0000000000..5f7c18e9bc --- /dev/null +++ b/programs/games/kosilka/KosFile.h @@ -0,0 +1,26 @@ +#pragma once + +#define SEEK_SET 0 +#define SEEK_CUR 1 + +#define FILE_BUFFER_SIZE 512 +#define OS_BLOCK_SIZE 1 +#define FILE_BUFFER_BLOCKS (FILE_BUFFER_SIZE / OS_BLOCK_SIZE) + + +class CKosFile +{ +public: + CKosFile(char *fileName); + virtual ~CKosFile(void); + virtual int Read(Byte *targetPtr, int readCount); + virtual int Write(Byte *sourcePtr, int writeCount); + virtual int Seek(int seekFrom, int seekStep); +protected: + int filePointer; + int bufferPointer; + bool validBuffer; + kosFileInfo fileInfo; + virtual void ValidateBuffer(void); + virtual void UpdateBuffer(void); +}; diff --git a/programs/games/kosilka/MCSMEMM.H b/programs/games/kosilka/MCSMEMM.H new file mode 100644 index 0000000000..42d61eaadb --- /dev/null +++ b/programs/games/kosilka/MCSMEMM.H @@ -0,0 +1,28 @@ +// + +struct MemBlock +{ + Dword Size; + Dword Addr; + MemBlock *Next; + MemBlock *Previous; +}; + + +#define INITIALQUEUESIZE (32 * 4) + +#define FALSE 0 +#define TRUE -1 + +#define MB_FREE 0 +#define MB_USER 1 + +#define SIZE_ALIGN 4 + + + +Byte *allocmem( Dword reqsize ); +Dword freemem( void *vaddress ); + + + diff --git a/programs/games/kosilka/compile.bat b/programs/games/kosilka/compile.bat new file mode 100644 index 0000000000..578c08f528 --- /dev/null +++ b/programs/games/kosilka/compile.bat @@ -0,0 +1,5 @@ +cl /c /O2 /nologo kosilka.cpp kosFile.cpp kosSyst.cpp mcsmemm.cpp +link /nologo /entry:crtStartUp /subsystem:native /base:0 /fixed /align:16 /nodefaultlib kosilka.obj kosFile.obj kosSyst.obj mcsmemm.obj +pe2kos kosilka.exe kosilka +del kosilka.exe +pause \ No newline at end of file diff --git a/programs/games/kosilka/kosSyst.cpp b/programs/games/kosilka/kosSyst.cpp new file mode 100644 index 0000000000..641f4eb302 --- /dev/null +++ b/programs/games/kosilka/kosSyst.cpp @@ -0,0 +1,834 @@ +#include "kosSyst.h" +#include + +#define atexitBufferSize 32 + + +char pureCallMessage[] = "PURE function call!"; + +char *kosExePath = NULL; + +// +void (__cdecl *atExitList[atexitBufferSize])(); +int atExitFnNum = 0; +// +int __cdecl atexit( void (__cdecl *func )( void )) +{ + // + if ( atExitFnNum < atexitBufferSize ) + { + // + atExitList[atExitFnNum++] = func; + return 0; + } + else + { + return 1; + } +} + + +// +Dword RandomSeed = 1; +// +void rtlSrand( Dword seed ) +{ + RandomSeed = seed; +} +// +Dword rtlRand( void ) +{ + //маска 0x80000776 + + Dword dwi, i; + + for ( i = 0; i < 32; i++ ) + { + + dwi = RandomSeed & 0x80000776; + + __asm{ + mov eax, dwi + mov edx, eax + bswap eax + xor eax, edx + xor al, ah + setpo al + movzx eax, al + mov dwi, eax + } + + RandomSeed = ( RandomSeed << 1 ) | ( dwi & 1 ); + } + + return RandomSeed; +} + +#if _MSC_VER >= 1400 +// +void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount ) +{ + __asm{ + mov edi, dst + mov eax, dst + mov esi, src + mov ecx, bytesCount + rep movsb + } +} + +// +void memset( Byte *dst, Byte filler, Dword count ) +{ + // + __asm{ + mov edi, dst + mov al, filler + mov ecx, count + rep stosb + } +} +#endif + +// +Dword rtlInterlockedExchange( Dword *target, Dword value ) +{ +// Dword result; + + // + __asm{ + mov eax, value + mov ebx, target + xchg eax, [ebx] +// mov result, eax + } + // +// return result; +} + + +////////////////////////////////////////////////////////////////////// +// +// копирование строки +// + +char * __cdecl strcpy( char *target, const char *source ) +{ + char *result = target; + + while( target[0] = source[0] ) + { + target++; + source++; + } + + return result; +} + + +////////////////////////////////////////////////////////////////////// +// +// реверсивный поиск символа +// + +char * __cdecl strrchr( const char * string, int c ) +{ + char *cPtr; + + // + for ( cPtr = (char *)string + strlen( string ); cPtr >= string; cPtr-- ) + { + // + if ( *cPtr == c ) return cPtr; + } + // + return NULL; +} + + +////////////////////////////////////////////////////////////////////// +// +// определение длины строки +// + +int __cdecl strlen( const char *line ) +{ + int i; + + for( i=0; line[i] != 0; i++ ); + return i; +} + + + +////////////////////////////////////////////////////////////////////// +// +// перевод шестнадцатиричного числа в символ +// + +unsigned int num2hex( unsigned int num ) +{ + if( num < 10 ) + return num + '0'; + return num - 10 + 'A'; +} + + +////////////////////////////////////////////////////////////////////// +// +// вывод строки на печать +// + +Dword dectab[] = { 1000000000, 100000000, 10000000, 1000000, 100000, + 10000, 1000, 100, 10, 0 }; + +// +void sprintf( char *Str, char* Format, ... ) +{ + int i, fmtlinesize, j, k, flag; + Dword head, tail; + char c; + va_list arglist; + // + va_start(arglist, Format); + + // + fmtlinesize = strlen( Format ); + // + if( fmtlinesize == 0 ) return; + + // + for( i = 0, j = 0; i < fmtlinesize; i++ ) + { + // + c = Format[i]; + // + if( c != '%' ) + { + Str[j++] = c; + continue; + } + // + i++; + // + if( i >= fmtlinesize ) break; + + // + flag = 0; + // + c = Format[i]; + // + switch( c ) + { + // + case '%': + Str[j++] = c; + break; + // вывод строки + case 'S': + Byte* str; + str = va_arg(arglist, Byte*); + for( k = 0; ( c = str[k] ) != 0; k++ ) + { + Str[j++] = c; + } + break; + // вывод байта + case 'B': + k = va_arg(arglist, int) & 0xFF; + Str[j++] = num2hex( ( k >> 4 ) & 0xF ); + Str[j++] = num2hex( k & 0xF ); + break; + // вывод символа + case 'C': + Str[j++] = va_arg(arglist, int) & 0xFF; + break; + // вывод двойного слова в шестнадцатиричном виде + case 'X': + Dword val; + val = va_arg(arglist, Dword); + for( k = 7; k >= 0; k-- ) + { + // + c = num2hex ( ( val >> (k * 4) ) & 0xF ); + // + if( c == '0' ) + { + if( flag ) Str[j++] = c; + } + else + { + flag++; + Str[j++] = c; + } + } + // + if( flag == 0 ) Str[j++] = '0'; + break; + // вывод двойного слова в десятичном виде + case 'U': + head = va_arg(arglist, Dword); + tail = 0; + for( k = 0; dectab[k] != 0; k++ ) + { + tail = head % dectab[k]; + head /= dectab[k]; + c = head + '0'; + if( c == '0' ) + { + if( flag ) Str[j++] = c; + } + else + { + flag++; + Str[j++] = c; + } + // + head = tail; + } + // + c = head + '0'; + Str[j++] = c; + break; + // вывод 64-битного слова в шестнадцатиричном виде + case 'Q': + unsigned int low_dword, high_dword; + low_dword = va_arg(arglist, unsigned int); + high_dword = va_arg(arglist, unsigned int); + for( k = 7; k >= 0; k-- ) + { + // + c = num2hex ( ( ( high_dword + 1) >> (k * 4) ) & 0xF ); + // + if( c == '0' ) + { + if( flag ) Str[j++] = c; + } + else + { + flag++; + Str[j++] = c; + } + } + // + for( k=7; k >= 0; k-- ) + { + // + c = num2hex ( ( low_dword >> (k * 4) ) & 0xF ); + // + if( c == '0' ) + { + if( flag ) Str[j++] = c; + } + else + { + flag++; + Str[j++] = c; + } + } + // + if( flag == 0 ) Str[j++] = '0'; + // + break; + // + default: + break; + } + } + // + Str[j] = 0; +} + + +// функция -1 завершения процесса +void kos_ExitApp() +{ + int i; + + // + for ( i = atExitFnNum - 1; i >= 0; i-- ) + { + // + atExitList[i](); + } + // + __asm{ + mov eax, -1 + int 0x40 + } +} + + +// функция 0 +void kos_DefineAndDrawWindow( + Word x, Word y, + Word sizeX, Word sizeY, + Byte mainAreaType, + Dword mainAreaColour, + Byte headerType, + Dword headerColour, + Dword borderColour + ) +{ + Dword arg1, arg2, arg3, arg4; + + // + arg1 = ( x << 16 ) + sizeX; + arg2 = ( y << 16 ) + sizeY; + arg3 = ( mainAreaType << 24 ) | mainAreaColour; + arg4 = ( headerType << 24 ) | headerColour; + // + __asm{ + mov eax, 0 + mov ebx, arg1 + mov ecx, arg2 + mov edx, arg3 + mov esi, arg4 + mov edi, borderColour + int 0x40 + } +} + + +// функция 1 поставить точку +void kos_PutPixel( Dword x, Dword y, Dword colour ) +{ + // + __asm{ + mov eax, 1 + mov ebx, x + mov ecx, y + mov edx, colour + int 0x40 + } +} + + +// функция 2 получить код нажатой клавиши +bool kos_GetKey( Byte &keyCode ) +{ + Dword result; + + // + __asm{ + mov eax, 2 + int 0x40 + mov result, eax + } + // + keyCode = result >> 8; + // + return ( result & 0xFF ) == 0; +} + + +// функция 3 получить время +Dword kos_GetSystemClock() +{ +// Dword result; + + // + __asm{ + mov eax, 3 + int 0x40 +// mov result, eax + } + // +// return result; +} + + +// функция 4 +void kos_WriteTextToWindow( + Word x, + Word y, + Byte fontType, + Dword textColour, + char *textPtr, + Dword textLen + ) +{ + Dword arg1, arg2; + + // + arg1 = ( x << 16 ) | y; + arg2 = ( fontType << 24 ) | textColour; + // + __asm{ + mov eax, 4 + mov ebx, arg1 + mov ecx, arg2 + mov edx, textPtr + mov esi, textLen + int 0x40 + } +} + + +// функция 5 пауза, в сотых долях секунды +void kos_Pause( Dword value ) +{ + // + __asm{ + mov eax, 5 + mov ebx, value + int 0x40 + } +} + + +// функция 7 нарисовать изображение +void kos_PutImage( RGB * imagePtr, Word sizeX, Word sizeY, Word x, Word y ) +{ + Dword arg1, arg2; + + // + arg1 = ( sizeX << 16 ) | sizeY; + arg2 = ( x << 16 ) | y; + // + __asm{ + mov eax, 7 + mov ebx, imagePtr + mov ecx, arg1 + mov edx, arg2 + int 0x40 + } +} + + + +// функция 8 определить кнопку +void kos_DefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour ) +{ + Dword arg1, arg2; + + // + arg1 = ( x << 16 ) | sizeX; + arg2 = ( y << 16 ) | sizeY; + // + __asm{ + mov eax, 8 + mov ebx, arg1 + mov ecx, arg2 + mov edx, buttonID + mov esi, colour + int 0x40 + } +} + + +// функция 9 - информация о процессе +Dword kos_ProcessInfo( sProcessInfo *targetPtr, Dword processID ) +{ +// Dword result; + + // + __asm{ + mov eax, 9 + mov ebx, targetPtr + mov ecx, processID + int 0x40 +// mov result, eax + } + // +// return result; +} + + +// функция 10 +Dword kos_WaitForEvent() +{ +// Dword result; + + __asm{ + mov eax, 10 + int 0x40 +// mov result, eax + } + +// return result; +} + + +// функция 11 +Dword kos_CheckForEvent() +{ +// Dword result; + + __asm{ + mov eax, 11 + int 0x40 +// mov result, eax + } + +// return result; +} + + +// функция 12 +void kos_WindowRedrawStatus( Dword status ) +{ + __asm{ + mov eax, 12 + mov ebx, status + int 0x40 + } +} + + +// функция 13 нарисовать полосу +void kos_DrawBar( Word x, Word y, Word sizeX, Word sizeY, Dword colour ) +{ + Dword arg1, arg2; + + // + arg1 = ( x << 16 ) | sizeX; + arg2 = ( y << 16 ) | sizeY; + // + __asm{ + mov eax, 13 + mov ebx, arg1 + mov ecx, arg2 + mov edx, colour + int 0x40 + } +} + + +// функция 17 +bool kos_GetButtonID( Dword &buttonID ) +{ + Dword result; + + // + __asm{ + mov eax, 17 + int 0x40 + mov result, eax + } + // + buttonID = result >> 8; + // + return (result & 0xFF) == 0; +} + + +// функция 23 +Dword kos_WaitForEvent( Dword timeOut ) +{ +// Dword result; + + __asm{ + mov eax, 23 + mov ebx, timeOut + int 0x40 +// mov result, eax + } + +// return result; +} + + +// получение информации о состоянии "мыши" функция 37 +void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY ) +{ + Dword mB; + Word curX; + Word curY; + sProcessInfo sPI; + + // + __asm{ + mov eax, 37 + mov ebx, 0 + int 0x40 + mov curY, ax + shr eax, 16 + mov curX, ax + mov eax, 37 + mov ebx, 2 + int 0x40 + mov mB, eax + } + // + kos_ProcessInfo( &sPI ); + // + buttons = mB; + cursorX = curX - sPI.processInfo.x_start; + cursorY = curY - sPI.processInfo.y_start; +} + + +// функция 40 установить маску событий +void kos_SetMaskForEvents( Dword mask ) +{ + // + __asm{ + mov eax, 40 + mov ebx, mask + int 0x40 + } +} + + +// функция 47 вывести в окно приложения число +void kos_DisplayNumberToWindow( + Dword value, + Dword digitsNum, + Word x, + Word y, + Dword colour, + eNumberBase nBase, + bool valueIsPointer + ) +{ + Dword arg1, arg2; + + // + arg1 = ( valueIsPointer ? 1 : 0 ) | + ( ((Byte)nBase) << 8 ) | + ( ( digitsNum & 0x1F ) << 16 ); + arg2 = ( x << 16 ) | y; + // + __asm{ + mov eax, 47 + mov ebx, arg1 + mov ecx, value + mov edx, arg2 + mov esi, colour + int 0x40 + } +} + +// функция 70 доступ к файловой системе +Dword kos_FileSystemAccess( kosFileInfo *fileInfo ) +{ +// Dword result; + + // + __asm{ + mov eax, 70 + mov ebx, fileInfo + int 0x40 +// mov result, eax + } + // +// return result; +} + + +// функция 63 вывод символя в окно отладки +void kos_DebugOutChar( char ccc ) +{ + // + __asm{ + mov eax, 63 + mov ebx, 1 + mov cl, ccc + int 0x40 + } +} + + +// функция 66 режим получения данных от клавиатуры +void kos_SetKeyboardDataMode( Dword mode ) +{ + // + __asm{ + mov eax, 66 + mov ebx, 1 + mov ecx, mode + int 0x40 + } +} + + +// вывод строки в окно отладки +void rtlDebugOutString( char *str ) +{ + // + for ( ; str[0] != 0; str++ ) + { + kos_DebugOutChar( str[0] ); + } + // + kos_DebugOutChar( 13 ); + kos_DebugOutChar( 10 ); +} + + +// функция 64 изменение количества памяти, выделенной для программы +bool kos_ApplicationMemoryResize( Dword targetSize ) +{ + Dword result; + + // + __asm{ + mov eax, 64 + mov ebx, 1 + mov ecx, targetSize + int 0x40 + mov result, eax + } + // + return result == 0; +} + + +// функция 67 изменить параметры окна, параметр == -1 не меняется +void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY ) +{ + // + __asm{ + mov eax, 67 + mov ebx, x + mov ecx, y + mov edx, sizeX + mov esi, sizeY + int 0x40 + } +} + + + +// вызов абстрактного метода +int __cdecl _purecall() +{ + rtlDebugOutString( pureCallMessage ); + kos_ExitApp(); + return 0; +} + + +// вызов статических инициализаторов +// заодно инициализация генератора случайных чисел +//#pragma section(".CRT$XCA",long,read,write) +//#pragma section(".CRT$XCZ",long,read,write) +#pragma data_seg(".CRT$XCA") +#pragma data_seg(".CRT$XCZ") +typedef void (__cdecl *_PVFV)(void); +__declspec(allocate(".CRT$XCA")) _PVFV __xc_a[1] = { NULL }; +__declspec(allocate(".CRT$XCZ")) _PVFV __xc_z[1] = { NULL }; +// +#pragma comment(linker, "/merge:.CRT=.rdata") +// +void crtStartUp() +{ + // вызываем инициализаторы по списку, NULL'ы игнорируем + for ( _PVFV *pbegin = __xc_a; pbegin < __xc_z; pbegin++ ) + { + // + if ( *pbegin != NULL ) + (**pbegin)(); + } + // инициализируем генератор случайных чисел + rtlSrand( kos_GetSystemClock() ); + // путь к файлу процесса + kosExePath = *((char **)0x20); + // вызов главной функции приложения + kos_Main(); + // выход + kos_ExitApp(); +} + + diff --git a/programs/games/kosilka/kosSyst.h b/programs/games/kosilka/kosSyst.h new file mode 100644 index 0000000000..5772c47e05 --- /dev/null +++ b/programs/games/kosilka/kosSyst.h @@ -0,0 +1,209 @@ +typedef unsigned __int32 Dword; +typedef unsigned __int16 Word; +typedef unsigned __int8 Byte; +//typedef unsigned __int32 size_t; + +#define NULL 0 + +#define MAX_PATH 256 + +#define FO_READ 0 +#define FO_WRITE 2 + +#define EM_WINDOW_REDRAW 1 +#define EM_KEY_PRESS 2 +#define EM_BUTTON_CLICK 4 +#define EM_APP_CLOSE 8 +#define EM_DRAW_BACKGROUND 16 +#define EM_MOUSE_EVENT 32 +#define EM_IPC 64 +#define EM_NETWORK 256 + +#define KM_CHARS 0 +#define KM_SCANS 1 + +#define WRS_BEGIN 1 +#define WRS_END 2 + +#define PROCESS_ID_SELF -1 + +#define abs(a) (a<0?0-a:a) + +extern "C" double acos(double x); +extern "C" double asin(double x); +extern "C" double floor(double x); +extern "C" double round(double x); +#pragma function(acos,asin) +#if _MSC_VER > 1200 +#pragma function(floor) +#endif + + +struct kosFileInfo +{ + Dword rwMode; + Dword OffsetLow; + Dword OffsetHigh; + Dword dataCount; + Byte *bufferPtr; + char fileURL[MAX_PATH]; +}; + + +struct RGB +{ + Byte b; + Byte g; + Byte r; + // + RGB() {}; + // + RGB( Dword value ) + { + r = (Byte)(value >> 16); + g = (Byte)(value >> 8); + b = (Byte)value; + }; + // + bool operator != ( RGB &another ) + { + return this->b != another.b || this->g != another.g || this->r != another.r; + }; + // + bool operator == ( RGB &another ) + { + return this->b == another.b && this->g == another.g && this->r == another.r; + }; +}; + + +union sProcessInfo +{ + Byte rawData[1024]; + struct + { + Dword cpu_usage; + Word window_stack_position; + Word window_stack_value; + Word reserved1; + char process_name[12]; + Dword memory_start; + Dword used_memory; + Dword PID; + Dword x_start; + Dword y_start; + Dword x_size; + Dword y_size; + Word slot_state; + } processInfo; +}; + +// +extern char *kosExePath; + +// +void crtStartUp(); +// +int __cdecl _purecall(); +// +int __cdecl atexit( void (__cdecl *func )( void )); +// +void rtlSrand( Dword seed ); +Dword rtlRand( void ); +// +char * __cdecl strcpy( char *target, const char *source ); +int __cdecl strlen( const char *line ); +char * __cdecl strrchr( const char * string, int c ); + +#if _MSC_VER < 1400 +extern "C" void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount ); +extern "C" void memset( Byte *dst, Byte filler, Dword count ); +#pragma intrinsic(memcpy,memset) +#else +void * __cdecl memcpy( void *dst, const void *src, size_t bytesCount ); +void memset( Byte *dst, Byte filler, Dword count ); +#endif + +void sprintf( char *Str, char* Format, ... ); +// +Dword rtlInterlockedExchange( Dword *target, Dword value ); +// функция -1 завершения процесса +void kos_ExitApp(); +// функция 0 +void kos_DefineAndDrawWindow( + Word x, Word y, + Word sizeX, Word sizeY, + Byte mainAreaType, Dword mainAreaColour, + Byte headerType, Dword headerColour, + Dword borderColour + ); +// функция 1 поставить точку +void kos_PutPixel( Dword x, Dword y, Dword colour ); +// функция 2 получить код нажатой клавиши +bool kos_GetKey( Byte &keyCode ); +// функция 3 получить время +Dword kos_GetSystemClock(); +// функция 4 +void kos_WriteTextToWindow( + Word x, Word y, + Byte fontType, + Dword textColour, + char *textPtr, + Dword textLen + ); +// функция 7 нарисовать изображение +void kos_PutImage( RGB * imagePtr, Word sizeX, Word sizeY, Word x, Word y ); +// функция 8 определить кнопку +void kos_DefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour ); +// функция 5 пауза, в сотых долях секунды +void kos_Pause( Dword value ); +// функция 9 - информация о процессе +Dword kos_ProcessInfo( sProcessInfo *targetPtr, Dword processID = PROCESS_ID_SELF ); +// функция 10 +Dword kos_WaitForEvent(); +// функция 11 +Dword kos_CheckForEvent(); +// функция 12 +void kos_WindowRedrawStatus( Dword status ); +// функция 13 нарисовать полосу +void kos_DrawBar( Word x, Word y, Word sizeX, Word sizeY, Dword colour ); +// функция 17 +bool kos_GetButtonID( Dword &buttonID ); +// функция 23 +Dword kos_WaitForEvent( Dword timeOut ); +// +enum eNumberBase +{ + nbDecimal = 0, + nbHex, + nbBin +}; +// получение информации о состоянии "мыши" функция 37 +void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY ); +// функция 40 установить маску событий +void kos_SetMaskForEvents( Dword mask ); +// функция 47 вывести в окно приложения число +void kos_DisplayNumberToWindow( + Dword value, + Dword digitsNum, + Word x, + Word y, + Dword colour, + eNumberBase nBase = nbDecimal, + bool valueIsPointer = false + ); +// функция 58 доступ к файловой системе +Dword kos_FileSystemAccess( kosFileInfo *fileInfo ); +// функция 63 +void kos_DebugOutChar( char ccc ); +// +void rtlDebugOutString( char *str ); +// функция 64 изменить параметры окна, параметр == -1 не меняется +void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY ); +// функция 67 изменение количества памяти, выделенной для программы +bool kos_ApplicationMemoryResize( Dword targetSize ); +// функция 66 режим получения данных от клавиатуры +void kos_SetKeyboardDataMode( Dword mode ); + +// +void kos_Main(); diff --git a/programs/games/kosilka/kosilka.cpp b/programs/games/kosilka/kosilka.cpp new file mode 100644 index 0000000000..c6e5a7c3c9 --- /dev/null +++ b/programs/games/kosilka/kosilka.cpp @@ -0,0 +1,1464 @@ +/* ------- КОСИЛКА ДЛЯ КОЛИБРИ ------- +Игра пишется на C++ (используется MS Visual C++ 6.0). +Это - исходник версии 1.0. + + Andrey Mihaylovich aka Dron2004 + */ + + + +#include "kosSyst.h" +#include "kosFile.h" + + + +//ВНЕШНИЕ УРОВНИ +bool external_levels_available=false; +bool external_levels = false; +int level_read_result; +Byte * externallevels; +Byte external_levels_count[1] = {0}; +///////////////// + +int lastkosilkadirection=1; +int laststep=0; //Последний ход. Здесь + // 0 - нет такового + // 1 - вниз + // 2 - вверх + // 3 - влево + // 4 - вправо + + +Byte skindata[13824]; +int read_result=0; +bool skin_available=false; +bool w_redraw=true; + +const char windowTitle[]="Љ®бЁ«Є  ¤«п Љ®«ЁЎаЁ"; +const char version[]="‚ҐабЁп 1.1"; +int levelcount=7; //Число уровней + +char gamearea[20][20]; //Карта + + +short int kosilkax; // Положение косилки +short int kosilkay; +short int kosilkadirection=1; //Направление прошлого шага. 1-вниз, 2-вверх, 3-влево, 4-вправо +short int lives=2; // Жизни +short int level=1; //Уровень +short int status=0; //Где 0 - приветствие + // 1 - игра + // 2 - игра пройдена + // 3 - вы проиграли + // 4 - выбор набора уровней (встроенный или внешний) + // -1 - о программе +bool gamestarted=false; //Блокировка игровых клавиш. Если false - играть нельзя + +bool drawgraphics=true; //Рисовать ли детальную графику (или ограничиться аскетичной) +bool drawanimation=true; //Анимировать ли +bool skinned=false; +int grassLeft(); //Сообщим о наличии функции Grass Left + +//Графика игры + +RGB kosilka_d[576]; +RGB kosilka_l[576]; +RGB kosilka_r[576]; +RGB kosilka_u[576]; +RGB grass[576]; +RGB stone[576]; +RGB tree[576]; +RGB skos[576]; + +Byte kosilka_d1[]={0,1,2,3,4,5,5,6,6,6,5,5,5,5,5,6,5,5,5,4,2,2,1,7,1,2,4,6,21 +,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,6,5,2,40,1,4,62,63,63,64,65,66,66 +,67,66,66,66,66,68,66,66,63,69,65,65,62,4,1,2,6,75,91,64,65,67,92,75,75,75,75,75 +,75,75,75,75,93,65,94,94,62,6,2,3,6,76,94,96,67,103,104,104,104,104,104,104,105 +,106,107,108,109,93,63,64,75,6,3,3,21,75,94,94,67,115,104,104,104,104,105,105 +,106,107,108,116,117,92,65,96,76,21,4,3,21,62,64,63,78,115,105,105,105,105,106 +,107,108,116,116,119,120,92,65,96,77,6,3,4,6,62,96,69,67,123,106,106,107,107,108 +,108,116,119,119,127,124,92,66,64,77,21,4,3,21,62,64,91,67,123,107,108,108,116 +,116,119,119,127,127,127,124,75,69,64,77,21,4,4,6,62,64,69,68,123,108,116,119 +,119,127,127,127,129,129,129,125,93,63,64,77,21,4,4,21,62,64,91,67,123,119,119 +,127,127,129,129,129,129,129,129,125,68,94,64,77,6,4,3,21,62,64,94,63,122,128 +,128,121,121,121,121,121,121,121,121,76,66,69,91,77,21,4,4,21,62,64,94,69,69,65 +,66,67,68,68,67,68,67,67,66,66,69,91,64,77,21,4,4,21,76,96,64,94,94,64,94,96,69 +,91,94,94,64,69,69,94,64,64,64,77,6,4,3,6,75,64,64,64,64,64,64,64,64,64,64,64,64 +,64,64,64,64,64,96,75,21,4,3,6,16,94,64,64,64,64,64,64,64,64,64,64,64,64,64,64 +,64,64,96,75,6,2,2,6,75,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62 +,6,2,1,2,33,95,111,111,111,111,79,79,79,79,79,79,79,79,111,95,79,111,95,33,32,40 +,7,42,49,44,47,72,44,47,80,49,45,72,45,70,47,47,47,46,71,45,44,49,50,15,15,43,45 +,72,70,71,44,71,43,44,44,46,47,71,49,71,45,47,45,47,80,80,110,0,15,45,45,45,44 +,44,72,72,70,45,44,71,46,71,80,44,45,47,44,71,72,71,45,9,14,45,47,72,46,73,45,47 +,72,46,45,47,45,70,43,45,45,46,47,44,43,43,42,10,8,32,42,45,46,44,43,44,44,47,45 +,45,49,44,46,46,45,44,45,44,45,42,41,9,10,114,36,36,12,10,12,14,9,11,10,36,13,11 +,10,9,13,12,11,9,10,8,8,8 +}; + +Byte kosilka_u1[]={8,9,9,10,9,11,12,13,9,10,11,13,8,10,11,9,14,12,10,12,14,8,11 +,10,9,41,42,43,44,45,44,45,46,46,44,45,45,45,47,44,44,43,44,46,45,42,32,0,14,42 +,45,43,44,47,46,45,45,43,70,45,71,45,46,72,47,45,73,46,44,71,45,14,11,45,71,72 +,71,44,47,45,44,80,71,46,71,44,45,70,72,72,44,44,45,45,45,15,0,110,80,80,71,45 +,47,45,71,49,71,47,46,44,44,43,71,44,71,70,72,43,71,15,15,50,49,44,45,71,46,47 +,47,71,70,45,72,45,49,80,47,44,72,47,44,45,50,15,1,32,121,95,111,79,95,111,79,79 +,79,79,79,79,79,79,111,111,111,111,95,121,3,1,2,5,62,96,64,64,64,64,64,64,64,64 +,64,64,64,64,64,64,64,96,96,75,5,2,2,6,75,94,64,64,64,64,64,64,64,64,64,64,64,64 +,64,64,64,64,96,76,6,3,4,21,75,96,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64 +,64,94,76,6,3,4,21,77,64,64,64,94,69,69,64,94,94,91,69,64,94,64,94,94,64,64,16 +,21,4,4,6,77,64,91,69,66,66,66,67,67,67,68,68,67,66,65,69,69,94,64,77,21,4 +,4,21,77,64,69,66,76,121,121,121,121,121,121,121,121,128,128,122,63,94,64,62,21 +,3,4,6,77,64,94,67,125,129,129,129,129,129,129,127,127,119,119,123,66,91,64,62 +,21,4,4,21,77,64,63,92,125,129,129,129,127,127,127,119,119,116,108,123,68,69,64 +,62,6,4,4,21,77,64,63,92,124,127,127,127,119,119,116,108,108,108,108,123,68,91 +,64,62,21,3,4,21,77,91,66,92,124,127,119,119,116,108,108,107,107,106,106,123,67 +,69,64,62,21,3,3,21,77,64,65,92,120,119,116,116,108,107,106,105,105,105,105,115 +,93,63,64,62,6,3,4,21,75,64,65,92,117,116,108,107,106,105,105,105,104,104,104 +,115,67,94,96,76,21,3,3,6,75,96,63,93,109,108,107,106,105,104,104,104,104,104 +,104,136,67,96,94,76,6,3,2,6,62,94,94,65,93,75,75,75,75,75,75,75,92,75,93,67,65 +,64,64,75,6,2,1,4,62,65,65,69,63,65,66,67,66,66,65,65,67,66,66,65,64,63,65,62,4 +,1,1,2,6,6,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,6,4,2,1,7,1,2,2,4,5 +,5,6,6,5,5,5,6,6,6,6,6,5,6,3,4,2,1,0 +}; + +Byte kosilka_l1[]={10,8,14,15,15,15,1,2,3,2,4,4,3,3,4,3,3,3,3,3,2,1,1,0,11,48,49 +,45,47,50,3,6,6,6,21,21,21,21,6,21,21,6,21,6,5,4,2,1,29,42,71,45,74,49,33,75,76 +,76,76,62,62,62,62,62,62,62,76,76,75,62,4,2,14,70,72,45,72,44,95,96,94,94,94,96 +,64,64,64,64,64,96,94,94,94,66,6,3,12,46,46,44,70,47,111,64,96,96,64,94,94,91,69 +,91,69,63,94,96,64,63,21,4,10,44,73,44,71,72,111,64,64,64,94,69,63,66,68,67,67 +,68,67,67,65,64,21,5,12,43,45,72,44,44,111,64,64,64,94,69,122,123,123,123,123 +,115,115,103,67,63,21,6,14,44,47,72,71,47,111,64,64,64,64,65,128,119,116,107,106 +,105,104,104,93,66,21,6,9,44,72,70,43,80,79,64,64,64,94,66,128,119,116,108,106 +,105,104,104,75,66,21,6,11,47,46,45,44,49,79,64,64,64,64,67,121,127,116,108,107 +,105,104,104,92,67,21,6,10,45,45,44,44,45,79,64,64,64,69,68,121,127,119,116,107 +,106,104,104,75,66,21,6,8,49,47,71,46,72,79,64,64,64,91,68,121,129,127,116,108 +,106,105,104,75,66,21,6,13,45,45,46,47,45,79,64,64,64,94,67,121,129,127,119,108 +,107,105,104,75,66,21,4,11,44,70,71,71,70,79,64,64,64,94,67,121,129,127,119,116 +,108,106,105,75,66,21,5,10,46,43,80,49,47,79,64,64,64,64,67,121,129,129,127,119 +,108,107,106,75,67,21,4,9,46,45,44,71,47,79,64,64,64,69,67,121,129,129,127,119 +,116,108,107,75,66,21,6,13,45,45,45,45,47,111,64,64,64,69,66,121,129,129,127,127 +,119,116,108,75,66,21,6,12,44,46,47,47,46,95,64,64,64,94,66,76,125,125,124,124 +,120,117,109,93,63,21,4,11,45,47,44,45,71,79,64,64,64,64,69,66,68,92,75,92,92,92 +,93,65,69,21,6,9,44,44,71,47,45,111,64,64,64,64,91,69,94,63,69,66,65,65,63,94,65 +,21,4,10,47,43,72,80,44,95,64,64,64,64,64,64,64,64,64,64,64,64,64,64,63,6,2,9,42 +,45,47,80,45,121,62,75,75,77,77,77,77,77,77,77,77,75,75,62,75,5,2,0,48,42,45,71 +,50,2,6,6,21,6,21,21,6,21,21,21,21,21,6,6,4,2,40,8,11,51,9,8,15,1,2,2,4,4,3,4,4 +,4,4,4,3,3,3,2,1,1,7 +}; + +Byte kosilka_r1[]={7,1,1,2,3,3,3,4,4,4,4,4,4,4,4,2,2,1,15,0,9,12,9,8,40,2,4,6,6 +,21,21,21,21,21,6,21,21,6,4,1,15,51,52,53,47,45,23,9,2,6,62,62,75,75,77,77,77,77 +,77,77,77,77,77,77,78,79,45,80,47,71,42,9,2,6,65,94,94,94,96,64,64,64,64,64,64 +,96,64,64,64,95,44,72,44,43,45,10,4,21,65,94,63,65,65,66,69,63,94,69,91,64,64,64 +,64,79,43,47,71,44,72,9,5,21,69,65,93,92,92,92,92,92,67,66,69,64,64,64,64,79,71 +,45,44,47,43,11,5,21,63,93,109,117,120,124,124,125,125,76,66,94,64,64,64,95,46 +,47,47,46,72,12,6,21,65,75,108,116,119,127,127,129,129,121,66,69,64,64,64,111,47 +,45,45,45,45,13,6,21,66,75,107,108,116,119,127,129,129,121,66,69,64,64,64,79,47 +,71,44,45,44,9,4,21,67,75,106,107,116,119,127,129,129,121,67,64,64,64,64,79,47 +,49,80,43,44,10,5,21,66,75,105,106,108,116,119,127,129,121,67,94,64,64,64,79,70 +,71,71,70,72,11,4,21,66,75,104,105,107,108,119,127,129,121,67,94,64,64,64,79,45 +,47,46,45,45,13,6,21,66,75,104,105,106,108,116,127,129,121,68,91,64,64,64,79,72 +,46,71,47,45,8,6,21,65,75,104,104,105,107,116,119,127,121,68,69,64,64,64,79,45 +,44,44,45,45,10,6,21,67,75,104,104,105,107,108,116,127,121,67,64,64,64,64,79,49 +,44,45,46,46,11,6,21,66,92,104,104,105,106,108,116,119,128,66,94,64,64,64,79,80 +,43,70,72,72,9,6,21,66,92,104,104,105,106,107,108,119,128,65,64,64,64,64,111,47 +,71,72,47,72,14,6,21,65,67,103,115,115,123,123,123,123,122,69,94,64,64,64,111,44 +,44,72,45,47,12,5,21,64,65,67,67,93,68,68,93,66,63,69,94,64,64,64,111,72,71,44 +,73,72,10,3,21,63,64,96,94,63,69,91,69,91,94,94,64,64,64,64,111,47,70,44,46,44 +,12,4,6,63,64,64,64,64,64,64,64,64,64,64,64,64,64,64,95,44,72,45,72,45,14,2,4,62 +,75,76,76,62,62,62,62,62,62,62,76,62,62,77,79,45,43,45,46,42,36,1,2,5,6,6,21,6 +,21,21,6,21,21,21,21,6,6,6,37,52,46,45,45,20,11,0,40,40,2,3,4,4,3,3,4,4,2,4,4,3 +,3,2,1,15,15,15,14,36,10 +}; + +Byte skos1[]={13,14,14,14,12,11,10,14,11,14,10,9,13,13,13,14,9,13,8,12,13,11,14 +,8,11,10,9,8,10,10,12,11,14,10,9,14,14,9,10,12,10,14,9,11,10,8,10,8,13,14,10,8 +,10,10,13,13,10,11,11,10,8,14,12,13,9,12,12,12,9,9,9,12,8,13,9,13,8,14,13,8,12 +,13,11,9,11,14,9,10,10,9,14,10,8,12,12,13,9,10,14,12,14,12,9,9,8,8,10,8,12,8,14 +,13,13,14,8,10,9,10,10,9,13,9,8,9,8,12,12,9,14,14,10,14,14,14,14,9,12,14,12,14 +,13,10,11,51,12,13,10,14,8,8,11,13,8,8,8,9,14,12,8,13,14,14,9,14,13,9,8,126 +,12,8,10,11,10,8,14,14,10,8,12,12,13,12,9,13,10,14,13,11,12,9,11,12,13,13,11,13 +,12,13,13,10,8,10,14,12,11,10,11,9,14,10,11,11,11,12,9,8,9,13,14,8,8,14,10,11,9 +,14,13,9,10,11,12,8,11,8,8,13,9,12,9,10,10,11,12,8,10,11,9,9,10,10,14,14,8,14,8 +,13,14,9,14,11,8,12,12,14,12,14,13,9,11,8,8,14,10,9,11,12,11,10,9,9,9,11,11,14 +,10,11,14,11,9,8,12,12,9,14,14,10,14,14,14,14,9,12,14,12,14,13,10,11,10,10,10,10 +,8,8,8,10,13,9,12,9,12,8,8,14,11,11,13,13,12,13,12,8,11,12,13,11,12,10,13,8,8,8 +,10,9,11,13,14,12,14,12,12,12,8,14,12,13,10,10,8,14,11,13,14,11,9,10,12,13,8,10 +,11,13,11,11,14,9,11,8,10,14,10,14,10,12,8,8,14,14,11,13,11,12,8,8,13,12,11,14,9 +,13,11,8,12,10,10,8,12,12,51,10,9,8,9,13,10,14,8,14,8,9,9,14,8,10,14,13,8,11,8 +,11,13,12,13,10,13,10,10,10,9,12,11,13,14,13,11,8,14,8,10,10,10,14,13,10,11,10 +,11,13,13,12,12,9,11,12,8,13,9,10,14,10,9,9,9,13,12,12,11,8,13,13,36,13,9,10,13 +,12,8,13,12,9,13,10,11,12,12,10,9,13,8,9,12,10,11,12,14,9,14,14,8,11,14,12,12,10 +,11,9,8,8,14,14,11,13,11,12,8,8,13,12,8,8,10,13,14,10,11,8,8,8,11,11,14,11,12,10 +,13,9,14,14,9,9,11,9,10,11,8,14,12,10,12,14,9,11,10,8,13,11,10,9,13,12,11,9,10,9 +,9,8 +}; + +Byte grass1[]={16,17,17,18,17,19,20,21,22,22,23,22,24,18,23,23,25,18,22,26,27,28 +,28,18,20,24,28,54,55,19,54,56,24,20,54,24,24,20,24,20,20,24,27,24,17,54,54,24 +,55,55,28,55,55,54,54,55,54,24,54,54,24,24,54,20,54,17,54,54,55,24,81,55,17,19 +,17,27,81,27,54,19,17,54,41,18,24,24,81,23,19,55,18,27,24,97,20,54,19,112,55,81 +,18,24,19,24,48,20,55,28,81,28,18,24,112,55,18,81,17,54,24,54,118,19,54,81,23,81 +,55,41,26,23,26,26,41,20,26,55,19,81,18,17,28,54,19,28,55,54,17,22,17,55,17,17 +,81,18,28,25,97,18,27,112,112,81,24,24,27,26,81,54,24,54,17,27,55,28,23,97,25,54 +,28,23,26,26,22,112,55,97,24,28,27,26,16,55,17,27,54,18,19,54,23,16,97,20,54,25 +,26,26,19,19,48,18,16,28,17,23,20,19,28,55,24,20,19,28,20,48,23,33,19,97,26,26 +,55,54,18,26,25,19,28,26,28,17,27,55,81,23,19,19,18,20,24,41,54,22,26,81,17,27 +,17,25,26,28,24,48,22,27,26,55,54,55,55,28,16,33,5,24,41,18,48,55,19,48,97,16,26 +,27,48,33,23,97,22,28,19,54,48,81,21,6,21,41,26,33,33,28,54,20,16,48,18,26,33,16 +,48,23,17,19,112,26,23,48,21,21,131,48,26,33,97,17,17,20,16,25,97,16,16,26,21,20 +,19,112,54,26,26,21,20,41,6,33,16,25,33,55,19,16,41,25,48,16,26,48,97,24,55,54 +,24,24,23,21,23,97,48,21,33,24,6,54,54,132,54,18,16,97,28,26,22,28,27,54,20,16 +,23,33,22,16,26,48,17,20,33,54,24,19,20,25,97,48,54,54,26,27,20,20,41,21,97,6,33 +,23,26,48,19,17,48,24,23,24,27,16,18,16,55,55,19,26,27,54,48,21,24,48,23,33,25 +,33,28,23,97,97,6,16,16,20,25,48,17,48,97,22,27,24,20,48,22,17,27,48,48,16,22,25 +,24,41,33,25,25,54,23,97,17,18,27,22,97,24,20,18,23,27,17,23,48,25,23,97,27,97 +,18,26,18,22,26,18,19,17,28,26,23,17,81,97,25,81,27,24,6,97,48,18,97,16,16,81,33 +,18,22,26,24,17,27,23,26,17,27,23,26,26,54,41,33,18,97,22,18,22,48,18,16,97,22 +,18,18,27,27,26,48,27,17,97,18,27,55,21,20,26,23,26,27,27,22,26,16,23,22,26,27 +,140,19,20 +}; + +Byte stone1[]={13,14,14,29,30,31,31,31,30,3,32,33,32,34,35,36,9,13,8,12,13,11,14 +,8,11,10,36,30,31,57,58,57,31,59,59,59,59,31,31,30,32,29,11,11,10,8,10,8,13,8,30 +,31,58,82,83,82,82,83,84,84,85,84,83,58,59,30,30,51,9,9,9,12,8,98,30,57,99,83,83 +,83,83,84,84,85,100,73,49,74,73,82,31,30,8,12,12,13,9,0,30,57,82,83,83,83,83,84 +,84,85,85,73,49,74,113,74,84,59,30,114,10,9,12,0,30,59,58,82,83,83,83,83,84,85 +,85,73,49,74,74,113,113,83,31,30,11,10,12,13,30,30,57,99,82,83,83,83,84,84,85 +,100,49,49,74,113,113,74,99,30,29,13,12,8,0,30,57,82,83,83,83,83,83,84,85,100,73 +,49,74,113,113,113,85,31,40,12,13,13,1,30,99,83,83,83,83,83,83,84,84,85,73,49,74 +,74,113,113,74,57,32,8,9,13,30,59,82,83,82,83,83,83,83,83,84,85,100,73,49,74,74 +,113,113,57,5,51,10,0,30,57,82,82,83,83,83,83,83,83,84,85,85,73,49,74,74,113,113 +,58,130,11,12,29,30,57,82,82,83,83,83,83,83,83,83,84,85,100,73,49,74,74,74,99,30 +,11,9,29,30,57,82,82,83,83,83,83,83,83,83,84,84,85,73,49,49,74,74,82,30,0,8,8,30 +,31,99,82,82,83,83,83,83,83,83,83,84,85,100,73,49,74,74,83,31,15,12,10,15,30,58 +,82,82,82,83,83,83,83,83,83,84,84,85,100,73,49,74,84,31,1,11,13,7,30,58,82,82,82 +,82,82,82,83,83,82,83,84,85,85,100,73,49,84,31,15,8,8,7,30,58,82,82,82,82,82,82 +,82,82,82,83,84,84,85,85,73,73,82,30,35,10,10,35,30,57,82,82,82,82,82,82,82,82 +,83,82,83,84,84,85,85,85,59,30,51,13,10,133,30,59,99,99,82,82,82,82,82,82,82,83 +,82,83,84,84,84,57,30,35,10,11,13,13,1,31,58,82,99,82,82,82,99,58,58,82,82,83,83 +,99,57,31,40,13,13,8,13,9,0,30,59,99,99,99,99,99,58,59,59,57,57,57,59,31,30,15 +,10,11,12,14,9,14,14,15,30,31,58,58,58,57,30,30,30,30,30,30,32,1,37,8,8,13,12,8 +,8,10,13,14,35,30,30,31,30,30,30,8,0,37,0,133,9,14,14,9,9,11,9,10,11,8,14,12,10 +,37,40,32,1,35,8,13,11,10,9,13,12,11,9,10,9,9,8 +}; + +Byte tree1[]={13,14,8,36,37,11,10,36,38,39,0,14,13,13,13,14,9,13,8,12,13,11,14,8 +,11,36,39,39,39,34,38,39,60,61,60,39,34,0,37,37,14,36,15,36,14,8,10,8,11,86,60 +,87,61,60,88,61,89,90,89,61,60,88,39,86,39,88,88,88,39,15,9,12,34,88,87,89,89 +,101,89,89,89,89,89,89,101,61,61,90,89,89,102,87,60,39,37,13,34,60,89,89,89,89 +,89,89,89,89,89,89,89,89,89,89,89,89,89,89,102,88,7,11,15,88,102,101,89,89,89,89 +,89,89,101,89,89,101,89,89,89,89,89,89,101,60,34,51,8,39,60,102,89,89,89,89,89 +,90,102,101,89,101,101,89,89,89,89,89,101,60,39,51,37,34,60,90,101,89,89,101,89 +,101,101,89,89,89,89,89,89,89,89,89,89,87,88,15,37,60,89,89,89,89,101,90,89,89 +,89,89,89,89,89,89,89,89,89,89,89,101,102,88,39,102,89,89,89,89,101,90,89,89,89 +,89,89,89,101,101,101,101,89,89,89,89,89,61,32,102,89,89,89,89,101,90,90,101,89 +,89,89,101,87,101,89,89,89,89,89,89,89,102,39,61,89,89,89,89,89,89,101,102,101 +,89,89,90,89,89,89,89,89,89,89,89,89,90,9,39,61,101,89,89,89,89,101,102,102,89 +,101,101,89,89,89,89,89,89,89,89,89,102,36,34,88,102,89,89,89,89,89,101,101,89 +,89,89,89,89,89,89,89,89,89,101,90,60,8,39,60,101,89,89,89,89,89,89,89,89,89,89 +,89,89,89,89,89,89,89,101,101,60,34,88,101,89,89,89,89,89,89,89,89,89,89,89,89 +,89,89,89,89,101,101,89,89,102,34,60,89,89,89,89,89,89,89,89,89,89,89,89,89,89 +,89,89,101,90,101,89,89,101,34,88,87,89,89,101,89,89,89,89,90,102,89,89,89,89,89 +,89,89,89,101,89,89,102,37,32,60,102,87,87,89,89,89,134,135,135,101,89,89,89,89 +,89,89,89,101,102,102,60,11,51,37,38,34,88,61,102,61,39,137,131,134,101,101,101 +,102,90,89,89,102,60,39,37,8,51,11,37,37,0,39,39,32,15,137,137,138,60,61,60,88 +,88,102,102,60,39,40,10,11,9,14,8,8,36,40,36,51,51,137,137,137,34,39,34,29,38,39 +,39,32,15,13,12,8,8,10,51,14,37,37,8,8,8,137,137,137,8,9,139,51,8,7,7,14,11,11,9 +,10,11,8,14,51,10,12,14,11,11,137,137,137,11,10,9,13,51,14,11,51,9,9,8 +}; + + +//Палитра цветов. Декодируем в 0xRRGGBB + +char * apppath; +char * levpath; +char * getSkinPathName(){ + + int lastslashindex=0; + static char skinfilename[]="kosskin.gfx"; + int tempslfnd=0; + + for (tempslfnd=0; tempslfnd < strlen(kosExePath); tempslfnd++){ + if (kosExePath[tempslfnd]=='/'){lastslashindex=tempslfnd;} + } + + apppath = new char[lastslashindex+strlen(skinfilename)+1]; + + for (tempslfnd=0; tempslfnd <= lastslashindex; tempslfnd++){ + apppath[tempslfnd]=kosExePath[tempslfnd]; + } + for (tempslfnd=0; tempslfnd < strlen(skinfilename); tempslfnd++){ + apppath[tempslfnd+lastslashindex+1]=skinfilename[tempslfnd]; + } + + + return apppath; + + +} + +char * getLevelsPathName(){ + + int lastslashindex=0; + static char levfilename[]="koslevel.pak"; + int tempslfnd=0; + + for (tempslfnd=0; tempslfnd < strlen(kosExePath); tempslfnd++){ + if (kosExePath[tempslfnd]=='/'){lastslashindex=tempslfnd;} + } + + levpath = new char[lastslashindex+strlen(levfilename)+1]; + + for (tempslfnd=0; tempslfnd <= lastslashindex; tempslfnd++){ + levpath[tempslfnd]=kosExePath[tempslfnd]; + } + for (tempslfnd=0; tempslfnd < strlen(levfilename); tempslfnd++){ + levpath[tempslfnd+lastslashindex+1]=levfilename[tempslfnd]; + } + + return levpath; + + +} + + +void decode_graphics(Byte * source, RGB * target){ + static RGB palette[] = { + 0x978A31,0x8B7F2E,0x867B2B,0x82762B,0x7F7428,0x79702B,0x766C26,0x90832E, + 0x978A2F,0x9A8C31,0x9B8D32,0x998C31,0x9C8E33,0x9D8F34,0x988B30,0x928531, + 0x887532,0xBAA454,0xA18C3D,0xC6B26A,0xA08E46,0x6B5F26,0xAF9844,0x9C873B, + 0xAB964D,0x988338,0xA89140,0xB49D4C,0xC1AC5C,0x94872F,0x303030,0x343435, + 0x827933,0x806E2F,0x8B8134,0x938632,0x96892F,0x988C33,0x8F873B,0x7E9F39, + 0x8E812D,0x92803F,0x75715C,0x676462,0x6D6A68,0x666260,0x6B6866,0x6A6664, + 0x8E7B35,0x626161,0x797641,0x9B8E33,0x7F7954,0x776A67,0xB29E55,0xBCA75E, + 0x978C3E,0x3E3E3D,0x434245,0x373938,0x3C9737,0x209437,0xB97934,0xE6863E, + 0xF28C41,0xE2833D,0xDD803B,0xD77C3A,0xD17938,0xEA883F,0x605D5B,0x686563, + 0x706D6B,0x5F5F5E,0x656566,0xB56931,0xAC663B,0xC17D36,0xC88338,0x997246, + 0x737271,0xA89546,0x4D4D4E,0x515152,0x565656,0x5A5A59,0x687B41,0x098933, + 0x5B9B38,0x009036,0x069136,0xF18B41,0xC27034,0xCD7737,0xEE8A40,0xA0774B, + 0xF18C41,0x948037,0x988B34,0x49484A,0x5D5D5D,0x039036,0x0E9236,0xB06B7B, + 0x949CF8,0x7C85F6,0x6A74F5,0x5A66F4,0x4653F1,0x5F53B6,0x726462,0x9C7449, + 0xD0C472,0x696969,0x998B32,0x9D6676,0x3B47DD,0x5349A0,0xD8CD77,0x343EC1, + 0x4F438C,0x8E5538,0xC37341,0x895D71,0x483B74,0x433359,0x9C8D34,0x2A329A, + 0x995F49,0x1D236D,0x756E37,0x524819,0x8D8848,0x9B8D34,0x157F2F,0x2D6C28, + 0xAA778B,0x663C15,0x4E5924,0x9D8F31,0xBCAD48 + }; + + for (int lc=0;lc<576;lc++) + target[lc] = palette[source[lc]]; +} + + +void interlevelpause(){ //Пауза между уровнями + Byte tempCode; + RGB tmprgb; + int tmpa=0; + laststep=0; + static int yellow_pal[] = {0xA8A93D,0xBEBF4C,0xD6D856,0xDFE15A,0xECEE5B, + 0xECEE5B,0xDFE15A,0xD6D856,0xBEBF4C,0xA8A93D}; + for (int iic=0;iic<240;iic++){ + kos_WaitForEvent(1); + kos_GetKey(tempCode); + + kos_DrawBar(iic*2,0,2,480,yellow_pal[tmpa]); + + tmpa++; + if (tmpa>9){tmpa=0;} + } +} + +void draw_element(int elx, int ely){ //Отрисовка элемента карты +switch (gamearea[elx][ely]){ + case 'g': + if (drawgraphics==true){ + kos_PutImage((RGB*)grass,24,24,elx*24,ely*24); + } + else + { + kos_DrawBar(elx*24,ely*24,24,24,0xAAAA00); + } + + break; + case 'k': + if (drawgraphics==true){ + switch(kosilkadirection){ + case 1: + kos_PutImage((RGB*)kosilka_d,24,24,elx*24,ely*24); + break; + case 2: + kos_PutImage((RGB*)kosilka_u,24,24,elx*24,ely*24); + break; + case 3: + kos_PutImage((RGB*)kosilka_l,24,24,elx*24,ely*24); + break; + case 4: + kos_PutImage((RGB*)kosilka_r,24,24,elx*24,ely*24); + break; + } + + + } + else + { + kos_DrawBar(elx*24,ely*24,24,24,0x00AAAA); + } + + + + break; + case 'n': + if (drawgraphics==true){ + kos_PutImage((RGB*)skos,24,24,elx*24,ely*24); + } + else + { + kos_DrawBar(elx*24,ely*24,24,24,0xAAAAAA); + } + + + break; + case 's': + if (drawgraphics==true){ + kos_PutImage((RGB*)stone,24,24,elx*24,ely*24); + } + else + { + kos_DrawBar(elx*24,ely*24,24,24,0x555555); + } + + + break; + + case 't': + if (drawgraphics==true){ + kos_PutImage((RGB*)tree,24,24,elx*24,ely*24); + } + else + { + kos_DrawBar(elx*24,ely*24,24,24,0x005500); + } + + + break; + + } + +} + + +void display_grass_left(){ //Выводим на экран количество оставшейся травы + kos_DrawBar(605,120,20,10,0xEEEEEE); + kos_DisplayNumberToWindow(grassLeft(),3,605,120,0x0000FF,nbDecimal,false); +} + + +void animate(int initcellx, int initcelly, int direction){ //анимация движения косилки + int tmpp=0; + + switch (direction){ + case 1: + for (tmpp=0; tmpp<23;tmpp++){ + if (drawgraphics==true){ + kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); + kos_PutImage((RGB*)kosilka_d,24,24,initcellx*24,initcelly*24+tmpp); + } else { + kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); + kos_DrawBar(initcellx*24,initcelly*24+tmpp,24,24,0x00AAAA); + + } + kos_Pause(1); + } + break; + case 2: + for (tmpp=0; tmpp<23;tmpp++){ + if (drawgraphics==true){ + kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); + kos_PutImage((RGB*)kosilka_u,24,24,initcellx*24,initcelly*24-tmpp); + } else { + kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); + kos_DrawBar(initcellx*24,initcelly*24-tmpp,24,24,0x00AAAA); + } + kos_Pause(1); + } + break; + case 3: + for (tmpp=0; tmpp<23;tmpp++){ + if (drawgraphics==true){ + kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); + kos_PutImage((RGB*)kosilka_r,24,24,initcellx*24+tmpp,initcelly*24); + } else { + kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); + kos_DrawBar(initcellx*24+tmpp,initcelly*24,24,24,0x00AAAA); + + } + kos_Pause(1); + } + break; + case 4: + for (tmpp=0; tmpp<23;tmpp++){ + if (drawgraphics==true){ + kos_PutImage((RGB*)skos,24,24,initcellx*24,initcelly*24); + kos_PutImage((RGB*)kosilka_l,24,24,initcellx*24-tmpp,initcelly*24); + } else { + kos_DrawBar(initcellx*24,initcelly*24,24,24,0xAAAAAA); + kos_DrawBar(initcellx*24-tmpp,initcelly*24,24,24,0x00AAAA); + + } + kos_Pause(1); + } + break; + } + + +} + + +void draw_window(void){ //Перерисовка окна + //----Leency + if (w_redraw) + { + kos_WindowRedrawStatus(1); //Начало перерисовки + kos_DefineAndDrawWindow(50,50,640,506,0x74,0xEEEEEE,0,0,(Dword)windowTitle); + } + w_redraw=false; + + + //Перерисовка карты + if ((status!=0)&&(status!=-1)&&(status!=4)) + { + kos_DrawBar(631-151,0,151,480,0xEEEEEE); + + kos_WriteTextToWindow(505,30,0x80, 0 ,"Љ Ћ ‘ € ‹ Љ Ђ",19); + kos_WriteTextToWindow(522,40,0x80, 0 ,"¤«п Љ®«ЁЎаЁ Ћ‘",14); + + kos_WriteTextToWindow(495,80,0x80, 0 ,"“а®ўҐ­м:",6); + kos_DisplayNumberToWindow(level,3,605,80,0x0000FF,nbDecimal,false); + + kos_WriteTextToWindow(495,95,0x80, 0 ,"Ћбв «®бм Ї®Їлв®Є:",11); + kos_DisplayNumberToWindow(lives,1,605,95,0x0000FF,nbDecimal,false); + + kos_WriteTextToWindow(495,120,0x80, 0 ,"Ћбв «®бм ва ўл:",11); + display_grass_left(); + + kos_WriteTextToWindow(526,450,0x80, 0 ,(char*)version,12); + + for (int cy=0;cy<20;cy++) for (int cx=0;cx<20;cx++) draw_element(cx,cy); + } + + if (status==0){ + kos_DrawBar(0,0,4,480,0x000000); + kos_DrawBar(628,0,3,480,0x000000); + //Leency---- + + + for (int tmpppy=0;tmpppy<20;tmpppy++){ + for (int tmpppx=0;tmpppx<26;tmpppx++){ + if ((tmpppx==0) || (tmpppx==25) || (tmpppy==0) || (tmpppy==19)){ + kos_PutImage((RGB*)stone,24,24,4+tmpppx*24,tmpppy*24); + } + else + { + kos_PutImage((RGB*)skos,24,24,4+tmpppx*24,tmpppy*24); + } + } + } + + if (drawgraphics==true){ + kos_PutImage((RGB*)kosilka_d,24,24,305,150); + } + else + { + kos_DrawBar(305,150,24,24,0x00AAAA); + } + + + if (drawanimation==true){ + kos_DrawBar(335,150,24,24,0x00AA00); + } + else + { + kos_DrawBar(335,150,24,24,0xAA0000); + } + + kos_WriteTextToWindow(257,200,0x80, 0xFFFFFF ,"Љ Ћ ‘ € ‹ Љ Ђ",19); + kos_WriteTextToWindow(290, 220,0x80, 0xFFFFFF ,"¤«п Љ®«ЁЎаЁ Ћ‘",14); + kos_WriteTextToWindow(239, 240,0x80, 0xFFFFFF ,"<¤«п ­ з «  ЁЈал ­ ¦¬ЁвҐ ENTER>",30); + kos_WriteTextToWindow(30, 380,0x80, 0xFFFFFF ,"<­ ¦¬ЁвҐ ¤«п ЇҐаҐЄ«о祭Ёп ०Ё¬  Ја дЁЄЁ>",53); + kos_WriteTextToWindow(30, 400,0x80, 0xFFFFFF ,"<­ ¦¬ЁвҐ ¤«п ўЄ«о祭Ёп/ўлЄ«о祭Ёп  ­Ё¬ жЁЁ>",41); + kos_WriteTextToWindow(30, 420,0x80, 0xFFFFFF ,"<­ ¦¬ЁвҐ ¤«п Їа®б¬®ва  бўҐ¤Ґ­Ё© ® Їа®Ја ¬¬Ґ>",32); + if (skin_available==true) {kos_WriteTextToWindow(30, 440,0x80, 0xFFFFFF ,"<­ ¦¬ЁвҐ зв®Ўл ўлЄ«озЁвм/ўЄ«озЁвм бЄЁ­>",27);} + + + // kos_WriteTextToWindow(470, 440,0x80, 0xFFFFFF ,"­ ¦¬ЁвҐ ¤«п ўл室 ",27); + // kos_DisplayNumberToWindow(external_levels_count[0],3,200,340,0x0000FF,nbDecimal,false); + + + + kos_WriteTextToWindow(536, 440,0x80, 0xFFFFFF ,(char*)version,0); + } + if (status==2){ + kos_DrawBar(10,150,610,200,0x528B4C); + kos_DrawBar(15,155,601,190,0x3BCF46); + kos_WriteTextToWindow(240,230,0x80, 0xFFFFFF ,"‚л ўлЁЈа «Ё!",13); + kos_WriteTextToWindow(240,250,0x80, 0xFFFFFF ,"<­ ¦¬ЁвҐ q ¤«п ў®§ўа в  ў ¬Ґ­о>",17); + } + if (status==3){ + kos_DrawBar(10,150,610,200,0x8B4C4C); + kos_DrawBar(15,155,601,190,0xCF3B3B); + kos_WriteTextToWindow(220,220,0x80, 0xFFFFFF ,"€Ја  ®Є®­зҐ­ ...",13); + kos_WriteTextToWindow(220,240,0x80, 0xFFFFFF ,"<­ ¦¬ЁвҐ r ¤«п в®Ј®, зв®Ўл блЈа вм Ґйс а §>",23); + kos_WriteTextToWindow(220,260,0x80, 0xFFFFFF ,"<­ ¦¬ЁвҐ q ¤«п ў®§ўа в  ў ¬Ґ­о>",17); + } + if (status==-1){ + + kos_DrawBar(0,0,4,480,0x000000); + kos_DrawBar(631-3,0,3,480,0x000000); + + for (int tmpppy=0;tmpppy<20;tmpppy++){ + for (int tmpppx=0;tmpppx<26;tmpppx++){ + if ((tmpppx==0) || (tmpppx==25) || (tmpppy==0) || (tmpppy==19)){ + kos_PutImage((RGB*)stone,24,24,4+tmpppx*24,tmpppy*24); + } + else + { + kos_PutImage((RGB*)skos,24,24,4+tmpppx*24,tmpppy*24); + } + } + } + + kos_WriteTextToWindow(40,40,0x80, 0xFFFFFF ,"Љ®бЁ«Є  ¤«п Ћ‘ Љ®«ЁЎаЁ",22); + kos_WriteTextToWindow(40,60,0x80, 0xFFFFFF ,(char*)version,12); + kos_WriteTextToWindow(40,75,0x80, 0xFFFFFF ,"________________________________________",40); + + kos_WriteTextToWindow(40,120,0x80, 0xFFFFFF ,"Љ®««ҐЄвЁў а §а Ў®взЁЄ®ў:",18); + kos_WriteTextToWindow(40,150,0x80, 0xEEFFEE ,"Ђ­¤аҐ© ЊЁе ©«®ўЁз aka Dron2004 - Їа®Ја ¬¬Ёа®ў ­ЁҐ, ўбв஥­­ п Ја дЁЄ  (ЎҐ§ бЄЁ­ )",32); + kos_WriteTextToWindow(40,170,0x80, 0xDDFFDD ,"Mario79 - вҐбвЁа®ў ­ЁҐ, Ї®¬®йм ў а §а Ў®вЄҐ, ў ¦­лҐ Ё¤ҐЁ",35); + kos_WriteTextToWindow(40,190,0x80, 0xCCFFCC ,"Ataualpa - вҐбвЁа®ў ­ЁҐ, Ї®¬®йм ў а §а Ў®вЄҐ",36); + kos_WriteTextToWindow(40,210,0x80, 0xBBFFBB ,"Leency - вҐбвЁа®ў ­ЁҐ, Ї®¬®йм ў а §а Ў®вЄҐ, § ¬Ґз вҐ«м­лҐ бЄЁ­л, ў ¦­лҐ Ё¤ҐЁ",62); + kos_WriteTextToWindow(40,230,0x80, 0xAAFFAA ,"Mike - вҐбвЁа®ў ­ЁҐ, Ї®¬®йм ў а §а Ў®вЄҐ",34); + kos_WriteTextToWindow(40,250,0x80, 0x99FF99 ,"bw - вҐбвЁа®ў ­ЁҐ, Ї®¬®йм ў а §а Ў®вЄҐ, ў ¦­лҐ Ё¤ҐЁ",49); + kos_WriteTextToWindow(40,270,0x80, 0x99FF99 ,"diamond - Ё¤Ґп ®в¬Ґ­л 室 , вҐбвЁа®ў ­ЁҐ",49); + + kos_WriteTextToWindow(40,300,0x80, 0x88FF88 ,"Ћв¤Ґ«м­®Ґ бЇ бЁЎ®:",16); + kos_WriteTextToWindow(40,330,0x80, 0x77FF77 ,"‚ᥬ, Єв® ЁЈа Ґв ў нвг ЁЈаг :-) !",50); + + + kos_WriteTextToWindow(40,430,0x80, 0x66FF66 ,"­ ¦¬ЁвҐ ¤«п ў®§ўа в  ў ¬Ґ­о",35); + } + + + if (status==4){ + kos_DrawBar(0,0,631,480,0x000000); + + + for (int tmpppy=0;tmpppy<20;tmpppy++){ + for (int tmpppx=0;tmpppx<26;tmpppx++){ + if ((tmpppx==0) || (tmpppx==25) || (tmpppy==0) || (tmpppy==19)){ + kos_PutImage((RGB*)stone,24,24,4+tmpppx*24,tmpppy*24); + } + else + { + kos_PutImage((RGB*)skos,24,24,4+tmpppx*24,tmpppy*24); + } + } + } + + kos_WriteTextToWindow(215, 200,0x80, 0xFFFFFF ,"‚лЎҐаЁвҐ ­ Ў®а га®ў­Ґ© (­ ¦¬ЁвҐ <1> Ё«Ё <2>):",0); + kos_WriteTextToWindow(215, 220,0x80, 0xFFFFFF ,"1. ‚бв஥­­лҐ га®ў­Ё",0); + kos_WriteTextToWindow(215, 240,0x80, 0xFFFFFF ,"2. ‚­Ґи­Ё© ­ Ў®а га®ў­Ґ©",0); + + } + + + kos_WindowRedrawStatus(2); //Конец перерисовки + +} + + + +//Описание уровней игры +//, где k - косилка +// g - трава +// n - скошенная трава +// s - камень +// t - дерево +void initializeLevel(int levnum){ + laststep=0; + if (external_levels==false){ + + kosilkadirection=1; + if (levnum==1){ + static char tmparea[20][20]={{'k','t','g','g','g','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','s','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, + {'g','s','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','s','g','g','s','g','g','g','g','g','g','g'}, + {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','s','s','s','g','g'}, + {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','s','s','s','g','g'}, + {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','s','s','s','g','g'}, + {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','s','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','s','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','t','g','s','g','g','g','s','g','g','g','g','s','g','g','g','g','g','g','g'}, + {'g','g','g','s','g','g','g','g','g','s','g','g','s','g','g','g','g','g','g','g'}}; + for (int tyy=0;tyy<20;tyy++){ + for (int txx=0;txx<20;txx++){ + + if (tmparea[txx][tyy]=='k'){ + kosilkax=tyy; + kosilkay=txx; + } + + gamearea[txx][tyy]=tmparea[tyy][txx]; + } + } + } + if (levnum==2){ + static char tmparea[20][20]={{'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g'}, + {'g','k','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g','g','s','s','g'}, + {'g','g','g','g','g','g','g','g','s','s','g','g','g','g','g','g','g','s','s','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','s','s','g','g','g','g','g'}, + {'g','g','g','s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','s','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}, + {'g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g'}}; + for (int tyy=0;tyy<20;tyy++){ + for (int txx=0;txx<20;txx++){ + + if (tmparea[txx][tyy]=='k'){ + kosilkax=tyy; + kosilkay=txx; + } + + gamearea[txx][tyy]=tmparea[tyy][txx]; + } + } + } + + if (levnum==3){ + static char tmparea[20][20]={{'t','n','t','n','t','n','t','n','t','n','t','n','t','n','t','n','t','n','t','k'}, + {'n','t','g','g','g','g','g','g','g','g','g','g','s','n','n','s','n','s','t','g'}, + {'t','n','g','g','g','g','g','g','g','g','g','g','n','t','n','n','n','t','t','g'}, + {'n','t','g','g','g','g','g','g','g','g','g','g','n','s','n','s','n','s','t','g'}, + {'t','n','g','g','g','g','g','s','s','g','g','g','n','n','n','n','n','t','t','g'}, + {'n','t','g','g','g','g','g','g','g','g','g','g','t','n','s','n','n','s','t','g'}, + {'t','n','g','g','g','g','g','g','g','g','g','g','n','n','n','n','n','t','t','g'}, + {'n','t','g','g','g','g','g','g','g','g','g','g','n','n','s','n','n','s','t','g'}, + {'t','n','g','g','g','g','g','g','g','g','g','g','n','s','n','n','n','t','t','g'}, + {'n','t','g','g','g','g','g','g','g','g','g','g','s','n','n','n','n','t','g','g'}, + {'t','n','g','g','g','s','g','g','g','g','g','g','t','t','t','t','t','t','g','g'}, + {'n','t','g','g','g','s','g','g','g','g','g','g','g','g','g','g','g','t','g','g'}, + {'t','n','g','g','g','g','g','g','g','g','g','g','t','t','g','g','g','t','g','g'}, + {'n','t','g','g','g','g','g','g','t','t','g','g','g','t','g','g','g','t','g','g'}, + {'t','n','g','g','g','g','g','g','t','t','g','g','g','t','g','g','g','t','g','g'}, + {'n','t','g','g','g','g','g','g','g','g','g','g','g','t','g','g','g','t','g','g'}, + {'t','n','g','g','g','g','g','g','g','g','g','g','g','t','t','g','g','t','g','g'}, + {'n','t','g','g','g','g','g','g','g','g','g','g','g','g','t','g','g','t','g','g'}, + {'t','n','g','g','g','g','g','g','g','g','g','g','g','g','t','g','g','t','g','g'}, + {'n','t','s','s','s','s','s','s','s','s','s','s','s','s','t','g','g','g','g','g'}}; + for (int tyy=0;tyy<20;tyy++){ + for (int txx=0;txx<20;txx++){ + + if (tmparea[txx][tyy]=='k'){ + kosilkax=tyy; + kosilkay=txx; + } + + gamearea[txx][tyy]=tmparea[tyy][txx]; + } + } + } + + if (levnum==4){ + static char tmparea[20][20]={{'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','n','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','n','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','n','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','n','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','s','s','t'}, + {'t','g','g','g','g','t','t','t','t','t','t','t','t','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','t','t','t','t','t','t','t','t','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','k','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}}; + for (int tyy=0;tyy<20;tyy++){ + for (int txx=0;txx<20;txx++){ + + if (tmparea[txx][tyy]=='k'){ + kosilkax=tyy; + kosilkay=txx; + } + + gamearea[txx][tyy]=tmparea[tyy][txx]; + } + } + } + + if (levnum==5){ + static char tmparea[20][20]={{'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}, + {'t','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','s','g','g','g','g','g','t','g','g','t','g','g','g','g','g','g','g','g','t'}, + {'t','t','g','g','g','g','t','n','t','t','t','g','g','g','g','g','g','g','g','t'}, + {'t','s','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, + {'t','k','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','t','n','n','t','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','t','n','n','t','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','t','n','n','n','t','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','t','n','t','t','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','t','t','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','t'}, + {'t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t'}}; + for (int tyy=0;tyy<20;tyy++){ + for (int txx=0;txx<20;txx++){ + + if (tmparea[txx][tyy]=='k'){ + kosilkax=tyy; + kosilkay=txx; + } + + gamearea[txx][tyy]=tmparea[tyy][txx]; + } + } + } + + if (levnum==6){ + static char tmparea[20][20]={{'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}, + {'s','k','t','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','s','s','s','s','s','s','s','s','s','s','s','s','s','s','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','t','t','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','t','t','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','t','t','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','t','t','g','g','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','t','t','t','g','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','t','t','t','t','t','t','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','t','t','t','t','t','t','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','t','t','g','g','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','t','t','g','g','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g','s','g','g','s'}, + {'s','g','g','s','g','g','g','g','g','g','g','g','g','g','g','g','s','g','g','s'}, + {'s','g','g','s','s','s','s','s','s','s','s','s','s','s','s','s','s','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}}; + for (int tyy=0;tyy<20;tyy++){ + for (int txx=0;txx<20;txx++){ + + if (tmparea[txx][tyy]=='k'){ + kosilkax=tyy; + kosilkay=txx; + } + + gamearea[txx][tyy]=tmparea[tyy][txx]; + } + } + } + + + if (levnum==7){ + static char tmparea[20][20]={{'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','t','t','t','t','t','t','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','t','k','g','g','g','t','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','s','t','t','s'}, + {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','s','s','s','s'}, + {'s','g','g','g','g','g','t','g','g','g','g','t','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','t','t','t','t','g','t','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','t','g','g','t','g','g','g','g','g','g','s'}, + {'s','g','g','g','g','g','g','g','g','t','g','g','t','g','g','g','g','g','g','s'}, + {'s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s'}}; + for (int tyy=0;tyy<20;tyy++){ + for (int txx=0;txx<20;txx++){ + + if (tmparea[txx][tyy]=='k'){ + kosilkax=tyy; + kosilkay=txx; + } + + gamearea[txx][tyy]=tmparea[tyy][txx]; + } + } + } + } + else + { + //ВНЕШНИЕ УРОВНИ + kosilkadirection=1; + + int currentrow=0; + int currentcol=0; + + for (int tmpcntr=0;tmpcntr<400;tmpcntr++){ + + currentcol=(int)(tmpcntr/20); + currentrow=tmpcntr-(((int)(tmpcntr/20))*20); + switch(externallevels[tmpcntr+(400*(levnum-1))]){ + + case 0: + gamearea[currentrow][currentcol]='n'; + break; + case 1: + gamearea[currentrow][currentcol]='g'; + break; + case 2: + gamearea[currentrow][currentcol]='k'; + kosilkax=currentrow; + kosilkay=currentcol; + break; + case 3: + gamearea[currentrow][currentcol]='s'; + break; + case 4: + gamearea[currentrow][currentcol]='t'; + break; + + } + } + + + } + + draw_window(); + +} + +//Преоверяем остаток травы +int grassLeft(){ + int leftgrass=0; + for (int chky=0;chky<20;chky++){ + for (int chkx=0;chkx<20;chkx++){ + if (gamearea[chkx][chky]=='g') { + leftgrass++; + } + } + } + return leftgrass; +} + + +//Меняем уровень или выводим сообщение о том, что все уровни пройдены +void updateStatus(){ + + + if (grassLeft()==0) { + if (level==levelcount){ + gamestarted=false; + status=2; + draw_window(); + } else { + gamestarted=false; + interlevelpause(); + level++; + initializeLevel(level); + gamestarted=true; + } + } + +} + + + + +void decode_skin(){ + int currentbyte3x=0; + RGB tmpRGB; + int tmpcc1=0; + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + kosilka_d[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + kosilka_u[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + kosilka_l[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + kosilka_r[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + skos[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + grass[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + stone[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + + for (tmpcc1=0;tmpcc1<576;tmpcc1++){ + + tmpRGB.r= skindata[currentbyte3x]; + tmpRGB.g= skindata[currentbyte3x+1]; + tmpRGB.b= skindata[currentbyte3x+2]; + tree[tmpcc1]=tmpRGB; + currentbyte3x+=3; + } + +} + + + +void load_external_levels(){ + + CKosFile lev(getLevelsPathName()); + +level_read_result=lev.Read (external_levels_count,1); + + if (level_read_result == 1){ + external_levels_available=true; + } + else + { + external_levels_available=false; + }; + + + if (external_levels_count[0]==0){ + external_levels_available=false; + } + else + { + externallevels = new Byte[400*external_levels_count[0]]; + lev.Read (externallevels,400*external_levels_count[0]); + } + + + +} + +void app_halt(){ + + delete apppath; + delete levpath; + if (external_levels_available==true) {delete externallevels;} + kos_ExitApp(); + +} + +void kos_Main(){ + + + load_external_levels(); + + CKosFile skin(getSkinPathName()); + + read_result=skin.Read (skindata,13824); + if (read_result != 13824){ + skin_available=false; + } + else + { + skin_available=true; + }; + + if (skin_available==false){ + decode_graphics(kosilka_d1,kosilka_d); + decode_graphics(kosilka_u1,kosilka_u); + decode_graphics(kosilka_l1,kosilka_l); + decode_graphics(kosilka_r1,kosilka_r); + decode_graphics(skos1,skos); + decode_graphics(stone1,stone); + decode_graphics(tree1,tree); + decode_graphics(grass1,grass); + skinned=false; + } + else + { + decode_skin(); + skinned=true; + } + + draw_window(); + + for (;;){ + + switch (kos_WaitForEvent()){ + case 1: + w_redraw=true; + draw_window(); + break; + case 2: + Byte keyCode; + kos_GetKey(keyCode); + if (status==1){ + if (gamestarted==true){ + switch (keyCode){ + case 177: + if (kosilkay<19){ + if (gamearea[kosilkax][kosilkay+1]=='g'){ + gamearea[kosilkax][kosilkay]='n'; + gamearea[kosilkax][kosilkay+1]='k'; + + if (drawanimation==true) {animate(kosilkax,kosilkay,1);} + + + lastkosilkadirection=kosilkadirection; + laststep=1; + + kosilkay++; + kosilkadirection=1; + draw_element(kosilkax,kosilkay); + draw_element(kosilkax,kosilkay-1); + display_grass_left(); + updateStatus(); + } + } + break; + case 178: + if (kosilkay>0){ + if (gamearea[kosilkax][kosilkay-1]=='g'){ + gamearea[kosilkax][kosilkay]='n'; + gamearea[kosilkax][kosilkay-1]='k'; + + if (drawanimation==true) {animate(kosilkax,kosilkay,2);} + + lastkosilkadirection=kosilkadirection; + laststep=2; + + kosilkay--; + kosilkadirection=2; + + draw_element(kosilkax,kosilkay); + draw_element(kosilkax,kosilkay+1); + display_grass_left(); + updateStatus(); + } + } + break; + + case 179: + if (kosilkax<19){ + if (gamearea[kosilkax+1][kosilkay]=='g'){ + gamearea[kosilkax][kosilkay]='n'; + gamearea[kosilkax+1][kosilkay]='k'; + + if (drawanimation==true) {animate(kosilkax,kosilkay,3);} + + + lastkosilkadirection=kosilkadirection; + laststep=3; + + kosilkax++; + kosilkadirection=4; + + draw_element(kosilkax,kosilkay); + draw_element(kosilkax-1,kosilkay); + display_grass_left(); + updateStatus(); + } + } + break; + + case 176: + if (kosilkax>0){ + if (gamearea[kosilkax-1][kosilkay]=='g'){ + gamearea[kosilkax][kosilkay]='n'; + gamearea[kosilkax-1][kosilkay]='k'; + + if (drawanimation==true) {animate(kosilkax,kosilkay,4);} + + lastkosilkadirection=kosilkadirection; + laststep=4; + + kosilkax--; + kosilkadirection=3; + + draw_element(kosilkax,kosilkay); + draw_element(kosilkax+1,kosilkay); + display_grass_left(); + updateStatus(); + } + } + break; + + case 27: + if (lives>0){ + lives--; + initializeLevel(level); + + } else { + gamestarted=false; + status=3; + draw_window(); + } + break; + + case 8: + if (laststep!=0){ + kosilkadirection=lastkosilkadirection; + if (laststep==1){ + gamearea[kosilkax][kosilkay]='g'; + gamearea[kosilkax][kosilkay-1]='k'; + draw_element(kosilkax,kosilkay); + draw_element(kosilkax,kosilkay-1); + kosilkay--; + } + if (laststep==2){ + gamearea[kosilkax][kosilkay]='g'; + gamearea[kosilkax][kosilkay+1]='k'; + draw_element(kosilkax,kosilkay); + draw_element(kosilkax,kosilkay+1); + kosilkay++; + } + + if (laststep==3){ + gamearea[kosilkax][kosilkay]='g'; + gamearea[kosilkax-1][kosilkay]='k'; + draw_element(kosilkax,kosilkay); + draw_element(kosilkax-1,kosilkay); + kosilkax--; + } + + if (laststep==4){ + gamearea[kosilkax][kosilkay]='g'; + gamearea[kosilkax+1][kosilkay]='k'; + draw_element(kosilkax,kosilkay); + draw_element(kosilkax+1,kosilkay); + kosilkax++; + } + + + laststep=0; + } + break; + + } + + } + } + if (status==0){ + if (keyCode==13){ //enter + if (external_levels_available==true){ + status=4; + draw_window(); + } + else + { + status=1; + initializeLevel(1); + gamestarted=true; + } + + } + + if (keyCode==103){ + if (drawgraphics==true){ + drawgraphics=false; + } else { + drawgraphics=true; + } + + if (drawgraphics==true){ + kos_PutImage((RGB*)kosilka_d,24,24,305,150); + } + else + { + kos_DrawBar(305,150,24,24,0x00AAAA); + } + } + + if (keyCode==97){ + if (drawanimation==true){ + drawanimation=false; + } else { + drawanimation=true; + } + + if (drawanimation==true){ + kos_DrawBar(335,150,24,24,0x00AA00); + } + else + { + kos_DrawBar(335,150,24,24,0xAA0000); + } + } + if (keyCode==104){ + status=-1; + draw_window(); + } + + if (keyCode==115){ + + if (skin_available==true){ + if (skinned==true){ + skinned=false; + decode_graphics(kosilka_d1,kosilka_d); + decode_graphics(kosilka_u1,kosilka_u); + decode_graphics(kosilka_l1,kosilka_l); + decode_graphics(kosilka_r1,kosilka_r); + decode_graphics(skos1,skos); + decode_graphics(stone1,stone); + decode_graphics(tree1,tree); + decode_graphics(grass1,grass); + } else { + skinned=true; + decode_skin(); + } + + draw_window(); + + } + + } + if (keyCode==27){ + app_halt(); + } + + } + + if (status==4){ + if (keyCode==49){ //1 + external_levels=false; + status=1; + initializeLevel(1); + gamestarted=true; + + } + + if (keyCode==50){ //2 + external_levels=true; + levelcount=external_levels_count[0]; + status=1; + initializeLevel(1); + gamestarted=true; + + } + } + + if (status==2){ + if (keyCode==113){ + lives=2; + status=0; + level=1; + draw_window(); + gamestarted=true; + } + } + + if (status==3){ + if (keyCode==113){ + lives=2; + status=0; + level=1; + draw_window(); + gamestarted=true; + + } + if (keyCode==114){ + lives=2; + status=1; + level=1; + initializeLevel(1); + gamestarted=true; + } + + } + + if (status==-1){ + if (keyCode==8){ + status=0; + draw_window(); + } + } + + //Выводим код нажатой клавиши. Фича временная + /* kos_DrawBar(20,250,150,10,0xEEEEEE); + kos_WriteTextToWindow(20,250,0x80, 0 ,"Button",0); + kos_DisplayNumberToWindow(keyCode,3,70,250,0x0000FF,nbDecimal,false); */ + break; + case 3: + + app_halt(); + break; + } + } +} + +// Конец исходника ;-) diff --git a/programs/games/kosilka/mcsmemm.cpp b/programs/games/kosilka/mcsmemm.cpp new file mode 100644 index 0000000000..20feab80f6 --- /dev/null +++ b/programs/games/kosilka/mcsmemm.cpp @@ -0,0 +1,329 @@ +// memman.cpp : Defines the entry point for the console application. +// + +#include "kosSyst.h" +#include "mcsmemm.h" + + +void * __cdecl operator new ( size_t count, size_t element_size ) +{ + return allocmem( (Dword)(count * element_size) ); +} + +void * __cdecl operator new [] ( size_t amount ) +{ + return allocmem( (Dword)amount ); +} + +void * __cdecl operator new ( size_t amount ) +{ + return allocmem( (Dword)amount ); +} + +void __cdecl operator delete ( void *pointer ) +{ + if ( pointer != NULL ) freemem( pointer ); +} + +void __cdecl operator delete [] ( void *pointer ) +{ + if ( pointer != NULL ) freemem( pointer ); +} + + +// +Dword mmMutex = FALSE; +MemBlock *rootfree = NULL; +MemBlock *rootuser = NULL; +bool mmInitialized = false; +Byte *mmHeapTop = NULL; + + +// +Byte * AllocMemFromSystem( Dword reqSize ) +{ + Byte *result; + sProcessInfo pInfo; + + // + if ( mmInitialized ) + { + result = mmHeapTop; + } + else + { + // + kos_ProcessInfo( &pInfo ); + // + result = (Byte *)(pInfo.processInfo.used_memory + 1); + // + mmInitialized = true; + } + // + if ( ! kos_ApplicationMemoryResize( ((Dword)result) + reqSize ) ) + { + result = NULL; + } + // + mmHeapTop = result + reqSize; + // + return result; +} + + +// +Byte *allocmem( Dword reqsize ) +{ + MemBlock *BlockForCheck; + MemBlock *LastKnownGood; + Dword tail; + Byte *address; + + //подровняем размер + if( ( tail = reqsize % SIZE_ALIGN ) != 0 ) + { + reqsize += SIZE_ALIGN - tail; + } + + LastKnownGood = NULL; + + // ждём освобождения мьютекса + while ( rtlInterlockedExchange( &mmMutex, TRUE ) ) + { + // + kos_Pause( 1 ); + } + + //ищем подходящий свободный блок + if( rootfree != NULL ) + { + for ( BlockForCheck = rootfree; ; BlockForCheck = BlockForCheck->Next ) + { + if ( BlockForCheck->Size >= reqsize ) + { + //нашли + if ( LastKnownGood != NULL ) + { + if ( LastKnownGood->Size >= BlockForCheck->Size ) + LastKnownGood = BlockForCheck; + } + else + LastKnownGood = BlockForCheck; + if ( LastKnownGood->Size == reqsize ) + break; + } + if ( BlockForCheck->Next == NULL ) + break; + } + } + + if ( LastKnownGood != NULL ) + { + //проверим найденный блок на возможность деления + tail = LastKnownGood->Size - reqsize; + if ( tail >= ( sizeof(MemBlock) + SIZE_ALIGN ) ) + { + //будем разбивать + BlockForCheck = (MemBlock *)( ( (Byte *)LastKnownGood ) + tail ); + BlockForCheck->Size = reqsize; + //вставим занятый блок в начало списка занатых блоков + if( rootuser != NULL ) + { + BlockForCheck->Next = rootuser; + rootuser->Previous = BlockForCheck; + BlockForCheck->Previous = NULL; + rootuser = BlockForCheck; + } + else + { + rootuser = BlockForCheck; + BlockForCheck->Next = NULL; + BlockForCheck->Previous = NULL; + } + + //изменим размер оставшейся части + LastKnownGood->Size = tail - sizeof(MemBlock); + address = ( (Byte *)BlockForCheck ) + sizeof(MemBlock); + + // отпустим мьютекс + rtlInterlockedExchange( &mmMutex, FALSE ); + + return address; + } + else + { + //перемести блок из очереди свободных в начало очереди занятых + //сначала выкинем его из очереди свободных + if ( LastKnownGood->Previous != NULL ) + { + LastKnownGood->Previous->Next = LastKnownGood->Next; + } + else + { + //блок стоит в начале очереди + rootfree = LastKnownGood->Next; + } + if( LastKnownGood->Next != NULL ) + { + LastKnownGood->Next->Previous = LastKnownGood->Previous; + } + //теперь вставим его в очередь занятых + if( rootuser != NULL ) + { + LastKnownGood->Next = rootuser; + rootuser->Previous = LastKnownGood; + LastKnownGood->Previous = NULL; + rootuser = LastKnownGood; + } + else + { + rootuser = LastKnownGood; + LastKnownGood->Next = NULL; + LastKnownGood->Previous = NULL; + } + // + address = ( (Byte *)LastKnownGood ) + sizeof(MemBlock); + + // отпустим мьютекс + rtlInterlockedExchange( &mmMutex, FALSE ); + + return address; + } + } + else + { + //надо получить ещё кусочек памяти + LastKnownGood = (MemBlock *)AllocMemFromSystem( reqsize + sizeof(MemBlock) ); + // + if( LastKnownGood != NULL ) + { + LastKnownGood->Size = reqsize; + //теперь вставим его в очередь занятых + if( rootuser != NULL ) + { + LastKnownGood->Next = rootuser; + rootuser->Previous = LastKnownGood; + LastKnownGood->Previous = NULL; + rootuser = LastKnownGood; + } + else + { + rootuser = LastKnownGood; + LastKnownGood->Next = NULL; + LastKnownGood->Previous = NULL; + } + address = ( (Byte *)LastKnownGood ) + sizeof(MemBlock); + + // отпустим мьютекс + rtlInterlockedExchange( &mmMutex, FALSE ); + + return address; + } + } + + // отпустим мьютекс + rtlInterlockedExchange( &mmMutex, FALSE ); + + // + rtlDebugOutString( "allocmem failed." ); + kos_ExitApp(); + // + return NULL; +} + +// +Dword freemem( void *vaddress ) +{ + Dword result; + + Byte *checknext, *address = (Byte *)vaddress; + + // ждём освобождения мьютекса + while ( rtlInterlockedExchange( &mmMutex, TRUE ) ) + { + // + kos_Pause( 1 ); + } + + MemBlock *released = (MemBlock *)( address - sizeof(MemBlock) ); + + result = released->Size; + + //убираем блок из списка занятых + if ( released->Previous != NULL ) + { + released->Previous->Next = released->Next; + } + else + { + rootuser = released->Next; + } + if ( released->Next != NULL ) + { + released->Next->Previous = released->Previous; + } + //закинем теперь этот блок в список свободных + released->Next = rootfree; + released->Previous = NULL; + rootfree = released; + if ( released->Next != NULL ) + { + released->Next->Previous = released; + } + + //теперь поищем смежные свободные блоки + checknext = (Byte *)(rootfree) + ( rootfree->Size + sizeof(MemBlock) ); + // + for ( released = rootfree->Next; released != NULL; released = released->Next ) + { + if ( checknext == (Byte *)released ) + { + //собираем блоки вместе + //сначала выкинем из очереди свободных + released->Previous->Next = released->Next; + if( released->Next != NULL ) + { + released->Next->Previous = released->Previous; + } + //теперь увеличим размер корневого блока + rootfree->Size += released->Size + sizeof(MemBlock); + break; + } + } + //если надо, поищем блоки перед текщим. + checknext = (Byte *)(rootfree); + // + if ( released == NULL ) + { + for ( released = rootfree->Next; released != NULL; released = released->Next ) + { + if ( checknext == (Byte *)released + ( released->Size + sizeof(MemBlock) ) ) + { + //собираем блоки вместе + //увеличим размер блока + released->Size += rootfree->Size + sizeof(MemBlock); + //теперь выкинем из очереди свободных + released->Previous->Next = released->Next; + if ( released->Next != NULL ) + { + released->Next->Previous = released->Previous; + } + //и закинем его в начало очереди вместо присоединённого блока из корня списка + if ( rootfree->Next != NULL ) + { + rootfree->Next->Previous = released; + } + released->Next = rootfree->Next; + released->Previous = NULL; + rootfree = released; + break; + } + } + } + + // отпустим мьютекс + rtlInterlockedExchange( &mmMutex, FALSE ); + + return result; +} +