You've answered your own question.
You are checking for one condition AND other conditions
IF(AND(condition1,condtion2,condition3,...etc,TRUE,FALSE)
(At this stage I'll leave it the others to resolve as I know this is going to get more complex)
If(D3 = "", (C12+H13),(C3+G13)+(D3-C3), if(d4 = "", (C12+H13),(C3+G13)+(D4-C4), ""))