merge
authorkoda
Tue, 07 Feb 2012 01:18:29 +0100
changeset 6643 eed176af3cc6
parent 6636 4450e746dc34 (current diff)
parent 6642 863459db5432 (diff)
child 6646 436289cfebf5
merge
--- a/hedgewars/pas2cSystem.pas	Tue Feb 07 01:18:03 2012 +0100
+++ b/hedgewars/pas2cSystem.pas	Tue Feb 07 01:18:29 2012 +0100
@@ -1,12 +1,12 @@
 system;
 
 type 
+    Integer = integer;
     LongInt = integer;
     LongWord = integer;
     Cardinal = integer;
     PtrInt = integer;
     Word = integer;
-    Integer = integer;
     Byte = integer;
     SmallInt = integer;
     ShortInt = integer;
--- a/hedgewars/uStore.pas	Tue Feb 07 01:18:03 2012 +0100
+++ b/hedgewars/uStore.pas	Tue Feb 07 01:18:29 2012 +0100
@@ -303,7 +303,7 @@
            ((vobCount > 0) or (ii <> sprFlake)) then
             begin
             if AltPath = ptNone then
-                if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk, sprFireButton] then // FIXME: hack
+                if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk] then // FIXME: hack
                     begin
                     if not reload then
                         begin
--- a/hedgewars/uTouch.pas	Tue Feb 07 01:18:03 2012 +0100
+++ b/hedgewars/uTouch.pas	Tue Feb 07 01:18:29 2012 +0100
@@ -58,12 +58,12 @@
 procedure aim(finger: Touch_Finger);
 function isOnCrosshair(finger: Touch_Finger): boolean;
 function isOnCurrentHog(finger: Touch_Finger): boolean;
-function isOnFireButton(finger: Touch_Finger): boolean;
 procedure convertToWorldCoord(var x,y: hwFloat; finger: Touch_Finger);
 procedure convertToFingerCoord(var x,y: hwFloat; oldX, oldY: hwFloat);
 function fingerHasMoved(finger: Touch_Finger): boolean;
 function calculateDelta(finger1, finger2: Touch_Finger): hwFloat;
 function getSecondFinger(finger: Touch_Finger): PTouch_Finger;
+function isOnRect(x,y,w,h: LongInt; finger: Touch_Finger): boolean;
 procedure printFinger(finger: Touch_Finger);
 implementation
 
@@ -72,14 +72,6 @@
     nilFingerId = High(SDL_FingerId);
 
 var
-    fireButtonLeft, fireButtonRight, fireButtonTop, fireButtonBottom : LongInt;
-        
-
-
-    leftButtonBoundary  : LongInt;
-    rightButtonBoundary : LongInt;
-    topButtonBoundary   : LongInt;
-    
     pointerCount : Longword;
     fingers: array of Touch_Finger;
     moveCursor : boolean;
@@ -92,9 +84,9 @@
     pinchSize : hwFloat;
     baseZoomValue: GLFloat;
 
-
     //aiming
-    aiming, movingCrosshair: boolean; 
+    aiming, movingCrosshair: boolean;
+    aimingUp, aimingDown: boolean; 
     crosshairCommand: ShortString;
     targetAngle: LongInt;
     stopFiring: boolean;
@@ -124,30 +116,50 @@
                 exit;
             end;
 
-            if isOnFireButton(finger^) then
+            if isOnRect(fireButtonX, fireButtonY, fireButtonW, fireButtonH, finger^) then
             begin
                 stopFiring:= false;
                 ParseCommand('+attack', true);
                 exit;
             end;
