\usepackage{tikz}
\usepackage{pgfmath}
\usepackage{ifthen}

\def\a{1.0}
\def\b{0.65}
\def\c{1.2}
\def\alfa{25}
\def\kbeta{40}
\def\xoffset{0.91}
\def\yoffset{-0.42}
\def\xwalloffset{0.50}
\def\ywalloffset{-0.42}

%Zmiana wielkości kątów \alfa i \kbeta oraz długości boków \a, \b, \c wymaga (przed poleceniami \wall, \pyramid, \otherwall i \otherpyramid) wywołania polecenia \update.

\newcommand\update
{
  \pgfmathparse{round(100*\a*cos(\alfa))/100}
  \edef\xoffset{\pgfmathresult}
  \pgfmathparse{round(-100*\a*sin(\alfa))/100}
  \edef\yoffset{\pgfmathresult}
  \pgfmathparse{round(100*\b*cos(\kbeta))/100}
  \edef\xwalloffset{\pgfmathresult}
  \pgfmathparse{-round(100*\b*sin(\kbeta))/100}
  \edef\ywalloffset{\pgfmathresult}
}

\update

\newcommand\rightside[3]
{
  \fill[fill=#3, draw=\linecolor, shift={(#1, #2)}] (0, 0) --++ (\kbeta:\b) --++ (0, \c) --++ (180+\kbeta:\b) -- cycle;
}

\newcommand\leftside[3]
{
  \fill[fill=#3, draw=\linecolor, shift={(#1, #2)}] (0, 0) --++ (180-\alfa:\a) --++ (0, \c) --++ (-\alfa:\a) -- cycle;
}

\newcommand\topside[3]
{
  \fill[fill=#3, draw=\linecolor, shift={(#1, #2)}] (0, 0) --++ (\kbeta:\b) --++ (180-\alfa:\a) --++ (180+\kbeta:\b) -- cycle;
}

\newcommand\cube[5]
{
  \topside{#1}{#2 + \c}{#3}
  \leftside{#1}{#2}{#5}
  \rightside{#1}{#2}{#4}
}

\newcommand\notemptytower[7]
{
  \typeout{#3}
  \setcounter{zCubes}{#7}
  \foreach \k in {1,...,#3}
  {
    \cube{#1}{#2 + \value{zCubes}*\c}{#4}{#5}{#6}
    \addtocounter{zCubes}{1}
  }
}

\newcommand\tower[7]
{
  \ifthenelse{#3=0}{}{\notemptytower{#1}{#2}{#3}{#4}{#5}{#6}{#7}}
}

\newcommand\wall[6]
{
  \setcounter{towers}{0}
  \foreach \j in #3
  {
    \addtocounter{towers}{1}
  }
  \setcounter{xCubes}{-\value{towers}}
  \addtocounter{xCubes}{1}
  \foreach \i/\j in #3
  {
    \tower{#1 + \value{xCubes}*\xoffset}{#2 + \value{xCubes}*\yoffset}{\i}{#4}{#5}{#6}{\j}
    \addtocounter{xCubes}{1}
  }
}

\newcommand\pyramid[6]
{
   \setcounter{walls}{0}
   \foreach \j in {#3}
   {
      \addtocounter{walls}{1}
   }
   \setcounter{yCubes}{-\value{walls}}
   \addtocounter{yCubes}{1}
   \setcounter{zCubes}{-\value{walls}}
   \foreach \j in {#3}
   {
      \wall{#1 - \value{yCubes}*\xwalloffset}{#2 + \value{yCubes}*\ywalloffset}{\j}{#4}{#5}{#6}
      \addtocounter{yCubes}{1}
      \addtocounter{zCubes}{1}
   }
}

\newcommand\othertower[6]
{
  \foreach \k in #3
  {
    \cube{#1}{#2 + \k*\c}{#4}{#5}{#6}
  }
}

\newcommand\otherwall[6]
{
  \setcounter{towers}{0}
  \foreach \j in #3
  {
    \addtocounter{towers}{1}
  }
  \setcounter{xCubes}{-\value{towers}}
  \addtocounter{xCubes}{1}
  \foreach \i in #3
  {
    \othertower{#1 + \value{xCubes}*\xoffset}{#2 + \value{xCubes}*\yoffset}{\i}{#4}{#5}{#6}
    \addtocounter{xCubes}{1}
  }
}

\newcommand\otherpyramid[6]
{
   \setcounter{walls}{0}
   \foreach \j in {#3}
   {
      \addtocounter{walls}{1}
   }
   \setcounter{yCubes}{-\value{walls}}
   \addtocounter{yCubes}{1}
   \setcounter{zCubes}{-\value{walls}}
   \foreach \j in {#3}
   {
      \otherwall{#1 - \value{yCubes}*\xwalloffset}{#2 + \value{yCubes}*\ywalloffset}{\j}{#4}{#5}{#6}
      \addtocounter{yCubes}{1}
      \addtocounter{zCubes}{1}
   }
}

\newcommand\contour[6]
{
    \draw[dotted, line width=0.2mm, color=#6, shift={(#1, #2)}] (0,0) --++ (180-\alfa:#3*\a) --++ (0,#5*\c) --++ (-\alfa:#3*\a) -- cycle;
    \draw[dotted, line width=0.2mm, color=#6, shift={(#1, #2)}] (0,0) --++ (\kbeta:#4*\b) --++ (0,#5*\c);
    \draw[dotted, line width=0.2mm, color=#6, shift={(#1, #2)}] (0,#5*\c) --++ (\kbeta:#4*\b) --++ (180-\alfa:#3*\a) --++ (180+\kbeta:#4*\b);
}