-{            if (finger^.x < leftButtonBoundary) and (finger^.y < 390) then
+            if isOnRect(arrowLeftX, arrowLeftY, arrowLeftW, arrowLeftH, finger^) then
             begin
                 ParseCommand('+left', true);
                 walkingLeft := true;
                 exit;
             end;
-            if finger^.x > rightButtonBoundary then
+            if isOnRect(arrowRightX, arrowRightY, arrowRightW, arrowRightH, finger^) then
             begin
                 ParseCommand('+right', true);
                 walkingRight:= true;
                 exit;
             end;
-            if finger^.y < topButtonBoundary then
+            if isOnRect(arrowUpX, arrowUpY, arrowUpW, arrowUpH, finger^) then
+            begin
+                ParseCommand('+up', true);
+                aimingUp:= true;
+                exit;
+            end;
+            if isOnRect(arrowDownX, arrowDownY, arrowUpW, arrowUpH, finger^) then
+            begin
+                ParseCommand('+down', true);
+                aimingDown:= true;
+                exit;
+            end;
+
+            if isOnRect(backjumpX, backjumpY, backjumpW, backjumpH, finger^) then
             begin
                 ParseCommand('hjump', true);
                 exit;
             end;
- }           moveCursor:= true; 
+            if isOnRect(forwardjumpX, forwardjumpY, forwardjumpW, forwardjumpH, finger^) then
+            begin
+                ParseCommand('ljump', true);
+                exit;
+            end;
+
+          
+            moveCursor:= true; 
         end;
         2:
         begin
@@ -221,17 +233,30 @@
         walkingLeft := false;
     end;
 
-    if walkingRight then
+if walkingRight then
     begin
         ParseCommand('-right', true);
         walkingRight := false;
     end;
+
+if aimingUp then
+    begin
+    ParseCommand('-up', true);
+    aimingUp:= false;
+    end;
+if aimingDown then
+    begin
+    ParseCommand('-down', true);
+    aimingDown:= false;
+    end;
+
+
 end;
 
 procedure onTouchDoubleClick(finger: Touch_Finger);
 begin
 finger := finger;//avoid compiler hint
-ParseCommand('ljump', true);
+//ParseCommand('ljump', true);
 end;
 
 procedure onTouchClick(finger: Touch_Finger);
@@ -252,7 +277,6 @@
     CursorPoint.X:= finger.x;
     CursorPoint.Y:= finger.y;
     doPut(CursorPoint.X, CursorPoint.Y, false); 
-    WriteToConsole(Format('%d %d', [CursorPoint.X, CursorPoint.Y]));
     exit
     end;
 
@@ -262,11 +286,11 @@
     exit;
     end;
 
-if finger.y < topButtonBoundary then
+{if finger.y < topButtonBoundary then
     begin
     ParseCommand('hjump', true);
     exit;
-    end;
+    end;}
 end;
 
 function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger;
@@ -423,9 +447,9 @@
 
         tmp := crosshairCommand;
         if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then
-            crosshairCommand := 'down'
+            crosshairCommand := 'up'
         else
-            crosshairCommand:= 'up';
+            crosshairCommand:= 'down';
         if movingCrosshair and (tmp <> crosshairCommand) then 
             begin
             ParseCommand('-' + tmp, true);
@@ -459,11 +483,6 @@
     convertToCursorDeltaY := round(y/32768*cScreenHeight)
 end;
 
-function isOnFireButton(finger: Touch_Finger): boolean;
-begin
-    isOnFireButton:= (finger.x <= fireButtonRight) and (finger.x >= fireButtonLeft) and (finger.y <= fireButtonBottom) and (finger.y >= fireButtonTop);
-end;
-
 function isOnCrosshair(finger: Touch_Finger): boolean;
 var
     x,y : hwFloat;
@@ -481,8 +500,6 @@
     x := _0;
     y := _0;
     convertToFingerCoord(x,y, CurrentHedgehog^.Gear^.X, CurrentHedgehog^.Gear^.Y);
-    WriteToConsole(Format('%d %s %d %s', [finger.x, cstr(x), finger.y, cstr(y) ]));
-    
     isOnCurrentHog := Distance(int2hwFloat(finger.X)-x, int2hwFloat(finger.Y)-y) < _50;
 end;
 
@@ -521,6 +538,15 @@
         getSecondFinger := @fingers[0];
 end;
 
+function isOnRect(x,y,w,h: LongInt; finger: Touch_Finger): boolean;
+begin
+WriteToConsole(Format('(%d,%d) (%d, %d) %d',[finger.x, finger.y, x,y, w]));
+isOnRect:= (finger.x > x)   and
+           (finger.x < x+w) and
+           (cScreenHeight - finger.y > y)   and
+           (cScreenHeight - finger.y < (y+w));
+end;
+
 procedure printFinger(finger: Touch_Finger);
 begin
     WriteToConsole(Format('id:%d, (%d,%d), (%d,%d), time: %d', [finger.id, finger.x, finger.y, finger.historicalX, finger.historicalY, finger.timeSinceDown]));
@@ -536,20 +562,9 @@
     walkingLeft := false;
     walkingRight := false;
 
-    leftButtonBoundary := cScreenWidth div 4;
-    rightButtonBoundary := cScreenWidth div 4*3;
-    topButtonBoundary := cScreenHeight div 6;
-    
     setLength(fingers, 4);
     for index := 0 to High(fingers) do 
         fingers[index].id := nilFingerId;
-
-
-    //uRenderCoordScaleX := Round(cScreenWidth/0.8 * 2);
-    fireButtonLeft := Round(cScreenWidth*0.01);
-    fireButtonRight := Round(fireButtonLeft + (spritesData[sprFireButton].Width*0.4));
-    fireButtonBottom := Round(cScreenHeight*0.99);
-    fireButtonTop := fireButtonBottom - Round(spritesData[sprFireButton].Height*0.4);
 end;
 
 begin
--- a/hedgewars/uTypes.pas	Tue Feb 07 01:18:03 2012 +0100
+++ b/hedgewars/uTypes.pas	Tue Feb 07 01:18:29 2012 +0100
@@ -58,6 +58,9 @@
             sprFinger, sprAirBomb, sprAirplane, sprAmAirplane, sprAmGirder,
             sprHHTelepMask, sprSwitch, sprParachute, sprTarget, sprRopeNode,
             sprQuestion, sprPowerBar, sprWindBar, sprWindL, sprWindR,
+{$IFDEF ANDROID}
+            sprFireButton, sprArrowUp, sprArrowDown, sprArrowLeft, sprArrowRight, sprBackjump, sprForwardjump,
+{$ENDIF}
             sprFlake, sprHandRope, sprHandBazooka, sprHandShotgun,
             sprHandDEagle, sprHandAirAttack, sprHandBaseball, sprPHammer,
             sprHandBlowTorch, sprBlowTorch, sprTeleport, sprHHDeath,
@@ -83,7 +86,7 @@
             sprHandResurrector, sprCross, sprAirDrill, sprNapalmBomb,
             sprBulletHit, sprSnowball, sprHandSnowball, sprSnow,
             sprSDFlake, sprSDWater, sprSDCloud, sprSDSplash, sprSDDroplet, sprTardis,
-            sprFireButton, sprSlider
+            sprSlider
             );
 
     // Gears that interact with other Gears and/or Land
--- a/hedgewars/uVariables.pas	Tue Feb 07 01:18:03 2012 +0100
+++ b/hedgewars/uVariables.pas	Tue Feb 07 01:18:29 2012 +0100
@@ -192,6 +192,20 @@
 
     LuaGoals        : shortstring;
 
+/////////////////////////////////////
+//Buttons
+{$IFDEF MOBILE}
+    buttonScale: GLFloat;
+
+    arrowUpX, arrowUpY, arrowUpW, arrowUpH: LongInt; 
+    arrowDownX, arrowDownY, arrowDownW, arrowDownH: LongInt; 
+    arrowLeftX, arrowLeftY, arrowLeftW, arrowLeftH: LongInt; 
+    arrowRightX, arrowRightY, arrowRightW, arrowRightH: LongInt; 
+
+    firebuttonX, fireButtonY, fireButtonW, fireButtonH: LongInt; 
+    backjumpX, backjumpY, backjumpW, backjumpH: LongInt; 
+    forwardjumpX, forwardjumpY, forwardjumpW, forwardjumpH: LongInt; 
+{$ENDIF}
 const
     cHHFileName = 'Hedgehog';
     cCHFileName = 'Crosshair';
@@ -380,6 +394,22 @@
             Width:  80; Height: 13; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: false; getImageDimensions: true),// sprWindL
             (FileName:      'WindR'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
             Width:  80; Height: 13; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: false; getImageDimensions: true),// sprWindR
+{$IFDEF ANDROID}
+            (FileName: 'firebutton'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 128; Height: 128; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprFireButton
+            (FileName: 'arrowUp'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 100; Height: 100; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprArrowUp
+            (FileName: 'arrowDown'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 100; Height: 100; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprArrowDown
+            (FileName: 'arrowLeft'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 100; Height: 100; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprArrowLeft
+            (FileName: 'arrowRight'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 100; Height: 100; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprArrowRight
+            (FileName: 'backjump'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 128; Height: 128; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprBackjump
+            (FileName: 'forwardjump'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 128; Height: 128; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprForwardJump
+{$ENDIF}
             (FileName:      'Flake'; Path:ptCurrTheme; AltPath: ptNone; Texture: nil; Surface: nil;
             Width:  64; Height: 64; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprFlake
             (FileName:     'amRope'; Path: ptHedgehog; AltPath: ptNone; Texture: nil; Surface: nil;
@@ -631,8 +661,6 @@
             Width:  16; Height: 16; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprSDDroplet
             (FileName:  'TARDIS'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
             Width:  48; Height: 79; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprTardis
-            (FileName: 'firebutton'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
-            Width: 450; Height: 150; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprFireButton
             (FileName:  'slider'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
             Width: 5; Height: 17; imageWidth: 5; imageHeight: 15; saveSurf: false; priority: tpLow; getDimensions: false; getImageDimensions: false) // sprSlider
             );
--- a/hedgewars/uWorld.pas	Tue Feb 07 01:18:03 2012 +0100
+++ b/hedgewars/uWorld.pas	Tue Feb 07 01:18:29 2012 +0100
@@ -198,6 +198,46 @@
 SkyOffset:= 0;
 HorizontOffset:= 0;
 
+{$IFDEF ANDROID}
+//positioning of the buttons
+buttonScale:= 1.5/cDefaultZoomLevel;
+firebuttonX:= (cScreenWidth shr 1) - Round(spritesData[sprFireButton].Texture^.h * buttonScale);
+firebuttonY:= -Round(spritesData[sprFireButton].Texture^.h* buttonScale) + cScreenHeight;
+firebuttonW:= Round(spritesData[sprFireButton].Texture^.w * buttonScale);
+firebuttonH:= Round(spritesData[sprFireButton].Texture^.h * buttonScale);
+
+backjumpX:= (cScreenWidth shr 1) - Round(spritesData[sprbackjump].Texture^.h * 2 * buttonScale);
+backjumpY:= -Round(spritesData[sprbackjump].Texture^.h * 1.2 *  buttonScale) + cScreenHeight;
+backjumpW:= Round(spritesData[sprbackjump].Texture^.w * buttonScale);
+backjumpH:= Round(spritesData[sprbackjump].Texture^.h * buttonScale);
+
+forwardjumpX:= (cScreenWidth shr 1) - Round(spritesData[sprforwardjump].Texture^.h * 1.2 * buttonScale);
+forwardjumpY:= -Round(spritesData[sprforwardjump].Texture^.h * 2 * buttonScale) + cScreenHeight;
+forwardjumpW:= Round(spritesData[sprforwardjump].Texture^.w * buttonScale);
+forwardjumpH:= Round(spritesData[sprforwardjump].Texture^.h * buttonScale);
+
+arrowLeftX:= -(cScreenWidth shr 1);
+arrowLeftY:= -Round(spritesData[sprArrowLeft].Texture^.h*buttonScale) + cScreenHeight  - Round(spritesData[sprArrowLeft].Texture^.h*buttonScale);
+arrowLeftW:= Round(spritesData[sprArrowLeft].Texture^.h * buttonScale);
+arrowLeftH:= Round(spritesData[sprArrowLeft].Texture^.h * buttonScale);
+
+arrowRightX:= -(cScreenWidth shr 1)+ Round(spritesData[sprArrowUp].Texture^.h * buttonScale *2);
+arrowRightY:= -Round(spritesData[sprArrowRight].Texture^.h*buttonScale) + cScreenHeight - Round(spritesData[sprArrowRight].Texture^.h*buttonScale);
+arrowRightW:= Round(spritesData[sprArrowRight].Texture^.w * buttonScale);
+arrowRightH:= Round(spritesData[sprArrowRight].Texture^.h * buttonScale);
+
+arrowUpX:= -(cScreenWidth shr 1) + Round(spritesData[sprArrowUp].Texture^.h * buttonScale);
+arrowUpY:= -Round(spritesData[sprArrowUp].Texture^.h*buttonScale) + cScreenHeight - Round(spritesData[sprArrowUp].Texture^.h*buttonScale*2);
+arrowUpW:= Round(spritesData[sprArrowUp].Texture^.w * buttonScale);
+arrowUpH:= Round(spritesData[sprArrowUp].Texture^.h * buttonScale);
+
+arrowDownX:= -(cScreenWidth shr 1) + Round(spritesData[sprArrowUp].Texture^.h * buttonScale);
+arrowDownY:= -Round(spritesData[sprArrowDown].Texture^.h*buttonscale) + cScreenHeight;
+arrowDownW:= Round(spritesData[sprArrowDown].Texture^.w * buttonScale);
+arrowDownH:= Round(spritesData[sprArrowDown].Texture^.h * buttonScale);
+
+
+{$ENDIF}
 end;
 
 procedure InitCameraBorders;
@@ -887,6 +927,7 @@
     highlight: Boolean;
     smallScreenOffset, offsetX, offsetY, screenBottom: LongInt;
     VertexBuffer: array [0..3] of TVertex2f;
+    scale: GLFloat;
 begin
 if (cReducedQuality and rqNoBackground) = 0 then
     begin
@@ -1053,7 +1094,14 @@
 
 {$IFDEF ANDROID}
 // Draw buttons Related to the Touch interface
-DrawTexture(Round(-cScreenWidth*0.5 + cScreenHeight*0.02),Round((cScreenHeight*0.98)-(spritesData[sprFireButton].Height*0.4) ),spritesData[sprFireButton].Texture, 0.4);
+DrawTexture(arrowLeftX, arrowLeftY,spritesData[sprArrowLeft].Texture, buttonScale);
+DrawTexture(arrowRightX, arrowRightY,spritesData[sprArrowRight].Texture, buttonScale);
+DrawTexture(arrowUpX, arrowUpY,spritesData[sprArrowUp].Texture, buttonScale);
+DrawTexture(arrowDownX, arrowDownY,spritesData[sprArrowDown].Texture, buttonScale);
+
+DrawTexture(fireButtonX, firebuttonY, spritesData[sprFireButton].Texture, buttonScale);
+DrawTexture(backjumpX, backjumpY, spritesData[sprBackjump].Texture, buttonScale);
+DrawTexture(forwardjumpX, forwardjumpY, spritesData[sprForwardjump].Texture, buttonScale);
 {$ENDIF}
 
 // Teams Healths
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/arrowdown.png has changed
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/arrowleft.png has changed
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/arrowright.png has changed
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/arrowup.png has changed
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/backjump.png has changed
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/firebutton.png has changed
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/forwardjump.png has changed
--- a/project_files/Android-build/Templates/Makefile.android	Tue Feb 07 01:18:03 2012 +0100
+++ b/project_files/Android-build/Templates/Makefile.android	Tue Feb 07 01:18:29 2012 +0100
@@ -20,7 +20,7 @@
 	$(PPCROSSARM) $(LINKERFLAGS) $(PPCROSSARM_FLAGS) $(PPCROSSARM_INCLUDES) $(FPC_DEFINES) -oout/libhwengine.so ../../hedgewars/hwLibrary.pas
 	${CMAKE_COMMAND} -E copy out/libhwengine.so SDL-android-project/libs/armeabi/
         
-        ${ANT} clean -f $(SDL_ANDROID_DIR)/build.xml
+	${ANT} clean -f $(SDL_ANDROID_DIR)/build.xml
 	${ANT} debug install -f $(SDL_ANDROID_DIR)/build.xml
 clean:  
 	${CMAKE_COMMAND} -E remove_directory out
--- a/tools/PascalUnitSyntaxTree.hs	Tue Feb 07 01:18:03 2012 +0100
+++ b/tools/PascalUnitSyntaxTree.hs	Tue Feb 07 01:18:29 2012 +0100
@@ -99,6 +99,7 @@
     | BTChar
     | BTString
     | BTInt
+    | BTBool
     | BTRecord [(String, BaseType)]
     | BTArray BaseType BaseType
     | BTFunction
--- a/tools/pas2c.hs	Tue Feb 07 01:18:03 2012 +0100
+++ b/tools/pas2c.hs	Tue Feb 07 01:18:29 2012 +0100
@@ -64,28 +64,21 @@
 renderCFiles :: Map.Map String PascalUnit -> IO ()
 renderCFiles units = do
     let u = Map.toList units
-    let ns = Map.map toNamespace units
-    mapM_ (toCFiles ns) u
+    let nss = Map.map (toNamespace nss) units
+    mapM_ (toCFiles nss) u
     where
-    toNamespace :: PascalUnit -> [Record]
-    toNamespace = concatMap tv2id . extractTVs
-    
-    extractTVs (System tv) = tv
-    extractTVs (Program {}) = []
-    extractTVs (Unit _ (Interface _ (TypesAndVars tv)) _ _ _) = tv
-    
-    tv2id :: TypeVarDeclaration -> [Record]
-    tv2id (TypeDeclaration i t@(Sequence ids)) = map (\(Identifier i _) -> fi i BTUnknown) $ i : ids
-    tv2id (TypeDeclaration (Identifier i _) t) = [(map toLower i, (i, BTUnknown))]
-    tv2id (VarDeclaration _ (ids, t) _) = map (\(Identifier i _) -> fi i BTUnknown) ids
-    tv2id (FunctionDeclaration (Identifier i _) _ _ _) = [fi i BTUnknown]
-    tv2id (OperatorDeclaration i _ _ _ _) = [fi i BTUnknown]
-    fi i t = (map toLower i, (i, t))
-    
+    toNamespace :: Map.Map String [Record] -> PascalUnit -> [Record]
+    toNamespace nss (System tvs) = 
+        currentScope $ execState (mapM_ (tvar2C True) tvs) (RenderState [] BTUnknown nss)
+    toNamespace _ (Program {}) = []
+    toNamespace nss (Unit _ interface _ _ _) = 
+        currentScope $ execState (interface2C interface) (RenderState [] BTUnknown nss)
+
    
 toCFiles :: Map.Map String [Record] -> (String, PascalUnit) -> IO ()
 toCFiles _ (_, System _) = return ()
 toCFiles ns p@(fn, pu) = do
+    hPutStrLn stdout $ show $ Map.lookup "pas2cSystem" ns
     hPutStrLn stderr $ "Rendering '" ++ fn ++ "'..."
     toCFiles' p
     where
@@ -149,10 +142,10 @@
 id2C False (Identifier i t) = do
     let i' = map toLower i
     v <- gets $ find (\(a, _) -> a == i') . currentScope
-    --ns <- gets currentScope
+    ns <- gets currentScope
     modify (\s -> s{lastType = t})
     if isNothing v then 
-        error $ "Not defined: '" ++ i' ++ "'"-- ++ show ns
+        error $ "Not defined: '" ++ i' ++ "'\n" ++ show ns
         else 
         return . text . fst . snd . fromJust $ v
 
@@ -171,7 +164,8 @@
     where
     f "integer" = BTInt
     f "pointer" = BTPointerTo BTVoid
-    f _ = error $ show st
+    f "boolean" = BTBool
+    f _ = error $ "Unknown system type: " ++ show st
 resolveType (PointerTo t) = liftM BTPointerTo $ resolveType t
 resolveType (RecordType tv mtvs) = do
     tvs <- mapM f (concat $ tv : fromMaybe [] mtvs)
@@ -183,6 +177,7 @@
 resolveType (ArrayDecl Nothing t) = liftM (BTArray BTInt) $ resolveType t
 resolveType (FunctionType _ _) = return BTFunction
 resolveType (DeriveType _) = return BTInt
+resolveType (String _) = return BTString
 --resolveType UnknownType = return BTUnknown    
 resolveType a = error $ "resolveType: " ++ show a
     
@@ -216,6 +211,7 @@
 tvar2C _ td@(TypeDeclaration i' t) = do
     tp <- type2C t
     tb <- resolveType t
+    error $ show (td, tb)
     i <- id2CTyped tb i'
     return $ text "type" <+> i <+> tp <> text ";"